diff options
-rw-r--r-- | opentracker.c | 29 | ||||
-rw-r--r-- | scan_urlencoded_query.c | 12 | ||||
-rw-r--r-- | scan_urlencoded_query.h | 13 | ||||
-rw-r--r-- | trackerlogic.c | 3 |
4 files changed, 30 insertions, 27 deletions
diff --git a/opentracker.c b/opentracker.c index ac3fda1..f3a7a29 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -111,7 +111,7 @@ void httpresponse(struct http_data* h,int64 s) | |||
111 | ot_torrent torrent; | 111 | ot_torrent torrent; |
112 | ot_hash *hash = NULL; | 112 | ot_hash *hash = NULL; |
113 | unsigned long numwant; | 113 | unsigned long numwant; |
114 | int compact,x; | 114 | int compact, scanon; |
115 | size_t reply_size = 0; | 115 | size_t reply_size = 0; |
116 | 116 | ||
117 | array_cat0(&h->r); | 117 | array_cat0(&h->r); |
@@ -124,9 +124,7 @@ e400: | |||
124 | goto bailout; | 124 | goto bailout; |
125 | } | 125 | } |
126 | 126 | ||
127 | // expect 'GET /uri?nnbjhg HTTP/1.*' | ||
128 | c+=4; | 127 | c+=4; |
129 | |||
130 | for (d=c; *d!=' '&&*d!='\t'&&*d!='\n'&&*d!='\r'; ++d) ; | 128 | for (d=c; *d!=' '&&*d!='\t'&&*d!='\n'&&*d!='\r'; ++d) ; |
131 | 129 | ||
132 | if (*d!=' ') goto e400; | 130 | if (*d!=' ') goto e400; |
@@ -134,7 +132,7 @@ e400: | |||
134 | if (c[0]!='/') goto e404; | 132 | if (c[0]!='/') goto e404; |
135 | while (*c=='/') ++c; | 133 | while (*c=='/') ++c; |
136 | 134 | ||
137 | switch( x = scan_urlencoded_query( &c, data = c, SCAN_PATH ) ) | 135 | switch( scan_urlencoded_query( &c, data = c, SCAN_PATH ) ) |
138 | { | 136 | { |
139 | case 6: /* scrape ? */ | 137 | case 6: /* scrape ? */ |
140 | if (byte_diff(data,6,"scrape")) | 138 | if (byte_diff(data,6,"scrape")) |
@@ -147,9 +145,13 @@ e400: | |||
147 | peer.port = 6881; | 145 | peer.port = 6881; |
148 | numwant = 50; | 146 | numwant = 50; |
149 | compact = 1; | 147 | compact = 1; |
148 | scanon = 1; | ||
150 | 149 | ||
151 | while( 1 ) { | 150 | while( scanon ) { |
152 | switch( x=scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) { | 151 | switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) { |
152 | case -2: /* terminator */ | ||
153 | scanon = 0; | ||
154 | break; | ||
153 | case -1: /* error */ | 155 | case -1: /* error */ |
154 | goto e404; | 156 | goto e404; |
155 | case 4: | 157 | case 4: |
@@ -157,16 +159,22 @@ e400: | |||
157 | /* scan int */ c; | 159 | /* scan int */ c; |
158 | else if(!byte_diff(data,4,"left")) | 160 | else if(!byte_diff(data,4,"left")) |
159 | /* scan int */ c; | 161 | /* scan int */ c; |
162 | else | ||
163 | scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE ); | ||
160 | break; | 164 | break; |
161 | case 7: | 165 | case 7: |
162 | if(!byte_diff(data,7,"numwant")) | 166 | if(!byte_diff(data,7,"numwant")) |
163 | /* scan int */ c; | 167 | /* scan int */ c; |
164 | else if(!byte_diff(data,7,"compact")) | 168 | else if(!byte_diff(data,7,"compact")) |
165 | /* scan flag */ c; | 169 | /* scan flag */ c; |
170 | else | ||
171 | scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE ); | ||
166 | break; | 172 | break; |
167 | case 9: | 173 | case 9: |
168 | if(byte_diff(data,9,"info_hash")) | 174 | if(byte_diff(data,9,"info_hash")) { |
175 | scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE ); | ||
169 | continue; | 176 | continue; |
177 | } | ||
170 | /* ignore this, when we have less than 20 bytes */ | 178 | /* ignore this, when we have less than 20 bytes */ |
171 | switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) { | 179 | switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) { |
172 | case -1: | 180 | case -1: |
@@ -178,13 +186,14 @@ e400: | |||
178 | continue; | 186 | continue; |
179 | } | 187 | } |
180 | default: | 188 | default: |
181 | printf("blub %i\n",x); | 189 | scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE ); |
182 | break; | 190 | break; |
183 | } | 191 | } |
184 | } | 192 | } |
185 | 193 | ||
186 | /* Scanned whole query string */ | 194 | /* Scanned whole query string */ |
187 | if( !hash || ( compact == 0 ) ) goto e404; | 195 | if( !hash || ( compact == 0 ) ) goto e404; |
196 | printf("ALLFINE\n"); | ||
188 | torrent = add_peer_to_torrent( hash, &peer ); | 197 | torrent = add_peer_to_torrent( hash, &peer ); |
189 | if( !torrent ) { | 198 | if( !torrent ) { |
190 | e500: | 199 | e500: |
@@ -194,18 +203,16 @@ e500: | |||
194 | reply = malloc( numwant*6+10 ); | 203 | reply = malloc( numwant*6+10 ); |
195 | if( reply ) | 204 | if( reply ) |
196 | reply_size = return_peers_for_torrent( torrent, numwant, reply ); | 205 | reply_size = return_peers_for_torrent( torrent, numwant, reply ); |
197 | if( !reply || reply_size < 0 ) { | 206 | if( !reply || ( reply_size < 0 ) ) { |
198 | if( reply ) free( reply ); | 207 | if( reply ) free( reply ); |
199 | goto e500; | 208 | goto e500; |
200 | } | 209 | } |
201 | break; | 210 | break; |
202 | default: /* neither scrape nor announce */ | 211 | default: /* neither scrape nor announce */ |
203 | printf("blub %i\n",x); | ||
204 | e404: | 212 | e404: |
205 | httperror(h,"404 Not Found","No such file or directory."); | 213 | httperror(h,"404 Not Found","No such file or directory."); |
206 | goto bailout; | 214 | goto bailout; |
207 | } | 215 | } |
208 | |||
209 | c=h->hdrbuf=(char*)malloc(500); | 216 | c=h->hdrbuf=(char*)malloc(500); |
210 | c+=fmt_str(c,"HTTP/1.1 Coming Up\r\nContent-Type: text/plain"); | 217 | c+=fmt_str(c,"HTTP/1.1 Coming Up\r\nContent-Type: text/plain"); |
211 | c+=fmt_str(c,"\r\nContent-Length: "); | 218 | c+=fmt_str(c,"\r\nContent-Length: "); |
diff --git a/scan_urlencoded_query.c b/scan_urlencoded_query.c index 6ba7808..3ac01cd 100644 --- a/scan_urlencoded_query.c +++ b/scan_urlencoded_query.c | |||
@@ -24,21 +24,23 @@ size_t scan_urlencoded_query(char **string, char *deststring, int flags) { | |||
24 | if( ( b = scan_fromhex(*s++) ) == 0xff ) return -1; | 24 | if( ( b = scan_fromhex(*s++) ) == 0xff ) return -1; |
25 | c=(c<<4)|b; | 25 | c=(c<<4)|b; |
26 | } | 26 | } |
27 | *d++ = c; | 27 | if(d) *d++ = c; |
28 | } | 28 | } |
29 | 29 | ||
30 | switch( c ) { | 30 | switch( c ) { |
31 | case 0: case '\r': case '\n': case ' ': | 31 | case 0: case '\r': case '\n': case ' ': |
32 | if ( ( flags & BREAK_AT_WHITESPACE ) == 0 ) return -1; | 32 | if( d == (unsigned char*)deststring ) return -2; |
33 | --s; | ||
33 | break; | 34 | break; |
34 | case '?': | 35 | case '?': |
35 | if ( ( flags & BREAK_AT_QUESTIONMARK ) == 0 ) return -1; | 36 | if( flags != SCAN_PATH ) return -1; |
36 | break; | 37 | break; |
37 | case '=': | 38 | case '=': |
38 | if ( ( flags & BREAK_AT_EQUALSIGN ) == 0 ) return -1; | 39 | if( flags != SCAN_SEARCHPATH_PARAM ) return -1; |
39 | break; | 40 | break; |
40 | case '&': | 41 | case '&': |
41 | if ( ( flags & BREAK_AT_AMPERSAND ) == 0 ) return -1; | 42 | if( flags == SCAN_PATH ) return -1; |
43 | if( flags == SCAN_SEARCHPATH_PARAM ) --s; | ||
42 | break; | 44 | break; |
43 | default: | 45 | default: |
44 | return -1; | 46 | return -1; |
diff --git a/scan_urlencoded_query.h b/scan_urlencoded_query.h index 03ed730..1e59745 100644 --- a/scan_urlencoded_query.h +++ b/scan_urlencoded_query.h | |||
@@ -1,14 +1,9 @@ | |||
1 | #ifndef __SCAN_URLENCODED_QUERY_H__ | 1 | #ifndef __SCAN_URLENCODED_QUERY_H__ |
2 | #define __SCAN_URLENCODED_QUERY_H__ | 2 | #define __SCAN_URLENCODED_QUERY_H__ |
3 | 3 | ||
4 | #define BREAK_AT_QUESTIONMARK (1<<0) | 4 | #define SCAN_PATH 0 |
5 | #define BREAK_AT_WHITESPACE (1<<1) | 5 | #define SCAN_SEARCHPATH_PARAM 1 |
6 | #define BREAK_AT_AMPERSAND (1<<2) | 6 | #define SCAN_SEARCHPATH_VALUE 2 |
7 | #define BREAK_AT_EQUALSIGN (1<<3) | ||
8 | |||
9 | #define SCAN_PATH ( BREAK_AT_QUESTIONMARK | BREAK_AT_WHITESPACE ) | ||
10 | #define SCAN_SEARCHPATH_PARAM ( BREAK_AT_EQUALSIGN ) | ||
11 | #define SCAN_SEARCHPATH_VALUE ( BREAK_AT_AMPERSAND | BREAK_AT_WHITESPACE ) | ||
12 | 7 | ||
13 | // string pointer to source, pointer to after terminator on return | 8 | // string pointer to source, pointer to after terminator on return |
14 | // deststring pointer to destination | 9 | // deststring pointer to destination |
diff --git a/trackerlogic.c b/trackerlogic.c index 1407522..03e7bd8 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
@@ -227,6 +227,7 @@ void *map_file( char *file_name ) { | |||
227 | char *map; | 227 | char *map; |
228 | if( file_name ) { | 228 | if( file_name ) { |
229 | int file_desc=open(file_name,O_RDWR|O_CREAT|O_NDELAY,0644); | 229 | int file_desc=open(file_name,O_RDWR|O_CREAT|O_NDELAY,0644); |
230 | printf( "%s\n", file_name ); | ||
230 | if( file_desc < 0) return 0; | 231 | if( file_desc < 0) return 0; |
231 | lseek( file_desc, OT_HUGE_FILESIZE, SEEK_SET ); | 232 | lseek( file_desc, OT_HUGE_FILESIZE, SEEK_SET ); |
232 | write( file_desc, "_", 1 ); | 233 | write( file_desc, "_", 1 ); |
@@ -263,8 +264,6 @@ int init_logic( char *directory ) { | |||
263 | torrents_list = map_file( NULL ); | 264 | torrents_list = map_file( NULL ); |
264 | torrents_count = 0; | 265 | torrents_count = 0; |
265 | 266 | ||
266 | printf( "%08x %08x\n", scratch_space, torrents_list ); | ||
267 | |||
268 | if( !scratch_space || !torrents_list ) { | 267 | if( !scratch_space || !torrents_list ) { |
269 | if( scratch_space || torrents_list ) | 268 | if( scratch_space || torrents_list ) |
270 | unmap_file( NULL, scratch_space ? (void*)scratch_space : (void*)torrents_list, 0 ); | 269 | unmap_file( NULL, scratch_space ? (void*)scratch_space : (void*)torrents_list, 0 ); |