// File: /workspace/github_c_makefile_star2_O2/yakushstanislav[P]EagleMQ/src/handlers.c
// Function: route_keys_command_handler
void route_keys_command_handler(EagleClient *client)
{
	ProtocolRequestRouteKeys *req = (ProtocolRequestRouteKeys*)client->request;
	ProtocolResponseHeader res;
	KeylistIterator keylist_iterator;
	KeylistNode *keylist_node;
	ListIterator list_iterator;
	ListNode *list_node;
	Route_t *route;
	Queue_t *queue_t;
	char *key;
	List *queues;
	char *list;
	int i;

	if (client->pos < sizeof(*req)) {
		add_status_response(client, 0, EG_PROTOCOL_STATUS_ERROR_PACKET);
		return;
	}

	if (!BIT_CHECK(client->perm, EG_USER_ADMIN_PERM) && !BIT_CHECK(client->perm, EG_USER_ROUTE_PERM)
		&& !BIT_CHECK(client->perm, EG_USER_ROUTE_KEYS_PERM)) {
		add_status_response(client, req->header.cmd, EG_PROTOCOL_STATUS_ERROR_ACCESS);
		return;
	}

	if (!check_input_buffer2(req->body.name, 64)) {
		add_status_response(client, req->header.cmd, EG_PROTOCOL_STATUS_ERROR_VALUE);
		return;
	}

	route = find_route_t(server->routes, req->body.name);
	if (!route) {
		add_status_response(client, req->header.cmd, EG_PROTOCOL_STATUS_ERROR_NOT_FOUND);
		return;
	}

	set_response_header(&res, req->header.cmd, EG_PROTOCOL_STATUS_SUCCESS,
		get_queue_number_route_t(route) * (32 + 64));

	list = (char*)xcalloc(sizeof(res) + res.bodylen);

	memcpy(list, &res, sizeof(res));

	i = sizeof(res);
	keylist_rewind(route->keys, &keylist_iterator);
	while ((keylist_node = keylist_next_node(&keylist_iterator)) != NULL)
	{
		key = EG_KEYLIST_NODE_KEY(keylist_node);
		queues = EG_KEYLIST_NODE_VALUE(keylist_node);

		list_rewind(queues, &list_iterator);
		while ((list_node = list_next_node(&list_iterator)) != NULL)
		{
			queue_t = EG_LIST_NODE_VALUE(list_node);

			memcpy(list + i, key, strlenz(key));
			i += 32;
			memcpy(list + i, queue_t->name, strlenz(queue_t->name));
			i += 64;
		}
	}

	add_response(client, list, sizeof(res) + res.bodylen);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r15
cmpq $0x47, 0x20(%rdi)
ja 0x6823
pushq $0x3
popq %rdx
movq %r15, %rdi
xorl %esi, %esi
jmp 0x6982
movq 0x10(%r15), %rbx
movabsq $0x2000000022, %rax     # imm = 0x2000000022
testq %rax, 0x8(%r15)
je 0x694a
leaq 0x8(%rbx), %r14
pushq $0x40
popq %rsi
movq %r14, %rdi
callq 0x4c9e
testl %eax, %eax
je 0x6978
movq %r15, 0x8(%rsp)
leaq 0xba32(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x178(%rax), %rdi
movq %r14, %rsi
callq 0x90e2
movzbl 0x2(%rbx), %r13d
testq %rax, %rax
je 0x6995
movq %rax, %r12
movq %rax, %rdi
callq 0x9153
imull $0x60, %eax, %ebx
leaq 0x8(%rbx), %rdi
callq 0x417e
movq %rax, %r14
movq %rbx, 0x18(%rsp)
movq %rbx, %rax
shlq $0x20, %rax
shll $0x10, %r13d
addq %r13, %rax
addq $0x1000080, %rax        # imm = 0x1000080
movq %rax, (%r14)
movq 0x50(%r12), %rdi
leaq 0x20(%rsp), %rsi
callq 0x7f19
movq %r14, 0x10(%rsp)
movq %r14, %rbx
addq $0x20, %rbx
pushq $0x8
popq %r13
leaq 0x20(%rsp), %rdi
callq 0x7f20
testq %rax, %rax
je 0x6952
movq 0x10(%rax), %rbp
movq 0x18(%rax), %rdi
leaq 0x28(%rsp), %rsi
callq 0x8226
movslq %r13d, %r13
leaq 0x28(%rsp), %rdi
callq 0x81e5
testq %rax, %rax
je 0x68d3
movq 0x10(%rax), %r15
leaq (%rbx,%r13), %r14
leaq (%rbx,%r13), %r12
addq $-0x20, %r12
movq %rbp, %rdi
callq 0x2150
leaq 0x1(%rax), %rdx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2280
movq %r15, %rdi
callq 0x2150
leaq 0x1(%rax), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2280
addq $0x60, %r13
jmp 0x68f7
movzbl 0x2(%rbx), %esi
pushq $0x5
jmp 0x697e
movq 0x18(%rsp), %rdx
orl $0x8, %edx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x512c
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl 0x2(%rbx), %esi
pushq $0x7
popq %rdx
movq %r15, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4f56
pushq $0x9
popq %rdx
movq 0x8(%rsp), %rdi
movl %r13d, %esi
jmp 0x6982