#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
#include "trackerlogic.h"
#include "scan_urlencoded_query.h"
ot_torrent torrent;
ot_hash *hash = NULL;
unsigned long numwant;
- int compact;
+ int compact,x;
size_t reply_size = 0;
array_cat0(&h->r);
if (*d!=' ') goto e400;
*d=0;
if (c[0]!='/') goto e404;
- while (c[1]=='/') ++c;
+ while (*c=='/') ++c;
- switch( scan_urlencoded_query( &c, data = c, SCAN_PATH ) ) {
+ switch( x = scan_urlencoded_query( &c, data = c, SCAN_PATH ) )
+ {
case 6: /* scrape ? */
- if (!byte_diff(c,6,"scrape"))
+ if (byte_diff(data,6,"scrape"))
goto e404;
break;
case 8:
- if( !byte_diff(c,8,"announce"))
+ if( byte_diff(data,8,"announce"))
goto e404;
-
byte_copy( peer.ip, 4, h->ip );
peer.port = 6881;
numwant = 50;
compact = 1;
while( 1 ) {
- switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) {
+ switch( x=scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) {
case -1: /* error */
goto e404;
case 4:
- if(!byte_diff(c,4,"port"))
+ if(!byte_diff(data,4,"port"))
/* scan int */ c;
- else if(!byte_diff(c,4,"left"))
+ else if(!byte_diff(data,4,"left"))
/* scan int */ c;
break;
case 7:
- if(!byte_diff(c,7,"numwant"))
+ if(!byte_diff(data,7,"numwant"))
/* scan int */ c;
- else if(!byte_diff(c,7,"compact"))
+ else if(!byte_diff(data,7,"compact"))
/* scan flag */ c;
break;
case 9:
- if(byte_diff(c,9,"info_hash"))
+ if(byte_diff(data,9,"info_hash"))
continue;
/* ignore this, when we have less than 20 bytes */
switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) {
goto e404;
case 20:
hash = (ot_hash*)data; /* Fall through intended */
+ printf("hash: %s\n",*hash);
default:
continue;
}
default:
- continue;
+ printf("blub %i\n",x);
+ break;
}
}
}
break;
default: /* neither scrape nor announce */
+ printf("blub %i\n",x);
e404:
httperror(h,"404 Not Found","No such file or directory.");
goto bailout;
io_wantwrite(s);
}
+void graceful( int s ) {
+ signal( SIGINT, SIG_IGN );
+ deinit_logic();
+}
+
int main()
{
int s=socket_tcp6();
char ip[16];
uint16 port;
- if (socket_bind6_reuse(s,V6any,8000,0)==-1)
+ if (socket_bind6_reuse(s,V6any,6969,0)==-1)
panic("socket_bind6_reuse");
if (socket_listen(s,16)==-1)
if (!io_fd(s))
panic("io_fd");
+ signal( SIGINT, graceful );
+ init_logic( "." );
+
io_wantread(s);
for (;;)