/*
silc-server.c : irssi
- Copyright (C) 2000 - 2001 Timo Sirainen
- Pekka Riikonen <priikone@poseidon.pspt.fi>
+ Copyright (C) 2000 - 2003 Timo Sirainen
+ Pekka Riikonen <priikone@silcnet.org>
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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, SILC_MESSAGE_FLAG_UTF8,
- msg, strlen(msg), TRUE);
+ silc_client_send_channel_message(silc_client, server->conn, rec->entry,
+ NULL, flags, msg, strlen(msg), TRUE);
+ return TRUE;
}
typedef struct {
char *nickname = NULL;
if (!clients_count) {
- printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
+ printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
"%s: There is no such client", rec->nick);
} else {
if (clients_count > 1) {
/* Find the correct one. The rec->nick might be a formatted nick
so this will find the correct one. */
- clients = silc_client_get_clients_local(silc_client, server->conn,
- nickname, rec->nick,
+ clients = silc_client_get_clients_local(silc_client, server->conn,
+ nickname, rec->nick,
&clients_count);
if (!clients) {
- printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
+ printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
"%s: There is no such client", rec->nick);
silc_free(nickname);
goto out;
/* Still check for exact math for nickname, this compares the
real (formatted) nickname and the nick (maybe formatted) that
- use gave. This is to assure that `nick' does not match
+ use gave. This is to assure that `nick' does not match
`nick@host'. */
if (strcasecmp(rec->nick, clients[0]->nickname)) {
- printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
+ printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
"%s: There is no such client", rec->nick);
goto out;
}
/* Send the private message */
- silc_client_send_private_message(client, conn, target,
+ silc_client_send_private_message(client, conn, target,
rec->flags,
rec->msg, rec->len,
TRUE);
}
-
+
out:
g_free(rec->nick);
g_free(rec->msg);
g_free(rec);
}
-static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
- int msg_len, SilcMessageFlags flags)
+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 */
- clients = silc_client_get_clients_local(silc_client, server->conn,
+ clients = silc_client_get_clients_local(silc_client, server->conn,
nickname, nick, &clients_count);
if (!clients) {
rec = g_new0(PRIVMSG_REC, 1);
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,
+ silc_client_send_private_message(silc_client, server->conn,
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 *data,
const char *enc, const char *type)
{
SILC_CHANNEL_REC *channel;
QUERY_REC *query;
+ char *unescaped_data;
+ SilcUInt32 unescaped_data_len;
char *mime_data;
int mime_data_len;
-
- if (!(IS_SILC_SERVER(server)) || (data == NULL) || (to == NULL) ||
+
+ if (!(IS_SILC_SERVER(server)) || (data == NULL) || (to == NULL) ||
(enc == NULL) || (type == NULL))
return;
-
+
+ unescaped_data = silc_unescape_data(data, &unescaped_data_len);
+
#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
+ mime_data_len = unescaped_data_len + strlen(SILC_MIME_HEADER) - 4
+ strlen(enc) + strlen(type);
if (mime_data_len >= SILC_PACKET_MAX_LEN)
return;
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);
+ unescaped_data, unescaped_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,
+ 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);
+ silc_free(unescaped_data);
}
static int isnickflag_func(char flag)
}
if (target_type == SEND_TARGET_CHANNEL)
- silc_send_channel(server, target, message ? message : msg);
+ silc_send_channel(server, target, message ? message : msg,
+ SILC_MESSAGE_FLAG_UTF8);
else
silc_send_msg(server, target, message ? message : msg,
message ? strlen(message) : strlen(msg),
silc_free(message);
}
-void silc_send_heartbeat(SilcSocketConnection sock,
+void silc_send_heartbeat(SilcSocketConnection sock,
void *hb_context)
{
SILC_SERVER_REC *server = SILC_SERVER(hb_context);
SILC_SERVER_REC *server;
g_return_val_if_fail(IS_SILC_SERVER_CONNECT(conn), NULL);
- if (conn->address == NULL || *conn->address == '\0')
+ if (conn->address == NULL || *conn->address == '\0')
return NULL;
if (conn->nick == NULL || *conn->nick == '\0') {
silc_say_error("Cannot connect: nickname is not set");
server->connrec = (SILC_SERVER_CONNECT_REC *)conn;
server_connect_ref(conn);
- if (server->connrec->port <= 0)
+ if (server->connrec->port <= 0)
server->connrec->port = 706;
server_connect_init((SERVER_REC *)server);
}
}
-/* Return a string of all channels in server in server->channels_join()
+/* Return a string of all channels in server in server->channels_join()
format */
char *silc_server_get_channels(SILC_SERVER_REC *server)
chans = g_string_new(NULL);
for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
CHANNEL_REC *channel = tmp->data;
-
+
g_string_sprintfa(chans, "%s,", channel->name);
}
ret = chans->str;
g_string_free(chans, FALSE);
-
+
return ret;
}
/* 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: 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] */
+/* SYNTAX: JOIN <channel> [<passphrase>] [-cipher <cipher>] [-hmac <hmac>] [-founder] [-auth [<pubkeyfile> <privkeyfile> [<privkey passphrase>]]]*/
/* 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)
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)
if (status == SILC_CLIENT_FILE_MONITOR_ERROR) {
if (error == SILC_CLIENT_FILE_NO_SUCH_FILE)
printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
- SILCTXT_FILE_ERROR_NO_SUCH_FILE,
- client_entry->nickname,
+ SILCTXT_FILE_ERROR_NO_SUCH_FILE,
+ client_entry->nickname,
filepath ? filepath : "[N/A]");
else if (error == SILC_CLIENT_FILE_PERMISSION_DENIED)
printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
- SILCTXT_FILE_ERROR_PERMISSION_DENIED,
+ SILCTXT_FILE_ERROR_PERMISSION_DENIED,
client_entry->nickname);
else
printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
FileGetClients internal = (FileGetClients)context;
if (!clients) {
- printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
+ printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
internal->nick);
silc_free(internal->data);
silc_free(internal->nick);
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;
}
-
+
if (type == 0)
cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[3]);
goto out;
}
-
+
/* Find client entry */
entrys = silc_client_get_clients_local(silc_client, conn, nickname,
argv[3], &entry_count);
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,
+ ret =
+ silc_client_file_send(silc_client, conn, silc_client_file_monitor,
+ 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));
client_entry->nickname);
if (ret == SILC_CLIENT_FILE_NO_SUCH_FILE)
printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
- SILCTXT_FILE_ERROR_NO_SUCH_FILE,
+ SILCTXT_FILE_ERROR_NO_SUCH_FILE,
client_entry->nickname, argv[2]);
}
MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
goto out;
}
-
+
/* Find client entry */
entrys = silc_client_get_clients_local(silc_client, conn, nickname,
argv[2], &entry_count);
goto out;
}
- ret = silc_client_file_receive(silc_client, conn,
+ ret = silc_client_file_receive(silc_client, conn,
silc_client_file_monitor, server, NULL,
server->current_session->session_id);
if (ret != SILC_CLIENT_FILE_OK) {
silc_dlist_start(server->ftp_sessions);
while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
if (ftp->client_entry == client_entry && !ftp->filepath) {
- ret = silc_client_file_receive(silc_client, conn,
+ ret = silc_client_file_receive(silc_client, conn,
silc_client_file_monitor, server,
NULL, ftp->session_id);
if (ret != SILC_CLIENT_FILE_OK) {
MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
goto out;
}
-
+
/* Find client entry */
entrys = silc_client_get_clients_local(silc_client, conn, nickname,
argv[2], &entry_count);
MSGLEVEL_CRAP, SILCTXT_FILE_NA);
goto out;
}
-
- silc_client_file_close(silc_client, conn,
+
+ silc_client_file_close(silc_client, conn,
server->current_session->session_id);
printformat_module("fe-common/silc", server, NULL,
MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
printformat_module("fe-common/silc", server, NULL,
MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_LINE,
- ftp->client_entry->nickname,
+ ftp->client_entry->nickname,
ftp->send ? "send" : "receive",
(SilcUInt32)(ftp->offset + 1023) / 1024,
(SilcUInt32)(ftp->filesize + 1023) / 1024,
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");
}
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,