4 Copyright (C) 2000 - 2001 Timo Sirainen
5 Pekka Riikonen <priikone@poseidon.pspt.fi>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "net-nonblock.h"
25 #include "net-sendbuffer.h"
35 #include "servers-setup.h"
37 #include "silc-servers.h"
38 #include "silc-channels.h"
39 #include "silc-queries.h"
40 #include "silc-nicklist.h"
41 #include "window-item-def.h"
43 #include "fe-common/core/printtext.h"
44 #include "fe-common/silc/module-formats.h"
46 #include "silc-commands.h"
48 void silc_servers_reconnect_init(void);
49 void silc_servers_reconnect_deinit(void);
51 static void silc_send_channel(SILC_SERVER_REC *server,
52 char *channel, char *msg)
54 SILC_CHANNEL_REC *rec;
56 rec = silc_channel_find(server, channel);
57 if (rec == NULL || rec->entry == NULL) {
58 cmd_return_error(CMDERR_NOT_JOINED);
62 silc_client_send_channel_message(silc_client, server->conn, rec->entry,
63 NULL, 0, msg, strlen(msg), TRUE);
69 SILC_SERVER_REC *server;
72 /* Callback function that sends the private message if the client was
73 resolved from the server. */
75 static void silc_send_msg_clients(SilcClient client,
76 SilcClientConnection conn,
77 SilcClientEntry *clients,
78 SilcUInt32 clients_count,
81 PRIVMSG_REC *rec = context;
82 SILC_SERVER_REC *server = rec->server;
83 SilcClientEntry target;
84 char *nickname = NULL;
87 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
88 "%s: There is no such client", rec->nick);
90 if (clients_count > 1) {
91 silc_parse_userfqdn(rec->nick, &nickname, NULL);
93 /* Find the correct one. The rec->nick might be a formatted nick
94 so this will find the correct one. */
95 clients = silc_client_get_clients_local(silc_client, server->conn,
99 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
100 "%s: There is no such client", rec->nick);
109 /* Still check for exact math for nickname, this compares the
110 real (formatted) nickname and the nick (maybe formatted) that
111 use gave. This is to assure that `nick' does not match
113 if (strcasecmp(rec->nick, clients[0]->nickname)) {
114 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
115 "%s: There is no such client", rec->nick);
119 /* Send the private message */
120 silc_client_send_private_message(client, conn, target, 0,
121 rec->msg, strlen(rec->msg),
131 static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg)
134 SilcClientEntry *clients;
135 SilcUInt32 clients_count;
136 char *nickname = NULL;
138 if (!silc_parse_userfqdn(nick, &nickname, NULL)) {
139 printformat_module("fe-common/silc", server, NULL,
140 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
144 /* Find client entry */
145 clients = silc_client_get_clients_local(silc_client, server->conn,
146 nickname, nick, &clients_count);
148 rec = g_new0(PRIVMSG_REC, 1);
149 rec->nick = g_strdup(nick);
150 rec->msg = g_strdup(msg);
151 rec->server = server;
153 /* Could not find client with that nick, resolve it from server. */
154 silc_client_get_clients(silc_client, server->conn,
155 nickname, NULL, silc_send_msg_clients, rec);
160 /* Send the private message directly */
162 silc_client_send_private_message(silc_client, server->conn,
163 clients[0], 0, msg, strlen(msg), TRUE);
166 static int isnickflag_func(char flag)
168 return flag == '@' || flag == '+';
171 static int ischannel_func(SERVER_REC *server, const char *data)
176 const char *get_nick_flags(void)
181 static void send_message(SILC_SERVER_REC *server, char *target,
182 char *msg, int target_type)
184 g_return_if_fail(server != NULL);
185 g_return_if_fail(target != NULL);
186 g_return_if_fail(msg != NULL);
188 if (target_type == SEND_TARGET_CHANNEL)
189 silc_send_channel(server, target, msg);
191 silc_send_msg(server, target, msg);
194 static void sig_connected(SILC_SERVER_REC *server)
196 SilcClientConnection conn;
197 SilcClientConnectionParams params;
201 if (!IS_SILC_SERVER(server))
204 /* Try to read detached session data and use it if found. */
205 memset(¶ms, 0, sizeof(params));
206 memset(file, 0, sizeof(file));
207 snprintf(file, sizeof(file) - 1, "%s/session", get_irssi_dir());
208 params.detach_data = silc_file_readfile(file, ¶ms.detach_data_len);
210 /* Add connection to the client library */
211 conn = silc_client_add_connection(silc_client, ¶ms,
212 server->connrec->address,
213 server->connrec->port,
217 silc_free(params.detach_data);
220 fd = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
222 /* Start key exchange with the server */
223 silc_client_start_key_exchange(silc_client, conn, fd);
225 server->ftp_sessions = silc_dlist_init();
226 server->isnickflag = isnickflag_func;
227 server->ischannel = ischannel_func;
228 server->get_nick_flags = get_nick_flags;
229 server->send_message = (void *) send_message;
232 static void sig_disconnected(SILC_SERVER_REC *server)
234 if (!IS_SILC_SERVER(server))
237 silc_dlist_uninit(server->ftp_sessions);
239 if (server->conn && server->conn->sock != NULL) {
240 silc_client_close_connection(silc_client, server->conn);
242 /* SILC closes the handle */
243 g_io_channel_unref(net_sendbuffer_handle(server->handle));
244 net_sendbuffer_destroy(server->handle, FALSE);
245 server->handle = NULL;
249 SILC_SERVER_REC *silc_server_connect(SILC_SERVER_CONNECT_REC *conn)
251 SILC_SERVER_REC *server;
253 g_return_val_if_fail(IS_SILC_SERVER_CONNECT(conn), NULL);
254 if (conn->address == NULL || *conn->address == '\0')
256 if (conn->nick == NULL || *conn->nick == '\0') {
257 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
258 "Cannot connect: nickname is not set");
262 server = g_new0(SILC_SERVER_REC, 1);
263 server->chat_type = SILC_PROTOCOL;
264 server->connrec = conn;
265 if (server->connrec->port <= 0)
266 server->connrec->port = 706;
268 server_connect_ref(SERVER_CONNECT(conn));
270 if (!server_start_connect((SERVER_REC *) server)) {
271 server_connect_unref(SERVER_CONNECT(conn));
279 /* Return a string of all channels in server in server->channels_join()
282 char *silc_server_get_channels(SILC_SERVER_REC *server)
288 g_return_val_if_fail(server != NULL, FALSE);
290 chans = g_string_new(NULL);
291 for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
292 CHANNEL_REC *channel = tmp->data;
294 g_string_sprintfa(chans, "%s,", channel->name);
298 g_string_truncate(chans, chans->len-1);
301 g_string_free(chans, FALSE);
306 /* Syntaxes of all SILC commands for HELP files (the help file generation
307 will snoop these from here). */
309 /* SYNTAX: BAN <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
310 /* SYNTAX: CMODE <channel> +|-<modes> [{ <arguments>}] */
311 /* SYNTAX: CUMODE <channel> +|-<modes> <nickname>[@<hostname>] [-pubkey|<passwd>] */
312 /* SYNTAX: GETKEY <nickname or server name> */
313 /* SYNTAX: INVITE <channel> [<nickname>[@hostname>] */
314 /* SYNTAX: INVITE <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
315 /* SYNTAX: KEY MSG <nickname> set|unset|list|agreement|negotiate [<arguments>] */
316 /* SYNTAX: KEY CHANNEL <channel> set|unset|list|change [<arguments>] */
317 /* SYNTAX: KICK <channel> <nickname>[@<hostname>] [<comment>] */
318 /* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] */
319 /* SYNTAX: OPER <username> [-pubkey] */
320 /* SYNTAX: SILCOPER <username> [-pubkey] */
321 /* SYNTAX: TOPIC <channel> [<topic>] */
322 /* SYNTAX: UMODE +|-<modes> */
323 /* SYNTAX: WHOIS <nickname>[@<hostname>] [<count>] */
324 /* SYNTAX: WHOWAS <nickname>[@<hostname>] [<count>] */
325 /* SYNTAX: CLOSE <server> [<port>] */
326 /* SYNTAX: SHUTDOWN */
327 /* SYNTAX: MOTD [<server>] */
328 /* SYNTAX: LIST [<channel>] */
329 /* SYNTAX: ME <message> */
330 /* SYNTAX: ACTION <channel> <message> */
331 /* SYNTAX: AWAY [<message>] */
332 /* SYNTAX: INFO [<server>] */
333 /* SYNTAX: NICK <nickname> */
334 /* SYNTAX: NOTICE <message> */
335 /* SYNTAX: PART [<channel>] */
337 /* SYNTAX: SCONNECT <server> [<port>] */
338 /* SYNTAX: USERS <channel> */
339 /* SYNTAX: FILE SEND <filepath> <nickname> [<local IP> [<local port>]] */
340 /* SYNTAX: FILE RECEIVE [<nickname>] */
341 /* SYNTAX: FILE CLOSE [<nickname>] */
343 /* SYNTAX: JOIN <channel> [<passphrase>] [-cipher <cipher>] [-hmac <hmac>] [-founder <-pubkey|passwd>] */
346 void silc_command_exec(SILC_SERVER_REC *server,
347 const char *command, const char *args)
350 unsigned char **argv;
351 SilcUInt32 *argv_lens, *argv_types;
353 SilcClientCommand cmd;
354 SilcClientCommandContext ctx;
356 g_return_if_fail(server != NULL);
358 tmpcmd = g_strdup(command);
360 cmd = silc_client_command_find(silc_client, tmpcmd);
365 /* Now parse all arguments */
366 data = g_strconcat(command, " ", args, NULL);
367 silc_parse_command_line(data, &argv, &argv_lens,
368 &argv_types, &argc, cmd->max_args);
371 /* Allocate command context. This and its internals must be free'd
372 by the command routine receiving it. */
373 ctx = silc_client_command_alloc();
374 ctx->client = silc_client;
375 ctx->conn = server->conn;
379 ctx->argv_lens = argv_lens;
380 ctx->argv_types = argv_types;
382 /* Execute command */
383 silc_client_command_call(cmd, ctx);
386 /* Generic command function to call any SILC command directly. */
388 static void command_self(const char *data, SILC_SERVER_REC *server,
391 CMD_SILC_SERVER(server);
393 if (!IS_SILC_SERVER(server) || !server->connected) {
394 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
398 if (IS_SILC_CHANNEL(item)) {
399 SILC_CHANNEL_REC *chanrec;
400 chanrec = silc_channel_find(server, item->name);
402 server->conn->current_channel = chanrec->entry;
405 silc_command_exec(server, current_command, data);
409 /* SCONNECT command. Calls actually SILC's CONNECT command since Irssi
410 has CONNECT command for other purposes. */
412 static void command_sconnect(const char *data, SILC_SERVER_REC *server)
414 CMD_SILC_SERVER(server);
415 if (!IS_SILC_SERVER(server) || !server->connected) {
416 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
420 silc_command_exec(server, "CONNECT", data);
426 SILC_TASK_CALLBACK(silc_client_file_close_later)
428 FtpSession ftp = (FtpSession)context;
430 SILC_LOG_DEBUG(("Start"));
432 silc_client_file_close(silc_client, ftp->conn, ftp->session_id);
433 silc_free(ftp->filepath);
437 static void silc_client_file_monitor(SilcClient client,
438 SilcClientConnection conn,
439 SilcClientMonitorStatus status,
440 SilcClientFileError error,
443 SilcClientEntry client_entry,
444 SilcUInt32 session_id,
445 const char *filepath,
448 SILC_SERVER_REC *server = (SILC_SERVER_REC *)context;
452 snprintf(fsize, sizeof(fsize) - 1, "%llu", ((filesize + 1023) / 1024));
454 silc_dlist_start(server->ftp_sessions);
455 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
456 if (ftp->session_id == session_id) {
457 if (!ftp->filepath && filepath)
458 ftp->filepath = strdup(filepath);
463 if (ftp == SILC_LIST_END)
466 if (status == SILC_CLIENT_FILE_MONITOR_ERROR) {
467 if (error == SILC_CLIENT_FILE_NO_SUCH_FILE)
468 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
469 SILCTXT_FILE_ERROR_NO_SUCH_FILE,
470 client_entry->nickname,
471 filepath ? filepath : "[N/A]");
472 else if (error == SILC_CLIENT_FILE_PERMISSION_DENIED)
473 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
474 SILCTXT_FILE_ERROR_PERMISSION_DENIED,
475 client_entry->nickname);
477 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
478 SILCTXT_FILE_ERROR, client_entry->nickname);
479 silc_schedule_task_add(silc_client->schedule, 0,
480 silc_client_file_close_later, ftp,
481 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
482 if (ftp == server->current_session)
483 server->current_session = NULL;
484 silc_dlist_del(server->ftp_sessions, ftp);
487 if (status == SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT) {
488 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
489 SILCTXT_FILE_KEY_EXCHANGE, client_entry->nickname);
492 /* Save some transmission data */
493 if (offset && filesize) {
494 unsigned long delta = time(NULL) - ftp->starttime;
496 ftp->percent = ((double)offset / (double)filesize) * (double)100.0;
498 ftp->kps = (double)((offset / (double)delta) + 1023) / (double)1024;
500 ftp->kps = (double)(offset + 1023) / (double)1024;
501 ftp->offset = offset;
502 ftp->filesize = filesize;
505 if (status == SILC_CLIENT_FILE_MONITOR_SEND) {
507 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
508 SILCTXT_FILE_TRANSMIT, filepath, fsize,
509 client_entry->nickname);
510 ftp->starttime = time(NULL);
512 if (offset == filesize) {
513 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
514 SILCTXT_FILE_TRANSMITTED, filepath, fsize,
515 client_entry->nickname, ftp->kps);
516 silc_schedule_task_add(silc_client->schedule, 0,
517 silc_client_file_close_later, ftp,
518 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
519 if (ftp == server->current_session)
520 server->current_session = NULL;
521 silc_dlist_del(server->ftp_sessions, ftp);
525 if (status == SILC_CLIENT_FILE_MONITOR_RECEIVE) {
527 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
528 SILCTXT_FILE_RECEIVE, filepath, fsize,
529 client_entry->nickname);
530 ftp->starttime = time(NULL);
533 if (offset == filesize) {
534 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
535 SILCTXT_FILE_RECEIVED, filepath, fsize,
536 client_entry->nickname, ftp->kps);
537 silc_schedule_task_add(silc_client->schedule, 0,
538 silc_client_file_close_later, ftp,
539 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
540 if (ftp == server->current_session)
541 server->current_session = NULL;
542 silc_dlist_del(server->ftp_sessions, ftp);
548 SILC_SERVER_REC *server;
554 static void silc_client_command_file_get_clients(SilcClient client,
555 SilcClientConnection conn,
556 SilcClientEntry *clients,
557 SilcUInt32 clients_count,
560 FileGetClients internal = (FileGetClients)context;
563 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
565 silc_free(internal->data);
566 silc_free(internal->nick);
571 signal_emit("command file", 3, internal->data, internal->server,
574 silc_free(internal->data);
575 silc_free(internal->nick);
579 static void command_file(const char *data, SILC_SERVER_REC *server,
582 SilcClientConnection conn;
583 SilcClientEntry *entrys, client_entry;
584 SilcClientFileError ret;
585 SilcUInt32 entry_count;
586 char *nickname = NULL, *tmp;
587 unsigned char **argv;
589 SilcUInt32 *argv_lens, *argv_types;
592 char *local_ip = NULL;
593 SilcUInt32 local_port = 0;
594 SilcUInt32 session_id;
596 CMD_SILC_SERVER(server);
597 if (!server || !IS_SILC_SERVER(server) || !server->connected)
598 cmd_return_error(CMDERR_NOT_CONNECTED);
602 /* Now parse all arguments */
603 tmp = g_strconcat("FILE", " ", data, NULL);
604 silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 6);
611 if (!strcasecmp(argv[1], "send"))
613 if (!strcasecmp(argv[1], "receive"))
615 if (!strcasecmp(argv[1], "close"))
620 cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
625 cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
627 /* Parse the typed nickname. */
628 if (!silc_parse_userfqdn(argv[3], &nickname, NULL)) {
629 printformat_module("fe-common/silc", server, NULL,
630 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[3]);
634 /* Find client entry */
635 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
636 argv[3], &entry_count);
638 FileGetClients inter = silc_calloc(1, sizeof(*inter));
639 inter->server = server;
640 inter->data = strdup(data);
641 inter->nick = strdup(nickname);
643 silc_client_get_clients(silc_client, conn, nickname, argv[3],
644 silc_client_command_file_get_clients, inter);
647 client_entry = entrys[0];
653 local_port = atoi(argv[5]);
656 silc_client_file_send(silc_client, conn, silc_client_file_monitor,
657 server, local_ip, local_port,
658 client_entry, argv[2], &session_id);
659 if (ret == SILC_CLIENT_FILE_OK) {
660 ftp = silc_calloc(1, sizeof(*ftp));
661 ftp->session_id = session_id;
663 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
664 SILCTXT_FILE_SEND, client_entry->nickname,
667 ftp->client_entry = client_entry;
668 ftp->filepath = strdup(argv[2]);
671 silc_dlist_add(server->ftp_sessions, ftp);
672 server->current_session = ftp;
674 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
675 printformat_module("fe-common/silc", server, NULL,
676 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
677 client_entry->nickname);
678 if (ret == SILC_CLIENT_FILE_NO_SUCH_FILE)
679 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
680 SILCTXT_FILE_ERROR_NO_SUCH_FILE,
681 client_entry->nickname, argv[2]);
687 /* Parse the typed nickname. */
689 if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
690 printformat_module("fe-common/silc", server, NULL,
691 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
695 /* Find client entry */
696 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
697 argv[2], &entry_count);
699 FileGetClients inter = silc_calloc(1, sizeof(*inter));
700 inter->server = server;
701 inter->data = strdup(data);
702 inter->nick = strdup(nickname);
704 silc_client_get_clients(silc_client, conn, nickname, argv[2],
705 silc_client_command_file_get_clients, inter);
708 client_entry = entrys[0];
711 if (!server->current_session) {
712 printformat_module("fe-common/silc", server, NULL,
713 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
717 ret = silc_client_file_receive(silc_client, conn,
718 silc_client_file_monitor, server,
719 server->current_session->session_id);
720 if (ret != SILC_CLIENT_FILE_OK) {
721 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
722 printformat_module("fe-common/silc", server, NULL,
723 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
724 server->current_session->client_entry->nickname);
726 printformat_module("fe-common/silc", server, NULL,
727 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
728 server->current_session->client_entry->nickname);
734 silc_dlist_start(server->ftp_sessions);
735 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
736 if (ftp->client_entry == client_entry && !ftp->filepath) {
737 ret = silc_client_file_receive(silc_client, conn,
738 silc_client_file_monitor, server,
740 if (ret != SILC_CLIENT_FILE_OK) {
741 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
742 printformat_module("fe-common/silc", server, NULL,
743 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
744 client_entry->nickname);
746 printformat_module("fe-common/silc", server, NULL,
747 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
748 client_entry->nickname);
754 if (ftp == SILC_LIST_END) {
755 printformat_module("fe-common/silc", server, NULL,
756 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
757 client_entry->nickname);
763 /* Parse the typed nickname. */
765 if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
766 printformat_module("fe-common/silc", server, NULL,
767 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
771 /* Find client entry */
772 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
773 argv[2], &entry_count);
775 FileGetClients inter = silc_calloc(1, sizeof(*inter));
776 inter->server = server;
777 inter->data = strdup(data);
778 inter->nick = strdup(nickname);
780 silc_client_get_clients(silc_client, conn, nickname, argv[2],
781 silc_client_command_file_get_clients, inter);
784 client_entry = entrys[0];
787 if (!server->current_session) {
788 printformat_module("fe-common/silc", server, NULL,
789 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
793 silc_client_file_close(silc_client, conn,
794 server->current_session->session_id);
795 printformat_module("fe-common/silc", server, NULL,
796 MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
797 server->current_session->client_entry->nickname,
798 server->current_session->filepath ?
799 server->current_session->filepath : "[N/A]");
800 silc_dlist_del(server->ftp_sessions, server->current_session);
801 silc_free(server->current_session->filepath);
802 silc_free(server->current_session);
803 server->current_session = NULL;
807 silc_dlist_start(server->ftp_sessions);
808 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
809 if (ftp->client_entry == client_entry) {
810 silc_client_file_close(silc_client, conn, ftp->session_id);
811 printformat_module("fe-common/silc", server, NULL,
812 MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
813 client_entry->nickname,
814 ftp->filepath ? ftp->filepath : "[N/A]");
815 if (ftp == server->current_session)
816 server->current_session = NULL;
817 silc_dlist_del(server->ftp_sessions, ftp);
818 silc_free(ftp->filepath);
824 if (ftp == SILC_LIST_END) {
825 printformat_module("fe-common/silc", server, NULL,
826 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
827 client_entry->nickname);
834 if (!silc_dlist_count(server->ftp_sessions)) {
835 printformat_module("fe-common/silc", server, NULL,
836 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
840 printformat_module("fe-common/silc", server, NULL,
841 MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_HEADER);
843 silc_dlist_start(server->ftp_sessions);
844 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
845 printformat_module("fe-common/silc", server, NULL,
846 MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_LINE,
847 ftp->client_entry->nickname,
848 ftp->send ? "send" : "receive",
849 (SilcUInt32)(ftp->offset + 1023) / 1024,
850 (SilcUInt32)(ftp->filesize + 1023) / 1024,
851 ftp->percent, ftp->kps,
852 ftp->filepath ? ftp->filepath : "[N/A]");
865 void silc_server_init(void)
867 silc_servers_reconnect_init();
869 signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
870 signal_add("server disconnected", (SIGNAL_FUNC) sig_disconnected);
871 command_bind_silc("whois", MODULE_NAME, (SIGNAL_FUNC) command_self);
872 command_bind_silc("whowas", MODULE_NAME, (SIGNAL_FUNC) command_self);
873 command_bind_silc("nick", MODULE_NAME, (SIGNAL_FUNC) command_self);
874 command_bind_silc("topic", MODULE_NAME, (SIGNAL_FUNC) command_self);
875 command_bind_silc("cmode", MODULE_NAME, (SIGNAL_FUNC) command_self);
876 command_bind_silc("cumode", MODULE_NAME, (SIGNAL_FUNC) command_self);
877 command_bind_silc("users", MODULE_NAME, (SIGNAL_FUNC) command_self);
878 command_bind_silc("list", MODULE_NAME, (SIGNAL_FUNC) command_self);
879 command_bind_silc("ban", MODULE_NAME, (SIGNAL_FUNC) command_self);
880 command_bind_silc("oper", MODULE_NAME, (SIGNAL_FUNC) command_self);
881 command_bind_silc("silcoper", MODULE_NAME, (SIGNAL_FUNC) command_self);
882 command_bind_silc("umode", MODULE_NAME, (SIGNAL_FUNC) command_self);
883 command_bind_silc("invite", MODULE_NAME, (SIGNAL_FUNC) command_self);
884 command_bind_silc("kill", MODULE_NAME, (SIGNAL_FUNC) command_self);
885 command_bind_silc("kick", MODULE_NAME, (SIGNAL_FUNC) command_self);
886 command_bind_silc("info", MODULE_NAME, (SIGNAL_FUNC) command_self);
887 command_bind_silc("ping", MODULE_NAME, (SIGNAL_FUNC) command_self);
888 command_bind_silc("motd", MODULE_NAME, (SIGNAL_FUNC) command_self);
889 command_bind_silc("close", MODULE_NAME, (SIGNAL_FUNC) command_self);
890 command_bind_silc("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
891 command_bind_silc("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
892 command_bind_silc("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
893 command_bind_silc("file", MODULE_NAME, (SIGNAL_FUNC) command_file);
894 command_bind_silc("detach", MODULE_NAME, (SIGNAL_FUNC) command_self);
896 command_set_options("connect", "+silcnet");
899 void silc_server_deinit(void)
901 silc_servers_reconnect_deinit();
903 signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
904 signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
905 command_unbind("whois", (SIGNAL_FUNC) command_self);
906 command_unbind("whowas", (SIGNAL_FUNC) command_self);
907 command_unbind("nick", (SIGNAL_FUNC) command_self);
908 command_unbind("topic", (SIGNAL_FUNC) command_self);
909 command_unbind("cmode", (SIGNAL_FUNC) command_self);
910 command_unbind("cumode", (SIGNAL_FUNC) command_self);
911 command_unbind("users", (SIGNAL_FUNC) command_self);
912 command_unbind("list", (SIGNAL_FUNC) command_self);
913 command_unbind("oper", (SIGNAL_FUNC) command_self);
914 command_unbind("silcoper", (SIGNAL_FUNC) command_self);
915 command_unbind("umode", (SIGNAL_FUNC) command_self);
916 command_unbind("invite", (SIGNAL_FUNC) command_self);
917 command_unbind("kill", (SIGNAL_FUNC) command_self);
918 command_unbind("kick", (SIGNAL_FUNC) command_self);
919 command_unbind("info", (SIGNAL_FUNC) command_self);
920 command_unbind("ping", (SIGNAL_FUNC) command_self);
921 command_unbind("motd", (SIGNAL_FUNC) command_self);
922 command_unbind("ban", (SIGNAL_FUNC) command_self);
923 command_unbind("close", (SIGNAL_FUNC) command_self);
924 command_unbind("shutdown", (SIGNAL_FUNC) command_self);
925 command_unbind("getkey", (SIGNAL_FUNC) command_self);
926 command_unbind("sconnect", (SIGNAL_FUNC) command_sconnect);
927 command_unbind("file", (SIGNAL_FUNC) command_file);
928 command_unbind("detach", (SIGNAL_FUNC) command_self);
931 void silc_server_free_ftp(SILC_SERVER_REC *server,
932 SilcClientEntry client_entry)
936 silc_dlist_start(server->ftp_sessions);
937 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
938 if (ftp->client_entry == client_entry) {
939 silc_dlist_del(server->ftp_sessions, ftp);
940 silc_free(ftp->filepath);