summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--opentracker.c2
-rw-r--r--ot_accesslist.c4
-rw-r--r--ot_fullscrape.c12
-rw-r--r--ot_hex.c4
-rw-r--r--ot_hex.h4
-rw-r--r--ot_http.c40
-rw-r--r--ot_iovec.c10
-rw-r--r--ot_iovec.h6
-rw-r--r--ot_stats.c22
-rw-r--r--ot_sync.c6
-rw-r--r--ot_urlencoded.c (renamed from scan_urlencoded_query.c)14
-rw-r--r--ot_urlencoded.h (renamed from scan_urlencoded_query.h)6
-rw-r--r--tests/runner.c2
-rw-r--r--tests/t_hex.c28
-rw-r--r--tests/t_iovec.c20
-rw-r--r--tests/t_urlencoded.c (renamed from tests/t_scan_urlencoded_query.c)54
-rw-r--r--tests/test.h2
18 files changed, 122 insertions, 122 deletions
diff --git a/Makefile b/Makefile
index 87c20e2..d9b8690 100644
--- a/Makefile
+++ b/Makefile
@@ -68,8 +68,8 @@ CFLAGS+=-I$(LIBOWFAT_HEADERS) -DGIT_VERSION=$(GIT_VERSION) -Wall -pipe -pthread
68LDFLAGS+=-L$(LIBOWFAT_LIBRARY) -lowfat -pthread 68LDFLAGS+=-L$(LIBOWFAT_LIBRARY) -lowfat -pthread
69 69
70BINARY =opentracker 70BINARY =opentracker
71HEADERS=trackerlogic.h scan_urlencoded_query.h ot_batch.h ot_buf.h ot_fdstate.h ot_hex.h ot_ip.h ot_config.h ot_scan.h ot_socket.h ot_mutex.h ot_random.h ot_stats.h ot_vector.h ot_clean.h ot_udp.h ot_iovec.h ot_fullscrape.h ot_accesslist.h ot_http.h ot_livesync.h ot_rijndael.h 71HEADERS=trackerlogic.h ot_urlencoded.h ot_batch.h ot_buf.h ot_fdstate.h ot_hex.h ot_ip.h ot_config.h ot_scan.h ot_socket.h ot_mutex.h ot_random.h ot_stats.h ot_vector.h ot_clean.h ot_udp.h ot_iovec.h ot_fullscrape.h ot_accesslist.h ot_http.h ot_livesync.h ot_rijndael.h
72SOURCES=opentracker.c trackerlogic.c scan_urlencoded_query.c ot_batch.c ot_buf.c ot_fdstate.c ot_hex.c ot_ip.c ot_config.c ot_scan.c ot_socket.c ot_mutex.c ot_random.c ot_stats.c ot_vector.c ot_clean.c ot_udp.c ot_iovec.c ot_fullscrape.c ot_accesslist.c ot_http.c ot_livesync.c ot_rijndael.c 72SOURCES=opentracker.c trackerlogic.c ot_urlencoded.c ot_batch.c ot_buf.c ot_fdstate.c ot_hex.c ot_ip.c ot_config.c ot_scan.c ot_socket.c ot_mutex.c ot_random.c ot_stats.c ot_vector.c ot_clean.c ot_udp.c ot_iovec.c ot_fullscrape.c ot_accesslist.c ot_http.c ot_livesync.c ot_rijndael.c
73SOURCES_proxy=proxy.c ot_batch.c ot_fdstate.c ot_vector.c ot_mutex.c ot_random.c ot_scan.c ot_ip.c ot_socket.c 73SOURCES_proxy=proxy.c ot_batch.c ot_fdstate.c ot_vector.c ot_mutex.c ot_random.c ot_scan.c ot_ip.c ot_socket.c
74 74
75OBJECTS = $(SOURCES:%.c=%.o) 75OBJECTS = $(SOURCES:%.c=%.o)
@@ -119,8 +119,8 @@ $(OBJECTS_proxy_debug): $(HEADERS)
119# has to. tests/stubs.c supplies the few symbols those modules reference but 119# has to. tests/stubs.c supplies the few symbols those modules reference but
120# the tests never reach. 120# the tests never reach.
121TESTBIN=tests/runner 121TESTBIN=tests/runner
122TEST_SOURCES=tests/runner.c tests/test.c tests/stubs.c tests/t_scan_urlencoded_query.c tests/t_iovec.c tests/t_vector.c tests/t_random.c tests/t_hex.c tests/t_accesslist.c tests/t_scan.c tests/t_buf.c tests/t_ip.c tests/t_socket.c tests/t_mutex.c tests/t_batch.c tests/t_fdstate.c 122TEST_SOURCES=tests/runner.c tests/test.c tests/stubs.c tests/t_urlencoded.c tests/t_iovec.c tests/t_vector.c tests/t_random.c tests/t_hex.c tests/t_accesslist.c tests/t_scan.c tests/t_buf.c tests/t_ip.c tests/t_socket.c tests/t_mutex.c tests/t_batch.c tests/t_fdstate.c
123TEST_UNITS=scan_urlencoded_query.c ot_batch.c ot_fdstate.c ot_buf.c ot_ip.c ot_socket.c ot_iovec.c ot_vector.c ot_random.c ot_hex.c ot_scan.c ot_accesslist.c ot_mutex.c 123TEST_UNITS=ot_urlencoded.c ot_batch.c ot_fdstate.c ot_buf.c ot_ip.c ot_socket.c ot_iovec.c ot_vector.c ot_random.c ot_hex.c ot_scan.c ot_accesslist.c ot_mutex.c
124TEST_HEADERS=tests/test.h $(HEADERS) 124TEST_HEADERS=tests/test.h $(HEADERS)
125# Tests reach code that sits behind feature flags, so the units under test are 125# Tests reach code that sits behind feature flags, so the units under test are
126# built with those features enabled. A test binary is not a production binary. 126# built with those features enabled. A test binary is not a production binary.
diff --git a/opentracker.c b/opentracker.c
index 0f0b314..f0f6404 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -375,7 +375,7 @@ void load_state(const char *const state_filename) {
375 while (fgets(inbuf, sizeof(inbuf), state_filehandle)) { 375 while (fgets(inbuf, sizeof(inbuf), state_filehandle)) {
376 size_t i; 376 size_t i;
377 377
378 if (!hex_tohash(infohash, inbuf)) 378 if (!hex_to_hash(infohash, inbuf))
379 continue; 379 continue;
380 i = 2 * sizeof(ot_hash); 380 i = 2 * sizeof(ot_hash);
381 381
diff --git a/ot_accesslist.c b/ot_accesslist.c
index ef845d6..79a11a5 100644
--- a/ot_accesslist.c
+++ b/ot_accesslist.c
@@ -110,7 +110,7 @@ size_t accesslist_parse_hashes(ot_hash *dest, size_t capacity, const char *buf,
110 size_t count = 0; 110 size_t count = 0;
111 111
112 while (count < capacity && end - offs >= 40) { 112 while (count < capacity && end - offs >= 40) {
113 if (hex_tohash(dest[count], offs)) { 113 if (hex_to_hash(dest[count], offs)) {
114 offs += 40; 114 offs += 40;
115 115
116 if (offs == end || !hex_isdigit((unsigned char)*offs)) 116 if (offs == end || !hex_isdigit((unsigned char)*offs))
@@ -308,7 +308,7 @@ static void *accesslist_adddel_worker(const char *fifoname, ot_accesslist *_
308 if (linelen < 41) 308 if (linelen < 41)
309 continue; 309 continue;
310 310
311 if (!hex_tohash(info_hash, line)) 311 if (!hex_to_hash(info_hash, line))
312 continue; 312 continue;
313 313
314 /* From now on we modify g_accesslist_add and g_accesslist_delete, so prevent the 314 /* From now on we modify g_accesslist_add and g_accesslist_delete, so prevent the
diff --git a/ot_fullscrape.c b/ot_fullscrape.c
index 788e574..0dee5c2 100644
--- a/ot_fullscrape.c
+++ b/ot_fullscrape.c
@@ -25,7 +25,7 @@
25#include "ot_fullscrape.h" 25#include "ot_fullscrape.h"
26#include "ot_iovec.h" 26#include "ot_iovec.h"
27#include "ot_mutex.h" 27#include "ot_mutex.h"
28#include "scan_urlencoded_query.h" 28#include "ot_urlencoded.h"
29#include "trackerlogic.h" 29#include "trackerlogic.h"
30 30
31/* Fetch full scrape info for all torrents 31/* Fetch full scrape info for all torrents
@@ -105,12 +105,12 @@ static char * fullscrape_write_one( ot_tasktype mode, char *r, ot_torrent *torre
105 105
106 break; 106 break;
107 case TASK_FULLSCRAPE_TPB_ASCII: 107 case TASK_FULLSCRAPE_TPB_ASCII:
108 hex_fromhash(r, *hash); 108 hex_from_hash(r, *hash);
109 r += 2 * sizeof(ot_hash); 109 r += 2 * sizeof(ot_hash);
110 r += sprintf(r, ":%zd:%zd\n", seed_count, peer_count - seed_count); 110 r += sprintf(r, ":%zd:%zd\n", seed_count, peer_count - seed_count);
111 break; 111 break;
112 case TASK_FULLSCRAPE_TPB_ASCII_PLUS: 112 case TASK_FULLSCRAPE_TPB_ASCII_PLUS:
113 hex_fromhash(r, *hash); 113 hex_from_hash(r, *hash);
114 r += 2 * sizeof(ot_hash); 114 r += 2 * sizeof(ot_hash);
115 r += sprintf(r, ":%zd:%zd:%zd\n", seed_count, peer_count - seed_count, down_count); 115 r += sprintf(r, ":%zd:%zd:%zd\n", seed_count, peer_count - seed_count, down_count);
116 break; 116 break;
@@ -126,7 +126,7 @@ static char * fullscrape_write_one( ot_tasktype mode, char *r, ot_torrent *torre
126 r += sprintf(r, ":%zd:%zd\n", seed_count, peer_count - seed_count); 126 r += sprintf(r, ":%zd:%zd\n", seed_count, peer_count - seed_count);
127 break; 127 break;
128 case TASK_FULLSCRAPE_TRACKERSTATE: 128 case TASK_FULLSCRAPE_TRACKERSTATE:
129 hex_fromhash(r, *hash); 129 hex_from_hash(r, *hash);
130 r += 2 * sizeof(ot_hash); 130 r += 2 * sizeof(ot_hash);
131 r += sprintf(r, ":%zd:%zd\n", torrent->peer_list6->base, down_count); 131 r += sprintf(r, ":%zd:%zd\n", torrent->peer_list6->base, down_count);
132 break; 132 break;
@@ -296,7 +296,7 @@ static void fullscrape_make_gzip(int taskid, ot_tasktype mode) {
296 iovector.iov_base = malloc(OT_SCRAPE_CHUNK_SIZE); 296 iovector.iov_base = malloc(OT_SCRAPE_CHUNK_SIZE);
297 297
298 if (!iovector.iov_base) { 298 if (!iovector.iov_base) {
299 fprintf(stderr, "Problem with iovec_fix_increase_or_free\n"); 299 fprintf(stderr, "Problem with iovec_next_chunk\n");
300 deflateEnd(&strm); 300 deflateEnd(&strm);
301 return; 301 return;
302 } 302 }
@@ -422,7 +422,7 @@ static void fullscrape_make_zstd(int taskid, ot_tasktype mode) {
422 iovector.iov_base = malloc(OT_SCRAPE_CHUNK_SIZE); 422 iovector.iov_base = malloc(OT_SCRAPE_CHUNK_SIZE);
423 423
424 if (!iovector.iov_base) { 424 if (!iovector.iov_base) {
425 fprintf(stderr, "Problem with iovec_fix_increase_or_free\n"); 425 fprintf(stderr, "Problem with iovec_next_chunk\n");
426 ZSTD_freeCCtx(zstream); 426 ZSTD_freeCCtx(zstream);
427 return; 427 return;
428 } 428 }
diff --git a/ot_hex.c b/ot_hex.c
index 9581951..2bf69c4 100644
--- a/ot_hex.c
+++ b/ot_hex.c
@@ -23,7 +23,7 @@ int hex_value(int c) {
23 23
24int hex_isdigit(int c) { return hex_value(c) >= 0; } 24int hex_isdigit(int c) { return hex_value(c) >= 0; }
25 25
26char *hex_fromhash(char *dest, const uint8_t *hash) { 26char *hex_from_hash(char *dest, const uint8_t *hash) {
27 static const char digits[] = "0123456789ABCDEF"; 27 static const char digits[] = "0123456789ABCDEF";
28 char *d = dest; 28 char *d = dest;
29 size_t i; 29 size_t i;
@@ -36,7 +36,7 @@ char *hex_fromhash(char *dest, const uint8_t *hash) {
36 return dest; 36 return dest;
37} 37}
38 38
39int hex_tohash(ot_hash hash, const char *src) { 39int hex_to_hash(ot_hash hash, const char *src) {
40 uint8_t decoded[sizeof(ot_hash)]; 40 uint8_t decoded[sizeof(ot_hash)];
41 size_t i; 41 size_t i;
42 42
diff --git a/ot_hex.h b/ot_hex.h
index 3b45b61..28eddf5 100644
--- a/ot_hex.h
+++ b/ot_hex.h
@@ -12,12 +12,12 @@
12 12
13/* Write hash as forty upper case hex digits followed by a terminating zero. 13/* Write hash as forty upper case hex digits followed by a terminating zero.
14 dest must have room for forty one bytes. Returns dest. */ 14 dest must have room for forty one bytes. Returns dest. */
15char *hex_fromhash(char *dest, const uint8_t *hash); 15char *hex_from_hash(char *dest, const uint8_t *hash);
16 16
17/* Read forty hex digits from src into hash. Returns non-zero on success. 17/* Read forty hex digits from src into hash. Returns non-zero on success.
18 On failure hash is left untouched and no byte of src beyond the offending 18 On failure hash is left untouched and no byte of src beyond the offending
19 character is read, so src need not be forty characters long. */ 19 character is read, so src need not be forty characters long. */
20int hex_tohash(ot_hash hash, const char *src); 20int hex_to_hash(ot_hash hash, const char *src);
21 21
22/* Non-zero if c is a hexadecimal digit, in either case. */ 22/* Non-zero if c is a hexadecimal digit, in either case. */
23int hex_isdigit(int c); 23int hex_isdigit(int c);
diff --git a/ot_http.c b/ot_http.c
index 6bf343c..6c3332c 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -27,7 +27,7 @@
27#include "ot_scan.h" 27#include "ot_scan.h"
28#include "ot_fdstate.h" 28#include "ot_fdstate.h"
29#include "ot_stats.h" 29#include "ot_stats.h"
30#include "scan_urlencoded_query.h" 30#include "ot_urlencoded.h"
31#include "trackerlogic.h" 31#include "trackerlogic.h"
32 32
33#define OT_MAXMULTISCRAPE_COUNT 64 33#define OT_MAXMULTISCRAPE_COUNT 64
@@ -257,21 +257,21 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c
257#endif 257#endif
258 258
259 while (scanon) { 259 while (scanon) {
260 switch (scan_find_keywords(keywords_main, &read_ptr, SCAN_SEARCHPATH_PARAM)) { 260 switch (urlencoded_match_keyword(keywords_main, &read_ptr, SCAN_SEARCHPATH_PARAM)) {
261 case -2: 261 case -2:
262 scanon = 0; 262 scanon = 0;
263 break; /* TERMINATOR */ 263 break; /* TERMINATOR */
264 case -1: 264 case -1:
265 HTTPERROR_400_PARAM; /* PARSE ERROR */ 265 HTTPERROR_400_PARAM; /* PARSE ERROR */
266 case -3: 266 case -3:
267 scan_urlencoded_skipvalue(&read_ptr); 267 urlencoded_skip_value(&read_ptr);
268 break; 268 break;
269 case 1: /* matched "mode" */ 269 case 1: /* matched "mode" */
270 if ((mode = scan_find_keywords(keywords_mode, &read_ptr, SCAN_SEARCHPATH_VALUE)) <= 0) 270 if ((mode = urlencoded_match_keyword(keywords_mode, &read_ptr, SCAN_SEARCHPATH_VALUE)) <= 0)
271 HTTPERROR_400_PARAM; 271 HTTPERROR_400_PARAM;
272 break; 272 break;
273 case 2: /* matched "format" */ 273 case 2: /* matched "format" */
274 if ((format = scan_find_keywords(keywords_format, &read_ptr, SCAN_SEARCHPATH_VALUE)) <= 0) 274 if ((format = urlencoded_match_keyword(keywords_format, &read_ptr, SCAN_SEARCHPATH_VALUE)) <= 0)
275 HTTPERROR_400_PARAM; 275 HTTPERROR_400_PARAM;
276 break; 276 break;
277 case 3: 277 case 3:
@@ -418,18 +418,18 @@ static ssize_t http_handle_scrape(const int64_t sock, struct ot_workstruct *ws,
418 } 418 }
419 419
420 while (scanon) { 420 while (scanon) {
421 switch (scan_find_keywords(keywords_scrape, &read_ptr, SCAN_SEARCHPATH_PARAM)) { 421 switch (urlencoded_match_keyword(keywords_scrape, &read_ptr, SCAN_SEARCHPATH_PARAM)) {
422 case -2: 422 case -2:
423 scanon = 0; 423 scanon = 0;
424 break; /* TERMINATOR */ 424 break; /* TERMINATOR */
425 default: 425 default:
426 HTTPERROR_400_PARAM; /* PARSE ERROR */ 426 HTTPERROR_400_PARAM; /* PARSE ERROR */
427 case -3: 427 case -3:
428 scan_urlencoded_skipvalue(&read_ptr); 428 urlencoded_skip_value(&read_ptr);
429 break; 429 break;
430 case 1: /* matched "info_hash" */ 430 case 1: /* matched "info_hash" */
431 /* ignore this, when we have less than 20 bytes */ 431 /* ignore this, when we have less than 20 bytes */
432 if (scan_urlencoded_query(&read_ptr, (char *)(multiscrape_buf + numwant++), SCAN_SEARCHPATH_VALUE) != (ssize_t)sizeof(ot_hash)) 432 if (urlencoded_parse(&read_ptr, (char *)(multiscrape_buf + numwant++), SCAN_SEARCHPATH_VALUE) != (ssize_t)sizeof(ot_hash))
433 HTTPERROR_400_PARAM; 433 HTTPERROR_400_PARAM;
434 break; 434 break;
435 } 435 }
@@ -518,24 +518,24 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
518 scanon = 1; 518 scanon = 1;
519 519
520 while (scanon) { 520 while (scanon) {
521 switch (scan_find_keywords(keywords_announce, &read_ptr, SCAN_SEARCHPATH_PARAM)) { 521 switch (urlencoded_match_keyword(keywords_announce, &read_ptr, SCAN_SEARCHPATH_PARAM)) {
522 case -2: 522 case -2:
523 scanon = 0; 523 scanon = 0;
524 break; /* TERMINATOR */ 524 break; /* TERMINATOR */
525 case -1: 525 case -1:
526 HTTPERROR_400_PARAM; /* PARSE ERROR */ 526 HTTPERROR_400_PARAM; /* PARSE ERROR */
527 case -3: 527 case -3:
528 scan_urlencoded_skipvalue(&read_ptr); 528 urlencoded_skip_value(&read_ptr);
529 break; 529 break;
530 case 1: /* matched "port" */ 530 case 1: /* matched "port" */
531 len = scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); 531 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE);
532 if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp) || (tmp > 0xffff)) 532 if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp) || (tmp > 0xffff))
533 HTTPERROR_400_PARAM; 533 HTTPERROR_400_PARAM;
534 port = htons(tmp); 534 port = htons(tmp);
535 OT_SETPORT(&ws->peer, &port); 535 OT_SETPORT(&ws->peer, &port);
536 break; 536 break;
537 case 2: /* matched "left" */ 537 case 2: /* matched "left" */
538 if ((len = scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE)) <= 0) 538 if ((len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE)) <= 0)
539 HTTPERROR_400_PARAM; 539 HTTPERROR_400_PARAM;
540 if (scan_fixed_int(write_ptr, len, &tmp)) 540 if (scan_fixed_int(write_ptr, len, &tmp))
541 tmp = 0; 541 tmp = 0;
@@ -543,7 +543,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
543 OT_PEERFLAG(&ws->peer) |= PEER_FLAG_SEEDING; 543 OT_PEERFLAG(&ws->peer) |= PEER_FLAG_SEEDING;
544 break; 544 break;
545 case 3: /* matched "event" */ 545 case 3: /* matched "event" */
546 switch (scan_find_keywords(keywords_announce_event, &read_ptr, SCAN_SEARCHPATH_VALUE)) { 546 switch (urlencoded_match_keyword(keywords_announce_event, &read_ptr, SCAN_SEARCHPATH_VALUE)) {
547 case -1: 547 case -1:
548 HTTPERROR_400_PARAM; 548 HTTPERROR_400_PARAM;
549 case 1: /* matched "completed" */ 549 case 1: /* matched "completed" */
@@ -557,7 +557,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
557 } 557 }
558 break; 558 break;
559 case 4: /* matched "numwant" */ 559 case 4: /* matched "numwant" */
560 len = scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); 560 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE);
561 if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp)) 561 if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp))
562 HTTPERROR_400_PARAM; 562 HTTPERROR_400_PARAM;
563 if (tmp < 0) 563 if (tmp < 0)
@@ -567,7 +567,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
567 numwant = tmp; 567 numwant = tmp;
568 break; 568 break;
569 case 5: /* matched "compact" */ 569 case 5: /* matched "compact" */
570 len = scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); 570 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE);
571 if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp)) 571 if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp))
572 HTTPERROR_400_PARAM; 572 HTTPERROR_400_PARAM;
573 if (!tmp) 573 if (!tmp)
@@ -577,7 +577,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
577 if (ws->hash) 577 if (ws->hash)
578 HTTPERROR_400_DOUBLEHASH; 578 HTTPERROR_400_DOUBLEHASH;
579 /* ignore this, when we have less than 20 bytes */ 579 /* ignore this, when we have less than 20 bytes */
580 if (scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE) != 20) 580 if (urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE) != 20)
581 HTTPERROR_400_PARAM; 581 HTTPERROR_400_PARAM;
582 ws->hash = (ot_hash *)write_ptr; 582 ws->hash = (ot_hash *)write_ptr;
583 break; 583 break;
@@ -585,7 +585,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
585 case 7: /* matched "ip" */ 585 case 7: /* matched "ip" */
586 { 586 {
587 char *tmp_buf1 = ws->reply, *tmp_buf2 = ws->reply + 16; 587 char *tmp_buf1 = ws->reply, *tmp_buf2 = ws->reply + 16;
588 len = scan_urlencoded_query(&read_ptr, tmp_buf2, SCAN_SEARCHPATH_VALUE); 588 len = urlencoded_parse(&read_ptr, tmp_buf2, SCAN_SEARCHPATH_VALUE);
589 tmp_buf2[len] = 0; 589 tmp_buf2[len] = 0;
590 if ((len <= 0) || !ip_scan(tmp_buf2, tmp_buf1)) 590 if ((len <= 0) || !ip_scan(tmp_buf2, tmp_buf1))
591 HTTPERROR_400_PARAM; 591 HTTPERROR_400_PARAM;
@@ -601,7 +601,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
601 uint64_t value; 601 uint64_t value;
602 signed short parsed, bits; 602 signed short parsed, bits;
603 603
604 len = scan_urlencoded_query(&read_ptr, tmp_buf, SCAN_SEARCHPATH_VALUE); 604 len = urlencoded_parse(&read_ptr, tmp_buf, SCAN_SEARCHPATH_VALUE);
605 tmp_buf[len] = 0; 605 tmp_buf[len] = 0;
606 if (len <= 0) 606 if (len <= 0)
607 HTTPERROR_400_PARAM; 607 HTTPERROR_400_PARAM;
@@ -630,7 +630,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct
630#endif 630#endif
631 case 9: /* matched "peer_id" */ 631 case 9: /* matched "peer_id" */
632 /* ignore this, when we have less than 20 bytes */ 632 /* ignore this, when we have less than 20 bytes */
633 if (scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE) != 20) 633 if (urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE) != 20)
634 HTTPERROR_400_PARAM; 634 HTTPERROR_400_PARAM;
635 ws->peer_id = write_ptr; 635 ws->peer_id = write_ptr;
636 break; 636 break;
@@ -709,7 +709,7 @@ ssize_t http_handle_request(const int64_t sock, struct ot_workstruct *ws) {
709 In reality we abandoned requiring the url to be correct. This now 709 In reality we abandoned requiring the url to be correct. This now
710 only decodes url encoded characters, we check for announces and 710 only decodes url encoded characters, we check for announces and
711 scrapes by looking for "a*" or "sc" */ 711 scrapes by looking for "a*" or "sc" */
712 len = scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_PATH); 712 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_PATH);
713 713
714 /* If parsing returned an error, leave with not found */ 714 /* If parsing returned an error, leave with not found */
715 if (g_redirecturl && (len == -2)) 715 if (g_redirecturl && (len == -2))
diff --git a/ot_iovec.c b/ot_iovec.c
index cd5b9f9..2ee455c 100644
--- a/ot_iovec.c
+++ b/ot_iovec.c
@@ -12,7 +12,7 @@
12/* Opentracker */ 12/* Opentracker */
13#include "ot_iovec.h" 13#include "ot_iovec.h"
14 14
15void *iovec_increase(size_t *iovec_entries, struct iovec **iovector, size_t new_alloc) { 15void *iovec_new_chunk(size_t *iovec_entries, struct iovec **iovector, size_t new_alloc) {
16 void *new_data; 16 void *new_data;
17 size_t new_entries = 1 + *iovec_entries; 17 size_t new_entries = 1 + *iovec_entries;
18 struct iovec *new_vec = realloc(*iovector, new_entries * sizeof(struct iovec)); 18 struct iovec *new_vec = realloc(*iovector, new_entries * sizeof(struct iovec));
@@ -62,7 +62,7 @@ void iovec_free(size_t *iovec_entries, struct iovec **iovector) {
62 *iovec_entries = 0; 62 *iovec_entries = 0;
63} 63}
64 64
65void iovec_fixlast(size_t *iovec_entries, struct iovec **iovector, void *last_ptr) { 65void iovec_trim_last(size_t *iovec_entries, struct iovec **iovector, void *last_ptr) {
66 if (*iovec_entries) { 66 if (*iovec_entries) {
67 char *base = (char *)((*iovector)[*iovec_entries - 1]).iov_base; 67 char *base = (char *)((*iovector)[*iovec_entries - 1]).iov_base;
68 size_t new_alloc = ((char *)last_ptr) - base; 68 size_t new_alloc = ((char *)last_ptr) - base;
@@ -72,12 +72,12 @@ void iovec_fixlast(size_t *iovec_entries, struct iovec **iovector, void *last_pt
72 } 72 }
73} 73}
74 74
75void *iovec_fix_increase_or_free(size_t *iovec_entries, struct iovec **iovector, void *last_ptr, size_t new_alloc) { 75void *iovec_next_chunk(size_t *iovec_entries, struct iovec **iovector, void *last_ptr, size_t new_alloc) {
76 void *new_data; 76 void *new_data;
77 77
78 iovec_fixlast(iovec_entries, iovector, last_ptr); 78 iovec_trim_last(iovec_entries, iovector, last_ptr);
79 79
80 if (!(new_data = iovec_increase(iovec_entries, iovector, new_alloc))) 80 if (!(new_data = iovec_new_chunk(iovec_entries, iovector, new_alloc)))
81 iovec_free(iovec_entries, iovector); 81 iovec_free(iovec_entries, iovector);
82 82
83 return new_data; 83 return new_data;
diff --git a/ot_iovec.h b/ot_iovec.h
index eb4365b..6f5a1d6 100644
--- a/ot_iovec.h
+++ b/ot_iovec.h
@@ -8,13 +8,13 @@
8 8
9#include <sys/uio.h> 9#include <sys/uio.h>
10 10
11void *iovec_increase(size_t *iovec_entries, struct iovec **iovector, size_t new_alloc); 11void *iovec_new_chunk(size_t *iovec_entries, struct iovec **iovector, size_t new_alloc);
12void *iovec_append(size_t *iovec_entries, struct iovec **iovector, struct iovec *append_iovector); 12void *iovec_append(size_t *iovec_entries, struct iovec **iovector, struct iovec *append_iovector);
13void iovec_fixlast(size_t *iovec_entries, struct iovec **iovector, void *last_ptr); 13void iovec_trim_last(size_t *iovec_entries, struct iovec **iovector, void *last_ptr);
14void iovec_free(size_t *iovec_entries, struct iovec **iovector); 14void iovec_free(size_t *iovec_entries, struct iovec **iovector);
15 15
16size_t iovec_length(const size_t *iovec_entries, const struct iovec **iovector); 16size_t iovec_length(const size_t *iovec_entries, const struct iovec **iovector);
17 17
18void *iovec_fix_increase_or_free(size_t *iovec_entries, struct iovec **iovector, void *last_ptr, size_t new_alloc); 18void *iovec_next_chunk(size_t *iovec_entries, struct iovec **iovector, void *last_ptr, size_t new_alloc);
19 19
20#endif 20#endif
diff --git a/ot_stats.c b/ot_stats.c
index 6589aef..ceeb89d 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -345,15 +345,15 @@ size_t stats_top_txt(char *reply, size_t amount) {
345 r += sprintf(r, "Top %zd torrents by peers:\n", amount); 345 r += sprintf(r, "Top %zd torrents by peers:\n", amount);
346 for (idx = 0; idx < amount; ++idx) 346 for (idx = 0; idx < amount; ++idx)
347 if (top100c[idx].val) 347 if (top100c[idx].val)
348 r += sprintf(r, "\t%zd\t%s\n", top100c[idx].val, hex_fromhash(hex_out, top100c[idx].hash)); 348 r += sprintf(r, "\t%zd\t%s\n", top100c[idx].val, hex_from_hash(hex_out, top100c[idx].hash));
349 r += sprintf(r, "Top %zd torrents by seeds:\n", amount); 349 r += sprintf(r, "Top %zd torrents by seeds:\n", amount);
350 for (idx = 0; idx < amount; ++idx) 350 for (idx = 0; idx < amount; ++idx)
351 if (top100s[idx].val) 351 if (top100s[idx].val)
352 r += sprintf(r, "\t%zd\t%s\n", top100s[idx].val, hex_fromhash(hex_out, top100s[idx].hash)); 352 r += sprintf(r, "\t%zd\t%s\n", top100s[idx].val, hex_from_hash(hex_out, top100s[idx].hash));
353 r += sprintf(r, "Top %zd torrents by leechers:\n", amount); 353 r += sprintf(r, "Top %zd torrents by leechers:\n", amount);
354 for (idx = 0; idx < amount; ++idx) 354 for (idx = 0; idx < amount; ++idx)
355 if (top100l[idx].val) 355 if (top100l[idx].val)
356 r += sprintf(r, "\t%zd\t%s\n", top100l[idx].val, hex_fromhash(hex_out, top100l[idx].hash)); 356 r += sprintf(r, "\t%zd\t%s\n", top100l[idx].val, hex_from_hash(hex_out, top100l[idx].hash));
357 357
358 return r - reply; 358 return r - reply;
359} 359}
@@ -459,7 +459,7 @@ static void stats_return_fulllog(size_t *iovec_entries, struct iovec **iovector,
459 459
460 while (loglist) { 460 while (loglist) {
461 if (r + (loglist->size + 64) >= re) { 461 if (r + (loglist->size + 64) >= re) {
462 r = iovec_fix_increase_or_free(iovec_entries, iovector, r, 32 * OT_STATS_TMPSIZE); 462 r = iovec_next_chunk(iovec_entries, iovector, r, 32 * OT_STATS_TMPSIZE);
463 if (!r) 463 if (!r)
464 return; 464 return;
465 re = r + 32 * OT_STATS_TMPSIZE; 465 re = r + 32 * OT_STATS_TMPSIZE;
@@ -479,7 +479,7 @@ static void stats_return_fulllog(size_t *iovec_entries, struct iovec **iovector,
479 free(loglist); 479 free(loglist);
480 loglist = llnext; 480 loglist = llnext;
481 } 481 }
482 iovec_fixlast(iovec_entries, iovector, r); 482 iovec_trim_last(iovec_entries, iovector, r);
483} 483}
484#endif 484#endif
485 485
@@ -570,7 +570,7 @@ static void stats_make(size_t *iovec_entries, struct iovec **iovector, ot_taskty
570 570
571 *iovec_entries = 0; 571 *iovec_entries = 0;
572 *iovector = NULL; 572 *iovector = NULL;
573 if (!(r = iovec_increase(iovec_entries, iovector, OT_STATS_TMPSIZE))) 573 if (!(r = iovec_new_chunk(iovec_entries, iovector, OT_STATS_TMPSIZE)))
574 return; 574 return;
575 575
576 switch (mode & TASK_TASK_MASK) { 576 switch (mode & TASK_TASK_MASK) {
@@ -587,13 +587,13 @@ static void stats_make(size_t *iovec_entries, struct iovec **iovector, ot_taskty
587 r += stats_top_txt(r, 10); 587 r += stats_top_txt(r, 10);
588 break; 588 break;
589 case TASK_STATS_TOP100: 589 case TASK_STATS_TOP100:
590 r = iovec_fix_increase_or_free(iovec_entries, iovector, r, 4 * OT_STATS_TMPSIZE); 590 r = iovec_next_chunk(iovec_entries, iovector, r, 4 * OT_STATS_TMPSIZE);
591 if (!r) 591 if (!r)
592 return; 592 return;
593 r += stats_top_txt(r, 100); 593 r += stats_top_txt(r, 100);
594 break; 594 break;
595 case TASK_STATS_EVERYTHING: 595 case TASK_STATS_EVERYTHING:
596 r = iovec_fix_increase_or_free(iovec_entries, iovector, r, OT_STATS_TMPSIZE + 64 * OT_PEER_TIMEOUT); 596 r = iovec_next_chunk(iovec_entries, iovector, r, OT_STATS_TMPSIZE + 64 * OT_PEER_TIMEOUT);
597 if (!r) 597 if (!r)
598 return; 598 return;
599 r += stats_return_everything(r); 599 r += stats_return_everything(r);
@@ -612,7 +612,7 @@ static void stats_make(size_t *iovec_entries, struct iovec **iovector, ot_taskty
612 iovec_free(iovec_entries, iovector); 612 iovec_free(iovec_entries, iovector);
613 return; 613 return;
614 } 614 }
615 iovec_fixlast(iovec_entries, iovector, r); 615 iovec_trim_last(iovec_entries, iovector, r);
616} 616}
617 617
618void stats_issue_event(ot_status_event event, PROTO_FLAG proto, uintptr_t event_data) { 618void stats_issue_event(ot_status_event event, PROTO_FLAG proto, uintptr_t event_data) {
@@ -651,9 +651,9 @@ void stats_issue_event(ot_status_event event, PROTO_FLAG proto, uintptr_t event_
651 localtime_r(&ttt, &time_now); 651 localtime_r(&ttt, &time_now);
652 strftime(timestring, sizeof(timestring), "%FT%T%z", &time_now); 652 strftime(timestring, sizeof(timestring), "%FT%T%z", &time_now);
653 653
654 hex_fromhash(hash_hex, *ws->hash); 654 hex_from_hash(hash_hex, *ws->hash);
655 if (ws->peer_id) 655 if (ws->peer_id)
656 hex_fromhash(peerid_hex, (uint8_t *)ws->peer_id); 656 hex_from_hash(peerid_hex, (uint8_t *)ws->peer_id);
657 else { 657 else {
658 *peerid_hex = 0; 658 *peerid_hex = 0;
659 } 659 }
diff --git a/ot_sync.c b/ot_sync.c
index dc71ddd..5527c94 100644
--- a/ot_sync.c
+++ b/ot_sync.c
@@ -77,7 +77,7 @@ static void sync_make(size_t *iovec_entries, struct iovec **iovector) {
77 /* Setup return vector... */ 77 /* Setup return vector... */
78 *iovec_entries = 0; 78 *iovec_entries = 0;
79 *iovector = NULL; 79 *iovector = NULL;
80 if (!(r = iovec_increase(iovec_entries, iovector, OT_SYNC_CHUNK_SIZE))) 80 if (!(r = iovec_new_chunk(iovec_entries, iovector, OT_SYNC_CHUNK_SIZE)))
81 return; 81 return;
82 82
83 /* ... and pointer to end of current output buffer. 83 /* ... and pointer to end of current output buffer.
@@ -105,7 +105,7 @@ static void sync_make(size_t *iovec_entries, struct iovec **iovector) {
105 105
106 /* Allocate a fresh output buffer at the end of our buffers list 106 /* Allocate a fresh output buffer at the end of our buffers list
107 release bucket and return, if that fails */ 107 release bucket and return, if that fails */
108 if (!(r = iovec_fix_increase_or_free(iovec_entries, iovector, r, OT_SYNC_CHUNK_SIZE))) 108 if (!(r = iovec_next_chunk(iovec_entries, iovector, r, OT_SYNC_CHUNK_SIZE)))
109 return mutex_bucket_unlock(bucket); 109 return mutex_bucket_unlock(bucket);
110 110
111 /* Adjust new end of output buffer */ 111 /* Adjust new end of output buffer */
@@ -131,7 +131,7 @@ static void sync_make(size_t *iovec_entries, struct iovec **iovector) {
131 *r++ = 'e'; 131 *r++ = 'e';
132 132
133 /* Release unused memory in current output buffer */ 133 /* Release unused memory in current output buffer */
134 iovec_fixlast(iovec_entries, iovector, r); 134 iovec_trim_last(iovec_entries, iovector, r);
135} 135}
136 136
137/* This is the entry point into this worker thread 137/* This is the entry point into this worker thread
diff --git a/scan_urlencoded_query.c b/ot_urlencoded.c
index cfc8708..1ca6e81 100644
--- a/scan_urlencoded_query.c
+++ b/ot_urlencoded.c
@@ -4,7 +4,7 @@
4 $id$ */ 4 $id$ */
5 5
6/* Opentracker */ 6/* Opentracker */
7#include "scan_urlencoded_query.h" 7#include "ot_urlencoded.h"
8 8
9/* System */ 9/* System */
10#include <string.h> 10#include <string.h>
@@ -53,7 +53,7 @@ static unsigned char fromhex(unsigned char x) {
53} 53}
54 54
55/* Skip the value of a param=value pair */ 55/* Skip the value of a param=value pair */
56void scan_urlencoded_skipvalue(char **string) { 56void urlencoded_skip_value(char **string) {
57 const unsigned char *s = *(const unsigned char **)string; 57 const unsigned char *s = *(const unsigned char **)string;
58 unsigned char f; 58 unsigned char f;
59 59
@@ -63,16 +63,16 @@ void scan_urlencoded_skipvalue(char **string) {
63 ; 63 ;
64 64
65 /* If we stopped at a hard terminator like \0 or \n, make the 65 /* If we stopped at a hard terminator like \0 or \n, make the
66 next scan_urlencoded_query encounter it again */ 66 next urlencoded_parse encounter it again */
67 if (f & SCAN_SEARCHPATH_TERMINATOR) 67 if (f & SCAN_SEARCHPATH_TERMINATOR)
68 --s; 68 --s;
69 69
70 *string = (char *)s; 70 *string = (char *)s;
71} 71}
72 72
73int scan_find_keywords(const ot_keywords *keywords, char **string, SCAN_SEARCHPATH_FLAG flags) { 73int urlencoded_match_keyword(const ot_keywords *keywords, char **string, SCAN_SEARCHPATH_FLAG flags) {
74 char *deststring = *string; 74 char *deststring = *string;
75 ssize_t match_length = scan_urlencoded_query(string, deststring, flags); 75 ssize_t match_length = urlencoded_parse(string, deststring, flags);
76 76
77 if (match_length < 0) 77 if (match_length < 0)
78 return match_length; 78 return match_length;
@@ -88,7 +88,7 @@ int scan_find_keywords(const ot_keywords *keywords, char **string, SCAN_SEARCHPA
88 return -3; 88 return -3;
89} 89}
90 90
91ssize_t scan_urlencoded_query(char **string, char *deststring, SCAN_SEARCHPATH_FLAG flags) { 91ssize_t urlencoded_parse(char **string, char *deststring, SCAN_SEARCHPATH_FLAG flags) {
92 const unsigned char *s = *(const unsigned char **)string; 92 const unsigned char *s = *(const unsigned char **)string;
93 unsigned char *d = (unsigned char *)deststring; 93 unsigned char *d = (unsigned char *)deststring;
94 unsigned char b, c; 94 unsigned char b, c;
@@ -121,7 +121,7 @@ ssize_t scan_urlencoded_query(char **string, char *deststring, SCAN_SEARCHPATH_F
121 if (d == (unsigned char *)deststring) 121 if (d == (unsigned char *)deststring)
122 return -2; 122 return -2;
123 123
124 /* Else make the next call to scan_urlencoded_param encounter it again */ 124 /* Else make the next call to urlencoded_parse encounter it again */
125 --s; 125 --s;
126 break; 126 break;
127 case '?': 127 case '?':
diff --git a/scan_urlencoded_query.h b/ot_urlencoded.h
index 24e09fd..8147370 100644
--- a/scan_urlencoded_query.h
+++ b/ot_urlencoded.h
@@ -30,7 +30,7 @@ typedef enum {
30 or -1 for parse error 30 or -1 for parse error
31 or -2 for terminator found 31 or -2 for terminator found
32*/ 32*/
33ssize_t scan_urlencoded_query(char **string, char *deststring, SCAN_SEARCHPATH_FLAG flags); 33ssize_t urlencoded_parse(char **string, char *deststring, SCAN_SEARCHPATH_FLAG flags);
34 34
35/* string in: pointer to source 35/* string in: pointer to source
36 out: pointer to next scan position 36 out: pointer to next scan position
@@ -40,12 +40,12 @@ ssize_t scan_urlencoded_query(char **string, char *deststring, SCAN_SEARCHPATH_F
40 or -2 for terminator found 40 or -2 for terminator found
41 or -3 for no keyword matched 41 or -3 for no keyword matched
42 */ 42 */
43int scan_find_keywords(const ot_keywords *keywords, char **string, SCAN_SEARCHPATH_FLAG flags); 43int urlencoded_match_keyword(const ot_keywords *keywords, char **string, SCAN_SEARCHPATH_FLAG flags);
44 44
45/* string in: pointer to value of a param=value pair to skip 45/* string in: pointer to value of a param=value pair to skip
46 out: pointer to next scan position on return 46 out: pointer to next scan position on return
47*/ 47*/
48void scan_urlencoded_skipvalue(char **string); 48void urlencoded_skip_value(char **string);
49 49
50/* data pointer to len chars of string 50/* data pointer to len chars of string
51 len length of chars in data to parse 51 len length of chars in data to parse
diff --git a/tests/runner.c b/tests/runner.c
index 335d83d..9e5c99f 100644
--- a/tests/runner.c
+++ b/tests/runner.c
@@ -14,7 +14,7 @@ struct module {
14 void (*run)(void); 14 void (*run)(void);
15}; 15};
16 16
17static const struct module modules[] = {{"scan_urlencoded_query", test_scan_urlencoded_query}, 17static const struct module modules[] = {{"ot_urlencoded", test_urlencoded},
18 {"ot_iovec", test_iovec}, 18 {"ot_iovec", test_iovec},
19 {"ot_vector", test_vector}, 19 {"ot_vector", test_vector},
20 {"ot_random", test_random}, 20 {"ot_random", test_random},
diff --git a/tests/t_hex.c b/tests/t_hex.c
index 7cce8ac..a761737 100644
--- a/tests/t_hex.c
+++ b/tests/t_hex.c
@@ -18,7 +18,7 @@ static void case_encode(void) {
18 18
19 test_case("a hash encodes to forty upper case digits and a terminator"); 19 test_case("a hash encodes to forty upper case digits and a terminator");
20 memset(dest, 0x7f, sizeof(dest)); 20 memset(dest, 0x7f, sizeof(dest));
21 CHECK_PTR(hex_fromhash(dest, sample), dest); 21 CHECK_PTR(hex_from_hash(dest, sample), dest);
22 CHECK_STR(dest, "000123456789ABCDEFFF10203040506070809" "0A0"); 22 CHECK_STR(dest, "000123456789ABCDEFFF10203040506070809" "0A0");
23 CHECK_INT(strlen(dest), 40); 23 CHECK_INT(strlen(dest), 40);
24 CHECK_INT((unsigned char)dest[41], 0x7f); 24 CHECK_INT((unsigned char)dest[41], 0x7f);
@@ -28,7 +28,7 @@ static void case_decode(void) {
28 ot_hash hash; 28 ot_hash hash;
29 29
30 test_case("forty digits decode back to the hash"); 30 test_case("forty digits decode back to the hash");
31 CHECK(hex_tohash(hash, "000123456789ABCDEFFF10203040506070809" "0A0")); 31 CHECK(hex_to_hash(hash, "000123456789ABCDEFFF10203040506070809" "0A0"));
32 CHECK_MEM(hash, sample, sizeof(sample)); 32 CHECK_MEM(hash, sample, sizeof(sample));
33} 33}
34 34
@@ -41,8 +41,8 @@ static void case_round_trip(void) {
41 for (i = 0; i < 256; ++i) { 41 for (i = 0; i < 256; ++i) {
42 uint8_t probe[20]; 42 uint8_t probe[20];
43 memset(probe, (uint8_t)i, sizeof(probe)); 43 memset(probe, (uint8_t)i, sizeof(probe));
44 hex_fromhash(text, probe); 44 hex_from_hash(text, probe);
45 if (!hex_tohash(hash, text) || memcmp(hash, probe, sizeof(probe))) { 45 if (!hex_to_hash(hash, text) || memcmp(hash, probe, sizeof(probe))) {
46 test_failf(__FILE__, __LINE__, "round trip failed for byte value %zu", i); 46 test_failf(__FILE__, __LINE__, "round trip failed for byte value %zu", i);
47 return; 47 return;
48 } 48 }
@@ -54,8 +54,8 @@ static void case_decode_is_case_insensitive(void) {
54 ot_hash upper, lower; 54 ot_hash upper, lower;
55 55
56 test_case("lower case digits decode the same as upper case"); 56 test_case("lower case digits decode the same as upper case");
57 CHECK(hex_tohash(upper, "ABCDEF0123456789ABCDEF0123456789ABCDEF01")); 57 CHECK(hex_to_hash(upper, "ABCDEF0123456789ABCDEF0123456789ABCDEF01"));
58 CHECK(hex_tohash(lower, "abcdef0123456789abcdef0123456789abcdef01")); 58 CHECK(hex_to_hash(lower, "abcdef0123456789abcdef0123456789abcdef01"));
59 CHECK_MEM(lower, upper, sizeof(ot_hash)); 59 CHECK_MEM(lower, upper, sizeof(ot_hash));
60} 60}
61 61
@@ -63,18 +63,18 @@ static void case_rejects_non_digits(void) {
63 ot_hash hash; 63 ot_hash hash;
64 64
65 test_case("a non hex character anywhere rejects the whole string"); 65 test_case("a non hex character anywhere rejects the whole string");
66 CHECK_INT(hex_tohash(hash, "g00123456789ABCDEFFF102030405060708090A0"), 0); 66 CHECK_INT(hex_to_hash(hash, "g00123456789ABCDEFFF102030405060708090A0"), 0);
67 CHECK_INT(hex_tohash(hash, "000123456789ABCDEFFF102030405060708090Ag"), 0); 67 CHECK_INT(hex_to_hash(hash, "000123456789ABCDEFFF102030405060708090Ag"), 0);
68 CHECK_INT(hex_tohash(hash, "000123456789ABCDEF:F102030405060708090A"), 0); 68 CHECK_INT(hex_to_hash(hash, "000123456789ABCDEF:F102030405060708090A"), 0);
69} 69}
70 70
71static void case_rejects_short_input(void) { 71static void case_rejects_short_input(void) {
72 ot_hash hash; 72 ot_hash hash;
73 73
74 test_case("a string shorter than forty digits is rejected"); 74 test_case("a string shorter than forty digits is rejected");
75 CHECK_INT(hex_tohash(hash, ""), 0); 75 CHECK_INT(hex_to_hash(hash, ""), 0);
76 CHECK_INT(hex_tohash(hash, "00"), 0); 76 CHECK_INT(hex_to_hash(hash, "00"), 0);
77 CHECK_INT(hex_tohash(hash, "000123456789ABCDEFFF102030405060708090A"), 0); 77 CHECK_INT(hex_to_hash(hash, "000123456789ABCDEFFF102030405060708090A"), 0);
78} 78}
79 79
80static void case_leaves_hash_untouched_on_failure(void) { 80static void case_leaves_hash_untouched_on_failure(void) {
@@ -82,7 +82,7 @@ static void case_leaves_hash_untouched_on_failure(void) {
82 82
83 test_case("a rejected string leaves the destination untouched"); 83 test_case("a rejected string leaves the destination untouched");
84 memset(hash, 0x5a, sizeof(hash)); 84 memset(hash, 0x5a, sizeof(hash));
85 CHECK_INT(hex_tohash(hash, "000123456789ABCDEFFF10203040506070809XX0"), 0); 85 CHECK_INT(hex_to_hash(hash, "000123456789ABCDEFFF10203040506070809XX0"), 0);
86 CHECK_MEM(hash, "\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a", sizeof(hash)); 86 CHECK_MEM(hash, "\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a", sizeof(hash));
87} 87}
88 88
@@ -96,7 +96,7 @@ static void case_stops_at_the_terminator(void) {
96 memcpy(guarded, "0012", 4); 96 memcpy(guarded, "0012", 4);
97 guarded[4] = 0; 97 guarded[4] = 0;
98 memset(guarded + 5, 'f', 3); 98 memset(guarded + 5, 'f', 3);
99 CHECK_INT(hex_tohash(hash, guarded), 0); 99 CHECK_INT(hex_to_hash(hash, guarded), 0);
100} 100}
101 101
102static void case_isdigit(void) { 102static void case_isdigit(void) {
diff --git a/tests/t_iovec.c b/tests/t_iovec.c
index 89f3fda..2553141 100644
--- a/tests/t_iovec.c
+++ b/tests/t_iovec.c
@@ -18,13 +18,13 @@ static void case_increase_and_length(void) {
18 void *first, *second; 18 void *first, *second;
19 19
20 test_case("increase appends an entry and length is their sum"); 20 test_case("increase appends an entry and length is their sum");
21 first = iovec_increase(&entries, &vector, 100); 21 first = iovec_new_chunk(&entries, &vector, 100);
22 CHECK(first != NULL); 22 CHECK(first != NULL);
23 CHECK_INT(entries, 1); 23 CHECK_INT(entries, 1);
24 CHECK_INT(vector[0].iov_len, 100); 24 CHECK_INT(vector[0].iov_len, 100);
25 CHECK_PTR(vector[0].iov_base, first); 25 CHECK_PTR(vector[0].iov_base, first);
26 26
27 second = iovec_increase(&entries, &vector, 50); 27 second = iovec_new_chunk(&entries, &vector, 50);
28 CHECK(second != NULL); 28 CHECK(second != NULL);
29 CHECK_INT(entries, 2); 29 CHECK_INT(entries, 2);
30 CHECK_INT(vector[1].iov_len, 50); 30 CHECK_INT(vector[1].iov_len, 50);
@@ -38,8 +38,8 @@ static void case_free_resets(void) {
38 struct iovec *vector = NULL; 38 struct iovec *vector = NULL;
39 39
40 test_case("free releases the entries and resets the vector"); 40 test_case("free releases the entries and resets the vector");
41 CHECK(iovec_increase(&entries, &vector, 10) != NULL); 41 CHECK(iovec_new_chunk(&entries, &vector, 10) != NULL);
42 CHECK(iovec_increase(&entries, &vector, 10) != NULL); 42 CHECK(iovec_new_chunk(&entries, &vector, 10) != NULL);
43 iovec_free(&entries, &vector); 43 iovec_free(&entries, &vector);
44 CHECK_INT(entries, 0); 44 CHECK_INT(entries, 0);
45 CHECK_PTR(vector, NULL); 45 CHECK_PTR(vector, NULL);
@@ -52,12 +52,12 @@ static void case_fixlast_shrinks(void) {
52 char *block; 52 char *block;
53 53
54 test_case("fixlast trims the last entry to the bytes actually used"); 54 test_case("fixlast trims the last entry to the bytes actually used");
55 CHECK(iovec_increase(&entries, &vector, 64) != NULL); 55 CHECK(iovec_new_chunk(&entries, &vector, 64) != NULL);
56 block = iovec_increase(&entries, &vector, 1000); 56 block = iovec_new_chunk(&entries, &vector, 1000);
57 CHECK(block != NULL); 57 CHECK(block != NULL);
58 memset(block, 'x', 20); 58 memset(block, 'x', 20);
59 59
60 iovec_fixlast(&entries, &vector, block + 20); 60 iovec_trim_last(&entries, &vector, block + 20);
61 CHECK_INT(entries, 2); 61 CHECK_INT(entries, 2);
62 CHECK_INT(vector[1].iov_len, 20); 62 CHECK_INT(vector[1].iov_len, 20);
63 CHECK_INT(iovec_length(&entries, (const struct iovec **)&vector), 84); 63 CHECK_INT(iovec_length(&entries, (const struct iovec **)&vector), 84);
@@ -71,7 +71,7 @@ static void case_fixlast_on_empty(void) {
71 struct iovec *vector = NULL; 71 struct iovec *vector = NULL;
72 72
73 test_case("fixlast on an empty vector does nothing"); 73 test_case("fixlast on an empty vector does nothing");
74 iovec_fixlast(&entries, &vector, NULL); 74 iovec_trim_last(&entries, &vector, NULL);
75 CHECK_INT(entries, 0); 75 CHECK_INT(entries, 0);
76 CHECK_PTR(vector, NULL); 76 CHECK_PTR(vector, NULL);
77} 77}
@@ -103,9 +103,9 @@ static void case_fix_increase(void) {
103 char *block; 103 char *block;
104 104
105 test_case("fix_increase trims the previous entry and adds a new one"); 105 test_case("fix_increase trims the previous entry and adds a new one");
106 block = iovec_increase(&entries, &vector, 500); 106 block = iovec_new_chunk(&entries, &vector, 500);
107 CHECK(block != NULL); 107 CHECK(block != NULL);
108 block = iovec_fix_increase_or_free(&entries, &vector, block + 30, 200); 108 block = iovec_next_chunk(&entries, &vector, block + 30, 200);
109 CHECK(block != NULL); 109 CHECK(block != NULL);
110 CHECK_INT(entries, 2); 110 CHECK_INT(entries, 2);
111 CHECK_INT(vector[0].iov_len, 30); 111 CHECK_INT(vector[0].iov_len, 30);
diff --git a/tests/t_scan_urlencoded_query.c b/tests/t_urlencoded.c
index cb6c982..1239e6b 100644
--- a/tests/t_scan_urlencoded_query.c
+++ b/tests/t_urlencoded.c
@@ -7,7 +7,7 @@
7#include <string.h> 7#include <string.h>
8 8
9/* Opentracker */ 9/* Opentracker */
10#include "scan_urlencoded_query.h" 10#include "ot_urlencoded.h"
11#include "test.h" 11#include "test.h"
12 12
13/* The scanner returns the number of bytes written to the destination, or 13/* The scanner returns the number of bytes written to the destination, or
@@ -23,7 +23,7 @@ static void case_path(void) {
23 ssize_t n; 23 ssize_t n;
24 24
25 test_case("path stops at the question mark"); 25 test_case("path stops at the question mark");
26 n = scan_urlencoded_query(&p, dest, SCAN_PATH); 26 n = urlencoded_parse(&p, dest, SCAN_PATH);
27 CHECK_INT(n, 9); 27 CHECK_INT(n, 9);
28 dest[n] = 0; 28 dest[n] = 0;
29 CHECK_STR(dest, "/announce"); 29 CHECK_STR(dest, "/announce");
@@ -37,22 +37,22 @@ static void case_param_and_value(void) {
37 ssize_t n; 37 ssize_t n;
38 38
39 test_case("parameter stops at '=', value stops at '&'"); 39 test_case("parameter stops at '=', value stops at '&'");
40 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_PARAM); 40 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_PARAM);
41 CHECK_INT(n, 9); 41 CHECK_INT(n, 9);
42 dest[n] = 0; 42 dest[n] = 0;
43 CHECK_STR(dest, "info_hash"); 43 CHECK_STR(dest, "info_hash");
44 44
45 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_VALUE); 45 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_VALUE);
46 CHECK_INT(n, 3); 46 CHECK_INT(n, 3);
47 dest[n] = 0; 47 dest[n] = 0;
48 CHECK_STR(dest, "abc"); 48 CHECK_STR(dest, "abc");
49 49
50 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_PARAM); 50 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_PARAM);
51 CHECK_INT(n, 4); 51 CHECK_INT(n, 4);
52 dest[n] = 0; 52 dest[n] = 0;
53 CHECK_STR(dest, "port"); 53 CHECK_STR(dest, "port");
54 54
55 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_VALUE); 55 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_VALUE);
56 CHECK_INT(n, 2); 56 CHECK_INT(n, 2);
57 dest[n] = 0; 57 dest[n] = 0;
58 CHECK_STR(dest, "80"); 58 CHECK_STR(dest, "80");
@@ -65,7 +65,7 @@ static void case_percent_decoding(void) {
65 ssize_t n; 65 ssize_t n;
66 66
67 test_case("percent escapes decode"); 67 test_case("percent escapes decode");
68 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_VALUE); 68 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_VALUE);
69 CHECK_INT(n, 3); 69 CHECK_INT(n, 3);
70 CHECK_MEM(dest, "ABC", 3); 70 CHECK_MEM(dest, "ABC", 3);
71} 71}
@@ -79,7 +79,7 @@ static void case_binary_info_hash(void) {
79 ssize_t n; 79 ssize_t n;
80 80
81 test_case("twenty byte binary value survives decoding"); 81 test_case("twenty byte binary value survives decoding");
82 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_VALUE); 82 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_VALUE);
83 CHECK_INT(n, 20); 83 CHECK_INT(n, 20);
84 CHECK_MEM(dest, want, 20); 84 CHECK_MEM(dest, want, 20);
85} 85}
@@ -90,7 +90,7 @@ static void case_in_place(void) {
90 ssize_t n; 90 ssize_t n;
91 91
92 test_case("decoding in place over the source is safe"); 92 test_case("decoding in place over the source is safe");
93 n = scan_urlencoded_query(&p, query, SCAN_SEARCHPATH_VALUE); 93 n = urlencoded_parse(&p, query, SCAN_SEARCHPATH_VALUE);
94 CHECK_INT(n, 2); 94 CHECK_INT(n, 2);
95 CHECK_MEM(query, "AB", 2); 95 CHECK_MEM(query, "AB", 2);
96} 96}
@@ -102,7 +102,7 @@ static void case_bad_escape(void) {
102 ssize_t n; 102 ssize_t n;
103 103
104 test_case("a non hexadecimal escape is a parse error"); 104 test_case("a non hexadecimal escape is a parse error");
105 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_VALUE); 105 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_VALUE);
106 CHECK_INT(n, -1); 106 CHECK_INT(n, -1);
107} 107}
108 108
@@ -113,7 +113,7 @@ static void case_truncated_escape(void) {
113 ssize_t n; 113 ssize_t n;
114 114
115 test_case("an escape cut short by the terminator is a parse error"); 115 test_case("an escape cut short by the terminator is a parse error");
116 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_VALUE); 116 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_VALUE);
117 CHECK_INT(n, -1); 117 CHECK_INT(n, -1);
118} 118}
119 119
@@ -125,11 +125,11 @@ static void case_terminator(void) {
125 ssize_t n; 125 ssize_t n;
126 126
127 test_case("a hard terminator before any output reports end of input"); 127 test_case("a hard terminator before any output reports end of input");
128 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_PARAM); 128 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_PARAM);
129 CHECK_INT(n, -2); 129 CHECK_INT(n, -2);
130 130
131 p = space; 131 p = space;
132 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_PARAM); 132 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_PARAM);
133 CHECK_INT(n, -2); 133 CHECK_INT(n, -2);
134} 134}
135 135
@@ -140,10 +140,10 @@ static void case_terminator_after_output(void) {
140 ssize_t n; 140 ssize_t n;
141 141
142 test_case("a hard terminator after output is left for the next call"); 142 test_case("a hard terminator after output is left for the next call");
143 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_VALUE); 143 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_VALUE);
144 CHECK_INT(n, 3); 144 CHECK_INT(n, 3);
145 CHECK_INT(*p, 0); 145 CHECK_INT(*p, 0);
146 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_VALUE); 146 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_VALUE);
147 CHECK_INT(n, -2); 147 CHECK_INT(n, -2);
148} 148}
149 149
@@ -159,14 +159,14 @@ static void case_separators_are_contextual(void) {
159 ssize_t n; 159 ssize_t n;
160 160
161 test_case("a question mark is literal inside a value"); 161 test_case("a question mark is literal inside a value");
162 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_VALUE); 162 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_VALUE);
163 CHECK_INT(n, 3); 163 CHECK_INT(n, 3);
164 dest[n] = 0; 164 dest[n] = 0;
165 CHECK_STR(dest, "a?b"); 165 CHECK_STR(dest, "a?b");
166 166
167 test_case("an equals sign is literal inside a value"); 167 test_case("an equals sign is literal inside a value");
168 p = equals; 168 p = equals;
169 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_VALUE); 169 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_VALUE);
170 CHECK_INT(n, 3); 170 CHECK_INT(n, 3);
171 dest[n] = 0; 171 dest[n] = 0;
172 CHECK_STR(dest, "a=b"); 172 CHECK_STR(dest, "a=b");
@@ -179,7 +179,7 @@ static void case_ampersand_in_path(void) {
179 ssize_t n; 179 ssize_t n;
180 180
181 test_case("an ampersand in a path is a parse error"); 181 test_case("an ampersand in a path is a parse error");
182 n = scan_urlencoded_query(&p, dest, SCAN_PATH); 182 n = urlencoded_parse(&p, dest, SCAN_PATH);
183 CHECK_INT(n, -1); 183 CHECK_INT(n, -1);
184} 184}
185 185
@@ -190,7 +190,7 @@ static void case_raw_high_byte(void) {
190 ssize_t n; 190 ssize_t n;
191 191
192 test_case("an undecoded byte above ASCII is a parse error"); 192 test_case("an undecoded byte above ASCII is a parse error");
193 n = scan_urlencoded_query(&p, dest, SCAN_SEARCHPATH_VALUE); 193 n = urlencoded_parse(&p, dest, SCAN_SEARCHPATH_VALUE);
194 CHECK_INT(n, -1); 194 CHECK_INT(n, -1);
195} 195}
196 196
@@ -200,12 +200,12 @@ static void case_skipvalue(void) {
200 char *p = query; 200 char *p = query;
201 201
202 test_case("skipvalue steps over the value and its separator"); 202 test_case("skipvalue steps over the value and its separator");
203 scan_urlencoded_skipvalue(&p); 203 urlencoded_skip_value(&p);
204 CHECK_STR(p, "next=1"); 204 CHECK_STR(p, "next=1");
205 205
206 test_case("skipvalue leaves a hard terminator in place"); 206 test_case("skipvalue leaves a hard terminator in place");
207 p = bare; 207 p = bare;
208 scan_urlencoded_skipvalue(&p); 208 urlencoded_skip_value(&p);
209 CHECK_INT(*p, 0); 209 CHECK_INT(*p, 0);
210} 210}
211 211
@@ -217,15 +217,15 @@ static void case_find_keywords(void) {
217 char *p = match; 217 char *p = match;
218 218
219 test_case("a known keyword returns its value"); 219 test_case("a known keyword returns its value");
220 CHECK_INT(scan_find_keywords(keywords, &p, SCAN_SEARCHPATH_PARAM), 2); 220 CHECK_INT(urlencoded_match_keyword(keywords, &p, SCAN_SEARCHPATH_PARAM), 2);
221 221
222 test_case("an unknown keyword returns -3"); 222 test_case("an unknown keyword returns -3");
223 p = nomatch; 223 p = nomatch;
224 CHECK_INT(scan_find_keywords(keywords, &p, SCAN_SEARCHPATH_PARAM), -3); 224 CHECK_INT(urlencoded_match_keyword(keywords, &p, SCAN_SEARCHPATH_PARAM), -3);
225 225
226 test_case("a prefix of a keyword does not match it"); 226 test_case("a prefix of a keyword does not match it");
227 p = prefix; 227 p = prefix;
228 CHECK_INT(scan_find_keywords(keywords, &p, SCAN_SEARCHPATH_PARAM), -3); 228 CHECK_INT(urlencoded_match_keyword(keywords, &p, SCAN_SEARCHPATH_PARAM), -3);
229} 229}
230 230
231static void case_fixed_int(void) { 231static void case_fixed_int(void) {
@@ -328,7 +328,7 @@ static void case_fmt_decoder_disagrees_on_dollar(void) {
328 encoder passes through unescaped, '$' is the only one the decoder then 328 encoder passes through unescaped, '$' is the only one the decoder then
329 refuses, and it refuses the whole string rather than stopping short. 329 refuses, and it refuses the whole string rather than stopping short.
330 Output of the urlencoded full scrape therefore does not round trip 330 Output of the urlencoded full scrape therefore does not round trip
331 through scan_urlencoded_query when a hash contains 0x24. Harmless today 331 through urlencoded_parse when a hash contains 0x24. Harmless today
332 because only third party tooling reads that output. */ 332 because only third party tooling reads that output. */
333 const uint8_t src[] = {'a', '$', 'b'}; 333 const uint8_t src[] = {'a', '$', 'b'};
334 char dest[16]; 334 char dest[16];
@@ -342,11 +342,11 @@ static void case_fmt_decoder_disagrees_on_dollar(void) {
342 dest[n] = 0; 342 dest[n] = 0;
343 CHECK_STR(dest, "a$b"); 343 CHECK_STR(dest, "a$b");
344 344
345 got = scan_urlencoded_query(&p, scanned, SCAN_SEARCHPATH_VALUE); 345 got = urlencoded_parse(&p, scanned, SCAN_SEARCHPATH_VALUE);
346 CHECK_INT(got, -1); 346 CHECK_INT(got, -1);
347} 347}
348 348
349void test_scan_urlencoded_query(void) { 349void test_urlencoded(void) {
350 case_path(); 350 case_path();
351 case_param_and_value(); 351 case_param_and_value();
352 case_percent_decoding(); 352 case_percent_decoding();
diff --git a/tests/test.h b/tests/test.h
index bc8c3bd..cebd08a 100644
--- a/tests/test.h
+++ b/tests/test.h
@@ -76,7 +76,7 @@ extern unsigned long test_failures;
76 } while (0) 76 } while (0)
77 77
78/* One entry point per module under test */ 78/* One entry point per module under test */
79void test_scan_urlencoded_query(void); 79void test_urlencoded(void);
80void test_iovec(void); 80void test_iovec(void);
81void test_vector(void); 81void test_vector(void);
82void test_random(void); 82void test_random(void);