From 779d6c235ff8fe5284fd10dc82a9b99e7fa38d06 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Mon, 5 Jan 2009 18:05:39 +0000 Subject: * http and udp routines now use thread local buffers passed in workstruct containers. In other words they do not use static_buffer anymore and are considered to be thread safe. * the new workstruct also introduces a well defined buffer and result passing path * a new function scan_find_keywords is a wrapper around scan_urlencoded_query that maps keys in url to values passed in an array of ot_keywords structs * this new function cleans up much of url parameter parsing work, where read_ptr and write_ptr have been introduced rather than the confusing char *c, *data variables * I now use memcmp instead of byte_diff to allow compiler to optimize constant size string compares * got rid of UTORRENT_1600_WORKAROUND * livesync_ticker is now only called from one (currently main) thread to avoid race conditions --- scan_urlencoded_query.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'scan_urlencoded_query.c') 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 @@ /* Libwofat */ #include "scan.h" +/* System */ +#include + /* Idea is to do a in place replacement or guarantee at least strlen( string ) bytes in deststring watch http://www.ietf.org/rfc/rfc2396.txt @@ -64,6 +67,22 @@ void scan_urlencoded_skipvalue( char **string ) { *string = (char*)s; } +int scan_find_keywords( const ot_keywords * keywords, char **string, SCAN_SEARCHPATH_FLAG flags) { + char *deststring = *string; + ssize_t match_length = scan_urlencoded_query(string, deststring, flags ); + + if( match_length < 0 ) return match_length; + if( match_length == 0 ) return -3; + + while( keywords->key ) { + if( !memcmp( keywords->key, deststring, match_length ) ) + return keywords->value; + keywords++; + } + + return -3; +} + ssize_t scan_urlencoded_query(char **string, char *deststring, SCAN_SEARCHPATH_FLAG flags) { const unsigned char* s=*(const unsigned char**) string; unsigned char *d = (unsigned char*)deststring; @@ -95,9 +114,7 @@ ssize_t scan_urlencoded_query(char **string, char *deststring, SCAN_SEARCHPATH_F --s; break; case '?': - /* XXX to help us parse path?param=value?param=value?... sent by µTorrent 1600 - do not return an error but silently terminate - if( flags != SCAN_PATH ) return -1; */ + if( flags != SCAN_PATH ) return -1; break; case '=': if( flags != SCAN_SEARCHPATH_PARAM ) return -1; -- cgit v1.2.3