]> jfr.im git - solanum.git/blob - librb/include/rb_linebuf.h
Remove ancient portability code (#361)
[solanum.git] / librb / include / rb_linebuf.h
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 *
24 */
25
26 #ifndef RB_LIB_H
27 # error "Do not use linebuf.h directly"
28 #endif
29
30 #ifndef __LINEBUF_H__
31 #define __LINEBUF_H__
32
33 #define LINEBUF_COMPLETE 0
34 #define LINEBUF_PARTIAL 1
35 #define LINEBUF_PARSED 0
36 #define LINEBUF_RAW 1
37
38 struct _buf_line;
39 struct _buf_head;
40
41 /* IRCv3 tags (512 bytes) + RFC1459 message (510 bytes) */
42 #define LINEBUF_TAGSLEN 512 /* IRCv3 message tags */
43 #define LINEBUF_DATALEN 510 /* RFC1459 message data */
44 #define LINEBUF_SIZE (512 + 510)
45 #define CRLF_LEN 2
46
47 typedef struct _buf_line
48 {
49 char buf[LINEBUF_SIZE + CRLF_LEN + 1];
50 uint8_t terminated; /* Whether we've terminated the buffer */
51 uint8_t raw; /* Whether this linebuf may hold 8-bit data */
52 int len; /* How much data we've got */
53 int refcount; /* how many linked lists are we in? */
54 } buf_line_t;
55
56 typedef struct _buf_head
57 {
58 rb_dlink_list list; /* the actual dlink list */
59 int len; /* length of all the data */
60 int alloclen; /* Actual allocated data length */
61 int writeofs; /* offset in the first line for the write */
62 int numlines; /* number of lines */
63 } buf_head_t;
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
70 void rb_linebuf_init(size_t heap_size);
71 void rb_linebuf_newbuf(buf_head_t *);
72 void rb_linebuf_donebuf(buf_head_t *);
73 int rb_linebuf_parse(buf_head_t *, char *, int, int);
74 int rb_linebuf_get(buf_head_t *, char *, int, int, int);
75 void rb_linebuf_put(buf_head_t *, const rb_strf_t *);
76 void rb_linebuf_attach(buf_head_t *, buf_head_t *);
77 void rb_count_rb_linebuf_memory(size_t *, size_t *);
78 int rb_linebuf_flush(rb_fde_t *F, buf_head_t *);
79
80
81 #endif