SILC_SERVER_CMD_REPLY(whowas, WHOWAS),
SILC_SERVER_CMD_REPLY(identify, IDENTIFY),
SILC_SERVER_CMD_REPLY(info, INFO),
+ SILC_SERVER_CMD_REPLY(motd, MOTD),
SILC_SERVER_CMD_REPLY(join, JOIN),
SILC_SERVER_CMD_REPLY(users, USERS),
}
}
-/* Caches the received WHOIS information. If we are normal server currently
- we cache global information only for short period of time. */
-/* XXX cache expirying not implemented yet! */
+/* Caches the received WHOIS information. */
static char
silc_server_command_reply_whois_save(SilcServerCommandReplyContext cmd)
/* We don't have that client anywhere, add it. The client is added
to global list since server didn't have it in the lists so it must be
global. */
- client = silc_idlist_add_client(server->global_list, nick,
+ client = silc_idlist_add_client(server->global_list, nick, strlen(nick),
strdup(username),
strdup(realname), client_id,
cmd->sock->user_data, NULL);
/* We don't have that client anywhere, add it. The client is added
to global list since server didn't have it in the lists so it must be
global. */
- client = silc_idlist_add_client(server->global_list, nick,
- strdup(username),
- strdup(realname),
+ client = silc_idlist_add_client(server->global_list, nick, strlen(nick),
+ strdup(username), strdup(realname),
silc_id_dup(client_id, SILC_ID_CLIENT),
cmd->sock->user_data, NULL);
if (!client)
/* We don't have that client anywhere, add it. The client is added
to global list since server didn't have it in the lists so it must be
global. */
- client = silc_idlist_add_client(server->global_list, nick,
+ client = silc_idlist_add_client(server->global_list, nick, strlen(nick),
username ? strdup(username) : NULL, NULL,
client_id, cmd->sock->user_data, NULL);
client->data.registered = TRUE;
if (!server_id)
goto out;
- /* Get the info string */
+ /* Get the name */
name = silc_argument_get_arg_type(cmd->args, 3, &tmp_len);
if (tmp_len > 256)
goto out;
silc_server_command_reply_free(cmd);
}
+/* Received reply fro MOTD command. */
+
+SILC_SERVER_CMD_REPLY_FUNC(motd)
+{
+ SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
+ SilcServer server = cmd->server;
+ SilcCommandStatus status;
+ SilcServerEntry entry;
+ SilcServerID *server_id;
+ unsigned int tmp_len;
+ unsigned char *tmp;
+
+ COMMAND_CHECK_STATUS;
+
+ /* Get Server ID */
+ 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);
+ if (!server_id)
+ goto out;
+
+ entry = silc_idlist_find_server_by_id(server->local_list, server_id, NULL);
+ if (!entry) {
+ entry = silc_idlist_find_server_by_id(server->global_list, server_id,
+ NULL);
+ if (!entry)
+ goto out;
+ }
+
+ /* Get the motd */
+ tmp = silc_argument_get_arg_type(cmd->args, 3, &tmp_len);
+ if (tmp_len > 256)
+ tmp = NULL;
+
+ entry->motd = tmp;
+
+ /* Execute any pending commands */
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_MOTD);
+
+ entry->motd = NULL;
+
+ out:
+ SILC_SERVER_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_MOTD);
+ silc_server_command_reply_free(cmd);
+}
+
/* Received reply for forwarded JOIN command. Router has created or joined
the client to the channel. We save some channel information locally
for future use. */
{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
+ SilcIDCacheEntry cache = NULL;
SilcCommandStatus status;
SilcChannelID *id;
SilcClientID *client_id = NULL;
unsigned char *id_string;
char *channel_name, *tmp;
unsigned int mode, created;
- SilcBuffer keyp, client_id_list, client_mode_list;
+ SilcBuffer keyp = NULL, client_id_list, client_mode_list;
COMMAND_CHECK_STATUS;
/* Get channel key */
tmp = silc_argument_get_arg_type(cmd->args, 7, &len);
- if (!tmp)
- goto out;
- keyp = silc_buffer_alloc(len);
- silc_buffer_pull_tail(keyp, SILC_BUFFER_END(keyp));
- silc_buffer_put(keyp, tmp, len);
+ if (tmp) {
+ keyp = silc_buffer_alloc(len);
+ silc_buffer_pull_tail(keyp, SILC_BUFFER_END(keyp));
+ silc_buffer_put(keyp, tmp, len);
+ }
id = silc_id_payload_parse_id(id_string, id_len);
if (!id)
silc_buffer_put(client_mode_list, tmp, len);
/* See whether we already have the channel. */
- entry = silc_idlist_find_channel_by_id(server->local_list, id, NULL);
+ entry = silc_idlist_find_channel_by_name(server->local_list,
+ channel_name, &cache);
if (!entry) {
/* Add new channel */
goto out;
}
} else {
- silc_free(id);
+ /* The entry exists. */
+ if (entry->id)
+ silc_free(entry->id);
+ entry->id = id;
+ cache->id = entry->id;
+
+ /* Remove the founder auth data if the mode is not set but we have
+ them in the entry */
+ if (!(mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) && entry->founder_key) {
+ silc_pkcs_public_key_free(entry->founder_key);
+ if (entry->founder_passwd) {
+ silc_free(entry->founder_passwd);
+ entry->founder_passwd = NULL;
+ }
+ }
+ }
+
+ if (entry->hmac_name && hmac) {
+ silc_free(entry->hmac_name);
+ entry->hmac_name = strdup(hmac->hmac->name);
+ }
+
+ /* Get the ban list */
+ tmp = silc_argument_get_arg_type(cmd->args, 8, &len);
+ if (tmp) {
+ if (entry->ban_list)
+ silc_free(entry->ban_list);
+ entry->ban_list = silc_calloc(len, sizeof(*entry->ban_list));
+ memcpy(entry->ban_list, tmp, len);
+ }
+
+ /* Get the invite list */
+ tmp = silc_argument_get_arg_type(cmd->args, 9, &len);
+ if (tmp) {
+ if (entry->invite_list)
+ silc_free(entry->invite_list);
+ entry->invite_list = silc_calloc(len, sizeof(*entry->invite_list));
+ memcpy(entry->invite_list, tmp, len);
+ }
+
+ /* Get the topic */
+ tmp = silc_argument_get_arg_type(cmd->args, 10, &len);
+ if (tmp) {
+ if (entry->topic)
+ silc_free(entry->topic);
+ entry->topic = strdup(tmp);
}
/* If channel was not created we know there is global users on the
entry->mode = mode;
/* Save channel key */
- silc_server_save_channel_key(server, keyp, entry);
- silc_buffer_free(keyp);
+ if (!(entry->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
+ silc_server_save_channel_key(server, keyp, entry);
+ }
+ if (keyp)
+ silc_buffer_free(keyp);
/* Save the users to the channel */
silc_server_save_users_on_channel(server, cmd->sock, entry,