summaryrefslogtreecommitdiff
path: root/ot_http.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_http.c')
-rw-r--r--ot_http.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/ot_http.c b/ot_http.c
index 971d81d..de57dad 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -306,13 +306,14 @@ static ot_keywords keywords_announce[] = { { "port", 1 }, { "left", 2 }, { "even
306{ NULL, -3 } }; 306{ NULL, -3 } };
307static ot_keywords keywords_announce_event[] = { { "completed", 1 }, { "stopped", 2 }, { NULL, -3 } }; 307static ot_keywords keywords_announce_event[] = { { "completed", 1 }, { "stopped", 2 }, { NULL, -3 } };
308static ssize_t http_handle_announce( const int64 sock, struct ot_workstruct *ws, char *read_ptr ) { 308static ssize_t http_handle_announce( const int64 sock, struct ot_workstruct *ws, char *read_ptr ) {
309 int numwant, tmp, scanon; 309 int numwant, tmp, scanon;
310 ot_peer peer; 310 ot_peer peer;
311 ot_hash *hash = NULL; 311 ot_hash *hash = NULL;
312 unsigned short port = htons(6881); 312 unsigned short port = htons(6881);
313 char *write_ptr; 313 char *write_ptr;
314 ssize_t len; 314 ssize_t len;
315 315 struct http_data *cookie = io_getcookie( sock );
316
316 /* This is to hack around stupid clients that send "announce ?info_hash" */ 317 /* This is to hack around stupid clients that send "announce ?info_hash" */
317 if( read_ptr[-1] != '?' ) { 318 if( read_ptr[-1] != '?' ) {
318 while( ( *read_ptr != '?' ) && ( *read_ptr != '\n' ) ) ++read_ptr; 319 while( ( *read_ptr != '?' ) && ( *read_ptr != '\n' ) ) ++read_ptr;
@@ -320,7 +321,33 @@ static ssize_t http_handle_announce( const int64 sock, struct ot_workstruct *ws,
320 ++read_ptr; 321 ++read_ptr;
321 } 322 }
322 323
323 OT_SETIP( &peer, ((struct http_data*)io_getcookie( sock ) )->ip ); 324#ifdef WANT_IP_FROM_PROXY
325 if( accesslist_isblessed( cookie->ip, OT_PERMISSION_MAY_PROXY ) ) {
326 ot_ip6 proxied_ip;
327 char *fwd, *fwd_new = ws->request;
328
329 /* Zero terminate for string routines. Normally we'd only overwrite bollocks */
330 ws->request[ws->request_size-1] = 0;
331
332 /* Find last occurence of the forwarded header */
333 do {
334 fwd = fwd_new;
335 fwd_new = strcasestr( fwd_new, "\nX-Forwarded-For:" );
336 } while( fwd_new );
337
338 /* Skip spaces between : and the ip address */
339 if( fwd ) {
340 fwd += 18; /* sizeof( "\nX-Forwarded-For:" ) */
341 while( *fwd == ' ' ) ++fwd;
342 }
343
344 if( fwd && scan_ip6( fwd, proxied_ip ) )
345 OT_SETIP( &peer, proxied_ip );
346 else
347 OT_SETIP( &peer, cookie->ip );
348 }
349#endif
350 OT_SETIP( &peer, cookie->ip );
324 OT_SETPORT( &peer, &port ); 351 OT_SETPORT( &peer, &port );
325 OT_PEERFLAG( &peer ) = 0; 352 OT_PEERFLAG( &peer ) = 0;
326 numwant = 50; 353 numwant = 50;