Mercurial > pidgin.yaz
annotate src/protocols/silc/buddy.c @ 10855:2d3a935462aa
[gaim-migrate @ 12530]
"
Enclosed is a patch for the Toolkit 0.9.14, just released, that had a API
change. Please commit, for without this patch Gaim can segfault.
" --Pekka
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 20 Apr 2005 03:54:02 +0000 |
parents | 54ac161a876e |
children | 3e43c132f151 |
rev | line source |
---|---|
8849 | 1 /* |
2 | |
3 silcgaim_buddy.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 /***************************** Key Agreement *********************************/ | |
25 | |
26 static void | |
9060 | 27 silcgaim_buddy_keyagr(GaimBlistNode *node, gpointer data); |
28 | |
29 static void | |
30 silcgaim_buddy_keyagr_do(GaimConnection *gc, const char *name, | |
31 gboolean force_local); | |
8849 | 32 |
33 typedef struct { | |
34 char *nick; | |
35 GaimConnection *gc; | |
36 } *SilcGaimResolve; | |
37 | |
38 static void | |
39 silcgaim_buddy_keyagr_resolved(SilcClient client, | |
40 SilcClientConnection conn, | |
41 SilcClientEntry *clients, | |
42 SilcUInt32 clients_count, | |
43 void *context) | |
44 { | |
45 GaimConnection *gc = client->application; | |
46 SilcGaimResolve r = context; | |
47 char tmp[256]; | |
48 | |
49 if (!clients) { | |
50 g_snprintf(tmp, sizeof(tmp), | |
51 _("User %s is not present in the network"), r->nick); | |
52 gaim_notify_error(gc, _("Key Agreement"), | |
53 _("Cannot perform the key agreement"), tmp); | |
54 silc_free(r->nick); | |
55 silc_free(r); | |
56 return; | |
57 } | |
58 | |
9060 | 59 silcgaim_buddy_keyagr_do(gc, r->nick, FALSE); |
8849 | 60 silc_free(r->nick); |
61 silc_free(r); | |
62 } | |
63 | |
64 typedef struct { | |
65 gboolean responder; | |
66 } *SilcGaimKeyAgr; | |
67 | |
68 static void | |
69 silcgaim_buddy_keyagr_cb(SilcClient client, | |
70 SilcClientConnection conn, | |
71 SilcClientEntry client_entry, | |
72 SilcKeyAgreementStatus status, | |
73 SilcSKEKeyMaterial *key, | |
74 void *context) | |
75 { | |
76 GaimConnection *gc = client->application; | |
77 SilcGaim sg = gc->proto_data; | |
78 SilcGaimKeyAgr a = context; | |
79 | |
80 if (!sg->conn) | |
81 return; | |
82 | |
83 switch (status) { | |
84 case SILC_KEY_AGREEMENT_OK: | |
85 { | |
86 GaimConversation *convo; | |
87 char tmp[128]; | |
88 | |
89 /* Set the private key for this client */ | |
90 silc_client_del_private_message_key(client, conn, client_entry); | |
91 silc_client_add_private_message_key_ske(client, conn, client_entry, | |
92 NULL, NULL, key, a->responder); | |
93 silc_ske_free_key_material(key); | |
94 | |
95 /* Open IM window */ | |
10246 | 96 convo = gaim_find_conversation_with_account(GAIM_CONV_IM, |
97 client_entry->nickname, sg->account); | |
8849 | 98 if (convo) |
99 gaim_conv_window_show(gaim_conversation_get_window(convo)); | |
100 else | |
101 convo = gaim_conversation_new(GAIM_CONV_IM, sg->account, | |
102 client_entry->nickname); | |
103 g_snprintf(tmp, sizeof(tmp), "%s [private key]", client_entry->nickname); | |
104 gaim_conversation_set_title(convo, tmp); | |
105 } | |
106 break; | |
107 | |
108 case SILC_KEY_AGREEMENT_ERROR: | |
109 gaim_notify_error(gc, _("Key Agreement"), | |
110 _("Error occurred during key agreement"), NULL); | |
111 break; | |
112 | |
113 case SILC_KEY_AGREEMENT_FAILURE: | |
114 gaim_notify_error(gc, _("Key Agreement"), _("Key Agreement failed"), NULL); | |
115 break; | |
116 | |
117 case SILC_KEY_AGREEMENT_TIMEOUT: | |
118 gaim_notify_error(gc, _("Key Agreement"), | |
119 _("Timeout during key agreement"), NULL); | |
120 break; | |
121 | |
122 case SILC_KEY_AGREEMENT_ABORTED: | |
123 gaim_notify_error(gc, _("Key Agreement"), | |
124 _("Key agreement was aborted"), NULL); | |
125 break; | |
126 | |
127 case SILC_KEY_AGREEMENT_ALREADY_STARTED: | |
128 gaim_notify_error(gc, _("Key Agreement"), | |
129 _("Key agreement is already started"), NULL); | |
130 break; | |
131 | |
132 case SILC_KEY_AGREEMENT_SELF_DENIED: | |
133 gaim_notify_error(gc, _("Key Agreement"), | |
134 _("Key agreement cannot be started with yourself"), | |
135 NULL); | |
136 break; | |
137 | |
138 default: | |
139 break; | |
140 } | |
141 | |
142 silc_free(a); | |
143 } | |
144 | |
145 static void | |
146 silcgaim_buddy_keyagr_do(GaimConnection *gc, const char *name, | |
147 gboolean force_local) | |
148 { | |
149 SilcGaim sg = gc->proto_data; | |
150 SilcClientEntry *clients; | |
151 SilcUInt32 clients_count; | |
8910 | 152 char *local_ip = NULL, *remote_ip = NULL; |
8849 | 153 gboolean local = TRUE; |
154 char *nickname; | |
155 SilcGaimKeyAgr a; | |
156 | |
157 if (!sg->conn || !name) | |
158 return; | |
159 | |
160 if (!silc_parse_userfqdn(name, &nickname, NULL)) | |
161 return; | |
162 | |
163 /* Find client entry */ | |
164 clients = silc_client_get_clients_local(sg->client, sg->conn, nickname, name, | |
165 &clients_count); | |
166 if (!clients) { | |
167 /* Resolve unknown user */ | |
168 SilcGaimResolve r = silc_calloc(1, sizeof(*r)); | |
169 if (!r) | |
170 return; | |
171 r->nick = g_strdup(name); | |
172 r->gc = gc; | |
173 silc_client_get_clients(sg->client, sg->conn, nickname, NULL, | |
174 silcgaim_buddy_keyagr_resolved, r); | |
175 silc_free(nickname); | |
176 return; | |
177 } | |
178 | |
179 /* Resolve the local IP from the outgoing socket connection. We resolve | |
180 it to check whether we have a private range IP address or public IP | |
181 address. If we have public then we will assume that we are not behind | |
182 NAT and will provide automatically the point of connection to the | |
183 agreement. If we have private range address we assume that we are | |
184 behind NAT and we let the responder provide the point of connection. | |
185 | |
186 The algorithm also checks the remote IP address of server connection. | |
187 If it is private range address and we have private range address we | |
188 assume that we are chatting in LAN and will provide the point of | |
189 connection. | |
190 | |
191 Naturally this algorithm does not always get things right. */ | |
192 | |
193 if (silc_net_check_local_by_sock(sg->conn->sock->sock, NULL, &local_ip)) { | |
194 /* Check if the IP is private */ | |
195 if (!force_local && silcgaim_ip_is_private(local_ip)) { | |
196 local = FALSE; | |
197 | |
198 /* Local IP is private, resolve the remote server IP to see whether | |
199 we are talking to Internet or just on LAN. */ | |
200 if (silc_net_check_host_by_sock(sg->conn->sock->sock, NULL, | |
201 &remote_ip)) | |
202 if (silcgaim_ip_is_private(remote_ip)) | |
203 /* We assume we are in LAN. Let's provide | |
204 the connection point. */ | |
205 local = TRUE; | |
206 } | |
207 } | |
208 | |
209 if (force_local) | |
210 local = TRUE; | |
211 | |
212 if (local && !local_ip) | |
213 local_ip = silc_net_localip(); | |
214 | |
215 a = silc_calloc(1, sizeof(*a)); | |
216 if (!a) | |
217 return; | |
218 a->responder = local; | |
219 | |
220 /* Send the key agreement request */ | |
221 silc_client_send_key_agreement(sg->client, sg->conn, clients[0], | |
222 local ? local_ip : NULL, NULL, 0, 60, | |
223 silcgaim_buddy_keyagr_cb, a); | |
224 | |
225 silc_free(local_ip); | |
226 silc_free(remote_ip); | |
227 silc_free(clients); | |
228 } | |
229 | |
230 typedef struct { | |
231 SilcClient client; | |
232 SilcClientConnection conn; | |
233 SilcClientID client_id; | |
234 char *hostname; | |
235 SilcUInt16 port; | |
236 } *SilcGaimKeyAgrAsk; | |
237 | |
238 static void | |
239 silcgaim_buddy_keyagr_request_cb(SilcGaimKeyAgrAsk a, gint id) | |
240 { | |
241 SilcGaimKeyAgr ai; | |
242 SilcClientEntry client_entry; | |
243 | |
244 if (id != 1) | |
245 goto out; | |
246 | |
247 /* Get the client entry. */ | |
248 client_entry = silc_client_get_client_by_id(a->client, a->conn, | |
249 &a->client_id); | |
250 if (!client_entry) { | |
251 gaim_notify_error(a->client->application, _("Key Agreement"), | |
252 _("The remote user is not present in the network any more"), | |
253 NULL); | |
254 goto out; | |
255 } | |
256 | |
257 /* If the hostname was provided by the requestor perform the key agreement | |
258 now. Otherwise, we will send him a request to connect to us. */ | |
259 if (a->hostname) { | |
260 ai = silc_calloc(1, sizeof(*ai)); | |
261 if (!ai) | |
262 goto out; | |
263 ai->responder = FALSE; | |
264 silc_client_perform_key_agreement(a->client, a->conn, client_entry, | |
265 a->hostname, a->port, | |
266 silcgaim_buddy_keyagr_cb, ai); | |
267 } else { | |
268 /* Send request. Force us as the point of connection since requestor | |
269 did not provide the point of connection. */ | |
270 silcgaim_buddy_keyagr_do(a->client->application, | |
271 client_entry->nickname, TRUE); | |
272 } | |
273 | |
274 out: | |
275 silc_free(a->hostname); | |
276 silc_free(a); | |
277 } | |
278 | |
279 void silcgaim_buddy_keyagr_request(SilcClient client, | |
280 SilcClientConnection conn, | |
281 SilcClientEntry client_entry, | |
282 const char *hostname, SilcUInt16 port) | |
283 { | |
284 char tmp[128], tmp2[128]; | |
285 SilcGaimKeyAgrAsk a; | |
286 | |
287 g_snprintf(tmp, sizeof(tmp), | |
288 _("Key agreement request received from %s. Would you like to " | |
289 "perform the key agreement?"), client_entry->nickname); | |
290 if (hostname) | |
291 g_snprintf(tmp2, sizeof(tmp2), | |
292 _("The remote user is waiting key agreement on:\n" | |
293 "Remote host: %s\nRemote port: %d"), hostname, port); | |
294 | |
295 a = silc_calloc(1, sizeof(*a)); | |
296 if (!a) | |
297 return; | |
298 a->client = client; | |
299 a->conn = conn; | |
300 a->client_id = *client_entry->id; | |
301 if (hostname) | |
302 a->hostname = strdup(hostname); | |
303 a->port = port; | |
304 | |
305 gaim_request_action(NULL, _("Key Agreement Request"), tmp, | |
306 hostname ? tmp2 : NULL, 1, a, 2, | |
307 _("Yes"), G_CALLBACK(silcgaim_buddy_keyagr_request_cb), | |
308 _("No"), G_CALLBACK(silcgaim_buddy_keyagr_request_cb)); | |
309 } | |
310 | |
311 static void | |
9060 | 312 silcgaim_buddy_keyagr(GaimBlistNode *node, gpointer data) |
8849 | 313 { |
9133
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
314 GaimBuddy *buddy; |
9060 | 315 |
316 buddy = (GaimBuddy *)node; | |
317 silcgaim_buddy_keyagr_do(buddy->account->gc, buddy->name, FALSE); | |
8849 | 318 } |
319 | |
320 | |
321 /**************************** Static IM Key **********************************/ | |
322 | |
323 static void | |
9030 | 324 silcgaim_buddy_resetkey(GaimBlistNode *node, gpointer data) |
8849 | 325 { |
9030 | 326 GaimBuddy *b; |
327 GaimConnection *gc; | |
328 SilcGaim sg; | |
8849 | 329 char *nickname; |
330 SilcClientEntry *clients; | |
331 SilcUInt32 clients_count; | |
332 | |
9030 | 333 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
334 | |
335 b = (GaimBuddy *) node; | |
336 gc = gaim_account_get_connection(b->account); | |
337 sg = gc->proto_data; | |
338 | |
339 if (!silc_parse_userfqdn(b->name, &nickname, NULL)) | |
8849 | 340 return; |
341 | |
342 /* Find client entry */ | |
343 clients = silc_client_get_clients_local(sg->client, sg->conn, | |
9030 | 344 nickname, b->name, |
8849 | 345 &clients_count); |
346 if (!clients) { | |
347 silc_free(nickname); | |
348 return; | |
349 } | |
350 | |
351 clients[0]->prv_resp = FALSE; | |
352 silc_client_del_private_message_key(sg->client, sg->conn, | |
353 clients[0]); | |
354 silc_free(clients); | |
355 silc_free(nickname); | |
356 } | |
357 | |
358 typedef struct { | |
359 SilcClient client; | |
360 SilcClientConnection conn; | |
361 SilcClientID client_id; | |
362 } *SilcGaimPrivkey; | |
363 | |
364 static void | |
365 silcgaim_buddy_privkey(GaimConnection *gc, const char *name); | |
366 | |
367 static void | |
368 silcgaim_buddy_privkey_cb(SilcGaimPrivkey p, const char *passphrase) | |
369 { | |
370 SilcClientEntry client_entry; | |
371 | |
372 if (!passphrase || !(*passphrase)) { | |
373 silc_free(p); | |
374 return; | |
375 } | |
376 | |
377 /* Get the client entry. */ | |
378 client_entry = silc_client_get_client_by_id(p->client, p->conn, | |
379 &p->client_id); | |
380 if (!client_entry) { | |
381 gaim_notify_error(p->client->application, _("IM With Password"), | |
382 _("The remote user is not present in the network any more"), | |
383 NULL); | |
384 silc_free(p); | |
385 return; | |
386 } | |
387 | |
388 /* Set the private message key */ | |
389 silc_client_del_private_message_key(p->client, p->conn, | |
390 client_entry); | |
391 silc_client_add_private_message_key(p->client, p->conn, | |
392 client_entry, NULL, NULL, | |
393 (unsigned char *)passphrase, | |
394 strlen(passphrase), FALSE, | |
395 client_entry->prv_resp); | |
396 if (!client_entry->prv_resp) | |
397 silc_client_send_private_message_key_request(p->client, | |
398 p->conn, | |
399 client_entry); | |
400 silc_free(p); | |
401 } | |
402 | |
403 static void | |
404 silcgaim_buddy_privkey_resolved(SilcClient client, | |
405 SilcClientConnection conn, | |
406 SilcClientEntry *clients, | |
407 SilcUInt32 clients_count, | |
408 void *context) | |
409 { | |
410 char tmp[256]; | |
411 | |
412 if (!clients) { | |
413 g_snprintf(tmp, sizeof(tmp), | |
414 _("User %s is not present in the network"), | |
415 (const char *)context); | |
416 gaim_notify_error(client->application, _("IM With Password"), | |
417 _("Cannot set IM key"), tmp); | |
418 g_free(context); | |
419 return; | |
420 } | |
421 | |
422 silcgaim_buddy_privkey(client->application, context); | |
423 silc_free(context); | |
424 } | |
425 | |
426 static void | |
9038 | 427 silcgaim_buddy_privkey(GaimConnection *gc, const char *name) |
8849 | 428 { |
9038 | 429 SilcGaim sg = gc->proto_data; |
8849 | 430 char *nickname; |
431 SilcGaimPrivkey p; | |
432 SilcClientEntry *clients; | |
433 SilcUInt32 clients_count; | |
434 | |
9038 | 435 if (!name) |
436 return; | |
437 if (!silc_parse_userfqdn(name, &nickname, NULL)) | |
8849 | 438 return; |
439 | |
440 /* Find client entry */ | |
441 clients = silc_client_get_clients_local(sg->client, sg->conn, | |
9038 | 442 nickname, name, |
8849 | 443 &clients_count); |
444 if (!clients) { | |
445 silc_client_get_clients(sg->client, sg->conn, nickname, NULL, | |
446 silcgaim_buddy_privkey_resolved, | |
9038 | 447 g_strdup(name)); |
8849 | 448 silc_free(nickname); |
449 return; | |
450 } | |
451 | |
452 p = silc_calloc(1, sizeof(*p)); | |
453 if (!p) | |
454 return; | |
455 p->client = sg->client; | |
456 p->conn = sg->conn; | |
457 p->client_id = *clients[0]->id; | |
458 gaim_request_input(NULL, _("IM With Password"), NULL, | |
459 _("Set IM Password"), NULL, FALSE, TRUE, NULL, | |
460 _("OK"), G_CALLBACK(silcgaim_buddy_privkey_cb), | |
461 _("Cancel"), G_CALLBACK(silcgaim_buddy_privkey_cb), | |
462 p); | |
463 | |
464 silc_free(clients); | |
465 silc_free(nickname); | |
466 } | |
467 | |
9038 | 468 static void |
469 silcgaim_buddy_privkey_menu(GaimBlistNode *node, gpointer data) | |
470 { | |
471 GaimBuddy *buddy; | |
472 GaimConnection *gc; | |
473 | |
474 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
475 | |
476 buddy = (GaimBuddy *) node; | |
477 gc = gaim_account_get_connection(buddy->account); | |
478 | |
479 silcgaim_buddy_privkey(gc, buddy->name); | |
480 } | |
481 | |
8849 | 482 |
483 /**************************** Get Public Key *********************************/ | |
484 | |
485 typedef struct { | |
486 SilcClient client; | |
487 SilcClientConnection conn; | |
488 SilcClientID client_id; | |
489 } *SilcGaimBuddyGetkey; | |
490 | |
491 static void | |
492 silcgaim_buddy_getkey(GaimConnection *gc, const char *name); | |
493 | |
494 static void | |
495 silcgaim_buddy_getkey_cb(SilcGaimBuddyGetkey g, | |
496 SilcClientCommandReplyContext cmd) | |
497 { | |
498 SilcClientEntry client_entry; | |
499 unsigned char *pk; | |
500 SilcUInt32 pk_len; | |
501 | |
502 /* Get the client entry. */ | |
503 client_entry = silc_client_get_client_by_id(g->client, g->conn, | |
504 &g->client_id); | |
505 if (!client_entry) { | |
506 gaim_notify_error(g->client->application, _("Get Public Key"), | |
507 _("The remote user is not present in the network any more"), | |
508 NULL); | |
509 silc_free(g); | |
510 return; | |
511 } | |
512 | |
513 if (!client_entry->public_key) { | |
514 silc_free(g); | |
515 return; | |
516 } | |
517 | |
518 /* Now verify the public key */ | |
519 pk = silc_pkcs_public_key_encode(client_entry->public_key, &pk_len); | |
520 silcgaim_verify_public_key(g->client, g->conn, client_entry->nickname, | |
521 SILC_SOCKET_TYPE_CLIENT, | |
522 pk, pk_len, SILC_SKE_PK_TYPE_SILC, | |
523 NULL, NULL); | |
524 silc_free(pk); | |
525 silc_free(g); | |
526 } | |
527 | |
528 static void | |
529 silcgaim_buddy_getkey_resolved(SilcClient client, | |
530 SilcClientConnection conn, | |
531 SilcClientEntry *clients, | |
532 SilcUInt32 clients_count, | |
533 void *context) | |
534 { | |
535 char tmp[256]; | |
536 | |
537 if (!clients) { | |
538 g_snprintf(tmp, sizeof(tmp), | |
539 _("User %s is not present in the network"), | |
540 (const char *)context); | |
541 gaim_notify_error(client->application, _("Get Public Key"), | |
542 _("Cannot fetch the public key"), tmp); | |
543 g_free(context); | |
544 return; | |
545 } | |
546 | |
547 silcgaim_buddy_getkey(client->application, context); | |
548 silc_free(context); | |
549 } | |
550 | |
551 static void | |
9038 | 552 silcgaim_buddy_getkey(GaimConnection *gc, const char *name) |
8849 | 553 { |
9038 | 554 SilcGaim sg = gc->proto_data; |
555 SilcClient client = sg->client; | |
556 SilcClientConnection conn = sg->conn; | |
8849 | 557 SilcClientEntry *clients; |
558 SilcUInt32 clients_count; | |
559 SilcGaimBuddyGetkey g; | |
560 char *nickname; | |
561 | |
9038 | 562 if (!name) |
563 return; | |
8849 | 564 |
9038 | 565 if (!silc_parse_userfqdn(name, &nickname, NULL)) |
8849 | 566 return; |
567 | |
568 /* Find client entry */ | |
9038 | 569 clients = silc_client_get_clients_local(client, conn, nickname, name, |
570 &clients_count); | |
8849 | 571 if (!clients) { |
572 silc_client_get_clients(client, conn, nickname, NULL, | |
573 silcgaim_buddy_getkey_resolved, | |
9038 | 574 g_strdup(name)); |
8849 | 575 silc_free(nickname); |
576 return; | |
577 } | |
578 | |
579 /* Call GETKEY */ | |
580 g = silc_calloc(1, sizeof(*g)); | |
581 if (!g) | |
582 return; | |
583 g->client = client; | |
584 g->conn = conn; | |
585 g->client_id = *clients[0]->id; | |
586 silc_client_command_call(client, conn, NULL, "GETKEY", | |
587 clients[0]->nickname, NULL); | |
588 silc_client_command_pending(conn, SILC_COMMAND_GETKEY, | |
589 conn->cmd_ident, | |
590 (SilcCommandCb)silcgaim_buddy_getkey_cb, g); | |
591 silc_free(clients); | |
592 silc_free(nickname); | |
593 } | |
594 | |
595 static void | |
9038 | 596 silcgaim_buddy_getkey_menu(GaimBlistNode *node, gpointer data) |
597 { | |
598 GaimBuddy *buddy; | |
599 GaimConnection *gc; | |
600 | |
601 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
602 | |
603 buddy = (GaimBuddy *) node; | |
604 gc = gaim_account_get_connection(buddy->account); | |
605 | |
606 silcgaim_buddy_privkey(gc, buddy->name); | |
607 | |
608 } | |
609 | |
610 static void | |
9030 | 611 silcgaim_buddy_showkey(GaimBlistNode *node, gpointer data) |
8849 | 612 { |
9030 | 613 GaimBuddy *b; |
614 GaimConnection *gc; | |
615 SilcGaim sg; | |
8849 | 616 SilcPublicKey public_key; |
617 const char *pkfile; | |
9030 | 618 |
619 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
8849 | 620 |
9030 | 621 b = (GaimBuddy *) node; |
622 gc = gaim_account_get_connection(b->account); | |
623 sg = gc->proto_data; | |
8849 | 624 |
9038 | 625 pkfile = gaim_blist_node_get_string(node, "public-key"); |
8849 | 626 if (!silc_pkcs_load_public_key(pkfile, &public_key, SILC_PKCS_FILE_PEM) && |
627 !silc_pkcs_load_public_key(pkfile, &public_key, SILC_PKCS_FILE_BIN)) { | |
628 gaim_notify_error(gc, | |
629 _("Show Public Key"), | |
630 _("Could not load public key"), NULL); | |
631 return; | |
632 } | |
633 | |
9030 | 634 silcgaim_show_public_key(sg, b->name, public_key, NULL, NULL); |
8849 | 635 silc_pkcs_public_key_free(public_key); |
636 } | |
637 | |
638 | |
639 /**************************** Buddy routines *********************************/ | |
640 | |
641 /* The buddies are implemented by using the WHOIS and WATCH commands that | |
642 can be used to search users by their public key. Since nicknames aren't | |
643 unique in SILC we cannot trust the buddy list using their nickname. We | |
644 associate public keys to buddies and use those to search and watch | |
645 in the network. | |
646 | |
647 The problem is that Gaim does not return GaimBuddy contexts to the | |
648 callbacks but the buddy names. Naturally, this is not going to work | |
649 with SILC. But, for now, we have to do what we can... */ | |
650 | |
651 typedef struct { | |
652 SilcClient client; | |
653 SilcClientConnection conn; | |
654 SilcClientID client_id; | |
655 GaimBuddy *b; | |
656 unsigned char *offline_pk; | |
657 SilcUInt32 offline_pk_len; | |
658 unsigned int offline : 1; | |
659 unsigned int pubkey_search : 1; | |
660 unsigned int init : 1; | |
661 } *SilcGaimBuddyRes; | |
662 | |
663 static void | |
664 silcgaim_add_buddy_ask_pk_cb(SilcGaimBuddyRes r, gint id); | |
665 static void | |
666 silcgaim_add_buddy_resolved(SilcClient client, | |
667 SilcClientConnection conn, | |
668 SilcClientEntry *clients, | |
669 SilcUInt32 clients_count, | |
670 void *context); | |
671 | |
672 void silcgaim_get_info(GaimConnection *gc, const char *who) | |
673 { | |
674 SilcGaim sg = gc->proto_data; | |
675 SilcClient client = sg->client; | |
676 SilcClientConnection conn = sg->conn; | |
677 SilcClientEntry client_entry; | |
678 GaimBuddy *b; | |
679 const char *filename, *nick = who; | |
680 char tmp[256]; | |
681 | |
682 if (!who) | |
683 return; | |
684 if (strlen(who) > 1 && who[0] == '@') | |
685 nick = who + 1; | |
686 if (strlen(who) > 1 && who[0] == '*') | |
687 nick = who + 1; | |
688 if (strlen(who) > 2 && who[0] == '*' && who[1] == '@') | |
689 nick = who + 2; | |
690 | |
691 b = gaim_find_buddy(gc->account, nick); | |
692 if (b) { | |
693 /* See if we have this buddy's public key. If we do use that | |
694 to search the details. */ | |
695 filename = gaim_blist_node_get_string((GaimBlistNode *)b, "public-key"); | |
696 if (filename) { | |
697 /* Call WHOIS. The user info is displayed in the WHOIS | |
698 command reply. */ | |
699 silc_client_command_call(client, conn, NULL, "WHOIS", | |
700 "-details", "-pubkey", filename, NULL); | |
701 return; | |
702 } | |
703 | |
704 if (!b->proto_data) { | |
705 g_snprintf(tmp, sizeof(tmp), | |
706 _("User %s is not present in the network"), b->name); | |
707 gaim_notify_error(gc, _("User Information"), | |
708 _("Cannot get user information"), tmp); | |
709 return; | |
710 } | |
711 | |
712 client_entry = silc_client_get_client_by_id(client, conn, b->proto_data); | |
713 if (client_entry) { | |
714 /* Call WHOIS. The user info is displayed in the WHOIS | |
715 command reply. */ | |
716 silc_client_command_call(client, conn, NULL, "WHOIS", | |
717 client_entry->nickname, "-details", NULL); | |
718 } | |
719 } else { | |
720 /* Call WHOIS just with nickname. */ | |
721 silc_client_command_call(client, conn, NULL, "WHOIS", nick, NULL); | |
722 } | |
723 } | |
724 | |
725 static void | |
726 silcgaim_add_buddy_pk_no(SilcGaimBuddyRes r) | |
727 { | |
728 char tmp[512]; | |
729 g_snprintf(tmp, sizeof(tmp), _("The %s buddy is not trusted"), | |
730 r->b->name); | |
731 gaim_notify_error(r->client->application, _("Add Buddy"), tmp, | |
8910 | 732 _("You cannot receive buddy notifications until you " |
733 "import his/her public key. You can use the Get Public Key " | |
8849 | 734 "command to get the public key.")); |
10050 | 735 gaim_prpl_got_user_status(gaim_buddy_get_account(r->b), gaim_buddy_get_name(r->b), SILCGAIM_STATUS_ID_OFFLINE, NULL); |
8849 | 736 } |
737 | |
738 static void | |
739 silcgaim_add_buddy_save(bool success, void *context) | |
740 { | |
741 SilcGaimBuddyRes r = context; | |
742 GaimBuddy *b = r->b; | |
743 SilcClient client = r->client; | |
744 SilcClientEntry client_entry; | |
745 SilcAttributePayload attr; | |
746 SilcAttribute attribute; | |
747 SilcVCardStruct vcard; | |
748 SilcAttributeObjMime message, extension; | |
749 SilcAttributeObjPk serverpk, usersign, serversign; | |
750 gboolean usign_success = TRUE, ssign_success = TRUE; | |
751 unsigned char filename[256], filename2[256], *fingerprint = NULL, *tmp; | |
752 SilcUInt32 len; | |
753 int i; | |
754 | |
755 if (!success) { | |
756 /* The user did not trust the public key. */ | |
757 silcgaim_add_buddy_pk_no(r); | |
758 silc_free(r); | |
759 return; | |
760 } | |
761 | |
762 if (r->offline) { | |
763 /* User is offline. Associate the imported public key with | |
764 this user. */ | |
765 fingerprint = silc_hash_fingerprint(NULL, r->offline_pk, | |
766 r->offline_pk_len); | |
767 for (i = 0; i < strlen(fingerprint); i++) | |
768 if (fingerprint[i] == ' ') | |
769 fingerprint[i] = '_'; | |
770 g_snprintf(filename, sizeof(filename) - 1, | |
771 "%s" G_DIR_SEPARATOR_S "clientkeys" G_DIR_SEPARATOR_S "clientkey_%s.pub", | |
772 silcgaim_silcdir(), fingerprint); | |
773 gaim_blist_node_set_string((GaimBlistNode *)b, "public-key", filename); | |
10050 | 774 gaim_prpl_got_user_status(gaim_buddy_get_account(r->b), gaim_buddy_get_name(r->b), SILCGAIM_STATUS_ID_OFFLINE, NULL); |
8849 | 775 silc_free(fingerprint); |
776 silc_free(r->offline_pk); | |
777 silc_free(r); | |
778 return; | |
779 } | |
780 | |
781 /* Get the client entry. */ | |
782 client_entry = silc_client_get_client_by_id(r->client, r->conn, | |
783 &r->client_id); | |
784 if (!client_entry) { | |
785 silc_free(r); | |
786 return; | |
787 } | |
788 | |
789 memset(&vcard, 0, sizeof(vcard)); | |
790 memset(&message, 0, sizeof(message)); | |
791 memset(&extension, 0, sizeof(extension)); | |
792 memset(&serverpk, 0, sizeof(serverpk)); | |
793 memset(&usersign, 0, sizeof(usersign)); | |
794 memset(&serversign, 0, sizeof(serversign)); | |
795 | |
796 /* Now that we have the public key and we trust it now we | |
797 save the attributes of the buddy and update its status. */ | |
798 | |
9133
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
799 if (client_entry->attrs) { |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
800 silc_dlist_start(client_entry->attrs); |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
801 while ((attr = silc_dlist_get(client_entry->attrs)) |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
802 != SILC_LIST_END) { |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
803 attribute = silc_attribute_get_attribute(attr); |
8849 | 804 |
9133
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
805 switch (attribute) { |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
806 case SILC_ATTRIBUTE_USER_INFO: |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
807 if (!silc_attribute_get_object(attr, (void *)&vcard, |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
808 sizeof(vcard))) |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
809 continue; |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
810 break; |
8849 | 811 |
9133
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
812 case SILC_ATTRIBUTE_STATUS_MESSAGE: |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
813 if (!silc_attribute_get_object(attr, (void *)&message, |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
814 sizeof(message))) |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
815 continue; |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
816 break; |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
817 |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
818 case SILC_ATTRIBUTE_EXTENSION: |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
819 if (!silc_attribute_get_object(attr, (void *)&extension, |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
820 sizeof(extension))) |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
821 continue; |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
822 break; |
8849 | 823 |
9133
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
824 case SILC_ATTRIBUTE_SERVER_PUBLIC_KEY: |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
825 if (serverpk.type) |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
826 continue; |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
827 if (!silc_attribute_get_object(attr, (void *)&serverpk, |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
828 sizeof(serverpk))) |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
829 continue; |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
830 break; |
8849 | 831 |
9133
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
832 case SILC_ATTRIBUTE_USER_DIGITAL_SIGNATURE: |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
833 if (usersign.data) |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
834 continue; |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
835 if (!silc_attribute_get_object(attr, (void *)&usersign, |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
836 sizeof(usersign))) |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
837 continue; |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
838 break; |
8849 | 839 |
9133
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
840 case SILC_ATTRIBUTE_SERVER_DIGITAL_SIGNATURE: |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
841 if (serversign.data) |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
842 continue; |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
843 if (!silc_attribute_get_object(attr, (void *)&serversign, |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
844 sizeof(serversign))) |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
845 continue; |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
846 break; |
8849 | 847 |
9133
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
848 default: |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
849 break; |
c42c3ac3466e
[gaim-migrate @ 9915]
Christian Hammond <chipx86@chipx86.com>
parents:
9060
diff
changeset
|
850 } |
8849 | 851 } |
852 } | |
853 | |
854 /* Verify the attribute signatures */ | |
855 | |
856 if (usersign.data) { | |
857 SilcPKCS pkcs; | |
858 unsigned char *verifyd; | |
859 SilcUInt32 verify_len; | |
860 | |
861 silc_pkcs_alloc("rsa", &pkcs); | |
862 verifyd = silc_attribute_get_verify_data(client_entry->attrs, | |
863 FALSE, &verify_len); | |
864 if (verifyd && silc_pkcs_public_key_set(pkcs, client_entry->public_key)){ | |
865 if (!silc_pkcs_verify_with_hash(pkcs, client->sha1hash, | |
866 usersign.data, | |
867 usersign.data_len, | |
868 verifyd, verify_len)) | |
869 usign_success = FALSE; | |
870 } | |
871 silc_free(verifyd); | |
872 } | |
873 | |
874 if (serversign.data && !strcmp(serverpk.type, "silc-rsa")) { | |
875 SilcPublicKey public_key; | |
876 SilcPKCS pkcs; | |
877 unsigned char *verifyd; | |
878 SilcUInt32 verify_len; | |
879 | |
880 if (silc_pkcs_public_key_decode(serverpk.data, serverpk.data_len, | |
881 &public_key)) { | |
882 silc_pkcs_alloc("rsa", &pkcs); | |
883 verifyd = silc_attribute_get_verify_data(client_entry->attrs, | |
884 TRUE, &verify_len); | |
885 if (verifyd && silc_pkcs_public_key_set(pkcs, public_key)) { | |
886 if (!silc_pkcs_verify_with_hash(pkcs, client->sha1hash, | |
887 serversign.data, | |
888 serversign.data_len, | |
889 verifyd, verify_len)) | |
890 ssign_success = FALSE; | |
891 } | |
892 silc_pkcs_public_key_free(public_key); | |
893 silc_free(verifyd); | |
894 } | |
895 } | |
896 | |
897 fingerprint = silc_fingerprint(client_entry->fingerprint, | |
898 client_entry->fingerprint_len); | |
899 for (i = 0; i < strlen(fingerprint); i++) | |
900 if (fingerprint[i] == ' ') | |
901 fingerprint[i] = '_'; | |
902 | |
903 if (usign_success || ssign_success) { | |
904 struct passwd *pw; | |
905 struct stat st; | |
906 | |
907 memset(filename2, 0, sizeof(filename2)); | |
908 | |
909 /* Filename for dir */ | |
910 tmp = fingerprint + strlen(fingerprint) - 9; | |
911 g_snprintf(filename, sizeof(filename) - 1, | |
912 "%s" G_DIR_SEPARATOR_S "friends" G_DIR_SEPARATOR_S "%s", | |
913 silcgaim_silcdir(), tmp); | |
914 | |
915 pw = getpwuid(getuid()); | |
916 if (!pw) | |
917 return; | |
918 | |
919 /* Create dir if it doesn't exist */ | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10341
diff
changeset
|
920 if ((g_stat(filename, &st)) == -1) { |
8849 | 921 if (errno == ENOENT) { |
922 if (pw->pw_uid == geteuid()) | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10341
diff
changeset
|
923 g_mkdir(filename, 0755); |
8849 | 924 } |
925 } | |
926 | |
927 /* Save VCard */ | |
928 g_snprintf(filename2, sizeof(filename2) - 1, | |
929 "%s" G_DIR_SEPARATOR_S "vcard", filename); | |
930 if (vcard.full_name) { | |
931 tmp = silc_vcard_encode(&vcard, &len); | |
932 silc_file_writefile(filename2, tmp, len); | |
933 silc_free(tmp); | |
934 } | |
935 | |
936 /* Save status message */ | |
937 if (message.mime) { | |
938 memset(filename2, 0, sizeof(filename2)); | |
939 g_snprintf(filename2, sizeof(filename2) - 1, | |
940 "%s" G_DIR_SEPARATOR_S "status_message.mime", | |
941 filename); | |
942 silc_file_writefile(filename2, message.mime, | |
943 message.mime_len); | |
944 } | |
945 | |
946 /* Save extension data */ | |
947 if (extension.mime) { | |
948 memset(filename2, 0, sizeof(filename2)); | |
949 g_snprintf(filename2, sizeof(filename2) - 1, | |
950 "%s" G_DIR_SEPARATOR_S "extension.mime", | |
951 filename); | |
952 silc_file_writefile(filename2, extension.mime, | |
953 extension.mime_len); | |
954 } | |
955 } | |
956 | |
957 /* Save the public key path to buddy properties, as it is used | |
958 to identify the buddy in the network (and not the nickname). */ | |
959 memset(filename, 0, sizeof(filename)); | |
960 g_snprintf(filename, sizeof(filename) - 1, | |
961 "%s" G_DIR_SEPARATOR_S "clientkeys" G_DIR_SEPARATOR_S "clientkey_%s.pub", | |
962 silcgaim_silcdir(), fingerprint); | |
963 gaim_blist_node_set_string((GaimBlistNode *)b, "public-key", filename); | |
964 | |
10050 | 965 /* Update online status */ |
966 gaim_prpl_got_user_status(gaim_buddy_get_account(r->b), gaim_buddy_get_name(r->b), SILCGAIM_STATUS_ID_ONLINE, NULL); | |
8849 | 967 |
968 /* Finally, start watching this user so we receive its status | |
969 changes from the server */ | |
970 g_snprintf(filename2, sizeof(filename2) - 1, "+%s", filename); | |
971 silc_client_command_call(r->client, r->conn, NULL, "WATCH", "-pubkey", | |
972 filename2, NULL); | |
973 | |
974 silc_free(fingerprint); | |
975 silc_free(r); | |
976 } | |
977 | |
978 static void | |
979 silcgaim_add_buddy_ask_import(void *user_data, const char *name) | |
980 { | |
981 SilcGaimBuddyRes r = (SilcGaimBuddyRes)user_data; | |
982 SilcPublicKey public_key; | |
983 | |
984 /* Load the public key */ | |
985 if (!silc_pkcs_load_public_key(name, &public_key, SILC_PKCS_FILE_PEM) && | |
986 !silc_pkcs_load_public_key(name, &public_key, SILC_PKCS_FILE_BIN)) { | |
987 silcgaim_add_buddy_ask_pk_cb(r, 0); | |
988 gaim_notify_error(r->client->application, | |
989 _("Add Buddy"), _("Could not load public key"), NULL); | |
990 return; | |
991 } | |
992 | |
993 /* Now verify the public key */ | |
994 r->offline_pk = silc_pkcs_public_key_encode(public_key, &r->offline_pk_len); | |
995 silcgaim_verify_public_key(r->client, r->conn, r->b->name, | |
996 SILC_SOCKET_TYPE_CLIENT, | |
997 r->offline_pk, r->offline_pk_len, | |
998 SILC_SKE_PK_TYPE_SILC, | |
999 silcgaim_add_buddy_save, r); | |
1000 } | |
1001 | |
1002 static void | |
1003 silcgaim_add_buddy_ask_pk_cancel(void *user_data, const char *name) | |
1004 { | |
1005 SilcGaimBuddyRes r = (SilcGaimBuddyRes)user_data; | |
1006 | |
1007 /* The user did not import public key. The buddy is unusable. */ | |
1008 silcgaim_add_buddy_pk_no(r); | |
1009 silc_free(r); | |
1010 } | |
1011 | |
1012 static void | |
1013 silcgaim_add_buddy_ask_pk_cb(SilcGaimBuddyRes r, gint id) | |
1014 { | |
1015 if (id != 0) { | |
1016 /* The user did not import public key. The buddy is unusable. */ | |
1017 silcgaim_add_buddy_pk_no(r); | |
1018 silc_free(r); | |
1019 return; | |
1020 } | |
1021 | |
1022 /* Open file selector to select the public key. */ | |
10232 | 1023 gaim_request_file(NULL, _("Open..."), NULL, FALSE, |
8849 | 1024 G_CALLBACK(silcgaim_add_buddy_ask_import), |
1025 G_CALLBACK(silcgaim_add_buddy_ask_pk_cancel), r); | |
1026 } | |
1027 | |
1028 static void | |
1029 silcgaim_add_buddy_ask_pk(SilcGaimBuddyRes r) | |
1030 { | |
1031 char tmp[512]; | |
1032 g_snprintf(tmp, sizeof(tmp), _("The %s buddy is not present in the network"), | |
1033 r->b->name); | |
1034 gaim_request_action(NULL, _("Add Buddy"), tmp, | |
8910 | 1035 _("To add the buddy you must import his/her public key. " |
8849 | 1036 "Press Import to import a public key."), 0, r, 2, |
1037 _("Cancel"), G_CALLBACK(silcgaim_add_buddy_ask_pk_cb), | |
1038 _("Import..."), G_CALLBACK(silcgaim_add_buddy_ask_pk_cb)); | |
1039 } | |
1040 | |
1041 static void | |
1042 silcgaim_add_buddy_getkey_cb(SilcGaimBuddyRes r, | |
1043 SilcClientCommandReplyContext cmd) | |
1044 { | |
1045 SilcClientEntry client_entry; | |
1046 unsigned char *pk; | |
1047 SilcUInt32 pk_len; | |
1048 | |
1049 /* Get the client entry. */ | |
1050 client_entry = silc_client_get_client_by_id(r->client, r->conn, | |
1051 &r->client_id); | |
1052 if (!client_entry || !client_entry->public_key) { | |
1053 /* The buddy is offline/nonexistent. We will require user | |
1054 to associate a public key with the buddy or the buddy | |
1055 cannot be added. */ | |
1056 r->offline = TRUE; | |
1057 silcgaim_add_buddy_ask_pk(r); | |
1058 return; | |
1059 } | |
1060 | |
1061 /* Now verify the public key */ | |
1062 pk = silc_pkcs_public_key_encode(client_entry->public_key, &pk_len); | |
1063 silcgaim_verify_public_key(r->client, r->conn, client_entry->nickname, | |
1064 SILC_SOCKET_TYPE_CLIENT, | |
1065 pk, pk_len, SILC_SKE_PK_TYPE_SILC, | |
1066 silcgaim_add_buddy_save, r); | |
1067 silc_free(pk); | |
1068 } | |
1069 | |
1070 static void | |
1071 silcgaim_add_buddy_select_cb(SilcGaimBuddyRes r, GaimRequestFields *fields) | |
1072 { | |
1073 GaimRequestField *f; | |
1074 const GList *list; | |
1075 SilcClientEntry client_entry; | |
1076 | |
1077 f = gaim_request_fields_get_field(fields, "list"); | |
1078 list = gaim_request_field_list_get_selected(f); | |
1079 if (!list) { | |
1080 /* The user did not select any user. */ | |
1081 silcgaim_add_buddy_pk_no(r); | |
1082 silc_free(r); | |
1083 return; | |
1084 } | |
1085 | |
1086 client_entry = gaim_request_field_list_get_data(f, list->data); | |
1087 silcgaim_add_buddy_resolved(r->client, r->conn, &client_entry, 1, r); | |
1088 } | |
1089 | |
1090 static void | |
1091 silcgaim_add_buddy_select_cancel(SilcGaimBuddyRes r, GaimRequestFields *fields) | |
1092 { | |
1093 /* The user did not select any user. */ | |
1094 silcgaim_add_buddy_pk_no(r); | |
1095 silc_free(r); | |
1096 } | |
1097 | |
1098 static void | |
1099 silcgaim_add_buddy_select(SilcGaimBuddyRes r, | |
1100 SilcClientEntry *clients, | |
1101 SilcUInt32 clients_count) | |
1102 { | |
1103 GaimRequestFields *fields; | |
1104 GaimRequestFieldGroup *g; | |
1105 GaimRequestField *f; | |
1106 char tmp[512]; | |
1107 int i; | |
1108 | |
1109 fields = gaim_request_fields_new(); | |
1110 g = gaim_request_field_group_new(NULL); | |
1111 f = gaim_request_field_list_new("list", NULL); | |
1112 gaim_request_field_group_add_field(g, f); | |
1113 gaim_request_field_list_set_multi_select(f, FALSE); | |
1114 gaim_request_fields_add_group(fields, g); | |
1115 | |
1116 for (i = 0; i < clients_count; i++) { | |
1117 g_snprintf(tmp, sizeof(tmp), "%s - %s (%s@%s)", | |
1118 clients[i]->realname, clients[i]->nickname, | |
1119 clients[i]->username, clients[i]->hostname ? | |
1120 clients[i]->hostname : ""); | |
1121 gaim_request_field_list_add(f, tmp, clients[i]); | |
1122 } | |
1123 | |
1124 gaim_request_fields(NULL, _("Add Buddy"), | |
8891 | 1125 _("Select correct user"), |
1126 r->pubkey_search | |
1127 ? _("More than one user was found with the same public key. Select " | |
1128 "the correct user from the list to add to the buddy list.") | |
1129 : _("More than one user was found with the same name. Select " | |
1130 "the correct user from the list to add to the buddy list."), | |
1131 fields, | |
1132 _("OK"), G_CALLBACK(silcgaim_add_buddy_select_cb), | |
1133 _("Cancel"), G_CALLBACK(silcgaim_add_buddy_select_cancel), r); | |
8849 | 1134 } |
1135 | |
1136 static void | |
1137 silcgaim_add_buddy_resolved(SilcClient client, | |
1138 SilcClientConnection conn, | |
1139 SilcClientEntry *clients, | |
1140 SilcUInt32 clients_count, | |
1141 void *context) | |
1142 { | |
1143 SilcGaimBuddyRes r = context; | |
1144 GaimBuddy *b = r->b; | |
1145 SilcAttributePayload pub; | |
1146 SilcAttributeObjPk userpk; | |
1147 unsigned char *pk; | |
1148 SilcUInt32 pk_len; | |
1149 const char *filename; | |
1150 | |
10029 | 1151 filename = gaim_blist_node_get_string((GaimBlistNode *)b, "public-key"); |
1152 | |
8849 | 1153 /* If the buddy is offline/nonexistent, we will require user |
1154 to associate a public key with the buddy or the buddy | |
1155 cannot be added. */ | |
1156 if (!clients_count) { | |
1157 if (r->init) { | |
1158 silc_free(r); | |
1159 return; | |
1160 } | |
1161 | |
1162 r->offline = TRUE; | |
10029 | 1163 /* If the user has already associated a public key, try loading it |
1164 * before prompting the user to load it again */ | |
1165 if (filename != NULL) | |
1166 silcgaim_add_buddy_ask_import(r, filename); | |
1167 else | |
1168 silcgaim_add_buddy_ask_pk(r); | |
8849 | 1169 return; |
1170 } | |
1171 | |
1172 /* If more than one client was found with nickname, we need to verify | |
1173 from user which one is the correct. */ | |
1174 if (clients_count > 1 && !r->pubkey_search) { | |
1175 if (r->init) { | |
1176 silc_free(r); | |
1177 return; | |
1178 } | |
1179 | |
1180 silcgaim_add_buddy_select(r, clients, clients_count); | |
1181 return; | |
1182 } | |
1183 | |
1184 /* If we searched using public keys and more than one entry was found | |
1185 the same person is logged on multiple times. */ | |
1186 if (clients_count > 1 && r->pubkey_search && b->name) { | |
1187 if (r->init) { | |
1188 /* Find the entry that closest matches to the | |
1189 buddy nickname. */ | |
1190 int i; | |
1191 for (i = 0; i < clients_count; i++) { | |
1192 if (!strncasecmp(b->name, clients[i]->nickname, | |
1193 strlen(b->name))) { | |
1194 clients[0] = clients[i]; | |
1195 break; | |
1196 } | |
1197 } | |
1198 } else { | |
1199 /* Verify from user which one is correct */ | |
1200 silcgaim_add_buddy_select(r, clients, clients_count); | |
1201 return; | |
1202 } | |
1203 } | |
1204 | |
1205 /* The client was found. Now get its public key and verify | |
1206 that before adding the buddy. */ | |
1207 memset(&userpk, 0, sizeof(userpk)); | |
1208 b->proto_data = silc_memdup(clients[0]->id, sizeof(*clients[0]->id)); | |
1209 r->client_id = *clients[0]->id; | |
1210 | |
1211 /* Get the public key from attributes, if not present then | |
1212 resolve it with GETKEY unless we have it cached already. */ | |
1213 if (clients[0]->attrs && !clients[0]->public_key) { | |
1214 pub = silcgaim_get_attr(clients[0]->attrs, | |
1215 SILC_ATTRIBUTE_USER_PUBLIC_KEY); | |
1216 if (!pub || !silc_attribute_get_object(pub, (void *)&userpk, | |
1217 sizeof(userpk))) { | |
1218 /* Get public key with GETKEY */ | |
1219 silc_client_command_call(client, conn, NULL, | |
1220 "GETKEY", clients[0]->nickname, NULL); | |
1221 silc_client_command_pending(conn, SILC_COMMAND_GETKEY, | |
1222 conn->cmd_ident, | |
1223 (SilcCommandCb)silcgaim_add_buddy_getkey_cb, | |
1224 r); | |
1225 return; | |
1226 } | |
1227 if (!silc_pkcs_public_key_decode(userpk.data, userpk.data_len, | |
1228 &clients[0]->public_key)) | |
1229 return; | |
1230 silc_free(userpk.data); | |
1231 } else if (filename && !clients[0]->public_key) { | |
1232 if (!silc_pkcs_load_public_key(filename, &clients[0]->public_key, | |
1233 SILC_PKCS_FILE_PEM) && | |
1234 !silc_pkcs_load_public_key(filename, &clients[0]->public_key, | |
1235 SILC_PKCS_FILE_BIN)) { | |
1236 /* Get public key with GETKEY */ | |
1237 silc_client_command_call(client, conn, NULL, | |
1238 "GETKEY", clients[0]->nickname, NULL); | |
1239 silc_client_command_pending(conn, SILC_COMMAND_GETKEY, | |
1240 conn->cmd_ident, | |
1241 (SilcCommandCb)silcgaim_add_buddy_getkey_cb, | |
1242 r); | |
1243 return; | |
1244 } | |
1245 } else if (!clients[0]->public_key) { | |
1246 /* Get public key with GETKEY */ | |
1247 silc_client_command_call(client, conn, NULL, | |
1248 "GETKEY", clients[0]->nickname, NULL); | |
1249 silc_client_command_pending(conn, SILC_COMMAND_GETKEY, | |
1250 conn->cmd_ident, | |
1251 (SilcCommandCb)silcgaim_add_buddy_getkey_cb, | |
1252 r); | |
1253 return; | |
1254 } | |
1255 | |
1256 /* We have the public key, verify it. */ | |
1257 pk = silc_pkcs_public_key_encode(clients[0]->public_key, &pk_len); | |
1258 silcgaim_verify_public_key(client, conn, clients[0]->nickname, | |
1259 SILC_SOCKET_TYPE_CLIENT, | |
1260 pk, pk_len, SILC_SKE_PK_TYPE_SILC, | |
1261 silcgaim_add_buddy_save, r); | |
1262 silc_free(pk); | |
1263 } | |
1264 | |
1265 static void | |
1266 silcgaim_add_buddy_i(GaimConnection *gc, GaimBuddy *b, gboolean init) | |
1267 { | |
1268 SilcGaim sg = gc->proto_data; | |
1269 SilcClient client = sg->client; | |
1270 SilcClientConnection conn = sg->conn; | |
1271 SilcGaimBuddyRes r; | |
1272 SilcBuffer attrs; | |
1273 const char *filename, *name = b->name; | |
1274 | |
1275 r = silc_calloc(1, sizeof(*r)); | |
1276 if (!r) | |
1277 return; | |
1278 r->client = client; | |
1279 r->conn = conn; | |
1280 r->b = b; | |
1281 r->init = init; | |
1282 | |
1283 /* See if we have this buddy's public key. If we do use that | |
1284 to search the details. */ | |
1285 filename = gaim_blist_node_get_string((GaimBlistNode *)b, "public-key"); | |
1286 if (filename) { | |
1287 SilcPublicKey public_key; | |
1288 SilcAttributeObjPk userpk; | |
1289 | |
1290 if (!silc_pkcs_load_public_key(filename, &public_key, | |
1291 SILC_PKCS_FILE_PEM) && | |
1292 !silc_pkcs_load_public_key(filename, &public_key, | |
1293 SILC_PKCS_FILE_BIN)) | |
1294 return; | |
1295 | |
1296 /* Get all attributes, and use the public key to search user */ | |
1297 name = NULL; | |
1298 attrs = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO, | |
1299 SILC_ATTRIBUTE_SERVICE, | |
1300 SILC_ATTRIBUTE_STATUS_MOOD, | |
1301 SILC_ATTRIBUTE_STATUS_FREETEXT, | |
1302 SILC_ATTRIBUTE_STATUS_MESSAGE, | |
1303 SILC_ATTRIBUTE_PREFERRED_LANGUAGE, | |
1304 SILC_ATTRIBUTE_PREFERRED_CONTACT, | |
1305 SILC_ATTRIBUTE_TIMEZONE, | |
1306 SILC_ATTRIBUTE_GEOLOCATION, | |
1307 SILC_ATTRIBUTE_DEVICE_INFO, 0); | |
1308 userpk.type = "silc-rsa"; | |
1309 userpk.data = silc_pkcs_public_key_encode(public_key, &userpk.data_len); | |
1310 attrs = silc_attribute_payload_encode(attrs, | |
1311 SILC_ATTRIBUTE_USER_PUBLIC_KEY, | |
1312 SILC_ATTRIBUTE_FLAG_VALID, | |
1313 &userpk, sizeof(userpk)); | |
1314 silc_free(userpk.data); | |
1315 silc_pkcs_public_key_free(public_key); | |
1316 r->pubkey_search = TRUE; | |
1317 } else { | |
1318 /* Get all attributes */ | |
1319 attrs = silc_client_attributes_request(0); | |
1320 } | |
1321 | |
1322 /* Resolve */ | |
1323 silc_client_get_clients_whois(client, conn, name, NULL, attrs, | |
1324 silcgaim_add_buddy_resolved, r); | |
1325 silc_buffer_free(attrs); | |
1326 } | |
1327 | |
9285 | 1328 void silcgaim_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
8849 | 1329 { |
9285 | 1330 silcgaim_add_buddy_i(gc, buddy, FALSE); |
8849 | 1331 } |
1332 | |
10341 | 1333 void silcgaim_add_buddies(GaimConnection *gc, GList *buddies, GList *groups) |
1334 { | |
1335 GList *curb = buddies; | |
1336 while (curb != NULL) { | |
1337 silcgaim_add_buddy_i(gc, curb->data, TRUE); | |
1338 curb = curb->next; | |
1339 } | |
1340 } | |
1341 | |
9285 | 1342 void silcgaim_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, |
1343 GaimGroup *group) | |
8849 | 1344 { |
9285 | 1345 silc_free(buddy->proto_data); |
8849 | 1346 } |
1347 | |
1348 void silcgaim_idle_set(GaimConnection *gc, int idle) | |
1349 | |
1350 { | |
1351 SilcGaim sg = gc->proto_data; | |
1352 SilcClient client = sg->client; | |
1353 SilcClientConnection conn = sg->conn; | |
1354 SilcAttributeObjService service; | |
1355 const char *server; | |
1356 int port; | |
1357 | |
1358 server = gaim_account_get_string(sg->account, "server", | |
1359 "silc.silcnet.org"); | |
1360 port = gaim_account_get_int(sg->account, "port", 706), | |
1361 | |
1362 memset(&service, 0, sizeof(service)); | |
1363 silc_client_attribute_del(client, conn, | |
1364 SILC_ATTRIBUTE_SERVICE, NULL); | |
1365 service.port = port; | |
1366 g_snprintf(service.address, sizeof(service.address), "%s", server); | |
1367 service.idle = idle; | |
1368 silc_client_attribute_add(client, conn, SILC_ATTRIBUTE_SERVICE, | |
1369 &service, sizeof(service)); | |
1370 } | |
1371 | |
1372 char *silcgaim_status_text(GaimBuddy *b) | |
1373 { | |
1374 SilcGaim sg = b->account->gc->proto_data; | |
1375 SilcClient client = sg->client; | |
1376 SilcClientConnection conn = sg->conn; | |
1377 SilcClientID *client_id = b->proto_data; | |
1378 SilcClientEntry client_entry; | |
1379 SilcAttributePayload attr; | |
1380 SilcAttributeMood mood = 0; | |
1381 | |
1382 /* Get the client entry. */ | |
1383 client_entry = silc_client_get_client_by_id(client, conn, client_id); | |
1384 if (!client_entry) | |
1385 return NULL; | |
1386 | |
1387 /* If user is online, we show the mood status, if available. | |
1388 If user is offline or away that status is indicated. */ | |
1389 | |
1390 if (client_entry->mode & SILC_UMODE_DETACHED) | |
1391 return g_strdup(_("Detached")); | |
1392 if (client_entry->mode & SILC_UMODE_GONE) | |
1393 return g_strdup(_("Away")); | |
1394 if (client_entry->mode & SILC_UMODE_INDISPOSED) | |
1395 return g_strdup(_("Indisposed")); | |
1396 if (client_entry->mode & SILC_UMODE_BUSY) | |
1397 return g_strdup(_("Busy")); | |
1398 if (client_entry->mode & SILC_UMODE_PAGE) | |
1399 return g_strdup(_("Wake Me Up")); | |
1400 if (client_entry->mode & SILC_UMODE_HYPER) | |
1401 return g_strdup(_("Hyper Active")); | |
1402 if (client_entry->mode & SILC_UMODE_ROBOT) | |
1403 return g_strdup(_("Robot")); | |
1404 | |
1405 attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_STATUS_MOOD); | |
1406 if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) { | |
1407 /* The mood is a bit mask, so we could show multiple moods, | |
1408 but let's show only one for now. */ | |
1409 if (mood & SILC_ATTRIBUTE_MOOD_HAPPY) | |
1410 return g_strdup(_("Happy")); | |
1411 if (mood & SILC_ATTRIBUTE_MOOD_SAD) | |
1412 return g_strdup(_("Sad")); | |
1413 if (mood & SILC_ATTRIBUTE_MOOD_ANGRY) | |
1414 return g_strdup(_("Angry")); | |
1415 if (mood & SILC_ATTRIBUTE_MOOD_JEALOUS) | |
1416 return g_strdup(_("Jealous")); | |
1417 if (mood & SILC_ATTRIBUTE_MOOD_ASHAMED) | |
1418 return g_strdup(_("Ashamed")); | |
1419 if (mood & SILC_ATTRIBUTE_MOOD_INVINCIBLE) | |
1420 return g_strdup(_("Invincible")); | |
1421 if (mood & SILC_ATTRIBUTE_MOOD_INLOVE) | |
1422 return g_strdup(_("In Love")); | |
1423 if (mood & SILC_ATTRIBUTE_MOOD_SLEEPY) | |
1424 return g_strdup(_("Sleepy")); | |
1425 if (mood & SILC_ATTRIBUTE_MOOD_BORED) | |
1426 return g_strdup(_("Bored")); | |
1427 if (mood & SILC_ATTRIBUTE_MOOD_EXCITED) | |
1428 return g_strdup(_("Excited")); | |
1429 if (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS) | |
1430 return g_strdup(_("Anxious")); | |
1431 } | |
1432 | |
1433 return NULL; | |
1434 } | |
1435 | |
1436 char *silcgaim_tooltip_text(GaimBuddy *b) | |
1437 { | |
1438 SilcGaim sg = b->account->gc->proto_data; | |
1439 SilcClient client = sg->client; | |
1440 SilcClientConnection conn = sg->conn; | |
1441 SilcClientID *client_id = b->proto_data; | |
1442 SilcClientEntry client_entry; | |
9488 | 1443 char *moodstr, *statusstr, *contactstr, *langstr, *devicestr, *tzstr, *geostr; |
8849 | 1444 GString *s; |
1445 char *buf; | |
1446 char tmp[256]; | |
1447 | |
1448 s = g_string_new(""); | |
1449 | |
1450 /* Get the client entry. */ | |
1451 client_entry = silc_client_get_client_by_id(client, conn, client_id); | |
1452 if (!client_entry) | |
1453 return NULL; | |
1454 | |
1455 if (client_entry->nickname) | |
9272 | 1456 g_string_append_printf(s, "\n<b>%s:</b> %s", _("Nickname"), |
8849 | 1457 client_entry->nickname); |
1458 if (client_entry->username && client_entry->hostname) | |
9272 | 1459 g_string_append_printf(s, "\n<b>%s:</b> %s@%s", _("Username"), |
8849 | 1460 client_entry->username, client_entry->hostname); |
1461 if (client_entry->mode) { | |
9488 | 1462 g_string_append_printf(s, "\n<b>%s:</b> ", _("User Modes")); |
8849 | 1463 memset(tmp, 0, sizeof(tmp)); |
1464 silcgaim_get_umode_string(client_entry->mode, | |
1465 tmp, sizeof(tmp) - strlen(tmp)); | |
9272 | 1466 g_string_append_printf(s, "%s", tmp); |
8849 | 1467 } |
1468 | |
9488 | 1469 silcgaim_parse_attrs(client_entry->attrs, &moodstr, &statusstr, &contactstr, &langstr, &devicestr, &tzstr, &geostr); |
1470 if (moodstr) { | |
1471 g_string_append_printf(s, "\n<b>%s:</b> %s", _("Mood"), moodstr); | |
1472 g_free(moodstr); | |
1473 } | |
1474 if (statusstr) { | |
1475 g_string_append_printf(s, "\n<b>%s:</b> %s", _("Status Text"), statusstr); | |
1476 g_free(statusstr); | |
8849 | 1477 } |
1478 | |
9488 | 1479 if (contactstr) { |
1480 g_string_append_printf(s, "\n<b>%s:</b> %s", _("Preferred Contact"), contactstr); | |
1481 g_free(contactstr); | |
1482 } | |
8849 | 1483 |
9488 | 1484 if (langstr) { |
1485 g_string_append_printf(s, "\n<b>%s:</b> %s", _("Preferred Language"), langstr); | |
1486 g_free(langstr); | |
8849 | 1487 } |
1488 | |
9488 | 1489 if (devicestr) { |
1490 g_string_append_printf(s, "\n<b>%s:</b> %s", _("Device"), devicestr); | |
1491 g_free(devicestr); | |
8849 | 1492 } |
1493 | |
9488 | 1494 if (tzstr) { |
1495 g_string_append_printf(s, "\n<b>%s:</b> %s", _("Timezone"), tzstr); | |
1496 g_free(tzstr); | |
1497 } | |
8849 | 1498 |
9488 | 1499 if (geostr) { |
1500 g_string_append_printf(s, "\n<b>%s:</b> %s", _("Geolocation"), geostr); | |
1501 g_free(geostr); | |
1502 } | |
8849 | 1503 |
1504 buf = g_string_free(s, FALSE); | |
1505 return buf; | |
1506 } | |
1507 | |
1508 static void | |
9038 | 1509 silcgaim_buddy_kill(GaimBlistNode *node, gpointer data) |
8849 | 1510 { |
9030 | 1511 GaimBuddy *b; |
1512 GaimConnection *gc; | |
1513 SilcGaim sg; | |
1514 | |
1515 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
1516 | |
1517 b = (GaimBuddy *) node; | |
1518 gc = gaim_account_get_connection(b->account); | |
1519 sg = gc->proto_data; | |
8849 | 1520 |
1521 /* Call KILL */ | |
9030 | 1522 silc_client_command_call(sg->client, sg->conn, NULL, "KILL", |
1523 b->name, "Killed by operator", NULL); | |
8849 | 1524 } |
1525 | |
9030 | 1526 GList *silcgaim_buddy_menu(GaimBuddy *buddy) |
8849 | 1527 { |
9030 | 1528 |
1529 GaimConnection *gc = gaim_account_get_connection(buddy->account); | |
8849 | 1530 SilcGaim sg = gc->proto_data; |
1531 SilcClientConnection conn = sg->conn; | |
1532 const char *pkfile = NULL; | |
1533 SilcClientEntry client_entry = NULL; | |
9030 | 1534 GaimBlistNodeAction *act; |
1535 GList *m = NULL; | |
8849 | 1536 |
9038 | 1537 pkfile = gaim_blist_node_get_string((GaimBlistNode *) buddy, "public-key"); |
9030 | 1538 client_entry = silc_client_get_client_by_id(sg->client, |
1539 sg->conn, | |
9038 | 1540 buddy->proto_data); |
8849 | 1541 |
1542 if (client_entry && client_entry->send_key) { | |
9030 | 1543 act = gaim_blist_node_action_new(_("Reset IM Key"), |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10589
diff
changeset
|
1544 silcgaim_buddy_resetkey, NULL, NULL); |
9030 | 1545 m = g_list_append(m, act); |
1546 | |
8849 | 1547 } else { |
9030 | 1548 act = gaim_blist_node_action_new(_("IM with Key Exchange"), |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10589
diff
changeset
|
1549 silcgaim_buddy_keyagr, NULL, NULL); |
9030 | 1550 m = g_list_append(m, act); |
8849 | 1551 |
9030 | 1552 act = gaim_blist_node_action_new(_("IM with Password"), |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10589
diff
changeset
|
1553 silcgaim_buddy_privkey_menu, |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10589
diff
changeset
|
1554 NULL, NULL); |
9030 | 1555 m = g_list_append(m, act); |
8849 | 1556 } |
1557 | |
1558 if (pkfile) { | |
9030 | 1559 act = gaim_blist_node_action_new(_("Show Public Key"), |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10589
diff
changeset
|
1560 silcgaim_buddy_showkey, NULL, NULL); |
9030 | 1561 m = g_list_append(m, act); |
1562 | |
8849 | 1563 } else { |
9030 | 1564 act = gaim_blist_node_action_new(_("Get Public Key..."), |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10589
diff
changeset
|
1565 silcgaim_buddy_getkey_menu, |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10589
diff
changeset
|
1566 NULL, NULL); |
9030 | 1567 m = g_list_append(m, act); |
8849 | 1568 } |
1569 | |
1570 if (conn && conn->local_entry->mode & SILC_UMODE_ROUTER_OPERATOR) { | |
9030 | 1571 act = gaim_blist_node_action_new(_("Kill User"), |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10589
diff
changeset
|
1572 silcgaim_buddy_kill, NULL, NULL); |
9030 | 1573 m = g_list_append(m, act); |
8849 | 1574 } |
1575 | |
1576 return m; | |
1577 } |