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,
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, "Unknown nick: %s", rec->nick);
85 if (clients_count > 1) {
86 silc_parse_userfqdn(rec->nick, &nickname, NULL);
88 /* Find the correct one. The rec->nick might be a formatted nick
89 so this will find the correct one. */
90 clients = silc_client_get_clients_local(silc_client, server->conn,
94 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
104 /* Send the private message */
105 silc_client_send_private_message(client, conn, target, 0,
106 rec->msg, strlen(rec->msg),
116 static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg)
119 SilcClientEntry *clients;
120 uint32 clients_count;
121 char *nickname = NULL;
123 if (!silc_parse_userfqdn(nick, &nickname, NULL)) {
124 printformat_module("fe-common/silc", server, NULL,
125 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
129 /* Find client entry */
130 clients = silc_client_get_clients_local(silc_client, server->conn,
131 nickname, nick, &clients_count);
133 rec = g_new0(PRIVMSG_REC, 1);
134 rec->nick = g_strdup(nick);
135 rec->msg = g_strdup(msg);
136 rec->server = server;
138 /* Could not find client with that nick, resolve it from server. */
139 silc_client_get_clients(silc_client, server->conn,
140 nickname, NULL, silc_send_msg_clients, rec);
145 /* Send the private message directly */
147 silc_client_send_private_message(silc_client, server->conn,
148 clients[0], 0, msg, strlen(msg), TRUE);
151 static int isnickflag_func(char flag)
153 return flag == '@' || flag == '+';
156 static int ischannel_func(const char *data)
161 const char *get_nick_flags(void)
166 static void send_message(SILC_SERVER_REC *server, char *target, char *msg)
168 g_return_if_fail(server != NULL);
169 g_return_if_fail(target != NULL);
170 g_return_if_fail(msg != NULL);
173 silc_send_channel(server, target, msg);
175 silc_send_msg(server, target, msg);
178 static void sig_connected(SILC_SERVER_REC *server)
180 SilcClientConnection conn;
183 if (!IS_SILC_SERVER(server))
186 conn = silc_client_add_connection(silc_client,
187 server->connrec->address,
188 server->connrec->port,
192 fd = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
193 if (!silc_client_start_key_exchange(silc_client, conn, fd)) {
194 /* some internal error occured */
195 server_disconnect(SERVER(server));
200 server->isnickflag = isnickflag_func;
201 server->ischannel = ischannel_func;
202 server->get_nick_flags = get_nick_flags;
203 server->send_message = (void *) send_message;
206 static void sig_disconnected(SILC_SERVER_REC *server)
208 if (!IS_SILC_SERVER(server))
211 if (server->conn && server->conn->sock != NULL) {
212 silc_client_close_connection(silc_client, NULL, server->conn);
214 /* SILC closes the handle */
215 g_io_channel_unref(net_sendbuffer_handle(server->handle));
216 net_sendbuffer_destroy(server->handle, FALSE);
217 server->handle = NULL;
221 SILC_SERVER_REC *silc_server_connect(SILC_SERVER_CONNECT_REC *conn)
223 SILC_SERVER_REC *server;
225 g_return_val_if_fail(IS_SILC_SERVER_CONNECT(conn), NULL);
226 if (conn->address == NULL || *conn->address == '\0')
228 if (conn->nick == NULL || *conn->nick == '\0') {
229 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
230 "Cannot connect: nickname is not set");
234 server = g_new0(SILC_SERVER_REC, 1);
235 server->chat_type = SILC_PROTOCOL;
236 server->connrec = conn;
237 if (server->connrec->port <= 0)
238 server->connrec->port = 706;
240 if (!server_start_connect((SERVER_REC *) server)) {
241 server_connect_free(SERVER_CONNECT(conn));
246 server->ftp_sessions = silc_dlist_init();
251 /* Return a string of all channels in server in server->channels_join()
254 char *silc_server_get_channels(SILC_SERVER_REC *server)
260 g_return_val_if_fail(server != NULL, FALSE);
262 chans = g_string_new(NULL);
263 for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
264 CHANNEL_REC *channel = tmp->data;
266 g_string_sprintfa(chans, "%s,", channel->name);
270 g_string_truncate(chans, chans->len-1);
273 g_string_free(chans, FALSE);
278 /* Syntaxes of all SILC commands for HELP files (the help file generation
279 will snoop these from here). */
281 /* SYNTAX: BAN <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
282 /* SYNTAX: CMODE <channel> +|-<modes> [{ <arguments>}] */
283 /* SYNTAX: CUMODE <channel> +|-<modes> <nickname>[@<hostname>] [-pubkey|<passwd>] */
284 /* SYNTAX: GETKEY <nickname or server name> */
285 /* SYNTAX: INVITE <channel> [<nickname>[@hostname>] */
286 /* SYNTAX: INVITE <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
287 /* SYNTAX: KEY MSG <nickname> set|unset|list|agreement|negotiate [<arguments>] */
288 /* SYNTAX: KEY CHANNEL <channel> set|unset|list|agreement|negotiate [<arguments>] */
289 /* SYNTAX: KICK <channel> <nickname>[@<hostname>] [<comment>] */
290 /* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] */
291 /* SYNTAX: OPER <username> [-pubkey] */
292 /* SYNTAX: SILCOPER <username> [-pubkey] */
293 /* SYNTAX: TOPIC <channel> [<topic>] */
294 /* SYNTAX: UMODE +|-<modes> */
295 /* SYNTAX: WHOIS <nickname>[@<hostname>] [<count>] */
296 /* SYNTAX: WHOWAS <nickname>[@<hostname>] [<count>] */
297 /* SYNTAX: CLOSE <server> [<port>] */
298 /* SYNTAX: SHUTDOWN */
299 /* SYNTAX: MOTD [<server>] */
300 /* SYNTAX: LIST [<channel>] */
301 /* SYNTAX: ME <message> */
302 /* SYNTAX: ACTION <channel> <message> */
303 /* SYNTAX: AWAY [<message>] */
304 /* SYNTAX: INFO [<server>] */
305 /* SYNTAX: NICK <nickname> */
306 /* SYNTAX: NOTICE <message> */
307 /* SYNTAX: PART [<channel>] */
309 /* SYNTAX: SCONNECT <server> [<port>] */
310 /* SYNTAX: USERS <channel> */
311 /* SYNTAX: FILE SEND <filepath> <nickname> [<local IP> [<local port>]] */
312 /* SYNTAX: FILE RECEIVE [<nickname>] */
313 /* SYNTAX: FILE CLOSE [<nickname>] */
316 void silc_command_exec(SILC_SERVER_REC *server,
317 const char *command, const char *args)
320 unsigned char **argv;
321 uint32 *argv_lens, *argv_types;
323 SilcClientCommand *cmd;
324 SilcClientCommandContext ctx;
326 g_return_if_fail(server != NULL);
328 tmpcmd = g_strdup(command);
330 cmd = silc_client_command_find(tmpcmd);
335 /* Now parse all arguments */
336 data = g_strconcat(command, " ", args, NULL);
337 silc_parse_command_line(data, &argv, &argv_lens,
338 &argv_types, &argc, cmd->max_args);
341 /* Allocate command context. This and its internals must be free'd
342 by the command routine receiving it. */
343 ctx = silc_client_command_alloc();
344 ctx->client = silc_client;
345 ctx->conn = server->conn;
349 ctx->argv_lens = argv_lens;
350 ctx->argv_types = argv_types;
352 /* Execute command */
353 (*cmd->cb)(ctx, NULL);
356 /* Generic command function to call any SILC command directly. */
358 static void command_self(const char *data, SILC_SERVER_REC *server,
361 if (!IS_SILC_SERVER(server) || !server->connected) {
362 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
366 if (IS_SILC_CHANNEL(item)) {
367 SILC_CHANNEL_REC *chanrec;
368 chanrec = silc_channel_find(server, item->name);
370 server->conn->current_channel = chanrec->entry;
373 silc_command_exec(server, current_command, data);
377 /* SCONNECT command. Calls actually SILC's CONNECT command since Irssi
378 has CONNECT command for other purposes. */
380 static void command_sconnect(const char *data, SILC_SERVER_REC *server)
382 if (!IS_SILC_SERVER(server) || !server->connected) {
383 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
387 silc_command_exec(server, "CONNECT", data);
391 static void event_text(const char *line, SILC_SERVER_REC *server,
396 g_return_if_fail(line != NULL);
398 if (!IS_SILC_ITEM(item))
401 str = g_strdup_printf("%s %s", item->name, line);
402 signal_emit("command msg", 3, str, server, item);
410 SILC_TASK_CALLBACK(silc_client_file_close_later)
412 FtpSession ftp = (FtpSession)context;
414 SILC_LOG_DEBUG(("Start"));
416 silc_client_file_close(silc_client, ftp->conn, ftp->session_id);
417 silc_free(ftp->filepath);
421 static void silc_client_file_monitor(SilcClient client,
422 SilcClientConnection conn,
423 SilcClientMonitorStatus status,
424 SilcClientFileError error,
427 SilcClientEntry client_entry,
429 const char *filepath,
432 SILC_SERVER_REC *server = (SILC_SERVER_REC *)context;
436 snprintf(fsize, sizeof(fsize) - 1, "%llu", ((filesize + 1023) / 1024));
438 silc_dlist_start(server->ftp_sessions);
439 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
440 if (ftp->session_id == session_id) {
441 if (!ftp->filepath && filepath)
442 ftp->filepath = strdup(filepath);
447 if (ftp == SILC_LIST_END)
450 if (status == SILC_CLIENT_FILE_MONITOR_ERROR) {
451 if (error == SILC_CLIENT_FILE_NO_SUCH_FILE)
452 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
453 SILCTXT_FILE_ERROR_NO_SUCH_FILE,
454 client_entry->nickname,
455 filepath ? filepath : "[N/A]");
456 else if (error == SILC_CLIENT_FILE_PERMISSION_DENIED)
457 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
458 SILCTXT_FILE_ERROR_PERMISSION_DENIED,
459 client_entry->nickname);
461 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
462 SILCTXT_FILE_ERROR, client_entry->nickname);
463 silc_schedule_task_add(silc_client->schedule, 0,
464 silc_client_file_close_later, ftp,
465 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
466 if (ftp == server->current_session)
467 server->current_session = NULL;
468 silc_dlist_del(server->ftp_sessions, ftp);
471 if (status == SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT) {
472 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
473 SILCTXT_FILE_KEY_EXCHANGE, client_entry->nickname);
476 /* Save some transmission data */
477 if (offset && filesize) {
478 unsigned long delta = time(NULL) - ftp->starttime;
480 ftp->percent = ((double)offset / (double)filesize) * (double)100.0;
482 ftp->kps = (double)((offset / (double)delta) + 1023) / (double)1024;
484 ftp->kps = (double)(offset + 1023) / (double)1024;
485 ftp->offset = offset;
486 ftp->filesize = filesize;
489 if (status == SILC_CLIENT_FILE_MONITOR_SEND) {
491 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
492 SILCTXT_FILE_TRANSMIT, filepath, fsize,
493 client_entry->nickname);
494 ftp->starttime = time(NULL);
496 if (offset == filesize) {
497 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
498 SILCTXT_FILE_TRANSMITTED, filepath, fsize,
499 client_entry->nickname, ftp->kps);
500 silc_schedule_task_add(silc_client->schedule, 0,
501 silc_client_file_close_later, ftp,
502 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
503 if (ftp == server->current_session)
504 server->current_session = NULL;
505 silc_dlist_del(server->ftp_sessions, ftp);
509 if (status == SILC_CLIENT_FILE_MONITOR_RECEIVE) {
511 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
512 SILCTXT_FILE_RECEIVE, filepath, fsize,
513 client_entry->nickname);
514 ftp->starttime = time(NULL);
517 if (offset == filesize) {
518 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
519 SILCTXT_FILE_RECEIVED, filepath, fsize,
520 client_entry->nickname, ftp->kps);
521 silc_schedule_task_add(silc_client->schedule, 0,
522 silc_client_file_close_later, ftp,
523 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
524 if (ftp == server->current_session)
525 server->current_session = NULL;
526 silc_dlist_del(server->ftp_sessions, ftp);
532 SILC_SERVER_REC *server;
538 static void silc_client_command_file_get_clients(SilcClient client,
539 SilcClientConnection conn,
540 SilcClientEntry *clients,
541 uint32 clients_count,
544 FileGetClients internal = (FileGetClients)context;
547 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
549 silc_free(internal->data);
550 silc_free(internal->nick);
555 signal_emit("command file", 3, internal->data, internal->server,
558 silc_free(internal->data);
559 silc_free(internal->nick);
563 static void command_file(const char *data, SILC_SERVER_REC *server,
566 SilcClientConnection conn;
567 SilcClientEntry *entrys, client_entry;
568 SilcClientFileError ret;
570 char *nickname = NULL, *tmp;
571 unsigned char **argv;
573 uint32 *argv_lens, *argv_types;
576 char *local_ip = NULL;
577 uint32 local_port = 0;
579 if (!server || !IS_SILC_SERVER(server) || !server->connected)
580 cmd_return_error(CMDERR_NOT_CONNECTED);
584 /* Now parse all arguments */
585 tmp = g_strconcat("FILE", " ", data, NULL);
586 silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 6);
593 if (!strcasecmp(argv[1], "send"))
595 if (!strcasecmp(argv[1], "receive"))
597 if (!strcasecmp(argv[1], "close"))
602 cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
607 cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
609 /* Parse the typed nickname. */
610 if (!silc_parse_userfqdn(argv[3], &nickname, NULL)) {
611 printformat_module("fe-common/silc", server, NULL,
612 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[3]);
616 /* Find client entry */
617 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
618 argv[3], &entry_count);
620 FileGetClients inter = silc_calloc(1, sizeof(*inter));
621 inter->server = server;
622 inter->data = strdup(data);
623 inter->nick = strdup(nickname);
625 silc_client_get_clients(silc_client, conn, nickname, argv[3],
626 silc_client_command_file_get_clients, inter);
629 client_entry = entrys[0];
635 local_port = atoi(argv[5]);
637 ftp = silc_calloc(1, sizeof(*ftp));
639 silc_client_file_send(silc_client, conn, silc_client_file_monitor,
640 server, local_ip, local_port,
641 client_entry, argv[2]);
643 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
644 SILCTXT_FILE_SEND, client_entry->nickname,
647 ftp->client_entry = client_entry;
648 ftp->filepath = strdup(argv[2]);
651 silc_dlist_add(server->ftp_sessions, ftp);
652 server->current_session = ftp;
657 /* Parse the typed nickname. */
659 if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
660 printformat_module("fe-common/silc", server, NULL,
661 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
665 /* Find client entry */
666 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
667 argv[2], &entry_count);
669 FileGetClients inter = silc_calloc(1, sizeof(*inter));
670 inter->server = server;
671 inter->data = strdup(data);
672 inter->nick = strdup(nickname);
674 silc_client_get_clients(silc_client, conn, nickname, argv[2],
675 silc_client_command_file_get_clients, inter);
678 client_entry = entrys[0];
681 if (!server->current_session) {
682 printformat_module("fe-common/silc", server, NULL,
683 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
687 ret = silc_client_file_receive(silc_client, conn,
688 silc_client_file_monitor, server,
689 server->current_session->session_id);
690 if (ret != SILC_CLIENT_FILE_OK) {
691 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
692 printformat_module("fe-common/silc", server, NULL,
693 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
694 server->current_session->client_entry->nickname);
696 printformat_module("fe-common/silc", server, NULL,
697 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
698 server->current_session->client_entry->nickname);
704 silc_dlist_start(server->ftp_sessions);
705 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
706 if (ftp->client_entry == client_entry && !ftp->filepath) {
707 ret = silc_client_file_receive(silc_client, conn,
708 silc_client_file_monitor, server,
710 if (ret != SILC_CLIENT_FILE_OK) {
711 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
712 printformat_module("fe-common/silc", server, NULL,
713 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
714 client_entry->nickname);
716 printformat_module("fe-common/silc", server, NULL,
717 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
718 client_entry->nickname);
724 if (ftp == SILC_LIST_END) {
725 printformat_module("fe-common/silc", server, NULL,
726 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
727 client_entry->nickname);
733 /* Parse the typed nickname. */
735 if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
736 printformat_module("fe-common/silc", server, NULL,
737 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
741 /* Find client entry */
742 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
743 argv[2], &entry_count);
745 FileGetClients inter = silc_calloc(1, sizeof(*inter));
746 inter->server = server;
747 inter->data = strdup(data);
748 inter->nick = strdup(nickname);
750 silc_client_get_clients(silc_client, conn, nickname, argv[2],
751 silc_client_command_file_get_clients, inter);
754 client_entry = entrys[0];
757 if (!server->current_session) {
758 printformat_module("fe-common/silc", server, NULL,
759 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
763 silc_client_file_close(silc_client, conn,
764 server->current_session->session_id);
765 printformat_module("fe-common/silc", server, NULL,
766 MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
767 server->current_session->client_entry->nickname,
768 server->current_session->filepath ?
769 server->current_session->filepath : "[N/A]");
770 silc_dlist_del(server->ftp_sessions, server->current_session);
771 silc_free(server->current_session->filepath);
772 silc_free(server->current_session);
773 server->current_session = NULL;
777 silc_dlist_start(server->ftp_sessions);
778 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
779 if (ftp->client_entry == client_entry) {
780 silc_client_file_close(silc_client, conn, ftp->session_id);
781 printformat_module("fe-common/silc", server, NULL,
782 MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
783 client_entry->nickname,
784 ftp->filepath ? ftp->filepath : "[N/A]");
785 if (ftp == server->current_session)
786 server->current_session = NULL;
787 silc_dlist_del(server->ftp_sessions, ftp);
788 silc_free(ftp->filepath);
794 if (ftp == SILC_LIST_END) {
795 printformat_module("fe-common/silc", server, NULL,
796 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
797 client_entry->nickname);
804 if (!silc_dlist_count(server->ftp_sessions)) {
805 printformat_module("fe-common/silc", server, NULL,
806 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
810 printformat_module("fe-common/silc", server, NULL,
811 MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_HEADER);
813 silc_dlist_start(server->ftp_sessions);
814 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
815 printformat_module("fe-common/silc", server, NULL,
816 MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_LINE,
817 ftp->client_entry->nickname,
818 ftp->send ? "send" : "receive",
819 (uint32)(ftp->offset + 1023) / 1024,
820 (uint32)(ftp->filesize + 1023) / 1024,
821 ftp->percent, ftp->kps,
822 ftp->filepath ? ftp->filepath : "[N/A]");
835 void silc_server_init(void)
837 silc_servers_reconnect_init();
839 signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
840 signal_add("server disconnected", (SIGNAL_FUNC) sig_disconnected);
841 signal_add("send text", (SIGNAL_FUNC) event_text);
842 command_bind("whois", MODULE_NAME, (SIGNAL_FUNC) command_self);
843 command_bind("whowas", MODULE_NAME, (SIGNAL_FUNC) command_self);
844 command_bind("nick", MODULE_NAME, (SIGNAL_FUNC) command_self);
845 command_bind("topic", MODULE_NAME, (SIGNAL_FUNC) command_self);
846 command_bind("cmode", MODULE_NAME, (SIGNAL_FUNC) command_self);
847 command_bind("cumode", MODULE_NAME, (SIGNAL_FUNC) command_self);
848 command_bind("users", MODULE_NAME, (SIGNAL_FUNC) command_self);
849 command_bind("list", MODULE_NAME, (SIGNAL_FUNC) command_self);
850 command_bind("ban", MODULE_NAME, (SIGNAL_FUNC) command_self);
851 command_bind("oper", MODULE_NAME, (SIGNAL_FUNC) command_self);
852 command_bind("silcoper", MODULE_NAME, (SIGNAL_FUNC) command_self);
853 command_bind("umode", MODULE_NAME, (SIGNAL_FUNC) command_self);
854 command_bind("invite", MODULE_NAME, (SIGNAL_FUNC) command_self);
855 command_bind("kill", MODULE_NAME, (SIGNAL_FUNC) command_self);
856 command_bind("kick", MODULE_NAME, (SIGNAL_FUNC) command_self);
857 command_bind("info", MODULE_NAME, (SIGNAL_FUNC) command_self);
858 command_bind("ping", MODULE_NAME, (SIGNAL_FUNC) command_self);
859 command_bind("motd", MODULE_NAME, (SIGNAL_FUNC) command_self);
860 command_bind("close", MODULE_NAME, (SIGNAL_FUNC) command_self);
861 command_bind("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
862 command_bind("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
863 command_bind("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
864 command_bind("file", MODULE_NAME, (SIGNAL_FUNC) command_file);
866 command_set_options("connect", "+silcnet");
869 void silc_server_deinit(void)
871 silc_servers_reconnect_deinit();
873 signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
874 signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
875 signal_remove("send text", (SIGNAL_FUNC) event_text);
876 command_unbind("whois", (SIGNAL_FUNC) command_self);
877 command_unbind("whowas", (SIGNAL_FUNC) command_self);
878 command_unbind("nick", (SIGNAL_FUNC) command_self);
879 command_unbind("topic", (SIGNAL_FUNC) command_self);
880 command_unbind("cmode", (SIGNAL_FUNC) command_self);
881 command_unbind("cumode", (SIGNAL_FUNC) command_self);
882 command_unbind("users", (SIGNAL_FUNC) command_self);
883 command_unbind("list", (SIGNAL_FUNC) command_self);
884 command_unbind("oper", (SIGNAL_FUNC) command_self);
885 command_unbind("silcoper", (SIGNAL_FUNC) command_self);
886 command_unbind("umode", (SIGNAL_FUNC) command_self);
887 command_unbind("invite", (SIGNAL_FUNC) command_self);
888 command_unbind("kill", (SIGNAL_FUNC) command_self);
889 command_unbind("kick", (SIGNAL_FUNC) command_self);
890 command_unbind("info", (SIGNAL_FUNC) command_self);
891 command_unbind("ping", (SIGNAL_FUNC) command_self);
892 command_unbind("motd", (SIGNAL_FUNC) command_self);
893 command_unbind("ban", (SIGNAL_FUNC) command_self);
894 command_unbind("close", (SIGNAL_FUNC) command_self);
895 command_unbind("shutdown", (SIGNAL_FUNC) command_self);
896 command_unbind("getkey", (SIGNAL_FUNC) command_self);
897 command_unbind("sconnect", (SIGNAL_FUNC) command_sconnect);
898 command_unbind("file", (SIGNAL_FUNC) command_file);
901 void silc_server_free_ftp(SILC_SERVER_REC *server,
902 SilcClientEntry client_entry)
906 silc_dlist_start(server->ftp_sessions);
907 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
908 if (ftp->client_entry == client_entry) {
909 silc_dlist_del(server->ftp_sessions, ftp);
910 silc_free(ftp->filepath);