// File: /workspace/github_c_makefile_star2_O1/bloomsource[P]dns_update/dns.c
// Function: proc_cmd
void proc_cmd( char* data, int len, char* ip, int port )
{
    cJSON *json_root, *json_domain, *json_ip, *json_cmd;
    char buf[1024];
    char json[1024];
    int json_len;
    int ilen;
    char domain[MAX_DOMAIN+1];
    dns_node* node;
    
    if( unpack_update_pkg( auth_key, TIME_DIFF, data, len ) )
    {
        write_log( "[WRN] recv invalid cmd pack!" );
        write_log_hex( data, len );
        return;
    }
    
    
    json_root = cJSON_Parse( data + sizeof(upd_pack_hdr) );
    if( !json_root )
    {
        write_log( "[WRN] recv invalid json cmd from %s:%d, parse failed.", ip, port );
        return;
    }
    
    json_cmd    = cJSON_GetObjectItem( json_root, "cmd" );
    json_domain = cJSON_GetObjectItem( json_root, "domain" );
    json_ip     = cJSON_GetObjectItem( json_root, "ip" );
    
    
    if( !json_cmd || !json_domain )
    {
        write_log( "[WRN] recv invalid json cmd from %s:%d, missing elements.", ip, port );
        cJSON_Delete( json_root );
        return;
    }
    
    ilen = strlen( json_domain->valuestring );
    if( ilen == 0 || ilen > MAX_DOMAIN )
    {
        write_log( "[WRN] recv cmd domain over length from %s:%d", ip, port );
        cJSON_Delete( json_root );
        return ;
    }
    snprintf( domain, sizeof(domain), "%s", json_domain->valuestring );
    

    
    strlower( domain );
    
    if( json_ip )
        ip = json_ip->valuestring;
    
    
    node = (dns_node*)rbtree_find( &domains, domain );
    if( !node )
    {
        node = malloc( sizeof( dns_node ) );
        if( !node )
        {
            write_log( "[ERR] malloc memory for dns_node failed! err:%s", ERR );
            strcpy( json, "{ \"retcode\": 1, \"desc\":\"mallof failed!\" }" );
            json_len = strlen( json );
            pack_update_pkg( auth_key, buf, json, json_len );
            udp_send( cmd_fd, ip, port, buf, json_len + sizeof(upd_pack_hdr) );
            cJSON_Delete( json_root );
            return;
        }
        strcpy( node->ip, ip );
        strcpy( node->domain, domain );
        
        rbtree_insert( &domains, (rbnode*)node );
        write_log( "set domain %-20s ip to %s", domain, ip );
    }
    else
    {
        if( strcmp( node->ip, ip ) )
        {
            write_log( "update domain %-20s ip to %s", domain, ip );
        }
        else
        {
            write_log( "client %-15s update domain %-20s", ip, domain );
            
        }
        
        strcpy( node->ip, ip );
        
    }
    
    cJSON_Delete( json_root );
    
    sprintf( json, "{ \"retcode\":0, \"desc\": \"ok\" }" );
    json_len = strlen( json );
    pack_update_pkg( auth_key, buf, json, json_len );
    udp_send( cmd_fd, ip, port, buf, json_len + sizeof(upd_pack_hdr) );
    return;
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x908, %rsp            # imm = 0x908
movl %ecx, %ebx
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
leaq 0xe817(%rip), %rdi      # 0x112e0
movl $0xa, %esi
movq %r15, %rdx
movl %ebp, %ecx
callq 0x399e
testl %eax, %eax
je 0x2b05
leaq 0x68d6(%rip), %rdi      # 0x93b9
xorl %eax, %eax
callq 0x32e8
movq %r15, %rdi
movl %ebp, %esi
addq $0x908, %rsp            # imm = 0x908
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3418
addq $0xc, %r15
movq %r15, %rdi
callq 0x5319
testq %rax, %rax
je 0x2b85
movq %rax, %r15
leaq 0x68ec(%rip), %rsi      # 0x940c
movq %rax, %rdi
callq 0x5a6f
movq %rax, %rbp
leaq 0x68de(%rip), %rsi      # 0x9410
movq %r15, %rdi
callq 0x5a6f
movq %rax, %r13
leaq 0x68d3(%rip), %rsi      # 0x9417
movq %r15, %rdi
callq 0x5a6f
movq %rax, %r12
testq %rbp, %rbp
setne %al
testq %r13, %r13
setne %cl
testb %cl, %al
je 0x2ba9
movq 0x20(%r13), %r13
movq %r13, %rdi
callq 0x2100
testl %eax, %eax
setne %cl
cmpl $0x100, %eax            # imm = 0x100
setl %al
testb %al, %cl
jne 0x2bd5
leaq 0x68d1(%rip), %rdi      # 0x9454
jmp 0x2bb0
leaq 0x684a(%rip), %rdi      # 0x93d6
movq %r14, %rsi
movl %ebx, %edx
xorl %eax, %eax
addq $0x908, %rsp            # imm = 0x908
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x32e8
leaq 0x686a(%rip), %rdi      # 0x941a
movq %r14, %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x32e8
movq %r15, %rdi
addq $0x908, %rsp            # imm = 0x908
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4d01
leaq 0x6933(%rip), %rdx      # 0x950f
movq %rsp, %rbp
movl $0x100, %esi            # imm = 0x100
movq %rbp, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x2130
movq %rbp, %rdi
callq 0x3713
testq %r12, %r12
je 0x2c03
movq 0x20(%r12), %r14
leaq 0xe5c6(%rip), %rdi      # 0x111d0
movq %rsp, %rsi
callq 0x71f0
testq %rax, %rax
je 0x2c3f
movq %rax, %r12
addq $0x120, %r12            # imm = 0x120
movq %r12, %rdi
movq %r14, %rsi
callq 0x2190
testl %eax, %eax
je 0x2c9b
leaq 0x68be(%rip), %rdi      # 0x94f5
movq %rsp, %rsi
movq %r14, %rdx
jmp 0x2ca8
movl $0x130, %edi            # imm = 0x130
callq 0x2320
testq %rax, %rax
je 0x2d35
movq %rax, %r12
leaq 0x120(%rax), %rdi
movq %r14, %rsi
callq 0x2060
movq %r12, %rdi
addq $0x20, %rdi
movq %rsp, %r13
movq %r13, %rsi
callq 0x2060
leaq 0xe553(%rip), %rdi      # 0x111d0
movq %r12, %rsi
callq 0x7236
leaq 0x684f(%rip), %rdi      # 0x94db
movq %r13, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x32e8
jmp 0x2cba
leaq 0x6870(%rip), %rdi      # 0x9512
movq %rsp, %rdx
movq %r14, %rsi
xorl %eax, %eax
callq 0x32e8
movq %r12, %rdi
movq %r14, %rsi
callq 0x2060
movq %r15, %rdi
callq 0x4d01
movups 0x6878(%rip), %xmm0     # 0x9541
leaq 0x100(%rsp), %r15
movups %xmm0, 0xe(%r15)
movups 0x6856(%rip), %xmm0     # 0x9533
movaps %xmm0, (%r15)
movq %r15, %rdi
callq 0x2100
movq %rax, %r12
leaq 0xe5ed(%rip), %rdi      # 0x112e0
leaq 0x500(%rsp), %r13
movq %r13, %rsi
movq %r15, %rdx
movl %r12d, %ecx
callq 0x3894
movl 0xe4bd(%rip), %edi      # 0x111cc
addl $0xc, %r12d
movq %r14, %rsi
movl %ebx, %edx
movq %r13, %rcx
movl %r12d, %r8d
callq 0x31e1
addq $0x908, %rsp            # imm = 0x908
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2040
movl (%rax), %edi
callq 0x22d0
leaq 0x6739(%rip), %rdi      # 0x9481
movq %rax, %rsi
xorl %eax, %eax
callq 0x32e8
movups 0x6758(%rip), %xmm0     # 0x94b1
leaq 0x100(%rsp), %r12
movaps %xmm0, (%r12)
movups 0x6754(%rip), %xmm0     # 0x94c1
movaps %xmm0, 0x10(%r12)
movups 0x6751(%rip), %xmm0     # 0x94cb
movups %xmm0, 0x1a(%r12)
movq %r12, %rdi
callq 0x2100
movq %rax, %r13
leaq 0xe54e(%rip), %rdi      # 0x112e0
leaq 0x500(%rsp), %rbp
movq %rbp, %rsi
movq %r12, %rdx
movl %r13d, %ecx
callq 0x3894
movl 0xe41e(%rip), %edi      # 0x111cc
addl $0xc, %r13d
movq %r14, %rsi
movl %ebx, %edx
movq %rbp, %rcx
movl %r13d, %r8d
callq 0x31e1
movq %r15, %rdi
callq 0x4d01
jmp 0x2d23