+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_GETKEY);
+ if (idp)
+ silc_id_payload_free(idp);
+ silc_free(client_id);
+ silc_free(server_id);
+ if (public_key)
+ silc_pkcs_public_key_free(public_key);
+ silc_server_command_reply_free(cmd);
+}
+
+SILC_SERVER_CMD_REPLY_FUNC(list)
+{
+ SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
+ SilcServer server = cmd->server;
+ SilcCommandStatus status;
+ SilcChannelID *channel_id = NULL;
+ SilcChannelEntry channel;
+ SilcIDCacheEntry cache;
+ SilcUInt32 len;
+ unsigned char *tmp, *name, *topic;
+ SilcUInt32 usercount = 0;
+ bool global_list = FALSE;
+
+ COMMAND_CHECK_STATUS_LIST;
+
+ tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
+ channel_id = silc_id_payload_parse_id(tmp, len);
+ if (!channel_id)
+ goto out;
+
+ name = silc_argument_get_arg_type(cmd->args, 3, NULL);
+ topic = silc_argument_get_arg_type(cmd->args, 4, NULL);
+ tmp = silc_argument_get_arg_type(cmd->args, 5, NULL);
+ if (tmp)
+ SILC_GET32_MSB(usercount, tmp);
+
+ /* Add the channel entry if we do not have it already */
+ channel = silc_idlist_find_channel_by_name(server->local_list,
+ name, &cache);
+ if (!channel) {
+ channel = silc_idlist_find_channel_by_name(server->global_list,
+ name, &cache);
+ global_list = TRUE;
+ }
+ if (!channel) {
+ /* If router did not find such channel in its lists then this must
+ be bogus channel or some router in the net is buggy. */
+ if (server->server_type != SILC_SERVER)
+ goto out;
+
+ channel = silc_idlist_add_channel(server->global_list, strdup(name),
+ SILC_CHANNEL_MODE_NONE, channel_id,
+ server->router, NULL, NULL,
+ time(NULL) + 60);
+ if (!channel)
+ goto out;
+ channel_id = NULL;
+ } else {
+ /* Found, update expiry */
+ if (global_list && server->server_type == SILC_SERVER)
+ cache->expire = time(NULL) + 60;
+ }
+
+ channel->user_count = usercount;
+
+ if (topic) {
+ silc_free(channel->topic);
+ channel->topic = strdup(topic);
+ }
+
+ /* Pending callbacks are not executed if this was an list entry */
+ if (status != SILC_STATUS_OK &&
+ status != SILC_STATUS_LIST_END) {
+ silc_server_command_reply_free(cmd);
+ return;
+ }
+
+ /* Now purge all old entries from the global list, otherwise we'll might
+ have non-existent entries for long periods of time in the cache. */
+ silc_idcache_purge(server->global_list->channels);
+
+ out:
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_LIST);
+ silc_free(channel_id);