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 void silc_servers_reconnect_init(void);
47 void silc_servers_reconnect_deinit(void);
49 static void silc_send_channel(SILC_SERVER_REC *server,
50 char *channel, char *msg)
52 SILC_CHANNEL_REC *rec;
54 rec = silc_channel_find(server, channel);
55 if (rec == NULL || rec->entry == NULL)
58 silc_client_send_channel_message(silc_client, server->conn, rec->entry,
59 NULL, 0, msg, strlen(msg), TRUE);
65 SILC_SERVER_REC *server;
68 /* Callback function that sends the private message if the client was
69 resolved from the server. */
71 static void silc_send_msg_clients(SilcClient client,
72 SilcClientConnection conn,
73 SilcClientEntry *clients,
74 SilcUInt32 clients_count,
77 PRIVMSG_REC *rec = context;
78 SILC_SERVER_REC *server = rec->server;
79 SilcClientEntry target;
80 char *nickname = NULL;
83 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
84 "%s: There is no such client", rec->nick);
86 if (clients_count > 1) {
87 silc_parse_userfqdn(rec->nick, &nickname, NULL);
89 /* Find the correct one. The rec->nick might be a formatted nick
90 so this will find the correct one. */
91 clients = silc_client_get_clients_local(silc_client, server->conn,
95 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
96 "%s: There is no such client", rec->nick);
105 /* Still check for exact math for nickname, this compares the
106 real (formatted) nickname and the nick (maybe formatted) that
107 use gave. This is to assure that `nick' does not match
109 if (strcasecmp(rec->nick, clients[0]->nickname)) {
110 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
111 "%s: There is no such client", rec->nick);
115 /* Send the private message */
116 silc_client_send_private_message(client, conn, target, 0,
117 rec->msg, strlen(rec->msg),
127 static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg)
130 SilcClientEntry *clients;
131 SilcUInt32 clients_count;
132 char *nickname = NULL;
134 if (!silc_parse_userfqdn(nick, &nickname, NULL)) {
135 printformat_module("fe-common/silc", server, NULL,
136 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
140 /* Find client entry */
141 clients = silc_client_get_clients_local(silc_client, server->conn,
142 nickname, nick, &clients_count);
144 rec = g_new0(PRIVMSG_REC, 1);
145 rec->nick = g_strdup(nick);
146 rec->msg = g_strdup(msg);
147 rec->server = server;
149 /* Could not find client with that nick, resolve it from server. */
150 silc_client_get_clients(silc_client, server->conn,
151 nickname, NULL, silc_send_msg_clients, rec);
156 /* Send the private message directly */
158 silc_client_send_private_message(silc_client, server->conn,
159 clients[0], 0, msg, strlen(msg), TRUE);
162 static int isnickflag_func(char flag)
164 return flag == '@' || flag == '+';
167 static int ischannel_func(SERVER_REC *server, const char *data)
172 const char *get_nick_flags(void)
177 static void send_message(SILC_SERVER_REC *server, char *target,
178 char *msg, int target_type)
180 g_return_if_fail(server != NULL);
181 g_return_if_fail(target != NULL);
182 g_return_if_fail(msg != NULL);
184 if (target_type == SEND_TARGET_CHANNEL)
185 silc_send_channel(server, target, msg);
187 silc_send_msg(server, target, msg);
190 static void sig_connected(SILC_SERVER_REC *server)
192 SilcClientConnection conn;
195 if (!IS_SILC_SERVER(server))
198 conn = silc_client_add_connection(silc_client,
199 server->connrec->address,
200 server->connrec->port,
204 fd = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
205 silc_client_start_key_exchange(silc_client, conn, fd);
207 server->ftp_sessions = silc_dlist_init();
208 server->isnickflag = isnickflag_func;
209 server->ischannel = ischannel_func;
210 server->get_nick_flags = get_nick_flags;
211 server->send_message = (void *) send_message;
214 static void sig_disconnected(SILC_SERVER_REC *server)
216 if (!IS_SILC_SERVER(server))
219 silc_dlist_uninit(server->ftp_sessions);
221 if (server->conn && server->conn->sock != NULL) {
222 silc_client_close_connection(silc_client, NULL, server->conn);
224 /* SILC closes the handle */
225 g_io_channel_unref(net_sendbuffer_handle(server->handle));
226 net_sendbuffer_destroy(server->handle, FALSE);
227 server->handle = NULL;
231 SILC_SERVER_REC *silc_server_connect(SILC_SERVER_CONNECT_REC *conn)
233 SILC_SERVER_REC *server;
235 g_return_val_if_fail(IS_SILC_SERVER_CONNECT(conn), NULL);
236 if (conn->address == NULL || *conn->address == '\0')
238 if (conn->nick == NULL || *conn->nick == '\0') {
239 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
240 "Cannot connect: nickname is not set");
244 server = g_new0(SILC_SERVER_REC, 1);
245 server->chat_type = SILC_PROTOCOL;
246 server->connrec = conn;
247 if (server->connrec->port <= 0)
248 server->connrec->port = 706;
250 server_connect_ref(SERVER_CONNECT(conn));
252 if (!server_start_connect((SERVER_REC *) server)) {
253 server_connect_unref(SERVER_CONNECT(conn));
261 /* Return a string of all channels in server in server->channels_join()
264 char *silc_server_get_channels(SILC_SERVER_REC *server)
270 g_return_val_if_fail(server != NULL, FALSE);
272 chans = g_string_new(NULL);
273 for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
274 CHANNEL_REC *channel = tmp->data;
276 g_string_sprintfa(chans, "%s,", channel->name);
280 g_string_truncate(chans, chans->len-1);
283 g_string_free(chans, FALSE);
288 /* Syntaxes of all SILC commands for HELP files (the help file generation
289 will snoop these from here). */
291 /* SYNTAX: BAN <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
292 /* SYNTAX: CMODE <channel> +|-<modes> [{ <arguments>}] */
293 /* SYNTAX: CUMODE <channel> +|-<modes> <nickname>[@<hostname>] [-pubkey|<passwd>] */
294 /* SYNTAX: GETKEY <nickname or server name> */
295 /* SYNTAX: INVITE <channel> [<nickname>[@hostname>] */
296 /* SYNTAX: INVITE <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
297 /* SYNTAX: KEY MSG <nickname> set|unset|list|agreement|negotiate [<arguments>] */
298 /* SYNTAX: KEY CHANNEL <channel> set|unset|list [<arguments>] */
299 /* SYNTAX: KICK <channel> <nickname>[@<hostname>] [<comment>] */
300 /* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] */
301 /* SYNTAX: OPER <username> [-pubkey] */
302 /* SYNTAX: SILCOPER <username> [-pubkey] */
303 /* SYNTAX: TOPIC <channel> [<topic>] */
304 /* SYNTAX: UMODE +|-<modes> */
305 /* SYNTAX: WHOIS <nickname>[@<hostname>] [<count>] */
306 /* SYNTAX: WHOWAS <nickname>[@<hostname>] [<count>] */
307 /* SYNTAX: CLOSE <server> [<port>] */
308 /* SYNTAX: SHUTDOWN */
309 /* SYNTAX: MOTD [<server>] */
310 /* SYNTAX: LIST [<channel>] */
311 /* SYNTAX: ME <message> */
312 /* SYNTAX: ACTION <channel> <message> */
313 /* SYNTAX: AWAY [<message>] */
314 /* SYNTAX: INFO [<server>] */
315 /* SYNTAX: NICK <nickname> */
316 /* SYNTAX: NOTICE <message> */
317 /* SYNTAX: PART [<channel>] */
319 /* SYNTAX: SCONNECT <server> [<port>] */
320 /* SYNTAX: USERS <channel> */
321 /* SYNTAX: FILE SEND <filepath> <nickname> [<local IP> [<local port>]] */
322 /* SYNTAX: FILE RECEIVE [<nickname>] */
323 /* SYNTAX: FILE CLOSE [<nickname>] */
325 /* SYNTAX: JOIN <channel> [<passphrase>] [-cipher <cipher>] [-hmac <hmac>] [-founder <-pubkey|passwd>] */
327 void silc_command_exec(SILC_SERVER_REC *server,
328 const char *command, const char *args)
331 unsigned char **argv;
332 SilcUInt32 *argv_lens, *argv_types;
334 SilcClientCommand cmd;
335 SilcClientCommandContext ctx;
337 g_return_if_fail(server != NULL);
339 tmpcmd = g_strdup(command);
341 cmd = silc_client_command_find(silc_client, tmpcmd);
346 /* Now parse all arguments */
347 data = g_strconcat(command, " ", args, NULL);
348 silc_parse_command_line(data, &argv, &argv_lens,
349 &argv_types, &argc, cmd->max_args);
352 /* Allocate command context. This and its internals must be free'd
353 by the command routine receiving it. */
354 ctx = silc_client_command_alloc();
355 ctx->client = silc_client;
356 ctx->conn = server->conn;
360 ctx->argv_lens = argv_lens;
361 ctx->argv_types = argv_types;
363 /* Execute command */
364 silc_client_command_call(cmd, ctx);
367 /* Generic command function to call any SILC command directly. */
369 static void command_self(const char *data, SILC_SERVER_REC *server,
372 if (!IS_SILC_SERVER(server) || !server->connected) {
373 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
377 if (IS_SILC_CHANNEL(item)) {
378 SILC_CHANNEL_REC *chanrec;
379 chanrec = silc_channel_find(server, item->name);
381 server->conn->current_channel = chanrec->entry;
384 silc_command_exec(server, current_command, data);
388 /* SCONNECT command. Calls actually SILC's CONNECT command since Irssi
389 has CONNECT command for other purposes. */
391 static void command_sconnect(const char *data, SILC_SERVER_REC *server)
393 if (!IS_SILC_SERVER(server) || !server->connected) {
394 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
398 silc_command_exec(server, "CONNECT", data);
404 SILC_TASK_CALLBACK(silc_client_file_close_later)
406 FtpSession ftp = (FtpSession)context;
408 SILC_LOG_DEBUG(("Start"));
410 silc_client_file_close(silc_client, ftp->conn, ftp->session_id);
411 silc_free(ftp->filepath);
415 static void silc_client_file_monitor(SilcClient client,
416 SilcClientConnection conn,
417 SilcClientMonitorStatus status,
418 SilcClientFileError error,
421 SilcClientEntry client_entry,
422 SilcUInt32 session_id,
423 const char *filepath,
426 SILC_SERVER_REC *server = (SILC_SERVER_REC *)context;
430 snprintf(fsize, sizeof(fsize) - 1, "%llu", ((filesize + 1023) / 1024));
432 silc_dlist_start(server->ftp_sessions);
433 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
434 if (ftp->session_id == session_id) {
435 if (!ftp->filepath && filepath)
436 ftp->filepath = strdup(filepath);
441 if (ftp == SILC_LIST_END)
444 if (status == SILC_CLIENT_FILE_MONITOR_ERROR) {
445 if (error == SILC_CLIENT_FILE_NO_SUCH_FILE)
446 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
447 SILCTXT_FILE_ERROR_NO_SUCH_FILE,
448 client_entry->nickname,
449 filepath ? filepath : "[N/A]");
450 else if (error == SILC_CLIENT_FILE_PERMISSION_DENIED)
451 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
452 SILCTXT_FILE_ERROR_PERMISSION_DENIED,
453 client_entry->nickname);
455 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
456 SILCTXT_FILE_ERROR, client_entry->nickname);
457 silc_schedule_task_add(silc_client->schedule, 0,
458 silc_client_file_close_later, ftp,
459 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
460 if (ftp == server->current_session)
461 server->current_session = NULL;
462 silc_dlist_del(server->ftp_sessions, ftp);
465 if (status == SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT) {
466 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
467 SILCTXT_FILE_KEY_EXCHANGE, client_entry->nickname);
470 /* Save some transmission data */
471 if (offset && filesize) {
472 unsigned long delta = time(NULL) - ftp->starttime;
474 ftp->percent = ((double)offset / (double)filesize) * (double)100.0;
476 ftp->kps = (double)((offset / (double)delta) + 1023) / (double)1024;
478 ftp->kps = (double)(offset + 1023) / (double)1024;
479 ftp->offset = offset;
480 ftp->filesize = filesize;
483 if (status == SILC_CLIENT_FILE_MONITOR_SEND) {
485 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
486 SILCTXT_FILE_TRANSMIT, filepath, fsize,
487 client_entry->nickname);
488 ftp->starttime = time(NULL);
490 if (offset == filesize) {
491 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
492 SILCTXT_FILE_TRANSMITTED, filepath, fsize,
493 client_entry->nickname, ftp->kps);
494 silc_schedule_task_add(silc_client->schedule, 0,
495 silc_client_file_close_later, ftp,
496 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
497 if (ftp == server->current_session)
498 server->current_session = NULL;
499 silc_dlist_del(server->ftp_sessions, ftp);
503 if (status == SILC_CLIENT_FILE_MONITOR_RECEIVE) {
505 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
506 SILCTXT_FILE_RECEIVE, filepath, fsize,
507 client_entry->nickname);
508 ftp->starttime = time(NULL);
511 if (offset == filesize) {
512 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
513 SILCTXT_FILE_RECEIVED, filepath, fsize,
514 client_entry->nickname, ftp->kps);
515 silc_schedule_task_add(silc_client->schedule, 0,
516 silc_client_file_close_later, ftp,
517 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
518 if (ftp == server->current_session)
519 server->current_session = NULL;
520 silc_dlist_del(server->ftp_sessions, ftp);
526 SILC_SERVER_REC *server;
532 static void silc_client_command_file_get_clients(SilcClient client,
533 SilcClientConnection conn,
534 SilcClientEntry *clients,
535 SilcUInt32 clients_count,
538 FileGetClients internal = (FileGetClients)context;
541 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
543 silc_free(internal->data);
544 silc_free(internal->nick);
549 signal_emit("command file", 3, internal->data, internal->server,
552 silc_free(internal->data);
553 silc_free(internal->nick);
557 static void command_file(const char *data, SILC_SERVER_REC *server,
560 SilcClientConnection conn;
561 SilcClientEntry *entrys, client_entry;
562 SilcClientFileError ret;
563 SilcUInt32 entry_count;
564 char *nickname = NULL, *tmp;
565 unsigned char **argv;
567 SilcUInt32 *argv_lens, *argv_types;
570 char *local_ip = NULL;
571 SilcUInt32 local_port = 0;
572 SilcUInt32 session_id;
574 if (!server || !IS_SILC_SERVER(server) || !server->connected)
575 cmd_return_error(CMDERR_NOT_CONNECTED);
579 /* Now parse all arguments */
580 tmp = g_strconcat("FILE", " ", data, NULL);
581 silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 6);
588 if (!strcasecmp(argv[1], "send"))
590 if (!strcasecmp(argv[1], "receive"))
592 if (!strcasecmp(argv[1], "close"))
597 cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
602 cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
604 /* Parse the typed nickname. */
605 if (!silc_parse_userfqdn(argv[3], &nickname, NULL)) {
606 printformat_module("fe-common/silc", server, NULL,
607 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[3]);
611 /* Find client entry */
612 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
613 argv[3], &entry_count);
615 FileGetClients inter = silc_calloc(1, sizeof(*inter));
616 inter->server = server;
617 inter->data = strdup(data);
618 inter->nick = strdup(nickname);
620 silc_client_get_clients(silc_client, conn, nickname, argv[3],
621 silc_client_command_file_get_clients, inter);
624 client_entry = entrys[0];
630 local_port = atoi(argv[5]);
633 silc_client_file_send(silc_client, conn, silc_client_file_monitor,
634 server, local_ip, local_port,
635 client_entry, argv[2], &session_id);
636 if (ret == SILC_CLIENT_FILE_OK) {
637 ftp = silc_calloc(1, sizeof(*ftp));
638 ftp->session_id = session_id;
640 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
641 SILCTXT_FILE_SEND, client_entry->nickname,
644 ftp->client_entry = client_entry;
645 ftp->filepath = strdup(argv[2]);
648 silc_dlist_add(server->ftp_sessions, ftp);
649 server->current_session = ftp;
651 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
652 printformat_module("fe-common/silc", server, NULL,
653 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
654 client_entry->nickname);
655 if (ret == SILC_CLIENT_FILE_NO_SUCH_FILE)
656 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
657 SILCTXT_FILE_ERROR_NO_SUCH_FILE,
658 client_entry->nickname, argv[2]);
664 /* Parse the typed nickname. */
666 if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
667 printformat_module("fe-common/silc", server, NULL,
668 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
672 /* Find client entry */
673 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
674 argv[2], &entry_count);
676 FileGetClients inter = silc_calloc(1, sizeof(*inter));
677 inter->server = server;
678 inter->data = strdup(data);
679 inter->nick = strdup(nickname);
681 silc_client_get_clients(silc_client, conn, nickname, argv[2],
682 silc_client_command_file_get_clients, inter);
685 client_entry = entrys[0];
688 if (!server->current_session) {
689 printformat_module("fe-common/silc", server, NULL,
690 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
694 ret = silc_client_file_receive(silc_client, conn,
695 silc_client_file_monitor, server,
696 server->current_session->session_id);
697 if (ret != SILC_CLIENT_FILE_OK) {
698 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
699 printformat_module("fe-common/silc", server, NULL,
700 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
701 server->current_session->client_entry->nickname);
703 printformat_module("fe-common/silc", server, NULL,
704 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
705 server->current_session->client_entry->nickname);
711 silc_dlist_start(server->ftp_sessions);
712 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
713 if (ftp->client_entry == client_entry && !ftp->filepath) {
714 ret = silc_client_file_receive(silc_client, conn,
715 silc_client_file_monitor, server,
717 if (ret != SILC_CLIENT_FILE_OK) {
718 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
719 printformat_module("fe-common/silc", server, NULL,
720 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
721 client_entry->nickname);
723 printformat_module("fe-common/silc", server, NULL,
724 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
725 client_entry->nickname);
731 if (ftp == SILC_LIST_END) {
732 printformat_module("fe-common/silc", server, NULL,
733 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
734 client_entry->nickname);
740 /* Parse the typed nickname. */
742 if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
743 printformat_module("fe-common/silc", server, NULL,
744 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
748 /* Find client entry */
749 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
750 argv[2], &entry_count);
752 FileGetClients inter = silc_calloc(1, sizeof(*inter));
753 inter->server = server;
754 inter->data = strdup(data);
755 inter->nick = strdup(nickname);
757 silc_client_get_clients(silc_client, conn, nickname, argv[2],
758 silc_client_command_file_get_clients, inter);
761 client_entry = entrys[0];
764 if (!server->current_session) {
765 printformat_module("fe-common/silc", server, NULL,
766 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
770 silc_client_file_close(silc_client, conn,
771 server->current_session->session_id);
772 printformat_module("fe-common/silc", server, NULL,
773 MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
774 server->current_session->client_entry->nickname,
775 server->current_session->filepath ?
776 server->current_session->filepath : "[N/A]");
777 silc_dlist_del(server->ftp_sessions, server->current_session);
778 silc_free(server->current_session->filepath);
779 silc_free(server->current_session);
780 server->current_session = NULL;
784 silc_dlist_start(server->ftp_sessions);
785 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
786 if (ftp->client_entry == client_entry) {
787 silc_client_file_close(silc_client, conn, ftp->session_id);
788 printformat_module("fe-common/silc", server, NULL,
789 MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
790 client_entry->nickname,
791 ftp->filepath ? ftp->filepath : "[N/A]");
792 if (ftp == server->current_session)
793 server->current_session = NULL;
794 silc_dlist_del(server->ftp_sessions, ftp);
795 silc_free(ftp->filepath);
801 if (ftp == SILC_LIST_END) {
802 printformat_module("fe-common/silc", server, NULL,
803 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
804 client_entry->nickname);
811 if (!silc_dlist_count(server->ftp_sessions)) {
812 printformat_module("fe-common/silc", server, NULL,
813 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
817 printformat_module("fe-common/silc", server, NULL,
818 MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_HEADER);
820 silc_dlist_start(server->ftp_sessions);
821 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
822 printformat_module("fe-common/silc", server, NULL,
823 MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_LINE,
824 ftp->client_entry->nickname,
825 ftp->send ? "send" : "receive",
826 (SilcUInt32)(ftp->offset + 1023) / 1024,
827 (SilcUInt32)(ftp->filesize + 1023) / 1024,
828 ftp->percent, ftp->kps,
829 ftp->filepath ? ftp->filepath : "[N/A]");
842 void silc_server_init(void)
844 silc_servers_reconnect_init();
846 signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
847 signal_add("server disconnected", (SIGNAL_FUNC) sig_disconnected);
848 command_bind("whois", MODULE_NAME, (SIGNAL_FUNC) command_self);
849 command_bind("whowas", MODULE_NAME, (SIGNAL_FUNC) command_self);
850 command_bind("nick", MODULE_NAME, (SIGNAL_FUNC) command_self);
851 command_bind("topic", MODULE_NAME, (SIGNAL_FUNC) command_self);
852 command_bind("cmode", MODULE_NAME, (SIGNAL_FUNC) command_self);
853 command_bind("cumode", MODULE_NAME, (SIGNAL_FUNC) command_self);
854 command_bind("users", MODULE_NAME, (SIGNAL_FUNC) command_self);
855 command_bind("list", MODULE_NAME, (SIGNAL_FUNC) command_self);
856 command_bind("ban", MODULE_NAME, (SIGNAL_FUNC) command_self);
857 command_bind("oper", MODULE_NAME, (SIGNAL_FUNC) command_self);
858 command_bind("silcoper", MODULE_NAME, (SIGNAL_FUNC) command_self);
859 command_bind("umode", MODULE_NAME, (SIGNAL_FUNC) command_self);
860 command_bind("invite", MODULE_NAME, (SIGNAL_FUNC) command_self);
861 command_bind("kill", MODULE_NAME, (SIGNAL_FUNC) command_self);
862 command_bind("kick", MODULE_NAME, (SIGNAL_FUNC) command_self);
863 command_bind("info", MODULE_NAME, (SIGNAL_FUNC) command_self);
864 command_bind("ping", MODULE_NAME, (SIGNAL_FUNC) command_self);
865 command_bind("motd", MODULE_NAME, (SIGNAL_FUNC) command_self);
866 command_bind("close", MODULE_NAME, (SIGNAL_FUNC) command_self);
867 command_bind("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
868 command_bind("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
869 command_bind("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
870 command_bind("file", MODULE_NAME, (SIGNAL_FUNC) command_file);
872 command_set_options("connect", "+silcnet");
875 void silc_server_deinit(void)
877 silc_servers_reconnect_deinit();
879 signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
880 signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
881 command_unbind("whois", (SIGNAL_FUNC) command_self);
882 command_unbind("whowas", (SIGNAL_FUNC) command_self);
883 command_unbind("nick", (SIGNAL_FUNC) command_self);
884 command_unbind("topic", (SIGNAL_FUNC) command_self);
885 command_unbind("cmode", (SIGNAL_FUNC) command_self);
886 command_unbind("cumode", (SIGNAL_FUNC) command_self);
887 command_unbind("users", (SIGNAL_FUNC) command_self);
888 command_unbind("list", (SIGNAL_FUNC) command_self);
889 command_unbind("oper", (SIGNAL_FUNC) command_self);
890 command_unbind("silcoper", (SIGNAL_FUNC) command_self);
891 command_unbind("umode", (SIGNAL_FUNC) command_self);
892 command_unbind("invite", (SIGNAL_FUNC) command_self);
893 command_unbind("kill", (SIGNAL_FUNC) command_self);
894 command_unbind("kick", (SIGNAL_FUNC) command_self);
895 command_unbind("info", (SIGNAL_FUNC) command_self);
896 command_unbind("ping", (SIGNAL_FUNC) command_self);
897 command_unbind("motd", (SIGNAL_FUNC) command_self);
898 command_unbind("ban", (SIGNAL_FUNC) command_self);
899 command_unbind("close", (SIGNAL_FUNC) command_self);
900 command_unbind("shutdown", (SIGNAL_FUNC) command_self);
901 command_unbind("getkey", (SIGNAL_FUNC) command_self);
902 command_unbind("sconnect", (SIGNAL_FUNC) command_sconnect);
903 command_unbind("file", (SIGNAL_FUNC) command_file);
906 void silc_server_free_ftp(SILC_SERVER_REC *server,
907 SilcClientEntry client_entry)
911 silc_dlist_start(server->ftp_sessions);
912 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
913 if (ftp->client_entry == client_entry) {
914 silc_dlist_del(server->ftp_sessions, ftp);
915 silc_free(ftp->filepath);