paulo@0: /* paulo@0: * $Id: gt_utils.h,v 1.8 2004/04/17 06:05:54 hipnod Exp $ paulo@0: * paulo@0: * Copyright (C) 2001-2003 giFT project (gift.sourceforge.net) paulo@0: * paulo@0: * This program is free software; you can redistribute it and/or modify it paulo@0: * under the terms of the GNU General Public License as published by the paulo@0: * Free Software Foundation; either version 2, or (at your option) any paulo@0: * later version. paulo@0: * paulo@0: * This program is distributed in the hope that it will be useful, but paulo@0: * WITHOUT ANY WARRANTY; without even the implied warranty of paulo@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU paulo@0: * General Public License for more details. paulo@0: */ paulo@0: paulo@0: #ifndef GIFT_GT_UTILS_H_ paulo@0: #define GIFT_GT_UTILS_H_ paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: /* define to set data structures to a predefined value after freeing */ paulo@0: /* #define POISON_FREE 1 */ paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: typedef struct gt_zlib_stream paulo@0: { paulo@0: void *streamptr; paulo@0: paulo@0: enum paulo@0: { paulo@0: ZSTREAM_NONE = 0x00, paulo@0: ZSTREAM_INFLATE = 0x01, paulo@0: ZSTREAM_DEFLATE = 0x02, paulo@0: } type; paulo@0: paulo@0: char *data; paulo@0: char *start, *end; paulo@0: char *pos; paulo@0: } ZlibStream; paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: char *make_str (char *pseudo_str, int len); paulo@0: paulo@0: int peer_addr (int fd, in_addr_t *r_ip, in_port_t *r_port); paulo@0: paulo@0: void fprint_hex (FILE *f, char *buf, int len); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: ZlibStream *zlib_stream_open (size_t max); paulo@0: void zlib_stream_close (ZlibStream *stream); paulo@0: int zlib_stream_inflate (ZlibStream *stream, char *data, size_t size); paulo@0: int zlib_stream_write (ZlibStream *stream, char *data, size_t size); paulo@0: paulo@0: /* returns the amount of data read */ paulo@0: int zlib_stream_read (ZlibStream *stream, char **r_data); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: #ifdef POISON_FREE paulo@0: #define poisoned_free(ptr, chr) \ paulo@0: do { \ paulo@0: memset ((ptr), (chr), sizeof (*(ptr))); \ paulo@0: free ((ptr)); \ paulo@0: } while (0) paulo@0: #else /* POISON_FREE */ paulo@0: #define poisoned_free(ptr, chr) \ paulo@0: free ((ptr)) paulo@0: #endif /* POISON_FREE */ paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: #endif /* GIFT_GT_UTILS_H_ */