summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordenis <>2006-12-08 22:37:44 +0000
committerdenis <>2006-12-08 22:37:44 +0000
commitdc025776dd77e2f8da1e2ee0667962115bf90bc8 (patch)
treeda7d6791a24e9d3a101a5d9a59213dc3b7080df0
parent62a9b0253280d5ef9636bcee5e26c3a288d0a9ec (diff)
Begun printf debugging
-rw-r--r--Makefile4
-rw-r--r--opentracker.c41
2 files changed, 29 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index b61849c..2aaf91d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
1CC?=gcc 1CC?=gcc
2CFLAGS+=-I../libowfat -Wall -O2 -pipe 2CFLAGS+=-I../libowfat -Wall -pipe -g -ggdb
3LDFLAGS+=-L../libowfat/ -lowfat -s 3LDFLAGS+=-L../libowfat/ -lowfat
4 4
5SOURCES=opentracker.c trackerlogic.c scan_urlencoded_query.c 5SOURCES=opentracker.c trackerlogic.c scan_urlencoded_query.c
6 6
diff --git a/opentracker.c b/opentracker.c
index d46858d..10b7d87 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -13,6 +13,8 @@
13#include <unistd.h> 13#include <unistd.h>
14#include <stdlib.h> 14#include <stdlib.h>
15#include <errno.h> 15#include <errno.h>
16#include <signal.h>
17#include <stdio.h>
16 18
17#include "trackerlogic.h" 19#include "trackerlogic.h"
18#include "scan_urlencoded_query.h" 20#include "scan_urlencoded_query.h"
@@ -109,7 +111,7 @@ void httpresponse(struct http_data* h,int64 s)
109 ot_torrent torrent; 111 ot_torrent torrent;
110 ot_hash *hash = NULL; 112 ot_hash *hash = NULL;
111 unsigned long numwant; 113 unsigned long numwant;
112 int compact; 114 int compact,x;
113 size_t reply_size = 0; 115 size_t reply_size = 0;
114 116
115 array_cat0(&h->r); 117 array_cat0(&h->r);
@@ -130,40 +132,40 @@ e400:
130 if (*d!=' ') goto e400; 132 if (*d!=' ') goto e400;
131 *d=0; 133 *d=0;
132 if (c[0]!='/') goto e404; 134 if (c[0]!='/') goto e404;
133 while (c[1]=='/') ++c; 135 while (*c=='/') ++c;
134 136
135 switch( scan_urlencoded_query( &c, data = c, SCAN_PATH ) ) { 137 switch( x = scan_urlencoded_query( &c, data = c, SCAN_PATH ) )
138 {
136 case 6: /* scrape ? */ 139 case 6: /* scrape ? */
137 if (!byte_diff(c,6,"scrape")) 140 if (byte_diff(data,6,"scrape"))
138 goto e404; 141 goto e404;
139 break; 142 break;
140 case 8: 143 case 8:
141 if( !byte_diff(c,8,"announce")) 144 if( byte_diff(data,8,"announce"))
142 goto e404; 145 goto e404;
143
144 byte_copy( peer.ip, 4, h->ip ); 146 byte_copy( peer.ip, 4, h->ip );
145 peer.port = 6881; 147 peer.port = 6881;
146 numwant = 50; 148 numwant = 50;
147 compact = 1; 149 compact = 1;
148 150
149 while( 1 ) { 151 while( 1 ) {
150 switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) { 152 switch( x=scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) {
151 case -1: /* error */ 153 case -1: /* error */
152 goto e404; 154 goto e404;
153 case 4: 155 case 4:
154 if(!byte_diff(c,4,"port")) 156 if(!byte_diff(data,4,"port"))
155 /* scan int */ c; 157 /* scan int */ c;
156 else if(!byte_diff(c,4,"left")) 158 else if(!byte_diff(data,4,"left"))
157 /* scan int */ c; 159 /* scan int */ c;
158 break; 160 break;
159 case 7: 161 case 7:
160 if(!byte_diff(c,7,"numwant")) 162 if(!byte_diff(data,7,"numwant"))
161 /* scan int */ c; 163 /* scan int */ c;
162 else if(!byte_diff(c,7,"compact")) 164 else if(!byte_diff(data,7,"compact"))
163 /* scan flag */ c; 165 /* scan flag */ c;
164 break; 166 break;
165 case 9: 167 case 9:
166 if(byte_diff(c,9,"info_hash")) 168 if(byte_diff(data,9,"info_hash"))
167 continue; 169 continue;
168 /* ignore this, when we have less than 20 bytes */ 170 /* ignore this, when we have less than 20 bytes */
169 switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) { 171 switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) {
@@ -171,11 +173,13 @@ e400:
171 goto e404; 173 goto e404;
172 case 20: 174 case 20:
173 hash = (ot_hash*)data; /* Fall through intended */ 175 hash = (ot_hash*)data; /* Fall through intended */
176 printf("hash: %s\n",*hash);
174 default: 177 default:
175 continue; 178 continue;
176 } 179 }
177 default: 180 default:
178 continue; 181 printf("blub %i\n",x);
182 break;
179 } 183 }
180 } 184 }
181 185
@@ -196,6 +200,7 @@ e500:
196 } 200 }
197 break; 201 break;
198 default: /* neither scrape nor announce */ 202 default: /* neither scrape nor announce */
203 printf("blub %i\n",x);
199e404: 204e404:
200 httperror(h,"404 Not Found","No such file or directory."); 205 httperror(h,"404 Not Found","No such file or directory.");
201 goto bailout; 206 goto bailout;
@@ -218,6 +223,11 @@ bailout:
218 io_wantwrite(s); 223 io_wantwrite(s);
219} 224}
220 225
226void graceful( int s ) {
227 signal( SIGINT, SIG_IGN );
228 deinit_logic();
229}
230
221int main() 231int main()
222{ 232{
223 int s=socket_tcp6(); 233 int s=socket_tcp6();
@@ -225,7 +235,7 @@ int main()
225 char ip[16]; 235 char ip[16];
226 uint16 port; 236 uint16 port;
227 237
228 if (socket_bind6_reuse(s,V6any,8000,0)==-1) 238 if (socket_bind6_reuse(s,V6any,6969,0)==-1)
229 panic("socket_bind6_reuse"); 239 panic("socket_bind6_reuse");
230 240
231 if (socket_listen(s,16)==-1) 241 if (socket_listen(s,16)==-1)
@@ -234,6 +244,9 @@ int main()
234 if (!io_fd(s)) 244 if (!io_fd(s))
235 panic("io_fd"); 245 panic("io_fd");
236 246
247 signal( SIGINT, graceful );
248 init_logic( "." );
249
237 io_wantread(s); 250 io_wantread(s);
238 251
239 for (;;) 252 for (;;)