Mercurial > hg > index.fcgi > gift-gnutella > gift-gnutella-0.0.11-1pba
view src/gt_utils.h @ 0:d39e1d0d75b6
initial add
author | paulo@hit-nxdomain.opendns.com |
---|---|
date | Sat, 20 Feb 2010 21:18:28 -0800 |
parents | |
children |
line source
1 /*
2 * $Id: gt_utils.h,v 1.8 2004/04/17 06:05:54 hipnod Exp $
3 *
4 * Copyright (C) 2001-2003 giFT project (gift.sourceforge.net)
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 */
17 #ifndef GIFT_GT_UTILS_H_
18 #define GIFT_GT_UTILS_H_
20 /*****************************************************************************/
22 /* define to set data structures to a predefined value after freeing */
23 /* #define POISON_FREE 1 */
25 /*****************************************************************************/
27 typedef struct gt_zlib_stream
28 {
29 void *streamptr;
31 enum
32 {
33 ZSTREAM_NONE = 0x00,
34 ZSTREAM_INFLATE = 0x01,
35 ZSTREAM_DEFLATE = 0x02,
36 } type;
38 char *data;
39 char *start, *end;
40 char *pos;
41 } ZlibStream;
43 /*****************************************************************************/
45 char *make_str (char *pseudo_str, int len);
47 int peer_addr (int fd, in_addr_t *r_ip, in_port_t *r_port);
49 void fprint_hex (FILE *f, char *buf, int len);
51 /*****************************************************************************/
53 ZlibStream *zlib_stream_open (size_t max);
54 void zlib_stream_close (ZlibStream *stream);
55 int zlib_stream_inflate (ZlibStream *stream, char *data, size_t size);
56 int zlib_stream_write (ZlibStream *stream, char *data, size_t size);
58 /* returns the amount of data read */
59 int zlib_stream_read (ZlibStream *stream, char **r_data);
61 /*****************************************************************************/
63 #ifdef POISON_FREE
64 #define poisoned_free(ptr, chr) \
65 do { \
66 memset ((ptr), (chr), sizeof (*(ptr))); \
67 free ((ptr)); \
68 } while (0)
69 #else /* POISON_FREE */
70 #define poisoned_free(ptr, chr) \
71 free ((ptr))
72 #endif /* POISON_FREE */
74 /*****************************************************************************/
76 #endif /* GIFT_GT_UTILS_H_ */