ot_torrent torrent;
ot_hash *hash = NULL;
unsigned long numwant;
- int compact,x;
+ int compact, scanon;
size_t reply_size = 0;
array_cat0(&h->r);
goto bailout;
}
- // expect 'GET /uri?nnbjhg HTTP/1.*'
c+=4;
-
for (d=c; *d!=' '&&*d!='\t'&&*d!='\n'&&*d!='\r'; ++d) ;
if (*d!=' ') goto e400;
if (c[0]!='/') goto e404;
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 ? */
if (byte_diff(data,6,"scrape"))
peer.port = 6881;
numwant = 50;
compact = 1;
+ scanon = 1;
- while( 1 ) {
- switch( x=scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) {
+ while( scanon ) {
+ switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) {
+ case -2: /* terminator */
+ scanon = 0;
+ break;
case -1: /* error */
goto e404;
case 4:
/* scan int */ c;
else if(!byte_diff(data,4,"left"))
/* scan int */ c;
+ else
+ scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE );
break;
case 7:
if(!byte_diff(data,7,"numwant"))
/* scan int */ c;
else if(!byte_diff(data,7,"compact"))
/* scan flag */ c;
+ else
+ scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE );
break;
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;
+ }
/* ignore this, when we have less than 20 bytes */
switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) {
case -1:
continue;
}
default:
- printf("blub %i\n",x);
+ scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE );
break;
}
}
/* Scanned whole query string */
if( !hash || ( compact == 0 ) ) goto e404;
+ printf("ALLFINE\n");
torrent = add_peer_to_torrent( hash, &peer );
if( !torrent ) {
e500:
reply = malloc( numwant*6+10 );
if( reply )
reply_size = return_peers_for_torrent( torrent, numwant, reply );
- if( !reply || reply_size < 0 ) {
+ if( !reply || ( reply_size < 0 ) ) {
if( reply ) free( reply );
goto e500;
}
break;
default: /* neither scrape nor announce */
- printf("blub %i\n",x);
e404:
httperror(h,"404 Not Found","No such file or directory.");
goto bailout;
}
-
c=h->hdrbuf=(char*)malloc(500);
c+=fmt_str(c,"HTTP/1.1 Coming Up\r\nContent-Type: text/plain");
c+=fmt_str(c,"\r\nContent-Length: ");
if( ( b = scan_fromhex(*s++) ) == 0xff ) return -1;
c=(c<<4)|b;
}
- *d++ = c;
+ if(d) *d++ = c;
}
switch( c ) {
case 0: case '\r': case '\n': case ' ':
- if ( ( flags & BREAK_AT_WHITESPACE ) == 0 ) return -1;
+ if( d == (unsigned char*)deststring ) return -2;
+ --s;
break;
case '?':
- if ( ( flags & BREAK_AT_QUESTIONMARK ) == 0 ) return -1;
+ if( flags != SCAN_PATH ) return -1;
break;
case '=':
- if ( ( flags & BREAK_AT_EQUALSIGN ) == 0 ) return -1;
+ if( flags != SCAN_SEARCHPATH_PARAM ) return -1;
break;
case '&':
- if ( ( flags & BREAK_AT_AMPERSAND ) == 0 ) return -1;
+ if( flags == SCAN_PATH ) return -1;
+ if( flags == SCAN_SEARCHPATH_PARAM ) --s;
break;
default:
return -1;
-#ifndef __SCAN_URLENCODED_QUERY_H__
+#ifndef __SCAN_URLENCODED_QUERY_H__
#define __SCAN_URLENCODED_QUERY_H__
-#define BREAK_AT_QUESTIONMARK (1<<0)
-#define BREAK_AT_WHITESPACE (1<<1)
-#define BREAK_AT_AMPERSAND (1<<2)
-#define BREAK_AT_EQUALSIGN (1<<3)
-
-#define SCAN_PATH ( BREAK_AT_QUESTIONMARK | BREAK_AT_WHITESPACE )
-#define SCAN_SEARCHPATH_PARAM ( BREAK_AT_EQUALSIGN )
-#define SCAN_SEARCHPATH_VALUE ( BREAK_AT_AMPERSAND | BREAK_AT_WHITESPACE )
+#define SCAN_PATH 0
+#define SCAN_SEARCHPATH_PARAM 1
+#define SCAN_SEARCHPATH_VALUE 2
// string pointer to source, pointer to after terminator on return
// deststring pointer to destination
char *map;
if( file_name ) {
int file_desc=open(file_name,O_RDWR|O_CREAT|O_NDELAY,0644);
+printf( "%s\n", file_name );
if( file_desc < 0) return 0;
lseek( file_desc, OT_HUGE_FILESIZE, SEEK_SET );
write( file_desc, "_", 1 );
torrents_list = map_file( NULL );
torrents_count = 0;
- printf( "%08x %08x\n", scratch_space, torrents_list );
-
if( !scratch_space || !torrents_list ) {
if( scratch_space || torrents_list )
unmap_file( NULL, scratch_space ? (void*)scratch_space : (void*)torrents_list, 0 );