// File: /workspace/github_c_makefile_star2_O2/schroeder-lvb[P]sissm/src/picladmin.c
// Function: commandExecute
int _commandExecute( char *cmdString, char *originID ) 
{   
    char *p, cmdOut[256], arg1Out[256], arg2Out[256];
    int i, errCode = 1;
    int isCommand = 0;

    // zero the physical stores
    //
    strclr( cmdOut );  strclr( arg1Out );  strclr( arg2Out );

    // The input string cmdString will be in the format, e.g., "botfixed 30"
    // parse command vs arguments and invoke the string-matched function 
    //
    if ( NULL != (p = getWord( cmdString, 0, " " ) )) strlcpy( cmdOut,  p, 256);
    if ( NULL != (p = getWord( cmdString, 1, " " ) )) strlcpy( arg1Out, p, 256);
    if ( NULL != (p = getWord( cmdString, 2, " " ) )) strlcpy( arg2Out, p, 256);

    // Handle special 'help' case for when no argument is specified
    // 
    if ( (0 == strcmp("help", cmdOut)) && (0 == strlen( arg1Out )) ) {
        strlcpy( arg1Out, cmdOut, 256 );
        strlcpy( cmdOut, "help",  256 );
    } 

    // remember the origin ID for some command that may need it (e.g., !help)
    //
    _setOriginID( originID );

    // loop through the command table
    //
    i = 0;
    while ( 1==1 ) {

        if ( (0 == strcmp( cmdTable[i].cmdShort, cmdOut )) || (0 == strcmp( cmdTable[i].cmdLong, cmdOut )) ) {

            isCommand = 1;

            // check if this admin has enough privilege to execute this command
            //
            if ( ! apiAuthIsAllowedCommand( originID, cmdTable[i].cmdLong ) ) {
                logPrintf( LOG_LEVEL_INFO, "picladmin", "Insufficient priv for [%s] to execute %s", originID, cmdString );
                _respSay( picladminConfig.msgInvalid );                       // unauthorized message
                break;
            }

            // execute the command
            //
            errCode = (*cmdTable[i].cmdFunction)( arg1Out, arg2Out, cmdString );
            if ( errCode == 0 ) {
                logPrintf( LOG_LEVEL_INFO, "picladmin", "Admin [%s] executed command: %s", originID, cmdString );
            }
            break;
        }
        i++;
        if ( 0==strcmp( cmdTable[i].cmdShort, "*") )
            break;
    }

    // check if the command was not in standard commands table -- if not
    // it may be a operator added macro.
    // 
    if ( !isCommand ) {

        // check if this admin has enough privilege to execute this command
        //
        if ( apiAuthIsAllowedMacro( originID, cmdOut ) ) {
        
            // execute the macro
            //
            _cmdMacros( cmdOut, "", "" );
            if ( errCode == 0 ) {
                logPrintf( LOG_LEVEL_INFO, "picladmin", "Admin [%s] executed macro: %s", originID, cmdOut );
            }
        }
    }

    // Command level security - set ident to invalid
    //
    _setOriginID( "INVALID" );

    return errCode; 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x300, %rsp            # imm = 0x300
movq %rsi, %rbx
movq %rdi, %r14
movq %rsp, %rdi
callq 0xed98
leaq 0x100(%rsp), %rdi
callq 0xed98
leaq 0x200(%rsp), %rdi
callq 0xed98
leaq 0xef22(%rip), %rdx      # 0x1b14e
movq %r14, %rdi
xorl %esi, %esi
callq 0xed9c
testq %rax, %rax
je 0xc24b
movq %rsp, %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xe97a
leaq 0xeefc(%rip), %rdx      # 0x1b14e
pushq $0x1
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
callq 0xed9c
testq %rax, %rax
je 0xc279
leaq 0x100(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xe97a
leaq 0xeece(%rip), %rdx      # 0x1b14e
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0xed9c
testq %rax, %rax
je 0xc2a5
leaq 0x200(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xe97a
leaq 0xeab6(%rip), %rdi      # 0x1ad62
movq %rsp, %rsi
pushq $0x5
popq %rdx
callq 0x82e0
testl %eax, %eax
jne 0xc2e9
cmpb $0x0, 0x100(%rsp)
jne 0xc2e9
leaq 0x100(%rsp), %rdi
movq %rsp, %r15
movl $0x100, %edx            # imm = 0x100
movq %r15, %rsi
callq 0xe97a
movl $0x706c6568, (%r15)     # imm = 0x706C6568
movb $0x0, 0x4(%r15)
movq %rbx, %rdi
callq 0xc3e4
leaq 0x1bf28(%rip), %r15     # 0x28220
movq %rsp, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x8220
testl %eax, %eax
je 0xc332
leaq 0x14(%r15), %rdi
movq %r12, %rsi
callq 0x8220
testl %eax, %eax
je 0xc332
cmpb $0x2a, 0x70(%r15)
jne 0xc32c
cmpb $0x0, 0x71(%r15)
je 0xc3af
addq $0x70, %r15
jmp 0xc2fb
leaq 0x14(%r15), %rsi
movq %rbx, %rdi
callq 0x12cba
testl %eax, %eax
je 0xc383
leaq 0x100(%rsp), %rdi
leaq 0x200(%rsp), %rsi
movq %r14, %rdx
xorl %eax, %eax
callq *0x68(%r15)
movl %eax, %ebp
testl %eax, %eax
jne 0xc3c6
leaq 0xe917(%rip), %rsi      # 0x1ac7f
leaq 0xf331(%rip), %rdx      # 0x1b6a0
pushq $0x2
popq %rdi
movq %rbx, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x1920b
xorl %ebp, %ebp
jmp 0xc3c6
leaq 0xe8f5(%rip), %rsi      # 0x1ac7f
leaq 0xf2e6(%rip), %rdx      # 0x1b677
pushq $0x2
popq %rdi
movq %rbx, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x1920b
leaq 0x2ad9c(%rip), %rdi     # 0x37144
callq 0xc3f8
jmp 0xc3c6
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x12d7e
testl %eax, %eax
je 0xc3c6
movq %rsp, %rdi
callq 0x9970
leaq 0xf2f3(%rip), %rdi      # 0x1b6c0
callq 0xc3e4
movl %ebp, %eax
addq $0x300, %rsp            # imm = 0x300
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq