6d0f6985591e584baaca25187f467d389ea17159
[jelmer/ctrlproxy.git] / src / line.h
1 /*
2         ctrlproxy: A modular IRC proxy
3         (c) 2002-2005 Jelmer Vernooij <jelmer@nl.linux.org>
4
5         This program is free software; you can redistribute it and/or modify
6         it under the terms of the GNU General Public License as published by
7         the Free Software Foundation; either version 2 of the License, or
8         (at your option) any later version.
9
10         This program is distributed in the hope that it will be useful,
11         but WITHOUT ANY WARRANTY; without even the implied warranty of
12         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13         GNU General Public License for more details.
14
15         You should have received a copy of the GNU General Public License
16         along with this program; if not, write to the Free Software
17         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __CTRLPROXY_LINE_H__
21 #define __CTRLPROXY_LINE_H__
22
23 #include <gmodule.h>
24
25 #ifndef G_MODULE_EXPORT
26 #define G_MODULE_EXPORT
27 #endif
28
29 /**
30  * @file
31  * @brief Line manipulation
32  */
33
34 enum has_endcolon { COLON_UNKNOWN = 0, WITH_COLON = 1, WITHOUT_COLON = 2 } ;
35
36 /**
37  * Line information.
38  */
39 struct line {
40         char *origin;
41         char **args; /* NULL terminated */
42         size_t argc;
43         enum has_endcolon has_endcolon;
44 };
45
46 /** 
47  * Copy a line
48  */
49 G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT G_MODULE_EXPORT struct line *linedup(const struct line *l);
50 G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT G_MODULE_EXPORT struct line *irc_parse_line(const char *data);
51 G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT G_MODULE_EXPORT struct line *virc_parse_line(const char *origin, va_list ap);
52 G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT G_MODULE_EXPORT char *irc_line_string(const struct line *l);
53 G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT G_MODULE_EXPORT char *irc_line_string_nl(const struct line *l);
54 G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT G_MODULE_EXPORT char *line_get_nick(const struct line *l);
55 G_MODULE_EXPORT void free_line(struct line *l);
56 G_GNUC_NULL_TERMINATED G_MODULE_EXPORT GIOStatus irc_send_args(GIOChannel *, GIConv, GError **, ...);
57 G_GNUC_PRINTF(4, 5) G_MODULE_EXPORT GIOStatus irc_sendf(GIOChannel *, GIConv, GError **, char *fmt, ...);
58 G_GNUC_WARN_UNUSED_RESULT G_MODULE_EXPORT GIOStatus irc_send_line(
59                                                                                 GIOChannel *, GIConv,
60                                                                                 const struct line *l,
61                                         GError **);
62 G_GNUC_PRINTF(1, 2) G_GNUC_WARN_UNUSED_RESULT G_MODULE_EXPORT struct line *irc_parse_linef(
63                                                                                                         const char *origin, ... );
64 G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT G_MODULE_EXPORT struct line *irc_parse_line_args(
65                                                                                                         const char *origin, ... );
66
67 /**
68  * Read a line from an IO Channel. This will return a line _with_ UTF-8 
69  * characters only!
70  */
71 G_GNUC_WARN_UNUSED_RESULT G_MODULE_EXPORT GIOStatus irc_recv_line(GIOChannel *c, GIConv iconv,
72                                                                                 GError **err, 
73                                                                                 struct line **);
74
75 G_MODULE_EXPORT gboolean line_add_arg(struct line *l, const char *arg);
76
77 #endif /* __CTRLPROXY_LINE_H__ */