+ client_mode_list = silc_buffer_alloc(tmp_len);
+ silc_buffer_pull_tail(client_mode_list, tmp_len);
+ silc_buffer_put(client_mode_list, tmp, tmp_len);
+
+ /* Save the users to the channel */
+ silc_server_save_users_on_channel(server, cmd->sock, channel, NULL,
+ client_id_list, client_mode_list,
+ list_count);
+
+ channel->global_users = silc_server_channel_has_global(channel);
+ channel->users_resolved = TRUE;
+
+ silc_buffer_free(client_id_list);
+ silc_buffer_free(client_mode_list);
+
+ out:
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_USERS);
+ silc_free(channel_id);
+ err:
+ silc_server_command_reply_free(cmd);
+}
+
+SILC_SERVER_CMD_REPLY_FUNC(getkey)
+{
+ SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
+ SilcServer server = cmd->server;
+ SilcStatus status, error;
+ SilcClientEntry client = NULL;
+ SilcServerEntry server_entry = NULL;
+ SilcClientID *client_id = NULL;
+ SilcServerID *server_id = NULL;
+ unsigned char *tmp;
+ SilcUInt32 len;
+ SilcIDPayload idp = NULL;
+ SilcIdType id_type;
+ SilcPublicKey public_key = NULL;
+
+ COMMAND_CHECK_STATUS;
+
+ tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
+ if (!tmp)
+ goto out;
+ idp = silc_id_payload_parse(tmp, len);
+ if (!idp)
+ goto out;
+
+ /* Get the public key payload */
+ tmp = silc_argument_get_arg_type(cmd->args, 3, &len);
+ if (!tmp)
+ goto out;
+
+ /* Decode the public key payload */
+ if (!silc_pkcs_public_key_payload_decode(tmp, len, &public_key))
+ goto out;
+
+ id_type = silc_id_payload_get_type(idp);
+ if (id_type == SILC_ID_CLIENT) {
+ client_id = silc_id_payload_get_id(idp);
+
+ client = silc_idlist_find_client_by_id(server->local_list, client_id,
+ TRUE, NULL);
+ if (!client) {
+ client = silc_idlist_find_client_by_id(server->global_list,
+ client_id, TRUE, NULL);
+ if (!client)
+ goto out;
+ }
+
+ client->data.public_key = public_key;
+ public_key = NULL;
+ } else if (id_type == SILC_ID_SERVER) {
+ server_id = silc_id_payload_get_id(idp);
+
+ server_entry = silc_idlist_find_server_by_id(server->local_list, server_id,
+ TRUE, NULL);
+ if (!server_entry) {
+ server_entry = silc_idlist_find_server_by_id(server->global_list,
+ server_id, TRUE, NULL);
+ if (!server_entry)
+ goto out;
+ }
+
+ server_entry->data.public_key = public_key;
+ public_key = NULL;
+ } else {
+ goto out;
+ }
+
+ out:
+ 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);
+ err:
+ silc_server_command_reply_free(cmd);
+}
+
+SILC_SERVER_CMD_REPLY_FUNC(list)
+{
+ SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
+ SilcServer server = cmd->server;
+ SilcStatus status, error;
+ 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;
+
+ tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
+ channel_id = silc_id_payload_parse_id(tmp, len, NULL);
+ 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);
+ err:
+ silc_server_command_reply_free(cmd);
+}
+
+SILC_SERVER_CMD_REPLY_FUNC(watch)
+{
+ SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
+ SilcStatus status, error;
+
+ COMMAND_CHECK_STATUS;