http-parser.c revision 7384b4e78eaab44693c985192276e31322155e32
/* Copyright (c) 2012 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "net.h"
#include "str.h"
#include "strescape.h"
#include "http-url.h"
#include "http-parser.h"
/*
Character definitions:
tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
/ "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
/ DIGIT / ALPHA
; any VCHAR, except special
special = "(" / ")" / "<" / ">" / "@" / ","
/ ";" / ":" / "\" / DQUOTE / "/" / "["
/ "]" / "?" / "=" / "{" / "}"
qdtext = OWS / %x21 / %x23-5B / %x5D-7E / obs-text
qdtext-nf = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
ctext = OWS / %x21-27 / %x2A-5B / %x5D-7E / obs-text
obs-text = %x80-FF
OWS = *( SP / HTAB )
Mapping
(1<<0) => tchar
(1<<1) => special
(1<<2) => %x21 / %x2A-5B / %x5D-7E
(1<<3) => %x23-29
(1<<4) => %x22-27
(1<<5) => HTAB / SP / obs-text
*/
const unsigned char _http_token_char_mask = (1<<0);
const unsigned char _http_char_lookup[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, // 00
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 10
32, 21, 18, 25, 25, 25, 25, 25, 10, 10, 5, 5, 6, 5, 5, 6, // 20
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, // 30
6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, // 40
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 2, 6, 5, 5, // 50
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, // 60
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 0, // 70
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // 80
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // 90
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // A0
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // B0
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // C0
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // D0
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // E0
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // F0
};
/*
* HTTP value parsing
*/
{
}
{
/* OWS = *( SP / HTAB ) */
return;
}
}
{
const unsigned char *first;
/* token = 1*tchar */
return 0;
return 1;
}
const char **token_r)
{
Appendix B:
For compatibility with legacy list rules, recipients SHOULD accept
empty list elements. In other words, consumers would follow the list
productions:
#element => [ ( "," / element ) *( OWS "," [ OWS element ] ) ]
1#element => *( "," OWS ) element *( OWS "," [ OWS element ] )
*/
for (;;) {
break;
return 0;
}
return 1;
}