mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-28 07:58:08 +01:00
Don't use uninitialized values as port numbers; use match for set as well as get.
This commit is contained in:
parent
f0e21dbd86
commit
da93ed5b31
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;
|
||||
int which = -1;
|
||||
int i;
|
||||
for ( i = 0; i < count; ++i ) {
|
||||
logf( XW_LOGINFO, "comparing %s,%s", *first, cmd );
|
||||
for ( i = 0; (i < count) && (nFound <= 1); ++i ) {
|
||||
if ( 0 == strncmp( cmd->c_str(), *first, cmdlen ) ) {
|
||||
++nFound;
|
||||
which = i;
|
||||
|
@ -280,32 +279,47 @@ cmd_get( int socket, const char** args )
|
|||
static bool
|
||||
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;
|
||||
if ( 0 == strcmp( args[1], "loglevel" ) ) {
|
||||
const char* attr = args[1];
|
||||
const char* val = args[2];
|
||||
if ( (NULL != attr) && (NULL != val) ) {
|
||||
switch( index ) {
|
||||
case 1:
|
||||
if ( NULL != val && val[0] != '\0' ) {
|
||||
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();
|
||||
if ( rc != NULL ) {
|
||||
rc->SetLogLevel( atoi(val) );
|
||||
needsHelp = false;
|
||||
}
|
||||
}
|
||||
} else if ( 0 == strcmp( args[1], "listeners" ) ) {
|
||||
istringstream str( args[2] );
|
||||
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 );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue