diff options
Diffstat (limited to 'scan_urlencoded_query.c')
| -rw-r--r-- | scan_urlencoded_query.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/scan_urlencoded_query.c b/scan_urlencoded_query.c index a17db2a..c3acefc 100644 --- a/scan_urlencoded_query.c +++ b/scan_urlencoded_query.c | |||
| @@ -9,6 +9,9 @@ | |||
| 9 | /* Libwofat */ | 9 | /* Libwofat */ |
| 10 | #include "scan.h" | 10 | #include "scan.h" |
| 11 | 11 | ||
| 12 | /* System */ | ||
| 13 | #include <string.h> | ||
| 14 | |||
| 12 | /* Idea is to do a in place replacement or guarantee at least | 15 | /* Idea is to do a in place replacement or guarantee at least |
| 13 | strlen( string ) bytes in deststring | 16 | strlen( string ) bytes in deststring |
| 14 | watch http://www.ietf.org/rfc/rfc2396.txt | 17 | watch http://www.ietf.org/rfc/rfc2396.txt |
| @@ -64,6 +67,22 @@ void scan_urlencoded_skipvalue( char **string ) { | |||
| 64 | *string = (char*)s; | 67 | *string = (char*)s; |
| 65 | } | 68 | } |
| 66 | 69 | ||
| 70 | int scan_find_keywords( const ot_keywords * keywords, char **string, SCAN_SEARCHPATH_FLAG flags) { | ||
| 71 | char *deststring = *string; | ||
| 72 | ssize_t match_length = scan_urlencoded_query(string, deststring, flags ); | ||
| 73 | |||
| 74 | if( match_length < 0 ) return match_length; | ||
| 75 | if( match_length == 0 ) return -3; | ||
| 76 | |||
| 77 | while( keywords->key ) { | ||
| 78 | if( !memcmp( keywords->key, deststring, match_length ) ) | ||
| 79 | return keywords->value; | ||
| 80 | keywords++; | ||
| 81 | } | ||
| 82 | |||
| 83 | return -3; | ||
| 84 | } | ||
| 85 | |||
| 67 | ssize_t scan_urlencoded_query(char **string, char *deststring, SCAN_SEARCHPATH_FLAG flags) { | 86 | ssize_t scan_urlencoded_query(char **string, char *deststring, SCAN_SEARCHPATH_FLAG flags) { |
| 68 | const unsigned char* s=*(const unsigned char**) string; | 87 | const unsigned char* s=*(const unsigned char**) string; |
| 69 | unsigned char *d = (unsigned char*)deststring; | 88 | unsigned char *d = (unsigned char*)deststring; |
| @@ -95,9 +114,7 @@ ssize_t scan_urlencoded_query(char **string, char *deststring, SCAN_SEARCHPATH_F | |||
| 95 | --s; | 114 | --s; |
| 96 | break; | 115 | break; |
| 97 | case '?': | 116 | case '?': |
| 98 | /* XXX to help us parse path?param=value?param=value?... sent by µTorrent 1600 | 117 | if( flags != SCAN_PATH ) return -1; |
| 99 | do not return an error but silently terminate | ||
| 100 | if( flags != SCAN_PATH ) return -1; */ | ||
| 101 | break; | 118 | break; |
| 102 | case '=': | 119 | case '=': |
| 103 | if( flags != SCAN_SEARCHPATH_PARAM ) return -1; | 120 | if( flags != SCAN_SEARCHPATH_PARAM ) return -1; |
