#include "server_internal.h"
#include "command_reply.h"
-/* All functions that call the COMMAND_CHECK_STATUS or the
- COMMAND_CHECK_STATUS_LIST macros must have out: goto label. */
-
-#define COMMAND_CHECK_STATUS \
-do { \
- SILC_LOG_DEBUG(("Start")); \
- SILC_GET16_MSB(status, silc_argument_get_arg_type(cmd->args, 1, NULL)); \
- if (status != SILC_STATUS_OK) \
- goto out; \
-} while(0)
-
-#define COMMAND_CHECK_STATUS_LIST \
-do { \
- SILC_LOG_DEBUG(("Start")); \
- SILC_GET16_MSB(status, silc_argument_get_arg_type(cmd->args, 1, NULL)); \
- if (status != SILC_STATUS_OK && \
- status != SILC_STATUS_LIST_START && \
- status != SILC_STATUS_LIST_ITEM && \
- status != SILC_STATUS_LIST_END) \
- goto out; \
+/* 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; \
} while(0)
/* Server command reply list. Not all commands have reply function as
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);
username = silc_argument_get_arg_type(cmd->args, 4, &len);
realname = silc_argument_get_arg_type(cmd->args, 5, &len);
- if (!id_data || !nickname || !username || !realname) {
- SILC_LOG_ERROR(("Incomplete WHOIS info: %s %s %s",
- nickname ? nickname : "",
- username ? username : "",
- realname ? realname : ""));
+ if (!id_data || !nickname || !username || !realname)
return FALSE;
- }
tmp = silc_argument_get_arg_type(cmd->args, 7, &len);
if (tmp)
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);
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ SilcStatus status, error;
- COMMAND_CHECK_STATUS_LIST;
+ COMMAND_CHECK_STATUS;
if (!silc_server_command_reply_whois_save(cmd))
goto out;
out:
/* If we received notify for invalid ID we'll remove the ID if we
have it cached. */
- if (status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID &&
+ if (error == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID &&
cmd->sock->type == SILC_SOCKET_TYPE_ROUTER) {
SilcClientEntry client;
SilcUInt32 tmp_len;
SILC_SERVER_CMD_REPLY_FUNC(whowas)
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
- SilcCommandStatus status;
+ SilcStatus status, error;
- COMMAND_CHECK_STATUS_LIST;
+ COMMAND_CHECK_STATUS;
if (!silc_server_command_reply_whowas_save(cmd))
goto out;
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ SilcStatus status, error;
- COMMAND_CHECK_STATUS_LIST;
+ COMMAND_CHECK_STATUS;
if (!silc_server_command_reply_identify_save(cmd))
goto out;
out:
/* If we received notify for invalid ID we'll remove the ID if we
have it cached. */
- if (status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID &&
+ if (error == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID &&
cmd->sock->type == SILC_SOCKET_TYPE_ROUTER) {
SilcClientEntry client;
SilcUInt32 tmp_len;
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ SilcStatus status, error;
SilcServerEntry entry;
SilcServerID *server_id;
SilcUInt32 tmp_len;
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ SilcStatus status, error;
SilcServerEntry entry = NULL;
SilcServerID *server_id;
SilcUInt32 tmp_len;
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
SilcIDCacheEntry cache = NULL;
- SilcCommandStatus status;
+ SilcStatus status, error;
SilcChannelID *id;
SilcClientID *client_id = NULL;
SilcChannelEntry entry;
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);
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ 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);
}
SILC_SERVER_CMD_REPLY_FUNC(users)
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ 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);
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ 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;
}
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ SilcStatus status, error;
SilcChannelID *channel_id = NULL;
SilcChannelEntry channel;
SilcIDCacheEntry cache;
SilcUInt32 usercount = 0;
bool global_list = FALSE;
- COMMAND_CHECK_STATUS_LIST;
+ COMMAND_CHECK_STATUS;
tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
channel_id = silc_id_payload_parse_id(tmp, len, NULL);
silc_free(channel_id);
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);
+ silc_server_command_reply_free(cmd);
+}