]> jfr.im git - irc/rqf/shadowircd.git/blame - libratbox/include/rb_linebuf.h
Copied libratbox and related stuff from shadowircd upstream.
[irc/rqf/shadowircd.git] / libratbox / include / rb_linebuf.h
CommitLineData
b57f37fb
WP
1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * linebuf.h: A header for the linebuf code.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
22 * USA
23 *
94b4fbf9 24 * $Id: rb_linebuf.h 26092 2008-09-19 15:13:52Z androsyn $
b57f37fb
WP
25 */
26
27#ifndef RB_LIB_H
94b4fbf9 28# error "Do not use linebuf.h directly"
b57f37fb
WP
29#endif
30
31#ifndef __LINEBUF_H__
32#define __LINEBUF_H__
33
34#define LINEBUF_COMPLETE 0
35#define LINEBUF_PARTIAL 1
36#define LINEBUF_PARSED 0
37#define LINEBUF_RAW 1
38
39struct _buf_line;
40struct _buf_head;
41
42/* How big we want a buffer - 510 data bytes, plus space for a '\0' */
43#define BUF_DATA_SIZE 511
44
45typedef struct _buf_line
46{
47 char buf[BUF_DATA_SIZE + 2];
4414eb3c 48 uint8_t terminated; /* Whether we've terminated the buffer */
94b4fbf9 49 uint8_t raw; /* Whether this linebuf may hold 8-bit data */
b57f37fb
WP
50 int len; /* How much data we've got */
51 int refcount; /* how many linked lists are we in? */
52} buf_line_t;
53
54typedef struct _buf_head
55{
56 rb_dlink_list list; /* the actual dlink list */
57 int len; /* length of all the data */
58 int alloclen; /* Actual allocated data length */
59 int writeofs; /* offset in the first line for the write */
60 int numlines; /* number of lines */
61} buf_head_t;
62
63
64
65/* they should be functions, but .. */
66#define rb_linebuf_len(x) ((x)->len)
67#define rb_linebuf_alloclen(x) ((x)->alloclen)
68#define rb_linebuf_numlines(x) ((x)->numlines)
69
70void rb_linebuf_init(size_t heap_size);
71void rb_linebuf_newbuf(buf_head_t *);
72void rb_linebuf_donebuf(buf_head_t *);
73int rb_linebuf_parse(buf_head_t *, char *, int, int);
74int rb_linebuf_get(buf_head_t *, char *, int, int, int);
75void rb_linebuf_putmsg(buf_head_t *, const char *, va_list *, const char *, ...);
76void rb_linebuf_put(buf_head_t *, const char *, ...);
94b4fbf9 77void rb_linebuf_putbuf(buf_head_t * bufhead, const char *buffer);
b57f37fb
WP
78void rb_linebuf_attach(buf_head_t *, buf_head_t *);
79void rb_count_rb_linebuf_memory(size_t *, size_t *);
80int rb_linebuf_flush(rb_fde_t *F, buf_head_t *);
81
82
83#endif