summaryrefslogtreecommitdiff
path: root/ot_http.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_http.c')
-rw-r--r--ot_http.c62
1 files changed, 2 insertions, 60 deletions
diff --git a/ot_http.c b/ot_http.c
index e0062ce..d8ab0a2 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -5,7 +5,6 @@
5 5
6/* System */ 6/* System */
7#include <sys/types.h> 7#include <sys/types.h>
8#include <sys/uio.h>
9#include <arpa/inet.h> 8#include <arpa/inet.h>
10#include <stdlib.h> 9#include <stdlib.h>
11#include <stdio.h> 10#include <stdio.h>
@@ -26,7 +25,6 @@
26#include "ot_fullscrape.h" 25#include "ot_fullscrape.h"
27#include "ot_stats.h" 26#include "ot_stats.h"
28#include "ot_accesslist.h" 27#include "ot_accesslist.h"
29#include "ot_sync.h"
30 28
31#define OT_MAXMULTISCRAPE_COUNT 64 29#define OT_MAXMULTISCRAPE_COUNT 64
32static ot_hash multiscrape_buf[OT_MAXMULTISCRAPE_COUNT]; 30static ot_hash multiscrape_buf[OT_MAXMULTISCRAPE_COUNT];
@@ -165,52 +163,6 @@ ssize_t http_sendiovecdata( const int64 client_socket, int iovec_entries, struct
165 return 0; 163 return 0;
166} 164}
167 165
168#ifdef WANT_SYNC_BATCH
169static ssize_t http_handle_sync( const int64 client_socket, char *data ) {
170 struct http_data* h = io_getcookie( client_socket );
171 size_t len;
172 int mode = SYNC_OUT, scanon = 1;
173 char *c = data;
174
175 if( !accesslist_isblessed( h->ip, OT_PERMISSION_MAY_SYNC ) )
176 HTTPERROR_403_IP;
177
178 while( scanon ) {
179 switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) {
180 case -2: scanon = 0; break; /* TERMINATOR */
181 case -1: HTTPERROR_400_PARAM; /* PARSE ERROR */
182 default: scan_urlencoded_skipvalue( &c ); break;
183 case 9:
184 if(byte_diff(data,9,"changeset")) {
185 scan_urlencoded_skipvalue( &c );
186 continue;
187 }
188 /* ignore this, when we dont at least see "d4:syncdee" */
189 if( ( len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) < 10 ) HTTPERROR_400_PARAM;
190 if( add_changeset_to_tracker( (uint8_t*)data, len ) ) HTTPERROR_400_PARAM;
191 if( mode == SYNC_OUT ) {
192 stats_issue_event( EVENT_SYNC_IN, FLAG_TCP, 0 );
193 mode = SYNC_IN;
194 }
195 break;
196 }
197 }
198
199 if( mode == SYNC_OUT ) {
200 /* Pass this task to the worker thread */
201 h->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK;
202 stats_issue_event( EVENT_SYNC_OUT_REQUEST, FLAG_TCP, 0 );
203 sync_deliver( client_socket );
204 io_dontwantread( client_socket );
205 return -2;
206 }
207
208 /* Simple but proof for now */
209 memmove( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, "OK", 2);
210 return 2;
211}
212#endif
213
214static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d, size_t l ) { 166static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d, size_t l ) {
215 char *c = data; 167 char *c = data;
216 int mode = TASK_STATS_PEERS, scanon = 1, format = 0; 168 int mode = TASK_STATS_PEERS, scanon = 1, format = 0;
@@ -245,10 +197,6 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d
245 mode = TASK_STATS_UDP; 197 mode = TASK_STATS_UDP;
246 else if( !byte_diff(data,4,"busy")) 198 else if( !byte_diff(data,4,"busy"))
247 mode = TASK_STATS_BUSY_NETWORKS; 199 mode = TASK_STATS_BUSY_NETWORKS;
248 else if( !byte_diff(data,4,"dmem"))
249 mode = TASK_STATS_MEMORY;
250 else if( !byte_diff(data,4,"vdeb"))
251 mode = TASK_STATS_VECTOR_DEBUG;
252 else if( !byte_diff(data,4,"torr")) 200 else if( !byte_diff(data,4,"torr"))
253 mode = TASK_STATS_TORRENTS; 201 mode = TASK_STATS_TORRENTS;
254 else if( !byte_diff(data,4,"fscr")) 202 else if( !byte_diff(data,4,"fscr"))
@@ -265,7 +213,7 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d
265 case 5: 213 case 5:
266 if( !byte_diff(data,5,"top10")) 214 if( !byte_diff(data,5,"top10"))
267 mode = TASK_STATS_TOP10; 215 mode = TASK_STATS_TOP10;
268 if( !byte_diff(data,5,"renew")) 216 else if( !byte_diff(data,5,"renew"))
269 mode = TASK_STATS_RENEW; 217 mode = TASK_STATS_RENEW;
270 else 218 else
271 HTTPERROR_400_PARAM; 219 HTTPERROR_400_PARAM;
@@ -524,7 +472,7 @@ static ssize_t http_handle_announce( const int64 client_socket, char *data ) {
524 len = remove_peer_from_torrent( hash, &peer, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, FLAG_TCP ); 472 len = remove_peer_from_torrent( hash, &peer, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, FLAG_TCP );
525 else { 473 else {
526 torrent = add_peer_to_torrent( hash, &peer WANT_SYNC_PARAM( 0 ) ); 474 torrent = add_peer_to_torrent( hash, &peer WANT_SYNC_PARAM( 0 ) );
527 if( !torrent || !( len = return_peers_for_torrent( hash, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, FLAG_TCP ) ) ) HTTPERROR_500; 475 if( !torrent || !( len = return_peers_for_torrent( torrent, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, FLAG_TCP ) ) ) HTTPERROR_500;
528 } 476 }
529 stats_issue_event( EVENT_ANNOUNCE, FLAG_TCP, len); 477 stats_issue_event( EVENT_ANNOUNCE, FLAG_TCP, len);
530 return len; 478 return len;
@@ -573,12 +521,6 @@ ssize_t http_handle_request( const int64 client_socket, char *data, size_t recv_
573 reply_size = http_handle_scrape( client_socket, c ); 521 reply_size = http_handle_scrape( client_socket, c );
574 /* All the rest is matched the standard way */ 522 /* All the rest is matched the standard way */
575 else switch( len ) { 523 else switch( len ) {
576#ifdef WANT_SYNC_BATCH
577 case 4: /* sync ? */
578 if( byte_diff( data, 4, "sync") ) HTTPERROR_404;
579 reply_size = http_handle_sync( client_socket, c );
580 break;
581#endif
582 case 5: /* stats ? */ 524 case 5: /* stats ? */
583 if( byte_diff( data, 5, "stats") ) HTTPERROR_404; 525 if( byte_diff( data, 5, "stats") ) HTTPERROR_404;
584 reply_size = http_handle_stats( client_socket, c, recv_header, recv_length ); 526 reply_size = http_handle_stats( client_socket, c, recv_header, recv_length );