09c6532d48688649aa766a6aae81211870e28318
[silc.git] / apps / irssi / src / silc / core / silc-servers.c
1 /*
2   silc-server.c : irssi
3
4   Copyright (C) 2000 - 2006 Timo Sirainen
5                             Pekka Riikonen <priikone@silcnet.org>
6
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.
11
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.
16
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
20 */
21
22 #include "module.h"
23
24 #include "net-nonblock.h"
25 #include "net-sendbuffer.h"
26 #include "signals.h"
27 #include "servers.h"
28 #include "commands.h"
29 #include "levels.h"
30 #include "modules.h"
31 #include "rawlog.h"
32 #include "misc.h"
33 #include "settings.h"
34
35 #include "servers-setup.h"
36
37 #include "client_ops.h"
38 #include "silc-servers.h"
39 #include "silc-channels.h"
40 #include "silc-queries.h"
41 #include "silc-nicklist.h"
42 #include "silc-cmdqueue.h"
43 #include "window-item-def.h"
44
45 #include "fe-common/core/printtext.h"
46 #include "fe-common/core/fe-channels.h"
47 #include "fe-common/core/keyboard.h"
48 #include "fe-common/silc/module-formats.h"
49
50 #include "silc-commands.h"
51
52 void silc_servers_reconnect_init(void);
53 void silc_servers_reconnect_deinit(void);
54
55 int silc_send_channel(SILC_SERVER_REC *server,
56                       char *channel, char *msg,
57                       SilcMessageFlags flags)
58 {
59   SILC_CHANNEL_REC *rec;
60
61   rec = silc_channel_find(server, channel);
62   if (rec == NULL || rec->entry == NULL) {
63     cmd_return_error_value(CMDERR_NOT_JOINED, FALSE);
64   }
65
66   return silc_client_send_channel_message(silc_client, server->conn,
67                                           rec->entry, NULL, flags, sha1hash,
68                                           msg, strlen(msg));
69 }
70
71 typedef struct {
72   char *nick;
73   char *msg;
74   int len;
75   SilcMessageFlags flags;
76   SILC_SERVER_REC *server;
77 } PRIVMSG_REC;
78
79 /* Callback function that sends the private message if the client was
80    resolved from the server. */
81
82 static void silc_send_msg_clients(SilcClient client,
83                                   SilcClientConnection conn,
84                                   SilcStatus status,
85                                   SilcDList clients,
86                                   void *context)
87 {
88   PRIVMSG_REC *rec = context;
89   SILC_SERVER_REC *server = rec->server;
90   SilcClientEntry target;
91   char nickname[128 + 1];
92   SilcDList lclients = NULL;
93
94   if (!clients) {
95     printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
96               "%s: There is no such client", rec->nick);
97   } else {
98     if (silc_dlist_count(clients) > 1) {
99       silc_parse_userfqdn(rec->nick, nickname, sizeof(nickname), NULL, 0);
100
101       /* Find the correct one. The rec->nick might be a formatted nick
102          so this will find the correct one. */
103       clients = lclients =
104         silc_client_get_clients_local(silc_client, server->conn,
105                                       nickname, rec->nick);
106       if (!clients) {
107         printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
108                   "%s: There is no such client", rec->nick);
109         goto out;
110       }
111     }
112
113     target = silc_dlist_get(clients);
114
115     /* Still check for exact math for nickname, this compares the
116        real (formatted) nickname and the nick (maybe formatted) that
117        user gave. This is to assure that `nick' does not match
118        `nick@host'. */
119     if (!silc_utf8_strcasecmp(rec->nick, target->nickname)) {
120       printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
121                 "%s: There is no such client", rec->nick);
122       goto out;
123     }
124
125     /* Send the private message */
126     silc_client_send_private_message(client, conn, target,
127                                      rec->flags, sha1hash,
128                                      rec->msg, rec->len);
129   }
130
131  out:
132   silc_client_list_free(silc_client, server->conn, lclients);
133   g_free(rec->nick);
134   g_free(rec->msg);
135   g_free(rec);
136 }
137
138 int silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
139                   int msg_len, SilcMessageFlags flags)
140 {
141   PRIVMSG_REC *rec;
142   char nickname[128 + 1];
143   SilcDList clients;
144   SilcClientEntry target;
145   int ret;
146
147   if (!silc_parse_userfqdn(nick, nickname, sizeof(nickname), NULL, 0)) {
148     printformat_module("fe-common/silc", server, NULL,
149                        MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
150     return FALSE;
151   }
152
153   /* Find client entry */
154   clients = silc_client_get_clients_local(silc_client, server->conn,
155                                           nickname, nick);
156   if (!clients) {
157     rec = g_new0(PRIVMSG_REC, 1);
158     rec->nick = g_strdup(nick);
159     rec->msg = g_strdup(msg);
160     rec->server = server;
161     rec->flags = flags;
162     rec->len = msg_len;
163
164     /* Could not find client with that nick, resolve it from server. */
165     silc_client_get_clients(silc_client, server->conn,
166                             nickname, NULL, silc_send_msg_clients, rec);
167     return TRUE;
168   }
169
170   /* Send the private message directly */
171   target = silc_dlist_get(clients);
172   ret = silc_client_send_private_message(silc_client, server->conn,
173                                          target, flags, sha1hash,
174                                          msg, msg_len);
175
176   silc_client_list_free(silc_client, server->conn, clients);
177
178   return ret;
179 }
180
181 void silc_send_mime(SILC_SERVER_REC *server, int channel, const char *to,
182                     const char *data, int sign)
183 {
184   char *unescaped_data;
185   SilcUInt32 unescaped_data_len;
186   int target_type;
187
188   if (!(IS_SILC_SERVER(server)) || (data == NULL) || (to == NULL))
189     return;
190
191   if (channel) {
192     target_type = SEND_TARGET_CHANNEL;
193   } else {
194     target_type = server_ischannel(SERVER(server), to) ?
195       SEND_TARGET_CHANNEL : SEND_TARGET_NICK;
196   }
197
198   unescaped_data = silc_unescape_data(data, &unescaped_data_len);
199
200   if (target_type == SEND_TARGET_CHANNEL) {
201     SILC_CHANNEL_REC *rec;
202
203     rec = silc_channel_find(server, to);
204     if (rec == NULL || rec->entry == NULL) {
205       cmd_return_error(CMDERR_NOT_JOINED);
206     }
207
208     silc_client_send_channel_message(silc_client, server->conn, rec->entry,
209                                      NULL, SILC_MESSAGE_FLAG_DATA |
210                                      (sign ? SILC_MESSAGE_FLAG_SIGNED : 0),
211                                      sha1hash, unescaped_data,
212                                      unescaped_data_len);
213   } else {
214     silc_send_msg(server, (char *)to, unescaped_data, unescaped_data_len,
215                   SILC_MESSAGE_FLAG_DATA |
216                   (sign ? SILC_MESSAGE_FLAG_SIGNED : 0));
217
218   }
219
220   signal_stop();
221
222   silc_free(unescaped_data);
223 }
224
225 static int isnickflag_func(char flag)
226 {
227   return flag == '@' || flag == '+';
228 }
229
230 static int ischannel_func(SERVER_REC *server, const char *data)
231 {
232   return FALSE;
233 }
234
235 const char *get_nick_flags(void)
236 {
237   return "@\0\0";
238 }
239
240 static void send_message(SILC_SERVER_REC *server, char *target,
241                          char *msg, int target_type)
242 {
243   char *message = NULL, *t = NULL;
244   int len;
245
246   g_return_if_fail(server != NULL);
247   g_return_if_fail(target != NULL);
248   g_return_if_fail(msg != NULL);
249
250   if (!silc_term_utf8()) {
251     len = silc_utf8_encoded_len(msg, strlen(msg), SILC_STRING_LOCALE);
252     message = silc_calloc(len + 1, sizeof(*message));
253     g_return_if_fail(message != NULL);
254     silc_utf8_encode(msg, strlen(msg), SILC_STRING_LOCALE, message, len);
255   }
256
257   if (target_type == SEND_TARGET_CHANNEL)
258     silc_send_channel(server, target, message ? message : msg,
259                       SILC_MESSAGE_FLAG_UTF8);
260   else {
261     if (!silc_term_utf8()) {
262       len = silc_utf8_encoded_len(target, strlen(target), SILC_STRING_LOCALE);
263       t = silc_calloc(len + 1, sizeof(*t));
264       g_return_if_fail(t != NULL);
265       silc_utf8_encode(target, strlen(target), SILC_STRING_LOCALE, t, len);
266     }
267
268     silc_send_msg(server, t ? t : target, message ? message : msg,
269                   message ? strlen(message) : strlen(msg),
270                   SILC_MESSAGE_FLAG_UTF8);
271   }
272
273   silc_free(message);
274   silc_free(t);
275 }
276
277 /* Connection callback */
278
279 static void silc_connect_cb(SilcClient client,
280                             SilcClientConnection conn,
281                             SilcClientConnectionStatus status,
282                             SilcStatus error,
283                             const char *message,
284                             void *context)
285 {
286   SILC_SERVER_REC *server = context;
287   char *file;
288
289   if (server->disconnected) {
290     silc_client_close_connection(client, conn);
291     return;
292   }
293
294   switch (status) {
295   case SILC_CLIENT_CONN_SUCCESS:
296     /* We have successfully connected to server */
297
298     /* Enable queueing until we have our requested nick */
299 #if 0
300     if (settings_get_str("nick") &&
301         !strcmp(conn->local_entry->nickname, conn->local_entry->username))
302       silc_queue_enable(conn);
303 #endif
304
305     /* Put default attributes */
306     silc_query_attributes_default(silc_client, conn);
307
308     server->connected = TRUE;
309     server->conn = conn;
310     server->conn->context = server;
311     signal_emit("event connected", 1, server);
312     break;
313
314   case SILC_CLIENT_CONN_SUCCESS_RESUME:
315     /* We have successfully resumed old detached session */
316     server->connected = TRUE;
317     server->conn = conn;
318     server->conn->context = server;
319     signal_emit("event connected", 1, server);
320
321     /* Put default attributes */
322     silc_query_attributes_default(silc_client, conn);
323
324     /* If we resumed old session check whether we need to update
325        our nickname */
326     if (strcmp(server->nick, conn->local_entry->nickname)) {
327       char *old;
328       old = g_strdup(server->nick);
329       server_change_nick(SERVER(server), conn->local_entry->nickname);
330       nicklist_rename_unique(SERVER(server),
331                              conn->local_entry, server->nick,
332                              conn->local_entry, conn->local_entry->nickname);
333       signal_emit("message own_nick", 4, server, server->nick, old, "");
334       g_free(old);
335     }
336
337     /* Remove the detach data now */
338     file = silc_get_session_filename(server);
339     unlink(file);
340     silc_free(file);
341     break;
342
343   case SILC_CLIENT_CONN_DISCONNECTED:
344     /* Server disconnected */
345     if (server->conn && server->conn->local_entry) {
346       nicklist_rename_unique(SERVER(server),
347                              server->conn->local_entry, server->nick,
348                              server->conn->local_entry,
349                              silc_client->username);
350       silc_change_nick(server, silc_client->username);
351     }
352
353     if (message)
354       silc_say(client, conn, SILC_CLIENT_MESSAGE_AUDIT,
355                "Server closed connection: %s (%d) %s",
356                silc_get_status_message(error), error,
357                message ? message : "");
358
359     if (server->conn)
360       server->conn->context = NULL;
361     server->conn = NULL;
362     server->connection_lost = TRUE;
363     server_disconnect(SERVER(server));
364     break;
365
366   default:
367     file = silc_get_session_filename(server);
368     if (silc_file_size(file) > 0)
369       printformat_module("fe-common/silc", server, NULL,
370                          MSGLEVEL_CRAP, SILCTXT_REATTACH_FAILED, file);
371
372     silc_free(file);
373
374     server->connection_lost = TRUE;
375     if (server->conn)
376       server->conn->context = NULL;
377     server_disconnect(SERVER(server));
378     break;
379   }
380 }
381
382 static void sig_connected_stream_created(SilcSocketStreamStatus status,
383                                          SilcStream stream, void *context)
384 {
385   SILC_SERVER_REC *server = context;
386   SilcClientConnectionParams params;
387   char *file;
388
389   if (!stream) {
390     server->connection_lost = TRUE;
391     server_disconnect(SERVER(server));
392     return;
393   }
394
395   if (server->disconnected) {
396     silc_stream_destroy(stream);
397     return;
398   }
399
400   /* Set connection parameters */
401   memset(&params, 0, sizeof(params));
402   params.nickname = (char *)settings_get_str("nick");
403
404   /* Try to read detached session data and use it if found. */
405   file = silc_get_session_filename(server);
406   params.detach_data = silc_file_readfile(file, &params.detach_data_len);
407   if (params.detach_data)
408     params.detach_data[params.detach_data_len] = 0;
409   if (params.detach_data)
410     printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
411                         SILCTXT_REATTACH, server->tag);
412
413   /* Start key exchange */
414   silc_client_key_exchange(silc_client, &params, irssi_pubkey, irssi_privkey,
415                            stream, SILC_CONN_SERVER, silc_connect_cb, server);
416
417   server->ftp_sessions = silc_dlist_init();
418   server->isnickflag = isnickflag_func;
419   server->ischannel = ischannel_func;
420   server->get_nick_flags = get_nick_flags;
421   server->send_message = (void *) send_message;
422 }
423
424 static void sig_connected(SILC_SERVER_REC *server)
425 {
426   int fd;
427
428   if (!IS_SILC_SERVER(server))
429     return;
430
431   /* Wrap the socket to TCP stream */
432   fd = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
433   silc_socket_tcp_stream_create(fd, TRUE, FALSE, silc_client->schedule,
434                                 sig_connected_stream_created, server);
435 }
436
437 static void sig_disconnected(SILC_SERVER_REC *server)
438 {
439   if (!IS_SILC_SERVER(server))
440     return;
441
442   silc_dlist_uninit(server->ftp_sessions);
443
444   if (server->conn) {
445     silc_client_close_connection(silc_client, server->conn);
446
447     /* SILC closes the handle */
448     g_io_channel_unref(net_sendbuffer_handle(server->handle));
449     net_sendbuffer_destroy(server->handle, FALSE);
450     server->handle = NULL;
451   }
452 }
453
454 SERVER_REC *silc_server_init_connect(SERVER_CONNECT_REC *conn)
455 {
456   SILC_SERVER_REC *server;
457
458   g_return_val_if_fail(IS_SILC_SERVER_CONNECT(conn), NULL);
459   if (conn->address == NULL || *conn->address == '\0')
460     return NULL;
461   if (conn->nick == NULL || *conn->nick == '\0') {
462     silc_say_error("Cannot connect: nickname is not set");
463     return NULL;
464   }
465
466   server = g_new0(SILC_SERVER_REC, 1);
467   server->chat_type = SILC_PROTOCOL;
468   server->connrec = (SILC_SERVER_CONNECT_REC *)conn;
469   server_connect_ref(conn);
470
471   if (server->connrec->port <= 0)
472     server->connrec->port = 706;
473
474   server_connect_init((SERVER_REC *)server);
475   return (SERVER_REC *)server;
476 }
477
478 void silc_server_connect(SERVER_REC *server)
479 {
480   if (!server_start_connect(server)) {
481     server_connect_unref(server->connrec);
482     g_free(server);
483     return;
484   }
485 }
486
487 /* Return a string of all channels in server in server->channels_join()
488    format */
489
490 char *silc_server_get_channels(SILC_SERVER_REC *server)
491 {
492   GSList *tmp;
493   GString *chans;
494   char *ret;
495
496   g_return_val_if_fail(server != NULL, FALSE);
497
498   chans = g_string_new(NULL);
499   for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
500     CHANNEL_REC *channel = tmp->data;
501
502     g_string_sprintfa(chans, "%s,", channel->name);
503   }
504
505   if (chans->len > 0)
506     g_string_truncate(chans, chans->len-1);
507
508   ret = chans->str;
509   g_string_free(chans, FALSE);
510
511   return ret;
512 }
513
514 /* Syntaxes of all SILC commands for HELP files (the help file generation
515    will snoop these from here). */
516
517 /* SYNTAX: BAN <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
518 /* SYNTAX: CMODE <channel> +|-<modes> [{ <arguments>}] */
519 /* SYNTAX: CUMODE <channel> +|-<modes> <nickname>[@<hostname>] */
520 /* SYNTAX: GETKEY <nickname or server name> */
521 /* SYNTAX: INVITE <channel> [<nickname>[@hostname>] */
522 /* SYNTAX: INVITE <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
523 /* SYNTAX: KEY MSG <nickname> set|unset|list|agreement|negotiate [<arguments>] */
524 /* SYNTAX: KEY CHANNEL <channel> set|unset|list|change [<arguments>] */
525 /* SYNTAX: KICK <channel> <nickname>[@<hostname>] [<comment>] */
526 /* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] [-pubkey] */
527 /* SYNTAX: OPER <username> [-pubkey] */
528 /* SYNTAX: SILCOPER <username> [-pubkey] */
529 /* SYNTAX: TOPIC <channel> [<topic>] */
530 /* SYNTAX: UMODE +|-<modes> */
531 /* SYNTAX: WHOIS [<nickname>[@<hostname>]] [-details] [-pubkey <pubkeyfile>] [<count>] */
532 /* SYNTAX: WHOWAS <nickname>[@<hostname>] [<count>] */
533 /* SYNTAX: CLOSE <server> [<port>] */
534 /* SYNTAX: SHUTDOWN */
535 /* SYNTAX: MOTD [<server>] */
536 /* SYNTAX: LIST [<channel>] */
537 /* SYNTAX: ME <message> */
538 /* SYNTAX: ACTION [-sign] [-channel] <target> <message> */
539 /* SYNTAX: AWAY [<message>] */
540 /* SYNTAX: INFO [<server>] */
541 /* SYNTAX: NICK <nickname> */
542 /* SYNTAX: NOTICE [-sign] [-channel] <target> <message> */
543 /* SYNTAX: PART [<channel>] */
544 /* SYNTAX: PING */
545 /* SYNTAX: SCONNECT <server> [<port>] */
546 /* SYNTAX: USERS <channel> */
547 /* SYNTAX: FILE SEND <filepath> <nickname> [<local IP> [<local port>]] [-no-listener]*/
548 /* SYNTAX: FILE ACCEPT [<nickname>] */
549 /* SYNTAX: FILE CLOSE [<nickname>] */
550 /* SYNTAX: FILE */
551 /* SYNTAX: JOIN <channel> [<passphrase>] [-cipher <cipher>] [-hmac <hmac>] [-founder] [-auth [<pubkeyfile> <privkeyfile> [<privkey passphrase>]]]*/
552 /* SYNTAX: DETACH */
553 /* SYNTAX: WATCH [<-add | -del> <nickname>] [-pubkey +|-<pubkeyfile>] */
554 /* SYNTAX: STATS */
555 /* SYNTAX: ATTR [<-del> <option> [{ <value>}]] */
556 /* SYNTAX: SMSG [<-channel>] <target> <message> */
557 /* SYNTAX: LISTKEYS [-servers] [-clients] [<public key file>] */
558
559 void silc_command_exec(SILC_SERVER_REC *server,
560                        const char *command, const char *args)
561 {
562   char *data;
563   g_return_if_fail(server != NULL);
564
565   /* Call the command */
566   data = g_strconcat(command, " ", args, NULL);
567   silc_queue_command_call(silc_client, server->conn, data);
568   g_free(data);
569 }
570
571 /* Generic command function to call any SILC command directly. */
572
573 static void command_self(const char *data, SILC_SERVER_REC *server,
574                          WI_ITEM_REC *item)
575 {
576   CMD_SILC_SERVER(server);
577
578   if (!IS_SILC_SERVER(server) || !server->connected) {
579     printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
580     return;
581   }
582
583   if (IS_SILC_CHANNEL(item)) {
584     SILC_CHANNEL_REC *chanrec;
585     chanrec = silc_channel_find(server, item->visible_name);
586     if (chanrec)
587       server->conn->current_channel = chanrec->entry;
588   }
589
590   silc_command_exec(server, current_command, data);
591   signal_stop();
592 }
593
594 /* SCONNECT command.  Calls actually SILC's CONNECT command since Irssi
595    has CONNECT command for other purposes. */
596
597 static void command_sconnect(const char *data, SILC_SERVER_REC *server)
598 {
599   CMD_SILC_SERVER(server);
600   if (!IS_SILC_SERVER(server) || !server->connected) {
601     printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
602     return;
603   }
604
605   silc_command_exec(server, "CONNECT", data);
606   signal_stop();
607 }
608
609 /* SMSG command, to send digitally signed messages */
610
611 static void command_smsg(const char *data, SILC_SERVER_REC *server,
612                          WI_ITEM_REC *item)
613 {
614   GHashTable *optlist;
615   char *target, *origtarget, *msg;
616   void *free_arg;
617   int free_ret, target_type;
618
619   g_return_if_fail(data != NULL);
620   if (server == NULL || !server->connected)
621     cmd_param_error(CMDERR_NOT_CONNECTED);
622
623   if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS |
624                       PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
625                       "msg", &optlist, &target, &msg))
626     return;
627   if (*target == '\0' || *msg == '\0')
628     cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
629
630   origtarget = target;
631   free_ret = FALSE;
632
633   if (strcmp(target, "*") == 0) {
634     if (item == NULL)
635       cmd_param_error(CMDERR_NOT_JOINED);
636
637     target_type = IS_CHANNEL(item) ?
638       SEND_TARGET_CHANNEL : SEND_TARGET_NICK;
639     target = (char *) window_item_get_target(item);
640   } else if (g_hash_table_lookup(optlist, "channel") != NULL) {
641     target_type = SEND_TARGET_CHANNEL;
642   } else {
643     target_type = server_ischannel(SERVER(server), target) ?
644       SEND_TARGET_CHANNEL : SEND_TARGET_NICK;
645   }
646
647   if (target != NULL) {
648     char *message = NULL, *t = NULL;
649     int len, result;
650
651     if (!silc_term_utf8()) {
652       len = silc_utf8_encoded_len(msg, strlen(msg), SILC_STRING_LOCALE);
653       message = silc_calloc(len + 1, sizeof(*message));
654       g_return_if_fail(message != NULL);
655       silc_utf8_encode(msg, strlen(msg), SILC_STRING_LOCALE, message, len);
656     }
657
658     if (target_type == SEND_TARGET_CHANNEL)
659       result = silc_send_channel(server, target, message ? message : msg,
660                                  SILC_MESSAGE_FLAG_UTF8 |
661                                  SILC_MESSAGE_FLAG_SIGNED);
662     else {
663       if (!silc_term_utf8()) {
664         len = silc_utf8_encoded_len(target, strlen(target),
665                                     SILC_STRING_LOCALE);
666         t = silc_calloc(len + 1, sizeof(*t));
667         g_return_if_fail(t != NULL);
668         silc_utf8_encode(target, strlen(target), SILC_STRING_LOCALE, t, len);
669       }
670       result = silc_send_msg(server, t ? t : target, message ? message : msg,
671                              message ? strlen(message) : strlen(msg),
672                              SILC_MESSAGE_FLAG_UTF8 |
673                              SILC_MESSAGE_FLAG_SIGNED);
674     }
675     silc_free(message);
676     silc_free(t);
677     if (!result)
678       goto out;
679   }
680
681   signal_emit(target != NULL && target_type == SEND_TARGET_CHANNEL ?
682               "message signed_own_public" : "message signed_own_private", 4,
683               server, msg, target, origtarget);
684 out:
685   if (free_ret && target != NULL) g_free(target);
686   cmd_params_free(free_arg);
687 }
688
689 #if 0
690 /* FILE command */
691
692 SILC_TASK_CALLBACK(silc_client_file_close_later)
693 {
694   FtpSession ftp = (FtpSession)context;
695
696   SILC_LOG_DEBUG(("Start"));
697
698   silc_client_file_close(silc_client, ftp->conn, ftp->session_id);
699   silc_free(ftp->filepath);
700   silc_free(ftp);
701 }
702
703 static void silc_client_file_monitor(SilcClient client,
704                                      SilcClientConnection conn,
705                                      SilcClientMonitorStatus status,
706                                      SilcClientFileError error,
707                                      SilcUInt64 offset,
708                                      SilcUInt64 filesize,
709                                      SilcClientEntry client_entry,
710                                      SilcUInt32 session_id,
711                                      const char *filepath,
712                                      void *context)
713 {
714   SILC_SERVER_REC *server = (SILC_SERVER_REC *)context;
715   FtpSession ftp;
716   char fsize[32];
717
718   if (status == SILC_CLIENT_FILE_MONITOR_CLOSED)
719     return;
720
721   snprintf(fsize, sizeof(fsize) - 1, "%llu", ((filesize + 1023) / 1024));
722
723   silc_dlist_start(server->ftp_sessions);
724   while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
725     if (ftp->session_id == session_id) {
726       if (!ftp->filepath && filepath)
727         ftp->filepath = strdup(filepath);
728       break;
729     }
730   }
731
732   if (ftp == SILC_LIST_END)
733     return;
734
735   if (status == SILC_CLIENT_FILE_MONITOR_ERROR) {
736     if (error == SILC_CLIENT_FILE_NO_SUCH_FILE)
737       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
738                          SILCTXT_FILE_ERROR_NO_SUCH_FILE,
739                          client_entry->nickname,
740                          filepath ? filepath : "[N/A]");
741     else if (error == SILC_CLIENT_FILE_PERMISSION_DENIED)
742       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
743                          SILCTXT_FILE_ERROR_PERMISSION_DENIED,
744                          client_entry->nickname);
745     else
746       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
747                          SILCTXT_FILE_ERROR, client_entry->nickname);
748     silc_schedule_task_add(silc_client->schedule, 0,
749                            silc_client_file_close_later, ftp,
750                            1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
751     silc_dlist_del(server->ftp_sessions, ftp);
752     if (ftp == server->current_session) {
753       server->current_session = NULL;
754       silc_dlist_start(server->ftp_sessions);
755       server->current_session = silc_dlist_get(server->ftp_sessions);
756     }
757   }
758
759   if (status == SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT) {
760     printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
761                        SILCTXT_FILE_KEY_EXCHANGE, client_entry->nickname);
762   }
763
764   /* Save some transmission data */
765   if (offset && filesize) {
766     unsigned long delta = time(NULL) - ftp->starttime;
767
768     ftp->percent = ((double)offset / (double)filesize) * (double)100.0;
769     if (delta)
770       ftp->kps = (double)((offset / (double)delta) + 1023) / (double)1024;
771     else
772       ftp->kps = (double)(offset + 1023) / (double)1024;
773     ftp->offset = offset;
774     ftp->filesize = filesize;
775   }
776
777   if (status == SILC_CLIENT_FILE_MONITOR_SEND) {
778     if (offset == 0) {
779       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
780                          SILCTXT_FILE_TRANSMIT, filepath, fsize,
781                          client_entry->nickname);
782       ftp->starttime = time(NULL);
783     }
784     if (offset == filesize) {
785       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
786                          SILCTXT_FILE_TRANSMITTED, filepath, fsize,
787                          client_entry->nickname, ftp->kps);
788       silc_schedule_task_add(silc_client->schedule, 0,
789                              silc_client_file_close_later, ftp,
790                              1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
791       silc_dlist_del(server->ftp_sessions, ftp);
792       if (ftp == server->current_session) {
793         server->current_session = NULL;
794         silc_dlist_start(server->ftp_sessions);
795         server->current_session = silc_dlist_get(server->ftp_sessions);
796       }
797
798     }
799   }
800
801   if (status == SILC_CLIENT_FILE_MONITOR_RECEIVE) {
802     if (offset == 0) {
803       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
804                          SILCTXT_FILE_RECEIVE, filepath, fsize,
805                          client_entry->nickname);
806       ftp->starttime = time(NULL);
807     }
808
809     if (offset == filesize) {
810       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
811                          SILCTXT_FILE_RECEIVED, filepath, fsize,
812                          client_entry->nickname, ftp->kps);
813       silc_schedule_task_add(silc_client->schedule, 0,
814                              silc_client_file_close_later, ftp,
815                              1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
816       silc_dlist_del(server->ftp_sessions, ftp);
817       if (ftp == server->current_session) {
818         server->current_session = NULL;
819         silc_dlist_start(server->ftp_sessions);
820         server->current_session = silc_dlist_get(server->ftp_sessions);
821       }
822
823     }
824   }
825 }
826
827 typedef struct {
828   SILC_SERVER_REC *server;
829   char *data;
830   char *nick;
831   WI_ITEM_REC *item;
832 } *FileGetClients;
833
834 static void silc_client_command_file_get_clients(SilcClient client,
835                                                  SilcClientConnection conn,
836                                                  SilcClientEntry *clients,
837                                                  SilcUInt32 clients_count,
838                                                  void *context)
839 {
840   FileGetClients internal = (FileGetClients)context;
841
842   if (!clients) {
843     printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
844               internal->nick);
845     silc_free(internal->data);
846     silc_free(internal->nick);
847     silc_free(internal);
848     return;
849   }
850
851   signal_emit("command file", 3, internal->data, internal->server,
852               internal->item);
853
854   silc_free(internal->data);
855   silc_free(internal->nick);
856   silc_free(internal);
857 }
858
859 static void command_file(const char *data, SILC_SERVER_REC *server,
860                          WI_ITEM_REC *item)
861 {
862   SilcClientConnection conn;
863   SilcClientEntry *entrys, client_entry;
864   SilcClientFileError ret;
865   SilcUInt32 entry_count;
866   char *nickname = NULL, *tmp;
867   unsigned char **argv;
868   SilcUInt32 argc;
869   SilcUInt32 *argv_lens, *argv_types;
870   int type = 0;
871   FtpSession ftp;
872   char *local_ip = NULL;
873   SilcUInt32 local_port = 0;
874   SilcUInt32 session_id;
875   bool do_not_bind = FALSE;
876
877   CMD_SILC_SERVER(server);
878   if (!server || !IS_SILC_SERVER(server) || !server->connected)
879     cmd_return_error(CMDERR_NOT_CONNECTED);
880
881   conn = server->conn;
882
883   /* Now parse all arguments */
884   tmp = g_strconcat("FILE", " ", data, NULL);
885   silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 7);
886   g_free(tmp);
887
888   if (argc == 1)
889     type = 4;
890
891   if (argc >= 2) {
892     if (!strcasecmp(argv[1], "send"))
893       type = 1;
894     if (!strcasecmp(argv[1], "accept"))
895       type = 2;
896     if (!strcasecmp(argv[1], "close"))
897       type = 3;
898   }
899
900   if (type == 0)
901     cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
902
903   switch (type) {
904   case 1:
905     if (argc < 4)
906       cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
907
908     /* Parse the typed nickname. */
909     if (!silc_parse_userfqdn(argv[3], &nickname, NULL)) {
910       printformat_module("fe-common/silc", server, NULL,
911                          MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[3]);
912       goto out;
913     }
914
915     /* Find client entry */
916     entrys = silc_client_get_clients_local(silc_client, conn, nickname,
917                                            argv[3], &entry_count);
918     if (!entrys) {
919       FileGetClients inter = silc_calloc(1, sizeof(*inter));
920       inter->server = server;
921       inter->data = strdup(data);
922       inter->nick = strdup(nickname);
923       inter->item = item;
924       silc_client_get_clients(silc_client, conn, nickname, argv[3],
925                               silc_client_command_file_get_clients, inter);
926       goto out;
927     }
928     client_entry = entrys[0];
929     silc_free(entrys);
930
931     if (argc >= 5) {
932       if (!strcasecmp(argv[4], "-no-listener"))
933         do_not_bind = TRUE;
934       else
935         local_ip = argv[4];
936     }
937     if (argc >= 6) {
938       if (!strcasecmp(argv[5], "-no-listener"))
939         do_not_bind = TRUE;
940       else
941         local_port = atoi(argv[5]);
942     }
943     if (argc >= 7) {
944       if (!strcasecmp(argv[6], "-no-listener"))
945         do_not_bind = TRUE;
946     }
947
948     ret =
949       silc_client_file_send(silc_client, conn, silc_client_file_monitor,
950                             server, local_ip, local_port, do_not_bind,
951                             client_entry, argv[2], &session_id);
952     if (ret == SILC_CLIENT_FILE_OK) {
953       ftp = silc_calloc(1, sizeof(*ftp));
954       ftp->session_id = session_id;
955
956       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
957                          SILCTXT_FILE_SEND, client_entry->nickname,
958                          argv[2]);
959
960       ftp->client_entry = client_entry;
961       ftp->filepath = strdup(argv[2]);
962       ftp->conn = conn;
963       ftp->send = TRUE;
964       silc_dlist_add(server->ftp_sessions, ftp);
965       server->current_session = ftp;
966     } else {
967       if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
968         printformat_module("fe-common/silc", server, NULL,
969                            MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
970                            client_entry->nickname);
971       if (ret == SILC_CLIENT_FILE_NO_SUCH_FILE)
972         printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
973                            SILCTXT_FILE_ERROR_NO_SUCH_FILE,
974                            client_entry->nickname, argv[2]);
975     }
976
977     break;
978
979   case 2:
980     /* Parse the typed nickname. */
981     if (argc >= 3) {
982       if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
983         printformat_module("fe-common/silc", server, NULL,
984                            MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
985         goto out;
986       }
987
988       /* Find client entry */
989       entrys = silc_client_get_clients_local(silc_client, conn, nickname,
990                                              argv[2], &entry_count);
991       if (!entrys) {
992         FileGetClients inter = silc_calloc(1, sizeof(*inter));
993         inter->server = server;
994         inter->data = strdup(data);
995         inter->nick = strdup(nickname);
996         inter->item = item;
997         silc_client_get_clients(silc_client, conn, nickname, argv[2],
998                                 silc_client_command_file_get_clients, inter);
999         goto out;
1000       }
1001       client_entry = entrys[0];
1002       silc_free(entrys);
1003     } else {
1004       if (!server->current_session) {
1005         printformat_module("fe-common/silc", server, NULL,
1006                            MSGLEVEL_CRAP, SILCTXT_FILE_NA);
1007         goto out;
1008       }
1009
1010       ret = silc_client_file_receive(silc_client, conn,
1011                                      silc_client_file_monitor, server, NULL,
1012                                      server->current_session->session_id,
1013                                      NULL, NULL);
1014       if (ret != SILC_CLIENT_FILE_OK) {
1015         if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
1016           printformat_module("fe-common/silc", server, NULL,
1017                              MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
1018                              server->current_session->client_entry->nickname);
1019         else {
1020           printformat_module("fe-common/silc", server, NULL,
1021                              MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
1022                              server->current_session->client_entry->nickname);
1023
1024           silc_client_file_close(silc_client, conn,
1025                                  server->current_session->session_id);
1026           silc_dlist_del(server->ftp_sessions, server->current_session);
1027           silc_free(server->current_session->filepath);
1028           silc_free(server->current_session);
1029           server->current_session = NULL;
1030
1031           silc_dlist_start(server->ftp_sessions);
1032           server->current_session = silc_dlist_get(server->ftp_sessions);
1033         }
1034       }
1035
1036       goto out;
1037     }
1038
1039     silc_dlist_start(server->ftp_sessions);
1040     while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
1041       if (ftp->client_entry == client_entry && !ftp->filepath) {
1042         ret = silc_client_file_receive(silc_client, conn,
1043                                        silc_client_file_monitor, server,
1044                                        NULL, ftp->session_id, NULL, NULL);
1045         if (ret != SILC_CLIENT_FILE_OK) {
1046           if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
1047             printformat_module("fe-common/silc", server, NULL,
1048                                MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
1049                                client_entry->nickname);
1050           else {
1051             printformat_module("fe-common/silc", server, NULL,
1052                                MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
1053                                client_entry->nickname);
1054             silc_client_file_close(silc_client, conn, ftp->session_id);
1055             silc_dlist_del(server->ftp_sessions, ftp);
1056             if (ftp == server->current_session) {
1057               server->current_session = NULL;
1058               silc_dlist_start(server->ftp_sessions);
1059               server->current_session = silc_dlist_get(server->ftp_sessions);
1060             }
1061             silc_free(ftp->filepath);
1062             silc_free(ftp);
1063           }
1064         }
1065         break;
1066       }
1067     }
1068
1069     if (ftp == SILC_LIST_END) {
1070       printformat_module("fe-common/silc", server, NULL,
1071                          MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
1072                          client_entry->nickname);
1073       goto out;
1074     }
1075     break;
1076
1077   case 3:
1078     /* Parse the typed nickname. */
1079     if (argc >= 3) {
1080       if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
1081         printformat_module("fe-common/silc", server, NULL,
1082                            MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
1083         goto out;
1084       }
1085
1086       /* Find client entry */
1087       entrys = silc_client_get_clients_local(silc_client, conn, nickname,
1088                                              argv[2], &entry_count);
1089       if (!entrys) {
1090         FileGetClients inter = silc_calloc(1, sizeof(*inter));
1091         inter->server = server;
1092         inter->data = strdup(data);
1093         inter->nick = strdup(nickname);
1094         inter->item = item;
1095         silc_client_get_clients(silc_client, conn, nickname, argv[2],
1096                                 silc_client_command_file_get_clients, inter);
1097         goto out;
1098       }
1099       client_entry = entrys[0];
1100       silc_free(entrys);
1101     } else {
1102       if (!server->current_session) {
1103         printformat_module("fe-common/silc", server, NULL,
1104                            MSGLEVEL_CRAP, SILCTXT_FILE_NA);
1105         goto out;
1106       }
1107
1108       silc_client_file_close(silc_client, conn,
1109                              server->current_session->session_id);
1110       printformat_module("fe-common/silc", server, NULL,
1111                          MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
1112                          server->current_session->client_entry->nickname,
1113                          server->current_session->filepath ?
1114                          server->current_session->filepath : "[N/A]");
1115       silc_dlist_del(server->ftp_sessions, server->current_session);
1116       silc_free(server->current_session->filepath);
1117       silc_free(server->current_session);
1118       server->current_session = NULL;
1119
1120       silc_dlist_start(server->ftp_sessions);
1121       server->current_session = silc_dlist_get(server->ftp_sessions);
1122       goto out;
1123     }
1124
1125     silc_dlist_start(server->ftp_sessions);
1126     while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
1127       if (ftp->client_entry == client_entry) {
1128         silc_client_file_close(silc_client, conn, ftp->session_id);
1129         printformat_module("fe-common/silc", server, NULL,
1130                            MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
1131                            client_entry->nickname,
1132                            ftp->filepath ? ftp->filepath : "[N/A]");
1133         silc_dlist_del(server->ftp_sessions, ftp);
1134         if (ftp == server->current_session) {
1135           server->current_session = NULL;
1136           silc_dlist_start(server->ftp_sessions);
1137           server->current_session = silc_dlist_get(server->ftp_sessions);
1138         }
1139         silc_free(ftp->filepath);
1140         silc_free(ftp);
1141         break;
1142       }
1143     }
1144
1145     if (ftp == SILC_LIST_END) {
1146       printformat_module("fe-common/silc", server, NULL,
1147                          MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
1148                          client_entry->nickname);
1149       goto out;
1150     }
1151     break;
1152
1153   case 4:
1154
1155     if (!silc_dlist_count(server->ftp_sessions)) {
1156       printformat_module("fe-common/silc", server, NULL,
1157                          MSGLEVEL_CRAP, SILCTXT_FILE_NA);
1158       goto out;
1159     }
1160
1161     printformat_module("fe-common/silc", server, NULL,
1162                        MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_HEADER);
1163
1164     silc_dlist_start(server->ftp_sessions);
1165     while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
1166       printformat_module("fe-common/silc", server, NULL,
1167                          MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_LINE,
1168                          ftp->client_entry->nickname,
1169                          ftp->session_id,
1170                          ftp->send ? "send" : "receive",
1171                          (SilcUInt32)(ftp->offset + 1023) / 1024,
1172                          (SilcUInt32)(ftp->filesize + 1023) / 1024,
1173                          ftp->percent, ftp->kps,
1174                          ftp->filepath ? ftp->filepath : "[N/A]");
1175     }
1176
1177     break;
1178
1179   default:
1180     break;
1181   }
1182
1183  out:
1184   silc_free(nickname);
1185 }
1186 #endif /* 0 */
1187
1188 void silc_server_init(void)
1189 {
1190   silc_servers_reconnect_init();
1191
1192   signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
1193   signal_add("server disconnected", (SIGNAL_FUNC) sig_disconnected);
1194   signal_add("mime-send", (SIGNAL_FUNC)silc_send_mime);
1195   command_bind_silc("whois", MODULE_NAME, (SIGNAL_FUNC) command_self);
1196   command_bind_silc("whowas", MODULE_NAME, (SIGNAL_FUNC) command_self);
1197   command_bind_silc("nick", MODULE_NAME, (SIGNAL_FUNC) command_self);
1198   command_bind_silc("topic", MODULE_NAME, (SIGNAL_FUNC) command_self);
1199   command_bind_silc("cmode", MODULE_NAME, (SIGNAL_FUNC) command_self);
1200   command_bind_silc("cumode", MODULE_NAME, (SIGNAL_FUNC) command_self);
1201   command_bind_silc("users", MODULE_NAME, (SIGNAL_FUNC) command_self);
1202   command_bind_silc("list", MODULE_NAME, (SIGNAL_FUNC) command_self);
1203   command_bind_silc("ban", MODULE_NAME, (SIGNAL_FUNC) command_self);
1204   command_bind_silc("oper", MODULE_NAME, (SIGNAL_FUNC) command_self);
1205   command_bind_silc("silcoper", MODULE_NAME, (SIGNAL_FUNC) command_self);
1206   command_bind_silc("umode", MODULE_NAME, (SIGNAL_FUNC) command_self);
1207   command_bind_silc("invite", MODULE_NAME, (SIGNAL_FUNC) command_self);
1208   command_bind_silc("kill", MODULE_NAME, (SIGNAL_FUNC) command_self);
1209   command_bind_silc("kick", MODULE_NAME, (SIGNAL_FUNC) command_self);
1210   command_bind_silc("info", MODULE_NAME, (SIGNAL_FUNC) command_self);
1211   command_bind_silc("ping", MODULE_NAME, (SIGNAL_FUNC) command_self);
1212   command_bind_silc("motd", MODULE_NAME, (SIGNAL_FUNC) command_self);
1213   command_bind_silc("close", MODULE_NAME, (SIGNAL_FUNC) command_self);
1214   command_bind_silc("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
1215   command_bind_silc("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
1216   command_bind_silc("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
1217 //  command_bind_silc("file", MODULE_NAME, (SIGNAL_FUNC) command_file);
1218   command_bind_silc("detach", MODULE_NAME, (SIGNAL_FUNC) command_self);
1219   command_bind_silc("watch", MODULE_NAME, (SIGNAL_FUNC) command_self);
1220   command_bind_silc("stats", MODULE_NAME, (SIGNAL_FUNC) command_self);
1221   command_bind_silc("attr", MODULE_NAME, (SIGNAL_FUNC) command_attr);
1222   command_bind_silc("smsg", MODULE_NAME, (SIGNAL_FUNC) command_smsg);
1223
1224   command_set_options("connect", "+silcnet");
1225 }
1226
1227 void silc_server_deinit(void)
1228 {
1229   silc_servers_reconnect_deinit();
1230
1231   signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
1232   signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
1233   signal_remove("mime-send", (SIGNAL_FUNC)silc_send_mime);
1234   command_unbind("whois", (SIGNAL_FUNC) command_self);
1235   command_unbind("whowas", (SIGNAL_FUNC) command_self);
1236   command_unbind("nick", (SIGNAL_FUNC) command_self);
1237   command_unbind("topic", (SIGNAL_FUNC) command_self);
1238   command_unbind("cmode", (SIGNAL_FUNC) command_self);
1239   command_unbind("cumode", (SIGNAL_FUNC) command_self);
1240   command_unbind("users", (SIGNAL_FUNC) command_self);
1241   command_unbind("list", (SIGNAL_FUNC) command_self);
1242   command_unbind("oper", (SIGNAL_FUNC) command_self);
1243   command_unbind("silcoper", (SIGNAL_FUNC) command_self);
1244   command_unbind("umode", (SIGNAL_FUNC) command_self);
1245   command_unbind("invite", (SIGNAL_FUNC) command_self);
1246   command_unbind("kill", (SIGNAL_FUNC) command_self);
1247   command_unbind("kick", (SIGNAL_FUNC) command_self);
1248   command_unbind("info", (SIGNAL_FUNC) command_self);
1249   command_unbind("ping", (SIGNAL_FUNC) command_self);
1250   command_unbind("motd", (SIGNAL_FUNC) command_self);
1251   command_unbind("ban", (SIGNAL_FUNC) command_self);
1252   command_unbind("close", (SIGNAL_FUNC) command_self);
1253   command_unbind("shutdown", (SIGNAL_FUNC) command_self);
1254   command_unbind("getkey", (SIGNAL_FUNC) command_self);
1255   command_unbind("sconnect", (SIGNAL_FUNC) command_sconnect);
1256 //  command_unbind("file", (SIGNAL_FUNC) command_file);
1257   command_unbind("detach", (SIGNAL_FUNC) command_self);
1258   command_unbind("watch", (SIGNAL_FUNC) command_self);
1259   command_unbind("stats", (SIGNAL_FUNC) command_self);
1260   command_unbind("attr", (SIGNAL_FUNC) command_attr);
1261   command_unbind("smsg", (SIGNAL_FUNC) command_smsg);
1262 }
1263
1264 #if 0
1265 void silc_server_free_ftp(SILC_SERVER_REC *server,
1266                           SilcClientEntry client_entry)
1267 {
1268   FtpSession ftp;
1269
1270   silc_dlist_start(server->ftp_sessions);
1271   while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
1272     if (ftp->client_entry == client_entry) {
1273       silc_dlist_del(server->ftp_sessions, ftp);
1274       silc_free(ftp->filepath);
1275       silc_free(ftp);
1276     }
1277   }
1278 }
1279 #endif /* 0 */
1280
1281 bool silc_term_utf8(void)
1282 {
1283   const char *str;
1284   str = settings_get_str("term_type");
1285   if (str)
1286     if (g_strcasecmp(str, "utf-8") == 0)
1287       return TRUE;
1288   return FALSE;
1289 }