More cleanup

dynamic-accesslists
erdgeist 18 years ago
parent 898206ac7a
commit b9743bf516

@ -103,19 +103,16 @@ const char* http_header(struct http_data* r,const char* h)
void httpresponse(struct http_data* h,int64 s)
{
char* c;
char *c, *d, *data;
array_cat0(&h->r);
c = array_start(&h->r);
if (byte_diff(c,4,"GET "))
{
if (byte_diff(c,4,"GET ")) {
e400:
httperror(h,"400 Invalid Request","This server only understands GET.");
goto bailout;
}
else
{
char *d, *data;
// expect 'GET /uri?nnbjhg HTTP/1.*'
c+=4;
@ -129,6 +126,10 @@ e400:
data = c;
switch( scan_urlencoded_query( &c, data, SCAN_PATH ) ) {
case 0:
e404:
httperror(h,"404 Not Found","No such file or directory.");
goto bailout;
case 6: /* scrape ? */
if (!byte_diff(c,6,"scrape"))
goto e404;
@ -139,6 +140,7 @@ e400:
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;
@ -146,7 +148,6 @@ e400:
data = c;
switch( scan_urlencoded_query( &c, data, SCAN_SEARCHPATH_PARAM ) ) {
case -1: /* error */
httperror(h,"404 Not Found","No such file or directory.");
goto e404;
case 4:
if(!byte_diff(c,4,"port"))
@ -160,9 +161,20 @@ e400:
else if(!byte_diff(c,7,"compact"))
/* scan flag */ c;
break;
case 9: /* info_hash */
if(!byte_diff(c,9,"info_hash")) c;
/* scan 20 bytes */
case 9: /* info_hash= */
if(!byte_diff(c,9,"info_hash")) {
data = c;
/* ignore this, when we have less than 20 bytes */
switch( scan_urlencoded_query( &c, data, SCAN_SEARCHPATH_VALUE ) )
case -1:
httperror(h,"404 Not Found","No such file or directory.");
goto bailout;
case 20:
hash = (ot_hash*)data;
break;
default:
continue;
}
break;
}
}
@ -170,7 +182,7 @@ e400:
break;
default: /* neither scrape nor announce */
httperror(h,"404 Not Found","No such file or directory.");
goto e404;
goto bailout;
}
c=h->hdrbuf=(char*)malloc(500);
@ -184,8 +196,8 @@ e400:
c+=fmt_str(c,"\r\nConnection: close\r\n\r\n");
iob_addbuf(&h->iob,h->hdrbuf,c - h->hdrbuf);
iob_addbuf(&h->iob,tracker_answer, tracker_answer_size);
}
e404:
bailout:
io_dontwantread(s);
io_wantwrite(s);
}

Loading…
Cancel
Save