2008-06-04 17:14:58 +00:00
|
|
|
#include <stdio.h> /* fprintf */
|
|
|
|
#include <string.h> /* strcmp */
|
|
|
|
#include "transmission.h"
|
2008-07-21 16:11:47 +00:00
|
|
|
#include "bencode.h"
|
2008-09-05 14:31:58 +00:00
|
|
|
#include "rpcimpl.h"
|
2008-06-04 17:14:58 +00:00
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
#define VERBOSE 0
|
|
|
|
|
2008-08-11 19:05:02 +00:00
|
|
|
static int test = 0;
|
2008-06-04 17:14:58 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
#define check( A ) \
|
|
|
|
{ \
|
|
|
|
++test; \
|
|
|
|
if( A ){ \
|
|
|
|
if( VERBOSE ) \
|
|
|
|
fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\
|
|
|
|
__LINE__ );\
|
|
|
|
} else { \
|
|
|
|
if( VERBOSE ) \
|
|
|
|
fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\
|
|
|
|
__LINE__ );\
|
|
|
|
return test; \
|
|
|
|
} \
|
|
|
|
}
|
2008-06-04 17:14:58 +00:00
|
|
|
|
2008-09-25 05:03:39 +00:00
|
|
|
#if 0
|
2008-06-04 17:14:58 +00:00
|
|
|
extern char* cidrize( const char * in );
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
extern int tr_rpcTestACL( const void * unused,
|
|
|
|
const char * acl,
|
|
|
|
char ** setme_errmsg );
|
2008-06-04 17:14:58 +00:00
|
|
|
|
|
|
|
static int
|
2008-09-23 19:11:04 +00:00
|
|
|
testWildcard( const char * in,
|
|
|
|
const char * expected )
|
2008-06-04 17:14:58 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
int ok;
|
2008-06-04 17:14:58 +00:00
|
|
|
char * str = cidrize( in );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-07-21 16:11:47 +00:00
|
|
|
/* fprintf( stderr, "in [%s] out [%s] expected [%s]\n", in, str, expected ); */
|
2008-06-04 17:14:58 +00:00
|
|
|
ok = expected ? !strcmp( expected, str ) : !str;
|
|
|
|
tr_free( str );
|
|
|
|
return ok;
|
|
|
|
}
|
2008-09-25 05:03:39 +00:00
|
|
|
#endif
|
2008-06-04 17:14:58 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
test_acl( void )
|
|
|
|
{
|
2008-09-25 05:03:39 +00:00
|
|
|
#if 0
|
2008-09-23 19:11:04 +00:00
|
|
|
int err;
|
2008-06-04 17:14:58 +00:00
|
|
|
char * errmsg = NULL;
|
|
|
|
|
|
|
|
check( testWildcard( "192.*.*.*", "192.0.0.0/8" ) );
|
|
|
|
check( testWildcard( "192.64.*.*", "192.64.0.0/16" ) );
|
|
|
|
check( testWildcard( "192.64.0.*", "192.64.0.0/24" ) );
|
|
|
|
check( testWildcard( "192.64.0.1", "192.64.0.1/32" ) );
|
2008-07-21 16:11:47 +00:00
|
|
|
check( testWildcard( "+192.*.*.*,-192.64.*.*",
|
|
|
|
"+192.0.0.0/8,-192.64.0.0/16" ) );
|
2008-06-04 17:14:58 +00:00
|
|
|
|
|
|
|
err = tr_rpcTestACL( NULL, "+192.*.*.*", &errmsg );
|
|
|
|
check( !err );
|
|
|
|
check( !errmsg );
|
|
|
|
err = tr_rpcTestACL( NULL, "+192.*.8.*", &errmsg );
|
|
|
|
check( err );
|
|
|
|
check( errmsg );
|
|
|
|
tr_free( errmsg );
|
|
|
|
errmsg = NULL;
|
2008-06-11 15:17:59 +00:00
|
|
|
err = tr_rpcTestACL( NULL, "+192.*.*.*,-192.168.*.*", &errmsg );
|
2008-06-04 17:14:58 +00:00
|
|
|
check( !err );
|
|
|
|
check( !errmsg );
|
2008-09-25 05:03:39 +00:00
|
|
|
#endif
|
2008-06-04 17:14:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-21 16:11:47 +00:00
|
|
|
static int
|
|
|
|
test_list( void )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
int64_t i;
|
2008-07-21 16:11:47 +00:00
|
|
|
const char * str;
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_benc top;
|
2008-07-21 16:11:47 +00:00
|
|
|
|
|
|
|
tr_rpc_parse_list_str( &top, "12", -1 );
|
|
|
|
check( tr_bencIsInt( &top ) );
|
|
|
|
check( tr_bencGetInt( &top, &i ) );
|
|
|
|
check( i == 12 );
|
|
|
|
tr_bencFree( &top );
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str( &top, "12", 1 );
|
|
|
|
check( tr_bencIsInt( &top ) );
|
|
|
|
check( tr_bencGetInt( &top, &i ) );
|
|
|
|
check( i == 1 );
|
|
|
|
tr_bencFree( &top );
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str( &top, "6,7", -1 );
|
|
|
|
check( tr_bencIsList( &top ) );
|
|
|
|
check( tr_bencListSize( &top ) == 2 );
|
|
|
|
check( tr_bencGetInt( tr_bencListChild( &top, 0 ), &i ) );
|
|
|
|
check( i == 6 );
|
|
|
|
check( tr_bencGetInt( tr_bencListChild( &top, 1 ), &i ) );
|
|
|
|
check( i == 7 );
|
|
|
|
tr_bencFree( &top );
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str( &top, "asdf", -1 );
|
|
|
|
check( tr_bencIsString( &top ) );
|
|
|
|
check( tr_bencGetStr( &top, &str ) );
|
|
|
|
check( !strcmp( str, "asdf" ) );
|
|
|
|
tr_bencFree( &top );
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str( &top, "1,3-5", -1 );
|
|
|
|
check( tr_bencIsList( &top ) );
|
|
|
|
check( tr_bencListSize( &top ) == 4 );
|
|
|
|
check( tr_bencGetInt( tr_bencListChild( &top, 0 ), &i ) );
|
|
|
|
check( i == 1 );
|
|
|
|
check( tr_bencGetInt( tr_bencListChild( &top, 1 ), &i ) );
|
|
|
|
check( i == 3 );
|
|
|
|
check( tr_bencGetInt( tr_bencListChild( &top, 2 ), &i ) );
|
|
|
|
check( i == 4 );
|
|
|
|
check( tr_bencGetInt( tr_bencListChild( &top, 3 ), &i ) );
|
|
|
|
check( i == 5 );
|
|
|
|
tr_bencFree( &top );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-04 17:14:58 +00:00
|
|
|
int
|
|
|
|
main( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
if( ( i = test_acl( ) ) )
|
2008-06-04 17:14:58 +00:00
|
|
|
return i;
|
2008-09-23 19:11:04 +00:00
|
|
|
if( ( i = test_list( ) ) )
|
2008-07-21 16:11:47 +00:00
|
|
|
return i;
|
2008-06-04 17:14:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|