8849
|
1 /*
|
|
2
|
|
3 silcgaim_ops.c
|
|
4
|
|
5 Author: Pekka Riikonen <priikone@silcnet.org>
|
|
6
|
|
7 Copyright (C) 2004 Pekka Riikonen
|
|
8
|
|
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; version 2 of the License.
|
|
12
|
|
13 This program is distributed in the hope that it will be useful,
|
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 GNU General Public License for more details.
|
|
17
|
|
18 */
|
|
19
|
|
20 #include "silcincludes.h"
|
|
21 #include "silcclient.h"
|
|
22 #include "silcgaim.h"
|
|
23
|
|
24 /* Message sent to the application by library. `conn' associates the
|
|
25 message to a specific connection. `conn', however, may be NULL.
|
|
26 The `type' indicates the type of the message sent by the library.
|
|
27 The application can for example filter the message according the
|
|
28 type. */
|
|
29
|
|
30 static void
|
|
31 silc_say(SilcClient client, SilcClientConnection conn,
|
|
32 SilcClientMessageType type, char *msg, ...)
|
|
33 {
|
|
34 /* Nothing */
|
|
35 }
|
|
36
|
|
37
|
|
38 /* Message for a channel. The `sender' is the sender of the message
|
|
39 The `channel' is the channel. The `message' is the message. Note
|
|
40 that `message' maybe NULL. The `flags' indicates message flags
|
|
41 and it is used to determine how the message can be interpreted
|
|
42 (like it may tell the message is multimedia message). */
|
|
43
|
|
44 static void
|
|
45 silc_channel_message(SilcClient client, SilcClientConnection conn,
|
|
46 SilcClientEntry sender, SilcChannelEntry channel,
|
|
47 SilcMessagePayload payload, SilcChannelPrivateKey key,
|
|
48 SilcMessageFlags flags, const unsigned char *message,
|
|
49 SilcUInt32 message_len)
|
|
50 {
|
|
51 GaimConnection *gc = client->application;
|
|
52 SilcGaim sg = gc->proto_data;
|
|
53 GaimConversation *convo = NULL;
|
9359
|
54 char *msg, *tmp;
|
8849
|
55
|
|
56 if (!message)
|
|
57 return;
|
|
58
|
|
59 if (key) {
|
|
60 GList *l;
|
|
61 SilcGaimPrvgrp prv;
|
|
62
|
|
63 for (l = sg->grps; l; l = l->next)
|
|
64 if (((SilcGaimPrvgrp)l->data)->key == key) {
|
|
65 prv = l->data;
|
|
66 convo = gaim_find_conversation_with_account(prv->channel,
|
|
67 sg->account);
|
|
68 break;
|
|
69 }
|
|
70 }
|
|
71 if (!convo)
|
|
72 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
73 sg->account);
|
|
74 if (!convo)
|
|
75 return;
|
|
76
|
|
77 if (flags & SILC_MESSAGE_FLAG_SIGNED &&
|
|
78 gaim_prefs_get_bool("/plugins/prpl/silc/verify_chat")) {
|
|
79 /* XXX */
|
|
80 }
|
|
81
|
|
82 if (flags & SILC_MESSAGE_FLAG_DATA) {
|
|
83 /* XXX */
|
|
84 return;
|
|
85 }
|
|
86
|
|
87 if (flags & SILC_MESSAGE_FLAG_ACTION) {
|
9353
|
88 msg = g_strdup_printf("/me %s",
|
8849
|
89 (const char *)message);
|
|
90 if (!msg)
|
|
91 return;
|
|
92
|
9359
|
93 tmp = gaim_escape_html(msg);
|
8849
|
94 /* Send to Gaim */
|
9353
|
95 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)),
|
|
96 sender->nickname ?
|
|
97 sender->nickname : "<unknown>", 0,
|
9359
|
98 tmp, time(NULL));
|
|
99 g_free(tmp);
|
8849
|
100 g_free(msg);
|
|
101 return;
|
|
102 }
|
|
103
|
|
104 if (flags & SILC_MESSAGE_FLAG_NOTICE) {
|
|
105 msg = g_strdup_printf("(notice) <I>%s</I> %s",
|
|
106 sender->nickname ?
|
|
107 sender->nickname : "<unknown>",
|
|
108 (const char *)message);
|
|
109 if (!msg)
|
|
110 return;
|
|
111
|
|
112 /* Send to Gaim */
|
|
113 gaim_conversation_write(convo, NULL, (const char *)msg,
|
|
114 GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
115 g_free(msg);
|
|
116 return;
|
|
117 }
|
|
118
|
9359
|
119 if (flags & SILC_MESSAGE_FLAG_UTF8) {
|
|
120 tmp = gaim_escape_html((const char *)message);
|
8849
|
121 /* Send to Gaim */
|
|
122 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)),
|
|
123 sender->nickname ?
|
|
124 sender->nickname : "<unknown>", 0,
|
9359
|
125 tmp, time(NULL));
|
|
126 g_free(tmp);
|
|
127 }
|
8849
|
128 }
|
|
129
|
|
130
|
|
131 /* Private message to the client. The `sender' is the sender of the
|
|
132 message. The message is `message'and maybe NULL. The `flags'
|
|
133 indicates message flags and it is used to determine how the message
|
|
134 can be interpreted (like it may tell the message is multimedia
|
|
135 message). */
|
|
136
|
|
137 static void
|
|
138 silc_private_message(SilcClient client, SilcClientConnection conn,
|
|
139 SilcClientEntry sender, SilcMessagePayload payload,
|
|
140 SilcMessageFlags flags, const unsigned char *message,
|
|
141 SilcUInt32 message_len)
|
|
142 {
|
|
143 GaimConnection *gc = client->application;
|
|
144 SilcGaim sg = gc->proto_data;
|
|
145 GaimConversation *convo = NULL;
|
9359
|
146 char *msg, *tmp;
|
8849
|
147
|
|
148 if (!message)
|
|
149 return;
|
|
150
|
|
151 if (sender->nickname)
|
|
152 convo = gaim_find_conversation_with_account(sender->nickname, sg->account);
|
|
153
|
|
154 if (flags & SILC_MESSAGE_FLAG_SIGNED &&
|
|
155 gaim_prefs_get_bool("/plugins/prpl/silc/verify_im")) {
|
|
156 /* XXX */
|
|
157 }
|
|
158
|
|
159 if (flags & SILC_MESSAGE_FLAG_DATA) {
|
|
160 /* XXX */
|
|
161 return;
|
|
162 }
|
|
163
|
|
164 if (flags & SILC_MESSAGE_FLAG_ACTION && convo) {
|
9353
|
165 msg = g_strdup_printf("/me %s",
|
8849
|
166 (const char *)message);
|
|
167 if (!msg)
|
|
168 return;
|
|
169
|
9359
|
170 tmp = gaim_escape_html(msg);
|
8849
|
171 /* Send to Gaim */
|
9353
|
172 serv_got_im(gc, sender->nickname ?
|
|
173 sender->nickname : "<unknown>",
|
9359
|
174 tmp, 0, time(NULL));
|
8849
|
175 g_free(msg);
|
9359
|
176 g_free(tmp);
|
8849
|
177 return;
|
|
178 }
|
|
179
|
|
180 if (flags & SILC_MESSAGE_FLAG_NOTICE && convo) {
|
|
181 msg = g_strdup_printf("(notice) <I>%s</I> %s",
|
|
182 sender->nickname ?
|
|
183 sender->nickname : "<unknown>",
|
|
184 (const char *)message);
|
|
185 if (!msg)
|
|
186 return;
|
|
187
|
|
188 /* Send to Gaim */
|
|
189 gaim_conversation_write(convo, NULL, (const char *)msg,
|
|
190 GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
191 g_free(msg);
|
|
192 return;
|
|
193 }
|
|
194
|
9359
|
195 if (flags & SILC_MESSAGE_FLAG_UTF8) {
|
|
196 tmp = gaim_escape_html((const char *)message);
|
8849
|
197 /* Send to Gaim */
|
|
198 serv_got_im(gc, sender->nickname ?
|
|
199 sender->nickname : "<unknown>",
|
9359
|
200 tmp, 0, time(NULL));
|
|
201 g_free(tmp);
|
|
202 }
|
8849
|
203 }
|
|
204
|
|
205
|
|
206 /* Notify message to the client. The notify arguments are sent in the
|
|
207 same order as servers sends them. The arguments are same as received
|
|
208 from the server except for ID's. If ID is received application receives
|
|
209 the corresponding entry to the ID. For example, if Client ID is received
|
|
210 application receives SilcClientEntry. Also, if the notify type is
|
|
211 for channel the channel entry is sent to application (even if server
|
|
212 does not send it because client library gets the channel entry from
|
|
213 the Channel ID in the packet's header). */
|
|
214
|
|
215 static void
|
|
216 silc_notify(SilcClient client, SilcClientConnection conn,
|
|
217 SilcNotifyType type, ...)
|
|
218 {
|
|
219 va_list va;
|
|
220 GaimConnection *gc = client->application;
|
|
221 SilcGaim sg = gc->proto_data;
|
|
222 GaimConversation *convo;
|
|
223 SilcClientEntry client_entry, client_entry2;
|
|
224 SilcChannelEntry channel;
|
|
225 SilcServerEntry server_entry;
|
|
226 SilcIdType idtype;
|
|
227 void *entry;
|
|
228 SilcUInt32 mode;
|
|
229 SilcHashTableList htl;
|
|
230 SilcChannelUser chu;
|
|
231 char buf[512], buf2[512], *tmp, *name;
|
|
232 SilcBuffer buffer;
|
|
233 SilcNotifyType notify;
|
|
234 GaimBuddy *b;
|
|
235 int i;
|
|
236
|
|
237 va_start(va, type);
|
|
238 memset(buf, 0, sizeof(buf));
|
|
239
|
|
240 switch (type) {
|
|
241
|
|
242 case SILC_NOTIFY_TYPE_NONE:
|
|
243 break;
|
|
244
|
|
245 case SILC_NOTIFY_TYPE_INVITE:
|
|
246 {
|
|
247 GHashTable *components;
|
|
248 channel = va_arg(va, SilcChannelEntry);
|
|
249 name = va_arg(va, char *);
|
|
250 client_entry = va_arg(va, SilcClientEntry);
|
|
251
|
|
252 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
9353
|
253 g_hash_table_insert(components, strdup("channel"), strdup(name));
|
|
254 serv_got_chat_invite(gc, name, client_entry->nickname, NULL, components);
|
8849
|
255 }
|
|
256 break;
|
|
257
|
|
258 case SILC_NOTIFY_TYPE_JOIN:
|
|
259 client_entry = va_arg(va, SilcClientEntry);
|
|
260 channel = va_arg(va, SilcChannelEntry);
|
|
261
|
|
262 /* If we joined channel, do nothing */
|
|
263 if (client_entry == conn->local_entry)
|
|
264 break;
|
|
265
|
|
266 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
267 sg->account);
|
|
268 if (!convo)
|
|
269 break;
|
|
270
|
|
271 /* Join user to channel */
|
8891
|
272 g_snprintf(buf, sizeof(buf), "%s@%s",
|
8849
|
273 client_entry->username, client_entry->hostname);
|
|
274 gaim_conv_chat_add_user(GAIM_CONV_CHAT(convo),
|
9554
|
275 g_strdup(client_entry->nickname), buf, GAIM_CBFLAGS_NONE);
|
8849
|
276
|
|
277 break;
|
|
278
|
|
279 case SILC_NOTIFY_TYPE_LEAVE:
|
|
280 client_entry = va_arg(va, SilcClientEntry);
|
|
281 channel = va_arg(va, SilcChannelEntry);
|
|
282
|
|
283 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
284 sg->account);
|
|
285 if (!convo)
|
|
286 break;
|
|
287
|
|
288 /* Remove user from channel */
|
|
289 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo),
|
|
290 client_entry->nickname, NULL);
|
|
291
|
|
292 break;
|
|
293
|
|
294 case SILC_NOTIFY_TYPE_SIGNOFF:
|
|
295 client_entry = va_arg(va, SilcClientEntry);
|
|
296 tmp = va_arg(va, char *);
|
|
297
|
|
298 if (!client_entry->nickname)
|
|
299 break;
|
|
300
|
|
301 /* Remove from all channels */
|
|
302 silc_hash_table_list(client_entry->channels, &htl);
|
|
303 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
304 convo = gaim_find_conversation_with_account(chu->channel->channel_name,
|
|
305 sg->account);
|
|
306 if (!convo)
|
|
307 continue;
|
|
308 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo),
|
|
309 client_entry->nickname,
|
|
310 tmp);
|
|
311 }
|
|
312 silc_hash_table_list_reset(&htl);
|
|
313
|
|
314 break;
|
|
315
|
|
316 case SILC_NOTIFY_TYPE_TOPIC_SET:
|
|
317 idtype = va_arg(va, int);
|
|
318 entry = va_arg(va, void *);
|
|
319 tmp = va_arg(va, char *);
|
|
320 channel = va_arg(va, SilcChannelEntry);
|
|
321
|
|
322 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
323 sg->account);
|
|
324 if (!convo)
|
|
325 break;
|
|
326
|
|
327 if (!tmp)
|
|
328 break;
|
|
329
|
|
330 if (idtype == SILC_ID_CLIENT) {
|
|
331 client_entry = (SilcClientEntry)entry;
|
|
332 g_snprintf(buf, sizeof(buf),
|
|
333 _("%s has changed the topic of <I>%s</I> to: %s"),
|
|
334 client_entry->nickname, channel->channel_name, tmp);
|
|
335 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), client_entry->nickname,
|
|
336 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
9518
|
337 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo),
|
|
338 client_entry->nickname, tmp);
|
8849
|
339 } else if (idtype == SILC_ID_SERVER) {
|
|
340 server_entry = (SilcServerEntry)entry;
|
|
341 g_snprintf(buf, sizeof(buf),
|
|
342 _("%s has changed the topic of <I>%s</I> to: %s"),
|
|
343 server_entry->server_name, channel->channel_name, tmp);
|
|
344 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), server_entry->server_name,
|
|
345 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
9518
|
346 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo),
|
|
347 server_entry->server_name, tmp);
|
8849
|
348 } else if (idtype == SILC_ID_CHANNEL) {
|
|
349 channel = (SilcChannelEntry)entry;
|
|
350 g_snprintf(buf, sizeof(buf),
|
|
351 _("%s has changed the topic of <I>%s</I> to: %s"),
|
|
352 channel->channel_name, channel->channel_name, tmp);
|
|
353 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), channel->channel_name,
|
|
354 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
9518
|
355 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo),
|
|
356 channel->channel_name, tmp);
|
|
357 } else {
|
|
358 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo), NULL, tmp);
|
8849
|
359 }
|
|
360
|
|
361 break;
|
|
362
|
|
363 case SILC_NOTIFY_TYPE_NICK_CHANGE:
|
|
364 client_entry = va_arg(va, SilcClientEntry);
|
|
365 client_entry2 = va_arg(va, SilcClientEntry);
|
|
366
|
|
367 if (!strcmp(client_entry->nickname, client_entry2->nickname))
|
|
368 break;
|
|
369
|
|
370 /* Change nick on all channels */
|
|
371 silc_hash_table_list(client_entry2->channels, &htl);
|
|
372 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
373 convo = gaim_find_conversation_with_account(chu->channel->channel_name,
|
|
374 sg->account);
|
|
375 if (!convo)
|
|
376 continue;
|
|
377 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(convo),
|
|
378 client_entry->nickname,
|
|
379 client_entry2->nickname);
|
|
380 }
|
|
381 silc_hash_table_list_reset(&htl);
|
|
382
|
|
383 break;
|
|
384
|
|
385 case SILC_NOTIFY_TYPE_CMODE_CHANGE:
|
|
386 idtype = va_arg(va, int);
|
|
387 entry = va_arg(va, void *);
|
|
388 mode = va_arg(va, SilcUInt32);
|
|
389 (void)va_arg(va, char *);
|
|
390 (void)va_arg(va, char *);
|
|
391 (void)va_arg(va, char *);
|
|
392 (void)va_arg(va, SilcPublicKey);
|
|
393 buffer = va_arg(va, SilcBuffer);
|
|
394 channel = va_arg(va, SilcChannelEntry);
|
|
395
|
|
396 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
397 sg->account);
|
|
398 if (!convo)
|
|
399 break;
|
|
400
|
|
401 if (idtype == SILC_ID_CLIENT)
|
|
402 name = ((SilcClientEntry)entry)->nickname;
|
|
403 else if (idtype == SILC_ID_SERVER)
|
|
404 name = ((SilcServerEntry)entry)->server_name;
|
|
405 else
|
|
406 name = ((SilcChannelEntry)entry)->channel_name;
|
|
407 if (!name)
|
|
408 break;
|
|
409
|
|
410 if (mode) {
|
|
411 silcgaim_get_chmode_string(mode, buf2, sizeof(buf2));
|
|
412 g_snprintf(buf, sizeof(buf),
|
|
413 _("<I>%s</I> set channel <I>%s</I> modes to: %s"), name,
|
|
414 channel->channel_name, buf2);
|
|
415 } else {
|
|
416 g_snprintf(buf, sizeof(buf),
|
|
417 _("<I>%s</I> removed all channel <I>%s</I> modes"), name,
|
|
418 channel->channel_name);
|
|
419 }
|
|
420 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), channel->channel_name,
|
|
421 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
422 break;
|
|
423
|
|
424 case SILC_NOTIFY_TYPE_CUMODE_CHANGE:
|
9554
|
425 {
|
|
426 GaimConvChatBuddyFlags flags = GAIM_CBFLAGS_NONE;
|
|
427 idtype = va_arg(va, int);
|
|
428 entry = va_arg(va, void *);
|
|
429 mode = va_arg(va, SilcUInt32);
|
|
430 client_entry2 = va_arg(va, SilcClientEntry);
|
|
431 channel = va_arg(va, SilcChannelEntry);
|
8849
|
432
|
9554
|
433 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
434 sg->account);
|
|
435 if (!convo)
|
|
436 break;
|
8849
|
437
|
9554
|
438 if (idtype == SILC_ID_CLIENT)
|
|
439 name = ((SilcClientEntry)entry)->nickname;
|
|
440 else if (idtype == SILC_ID_SERVER)
|
|
441 name = ((SilcServerEntry)entry)->server_name;
|
|
442 else
|
|
443 name = ((SilcChannelEntry)entry)->channel_name;
|
|
444 if (!name)
|
|
445 break;
|
8849
|
446
|
9554
|
447 if (mode) {
|
|
448 silcgaim_get_chumode_string(mode, buf2, sizeof(buf2));
|
|
449 g_snprintf(buf, sizeof(buf),
|
|
450 _("<I>%s</I> set <I>%s's</I> modes to: %s"), name,
|
|
451 client_entry2->nickname, buf2);
|
|
452 if (mode & SILC_CHANNEL_UMODE_CHANFO)
|
|
453 flags |= GAIM_CBFLAGS_FOUNDER;
|
|
454 if (mode & SILC_CHANNEL_UMODE_CHANOP)
|
|
455 flags |= GAIM_CBFLAGS_OP;
|
|
456 } else {
|
|
457 g_snprintf(buf, sizeof(buf),
|
|
458 _("<I>%s</I> removed all <I>%s's</I> modes"), name,
|
|
459 client_entry2->nickname);
|
|
460 }
|
|
461 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), channel->channel_name,
|
|
462 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
463 gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(convo), client_entry2->nickname, flags);
|
|
464 break;
|
8849
|
465 }
|
|
466
|
|
467 case SILC_NOTIFY_TYPE_MOTD:
|
|
468 tmp = va_arg(va, char *);
|
|
469 silc_free(sg->motd);
|
|
470 sg->motd = silc_memdup(tmp, strlen(tmp));
|
|
471 break;
|
|
472
|
|
473 case SILC_NOTIFY_TYPE_KICKED:
|
|
474 client_entry = va_arg(va, SilcClientEntry);
|
|
475 tmp = va_arg(va, char *);
|
|
476 client_entry2 = va_arg(va, SilcClientEntry);
|
|
477 channel = va_arg(va, SilcChannelEntry);
|
|
478
|
|
479 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
480 sg->account);
|
|
481 if (!convo)
|
|
482 break;
|
|
483
|
|
484 if (client_entry == conn->local_entry) {
|
|
485 /* Remove us from channel */
|
|
486 g_snprintf(buf, sizeof(buf),
|
|
487 _("You have been kicked off <I>%s</I> by <I>%s</I> (%s)"),
|
|
488 channel->channel_name, client_entry2->nickname,
|
|
489 tmp ? tmp : "");
|
|
490 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), client_entry->nickname,
|
|
491 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
492 serv_got_chat_left(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)));
|
|
493 } else {
|
|
494 /* Remove user from channel */
|
|
495 g_snprintf(buf, sizeof(buf), ("Kicked by %s (%s)"),
|
|
496 client_entry2->nickname, tmp ? tmp : "");
|
9353
|
497 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo),
|
8849
|
498 client_entry->nickname,
|
|
499 buf);
|
|
500 }
|
|
501
|
|
502 break;
|
|
503
|
|
504 case SILC_NOTIFY_TYPE_KILLED:
|
|
505 client_entry = va_arg(va, SilcClientEntry);
|
|
506 tmp = va_arg(va, char *);
|
|
507 idtype = va_arg(va, int);
|
|
508 entry = va_arg(va, SilcClientEntry);
|
|
509
|
|
510 if (!client_entry->nickname)
|
|
511 break;
|
|
512
|
|
513 if (client_entry == conn->local_entry) {
|
|
514 if (idtype == SILC_ID_CLIENT) {
|
|
515 client_entry2 = (SilcClientEntry)entry;
|
|
516 g_snprintf(buf, sizeof(buf),
|
|
517 _("You have been killed by %s (%s)"),
|
|
518 client_entry2->nickname, tmp ? tmp : "");
|
|
519 } else if (idtype == SILC_ID_SERVER) {
|
|
520 server_entry = (SilcServerEntry)entry;
|
|
521 g_snprintf(buf, sizeof(buf),
|
|
522 _("You have been killed by %s (%s)"),
|
|
523 server_entry->server_name, tmp ? tmp : "");
|
|
524 } else if (idtype == SILC_ID_CHANNEL) {
|
|
525 channel = (SilcChannelEntry)entry;
|
|
526 g_snprintf(buf, sizeof(buf),
|
|
527 _("You have been killed by %s (%s)"),
|
|
528 channel->channel_name, tmp ? tmp : "");
|
|
529 }
|
|
530
|
|
531 /* Remove us from all channels */
|
|
532 silc_hash_table_list(client_entry->channels, &htl);
|
|
533 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
534 convo = gaim_find_conversation_with_account(chu->channel->channel_name,
|
|
535 sg->account);
|
|
536 if (!convo)
|
|
537 continue;
|
|
538 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), client_entry->nickname,
|
|
539 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
540 serv_got_chat_left(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)));
|
|
541 }
|
|
542 silc_hash_table_list_reset(&htl);
|
|
543
|
|
544 } else {
|
|
545 if (idtype == SILC_ID_CLIENT) {
|
|
546 client_entry2 = (SilcClientEntry)entry;
|
|
547 g_snprintf(buf, sizeof(buf),
|
|
548 _("Killed by %s (%s)"),
|
|
549 client_entry2->nickname, tmp ? tmp : "");
|
|
550 } else if (idtype == SILC_ID_SERVER) {
|
|
551 server_entry = (SilcServerEntry)entry;
|
|
552 g_snprintf(buf, sizeof(buf),
|
|
553 _("Killed by %s (%s)"),
|
|
554 server_entry->server_name, tmp ? tmp : "");
|
|
555 } else if (idtype == SILC_ID_CHANNEL) {
|
|
556 channel = (SilcChannelEntry)entry;
|
|
557 g_snprintf(buf, sizeof(buf),
|
|
558 _("Killed by %s (%s)"),
|
|
559 channel->channel_name, tmp ? tmp : "");
|
|
560 }
|
|
561
|
|
562 /* Remove user from all channels */
|
|
563 silc_hash_table_list(client_entry->channels, &htl);
|
|
564 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
565 convo = gaim_find_conversation_with_account(chu->channel->channel_name,
|
|
566 sg->account);
|
|
567 if (!convo)
|
|
568 continue;
|
|
569 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo),
|
|
570 client_entry->nickname, tmp);
|
|
571 }
|
|
572 silc_hash_table_list_reset(&htl);
|
|
573 }
|
|
574
|
|
575 break;
|
|
576
|
|
577 case SILC_NOTIFY_TYPE_CHANNEL_CHANGE:
|
|
578 break;
|
|
579
|
|
580 case SILC_NOTIFY_TYPE_SERVER_SIGNOFF:
|
|
581 {
|
|
582 int i;
|
|
583 SilcClientEntry *clients;
|
|
584 SilcUInt32 clients_count;
|
|
585
|
|
586 (void)va_arg(va, void *);
|
|
587 clients = va_arg(va, SilcClientEntry *);
|
|
588 clients_count = va_arg(va, SilcUInt32);
|
|
589
|
|
590 for (i = 0; i < clients_count; i++) {
|
|
591 if (!clients[i]->nickname)
|
|
592 break;
|
|
593
|
|
594 /* Remove from all channels */
|
|
595 silc_hash_table_list(clients[i]->channels, &htl);
|
|
596 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
597 convo =
|
|
598 gaim_find_conversation_with_account(chu->channel->channel_name,
|
|
599 sg->account);
|
|
600 if (!convo)
|
|
601 continue;
|
|
602 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo),
|
|
603 clients[i]->nickname,
|
|
604 _("Server signoff"));
|
|
605 }
|
|
606 silc_hash_table_list_reset(&htl);
|
|
607 }
|
|
608 }
|
|
609 break;
|
|
610
|
|
611 case SILC_NOTIFY_TYPE_ERROR:
|
|
612 {
|
|
613 SilcStatus error = va_arg(va, int);
|
|
614 gaim_notify_error(gc, "Error Notify",
|
|
615 silc_get_status_message(error),
|
|
616 NULL);
|
|
617 }
|
|
618 break;
|
|
619
|
|
620 case SILC_NOTIFY_TYPE_WATCH:
|
|
621 {
|
|
622 SilcPublicKey public_key;
|
|
623 unsigned char *pk;
|
|
624 SilcUInt32 pk_len;
|
|
625 char *fingerprint;
|
|
626
|
|
627 client_entry = va_arg(va, SilcClientEntry);
|
|
628 (void)va_arg(va, char *);
|
|
629 mode = va_arg(va, SilcUInt32);
|
|
630 notify = va_arg(va, int);
|
|
631 public_key = va_arg(va, SilcPublicKey);
|
|
632
|
|
633 b = NULL;
|
|
634 if (public_key) {
|
|
635 GaimBlistNode *gnode, *cnode, *bnode;
|
|
636 const char *f;
|
|
637
|
|
638 pk = silc_pkcs_public_key_encode(public_key, &pk_len);
|
|
639 if (!pk)
|
|
640 break;
|
|
641 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
|
|
642 for (i = 0; i < strlen(fingerprint); i++)
|
|
643 if (fingerprint[i] == ' ')
|
|
644 fingerprint[i] = '_';
|
|
645 g_snprintf(buf, sizeof(buf) - 1,
|
|
646 "%s" G_DIR_SEPARATOR_S "clientkeys"
|
|
647 G_DIR_SEPARATOR_S "clientkey_%s.pub",
|
|
648 silcgaim_silcdir(), fingerprint);
|
|
649 silc_free(fingerprint);
|
|
650 silc_free(pk);
|
|
651
|
|
652 /* Find buddy by associated public key */
|
|
653 for (gnode = gaim_get_blist()->root; gnode;
|
|
654 gnode = gnode->next) {
|
|
655 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
|
|
656 continue;
|
|
657 for (cnode = gnode->child; cnode; cnode = cnode->next) {
|
|
658 if( !GAIM_BLIST_NODE_IS_CONTACT(cnode))
|
|
659 continue;
|
|
660 for (bnode = cnode->child; bnode;
|
|
661 bnode = bnode->next) {
|
|
662 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode))
|
|
663 continue;
|
|
664 b = (GaimBuddy *)bnode;
|
|
665 if (b->account != gc->account)
|
|
666 continue;
|
|
667 f = gaim_blist_node_get_string(bnode, "public-key");
|
|
668 if (!strcmp(f, buf))
|
|
669 goto cont;
|
|
670 }
|
|
671 }
|
|
672 }
|
|
673 }
|
|
674 cont:
|
|
675 if (!b) {
|
|
676 /* Find buddy by nickname */
|
|
677 b = gaim_find_buddy(sg->account, client_entry->nickname);
|
|
678 if (!b) {
|
9272
|
679 gaim_debug_warning("silc", "WATCH for %s, unknown buddy",
|
8849
|
680 client_entry->nickname);
|
|
681 break;
|
|
682 }
|
|
683 }
|
|
684
|
|
685 silc_free(b->proto_data);
|
|
686 b->proto_data = silc_memdup(client_entry->id,
|
|
687 sizeof(*client_entry->id));
|
|
688 if (notify == SILC_NOTIFY_TYPE_NICK_CHANGE) {
|
|
689 break;
|
|
690 } else if (notify == SILC_NOTIFY_TYPE_UMODE_CHANGE) {
|
|
691 /* See if client was away and is now present */
|
|
692 if (!(mode & (SILC_UMODE_GONE | SILC_UMODE_INDISPOSED |
|
|
693 SILC_UMODE_BUSY | SILC_UMODE_PAGE |
|
|
694 SILC_UMODE_DETACHED)) &&
|
|
695 (client_entry->mode & SILC_UMODE_GONE ||
|
|
696 client_entry->mode & SILC_UMODE_INDISPOSED ||
|
|
697 client_entry->mode & SILC_UMODE_BUSY ||
|
|
698 client_entry->mode & SILC_UMODE_PAGE ||
|
|
699 client_entry->mode & SILC_UMODE_DETACHED)) {
|
|
700 client_entry->mode = mode;
|
|
701 gaim_blist_update_buddy_presence(b, GAIM_BUDDY_ONLINE);
|
|
702 }
|
|
703 else if ((mode & SILC_UMODE_GONE) ||
|
|
704 (mode & SILC_UMODE_INDISPOSED) ||
|
|
705 (mode & SILC_UMODE_BUSY) ||
|
|
706 (mode & SILC_UMODE_PAGE) ||
|
|
707 (mode & SILC_UMODE_DETACHED)) {
|
|
708 client_entry->mode = mode;
|
|
709 gaim_blist_update_buddy_presence(b, GAIM_BUDDY_OFFLINE);
|
|
710 }
|
|
711 } else if (notify == SILC_NOTIFY_TYPE_SIGNOFF ||
|
|
712 notify == SILC_NOTIFY_TYPE_SERVER_SIGNOFF ||
|
|
713 notify == SILC_NOTIFY_TYPE_KILLED) {
|
|
714 client_entry->mode = mode;
|
|
715 gaim_blist_update_buddy_presence(b, GAIM_BUDDY_OFFLINE);
|
|
716 } else if (notify == SILC_NOTIFY_TYPE_NONE) {
|
|
717 client_entry->mode = mode;
|
|
718 gaim_blist_update_buddy_presence(b, GAIM_BUDDY_ONLINE);
|
|
719 }
|
|
720 }
|
|
721 break;
|
|
722
|
|
723 default:
|
9353
|
724 gaim_debug_info("silc", "Unhandled notification: %d\n", type);
|
8849
|
725 break;
|
|
726 }
|
|
727
|
|
728 va_end(va);
|
|
729 }
|
|
730
|
|
731
|
|
732 /* Command handler. This function is called always in the command function.
|
|
733 If error occurs it will be called as well. `conn' is the associated
|
|
734 client connection. `cmd_context' is the command context that was
|
|
735 originally sent to the command. `success' is FALSE if error occurred
|
|
736 during command. `command' is the command being processed. It must be
|
|
737 noted that this is not reply from server. This is merely called just
|
|
738 after application has called the command. Just to tell application
|
|
739 that the command really was processed. */
|
|
740
|
|
741 static void
|
|
742 silc_command(SilcClient client, SilcClientConnection conn,
|
|
743 SilcClientCommandContext cmd_context, bool success,
|
|
744 SilcCommand command, SilcStatus status)
|
|
745 {
|
|
746 GaimConnection *gc = client->application;
|
|
747 SilcGaim sg = gc->proto_data;
|
|
748
|
|
749 switch (command) {
|
|
750
|
|
751 case SILC_COMMAND_CMODE:
|
|
752 if (cmd_context->argc == 3 &&
|
|
753 !strcmp(cmd_context->argv[2], "+C"))
|
|
754 sg->chpk = TRUE;
|
|
755 else
|
|
756 sg->chpk = FALSE;
|
|
757 break;
|
|
758
|
|
759 default:
|
|
760 break;
|
|
761 }
|
|
762 }
|
|
763
|
9024
|
764 #if 0
|
8849
|
765 static void
|
|
766 silcgaim_whois_more(SilcClientEntry client_entry, gint id)
|
|
767 {
|
|
768 SilcAttributePayload attr;
|
|
769 SilcAttribute attribute;
|
|
770 char *buf;
|
|
771 GString *s;
|
|
772 SilcVCardStruct vcard;
|
|
773 int i;
|
|
774
|
|
775 if (id != 0)
|
|
776 return;
|
|
777
|
|
778 memset(&vcard, 0, sizeof(vcard));
|
|
779
|
|
780 s = g_string_new("");
|
|
781
|
|
782 silc_dlist_start(client_entry->attrs);
|
|
783 while ((attr = silc_dlist_get(client_entry->attrs)) != SILC_LIST_END) {
|
|
784 attribute = silc_attribute_get_attribute(attr);
|
|
785 switch (attribute) {
|
|
786
|
|
787 case SILC_ATTRIBUTE_USER_INFO:
|
|
788 if (!silc_attribute_get_object(attr, (void *)&vcard,
|
|
789 sizeof(vcard)))
|
|
790 continue;
|
9039
|
791 g_string_append_printf(s, "%s:\n\n", _("Personal Information"));
|
8849
|
792 if (vcard.full_name)
|
9039
|
793 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
794 _("Full Name"),
|
8849
|
795 vcard.full_name);
|
|
796 if (vcard.first_name)
|
9039
|
797 g_string_append_printf(s, "%s:\t%s\n",
|
|
798 _("First Name"),
|
8849
|
799 vcard.first_name);
|
|
800 if (vcard.middle_names)
|
9039
|
801 g_string_append_printf(s, "%s:\t%s\n",
|
|
802 _("Middle Name"),
|
8849
|
803 vcard.middle_names);
|
|
804 if (vcard.family_name)
|
9039
|
805 g_string_append_printf(s, "%s:\t%s\n",
|
|
806 _("Family Name"),
|
8849
|
807 vcard.family_name);
|
|
808 if (vcard.nickname)
|
9039
|
809 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
810 _("Nickname"),
|
8849
|
811 vcard.nickname);
|
|
812 if (vcard.bday)
|
9039
|
813 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
814 _("Birth Day"),
|
8849
|
815 vcard.bday);
|
|
816 if (vcard.title)
|
9039
|
817 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
818 _("Job Title"),
|
8849
|
819 vcard.title);
|
|
820 if (vcard.role)
|
9039
|
821 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
822 _("Job Role"),
|
8849
|
823 vcard.role);
|
|
824 if (vcard.org_name)
|
9039
|
825 g_string_append_printf(s, "%s:\t%s\n",
|
|
826 _("Organization"),
|
8849
|
827 vcard.org_name);
|
|
828 if (vcard.org_unit)
|
9039
|
829 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
830 _("Unit"),
|
8849
|
831 vcard.org_unit);
|
|
832 if (vcard.url)
|
9039
|
833 g_string_append_printf(s, "%s:\t%s\n",
|
|
834 _("Homepage"),
|
8849
|
835 vcard.url);
|
|
836 if (vcard.label)
|
9039
|
837 g_string_append_printf(s, "%s:\t%s\n",
|
|
838 _("Address"),
|
8849
|
839 vcard.label);
|
|
840 for (i = 0; i < vcard.num_tels; i++) {
|
|
841 if (vcard.tels[i].telnum)
|
9039
|
842 g_string_append_printf(s, "%s:\t\t\t%s\n",
|
|
843 _("Phone"),
|
8849
|
844 vcard.tels[i].telnum);
|
|
845 }
|
|
846 for (i = 0; i < vcard.num_emails; i++) {
|
|
847 if (vcard.emails[i].address)
|
9039
|
848 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
849 _("EMail"),
|
8849
|
850 vcard.emails[i].address);
|
|
851 }
|
|
852 if (vcard.note)
|
9039
|
853 g_string_append_printf(s, "\n%s:\t\t%s\n",
|
|
854 _("Note"),
|
8849
|
855 vcard.note);
|
|
856 break;
|
|
857 }
|
|
858 }
|
|
859
|
|
860 buf = g_string_free(s, FALSE);
|
|
861 gaim_notify_info(NULL, _("User Information"), _("User Information"),
|
|
862 buf);
|
|
863 g_free(buf);
|
|
864 }
|
9024
|
865 #endif
|
8849
|
866
|
|
867 /* Command reply handler. This function is called always in the command reply
|
|
868 function. If error occurs it will be called as well. Normal scenario
|
|
869 is that it will be called after the received command data has been parsed
|
|
870 and processed. The function is used to pass the received command data to
|
|
871 the application.
|
|
872
|
|
873 `conn' is the associated client connection. `cmd_payload' is the command
|
|
874 payload data received from server and it can be ignored. It is provided
|
|
875 if the application would like to re-parse the received command data,
|
|
876 however, it must be noted that the data is parsed already by the library
|
|
877 thus the payload can be ignored. `success' is FALSE if error occurred.
|
|
878 In this case arguments are not sent to the application. The `status' is
|
|
879 the command reply status server returned. The `command' is the command
|
|
880 reply being processed. The function has variable argument list and each
|
|
881 command defines the number and type of arguments it passes to the
|
|
882 application (on error they are not sent). */
|
|
883
|
|
884 static void
|
|
885 silc_command_reply(SilcClient client, SilcClientConnection conn,
|
|
886 SilcCommandPayload cmd_payload, bool success,
|
|
887 SilcCommand command, SilcStatus status, ...)
|
|
888 {
|
|
889 GaimConnection *gc = client->application;
|
|
890 SilcGaim sg = gc->proto_data;
|
|
891 GaimConversation *convo;
|
|
892 va_list vp;
|
|
893
|
|
894 va_start(vp, status);
|
|
895
|
|
896 switch (command) {
|
|
897 case SILC_COMMAND_JOIN:
|
|
898 {
|
|
899 SilcChannelEntry channel_entry;
|
|
900
|
|
901 if (!success) {
|
|
902 gaim_notify_error(gc, _("Join Chat"), _("Cannot join channel"),
|
|
903 silc_get_status_message(status));
|
|
904 return;
|
|
905 }
|
|
906
|
|
907 (void)va_arg(vp, char *);
|
|
908 channel_entry = va_arg(vp, SilcChannelEntry);
|
|
909
|
|
910 /* Resolve users on channel */
|
|
911 silc_client_get_clients_by_channel(client, conn, channel_entry,
|
|
912 silcgaim_chat_join_done,
|
|
913 channel_entry);
|
|
914 }
|
|
915 break;
|
|
916
|
|
917 case SILC_COMMAND_LEAVE:
|
|
918 break;
|
|
919
|
|
920 case SILC_COMMAND_USERS:
|
|
921 break;
|
|
922
|
|
923 case SILC_COMMAND_WHOIS:
|
|
924 {
|
|
925 SilcUInt32 idle, mode;
|
|
926 SilcBuffer channels, user_modes;
|
|
927 SilcClientEntry client_entry;
|
9488
|
928 char *buf, tmp[1024], *tmp2;
|
|
929 char *moodstr, *statusstr, *contactstr, *langstr, *devicestr, *tzstr, *geostr;
|
8849
|
930 GString *s;
|
|
931
|
|
932 if (!success) {
|
|
933 gaim_notify_error(gc, _("User Information"),
|
9488
|
934 _("Cannot get user information"),
|
|
935 silc_get_status_message(status));
|
8849
|
936 break;
|
|
937 }
|
|
938
|
|
939 client_entry = va_arg(vp, SilcClientEntry);
|
|
940 if (!client_entry->nickname)
|
|
941 break;
|
|
942 (void)va_arg(vp, char *);
|
|
943 (void)va_arg(vp, char *);
|
|
944 (void)va_arg(vp, char *);
|
|
945 channels = va_arg(vp, SilcBuffer);
|
|
946 mode = va_arg(vp, SilcUInt32);
|
|
947 idle = va_arg(vp, SilcUInt32);
|
|
948 (void)va_arg(vp, unsigned char *);
|
|
949 user_modes = va_arg(vp, SilcBuffer);
|
|
950
|
|
951 s = g_string_new("");
|
9488
|
952 tmp2 = gaim_escape_html(client_entry->nickname);
|
|
953 g_string_append_printf(s, "<b>%s:</b> %s", _("Nickname"), tmp2);
|
|
954 g_free(tmp2);
|
|
955 if (client_entry->realname) {
|
|
956 tmp2 = gaim_escape_html(client_entry->realname);
|
|
957 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Realname"), tmp2);
|
|
958 g_free(tmp2);
|
|
959 }
|
|
960 if (client_entry->username) {
|
|
961 tmp2 = gaim_escape_html(client_entry->username);
|
|
962 if (client_entry->hostname)
|
|
963 g_string_append_printf(s, "<br><b>%s:</b> %s@%s", _("Username"), tmp2, client_entry->hostname);
|
|
964 else
|
|
965 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Username"), tmp2);
|
|
966 g_free(tmp2);
|
|
967 }
|
|
968
|
|
969 if (client_entry->mode) {
|
|
970 g_string_append_printf(s, "<br><b>%s:</b> ", _("User Modes"));
|
|
971 memset(tmp, 0, sizeof(tmp));
|
|
972 silcgaim_get_umode_string(client_entry->mode,
|
|
973 tmp, sizeof(tmp) - strlen(tmp));
|
|
974 g_string_append_printf(s, "%s", tmp);
|
|
975 }
|
|
976
|
|
977 silcgaim_parse_attrs(client_entry->attrs, &moodstr, &statusstr, &contactstr, &langstr, &devicestr, &tzstr, &geostr);
|
|
978 if (moodstr) {
|
|
979 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Mood"), moodstr);
|
|
980 g_free(moodstr);
|
|
981 }
|
|
982
|
|
983 if (statusstr) {
|
|
984 tmp2 = gaim_escape_html(statusstr);
|
|
985 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Status Text"), tmp2);
|
|
986 g_free(statusstr);
|
|
987 g_free(tmp2);
|
|
988 }
|
|
989
|
|
990 if (contactstr) {
|
|
991 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Preferred Contact"), contactstr);
|
|
992 g_free(contactstr);
|
|
993 }
|
|
994
|
|
995 if (langstr) {
|
|
996 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Preferred Language"), langstr);
|
|
997 g_free(langstr);
|
|
998 }
|
|
999
|
|
1000 if (devicestr) {
|
|
1001 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Device"), devicestr);
|
|
1002 g_free(devicestr);
|
|
1003 }
|
|
1004
|
|
1005 if (tzstr) {
|
|
1006 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Timezone"), tzstr);
|
|
1007 g_free(tzstr);
|
|
1008 }
|
|
1009
|
|
1010 if (geostr) {
|
|
1011 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Geolocation"), geostr);
|
|
1012 g_free(geostr);
|
|
1013 }
|
|
1014
|
8849
|
1015 if (client_entry->server)
|
9488
|
1016 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Server"), client_entry->server);
|
8849
|
1017
|
|
1018 if (channels && user_modes) {
|
|
1019 SilcUInt32 *umodes;
|
|
1020 SilcDList list =
|
|
1021 silc_channel_payload_parse_list(channels->data,
|
9488
|
1022 channels->len);
|
8849
|
1023 if (list && silc_get_mode_list(user_modes,
|
9488
|
1024 silc_dlist_count(list),
|
|
1025 &umodes)) {
|
8849
|
1026 SilcChannelPayload entry;
|
|
1027 int i = 0;
|
|
1028
|
9488
|
1029 g_string_append_printf(s, "<br><b>%s:</b> ", _("Currently on"));
|
8849
|
1030 memset(tmp, 0, sizeof(tmp));
|
|
1031 silc_dlist_start(list);
|
|
1032 while ((entry = silc_dlist_get(list))
|
9488
|
1033 != SILC_LIST_END) {
|
8849
|
1034 SilcUInt32 name_len;
|
|
1035 char *m = silc_client_chumode_char(umodes[i++]);
|
|
1036 char *name = silc_channel_get_name(entry, &name_len);
|
|
1037 if (m)
|
|
1038 silc_strncat(tmp, sizeof(tmp) - 1, m, strlen(m));
|
|
1039 silc_strncat(tmp, sizeof(tmp) - 1, name, name_len);
|
|
1040 silc_strncat(tmp, sizeof(tmp) - 1, " ", 1);
|
|
1041 silc_free(m);
|
|
1042
|
|
1043 }
|
9488
|
1044 tmp2 = gaim_escape_html(tmp);
|
|
1045 g_string_append_printf(s, "%s", tmp2);
|
|
1046 g_free(tmp2);
|
8849
|
1047 silc_free(umodes);
|
|
1048 }
|
|
1049 }
|
|
1050
|
|
1051 if (client_entry->public_key) {
|
|
1052 char *fingerprint, *babbleprint;
|
|
1053 unsigned char *pk;
|
|
1054 SilcUInt32 pk_len;
|
|
1055 pk = silc_pkcs_public_key_encode(client_entry->public_key, &pk_len);
|
|
1056 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
|
|
1057 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len);
|
9488
|
1058 g_string_append_printf(s, "<br><b>%s:</b><br>%s", _("Public Key Fingerprint"), fingerprint);
|
|
1059 g_string_append_printf(s, "<br><b>%s:</b><br>%s", _("Public Key Babbleprint"), babbleprint);
|
8849
|
1060 silc_free(fingerprint);
|
|
1061 silc_free(babbleprint);
|
|
1062 silc_free(pk);
|
|
1063 }
|
|
1064
|
|
1065 buf = g_string_free(s, FALSE);
|
|
1066 #if 0 /* XXX for now, let's not show attrs here */
|
|
1067 if (client_entry->attrs)
|
|
1068 gaim_request_action(NULL, _("User Information"),
|
9488
|
1069 _("User Information"),
|
|
1070 buf, 1, client_entry, 2,
|
|
1071 _("OK"), G_CALLBACK(silcgaim_whois_more),
|
|
1072 _("More..."), G_CALLBACK(silcgaim_whois_more));
|
8849
|
1073 else
|
|
1074 #endif
|
9488
|
1075 gaim_notify_formatted(gc, NULL, _("Buddy Information"), NULL, buf, NULL, NULL);
|
|
1076 g_free(buf);
|
|
1077 }
|
|
1078 break;
|
|
1079
|
|
1080 case SILC_COMMAND_WHOWAS:
|
|
1081 {
|
|
1082 SilcClientEntry client_entry;
|
|
1083 char *buf, *nickname, *realname, *username, *tmp;
|
|
1084 GString *s;
|
|
1085
|
|
1086 if (!success) {
|
|
1087 gaim_notify_error(gc, _("User Information"),
|
|
1088 _("Cannot get user information"),
|
|
1089 silc_get_status_message(status));
|
|
1090 break;
|
|
1091 }
|
|
1092
|
|
1093 client_entry = va_arg(vp, SilcClientEntry);
|
|
1094 nickname = va_arg(vp, char *);
|
|
1095 username = va_arg(vp, char *);
|
|
1096 realname = va_arg(vp, char *);
|
|
1097 if (!nickname)
|
|
1098 break;
|
|
1099
|
|
1100 s = g_string_new("");
|
|
1101 tmp = gaim_escape_html(nickname);
|
|
1102 g_string_append_printf(s, "<b>%s:</b> %s", _("Nickname"), tmp);
|
|
1103 g_free(tmp);
|
|
1104 if (realname) {
|
|
1105 tmp = gaim_escape_html(realname);
|
|
1106 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Realname"), tmp);
|
|
1107 g_free(tmp);
|
|
1108 }
|
|
1109 if (username) {
|
|
1110 tmp = gaim_escape_html(username);
|
|
1111 if (client_entry && client_entry->hostname)
|
|
1112 g_string_append_printf(s, "<br><b>%s:</b> %s@%s", _("Username"), tmp, client_entry->hostname);
|
|
1113 else
|
|
1114 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Username"), tmp);
|
|
1115 g_free(tmp);
|
|
1116 }
|
|
1117 if (client_entry && client_entry->server)
|
|
1118 g_string_append_printf(s, "<br><b>%s:</b> %s", _("Server"), client_entry->server);
|
|
1119
|
|
1120
|
|
1121 if (client_entry && client_entry->public_key) {
|
|
1122 char *fingerprint, *babbleprint;
|
|
1123 unsigned char *pk;
|
|
1124 SilcUInt32 pk_len;
|
|
1125 pk = silc_pkcs_public_key_encode(client_entry->public_key, &pk_len);
|
|
1126 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
|
|
1127 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len);
|
|
1128 g_string_append_printf(s, "<br><b>%s:</b><br>%s", _("Public Key Fingerprint"), fingerprint);
|
|
1129 g_string_append_printf(s, "<br><b>%s:</b><br>%s", _("Public Key Babbleprint"), babbleprint);
|
|
1130 silc_free(fingerprint);
|
|
1131 silc_free(babbleprint);
|
|
1132 silc_free(pk);
|
|
1133 }
|
|
1134
|
|
1135 buf = g_string_free(s, FALSE);
|
|
1136 gaim_notify_formatted(gc, NULL, _("Buddy Information"), NULL, buf, NULL, NULL);
|
8849
|
1137 g_free(buf);
|
|
1138 }
|
|
1139 break;
|
|
1140
|
|
1141 case SILC_COMMAND_DETACH:
|
|
1142 if (!success) {
|
|
1143 gaim_notify_error(gc, _("Detach From Server"), _("Cannot detach"),
|
|
1144 silc_get_status_message(status));
|
|
1145 return;
|
|
1146 }
|
|
1147 break;
|
|
1148
|
|
1149 case SILC_COMMAND_TOPIC:
|
|
1150 {
|
|
1151 SilcChannelEntry channel;
|
|
1152
|
|
1153 if (!success) {
|
|
1154 gaim_notify_error(gc, _("Topic"), _("Cannot set topic"),
|
|
1155 silc_get_status_message(status));
|
|
1156 return;
|
|
1157 }
|
|
1158
|
|
1159 channel = va_arg(vp, SilcChannelEntry);
|
|
1160
|
|
1161 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
1162 sg->account);
|
9353
|
1163 if (!convo) {
|
|
1164 gaim_debug_error("silc", "Got a topic for %s, which doesn't exist\n",
|
|
1165 channel->channel_name);
|
8849
|
1166 break;
|
9353
|
1167 }
|
|
1168
|
|
1169 if (gaim_conversation_get_type(convo) != GAIM_CONV_CHAT) {
|
|
1170 gaim_debug_error("silc", "Got a topic for %s, which isn't a chat\n",
|
|
1171 channel->channel_name);
|
|
1172 break;
|
|
1173 }
|
8849
|
1174
|
|
1175 /* Set topic */
|
|
1176 if (channel->topic)
|
|
1177 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo), NULL, channel->topic);
|
|
1178 }
|
|
1179 break;
|
|
1180
|
9353
|
1181 case SILC_COMMAND_NICK:
|
|
1182 {
|
|
1183 /* I don't think we should need to do this because the server should
|
|
1184 * be sending a SILC_NOTIFY_TYPE_NICK_CHANGE when we change our own
|
|
1185 * nick, but it isn't, so we deal with it here instead. Stu. */
|
|
1186 SilcClientEntry local_entry;
|
|
1187 SilcHashTableList htl;
|
|
1188 SilcChannelUser chu;
|
|
1189 const char *oldnick;
|
|
1190
|
|
1191 if (!success) {
|
9488
|
1192 gaim_notify_error(gc, _("Nick"), _("Failed to change nickname"),
|
|
1193 silc_get_status_message(status));
|
9353
|
1194 return;
|
|
1195 }
|
|
1196
|
|
1197 local_entry = va_arg(vp, SilcClientEntry);
|
|
1198
|
|
1199 /* Change nick on all channels */
|
|
1200 silc_hash_table_list(local_entry->channels, &htl);
|
|
1201 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
1202 convo = gaim_find_conversation_with_account(chu->channel->channel_name,
|
|
1203 sg->account);
|
|
1204 if (!convo || (gaim_conversation_get_type(convo) != GAIM_CONV_CHAT))
|
|
1205 continue;
|
|
1206 oldnick = gaim_conv_chat_get_nick(GAIM_CONV_CHAT(convo));
|
|
1207 if (strcmp(oldnick, local_entry->nickname)) {
|
|
1208 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(convo),
|
|
1209 oldnick, local_entry->nickname);
|
|
1210 gaim_conv_chat_set_nick(GAIM_CONV_CHAT(convo), local_entry->nickname);
|
|
1211 }
|
|
1212 }
|
|
1213 silc_hash_table_list_reset(&htl);
|
9488
|
1214
|
|
1215 gaim_connection_set_display_name(gc, local_entry->nickname);
|
9353
|
1216 }
|
|
1217 break;
|
|
1218
|
8849
|
1219 case SILC_COMMAND_LIST:
|
|
1220 {
|
|
1221 char *topic, *name;
|
|
1222 int usercount;
|
|
1223 GaimRoomlistRoom *room;
|
|
1224
|
|
1225 if (sg->roomlist_canceled)
|
|
1226 break;
|
|
1227
|
|
1228 if (!success) {
|
|
1229 gaim_notify_error(gc, _("Roomlist"), _("Cannot get room list"),
|
|
1230 silc_get_status_message(status));
|
|
1231 gaim_roomlist_set_in_progress(sg->roomlist, FALSE);
|
|
1232 gaim_roomlist_unref(sg->roomlist);
|
|
1233 sg->roomlist = NULL;
|
|
1234 return;
|
|
1235 }
|
|
1236
|
|
1237 (void)va_arg(vp, SilcChannelEntry);
|
|
1238 name = va_arg(vp, char *);
|
|
1239 topic = va_arg(vp, char *);
|
|
1240 usercount = va_arg(vp, int);
|
|
1241
|
|
1242 room = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, name, NULL);
|
|
1243 gaim_roomlist_room_add_field(sg->roomlist, room, name);
|
|
1244 gaim_roomlist_room_add_field(sg->roomlist, room,
|
|
1245 SILC_32_TO_PTR(usercount));
|
|
1246 gaim_roomlist_room_add_field(sg->roomlist, room,
|
|
1247 topic ? topic : "");
|
|
1248 gaim_roomlist_room_add(sg->roomlist, room);
|
|
1249
|
|
1250 if (status == SILC_STATUS_LIST_END ||
|
|
1251 status == SILC_STATUS_OK) {
|
|
1252 gaim_roomlist_set_in_progress(sg->roomlist, FALSE);
|
|
1253 gaim_roomlist_unref(sg->roomlist);
|
|
1254 sg->roomlist = NULL;
|
|
1255 }
|
|
1256 }
|
|
1257 break;
|
|
1258
|
|
1259 case SILC_COMMAND_GETKEY:
|
|
1260 {
|
|
1261 SilcPublicKey public_key;
|
|
1262
|
|
1263 if (!success) {
|
|
1264 gaim_notify_error(gc, _("Get Public Key"),
|
|
1265 _("Cannot fetch the public key"),
|
|
1266 silc_get_status_message(status));
|
|
1267 return;
|
|
1268 }
|
|
1269
|
|
1270 (void)va_arg(vp, SilcUInt32);
|
|
1271 (void)va_arg(vp, void *);
|
|
1272 public_key = va_arg(vp, SilcPublicKey);
|
|
1273
|
|
1274 if (!public_key)
|
|
1275 gaim_notify_error(gc, _("Get Public Key"),
|
|
1276 _("Cannot fetch the public key"),
|
|
1277 _("No public key was received"));
|
|
1278 }
|
|
1279 break;
|
|
1280
|
|
1281 case SILC_COMMAND_INFO:
|
|
1282 {
|
|
1283
|
|
1284 SilcServerEntry server_entry;
|
|
1285 char *server_name;
|
|
1286 char *server_info;
|
9353
|
1287 char tmp[256], *msg;
|
8849
|
1288
|
|
1289 if (!success) {
|
|
1290 gaim_notify_error(gc, _("Server Information"),
|
|
1291 _("Cannot get server information"),
|
|
1292 silc_get_status_message(status));
|
|
1293 return;
|
|
1294 }
|
|
1295
|
|
1296 server_entry = va_arg(vp, SilcServerEntry);
|
|
1297 server_name = va_arg(vp, char *);
|
|
1298 server_info = va_arg(vp, char *);
|
|
1299
|
|
1300 if (server_name && server_info) {
|
|
1301 g_snprintf(tmp, sizeof(tmp), "Server: %s\n%s",
|
|
1302 server_name, server_info);
|
9353
|
1303 msg = g_markup_escape_text(tmp, strlen(tmp));
|
9488
|
1304 gaim_notify_info(gc, NULL, _("Server Information"), msg);
|
9353
|
1305 g_free(msg);
|
8849
|
1306 }
|
|
1307 }
|
|
1308 break;
|
|
1309
|
9488
|
1310 case SILC_COMMAND_STATS:
|
|
1311 {
|
|
1312 SilcUInt32 starttime, uptime, my_clients, my_channels, my_server_ops,
|
|
1313 my_router_ops, cell_clients, cell_channels, cell_servers,
|
|
1314 clients, channels, servers, routers, server_ops, router_ops;
|
|
1315 SilcUInt32 buffer_length;
|
|
1316 SilcBufferStruct buf;
|
|
1317
|
|
1318 unsigned char *server_stats;
|
|
1319 char *msg;
|
|
1320
|
|
1321 if (!success) {
|
|
1322 gaim_notify_error(gc, _("Server Statistics"),
|
9507
|
1323 _("Cannot get server statistics"),
|
9488
|
1324 silc_get_status_message(status));
|
|
1325 return;
|
|
1326 }
|
|
1327
|
|
1328 server_stats = va_arg(vp, unsigned char *);
|
|
1329 buffer_length = va_arg(vp, SilcUInt32);
|
|
1330 if (!server_stats || !buffer_length) {
|
|
1331 gaim_notify_error(gc, _("Server Statistics"),
|
|
1332 _("No server statisitics available"), NULL);
|
|
1333 break;
|
|
1334 }
|
|
1335 silc_buffer_set(&buf, server_stats, buffer_length);
|
|
1336 silc_buffer_unformat(&buf,
|
|
1337 SILC_STR_UI_INT(&starttime),
|
|
1338 SILC_STR_UI_INT(&uptime),
|
|
1339 SILC_STR_UI_INT(&my_clients),
|
|
1340 SILC_STR_UI_INT(&my_channels),
|
|
1341 SILC_STR_UI_INT(&my_server_ops),
|
|
1342 SILC_STR_UI_INT(&my_router_ops),
|
|
1343 SILC_STR_UI_INT(&cell_clients),
|
|
1344 SILC_STR_UI_INT(&cell_channels),
|
|
1345 SILC_STR_UI_INT(&cell_servers),
|
|
1346 SILC_STR_UI_INT(&clients),
|
|
1347 SILC_STR_UI_INT(&channels),
|
|
1348 SILC_STR_UI_INT(&servers),
|
|
1349 SILC_STR_UI_INT(&routers),
|
|
1350 SILC_STR_UI_INT(&server_ops),
|
|
1351 SILC_STR_UI_INT(&router_ops),
|
|
1352 SILC_STR_END);
|
|
1353
|
|
1354 msg = g_strdup_printf(_("Local server start time: %s\n"
|
|
1355 "Local server uptime: %s\n"
|
|
1356 "Local server clients: %d\n"
|
|
1357 "Local server channels: %d\n"
|
|
1358 "Local server operators: %d\n"
|
|
1359 "Local router operators: %d\n"
|
|
1360 "Local cell clients: %d\n"
|
|
1361 "Local cell channels: %d\n"
|
|
1362 "Local cell servers: %d\n"
|
|
1363 "Total clients: %d\n"
|
|
1364 "Total channels: %d\n"
|
|
1365 "Total servers: %d\n"
|
|
1366 "Total routers: %d\n"
|
|
1367 "Total server operators: %d\n"
|
|
1368 "Total router operators: %d\n"),
|
|
1369 silc_get_time(starttime),
|
|
1370 gaim_str_seconds_to_string((int)uptime),
|
|
1371 (int)my_clients, (int)my_channels, (int)my_server_ops, (int)my_router_ops,
|
|
1372 (int)cell_clients, (int)cell_channels, (int)cell_servers,
|
|
1373 (int)clients, (int)channels, (int)servers, (int)routers,
|
|
1374 (int)server_ops, (int)router_ops);
|
|
1375
|
|
1376 gaim_notify_info(gc, NULL,
|
|
1377 _("Network Statistics"), msg);
|
|
1378 g_free(msg);
|
|
1379 }
|
|
1380 break;
|
|
1381
|
|
1382 case SILC_COMMAND_PING:
|
|
1383 {
|
|
1384 if (!success) {
|
|
1385 gaim_notify_error(gc, _("Ping"), _("Ping failed"),
|
|
1386 silc_get_status_message(status));
|
|
1387 return;
|
|
1388 }
|
|
1389
|
|
1390 gaim_notify_info(gc, _("Ping"), _("Ping reply received from server"),
|
|
1391 NULL);
|
|
1392 }
|
|
1393 break;
|
|
1394
|
8849
|
1395 case SILC_COMMAND_KILL:
|
|
1396 if (!success) {
|
|
1397 gaim_notify_error(gc, _("Kill User"),
|
|
1398 _("Could not kill user"),
|
|
1399 silc_get_status_message(status));
|
|
1400 return;
|
|
1401 }
|
|
1402 break;
|
|
1403
|
|
1404 case SILC_COMMAND_CMODE:
|
|
1405 {
|
|
1406 SilcChannelEntry channel_entry;
|
|
1407 SilcBuffer channel_pubkeys;
|
|
1408
|
|
1409 if (!success)
|
|
1410 return;
|
|
1411
|
|
1412 channel_entry = va_arg(vp, SilcChannelEntry);
|
|
1413 (void)va_arg(vp, SilcUInt32);
|
|
1414 (void)va_arg(vp, SilcPublicKey);
|
|
1415 channel_pubkeys = va_arg(vp, SilcBuffer);
|
|
1416
|
|
1417 if (sg->chpk)
|
|
1418 silcgaim_chat_chauth_show(sg, channel_entry, channel_pubkeys);
|
|
1419 }
|
|
1420 break;
|
|
1421
|
|
1422 default:
|
9353
|
1423 if (success)
|
|
1424 gaim_debug_info("silc", "Unhandled command: %d (succeeded)\n", command);
|
|
1425 else
|
|
1426 gaim_debug_info("silc", "Unhandled command: %d (failed: %s)\n", command,
|
|
1427 silc_get_status_message(status));
|
8849
|
1428 break;
|
|
1429 }
|
|
1430
|
|
1431 va_end(vp);
|
|
1432 }
|
|
1433
|
|
1434
|
|
1435 /* Called to indicate that connection was either successfully established
|
|
1436 or connecting failed. This is also the first time application receives
|
9488
|
1437 the SilcClientConnection object which it should save somewhere.
|
8849
|
1438 If the `success' is FALSE the application must always call the function
|
|
1439 silc_client_close_connection. */
|
|
1440
|
|
1441 static void
|
|
1442 silc_connected(SilcClient client, SilcClientConnection conn,
|
|
1443 SilcClientConnectionStatus status)
|
|
1444 {
|
|
1445 GaimConnection *gc = client->application;
|
|
1446 SilcGaim sg = gc->proto_data;
|
|
1447 gboolean reject_watch, block_invites, block_ims;
|
|
1448
|
|
1449 if (!gc) {
|
|
1450 sg->conn = NULL;
|
|
1451 silc_client_close_connection(client, conn);
|
|
1452 return;
|
|
1453 }
|
|
1454
|
|
1455 switch (status) {
|
|
1456 case SILC_CLIENT_CONN_SUCCESS:
|
|
1457 case SILC_CLIENT_CONN_SUCCESS_RESUME:
|
|
1458 gaim_connection_set_state(gc, GAIM_CONNECTED);
|
|
1459 serv_finish_login(gc);
|
|
1460 unlink(silcgaim_session_file(gaim_account_get_username(sg->account)));
|
|
1461
|
|
1462 /* Send any UMODEs configured for account */
|
|
1463 reject_watch = gaim_account_get_bool(sg->account, "reject-watch", FALSE);
|
|
1464 block_invites = gaim_account_get_bool(sg->account, "block-invites", FALSE);
|
|
1465 block_ims = gaim_account_get_bool(sg->account, "block-ims", FALSE);
|
|
1466 if (reject_watch || block_invites || block_ims) {
|
|
1467 char m[5];
|
|
1468 g_snprintf(m, sizeof(m), "+%s%s%s",
|
9488
|
1469 reject_watch ? "w" : "",
|
|
1470 block_invites ? "I" : "",
|
|
1471 block_ims ? "P" : "");
|
8849
|
1472 silc_client_command_call(sg->client, sg->conn, NULL,
|
9488
|
1473 "UMODE", m, NULL);
|
8849
|
1474 }
|
|
1475
|
|
1476 return;
|
|
1477 break;
|
|
1478 case SILC_CLIENT_CONN_ERROR:
|
|
1479 gaim_connection_error(gc, _("Error during connecting to SILC Server"));
|
|
1480 unlink(silcgaim_session_file(gaim_account_get_username(sg->account)));
|
|
1481 break;
|
|
1482
|
|
1483 case SILC_CLIENT_CONN_ERROR_KE:
|
|
1484 gaim_connection_error(gc, _("Key Exchange failed"));
|
|
1485 break;
|
|
1486
|
|
1487 case SILC_CLIENT_CONN_ERROR_AUTH:
|
|
1488 gaim_connection_error(gc, _("Authentication failed"));
|
|
1489 break;
|
|
1490
|
|
1491 case SILC_CLIENT_CONN_ERROR_RESUME:
|
|
1492 gaim_connection_error(gc,
|
8910
|
1493 _("Resuming detached session failed. "
|
8849
|
1494 "Press Reconnect to create new connection."));
|
|
1495 unlink(silcgaim_session_file(gaim_account_get_username(sg->account)));
|
|
1496 break;
|
|
1497
|
|
1498 case SILC_CLIENT_CONN_ERROR_TIMEOUT:
|
9039
|
1499 gaim_connection_error(gc, _("Connection Timeout"));
|
8849
|
1500 break;
|
|
1501 }
|
|
1502
|
|
1503 /* Error */
|
|
1504 sg->conn = NULL;
|
|
1505 silc_client_close_connection(client, conn);
|
|
1506 }
|
|
1507
|
|
1508
|
|
1509 /* Called to indicate that connection was disconnected to the server.
|
|
1510 The `status' may tell the reason of the disconnection, and if the
|
|
1511 `message' is non-NULL it may include the disconnection message
|
|
1512 received from server. */
|
|
1513
|
|
1514 static void
|
|
1515 silc_disconnected(SilcClient client, SilcClientConnection conn,
|
|
1516 SilcStatus status, const char *message)
|
|
1517 {
|
|
1518 GaimConnection *gc = client->application;
|
|
1519 SilcGaim sg = gc->proto_data;
|
|
1520
|
|
1521 if (sg->resuming && !sg->detaching)
|
|
1522 unlink(silcgaim_session_file(gaim_account_get_username(sg->account)));
|
|
1523
|
|
1524 sg->conn = NULL;
|
|
1525
|
|
1526 /* Close the connection */
|
|
1527 if (!sg->detaching)
|
|
1528 gaim_connection_error(gc, _("Disconnected by server"));
|
|
1529 else
|
|
1530 gaim_connection_destroy(gc);
|
|
1531 }
|
|
1532
|
|
1533
|
|
1534 typedef struct {
|
|
1535 SilcGetAuthMeth completion;
|
|
1536 void *context;
|
|
1537 } *SilcGaimGetAuthMethod;
|
|
1538
|
|
1539 /* Callback called when we've received the authentication method information
|
|
1540 from the server after we've requested it. */
|
|
1541
|
|
1542 static void silc_get_auth_method_callback(SilcClient client,
|
|
1543 SilcClientConnection conn,
|
|
1544 SilcAuthMethod auth_meth,
|
|
1545 void *context)
|
|
1546 {
|
|
1547 SilcGaimGetAuthMethod internal = context;
|
|
1548
|
|
1549 switch (auth_meth) {
|
|
1550 case SILC_AUTH_NONE:
|
|
1551 /* No authentication required. */
|
|
1552 (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context);
|
|
1553 break;
|
|
1554
|
|
1555 case SILC_AUTH_PASSWORD:
|
|
1556 /* By returning NULL here the library will ask the passphrase from us
|
|
1557 by calling the silc_ask_passphrase. */
|
|
1558 (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context);
|
|
1559 break;
|
|
1560
|
|
1561 case SILC_AUTH_PUBLIC_KEY:
|
|
1562 /* Do not get the authentication data now, the library will generate
|
|
1563 it using our default key, if we do not provide it here. */
|
|
1564 (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context);
|
|
1565 break;
|
|
1566 }
|
|
1567
|
|
1568 silc_free(internal);
|
|
1569 }
|
|
1570
|
|
1571 /* Find authentication method and authentication data by hostname and
|
|
1572 port. The hostname may be IP address as well. When the authentication
|
|
1573 method has been resolved the `completion' callback with the found
|
|
1574 authentication method and authentication data is called. The `conn'
|
|
1575 may be NULL. */
|
|
1576
|
|
1577 static void
|
|
1578 silc_get_auth_method(SilcClient client, SilcClientConnection conn,
|
|
1579 char *hostname, SilcUInt16 port,
|
|
1580 SilcGetAuthMeth completion, void *context)
|
|
1581 {
|
|
1582 GaimConnection *gc = client->application;
|
|
1583 SilcGaim sg = gc->proto_data;
|
|
1584 SilcGaimGetAuthMethod internal;
|
|
1585
|
|
1586 /* Progress */
|
|
1587 if (sg->resuming)
|
|
1588 gaim_connection_update_progress(gc, _("Resuming session"), 4, 5);
|
|
1589 else
|
|
1590 gaim_connection_update_progress(gc, _("Authenticating connection"), 4, 5);
|
|
1591
|
|
1592 /* Check configuration if we have this connection configured. If we
|
|
1593 have then return that data immediately, as it's faster way. */
|
|
1594 if (gc->account->password && *gc->account->password) {
|
|
1595 completion(TRUE, SILC_AUTH_PASSWORD, gc->account->password,
|
|
1596 strlen(gc->account->password), context);
|
|
1597 return;
|
|
1598 }
|
|
1599 if (gaim_account_get_bool(sg->account, "pubkey-auth", FALSE)) {
|
|
1600 completion(TRUE, SILC_AUTH_PUBLIC_KEY, NULL, 0, context);
|
|
1601 return;
|
|
1602 }
|
|
1603
|
|
1604 /* Resolve the authentication method from server, as we may not know it. */
|
|
1605 internal = silc_calloc(1, sizeof(*internal));
|
|
1606 if (!internal)
|
|
1607 return;
|
|
1608 internal->completion = completion;
|
|
1609 internal->context = context;
|
|
1610 silc_client_request_authentication_method(client, conn,
|
|
1611 silc_get_auth_method_callback,
|
|
1612 internal);
|
|
1613 }
|
|
1614
|
|
1615
|
|
1616 /* Verifies received public key. The `conn_type' indicates which entity
|
|
1617 (server, client etc.) has sent the public key. If user decides to trust
|
|
1618 the application may save the key as trusted public key for later
|
|
1619 use. The `completion' must be called after the public key has been
|
|
1620 verified. */
|
|
1621
|
|
1622 static void
|
|
1623 silc_verify_public_key(SilcClient client, SilcClientConnection conn,
|
|
1624 SilcSocketType conn_type, unsigned char *pk,
|
|
1625 SilcUInt32 pk_len, SilcSKEPKType pk_type,
|
|
1626 SilcVerifyPublicKey completion, void *context)
|
|
1627 {
|
|
1628 GaimConnection *gc = client->application;
|
|
1629 SilcGaim sg = gc->proto_data;
|
|
1630
|
|
1631 if (!sg->conn && (conn_type == SILC_SOCKET_TYPE_SERVER ||
|
|
1632 conn_type == SILC_SOCKET_TYPE_ROUTER)) {
|
|
1633 /* Progress */
|
|
1634 if (sg->resuming)
|
|
1635 gaim_connection_update_progress(gc, _("Resuming session"), 3, 5);
|
|
1636 else
|
|
1637 gaim_connection_update_progress(gc, _("Verifying server public key"),
|
|
1638 3, 5);
|
|
1639 }
|
|
1640
|
|
1641 /* Verify public key */
|
|
1642 silcgaim_verify_public_key(client, conn, NULL, conn_type, pk,
|
|
1643 pk_len, pk_type, completion, context);
|
|
1644 }
|
|
1645
|
|
1646 typedef struct {
|
|
1647 SilcAskPassphrase completion;
|
|
1648 void *context;
|
|
1649 } *SilcGaimAskPassphrase;
|
|
1650
|
|
1651 static void
|
|
1652 silc_ask_passphrase_cb(SilcGaimAskPassphrase internal, const char *passphrase)
|
|
1653 {
|
|
1654 if (!passphrase || !(*passphrase))
|
|
1655 internal->completion(NULL, 0, internal->context);
|
|
1656 else
|
|
1657 internal->completion((unsigned char *)passphrase,
|
|
1658 strlen(passphrase), internal->context);
|
|
1659 silc_free(internal);
|
|
1660 }
|
|
1661
|
|
1662 /* Ask (interact, that is) a passphrase from user. The passphrase is
|
|
1663 returned to the library by calling the `completion' callback with
|
|
1664 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
|
|
1665 if not then the library will attempt to encode. */
|
|
1666
|
|
1667 static void
|
|
1668 silc_ask_passphrase(SilcClient client, SilcClientConnection conn,
|
|
1669 SilcAskPassphrase completion, void *context)
|
|
1670 {
|
|
1671 SilcGaimAskPassphrase internal = silc_calloc(1, sizeof(*internal));
|
|
1672
|
|
1673 if (!internal)
|
|
1674 return;
|
|
1675 internal->completion = completion;
|
|
1676 internal->context = context;
|
|
1677 gaim_request_input(NULL, _("Passphrase"), NULL,
|
|
1678 _("Passphrase required"), NULL, FALSE, TRUE, NULL,
|
|
1679 _("OK"), G_CALLBACK(silc_ask_passphrase_cb),
|
|
1680 _("Cancel"), G_CALLBACK(silc_ask_passphrase_cb),
|
|
1681 internal);
|
|
1682 }
|
|
1683
|
|
1684
|
|
1685 /* Notifies application that failure packet was received. This is called
|
|
1686 if there is some protocol active in the client. The `protocol' is the
|
|
1687 protocol context. The `failure' is opaque pointer to the failure
|
|
1688 indication. Note, that the `failure' is protocol dependant and
|
|
1689 application must explicitly cast it to correct type. Usually `failure'
|
|
1690 is 32 bit failure type (see protocol specs for all protocol failure
|
|
1691 types). */
|
|
1692
|
|
1693 static void
|
|
1694 silc_failure(SilcClient client, SilcClientConnection conn,
|
|
1695 SilcProtocol protocol, void *failure)
|
|
1696 {
|
|
1697 GaimConnection *gc = client->application;
|
|
1698 char buf[128];
|
|
1699
|
|
1700 memset(buf, 0, sizeof(buf));
|
|
1701
|
|
1702 if (protocol->protocol->type == SILC_PROTOCOL_CLIENT_KEY_EXCHANGE) {
|
|
1703 SilcSKEStatus status = (SilcSKEStatus)SILC_PTR_TO_32(failure);
|
|
1704
|
|
1705 if (status == SILC_SKE_STATUS_BAD_VERSION)
|
|
1706 g_snprintf(buf, sizeof(buf),
|
|
1707 _("Failure: Version mismatch, upgrade your client"));
|
|
1708 if (status == SILC_SKE_STATUS_UNSUPPORTED_PUBLIC_KEY)
|
|
1709 g_snprintf(buf, sizeof(buf),
|
|
1710 _("Failure: Remote does not trust/support your public key"));
|
|
1711 if (status == SILC_SKE_STATUS_UNKNOWN_GROUP)
|
|
1712 g_snprintf(buf, sizeof(buf),
|
|
1713 _("Failure: Remote does not support proposed KE group"));
|
|
1714 if (status == SILC_SKE_STATUS_UNKNOWN_CIPHER)
|
|
1715 g_snprintf(buf, sizeof(buf),
|
|
1716 _("Failure: Remote does not support proposed cipher"));
|
|
1717 if (status == SILC_SKE_STATUS_UNKNOWN_PKCS)
|
|
1718 g_snprintf(buf, sizeof(buf),
|
|
1719 _("Failure: Remote does not support proposed PKCS"));
|
|
1720 if (status == SILC_SKE_STATUS_UNKNOWN_HASH_FUNCTION)
|
|
1721 g_snprintf(buf, sizeof(buf),
|
|
1722 _("Failure: Remote does not support proposed hash function"));
|
|
1723 if (status == SILC_SKE_STATUS_UNKNOWN_HMAC)
|
|
1724 g_snprintf(buf, sizeof(buf),
|
|
1725 _("Failure: Remote does not support proposed HMAC"));
|
|
1726 if (status == SILC_SKE_STATUS_INCORRECT_SIGNATURE)
|
|
1727 g_snprintf(buf, sizeof(buf), _("Failure: Incorrect signature"));
|
|
1728 if (status == SILC_SKE_STATUS_INVALID_COOKIE)
|
|
1729 g_snprintf(buf, sizeof(buf), _("Failure: Invalid cookie"));
|
|
1730
|
|
1731 /* Show the error on the progress bar. A more generic error message
|
|
1732 is going to be showed to user after this in the silc_connected. */
|
|
1733 gaim_connection_update_progress(gc, buf, 2, 5);
|
|
1734 }
|
|
1735
|
|
1736 if (protocol->protocol->type == SILC_PROTOCOL_CLIENT_CONNECTION_AUTH) {
|
|
1737 SilcUInt32 err = SILC_PTR_TO_32(failure);
|
|
1738
|
|
1739 if (err == SILC_AUTH_FAILED)
|
|
1740 g_snprintf(buf, sizeof(buf), _("Failure: Authentication failed"));
|
|
1741
|
|
1742 /* Show the error on the progress bar. A more generic error message
|
|
1743 is going to be showed to user after this in the silc_connected. */
|
|
1744 gaim_connection_update_progress(gc, buf, 4, 5);
|
|
1745 }
|
|
1746 }
|
|
1747
|
|
1748 /* Asks whether the user would like to perform the key agreement protocol.
|
|
1749 This is called after we have received an key agreement packet or an
|
|
1750 reply to our key agreement packet. This returns TRUE if the user wants
|
|
1751 the library to perform the key agreement protocol and FALSE if it is not
|
|
1752 desired (application may start it later by calling the function
|
|
1753 silc_client_perform_key_agreement). If TRUE is returned also the
|
|
1754 `completion' and `context' arguments must be set by the application. */
|
|
1755
|
|
1756 static bool
|
|
1757 silc_key_agreement(SilcClient client, SilcClientConnection conn,
|
|
1758 SilcClientEntry client_entry, const char *hostname,
|
|
1759 SilcUInt16 port, SilcKeyAgreementCallback *completion,
|
|
1760 void **context)
|
|
1761 {
|
|
1762 silcgaim_buddy_keyagr_request(client, conn, client_entry, hostname, port);
|
|
1763 *completion = NULL;
|
|
1764 *context = NULL;
|
|
1765 return FALSE;
|
|
1766 }
|
|
1767
|
|
1768
|
|
1769 /* Notifies application that file transfer protocol session is being
|
|
1770 requested by the remote client indicated by the `client_entry' from
|
|
1771 the `hostname' and `port'. The `session_id' is the file transfer
|
|
1772 session and it can be used to either accept or reject the file
|
|
1773 transfer request, by calling the silc_client_file_receive or
|
|
1774 silc_client_file_close, respectively. */
|
|
1775
|
|
1776 static void
|
|
1777 silc_ftp(SilcClient client, SilcClientConnection conn,
|
|
1778 SilcClientEntry client_entry, SilcUInt32 session_id,
|
|
1779 const char *hostname, SilcUInt16 port)
|
|
1780 {
|
|
1781 silcgaim_ftp_request(client, conn, client_entry, session_id,
|
|
1782 hostname, port);
|
|
1783 }
|
|
1784
|
|
1785
|
|
1786 /* Delivers SILC session detachment data indicated by `detach_data' to the
|
|
1787 application. If application has issued SILC_COMMAND_DETACH command
|
|
1788 the client session in the SILC network is not quit. The client remains
|
|
1789 in the network but is detached. The detachment data may be used later
|
|
1790 to resume the session in the SILC Network. The appliation is
|
|
1791 responsible of saving the `detach_data', to for example in a file.
|
|
1792
|
|
1793 The detachment data can be given as argument to the functions
|
|
1794 silc_client_connect_to_server, or silc_client_add_connection when
|
|
1795 creating connection to remote server, inside SilcClientConnectionParams
|
|
1796 structure. If it is provided the client library will attempt to resume
|
|
1797 the session in the network. After the connection is created
|
|
1798 successfully, the application is responsible of setting the user
|
|
1799 interface for user into the same state it was before detaching (showing
|
|
1800 same channels, channel modes, etc). It can do this by fetching the
|
|
1801 information (like joined channels) from the client library. */
|
|
1802
|
|
1803 static void
|
|
1804 silc_detach(SilcClient client, SilcClientConnection conn,
|
|
1805 const unsigned char *detach_data, SilcUInt32 detach_data_len)
|
|
1806 {
|
|
1807 GaimConnection *gc = client->application;
|
|
1808 SilcGaim sg = gc->proto_data;
|
|
1809 const char *file;
|
|
1810
|
|
1811 /* Save the detachment data to file. */
|
|
1812 file = silcgaim_session_file(gaim_account_get_username(sg->account));
|
|
1813 unlink(file);
|
|
1814 silc_file_writefile(file, detach_data, detach_data_len);
|
|
1815 }
|
|
1816
|
|
1817 SilcClientOperations ops = {
|
|
1818 silc_say,
|
|
1819 silc_channel_message,
|
|
1820 silc_private_message,
|
|
1821 silc_notify,
|
|
1822 silc_command,
|
|
1823 silc_command_reply,
|
|
1824 silc_connected,
|
|
1825 silc_disconnected,
|
|
1826 silc_get_auth_method,
|
|
1827 silc_verify_public_key,
|
|
1828 silc_ask_passphrase,
|
|
1829 silc_failure,
|
|
1830 silc_key_agreement,
|
|
1831 silc_ftp,
|
|
1832 silc_detach
|
|
1833 };
|