void silc_servers_reconnect_init(void);
void silc_servers_reconnect_deinit(void);
-static void silc_send_channel(SILC_SERVER_REC *server,
- char *channel, char *msg)
+static int silc_send_channel(SILC_SERVER_REC *server,
+ char *channel, char *msg,
+ SilcMessageFlags flags)
{
SILC_CHANNEL_REC *rec;
rec = silc_channel_find(server, channel);
if (rec == NULL || rec->entry == NULL) {
- cmd_return_error(CMDERR_NOT_JOINED);
- return;
+ cmd_return_error_value(CMDERR_NOT_JOINED, FALSE);
}
silc_client_send_channel_message(silc_client, server->conn, rec->entry,
- NULL, 0, msg, strlen(msg), TRUE);
+ NULL, flags, msg, strlen(msg), TRUE);
+ return TRUE;
}
typedef struct {
char *nick;
char *msg;
+ int len;
+ SilcMessageFlags flags;
SILC_SERVER_REC *server;
} PRIVMSG_REC;
}
/* 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 int silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
+ int msg_len, SilcMessageFlags flags)
{
PRIVMSG_REC *rec;
SilcClientEntry *clients;
if (!silc_parse_userfqdn(nick, &nickname, NULL)) {
printformat_module("fe-common/silc", server, NULL,
MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
- return;
+ return FALSE;
}
/* Find client entry */
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,
nickname, NULL, silc_send_msg_clients, rec);
silc_free(nickname);
- return;
+ return FALSE;
}
/* 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);
+ return 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)
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 (!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, msg);
+ silc_send_channel(server, target, message ? message : msg,
+ SILC_MESSAGE_FLAG_UTF8);
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);
+}
+
+void silc_send_heartbeat(SilcSocketConnection sock,
+ void *hb_context)
+{
+ SILC_SERVER_REC *server = SILC_SERVER(hb_context);
+
+ if (server == NULL)
+ return;
+
+ silc_client_send_packet(silc_client, server->conn, SILC_PACKET_HEARTBEAT,
+ NULL, 0);
}
static void sig_connected(SILC_SERVER_REC *server)
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);
+ if (params.detach_data)
+ params.detach_data[params.detach_data_len] = 0;
/* Add connection to the client library */
conn = silc_client_add_connection(silc_client, ¶ms,
/* Start key exchange with the server */
silc_client_start_key_exchange(silc_client, conn, fd);
+ /* Put default attributes */
+ silc_query_attributes_default(silc_client, conn);
+
+ /* initialize heartbeat sending */
+ if (settings_get_int("heartbeat") > 0)
+ silc_socket_set_heartbeat(conn->sock, settings_get_int("heartbeat"),
+ (void *)server,
+ (SilcSocketConnectionHBCb)silc_send_heartbeat,
+ silc_client->schedule);
+
server->ftp_sessions = silc_dlist_init();
server->isnickflag = isnickflag_func;
server->ischannel = ischannel_func;
}
}
-SILC_SERVER_REC *silc_server_connect(SILC_SERVER_CONNECT_REC *conn)
+SERVER_REC *silc_server_init_connect(SERVER_CONNECT_REC *conn)
{
SILC_SERVER_REC *server;
if (conn->address == NULL || *conn->address == '\0')
return NULL;
if (conn->nick == NULL || *conn->nick == '\0') {
- printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
- "Cannot connect: nickname is not set");
+ silc_say_error("Cannot connect: nickname is not set");
return NULL;
}
server = g_new0(SILC_SERVER_REC, 1);
server->chat_type = SILC_PROTOCOL;
- server->connrec = conn;
+ server->connrec = (SILC_SERVER_CONNECT_REC *)conn;
+ server_connect_ref(conn);
+
if (server->connrec->port <= 0)
server->connrec->port = 706;
- server_connect_ref(SERVER_CONNECT(conn));
+ server_connect_init((SERVER_REC *)server);
+ return (SERVER_REC *)server;
+}
- if (!server_start_connect((SERVER_REC *) server)) {
- server_connect_unref(SERVER_CONNECT(conn));
+void silc_server_connect(SERVER_REC *server)
+{
+ if (!server_start_connect(server)) {
+ server_connect_unref(server->connrec);
g_free(server);
- return NULL;
+ return;
}
-
- return server;
}
/* Return a string of all channels in server in server->channels_join()
/* 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|change [<arguments>] */
/* SYNTAX: KICK <channel> <nickname>[@<hostname>] [<comment>] */
-/* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] */
+/* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] [-pubkey] */
/* 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: PING */
/* SYNTAX: SCONNECT <server> [<port>] */
/* SYNTAX: USERS <channel> */
-/* SYNTAX: FILE SEND <filepath> <nickname> [<local IP> [<local port>]] */
-/* SYNTAX: FILE RECEIVE [<nickname>] */
+/* SYNTAX: FILE SEND <filepath> <nickname> [<local IP> [<local port>]] [-no-listener]*/
+/* SYNTAX: FILE ACCEPT [<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 */
+/* SYNTAX: ATTR [<-del> <option> [{ <value>}]] */
+/* SYNTAX: SMSG [<-channel>] <target> <message> */
void silc_command_exec(SILC_SERVER_REC *server,
const char *command, const char *args)
{
- SilcUInt32 argc = 0;
- unsigned char **argv;
- SilcUInt32 *argv_lens, *argv_types;
- char *data, *tmpcmd;
- SilcClientCommand cmd;
- SilcClientCommandContext ctx;
-
+ char *data;
g_return_if_fail(server != NULL);
- tmpcmd = g_strdup(command);
- g_strup(tmpcmd);
- cmd = silc_client_command_find(silc_client, tmpcmd);
- g_free(tmpcmd);
- if (cmd == NULL)
- return;
-
- /* Now parse all arguments */
+ /* Call the command */
data = g_strconcat(command, " ", args, NULL);
- silc_parse_command_line(data, &argv, &argv_lens,
- &argv_types, &argc, cmd->max_args);
+ silc_client_command_call(silc_client, server->conn, data);
g_free(data);
-
- /* Allocate command context. This and its internals must be free'd
- by the command routine receiving it. */
- ctx = silc_client_command_alloc();
- ctx->client = silc_client;
- ctx->conn = server->conn;
- ctx->command = cmd;
- ctx->argc = argc;
- ctx->argv = argv;
- ctx->argv_lens = argv_lens;
- ctx->argv_types = argv_types;
-
- /* Execute command */
- silc_client_command_call(cmd, ctx);
}
/* Generic command function to call any SILC command directly. */
if (IS_SILC_CHANNEL(item)) {
SILC_CHANNEL_REC *chanrec;
- chanrec = silc_channel_find(server, item->name);
+ chanrec = silc_channel_find(server, item->visible_name);
if (chanrec)
server->conn->current_channel = chanrec->entry;
}
signal_stop();
}
+/* SMSG command, to send digitally signed messages */
+
+static void command_smsg(const char *data, SILC_SERVER_REC *server,
+ WI_ITEM_REC *item)
+{
+ GHashTable *optlist;
+ char *target, *origtarget, *msg;
+ void *free_arg;
+ int free_ret, target_type;
+
+ g_return_if_fail(data != NULL);
+ if (server == NULL || !server->connected)
+ cmd_param_error(CMDERR_NOT_CONNECTED);
+
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS |
+ PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
+ "msg", &optlist, &target, &msg))
+ return;
+ if (*target == '\0' || *msg == '\0')
+ cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
+
+ origtarget = target;
+ free_ret = FALSE;
+
+ if (strcmp(target, "*") == 0) {
+ if (item == NULL)
+ cmd_param_error(CMDERR_NOT_JOINED);
+
+ target_type = IS_CHANNEL(item) ?
+ SEND_TARGET_CHANNEL : SEND_TARGET_NICK;
+ target = (char *) window_item_get_target(item);
+ } else if (g_hash_table_lookup(optlist, "channel") != NULL) {
+ target_type = SEND_TARGET_CHANNEL;
+ } else {
+ target_type = server_ischannel(SERVER(server), target) ?
+ SEND_TARGET_CHANNEL : SEND_TARGET_NICK;
+ }
+
+ if (target != NULL) {
+ char *message = NULL;
+ int len, result;
+
+ 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)
+ result = silc_send_channel(server, target, message ? message : msg,
+ SILC_MESSAGE_FLAG_UTF8 |
+ SILC_MESSAGE_FLAG_SIGNED);
+ else
+ result = silc_send_msg(server, target, message ? message : msg,
+ message ? strlen(message) : strlen(msg),
+ SILC_MESSAGE_FLAG_UTF8 |
+ SILC_MESSAGE_FLAG_SIGNED);
+ silc_free(message);
+ if (!result)
+ goto out;
+ }
+
+ signal_emit(target != NULL && target_type == SEND_TARGET_CHANNEL ?
+ "message signed_own_public" : "message signed_own_private", 4,
+ server, msg, target, origtarget);
+out:
+ if (free_ret && target != NULL) g_free(target);
+ cmd_params_free(free_arg);
+}
+
/* FILE command */
SILC_TASK_CALLBACK(silc_client_file_close_later)
char *local_ip = NULL;
SilcUInt32 local_port = 0;
SilcUInt32 session_id;
+ bool do_not_bind = FALSE;
CMD_SILC_SERVER(server);
if (!server || !IS_SILC_SERVER(server) || !server->connected)
/* Now parse all arguments */
tmp = g_strconcat("FILE", " ", data, NULL);
- silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 6);
+ silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 7);
g_free(tmp);
if (argc == 1)
if (argc >= 2) {
if (!strcasecmp(argv[1], "send"))
type = 1;
- if (!strcasecmp(argv[1], "receive"))
+ if (!strcasecmp(argv[1], "accept"))
type = 2;
if (!strcasecmp(argv[1], "close"))
type = 3;
client_entry = entrys[0];
silc_free(entrys);
- if (argc >= 5)
- local_ip = argv[4];
- if (argc >= 6)
- local_port = atoi(argv[5]);
+ if (argc >= 5) {
+ if (!strcasecmp(argv[4], "-no-listener"))
+ do_not_bind = TRUE;
+ else
+ local_ip = argv[4];
+ }
+ if (argc >= 6) {
+ if (!strcasecmp(argv[5], "-no-listener"))
+ do_not_bind = TRUE;
+ else
+ local_port = atoi(argv[5]);
+ }
+ if (argc >= 7) {
+ if (!strcasecmp(argv[6], "-no-listener"))
+ do_not_bind = TRUE;
+ }
ret =
silc_client_file_send(silc_client, conn, silc_client_file_monitor,
- server, local_ip, local_port,
+ server, local_ip, local_port, do_not_bind,
client_entry, argv[2], &session_id);
if (ret == SILC_CLIENT_FILE_OK) {
ftp = silc_calloc(1, sizeof(*ftp));
}
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,
signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
signal_add("server disconnected", (SIGNAL_FUNC) sig_disconnected);
+ 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("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_bind_silc("attr", MODULE_NAME, (SIGNAL_FUNC) command_attr);
+ command_bind_silc("smsg", MODULE_NAME, (SIGNAL_FUNC) command_smsg);
command_set_options("connect", "+silcnet");
}
signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
+ 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("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);
+ command_unbind("attr", (SIGNAL_FUNC) command_attr);
+ command_unbind("smsg", (SIGNAL_FUNC) command_smsg);
}
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;
+}