dovecot-2.2: lib-http: Added support for parsing HTTP word synta...

dovecot at dovecot.org dovecot at dovecot.org
Sun Sep 15 03:38:25 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/1404dbde402c
changeset: 16742:1404dbde402c
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Sun Sep 15 03:37:59 2013 +0300
description:
lib-http: Added support for parsing HTTP word syntax, which includes quoted-string.

diffstat:

 src/lib-http/http-parser.c |  65 +++++++++++++++++++++++++++++++++++++++++++++-
 src/lib-http/http-parser.h |   3 ++
 2 files changed, 67 insertions(+), 1 deletions(-)

diffs (94 lines):

diff -r b172c130df9b -r 1404dbde402c src/lib-http/http-parser.c
--- a/src/lib-http/http-parser.c	Sun Sep 15 03:36:44 2013 +0300
+++ b/src/lib-http/http-parser.c	Sun Sep 15 03:37:59 2013 +0300
@@ -23,8 +23,12 @@
  ctext          = OWS / %x21-27 / %x2A-5B / %x5D-7E / obs-text 
  obs-text       = %x80-FF
  OWS            = *( SP / HTAB )
+ VCHAR          =  %x21-7E
 
- Mapping
+ 'text'         = ( HTAB / SP / VCHAR / obs-text )
+ 
+ Character bit mappings:
+
  (1<<0) => tchar
  (1<<1) => special
  (1<<2) => %x21 / %x2A-5B / %x5D-7E
@@ -127,6 +131,65 @@
 	return 1;
 }
 
+int http_parse_quoted_string(struct http_parser *parser, const char **str_r)
+{
+	string_t *str;
 
+	/* quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
+	   qdtext        = HTAB / SP / "!" / %x23-5B ; '#'-'['
+	                   / %x5D-7E ; ']'-'~'
+	                   / obs-text
+	   quoted-pair   = "\" ( HTAB / SP / VCHAR / obs-text )
+	   obs-text      = %x80-FF
+	 */
 
+	/* DQUOTE */
+	if (parser->cur >= parser->end || parser->cur[0] != '"')
+		return 0;
+	parser->cur++;
 
+	/* *( qdtext / quoted-pair ) */
+	str = t_str_new(256);
+	for (;;) {
+		const unsigned char *first;
+
+		/* *qdtext */
+		first = parser->cur;
+		while (parser->cur < parser->end && http_char_is_qdtext(*parser->cur))
+			parser->cur++;
+
+		if (parser->cur >= parser->end)
+			return -1;
+
+		str_append_n(str, first, parser->cur - first);
+
+		/* DQUOTE */
+		if (*parser->cur == '"') {
+			parser->cur++;
+			break;
+
+		/* "\" */
+		} else if (*parser->cur == '\\') {
+			parser->cur++;
+			
+			if (parser->cur >= parser->end || !http_char_is_text(*parser->cur))
+				return -1;
+			str_append_c(str, *parser->cur);
+
+		/* ERROR */
+		} else {
+			return -1;
+		}
+	}
+	*str_r = str_c(str);
+	return 1;
+}
+
+int http_parse_word(struct http_parser *parser, const char **word_r)
+{
+	if (parser->cur >= parser->end)
+		return 0;
+	if (parser->cur[0] == '"')
+		return http_parse_quoted_string(parser, word_r);
+	return http_parse_token(parser, word_r);
+}
diff -r b172c130df9b -r 1404dbde402c src/lib-http/http-parser.h
--- a/src/lib-http/http-parser.h	Sun Sep 15 03:36:44 2013 +0300
+++ b/src/lib-http/http-parser.h	Sun Sep 15 03:37:59 2013 +0300
@@ -50,4 +50,7 @@
 int http_parse_token_list_next(struct http_parser *parser,
 	const char **token_r);
 
+int http_parse_quoted_string(struct http_parser *parser, const char **str_r);
+int http_parse_word(struct http_parser *parser, const char **word_r);
+
 #endif


More information about the dovecot-cvs mailing list