// File: /workspace/github_c_makefile_star2_O3/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 0xe81b(%rip), %rdi      # 0x112e0
movl $0xa, %esi
movq %r15, %rdx
movl %ebp, %ecx
callq 0x396e
testl %eax, %eax
je 0x2b01
leaq 0x68b8(%rip), %rdi      # 0x9397
xorl %eax, %eax
callq 0x32b8
movq %r15, %rdi
movl %ebp, %esi
addq $0x908, %rsp            # imm = 0x908
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x33e8
addq $0xc, %r15
movq %r15, %rdi
callq 0x52d3
testq %rax, %rax
je 0x2b81
movq %rax, %r15
leaq 0x68ce(%rip), %rsi      # 0x93ea
movq %rax, %rdi
callq 0x5a3a
movq %rax, %rbp
leaq 0x68c0(%rip), %rsi      # 0x93ee
movq %r15, %rdi
callq 0x5a3a
movq %rax, %r13
leaq 0x68b5(%rip), %rsi      # 0x93f5
movq %r15, %rdi
callq 0x5a3a
movq %rax, %r12
testq %rbp, %rbp
setne %al
testq %r13, %r13
setne %cl
testb %cl, %al
je 0x2ba5
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 0x2bd1
leaq 0x68b3(%rip), %rdi      # 0x9432
jmp 0x2bac
leaq 0x682c(%rip), %rdi      # 0x93b4
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 0x32b8
leaq 0x684c(%rip), %rdi      # 0x93f8
movq %r14, %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x32b8
movq %r15, %rdi
addq $0x908, %rsp            # imm = 0x908
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4d23
leaq 0x6915(%rip), %rdx      # 0x94ed
movq %rsp, %rbp
movl $0x100, %esi            # imm = 0x100
movq %rbp, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x2130
movq %rbp, %rdi
callq 0x36e3
testq %r12, %r12
je 0x2bff
movq 0x20(%r12), %r14
leaq 0xe5ca(%rip), %rdi      # 0x111d0
movq %rsp, %rsi
callq 0x7161
testq %rax, %rax
je 0x2c3b
movq %rax, %r12
addq $0x120, %r12            # imm = 0x120
movq %r12, %rdi
movq %r14, %rsi
callq 0x2190
testl %eax, %eax
je 0x2c97
leaq 0x68a0(%rip), %rdi      # 0x94d3
movq %rsp, %rsi
movq %r14, %rdx
jmp 0x2ca4
movl $0x130, %edi            # imm = 0x130
callq 0x2320
testq %rax, %rax
je 0x2d31
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 0xe557(%rip), %rdi      # 0x111d0
movq %r12, %rsi
callq 0x71a0
leaq 0x6831(%rip), %rdi      # 0x94b9
movq %r13, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x32b8
jmp 0x2cb6
leaq 0x6852(%rip), %rdi      # 0x94f0
movq %rsp, %rdx
movq %r14, %rsi
xorl %eax, %eax
callq 0x32b8
movq %r12, %rdi
movq %r14, %rsi
callq 0x2060
movq %r15, %rdi
callq 0x4d23
movups 0x685a(%rip), %xmm0     # 0x951f
leaq 0x100(%rsp), %r15
movups %xmm0, 0xe(%r15)
movups 0x6838(%rip), %xmm0     # 0x9511
movaps %xmm0, (%r15)
movq %r15, %rdi
callq 0x2100
movq %rax, %r12
leaq 0xe5f1(%rip), %rdi      # 0x112e0
leaq 0x500(%rsp), %r13
movq %r13, %rsi
movq %r15, %rdx
movl %r12d, %ecx
callq 0x3864
movl 0xe4c1(%rip), %edi      # 0x111cc
addl $0xc, %r12d
movq %r14, %rsi
movl %ebx, %edx
movq %r13, %rcx
movl %r12d, %r8d
callq 0x31b1
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 0x671b(%rip), %rdi      # 0x945f
movq %rax, %rsi
xorl %eax, %eax
callq 0x32b8
movups 0x673a(%rip), %xmm0     # 0x948f
leaq 0x100(%rsp), %r12
movaps %xmm0, (%r12)
movups 0x6736(%rip), %xmm0     # 0x949f
movaps %xmm0, 0x10(%r12)
movups 0x6733(%rip), %xmm0     # 0x94a9
movups %xmm0, 0x1a(%r12)
movq %r12, %rdi
callq 0x2100
movq %rax, %r13
leaq 0xe552(%rip), %rdi      # 0x112e0
leaq 0x500(%rsp), %rbp
movq %rbp, %rsi
movq %r12, %rdx
movl %r13d, %ecx
callq 0x3864
movl 0xe422(%rip), %edi      # 0x111cc
addl $0xc, %r13d
movq %r14, %rsi
movl %ebx, %edx
movq %rbp, %rcx
movl %r13d, %r8d
callq 0x31b1
movq %r15, %rdi
callq 0x4d23
jmp 0x2d1f