|
|
@ -111,7 +111,7 @@ void httpresponse(struct http_data* h,int64 s)
|
|
|
|
ot_torrent torrent;
|
|
|
|
ot_torrent torrent;
|
|
|
|
ot_hash *hash = NULL;
|
|
|
|
ot_hash *hash = NULL;
|
|
|
|
unsigned long numwant;
|
|
|
|
unsigned long numwant;
|
|
|
|
int compact,x;
|
|
|
|
int compact, scanon;
|
|
|
|
size_t reply_size = 0;
|
|
|
|
size_t reply_size = 0;
|
|
|
|
|
|
|
|
|
|
|
|
array_cat0(&h->r);
|
|
|
|
array_cat0(&h->r);
|
|
|
@ -124,9 +124,7 @@ e400:
|
|
|
|
goto bailout;
|
|
|
|
goto bailout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// expect 'GET /uri?nnbjhg HTTP/1.*'
|
|
|
|
|
|
|
|
c+=4;
|
|
|
|
c+=4;
|
|
|
|
|
|
|
|
|
|
|
|
for (d=c; *d!=' '&&*d!='\t'&&*d!='\n'&&*d!='\r'; ++d) ;
|
|
|
|
for (d=c; *d!=' '&&*d!='\t'&&*d!='\n'&&*d!='\r'; ++d) ;
|
|
|
|
|
|
|
|
|
|
|
|
if (*d!=' ') goto e400;
|
|
|
|
if (*d!=' ') goto e400;
|
|
|
@ -134,7 +132,7 @@ e400:
|
|
|
|
if (c[0]!='/') goto e404;
|
|
|
|
if (c[0]!='/') goto e404;
|
|
|
|
while (*c=='/') ++c;
|
|
|
|
while (*c=='/') ++c;
|
|
|
|
|
|
|
|
|
|
|
|
switch( x = scan_urlencoded_query( &c, data = c, SCAN_PATH ) )
|
|
|
|
switch( scan_urlencoded_query( &c, data = c, SCAN_PATH ) )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case 6: /* scrape ? */
|
|
|
|
case 6: /* scrape ? */
|
|
|
|
if (byte_diff(data,6,"scrape"))
|
|
|
|
if (byte_diff(data,6,"scrape"))
|
|
|
@ -147,9 +145,13 @@ e400:
|
|
|
|
peer.port = 6881;
|
|
|
|
peer.port = 6881;
|
|
|
|
numwant = 50;
|
|
|
|
numwant = 50;
|
|
|
|
compact = 1;
|
|
|
|
compact = 1;
|
|
|
|
|
|
|
|
scanon = 1;
|
|
|
|
|
|
|
|
|
|
|
|
while( 1 ) {
|
|
|
|
while( scanon ) {
|
|
|
|
switch( x=scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) {
|
|
|
|
switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) {
|
|
|
|
|
|
|
|
case -2: /* terminator */
|
|
|
|
|
|
|
|
scanon = 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case -1: /* error */
|
|
|
|
case -1: /* error */
|
|
|
|
goto e404;
|
|
|
|
goto e404;
|
|
|
|
case 4:
|
|
|
|
case 4:
|
|
|
@ -157,16 +159,22 @@ e400:
|
|
|
|
/* scan int */ c;
|
|
|
|
/* scan int */ c;
|
|
|
|
else if(!byte_diff(data,4,"left"))
|
|
|
|
else if(!byte_diff(data,4,"left"))
|
|
|
|
/* scan int */ c;
|
|
|
|
/* scan int */ c;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE );
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
case 7:
|
|
|
|
if(!byte_diff(data,7,"numwant"))
|
|
|
|
if(!byte_diff(data,7,"numwant"))
|
|
|
|
/* scan int */ c;
|
|
|
|
/* scan int */ c;
|
|
|
|
else if(!byte_diff(data,7,"compact"))
|
|
|
|
else if(!byte_diff(data,7,"compact"))
|
|
|
|
/* scan flag */ c;
|
|
|
|
/* scan flag */ c;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE );
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
case 9:
|
|
|
|
if(byte_diff(data,9,"info_hash"))
|
|
|
|
if(byte_diff(data,9,"info_hash")) {
|
|
|
|
|
|
|
|
scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE );
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
/* ignore this, when we have less than 20 bytes */
|
|
|
|
/* ignore this, when we have less than 20 bytes */
|
|
|
|
switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) {
|
|
|
|
switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) {
|
|
|
|
case -1:
|
|
|
|
case -1:
|
|
|
@ -178,13 +186,14 @@ e400:
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
printf("blub %i\n",x);
|
|
|
|
scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE );
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Scanned whole query string */
|
|
|
|
/* Scanned whole query string */
|
|
|
|
if( !hash || ( compact == 0 ) ) goto e404;
|
|
|
|
if( !hash || ( compact == 0 ) ) goto e404;
|
|
|
|
|
|
|
|
printf("ALLFINE\n");
|
|
|
|
torrent = add_peer_to_torrent( hash, &peer );
|
|
|
|
torrent = add_peer_to_torrent( hash, &peer );
|
|
|
|
if( !torrent ) {
|
|
|
|
if( !torrent ) {
|
|
|
|
e500:
|
|
|
|
e500:
|
|
|
@ -194,18 +203,16 @@ e500:
|
|
|
|
reply = malloc( numwant*6+10 );
|
|
|
|
reply = malloc( numwant*6+10 );
|
|
|
|
if( reply )
|
|
|
|
if( reply )
|
|
|
|
reply_size = return_peers_for_torrent( torrent, numwant, reply );
|
|
|
|
reply_size = return_peers_for_torrent( torrent, numwant, reply );
|
|
|
|
if( !reply || reply_size < 0 ) {
|
|
|
|
if( !reply || ( reply_size < 0 ) ) {
|
|
|
|
if( reply ) free( reply );
|
|
|
|
if( reply ) free( reply );
|
|
|
|
goto e500;
|
|
|
|
goto e500;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default: /* neither scrape nor announce */
|
|
|
|
default: /* neither scrape nor announce */
|
|
|
|
printf("blub %i\n",x);
|
|
|
|
|
|
|
|
e404:
|
|
|
|
e404:
|
|
|
|
httperror(h,"404 Not Found","No such file or directory.");
|
|
|
|
httperror(h,"404 Not Found","No such file or directory.");
|
|
|
|
goto bailout;
|
|
|
|
goto bailout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
c=h->hdrbuf=(char*)malloc(500);
|
|
|
|
c=h->hdrbuf=(char*)malloc(500);
|
|
|
|
c+=fmt_str(c,"HTTP/1.1 Coming Up\r\nContent-Type: text/plain");
|
|
|
|
c+=fmt_str(c,"HTTP/1.1 Coming Up\r\nContent-Type: text/plain");
|
|
|
|
c+=fmt_str(c,"\r\nContent-Length: ");
|
|
|
|
c+=fmt_str(c,"\r\nContent-Length: ");
|
|
|
|