// File: /workspace/github_c_makefile_star2_O1/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, %r13
cmpq $0x47, 0x20(%rdi)
ja 0x6d76
movq %r13, %rdi
xorl %esi, %esi
movl $0x3, %edx
jmp 0x6f11
movq 0x10(%r13), %rbx
movabsq $0x2000000022, %rax     # imm = 0x2000000022
testq %rax, 0x8(%r13)
je 0x6eea
leaq 0x8(%rbx), %r14
movl $0x40, %esi
movq %r14, %rdi
callq 0x4ed8
testl %eax, %eax
je 0x6ef8
leaq 0xb4e2(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x178(%rax), %rdi
movq %r14, %rsi
callq 0x9a0f
movzbl 0x2(%rbx), %r12d
testq %rax, %rax
je 0x6f06
movq %rax, %r15
movq %r13, 0x10(%rsp)
movq %rax, %rdi
callq 0x9a80
shll $0x5, %eax
leal (%rax,%rax,2), %ebx
leaq 0x8(%rbx), %rdi
callq 0x4376
movq %rbx, 0x8(%rsp)
movq %rbx, %rcx
shlq $0x20, %rcx
shll $0x10, %r12d
addq %r12, %rcx
addq $0x1000080, %rcx        # imm = 0x1000080
movq %rax, (%rsp)
movq %rcx, (%rax)
movq 0x50(%r15), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x86b7
movq %r15, %rdi
callq 0x86be
testq %rax, %rax
je 0x6ec5
movq (%rsp), %rcx
addq $0x20, %rcx
movq %rcx, 0x18(%rsp)
movl $0x8, %ebx
leaq 0x28(%rsp), %r12
movq 0x10(%rax), %rbp
movq 0x18(%rax), %rdi
movq %r12, %rsi
callq 0x8a40
movq %r12, %rdi
callq 0x89ff
testq %rax, %rax
je 0x6eb6
movslq %ebx, %r15
addq 0x18(%rsp), %r15
movq 0x10(%rax), %r14
leaq -0x20(%r15), %r13
movq %rbp, %rdi
callq 0x2160
leaq 0x1(%rax), %rdx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2290
movq %r14, %rdi
callq 0x2160
leaq 0x1(%rax), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x2290
movq %r12, %rdi
callq 0x89ff
addq $0x60, %r15
addl $0x60, %ebx
testq %rax, %rax
jne 0x6e6c
leaq 0x20(%rsp), %rdi
callq 0x86be
testq %rax, %rax
jne 0x6e47
movq 0x8(%rsp), %rdx
orl $0x8, %edx
movq 0x10(%rsp), %rdi
movq (%rsp), %rsi
callq 0x5396
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl 0x2(%rbx), %esi
movq %r13, %rdi
movl $0x5, %edx
jmp 0x6f11
movzbl 0x2(%rbx), %esi
movq %r13, %rdi
movl $0x7, %edx
jmp 0x6f11
movq %r13, %rdi
movl %r12d, %esi
movl $0x9, %edx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x51a2