#include "fe-common/core/keyboard.h"
#include "fe-common/silc/module-formats.h"
+#include "core.h"
+
static void
silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
const char *name, SilcSocketType conn_type,
void silc_channel_message(SilcClient client, SilcClientConnection conn,
SilcClientEntry sender, SilcChannelEntry channel,
- SilcMessageFlags flags, char *msg)
+ SilcMessageFlags flags, const unsigned char *message,
+ SilcUInt32 message_len)
{
SILC_SERVER_REC *server;
SILC_NICK_REC *nick;
SILC_LOG_DEBUG(("Start"));
- if (!msg)
+ if (!message)
return;
server = conn == NULL ? NULL : conn->context;
if (flags & SILC_MESSAGE_FLAG_ACTION)
printformat_module("fe-common/silc", server, channel->channel_name,
MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_ACTION,
- nick == NULL ? "[<unknown>]" : nick->nick, msg);
+ nick == NULL ? "[<unknown>]" : nick->nick, message);
else if (flags & SILC_MESSAGE_FLAG_NOTICE)
printformat_module("fe-common/silc", server, channel->channel_name,
MSGLEVEL_NOTICES, SILCTXT_CHANNEL_NOTICE,
- nick == NULL ? "[<unknown>]" : nick->nick, msg);
+ nick == NULL ? "[<unknown>]" : nick->nick, message);
else
- signal_emit("message public", 6, server, msg,
+ signal_emit("message public", 6, server, message,
nick == NULL ? "[<unknown>]" : nick->nick,
nick == NULL ? "" : nick->host == NULL ? "" : nick->host,
chanrec->name, nick);
void silc_private_message(SilcClient client, SilcClientConnection conn,
SilcClientEntry sender, SilcMessageFlags flags,
- char *msg)
+ const unsigned char *message,
+ SilcUInt32 message_len)
{
SILC_SERVER_REC *server;
char userhost[256];
if (sender->username)
snprintf(userhost, sizeof(userhost) - 1, "%s@%s",
sender->username, sender->hostname);
- signal_emit("message private", 4, server, msg,
+ signal_emit("message private", 4, server, message,
sender->nickname ? sender->nickname : "[<unknown>]",
sender->username ? userhost : NULL);
}
SILC_CHANNEL_REC *chanrec;
SILC_NICK_REC *nickrec;
SilcClientEntry client_entry, client_entry2;
- SilcChannelEntry channel;
+ SilcChannelEntry channel, channel2;
SilcServerEntry server_entry;
SilcIdType idtype;
void *entry;
signal_emit("message topic", 5, server, channel->channel_name,
tmp, server_entry->server_name,
server_entry->server_name);
- } else {
+ } else if (idtype == SILC_ID_CHANNEL) {
channel = (SilcChannelEntry)entry;
signal_emit("message topic", 5, server, channel->channel_name,
tmp, channel->channel_name, channel->channel_name);
client_entry = va_arg(va, SilcClientEntry);
client_entry2 = va_arg(va, SilcClientEntry);
+
+ if (!strcmp(client_entry->nickname, client_entry2->nickname))
+ break;
memset(userhost, 0, sizeof(userhost));
snprintf(userhost, sizeof(userhost) - 1, "%s@%s",
MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE,
channel->channel_name, tmp ? tmp : "removed all",
server_entry->server_name);
+ } else if (idtype == SILC_ID_CHANNEL) {
+ channel2 = (SilcChannelEntry)entry;
+ printformat_module("fe-common/silc", server, channel->channel_name,
+ MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE,
+ channel->channel_name, tmp ? tmp : "removed all",
+ channel2->channel_name);
}
silc_free(tmp);
SILC_LOG_DEBUG(("Notify: CUMODE_CHANGE"));
- client_entry = va_arg(va, SilcClientEntry);
+ idtype = va_arg(va, int);
+ entry = va_arg(va, void *);
mode = va_arg(va, SilcUInt32);
client_entry2 = va_arg(va, SilcClientEntry);
channel = va_arg(va, SilcChannelEntry);
}
}
- printformat_module("fe-common/silc", server, channel->channel_name,
- MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE,
- channel->channel_name, client_entry2->nickname,
- tmp ? tmp : "removed all",
- client_entry->nickname);
+ if (idtype == SILC_ID_CLIENT) {
+ client_entry = (SilcClientEntry)entry;
+ printformat_module("fe-common/silc", server, channel->channel_name,
+ MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE,
+ channel->channel_name, client_entry2->nickname,
+ tmp ? tmp : "removed all",
+ client_entry->nickname);
+ } else if (idtype == SILC_ID_SERVER) {
+ server_entry = (SilcServerEntry)entry;
+ printformat_module("fe-common/silc", server, channel->channel_name,
+ MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE,
+ channel->channel_name, client_entry2->nickname,
+ tmp ? tmp : "removed all",
+ server_entry->server_name);
+ } else if (idtype == SILC_ID_CHANNEL) {
+ channel2 = (SilcChannelEntry)entry;
+ printformat_module("fe-common/silc", server, channel->channel_name,
+ MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE,
+ channel->channel_name, client_entry2->nickname,
+ tmp ? tmp : "removed all",
+ channel2->channel_name);
+ }
if (mode & SILC_CHANNEL_UMODE_CHANFO)
printformat_module("fe-common/silc",
if (client_entry == conn->local_entry) {
printformat_module("fe-common/silc", server, channel->channel_name,
MSGLEVEL_CRAP, SILCTXT_CHANNEL_KICKED_YOU,
- channel->channel_name, client_entry2->nickname,
+ channel->channel_name,
+ client_entry ? client_entry2->nickname : "",
tmp ? tmp : "");
if (chanrec) {
chanrec->kicked = TRUE;
printformat_module("fe-common/silc", server, channel->channel_name,
MSGLEVEL_CRAP, SILCTXT_CHANNEL_KICKED,
client_entry->nickname, channel->channel_name,
- client_entry2->nickname, tmp ? tmp : "");
+ client_entry2 ? client_entry2->nickname : "",
+ tmp ? tmp : "");
if (chanrec) {
SILC_NICK_REC *nickrec = silc_nicklist_find(chanrec, client_entry);
client_entry = va_arg(va, SilcClientEntry);
tmp = va_arg(va, char *);
+ idtype = va_arg(va, int);
+ entry = va_arg(va, SilcClientEntry);
if (client_entry == conn->local_entry) {
- printformat_module("fe-common/silc", server, NULL,
- MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED_YOU,
- tmp ? tmp : "");
+ if (idtype == SILC_ID_CLIENT) {
+ client_entry2 = (SilcClientEntry)entry;
+ printformat_module("fe-common/silc", server, NULL,
+ MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED_YOU,
+ client_entry2 ? client_entry2->nickname : "",
+ tmp ? tmp : "");
+ } else if (idtype == SILC_ID_SERVER) {
+ server_entry = (SilcServerEntry)entry;
+ printformat_module("fe-common/silc", server, NULL,
+ MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED_YOU,
+ server_entry->server_name, tmp ? tmp : "");
+ } else if (idtype == SILC_ID_CHANNEL) {
+ channel = (SilcChannelEntry)entry;
+ printformat_module("fe-common/silc", server, NULL,
+ MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED_YOU,
+ channel->channel_name, tmp ? tmp : "");
+ }
} else {
list1 = nicklist_get_same_unique(SERVER(server), client_entry);
for (list_tmp = list1; list_tmp != NULL; list_tmp =
nicklist_remove(channel, nickrec);
}
- printformat_module("fe-common/silc", server, NULL,
- MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED,
- client_entry->nickname,
- tmp ? tmp : "");
+ if (idtype == SILC_ID_CLIENT) {
+ client_entry2 = (SilcClientEntry)entry;
+ printformat_module("fe-common/silc", server, NULL,
+ MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED,
+ client_entry->nickname,
+ client_entry2 ? client_entry2->nickname : "",
+ tmp ? tmp : "");
+ } else if (idtype == SILC_ID_SERVER) {
+ server_entry = (SilcServerEntry)entry;
+ printformat_module("fe-common/silc", server, NULL,
+ MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED,
+ client_entry->nickname,
+ server_entry->server_name, tmp ? tmp : "");
+ } else if (idtype == SILC_ID_CHANNEL) {
+ channel = (SilcChannelEntry)entry;
+ printformat_module("fe-common/silc", server, NULL,
+ MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED,
+ client_entry->nickname,
+ channel->channel_name, tmp ? tmp : "");
+ }
}
break;
or connecting failed. This is also the first time application receives
the SilcClientConnection object which it should save somewhere. */
-void silc_connect(SilcClient client, SilcClientConnection conn, int success)
+void silc_connect(SilcClient client, SilcClientConnection conn,
+ SilcClientConnectionStatus status)
{
SILC_SERVER_REC *server = conn->context;
- if (!server && !success) {
- silc_client_close_connection(client, NULL, conn);
+ if (!server || status == SILC_CLIENT_CONN_ERROR) {
+ silc_client_close_connection(client, conn);
return;
}
- if (success) {
+ switch (status) {
+ case SILC_CLIENT_CONN_SUCCESS:
+ /* We have successfully connected to server */
server->connected = TRUE;
signal_emit("event connected", 1, server);
- } else {
+ break;
+
+ case SILC_CLIENT_CONN_SUCCESS_RESUME:
+ /* We have successfully resumed old detached session */
+ server->connected = TRUE;
+ signal_emit("event connected", 1, server);
+
+ /* If we resumed old session check whether we need to update
+ our nickname */
+ if (strcmp(server->nick, conn->local_entry->nickname)) {
+ char *old;
+ old = g_strdup(server->nick);
+ server_change_nick(SERVER(server), conn->local_entry->nickname);
+ nicklist_rename_unique(SERVER(server),
+ conn->local_entry, server->nick,
+ conn->local_entry, conn->local_entry->nickname);
+ signal_emit("message own_nick", 4, server, server->nick, old, "");
+ g_free(old);
+ }
+ break;
+
+ default:
server->connection_lost = TRUE;
if (server->conn)
server->conn->context = NULL;
server_disconnect(SERVER(server));
+ break;
}
}
SILC_LOG_DEBUG(("Start"));
+ if (!server || server->connection_lost)
+ return;
+
if (server->conn && server->conn->local_entry) {
nicklist_rename_unique(SERVER(server),
server->conn->local_entry, server->nick,
ownnick = NICK(silc_nicklist_find(chanrec, conn->local_entry));
nicklist_set_own(CHANNEL(chanrec), ownnick);
signal_emit("channel joined", 1, chanrec);
+ chanrec->entry = channel;
if (chanrec->topic)
printformat_module("fe-common/silc", server, channel->channel_name,
char buf[1024], *nickname, *username, *realname, *nick;
unsigned char *fingerprint;
SilcUInt32 idle, mode;
- SilcBuffer channels;
+ SilcBuffer channels, user_modes;
SilcClientEntry client_entry;
if (status == SILC_STATUS_ERR_NO_SUCH_NICK) {
silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
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) {
client_entry = silc_client_get_client_by_id(client, conn,
client_id);
mode = va_arg(vp, SilcUInt32);
idle = va_arg(vp, SilcUInt32);
fingerprint = va_arg(vp, unsigned char *);
+ user_modes = va_arg(vp, SilcBuffer);
silc_parse_userfqdn(nickname, &nick, NULL);
printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
SILCTXT_WHOIS_REALNAME, realname);
silc_free(nick);
- if (channels) {
+ if (channels && user_modes) {
+ SilcUInt32 *umodes;
SilcDList list = silc_channel_payload_parse_list(channels->data,
channels->len);
- if (list) {
+ if (list && silc_get_mode_list(user_modes, silc_dlist_count(list),
+ &umodes)) {
SilcChannelPayload entry;
+ int i = 0;
+
memset(buf, 0, sizeof(buf));
silc_dlist_start(list);
while ((entry = silc_dlist_get(list)) != SILC_LIST_END) {
- char *m = silc_client_chumode_char(silc_channel_get_mode(entry));
SilcUInt32 name_len;
+ char *m = silc_client_chumode_char(umodes[i++]);
char *name = silc_channel_get_name(entry, &name_len);
if (m)
printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
SILCTXT_WHOIS_CHANNELS, buf);
silc_channel_payload_list_free(list);
+ silc_free(umodes);
}
}
if ((mode & SILC_UMODE_SERVER_OPERATOR) ||
(mode & SILC_UMODE_ROUTER_OPERATOR)) {
strcat(buf, (mode & SILC_UMODE_SERVER_OPERATOR) ?
- "Server Operator " :
+ "Server Operator" :
(mode & SILC_UMODE_ROUTER_OPERATOR) ?
- "SILC Operator " : "[Unknown mode] ");
+ "SILC Operator" : "[Unknown mode]");
}
if (mode & SILC_UMODE_GONE)
- strcat(buf, "away");
+ strcat(buf, " [away]");
+ if (mode & SILC_UMODE_INDISPOSED)
+ strcat(buf, " [indisposed]");
+ if (mode & SILC_UMODE_BUSY)
+ strcat(buf, " [busy]");
+ if (mode & SILC_UMODE_PAGE)
+ strcat(buf, " [page to reach]");
+ if (mode & SILC_UMODE_HYPER)
+ strcat(buf, " [hyper active]");
+ if (mode & SILC_UMODE_ROBOT)
+ strcat(buf, " [robot]");
+ if (mode & SILC_UMODE_ANONYMOUS)
+ strcat(buf, " [anonymous]");
+ if (mode & SILC_UMODE_BLOCK_PRIVMSG)
+ strcat(buf, " [blocks private messages]");
+ if (mode & SILC_UMODE_DETACHED)
+ strcat(buf, " [detached]");
printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
SILCTXT_WHOIS_MODES, buf);
silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
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) {
client_entry = silc_client_get_client_by_id(client, conn,
client_id);
mode = silc_client_chumode_char(chu->mode);
if (e->mode & SILC_UMODE_GONE)
strcat(stat, "G");
- else
+ else if (e->mode & SILC_UMODE_INDISPOSED)
+ strcat(stat, "I");
+ else if (e->mode & SILC_UMODE_BUSY)
+ strcat(stat, "B");
+ else if (e->mode & SILC_UMODE_PAGE)
+ strcat(stat, "P");
+ else if (e->mode & SILC_UMODE_HYPER)
strcat(stat, "H");
+ else if (e->mode & SILC_UMODE_ROBOT)
+ strcat(stat, "R");
+ else if (e->mode & SILC_UMODE_ANONYMOUS)
+ strcat(stat, "?");
+ else
+ strcat(stat, "A");
if (mode)
strcat(stat, mode);
if (!name) {
snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity,
conn->sock->ip, conn->sock->port);
- snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s",
- pw->pw_dir, entity, file);
+ snprintf(filename, sizeof(filename) - 1, "%s/%skeys/%s",
+ get_irssi_dir(), entity, file);
snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity,
conn->sock->hostname, conn->sock->port);
- snprintf(filename2, sizeof(filename2) - 1, "%s/.silc/%skeys/%s",
- pw->pw_dir, entity, file);
+ snprintf(filename2, sizeof(filename2) - 1, "%s/%skeys/%s",
+ get_irssi_dir(), entity, file);
ipf = filename;
hostf = filename2;
} else {
snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity,
name, conn->sock->port);
- snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s",
- pw->pw_dir, entity, file);
+ snprintf(filename, sizeof(filename) - 1, "%s/%skeys/%s",
+ get_irssi_dir(), entity, file);
ipf = filename;
}
fingerprint[i] = '_';
snprintf(file, sizeof(file) - 1, "%skey_%s.pub", entity, fingerprint);
- snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s",
- pw->pw_dir, entity, file);
+ snprintf(filename, sizeof(filename) - 1, "%s/%skeys/%s",
+ get_irssi_dir(), entity, file);
silc_free(fingerprint);
ipf = filename;
return FALSE;
}
+/* Notifies application that file transfer protocol session is being
+ requested by the remote client indicated by the `client_entry' from
+ the `hostname' and `port'. The `session_id' is the file transfer
+ session and it can be used to either accept or reject the file
+ transfer request, by calling the silc_client_file_receive or
+ silc_client_file_close, respectively. */
+
void silc_ftp(SilcClient client, SilcClientConnection conn,
SilcClientEntry client_entry, SilcUInt32 session_id,
const char *hostname, SilcUInt16 port)
client_entry->nickname, hostname, portstr);
}
+/* Delivers SILC session detachment data indicated by `detach_data' to the
+ application. If application has issued SILC_COMMAND_DETACH command
+ the client session in the SILC network is not quit. The client remains
+ in the network but is detached. The detachment data may be used later
+ to resume the session in the SILC Network. The appliation is
+ responsible of saving the `detach_data', to for example in a file.
+
+ The detachment data can be given as argument to the functions
+ silc_client_connect_to_server, or silc_client_add_connection when
+ creating connection to remote server, inside SilcClientConnectionParams
+ structure. If it is provided the client library will attempt to resume
+ the session in the network. After the connection is created
+ successfully, the application is responsible of setting the user
+ interface for user into the same state it was before detaching (showing
+ same channels, channel modes, etc). It can do this by fetching the
+ information (like joined channels) from the client library. */
+
+void
+silc_detach(SilcClient client, SilcClientConnection conn,
+ const unsigned char *detach_data, SilcUInt32 detach_data_len)
+{
+ char file[256];
+
+ /* Save the detachment data to file. */
+
+ memset(file, 0, sizeof(file));
+ snprintf(file, sizeof(file) - 1, "%s/session", get_irssi_dir());
+ silc_file_writefile(file, detach_data, detach_data_len);
+}
+
+
/* SILC client operations */
SilcClientOperations ops = {
silc_say,
silc_failure,
silc_key_agreement,
silc_ftp,
+ silc_detach,
};