#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_data(client);
+ silc_idlist_del_client(server->global_list, client);
+ }
+ silc_free(client_id);
+ }
+ }
+ }
+}
+
/* Caches the received WHOIS information. */
static char
client = silc_idlist_add_client(server->global_list, nick,
strdup(username),
strdup(realname), client_id,
- cmd->sock->user_data, NULL,
- time(NULL) + 300);
+ cmd->sock->user_data, NULL, 0);
if (!client) {
SILC_LOG_ERROR(("Could not add new client to the ID Cache"));
return FALSE;
/* Create new cache entry */
silc_idcache_add(global ? server->global_list->clients :
server->local_list->clients, nick, client->id,
- client, 0, &cache);
+ client, 0, NULL);
silc_free(client_id);
}
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))
+ /* If client is global and is not on any channel then add that we'll
+ expire the entry after a while. */
+ if (global) {
+ silc_idlist_find_client_by_id(server->global_list, client->id,
+ FALSE, &cache);
+ if (!silc_hash_table_count(client->channels))
cache->expire = time(NULL) + 300;
+ else
+ cache->expire = 0;
+ }
}
if (fingerprint && flen == sizeof(client->data.fingerprint))
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. */
client, 0, NULL);
}
+ /* If client is global and is not on any channel then add that we'll
+ expire the entry after a while. */
+ if (global) {
+ silc_idlist_find_client_by_id(server->global_list, client->id,
+ FALSE, &cache);
+ if (!silc_hash_table_count(client->channels))
+ cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
+ else
+ cache->expire = 0;
+ }
+
silc_free(client_id);
return TRUE;
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);
}
global. */
client = silc_idlist_add_client(server->global_list, nick,
info ? strdup(info) : NULL, NULL,
- client_id, cmd->sock->user_data, NULL,
- time(NULL) + 300);
+ client_id, cmd->sock->user_data,
+ NULL, time(NULL) + 300);
if (!client) {
SILC_LOG_ERROR(("Could not add new client to the ID Cache"));
goto error;
client->data.status &= ~SILC_IDLIST_STATUS_RESOLVING;
if (name) {
- /* 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;
-
/* Add new cache entry */
silc_idcache_add(global ? server->global_list->clients :
server->local_list->clients, nick, client->id,
client, expire, NULL);
}
+ /* If client is global and is not on any channel then add that we'll
+ expire the entry after a while. */
+ if (global && server->server_type == SILC_SERVER) {
+ SilcIDCacheEntry cache = NULL;
+ silc_idlist_find_client_by_id(server->global_list, client->id,
+ FALSE, &cache);
+ if (!silc_hash_table_count(client->channels))
+ cache->expire = time(NULL) + 300;
+ else
+ cache->expire = 0;
+ }
+
silc_free(client_id);
}
/* We don't have that server anywhere, add it. */
server_entry = silc_idlist_add_server(server->global_list,
strdup(name), 0,
- server_id, NULL, NULL);
+ server_id, server->router,
+ SILC_PRIMARY_ROUTE(server));
if (!server_entry) {
silc_free(server_id);
goto error;
if (server->server_type != SILC_SERVER)
goto error;
- /* We don't have that server anywhere, add it. */
+ /* We don't have that channel anywhere, add it. */
channel = silc_idlist_add_channel(server->global_list, strdup(name),
SILC_CHANNEL_MODE_NONE, channel_id,
server->router, NULL, NULL, 0);
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;
/* Add the server to global list */
server_id = silc_id_dup(server_id, SILC_ID_SERVER);
entry = silc_idlist_add_server(server->global_list, name, 0,
- server_id, NULL, NULL);
+ server_id, cmd->sock->user_data,
+ cmd->sock);
if (!entry) {
silc_free(server_id);
goto out;
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);
goto out;
}
server->stat.my_channels++;
+ server->stat.channels++;
} else {
/* The entry exists. */
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));
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_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;
goto out;
idp = silc_id_payload_encode(channel_id, SILC_ID_CHANNEL);
- silc_server_send_command(server, server->router->connection,
+ silc_server_send_command(server, SILC_PRIMARY_ROUTE(server),
SILC_COMMAND_IDENTIFY, ++server->cmd_ident,
1, 5, idp->data, idp->len);
silc_buffer_free(idp);
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;
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);
}