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_stats.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'ot_stats.c') diff --git a/ot_stats.c b/ot_stats.c index afc972a..d43f29c 100644 --- a/ot_stats.c +++ b/ot_stats.c @@ -23,6 +23,7 @@ /* Opentracker */ #include "ot_accesslist.h" +#include "ot_hex.h" #include "ot_iovec.h" #include "ot_mutex.h" #include "ot_stats.h" @@ -295,18 +296,6 @@ static int torrent_statter(ot_torrent *torrent, uintptr_t data) { } /* Converter function from memory to human readable hex strings */ -static char *to_hex(char *d, uint8_t *s) { - char *m = "0123456789ABCDEF"; - char *t = d; - char *e = d + 40; - while (d < e) { - *d++ = m[*s >> 4]; - *d++ = m[*s++ & 15]; - } - *d = 0; - return t; -} - typedef struct { size_t val; ot_hash hash; @@ -361,15 +350,15 @@ size_t stats_top_txt(char *reply, size_t amount) { r += sprintf(r, "Top %zd torrents by peers:\n", amount); for (idx = 0; idx < amount; ++idx) if (top100c[idx].val) - r += sprintf(r, "\t%zd\t%s\n", top100c[idx].val, to_hex(hex_out, top100c[idx].hash)); + r += sprintf(r, "\t%zd\t%s\n", top100c[idx].val, hex_fromhash(hex_out, top100c[idx].hash)); r += sprintf(r, "Top %zd torrents by seeds:\n", amount); for (idx = 0; idx < amount; ++idx) if (top100s[idx].val) - r += sprintf(r, "\t%zd\t%s\n", top100s[idx].val, to_hex(hex_out, top100s[idx].hash)); + r += sprintf(r, "\t%zd\t%s\n", top100s[idx].val, hex_fromhash(hex_out, top100s[idx].hash)); r += sprintf(r, "Top %zd torrents by leechers:\n", amount); for (idx = 0; idx < amount; ++idx) if (top100l[idx].val) - r += sprintf(r, "\t%zd\t%s\n", top100l[idx].val, to_hex(hex_out, top100l[idx].hash)); + r += sprintf(r, "\t%zd\t%s\n", top100l[idx].val, hex_fromhash(hex_out, top100l[idx].hash)); return r - reply; } @@ -667,9 +656,9 @@ void stats_issue_event(ot_status_event event, PROTO_FLAG proto, uintptr_t event_ localtime_r(&ttt, &time_now); strftime(timestring, sizeof(timestring), "%FT%T%z", &time_now); - to_hex(hash_hex, *ws->hash); + hex_fromhash(hash_hex, *ws->hash); if (ws->peer_id) - to_hex(peerid_hex, (uint8_t *)ws->peer_id); + hex_fromhash(peerid_hex, (uint8_t *)ws->peer_id); else { *peerid_hex = 0; } -- cgit v1.3