From 212eeb073e61928227ab34c40ea8f5c300d7a924 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 26 Oct 2011 14:04:28 +0100 Subject: [PATCH] adding dlight-dlhist-read --- Makefile | 5 ++++- dlhist-read.c | 15 +++++++++++++++ dlhist.c | 40 ++++++++++++++++++++++++++++++++++++++++ dlhist.h | 4 ++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 dlhist-read.c diff --git a/Makefile b/Makefile index 6a1bcd4..3424e29 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,9 @@ CC = gcc LDFLAGS = -lxml2 -lcurl -lpcre CFLAGS = -g -Wall -I/usr/include/libxml2 -PROGRAMS = dlight dlight-compile dlight-read-config dlight-filter-check + +PROGRAMS = dlight dlight-compile dlight-read-config dlight-filter-check \ + dlight-dlhist-read ifeq ($(DEBUG), 1) CFLAGS +=-D__DEBUG__ @@ -26,6 +28,7 @@ dlight-compile : compile.o buffer.o env.o lockfile.o filter.o cconf.o \ error.o version.o dlight-read-config : read-config.o buffer.o env.o cconf.o error.o version.o dlight-filter-check: filter-check.o filter.o error.o version.o +dlight-dlhist-read : dlhist-read.o buffer.o utils.o env.o error.o lockfile.o dlhist.o dlight-% : %.o $(CC) $(LDFLAGS) -o $@ $^ diff --git a/dlhist-read.c b/dlhist-read.c new file mode 100644 index 0000000..45def0e --- /dev/null +++ b/dlhist-read.c @@ -0,0 +1,15 @@ + +#include +#include "dlhist.h" + +int main() { + + if (dlhist_open() < 0) + return 1; + + dlhist_print(); + + dlhist_close(); + + return 0; +} diff --git a/dlhist.c b/dlhist.c index 61f49f3..b787121 100644 --- a/dlhist.c +++ b/dlhist.c @@ -443,3 +443,43 @@ void dlhist_close() { table = NULL; table_count = table_size = 0; } + +static const char hexmap[16] = { + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' +}; + +static const char* sha1_to_hex(const unsigned char *sha1) { + + int i; + static char hex[41]; + char *h = hex; + + for(i=0; i < 20; i++) { + unsigned char v = *sha1++; + *h++ = hexmap[v >> 4]; + *h++ = hexmap[v & 15]; + } + return hex; +} + + +void dlhist_print() { + + int i, j; + + for(i=0; i < table_size; i++) { + struct hash_entry *entry = table + i; + + if (he_empty(entry)) + continue; + + printf("%10u %40s\n", entry->key, sha1_to_hex(entry->key)); + + for(j=0; j < entry->dest_nr; j++) { + struct destination *dest = entry->dest + j; + + printf("\t%10u %s\n", dest->time, dest->path); + } + } +} diff --git a/dlhist.h b/dlhist.h index b62db4a..787cafa 100644 --- a/dlhist.h +++ b/dlhist.h @@ -30,4 +30,8 @@ void dlhist_purge(unsigned int interval); void dlhist_close(void); +void dlhist_close(); + +void dlhist_print(); + #endif /* DLHIST_H */