diff options
| author | erdgeist <> | 2007-10-18 23:33:07 +0000 |
|---|---|---|
| committer | erdgeist <> | 2007-10-18 23:33:07 +0000 |
| commit | b86e6382a1d496cdb2acb0b85732c644de3add11 (patch) | |
| tree | f9a169f692b59201cee2fa73cd993a90f83e902d /scan_urlencoded_query.c | |
| parent | dba3bb3ae7957773f9799a14d6f7b47f08b7c03b (diff) | |
Save a lot of work when skipping through uninteresting http request parameters
Diffstat (limited to 'scan_urlencoded_query.c')
| -rw-r--r-- | scan_urlencoded_query.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/scan_urlencoded_query.c b/scan_urlencoded_query.c index a11b65c..f754fdc 100644 --- a/scan_urlencoded_query.c +++ b/scan_urlencoded_query.c | |||
| @@ -15,10 +15,10 @@ | |||
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | static const unsigned char is_unreserved[256] = { | 17 | static const unsigned char is_unreserved[256] = { |
| 18 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | 18 | 8,0,0,0,0,0,0,0,0,0,8,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 19 | 0,1,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0, | 19 | 8,7,0,0,0,7,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,7,6, |
| 20 | 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, | 20 | 0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,7, |
| 21 | 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0, | 21 | 0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,0,0,7,0, |
| 22 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | 22 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 23 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | 23 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 24 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | 24 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| @@ -32,31 +32,35 @@ static unsigned char fromhex(unsigned char x) { | |||
| 32 | return 0xff; | 32 | return 0xff; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | ssize_t scan_urlencoded_query(char **string, char *deststring, int flags) { | 35 | void scan_urlencoded_skipvalue( char **string ) { |
| 36 | const unsigned char* s=*(const unsigned char**) string; | ||
| 37 | unsigned char f; | ||
| 38 | |||
| 39 | while( ( f = is_unreserved[ *s++ ] ) & SCAN_SEARCHPATH_VALUE ); | ||
| 40 | if( f & SCAN_SEARCHPATH_TERMINATOR ) --s; | ||
| 41 | *string = (char*)s; | ||
| 42 | } | ||
| 43 | |||
| 44 | ssize_t scan_urlencoded_query(char **string, char *deststring, SCAN_SEARCHPATH_FLAG flags) { | ||
| 36 | const unsigned char* s=*(const unsigned char**) string; | 45 | const unsigned char* s=*(const unsigned char**) string; |
| 37 | unsigned char *d = (unsigned char*)deststring; | 46 | unsigned char *d = (unsigned char*)deststring; |
| 38 | register unsigned char b, c; | 47 | unsigned char b, c, f; |
| 39 | 48 | ||
| 40 | retry_parsing: | 49 | while( ( f = is_unreserved[ c = *s++ ] ) & flags ) { |
| 41 | while( is_unreserved[ c = *s++ ] ) { | ||
| 42 | if( c=='%') { | 50 | if( c=='%') { |
| 43 | if( ( b = fromhex(*s++) ) == 0xff ) return -1; | 51 | if( ( b = fromhex(*s++) ) == 0xff ) return -1; |
| 44 | if( ( c = fromhex(*s++) ) == 0xff ) return -1; | 52 | if( ( c = fromhex(*s++) ) == 0xff ) return -1; |
| 45 | c|=(b<<4); | 53 | c|=(b<<4); |
| 46 | } | 54 | } |
| 47 | if( d ) *d++ = c; | 55 | *d++ = c; |
| 48 | } | 56 | } |
| 49 | 57 | ||
| 50 | switch( c ) { | 58 | switch( c ) { |
| 51 | case 0: case '\r': case '\n': case ' ': | 59 | case 0: case '\r': case '\n': case ' ': |
| 52 | if( d && ( d == (unsigned char*)deststring ) ) return -2; | 60 | if( d == (unsigned char*)deststring ) return -2; |
| 53 | --s; | 61 | --s; |
| 54 | break; | 62 | break; |
| 55 | case '?': | 63 | case '?': |
| 56 | if( flags != SCAN_PATH ) { | ||
| 57 | if( d ) *d++ = c; | ||
| 58 | goto retry_parsing; | ||
| 59 | } | ||
| 60 | break; | 64 | break; |
| 61 | case '=': | 65 | case '=': |
| 62 | if( flags != SCAN_SEARCHPATH_PARAM ) return -1; | 66 | if( flags != SCAN_SEARCHPATH_PARAM ) return -1; |
