1
0
mirror of git://erdgeist.org/opentracker synced 2025-01-13 16:30:06 +00:00

Further compact code

This commit is contained in:
erdgeist 2006-12-08 21:00:56 +00:00
parent b9743bf516
commit 419e65cc2a

View File

@ -104,6 +104,9 @@ const char* http_header(struct http_data* r,const char* h)
void httpresponse(struct http_data* h,int64 s) void httpresponse(struct http_data* h,int64 s)
{ {
char *c, *d, *data; char *c, *d, *data;
struct ot_peer peer;
ot_hash *hash = NULL;
array_cat0(&h->r); array_cat0(&h->r);
c = array_start(&h->r); c = array_start(&h->r);
@ -124,8 +127,7 @@ e400:
if (c[0]!='/') goto e404; if (c[0]!='/') goto e404;
while (c[1]=='/') ++c; while (c[1]=='/') ++c;
data = c; switch( scan_urlencoded_query( &c, data = c, SCAN_PATH ) ) {
switch( scan_urlencoded_query( &c, data, SCAN_PATH ) ) {
case 0: case 0:
e404: e404:
httperror(h,"404 Not Found","No such file or directory."); httperror(h,"404 Not Found","No such file or directory.");
@ -134,49 +136,42 @@ e404:
if (!byte_diff(c,6,"scrape")) if (!byte_diff(c,6,"scrape"))
goto e404; goto e404;
break; break;
case 9: case 8:
if( !byte_diff(c,8,"announce")) if( !byte_diff(c,8,"announce"))
goto e404; goto e404;
else {
// info_hash, left, port, numwant, compact
struct ot_peer peer;
ot_hash *hash = NULL;
byte_copy( peer.ip, 4, h->ip );
peer.port = 6881;
while( 1 ) { byte_copy( peer.ip, 4, h->ip );
data = c; peer.port = 6881;
switch( scan_urlencoded_query( &c, data, SCAN_SEARCHPATH_PARAM ) ) {
case -1: /* error */ while( 1 ) {
goto e404; switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) {
case 4: case -1: /* error */
if(!byte_diff(c,4,"port")) goto e404;
/* scan int */ c; case 4:
else if(!byte_diff(c,4,"left")) if(!byte_diff(c,4,"port"))
/* scan int */ c; /* scan int */ c;
break; else if(!byte_diff(c,4,"left"))
case 7: /* scan int */ c;
if(!byte_diff(c,7,"numwant")) break;
/* scan int */ c; case 7:
else if(!byte_diff(c,7,"compact")) if(!byte_diff(c,7,"numwant"))
/* scan flag */ c; /* scan int */ c;
break; else if(!byte_diff(c,7,"compact"))
case 9: /* info_hash= */ /* scan flag */ c;
if(!byte_diff(c,9,"info_hash")) { break;
data = c; case 9: /* info_hash= */
/* ignore this, when we have less than 20 bytes */ if(!byte_diff(c,9,"info_hash")) {
switch( scan_urlencoded_query( &c, data, SCAN_SEARCHPATH_VALUE ) ) /* ignore this, when we have less than 20 bytes */
case -1: switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) )
httperror(h,"404 Not Found","No such file or directory."); case -1:
goto bailout; httperror(h,"404 Not Found","No such file or directory.");
case 20: goto bailout;
hash = (ot_hash*)data; case 20:
break; hash = (ot_hash*)data; /* Fall through intended */
default: default:
continue; continue;
}
break;
} }
break;
} }
} }
break; break;