// File: /workspace/github_c_makefile_star2_O2/GangZhuo[P]dohclient/src/channel_chndoh.c
// Function: http_cb
static void http_cb(
	int status,
	http_request_t* request,
	http_response_t* response,
	void* state)
{
	channel_req_t* rq = (channel_req_t*)state;
	channel_chndoh_t* c = rq->ctx;
	doh_server_t* doh = NULL;
	ns_msg_t* result = NULL;
	char* data;
	int datalen;
	int http_status = 0;
	const char* status_text = NULL;

	doh = (doh_server_t*)http_request_get_state(request);

	if (status == HTTP_OK &&
		(http_status = http_response_get_status_code(response, &status_text)) == 200) {
		result = (ns_msg_t*)malloc(sizeof(ns_msg_t));
		if (!result) {
			loge("alloc\n");
			goto exit;
		}
		
		if (init_ns_msg(result)) {
			loge("init_ns_msg() error\n");
			free(result);
			result = NULL;
			goto exit;
		}

		data = http_response_get_data(response, &datalen);
		if (ns_parse(result, (const uint8_t*)data, datalen)) {
			loge("ns_parse() error\n");
			ns_msg_free(result);
			free(result);
			result = NULL;
			goto exit;
		}

		result->id = doh == &c->chndoh ? 0 : 1;

		logd("%d. query %s success: %s - %s (%lu ms)\n",
			2 - rq->wait_num,
			rq->qr.qname,
			msg_answers(result),
			doh->name ? doh->name : (doh->host ? doh->host : doh->addrstr),
			OS_GetTickCount() - rq->start_time);
	}
	else {
		loge("%d. query %s failed: HTTP %d %s - %s (%lu ms)\n",
			2 - rq->wait_num,
			rq->qr.qname,
			http_status,
			status_text,
			doh->name ? doh->name : (doh->host ? doh->host : doh->addrstr),
			OS_GetTickCount() - rq->start_time);
	}

exit:
	free(http_request_get_data(request, &datalen));
	http_request_destroy(request);
	http_response_destroy(response);

	query_cb(NULL, result ? 0 : -1, result, FALSE, !!result, rq);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %rbx
movq %rdx, %r13
movl %edi, %r14d
movq 0x60(%rcx), %r12
andq $0x0, 0x20(%rsp)
movq %rsi, 0x30(%rsp)
movq %rsi, %rdi
callq 0x13465
movq %rax, %r15
xorl %ebp, %ebp
testl %r14d, %r14d
jne 0xba96
leaq 0x20(%rsp), %rsi
movq %r13, %rdi
callq 0x13ae2
movl %eax, %ebp
cmpl $0xc8, %eax
jne 0xba96
movq %r12, %rbp
pushq $0x20
popq %rdi
callq 0x34c0
testq %rax, %rax
je 0xbb93
movq %rax, %r12
movq %rax, %rdi
callq 0x18296
testl %eax, %eax
je 0xbbce
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xbc28
leaq 0x14f3c(%rip), %rsi     # 0x209b0
leaq 0x1550e(%rip), %rdx     # 0x20f89
leaq 0x14b2a(%rip), %r8      # 0x205ac
pushq $0x3
popq %rdi
movl $0x2e0, %ecx            # imm = 0x2E0
xorl %eax, %eax
callq 0x1662e
jmp 0xbc28
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xbb45
movq %r13, 0x10(%rsp)
pushq $0x2
popq %r14
subl 0x74(%rbx), %r14d
movq %rbx, %r13
movq 0x8(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x450(%r15), %rbx
testq %rbx, %rbx
jne 0xbaeb
movq 0x460(%r15), %rbx
testq %rbx, %rbx
jne 0xbaeb
movq 0x458(%r15), %rbx
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x181bb
movq %rax, %r10
subq 0x80(%r13), %r10
subq $0x8, %rsp
leaq 0x14ea6(%rip), %rsi     # 0x209b0
leaq 0x15478(%rip), %rdx     # 0x20f89
leaq 0x1548b(%rip), %r8      # 0x20fa3
pushq $0x3
popq %rdi
movl $0x2ff, %ecx            # imm = 0x2FF
movl %r14d, %r9d
movl $0x0, %eax
pushq %r10
pushq %rbx
movq %r13, %rbx
pushq 0x40(%rsp)
pushq %rbp
pushq 0x30(%rsp)
callq 0x1662e
addq $0x30, %rsp
movq 0x10(%rsp), %r13
leaq 0x1c(%rsp), %rsi
movq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x134c8
movq %rax, %rdi
callq 0x3460
movq %r14, %rdi
callq 0x132b5
movq %r13, %rdi
callq 0x13901
xorl %esi, %esi
cmpq $0x1, %r12
sbbl %esi, %esi
xorl %edi, %edi
movq %r12, %rdx
movq %rbx, %r9
callq 0xb208
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xbb45
leaq 0x14e07(%rip), %rsi     # 0x209b0
leaq 0x153d9(%rip), %rdx     # 0x20f89
leaq 0x15cfc(%rip), %r8      # 0x218b3
xorl %r12d, %r12d
pushq $0x3
popq %rdi
movl $0x2db, %ecx            # imm = 0x2DB
xorl %eax, %eax
callq 0x1662e
jmp 0xbb45
leaq 0x1c(%rsp), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x13b36
movl (%r14), %edx
movq %r12, %rdi
movq %rax, %rsi
callq 0x18e8f
testl %eax, %eax
je 0xbc38
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xbc20
leaq 0x14dad(%rip), %rsi     # 0x209b0
leaq 0x1537f(%rip), %rdx     # 0x20f89
leaq 0x15380(%rip), %r8      # 0x20f91
pushq $0x3
popq %rdi
movl $0x2e8, %ecx            # imm = 0x2E8
xorl %eax, %eax
callq 0x1662e
movq %r12, %rdi
callq 0x188ce
movq %r12, %rdi
callq 0x3460
xorl %r12d, %r12d
jmp 0xbb45
subq $-0x80, %rbp
xorl %eax, %eax
cmpq %rbp, %r15
setne %al
movw %ax, (%r12)
xorl %eax, %eax
callq 0x165f5
cmpl $0x7, (%rax)
jl 0xbb45
movq %r13, 0x10(%rsp)
pushq $0x2
popq %rbp
subl 0x74(%rbx), %ebp
movq 0x8(%rbx), %r13
movq %r12, %rdi
callq 0x18bcb
movq %rax, 0x8(%rsp)
movq 0x450(%r15), %r14
testq %r14, %r14
jne 0xbc94
movq 0x460(%r15), %r14
testq %r14, %r14
jne 0xbc94
movq 0x458(%r15), %r14
xorl %eax, %eax
callq 0x181bb
movq %rax, %r10
subq 0x80(%rbx), %r10
leaq 0x14d04(%rip), %rsi     # 0x209b0
leaq 0x152d6(%rip), %rdx     # 0x20f89
leaq 0x15056(%rip), %r8      # 0x20d10
pushq $0x7
popq %rdi
movl $0x2f6, %ecx            # imm = 0x2F6
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq %r14
pushq 0x18(%rsp)
pushq %r13
callq 0x1662e
addq $0x20, %rsp
jmp 0xbb40
nop