unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

dbuf.h (3321B)

      1 /************************************************************************
      2  *   Unreal Internet Relay Chat Daemon, include/dbuf.h
      3  *   Copyright (C) 1990 Markku Savela
      4  *   Copyright (C) 2013 William Pitcock <nenolod@dereferenced.org>
      5  *
      6  *   This program is free software; you can redistribute it and/or modify
      7  *   it under the terms of the GNU General Public License as published by
      8  *   the Free Software Foundation; either version 1, or (at your option)
      9  *   any later version.
     10  *
     11  *   This program is distributed in the hope that it will be useful,
     12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  *   GNU General Public License for more details.
     15  *
     16  *   You should have received a copy of the GNU General Public License
     17  *   along with this program; if not, write to the Free Software
     18  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     19  *
     20  *   $Id$
     21  */
     22 
     23 #ifndef __dbuf_include__
     24 #define __dbuf_include__
     25 
     26 #include "list.h"
     27 
     28 /* 512 bytes -- 510 character bytes + \r\n, per rfc1459 */
     29 #define DBUF_BLOCK_SIZE		(512)
     30 
     31 /*
     32 ** dbuf is a collection of functions which can be used to
     33 ** maintain a dynamic buffering of a byte stream.
     34 ** Functions allocate and release memory dynamically as
     35 ** required [Actually, there is nothing that prevents
     36 ** this package maintaining the buffer on disk, either]
     37 */
     38 
     39 /*
     40 ** These structure definitions are only here to be used
     41 ** as a whole, *DO NOT EVER REFER TO THESE FIELDS INSIDE
     42 ** THE STRUCTURES*! It must be possible to change the internal
     43 ** implementation of this package without changing the
     44 ** interface.
     45 */
     46 typedef struct dbuf {
     47 	u_int length;		/* Current number of bytes stored */
     48 //	u_int offset;		/* Offset to the first byte */
     49 	struct list_head dbuf_list;
     50 } dbuf;
     51 
     52 /*
     53 ** And this 'dbufbuf' should never be referenced outside the
     54 ** implementation of 'dbuf'--would be "hidden" if C had such
     55 ** keyword...
     56 ** If it was possible, this would compile to be exactly 1 memory
     57 ** page in size. 2048 bytes seems to be the most common size, so
     58 ** as long as a pointer is 4 bytes, we get 2032 bytes for buffer
     59 ** data after we take away a bit for malloc to play with. -avalon
     60 */
     61 typedef struct dbufbuf {
     62 	struct list_head dbuf_node;
     63 	size_t size;
     64 	char data[DBUF_BLOCK_SIZE];
     65 } dbufbuf;
     66 
     67 /*
     68 ** dbuf_put
     69 **	Append the number of bytes to the buffer, allocating more
     70 **	memory as needed. Bytes are copied into internal buffers
     71 **	from users buffer.
     72 */
     73 void dbuf_put(dbuf *, const char *, size_t);
     74 					/* Dynamic buffer header */
     75 					/* Pointer to data to be stored */
     76 					/* Number of bytes to store */
     77 
     78 void dbuf_delete(dbuf *, size_t);
     79 					/* Dynamic buffer header */
     80 					/* Number of bytes to delete */
     81 
     82 /*
     83 ** DBufLength
     84 **	Return the current number of bytes stored into the buffer.
     85 **	(One should use this instead of referencing the internal
     86 **	length field explicitly...)
     87 */
     88 #define DBufLength(dyn) ((dyn)->length)
     89 
     90 /*
     91 ** DBufClear
     92 **	Scratch the current content of the buffer. Release all
     93 **	allocated buffers and make it empty.
     94 */
     95 #define DBufClear(dyn)	dbuf_delete((dyn),DBufLength(dyn))
     96 
     97 extern int dbuf_getmsg(dbuf *, char *);
     98 extern int dbuf_get(dbuf *dyn, char **buf);
     99 extern void dbuf_queue_init(dbuf *dyn);
    100 extern void dbuf_init(void);
    101 
    102 #endif /* __dbuf_include__ */