-/* Assembles USERS command and executes it. This is called when client
- joins to a channel and we wan't to send USERS command reply to the
- client. */
-
-void silc_server_command_send_users(SilcServer server,
- SilcSocketConnection sock,
- SilcChannelEntry channel,
- int pending)
-{
- SilcServerCommandContext cmd;
- SilcBuffer buffer, idp;
- SilcPacketContext *packet = silc_packet_context_alloc();
-
- SILC_LOG_DEBUG(("Start"));
-
- /* Create USERS command packet and process it. */
- idp = silc_id_payload_encode(channel->id, SILC_ID_CHANNEL);
- buffer = silc_command_payload_encode_va(SILC_COMMAND_USERS, 0, 1,
- 1, idp->data, idp->len);
-
- packet->buffer = silc_buffer_copy(buffer);
- packet->sock = sock;
- packet->type = SILC_PACKET_COMMAND;
-
- cmd = silc_server_command_alloc();
- cmd->payload = silc_command_payload_parse(buffer);
- if (!cmd->payload) {
- silc_free(cmd);
- silc_buffer_free(buffer);
- silc_buffer_free(idp);
- silc_packet_context_free(packet);
- return;
- }
- cmd->args = silc_command_get_args(cmd->payload);
- cmd->server = server;
- cmd->sock = silc_socket_dup(sock);
- cmd->packet = silc_packet_context_dup(packet);
- cmd->pending = FALSE;
-
- if (pending) {
- /* If this function was called from pending command then instead of
- processing the command now, register a pending command callback which
- will process it after we've received the automatic USERS command
- reply which server will send in JOIN. */
- silc_server_command_pending(server, SILC_COMMAND_USERS, 0, NULL,
- silc_server_command_users, cmd);
- cmd->pending = TRUE;
- silc_buffer_free(buffer);
- silc_buffer_free(idp);
- return;
- }
-
- /* Process USERS command. */
- silc_server_command_users((void *)cmd);
-
- silc_buffer_free(buffer);
- silc_buffer_free(idp);
- silc_packet_context_free(packet);
-}
-