#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_CMD_REPLY_FUNC(whois)
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
- SilcServer server = cmd->server;
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. */
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;
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 */
out:
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_INFO);
+ err:
silc_server_command_reply_free(cmd);
}
out:
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_MOTD);
+ err:
silc_server_command_reply_free(cmd);
if (entry)
out:
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_JOIN);
+ err:
silc_free(client_id);
silc_server_command_reply_free(cmd);
out:
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_STATS);
+ err:
+ silc_server_command_reply_free(cmd);
}
SILC_SERVER_CMD_REPLY_FUNC(users)
out:
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_USERS);
silc_free(channel_id);
+ err:
silc_server_command_reply_free(cmd);
}
silc_free(server_id);
if (public_key)
silc_pkcs_public_key_free(public_key);
+ err:
silc_server_command_reply_free(cmd);
}
out:
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_LIST);
silc_free(channel_id);
+ err:
silc_server_command_reply_free(cmd);
}
out:
SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_WATCH);
+ err:
silc_server_command_reply_free(cmd);
}