diff options
Diffstat (limited to 'opentracker.c')
-rw-r--r-- | opentracker.c | 29 |
1 files changed, 18 insertions, 11 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: "); |