// File: /workspace/github_c_makefile_star2_O2/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 0xf832(%rip), %rdi      # 0x122e0
pushq $0xa
popq %rsi
movq %r15, %rdx
movl %ebp, %ecx
callq 0x3883
testl %eax, %eax
je 0x2ae8
leaq 0x68f3(%rip), %rdi      # 0x93b9
xorl %eax, %eax
callq 0x3281
movq %r15, %rdi
movl %ebp, %esi
addq $0x908, %rsp            # imm = 0x908
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x33ab
addq $0xc, %r15
movq %r15, %rdi
callq 0x51d6
testq %rax, %rax
je 0x2b68
movq %rax, %r15
leaq 0x6909(%rip), %rsi      # 0x940c
movq %rax, %rdi
callq 0x585c
movq %rax, %rbp
leaq 0x68fb(%rip), %rsi      # 0x9410
movq %r15, %rdi
callq 0x585c
movq %rax, %r13
leaq 0x68f0(%rip), %rsi      # 0x9417
movq %r15, %rdi
callq 0x585c
movq %rax, %r12
testq %rbp, %rbp
setne %al
testq %r13, %r13
setne %cl
testb %cl, %al
je 0x2b8c
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 0x2bb8
leaq 0x68ee(%rip), %rdi      # 0x9454
jmp 0x2b93
leaq 0x6867(%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 0x3281
leaq 0x6887(%rip), %rdi      # 0x941a
movq %r14, %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x3281
movq %r15, %rdi
addq $0x908, %rsp            # imm = 0x908
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4b73
leaq 0x6950(%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 0x3647
testq %r12, %r12
je 0x2be6
movq 0x20(%r12), %r14
leaq 0xf5e3(%rip), %rdi      # 0x121d0
movq %rsp, %rsi
callq 0x6a00
testq %rax, %rax
je 0x2c22
movq %rax, %r12
addq $0x120, %r12            # imm = 0x120
movq %r12, %rdi
movq %r14, %rsi
callq 0x2190
testl %eax, %eax
je 0x2c7e
leaq 0x68db(%rip), %rdi      # 0x94f5
movq %rsp, %rsi
movq %r14, %rdx
jmp 0x2c8b
movl $0x130, %edi            # imm = 0x130
callq 0x2320
testq %rax, %rax
je 0x2d18
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 0xf570(%rip), %rdi      # 0x121d0
movq %r12, %rsi
callq 0x6a3d
leaq 0x686c(%rip), %rdi      # 0x94db
movq %r13, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3281
jmp 0x2c9d
leaq 0x688d(%rip), %rdi      # 0x9512
movq %rsp, %rdx
movq %r14, %rsi
xorl %eax, %eax
callq 0x3281
movq %r12, %rdi
movq %r14, %rsi
callq 0x2060
movq %r15, %rdi
callq 0x4b73
movups 0x6895(%rip), %xmm0     # 0x9541
leaq 0x100(%rsp), %r15
movups %xmm0, 0xe(%r15)
movups 0x6873(%rip), %xmm0     # 0x9533
movaps %xmm0, (%r15)
movq %r15, %rdi
callq 0x2100
movq %rax, %r12
leaq 0xf60a(%rip), %rdi      # 0x122e0
leaq 0x500(%rsp), %r13
movq %r13, %rsi
movq %r15, %rdx
movl %r12d, %ecx
callq 0x3773
movl 0xf4da(%rip), %edi      # 0x121cc
addl $0xc, %r12d
movq %r14, %rsi
movl %ebx, %edx
movq %r13, %rcx
movl %r12d, %r8d
callq 0x317e
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 0x6756(%rip), %rdi      # 0x9481
movq %rax, %rsi
xorl %eax, %eax
callq 0x3281
movups 0x6775(%rip), %xmm0     # 0x94b1
leaq 0x100(%rsp), %r12
movaps %xmm0, (%r12)
movups 0x6771(%rip), %xmm0     # 0x94c1
movaps %xmm0, 0x10(%r12)
movups 0x676e(%rip), %xmm0     # 0x94cb
movups %xmm0, 0x1a(%r12)
movq %r12, %rdi
callq 0x2100
movq %rax, %r13
leaq 0xf56b(%rip), %rdi      # 0x122e0
leaq 0x500(%rsp), %rbp
movq %rbp, %rsi
movq %r12, %rdx
movl %r13d, %ecx
callq 0x3773
movl 0xf43b(%rip), %edi      # 0x121cc
addl $0xc, %r13d
movq %r14, %rsi
movl %ebx, %edx
movq %rbp, %rcx
movl %r13d, %r8d
callq 0x317e
movq %r15, %rdi
callq 0x4b73
jmp 0x2d06