+ 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;
+ SilcServerID server_id;
+ 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_public_key_payload_decode(tmp, len, &public_key))
+ goto out;
+
+ id_type = silc_id_payload_get_type(idp);
+ if (id_type == SILC_ID_CLIENT) {
+ silc_id_payload_get_id(idp, &client_id, sizeof(client_id));
+
+ 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;
+ }
+
+ if (!client->data.public_key) {
+ /* Add client's public key to repository */
+ if (!silc_server_get_public_key_by_client(server, client, NULL))
+ silc_skr_add_public_key_simple(server->repository,
+ public_key,
+ SILC_SKR_USAGE_IDENTIFICATION,
+ client, NULL);
+ client->data.public_key = public_key;
+ public_key = NULL;
+ }
+ } else if (id_type == SILC_ID_SERVER) {
+ silc_id_payload_get_id(idp, &server_id, sizeof(server_id));
+
+ 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);
+ 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;
+ SilcID id;
+ SilcChannelEntry channel;
+ SilcIDCacheEntry cache;
+ unsigned char *tmp, *name, *namec = NULL, *topic;
+ SilcUInt32 usercount = 0;
+ SilcBool global_list = FALSE;
+
+ COMMAND_CHECK_STATUS;
+
+ if (!silc_argument_get_decoded(cmd->args, 2, SILC_ARGUMENT_ID, &id, NULL))
+ 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);
+
+ namec = silc_channel_name_check(name, strlen(name), SILC_STRING_UTF8,
+ 256, NULL);
+ if (!namec)
+ goto out;
+
+ /* Add the channel entry if we do not have it already */
+ channel = silc_idlist_find_channel_by_name(server->local_list,
+ namec, &cache);
+ if (!channel) {
+ channel = silc_idlist_find_channel_by_name(server->global_list,
+ namec, &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,
+ silc_id_dup(SILC_ID_GET_ID(id),
+ SILC_ID_CHANNEL),
+ server->router, NULL, NULL, NULL);
+ if (!channel)
+ goto out;
+ }
+
+ 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;
+ }
+
+ out:
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_LIST);
+ err:
+ silc_free(namec);
+ silc_server_command_reply_free(cmd);
+}
+
+SILC_SERVER_CMD_REPLY_FUNC(watch)
+{
+ SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
+ SilcStatus status, error;
+
+ COMMAND_CHECK_STATUS;
+
+ out:
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_WATCH);
+ err:
+ silc_server_command_reply_free(cmd);
+}
+
+SILC_SERVER_CMD_REPLY_FUNC(ping)
+{
+ SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
+ SilcStatus status, error;
+
+ COMMAND_CHECK_STATUS;
+
+ out:
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_PING);
+ err: