// File: /workspace/github_c_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movq %rsi, %rbx
movq %rdi, %r14
movq %rsp, %rdi
callq 0xf4dd
leaq 0x100(%rsp), %rdi
callq 0xf4dd
leaq 0x200(%rsp), %rdi
callq 0xf4dd
leaq 0xfac3(%rip), %rdx      # 0x1c156
movq %r14, %rdi
xorl %esi, %esi
callq 0xf4e1
testq %rax, %rax
je 0xc6b2
movq %rsp, %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xf038
leaq 0xfa9d(%rip), %rdx      # 0x1c156
movq %r14, %rdi
movl $0x1, %esi
callq 0xf4e1
testq %rax, %rax
je 0xc6e0
leaq 0x100(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xf038
leaq 0xfa6f(%rip), %rdx      # 0x1c156
movq %r14, %rdi
movl $0x2, %esi
callq 0xf4e1
testq %rax, %rax
je 0xc70e
leaq 0x200(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xf038
movl $0x706c6568, %eax       # imm = 0x706C6568
xorl (%rsp), %eax
movzbl 0x4(%rsp), %ecx
orl %eax, %ecx
jne 0xc74d
cmpb $0x0, 0x100(%rsp)
jne 0xc74d
leaq 0x100(%rsp), %rdi
movq %rsp, %r15
movl $0x100, %edx            # imm = 0x100
movq %r15, %rsi
callq 0xf038
movl $0x706c6568, (%r15)     # imm = 0x706C6568
movb $0x0, 0x4(%r15)
leaq 0x5161c(%rip), %rdi     # 0x5dd70
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rsi
callq 0xf038
leaq 0x1bb28(%rip), %r15     # 0x28290
movq %rsp, %r12
leaq 0xf48a(%rip), %r13      # 0x1bbfc
leaq -0x70(%r15), %rdi
movq %r12, %rsi
callq 0x8220
testl %eax, %eax
je 0xc7ad
leaq -0x5c(%r15), %rdi
movq %r12, %rsi
callq 0x8220
testl %eax, %eax
je 0xc7ad
movq %r15, %rdi
movq %r13, %rsi
callq 0x8220
addq $0x70, %r15
testl %eax, %eax
jne 0xc772
movb $0x1, %r12b
jmp 0xc869
leaq -0x5c(%r15), %rsi
movq %rbx, %rdi
callq 0x136e2
testl %eax, %eax
je 0xc807
xorl %r12d, %r12d
leaq 0x100(%rsp), %rdi
leaq 0x200(%rsp), %rsi
movq %r14, %rdx
xorl %eax, %eax
callq *-0x8(%r15)
movl %eax, %ebp
testl %eax, %eax
jne 0xc86e
leaq 0xf49d(%rip), %rsi      # 0x1bc87
leaq 0xfeb7(%rip), %rdx      # 0x1c6a8
movl $0x2, %edi
movq %rbx, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x1a227
xorl %ebp, %ebp
jmp 0xc86e
leaq 0xf479(%rip), %rsi      # 0x1bc87
leaq 0xfe6a(%rip), %rdx      # 0x1c67f
xorl %r12d, %r12d
movl $0x2, %edi
movq %rbx, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x1a227
callq 0x83c0
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
cltq
shlq $0xa, %rax
leaq 0x280e9(%rip), %rcx     # 0x34940
leaq (%rax,%rcx), %rdi
addq $0x2804, %rdi           # imm = 0x2804
xorl %eax, %eax
callq 0x1316b
movl $0x1, %ebp
testb %r12b, %r12b
je 0xc8ae
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x137de
testl %eax, %eax
je 0xc8ae
movq %rsp, %rdi
callq 0x9b04
testl %ebp, %ebp
jne 0xc8ae
leaq 0xf3f2(%rip), %rsi      # 0x1bc87
leaq 0xfe2c(%rip), %rdx      # 0x1c6c8
movq %rsp, %r8
movl $0x2, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1a227
movabsq $0x44494c41564e49, %rax # imm = 0x44494C41564E49
movq %rax, 0x514b1(%rip)     # 0x5dd70
movl %ebp, %eax
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq