-
+ 42269E10B09731558FE6D6E4F8D52F3C3CE10AD1C67496E22F7EC0E19C6D6586F1491921486E90A468905A68D6414D7B7F68914582206CCC2CE2E3ED1E2D3F3D
mpi/include/iobuf.h
(0 . 0)(1 . 161)
1017 /* iobuf.h - I/O buffer
1018 * Copyright (C) 1998, 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
1019 *
1020 * This file is part of GNUPG.
1021 *
1022 * GNUPG is free software; you can redistribute it and/or modify
1023 * it under the terms of the GNU General Public License as published by
1024 * the Free Software Foundation; either version 3 of the License, or
1025 * (at your option) any later version.
1026 *
1027 * GNUPG is distributed in the hope that it will be useful,
1028 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1029 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1030 * GNU General Public License for more details.
1031 *
1032 * You should have received a copy of the GNU General Public License
1033 * along with this program; if not, see <http://www.gnu.org/licenses/>.
1034 */
1035
1036 #ifndef G10_IOBUF_H
1037 #define G10_IOBUF_H
1038
1039 #include "types.h"
1040
1041
1042 #define DBG_IOBUF iobuf_debug_mode
1043
1044 #define IOBUFCTRL_INIT 1
1045 #define IOBUFCTRL_FREE 2
1046 #define IOBUFCTRL_UNDERFLOW 3
1047 #define IOBUFCTRL_FLUSH 4
1048 #define IOBUFCTRL_DESC 5
1049 #define IOBUFCTRL_CANCEL 6
1050 #define IOBUFCTRL_USER 16
1051
1052 typedef struct iobuf_struct *IOBUF;
1053 typedef struct iobuf_struct *iobuf_t;
1054
1055 /* fixme: we should hide most of this stuff */
1056 struct iobuf_struct {
1057 int use; /* 1 input , 2 output, 3 temp */
1058 off_t nlimit;
1059 off_t nbytes; /* used together with nlimit */
1060 off_t ntotal; /* total bytes read (position of stream) */
1061 int nofast; /* used by the iobuf_get() */
1062 void *directfp;
1063 struct {
1064 size_t size; /* allocated size */
1065 size_t start; /* number of invalid bytes at the begin of the buffer */
1066 size_t len; /* currently filled to this size */
1067 byte *buf;
1068 } d;
1069 int filter_eof;
1070 int error;
1071 int (*filter)( void *opaque, int control,
1072 IOBUF chain, byte *buf, size_t *len);
1073 void *filter_ov; /* value for opaque */
1074 int filter_ov_owner;
1075 char *real_fname;
1076 IOBUF chain; /* next iobuf used for i/o if any (passed to filter) */
1077 int no, subno;
1078 const char *desc;
1079 void *opaque; /* can be used to hold any information */
1080 /* this value is copied to all instances */
1081 struct {
1082 size_t size; /* allocated size */
1083 size_t start; /* number of invalid bytes at the begin of the buffer */
1084 size_t len; /* currently filled to this size */
1085 byte *buf;
1086 } unget;
1087 };
1088
1089 #ifndef EXTERN_UNLESS_MAIN_MODULE
1090 #if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
1091 #define EXTERN_UNLESS_MAIN_MODULE extern
1092 #else
1093 #define EXTERN_UNLESS_MAIN_MODULE
1094 #endif
1095 #endif
1096 EXTERN_UNLESS_MAIN_MODULE int iobuf_debug_mode;
1097
1098 void iobuf_enable_special_filenames ( int yes );
1099 int iobuf_is_pipe_filename (const char *fname);
1100 IOBUF iobuf_alloc(int use, size_t bufsize);
1101 IOBUF iobuf_temp(void);
1102 IOBUF iobuf_temp_with_content( const char *buffer, size_t length );
1103 IOBUF iobuf_open( const char *fname );
1104 IOBUF iobuf_fdopen( int fd, const char *mode );
1105 IOBUF iobuf_sockopen( int fd, const char *mode );
1106 IOBUF iobuf_create( const char *fname );
1107 IOBUF iobuf_append( const char *fname );
1108 IOBUF iobuf_openrw( const char *fname );
1109 int iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval );
1110 int iobuf_close( IOBUF iobuf );
1111 int iobuf_cancel( IOBUF iobuf );
1112
1113 int iobuf_push_filter( IOBUF a, int (*f)(void *opaque, int control,
1114 IOBUF chain, byte *buf, size_t *len), void *ov );
1115 int iobuf_push_filter2( IOBUF a,
1116 int (*f)(void *opaque, int control,
1117 IOBUF chain, byte *buf, size_t *len),
1118 void *ov, int rel_ov );
1119 int iobuf_flush(IOBUF a);
1120 void iobuf_clear_eof(IOBUF a);
1121 #define iobuf_set_error(a) do { (a)->error = 1; } while(0)
1122 #define iobuf_error(a) ((a)->error)
1123
1124 void iobuf_set_limit( IOBUF a, off_t nlimit );
1125
1126 off_t iobuf_tell( IOBUF a );
1127 int iobuf_seek( IOBUF a, off_t newpos );
1128
1129 int iobuf_readbyte(IOBUF a);
1130 int iobuf_read(IOBUF a, byte *buf, unsigned buflen );
1131 unsigned iobuf_read_line( IOBUF a, byte **addr_of_buffer,
1132 unsigned *length_of_buffer, unsigned *max_length );
1133 int iobuf_peek(IOBUF a, byte *buf, unsigned buflen );
1134 int iobuf_writebyte(IOBUF a, unsigned c);
1135 int iobuf_write(IOBUF a, byte *buf, unsigned buflen );
1136 int iobuf_writestr(IOBUF a, const char *buf );
1137
1138 void iobuf_flush_temp( IOBUF temp );
1139 int iobuf_write_temp( IOBUF a, IOBUF temp );
1140 size_t iobuf_temp_to_buffer( IOBUF a, byte *buffer, size_t buflen );
1141 void iobuf_unget_and_close_temp( IOBUF a, IOBUF temp );
1142
1143 int iobuf_get_fd (IOBUF a);
1144 off_t iobuf_get_filelength (IOBUF a, int *overflow);
1145 #define IOBUF_FILELENGTH_LIMIT 0xffffffff
1146 const char *iobuf_get_real_fname( IOBUF a );
1147 const char *iobuf_get_fname( IOBUF a );
1148
1149 void iobuf_set_partial_block_mode( IOBUF a, size_t len );
1150
1151 int iobuf_translate_file_handle ( int fd, int for_write );
1152
1153 /* Get a byte form the iobuf; must check for eof prior to this function.
1154 * This function returns values in the range 0 .. 255 or -1 to indicate EOF
1155 * iobuf_get_noeof() does not return -1 to indicate EOF, but masks the
1156 * returned value to be in the range 0..255.
1157 */
1158 #define iobuf_get(a) \
1159 ( ((a)->nofast || (a)->d.start >= (a)->d.len )? \
1160 iobuf_readbyte((a)) : ( (a)->nbytes++, (a)->d.buf[(a)->d.start++] ) )
1161 #define iobuf_get_noeof(a) (iobuf_get((a))&0xff)
1162
1163 /* write a byte to the iobuf and return true on write error
1164 * This macro does only write the low order byte
1165 */
1166 #define iobuf_put(a,c) iobuf_writebyte(a,c)
1167
1168 #define iobuf_where(a) "[don't know]"
1169 #define iobuf_id(a) ((a)->no)
1170
1171 #define iobuf_get_temp_buffer(a) ( (a)->d.buf )
1172 #define iobuf_get_temp_length(a) ( (a)->d.len )
1173 #define iobuf_is_temp(a) ( (a)->use == 3 )
1174
1175 void iobuf_skip_rest (IOBUF a, unsigned long n, int partial);
1176
1177 #endif /*G10_IOBUF_H*/