]>
Commit | Line | Data |
---|---|---|
a8e69f5d AC |
1 | /* |
2 | * charybdis - an advanced ircd. | |
3 | * Copyright (c) 2016 William Pitcock <nenolod@dereferenced.org>. | |
4 | * | |
5 | * Permission to use, copy, modify, and/or distribute this software for any | |
6 | * purpose with or without fee is hereby granted, provided that the above | |
7 | * copyright notice and this permission notice is present in all copies. | |
8 | * | |
9 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
10 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
11 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
12 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
13 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
14 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
15 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
16 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
17 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
18 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
19 | * POSSIBILITY OF SUCH DAMAGE. | |
20 | */ | |
21 | ||
22 | #include "stdinc.h" | |
23 | #include "ircd_defs.h" | |
24 | #include "msgbuf.h" | |
25 | ||
26 | /* | |
27 | * parse a message into a MsgBuf. | |
28 | * returns 0 on success, 1 on error. | |
29 | */ | |
30 | int | |
31 | msgbuf_parse(struct MsgBuf *msgbuf, char *line) | |
32 | { | |
33 | char *ch; | |
34 | char *parv[MAXPARA]; | |
35 | size_t n_para; | |
36 | int i; | |
37 | ||
38 | /* skip any leading spaces */ | |
39 | for (ch = line; *ch && *ch == ' '; ch++) | |
40 | ; | |
41 | ||
42 | msgbuf_init(msgbuf); | |
43 | ||
44 | if (*ch == '@') | |
45 | { | |
46 | char *t = ch++; | |
47 | ||
48 | ch = strchr(ch, ' '); | |
49 | if (ch != NULL) | |
50 | { | |
269dd686 | 51 | while (1) |
a8e69f5d AC |
52 | { |
53 | char *next = strchr(t, ';'); | |
54 | char *eq = strchr(t, '='); | |
55 | ||
56 | if (next != NULL) | |
57 | *next = '\0'; | |
58 | ||
59 | if (eq > next) | |
60 | eq = NULL; | |
61 | ||
62 | if (eq != NULL) | |
63 | *eq = '\0'; | |
64 | ||
65 | msgbuf_append_tag(msgbuf, t, eq); | |
269dd686 AC |
66 | |
67 | if (next != NULL) | |
68 | t = next + 1; | |
69 | else | |
70 | break; | |
a8e69f5d AC |
71 | } |
72 | } | |
73 | } | |
74 | ||
75 | /* skip any whitespace between tags and origin */ | |
76 | for (; *ch && *ch == ' '; ch++) | |
77 | ; | |
78 | ||
79 | if (*ch == ':') | |
80 | { | |
81 | ch++; | |
82 | msgbuf->origin = ch; | |
83 | ||
84 | char *end = strchr(ch, ' '); | |
85 | if (end == NULL) | |
86 | return 1; | |
87 | ||
88 | *end = '\0'; | |
89 | ||
90 | for (ch = end + 1; *ch && *ch == ' '; ch++) | |
91 | ; | |
92 | } | |
93 | ||
94 | if (*ch == '\0') | |
95 | return 1; | |
96 | ||
97 | n_para = rb_string_to_array(ch, parv, MAXPARA); | |
98 | if (n_para == 0) | |
99 | return 1; | |
100 | ||
101 | msgbuf->cmd = parv[0]; | |
269dd686 | 102 | for (i = 0; i < n_para; i++) |
a8e69f5d AC |
103 | msgbuf_append_para(msgbuf, parv[i]); |
104 | ||
105 | return 0; | |
106 | } |