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/core/fe-channels.h"
45 #include "fe-common/core/keyboard.h"
46 #include "fe-common/silc/module-formats.h"
48 #include "silc-commands.h"
50 void silc_servers_reconnect_init(void);
51 void silc_servers_reconnect_deinit(void);
53 static void silc_send_channel(SILC_SERVER_REC *server,
54 char *channel, char *msg)
56 SILC_CHANNEL_REC *rec;
58 rec = silc_channel_find(server, channel);
59 if (rec == NULL || rec->entry == NULL) {
60 cmd_return_error(CMDERR_NOT_JOINED);
64 silc_client_send_channel_message(silc_client, server->conn, rec->entry,
65 NULL, SILC_MESSAGE_FLAG_UTF8,
66 msg, strlen(msg), TRUE);
73 SilcMessageFlags flags;
74 SILC_SERVER_REC *server;
77 /* Callback function that sends the private message if the client was
78 resolved from the server. */
80 static void silc_send_msg_clients(SilcClient client,
81 SilcClientConnection conn,
82 SilcClientEntry *clients,
83 SilcUInt32 clients_count,
86 PRIVMSG_REC *rec = context;
87 SILC_SERVER_REC *server = rec->server;
88 SilcClientEntry target;
89 char *nickname = NULL;
92 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
93 "%s: There is no such client", rec->nick);
95 if (clients_count > 1) {
96 silc_parse_userfqdn(rec->nick, &nickname, NULL);
98 /* Find the correct one. The rec->nick might be a formatted nick
99 so this will find the correct one. */
100 clients = silc_client_get_clients_local(silc_client, server->conn,
104 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
105 "%s: There is no such client", rec->nick);
114 /* Still check for exact math for nickname, this compares the
115 real (formatted) nickname and the nick (maybe formatted) that
116 use gave. This is to assure that `nick' does not match
118 if (strcasecmp(rec->nick, clients[0]->nickname)) {
119 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
120 "%s: There is no such client", rec->nick);
124 /* Send the private message */
125 silc_client_send_private_message(client, conn, target,
137 static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
138 int msg_len, SilcMessageFlags flags)
141 SilcClientEntry *clients;
142 SilcUInt32 clients_count;
143 char *nickname = NULL;
145 if (!silc_parse_userfqdn(nick, &nickname, NULL)) {
146 printformat_module("fe-common/silc", server, NULL,
147 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
151 /* Find client entry */
152 clients = silc_client_get_clients_local(silc_client, server->conn,
153 nickname, nick, &clients_count);
155 rec = g_new0(PRIVMSG_REC, 1);
156 rec->nick = g_strdup(nick);
157 rec->msg = g_strdup(msg);
158 rec->server = server;
162 /* Could not find client with that nick, resolve it from server. */
163 silc_client_get_clients(silc_client, server->conn,
164 nickname, NULL, silc_send_msg_clients, rec);
169 /* Send the private message directly */
171 silc_client_send_private_message(silc_client, server->conn,
176 void silc_send_mime(SILC_SERVER_REC *server, WI_ITEM_REC *to,
177 const char *data, int data_len,
178 const char *enc, const char *type)
180 SILC_CHANNEL_REC *channel;
185 if (!(IS_SILC_SERVER(server)) || (data == NULL) || (to == NULL) ||
186 (enc == NULL) || (type == NULL))
189 #define SILC_MIME_HEADER "MIME-Version: 1.0\r\nContent-Type: %s\r\nContent-Transfer-Encoding: %s\r\n\r\n"
191 mime_data_len = data_len + strlen(SILC_MIME_HEADER) - 4
192 + strlen(enc) + strlen(type);
193 if (mime_data_len >= SILC_PACKET_MAX_LEN)
196 /* we risk to large packets here... */
197 mime_data = silc_calloc(mime_data_len, sizeof(*mime_data));
198 snprintf(mime_data, mime_data_len, SILC_MIME_HEADER, type, enc);
199 memmove(mime_data + strlen(SILC_MIME_HEADER) - 4 + strlen(enc) + strlen(type),
202 #undef SILC_MIME_HEADER
204 if (IS_SILC_CHANNEL(to)) {
205 channel = SILC_CHANNEL(to);
206 silc_client_send_channel_message(silc_client, server->conn, channel->entry,
207 NULL, SILC_MESSAGE_FLAG_DATA,
208 mime_data, mime_data_len, TRUE);
209 } else if (IS_SILC_QUERY(to)) {
210 query = SILC_QUERY(to);
211 silc_send_msg(server, query->name, mime_data, mime_data_len,
212 SILC_MESSAGE_FLAG_DATA);
216 silc_free(mime_data);
219 static int isnickflag_func(char flag)
221 return flag == '@' || flag == '+';
224 static int ischannel_func(SERVER_REC *server, const char *data)
229 const char *get_nick_flags(void)
234 static void send_message(SILC_SERVER_REC *server, char *target,
235 char *msg, int target_type)
237 char *message = NULL;
240 g_return_if_fail(server != NULL);
241 g_return_if_fail(target != NULL);
242 g_return_if_fail(msg != NULL);
244 if (!silc_term_utf8()) {
245 len = silc_utf8_encoded_len(msg, strlen(msg), SILC_STRING_LANGUAGE);
246 message = silc_calloc(len + 1, sizeof(*message));
247 g_return_if_fail(message != NULL);
248 silc_utf8_encode(msg, strlen(msg), SILC_STRING_LANGUAGE, message, len);
251 if (target_type == SEND_TARGET_CHANNEL)
252 silc_send_channel(server, target, message ? message : msg);
254 silc_send_msg(server, target, message ? message : msg,
255 message ? strlen(message) : strlen(msg),
256 SILC_MESSAGE_FLAG_UTF8);
261 static void sig_connected(SILC_SERVER_REC *server)
263 SilcClientConnection conn;
264 SilcClientConnectionParams params;
268 if (!IS_SILC_SERVER(server))
271 /* Try to read detached session data and use it if found. */
272 memset(¶ms, 0, sizeof(params));
273 memset(file, 0, sizeof(file));
274 snprintf(file, sizeof(file) - 1, "%s/session", get_irssi_dir());
275 params.detach_data = silc_file_readfile(file, ¶ms.detach_data_len);
277 /* Add connection to the client library */
278 conn = silc_client_add_connection(silc_client, ¶ms,
279 server->connrec->address,
280 server->connrec->port,
284 if (params.detach_data)
285 keyboard_entry_redirect(NULL,
286 "-- Resuming old session, may take a while ...",
287 ENTRY_REDIRECT_FLAG_HIDDEN, server);
289 silc_free(params.detach_data);
292 fd = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
294 /* Start key exchange with the server */
295 silc_client_start_key_exchange(silc_client, conn, fd);
297 server->ftp_sessions = silc_dlist_init();
298 server->isnickflag = isnickflag_func;
299 server->ischannel = ischannel_func;
300 server->get_nick_flags = get_nick_flags;
301 server->send_message = (void *) send_message;
304 static void sig_disconnected(SILC_SERVER_REC *server)
306 if (!IS_SILC_SERVER(server))
309 silc_dlist_uninit(server->ftp_sessions);
311 if (server->conn && server->conn->sock != NULL) {
312 silc_client_close_connection(silc_client, server->conn);
314 /* SILC closes the handle */
315 g_io_channel_unref(net_sendbuffer_handle(server->handle));
316 net_sendbuffer_destroy(server->handle, FALSE);
317 server->handle = NULL;
321 SILC_SERVER_REC *silc_server_connect(SILC_SERVER_CONNECT_REC *conn){
322 SILC_SERVER_REC *server;
324 g_return_val_if_fail(IS_SILC_SERVER_CONNECT(conn), NULL);
325 if (conn->address == NULL || *conn->address == '\0')
327 if (conn->nick == NULL || *conn->nick == '\0') {
328 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
329 "Cannot connect: nickname is not set");
333 server = g_new0(SILC_SERVER_REC, 1);
334 server->chat_type = SILC_PROTOCOL;
335 server->connrec = conn;
336 if (server->connrec->port <= 0)
337 server->connrec->port = 706;
339 server_connect_ref(SERVER_CONNECT(conn));
341 if (!server_start_connect((SERVER_REC *) server)) {
342 server_connect_unref(SERVER_CONNECT(conn));
350 /* Return a string of all channels in server in server->channels_join()
353 char *silc_server_get_channels(SILC_SERVER_REC *server)
359 g_return_val_if_fail(server != NULL, FALSE);
361 chans = g_string_new(NULL);
362 for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
363 CHANNEL_REC *channel = tmp->data;
365 g_string_sprintfa(chans, "%s,", channel->name);
369 g_string_truncate(chans, chans->len-1);
372 g_string_free(chans, FALSE);
377 /* Syntaxes of all SILC commands for HELP files (the help file generation
378 will snoop these from here). */
380 /* SYNTAX: BAN <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
381 /* SYNTAX: CMODE <channel> +|-<modes> [{ <arguments>}] */
382 /* SYNTAX: CUMODE <channel> +|-<modes> <nickname>[@<hostname>] */
383 /* SYNTAX: GETKEY <nickname or server name> */
384 /* SYNTAX: INVITE <channel> [<nickname>[@hostname>] */
385 /* SYNTAX: INVITE <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
386 /* SYNTAX: KEY MSG <nickname> set|unset|list|agreement|negotiate [<arguments>] */
387 /* SYNTAX: KEY CHANNEL <channel> set|unset|list|change [<arguments>] */
388 /* SYNTAX: KICK <channel> <nickname>[@<hostname>] [<comment>] */
389 /* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] */
390 /* SYNTAX: OPER <username> [-pubkey] */
391 /* SYNTAX: SILCOPER <username> [-pubkey] */
392 /* SYNTAX: TOPIC <channel> [<topic>] */
393 /* SYNTAX: UMODE +|-<modes> */
394 /* SYNTAX: WHOIS <nickname>[@<hostname>] [<count>] */
395 /* SYNTAX: WHOWAS <nickname>[@<hostname>] [<count>] */
396 /* SYNTAX: CLOSE <server> [<port>] */
397 /* SYNTAX: SHUTDOWN */
398 /* SYNTAX: MOTD [<server>] */
399 /* SYNTAX: LIST [<channel>] */
400 /* SYNTAX: ME <message> */
401 /* SYNTAX: ACTION <channel> <message> */
402 /* SYNTAX: AWAY [<message>] */
403 /* SYNTAX: INFO [<server>] */
404 /* SYNTAX: NICK <nickname> */
405 /* SYNTAX: NOTICE <message> */
406 /* SYNTAX: PART [<channel>] */
408 /* SYNTAX: SCONNECT <server> [<port>] */
409 /* SYNTAX: USERS <channel> */
410 /* SYNTAX: FILE SEND <filepath> <nickname> [<local IP> [<local port>]] */
411 /* SYNTAX: FILE RECEIVE [<nickname>] */
412 /* SYNTAX: FILE CLOSE [<nickname>] */
414 /* SYNTAX: JOIN <channel> [<passphrase>] [-cipher <cipher>] [-hmac <hmac>] [-founder] */
416 /* SYNTAX: WATCH [<-add | -del> <nickname>] */
418 void silc_command_exec(SILC_SERVER_REC *server,
419 const char *command, const char *args)
422 unsigned char **argv;
423 SilcUInt32 *argv_lens, *argv_types;
425 SilcClientCommand cmd;
426 SilcClientCommandContext ctx;
428 g_return_if_fail(server != NULL);
430 tmpcmd = g_strdup(command);
432 cmd = silc_client_command_find(silc_client, tmpcmd);
437 /* Now parse all arguments */
438 data = g_strconcat(command, " ", args, NULL);
439 silc_parse_command_line(data, &argv, &argv_lens,
440 &argv_types, &argc, cmd->max_args);
443 /* Allocate command context. This and its internals must be free'd
444 by the command routine receiving it. */
445 ctx = silc_client_command_alloc();
446 ctx->client = silc_client;
447 ctx->conn = server->conn;
451 ctx->argv_lens = argv_lens;
452 ctx->argv_types = argv_types;
454 /* Execute command */
455 silc_client_command_call(cmd, ctx);
458 /* Generic command function to call any SILC command directly. */
460 static void command_self(const char *data, SILC_SERVER_REC *server,
463 CMD_SILC_SERVER(server);
465 if (!IS_SILC_SERVER(server) || !server->connected) {
466 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
470 if (IS_SILC_CHANNEL(item)) {
471 SILC_CHANNEL_REC *chanrec;
472 chanrec = silc_channel_find(server, item->name);
474 server->conn->current_channel = chanrec->entry;
477 silc_command_exec(server, current_command, data);
481 /* SCONNECT command. Calls actually SILC's CONNECT command since Irssi
482 has CONNECT command for other purposes. */
484 static void command_sconnect(const char *data, SILC_SERVER_REC *server)
486 CMD_SILC_SERVER(server);
487 if (!IS_SILC_SERVER(server) || !server->connected) {
488 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
492 silc_command_exec(server, "CONNECT", data);
498 SILC_TASK_CALLBACK(silc_client_file_close_later)
500 FtpSession ftp = (FtpSession)context;
502 SILC_LOG_DEBUG(("Start"));
504 silc_client_file_close(silc_client, ftp->conn, ftp->session_id);
505 silc_free(ftp->filepath);
509 static void silc_client_file_monitor(SilcClient client,
510 SilcClientConnection conn,
511 SilcClientMonitorStatus status,
512 SilcClientFileError error,
515 SilcClientEntry client_entry,
516 SilcUInt32 session_id,
517 const char *filepath,
520 SILC_SERVER_REC *server = (SILC_SERVER_REC *)context;
524 snprintf(fsize, sizeof(fsize) - 1, "%llu", ((filesize + 1023) / 1024));
526 silc_dlist_start(server->ftp_sessions);
527 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
528 if (ftp->session_id == session_id) {
529 if (!ftp->filepath && filepath)
530 ftp->filepath = strdup(filepath);
535 if (ftp == SILC_LIST_END)
538 if (status == SILC_CLIENT_FILE_MONITOR_ERROR) {
539 if (error == SILC_CLIENT_FILE_NO_SUCH_FILE)
540 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
541 SILCTXT_FILE_ERROR_NO_SUCH_FILE,
542 client_entry->nickname,
543 filepath ? filepath : "[N/A]");
544 else if (error == SILC_CLIENT_FILE_PERMISSION_DENIED)
545 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
546 SILCTXT_FILE_ERROR_PERMISSION_DENIED,
547 client_entry->nickname);
549 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
550 SILCTXT_FILE_ERROR, client_entry->nickname);
551 silc_schedule_task_add(silc_client->schedule, 0,
552 silc_client_file_close_later, ftp,
553 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
554 if (ftp == server->current_session)
555 server->current_session = NULL;
556 silc_dlist_del(server->ftp_sessions, ftp);
559 if (status == SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT) {
560 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
561 SILCTXT_FILE_KEY_EXCHANGE, client_entry->nickname);
564 /* Save some transmission data */
565 if (offset && filesize) {
566 unsigned long delta = time(NULL) - ftp->starttime;
568 ftp->percent = ((double)offset / (double)filesize) * (double)100.0;
570 ftp->kps = (double)((offset / (double)delta) + 1023) / (double)1024;
572 ftp->kps = (double)(offset + 1023) / (double)1024;
573 ftp->offset = offset;
574 ftp->filesize = filesize;
577 if (status == SILC_CLIENT_FILE_MONITOR_SEND) {
579 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
580 SILCTXT_FILE_TRANSMIT, filepath, fsize,
581 client_entry->nickname);
582 ftp->starttime = time(NULL);
584 if (offset == filesize) {
585 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
586 SILCTXT_FILE_TRANSMITTED, filepath, fsize,
587 client_entry->nickname, ftp->kps);
588 silc_schedule_task_add(silc_client->schedule, 0,
589 silc_client_file_close_later, ftp,
590 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
591 if (ftp == server->current_session)
592 server->current_session = NULL;
593 silc_dlist_del(server->ftp_sessions, ftp);
597 if (status == SILC_CLIENT_FILE_MONITOR_RECEIVE) {
599 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
600 SILCTXT_FILE_RECEIVE, filepath, fsize,
601 client_entry->nickname);
602 ftp->starttime = time(NULL);
605 if (offset == filesize) {
606 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
607 SILCTXT_FILE_RECEIVED, filepath, fsize,
608 client_entry->nickname, ftp->kps);
609 silc_schedule_task_add(silc_client->schedule, 0,
610 silc_client_file_close_later, ftp,
611 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
612 if (ftp == server->current_session)
613 server->current_session = NULL;
614 silc_dlist_del(server->ftp_sessions, ftp);
620 SILC_SERVER_REC *server;
626 static void silc_client_command_file_get_clients(SilcClient client,
627 SilcClientConnection conn,
628 SilcClientEntry *clients,
629 SilcUInt32 clients_count,
632 FileGetClients internal = (FileGetClients)context;
635 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
637 silc_free(internal->data);
638 silc_free(internal->nick);
643 signal_emit("command file", 3, internal->data, internal->server,
646 silc_free(internal->data);
647 silc_free(internal->nick);
651 static void command_file(const char *data, SILC_SERVER_REC *server,
654 SilcClientConnection conn;
655 SilcClientEntry *entrys, client_entry;
656 SilcClientFileError ret;
657 SilcUInt32 entry_count;
658 char *nickname = NULL, *tmp;
659 unsigned char **argv;
661 SilcUInt32 *argv_lens, *argv_types;
664 char *local_ip = NULL;
665 SilcUInt32 local_port = 0;
666 SilcUInt32 session_id;
668 CMD_SILC_SERVER(server);
669 if (!server || !IS_SILC_SERVER(server) || !server->connected)
670 cmd_return_error(CMDERR_NOT_CONNECTED);
674 /* Now parse all arguments */
675 tmp = g_strconcat("FILE", " ", data, NULL);
676 silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 6);
683 if (!strcasecmp(argv[1], "send"))
685 if (!strcasecmp(argv[1], "receive"))
687 if (!strcasecmp(argv[1], "close"))
692 cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
697 cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
699 /* Parse the typed nickname. */
700 if (!silc_parse_userfqdn(argv[3], &nickname, NULL)) {
701 printformat_module("fe-common/silc", server, NULL,
702 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[3]);
706 /* Find client entry */
707 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
708 argv[3], &entry_count);
710 FileGetClients inter = silc_calloc(1, sizeof(*inter));
711 inter->server = server;
712 inter->data = strdup(data);
713 inter->nick = strdup(nickname);
715 silc_client_get_clients(silc_client, conn, nickname, argv[3],
716 silc_client_command_file_get_clients, inter);
719 client_entry = entrys[0];
725 local_port = atoi(argv[5]);
728 silc_client_file_send(silc_client, conn, silc_client_file_monitor,
729 server, local_ip, local_port,
730 client_entry, argv[2], &session_id);
731 if (ret == SILC_CLIENT_FILE_OK) {
732 ftp = silc_calloc(1, sizeof(*ftp));
733 ftp->session_id = session_id;
735 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
736 SILCTXT_FILE_SEND, client_entry->nickname,
739 ftp->client_entry = client_entry;
740 ftp->filepath = strdup(argv[2]);
743 silc_dlist_add(server->ftp_sessions, ftp);
744 server->current_session = ftp;
746 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
747 printformat_module("fe-common/silc", server, NULL,
748 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
749 client_entry->nickname);
750 if (ret == SILC_CLIENT_FILE_NO_SUCH_FILE)
751 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
752 SILCTXT_FILE_ERROR_NO_SUCH_FILE,
753 client_entry->nickname, argv[2]);
759 /* Parse the typed nickname. */
761 if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
762 printformat_module("fe-common/silc", server, NULL,
763 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
767 /* Find client entry */
768 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
769 argv[2], &entry_count);
771 FileGetClients inter = silc_calloc(1, sizeof(*inter));
772 inter->server = server;
773 inter->data = strdup(data);
774 inter->nick = strdup(nickname);
776 silc_client_get_clients(silc_client, conn, nickname, argv[2],
777 silc_client_command_file_get_clients, inter);
780 client_entry = entrys[0];
783 if (!server->current_session) {
784 printformat_module("fe-common/silc", server, NULL,
785 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
789 ret = silc_client_file_receive(silc_client, conn,
790 silc_client_file_monitor, server, NULL,
791 server->current_session->session_id);
792 if (ret != SILC_CLIENT_FILE_OK) {
793 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
794 printformat_module("fe-common/silc", server, NULL,
795 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
796 server->current_session->client_entry->nickname);
798 printformat_module("fe-common/silc", server, NULL,
799 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
800 server->current_session->client_entry->nickname);
806 silc_dlist_start(server->ftp_sessions);
807 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
808 if (ftp->client_entry == client_entry && !ftp->filepath) {
809 ret = silc_client_file_receive(silc_client, conn,
810 silc_client_file_monitor, server,
811 NULL, ftp->session_id);
812 if (ret != SILC_CLIENT_FILE_OK) {
813 if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
814 printformat_module("fe-common/silc", server, NULL,
815 MSGLEVEL_CRAP, SILCTXT_FILE_ALREADY_STARTED,
816 client_entry->nickname);
818 printformat_module("fe-common/silc", server, NULL,
819 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
820 client_entry->nickname);
826 if (ftp == SILC_LIST_END) {
827 printformat_module("fe-common/silc", server, NULL,
828 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
829 client_entry->nickname);
835 /* Parse the typed nickname. */
837 if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
838 printformat_module("fe-common/silc", server, NULL,
839 MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
843 /* Find client entry */
844 entrys = silc_client_get_clients_local(silc_client, conn, nickname,
845 argv[2], &entry_count);
847 FileGetClients inter = silc_calloc(1, sizeof(*inter));
848 inter->server = server;
849 inter->data = strdup(data);
850 inter->nick = strdup(nickname);
852 silc_client_get_clients(silc_client, conn, nickname, argv[2],
853 silc_client_command_file_get_clients, inter);
856 client_entry = entrys[0];
859 if (!server->current_session) {
860 printformat_module("fe-common/silc", server, NULL,
861 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
865 silc_client_file_close(silc_client, conn,
866 server->current_session->session_id);
867 printformat_module("fe-common/silc", server, NULL,
868 MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
869 server->current_session->client_entry->nickname,
870 server->current_session->filepath ?
871 server->current_session->filepath : "[N/A]");
872 silc_dlist_del(server->ftp_sessions, server->current_session);
873 silc_free(server->current_session->filepath);
874 silc_free(server->current_session);
875 server->current_session = NULL;
879 silc_dlist_start(server->ftp_sessions);
880 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
881 if (ftp->client_entry == client_entry) {
882 silc_client_file_close(silc_client, conn, ftp->session_id);
883 printformat_module("fe-common/silc", server, NULL,
884 MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
885 client_entry->nickname,
886 ftp->filepath ? ftp->filepath : "[N/A]");
887 if (ftp == server->current_session)
888 server->current_session = NULL;
889 silc_dlist_del(server->ftp_sessions, ftp);
890 silc_free(ftp->filepath);
896 if (ftp == SILC_LIST_END) {
897 printformat_module("fe-common/silc", server, NULL,
898 MSGLEVEL_CRAP, SILCTXT_FILE_CLIENT_NA,
899 client_entry->nickname);
906 if (!silc_dlist_count(server->ftp_sessions)) {
907 printformat_module("fe-common/silc", server, NULL,
908 MSGLEVEL_CRAP, SILCTXT_FILE_NA);
912 printformat_module("fe-common/silc", server, NULL,
913 MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_HEADER);
915 silc_dlist_start(server->ftp_sessions);
916 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
917 printformat_module("fe-common/silc", server, NULL,
918 MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_LINE,
919 ftp->client_entry->nickname,
920 ftp->send ? "send" : "receive",
921 (SilcUInt32)(ftp->offset + 1023) / 1024,
922 (SilcUInt32)(ftp->filesize + 1023) / 1024,
923 ftp->percent, ftp->kps,
924 ftp->filepath ? ftp->filepath : "[N/A]");
937 void silc_server_init(void)
939 silc_servers_reconnect_init();
941 signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
942 signal_add("server disconnected", (SIGNAL_FUNC) sig_disconnected);
943 signal_add("mime-send", (SIGNAL_FUNC)silc_send_mime);
944 command_bind_silc("whois", MODULE_NAME, (SIGNAL_FUNC) command_self);
945 command_bind_silc("whowas", MODULE_NAME, (SIGNAL_FUNC) command_self);
946 command_bind_silc("nick", MODULE_NAME, (SIGNAL_FUNC) command_self);
947 command_bind_silc("topic", MODULE_NAME, (SIGNAL_FUNC) command_self);
948 command_bind_silc("cmode", MODULE_NAME, (SIGNAL_FUNC) command_self);
949 command_bind_silc("cumode", MODULE_NAME, (SIGNAL_FUNC) command_self);
950 command_bind_silc("users", MODULE_NAME, (SIGNAL_FUNC) command_self);
951 command_bind_silc("list", MODULE_NAME, (SIGNAL_FUNC) command_self);
952 command_bind_silc("ban", MODULE_NAME, (SIGNAL_FUNC) command_self);
953 command_bind_silc("oper", MODULE_NAME, (SIGNAL_FUNC) command_self);
954 command_bind_silc("silcoper", MODULE_NAME, (SIGNAL_FUNC) command_self);
955 command_bind_silc("umode", MODULE_NAME, (SIGNAL_FUNC) command_self);
956 command_bind_silc("invite", MODULE_NAME, (SIGNAL_FUNC) command_self);
957 command_bind_silc("kill", MODULE_NAME, (SIGNAL_FUNC) command_self);
958 command_bind_silc("kick", MODULE_NAME, (SIGNAL_FUNC) command_self);
959 command_bind_silc("info", MODULE_NAME, (SIGNAL_FUNC) command_self);
960 command_bind_silc("ping", MODULE_NAME, (SIGNAL_FUNC) command_self);
961 command_bind_silc("motd", MODULE_NAME, (SIGNAL_FUNC) command_self);
962 command_bind_silc("close", MODULE_NAME, (SIGNAL_FUNC) command_self);
963 command_bind_silc("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
964 command_bind_silc("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
965 command_bind_silc("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
966 command_bind_silc("file", MODULE_NAME, (SIGNAL_FUNC) command_file);
967 command_bind_silc("detach", MODULE_NAME, (SIGNAL_FUNC) command_self);
968 command_bind_silc("watch", MODULE_NAME, (SIGNAL_FUNC) command_self);
970 command_set_options("connect", "+silcnet");
973 void silc_server_deinit(void)
975 silc_servers_reconnect_deinit();
977 signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
978 signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
979 signal_remove("mime-send", (SIGNAL_FUNC)silc_send_mime);
980 command_unbind("whois", (SIGNAL_FUNC) command_self);
981 command_unbind("whowas", (SIGNAL_FUNC) command_self);
982 command_unbind("nick", (SIGNAL_FUNC) command_self);
983 command_unbind("topic", (SIGNAL_FUNC) command_self);
984 command_unbind("cmode", (SIGNAL_FUNC) command_self);
985 command_unbind("cumode", (SIGNAL_FUNC) command_self);
986 command_unbind("users", (SIGNAL_FUNC) command_self);
987 command_unbind("list", (SIGNAL_FUNC) command_self);
988 command_unbind("oper", (SIGNAL_FUNC) command_self);
989 command_unbind("silcoper", (SIGNAL_FUNC) command_self);
990 command_unbind("umode", (SIGNAL_FUNC) command_self);
991 command_unbind("invite", (SIGNAL_FUNC) command_self);
992 command_unbind("kill", (SIGNAL_FUNC) command_self);
993 command_unbind("kick", (SIGNAL_FUNC) command_self);
994 command_unbind("info", (SIGNAL_FUNC) command_self);
995 command_unbind("ping", (SIGNAL_FUNC) command_self);
996 command_unbind("motd", (SIGNAL_FUNC) command_self);
997 command_unbind("ban", (SIGNAL_FUNC) command_self);
998 command_unbind("close", (SIGNAL_FUNC) command_self);
999 command_unbind("shutdown", (SIGNAL_FUNC) command_self);
1000 command_unbind("getkey", (SIGNAL_FUNC) command_self);
1001 command_unbind("sconnect", (SIGNAL_FUNC) command_sconnect);
1002 command_unbind("file", (SIGNAL_FUNC) command_file);
1003 command_unbind("detach", (SIGNAL_FUNC) command_self);
1004 command_unbind("watch", (SIGNAL_FUNC) command_self);
1007 void silc_server_free_ftp(SILC_SERVER_REC *server,
1008 SilcClientEntry client_entry)
1012 silc_dlist_start(server->ftp_sessions);
1013 while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
1014 if (ftp->client_entry == client_entry) {
1015 silc_dlist_del(server->ftp_sessions, ftp);
1016 silc_free(ftp->filepath);
1022 bool silc_term_utf8(void)
1025 str = settings_get_str("term_type");
1027 if (g_strcasecmp(str, "utf-8") == 0)