5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 2001 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
22 #include "chat-protocols.h"
26 #include "servers-setup.h"
27 #include "channels-setup.h"
28 #include "silc-servers.h"
29 #include "silc-channels.h"
30 #include "silc-queries.h"
31 #include "silc-nicklist.h"
36 #include "fe-common/core/printtext.h"
37 #include "fe-common/core/fe-channels.h"
38 #include "fe-common/core/keyboard.h"
39 #include "fe-common/silc/module-formats.h"
44 silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
45 const char *name, SilcSocketType conn_type,
46 unsigned char *pk, SilcUInt32 pk_len,
47 SilcSKEPKType pk_type,
48 SilcVerifyPublicKey completion, void *context);
50 static void silc_get_umode_string(SilcUInt32 mode, char *buf,
53 if ((mode & SILC_UMODE_SERVER_OPERATOR) ||
54 (mode & SILC_UMODE_ROUTER_OPERATOR)) {
55 strcat(buf, (mode & SILC_UMODE_SERVER_OPERATOR) ?
57 (mode & SILC_UMODE_ROUTER_OPERATOR) ?
58 "[SILC operator]" : "[unknown mode]");
60 if (mode & SILC_UMODE_GONE)
61 strcat(buf, " [away]");
62 if (mode & SILC_UMODE_INDISPOSED)
63 strcat(buf, " [indisposed]");
64 if (mode & SILC_UMODE_BUSY)
65 strcat(buf, " [busy]");
66 if (mode & SILC_UMODE_PAGE)
67 strcat(buf, " [page to reach]");
68 if (mode & SILC_UMODE_HYPER)
69 strcat(buf, " [hyper active]");
70 if (mode & SILC_UMODE_ROBOT)
71 strcat(buf, " [robot]");
72 if (mode & SILC_UMODE_ANONYMOUS)
73 strcat(buf, " [anonymous]");
74 if (mode & SILC_UMODE_BLOCK_PRIVMSG)
75 strcat(buf, " [blocks private messages]");
76 if (mode & SILC_UMODE_DETACHED)
77 strcat(buf, " [detached]");
78 if (mode & SILC_UMODE_REJECT_WATCHING)
79 strcat(buf, " [rejects watching]");
80 if (mode & SILC_UMODE_BLOCK_INVITE)
81 strcat(buf, " [blocks invites]");
84 void silc_say(SilcClient client, SilcClientConnection conn,
85 SilcClientMessageType type, char *msg, ...)
87 SILC_SERVER_REC *server;
91 server = conn == NULL ? NULL : conn->context;
94 str = g_strdup_vprintf(msg, va);
95 printtext(server, NULL, MSGLEVEL_CRAP, "%s", str);
100 void silc_say_error(char *msg, ...)
106 str = g_strdup_vprintf(msg, va);
107 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "%s", str);
113 /* Message for a channel. The `sender' is the nickname of the sender
114 received in the packet. The `channel_name' is the name of the channel. */
116 void silc_channel_message(SilcClient client, SilcClientConnection conn,
117 SilcClientEntry sender, SilcChannelEntry channel,
118 SilcMessageFlags flags, const unsigned char *message,
119 SilcUInt32 message_len)
121 SILC_SERVER_REC *server;
123 SILC_CHANNEL_REC *chanrec;
125 SILC_LOG_DEBUG(("Start"));
130 server = conn == NULL ? NULL : conn->context;
131 chanrec = silc_channel_find_entry(server, channel);
135 nick = silc_nicklist_find(chanrec, sender);
137 /* We didn't find client but it clearly exists, add it. */
138 SilcChannelUser chu = silc_client_on_channel(channel, sender);
140 nick = silc_nicklist_insert(chanrec, chu, FALSE);
143 if (flags & SILC_MESSAGE_FLAG_DATA) {
144 /* MIME object received, try to display it as well as we can */
145 char type[128], enc[128];
149 memset(type, 0, sizeof(type));
150 memset(enc, 0, sizeof(enc));
151 if (!silc_mime_parse(message, message_len, NULL, 0, type, sizeof(type) - 1,
152 enc, sizeof(enc) - 1, &data, &data_len))
155 /* Then figure out what we can display */
156 if (strstr(type, "text/") && !strstr(type, "text/t140") &&
157 !strstr(type, "text/vnd")) {
158 /* It is something textual, display it */
159 message = (const unsigned char *)data;
161 printformat_module("fe-common/silc", server, channel->channel_name,
162 MSGLEVEL_CRAP, SILCTXT_MESSAGE_DATA,
163 nick == NULL ? "[<unknown>]" : nick->nick, type);
171 if (flags & SILC_MESSAGE_FLAG_ACTION)
172 printformat_module("fe-common/silc", server, channel->channel_name,
173 MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_ACTION,
174 nick == NULL ? "[<unknown>]" : nick->nick, message);
175 else if (flags & SILC_MESSAGE_FLAG_NOTICE)
176 printformat_module("fe-common/silc", server, channel->channel_name,
177 MSGLEVEL_NOTICES, SILCTXT_CHANNEL_NOTICE,
178 nick == NULL ? "[<unknown>]" : nick->nick, message);
180 if (flags & SILC_MESSAGE_FLAG_UTF8 && !silc_term_utf8()) {
181 char tmp[256], *cp, *dm = NULL;
183 memset(tmp, 0, sizeof(tmp));
185 if (message_len > sizeof(tmp) - 1) {
186 dm = silc_calloc(message_len + 1, sizeof(*dm));
190 silc_utf8_decode(message, message_len, SILC_STRING_LANGUAGE,
192 signal_emit("message public", 6, server, cp,
193 nick == NULL ? "[<unknown>]" : nick->nick,
194 nick == NULL ? "" : nick->host == NULL ? "" : nick->host,
195 chanrec->name, nick);
200 signal_emit("message public", 6, server, message,
201 nick == NULL ? "[<unknown>]" : nick->nick,
202 nick == NULL ? "" : nick->host == NULL ? "" : nick->host,
203 chanrec->name, nick);
207 /* Private message to the client. The `sender' is the nickname of the
208 sender received in the packet. */
210 void silc_private_message(SilcClient client, SilcClientConnection conn,
211 SilcClientEntry sender, SilcMessageFlags flags,
212 const unsigned char *message,
213 SilcUInt32 message_len)
215 SILC_SERVER_REC *server;
218 SILC_LOG_DEBUG(("Start"));
220 server = conn == NULL ? NULL : conn->context;
221 memset(userhost, 0, sizeof(userhost));
222 if (sender->username)
223 snprintf(userhost, sizeof(userhost) - 1, "%s@%s",
224 sender->username, sender->hostname);
226 if (flags & SILC_MESSAGE_FLAG_DATA) {
227 /* MIME object received, try to display it as well as we can */
228 char type[128], enc[128];
232 memset(type, 0, sizeof(type));
233 memset(enc, 0, sizeof(enc));
234 if (!silc_mime_parse(message, message_len, NULL, 0, type, sizeof(type) - 1,
235 enc, sizeof(enc) - 1, &data, &data_len))
238 /* Then figure out what we can display */
239 if (strstr(type, "text/") && !strstr(type, "text/t140") &&
240 !strstr(type, "text/vnd")) {
241 /* It is something textual, display it */
242 message = (const unsigned char *)data;
244 printformat_module("fe-common/silc", server, NULL,
245 MSGLEVEL_CRAP, SILCTXT_MESSAGE_DATA,
246 sender->nickname ? sender->nickname : "[<unknown>]",
255 if (flags & SILC_MESSAGE_FLAG_UTF8 && !silc_term_utf8()) {
256 char tmp[256], *cp, *dm = NULL;
258 memset(tmp, 0, sizeof(tmp));
260 if (message_len > sizeof(tmp) - 1) {
261 dm = silc_calloc(message_len + 1, sizeof(*dm));
265 silc_utf8_decode(message, message_len, SILC_STRING_LANGUAGE,
267 signal_emit("message private", 4, server, cp,
268 sender->nickname ? sender->nickname : "[<unknown>]",
269 sender->username ? userhost : NULL);
274 signal_emit("message private", 4, server, message,
275 sender->nickname ? sender->nickname : "[<unknown>]",
276 sender->username ? userhost : NULL);
279 /* Notify message to the client. The notify arguments are sent in the
280 same order as servers sends them. The arguments are same as received
281 from the server except for ID's. If ID is received application receives
282 the corresponding entry to the ID. For example, if Client ID is received
283 application receives SilcClientEntry. Also, if the notify type is
284 for channel the channel entry is sent to application (even if server
285 does not send it). */
287 void silc_notify(SilcClient client, SilcClientConnection conn,
288 SilcNotifyType type, ...)
291 SILC_SERVER_REC *server;
292 SILC_CHANNEL_REC *chanrec;
293 SILC_NICK_REC *nickrec;
294 SilcClientEntry client_entry, client_entry2;
295 SilcChannelEntry channel, channel2;
296 SilcServerEntry server_entry;
302 GSList *list1, *list_tmp;
304 SILC_LOG_DEBUG(("Start"));
308 server = conn == NULL ? NULL : conn->context;
311 case SILC_NOTIFY_TYPE_NONE:
312 /* Some generic notice from server */
313 printtext(server, NULL, MSGLEVEL_CRAP, "%s", (char *)va_arg(va, char *));
316 case SILC_NOTIFY_TYPE_INVITE:
318 * Invited or modified invite list.
321 SILC_LOG_DEBUG(("Notify: INVITE"));
323 channel = va_arg(va, SilcChannelEntry);
324 name = va_arg(va, char *);
325 client_entry = va_arg(va, SilcClientEntry);
327 memset(buf, 0, sizeof(buf));
328 snprintf(buf, sizeof(buf) - 1, "%s@%s",
329 client_entry->username, client_entry->hostname);
330 signal_emit("message invite", 4, server, channel ? channel->channel_name :
331 name, client_entry->nickname, buf);
334 case SILC_NOTIFY_TYPE_JOIN:
339 SILC_LOG_DEBUG(("Notify: JOIN"));
341 client_entry = va_arg(va, SilcClientEntry);
342 channel = va_arg(va, SilcChannelEntry);
344 if (client_entry == server->conn->local_entry) {
345 /* You joined to channel */
346 chanrec = silc_channel_find(server, channel->channel_name);
347 if (chanrec != NULL && !chanrec->joined)
348 chanrec->entry = channel;
350 chanrec = silc_channel_find_entry(server, channel);
351 if (chanrec != NULL) {
352 SilcChannelUser chu = silc_client_on_channel(channel, client_entry);
354 nickrec = silc_nicklist_insert(chanrec, chu, TRUE);
358 memset(buf, 0, sizeof(buf));
359 if (client_entry->username)
360 snprintf(buf, sizeof(buf) - 1, "%s@%s",
361 client_entry->username, client_entry->hostname);
362 signal_emit("message join", 4, server, channel->channel_name,
363 client_entry->nickname,
364 client_entry->username == NULL ? "" : buf);
367 case SILC_NOTIFY_TYPE_LEAVE:
372 SILC_LOG_DEBUG(("Notify: LEAVE"));
374 client_entry = va_arg(va, SilcClientEntry);
375 channel = va_arg(va, SilcChannelEntry);
377 memset(buf, 0, sizeof(buf));
378 if (client_entry->username)
379 snprintf(buf, sizeof(buf) - 1, "%s@%s",
380 client_entry->username, client_entry->hostname);
381 signal_emit("message part", 5, server, channel->channel_name,
382 client_entry->nickname, client_entry->username ?
383 buf : "", client_entry->nickname);
385 chanrec = silc_channel_find_entry(server, channel);
386 if (chanrec != NULL) {
387 nickrec = silc_nicklist_find(chanrec, client_entry);
389 nicklist_remove(CHANNEL(chanrec), NICK(nickrec));
393 case SILC_NOTIFY_TYPE_SIGNOFF:
398 SILC_LOG_DEBUG(("Notify: SIGNOFF"));
400 client_entry = va_arg(va, SilcClientEntry);
401 tmp = va_arg(va, char *);
403 silc_server_free_ftp(server, client_entry);
405 memset(buf, 0, sizeof(buf));
406 if (client_entry->username)
407 snprintf(buf, sizeof(buf) - 1, "%s@%s",
408 client_entry->username, client_entry->hostname);
409 signal_emit("message quit", 4, server, client_entry->nickname,
410 client_entry->username ? buf : "",
413 list1 = nicklist_get_same_unique(SERVER(server), client_entry);
414 for (list_tmp = list1; list_tmp != NULL; list_tmp =
415 list_tmp->next->next) {
416 CHANNEL_REC *channel = list_tmp->data;
417 NICK_REC *nickrec = list_tmp->next->data;
419 nicklist_remove(channel, nickrec);
423 case SILC_NOTIFY_TYPE_TOPIC_SET:
428 SILC_LOG_DEBUG(("Notify: TOPIC_SET"));
430 idtype = va_arg(va, int);
431 entry = va_arg(va, void *);
432 tmp = va_arg(va, char *);
433 channel = va_arg(va, SilcChannelEntry);
435 chanrec = silc_channel_find_entry(server, channel);
436 if (chanrec != NULL) {
437 g_free_not_null(chanrec->topic);
438 chanrec->topic = *tmp == '\0' ? NULL : g_strdup(tmp);
439 signal_emit("channel topic changed", 1, chanrec);
442 if (idtype == SILC_ID_CLIENT) {
443 client_entry = (SilcClientEntry)entry;
444 memset(buf, 0, sizeof(buf));
445 snprintf(buf, sizeof(buf) - 1, "%s@%s",
446 client_entry->username, client_entry->hostname);
447 signal_emit("message topic", 5, server, channel->channel_name,
448 tmp, client_entry->nickname, buf);
449 } else if (idtype == SILC_ID_SERVER) {
450 server_entry = (SilcServerEntry)entry;
451 signal_emit("message topic", 5, server, channel->channel_name,
452 tmp, server_entry->server_name,
453 server_entry->server_name);
454 } else if (idtype == SILC_ID_CHANNEL) {
455 channel = (SilcChannelEntry)entry;
456 signal_emit("message topic", 5, server, channel->channel_name,
457 tmp, channel->channel_name, channel->channel_name);
461 case SILC_NOTIFY_TYPE_NICK_CHANGE:
466 SILC_LOG_DEBUG(("Notify: NICK_CHANGE"));
468 client_entry = va_arg(va, SilcClientEntry);
469 client_entry2 = va_arg(va, SilcClientEntry);
471 if (!strcmp(client_entry->nickname, client_entry2->nickname))
474 memset(buf, 0, sizeof(buf));
475 snprintf(buf, sizeof(buf) - 1, "%s@%s",
476 client_entry2->username, client_entry2->hostname);
477 nicklist_rename_unique(SERVER(server),
478 client_entry, client_entry->nickname,
479 client_entry2, client_entry2->nickname);
480 signal_emit("message nick", 4, server, client_entry2->nickname,
481 client_entry->nickname, buf);
484 case SILC_NOTIFY_TYPE_CMODE_CHANGE:
486 * Changed channel mode.
489 SILC_LOG_DEBUG(("Notify: CMODE_CHANGE"));
491 idtype = va_arg(va, int);
492 entry = va_arg(va, void *);
493 mode = va_arg(va, SilcUInt32);
494 (void)va_arg(va, char *);
495 (void)va_arg(va, char *);
496 channel = va_arg(va, SilcChannelEntry);
498 tmp = silc_client_chmode(mode,
499 channel->channel_key ?
500 silc_cipher_get_name(channel->channel_key) : "",
502 silc_hmac_get_name(channel->hmac) : "");
504 chanrec = silc_channel_find_entry(server, channel);
505 if (chanrec != NULL) {
506 g_free_not_null(chanrec->mode);
507 chanrec->mode = g_strdup(tmp == NULL ? "" : tmp);
508 signal_emit("channel mode changed", 1, chanrec);
511 if (idtype == SILC_ID_CLIENT) {
512 client_entry = (SilcClientEntry)entry;
513 printformat_module("fe-common/silc", server, channel->channel_name,
514 MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE,
515 channel->channel_name, tmp ? tmp : "removed all",
516 client_entry->nickname);
517 } else if (idtype == SILC_ID_SERVER) {
518 server_entry = (SilcServerEntry)entry;
519 printformat_module("fe-common/silc", server, channel->channel_name,
520 MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE,
521 channel->channel_name, tmp ? tmp : "removed all",
522 server_entry->server_name);
523 } else if (idtype == SILC_ID_CHANNEL) {
524 channel2 = (SilcChannelEntry)entry;
525 printformat_module("fe-common/silc", server, channel->channel_name,
526 MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE,
527 channel->channel_name, tmp ? tmp : "removed all",
528 channel2->channel_name);
534 case SILC_NOTIFY_TYPE_CUMODE_CHANGE:
536 * Changed user's mode on channel.
539 SILC_LOG_DEBUG(("Notify: CUMODE_CHANGE"));
541 idtype = va_arg(va, int);
542 entry = va_arg(va, void *);
543 mode = va_arg(va, SilcUInt32);
544 client_entry2 = va_arg(va, SilcClientEntry);
545 channel = va_arg(va, SilcChannelEntry);
547 tmp = silc_client_chumode(mode);
548 chanrec = silc_channel_find_entry(server, channel);
549 if (chanrec != NULL) {
552 if (client_entry2 == server->conn->local_entry)
553 chanrec->chanop = (mode & SILC_CHANNEL_UMODE_CHANOP) != 0;
555 nick = silc_nicklist_find(chanrec, client_entry2);
557 nick->op = (mode & SILC_CHANNEL_UMODE_CHANOP) != 0;
558 nick->founder = (mode & SILC_CHANNEL_UMODE_CHANFO) != 0;
559 signal_emit("nick mode changed", 2, chanrec, nick);
563 if (idtype == SILC_ID_CLIENT) {
564 client_entry = (SilcClientEntry)entry;
565 printformat_module("fe-common/silc", server, channel->channel_name,
566 MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE,
567 channel->channel_name, client_entry2->nickname,
568 tmp ? tmp : "removed all",
569 client_entry->nickname);
570 } else if (idtype == SILC_ID_SERVER) {
571 server_entry = (SilcServerEntry)entry;
572 printformat_module("fe-common/silc", server, channel->channel_name,
573 MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE,
574 channel->channel_name, client_entry2->nickname,
575 tmp ? tmp : "removed all",
576 server_entry->server_name);
577 } else if (idtype == SILC_ID_CHANNEL) {
578 channel2 = (SilcChannelEntry)entry;
579 printformat_module("fe-common/silc", server, channel->channel_name,
580 MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE,
581 channel->channel_name, client_entry2->nickname,
582 tmp ? tmp : "removed all",
583 channel2->channel_name);
586 if (mode & SILC_CHANNEL_UMODE_CHANFO)
587 printformat_module("fe-common/silc",
588 server, channel->channel_name, MSGLEVEL_CRAP,
589 SILCTXT_CHANNEL_FOUNDER,
590 channel->channel_name, client_entry2->nickname);
592 if (mode & SILC_CHANNEL_UMODE_QUIET && conn->local_entry == client_entry2)
593 printformat_module("fe-common/silc",
594 server, channel->channel_name, MSGLEVEL_CRAP,
595 SILCTXT_CHANNEL_QUIETED, channel->channel_name);
600 case SILC_NOTIFY_TYPE_MOTD:
605 SILC_LOG_DEBUG(("Notify: MOTD"));
607 tmp = va_arg(va, char *);
609 if (!settings_get_bool("skip_motd"))
610 printtext_multiline(server, NULL, MSGLEVEL_CRAP, "%s", tmp);
613 case SILC_NOTIFY_TYPE_KICKED:
615 * Someone was kicked from channel.
618 SILC_LOG_DEBUG(("Notify: KICKED"));
620 client_entry = va_arg(va, SilcClientEntry);
621 tmp = va_arg(va, char *);
622 client_entry2 = va_arg(va, SilcClientEntry);
623 channel = va_arg(va, SilcChannelEntry);
625 chanrec = silc_channel_find_entry(server, channel);
627 if (client_entry == conn->local_entry) {
628 printformat_module("fe-common/silc", server, channel->channel_name,
629 MSGLEVEL_CRAP, SILCTXT_CHANNEL_KICKED_YOU,
630 channel->channel_name,
631 client_entry ? client_entry2->nickname : "",
634 chanrec->kicked = TRUE;
635 channel_destroy((CHANNEL_REC *)chanrec);
638 printformat_module("fe-common/silc", server, channel->channel_name,
639 MSGLEVEL_CRAP, SILCTXT_CHANNEL_KICKED,
640 client_entry->nickname, channel->channel_name,
641 client_entry2 ? client_entry2->nickname : "",
645 SILC_NICK_REC *nickrec = silc_nicklist_find(chanrec, client_entry);
647 nicklist_remove(CHANNEL(chanrec), NICK(nickrec));
652 case SILC_NOTIFY_TYPE_KILLED:
654 * Someone was killed from the network.
657 SILC_LOG_DEBUG(("Notify: KILLED"));
659 client_entry = va_arg(va, SilcClientEntry);
660 tmp = va_arg(va, char *);
661 idtype = va_arg(va, int);
662 entry = va_arg(va, SilcClientEntry);
664 if (client_entry == conn->local_entry) {
665 if (idtype == SILC_ID_CLIENT) {
666 client_entry2 = (SilcClientEntry)entry;
667 printformat_module("fe-common/silc", server, NULL,
668 MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED_YOU,
669 client_entry2 ? client_entry2->nickname : "",
671 } else if (idtype == SILC_ID_SERVER) {
672 server_entry = (SilcServerEntry)entry;
673 printformat_module("fe-common/silc", server, NULL,
674 MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED_YOU,
675 server_entry->server_name, tmp ? tmp : "");
676 } else if (idtype == SILC_ID_CHANNEL) {
677 channel = (SilcChannelEntry)entry;
678 printformat_module("fe-common/silc", server, NULL,
679 MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED_YOU,
680 channel->channel_name, tmp ? tmp : "");
683 list1 = nicklist_get_same_unique(SERVER(server), client_entry);
684 for (list_tmp = list1; list_tmp != NULL; list_tmp =
685 list_tmp->next->next) {
686 CHANNEL_REC *channel = list_tmp->data;
687 NICK_REC *nickrec = list_tmp->next->data;
688 nicklist_remove(channel, nickrec);
691 if (idtype == SILC_ID_CLIENT) {
692 client_entry2 = (SilcClientEntry)entry;
693 printformat_module("fe-common/silc", server, NULL,
694 MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED,
695 client_entry->nickname,
696 client_entry2 ? client_entry2->nickname : "",
698 } else if (idtype == SILC_ID_SERVER) {
699 server_entry = (SilcServerEntry)entry;
700 printformat_module("fe-common/silc", server, NULL,
701 MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED,
702 client_entry->nickname,
703 server_entry->server_name, tmp ? tmp : "");
704 } else if (idtype == SILC_ID_CHANNEL) {
705 channel = (SilcChannelEntry)entry;
706 printformat_module("fe-common/silc", server, NULL,
707 MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED,
708 client_entry->nickname,
709 channel->channel_name, tmp ? tmp : "");
714 case SILC_NOTIFY_TYPE_CHANNEL_CHANGE:
717 case SILC_NOTIFY_TYPE_SERVER_SIGNOFF:
720 * Server has quit the network.
723 SilcClientEntry *clients;
724 SilcUInt32 clients_count;
726 SILC_LOG_DEBUG(("Notify: SIGNOFF"));
728 (void)va_arg(va, void *);
729 clients = va_arg(va, SilcClientEntry *);
730 clients_count = va_arg(va, SilcUInt32);
732 for (i = 0; i < clients_count; i++) {
733 memset(buf, 0, sizeof(buf));
734 if (clients[i]->username)
735 snprintf(buf, sizeof(buf) - 1, "%s@%s",
736 clients[i]->username, clients[i]->hostname);
737 signal_emit("message quit", 4, server, clients[i]->nickname,
738 clients[i]->username ? buf : "",
741 silc_server_free_ftp(server, clients[i]);
743 list1 = nicklist_get_same_unique(SERVER(server), clients[i]);
744 for (list_tmp = list1; list_tmp != NULL; list_tmp =
745 list_tmp->next->next) {
746 CHANNEL_REC *channel = list_tmp->data;
747 NICK_REC *nickrec = list_tmp->next->data;
748 nicklist_remove(channel, nickrec);
754 case SILC_NOTIFY_TYPE_ERROR:
756 SilcStatus error = va_arg(va, int);
758 silc_say(client, conn, SILC_CLIENT_MESSAGE_ERROR,
759 "%s", silc_get_status_message(error));
763 case SILC_NOTIFY_TYPE_WATCH:
765 SilcNotifyType notify;
767 client_entry = va_arg(va, SilcClientEntry);
768 name = va_arg(va, char *); /* Maybe NULL */
769 mode = va_arg(va, SilcUInt32);
770 notify = va_arg(va, int);
772 if (notify == SILC_NOTIFY_TYPE_NICK_CHANGE) {
774 printformat_module("fe-common/silc", server, NULL,
775 MSGLEVEL_CRAP, SILCTXT_WATCH_NICK_CHANGE,
776 client_entry->nickname, name);
778 printformat_module("fe-common/silc", server, NULL,
779 MSGLEVEL_CRAP, SILCTXT_WATCH_PRESENT,
780 client_entry->nickname);
781 } else if (notify == SILC_NOTIFY_TYPE_UMODE_CHANGE) {
782 /* See if client was away and is now present */
783 if (!(mode & (SILC_UMODE_GONE | SILC_UMODE_INDISPOSED |
784 SILC_UMODE_BUSY | SILC_UMODE_PAGE |
785 SILC_UMODE_DETACHED)) &&
786 (client_entry->mode & SILC_UMODE_GONE ||
787 client_entry->mode & SILC_UMODE_INDISPOSED ||
788 client_entry->mode & SILC_UMODE_BUSY ||
789 client_entry->mode & SILC_UMODE_PAGE ||
790 client_entry->mode & SILC_UMODE_DETACHED)) {
791 printformat_module("fe-common/silc", server, NULL,
792 MSGLEVEL_CRAP, SILCTXT_WATCH_PRESENT,
793 client_entry->nickname);
797 memset(buf, 0, sizeof(buf));
798 silc_get_umode_string(mode, buf, sizeof(buf) - 1);
799 printformat_module("fe-common/silc", server, NULL,
800 MSGLEVEL_CRAP, SILCTXT_WATCH_UMODE_CHANGE,
801 client_entry->nickname, buf);
803 } else if (notify == SILC_NOTIFY_TYPE_KILLED) {
804 printformat_module("fe-common/silc", server, NULL,
805 MSGLEVEL_CRAP, SILCTXT_WATCH_KILLED,
806 client_entry->nickname);
807 } else if (notify == SILC_NOTIFY_TYPE_SIGNOFF ||
808 notify == SILC_NOTIFY_TYPE_SERVER_SIGNOFF) {
809 printformat_module("fe-common/silc", server, NULL,
810 MSGLEVEL_CRAP, SILCTXT_WATCH_SIGNOFF,
811 client_entry->nickname);
812 } else if (notify == SILC_NOTIFY_TYPE_NONE) {
813 /* Client logged in to the network */
814 printformat_module("fe-common/silc", server, NULL,
815 MSGLEVEL_CRAP, SILCTXT_WATCH_PRESENT,
816 client_entry->nickname);
823 printformat_module("fe-common/silc", server, NULL,
824 MSGLEVEL_CRAP, SILCTXT_UNKNOWN_NOTIFY, type);
831 /* Called to indicate that connection was either successfully established
832 or connecting failed. This is also the first time application receives
833 the SilcClientConnection object which it should save somewhere. */
835 void silc_connect(SilcClient client, SilcClientConnection conn,
836 SilcClientConnectionStatus status)
838 SILC_SERVER_REC *server = conn->context;
840 if (!server || server->disconnected) {
841 silc_client_close_connection(client, conn);
846 case SILC_CLIENT_CONN_SUCCESS:
847 /* We have successfully connected to server */
848 server->connected = TRUE;
849 signal_emit("event connected", 1, server);
852 case SILC_CLIENT_CONN_SUCCESS_RESUME:
853 /* We have successfully resumed old detached session */
854 server->connected = TRUE;
855 signal_emit("event connected", 1, server);
857 /* If we resumed old session check whether we need to update
859 if (strcmp(server->nick, conn->local_entry->nickname)) {
861 old = g_strdup(server->nick);
862 server_change_nick(SERVER(server), conn->local_entry->nickname);
863 nicklist_rename_unique(SERVER(server),
864 conn->local_entry, server->nick,
865 conn->local_entry, conn->local_entry->nickname);
866 signal_emit("message own_nick", 4, server, server->nick, old, "");
872 server->connection_lost = TRUE;
874 server->conn->context = NULL;
875 server_disconnect(SERVER(server));
880 /* Called to indicate that connection was disconnected to the server. */
882 void silc_disconnect(SilcClient client, SilcClientConnection conn,
883 SilcStatus status, const char *message)
885 SILC_SERVER_REC *server = conn->context;
887 SILC_LOG_DEBUG(("Start"));
889 if (!server || server->connection_lost)
892 if (server->conn && server->conn->local_entry) {
893 nicklist_rename_unique(SERVER(server),
894 server->conn->local_entry, server->nick,
895 server->conn->local_entry,
896 silc_client->username);
897 silc_change_nick(server, silc_client->username);
901 silc_say(client, conn, SILC_CLIENT_MESSAGE_AUDIT,
902 "Server closed connection: %s (%d) %s",
903 silc_get_status_message(status), status,
904 message ? message : "");
906 server->conn->context = NULL;
908 server->connection_lost = TRUE;
909 server_disconnect(SERVER(server));
912 /* Command handler. This function is called always in the command function.
913 If error occurs it will be called as well. `conn' is the associated
914 client connection. `cmd_context' is the command context that was
915 originally sent to the command. `success' is FALSE if error occured
916 during command. `command' is the command being processed. It must be
917 noted that this is not reply from server. This is merely called just
918 after application has called the command. Just to tell application
919 that the command really was processed. */
921 void silc_command(SilcClient client, SilcClientConnection conn,
922 SilcClientCommandContext cmd_context, bool success,
923 SilcCommand command, SilcStatus status)
925 SILC_SERVER_REC *server = conn->context;
927 SILC_LOG_DEBUG(("Start"));
930 silc_say_error("%s", silc_get_status_message(status));
936 case SILC_COMMAND_INVITE:
937 if (cmd_context->argc > 2)
938 printformat_module("fe-common/silc", server, NULL,
939 MSGLEVEL_CRAP, SILCTXT_CHANNEL_INVITING,
940 cmd_context->argv[2],
941 (cmd_context->argv[1][0] == '*' ?
942 (char *)conn->current_channel->channel_name :
943 (char *)cmd_context->argv[1]));
946 case SILC_COMMAND_DETACH:
947 server->no_reconnect = TRUE;
955 /* Client info resolving callback when JOIN command reply is received.
956 This will cache all users on the channel. */
958 static void silc_client_join_get_users(SilcClient client,
959 SilcClientConnection conn,
960 SilcClientEntry *clients,
961 SilcUInt32 clients_count,
964 SilcChannelEntry channel = (SilcChannelEntry)context;
965 SilcHashTableList htl;
967 SILC_SERVER_REC *server = conn->context;
968 SILC_CHANNEL_REC *chanrec;
969 SilcClientEntry founder = NULL;
972 SILC_LOG_DEBUG(("Start, channel %s, %d users", channel->channel_name,
973 silc_hash_table_count(channel->user_list)));
978 chanrec = silc_channel_find(server, channel->channel_name);
982 silc_hash_table_list(channel->user_list, &htl);
983 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
984 if (!chu->client->nickname)
986 if (chu->mode & SILC_CHANNEL_UMODE_CHANFO)
987 founder = chu->client;
988 silc_nicklist_insert(chanrec, chu, FALSE);
990 silc_hash_table_list_reset(&htl);
992 ownnick = NICK(silc_nicklist_find(chanrec, conn->local_entry));
993 nicklist_set_own(CHANNEL(chanrec), ownnick);
994 signal_emit("channel joined", 1, chanrec);
995 chanrec->entry = channel;
998 printformat_module("fe-common/silc", server, channel->channel_name,
999 MSGLEVEL_CRAP, SILCTXT_CHANNEL_TOPIC,
1000 channel->channel_name, chanrec->topic);
1003 if (founder == conn->local_entry)
1004 printformat_module("fe-common/silc",
1005 server, channel->channel_name, MSGLEVEL_CRAP,
1006 SILCTXT_CHANNEL_FOUNDER_YOU,
1007 channel->channel_name);
1009 printformat_module("fe-common/silc",
1010 server, channel->channel_name, MSGLEVEL_CRAP,
1011 SILCTXT_CHANNEL_FOUNDER,
1012 channel->channel_name, founder->nickname);
1018 SilcClientConnection conn;
1024 void silc_getkey_cb(bool success, void *context)
1026 GetkeyContext getkey = (GetkeyContext)context;
1027 char *entity = (getkey->id_type == SILC_ID_CLIENT ? "user" : "server");
1028 char *name = (getkey->id_type == SILC_ID_CLIENT ?
1029 ((SilcClientEntry)getkey->entry)->nickname :
1030 ((SilcServerEntry)getkey->entry)->server_name);
1033 printformat_module("fe-common/silc", NULL, NULL,
1034 MSGLEVEL_CRAP, SILCTXT_PUBKEY_VERIFIED, entity, name);
1036 printformat_module("fe-common/silc", NULL, NULL,
1037 MSGLEVEL_CRAP, SILCTXT_PUBKEY_NOTVERIFIED,
1041 silc_free(getkey->fingerprint);
1045 /* Command reply handler. This function is called always in the command reply
1046 function. If error occurs it will be called as well. Normal scenario
1047 is that it will be called after the received command data has been parsed
1048 and processed. The function is used to pass the received command data to
1051 `conn' is the associated client connection. `cmd_payload' is the command
1052 payload data received from server and it can be ignored. It is provided
1053 if the application would like to re-parse the received command data,
1054 however, it must be noted that the data is parsed already by the library
1055 thus the payload can be ignored. `success' is FALSE if error occured.
1056 In this case arguments are not sent to the application. `command' is the
1057 command reply being processed. The function has variable argument list
1058 and each command defines the number and type of arguments it passes to the
1059 application (on error they are not sent). */
1062 silc_command_reply(SilcClient client, SilcClientConnection conn,
1063 SilcCommandPayload cmd_payload, bool success,
1064 SilcCommand command, SilcStatus status, ...)
1067 SILC_SERVER_REC *server = conn->context;
1068 SILC_CHANNEL_REC *chanrec;
1071 va_start(vp, status);
1073 SILC_LOG_DEBUG(("Start"));
1076 case SILC_COMMAND_WHOIS:
1078 char buf[1024], *nickname, *username, *realname, *nick;
1079 unsigned char *fingerprint;
1080 SilcUInt32 idle, mode;
1081 SilcBuffer channels, user_modes;
1082 SilcClientEntry client_entry;
1085 if (status == SILC_STATUS_ERR_NO_SUCH_NICK) {
1086 /* Print the unknown nick for user */
1087 unsigned char *tmp =
1088 silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
1091 silc_say_error("%s: %s", tmp,
1092 silc_get_status_message(status));
1094 } else if (status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
1095 /* Try to find the entry for the unknown client ID, since we
1096 might have, and print the nickname of it for user. */
1098 unsigned char *tmp =
1099 silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
1102 SilcClientID *client_id = silc_id_payload_parse_id(tmp, tmp_len,
1105 client_entry = silc_client_get_client_by_id(client, conn,
1107 if (client_entry && client_entry->nickname)
1108 silc_say_error("%s: %s", client_entry->nickname,
1109 silc_get_status_message(status));
1110 silc_free(client_id);
1114 } else if (!success) {
1115 silc_say_error("WHOIS: %s", silc_get_status_message(status));
1119 client_entry = va_arg(vp, SilcClientEntry);
1120 nickname = va_arg(vp, char *);
1121 username = va_arg(vp, char *);
1122 realname = va_arg(vp, char *);
1123 channels = va_arg(vp, SilcBuffer);
1124 mode = va_arg(vp, SilcUInt32);
1125 idle = va_arg(vp, SilcUInt32);
1126 fingerprint = va_arg(vp, unsigned char *);
1127 user_modes = va_arg(vp, SilcBuffer);
1128 attrs = va_arg(vp, SilcDList);
1130 silc_parse_userfqdn(nickname, &nick, NULL);
1131 printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
1132 SILCTXT_WHOIS_USERINFO, nickname,
1133 client_entry->username, client_entry->hostname,
1134 nick, client_entry->nickname);
1135 printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
1136 SILCTXT_WHOIS_REALNAME, realname);
1139 if (channels && user_modes) {
1141 SilcDList list = silc_channel_payload_parse_list(channels->data,
1143 if (list && silc_get_mode_list(user_modes, silc_dlist_count(list),
1145 SilcChannelPayload entry;
1148 memset(buf, 0, sizeof(buf));
1149 silc_dlist_start(list);
1150 while ((entry = silc_dlist_get(list)) != SILC_LIST_END) {
1151 SilcUInt32 name_len;
1152 char *m = silc_client_chumode_char(umodes[i++]);
1153 char *name = silc_channel_get_name(entry, &name_len);
1156 strncat(buf, m, strlen(m));
1157 strncat(buf, name, name_len);
1158 strncat(buf, " ", 1);
1162 printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
1163 SILCTXT_WHOIS_CHANNELS, buf);
1164 silc_channel_payload_list_free(list);
1170 memset(buf, 0, sizeof(buf));
1171 silc_get_umode_string(mode, buf, sizeof(buf - 1));
1172 printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
1173 SILCTXT_WHOIS_MODES, buf);
1176 if (idle && nickname) {
1177 memset(buf, 0, sizeof(buf));
1178 snprintf(buf, sizeof(buf) - 1, "%lu %s",
1179 idle > 60 ? (idle / 60) : idle,
1180 idle > 60 ? "minutes" : "seconds");
1182 printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
1183 SILCTXT_WHOIS_IDLE, buf);
1187 fingerprint = silc_fingerprint(fingerprint, 20);
1188 printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
1189 SILCTXT_WHOIS_FINGERPRINT, fingerprint);
1190 silc_free(fingerprint);
1194 silc_query_attributes_print(server, silc_client, conn, attrs,
1199 case SILC_COMMAND_IDENTIFY:
1201 SilcClientEntry client_entry;
1203 if (status == SILC_STATUS_ERR_NO_SUCH_NICK) {
1204 /* Print the unknown nick for user */
1205 unsigned char *tmp =
1206 silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
1209 silc_say_error("%s: %s", tmp,
1210 silc_get_status_message(status));
1212 } else if (status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
1213 /* Try to find the entry for the unknown client ID, since we
1214 might have, and print the nickname of it for user. */
1216 unsigned char *tmp =
1217 silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
1220 SilcClientID *client_id = silc_id_payload_parse_id(tmp, tmp_len,
1223 client_entry = silc_client_get_client_by_id(client, conn,
1225 if (client_entry && client_entry->nickname)
1226 silc_say_error("%s: %s", client_entry->nickname,
1227 silc_get_status_message(status));
1228 silc_free(client_id);
1237 case SILC_COMMAND_WHOWAS:
1239 char *nickname, *username, *realname;
1241 if (status == SILC_STATUS_ERR_NO_SUCH_NICK ||
1242 status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
1244 tmp = silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
1247 silc_say_error("%s: %s", tmp,
1248 silc_get_status_message(status));
1250 } else if (!success) {
1251 silc_say_error("WHOWAS: %s", silc_get_status_message(status));
1255 (void)va_arg(vp, SilcClientEntry);
1256 nickname = va_arg(vp, char *);
1257 username = va_arg(vp, char *);
1258 realname = va_arg(vp, char *);
1260 printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
1261 SILCTXT_WHOWAS_USERINFO, nickname, username,
1262 realname ? realname : "");
1266 case SILC_COMMAND_INVITE:
1268 SilcChannelEntry channel;
1270 SilcArgumentPayload args;
1276 channel = va_arg(vp, SilcChannelEntry);
1277 invite_list = va_arg(vp, char *);
1279 args = silc_command_get_args(cmd_payload);
1281 argc = silc_argument_get_arg_num(args);
1284 printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
1285 SILCTXT_CHANNEL_INVITE_LIST, channel->channel_name,
1288 printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
1289 SILCTXT_CHANNEL_NO_INVITE_LIST,
1290 channel->channel_name);
1294 case SILC_COMMAND_JOIN:
1296 char *channel, *mode, *topic;
1298 SilcChannelEntry channel_entry;
1299 SilcBuffer client_id_list;
1300 SilcUInt32 list_count;
1305 channel = va_arg(vp, char *);
1306 channel_entry = va_arg(vp, SilcChannelEntry);
1307 modei = va_arg(vp, SilcUInt32);
1308 (void)va_arg(vp, SilcUInt32);
1309 (void)va_arg(vp, unsigned char *);
1310 (void)va_arg(vp, unsigned char *);
1311 (void)va_arg(vp, unsigned char *);
1312 topic = va_arg(vp, char *);
1313 (void)va_arg(vp, unsigned char *);
1314 list_count = va_arg(vp, SilcUInt32);
1315 client_id_list = va_arg(vp, SilcBuffer);
1317 chanrec = silc_channel_find(server, channel);
1319 chanrec = silc_channel_create(server, channel, channel, TRUE);
1322 g_free_not_null(chanrec->topic);
1323 chanrec->topic = *topic == '\0' ? NULL : g_strdup(topic);
1324 signal_emit("channel topic changed", 1, chanrec);
1327 mode = silc_client_chmode(modei,
1328 channel_entry->channel_key ?
1329 silc_cipher_get_name(channel_entry->
1331 channel_entry->hmac ?
1332 silc_hmac_get_name(channel_entry->hmac) : "");
1333 g_free_not_null(chanrec->mode);
1334 chanrec->mode = g_strdup(mode == NULL ? "" : mode);
1335 signal_emit("channel mode changed", 1, chanrec);
1337 /* Resolve the client information */
1338 silc_client_get_clients_by_list(client, conn, list_count, client_id_list,
1339 silc_client_join_get_users,
1345 case SILC_COMMAND_NICK:
1348 SilcClientEntry client = va_arg(vp, SilcClientEntry);
1353 old = g_strdup(server->nick);
1354 server_change_nick(SERVER(server), client->nickname);
1355 nicklist_rename_unique(SERVER(server),
1356 server->conn->local_entry, server->nick,
1357 client, client->nickname);
1358 signal_emit("message own_nick", 4, server, server->nick, old, "");
1363 case SILC_COMMAND_LIST:
1368 char tmp[256], *cp, *dm = NULL;
1373 (void)va_arg(vp, SilcChannelEntry);
1374 name = va_arg(vp, char *);
1375 topic = va_arg(vp, char *);
1376 usercount = va_arg(vp, int);
1378 if (!silc_term_utf8() && silc_utf8_valid(topic, strlen(topic))) {
1379 memset(tmp, 0, sizeof(tmp));
1381 if (strlen(topic) > sizeof(tmp) - 1) {
1382 dm = silc_calloc(strlen(topic) + 1, sizeof(*dm));
1386 silc_utf8_decode(topic, strlen(topic), SILC_STRING_LANGUAGE,
1391 if (status == SILC_STATUS_LIST_START ||
1392 status == SILC_STATUS_OK)
1393 printformat_module("fe-common/silc", server, NULL,
1394 MSGLEVEL_CRAP, SILCTXT_LIST_HEADER);
1397 snprintf(users, sizeof(users) - 1, "N/A");
1399 snprintf(users, sizeof(users) - 1, "%d", usercount);
1400 printformat_module("fe-common/silc", server, NULL,
1401 MSGLEVEL_CRAP, SILCTXT_LIST,
1402 name, users, topic ? topic : "");
1407 case SILC_COMMAND_UMODE:
1414 mode = va_arg(vp, SilcUInt32);
1416 if (mode & SILC_UMODE_SERVER_OPERATOR &&
1417 !(server->umode & SILC_UMODE_SERVER_OPERATOR))
1418 printformat_module("fe-common/silc", server, NULL,
1419 MSGLEVEL_CRAP, SILCTXT_SERVER_OPER);
1421 if (mode & SILC_UMODE_ROUTER_OPERATOR &&
1422 !(server->umode & SILC_UMODE_ROUTER_OPERATOR))
1423 printformat_module("fe-common/silc", server, NULL,
1424 MSGLEVEL_CRAP, SILCTXT_ROUTER_OPER);
1426 server->umode = mode;
1427 signal_emit("user mode changed", 2, server, NULL);
1431 case SILC_COMMAND_OPER:
1435 server->umode |= SILC_UMODE_SERVER_OPERATOR;
1436 signal_emit("user mode changed", 2, server, NULL);
1438 printformat_module("fe-common/silc", server, NULL,
1439 MSGLEVEL_CRAP, SILCTXT_SERVER_OPER);
1442 case SILC_COMMAND_SILCOPER:
1446 server->umode |= SILC_UMODE_ROUTER_OPERATOR;
1447 signal_emit("user mode changed", 2, server, NULL);
1449 printformat_module("fe-common/silc", server, NULL,
1450 MSGLEVEL_CRAP, SILCTXT_ROUTER_OPER);
1453 case SILC_COMMAND_USERS:
1455 SilcHashTableList htl;
1456 SilcChannelEntry channel;
1457 SilcChannelUser chu;
1462 channel = va_arg(vp, SilcChannelEntry);
1464 printformat_module("fe-common/silc", server, channel->channel_name,
1465 MSGLEVEL_CRAP, SILCTXT_USERS_HEADER,
1466 channel->channel_name);
1468 silc_hash_table_list(channel->user_list, &htl);
1469 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
1470 SilcClientEntry e = chu->client;
1471 char stat[5], *mode;
1476 memset(stat, 0, sizeof(stat));
1477 mode = silc_client_chumode_char(chu->mode);
1478 if (e->mode & SILC_UMODE_GONE)
1480 else if (e->mode & SILC_UMODE_INDISPOSED)
1482 else if (e->mode & SILC_UMODE_BUSY)
1484 else if (e->mode & SILC_UMODE_PAGE)
1486 else if (e->mode & SILC_UMODE_HYPER)
1488 else if (e->mode & SILC_UMODE_ROBOT)
1490 else if (e->mode & SILC_UMODE_ANONYMOUS)
1497 printformat_module("fe-common/silc", server, channel->channel_name,
1498 MSGLEVEL_CRAP, SILCTXT_USERS,
1500 e->username ? e->username : "",
1501 e->hostname ? e->hostname : "",
1502 e->realname ? e->realname : "");
1506 silc_hash_table_list_reset(&htl);
1510 case SILC_COMMAND_BAN:
1512 SilcChannelEntry channel;
1518 channel = va_arg(vp, SilcChannelEntry);
1519 ban_list = va_arg(vp, char *);
1522 printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
1523 SILCTXT_CHANNEL_BAN_LIST, channel->channel_name,
1526 printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
1527 SILCTXT_CHANNEL_NO_BAN_LIST,
1528 channel->channel_name);
1532 case SILC_COMMAND_GETKEY:
1536 SilcPublicKey public_key;
1539 GetkeyContext getkey;
1545 id_type = va_arg(vp, SilcUInt32);
1546 entry = va_arg(vp, void *);
1547 public_key = va_arg(vp, SilcPublicKey);
1550 pk = silc_pkcs_public_key_encode(public_key, &pk_len);
1552 getkey = silc_calloc(1, sizeof(*getkey));
1553 getkey->entry = entry;
1554 getkey->id_type = id_type;
1555 getkey->client = client;
1556 getkey->conn = conn;
1557 getkey->fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
1559 name = (id_type == SILC_ID_CLIENT ?
1560 ((SilcClientEntry)entry)->nickname :
1561 ((SilcServerEntry)entry)->server_name);
1563 silc_verify_public_key_internal(client, conn, name,
1564 (id_type == SILC_ID_CLIENT ?
1565 SILC_SOCKET_TYPE_CLIENT :
1566 SILC_SOCKET_TYPE_SERVER),
1567 pk, pk_len, SILC_SKE_PK_TYPE_SILC,
1568 silc_getkey_cb, getkey);
1571 printformat_module("fe-common/silc", server, NULL,
1572 MSGLEVEL_CRAP, SILCTXT_PUBKEY_NOKEY);
1577 case SILC_COMMAND_INFO:
1579 SilcServerEntry server_entry;
1586 server_entry = va_arg(vp, SilcServerEntry);
1587 server_name = va_arg(vp, char *);
1588 server_info = va_arg(vp, char *);
1590 if (server_name && server_info )
1592 printtext(server, NULL, MSGLEVEL_CRAP, "Server: %s", server_name);
1593 printtext(server, NULL, MSGLEVEL_CRAP, "%s", server_info);
1598 case SILC_COMMAND_TOPIC:
1600 SilcChannelEntry channel;
1602 char tmp[256], *cp, *dm = NULL;
1607 channel = va_arg(vp, SilcChannelEntry);
1608 topic = va_arg(vp, char *);
1610 if (!silc_term_utf8() && silc_utf8_valid(topic, strlen(topic))) {
1611 memset(tmp, 0, sizeof(tmp));
1613 if (strlen(topic) > sizeof(tmp) - 1) {
1614 dm = silc_calloc(strlen(topic) + 1, sizeof(*dm));
1618 silc_utf8_decode(topic, strlen(topic), SILC_STRING_LANGUAGE,
1624 chanrec = silc_channel_find_entry(server, channel);
1626 g_free_not_null(chanrec->topic);
1627 chanrec->topic = *topic == '\0' ? NULL : g_strdup(topic);
1628 signal_emit("channel topic changed", 1, chanrec);
1630 printformat_module("fe-common/silc", server, channel->channel_name,
1631 MSGLEVEL_CRAP, SILCTXT_CHANNEL_TOPIC,
1632 channel->channel_name, topic);
1634 printformat_module("fe-common/silc", server, channel->channel_name,
1635 MSGLEVEL_CRAP, SILCTXT_CHANNEL_TOPIC_NOT_SET,
1636 channel->channel_name);
1642 case SILC_COMMAND_WATCH:
1645 case SILC_COMMAND_STATS:
1647 SilcUInt32 starttime, uptime, my_clients, my_channels, my_server_ops,
1648 my_router_ops, cell_clients, cell_channels, cell_servers,
1649 clients, channels, servers, routers, server_ops, router_ops;
1651 SilcBufferStruct buf;
1652 unsigned char *tmp_buf;
1654 const char *tmptime;
1655 int days, hours, mins, secs;
1660 tmp_buf = va_arg(vp, unsigned char *);
1661 buf_len = va_arg(vp, SilcUInt32);
1663 if (!tmp_buf || !buf_len) {
1664 printtext(server, NULL, MSGLEVEL_CRAP, "No statistics available");
1668 /* Get statistics structure */
1669 silc_buffer_set(&buf, tmp_buf, buf_len);
1670 silc_buffer_unformat(&buf,
1671 SILC_STR_UI_INT(&starttime),
1672 SILC_STR_UI_INT(&uptime),
1673 SILC_STR_UI_INT(&my_clients),
1674 SILC_STR_UI_INT(&my_channels),
1675 SILC_STR_UI_INT(&my_server_ops),
1676 SILC_STR_UI_INT(&my_router_ops),
1677 SILC_STR_UI_INT(&cell_clients),
1678 SILC_STR_UI_INT(&cell_channels),
1679 SILC_STR_UI_INT(&cell_servers),
1680 SILC_STR_UI_INT(&clients),
1681 SILC_STR_UI_INT(&channels),
1682 SILC_STR_UI_INT(&servers),
1683 SILC_STR_UI_INT(&routers),
1684 SILC_STR_UI_INT(&server_ops),
1685 SILC_STR_UI_INT(&router_ops),
1688 tmptime = silc_get_time(starttime);
1689 printformat_module("fe-common/silc", server, NULL,
1690 MSGLEVEL_CRAP, SILCTXT_STATS,
1691 "Local server start time", tmptime);
1693 days = uptime / (24 * 60 * 60);
1694 uptime -= days * (24 * 60 * 60);
1695 hours = uptime / (60 * 60);
1696 uptime -= hours * (60 * 60);
1698 uptime -= mins * 60;
1700 snprintf(tmp, sizeof(tmp) - 1, "%d days %d hours %d mins %d secs",
1701 days, hours, mins, secs);
1702 printformat_module("fe-common/silc", server, NULL,
1703 MSGLEVEL_CRAP, SILCTXT_STATS,
1704 "Local server uptime", tmp);
1706 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)my_clients);
1707 printformat_module("fe-common/silc", server, NULL,
1708 MSGLEVEL_CRAP, SILCTXT_STATS,
1709 "Local server clients", tmp);
1711 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)my_channels);
1712 printformat_module("fe-common/silc", server, NULL,
1713 MSGLEVEL_CRAP, SILCTXT_STATS,
1714 "Local server channels", tmp);
1716 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)my_server_ops);
1717 printformat_module("fe-common/silc", server, NULL,
1718 MSGLEVEL_CRAP, SILCTXT_STATS,
1719 "Local server operators", tmp);
1721 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)my_router_ops);
1722 printformat_module("fe-common/silc", server, NULL,
1723 MSGLEVEL_CRAP, SILCTXT_STATS,
1724 "Local router operators", tmp);
1726 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cell_clients);
1727 printformat_module("fe-common/silc", server, NULL,
1728 MSGLEVEL_CRAP, SILCTXT_STATS,
1729 "Local cell clients", tmp);
1731 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cell_channels);
1732 printformat_module("fe-common/silc", server, NULL,
1733 MSGLEVEL_CRAP, SILCTXT_STATS,
1734 "Local cell channels", tmp);
1736 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cell_servers);
1737 printformat_module("fe-common/silc", server, NULL,
1738 MSGLEVEL_CRAP, SILCTXT_STATS,
1739 "Local cell servers", tmp);
1741 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)clients);
1742 printformat_module("fe-common/silc", server, NULL,
1743 MSGLEVEL_CRAP, SILCTXT_STATS,
1744 "Total clients", tmp);
1746 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)channels);
1747 printformat_module("fe-common/silc", server, NULL,
1748 MSGLEVEL_CRAP, SILCTXT_STATS,
1749 "Total channels", tmp);
1751 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)servers);
1752 printformat_module("fe-common/silc", server, NULL,
1753 MSGLEVEL_CRAP, SILCTXT_STATS,
1754 "Total servers", tmp);
1756 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)routers);
1757 printformat_module("fe-common/silc", server, NULL,
1758 MSGLEVEL_CRAP, SILCTXT_STATS,
1759 "Total routers", tmp);
1761 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)server_ops);
1762 printformat_module("fe-common/silc", server, NULL,
1763 MSGLEVEL_CRAP, SILCTXT_STATS,
1764 "Total server operators", tmp);
1766 snprintf(tmp, sizeof(tmp) - 1, "%d", (int)router_ops);
1767 printformat_module("fe-common/silc", server, NULL,
1768 MSGLEVEL_CRAP, SILCTXT_STATS,
1769 "Total router operators", tmp);
1780 SilcClientConnection conn;
1786 SilcSKEPKType pk_type;
1787 SilcVerifyPublicKey completion;
1791 static void verify_public_key_completion(const char *line, void *context)
1793 PublicKeyVerify verify = (PublicKeyVerify)context;
1795 if (line[0] == 'Y' || line[0] == 'y') {
1796 /* Call the completion */
1797 if (verify->completion)
1798 verify->completion(TRUE, verify->context);
1800 /* Save the key for future checking */
1801 silc_pkcs_save_public_key_data(verify->filename, verify->pk,
1802 verify->pk_len, SILC_PKCS_FILE_PEM);
1804 /* Call the completion */
1805 if (verify->completion)
1806 verify->completion(FALSE, verify->context);
1808 printformat_module("fe-common/silc", NULL, NULL,
1809 MSGLEVEL_CRAP, SILCTXT_PUBKEY_DISCARD,
1810 verify->entity_name ? verify->entity_name :
1814 silc_free(verify->filename);
1815 silc_free(verify->entity);
1816 silc_free(verify->entity_name);
1817 silc_free(verify->pk);
1821 /* Internal routine to verify public key. If the `completion' is provided
1822 it will be called to indicate whether public was verified or not. For
1823 server/router public key this will check for filename that includes the
1824 remote host's IP address and remote host's hostname. */
1827 silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
1828 const char *name, SilcSocketType conn_type,
1829 unsigned char *pk, SilcUInt32 pk_len,
1830 SilcSKEPKType pk_type,
1831 SilcVerifyPublicKey completion, void *context)
1834 char file[256], filename[256], filename2[256], *ipf, *hostf = NULL;
1835 char *fingerprint, *babbleprint, *format;
1838 char *entity = ((conn_type == SILC_SOCKET_TYPE_SERVER ||
1839 conn_type == SILC_SOCKET_TYPE_ROUTER) ?
1840 "server" : "client");
1841 PublicKeyVerify verify;
1843 if (pk_type != SILC_SKE_PK_TYPE_SILC) {
1844 printformat_module("fe-common/silc", NULL, NULL,
1845 MSGLEVEL_CRAP, SILCTXT_PUBKEY_UNSUPPORTED,
1848 completion(FALSE, context);
1852 pw = getpwuid(getuid());
1855 completion(FALSE, context);
1859 memset(filename, 0, sizeof(filename));
1860 memset(filename2, 0, sizeof(filename2));
1861 memset(file, 0, sizeof(file));
1863 if (conn_type == SILC_SOCKET_TYPE_SERVER ||
1864 conn_type == SILC_SOCKET_TYPE_ROUTER) {
1866 snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity,
1867 conn->sock->ip, conn->sock->port);
1868 snprintf(filename, sizeof(filename) - 1, "%s/%skeys/%s",
1869 get_irssi_dir(), entity, file);
1871 snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity,
1872 conn->sock->hostname, conn->sock->port);
1873 snprintf(filename2, sizeof(filename2) - 1, "%s/%skeys/%s",
1874 get_irssi_dir(), entity, file);
1879 snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity,
1880 name, conn->sock->port);
1881 snprintf(filename, sizeof(filename) - 1, "%s/%skeys/%s",
1882 get_irssi_dir(), entity, file);
1887 /* Replace all whitespaces with `_'. */
1888 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
1889 for (i = 0; i < strlen(fingerprint); i++)
1890 if (fingerprint[i] == ' ')
1891 fingerprint[i] = '_';
1893 snprintf(file, sizeof(file) - 1, "%skey_%s.pub", entity, fingerprint);
1894 snprintf(filename, sizeof(filename) - 1, "%s/%skeys/%s",
1895 get_irssi_dir(), entity, file);
1896 silc_free(fingerprint);
1901 /* Take fingerprint of the public key */
1902 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
1903 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len);
1905 verify = silc_calloc(1, sizeof(*verify));
1906 verify->client = client;
1907 verify->conn = conn;
1908 verify->filename = strdup(ipf);
1909 verify->entity = strdup(entity);
1910 verify->entity_name = (conn_type != SILC_SOCKET_TYPE_CLIENT ?
1911 (name ? strdup(name) : strdup(conn->sock->hostname))
1913 verify->pk = silc_calloc(pk_len, sizeof(*verify->pk));
1914 memcpy(verify->pk, pk, pk_len);
1915 verify->pk_len = pk_len;
1916 verify->pk_type = pk_type;
1917 verify->completion = completion;
1918 verify->context = context;
1920 /* Check whether this key already exists */
1921 if (stat(ipf, &st) < 0 && (!hostf || stat(hostf, &st) < 0)) {
1922 /* Key does not exist, ask user to verify the key and save it */
1924 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1925 SILCTXT_PUBKEY_RECEIVED,verify->entity_name ?
1926 verify->entity_name : entity);
1927 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1928 SILCTXT_PUBKEY_FINGERPRINT, entity, fingerprint);
1929 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1930 SILCTXT_PUBKEY_BABBLEPRINT, babbleprint);
1931 format = format_get_text("fe-common/silc", NULL, NULL, NULL,
1932 SILCTXT_PUBKEY_ACCEPT);
1933 keyboard_entry_redirect((SIGNAL_FUNC)verify_public_key_completion,
1936 silc_free(fingerprint);
1939 /* The key already exists, verify it. */
1940 SilcPublicKey public_key;
1941 unsigned char *encpk;
1942 SilcUInt32 encpk_len;
1944 /* Load the key file, try for both IP filename and hostname filename */
1945 if (!silc_pkcs_load_public_key(ipf, &public_key,
1946 SILC_PKCS_FILE_PEM) &&
1947 !silc_pkcs_load_public_key(ipf, &public_key,
1948 SILC_PKCS_FILE_BIN) &&
1949 (!hostf || (!silc_pkcs_load_public_key(hostf, &public_key,
1950 SILC_PKCS_FILE_PEM) &&
1951 !silc_pkcs_load_public_key(hostf, &public_key,
1952 SILC_PKCS_FILE_BIN)))) {
1953 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1954 SILCTXT_PUBKEY_RECEIVED,verify->entity_name ?
1955 verify->entity_name : entity);
1956 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1957 SILCTXT_PUBKEY_FINGERPRINT, entity, fingerprint);
1958 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1959 SILCTXT_PUBKEY_BABBLEPRINT, babbleprint);
1960 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1961 SILCTXT_PUBKEY_COULD_NOT_LOAD, entity);
1962 format = format_get_text("fe-common/silc", NULL, NULL, NULL,
1963 SILCTXT_PUBKEY_ACCEPT_ANYWAY);
1964 keyboard_entry_redirect((SIGNAL_FUNC)verify_public_key_completion,
1967 silc_free(fingerprint);
1971 /* Encode the key data */
1972 encpk = silc_pkcs_public_key_encode(public_key, &encpk_len);
1974 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1975 SILCTXT_PUBKEY_RECEIVED,verify->entity_name ?
1976 verify->entity_name : entity);
1977 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1978 SILCTXT_PUBKEY_FINGERPRINT, entity, fingerprint);
1979 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1980 SILCTXT_PUBKEY_BABBLEPRINT, babbleprint);
1981 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1982 SILCTXT_PUBKEY_MALFORMED, entity);
1983 format = format_get_text("fe-common/silc", NULL, NULL, NULL,
1984 SILCTXT_PUBKEY_ACCEPT_ANYWAY);
1985 keyboard_entry_redirect((SIGNAL_FUNC)verify_public_key_completion,
1988 silc_free(fingerprint);
1992 /* Compare the keys */
1993 if (memcmp(encpk, pk, encpk_len)) {
1994 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1995 SILCTXT_PUBKEY_RECEIVED,verify->entity_name ?
1996 verify->entity_name : entity);
1997 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
1998 SILCTXT_PUBKEY_FINGERPRINT, entity, fingerprint);
1999 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2000 SILCTXT_PUBKEY_BABBLEPRINT, babbleprint);
2001 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2002 SILCTXT_PUBKEY_NO_MATCH, entity);
2003 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2004 SILCTXT_PUBKEY_MAYBE_EXPIRED, entity);
2005 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2006 SILCTXT_PUBKEY_MITM_ATTACK, entity);
2008 /* Ask user to verify the key and save it */
2009 format = format_get_text("fe-common/silc", NULL, NULL, NULL,
2010 SILCTXT_PUBKEY_ACCEPT_ANYWAY);
2011 keyboard_entry_redirect((SIGNAL_FUNC)verify_public_key_completion,
2014 silc_free(fingerprint);
2018 /* Local copy matched */
2020 completion(TRUE, context);
2021 silc_free(fingerprint);
2025 /* Verifies received public key. The `conn_type' indicates which entity
2026 (server, client etc.) has sent the public key. If user decides to trust
2027 the key may be saved as trusted public key for later use. The
2028 `completion' must be called after the public key has been verified. */
2031 silc_verify_public_key(SilcClient client, SilcClientConnection conn,
2032 SilcSocketType conn_type, unsigned char *pk,
2033 SilcUInt32 pk_len, SilcSKEPKType pk_type,
2034 SilcVerifyPublicKey completion, void *context)
2036 silc_verify_public_key_internal(client, conn, NULL, conn_type, pk,
2038 completion, context);
2041 /* Asks passphrase from user on the input line. */
2044 SilcAskPassphrase completion;
2048 void ask_passphrase_completion(const char *passphrase, void *context)
2050 AskPassphrase p = (AskPassphrase)context;
2051 if (passphrase && passphrase[0] == '\0')
2053 p->completion((unsigned char *)passphrase,
2054 passphrase ? strlen(passphrase) : 0, p->context);
2058 void silc_ask_passphrase(SilcClient client, SilcClientConnection conn,
2059 SilcAskPassphrase completion, void *context)
2061 AskPassphrase p = silc_calloc(1, sizeof(*p));
2062 p->completion = completion;
2063 p->context = context;
2065 keyboard_entry_redirect((SIGNAL_FUNC)ask_passphrase_completion,
2066 "Passphrase: ", ENTRY_REDIRECT_FLAG_HIDDEN, p);
2070 SilcGetAuthMeth completion;
2072 } *InternalGetAuthMethod;
2074 /* Callback called when we've received the authentication method information
2075 from the server after we've requested it. This will get the authentication
2076 data from the user if needed. */
2078 static void silc_get_auth_method_callback(SilcClient client,
2079 SilcClientConnection conn,
2080 SilcAuthMethod auth_meth,
2083 InternalGetAuthMethod internal = (InternalGetAuthMethod)context;
2085 SILC_LOG_DEBUG(("Start"));
2087 switch (auth_meth) {
2088 case SILC_AUTH_NONE:
2089 /* No authentication required. */
2090 (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context);
2092 case SILC_AUTH_PASSWORD:
2094 /* Check whether we find the password for this server in our
2095 configuration. If not, then don't provide so library will ask
2096 it from the user. */
2097 SERVER_SETUP_REC *setup = server_setup_find_port(conn->remote_host,
2099 if (!setup || !setup->password) {
2100 (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context);
2104 (*internal->completion)(TRUE, auth_meth, setup->password,
2105 strlen(setup->password), internal->context);
2108 case SILC_AUTH_PUBLIC_KEY:
2109 /* Do not get the authentication data now, the library will generate
2110 it using our default key, if we do not provide it here. */
2111 /* XXX In the future when we support multiple local keys and multiple
2112 local certificates we will need to ask from user which one to use. */
2113 (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context);
2117 silc_free(internal);
2120 /* Find authentication method and authentication data by hostname and
2121 port. The hostname may be IP address as well. The found authentication
2122 method and authentication data is returned to `auth_meth', `auth_data'
2123 and `auth_data_len'. The function returns TRUE if authentication method
2124 is found and FALSE if not. `conn' may be NULL. */
2126 void silc_get_auth_method(SilcClient client, SilcClientConnection conn,
2127 char *hostname, SilcUInt16 port,
2128 SilcGetAuthMeth completion, void *context)
2130 InternalGetAuthMethod internal;
2132 SILC_LOG_DEBUG(("Start"));
2134 /* If we do not have this connection configured by the user in a
2135 configuration file then resolve the authentication method from the
2136 server for this session. */
2137 internal = silc_calloc(1, sizeof(*internal));
2138 internal->completion = completion;
2139 internal->context = context;
2141 silc_client_request_authentication_method(client, conn,
2142 silc_get_auth_method_callback,
2146 /* Notifies application that failure packet was received. This is called
2147 if there is some protocol active in the client. The `protocol' is the
2148 protocol context. The `failure' is opaque pointer to the failure
2149 indication. Note, that the `failure' is protocol dependant and application
2150 must explicitly cast it to correct type. Usually `failure' is 32 bit
2151 failure type (see protocol specs for all protocol failure types). */
2153 void silc_failure(SilcClient client, SilcClientConnection conn,
2154 SilcProtocol protocol, void *failure)
2156 SILC_LOG_DEBUG(("Start"));
2158 if (protocol->protocol->type == SILC_PROTOCOL_CLIENT_KEY_EXCHANGE) {
2159 SilcSKEStatus status = (SilcSKEStatus)failure;
2161 if (status == SILC_SKE_STATUS_BAD_VERSION)
2162 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2163 SILCTXT_KE_BAD_VERSION);
2164 if (status == SILC_SKE_STATUS_UNSUPPORTED_PUBLIC_KEY)
2165 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2166 SILCTXT_KE_UNSUPPORTED_PUBLIC_KEY);
2167 if (status == SILC_SKE_STATUS_UNKNOWN_GROUP)
2168 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2169 SILCTXT_KE_UNKNOWN_GROUP);
2170 if (status == SILC_SKE_STATUS_UNKNOWN_CIPHER)
2171 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2172 SILCTXT_KE_UNKNOWN_CIPHER);
2173 if (status == SILC_SKE_STATUS_UNKNOWN_PKCS)
2174 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2175 SILCTXT_KE_UNKNOWN_PKCS);
2176 if (status == SILC_SKE_STATUS_UNKNOWN_HASH_FUNCTION)
2177 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2178 SILCTXT_KE_UNKNOWN_HASH_FUNCTION);
2179 if (status == SILC_SKE_STATUS_UNKNOWN_HMAC)
2180 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2181 SILCTXT_KE_UNKNOWN_HMAC);
2182 if (status == SILC_SKE_STATUS_INCORRECT_SIGNATURE)
2183 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2184 SILCTXT_KE_INCORRECT_SIGNATURE);
2185 if (status == SILC_SKE_STATUS_INVALID_COOKIE)
2186 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2187 SILCTXT_KE_INVALID_COOKIE);
2190 if (protocol->protocol->type == SILC_PROTOCOL_CLIENT_CONNECTION_AUTH) {
2191 SilcUInt32 err = (SilcUInt32)failure;
2193 if (err == SILC_AUTH_FAILED)
2194 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2195 SILCTXT_AUTH_FAILED);
2199 /* Asks whether the user would like to perform the key agreement protocol.
2200 This is called after we have received an key agreement packet or an
2201 reply to our key agreement packet. This returns TRUE if the user wants
2202 the library to perform the key agreement protocol and FALSE if it is not
2203 desired (application may start it later by calling the function
2204 silc_client_perform_key_agreement). */
2206 bool silc_key_agreement(SilcClient client, SilcClientConnection conn,
2207 SilcClientEntry client_entry, const char *hostname,
2208 SilcUInt16 port, SilcKeyAgreementCallback *completion,
2213 SILC_LOG_DEBUG(("Start"));
2215 /* We will just display the info on the screen and return FALSE and user
2216 will have to start the key agreement with a command. */
2219 snprintf(portstr, sizeof(portstr) - 1, "%d", port);
2222 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2223 SILCTXT_KEY_AGREEMENT_REQUEST, client_entry->nickname);
2225 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2226 SILCTXT_KEY_AGREEMENT_REQUEST_HOST,
2227 client_entry->nickname, hostname, portstr);
2235 /* Notifies application that file transfer protocol session is being
2236 requested by the remote client indicated by the `client_entry' from
2237 the `hostname' and `port'. The `session_id' is the file transfer
2238 session and it can be used to either accept or reject the file
2239 transfer request, by calling the silc_client_file_receive or
2240 silc_client_file_close, respectively. */
2242 void silc_ftp(SilcClient client, SilcClientConnection conn,
2243 SilcClientEntry client_entry, SilcUInt32 session_id,
2244 const char *hostname, SilcUInt16 port)
2246 SILC_SERVER_REC *server;
2248 FtpSession ftp = silc_calloc(1, sizeof(*ftp));
2250 SILC_LOG_DEBUG(("Start"));
2252 server = conn->context;
2254 ftp->client_entry = client_entry;
2255 ftp->session_id = session_id;
2258 silc_dlist_add(server->ftp_sessions, ftp);
2259 server->current_session = ftp;
2262 snprintf(portstr, sizeof(portstr) - 1, "%d", port);
2265 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2266 SILCTXT_FILE_REQUEST, client_entry->nickname);
2268 printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
2269 SILCTXT_FILE_REQUEST_HOST,
2270 client_entry->nickname, hostname, portstr);
2273 /* Delivers SILC session detachment data indicated by `detach_data' to the
2274 application. If application has issued SILC_COMMAND_DETACH command
2275 the client session in the SILC network is not quit. The client remains
2276 in the network but is detached. The detachment data may be used later
2277 to resume the session in the SILC Network. The appliation is
2278 responsible of saving the `detach_data', to for example in a file.
2280 The detachment data can be given as argument to the functions
2281 silc_client_connect_to_server, or silc_client_add_connection when
2282 creating connection to remote server, inside SilcClientConnectionParams
2283 structure. If it is provided the client library will attempt to resume
2284 the session in the network. After the connection is created
2285 successfully, the application is responsible of setting the user
2286 interface for user into the same state it was before detaching (showing
2287 same channels, channel modes, etc). It can do this by fetching the
2288 information (like joined channels) from the client library. */
2291 silc_detach(SilcClient client, SilcClientConnection conn,
2292 const unsigned char *detach_data, SilcUInt32 detach_data_len)
2296 /* Save the detachment data to file. */
2298 memset(file, 0, sizeof(file));
2299 snprintf(file, sizeof(file) - 1, "%s/session", get_irssi_dir());
2300 silc_file_writefile(file, detach_data, detach_data_len);
2304 /* SILC client operations */
2305 SilcClientOperations ops = {
2307 silc_channel_message,
2308 silc_private_message,
2314 silc_get_auth_method,
2315 silc_verify_public_key,
2316 silc_ask_passphrase,