summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2009-11-18 03:56:26 +0000
committererdgeist <>2009-11-18 03:56:26 +0000
commit90e7262d9d79b4098cbc52df549e138b77add193 (patch)
tree13375e57250995b14bad09070532542ba9dedf1d
parent1665c54179873fe0c0939225882b1df7df7588d7 (diff)
Preparing more efficient header parsing
-rw-r--r--opentracker.c22
-rw-r--r--trackerlogic.h2
2 files changed, 22 insertions, 2 deletions
diff --git a/opentracker.c b/opentracker.c
index 9cdc68e..c1fe945 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -122,6 +122,24 @@ static void help( char *name ) {
122} 122}
123#undef HELPLINE 123#undef HELPLINE
124 124
125static size_t header_complete( char * request, ssize_t byte_count ) {
126 int i = 0, state = 0;
127
128 for( i=1; i < byte_count; i+=2 )
129 if( request[i] <= 13 ) {
130 i--;
131 for( state = 0 ; i < byte_count; ++i ) {
132 char c = request[i];
133 if( c == '\r' || c == '\n' )
134 state = ( state >> 2 ) | ( ( c << 6 ) & 0xc0 );
135 else
136 break;
137 if( state >= 0xa0 || state == 0x99 ) return i + 1;
138 }
139 }
140 return 0;
141}
142
125static void handle_dead( const int64 sock ) { 143static void handle_dead( const int64 sock ) {
126 struct http_data* cookie=io_getcookie( sock ); 144 struct http_data* cookie=io_getcookie( sock );
127 if( cookie ) { 145 if( cookie ) {
@@ -330,8 +348,8 @@ static int scan_ip6_port( const char *src, ot_ip6 ip, uint16 *port ) {
330 if( bracket && *s == ']' ) ++s; 348 if( bracket && *s == ']' ) ++s;
331 if( *s == 0 || isspace(*s)) return s-src; 349 if( *s == 0 || isspace(*s)) return s-src;
332 if( !ip6_isv4mapped(ip)){ 350 if( !ip6_isv4mapped(ip)){
333 if( *s != ':' && *s != '.' ) return 0; 351 if( *s != ':' && *s != '.' ) return 0;
334 if( !bracket && *(s) == ':' ) return 0; 352 if( !bracket && *(s) == ':' ) return 0;
335 s++; 353 s++;
336 } else { 354 } else {
337 if( *(s++) != ':' ) return 0; 355 if( *(s++) != ':' ) return 0;
diff --git a/trackerlogic.h b/trackerlogic.h
index 5a40055..4052fa4 100644
--- a/trackerlogic.h
+++ b/trackerlogic.h
@@ -118,8 +118,10 @@ struct ot_workstruct {
118#endif 118#endif
119 119
120 /* HTTP specific, non static */ 120 /* HTTP specific, non static */
121 int keep_alive;
121 char *request; 122 char *request;
122 ssize_t request_size; 123 ssize_t request_size;
124 ssize_t header_size;
123 char *reply; 125 char *reply;
124 ssize_t reply_size; 126 ssize_t reply_size;
125}; 127};