// File: /workspace/github_c_makefile_star2_O0/yakushstanislav[P]EagleMQ/src/handlers.c
// Function: channel_list_command_handler
void channel_list_command_handler(EagleClient *client)
{
	ProtocolRequestChannelList *req = (ProtocolRequestChannelList*)client->request;
	ProtocolResponseHeader res;
	ListIterator iterator;
	ListNode *node;
	Channel_t *channel;
	char *list;
	uint32_t topics;
	uint32_t patterns;
	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_CHANNEL_PERM)
		&& !BIT_CHECK(client->perm, EG_USER_CHANNEL_LIST_PERM)) {
		add_status_response(client, req->cmd, EG_PROTOCOL_STATUS_ERROR_ACCESS);
		return;
	}

	set_response_header(&res, req->cmd, EG_PROTOCOL_STATUS_SUCCESS,
		EG_LIST_LENGTH(server->channels) * (64 + (sizeof(uint32_t) * 3)));

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

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

	i = sizeof(res);
	list_rewind(server->channels, &iterator);
	while ((node = list_next_node(&iterator)) != NULL)
	{
		channel = EG_LIST_NODE_VALUE(node);

		topics = EG_KEYLIST_LENGTH(channel->topics);
		patterns = EG_KEYLIST_LENGTH(channel->patterns);

		memcpy(list + i, channel->name, strlenz(channel->name));
		i += 64;
		memcpy(list + i, &channel->flags, sizeof(uint32_t));
		i += sizeof(uint32_t);
		memcpy(list + i, &topics, sizeof(uint32_t));
		i += sizeof(uint32_t);
		memcpy(list + i, &patterns, sizeof(uint32_t));
		i += sizeof(uint32_t);
	}

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x8, 0x20(%rax)
jae 0xa0d8
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x6980
jmp 0xa283
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x20, %rax
cmpq $0x0, %rax
jne 0xa12f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x4, %rax
cmpq $0x0, %rax
jne 0xa12f
movq -0x8(%rbp), %rcx
movabsq $0x200000000000, %rax   # imm = 0x200000000000
andq 0x8(%rcx), %rax
cmpq $0x0, %rax
jne 0xa12f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %esi
movl $0x5, %edx
callq 0x6980
jmp 0xa283
movq -0x10(%rbp), %rax
movb 0x2(%rax), %al
leaq 0xd173(%rip), %rcx      # 0x172b0
movq (%rcx), %rcx
movq 0x180(%rcx), %rcx
movl 0x20(%rcx), %ecx
imulq $0x4c, %rcx, %rcx
leaq -0x18(%rbp), %rdi
movl $0x1, %edx
movzbl %al, %esi
callq 0x6c70
movl -0x14(%rbp), %eax
movl %eax, %edi
addq $0x8, %rdi
callq 0x5160
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, (%rax)
movl $0x8, -0x4c(%rbp)
leaq 0xd126(%rip), %rax      # 0x172b0
movq (%rax), %rax
movq 0x180(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0xc520
leaq -0x28(%rbp), %rdi
callq 0xc450
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0xa26d
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rax
movl 0x20(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x20(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rdi
callq 0x2160
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x22c0
movl -0x4c(%rbp), %eax
addl $0x40, %eax
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq -0x38(%rbp), %rdx
movl 0x40(%rdx), %edx
movl %edx, (%rax,%rcx)
movslq -0x4c(%rbp), %rax
addq $0x4, %rax
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl -0x44(%rbp), %edx
movl %edx, (%rax,%rcx)
movslq -0x4c(%rbp), %rax
addq $0x4, %rax
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl -0x48(%rbp), %edx
movl %edx, (%rax,%rcx)
movslq -0x4c(%rbp), %rax
addq $0x4, %rax
movl %eax, -0x4c(%rbp)
jmp 0xa19d
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x14(%rbp), %eax
addq $0x8, %rax
movl %eax, %edx
callq 0x6cb0
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)