serverspy/src/serverspy.cxx
//------------------------------------------------------------------------------
// This function will parse the administrator command and will return 
// command code + will set param pointer to point to the optional parameter.
//------------------------------------------------------------------------------
This function will parse the administrator command and will return
command code + will set param pointer to point to the optional parameter.
This function will parse the administrator command and will return command code + will set param pointer to point to the optional parameter .
int AdminParseCommand(char* command, void** param) {
    char* p;
    static char parsed[10][100];
    static int cliID;
    int cmd_count=0;
    int i=0;
    p=command;
    while (*p!=0) {
        if(*p==' ') {
            if(cmd_count<9) {
                parsed[cmd_count][i]=0;
                cmd_count++;
                while(*p==' ') p++;
                i=0;
                continue;
            }
        }
        if(i<99)
        parsed[cmd_count][i++]=*p;
        p++;
    }
    parsed[cmd_count][i]=0;
    cmd_count++;
    if(strcmp(parsed[0],"reboot")==0) {
        return REBOOT;
    }
    if(strcmp(parsed[0],"list")==0) {
        if(cmd_count==1) {
            return ALL_LIST;
        } else {
            if((strcmp(parsed[1],"-host")==0) && (cmd_count>2)) {
                *param = (void *)parsed[2];
                return HOST_LIST;
            }
            if((strcmp(parsed[1],"-user")==0) && (cmd_count>2)) {
                *param = (void *)parsed[2];
                return USER_LIST;
            }
            *param = (void *)parsed[1];
            return USER_LIST;
        }
    }
    if(strcmp(parsed[0],"count")==0) {
        if(cmd_count==1) {
            return ALL_COUNT;
        } else {
            if((strcmp(parsed[1],"-host")==0) && (cmd_count>2)) {
                *param = (void *)parsed[2];
                return HOST_COUNT;
            }
            if((strcmp(parsed[1],"-user")==0) && (cmd_count>2)) {
                *param = (void *)parsed[2];
                return USER_COUNT;
            }
            *param = (void *)parsed[1];
            return USER_COUNT;
        }
    }
    if(strcmp(parsed[0],"stop")==0) {
        if(cmd_count==1) {
            return ALL_STOP;
        } else {
            if((strcmp(parsed[1],"-host")==0) && cmd_count>2) {
                *param = (void *)parsed[2];
                return HOST_STOP;
            }
            if((strcmp(parsed[1],"-user")==0) && cmd_count>2) {
                *param = (void *)parsed[2];
                return USER_STOP;
            }
            cliID= atoi(parsed[1]);
            *param = (void *)&cliID;
            return CLIENT_STOP;
        }
    }
    return UNKNOWN;
}
int AdminParseCommand ( char * command , void * * param ) { char * p ; static char parsed [ 10 ] [ 100 ] ; static int cliID ; int cmd_count = 0 ; int i = 0 ; p = command ; while ( * p != 0 ) { if ( * p == ' ' ) { if ( cmd_count < 9 ) { parsed [ cmd_count ] [ i ] = 0 ; cmd_count ++ ; while ( * p == ' ' ) p ++ ; i = 0 ; continue ; } } if ( i < 99 ) parsed [ cmd_count ] [ i ++ ] = * p ; p ++ ; } parsed [ cmd_count ] [ i ] = 0 ; cmd_count ++ ; if ( strcmp ( parsed [ 0 ] , " " ) == 0 ) { return REBOOT ; } if ( strcmp ( parsed [ 0 ] , " " ) == 0 ) { if ( cmd_count == 1 ) { return ALL_LIST ; } else { if ( ( strcmp ( parsed [ 1 ] , " " ) == 0 ) && ( cmd_count > 2 ) ) { * param = ( void * ) parsed [ 2 ] ; return HOST_LIST ; } if ( ( strcmp ( parsed [ 1 ] , " " ) == 0 ) && ( cmd_count > 2 ) ) { * param = ( void * ) parsed [ 2 ] ; return USER_LIST ; } * param = ( void * ) parsed [ 1 ] ; return USER_LIST ; } } if ( strcmp ( parsed [ 0 ] , " " ) == 0 ) { if ( cmd_count == 1 ) { return ALL_COUNT ; } else { if ( ( strcmp ( parsed [ 1 ] , " " ) == 0 ) && ( cmd_count > 2 ) ) { * param = ( void * ) parsed [ 2 ] ; return HOST_COUNT ; } if ( ( strcmp ( parsed [ 1 ] , " " ) == 0 ) && ( cmd_count > 2 ) ) { * param = ( void * ) parsed [ 2 ] ; return USER_COUNT ; } * param = ( void * ) parsed [ 1 ] ; return USER_COUNT ; } } if ( strcmp ( parsed [ 0 ] , " " ) == 0 ) { if ( cmd_count == 1 ) { return ALL_STOP ; } else { if ( ( strcmp ( parsed [ 1 ] , " " ) == 0 ) && cmd_count > 2 ) { * param = ( void * ) parsed [ 2 ] ; return HOST_STOP ; } if ( ( strcmp ( parsed [ 1 ] , " " ) == 0 ) && cmd_count > 2 ) { * param = ( void * ) parsed [ 2 ] ; return USER_STOP ; } cliID = atoi ( parsed [ 1 ] ) ; * param = ( void * ) & cliID ; return CLIENT_STOP ; } } return UNKNOWN ; }
This function will parse the administrator command and will return
command code + will set param pointer to point to the optional parameter.
This function will parse the administrator command and will return command code + will set param pointer to point to the optional parameter .