// File: /workspace/github_c_makefile_star2_O0/xiaowenhuyuehu[P]remote_access/src/core/remote_terminal.c
// Function: get_msg_header
static inline int get_msg_header(char *buf, RemoteTerminalMsgHeader *hdr)
{
    int first = 0, second = 0, len = 0, hdr_len = 0;
    char *tmp = NULL, *ret = NULL, *hdr_start = NULL;

    if(!buf || !hdr)
        return 0;

    memset(hdr, 0, sizeof(RemoteTerminalMsgHeader));
    tmp = strchr(buf,'{');
    if(!tmp)
        goto _exit;
    first = tmp - buf; 

    tmp = strchr(buf, '}');
    if(!tmp)
        goto _exit;
    second = tmp - buf;

    hdr_start = buf + first;
    hdr_len = second - first + 1;

    ret = json_get_value_by_name(hdr_start, hdr_len, "msg_type", NULL, NULL);
    if(!ret)
        goto _exit;
    hdr->msg_type = atoi(ret);
    
    ret = json_get_value_by_name(hdr_start, hdr_len, "service_type", NULL, NULL);
    //service type is not a must
    if(ret){
        hdr->srv_type = atoi(ret);
    }
    
    ret = json_get_value_by_name(hdr_start, hdr_len, "payload_len", NULL, NULL);
    if(!ret)
        goto _exit;
    hdr->payload_len = atoi(ret);
   
    len = 0;
    ret = json_get_value_by_name(hdr_start, hdr_len, "msg_id", &len, NULL);
    //msg_id is not a must
    if(ret){
        strncpy(hdr->msg_id, ret, len < 63 ? len : 63);
    }
 
    ret = json_get_value_by_name(hdr_start, hdr_len, "timestamp", NULL, NULL);
    if(ret){
        hdr->timestamp = atol(ret);
    }
   
    len = 0;
    ret = json_get_value_by_name(hdr_start, hdr_len, "token", &len, NULL);
    if(ret){
        strncpy(hdr->token, ret, len < 63 ? len : 63);
    }
    
    hdr->hdr_len = second - first + sizeof("\r \r ");

    log_info("msg hander:  %s", buf); 
    return 1;
_exit:
    log_error("header json formate error:  %s ", buf);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x86a2
cmpq $0x0, -0x18(%rbp)
jne 0x86ae
movl $0x0, -0x4(%rbp)
jmp 0x8972
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0xa0, %edx
callq 0x2090
movq -0x10(%rbp), %rdi
movl $0x7b, %esi
callq 0x23a0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x86dc
jmp 0x8941
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movl $0x7d, %esi
callq 0x23a0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x8708
jmp 0x8941
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x20(%rbp), %eax
subl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x40(%rbp), %rdi
movl -0x28(%rbp), %esi
leaq 0x3465(%rip), %rdx      # 0xbba4
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0x3f50
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x875c
jmp 0x8941
movq -0x38(%rbp), %rdi
callq 0x2360
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x40(%rbp), %rdi
movl -0x28(%rbp), %esi
leaq 0x3432(%rip), %rdx      # 0xbbad
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0x3f50
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x87a5
movq -0x38(%rbp), %rdi
callq 0x2360
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x40(%rbp), %rdi
movl -0x28(%rbp), %esi
leaq 0x3407(%rip), %rdx      # 0xbbba
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0x3f50
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x87d0
jmp 0x8941
movq -0x38(%rbp), %rdi
callq 0x2360
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movl $0x0, -0x24(%rbp)
movq -0x40(%rbp), %rdi
movl -0x28(%rbp), %esi
leaq 0x33cf(%rip), %rdx      # 0xbbc6
leaq -0x24(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x3f50
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x884f
movq -0x18(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpl $0x3f, -0x24(%rbp)
jge 0x8832
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x883c
movl $0x3f, %eax
movl %eax, -0x54(%rbp)
jmp 0x883c
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdi
movl -0x54(%rbp), %eax
movslq %eax, %rdx
callq 0x24b0
movq -0x40(%rbp), %rdi
movl -0x28(%rbp), %esi
leaq 0x3370(%rip), %rdx      # 0xbbcd
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0x3f50
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x8889
movq -0x38(%rbp), %rdi
callq 0x22f0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x50(%rax)
movl $0x0, -0x24(%rbp)
movq -0x40(%rbp), %rdi
movl -0x28(%rbp), %esi
leaq 0x3339(%rip), %rdx      # 0xbbd7
leaq -0x24(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x3f50
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x88f6
movq -0x18(%rbp), %rax
addq $0x58, %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpl $0x3f, -0x24(%rbp)
jge 0x88d9
movl -0x24(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x88e3
movl $0x3f, %eax
movl %eax, -0x6c(%rbp)
jmp 0x88e3
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdi
movl -0x6c(%rbp), %eax
movslq %eax, %rdx
callq 0x24b0
movl -0x20(%rbp), %eax
subl -0x1c(%rbp), %eax
cltq
addq $0x5, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x98(%rax)
movq -0x10(%rbp), %r9
movl $0x1, %edi
leaq 0x2d1b(%rip), %rsi      # 0xb639
leaq 0x2cc1(%rip), %rdx      # 0xb5e6
movl $0x9f, %ecx
leaq 0x32ac(%rip), %r8       # 0xbbdd
movb $0x0, %al
callq 0x4f90
movl $0x1, -0x4(%rbp)
jmp 0x8972
movq -0x10(%rbp), %r9
movl $0x3, %edi
leaq 0x2c8f(%rip), %rsi      # 0xb5e0
leaq 0x2c8e(%rip), %rdx      # 0xb5e6
movl $0xa2, %ecx
leaq 0x3289(%rip), %r8       # 0xbbed
movb $0x0, %al
callq 0x4f90
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)