Don't use uninitialized values as port numbers; use match for set as well as get.

This commit is contained in:
ehouse 2007-12-03 00:45:09 +00:00
parent bd1222f2dc
commit 86fa3159d6

View file

@ -83,8 +83,7 @@ match( string* cmd, char * const* first, int incr, int count )
const char* cmdFound = NULL; const char* cmdFound = NULL;
int which = -1; int which = -1;
int i; int i;
for ( i = 0; i < count; ++i ) { for ( i = 0; (i < count) && (nFound <= 1); ++i ) {
logf( XW_LOGINFO, "comparing %s,%s", *first, cmd );
if ( 0 == strncmp( cmd->c_str(), *first, cmdlen ) ) { if ( 0 == strncmp( cmd->c_str(), *first, cmdlen ) ) {
++nFound; ++nFound;
which = i; which = i;
@ -280,19 +279,17 @@ cmd_get( int socket, const char** args )
static bool static bool
cmd_set( int socket, const char** args ) cmd_set( int socket, const char** args )
{ {
bool needsHelp = true;
if ( 0 == strcmp( args[1], "loglevel" ) ) {
const char* attr = args[1];
const char* val = args[2]; const char* val = args[2];
if ( (NULL != attr) && (NULL != val) ) { char* const attrs[] = { "help", "listeners", "loglevel" };
RelayConfigs* rc = RelayConfigs::GetConfigs(); string attr(args[1]);
if ( rc != NULL ) { int index = match( &attr, attrs, sizeof(attrs[0]),
rc->SetLogLevel( atoi(val) ); sizeof(attrs)/sizeof(attrs[0]));
needsHelp = false;
} bool needsHelp = true;
} switch( index ) {
} else if ( 0 == strcmp( args[1], "listeners" ) ) { case 1:
istringstream str( args[2] ); if ( NULL != val && val[0] != '\0' ) {
istringstream str( val );
vector<int> sv; vector<int> sv;
while ( !str.eof() ) { while ( !str.eof() ) {
int sock; int sock;
@ -302,10 +299,27 @@ cmd_set( int socket, const char** args )
sv.push_back( sock ); sv.push_back( sock );
} }
g_listeners.SetAll( &sv ); g_listeners.SetAll( &sv );
needsHelp = false;
}
break;
case 2:
if ( NULL != val && val[0] != '\0' ) {
RelayConfigs* rc = RelayConfigs::GetConfigs();
if ( rc != NULL ) {
rc->SetLogLevel( atoi(val) );
needsHelp = false;
}
}
break;
default:
break;
} }
if ( needsHelp ) { if ( needsHelp ) {
print_to_sock( socket, true, "* %s loglevel <n>", args[0] ); print_to_sock( socket, true,
"* %s listeners <n>,[<n>,..<n>,]\n"
"* %s loglevel <n>"
,args[0], args[0] );
} }
return false; return false;
} }