// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x960, %rsp            # imm = 0x960
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rdx
movl -0xc(%rbp), %ecx
leaq 0x147b9(%rip), %rdi     # 0x176f0
movl $0xa, %esi
callq 0x44e0
cmpl $0x0, %eax
je 0x2f65
leaq 0xc4bb(%rip), %rdi      # 0xf408
movb $0x0, %al
callq 0x3b40
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x3ca0
jmp 0x32a8
movq -0x8(%rbp), %rdi
addq $0xc, %rdi
callq 0x75d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2f97
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
leaq 0xc49a(%rip), %rdi      # 0xf425
movb $0x0, %al
callq 0x3b40
jmp 0x32a8
movq -0x28(%rbp), %rdi
leaq 0xc4b9(%rip), %rsi      # 0xf45b
callq 0x7cd0
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
leaq 0xc4a9(%rip), %rsi      # 0xf45f
callq 0x7cd0
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
leaq 0xc49c(%rip), %rsi      # 0xf466
callq 0x7cd0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x2fe1
cmpq $0x0, -0x30(%rbp)
jne 0x3004
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
leaq 0xc47a(%rip), %rdi      # 0xf469
movb $0x0, %al
callq 0x3b40
movq -0x28(%rbp), %rdi
callq 0x6f30
jmp 0x32a8
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x20f0
movl %eax, -0x848(%rbp)
cmpl $0x0, -0x848(%rbp)
je 0x302c
cmpl $0xff, -0x848(%rbp)
jle 0x304f
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
leaq 0xc469(%rip), %rdi      # 0xf4a3
movb $0x0, %al
callq 0x3b40
movq -0x28(%rbp), %rdi
callq 0x6f30
jmp 0x32a8
leaq -0x950(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rcx
movl $0x100, %esi            # imm = 0x100
leaq 0xc4f4(%rip), %rdx      # 0xf55e
movb $0x0, %al
callq 0x2130
leaq -0x950(%rbp), %rdi
callq 0x40a0
cmpq $0x0, -0x38(%rbp)
je 0x3090
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x18(%rbp)
leaq -0x950(%rbp), %rsi
leaq 0x14542(%rip), %rdi     # 0x175e0
callq 0xb420
movq %rax, -0x958(%rbp)
cmpq $0x0, -0x958(%rbp)
jne 0x31ca
movl $0x130, %edi            # imm = 0x130
callq 0x2330
movq %rax, -0x958(%rbp)
cmpq $0x0, -0x958(%rbp)
jne 0x316e
callq 0x2040
movl (%rax), %edi
callq 0x22f0
movq %rax, %rsi
leaq 0xc3e3(%rip), %rdi      # 0xf4d0
movb $0x0, %al
callq 0x3b40
leaq -0x840(%rbp), %rdi
leaq 0xc3fe(%rip), %rsi      # 0xf500
callq 0x2060
leaq -0x840(%rbp), %rdi
callq 0x20f0
movl %eax, -0x844(%rbp)
leaq -0x440(%rbp), %rsi
leaq -0x840(%rbp), %rdx
movl -0x844(%rbp), %ecx
leaq 0x145bc(%rip), %rdi     # 0x176f0
callq 0x42e0
movl 0x1449d(%rip), %edi     # 0x175dc
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
leaq -0x440(%rbp), %rcx
movslq -0x844(%rbp), %rax
addq $0xc, %rax
movl %eax, %r8d
callq 0x39a0
movq -0x28(%rbp), %rdi
callq 0x6f30
jmp 0x32a8
movq -0x958(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movq -0x18(%rbp), %rsi
callq 0x2060
movq -0x958(%rbp), %rdi
addq $0x20, %rdi
leaq -0x950(%rbp), %rsi
callq 0x2060
movq -0x958(%rbp), %rsi
leaq 0x14436(%rip), %rdi     # 0x175e0
callq 0xb520
leaq -0x950(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0xc369(%rip), %rdi      # 0xf52a
movb $0x0, %al
callq 0x3b40
jmp 0x3231
movq -0x958(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movq -0x18(%rbp), %rsi
callq 0x2190
cmpl $0x0, %eax
je 0x3201
leaq -0x950(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0xc34c(%rip), %rdi      # 0xf544
movb $0x0, %al
callq 0x3b40
jmp 0x321a
movq -0x18(%rbp), %rsi
leaq -0x950(%rbp), %rdx
leaq 0xc34e(%rip), %rdi      # 0xf561
movb $0x0, %al
callq 0x3b40
movq -0x958(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movq -0x18(%rbp), %rsi
callq 0x2060
movq -0x28(%rbp), %rdi
callq 0x6f30
leaq -0x840(%rbp), %rdi
leaq 0xc33a(%rip), %rsi      # 0xf582
movb $0x0, %al
callq 0x22c0
leaq -0x840(%rbp), %rdi
callq 0x20f0
movl %eax, -0x844(%rbp)
leaq -0x440(%rbp), %rsi
leaq -0x840(%rbp), %rdx
movl -0x844(%rbp), %ecx
leaq 0x14474(%rip), %rdi     # 0x176f0
callq 0x42e0
movl 0x14355(%rip), %edi     # 0x175dc
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
leaq -0x440(%rbp), %rcx
movslq -0x844(%rbp), %rax
addq $0xc, %rax
movl %eax, %r8d
callq 0x39a0
addq $0x960, %rsp            # imm = 0x960
popq %rbp
retq
nopw %cs:(%rax,%rax)