// File: /workspace/github_c_makefile_star2_O0/loversmile[P]sugarcrm/sugar_client.c
// Function: crmClient
void *crmClient(void *data)
{
    char *server = "http://192.168.124.27/crm/service/v4_1/soap.php";
    //char *server = "http://192.168.124.99/crm/service/v4_1/soap.php";
    
    //struct login_return = NULL;
    //login_return = initLoginReturn(login_return);
    int normal = 1;
    int time_now = 0;
    
    SGCRMInfoTask *info_task = NULL;
    info_task = initSGCRMInfoTask(info_task);
    //info_task->server_info = initSGServerInfo(info_task->server_info);
    info_task->server_info->soap = soap_new();
    info_task->server_info->soap_endpoint = strdup(server);
    
    queueInitialize(&request_crm_queue);
    
    SGCRMTask *crm_task = NULL;
    
    char *username = "admin";
    char *password = "123456";
    int login_ret = -1;
    int ret = -1;
    while(g_crm_task) {
        printf("%d\n", time(NULL));
        printf("%d\n", time_now);
        //This need a function to monitor crmtask
		monitorTaskAll();

        if (normal == 1 && (time(NULL) - time_now) >= 1790 )
        {
            time_now = time(NULL);
            //info_task->login_return = initSGLoginReturn(info_task->login_return);
            login_ret = SGCRMLogin(info_task->server_info, username, password, info_task->login_return); 
        } 
        else if (normal == 0)
        {
            //info_task->login_return = initSGLoginReturn(info_task->login_return);
            login_ret = SGCRMLogin(info_task->server_info, username, password, info_task->login_return);
        }

        if (login_ret == 0 && info_task->login_return && 
                info_task->login_return->session_id && 
                info_task->login_return->user_id)
        {
            printf("session = %s\n", info_task->login_return->session_id);
            printf("user    = %s\n", info_task->login_return->user_id);
            normal = 1;
        } 
        else 
        {
            printf("login error login_ret = %d\n", login_ret);
            normal = 0;
            sleep(1);
            continue;
        }
        
        while(DEQUEUE_SUCCESS_AND_CONTINUE == (ret = dequeueTask(&request_crm_queue, &crm_task)) || DEQUEUE_SUCCESS_AND_EMPTY == ret)
        {
            if (crm_task)
            {
                int res = executeRequest(info_task, crm_task);
                
            }
        }
        cleanSGCRMTask(crm_task);
        sleep(1);
		//break;
    }
	cleanSGCRMInfoTask(info_task);
    cleanQueue(&request_crm_queue);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
leaq 0x96b9(%rip), %rax      # 0x7985c
movq %rax, -0x18(%rbp)
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x70910
movq %rax, -0x28(%rbp)
callq 0x5a420
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rdi
callq 0x33a0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x8(%rax)
leaq 0x1f13c(%rip), %rdi     # 0x8f338
callq 0x705a0
movq $0x0, -0x30(%rbp)
leaq 0xbf23(%rip), %rax      # 0x7c133
movq %rax, -0x38(%rbp)
leaq 0xbf1e(%rip), %rax      # 0x7c139
movq %rax, -0x40(%rbp)
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, 0x1f16c(%rip)     # 0x8f3a0
je 0x703d2
xorl %eax, %eax
movl %eax, %edi
callq 0x3250
movq %rax, %rsi
leaq 0xc203(%rip), %rdi      # 0x7c450
movb $0x0, %al
callq 0x3140
movl -0x20(%rbp), %esi
leaq 0xc1f2(%rip), %rdi      # 0x7c450
movb $0x0, %al
callq 0x3140
callq 0x70080
cmpl $0x1, -0x1c(%rbp)
jne 0x702b5
xorl %eax, %eax
movl %eax, %edi
callq 0x3250
movslq -0x20(%rbp), %rcx
subq %rcx, %rax
cmpq $0x6fe, %rax            # imm = 0x6FE
jl 0x702b5
xorl %eax, %eax
movl %eax, %edi
callq 0x3250
movl %eax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rax
movq (%rax), %rcx
callq 0x77040
movl %eax, -0x44(%rbp)
jmp 0x702dc
cmpl $0x0, -0x1c(%rbp)
jne 0x702da
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rax
movq (%rax), %rcx
callq 0x77040
movl %eax, -0x44(%rbp)
jmp 0x702dc
cmpl $0x0, -0x44(%rbp)
jne 0x70341
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
je 0x70341
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, (%rax)
je 0x70341
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0x70341
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rsi
leaq 0xbe28(%rip), %rdi      # 0x7c140
movb $0x0, %al
callq 0x3140
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rsi
leaq 0xbe1d(%rip), %rdi      # 0x7c14e
movb $0x0, %al
callq 0x3140
movl $0x1, -0x1c(%rbp)
jmp 0x70368
movl -0x44(%rbp), %esi
leaq 0xbe11(%rip), %rdi      # 0x7c15c
movb $0x0, %al
callq 0x3140
movl $0x0, -0x1c(%rbp)
movl $0x1, %edi
callq 0x33c0
jmp 0x7022d
jmp 0x7036a
leaq 0x1efc7(%rip), %rdi     # 0x8f338
leaq -0x30(%rbp), %rsi
callq 0x707d0
movl %eax, %edx
movl %edx, -0x48(%rbp)
movb $0x1, %al
xorl %ecx, %ecx
cmpl %edx, %ecx
movb %al, -0x4d(%rbp)
je 0x70398
movl $0x1, %eax
cmpl -0x48(%rbp), %eax
sete %al
movb %al, -0x4d(%rbp)
movb -0x4d(%rbp), %al
testb $0x1, %al
jne 0x703a1
jmp 0x703ba
cmpq $0x0, -0x30(%rbp)
je 0x703b8
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x700e0
movl %eax, -0x4c(%rbp)
jmp 0x7036a
movq -0x30(%rbp), %rdi
callq 0x706b0
movl $0x1, %edi
callq 0x33c0
jmp 0x7022d
movq -0x28(%rbp), %rdi
callq 0x709e0
leaq 0x1ef56(%rip), %rdi     # 0x8f338
callq 0x70620
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)