Mercurial > masqmail
annotate src/parse.c @ 273:00724782b6c9
parse.c: comments, better debugging, tiny refactoring
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Fri, 03 Dec 2010 19:25:43 -0300 |
parents | 899175e8dff0 |
children | 89199eda6144 |
rev | line source |
---|---|
0 | 1 /* MasqMail |
2 Copyright (C) 1999-2001 Oliver Kurth | |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
3 Copyright (C) 2010 markus schnalke <meillo@marmaro.de> |
0 | 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 */ | |
19 | |
20 #ifndef PARSE_TEST | |
21 #include "masqmail.h" | |
22 #endif | |
23 | |
24 /* This is really dangerous. I hope that I was careful enough, | |
25 but maybe there is some malformed address possible that causes | |
26 this to segfault or be caught in endless loops. | |
27 | |
28 If you find something like that, PLEASE mail the string to me | |
29 (no matter how idiotic it is), so that I can debug that. | |
30 Those things really should not happen. | |
31 */ | |
32 | |
33 static gchar *specials = "()<>@,;:\\\".[]`"; | |
34 | |
35 char *parse_error = NULL; | |
36 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
37 static gchar* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
38 skip_comment(gchar * p) |
0 | 39 { |
40 | |
41 #ifdef PARSE_TEST | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
42 g_print("skip_comment: %s\n", p); |
0 | 43 #endif |
44 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
45 p++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
46 while (*p && *p != ')') { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
47 p++; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
48 if (*p == '(') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
49 p = skip_comment(p); |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
50 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
51 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
52 p++; |
0 | 53 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
54 return p; |
0 | 55 } |
56 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
57 static gboolean |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
58 read_word(gchar * p, gchar ** b, gchar ** e) |
0 | 59 { |
60 #ifdef PARSE_TEST | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
61 g_print("read_word: %s\n", p); |
0 | 62 #endif |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
63 /* eat leading spaces */ |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
64 while (*p && isspace(*p)) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
65 p++; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
66 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
67 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
68 *b = p; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
69 /* b = &p; */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
70 if (*p == '\"') { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
71 /* quoted-string */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
72 p++; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
73 while (*p && (*p != '\"')) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
74 p++; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
75 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
76 p++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
77 } else { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
78 /* atom */ |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
79 while (*p && !strchr(specials, *p) && !iscntrl(*p) && !isspace(*p)) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
80 p++; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
81 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
82 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
83 *e = p; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
84 return TRUE; |
0 | 85 } |
86 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
87 static gboolean |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
88 read_word_with_dots(gchar * p, gchar ** b, gchar ** e) |
0 | 89 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
90 gchar *b0 = p; |
0 | 91 |
92 #ifdef PARSE_TEST | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
93 g_print("read_word_with_dots: %s\n", p); |
0 | 94 #endif |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
95 while (TRUE) { |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
96 if (!read_word(p, b, e)) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
97 return FALSE; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
98 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
99 p = *e; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
100 if (*p != '.') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
101 break; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
102 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
103 p++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
104 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
105 *b = b0; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
106 *e = p; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
107 return TRUE; |
0 | 108 } |
109 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
110 static gboolean |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
111 read_domain(gchar * p, gchar ** b, gchar ** e) |
0 | 112 { |
113 #ifdef PARSE_TEST | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
114 g_print("read_domain: %s\n", p); |
0 | 115 #endif |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
116 *b = p; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
117 if (*p != '[') { |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
118 while (isalnum(*p) || (*p == '-') || (*p == '.')) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
119 p++; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
120 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
121 } else { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
122 p++; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
123 while (isalpha(*p) || (*p == '.')) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
124 p++; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
125 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
126 if (*p != ']') { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
127 parse_error = g_strdup_printf("']' expected at end of literal address %s", *b); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
128 return FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
129 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
130 p++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
131 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
132 *e = p; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
133 return TRUE; |
0 | 134 } |
135 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
136 gboolean |
15 | 137 parse_address_rfc822(gchar* string, gchar** local_begin, gchar** local_end, gchar** domain_begin, |
138 gchar** domain_end, gchar** address_end) | |
0 | 139 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
140 gint angle_brackets = 0; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
141 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
142 gchar *p = string; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
143 gchar *b, *e; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
144 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
145 *local_begin = *local_end = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
146 *domain_begin = *domain_end = NULL; |
0 | 147 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
148 /* might be some memory left from previous call: */ |
273
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
149 if (parse_error) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
150 g_free(parse_error); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
151 parse_error = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
152 } |
0 | 153 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
154 /* leading spaces and angle brackets */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
155 while (*p && (isspace(*p) || (*p == '<'))) { |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
156 if (*p == '<') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
157 angle_brackets++; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
158 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
159 p++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
160 } |
0 | 161 |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
162 if (!*p) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
163 return FALSE; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
164 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
165 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
166 while (TRUE) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
167 if (!read_word_with_dots(p, &b, &e)) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
168 return FALSE; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
169 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
170 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
171 p = e; |
0 | 172 #ifdef PARSE_TEST |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
173 g_print("after read_word_with_dots: %s\n", p); |
0 | 174 #endif |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
175 /* eat white spaces and comments */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
176 while ((*p && (isspace(*p))) || (*p == '(')) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
177 if (*p == '(') { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
178 if (!(p = skip_comment(p))) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
179 parse_error = g_strdup("missing right bracket ')'"); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
180 return FALSE; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
181 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
182 } else { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
183 p++; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
184 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
185 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
186 /* we now have a non-space char that is not |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
187 the beginning of a comment */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
188 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
189 if (*p == '@') { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
190 /* the last word was the local_part of an addr-spec */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
191 *local_begin = b; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
192 *local_end = e; |
0 | 193 #ifdef PARSE_TEST |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
194 g_print("found local part: %s\n", *local_begin); |
0 | 195 #endif |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
196 if (*p == '@') { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
197 p++; /* skip @ */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
198 /* now the domain */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
199 if (!read_domain(p, &b, &e)) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
200 return FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
201 } |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
202 p = e; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
203 *domain_begin = b; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
204 *domain_end = e; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
205 } else { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
206 /* unqualified? */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
207 *domain_begin = *domain_end = NULL; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
208 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
209 break; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
210 |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
211 } else if (*p == '<') { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
212 /* addr-spec follows */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
213 while (isspace(*p) || (*p == '<')) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
214 if (*p == '<') { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
215 angle_brackets++; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
216 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
217 p++; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
218 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
219 if (!read_word_with_dots(p, &b, &e)) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
220 return FALSE; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
221 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
222 p = e; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
223 *local_begin = b; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
224 *local_end = e; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
225 #ifdef PARSE_TEST |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
226 g_print("found local part: %s\n", *local_begin); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
227 #endif |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
228 if (*p == '@') { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
229 p++; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
230 if (!read_domain(p, &b, &e)) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
231 return FALSE; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
232 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
233 p = e; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
234 *domain_begin = b; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
235 *domain_end = e; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
236 } else { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
237 /* may be unqualified address */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
238 *domain_begin = *domain_end = NULL; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
239 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
240 break; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
241 |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
242 } else if (!*p || *p == '>') { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
243 *local_begin = b; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
244 *local_end = e; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
245 #ifdef PARSE_TEST |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
246 g_print("found local part: %s\n", *local_begin); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
247 #endif |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
248 *domain_begin = *domain_end = NULL; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
249 break; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
250 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
251 } else if (strchr(specials, *p) || iscntrl(*p) || isspace(*p)) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
252 parse_error = g_strdup_printf("unexpected character: %c", *p); |
273
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
253 #ifdef PARSE_TEST |
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
254 g_print("unexpected character: %c", *p); |
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
255 #endif |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
256 return FALSE; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
257 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
258 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
259 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
260 /* trailing spaces and angle brackets */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
261 #ifdef PARSE_TEST |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
262 g_print("down counting trailing '>'\n"); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
263 #endif |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
264 while (*p && (isspace(*p) || (*p == '>'))) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
265 if (*p == '>') { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
266 angle_brackets--; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
267 } |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
268 p++; |
0 | 269 } |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
270 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
271 *address_end = p; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
272 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
273 if (angle_brackets > 0) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
274 parse_error = g_strdup("missing '>' at end of string"); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
275 return FALSE; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
276 } else if (angle_brackets < 0) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
277 parse_error = g_strdup("superfluous '>' at end of string"); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
278 return FALSE; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
279 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
280 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
281 /* we successfully parsed the address */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
282 return TRUE; |
0 | 283 } |
284 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
285 gboolean |
15 | 286 parse_address_rfc821(gchar* string, gchar** local_begin, gchar** local_end, gchar** domain_begin, |
287 gchar** domain_end, gchar** address_end) | |
0 | 288 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
289 gint angle_brackets = 0; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
290 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
291 gchar *p = string; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
292 gchar *b, *e; |
0 | 293 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
294 *local_begin = *local_end = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
295 *domain_begin = *domain_end = NULL; |
0 | 296 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
297 /* might be some memory left from previous call: */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
298 if (parse_error != NULL) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
299 g_free(parse_error); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
300 parse_error = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
301 } |
0 | 302 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
303 /* leading spaces and angle brackets */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
304 while (*p && (isspace(*p) || (*p == '<'))) { |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
305 if (*p == '<') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
306 angle_brackets++; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
307 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
308 p++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
309 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
310 |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
311 if (!*p) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
312 return FALSE; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
313 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
314 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
315 while (TRUE) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
316 if (!read_word_with_dots(p, &b, &e)) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
317 return FALSE; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
318 } |
0 | 319 |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
320 p = e; |
0 | 321 #ifdef PARSE_TEST |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
322 g_print("after read_word_with_dots: %s\n", p); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
323 #endif |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
324 *local_begin = b; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
325 *local_end = e; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
326 #ifdef PARSE_TEST |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
327 g_print("found local part: %s\n", *local_begin); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
328 g_print("local_end = %s\n", *local_end); |
0 | 329 #endif |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
330 if (!(*p) || isspace(*p) || (*p == '>')) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
331 /* unqualified ? */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
332 domain_begin = domain_end = NULL; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
333 break; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
334 } else if (*p == '@') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
335 p++; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
336 if (read_domain(p, &b, &e)) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
337 p = e; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
338 *domain_begin = b; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
339 *domain_end = e; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
340 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
341 break; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
342 } else { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
343 parse_error = g_strdup_printf ("unexpected character after local part '%c'", *p); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
344 return FALSE; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
345 } |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
346 } |
0 | 347 |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
348 /* trailing spaces and angle brackets */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
349 #ifdef PARSE_TEST |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
350 g_print("down counting trailing '>'\n"); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
351 #endif |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
352 while (*p && (isspace(*p) || (*p == '>'))) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
353 if (*p == '>') { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
354 angle_brackets--; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
355 } |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
356 p++; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
357 } |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
358 *address_end = p; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
359 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
360 if (angle_brackets > 0) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
361 parse_error = g_strdup("missing '>' at end of string"); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
362 return FALSE; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
363 } else if (angle_brackets < 0) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
364 parse_error = g_strdup("superfluous '>' at end of string"); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
365 return FALSE; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
366 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
367 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
368 /* we successfully parsed the address */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
369 return TRUE; |
0 | 370 } |
371 | |
372 /* | |
373 allocate address, reading from string. | |
374 On failure, returns NULL. | |
114 | 375 after call, end contains a pointer to the end of the parsed string |
0 | 376 end may be NULL, if we are not interested. |
377 | |
378 parses both rfc 821 and rfc 822 addresses, depending on flag is_rfc821 | |
379 */ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
380 address* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
381 _create_address(gchar * string, gchar ** end, gboolean is_rfc821) |
0 | 382 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
383 gchar *loc_beg, *loc_end; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
384 gchar *dom_beg, *dom_end; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
385 gchar *addr_end; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
386 gboolean ret; |
0 | 387 |
273
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
388 /* TODO: what about (string == NULL)? */ |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
389 if (string && (string[0] == '\0')) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
390 address *addr = g_malloc(sizeof(address)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
391 addr->address = g_strdup(""); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
392 addr->local_part = g_strdup(""); |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
393 /* 'NULL' address (failure notice), |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
394 "" makes sure it will not be qualified with a hostname */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
395 addr->domain = g_strdup(""); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
396 return addr; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
397 } |
0 | 398 |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
399 if (is_rfc821) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
400 ret = parse_address_rfc821(string, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
401 } else { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
402 ret = parse_address_rfc822(string, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
403 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
404 if (!ret) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
405 return NULL; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
406 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
407 |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
408 address *addr = g_malloc(sizeof(address)); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
409 gchar *p = addr_end; |
0 | 410 |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
411 memset(addr, 0, sizeof(address)); |
0 | 412 |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
413 if (loc_beg[0] == '|') { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
414 parse_error = g_strdup("no pipe allowed for RFC 822/821 address"); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
415 return NULL; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
416 } |
0 | 417 |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
418 while (*p && (*p != ',')) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
419 p++; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
420 } |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
421 addr->address = g_strndup(string, p - string); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
422 addr->local_part = g_strndup(loc_beg, loc_end - loc_beg); |
0 | 423 |
424 #ifdef PARSE_TEST | |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
425 g_print("addr->local_part = %s\n", addr->local_part); |
0 | 426 #endif |
427 | |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
428 if (dom_beg != NULL) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
429 addr->domain = g_strndup(dom_beg, dom_end - dom_beg); |
273
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
430 } else if (addr->local_part[0] == '\0') { |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
431 /* 'NULL' address (failure notice), |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
432 "" makes sure it will not be qualified with a hostname */ |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
433 addr->domain = g_strdup(""); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
434 } else { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
435 addr->domain = NULL; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
436 } |
0 | 437 |
273
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
438 if (end) { |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
439 *end = p; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
440 } |
0 | 441 |
442 #ifndef PARSE_TEST | |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
443 addr_unmark_delivered(addr); |
0 | 444 #endif |
445 | |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
446 return addr; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
447 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
448 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
449 address* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
450 create_address_rfc822(gchar * string, gchar ** end) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
451 { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
452 return _create_address(string, end, FALSE); |
0 | 453 } |
454 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
455 address* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
456 create_address_rfc821(gchar * string, gchar ** end) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
457 { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
458 return _create_address(string, end, TRUE); |
0 | 459 } |
460 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
461 GList* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
462 addr_list_append_rfc822(GList * addr_list, gchar * string, gchar * domain) |
0 | 463 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
464 gchar *p = string; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
465 gchar *end; |
0 | 466 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
467 while (*p) { |
273
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
468 #ifdef PARSE_TEST |
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
469 g_print("string: %s\n", p); |
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
470 #endif |
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
471 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
472 address *addr = _create_address(p, &end, FALSE); |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
473 if (!addr) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
474 break; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
475 } |
0 | 476 |
273
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
477 #ifdef PARSE_TEST |
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
478 g_print("addr: %s (%s<@>%s)", addr->address, addr->local_part, addr->domain); |
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
479 #endif |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
480 if (domain && !addr->domain) { |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
481 addr->domain = g_strdup(domain); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
482 } |
273
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
483 #ifdef PARSE_TEST |
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
484 g_print(" (%s<@>%s)\n", addr->local_part, addr->domain); |
00724782b6c9
parse.c: comments, better debugging, tiny refactoring
markus schnalke <meillo@marmaro.de>
parents:
271
diff
changeset
|
485 #endif |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
486 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
487 addr_list = g_list_append(addr_list, addr); |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
488 p = end; |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
489 |
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
490 while (*p == ',' || isspace(*p)) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
491 p++; |
271
899175e8dff0
heavy refactoring in the small of parse.c
markus schnalke <meillo@marmaro.de>
parents:
114
diff
changeset
|
492 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
493 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
494 return addr_list; |
0 | 495 } |