-
+ 42269E10B09731558FE6D6E4F8D52F3C3CE10AD1C67496E22F7EC0E19C6D6586F1491921486E90A468905A68D6414D7B7F68914582206CCC2CE2E3ED1E2D3F3D
mpi/include/iobuf.h
(0 . 0)(1 . 161)
1121 /* iobuf.h - I/O buffer
1122 * Copyright (C) 1998, 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
1123 *
1124 * This file is part of GNUPG.
1125 *
1126 * GNUPG is free software; you can redistribute it and/or modify
1127 * it under the terms of the GNU General Public License as published by
1128 * the Free Software Foundation; either version 3 of the License, or
1129 * (at your option) any later version.
1130 *
1131 * GNUPG is distributed in the hope that it will be useful,
1132 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1133 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1134 * GNU General Public License for more details.
1135 *
1136 * You should have received a copy of the GNU General Public License
1137 * along with this program; if not, see <http://www.gnu.org/licenses/>.
1138 */
1139
1140 #ifndef G10_IOBUF_H
1141 #define G10_IOBUF_H
1142
1143 #include "types.h"
1144
1145
1146 #define DBG_IOBUF iobuf_debug_mode
1147
1148 #define IOBUFCTRL_INIT 1
1149 #define IOBUFCTRL_FREE 2
1150 #define IOBUFCTRL_UNDERFLOW 3
1151 #define IOBUFCTRL_FLUSH 4
1152 #define IOBUFCTRL_DESC 5
1153 #define IOBUFCTRL_CANCEL 6
1154 #define IOBUFCTRL_USER 16
1155
1156 typedef struct iobuf_struct *IOBUF;
1157 typedef struct iobuf_struct *iobuf_t;
1158
1159 /* fixme: we should hide most of this stuff */
1160 struct iobuf_struct {
1161 int use; /* 1 input , 2 output, 3 temp */
1162 off_t nlimit;
1163 off_t nbytes; /* used together with nlimit */
1164 off_t ntotal; /* total bytes read (position of stream) */
1165 int nofast; /* used by the iobuf_get() */
1166 void *directfp;
1167 struct {
1168 size_t size; /* allocated size */
1169 size_t start; /* number of invalid bytes at the begin of the buffer */
1170 size_t len; /* currently filled to this size */
1171 byte *buf;
1172 } d;
1173 int filter_eof;
1174 int error;
1175 int (*filter)( void *opaque, int control,
1176 IOBUF chain, byte *buf, size_t *len);
1177 void *filter_ov; /* value for opaque */
1178 int filter_ov_owner;
1179 char *real_fname;
1180 IOBUF chain; /* next iobuf used for i/o if any (passed to filter) */
1181 int no, subno;
1182 const char *desc;
1183 void *opaque; /* can be used to hold any information */
1184 /* this value is copied to all instances */
1185 struct {
1186 size_t size; /* allocated size */
1187 size_t start; /* number of invalid bytes at the begin of the buffer */
1188 size_t len; /* currently filled to this size */
1189 byte *buf;
1190 } unget;
1191 };
1192
1193 #ifndef EXTERN_UNLESS_MAIN_MODULE
1194 #if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
1195 #define EXTERN_UNLESS_MAIN_MODULE extern
1196 #else
1197 #define EXTERN_UNLESS_MAIN_MODULE
1198 #endif
1199 #endif
1200 EXTERN_UNLESS_MAIN_MODULE int iobuf_debug_mode;
1201
1202 void iobuf_enable_special_filenames ( int yes );
1203 int iobuf_is_pipe_filename (const char *fname);
1204 IOBUF iobuf_alloc(int use, size_t bufsize);
1205 IOBUF iobuf_temp(void);
1206 IOBUF iobuf_temp_with_content( const char *buffer, size_t length );
1207 IOBUF iobuf_open( const char *fname );
1208 IOBUF iobuf_fdopen( int fd, const char *mode );
1209 IOBUF iobuf_sockopen( int fd, const char *mode );
1210 IOBUF iobuf_create( const char *fname );
1211 IOBUF iobuf_append( const char *fname );
1212 IOBUF iobuf_openrw( const char *fname );
1213 int iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval );
1214 int iobuf_close( IOBUF iobuf );
1215 int iobuf_cancel( IOBUF iobuf );
1216
1217 int iobuf_push_filter( IOBUF a, int (*f)(void *opaque, int control,
1218 IOBUF chain, byte *buf, size_t *len), void *ov );
1219 int iobuf_push_filter2( IOBUF a,
1220 int (*f)(void *opaque, int control,
1221 IOBUF chain, byte *buf, size_t *len),
1222 void *ov, int rel_ov );
1223 int iobuf_flush(IOBUF a);
1224 void iobuf_clear_eof(IOBUF a);
1225 #define iobuf_set_error(a) do { (a)->error = 1; } while(0)
1226 #define iobuf_error(a) ((a)->error)
1227
1228 void iobuf_set_limit( IOBUF a, off_t nlimit );
1229
1230 off_t iobuf_tell( IOBUF a );
1231 int iobuf_seek( IOBUF a, off_t newpos );
1232
1233 int iobuf_readbyte(IOBUF a);
1234 int iobuf_read(IOBUF a, byte *buf, unsigned buflen );
1235 unsigned iobuf_read_line( IOBUF a, byte **addr_of_buffer,
1236 unsigned *length_of_buffer, unsigned *max_length );
1237 int iobuf_peek(IOBUF a, byte *buf, unsigned buflen );
1238 int iobuf_writebyte(IOBUF a, unsigned c);
1239 int iobuf_write(IOBUF a, byte *buf, unsigned buflen );
1240 int iobuf_writestr(IOBUF a, const char *buf );
1241
1242 void iobuf_flush_temp( IOBUF temp );
1243 int iobuf_write_temp( IOBUF a, IOBUF temp );
1244 size_t iobuf_temp_to_buffer( IOBUF a, byte *buffer, size_t buflen );
1245 void iobuf_unget_and_close_temp( IOBUF a, IOBUF temp );
1246
1247 int iobuf_get_fd (IOBUF a);
1248 off_t iobuf_get_filelength (IOBUF a, int *overflow);
1249 #define IOBUF_FILELENGTH_LIMIT 0xffffffff
1250 const char *iobuf_get_real_fname( IOBUF a );
1251 const char *iobuf_get_fname( IOBUF a );
1252
1253 void iobuf_set_partial_block_mode( IOBUF a, size_t len );
1254
1255 int iobuf_translate_file_handle ( int fd, int for_write );
1256
1257 /* Get a byte form the iobuf; must check for eof prior to this function.
1258 * This function returns values in the range 0 .. 255 or -1 to indicate EOF
1259 * iobuf_get_noeof() does not return -1 to indicate EOF, but masks the
1260 * returned value to be in the range 0..255.
1261 */
1262 #define iobuf_get(a) \
1263 ( ((a)->nofast || (a)->d.start >= (a)->d.len )? \
1264 iobuf_readbyte((a)) : ( (a)->nbytes++, (a)->d.buf[(a)->d.start++] ) )
1265 #define iobuf_get_noeof(a) (iobuf_get((a))&0xff)
1266
1267 /* write a byte to the iobuf and return true on write error
1268 * This macro does only write the low order byte
1269 */
1270 #define iobuf_put(a,c) iobuf_writebyte(a,c)
1271
1272 #define iobuf_where(a) "[don't know]"
1273 #define iobuf_id(a) ((a)->no)
1274
1275 #define iobuf_get_temp_buffer(a) ( (a)->d.buf )
1276 #define iobuf_get_temp_length(a) ( (a)->d.len )
1277 #define iobuf_is_temp(a) ( (a)->use == 3 )
1278
1279 void iobuf_skip_rest (IOBUF a, unsigned long n, int partial);
1280
1281 #endif /*G10_IOBUF_H*/