From 168285b4569f862443419a2bffe221e1a8ab8150 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 24 Oct 2026 02:04:33 +0200 Subject: Replace all manual hex conversion with the new helper --- ot_accesslist.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'ot_accesslist.c') diff --git a/ot_accesslist.c b/ot_accesslist.c index 2827494..ee6adb2 100644 --- a/ot_accesslist.c +++ b/ot_accesslist.c @@ -20,10 +20,10 @@ #include "fmt.h" #include "ip6.h" #include "mmap.h" -#include "scan.h" /* Opentracker */ #include "ot_accesslist.h" +#include "ot_hex.h" #include "ot_vector.h" #include "trackerlogic.h" @@ -128,20 +128,11 @@ static void accesslist_readfile(void) { /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */ while (read_offs <= map_end) { - size_t i; - for (i = 0; i < sizeof(ot_hash); ++i) { - int eger1 = scan_fromhex((unsigned char)read_offs[2 * i]); - int eger2 = scan_fromhex((unsigned char)read_offs[1 + 2 * i]); - if (eger1 < 0 || eger2 < 0) - break; - (*info_hash)[i] = (uint8_t)(eger1 * 16 + eger2); - } - - if (i == sizeof(ot_hash)) { + if (hex_tohash(*info_hash, read_offs)) { read_offs += 40; /* Append accesslist to accesslist vector */ - if (read_offs == map_end || scan_fromhex((unsigned char)*read_offs) < 0) + if (read_offs == map_end || !hex_isdigit((unsigned char)*read_offs)) ++info_hash; } @@ -261,7 +252,6 @@ static void *accesslist_adddel_worker(char *fifoname, ot_accesslist *_Atomic while ((linelen = getline(&line, &linecap, fifo)) > 0) { ot_hash info_hash; - size_t i; printf("Got line %*s", (int)linelen, line); /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" @@ -269,15 +259,7 @@ static void *accesslist_adddel_worker(char *fifoname, ot_accesslist *_Atomic if (linelen < 41) continue; - for (i = 0; i < sizeof(ot_hash); ++i) { - int eger1 = scan_fromhex((unsigned char)line[2 * i]); - int eger2 = scan_fromhex((unsigned char)line[1 + 2 * i]); - if (eger1 < 0 || eger2 < 0) - break; - ((uint8_t *)info_hash)[i] = (uint8_t)(eger1 * 16 + eger2); - } - printf("parsed info_hash %20s\n", info_hash); - if (i != sizeof(ot_hash)) + if (!hex_tohash(info_hash, line)) continue; /* From now on we modify g_accesslist_add and g_accesslist_delete, so prevent the -- cgit v1.3