command_reply.c
- Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+ Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2001 Pekka Riikonen
+ Copyright (C) 1997 - 2002 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#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. */
+/* All functions that call the COMMAND_CHECK_STATUS 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; \
+#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_CMD_REPLY(info, INFO),
SILC_SERVER_CMD_REPLY(motd, MOTD),
SILC_SERVER_CMD_REPLY(join, JOIN),
+ SILC_SERVER_CMD_REPLY(stats, STATS),
SILC_SERVER_CMD_REPLY(users, USERS),
SILC_SERVER_CMD_REPLY(getkey, GETKEY),
SILC_SERVER_CMD_REPLY(list, LIST),
SilcServerCommandReplyContext ctx;
SilcCommandPayload payload;
SilcCommand command;
- uint16 ident;
+ SilcUInt16 ident;
SILC_LOG_DEBUG(("Start"));
SilcClientEntry client;
char global = FALSE;
char *nick;
- uint32 mode = 0, len, id_len, flen;
+ SilcUInt32 mode = 0, len, id_len, flen;
int expire = 0;
id_data = silc_argument_get_arg_type(cmd->args, 2, &id_len);
if (tmp)
SILC_GET32_MSB(mode, tmp);
- client_id = silc_id_payload_parse_id(id_data, id_len);
+ client_id = silc_id_payload_parse_id(id_data, id_len, NULL);
if (!client_id)
return FALSE;
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ SilcCommandStatus 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;
- uint32 tmp_len;
+ 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);
+ 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"));
silc_server_command_reply_whowas_save(SilcServerCommandReplyContext cmd)
{
SilcServer server = cmd->server;
- uint32 len, id_len;
+ SilcUInt32 len, id_len;
unsigned char *id_data;
char *nickname, *username, *realname, *servername = NULL;
SilcClientID *client_id;
realname = silc_argument_get_arg_type(cmd->args, 5, &len);
- client_id = silc_id_payload_parse_id(id_data, id_len);
+ client_id = silc_id_payload_parse_id(id_data, id_len, NULL);
if (!client_id)
return FALSE;
SILC_SERVER_CMD_REPLY_FUNC(whowas)
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
- SilcCommandStatus status;
+ SilcCommandStatus status, error;
- COMMAND_CHECK_STATUS_LIST;
+ COMMAND_CHECK_STATUS;
if (!silc_server_command_reply_whowas_save(cmd))
goto out;
silc_server_command_reply_identify_save(SilcServerCommandReplyContext cmd)
{
SilcServer server = cmd->server;
- uint32 len, id_len;
+ SilcUInt32 len, id_len;
unsigned char *id_data;
char *name, *info;
SilcClientID *client_id = NULL;
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ SilcCommandStatus 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;
- uint32 tmp_len;
+ 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);
+ 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"));
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ SilcCommandStatus status, error;
SilcServerEntry entry;
SilcServerID *server_id;
- uint32 tmp_len;
+ SilcUInt32 tmp_len;
unsigned char *tmp, *name;
COMMAND_CHECK_STATUS;
tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
if (!tmp)
goto out;
- server_id = silc_id_payload_parse_id(tmp, tmp_len);
+ server_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
if (!server_id)
goto out;
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ SilcCommandStatus status, error;
SilcServerEntry entry = NULL;
SilcServerID *server_id;
- uint32 tmp_len;
+ SilcUInt32 tmp_len;
unsigned char *tmp;
COMMAND_CHECK_STATUS;
tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
if (!tmp)
goto out;
- server_id = silc_id_payload_parse_id(tmp, tmp_len);
+ server_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
if (!server_id)
goto out;
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
SilcIDCacheEntry cache = NULL;
- SilcCommandStatus status;
+ SilcCommandStatus status, error;
SilcChannelID *id;
SilcClientID *client_id = NULL;
SilcChannelEntry entry;
SilcHmac hmac = NULL;
- uint32 id_len, len, list_count;
+ SilcUInt32 id_len, len, list_count;
unsigned char *id_string;
char *channel_name, *tmp;
- uint32 mode, created;
+ SilcUInt32 mode, created;
SilcBuffer keyp = NULL, client_id_list = NULL, client_mode_list = NULL;
COMMAND_CHECK_STATUS;
tmp = silc_argument_get_arg_type(cmd->args, 4, &len);
if (!tmp)
goto out;
- client_id = silc_id_payload_parse_id(tmp, len);
+ client_id = silc_id_payload_parse_id(tmp, len, NULL);
if (!client_id)
goto out;
}
/* Parse the Channel ID */
- id = silc_id_payload_parse_id(id_string, id_len);
+ id = silc_id_payload_parse_id(id_string, id_len, NULL);
if (!id)
goto out;
/* If the channel is found from global list we must move it to the
local list. */
- entry = silc_idlist_find_channel_by_name(server->global_list,
+ entry = silc_idlist_find_channel_by_name(server->global_list,
channel_name, &cache);
- if (entry) {
- if (entry->rekey) {
- silc_schedule_task_del_by_context(server->schedule, entry->rekey);
- SILC_LOG_ERROR(("global_list->channels: entry->rekey != NULL, inform Pekka now!!!"));
- }
+ if (entry)
silc_idlist_del_channel(server->global_list, entry);
- }
/* Add the channel to our local list. */
- entry = silc_idlist_add_channel(server->local_list, strdup(channel_name),
- SILC_CHANNEL_MODE_NONE, id,
+ entry = silc_idlist_add_channel(server->local_list, strdup(channel_name),
+ SILC_CHANNEL_MODE_NONE, id,
server->router, NULL, hmac, 0);
if (!entry) {
silc_free(id);
silc_buffer_free(client_mode_list);
}
+/* Received reply to STATS command. */
+
+SILC_SERVER_CMD_REPLY_FUNC(stats)
+{
+ SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
+ SilcServer server = cmd->server;
+ SilcCommandStatus status, error;
+ unsigned char *tmp;
+ SilcUInt32 tmp_len;
+ SilcBufferStruct buf;
+
+ COMMAND_CHECK_STATUS;
+
+ /* Get statistics structure */
+ tmp = silc_argument_get_arg_type(cmd->args, 3, &tmp_len);
+ if (server->server_type == SILC_SERVER && tmp) {
+ silc_buffer_set(&buf, tmp, tmp_len);
+ silc_buffer_unformat(&buf,
+ SILC_STR_UI_INT(NULL),
+ SILC_STR_UI_INT(NULL),
+ SILC_STR_UI_INT(NULL),
+ SILC_STR_UI_INT(NULL),
+ SILC_STR_UI_INT(NULL),
+ SILC_STR_UI_INT(NULL),
+ SILC_STR_UI_INT(&server->stat.cell_clients),
+ SILC_STR_UI_INT(&server->stat.cell_channels),
+ SILC_STR_UI_INT(&server->stat.cell_servers),
+ SILC_STR_UI_INT(&server->stat.clients),
+ SILC_STR_UI_INT(&server->stat.channels),
+ SILC_STR_UI_INT(&server->stat.servers),
+ SILC_STR_UI_INT(&server->stat.routers),
+ SILC_STR_UI_INT(&server->stat.server_ops),
+ SILC_STR_UI_INT(&server->stat.router_ops),
+ SILC_STR_END);
+ }
+
+ out:
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_USERS);
+}
+
SILC_SERVER_CMD_REPLY_FUNC(users)
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ SilcCommandStatus status, error;
SilcChannelEntry channel;
SilcChannelID *channel_id = NULL;
SilcBuffer client_id_list;
SilcBuffer client_mode_list;
unsigned char *tmp;
- uint32 tmp_len;
- uint32 list_count;
+ SilcUInt32 tmp_len;
+ SilcUInt32 list_count;
COMMAND_CHECK_STATUS;
tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
if (!tmp)
goto out;
- channel_id = silc_id_payload_parse_id(tmp, tmp_len);
+ channel_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
if (!channel_id)
goto out;
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ SilcCommandStatus status, error;
SilcClientEntry client = NULL;
SilcServerEntry server_entry = NULL;
SilcClientID *client_id = NULL;
SilcServerID *server_id = NULL;
SilcSKEPKType type;
unsigned char *tmp, *pk;
- uint32 len;
- uint16 pk_len;
+ SilcUInt32 len;
+ SilcUInt16 pk_len;
SilcIDPayload idp = NULL;
SilcIdType id_type;
SilcPublicKey public_key = NULL;
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
- SilcCommandStatus status;
+ SilcCommandStatus status, error;
SilcChannelID *channel_id = NULL;
SilcChannelEntry channel;
SilcIDCacheEntry cache;
- uint32 len;
+ SilcUInt32 len;
unsigned char *tmp, *name, *topic;
- uint32 usercount = 0;
+ 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);
+ channel_id = silc_id_payload_parse_id(tmp, len, NULL);
if (!channel_id)
goto out;