summaryrefslogtreecommitdiff
path: root/src/ot_http.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ot_http.c')
-rw-r--r--src/ot_http.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/ot_http.c b/src/ot_http.c
index 29f41a3..fc49333 100644
--- a/src/ot_http.c
+++ b/src/ot_http.c
@@ -313,7 +313,7 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c
313#endif 313#endif
314 314
315 while (scanon) { 315 while (scanon) {
316 switch (urlencoded_match_keyword(keywords_main, &read_ptr, SCAN_SEARCHPATH_PARAM)) { 316 switch (urlencoded_match_keyword(keywords_main, &read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_PARAM)) {
317 case -2: 317 case -2:
318 scanon = 0; 318 scanon = 0;
319 break; /* TERMINATOR */ 319 break; /* TERMINATOR */
@@ -323,11 +323,11 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c
323 urlencoded_skip_value(&read_ptr); 323 urlencoded_skip_value(&read_ptr);
324 break; 324 break;
325 case 1: /* matched "mode" */ 325 case 1: /* matched "mode" */
326 if ((mode = urlencoded_match_keyword(keywords_mode, &read_ptr, SCAN_SEARCHPATH_VALUE)) <= 0) 326 if ((mode = urlencoded_match_keyword(keywords_mode, &read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_VALUE)) <= 0)
327 HTTPERROR_400_PARAM; 327 HTTPERROR_400_PARAM;
328 break; 328 break;
329 case 2: /* matched "format" */ 329 case 2: /* matched "format" */
330 if ((format = urlencoded_match_keyword(keywords_format, &read_ptr, SCAN_SEARCHPATH_VALUE)) <= 0) 330 if ((format = urlencoded_match_keyword(keywords_format, &read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_VALUE)) <= 0)
331 HTTPERROR_400_PARAM; 331 HTTPERROR_400_PARAM;
332 break; 332 break;
333 case 3: 333 case 3:
@@ -505,7 +505,7 @@ static ssize_t http_handle_scrape(const int64_t sock, struct ot_workstruct *ws,
505 } 505 }
506 506
507 while (scanon) { 507 while (scanon) {
508 switch (urlencoded_match_keyword(keywords_scrape, &read_ptr, SCAN_SEARCHPATH_PARAM)) { 508 switch (urlencoded_match_keyword(keywords_scrape, &read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_PARAM)) {
509 case -2: 509 case -2:
510 scanon = 0; 510 scanon = 0;
511 break; /* TERMINATOR */ 511 break; /* TERMINATOR */
@@ -515,10 +515,12 @@ static ssize_t http_handle_scrape(const int64_t sock, struct ot_workstruct *ws,
515 urlencoded_skip_value(&read_ptr); 515 urlencoded_skip_value(&read_ptr);
516 break; 516 break;
517 case 1: /* matched "info_hash" */ 517 case 1: /* matched "info_hash" */
518 {
518 /* ignore this, when we have less than 20 bytes */ 519 /* ignore this, when we have less than 20 bytes */
519 if (urlencoded_parse(&read_ptr, (char *)(multiscrape_buf + numwant++), SCAN_SEARCHPATH_VALUE) != (ssize_t)sizeof(ot_hash)) 520 ot_hash *slot = multiscrape_buf + numwant++;
521 if (urlencoded_parse(&read_ptr, (char *)slot, (char *)(slot + 1), SCAN_SEARCHPATH_VALUE) != (ssize_t)sizeof(ot_hash))
520 HTTPERROR_400_PARAM; 522 HTTPERROR_400_PARAM;
521 break; 523 } break;
522 } 524 }
523 } 525 }
524 526
@@ -622,7 +624,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
622 scanon = 1; 624 scanon = 1;
623 625
624 while (scanon) { 626 while (scanon) {
625 switch (urlencoded_match_keyword(keywords_announce, &read_ptr, SCAN_SEARCHPATH_PARAM)) { 627 switch (urlencoded_match_keyword(keywords_announce, &read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_PARAM)) {
626 case -2: 628 case -2:
627 scanon = 0; 629 scanon = 0;
628 break; /* TERMINATOR */ 630 break; /* TERMINATOR */
@@ -632,14 +634,14 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
632 urlencoded_skip_value(&read_ptr); 634 urlencoded_skip_value(&read_ptr);
633 break; 635 break;
634 case 1: /* matched "port" */ 636 case 1: /* matched "port" */
635 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); 637 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_VALUE);
636 if ((len <= 0) || scan_int(write_ptr, len, &tmp) || (tmp > 0xffff)) 638 if ((len <= 0) || scan_int(write_ptr, len, &tmp) || (tmp > 0xffff))
637 HTTPERROR_400_PARAM; 639 HTTPERROR_400_PARAM;
638 port = htons((uint16_t)tmp); 640 port = htons((uint16_t)tmp);
639 OT_SETPORT(&ws->peer, &port); 641 OT_SETPORT(&ws->peer, &port);
640 break; 642 break;
641 case 2: /* matched "left" */ 643 case 2: /* matched "left" */
642 if ((len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE)) <= 0) 644 if ((len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_VALUE)) <= 0)
643 HTTPERROR_400_PARAM; 645 HTTPERROR_400_PARAM;
644 if (scan_int(write_ptr, len, &tmp)) 646 if (scan_int(write_ptr, len, &tmp))
645 tmp = 0; 647 tmp = 0;
@@ -647,7 +649,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
647 OT_PEERFLAG(&ws->peer) |= PEER_FLAG_SEEDING; 649 OT_PEERFLAG(&ws->peer) |= PEER_FLAG_SEEDING;
648 break; 650 break;
649 case 3: /* matched "event" */ 651 case 3: /* matched "event" */
650 switch (urlencoded_match_keyword(keywords_announce_event, &read_ptr, SCAN_SEARCHPATH_VALUE)) { 652 switch (urlencoded_match_keyword(keywords_announce_event, &read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_VALUE)) {
651 case -1: 653 case -1:
652 HTTPERROR_400_PARAM; 654 HTTPERROR_400_PARAM;
653 case 1: /* matched "completed" */ 655 case 1: /* matched "completed" */
@@ -661,7 +663,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
661 } 663 }
662 break; 664 break;
663 case 4: /* matched "numwant" */ 665 case 4: /* matched "numwant" */
664 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); 666 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_VALUE);
665 if ((len <= 0) || scan_int(write_ptr, len, &tmp)) 667 if ((len <= 0) || scan_int(write_ptr, len, &tmp))
666 HTTPERROR_400_PARAM; 668 HTTPERROR_400_PARAM;
667 if (tmp < 0) 669 if (tmp < 0)
@@ -671,7 +673,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
671 numwant = (size_t)tmp; 673 numwant = (size_t)tmp;
672 break; 674 break;
673 case 5: /* matched "compact" */ 675 case 5: /* matched "compact" */
674 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); 676 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_VALUE);
675 if ((len <= 0) || scan_int(write_ptr, len, &tmp)) 677 if ((len <= 0) || scan_int(write_ptr, len, &tmp))
676 HTTPERROR_400_PARAM; 678 HTTPERROR_400_PARAM;
677 if (!tmp) 679 if (!tmp)
@@ -681,7 +683,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
681 if (ws->hash) 683 if (ws->hash)
682 HTTPERROR_400_DOUBLEHASH; 684 HTTPERROR_400_DOUBLEHASH;
683 /* ignore this, when we have less than 20 bytes */ 685 /* ignore this, when we have less than 20 bytes */
684 if (urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE) != 20) 686 if (urlencoded_parse(&read_ptr, write_ptr = read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_VALUE) != 20)
685 HTTPERROR_400_PARAM; 687 HTTPERROR_400_PARAM;
686 ws->hash = (ot_hash *)write_ptr; 688 ws->hash = (ot_hash *)write_ptr;
687 break; 689 break;
@@ -689,7 +691,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
689 case 7: /* matched "ip" */ 691 case 7: /* matched "ip" */
690 { 692 {
691 char *tmp_buf1 = ws->reply, *tmp_buf2 = ws->reply + 16; 693 char *tmp_buf1 = ws->reply, *tmp_buf2 = ws->reply + 16;
692 len = urlencoded_parse(&read_ptr, tmp_buf2, SCAN_SEARCHPATH_VALUE); 694 len = urlencoded_parse(&read_ptr, tmp_buf2, ws->outbuf + G_OUTBUF_SIZE, SCAN_SEARCHPATH_VALUE);
693 tmp_buf2[len] = 0; 695 tmp_buf2[len] = 0;
694 if ((len <= 0) || ip_parse(tmp_buf2, tmp_buf1) != (size_t)len) 696 if ((len <= 0) || ip_parse(tmp_buf2, tmp_buf1) != (size_t)len)
695 HTTPERROR_400_PARAM; 697 HTTPERROR_400_PARAM;
@@ -698,7 +700,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
698#endif 700#endif
699 case 8: /* matched "peer_id" */ 701 case 8: /* matched "peer_id" */
700 /* ignore this, when we have less than 20 bytes */ 702 /* ignore this, when we have less than 20 bytes */
701 if (urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE) != 20) 703 if (urlencoded_parse(&read_ptr, write_ptr = read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_VALUE) != 20)
702 HTTPERROR_400_PARAM; 704 HTTPERROR_400_PARAM;
703 ws->peer_id = write_ptr; 705 ws->peer_id = write_ptr;
704 break; 706 break;
@@ -772,7 +774,7 @@ ssize_t http_handle_request(const int64_t sock, struct ot_workstruct *ws) {
772 In reality we abandoned requiring the url to be correct. This now 774 In reality we abandoned requiring the url to be correct. This now
773 only decodes url encoded characters, we check for announces and 775 only decodes url encoded characters, we check for announces and
774 scrapes by looking for "a*" or "sc" */ 776 scrapes by looking for "a*" or "sc" */
775 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_PATH); 777 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, ws->request + ws->request_size, SCAN_PATH);
776 778
777 /* If parsing returned an error, leave with not found */ 779 /* If parsing returned an error, leave with not found */
778 if (g_redirecturl && (len == -2)) 780 if (g_redirecturl && (len == -2))