From 78c3cebc389a2b0d426d74900a65b8656edb426d Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 26 Oct 2026 18:13:27 +0100 Subject: Third run of making variable and function names more readable, integer scans and ip parsers --- ot_http.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'ot_http.c') diff --git a/ot_http.c b/ot_http.c index 6c3332c..3c135cb 100644 --- a/ot_http.c +++ b/ot_http.c @@ -482,7 +482,8 @@ static ot_keywords keywords_announce[] = {{"port", 1}, {"left", 2}, {"event", static ot_keywords keywords_announce_event[] = {{"completed", 1}, {"stopped", 2}, {NULL, -3}}; static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct *ws, char *read_ptr) { size_t numwant; - int tmp, scanon; + int64_t tmp; + int scanon; unsigned short port = 0; char *write_ptr; ssize_t len; @@ -501,7 +502,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct if (accesslist_is_blessed(cookie->ip, OT_PERMISSION_MAY_PROXY)) { ot_ip6 proxied_ip; char *fwd = http_header(ws->request, ws->header_size, "x-forwarded-for"); - if (fwd && ip_scan(fwd, proxied_ip)) { + if (fwd && ip_parse(fwd, proxied_ip)) { OT_SETIP(ws->peer, proxied_ip); } else OT_SETIP(ws->peer, cookie->ip); @@ -529,15 +530,15 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct break; case 1: /* matched "port" */ len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); - if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp) || (tmp > 0xffff)) + if ((len <= 0) || scan_int(write_ptr, len, &tmp) || (tmp > 0xffff)) HTTPERROR_400_PARAM; - port = htons(tmp); + port = htons((uint16_t)tmp); OT_SETPORT(&ws->peer, &port); break; case 2: /* matched "left" */ if ((len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE)) <= 0) HTTPERROR_400_PARAM; - if (scan_fixed_int(write_ptr, len, &tmp)) + if (scan_int(write_ptr, len, &tmp)) tmp = 0; if (!tmp) OT_PEERFLAG(&ws->peer) |= PEER_FLAG_SEEDING; @@ -558,17 +559,17 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct break; case 4: /* matched "numwant" */ len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); - if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp)) + if ((len <= 0) || scan_int(write_ptr, len, &tmp)) HTTPERROR_400_PARAM; if (tmp < 0) tmp = 50; if (tmp > 200) tmp = 200; - numwant = tmp; + numwant = (size_t)tmp; break; case 5: /* matched "compact" */ len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); - if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp)) + if ((len <= 0) || scan_int(write_ptr, len, &tmp)) HTTPERROR_400_PARAM; if (!tmp) HTTPERROR_400_COMPACT; @@ -587,7 +588,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct char *tmp_buf1 = ws->reply, *tmp_buf2 = ws->reply + 16; len = urlencoded_parse(&read_ptr, tmp_buf2, SCAN_SEARCHPATH_VALUE); tmp_buf2[len] = 0; - if ((len <= 0) || !ip_scan(tmp_buf2, tmp_buf1)) + if ((len <= 0) || !ip_parse(tmp_buf2, tmp_buf1)) HTTPERROR_400_PARAM; OT_SETIP(&ws->peer, tmp_buf1); } break; @@ -609,13 +610,13 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct loglist_reset(); return ws->reply_size = sprintf(ws->reply, "Successfully removed.\n"); } - parsed = ip_scan(tmp_buf, net.address); + parsed = ip_parse(tmp_buf, net.address); if (!parsed) HTTPERROR_400_PARAM; if (tmp_buf[parsed++] != '/') bits = 128; else { - parsed = scan_udec(tmp_buf + parsed, &value, 128); + parsed = scan_uint(tmp_buf + parsed, &value, 128); if (!parsed) HTTPERROR_400_PARAM; bits = (signed short)value; -- cgit v1.3