Lines Matching refs:parser

8 #include "smtp-parser.h"
120 void smtp_parser_init(struct smtp_parser *parser,
123 parser->pool = pool;
124 parser->begin = parser->cur = (unsigned char *)data;
125 parser->end = (unsigned char *)data + strlen(data);
126 parser->error = NULL;
134 smtp_parser_parse_ldh_str(struct smtp_parser *parser,
137 const unsigned char *pbegin = parser->cur, *palnum;
145 while (parser->cur < parser->end) {
146 if (i_isalnum(*parser->cur))
147 palnum = parser->cur;
148 else if (*parser->cur != '-')
150 parser->cur++;
152 if (parser->cur == pbegin || palnum == NULL) {
153 parser->cur = pbegin;
157 parser->cur = palnum+1;
159 str_append_n(out, pbegin, parser->cur - pbegin);
163 int smtp_parser_parse_domain(struct smtp_parser *parser,
179 if (parser->cur >= parser->end ||
180 (!i_isalnum(*parser->cur) && *parser->cur != '-' &&
181 *parser->cur != '_'))
189 if (parser->cur >= parser->end || *parser->cur == '.') {
190 parser->error = "Empty sub-domain";
193 if (!i_isalnum(*parser->cur) && *parser->cur != '-' &&
194 *parser->cur != '_') {
195 parser->error = "Invalid character in domain";
199 str_append_c(value, *parser->cur);
200 parser->cur++;
203 while (parser->cur < parser->end) {
204 if (!i_isalnum(*parser->cur) && *parser->cur != '-' &&
205 *parser->cur != '_')
209 str_append_c(value, *parser->cur);
210 parser->cur++;
214 if (parser->cur >= parser->end || *parser->cur != '.')
219 parser->cur++;
228 smtp_parser_parse_snum(struct smtp_parser *parser, string_t *literal,
231 const unsigned char *pbegin = parser->cur;
239 if (*parser->cur < '0' || *parser->cur > '9')
245 if ((uint8_t)(*parser->cur - '0') > ((uint8_t)-1 % 10))
248 octet = octet * 10 + (*parser->cur - '0');
249 parser->cur++;
250 } while (*parser->cur >= '0' && *parser->cur <= '9');
253 str_append_n(literal, pbegin, parser->cur - pbegin);
259 smtp_parser_parse_ipv4_address(struct smtp_parser *parser,
268 if ((ret = smtp_parser_parse_snum(parser, literal, &octet)) <= 0)
272 for (i = 0; i < 3 && parser->cur < parser->end; i++) {
273 if (*parser->cur != '.')
278 parser->cur++;
280 if ((ret = smtp_parser_parse_snum(parser,
291 int smtp_parser_parse_address_literal(struct smtp_parser *parser,
317 if (parser->cur >= parser->end || *parser->cur != '[')
319 parser->cur++;
330 if ((ret=smtp_parser_parse_ipv4_address(parser, value, &ip4)) != 0) {
332 parser->error = "Invalid IPv4 address literal";
352 if ((ret=smtp_parser_parse_ldh_str(parser, tagbuf)) <= 0 ||
353 parser->cur >= parser->end || *parser->cur != ':') {
354 parser->error = "Invalid address literal";
360 parser->error = t_strdup_printf(
365 parser->cur++;
370 pblock = parser->cur;
371 while (parser->cur < parser->end &&
372 smtp_char_is_dcontent(*parser->cur))
373 parser->cur++;
375 if (parser->cur == pblock) {
376 parser->error = "Empty address literal";
380 str_append_n(value, pblock, parser->cur - pblock);
385 parser->cur - pblock), &ip6)) <= 0) {
386 parser->error = "Invalid IPv6 address literal";
397 if (parser->cur >= parser->end) {
398 parser->error = "Missing ']' at end of address literal";
400 } else if (*parser->cur != ']') {
401 parser->error = "Invalid character in address literal";
405 parser->cur++;
413 int smtp_parser_parse_quoted_string(struct smtp_parser *parser,
432 if (parser->cur >= parser->end || *parser->cur != '"')
434 parser->cur++;
440 while (parser->cur < parser->end) {
441 pbegin = parser->cur;
442 while (parser->cur < parser->end &&
443 smtp_char_is_qtext(*parser->cur)) {
445 parser->cur++;
449 str_append_n(value, pbegin, parser->cur - pbegin);
451 if (parser->cur >= parser->end || *parser->cur != '\\')
453 parser->cur++;
456 if (parser->cur >= parser->end ||
457 !smtp_char_is_qpair(*parser->cur)) {
458 parser->error =
464 str_append_c(value, *parser->cur);
465 parser->cur++;
469 if (parser->cur >= parser->end) {
470 parser->error = "Premature end of quoted string";
473 if (*parser->cur != '"') {
474 parser->error = "Invalid character in quoted string";
477 parser->cur++;
484 smtp_parser_skip_atom(struct smtp_parser *parser)
488 if (parser->cur >= parser->end || !smtp_char_is_atext(*parser->cur))
490 parser->cur++;
492 while (parser->cur < parser->end && smtp_char_is_atext(*parser->cur))
493 parser->cur++;
497 int smtp_parser_parse_atom(struct smtp_parser *parser,
500 const unsigned char *pbegin = parser->cur;
503 if ((ret=smtp_parser_skip_atom(parser)) <= 0)
507 *value_r = t_strndup(pbegin, parser->cur - pbegin);
511 int smtp_parser_parse_string(struct smtp_parser *parser,
518 if ((ret=smtp_parser_parse_quoted_string(parser, value_r)) != 0)
520 return smtp_parser_parse_atom(parser, value_r);
543 int smtp_parser_parse_xtext(struct smtp_parser *parser,
554 if (parser->cur >= parser->end ||
555 (!smtp_char_is_xtext(*parser->cur) && *parser->cur != '+'))
558 while (parser->cur < parser->end) {
559 const unsigned char *pbegin = parser->cur;
561 while (parser->cur < parser->end &&
562 smtp_char_is_xtext(*parser->cur))
563 parser->cur++;
566 str_append_n(out, pbegin, parser->cur - pbegin);
568 if (parser->cur >= parser->end || *parser->cur != '+')
570 parser->cur++;
573 if (smtp_parse_xtext_hexdigit(*parser->cur, &hexchar)) {
574 parser->cur++;
575 if (smtp_parse_xtext_hexdigit(*parser->cur, &hexchar)) {
576 parser->cur++;
583 parser->error = "Invalid hexchar after '+' in xtext";