#include "window-item-def.h"
#include "fe-common/core/printtext.h"
+#include "fe-common/core/fe-channels.h"
+#include "fe-common/core/keyboard.h"
#include "fe-common/silc/module-formats.h"
+#include "silc-commands.h"
+
void silc_servers_reconnect_init(void);
void silc_servers_reconnect_deinit(void);
SILC_CHANNEL_REC *rec;
rec = silc_channel_find(server, channel);
- if (rec == NULL || rec->entry == NULL)
+ if (rec == NULL || rec->entry == NULL) {
+ cmd_return_error(CMDERR_NOT_JOINED);
return;
-
+ }
+
silc_client_send_channel_message(silc_client, server->conn, rec->entry,
- NULL, 0, msg, strlen(msg), TRUE);
+ NULL, SILC_MESSAGE_FLAG_UTF8,
+ msg, strlen(msg), TRUE);
}
typedef struct {
char *nick;
char *msg;
+ int len;
+ SilcMessageFlags flags;
SILC_SERVER_REC *server;
} PRIVMSG_REC;
static void silc_send_msg_clients(SilcClient client,
SilcClientConnection conn,
SilcClientEntry *clients,
- uint32 clients_count,
+ SilcUInt32 clients_count,
void *context)
{
PRIVMSG_REC *rec = context;
}
/* Send the private message */
- silc_client_send_private_message(client, conn, target, 0,
- rec->msg, strlen(rec->msg),
+ silc_client_send_private_message(client, conn, target,
+ rec->flags,
+ rec->msg, rec->len,
TRUE);
}
g_free(rec);
}
-static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg)
+static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
+ int msg_len, SilcMessageFlags flags)
{
PRIVMSG_REC *rec;
SilcClientEntry *clients;
- uint32 clients_count;
+ SilcUInt32 clients_count;
char *nickname = NULL;
if (!silc_parse_userfqdn(nick, &nickname, NULL)) {
rec->nick = g_strdup(nick);
rec->msg = g_strdup(msg);
rec->server = server;
+ rec->flags = flags;
+ rec->len = msg_len;
/* Could not find client with that nick, resolve it from server. */
silc_client_get_clients(silc_client, server->conn,
/* Send the private message directly */
silc_free(nickname);
silc_client_send_private_message(silc_client, server->conn,
- clients[0], 0, msg, strlen(msg), TRUE);
+ clients[0], flags,
+ msg, msg_len, TRUE);
+}
+
+void silc_send_mime(SILC_SERVER_REC *server, WI_ITEM_REC *to,
+ const char *data, int data_len,
+ const char *enc, const char *type)
+{
+ SILC_CHANNEL_REC *channel;
+ QUERY_REC *query;
+ char *mime_data;
+ int mime_data_len;
+
+ if (!(IS_SILC_SERVER(server)) || (data == NULL) || (to == NULL) ||
+ (enc == NULL) || (type == NULL))
+ return;
+
+#define SILC_MIME_HEADER "MIME-Version: 1.0\r\nContent-Type: %s\r\nContent-Transfer-Encoding: %s\r\n\r\n"
+
+ mime_data_len = data_len + strlen(SILC_MIME_HEADER) - 4
+ + strlen(enc) + strlen(type);
+ if (mime_data_len >= SILC_PACKET_MAX_LEN)
+ return;
+
+ /* we risk to large packets here... */
+ mime_data = silc_calloc(mime_data_len, sizeof(*mime_data));
+ snprintf(mime_data, mime_data_len, SILC_MIME_HEADER, type, enc);
+ memmove(mime_data + strlen(SILC_MIME_HEADER) - 4 + strlen(enc) + strlen(type),
+ data, data_len);
+
+#undef SILC_MIME_HEADER
+
+ if (IS_SILC_CHANNEL(to)) {
+ channel = SILC_CHANNEL(to);
+ silc_client_send_channel_message(silc_client, server->conn, channel->entry,
+ NULL, SILC_MESSAGE_FLAG_DATA,
+ mime_data, mime_data_len, TRUE);
+ } else if (IS_SILC_QUERY(to)) {
+ query = SILC_QUERY(to);
+ silc_send_msg(server, query->name, mime_data, mime_data_len,
+ SILC_MESSAGE_FLAG_DATA);
+
+ }
+
+ silc_free(mime_data);
}
static int isnickflag_func(char flag)
return flag == '@' || flag == '+';
}
-static int ischannel_func(const char *data)
+static int ischannel_func(SERVER_REC *server, const char *data)
{
- return *data == '#';
+ return FALSE;
}
const char *get_nick_flags(void)
return "@\0\0";
}
-static void send_message(SILC_SERVER_REC *server, char *target, char *msg)
+static void send_message(SILC_SERVER_REC *server, char *target,
+ char *msg, int target_type)
{
+ char *message = NULL;
+ int len;
+
g_return_if_fail(server != NULL);
g_return_if_fail(target != NULL);
g_return_if_fail(msg != NULL);
- if (*target == '#')
- silc_send_channel(server, target, msg);
+ if (!silc_term_utf8()) {
+ len = silc_utf8_encoded_len(msg, strlen(msg), SILC_STRING_LANGUAGE);
+ message = silc_calloc(len + 1, sizeof(*message));
+ g_return_if_fail(message != NULL);
+ silc_utf8_encode(msg, strlen(msg), SILC_STRING_LANGUAGE, message, len);
+ }
+
+ if (target_type == SEND_TARGET_CHANNEL)
+ silc_send_channel(server, target, message ? message : msg);
else
- silc_send_msg(server, target, msg);
+ silc_send_msg(server, target, message ? message : msg,
+ message ? strlen(message) : strlen(msg),
+ SILC_MESSAGE_FLAG_UTF8);
+
+ silc_free(message);
}
static void sig_connected(SILC_SERVER_REC *server)
{
SilcClientConnection conn;
+ SilcClientConnectionParams params;
+ char file[256];
int fd;
if (!IS_SILC_SERVER(server))
return;
- conn = silc_client_add_connection(silc_client,
+ /* Try to read detached session data and use it if found. */
+ memset(¶ms, 0, sizeof(params));
+ memset(file, 0, sizeof(file));
+ snprintf(file, sizeof(file) - 1, "%s/session", get_irssi_dir());
+ params.detach_data = silc_file_readfile(file, ¶ms.detach_data_len);
+
+ /* Add connection to the client library */
+ conn = silc_client_add_connection(silc_client, ¶ms,
server->connrec->address,
server->connrec->port,
server);
server->conn = conn;
-
+
+ if (params.detach_data)
+ keyboard_entry_redirect(NULL,
+ "-- Resuming old session, may take a while ...",
+ ENTRY_REDIRECT_FLAG_HIDDEN, server);
+
+ silc_free(params.detach_data);
+ unlink(file);
+
fd = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
+
+ /* Start key exchange with the server */
silc_client_start_key_exchange(silc_client, conn, fd);
server->ftp_sessions = silc_dlist_init();
silc_dlist_uninit(server->ftp_sessions);
if (server->conn && server->conn->sock != NULL) {
- silc_client_close_connection(silc_client, NULL, server->conn);
-
+ silc_client_close_connection(silc_client, server->conn);
+
/* SILC closes the handle */
g_io_channel_unref(net_sendbuffer_handle(server->handle));
net_sendbuffer_destroy(server->handle, FALSE);
}
}
-SILC_SERVER_REC *silc_server_connect(SILC_SERVER_CONNECT_REC *conn)
-{
+SILC_SERVER_REC *silc_server_connect(SILC_SERVER_CONNECT_REC *conn){
SILC_SERVER_REC *server;
g_return_val_if_fail(IS_SILC_SERVER_CONNECT(conn), NULL);
if (server->connrec->port <= 0)
server->connrec->port = 706;
+ server_connect_ref(SERVER_CONNECT(conn));
+
if (!server_start_connect((SERVER_REC *) server)) {
- server_connect_free(SERVER_CONNECT(conn));
+ server_connect_unref(SERVER_CONNECT(conn));
g_free(server);
return NULL;
}
/* SYNTAX: BAN <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
/* SYNTAX: CMODE <channel> +|-<modes> [{ <arguments>}] */
-/* SYNTAX: CUMODE <channel> +|-<modes> <nickname>[@<hostname>] [-pubkey|<passwd>] */
+/* SYNTAX: CUMODE <channel> +|-<modes> <nickname>[@<hostname>] */
/* SYNTAX: GETKEY <nickname or server name> */
/* SYNTAX: INVITE <channel> [<nickname>[@hostname>] */
/* SYNTAX: INVITE <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
/* SYNTAX: KEY MSG <nickname> set|unset|list|agreement|negotiate [<arguments>] */
-/* SYNTAX: KEY CHANNEL <channel> set|unset|list [<arguments>] */
+/* SYNTAX: KEY CHANNEL <channel> set|unset|list|change [<arguments>] */
/* SYNTAX: KICK <channel> <nickname>[@<hostname>] [<comment>] */
/* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] */
/* SYNTAX: OPER <username> [-pubkey] */
/* SYNTAX: SILCOPER <username> [-pubkey] */
/* SYNTAX: TOPIC <channel> [<topic>] */
/* SYNTAX: UMODE +|-<modes> */
-/* SYNTAX: WHOIS <nickname>[@<hostname>] [<count>] */
+/* SYNTAX: WHOIS <nickname>[@<hostname>] [-details] [<count>] */
/* SYNTAX: WHOWAS <nickname>[@<hostname>] [<count>] */
/* SYNTAX: CLOSE <server> [<port>] */
/* SYNTAX: SHUTDOWN */
/* SYNTAX: FILE RECEIVE [<nickname>] */
/* SYNTAX: FILE CLOSE [<nickname>] */
/* SYNTAX: FILE */
-/* SYNTAX: JOIN <channel> [<passphrase>] [-cipher <cipher>] [-hmac <hmac>] [-founder <-pubkey|passwd>] */
+/* SYNTAX: JOIN <channel> [<passphrase>] [-cipher <cipher>] [-hmac <hmac>] [-founder] */
+/* SYNTAX: DETACH */
+/* SYNTAX: WATCH [<-add | -del> <nickname>] */
+/* SYNTAX: STATS */
void silc_command_exec(SILC_SERVER_REC *server,
const char *command, const char *args)
{
- uint32 argc = 0;
+ SilcUInt32 argc = 0;
unsigned char **argv;
- uint32 *argv_lens, *argv_types;
+ SilcUInt32 *argv_lens, *argv_types;
char *data, *tmpcmd;
SilcClientCommand cmd;
SilcClientCommandContext ctx;
static void command_self(const char *data, SILC_SERVER_REC *server,
WI_ITEM_REC *item)
{
+ CMD_SILC_SERVER(server);
+
if (!IS_SILC_SERVER(server) || !server->connected) {
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
return;
static void command_sconnect(const char *data, SILC_SERVER_REC *server)
{
+ CMD_SILC_SERVER(server);
if (!IS_SILC_SERVER(server) || !server->connected) {
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
return;
signal_stop();
}
-static void event_text(const char *line, SILC_SERVER_REC *server,
- WI_ITEM_REC *item)
-{
- char *str;
-
- g_return_if_fail(line != NULL);
-
- if (!IS_SILC_ITEM(item))
- return;
-
- str = g_strdup_printf("%s %s", item->name, line);
- signal_emit("command msg", 3, str, server, item);
- g_free(str);
-
- signal_stop();
-}
-
/* FILE command */
SILC_TASK_CALLBACK(silc_client_file_close_later)
SilcClientConnection conn,
SilcClientMonitorStatus status,
SilcClientFileError error,
- uint64 offset,
- uint64 filesize,
+ SilcUInt64 offset,
+ SilcUInt64 filesize,
SilcClientEntry client_entry,
- uint32 session_id,
+ SilcUInt32 session_id,
const char *filepath,
void *context)
{
static void silc_client_command_file_get_clients(SilcClient client,
SilcClientConnection conn,
SilcClientEntry *clients,
- uint32 clients_count,
+ SilcUInt32 clients_count,
void *context)
{
FileGetClients internal = (FileGetClients)context;
SilcClientConnection conn;
SilcClientEntry *entrys, client_entry;
SilcClientFileError ret;
- uint32 entry_count;
+ SilcUInt32 entry_count;
char *nickname = NULL, *tmp;
unsigned char **argv;
- uint32 argc;
- uint32 *argv_lens, *argv_types;
+ SilcUInt32 argc;
+ SilcUInt32 *argv_lens, *argv_types;
int type = 0;
FtpSession ftp;
char *local_ip = NULL;
- uint32 local_port = 0;
- uint32 session_id;
+ SilcUInt32 local_port = 0;
+ SilcUInt32 session_id;
+ CMD_SILC_SERVER(server);
if (!server || !IS_SILC_SERVER(server) || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
}
ret = silc_client_file_receive(silc_client, conn,
- silc_client_file_monitor, server,
+ silc_client_file_monitor, server, NULL,
server->current_session->session_id);
if (ret != SILC_CLIENT_FILE_OK) {
if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
if (ftp->client_entry == client_entry && !ftp->filepath) {
ret = silc_client_file_receive(silc_client, conn,
silc_client_file_monitor, server,
- ftp->session_id);
+ NULL, ftp->session_id);
if (ret != SILC_CLIENT_FILE_OK) {
if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
printformat_module("fe-common/silc", server, NULL,
MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_LINE,
ftp->client_entry->nickname,
ftp->send ? "send" : "receive",
- (uint32)(ftp->offset + 1023) / 1024,
- (uint32)(ftp->filesize + 1023) / 1024,
+ (SilcUInt32)(ftp->offset + 1023) / 1024,
+ (SilcUInt32)(ftp->filesize + 1023) / 1024,
ftp->percent, ftp->kps,
ftp->filepath ? ftp->filepath : "[N/A]");
}
signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
signal_add("server disconnected", (SIGNAL_FUNC) sig_disconnected);
- signal_add("send text", (SIGNAL_FUNC) event_text);
- command_bind("whois", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("whowas", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("nick", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("topic", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("cmode", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("cumode", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("users", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("list", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("ban", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("oper", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("silcoper", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("umode", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("invite", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("kill", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("kick", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("info", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("ping", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("motd", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("close", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
- command_bind("file", MODULE_NAME, (SIGNAL_FUNC) command_file);
+ signal_add("mime-send", (SIGNAL_FUNC)silc_send_mime);
+ command_bind_silc("whois", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("whowas", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("nick", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("topic", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("cmode", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("cumode", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("users", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("list", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("ban", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("oper", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("silcoper", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("umode", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("invite", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("kill", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("kick", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("info", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("ping", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("motd", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("close", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
+ command_bind_silc("file", MODULE_NAME, (SIGNAL_FUNC) command_file);
+ command_bind_silc("detach", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("watch", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind_silc("stats", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_set_options("connect", "+silcnet");
}
signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
- signal_remove("send text", (SIGNAL_FUNC) event_text);
+ signal_remove("mime-send", (SIGNAL_FUNC)silc_send_mime);
command_unbind("whois", (SIGNAL_FUNC) command_self);
command_unbind("whowas", (SIGNAL_FUNC) command_self);
command_unbind("nick", (SIGNAL_FUNC) command_self);
command_unbind("getkey", (SIGNAL_FUNC) command_self);
command_unbind("sconnect", (SIGNAL_FUNC) command_sconnect);
command_unbind("file", (SIGNAL_FUNC) command_file);
+ command_unbind("detach", (SIGNAL_FUNC) command_self);
+ command_unbind("watch", (SIGNAL_FUNC) command_self);
+ command_unbind("stats", (SIGNAL_FUNC) command_self);
}
void silc_server_free_ftp(SILC_SERVER_REC *server,
}
}
}
+
+bool silc_term_utf8(void)
+{
+ const char *str;
+ str = settings_get_str("term_type");
+ if (str)
+ if (g_strcasecmp(str, "utf-8") == 0)
+ return TRUE;
+ return FALSE;
+}