start to move printing to fe/silc, start to convert stuff we receive to
[silc.git] / apps / irssi / src / fe-common / silc / fe-silc-channels.c
1 /*
2  fe-silc-channels.c : irssi
3
4     Copyright (C) 2000 Timo Sirainen
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "module.h"
22 #include "modules.h"
23 #include "themes.h"
24 #include "levels.h"
25 #include "misc.h"
26 #include "special-vars.h"
27 #include "settings.h"
28
29 #include "silc-servers.h"
30
31 #include "window-items.h"
32 #include "hilight-text.h"
33 #include "printtext.h"
34 #include "module-formats.h"
35
36 void sig_message_appears(SILC_SERVER_REC *server, const char *channel,
37                         const char *oldnick, const char *newnick,
38                         const char *address)
39 {
40         printformat_module("fe-common/silc", server, channel, MSGLEVEL_NICKS,
41                                 SILCTXT_CHANNEL_APPEARS, oldnick, newnick,
42                                 channel, address);
43 }
44
45 /* FIXME: convert identifier */
46 void sig_message_channel_pubkeys(SILC_SERVER_REC *server,
47                                 SilcChannelEntry channel_entry,
48                                 SilcBuffer channel_pubkeys)
49 {
50   SilcUInt16 argc;
51   SilcArgumentPayload chpks;
52   unsigned char *pk;
53   SilcUInt32 pk_len, type;
54   int c = 1;
55   char *fingerprint, *babbleprint;
56   SilcPublicKey pubkey;
57   SilcPublicKeyIdentifier ident;
58
59   if (channel_pubkeys == NULL) {
60     printformat_module("fe-common/silc", server, NULL,
61                      MSGLEVEL_CRAP, SILCTXT_CHANNEL_PK_NO_LIST,
62                      channel_entry->channel_name);
63     return;
64   }
65
66   printformat_module("fe-common/silc", server, NULL,
67                      MSGLEVEL_CRAP, SILCTXT_CHANNEL_PK_LIST,
68                      channel_entry->channel_name);
69
70   SILC_GET16_MSB(argc, channel_pubkeys->data);
71   chpks = silc_argument_payload_parse(channel_pubkeys->data + 2,
72                                       channel_pubkeys->len - 2, argc);
73   if (!chpks)
74     return;
75
76   pk = silc_argument_get_first_arg(chpks, &type, &pk_len);
77   while (pk) {
78     fingerprint = silc_hash_fingerprint(NULL, pk + 4, pk_len - 4);
79     babbleprint = silc_hash_babbleprint(NULL, pk + 4, pk_len - 4);
80     silc_pkcs_public_key_payload_decode(pk, pk_len, &pubkey);
81     ident = silc_pkcs_decode_identifier(pubkey->identifier);
82
83     printformat_module("fe-common/silc", server, NULL,
84                        MSGLEVEL_CRAP, SILCTXT_CHANNEL_PK_LIST_ENTRY,
85                        c++, channel_entry->channel_name,
86                        type == 0x00 ? "Added" : "Removed",
87                        ident->realname ? ident->realname : "",
88                        fingerprint, babbleprint);
89
90     silc_free(fingerprint);
91     silc_free(babbleprint);
92     silc_pkcs_public_key_free(pubkey);
93     silc_pkcs_free_identifier(ident);
94     pk = silc_argument_get_next_arg(chpks, &type, &pk_len);
95   }
96
97   silc_argument_payload_free(chpks);
98 }
99
100 void sig_message_generic(SILC_SERVER_REC *server, const char *target,
101                         int msglevel, const char *msg)
102 {
103   printtext(server, target, msglevel, "%s", msg);
104 }
105
106 void sig_cmode_changed(SILC_SERVER_REC *server, const char *channel,
107                         const char *mode, const char *nick)
108 {
109   printformat_module("fe-common/silc", server, channel, MSGLEVEL_MODES,
110                         SILCTXT_CHANNEL_CMODE, channel,
111                         mode ? mode : "removed all", 
112                         nick ? nick : "");
113 }
114
115 void sig_cumode_changed(SILC_SERVER_REC *server, const char *channel,
116                         const char *who,
117                         const char *mode, const char *nick)
118 {
119   printformat_module("fe-common/silc", server, channel, MSGLEVEL_MODES,
120                         SILCTXT_CHANNEL_CUMODE, channel, who,
121                         mode ? mode : "removed all",
122                         nick ? nick : "");
123 }
124
125 void sig_channel_founder(SILC_SERVER_REC *server, const char *channel,
126                         const char *nick)
127 {
128   printformat_module("fe-common/silc", server, channel, MSGLEVEL_CRAP,
129                         SILCTXT_CHANNEL_FOUNDER, channel, nick);
130 }
131
132 void sig_quieted(SILC_SERVER_REC *server, const char *channel)
133 {
134   printformat_module("fe-common/silc", server, channel, MSGLEVEL_CRAP,
135                         SILCTXT_CHANNEL_QUIETED, channel);
136 }
137
138 void sig_motd(SILC_SERVER_REC *server, const char *motd)
139 {
140   printtext_multiline(server, NULL, MSGLEVEL_CRAP, "%s", motd);
141 }
142
143 void fe_silc_channels_init(void)
144 {
145         signal_add("message silc appears", 
146                         (SIGNAL_FUNC) sig_message_appears);
147         signal_add("message silc pubkeys",
148                         (SIGNAL_FUNC) sig_message_channel_pubkeys);
149         signal_add("message silc generic",
150                         (SIGNAL_FUNC) sig_message_generic);
151         signal_add("message silc cmode",
152                         (SIGNAL_FUNC) sig_cmode_changed);
153         signal_add("message silc cumode",
154                         (SIGNAL_FUNC) sig_cumode_changed);
155         signal_add("message silc founder",
156                         (SIGNAL_FUNC) sig_channel_founder);
157         signal_add("message silc quieted",
158                         (SIGNAL_FUNC) sig_quieted);
159         signal_add("message silc motd",
160                         (SIGNAL_FUNC) sig_motd);
161 }
162
163 void fe_silc_channels_deinit(void)
164 {
165         signal_remove("message silc appears", 
166                         (SIGNAL_FUNC) sig_message_appears);
167         signal_remove("message silc pubkeys",
168                         (SIGNAL_FUNC) sig_message_channel_pubkeys);
169         signal_remove("message silc generic",
170                         (SIGNAL_FUNC) sig_message_generic);
171         signal_remove("message silc cmode",
172                         (SIGNAL_FUNC) sig_cmode_changed);
173         signal_remove("message silc cumode",
174                         (SIGNAL_FUNC) sig_cumode_changed);
175         signal_remove("message silc founder",
176                         (SIGNAL_FUNC) sig_channel_founder);
177         signal_remove("message silc quieted",
178                         (SIGNAL_FUNC) sig_quieted);
179         signal_remove("message silc motd",
180                         (SIGNAL_FUNC) sig_motd);
181 }