/*
silc-server.c : irssi
- Copyright (C) 2000 - 2006 Timo Sirainen
+ Copyright (C) 2000 - 2007 Timo Sirainen
Pekka Riikonen <priikone@silcnet.org>
This program is free software; you can redistribute it and/or modify
silc_free(unescaped_data);
}
-static int isnickflag_func(char flag)
+static int isnickflag_func(SERVER_REC *server, char flag)
{
return flag == '@' || flag == '+';
}
return FALSE;
}
-const char *get_nick_flags(void)
+const char *get_nick_flags(SERVER_REC *server)
{
return "@\0\0";
}
SILC_SERVER_REC *server = context;
char *file;
+ SILC_LOG_DEBUG(("Connection callback %p, status %d, error %d, message %s",
+ conn, status, error, message ? message : "N/A"));
+
server->op = NULL;
switch (status) {
silc_free(file);
server->connection_lost = TRUE;
+ server->conn = NULL;
if (server->conn)
server->conn->context = NULL;
if (!server->disconnected)
}
}
+/* Called after TCP stream has been created */
+
static void sig_connected_stream_created(SilcSocketStreamStatus status,
SilcStream stream, void *context)
{
SilcClientConnectionParams params;
char *file;
+ server->tcp_op = NULL;
if (!stream) {
server->connection_lost = TRUE;
server_disconnect(SERVER(server));
if (params.detach_data)
printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
SILCTXT_REATTACH, server->tag);
+ silc_free(file);
/* Start key exchange */
server->op = silc_client_key_exchange(silc_client, ¶ms,
/* Wrap the socket to TCP stream */
fd = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
- silc_socket_tcp_stream_create(fd, TRUE, FALSE, silc_client->schedule,
- sig_connected_stream_created, server);
+ server->tcp_op =
+ silc_socket_tcp_stream_create(fd, TRUE, FALSE,
+ silc_client->schedule,
+ sig_connected_stream_created, server);
}
static void sig_disconnected(SILC_SERVER_REC *server)
silc_dlist_uninit(server->ftp_sessions);
if (server->conn) {
+ /* Close connection */
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);
- server->handle = NULL;
} else if (server->op) {
+ /* Abort on going connecting (key exchange) */
silc_async_abort(server->op, NULL, NULL);
server->op = NULL;
+ } else if (server->tcp_op) {
+ /* Abort on going TCP stream creation */
+ silc_async_abort(server->tcp_op, NULL, NULL);
+ server->tcp_op = NULL;
}
+
+ /* SILC closes the handle */
+ g_io_channel_unref(net_sendbuffer_handle(server->handle));
+ net_sendbuffer_destroy(server->handle, FALSE);
+ server->handle = NULL;
}
SERVER_REC *silc_server_init_connect(SERVER_CONNECT_REC *conn)
/* SYNTAX: WHOIS [<nickname>[@<hostname>]] [-details] [-pubkey <pubkeyfile>] [<count>] */
/* SYNTAX: WHOWAS <nickname>[@<hostname>] [<count>] */
/* SYNTAX: CLOSE <server> [<port>] */
-/* SYNTAX: SHUTDOWN */
/* SYNTAX: MOTD [<server>] */
/* SYNTAX: LIST [<channel>] */
/* SYNTAX: ME <message> */
/* SYNTAX: NOTICE [-sign] [-channel] <target> <message> */
/* SYNTAX: PART [<channel>] */
/* SYNTAX: PING */
-/* SYNTAX: SCONNECT <server> [<port>] */
/* SYNTAX: USERS <channel> */
/* SYNTAX: FILE SEND <filepath> <nickname> [<local IP> [<local port>]] [-no-listener]*/
/* SYNTAX: FILE ACCEPT [<nickname>] */
signal_stop();
}
-/* SCONNECT command. Calls actually SILC's CONNECT command since Irssi
- has CONNECT command for other purposes. */
-
-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;
- }
-
- silc_command_exec(server, "CONNECT", data);
- signal_stop();
-}
-
/* SMSG command, to send digitally signed messages */
static void command_smsg(const char *data, SILC_SERVER_REC *server,
cmd_params_free(free_arg);
}
-#if 0
/* FILE command */
SILC_TASK_CALLBACK(silc_client_file_close_later)
if (ftp == SILC_LIST_END)
return;
- if (status == SILC_CLIENT_FILE_MONITOR_ERROR) {
+ if (status == SILC_CLIENT_FILE_MONITOR_ERROR ||
+ status == SILC_CLIENT_FILE_MONITOR_DISCONNECT) {
if (error == SILC_CLIENT_FILE_NO_SUCH_FILE)
printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
SILCTXT_FILE_ERROR_NO_SUCH_FILE,
else
printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
SILCTXT_FILE_ERROR, client_entry->nickname);
- silc_schedule_task_add(silc_client->schedule, 0,
- silc_client_file_close_later, ftp,
- 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
+ silc_schedule_task_add_timeout(silc_client->schedule,
+ silc_client_file_close_later, ftp,
+ 1, 0);
silc_dlist_del(server->ftp_sessions, ftp);
if (ftp == server->current_session) {
server->current_session = NULL;
printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
SILCTXT_FILE_TRANSMITTED, filepath, fsize,
client_entry->nickname, ftp->kps);
- silc_schedule_task_add(silc_client->schedule, 0,
- silc_client_file_close_later, ftp,
- 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
+ silc_schedule_task_add_timeout(silc_client->schedule,
+ silc_client_file_close_later, ftp,
+ 1, 0);
silc_dlist_del(server->ftp_sessions, ftp);
if (ftp == server->current_session) {
server->current_session = NULL;
printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
SILCTXT_FILE_RECEIVED, filepath, fsize,
client_entry->nickname, ftp->kps);
- silc_schedule_task_add(silc_client->schedule, 0,
- silc_client_file_close_later, ftp,
- 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
+ silc_schedule_task_add_timeout(silc_client->schedule,
+ silc_client_file_close_later, ftp,
+ 1, 0);
silc_dlist_del(server->ftp_sessions, ftp);
if (ftp == server->current_session) {
server->current_session = NULL;
static void silc_client_command_file_get_clients(SilcClient client,
SilcClientConnection conn,
- SilcClientEntry *clients,
- SilcUInt32 clients_count,
+ SilcStatus status,
+ SilcDList clients,
void *context)
{
FileGetClients internal = (FileGetClients)context;
WI_ITEM_REC *item)
{
SilcClientConnection conn;
- SilcClientEntry *entrys, client_entry;
+ SilcClientEntry client_entry;
+ SilcDList entries;
SilcClientFileError ret;
- SilcUInt32 entry_count;
- char *nickname = NULL, *tmp;
+ char nickname[128 + 1], *tmp;
unsigned char **argv;
SilcUInt32 argc;
SilcUInt32 *argv_lens, *argv_types;
SilcUInt32 local_port = 0;
SilcUInt32 session_id;
bool do_not_bind = FALSE;
+ SilcClientConnectionParams params;
CMD_SILC_SERVER(server);
if (!server || !IS_SILC_SERVER(server) || !server->connected)
cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
/* Parse the typed nickname. */
- if (!silc_parse_userfqdn(argv[3], &nickname, NULL)) {
+ if (!silc_parse_userfqdn(argv[3], nickname, sizeof(nickname), NULL, 0)) {
printformat_module("fe-common/silc", server, NULL,
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);
- if (!entrys) {
+ entries = silc_client_get_clients_local(silc_client, conn, nickname,
+ argv[3]);
+ if (!entries) {
FileGetClients inter = silc_calloc(1, sizeof(*inter));
inter->server = server;
inter->data = strdup(data);
silc_client_command_file_get_clients, inter);
goto out;
}
- client_entry = entrys[0];
- silc_free(entrys);
+ silc_dlist_start(entries);
+ client_entry = silc_dlist_get(entries);
if (argc >= 5) {
if (!strcasecmp(argv[4], "-no-listener"))
do_not_bind = TRUE;
}
- 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);
+ memset(¶ms, 0, sizeof(params));
+ if (!do_not_bind) {
+ if (local_ip)
+ params.local_ip = strdup(local_ip);
+ params.local_port = local_port;
+ if (!params.local_ip && settings_get_bool("use_auto_addr")) {
+ params.local_ip = (char *)settings_get_str("auto_public_ip");
+ if ((params.local_ip) && (*params.local_ip == '\0')) {
+ params.local_ip = silc_net_localip();
+ } else {
+ params.bind_ip = (char *)settings_get_str("auto_bind_ip");
+ if ((params.bind_ip) && (*params.bind_ip == '\0'))
+ params.bind_ip = NULL;
+ params.local_port = settings_get_int("auto_bind_port");
+ }
+ }
+ if (!params.local_ip)
+ params.local_ip = silc_net_localip();
+ }
+ params.timeout_secs = settings_get_int("key_exchange_timeout_secs");
+
+ ret = silc_client_file_send(silc_client, conn, client_entry, ¶ms,
+ irssi_pubkey, irssi_privkey,
+ silc_client_file_monitor, server, argv[2],
+ &session_id);
if (ret == SILC_CLIENT_FILE_OK) {
ftp = silc_calloc(1, sizeof(*ftp));
ftp->session_id = session_id;
client_entry->nickname, argv[2]);
}
+ silc_client_list_free(silc_client, server->conn, entries);
break;
case 2:
/* Parse the typed nickname. */
if (argc >= 3) {
- if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
+ if (!silc_parse_userfqdn(argv[2], nickname, sizeof(nickname), NULL, 0)) {
printformat_module("fe-common/silc", server, NULL,
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);
- if (!entrys) {
+ entries = silc_client_get_clients_local(silc_client, conn, nickname,
+ argv[2]);
+ if (!entries) {
FileGetClients inter = silc_calloc(1, sizeof(*inter));
inter->server = server;
inter->data = strdup(data);
silc_client_command_file_get_clients, inter);
goto out;
}
- client_entry = entrys[0];
- silc_free(entrys);
+ silc_dlist_start(entries);
+ client_entry = silc_dlist_get(entries);
+ silc_client_list_free(silc_client, server->conn, entries);
} else {
if (!server->current_session) {
printformat_module("fe-common/silc", server, NULL,
goto out;
}
- ret = silc_client_file_receive(silc_client, conn,
+ memset(¶ms, 0, sizeof(params));
+ if (settings_get_bool("use_auto_addr")) {
+ params.local_ip = (char *)settings_get_str("auto_public_ip");
+ if ((params.local_ip) && (*params.local_ip == '\0')) {
+ params.local_ip = silc_net_localip();
+ } else {
+ params.bind_ip = (char *)settings_get_str("auto_bind_ip");
+ if ((params.bind_ip) && (*params.bind_ip == '\0'))
+ params.bind_ip = NULL;
+ params.local_port = settings_get_int("auto_bind_port");
+ }
+ }
+ if (!params.local_ip)
+ params.local_ip = silc_net_localip();
+ params.timeout_secs = settings_get_int("key_exchange_timeout_secs");
+
+ ret = silc_client_file_receive(silc_client, conn, ¶ms,
+ irssi_pubkey, irssi_privkey,
silc_client_file_monitor, server, NULL,
server->current_session->session_id,
NULL, NULL);
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,
+ memset(¶ms, 0, sizeof(params));
+ if (settings_get_bool("use_auto_addr")) {
+ params.local_ip = (char *)settings_get_str("auto_public_ip");
+ if ((params.local_ip) && (*params.local_ip == '\0')) {
+ params.local_ip = silc_net_localip();
+ } else {
+ params.bind_ip = (char *)settings_get_str("auto_bind_ip");
+ if ((params.bind_ip) && (*params.bind_ip == '\0'))
+ params.bind_ip = NULL;
+ params.local_port = settings_get_int("auto_bind_port");
+ }
+ }
+ if (!params.local_ip)
+ params.local_ip = silc_net_localip();
+ params.timeout_secs = settings_get_int("key_exchange_timeout_secs");
+
+ ret = silc_client_file_receive(silc_client, conn, ¶ms,
+ irssi_pubkey, irssi_privkey,
silc_client_file_monitor, server,
NULL, ftp->session_id, NULL, NULL);
if (ret != SILC_CLIENT_FILE_OK) {
case 3:
/* Parse the typed nickname. */
if (argc >= 3) {
- if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
+ if (!silc_parse_userfqdn(argv[2], nickname, sizeof(nickname), NULL, 0)) {
printformat_module("fe-common/silc", server, NULL,
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);
- if (!entrys) {
+ entries = silc_client_get_clients_local(silc_client, conn, nickname,
+ argv[2]);
+ if (!entries) {
FileGetClients inter = silc_calloc(1, sizeof(*inter));
inter->server = server;
inter->data = strdup(data);
silc_client_command_file_get_clients, inter);
goto out;
}
- client_entry = entrys[0];
- silc_free(entrys);
+ silc_dlist_start(entries);
+ client_entry = silc_dlist_get(entries);
+ silc_client_list_free(silc_client, server->conn, entries);
} else {
if (!server->current_session) {
printformat_module("fe-common/silc", server, NULL,
}
out:
- silc_free(nickname);
+ return;
}
-#endif /* 0 */
void silc_server_init(void)
{
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("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_unbind("motd", (SIGNAL_FUNC) command_self);
command_unbind("ban", (SIGNAL_FUNC) command_self);
command_unbind("close", (SIGNAL_FUNC) command_self);
- command_unbind("shutdown", (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("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("smsg", (SIGNAL_FUNC) command_smsg);
}
-#if 0
void silc_server_free_ftp(SILC_SERVER_REC *server,
SilcClientEntry client_entry)
{
}
}
}
-#endif /* 0 */
bool silc_term_utf8(void)
{
const char *str;
- str = settings_get_str("term_type");
+ str = settings_get_str("term_charset");
if (str)
if (g_strcasecmp(str, "utf-8") == 0)
return TRUE;