#include "command_reply.h"
/* All functions that call the COMMAND_CHECK_STATUS macros must have
- out: goto label. */
-
-#define COMMAND_CHECK_STATUS \
-do { \
- SILC_LOG_DEBUG(("Start")); \
- if (!silc_command_get_status(cmd->payload, &status, &error)) \
- goto out; \
+ out: and err: goto labels. */
+
+#define COMMAND_CHECK_STATUS \
+do { \
+ SILC_LOG_DEBUG(("Start")); \
+ if (!silc_command_get_status(cmd->payload, &status, &error)) { \
+ if (SILC_STATUS_IS_ERROR(status)) \
+ goto out; \
+ if (status == SILC_STATUS_LIST_END) \
+ goto out; \
+ goto err; \
+ } \
} while(0)
/* Server command reply list. Not all commands have reply function as
}
}
+static void
+silc_server_command_process_error(SilcServerCommandReplyContext cmd,
+ SilcStatus error)
+{
+ SilcServer server = cmd->server;
+
+ /* If we received notify for invalid ID we'll remove the ID if we
+ have it cached. */
+ if (error == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID &&
+ cmd->sock->type == SILC_SOCKET_TYPE_ROUTER) {
+ SilcClientEntry client;
+ SilcUInt32 tmp_len;
+ unsigned char *tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
+ if (tmp) {
+ SilcClientID *client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
+ if (client_id) {
+ SILC_LOG_DEBUG(("Received invalid client ID notification, deleting "
+ "the entry from cache"));
+ client = silc_idlist_find_client_by_id(server->global_list,
+ client_id, FALSE, NULL);
+ if (client) {
+ silc_server_remove_from_channels(server, NULL, client, TRUE,
+ NULL, TRUE);
+ silc_idlist_del_client(server->global_list, client);
+ }
+ silc_free(client_id);
+ }
+ }
+ }
+}
+
/* Caches the received WHOIS information. */
static char
silc_server_command_reply_whois_save(SilcServerCommandReplyContext cmd)
{
SilcServer server = cmd->server;
- unsigned char *tmp, *id_data;
+ unsigned char *tmp, *id_data, *umodes;
char *nickname, *username, *realname, *servername = NULL;
unsigned char *fingerprint;
SilcClientID *client_id;
SilcClientEntry client;
+ SilcIDCacheEntry cache = NULL;
char global = FALSE;
char *nick;
- SilcUInt32 mode = 0, len, id_len, flen;
- int expire = 0;
+ SilcUInt32 mode = 0, len, len2, id_len, flen;
id_data = silc_argument_get_arg_type(cmd->args, 2, &id_len);
nickname = silc_argument_get_arg_type(cmd->args, 3, &len);
client->data.status |= SILC_IDLIST_STATUS_RESOLVED;
client->data.status &= ~SILC_IDLIST_STATUS_RESOLVING;
- /* If client is global and is not on any channel then add that we'll
- expire the entry after a while. */
- if (global && !silc_hash_table_count(client->channels) &&
- server->server_type == SILC_SERVER)
- expire = time(NULL) + 300;
-
/* Create new cache entry */
silc_idcache_add(global ? server->global_list->clients :
server->local_list->clients, nick, client->id,
- client, expire, NULL);
+ client, 0, &cache);
silc_free(client_id);
}
+ /* Save channel list if it was sent to us */
+ if (server->server_type == SILC_SERVER) {
+ tmp = silc_argument_get_arg_type(cmd->args, 6, &len);
+ umodes = silc_argument_get_arg_type(cmd->args, 10, &len2);
+ if (tmp && umodes) {
+ SilcBufferStruct channels_buf, umodes_buf;
+ silc_buffer_set(&channels_buf, tmp, len);
+ silc_buffer_set(&umodes_buf, umodes, len2);
+ silc_server_save_user_channels(server, cmd->sock, client, &channels_buf,
+ &umodes_buf);
+ } else {
+ silc_server_save_user_channels(server, cmd->sock, client, NULL, NULL);
+ }
+
+ if (cache)
+ /* If client is global and is not on any channel then add that we'll
+ expire the entry after a while. */
+ if (global && !silc_hash_table_count(client->channels))
+ cache->expire = time(NULL) + 300;
+ }
+
if (fingerprint && flen == sizeof(client->data.fingerprint))
memcpy(client->data.fingerprint, fingerprint, flen);
SILC_SERVER_CMD_REPLY_FUNC(whois)
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
- SilcServer server = cmd->server;
- SilcCommandStatus status, error;
+ SilcStatus status, error;
COMMAND_CHECK_STATUS;
}
out:
- /* If we received notify for invalid ID we'll remove the ID if we
- have it cached. */
- if (error == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID &&
- cmd->sock->type == SILC_SOCKET_TYPE_ROUTER) {
- SilcClientEntry client;
- SilcUInt32 tmp_len;
- unsigned char *tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
- if (tmp) {
- SilcClientID *client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
- if (client_id) {
- SILC_LOG_DEBUG(("Received invalid client ID notification, deleting "
- "the entry from cache"));
- client = silc_idlist_find_client_by_id(server->global_list,
- client_id, FALSE, NULL);
- if (client) {
- silc_server_remove_from_channels(server, NULL, client, TRUE,
- NULL, TRUE);
- silc_idlist_del_client(server->global_list, client);
- }
- silc_free(client_id);
- }
- }
- }
-
+ silc_server_command_process_error(cmd, error);
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_WHOIS);
silc_server_command_reply_free(cmd);
+ return;
+
+ err:
+ silc_server_command_process_error(cmd, error);
+ silc_server_command_reply_free(cmd);
}
/* Caches the received WHOWAS information for a short period of time. */
SILC_SERVER_CMD_REPLY_FUNC(whowas)
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
- SilcCommandStatus status, error;
+ SilcStatus status, error;
COMMAND_CHECK_STATUS;
out:
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_WHOWAS);
+ err:
silc_server_command_reply_free(cmd);
}
SILC_SERVER_CMD_REPLY_FUNC(identify)
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
- SilcServer server = cmd->server;
- SilcCommandStatus status, error;
+ SilcStatus status, error;
COMMAND_CHECK_STATUS;
}
out:
- /* If we received notify for invalid ID we'll remove the ID if we
- have it cached. */
- if (error == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID &&
- cmd->sock->type == SILC_SOCKET_TYPE_ROUTER) {
- SilcClientEntry client;
- SilcUInt32 tmp_len;
- unsigned char *tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
- if (tmp) {
- SilcClientID *client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
- if (client_id) {
- SILC_LOG_DEBUG(("Received invalid client ID notification, deleting "
- "the entry from cache"));
- client = silc_idlist_find_client_by_id(server->global_list,
- client_id, FALSE, NULL);
- if (client) {
- silc_server_remove_from_channels(server, NULL, client, TRUE,
- NULL, TRUE);
- silc_idlist_del_client(server->global_list, client);
- }
- silc_free(client_id);
- }
- }
- }
-
+ silc_server_command_process_error(cmd, error);
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_IDENTIFY);
silc_server_command_reply_free(cmd);
+ return;
+
+ err:
+ silc_server_command_process_error(cmd, error);
+ silc_server_command_reply_free(cmd);
}
/* Received reply fro INFO command. Cache the server and its information */
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status, error;
+ SilcStatus status, error;
SilcServerEntry entry;
SilcServerID *server_id;
SilcUInt32 tmp_len;
out:
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_INFO);
+ err:
silc_server_command_reply_free(cmd);
}
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status, error;
+ SilcStatus status, error;
SilcServerEntry entry = NULL;
SilcServerID *server_id;
SilcUInt32 tmp_len;
out:
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_MOTD);
+ err:
silc_server_command_reply_free(cmd);
if (entry)
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
SilcIDCacheEntry cache = NULL;
- SilcCommandStatus status, error;
+ SilcStatus status, error;
SilcChannelID *id;
SilcClientID *client_id = NULL;
SilcChannelEntry entry;
char *channel_name, *tmp;
SilcUInt32 mode, created;
SilcBuffer keyp = NULL, client_id_list = NULL, client_mode_list = NULL;
+ SilcPublicKey founder_key = NULL;
COMMAND_CHECK_STATUS;
silc_buffer_pull_tail(client_mode_list, len);
silc_buffer_put(client_mode_list, tmp, len);
+ /* Get founder key */
+ tmp = silc_argument_get_arg_type(cmd->args, 15, &len);
+ if (tmp)
+ silc_pkcs_public_key_decode(tmp, len, &founder_key);
+
/* See whether we already have the channel. */
entry = silc_idlist_find_channel_by_name(server->local_list,
channel_name, &cache);
them in the entry */
if (!(mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) && entry->founder_key) {
silc_pkcs_public_key_free(entry->founder_key);
- silc_free(entry->founder_passwd);
- entry->founder_passwd = NULL;
+ entry->founder_key = NULL;
}
}
+ if (founder_key) {
+ if (entry->founder_key)
+ silc_pkcs_public_key_free(entry->founder_key);
+ entry->founder_key = founder_key;
+ founder_key = NULL;
+ }
+
if (entry->hmac_name && hmac) {
silc_free(entry->hmac_name);
entry->hmac_name = strdup(silc_hmac_get_name(hmac));
silc_server_save_users_on_channel(server, cmd->sock, entry,
client_id, client_id_list,
client_mode_list, list_count);
+ entry->users_resolved = TRUE;
out:
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_JOIN);
+ err:
silc_free(client_id);
silc_server_command_reply_free(cmd);
+ silc_pkcs_public_key_free(founder_key);
if (client_id_list)
silc_buffer_free(client_id_list);
if (client_mode_list)
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status, error;
+ SilcStatus status, error;
unsigned char *tmp;
SilcUInt32 tmp_len;
SilcBufferStruct buf;
}
out:
- SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_USERS);
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_STATS);
+ err:
+ silc_server_command_reply_free(cmd);
}
SILC_SERVER_CMD_REPLY_FUNC(users)
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status, error;
+ SilcStatus status, error;
SilcChannelEntry channel;
SilcChannelID *channel_id = NULL;
SilcBuffer client_id_list;
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);
}
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status, error;
+ SilcStatus status, error;
SilcClientEntry client = NULL;
SilcServerEntry server_entry = NULL;
SilcClientID *client_id = NULL;
}
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->data.public_key = public_key;
+ public_key = NULL;
} else {
goto out;
}
silc_free(server_id);
if (public_key)
silc_pkcs_public_key_free(public_key);
+ err:
silc_server_command_reply_free(cmd);
}
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status, error;
+ SilcStatus status, error;
SilcChannelID *channel_id = NULL;
SilcChannelEntry channel;
SilcIDCacheEntry cache;
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;
+
+ out:
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_WATCH);
+ err:
silc_server_command_reply_free(cmd);
}