// File: /workspace/github_c_makefile_star2_O1/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
movq $0x0, 0x20(%rsp)
movq %rsi, 0x30(%rsp)
movq %rsi, %rdi
callq 0x14619
movq %rax, %r15
xorl %ebp, %ebp
testl %r14d, %r14d
jne 0xc441
leaq 0x20(%rsp), %rsi
movq %r13, %rdi
callq 0x14d77
movl %eax, %ebp
cmpl $0xc8, %eax
jne 0xc441
movq %r12, %rbp
movl $0x20, %edi
callq 0x34b0
testq %rax, %rax
je 0xc542
movq %rax, %r12
movq %rax, %rdi
callq 0x19b12
testl %eax, %eax
je 0xc57f
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xc5db
leaq 0x1658b(%rip), %rsi     # 0x229a8
leaq 0x16b5d(%rip), %rdx     # 0x22f81
leaq 0x161a1(%rip), %r8      # 0x225cc
movl $0x3, %edi
movl $0x2e0, %ecx            # imm = 0x2E0
xorl %eax, %eax
callq 0x17d92
jmp 0xc5db
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xc4f4
movq %r13, 0x10(%rsp)
movl $0x2, %r14d
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 0xc498
movq 0x460(%r15), %rbx
testq %rbx, %rbx
jne 0xc498
movq 0x458(%r15), %rbx
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x19a24
movq %rax, %r10
subq 0x80(%r13), %r10
subq $0x8, %rsp
leaq 0x164f1(%rip), %rsi     # 0x229a8
leaq 0x16ac3(%rip), %rdx     # 0x22f81
leaq 0x16ad6(%rip), %r8      # 0x22f9b
movl $0x3, %edi
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 0x17d92
addq $0x30, %rsp
movq 0x10(%rsp), %r13
leaq 0x1c(%rsp), %rsi
movq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x146b5
movq %rax, %rdi
callq 0x3450
movq %r14, %rdi
callq 0x143e9
movq %r13, %rdi
callq 0x14b16
xorl %esi, %esi
cmpq $0x1, %r12
sbbl %esi, %esi
xorl %edi, %edi
movq %r12, %rdx
movq %rbx, %r9
callq 0xbb39
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xc4f4
leaq 0x16450(%rip), %rsi     # 0x229a8
leaq 0x16a22(%rip), %rdx     # 0x22f81
leaq 0x1733d(%rip), %r8      # 0x238a3
xorl %r12d, %r12d
movl $0x3, %edi
movl $0x2db, %ecx            # imm = 0x2DB
xorl %eax, %eax
callq 0x17d92
jmp 0xc4f4
leaq 0x1c(%rsp), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x14dd5
movl (%r14), %edx
movq %r12, %rdi
movq %rax, %rsi
callq 0x1a7e0
testl %eax, %eax
je 0xc5eb
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xc5d3
leaq 0x163f4(%rip), %rsi     # 0x229a8
leaq 0x169c6(%rip), %rdx     # 0x22f81
leaq 0x169c7(%rip), %r8      # 0x22f89
movl $0x3, %edi
movl $0x2e8, %ecx            # imm = 0x2E8
xorl %eax, %eax
callq 0x17d92
movq %r12, %rdi
callq 0x1a1dd
movq %r12, %rdi
callq 0x3450
xorl %r12d, %r12d
jmp 0xc4f4
subq $-0x80, %rbp
xorl %eax, %eax
cmpq %rbp, %r15
setne %al
movw %ax, (%r12)
xorl %eax, %eax
callq 0x17d59
cmpl $0x7, (%rax)
jl 0xc4f4
movq %r13, 0x10(%rsp)
movl $0x2, %ebp
subl 0x74(%rbx), %ebp
movq 0x8(%rbx), %r13
movq %r12, %rdi
callq 0x1a4f0
movq %rax, 0x8(%rsp)
movq 0x450(%r15), %r14
testq %r14, %r14
jne 0xc649
movq 0x460(%r15), %r14
testq %r14, %r14
jne 0xc649
movq 0x458(%r15), %r14
xorl %eax, %eax
callq 0x19a24
movq %rax, %r10
subq 0x80(%rbx), %r10
leaq 0x16347(%rip), %rsi     # 0x229a8
leaq 0x16919(%rip), %rdx     # 0x22f81
leaq 0x16699(%rip), %r8      # 0x22d08
movl $0x7, %edi
movl $0x2f6, %ecx            # imm = 0x2F6
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq %r14
pushq 0x18(%rsp)
pushq %r13
callq 0x17d92
addq $0x20, %rsp
jmp 0xc4ef
nop