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