mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-11 08:48:06 +01:00
Don't use uninitialized values as port numbers; use match for set as well as get.
This commit is contained in:
parent
bd1222f2dc
commit
86fa3159d6
1 changed files with 32 additions and 18 deletions
|
@ -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,32 +279,47 @@ 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 )
|
||||||
{
|
{
|
||||||
|
const char* val = args[2];
|
||||||
|
char* const attrs[] = { "help", "listeners", "loglevel" };
|
||||||
|
string attr(args[1]);
|
||||||
|
int index = match( &attr, attrs, sizeof(attrs[0]),
|
||||||
|
sizeof(attrs)/sizeof(attrs[0]));
|
||||||
|
|
||||||
bool needsHelp = true;
|
bool needsHelp = true;
|
||||||
if ( 0 == strcmp( args[1], "loglevel" ) ) {
|
switch( index ) {
|
||||||
const char* attr = args[1];
|
case 1:
|
||||||
const char* val = args[2];
|
if ( NULL != val && val[0] != '\0' ) {
|
||||||
if ( (NULL != attr) && (NULL != val) ) {
|
istringstream str( val );
|
||||||
|
vector<int> sv;
|
||||||
|
while ( !str.eof() ) {
|
||||||
|
int sock;
|
||||||
|
char comma;
|
||||||
|
str >> sock >> comma;
|
||||||
|
logf( XW_LOGERROR, "%s: read %d", __func__, sock );
|
||||||
|
sv.push_back( sock );
|
||||||
|
}
|
||||||
|
g_listeners.SetAll( &sv );
|
||||||
|
needsHelp = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if ( NULL != val && val[0] != '\0' ) {
|
||||||
RelayConfigs* rc = RelayConfigs::GetConfigs();
|
RelayConfigs* rc = RelayConfigs::GetConfigs();
|
||||||
if ( rc != NULL ) {
|
if ( rc != NULL ) {
|
||||||
rc->SetLogLevel( atoi(val) );
|
rc->SetLogLevel( atoi(val) );
|
||||||
needsHelp = false;
|
needsHelp = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( 0 == strcmp( args[1], "listeners" ) ) {
|
break;
|
||||||
istringstream str( args[2] );
|
default:
|
||||||
vector<int> sv;
|
break;
|
||||||
while ( !str.eof() ) {
|
|
||||||
int sock;
|
|
||||||
char comma;
|
|
||||||
str >> sock >> comma;
|
|
||||||
logf( XW_LOGERROR, "%s: read %d", __func__, sock );
|
|
||||||
sv.push_back( sock );
|
|
||||||
}
|
|
||||||
g_listeners.SetAll( &sv );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue