|
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 */
|
|
|
96 convo = gaim_find_conversation_with_account(client_entry->nickname,
|
|
|
97 sg->account);
|
|
|
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 {
|
|
9060
|
314 GaimBuddy *buddy;
|
|
|
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."));
|
|
|
735 gaim_blist_update_buddy_presence(r->b, GAIM_BUDDY_OFFLINE);
|
|
|
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);
|
|
|
774 gaim_blist_save();
|
|
|
775 gaim_blist_update_buddy_presence(r->b, GAIM_BUDDY_OFFLINE);
|
|
|
776 silc_free(fingerprint);
|
|
|
777 silc_free(r->offline_pk);
|
|
|
778 silc_free(r);
|
|
|
779 return;
|
|
|
780 }
|
|
|
781
|
|
|
782 /* Get the client entry. */
|
|
|
783 client_entry = silc_client_get_client_by_id(r->client, r->conn,
|
|
|
784 &r->client_id);
|
|
|
785 if (!client_entry) {
|
|
|
786 silc_free(r);
|
|
|
787 return;
|
|
|
788 }
|
|
|
789
|
|
|
790 memset(&vcard, 0, sizeof(vcard));
|
|
|
791 memset(&message, 0, sizeof(message));
|
|
|
792 memset(&extension, 0, sizeof(extension));
|
|
|
793 memset(&serverpk, 0, sizeof(serverpk));
|
|
|
794 memset(&usersign, 0, sizeof(usersign));
|
|
|
795 memset(&serversign, 0, sizeof(serversign));
|
|
|
796
|
|
|
797 /* Now that we have the public key and we trust it now we
|
|
|
798 save the attributes of the buddy and update its status. */
|
|
|
799
|
|
|
800 silc_dlist_start(client_entry->attrs);
|
|
|
801 while ((attr = silc_dlist_get(client_entry->attrs)) != SILC_LIST_END) {
|
|
|
802 attribute = silc_attribute_get_attribute(attr);
|
|
|
803
|
|
|
804 switch (attribute) {
|
|
|
805
|
|
|
806 case SILC_ATTRIBUTE_USER_INFO:
|
|
|
807 if (!silc_attribute_get_object(attr, (void *)&vcard,
|
|
|
808 sizeof(vcard)))
|
|
|
809 continue;
|
|
|
810 break;
|
|
|
811
|
|
|
812 case SILC_ATTRIBUTE_STATUS_MESSAGE:
|
|
|
813 if (!silc_attribute_get_object(attr, (void *)&message,
|
|
|
814 sizeof(message)))
|
|
|
815 continue;
|
|
|
816 break;
|
|
|
817
|
|
|
818 case SILC_ATTRIBUTE_EXTENSION:
|
|
|
819 if (!silc_attribute_get_object(attr, (void *)&extension,
|
|
|
820 sizeof(extension)))
|
|
|
821 continue;
|
|
|
822 break;
|
|
|
823
|
|
|
824 case SILC_ATTRIBUTE_SERVER_PUBLIC_KEY:
|
|
|
825 if (serverpk.type)
|
|
|
826 continue;
|
|
|
827 if (!silc_attribute_get_object(attr, (void *)&serverpk,
|
|
|
828 sizeof(serverpk)))
|
|
|
829 continue;
|
|
|
830 break;
|
|
|
831
|
|
|
832 case SILC_ATTRIBUTE_USER_DIGITAL_SIGNATURE:
|
|
|
833 if (usersign.data)
|
|
|
834 continue;
|
|
|
835 if (!silc_attribute_get_object(attr, (void *)&usersign,
|
|
|
836 sizeof(usersign)))
|
|
|
837 continue;
|
|
|
838 break;
|
|
|
839
|
|
|
840 case SILC_ATTRIBUTE_SERVER_DIGITAL_SIGNATURE:
|
|
|
841 if (serversign.data)
|
|
|
842 continue;
|
|
|
843 if (!silc_attribute_get_object(attr, (void *)&serversign,
|
|
|
844 sizeof(serversign)))
|
|
|
845 continue;
|
|
|
846 break;
|
|
|
847
|
|
|
848 default:
|
|
|
849 break;
|
|
|
850 }
|
|
|
851 }
|
|
|
852
|
|
|
853 /* Verify the attribute signatures */
|
|
|
854
|
|
|
855 if (usersign.data) {
|
|
|
856 SilcPKCS pkcs;
|
|
|
857 unsigned char *verifyd;
|
|
|
858 SilcUInt32 verify_len;
|
|
|
859
|
|
|
860 silc_pkcs_alloc("rsa", &pkcs);
|
|
|
861 verifyd = silc_attribute_get_verify_data(client_entry->attrs,
|
|
|
862 FALSE, &verify_len);
|
|
|
863 if (verifyd && silc_pkcs_public_key_set(pkcs, client_entry->public_key)){
|
|
|
864 if (!silc_pkcs_verify_with_hash(pkcs, client->sha1hash,
|
|
|
865 usersign.data,
|
|
|
866 usersign.data_len,
|
|
|
867 verifyd, verify_len))
|
|
|
868 usign_success = FALSE;
|
|
|
869 }
|
|
|
870 silc_free(verifyd);
|
|
|
871 }
|
|
|
872
|
|
|
873 if (serversign.data && !strcmp(serverpk.type, "silc-rsa")) {
|
|
|
874 SilcPublicKey public_key;
|
|
|
875 SilcPKCS pkcs;
|
|
|
876 unsigned char *verifyd;
|
|
|
877 SilcUInt32 verify_len;
|
|
|
878
|
|
|
879 if (silc_pkcs_public_key_decode(serverpk.data, serverpk.data_len,
|
|
|
880 &public_key)) {
|
|
|
881 silc_pkcs_alloc("rsa", &pkcs);
|
|
|
882 verifyd = silc_attribute_get_verify_data(client_entry->attrs,
|
|
|
883 TRUE, &verify_len);
|
|
|
884 if (verifyd && silc_pkcs_public_key_set(pkcs, public_key)) {
|
|
|
885 if (!silc_pkcs_verify_with_hash(pkcs, client->sha1hash,
|
|
|
886 serversign.data,
|
|
|
887 serversign.data_len,
|
|
|
888 verifyd, verify_len))
|
|
|
889 ssign_success = FALSE;
|
|
|
890 }
|
|
|
891 silc_pkcs_public_key_free(public_key);
|
|
|
892 silc_free(verifyd);
|
|
|
893 }
|
|
|
894 }
|
|
|
895
|
|
|
896 fingerprint = silc_fingerprint(client_entry->fingerprint,
|
|
|
897 client_entry->fingerprint_len);
|
|
|
898 for (i = 0; i < strlen(fingerprint); i++)
|
|
|
899 if (fingerprint[i] == ' ')
|
|
|
900 fingerprint[i] = '_';
|
|
|
901
|
|
|
902 if (usign_success || ssign_success) {
|
|
|
903 struct passwd *pw;
|
|
|
904 struct stat st;
|
|
|
905
|
|
|
906 memset(filename2, 0, sizeof(filename2));
|
|
|
907
|
|
|
908 /* Filename for dir */
|
|
|
909 tmp = fingerprint + strlen(fingerprint) - 9;
|
|
|
910 g_snprintf(filename, sizeof(filename) - 1,
|
|
|
911 "%s" G_DIR_SEPARATOR_S "friends" G_DIR_SEPARATOR_S "%s",
|
|
|
912 silcgaim_silcdir(), tmp);
|
|
|
913
|
|
|
914 pw = getpwuid(getuid());
|
|
|
915 if (!pw)
|
|
|
916 return;
|
|
|
917
|
|
|
918 /* Create dir if it doesn't exist */
|
|
|
919 if ((stat(filename, &st)) == -1) {
|
|
|
920 if (errno == ENOENT) {
|
|
|
921 if (pw->pw_uid == geteuid())
|
|
|
922 mkdir(filename, 0755);
|
|
|
923 }
|
|
|
924 }
|
|
|
925
|
|
|
926 /* Save VCard */
|
|
|
927 g_snprintf(filename2, sizeof(filename2) - 1,
|
|
|
928 "%s" G_DIR_SEPARATOR_S "vcard", filename);
|
|
|
929 if (vcard.full_name) {
|
|
|
930 tmp = silc_vcard_encode(&vcard, &len);
|
|
|
931 silc_file_writefile(filename2, tmp, len);
|
|
|
932 silc_free(tmp);
|
|
|
933 }
|
|
|
934
|
|
|
935 /* Save status message */
|
|
|
936 if (message.mime) {
|
|
|
937 memset(filename2, 0, sizeof(filename2));
|
|
|
938 g_snprintf(filename2, sizeof(filename2) - 1,
|
|
|
939 "%s" G_DIR_SEPARATOR_S "status_message.mime",
|
|
|
940 filename);
|
|
|
941 silc_file_writefile(filename2, message.mime,
|
|
|
942 message.mime_len);
|
|
|
943 }
|
|
|
944
|
|
|
945 /* Save extension data */
|
|
|
946 if (extension.mime) {
|
|
|
947 memset(filename2, 0, sizeof(filename2));
|
|
|
948 g_snprintf(filename2, sizeof(filename2) - 1,
|
|
|
949 "%s" G_DIR_SEPARATOR_S "extension.mime",
|
|
|
950 filename);
|
|
|
951 silc_file_writefile(filename2, extension.mime,
|
|
|
952 extension.mime_len);
|
|
|
953 }
|
|
|
954 }
|
|
|
955
|
|
|
956 /* Save the public key path to buddy properties, as it is used
|
|
|
957 to identify the buddy in the network (and not the nickname). */
|
|
|
958 memset(filename, 0, sizeof(filename));
|
|
|
959 g_snprintf(filename, sizeof(filename) - 1,
|
|
|
960 "%s" G_DIR_SEPARATOR_S "clientkeys" G_DIR_SEPARATOR_S "clientkey_%s.pub",
|
|
|
961 silcgaim_silcdir(), fingerprint);
|
|
|
962 gaim_blist_node_set_string((GaimBlistNode *)b, "public-key", filename);
|
|
|
963 gaim_blist_save();
|
|
|
964
|
|
|
965 /* Update online status on the buddy list */
|
|
|
966 gaim_blist_update_buddy_presence(b, GAIM_BUDDY_ONLINE);
|
|
|
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. */
|
|
|
1023 gaim_request_file(NULL, _("Open..."), NULL,
|
|
|
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
|
|
|
1151 /* If the buddy is offline/nonexistent, we will require user
|
|
|
1152 to associate a public key with the buddy or the buddy
|
|
|
1153 cannot be added. */
|
|
|
1154 if (!clients_count) {
|
|
|
1155 if (r->init) {
|
|
|
1156 silc_free(r);
|
|
|
1157 return;
|
|
|
1158 }
|
|
|
1159
|
|
|
1160 r->offline = TRUE;
|
|
|
1161 silcgaim_add_buddy_ask_pk(r);
|
|
|
1162 return;
|
|
|
1163 }
|
|
|
1164
|
|
|
1165 /* If more than one client was found with nickname, we need to verify
|
|
|
1166 from user which one is the correct. */
|
|
|
1167 if (clients_count > 1 && !r->pubkey_search) {
|
|
|
1168 if (r->init) {
|
|
|
1169 silc_free(r);
|
|
|
1170 return;
|
|
|
1171 }
|
|
|
1172
|
|
|
1173 silcgaim_add_buddy_select(r, clients, clients_count);
|
|
|
1174 return;
|
|
|
1175 }
|
|
|
1176
|
|
|
1177 /* If we searched using public keys and more than one entry was found
|
|
|
1178 the same person is logged on multiple times. */
|
|
|
1179 if (clients_count > 1 && r->pubkey_search && b->name) {
|
|
|
1180 if (r->init) {
|
|
|
1181 /* Find the entry that closest matches to the
|
|
|
1182 buddy nickname. */
|
|
|
1183 int i;
|
|
|
1184 for (i = 0; i < clients_count; i++) {
|
|
|
1185 if (!strncasecmp(b->name, clients[i]->nickname,
|
|
|
1186 strlen(b->name))) {
|
|
|
1187 clients[0] = clients[i];
|
|
|
1188 break;
|
|
|
1189 }
|
|
|
1190 }
|
|
|
1191 } else {
|
|
|
1192 /* Verify from user which one is correct */
|
|
|
1193 silcgaim_add_buddy_select(r, clients, clients_count);
|
|
|
1194 return;
|
|
|
1195 }
|
|
|
1196 }
|
|
|
1197
|
|
|
1198 /* The client was found. Now get its public key and verify
|
|
|
1199 that before adding the buddy. */
|
|
|
1200 memset(&userpk, 0, sizeof(userpk));
|
|
|
1201 b->proto_data = silc_memdup(clients[0]->id, sizeof(*clients[0]->id));
|
|
|
1202 r->client_id = *clients[0]->id;
|
|
|
1203
|
|
|
1204 filename = gaim_blist_node_get_string((GaimBlistNode *)b, "public-key");
|
|
|
1205
|
|
|
1206 /* Get the public key from attributes, if not present then
|
|
|
1207 resolve it with GETKEY unless we have it cached already. */
|
|
|
1208 if (clients[0]->attrs && !clients[0]->public_key) {
|
|
|
1209 pub = silcgaim_get_attr(clients[0]->attrs,
|
|
|
1210 SILC_ATTRIBUTE_USER_PUBLIC_KEY);
|
|
|
1211 if (!pub || !silc_attribute_get_object(pub, (void *)&userpk,
|
|
|
1212 sizeof(userpk))) {
|
|
|
1213 /* Get public key with GETKEY */
|
|
|
1214 silc_client_command_call(client, conn, NULL,
|
|
|
1215 "GETKEY", clients[0]->nickname, NULL);
|
|
|
1216 silc_client_command_pending(conn, SILC_COMMAND_GETKEY,
|
|
|
1217 conn->cmd_ident,
|
|
|
1218 (SilcCommandCb)silcgaim_add_buddy_getkey_cb,
|
|
|
1219 r);
|
|
|
1220 return;
|
|
|
1221 }
|
|
|
1222 if (!silc_pkcs_public_key_decode(userpk.data, userpk.data_len,
|
|
|
1223 &clients[0]->public_key))
|
|
|
1224 return;
|
|
|
1225 silc_free(userpk.data);
|
|
|
1226 } else if (filename && !clients[0]->public_key) {
|
|
|
1227 if (!silc_pkcs_load_public_key(filename, &clients[0]->public_key,
|
|
|
1228 SILC_PKCS_FILE_PEM) &&
|
|
|
1229 !silc_pkcs_load_public_key(filename, &clients[0]->public_key,
|
|
|
1230 SILC_PKCS_FILE_BIN)) {
|
|
|
1231 /* Get public key with GETKEY */
|
|
|
1232 silc_client_command_call(client, conn, NULL,
|
|
|
1233 "GETKEY", clients[0]->nickname, NULL);
|
|
|
1234 silc_client_command_pending(conn, SILC_COMMAND_GETKEY,
|
|
|
1235 conn->cmd_ident,
|
|
|
1236 (SilcCommandCb)silcgaim_add_buddy_getkey_cb,
|
|
|
1237 r);
|
|
|
1238 return;
|
|
|
1239 }
|
|
|
1240 } else if (!clients[0]->public_key) {
|
|
|
1241 /* Get public key with GETKEY */
|
|
|
1242 silc_client_command_call(client, conn, NULL,
|
|
|
1243 "GETKEY", clients[0]->nickname, NULL);
|
|
|
1244 silc_client_command_pending(conn, SILC_COMMAND_GETKEY,
|
|
|
1245 conn->cmd_ident,
|
|
|
1246 (SilcCommandCb)silcgaim_add_buddy_getkey_cb,
|
|
|
1247 r);
|
|
|
1248 return;
|
|
|
1249 }
|
|
|
1250
|
|
|
1251 /* We have the public key, verify it. */
|
|
|
1252 pk = silc_pkcs_public_key_encode(clients[0]->public_key, &pk_len);
|
|
|
1253 silcgaim_verify_public_key(client, conn, clients[0]->nickname,
|
|
|
1254 SILC_SOCKET_TYPE_CLIENT,
|
|
|
1255 pk, pk_len, SILC_SKE_PK_TYPE_SILC,
|
|
|
1256 silcgaim_add_buddy_save, r);
|
|
|
1257 silc_free(pk);
|
|
|
1258 }
|
|
|
1259
|
|
|
1260 static void
|
|
|
1261 silcgaim_add_buddy_i(GaimConnection *gc, GaimBuddy *b, gboolean init)
|
|
|
1262 {
|
|
|
1263 SilcGaim sg = gc->proto_data;
|
|
|
1264 SilcClient client = sg->client;
|
|
|
1265 SilcClientConnection conn = sg->conn;
|
|
|
1266 SilcGaimBuddyRes r;
|
|
|
1267 SilcBuffer attrs;
|
|
|
1268 const char *filename, *name = b->name;
|
|
|
1269
|
|
|
1270 r = silc_calloc(1, sizeof(*r));
|
|
|
1271 if (!r)
|
|
|
1272 return;
|
|
|
1273 r->client = client;
|
|
|
1274 r->conn = conn;
|
|
|
1275 r->b = b;
|
|
|
1276 r->init = init;
|
|
|
1277
|
|
|
1278 /* See if we have this buddy's public key. If we do use that
|
|
|
1279 to search the details. */
|
|
|
1280 filename = gaim_blist_node_get_string((GaimBlistNode *)b, "public-key");
|
|
|
1281 if (filename) {
|
|
|
1282 SilcPublicKey public_key;
|
|
|
1283 SilcAttributeObjPk userpk;
|
|
|
1284
|
|
|
1285 if (!silc_pkcs_load_public_key(filename, &public_key,
|
|
|
1286 SILC_PKCS_FILE_PEM) &&
|
|
|
1287 !silc_pkcs_load_public_key(filename, &public_key,
|
|
|
1288 SILC_PKCS_FILE_BIN))
|
|
|
1289 return;
|
|
|
1290
|
|
|
1291 /* Get all attributes, and use the public key to search user */
|
|
|
1292 name = NULL;
|
|
|
1293 attrs = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
|
|
|
1294 SILC_ATTRIBUTE_SERVICE,
|
|
|
1295 SILC_ATTRIBUTE_STATUS_MOOD,
|
|
|
1296 SILC_ATTRIBUTE_STATUS_FREETEXT,
|
|
|
1297 SILC_ATTRIBUTE_STATUS_MESSAGE,
|
|
|
1298 SILC_ATTRIBUTE_PREFERRED_LANGUAGE,
|
|
|
1299 SILC_ATTRIBUTE_PREFERRED_CONTACT,
|
|
|
1300 SILC_ATTRIBUTE_TIMEZONE,
|
|
|
1301 SILC_ATTRIBUTE_GEOLOCATION,
|
|
|
1302 SILC_ATTRIBUTE_DEVICE_INFO, 0);
|
|
|
1303 userpk.type = "silc-rsa";
|
|
|
1304 userpk.data = silc_pkcs_public_key_encode(public_key, &userpk.data_len);
|
|
|
1305 attrs = silc_attribute_payload_encode(attrs,
|
|
|
1306 SILC_ATTRIBUTE_USER_PUBLIC_KEY,
|
|
|
1307 SILC_ATTRIBUTE_FLAG_VALID,
|
|
|
1308 &userpk, sizeof(userpk));
|
|
|
1309 silc_free(userpk.data);
|
|
|
1310 silc_pkcs_public_key_free(public_key);
|
|
|
1311 r->pubkey_search = TRUE;
|
|
|
1312 } else {
|
|
|
1313 /* Get all attributes */
|
|
|
1314 attrs = silc_client_attributes_request(0);
|
|
|
1315 }
|
|
|
1316
|
|
|
1317 /* Resolve */
|
|
|
1318 silc_client_get_clients_whois(client, conn, name, NULL, attrs,
|
|
|
1319 silcgaim_add_buddy_resolved, r);
|
|
|
1320 silc_buffer_free(attrs);
|
|
|
1321 }
|
|
|
1322
|
|
|
1323 void silcgaim_add_buddy(GaimConnection *gc, const char *name, GaimGroup *grp)
|
|
|
1324 {
|
|
|
1325 GaimBuddy *b;
|
|
|
1326
|
|
|
1327 b = gaim_find_buddy_in_group(gc->account, name, grp);
|
|
|
1328 if (!b)
|
|
|
1329 return;
|
|
|
1330
|
|
|
1331 silcgaim_add_buddy_i(gc, b, FALSE);
|
|
|
1332 }
|
|
|
1333
|
|
|
1334 void silcgaim_add_buddies(GaimConnection *gc, GList *buddies)
|
|
|
1335 {
|
|
|
1336 while (buddies) {
|
|
|
1337 GaimBuddy *b;
|
|
|
1338 b = gaim_find_buddy(gc->account, buddies->data);
|
|
|
1339 if (!b)
|
|
|
1340 continue;
|
|
|
1341 silcgaim_add_buddy_i(gc, b, TRUE);
|
|
|
1342 buddies = buddies->next;
|
|
|
1343 }
|
|
|
1344 }
|
|
|
1345
|
|
|
1346 void silcgaim_remove_buddy(GaimConnection *gc, const char *name,
|
|
|
1347 const char *group)
|
|
|
1348 {
|
|
|
1349 GaimBuddy *b;
|
|
|
1350 GaimGroup *g;
|
|
|
1351
|
|
|
1352 g = gaim_find_group(group);
|
|
|
1353 b = gaim_find_buddy_in_group(gc->account, name, g);
|
|
|
1354 if (!b)
|
|
|
1355 return;
|
|
|
1356
|
|
|
1357 silc_free(b->proto_data);
|
|
|
1358 }
|
|
|
1359
|
|
|
1360 void silcgaim_idle_set(GaimConnection *gc, int idle)
|
|
|
1361
|
|
|
1362 {
|
|
|
1363 SilcGaim sg = gc->proto_data;
|
|
|
1364 SilcClient client = sg->client;
|
|
|
1365 SilcClientConnection conn = sg->conn;
|
|
|
1366 SilcAttributeObjService service;
|
|
|
1367 const char *server;
|
|
|
1368 int port;
|
|
|
1369
|
|
|
1370 server = gaim_account_get_string(sg->account, "server",
|
|
|
1371 "silc.silcnet.org");
|
|
|
1372 port = gaim_account_get_int(sg->account, "port", 706),
|
|
|
1373
|
|
|
1374 memset(&service, 0, sizeof(service));
|
|
|
1375 silc_client_attribute_del(client, conn,
|
|
|
1376 SILC_ATTRIBUTE_SERVICE, NULL);
|
|
|
1377 service.port = port;
|
|
|
1378 g_snprintf(service.address, sizeof(service.address), "%s", server);
|
|
|
1379 service.idle = idle;
|
|
|
1380 silc_client_attribute_add(client, conn, SILC_ATTRIBUTE_SERVICE,
|
|
|
1381 &service, sizeof(service));
|
|
|
1382 }
|
|
|
1383
|
|
|
1384 char *silcgaim_status_text(GaimBuddy *b)
|
|
|
1385 {
|
|
|
1386 SilcGaim sg = b->account->gc->proto_data;
|
|
|
1387 SilcClient client = sg->client;
|
|
|
1388 SilcClientConnection conn = sg->conn;
|
|
|
1389 SilcClientID *client_id = b->proto_data;
|
|
|
1390 SilcClientEntry client_entry;
|
|
|
1391 SilcAttributePayload attr;
|
|
|
1392 SilcAttributeMood mood = 0;
|
|
|
1393
|
|
|
1394 /* Get the client entry. */
|
|
|
1395 client_entry = silc_client_get_client_by_id(client, conn, client_id);
|
|
|
1396 if (!client_entry)
|
|
|
1397 return NULL;
|
|
|
1398
|
|
|
1399 /* If user is online, we show the mood status, if available.
|
|
|
1400 If user is offline or away that status is indicated. */
|
|
|
1401
|
|
|
1402 if (client_entry->mode & SILC_UMODE_DETACHED)
|
|
|
1403 return g_strdup(_("Detached"));
|
|
|
1404 if (client_entry->mode & SILC_UMODE_GONE)
|
|
|
1405 return g_strdup(_("Away"));
|
|
|
1406 if (client_entry->mode & SILC_UMODE_INDISPOSED)
|
|
|
1407 return g_strdup(_("Indisposed"));
|
|
|
1408 if (client_entry->mode & SILC_UMODE_BUSY)
|
|
|
1409 return g_strdup(_("Busy"));
|
|
|
1410 if (client_entry->mode & SILC_UMODE_PAGE)
|
|
|
1411 return g_strdup(_("Wake Me Up"));
|
|
|
1412 if (client_entry->mode & SILC_UMODE_HYPER)
|
|
|
1413 return g_strdup(_("Hyper Active"));
|
|
|
1414 if (client_entry->mode & SILC_UMODE_ROBOT)
|
|
|
1415 return g_strdup(_("Robot"));
|
|
|
1416
|
|
|
1417 attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_STATUS_MOOD);
|
|
|
1418 if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) {
|
|
|
1419 /* The mood is a bit mask, so we could show multiple moods,
|
|
|
1420 but let's show only one for now. */
|
|
|
1421 if (mood & SILC_ATTRIBUTE_MOOD_HAPPY)
|
|
|
1422 return g_strdup(_("Happy"));
|
|
|
1423 if (mood & SILC_ATTRIBUTE_MOOD_SAD)
|
|
|
1424 return g_strdup(_("Sad"));
|
|
|
1425 if (mood & SILC_ATTRIBUTE_MOOD_ANGRY)
|
|
|
1426 return g_strdup(_("Angry"));
|
|
|
1427 if (mood & SILC_ATTRIBUTE_MOOD_JEALOUS)
|
|
|
1428 return g_strdup(_("Jealous"));
|
|
|
1429 if (mood & SILC_ATTRIBUTE_MOOD_ASHAMED)
|
|
|
1430 return g_strdup(_("Ashamed"));
|
|
|
1431 if (mood & SILC_ATTRIBUTE_MOOD_INVINCIBLE)
|
|
|
1432 return g_strdup(_("Invincible"));
|
|
|
1433 if (mood & SILC_ATTRIBUTE_MOOD_INLOVE)
|
|
|
1434 return g_strdup(_("In Love"));
|
|
|
1435 if (mood & SILC_ATTRIBUTE_MOOD_SLEEPY)
|
|
|
1436 return g_strdup(_("Sleepy"));
|
|
|
1437 if (mood & SILC_ATTRIBUTE_MOOD_BORED)
|
|
|
1438 return g_strdup(_("Bored"));
|
|
|
1439 if (mood & SILC_ATTRIBUTE_MOOD_EXCITED)
|
|
|
1440 return g_strdup(_("Excited"));
|
|
|
1441 if (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS)
|
|
|
1442 return g_strdup(_("Anxious"));
|
|
|
1443 }
|
|
|
1444
|
|
|
1445 return NULL;
|
|
|
1446 }
|
|
|
1447
|
|
|
1448 char *silcgaim_tooltip_text(GaimBuddy *b)
|
|
|
1449 {
|
|
|
1450 SilcGaim sg = b->account->gc->proto_data;
|
|
|
1451 SilcClient client = sg->client;
|
|
|
1452 SilcClientConnection conn = sg->conn;
|
|
|
1453 SilcClientID *client_id = b->proto_data;
|
|
|
1454 SilcClientEntry client_entry;
|
|
|
1455 SilcAttributePayload attr;
|
|
|
1456 SilcAttributeMood mood = 0;
|
|
|
1457 SilcAttributeContact contact;
|
|
|
1458 SilcAttributeObjDevice device;
|
|
|
1459 SilcAttributeObjGeo geo;
|
|
|
1460 GString *s;
|
|
|
1461 char *buf;
|
|
|
1462 char tmp[256];
|
|
|
1463
|
|
|
1464 s = g_string_new("");
|
|
|
1465
|
|
|
1466 /* Get the client entry. */
|
|
|
1467 client_entry = silc_client_get_client_by_id(client, conn, client_id);
|
|
|
1468 if (!client_entry)
|
|
|
1469 return NULL;
|
|
|
1470
|
|
|
1471 if (client_entry->nickname)
|
|
9039
|
1472 g_string_append_printf(s, "<b>%s:</b> %s\n", _("Nickname"),
|
|
8849
|
1473 client_entry->nickname);
|
|
|
1474 if (client_entry->username && client_entry->hostname)
|
|
9039
|
1475 g_string_append_printf(s, "<b>%s:</b> %s@%s\n", _("Username"),
|
|
8849
|
1476 client_entry->username, client_entry->hostname);
|
|
|
1477 if (client_entry->mode) {
|
|
9039
|
1478 g_string_append_printf(s, "<b>%s:</b> ", _("Modes"));
|
|
8849
|
1479 memset(tmp, 0, sizeof(tmp));
|
|
|
1480 silcgaim_get_umode_string(client_entry->mode,
|
|
|
1481 tmp, sizeof(tmp) - strlen(tmp));
|
|
|
1482 g_string_append_printf(s, "%s\n", tmp);
|
|
|
1483 }
|
|
|
1484
|
|
|
1485 attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_STATUS_MOOD);
|
|
|
1486 if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) {
|
|
|
1487 if (mood)
|
|
9039
|
1488 g_string_append_printf(s, "<b>%s:</b> ", _("Mood"));
|
|
8849
|
1489 if (mood & SILC_ATTRIBUTE_MOOD_HAPPY)
|
|
9039
|
1490 g_string_append_printf(s, "[%s] ", _("Happy"));
|
|
8849
|
1491 if (mood & SILC_ATTRIBUTE_MOOD_SAD)
|
|
9039
|
1492 g_string_append_printf(s, "[%s] ", _("Sad"));
|
|
8849
|
1493 if (mood & SILC_ATTRIBUTE_MOOD_ANGRY)
|
|
9039
|
1494 g_string_append_printf(s, "[%s] ", _("Angry"));
|
|
8849
|
1495 if (mood & SILC_ATTRIBUTE_MOOD_JEALOUS)
|
|
9039
|
1496 g_string_append_printf(s, "[%s] ", _("Jealous"));
|
|
8849
|
1497 if (mood & SILC_ATTRIBUTE_MOOD_ASHAMED)
|
|
9039
|
1498 g_string_append_printf(s, "[%s] ", _("Ashamed"));
|
|
8849
|
1499 if (mood & SILC_ATTRIBUTE_MOOD_INVINCIBLE)
|
|
9039
|
1500 g_string_append_printf(s, "[%s] ", _("Invincible"));
|
|
8849
|
1501 if (mood & SILC_ATTRIBUTE_MOOD_INLOVE)
|
|
9039
|
1502 g_string_append_printf(s, "[%s] ", _("In Love"));
|
|
8849
|
1503 if (mood & SILC_ATTRIBUTE_MOOD_SLEEPY)
|
|
9039
|
1504 g_string_append_printf(s, "[%s] ", _("Sleepy"));
|
|
8849
|
1505 if (mood & SILC_ATTRIBUTE_MOOD_BORED)
|
|
9039
|
1506 g_string_append_printf(s, "[%s] ", _("Bored"));
|
|
8849
|
1507 if (mood & SILC_ATTRIBUTE_MOOD_EXCITED)
|
|
9039
|
1508 g_string_append_printf(s, "[%s] ", _("Excited"));
|
|
8849
|
1509 if (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS)
|
|
9039
|
1510 g_string_append_printf(s, "[%s] ", _("Anxious"));
|
|
8849
|
1511 if (mood)
|
|
|
1512 g_string_append_printf(s, "\n");
|
|
|
1513 }
|
|
|
1514
|
|
|
1515 attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_STATUS_FREETEXT);
|
|
|
1516 memset(tmp, 0, sizeof(tmp));
|
|
|
1517 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp)))
|
|
9039
|
1518 g_string_append_printf(s, "<b>%s:</b> %s\n", _("Status Text"), tmp);
|
|
8849
|
1519
|
|
|
1520 attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_PREFERRED_CONTACT);
|
|
|
1521 if (attr && silc_attribute_get_object(attr, &contact, sizeof(contact))) {
|
|
|
1522 if (contact)
|
|
9039
|
1523 g_string_append_printf(s, "<b>%s:</b> ", _("Preferred Contact"));
|
|
8849
|
1524 if (contact & SILC_ATTRIBUTE_CONTACT_CHAT)
|
|
9039
|
1525 g_string_append_printf(s, "[%s] ", _("Chat"));
|
|
8849
|
1526 if (contact & SILC_ATTRIBUTE_CONTACT_EMAIL)
|
|
9039
|
1527 g_string_append_printf(s, "[%s] ", _("Email"));
|
|
8849
|
1528 if (contact & SILC_ATTRIBUTE_CONTACT_CALL)
|
|
9039
|
1529 g_string_append_printf(s, "[%s] ", _("Phone"));
|
|
8849
|
1530 if (contact & SILC_ATTRIBUTE_CONTACT_PAGE)
|
|
9039
|
1531 g_string_append_printf(s, "[%s] ", _("Paging"));
|
|
8849
|
1532 if (contact & SILC_ATTRIBUTE_CONTACT_SMS)
|
|
9039
|
1533 g_string_append_printf(s, "[%s] ", _("SMS"));
|
|
8849
|
1534 if (contact & SILC_ATTRIBUTE_CONTACT_MMS)
|
|
9039
|
1535 g_string_append_printf(s, "[%s] ", _("MMS"));
|
|
8849
|
1536 if (contact & SILC_ATTRIBUTE_CONTACT_VIDEO)
|
|
9039
|
1537 g_string_append_printf(s, "[%s] ", _("Video Conferencing"));
|
|
8849
|
1538 g_string_append_printf(s, "\n");
|
|
|
1539 }
|
|
|
1540
|
|
|
1541 attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_PREFERRED_LANGUAGE);
|
|
|
1542 memset(tmp, 0, sizeof(tmp));
|
|
|
1543 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp)))
|
|
9039
|
1544 g_string_append_printf(s, "<b>%s:</b> %s\n", _("Preferred Language"), tmp);
|
|
8849
|
1545
|
|
|
1546 attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_DEVICE_INFO);
|
|
|
1547 memset(&device, 0, sizeof(device));
|
|
|
1548 if (attr && silc_attribute_get_object(attr, &device, sizeof(device))) {
|
|
9039
|
1549 g_string_append_printf(s, "<b>%s:</b> ", _("Device"));
|
|
8849
|
1550 if (device.type == SILC_ATTRIBUTE_DEVICE_COMPUTER)
|
|
9039
|
1551 g_string_append_printf(s, "%s: ", _("Computer"));
|
|
8849
|
1552 if (device.type == SILC_ATTRIBUTE_DEVICE_MOBILE_PHONE)
|
|
9039
|
1553 g_string_append_printf(s, "%s: ", _("Mobile Phone"));
|
|
8849
|
1554 if (device.type == SILC_ATTRIBUTE_DEVICE_PDA)
|
|
9039
|
1555 g_string_append_printf(s, "%s: ", _("PDA"));
|
|
8849
|
1556 if (device.type == SILC_ATTRIBUTE_DEVICE_TERMINAL)
|
|
9039
|
1557 g_string_append_printf(s, "%s: ", _("Terminal"));
|
|
8849
|
1558 g_string_append_printf(s, "%s %s %s %s\n",
|
|
|
1559 device.manufacturer ? device.manufacturer : "",
|
|
|
1560 device.version ? device.version : "",
|
|
|
1561 device.model ? device.model : "",
|
|
|
1562 device.language ? device.language : "");
|
|
|
1563 }
|
|
|
1564
|
|
|
1565 attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_TIMEZONE);
|
|
|
1566 memset(tmp, 0, sizeof(tmp));
|
|
|
1567 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp)))
|
|
9039
|
1568 g_string_append_printf(s, "<b>%s:</b> %s\n", _("Timezone"), tmp);
|
|
8849
|
1569
|
|
|
1570 attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_GEOLOCATION);
|
|
|
1571 memset(&geo, 0, sizeof(geo));
|
|
|
1572 if (attr && silc_attribute_get_object(attr, &geo, sizeof(geo)))
|
|
9039
|
1573 g_string_append_printf(s, "<b>%s:</b> %s %s %s (%s)\n",
|
|
|
1574 _("Geolocation"),
|
|
8849
|
1575 geo.longitude ? geo.longitude : "",
|
|
|
1576 geo.latitude ? geo.latitude : "",
|
|
|
1577 geo.altitude ? geo.altitude : "",
|
|
|
1578 geo.accuracy ? geo.accuracy : "");
|
|
|
1579
|
|
|
1580 buf = g_string_free(s, FALSE);
|
|
|
1581 return buf;
|
|
|
1582 }
|
|
|
1583
|
|
|
1584 static void
|
|
9038
|
1585 silcgaim_buddy_kill(GaimBlistNode *node, gpointer data)
|
|
8849
|
1586 {
|
|
9030
|
1587 GaimBuddy *b;
|
|
|
1588 GaimConnection *gc;
|
|
|
1589 SilcGaim sg;
|
|
|
1590
|
|
|
1591 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
|
1592
|
|
|
1593 b = (GaimBuddy *) node;
|
|
|
1594 gc = gaim_account_get_connection(b->account);
|
|
|
1595 sg = gc->proto_data;
|
|
8849
|
1596
|
|
|
1597 /* Call KILL */
|
|
9030
|
1598 silc_client_command_call(sg->client, sg->conn, NULL, "KILL",
|
|
|
1599 b->name, "Killed by operator", NULL);
|
|
8849
|
1600 }
|
|
|
1601
|
|
|
1602 static void
|
|
9038
|
1603 silcgaim_buddy_send_file(GaimBlistNode *node, gpointer data)
|
|
8849
|
1604 {
|
|
9030
|
1605 GaimBuddy *b;
|
|
|
1606 GaimConnection *gc;
|
|
|
1607
|
|
|
1608 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
|
1609
|
|
|
1610 b = (GaimBuddy *) node;
|
|
|
1611 gc = gaim_account_get_connection(b->account);
|
|
|
1612
|
|
|
1613 silcgaim_ftp_send_file(gc, b->name);
|
|
8849
|
1614 }
|
|
|
1615
|
|
9030
|
1616 GList *silcgaim_buddy_menu(GaimBuddy *buddy)
|
|
8849
|
1617 {
|
|
9030
|
1618
|
|
|
1619 GaimConnection *gc = gaim_account_get_connection(buddy->account);
|
|
8849
|
1620 SilcGaim sg = gc->proto_data;
|
|
|
1621 SilcClientConnection conn = sg->conn;
|
|
|
1622 const char *pkfile = NULL;
|
|
|
1623 SilcClientEntry client_entry = NULL;
|
|
9030
|
1624 GaimBlistNodeAction *act;
|
|
|
1625 GList *m = NULL;
|
|
8849
|
1626
|
|
9038
|
1627 pkfile = gaim_blist_node_get_string((GaimBlistNode *) buddy, "public-key");
|
|
9030
|
1628 client_entry = silc_client_get_client_by_id(sg->client,
|
|
|
1629 sg->conn,
|
|
9038
|
1630 buddy->proto_data);
|
|
8849
|
1631
|
|
|
1632 if (client_entry && client_entry->send_key) {
|
|
9030
|
1633 act = gaim_blist_node_action_new(_("Reset IM Key"),
|
|
9038
|
1634 silcgaim_buddy_resetkey, NULL);
|
|
9030
|
1635 m = g_list_append(m, act);
|
|
|
1636
|
|
8849
|
1637 } else {
|
|
9030
|
1638 act = gaim_blist_node_action_new(_("IM with Key Exchange"),
|
|
9038
|
1639 silcgaim_buddy_keyagr, NULL);
|
|
9030
|
1640 m = g_list_append(m, act);
|
|
8849
|
1641
|
|
9030
|
1642 act = gaim_blist_node_action_new(_("IM with Password"),
|
|
9038
|
1643 silcgaim_buddy_privkey_menu, NULL);
|
|
9030
|
1644 m = g_list_append(m, act);
|
|
8849
|
1645 }
|
|
|
1646
|
|
|
1647 if (pkfile) {
|
|
9030
|
1648 act = gaim_blist_node_action_new(_("Show Public Key"),
|
|
9038
|
1649 silcgaim_buddy_showkey, NULL);
|
|
9030
|
1650 m = g_list_append(m, act);
|
|
|
1651
|
|
8849
|
1652 } else {
|
|
9030
|
1653 act = gaim_blist_node_action_new(_("Get Public Key..."),
|
|
9038
|
1654 silcgaim_buddy_getkey_menu, NULL);
|
|
9030
|
1655 m = g_list_append(m, act);
|
|
8849
|
1656 }
|
|
|
1657
|
|
9030
|
1658 act = gaim_blist_node_action_new(_("Send File..."),
|
|
9038
|
1659 silcgaim_buddy_send_file, NULL);
|
|
9030
|
1660 m = g_list_append(m, act);
|
|
8849
|
1661
|
|
|
1662 if (conn && conn->local_entry->mode & SILC_UMODE_ROUTER_OPERATOR) {
|
|
9030
|
1663 act = gaim_blist_node_action_new(_("Kill User"),
|
|
9038
|
1664 silcgaim_buddy_kill, NULL);
|
|
9030
|
1665 m = g_list_append(m, act);
|
|
8849
|
1666 }
|
|
|
1667
|
|
|
1668 return m;
|
|
|
1669 }
|