Archived
1
0
Fork 0

adding dlight-dlhist-read

This commit is contained in:
Henrik Hautakoski 2011-10-26 14:04:28 +01:00
parent 697d512ea6
commit 212eeb073e
4 changed files with 63 additions and 1 deletions

View file

@ -9,7 +9,9 @@ CC = gcc
LDFLAGS = -lxml2 -lcurl -lpcre LDFLAGS = -lxml2 -lcurl -lpcre
CFLAGS = -g -Wall -I/usr/include/libxml2 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) ifeq ($(DEBUG), 1)
CFLAGS +=-D__DEBUG__ 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 error.o version.o
dlight-read-config : read-config.o buffer.o env.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-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 dlight-% : %.o
$(CC) $(LDFLAGS) -o $@ $^ $(CC) $(LDFLAGS) -o $@ $^

15
dlhist-read.c Normal file
View file

@ -0,0 +1,15 @@
#include <stdio.h>
#include "dlhist.h"
int main() {
if (dlhist_open() < 0)
return 1;
dlhist_print();
dlhist_close();
return 0;
}

View file

@ -443,3 +443,43 @@ void dlhist_close() {
table = NULL; table = NULL;
table_count = table_size = 0; 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);
}
}
}

View file

@ -30,4 +30,8 @@ void dlhist_purge(unsigned int interval);
void dlhist_close(void); void dlhist_close(void);
void dlhist_close();
void dlhist_print();
#endif /* DLHIST_H */ #endif /* DLHIST_H */