summaryrefslogtreecommitdiff
path: root/ot_http.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_http.c')
-rw-r--r--ot_http.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/ot_http.c b/ot_http.c
index a87a02e..a789f0d 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -141,13 +141,12 @@ ssize_t http_issue_error(const int64 sock, struct ot_workstruct *ws, int code) {
141 return ws->reply_size = -2; 141 return ws->reply_size = -2;
142} 142}
143 143
144ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec_entries, struct iovec *iovector, int is_partial) { 144ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, size_t iovec_entries, struct iovec *iovector, int is_partial) {
145 struct http_data *cookie = io_getcookie(sock); 145 struct http_data *cookie = io_getcookie(sock);
146 io_batch *current; 146 io_batch *current;
147 char *header; 147 char *header;
148 const char *encoding = ""; 148 const char *encoding = "";
149 int i; 149 size_t i, header_size, size = iovec_length(&iovec_entries, (const struct iovec **)&iovector);
150 size_t header_size, size = iovec_length(&iovec_entries, (const struct iovec **)&iovector);
151 tai6464 t; 150 tai6464 t;
152 151
153 /* No cookie? Bad socket. Leave. */ 152 /* No cookie? Bad socket. Leave. */
@@ -203,7 +202,7 @@ ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec
203 iob_addbuf_free(current, header, header_size); 202 iob_addbuf_free(current, header, header_size);
204 203
205 /* Split huge iovectors into separate io_batches */ 204 /* Split huge iovectors into separate io_batches */
206 for (i = 0; i < iovec_entries; ++i) { 205 for (i = 0; i < (size_t)iovec_entries; ++i) {
207 /* If the current batch's limit is reached, try to reallocate a new batch to work on */ 206 /* If the current batch's limit is reached, try to reallocate a new batch to work on */
208 if (current->bytesleft > OT_BATCH_LIMIT) { 207 if (current->bytesleft > OT_BATCH_LIMIT) {
209 io_batch *new_batch = realloc(cookie->batch, (cookie->batches + 1) * sizeof(io_batch)); 208 io_batch *new_batch = realloc(cookie->batch, (cookie->batches + 1) * sizeof(io_batch));
@@ -426,8 +425,9 @@ static ssize_t http_handle_fullscrape(const int64 sock, struct ot_workstruct *ws
426static ssize_t http_handle_scrape(const int64 sock, struct ot_workstruct *ws, char *read_ptr) { 425static ssize_t http_handle_scrape(const int64 sock, struct ot_workstruct *ws, char *read_ptr) {
427 static const ot_keywords keywords_scrape[] = {{"info_hash", 1}, {NULL, -3}}; 426 static const ot_keywords keywords_scrape[] = {{"info_hash", 1}, {NULL, -3}};
428 427
429 ot_hash *multiscrape_buf = (ot_hash *)ws->request; 428 ot_hash *multiscrape_buf = (ot_hash *)ws->request;
430 int scanon = 1, numwant = 0; 429 int scanon = 1;
430 size_t numwant = 0;
431 431
432 /* This is to hack around stupid clients that send "scrape ?info_hash" */ 432 /* This is to hack around stupid clients that send "scrape ?info_hash" */
433 if (read_ptr[-1] != '?') { 433 if (read_ptr[-1] != '?') {
@@ -502,7 +502,8 @@ static ot_keywords keywords_announce[] = {{"port", 1}, {"left", 2}, {"event",
502 {"peer_id", 9}, {NULL, -3}}; 502 {"peer_id", 9}, {NULL, -3}};
503static ot_keywords keywords_announce_event[] = {{"completed", 1}, {"stopped", 2}, {NULL, -3}}; 503static ot_keywords keywords_announce_event[] = {{"completed", 1}, {"stopped", 2}, {NULL, -3}};
504static ssize_t http_handle_announce(const int64 sock, struct ot_workstruct *ws, char *read_ptr) { 504static ssize_t http_handle_announce(const int64 sock, struct ot_workstruct *ws, char *read_ptr) {
505 int numwant, tmp, scanon; 505 size_t numwant;
506 int tmp, scanon;
506 unsigned short port = 0; 507 unsigned short port = 0;
507 char *write_ptr; 508 char *write_ptr;
508 ssize_t len; 509 ssize_t len;
@@ -578,8 +579,9 @@ static ssize_t http_handle_announce(const int64 sock, struct ot_workstruct *
578 break; 579 break;
579 case 4: /* matched "numwant" */ 580 case 4: /* matched "numwant" */
580 len = scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); 581 len = scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE);
581 if ((len <= 0) || scan_fixed_int(write_ptr, len, &numwant)) 582 if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp))
582 HTTPERROR_400_PARAM; 583 HTTPERROR_400_PARAM;
584 numwant = tmp;
583 if (numwant < 0) 585 if (numwant < 0)
584 numwant = 50; 586 numwant = 50;
585 if (numwant > 200) 587 if (numwant > 200)