1997-11-18 14:06:00 +00:00
|
|
|
/* iobuf.h - I/O buffer
|
2004-03-04 20:46:56 +00:00
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
|
1997-11-18 14:06:00 +00:00
|
|
|
*
|
1998-06-16 15:13:28 +00:00
|
|
|
* This file is part of GNUPG.
|
1997-11-18 14:06:00 +00:00
|
|
|
*
|
1998-06-16 15:13:28 +00:00
|
|
|
* GNUPG is free software; you can redistribute it and/or modify
|
1997-11-18 14:06:00 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
1998-06-16 15:13:28 +00:00
|
|
|
* GNUPG is distributed in the hope that it will be useful,
|
1997-11-18 14:06:00 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-05-31 08:39:18 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
1997-11-18 14:06:00 +00:00
|
|
|
*/
|
|
|
|
|
2002-06-29 13:31:13 +00:00
|
|
|
#ifndef G10_IOBUF_H
|
|
|
|
#define G10_IOBUF_H
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define DBG_IOBUF iobuf_debug_mode
|
|
|
|
|
|
|
|
#define IOBUFCTRL_INIT 1
|
|
|
|
#define IOBUFCTRL_FREE 2
|
|
|
|
#define IOBUFCTRL_UNDERFLOW 3
|
|
|
|
#define IOBUFCTRL_FLUSH 4
|
|
|
|
#define IOBUFCTRL_DESC 5
|
2000-07-14 17:34:53 +00:00
|
|
|
#define IOBUFCTRL_CANCEL 6
|
1997-11-18 14:06:00 +00:00
|
|
|
#define IOBUFCTRL_USER 16
|
|
|
|
|
|
|
|
typedef struct iobuf_struct *IOBUF;
|
2006-12-06 09:52:40 +00:00
|
|
|
typedef struct iobuf_struct *iobuf_t;
|
1997-11-18 14:06:00 +00:00
|
|
|
|
1999-02-16 13:16:33 +00:00
|
|
|
/* fixme: we should hide most of this stuff */
|
1997-11-18 14:06:00 +00:00
|
|
|
struct iobuf_struct {
|
1999-02-16 13:16:33 +00:00
|
|
|
int use; /* 1 input , 2 output, 3 temp */
|
2002-06-29 13:31:13 +00:00
|
|
|
off_t nlimit;
|
|
|
|
off_t nbytes; /* used together with nlimit */
|
|
|
|
off_t ntotal; /* total bytes read (position of stream) */
|
1998-10-16 16:00:17 +00:00
|
|
|
int nofast; /* used by the iobuf_get() */
|
|
|
|
void *directfp;
|
1997-11-18 14:06:00 +00:00
|
|
|
struct {
|
|
|
|
size_t size; /* allocated size */
|
|
|
|
size_t start; /* number of invalid bytes at the begin of the buffer */
|
|
|
|
size_t len; /* currently filled to this size */
|
|
|
|
byte *buf;
|
|
|
|
} d;
|
|
|
|
int filter_eof;
|
1998-07-06 10:23:57 +00:00
|
|
|
int error;
|
1997-11-18 14:06:00 +00:00
|
|
|
int (*filter)( void *opaque, int control,
|
|
|
|
IOBUF chain, byte *buf, size_t *len);
|
|
|
|
void *filter_ov; /* value for opaque */
|
1999-02-19 14:54:00 +00:00
|
|
|
int filter_ov_owner;
|
1999-06-01 14:08:57 +00:00
|
|
|
char *real_fname;
|
1997-11-18 14:06:00 +00:00
|
|
|
IOBUF chain; /* next iobuf used for i/o if any (passed to filter) */
|
|
|
|
int no, subno;
|
|
|
|
const char *desc;
|
1998-01-24 16:32:27 +00:00
|
|
|
void *opaque; /* can be used to hold any information */
|
1997-11-21 14:53:57 +00:00
|
|
|
/* this value is copied to all instances */
|
1998-02-04 18:54:31 +00:00
|
|
|
struct {
|
|
|
|
size_t size; /* allocated size */
|
|
|
|
size_t start; /* number of invalid bytes at the begin of the buffer */
|
|
|
|
size_t len; /* currently filled to this size */
|
|
|
|
byte *buf;
|
|
|
|
} unget;
|
1997-11-18 14:06:00 +00:00
|
|
|
};
|
|
|
|
|
2002-06-29 13:31:13 +00:00
|
|
|
#ifndef EXTERN_UNLESS_MAIN_MODULE
|
2003-05-24 16:40:46 +00:00
|
|
|
#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
|
|
|
|
#define EXTERN_UNLESS_MAIN_MODULE extern
|
|
|
|
#else
|
|
|
|
#define EXTERN_UNLESS_MAIN_MODULE
|
|
|
|
#endif
|
2002-06-29 13:31:13 +00:00
|
|
|
#endif
|
|
|
|
EXTERN_UNLESS_MAIN_MODULE int iobuf_debug_mode;
|
1997-11-18 14:06:00 +00:00
|
|
|
|
2002-06-29 13:31:13 +00:00
|
|
|
void iobuf_enable_special_filenames ( int yes );
|
2004-10-13 09:59:46 +00:00
|
|
|
int iobuf_is_pipe_filename (const char *fname);
|
1999-02-16 13:16:33 +00:00
|
|
|
IOBUF iobuf_alloc(int use, size_t bufsize);
|
1997-11-18 14:06:00 +00:00
|
|
|
IOBUF iobuf_temp(void);
|
1998-10-21 17:34:36 +00:00
|
|
|
IOBUF iobuf_temp_with_content( const char *buffer, size_t length );
|
1997-11-18 14:06:00 +00:00
|
|
|
IOBUF iobuf_open( const char *fname );
|
1999-01-13 13:12:50 +00:00
|
|
|
IOBUF iobuf_fdopen( int fd, const char *mode );
|
2002-06-29 13:31:13 +00:00
|
|
|
IOBUF iobuf_sockopen( int fd, const char *mode );
|
1997-11-18 14:06:00 +00:00
|
|
|
IOBUF iobuf_create( const char *fname );
|
1997-12-16 19:15:09 +00:00
|
|
|
IOBUF iobuf_append( const char *fname );
|
1997-12-19 11:41:47 +00:00
|
|
|
IOBUF iobuf_openrw( const char *fname );
|
2002-06-29 13:31:13 +00:00
|
|
|
int iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval );
|
1997-11-18 14:06:00 +00:00
|
|
|
int iobuf_close( IOBUF iobuf );
|
|
|
|
int iobuf_cancel( IOBUF iobuf );
|
|
|
|
|
|
|
|
int iobuf_push_filter( IOBUF a, int (*f)(void *opaque, int control,
|
|
|
|
IOBUF chain, byte *buf, size_t *len), void *ov );
|
1999-02-19 14:54:00 +00:00
|
|
|
int iobuf_push_filter2( IOBUF a,
|
|
|
|
int (*f)(void *opaque, int control,
|
|
|
|
IOBUF chain, byte *buf, size_t *len),
|
|
|
|
void *ov, int rel_ov );
|
1997-11-18 14:06:00 +00:00
|
|
|
int iobuf_flush(IOBUF a);
|
|
|
|
void iobuf_clear_eof(IOBUF a);
|
1998-07-06 10:23:57 +00:00
|
|
|
#define iobuf_set_error(a) do { (a)->error = 1; } while(0)
|
|
|
|
#define iobuf_error(a) ((a)->error)
|
1997-11-18 14:06:00 +00:00
|
|
|
|
2002-06-29 13:31:13 +00:00
|
|
|
void iobuf_set_limit( IOBUF a, off_t nlimit );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
2002-06-29 13:31:13 +00:00
|
|
|
off_t iobuf_tell( IOBUF a );
|
|
|
|
int iobuf_seek( IOBUF a, off_t newpos );
|
1997-12-12 12:03:58 +00:00
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
int iobuf_readbyte(IOBUF a);
|
1998-02-11 03:25:44 +00:00
|
|
|
int iobuf_read(IOBUF a, byte *buf, unsigned buflen );
|
1999-01-09 17:59:58 +00:00
|
|
|
unsigned iobuf_read_line( IOBUF a, byte **addr_of_buffer,
|
|
|
|
unsigned *length_of_buffer, unsigned *max_length );
|
1998-02-16 20:05:02 +00:00
|
|
|
int iobuf_peek(IOBUF a, byte *buf, unsigned buflen );
|
1997-11-18 14:06:00 +00:00
|
|
|
int iobuf_writebyte(IOBUF a, unsigned c);
|
|
|
|
int iobuf_write(IOBUF a, byte *buf, unsigned buflen );
|
1997-11-19 13:12:23 +00:00
|
|
|
int iobuf_writestr(IOBUF a, const char *buf );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
1999-01-20 18:10:35 +00:00
|
|
|
void iobuf_flush_temp( IOBUF temp );
|
1997-11-18 14:06:00 +00:00
|
|
|
int iobuf_write_temp( IOBUF a, IOBUF temp );
|
|
|
|
size_t iobuf_temp_to_buffer( IOBUF a, byte *buffer, size_t buflen );
|
1998-02-04 18:54:31 +00:00
|
|
|
void iobuf_unget_and_close_temp( IOBUF a, IOBUF temp );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
2004-10-13 18:10:06 +00:00
|
|
|
int iobuf_get_fd (IOBUF a);
|
2005-10-05 16:58:50 +00:00
|
|
|
off_t iobuf_get_filelength (IOBUF a, int *overflow);
|
2000-09-18 14:35:34 +00:00
|
|
|
#define IOBUF_FILELENGTH_LIMIT 0xffffffff
|
1999-06-01 14:08:57 +00:00
|
|
|
const char *iobuf_get_real_fname( IOBUF a );
|
1997-11-21 14:53:57 +00:00
|
|
|
const char *iobuf_get_fname( IOBUF a );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
1998-01-16 21:15:24 +00:00
|
|
|
void iobuf_set_partial_block_mode( IOBUF a, size_t len );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
2002-06-29 13:31:13 +00:00
|
|
|
int iobuf_translate_file_handle ( int fd, int for_write );
|
|
|
|
|
2006-07-26 11:25:36 +00:00
|
|
|
/* Get a byte form the iobuf; must check for eof prior to this function.
|
|
|
|
* This function returns values in the range 0 .. 255 or -1 to indicate EOF
|
1997-11-18 14:06:00 +00:00
|
|
|
* iobuf_get_noeof() does not return -1 to indicate EOF, but masks the
|
2006-07-26 11:25:36 +00:00
|
|
|
* returned value to be in the range 0..255.
|
1997-11-18 14:06:00 +00:00
|
|
|
*/
|
|
|
|
#define iobuf_get(a) \
|
1998-10-16 16:00:17 +00:00
|
|
|
( ((a)->nofast || (a)->d.start >= (a)->d.len )? \
|
1997-11-18 14:06:00 +00:00
|
|
|
iobuf_readbyte((a)) : ( (a)->nbytes++, (a)->d.buf[(a)->d.start++] ) )
|
|
|
|
#define iobuf_get_noeof(a) (iobuf_get((a))&0xff)
|
|
|
|
|
|
|
|
/* write a byte to the iobuf and return true on write error
|
|
|
|
* This macro does only write the low order byte
|
|
|
|
*/
|
|
|
|
#define iobuf_put(a,c) iobuf_writebyte(a,c)
|
|
|
|
|
|
|
|
#define iobuf_where(a) "[don't know]"
|
|
|
|
#define iobuf_id(a) ((a)->no)
|
|
|
|
|
1998-10-21 17:34:36 +00:00
|
|
|
#define iobuf_get_temp_buffer(a) ( (a)->d.buf )
|
1997-11-18 14:06:00 +00:00
|
|
|
#define iobuf_get_temp_length(a) ( (a)->d.len )
|
1999-02-16 13:16:33 +00:00
|
|
|
#define iobuf_is_temp(a) ( (a)->use == 3 )
|
1997-11-18 14:06:00 +00:00
|
|
|
|
2004-09-09 12:42:10 +00:00
|
|
|
void iobuf_skip_rest (IOBUF a, unsigned long n, int partial);
|
|
|
|
|
2002-06-29 13:31:13 +00:00
|
|
|
#endif /*G10_IOBUF_H*/
|