From 131211b4daf83b7c594337f4e7c71e4711094d71 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Tue, 13 Jan 2009 22:41:17 +0000 Subject: V6 --- ot_accesslist.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'ot_accesslist.c') diff --git a/ot_accesslist.c b/ot_accesslist.c index 0cb6fe7..304b3f1 100644 --- a/ot_accesslist.c +++ b/ot_accesslist.c @@ -8,10 +8,12 @@ #include #include #include +#include /* Libowfat */ #include "byte.h" #include "scan.h" +#include "ip6.h" /* Opentracker */ #include "trackerlogic.h" @@ -32,14 +34,14 @@ void accesslist_deinit( void ) { accesslist_reset( ); } -static int accesslist_addentry( ot_hash *infohash ) { +static int accesslist_addentry( ot_hash infohash ) { int eger; void *insert = vector_find_or_insert( &accesslist, infohash, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &eger ); if( !insert ) return -1; - memmove( insert, infohash, OT_HASH_COMPARE_SIZE ); + memcpy( insert, infohash, OT_HASH_COMPARE_SIZE ); return 0; } @@ -64,7 +66,7 @@ static void accesslist_readfile( int foo ) { /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */ while( fgets( inbuf, sizeof(inbuf), accesslist_filehandle ) ) { int i; - for( i=0; i<20; ++i ) { + for( i=0; i<(int)sizeof(ot_hash); ++i ) { int eger = 16 * scan_fromhex( inbuf[ 2*i ] ) + scan_fromhex( inbuf[ 1 + 2*i ] ); if( eger < 0 ) continue; @@ -74,13 +76,13 @@ static void accesslist_readfile( int foo ) { continue; /* Append accesslist to accesslist vector */ - accesslist_addentry( &infohash ); + accesslist_addentry( infohash ); } fclose( accesslist_filehandle ); } -int accesslist_hashisvalid( ot_hash *hash ) { +int accesslist_hashisvalid( ot_hash hash ) { int exactmatch; binary_search( hash, accesslist.data, accesslist.size, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &exactmatch ); @@ -102,30 +104,39 @@ void accesslist_init( ) { } #endif -static uint32_t g_adminip_addresses[OT_ADMINIP_MAX]; +static ot_ip6 g_adminip_addresses[OT_ADMINIP_MAX]; static ot_permissions g_adminip_permissions[OT_ADMINIP_MAX]; static unsigned int g_adminip_count = 0; -int accesslist_blessip( char *ip, ot_permissions permissions ) { +int accesslist_blessip( ot_ip6 ip, ot_permissions permissions ) { if( g_adminip_count >= OT_ADMINIP_MAX ) return -1; - WRITE32(g_adminip_addresses + g_adminip_count,0,READ32(ip,0)); + + memcpy(g_adminip_addresses + g_adminip_count,ip,sizeof(ot_ip6)); g_adminip_permissions[ g_adminip_count++ ] = permissions; + #ifdef _DEBUG - uint8_t *_ip = (uint8_t*)ip; - fprintf( stderr, "Blessing ip address %d.%d.%d.%d with:", _ip[0], _ip[1], _ip[2], _ip[3]); - if( permissions & OT_PERMISSION_MAY_STAT ) fputs( " may_fetch_stats", stderr ); - if( permissions & OT_PERMISSION_MAY_LIVESYNC ) fputs( " may_sync_live", stderr ); - if( permissions & OT_PERMISSION_MAY_FULLSCRAPE ) fputs( " may_fetch_fullscrapes", stderr ); - if( !permissions ) fputs(" nothing.\n", stderr); else fputs(".\n", stderr ); + { + char _debug[512]; + int off = snprintf( _debug, sizeof(_debug), "Blessing ip address " ); + off += fmt_ip6(_debug+off, ip ); + + if( permissions & OT_PERMISSION_MAY_STAT ) off += snprintf( _debug+off, 512-off, " may_fetch_stats" ); + if( permissions & OT_PERMISSION_MAY_LIVESYNC ) off += snprintf( _debug+off, 512-off, " may_sync_live" ); + if( permissions & OT_PERMISSION_MAY_FULLSCRAPE ) off += snprintf( _debug+off, 512-off, " may_fetch_fullscrapes" ); + if( !permissions ) off += snprintf( _debug+off, sizeof(_debug)-off, " nothing\n" ); + _debug[off++] = '.'; + write( 2, _debug, off ); + } #endif + return 0; } -int accesslist_isblessed( char *ip, ot_permissions permissions ) { +int accesslist_isblessed( ot_ip6 ip, ot_permissions permissions ) { unsigned int i; for( i=0; i