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)
60 silc_client_send_channel_message(silc_client, server->conn, rec->entry,
61 NULL, 0, msg, strlen(msg), TRUE);
67 SILC_SERVER_REC *server;
70 /* Callback function that sends the private message if the client was
71 resolved from the server. */
73 static void silc_send_msg_clients(SilcClient client,
74 SilcClientConnection conn,
75 SilcClientEntry *clients,
76 SilcUInt32 clients_count,
79 PRIVMSG_REC *rec = context;
80 SILC_SERVER_REC *server = rec->server;
81 SilcClientEntry target;
82 char *nickname = NULL;
85 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
86 "%s: There is no such client", rec->nick);
88 if (clients_count > 1) {
89 silc_parse_userfqdn(rec->nick, &nickname, NULL);
91 /* Find the correct one. The rec->nick might be a formatted nick
92 so this will find the correct one. */
93 clients = silc_client_get_clients_local(silc_client, server->conn,
97 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
98 "%s: There is no such client", rec->nick);
107 /* Still check for exact math for nickname, this compares the
108 real (formatted) nickname and the nick (maybe formatted) that
109 use gave. This is to assure that `nick' does not match
111 if (strcasecmp(rec->nick, clients[0]->nickname)) {
112 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
113 "%s: There is no such client", rec->nick);
117 /* Send the private message */
118 silc_client_send_private_message(client, conn, target, 0,
119 rec->msg, strlen(rec->msg),
129 static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg)
132 SilcClientEntry *clients;
133 SilcUInt32 clients_count;
134 char *nickname = NULL;
136 if (!silc_parse_userfqdn(nick, &nickname, NULL)) {
137 printformat_module("fe-common/silc", server, NULL,
138 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
142 /* Find client entry */
143 clients = silc_client_get_clients_local(silc_client, server->conn,
144 nickname, nick, &clients_count);
146 rec = g_new0(PRIVMSG_REC, 1);
147 rec->nick = g_strdup(nick);
148 rec->msg = g_strdup(msg);
149 rec->server = server;
151 /* Could not find client with that nick, resolve it from server. */
152 silc_client_get_clients(silc_client, server->conn,
153 nickname, NULL, silc_send_msg_clients, rec);
158 /* Send the private message directly */
160 silc_client_send_private_message(silc_client, server->conn,
161 clients[0], 0, msg, strlen(msg), TRUE);
164 static int isnickflag_func(char flag)
166 return flag == '@' || flag == '+';
169 static int ischannel_func(SERVER_REC *server, const char *data)
174 const char *get_nick_flags(void)
179 static void send_message(SILC_SERVER_REC *server, char *target,
180 char *msg, int target_type)
182 g_return_if_fail(server != NULL);
183 g_return_if_fail(target != NULL);
184 g_return_if_fail(msg != NULL);
186 if (target_type == SEND_TARGET_CHANNEL)
187 silc_send_channel(server, target, msg);
189 silc_send_msg(server, target, msg);
192 static void sig_connected(SILC_SERVER_REC *server)
194 SilcClientConnection conn;
197 if (!IS_SILC_SERVER(server))
200 conn = silc_client_add_connection(silc_client,
201 server->connrec->address,
202 server->connrec->port,
206 fd = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
207 silc_client_start_key_exchange(silc_client, conn, fd);
209 server->ftp_sessions = silc_dlist_init();
210 server->isnickflag = isnickflag_func;
211 server->ischannel = ischannel_func;
212 server->get_nick_flags = get_nick_flags;
213 server->send_message = (void *) send_message;
216 static void sig_disconnected(SILC_SERVER_REC *server)
218 if (!IS_SILC_SERVER(server))
221 silc_dlist_uninit(server->ftp_sessions);
223 if (server->conn && server->conn->sock != NULL) {
224 silc_client_close_connection(silc_client, server->conn);
226 /* SILC closes the handle */
227 g_io_channel_unref(net_sendbuffer_handle(server->handle));
228 net_sendbuffer_destroy(server->handle, FALSE);
229 server->handle = NULL;
233 SILC_SERVER_REC *silc_server_connect(SILC_SERVER_CONNECT_REC *conn)
235 SILC_SERVER_REC *server;
237 g_return_val_if_fail(IS_SILC_SERVER_CONNECT(conn), NULL);
238 if (conn->address == NULL || *conn->address == '\0')
240 if (conn->nick == NULL || *conn->nick == '\0') {
241 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
242 "Cannot connect: nickname is not set");
246 server = g_new0(SILC_SERVER_REC, 1);
247 server->chat_type = SILC_PROTOCOL;
248 server->connrec = conn;
249 if (server->connrec->port <= 0)
250 server->connrec->port = 706;
252 server_connect_ref(SERVER_CONNECT(conn));
254 if (!server_start_connect((SERVER_REC *) server)) {
255 server_connect_unref(SERVER_CONNECT(conn));
263 /* Return a string of all channels in server in server->channels_join()
266 char *silc_server_get_channels(SILC_SERVER_REC *server)
272 g_return_val_if_fail(server != NULL, FALSE);
274 chans = g_string_new(NULL);
275 for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
276 CHANNEL_REC *channel = tmp->data;
278 g_string_sprintfa(chans, "%s,", channel->name);
282 g_string_truncate(chans, chans->len-1);
285 g_string_free(chans, FALSE);
290 /* Syntaxes of all SILC commands for HELP files (the help file generation
291 will snoop these from here). */
293 /* SYNTAX: BAN <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
294 /* SYNTAX: CMODE <channel> +|-<modes> [{ <arguments>}] */
295 /* SYNTAX: CUMODE <channel> +|-<modes> <nickname>[@<hostname>] [-pubkey|<passwd>] */
296 /* SYNTAX: GETKEY <nickname or server name> */
297 /* SYNTAX: INVITE <channel> [<nickname>[@hostname>] */
298 /* SYNTAX: INVITE <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
299 /* SYNTAX: KEY MSG <nickname> set|unset|list|agreement|negotiate [<arguments>] */
300 /* SYNTAX: KEY CHANNEL <channel> set|unset|list|change [<arguments>] */
301 /* SYNTAX: KICK <channel> <nickname>[@<hostname>] [<comment>] */
302 /* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] */
303 /* SYNTAX: OPER <username> [-pubkey] */
304 /* SYNTAX: SILCOPER <username> [-pubkey] */
305 /* SYNTAX: TOPIC <channel> [<topic>] */
306 /* SYNTAX: UMODE +|-<modes> */
307 /* SYNTAX: WHOIS <nickname>[@<hostname>] [<count>] */
308 /* SYNTAX: WHOWAS <nickname>[@<hostname>] [<count>] */
309 /* SYNTAX: CLOSE <server> [<port>] */
310 /* SYNTAX: SHUTDOWN */
311 /* SYNTAX: MOTD [<server>] */
312 /* SYNTAX: LIST [<channel>] */
313 /* SYNTAX: ME <message> */
314 /* SYNTAX: ACTION <channel> <message> */
315 /* SYNTAX: AWAY [<message>] */
316 /* SYNTAX: INFO [<server>] */
317 /* SYNTAX: NICK <nickname> */
318 /* SYNTAX: NOTICE <message> */
319 /* SYNTAX: PART [<channel>] */
321 /* SYNTAX: SCONNECT <server> [<port>] */
322 /* SYNTAX: USERS <channel> */
323 /* SYNTAX: FILE SEND <filepath> <nickname> [<local IP> [<local port>]] */
324 /* SYNTAX: FILE RECEIVE [<nickname>] */
325 /* SYNTAX: FILE CLOSE [<nickname>] */
327 /* SYNTAX: JOIN <channel> [<passphrase>] [-cipher <cipher>] [-hmac <hmac>] [-founder <-pubkey|passwd>] */
329 void silc_command_exec(SILC_SERVER_REC *server,
330 const char *command, const char *args)
333 unsigned char **argv;
334 SilcUInt32 *argv_lens, *argv_types;
336 SilcClientCommand cmd;
337 SilcClientCommandContext ctx;
339 g_return_if_fail(server != NULL);
341 tmpcmd = g_strdup(command);
343 cmd = silc_client_command_find(silc_client, tmpcmd);
348 /* Now parse all arguments */
349 data = g_strconcat(command, " ", args, NULL);
350 silc_parse_command_line(data, &argv, &argv_lens,
351 &argv_types, &argc, cmd->max_args);
354 /* Allocate command context. This and its internals must be free'd
355 by the command routine receiving it. */
356 ctx = silc_client_command_alloc();
357 ctx->client = silc_client;
358 ctx->conn = server->conn;
362 ctx->argv_lens = argv_lens;
363 ctx->argv_types = argv_types;
365 /* Execute command */
366 silc_client_command_call(cmd, ctx);
369 /* Generic command function to call any SILC command directly. */
371 static void command_self(const char *data, SILC_SERVER_REC *server,
374 CMD_SILC_SERVER(server);
376 if (!IS_SILC_SERVER(server) || !server->connected) {
377 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
381 if (IS_SILC_CHANNEL(item)) {
382 SILC_CHANNEL_REC *chanrec;
383 chanrec = silc_channel_find(server, item->name);
385 server->conn->current_channel = chanrec->entry;
388 silc_command_exec(server, current_command, data);
392 /* SCONNECT command. Calls actually SILC's CONNECT command since Irssi
393 has CONNECT command for other purposes. */
395 static void command_sconnect(const char *data, SILC_SERVER_REC *server)
397 CMD_SILC_SERVER(server);
398 if (!IS_SILC_SERVER(server) || !server->connected) {
399 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
403 silc_command_exec(server, "CONNECT", data);
409 SILC_TASK_CALLBACK(silc_client_file_close_later)
411 FtpSession ftp = (FtpSession)context;
413 SILC_LOG_DEBUG(("Start"));
415 silc_client_file_close(silc_client, ftp->conn, ftp->session_id);
416 silc_free(ftp->filepath);
420 static void silc_client_file_monitor(SilcClient client,
421 SilcClientConnection conn,
422 SilcClientMonitorStatus status,
423 SilcClientFileError error,
426 SilcClientEntry client_entry,
427 SilcUInt32 session_id,
428 const char *filepath,
431 SILC_SERVER_REC *server = (SILC_SERVER_REC *)context;
435 snprintf(fsize, sizeof(fsize) - 1, "%llu", ((filesize + 1023) / 1024));
437 silc_dlist_start(server->ftp_sessions);
438 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
439 if (ftp->session_id == session_id) {
440 if (!ftp->filepath && filepath)
441 ftp->filepath = strdup(filepath);
446 if (ftp == SILC_LIST_END)
449 if (status == SILC_CLIENT_FILE_MONITOR_ERROR) {
450 if (error == SILC_CLIENT_FILE_NO_SUCH_FILE)
451 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
452 SILCTXT_FILE_ERROR_NO_SUCH_FILE,
453 client_entry->nickname,
454 filepath ? filepath : "[N/A]");
455 else if (error == SILC_CLIENT_FILE_PERMISSION_DENIED)
456 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
457 SILCTXT_FILE_ERROR_PERMISSION_DENIED,
458 client_entry->nickname);
460 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
461 SILCTXT_FILE_ERROR, client_entry->nickname);
462 silc_schedule_task_add(silc_client->schedule, 0,
463 silc_client_file_close_later, ftp,
464 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
465 if (ftp == server->current_session)
466 server->current_session = NULL;
467 silc_dlist_del(server->ftp_sessions, ftp);
470 if (status == SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT) {
471 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
472 SILCTXT_FILE_KEY_EXCHANGE, client_entry->nickname);
475 /* Save some transmission data */
476 if (offset && filesize) {
477 unsigned long delta = time(NULL) - ftp->starttime;
479 ftp->percent = ((double)offset / (double)filesize) * (double)100.0;
481 ftp->kps = (double)((offset / (double)delta) + 1023) / (double)1024;
483 ftp->kps = (double)(offset + 1023) / (double)1024;
484 ftp->offset = offset;
485 ftp->filesize = filesize;
488 if (status == SILC_CLIENT_FILE_MONITOR_SEND) {
490 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
491 SILCTXT_FILE_TRANSMIT, filepath, fsize,
492 client_entry->nickname);
493 ftp->starttime = time(NULL);
495 if (offset == filesize) {
496 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
497 SILCTXT_FILE_TRANSMITTED, filepath, fsize,
498 client_entry->nickname, ftp->kps);
499 silc_schedule_task_add(silc_client->schedule, 0,
500 silc_client_file_close_later, ftp,
501 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
502 if (ftp == server->current_session)
503 server->current_session = NULL;
504 silc_dlist_del(server->ftp_sessions, ftp);
508 if (status == SILC_CLIENT_FILE_MONITOR_RECEIVE) {
510 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
511 SILCTXT_FILE_RECEIVE, filepath, fsize,
512 client_entry->nickname);
513 ftp->starttime = time(NULL);
516 if (offset == filesize) {
517 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
518 SILCTXT_FILE_RECEIVED, filepath, fsize,
519 client_entry->nickname, ftp->kps);
520 silc_schedule_task_add(silc_client->schedule, 0,
521 silc_client_file_close_later, ftp,
522 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
523 if (ftp == server->current_session)
524 server->current_session = NULL;
525 silc_dlist_del(server->ftp_sessions, ftp);
531 SILC_SERVER_REC *server;
537 static void silc_client_command_file_get_clients(SilcClient client,
538 SilcClientConnection conn,
539 SilcClientEntry *clients,
540 SilcUInt32 clients_count,
543 FileGetClients internal = (FileGetClients)context;
546 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
548 silc_free(internal->data);
549 silc_free(internal->nick);
554 signal_emit("command file", 3, internal->data, internal->server,
557 silc_free(internal->data);
558 silc_free(internal->nick);
562 static void command_file(const char *data, SILC_SERVER_REC *server,
565 SilcClientConnection conn;
566 SilcClientEntry *entrys, client_entry;
567 SilcClientFileError ret;
568 SilcUInt32 entry_count;
569 char *nickname = NULL, *tmp;
570 unsigned char **argv;
572 SilcUInt32 *argv_lens, *argv_types;
575 char *local_ip = NULL;
576 SilcUInt32 local_port = 0;
577 SilcUInt32 session_id;
579 CMD_SILC_SERVER(server);
580 if (!server || !IS_SILC_SERVER(server) || !server->connected)
581 cmd_return_error(CMDERR_NOT_CONNECTED);
585 /* Now parse all arguments */
586 tmp = g_strconcat("FILE", " ", data, NULL);
587 silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 6);
594 if (!strcasecmp(argv[1], "send"))
596 if (!strcasecmp(argv[1], "receive"))
598 if (!strcasecmp(argv[1], "close"))
603 cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
608 cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
610 /* Parse the typed nickname. */
611 if (!silc_parse_userfqdn(argv[3], &nickname, NULL)) {
612 printformat_module("fe-common/silc", server, NULL,
613 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[3]);
617 /* Find client entry */
618 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
619 argv[3], &entry_count);
621 FileGetClients inter = silc_calloc(1, sizeof(*inter));
622 inter->server = server;
623 inter->data = strdup(data);
624 inter->nick = strdup(nickname);
626 silc_client_get_clients(silc_client, conn, nickname, argv[3],
627 silc_client_command_file_get_clients, inter);
630 client_entry = entrys[0];
636 local_port = atoi(argv[5]);
639 silc_client_file_send(silc_client, conn, silc_client_file_monitor,
640 server, local_ip, local_port,
641 client_entry, argv[2], &session_id);
642 if (ret == SILC_CLIENT_FILE_OK) {
643 ftp = silc_calloc(1, sizeof(*ftp));
644 ftp->session_id = session_id;
646 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
647 SILCTXT_FILE_SEND, client_entry->nickname,
650 ftp->client_entry = client_entry;
651 ftp->filepath = strdup(argv[2]);
654 silc_dlist_add(server->ftp_sessions, ftp);
655 server->current_session = ftp;
657 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
658 printformat_module("fe-common/silc", server, NULL,
659 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
660 client_entry->nickname);
661 if (ret == SILC_CLIENT_FILE_NO_SUCH_FILE)
662 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
663 SILCTXT_FILE_ERROR_NO_SUCH_FILE,
664 client_entry->nickname, argv[2]);
670 /* Parse the typed nickname. */
672 if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
673 printformat_module("fe-common/silc", server, NULL,
674 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
678 /* Find client entry */
679 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
680 argv[2], &entry_count);
682 FileGetClients inter = silc_calloc(1, sizeof(*inter));
683 inter->server = server;
684 inter->data = strdup(data);
685 inter->nick = strdup(nickname);
687 silc_client_get_clients(silc_client, conn, nickname, argv[2],
688 silc_client_command_file_get_clients, inter);
691 client_entry = entrys[0];
694 if (!server->current_session) {
695 printformat_module("fe-common/silc", server, NULL,
696 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
700 ret = silc_client_file_receive(silc_client, conn,
701 silc_client_file_monitor, server,
702 server->current_session->session_id);
703 if (ret != SILC_CLIENT_FILE_OK) {
704 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
705 printformat_module("fe-common/silc", server, NULL,
706 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
707 server->current_session->client_entry->nickname);
709 printformat_module("fe-common/silc", server, NULL,
710 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
711 server->current_session->client_entry->nickname);
717 silc_dlist_start(server->ftp_sessions);
718 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
719 if (ftp->client_entry == client_entry && !ftp->filepath) {
720 ret = silc_client_file_receive(silc_client, conn,
721 silc_client_file_monitor, server,
723 if (ret != SILC_CLIENT_FILE_OK) {
724 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
725 printformat_module("fe-common/silc", server, NULL,
726 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
727 client_entry->nickname);
729 printformat_module("fe-common/silc", server, NULL,
730 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
731 client_entry->nickname);
737 if (ftp == SILC_LIST_END) {
738 printformat_module("fe-common/silc", server, NULL,
739 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
740 client_entry->nickname);
746 /* Parse the typed nickname. */
748 if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
749 printformat_module("fe-common/silc", server, NULL,
750 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
754 /* Find client entry */
755 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
756 argv[2], &entry_count);
758 FileGetClients inter = silc_calloc(1, sizeof(*inter));
759 inter->server = server;
760 inter->data = strdup(data);
761 inter->nick = strdup(nickname);
763 silc_client_get_clients(silc_client, conn, nickname, argv[2],
764 silc_client_command_file_get_clients, inter);
767 client_entry = entrys[0];
770 if (!server->current_session) {
771 printformat_module("fe-common/silc", server, NULL,
772 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
776 silc_client_file_close(silc_client, conn,
777 server->current_session->session_id);
778 printformat_module("fe-common/silc", server, NULL,
779 MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
780 server->current_session->client_entry->nickname,
781 server->current_session->filepath ?
782 server->current_session->filepath : "[N/A]");
783 silc_dlist_del(server->ftp_sessions, server->current_session);
784 silc_free(server->current_session->filepath);
785 silc_free(server->current_session);
786 server->current_session = NULL;
790 silc_dlist_start(server->ftp_sessions);
791 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
792 if (ftp->client_entry == client_entry) {
793 silc_client_file_close(silc_client, conn, ftp->session_id);
794 printformat_module("fe-common/silc", server, NULL,
795 MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
796 client_entry->nickname,
797 ftp->filepath ? ftp->filepath : "[N/A]");
798 if (ftp == server->current_session)
799 server->current_session = NULL;
800 silc_dlist_del(server->ftp_sessions, ftp);
801 silc_free(ftp->filepath);
807 if (ftp == SILC_LIST_END) {
808 printformat_module("fe-common/silc", server, NULL,
809 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
810 client_entry->nickname);
817 if (!silc_dlist_count(server->ftp_sessions)) {
818 printformat_module("fe-common/silc", server, NULL,
819 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
823 printformat_module("fe-common/silc", server, NULL,
824 MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_HEADER);
826 silc_dlist_start(server->ftp_sessions);
827 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
828 printformat_module("fe-common/silc", server, NULL,
829 MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_LINE,
830 ftp->client_entry->nickname,
831 ftp->send ? "send" : "receive",
832 (SilcUInt32)(ftp->offset + 1023) / 1024,
833 (SilcUInt32)(ftp->filesize + 1023) / 1024,
834 ftp->percent, ftp->kps,
835 ftp->filepath ? ftp->filepath : "[N/A]");
848 void silc_server_init(void)
850 silc_servers_reconnect_init();
852 signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
853 signal_add("server disconnected", (SIGNAL_FUNC) sig_disconnected);
854 command_bind_silc("whois", MODULE_NAME, (SIGNAL_FUNC) command_self);
855 command_bind_silc("whowas", MODULE_NAME, (SIGNAL_FUNC) command_self);
856 command_bind_silc("nick", MODULE_NAME, (SIGNAL_FUNC) command_self);
857 command_bind_silc("topic", MODULE_NAME, (SIGNAL_FUNC) command_self);
858 command_bind_silc("cmode", MODULE_NAME, (SIGNAL_FUNC) command_self);
859 command_bind_silc("cumode", MODULE_NAME, (SIGNAL_FUNC) command_self);
860 command_bind_silc("users", MODULE_NAME, (SIGNAL_FUNC) command_self);
861 command_bind_silc("list", MODULE_NAME, (SIGNAL_FUNC) command_self);
862 command_bind_silc("ban", MODULE_NAME, (SIGNAL_FUNC) command_self);
863 command_bind_silc("oper", MODULE_NAME, (SIGNAL_FUNC) command_self);
864 command_bind_silc("silcoper", MODULE_NAME, (SIGNAL_FUNC) command_self);
865 command_bind_silc("umode", MODULE_NAME, (SIGNAL_FUNC) command_self);
866 command_bind_silc("invite", MODULE_NAME, (SIGNAL_FUNC) command_self);
867 command_bind_silc("kill", MODULE_NAME, (SIGNAL_FUNC) command_self);
868 command_bind_silc("kick", MODULE_NAME, (SIGNAL_FUNC) command_self);
869 command_bind_silc("info", MODULE_NAME, (SIGNAL_FUNC) command_self);
870 command_bind_silc("ping", MODULE_NAME, (SIGNAL_FUNC) command_self);
871 command_bind_silc("motd", MODULE_NAME, (SIGNAL_FUNC) command_self);
872 command_bind_silc("close", MODULE_NAME, (SIGNAL_FUNC) command_self);
873 command_bind_silc("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
874 command_bind_silc("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
875 command_bind_silc("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
876 command_bind_silc("file", MODULE_NAME, (SIGNAL_FUNC) command_file);
878 command_set_options("connect", "+silcnet");
881 void silc_server_deinit(void)
883 silc_servers_reconnect_deinit();
885 signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
886 signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
887 command_unbind("whois", (SIGNAL_FUNC) command_self);
888 command_unbind("whowas", (SIGNAL_FUNC) command_self);
889 command_unbind("nick", (SIGNAL_FUNC) command_self);
890 command_unbind("topic", (SIGNAL_FUNC) command_self);
891 command_unbind("cmode", (SIGNAL_FUNC) command_self);
892 command_unbind("cumode", (SIGNAL_FUNC) command_self);
893 command_unbind("users", (SIGNAL_FUNC) command_self);
894 command_unbind("list", (SIGNAL_FUNC) command_self);
895 command_unbind("oper", (SIGNAL_FUNC) command_self);
896 command_unbind("silcoper", (SIGNAL_FUNC) command_self);
897 command_unbind("umode", (SIGNAL_FUNC) command_self);
898 command_unbind("invite", (SIGNAL_FUNC) command_self);
899 command_unbind("kill", (SIGNAL_FUNC) command_self);
900 command_unbind("kick", (SIGNAL_FUNC) command_self);
901 command_unbind("info", (SIGNAL_FUNC) command_self);
902 command_unbind("ping", (SIGNAL_FUNC) command_self);
903 command_unbind("motd", (SIGNAL_FUNC) command_self);
904 command_unbind("ban", (SIGNAL_FUNC) command_self);
905 command_unbind("close", (SIGNAL_FUNC) command_self);
906 command_unbind("shutdown", (SIGNAL_FUNC) command_self);
907 command_unbind("getkey", (SIGNAL_FUNC) command_self);
908 command_unbind("sconnect", (SIGNAL_FUNC) command_sconnect);
909 command_unbind("file", (SIGNAL_FUNC) command_file);
912 void silc_server_free_ftp(SILC_SERVER_REC *server,
913 SilcClientEntry client_entry)
917 silc_dlist_start(server->ftp_sessions);
918 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
919 if (ftp->client_entry == client_entry) {
920 silc_dlist_del(server->ftp_sessions, ftp);
921 silc_free(ftp->filepath);