Tue, 15 Jun 2004 04:37:12 +0000
[gaim-migrate @ 10091]
Earth!
Fire!
Wind! (the hot chick)
Water!
Heart!
| 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 | { |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
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
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
324 | silcgaim_buddy_resetkey(GaimBlistNode *node, gpointer data) |
| 8849 | 325 | { |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
326 | GaimBuddy *b; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
327 | GaimConnection *gc; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
328 | SilcGaim sg; |
| 8849 | 329 | char *nickname; |
| 330 | SilcClientEntry *clients; | |
| 331 | SilcUInt32 clients_count; | |
| 332 | ||
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
333 | g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
334 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
335 | b = (GaimBuddy *) node; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
336 | gc = gaim_account_get_connection(b->account); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
337 | sg = gc->proto_data; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
338 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
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
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
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
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
611 | silcgaim_buddy_showkey(GaimBlistNode *node, gpointer data) |
| 8849 | 612 | { |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
613 | GaimBuddy *b; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
614 | GaimConnection *gc; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
615 | SilcGaim sg; |
| 8849 | 616 | SilcPublicKey public_key; |
| 617 | const char *pkfile; | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
618 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
619 | g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
| 8849 | 620 | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
621 | b = (GaimBuddy *) node; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
622 | gc = gaim_account_get_connection(b->account); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
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
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
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_update_buddy_presence(r->b, GAIM_BUDDY_OFFLINE); | |
| 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
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
799 | if (client_entry->attrs) { |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
800 | silc_dlist_start(client_entry->attrs); |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
801 | while ((attr = silc_dlist_get(client_entry->attrs)) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
802 | != SILC_LIST_END) { |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
803 | attribute = silc_attribute_get_attribute(attr); |
| 8849 | 804 | |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
805 | switch (attribute) { |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
806 | case SILC_ATTRIBUTE_USER_INFO: |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
807 | if (!silc_attribute_get_object(attr, (void *)&vcard, |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
808 | sizeof(vcard))) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
809 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
810 | break; |
| 8849 | 811 | |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
812 | case SILC_ATTRIBUTE_STATUS_MESSAGE: |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
813 | if (!silc_attribute_get_object(attr, (void *)&message, |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
814 | sizeof(message))) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
815 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
816 | break; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
817 | |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
818 | case SILC_ATTRIBUTE_EXTENSION: |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
819 | if (!silc_attribute_get_object(attr, (void *)&extension, |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
820 | sizeof(extension))) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
821 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
822 | break; |
| 8849 | 823 | |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
824 | case SILC_ATTRIBUTE_SERVER_PUBLIC_KEY: |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
825 | if (serverpk.type) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
826 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
827 | if (!silc_attribute_get_object(attr, (void *)&serverpk, |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
828 | sizeof(serverpk))) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
829 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
830 | break; |
| 8849 | 831 | |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
832 | case SILC_ATTRIBUTE_USER_DIGITAL_SIGNATURE: |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
833 | if (usersign.data) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
834 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
835 | if (!silc_attribute_get_object(attr, (void *)&usersign, |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
836 | sizeof(usersign))) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
837 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
838 | break; |
| 8849 | 839 | |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
840 | case SILC_ATTRIBUTE_SERVER_DIGITAL_SIGNATURE: |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
841 | if (serversign.data) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
842 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
843 | if (!silc_attribute_get_object(attr, (void *)&serversign, |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
844 | sizeof(serversign))) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
845 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
846 | break; |
| 8849 | 847 | |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
848 | default: |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
849 | break; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
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 */ | |
| 920 | if ((stat(filename, &st)) == -1) { | |
| 921 | if (errno == ENOENT) { | |
| 922 | if (pw->pw_uid == geteuid()) | |
| 923 | mkdir(filename, 0755); | |
| 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 | gaim_blist_save(); | |
| 965 | ||
| 966 | /* Update online status on the buddy list */ | |
| 967 | gaim_blist_update_buddy_presence(b, GAIM_BUDDY_ONLINE); | |
| 968 | ||
| 969 | /* Finally, start watching this user so we receive its status | |
| 970 | changes from the server */ | |
| 971 | g_snprintf(filename2, sizeof(filename2) - 1, "+%s", filename); | |
| 972 | silc_client_command_call(r->client, r->conn, NULL, "WATCH", "-pubkey", | |
| 973 | filename2, NULL); | |
| 974 | ||
| 975 | silc_free(fingerprint); | |
| 976 | silc_free(r); | |
| 977 | } | |
| 978 | ||
| 979 | static void | |
| 980 | silcgaim_add_buddy_ask_import(void *user_data, const char *name) | |
| 981 | { | |
| 982 | SilcGaimBuddyRes r = (SilcGaimBuddyRes)user_data; | |
| 983 | SilcPublicKey public_key; | |
| 984 | ||
| 985 | /* Load the public key */ | |
| 986 | if (!silc_pkcs_load_public_key(name, &public_key, SILC_PKCS_FILE_PEM) && | |
| 987 | !silc_pkcs_load_public_key(name, &public_key, SILC_PKCS_FILE_BIN)) { | |
| 988 | silcgaim_add_buddy_ask_pk_cb(r, 0); | |
| 989 | gaim_notify_error(r->client->application, | |
| 990 | _("Add Buddy"), _("Could not load public key"), NULL); | |
| 991 | return; | |
| 992 | } | |
| 993 | ||
| 994 | /* Now verify the public key */ | |
| 995 | r->offline_pk = silc_pkcs_public_key_encode(public_key, &r->offline_pk_len); | |
| 996 | silcgaim_verify_public_key(r->client, r->conn, r->b->name, | |
| 997 | SILC_SOCKET_TYPE_CLIENT, | |
| 998 | r->offline_pk, r->offline_pk_len, | |
| 999 | SILC_SKE_PK_TYPE_SILC, | |
| 1000 | silcgaim_add_buddy_save, r); | |
| 1001 | } | |
| 1002 | ||
| 1003 | static void | |
| 1004 | silcgaim_add_buddy_ask_pk_cancel(void *user_data, const char *name) | |
| 1005 | { | |
| 1006 | SilcGaimBuddyRes r = (SilcGaimBuddyRes)user_data; | |
| 1007 | ||
| 1008 | /* The user did not import public key. The buddy is unusable. */ | |
| 1009 | silcgaim_add_buddy_pk_no(r); | |
| 1010 | silc_free(r); | |
| 1011 | } | |
| 1012 | ||
| 1013 | static void | |
| 1014 | silcgaim_add_buddy_ask_pk_cb(SilcGaimBuddyRes r, gint id) | |
| 1015 | { | |
| 1016 | if (id != 0) { | |
| 1017 | /* The user did not import public key. The buddy is unusable. */ | |
| 1018 | silcgaim_add_buddy_pk_no(r); | |
| 1019 | silc_free(r); | |
| 1020 | return; | |
| 1021 | } | |
| 1022 | ||
| 1023 | /* Open file selector to select the public key. */ | |
| 1024 | gaim_request_file(NULL, _("Open..."), NULL, | |
| 1025 | G_CALLBACK(silcgaim_add_buddy_ask_import), | |
| 1026 | G_CALLBACK(silcgaim_add_buddy_ask_pk_cancel), r); | |
| 1027 | } | |
| 1028 | ||
| 1029 | static void | |
| 1030 | silcgaim_add_buddy_ask_pk(SilcGaimBuddyRes r) | |
| 1031 | { | |
| 1032 | char tmp[512]; | |
| 1033 | g_snprintf(tmp, sizeof(tmp), _("The %s buddy is not present in the network"), | |
| 1034 | r->b->name); | |
| 1035 | gaim_request_action(NULL, _("Add Buddy"), tmp, | |
| 8910 | 1036 | _("To add the buddy you must import his/her public key. " |
| 8849 | 1037 | "Press Import to import a public key."), 0, r, 2, |
| 1038 | _("Cancel"), G_CALLBACK(silcgaim_add_buddy_ask_pk_cb), | |
| 1039 | _("Import..."), G_CALLBACK(silcgaim_add_buddy_ask_pk_cb)); | |
| 1040 | } | |
| 1041 | ||
| 1042 | static void | |
| 1043 | silcgaim_add_buddy_getkey_cb(SilcGaimBuddyRes r, | |
| 1044 | SilcClientCommandReplyContext cmd) | |
| 1045 | { | |
| 1046 | SilcClientEntry client_entry; | |
| 1047 | unsigned char *pk; | |
| 1048 | SilcUInt32 pk_len; | |
| 1049 | ||
| 1050 | /* Get the client entry. */ | |
| 1051 | client_entry = silc_client_get_client_by_id(r->client, r->conn, | |
| 1052 | &r->client_id); | |
| 1053 | if (!client_entry || !client_entry->public_key) { | |
| 1054 | /* The buddy is offline/nonexistent. We will require user | |
| 1055 | to associate a public key with the buddy or the buddy | |
| 1056 | cannot be added. */ | |
| 1057 | r->offline = TRUE; | |
| 1058 | silcgaim_add_buddy_ask_pk(r); | |
| 1059 | return; | |
| 1060 | } | |
| 1061 | ||
| 1062 | /* Now verify the public key */ | |
| 1063 | pk = silc_pkcs_public_key_encode(client_entry->public_key, &pk_len); | |
| 1064 | silcgaim_verify_public_key(r->client, r->conn, client_entry->nickname, | |
| 1065 | SILC_SOCKET_TYPE_CLIENT, | |
| 1066 | pk, pk_len, SILC_SKE_PK_TYPE_SILC, | |
| 1067 | silcgaim_add_buddy_save, r); | |
| 1068 | silc_free(pk); | |
| 1069 | } | |
| 1070 | ||
| 1071 | static void | |
| 1072 | silcgaim_add_buddy_select_cb(SilcGaimBuddyRes r, GaimRequestFields *fields) | |
| 1073 | { | |
| 1074 | GaimRequestField *f; | |
| 1075 | const GList *list; | |
| 1076 | SilcClientEntry client_entry; | |
| 1077 | ||
| 1078 | f = gaim_request_fields_get_field(fields, "list"); | |
| 1079 | list = gaim_request_field_list_get_selected(f); | |
| 1080 | if (!list) { | |
| 1081 | /* The user did not select any user. */ | |
| 1082 | silcgaim_add_buddy_pk_no(r); | |
| 1083 | silc_free(r); | |
| 1084 | return; | |
| 1085 | } | |
| 1086 | ||
| 1087 | client_entry = gaim_request_field_list_get_data(f, list->data); | |
| 1088 | silcgaim_add_buddy_resolved(r->client, r->conn, &client_entry, 1, r); | |
| 1089 | } | |
| 1090 | ||
| 1091 | static void | |
| 1092 | silcgaim_add_buddy_select_cancel(SilcGaimBuddyRes r, GaimRequestFields *fields) | |
| 1093 | { | |
| 1094 | /* The user did not select any user. */ | |
| 1095 | silcgaim_add_buddy_pk_no(r); | |
| 1096 | silc_free(r); | |
| 1097 | } | |
| 1098 | ||
| 1099 | static void | |
| 1100 | silcgaim_add_buddy_select(SilcGaimBuddyRes r, | |
| 1101 | SilcClientEntry *clients, | |
| 1102 | SilcUInt32 clients_count) | |
| 1103 | { | |
| 1104 | GaimRequestFields *fields; | |
| 1105 | GaimRequestFieldGroup *g; | |
| 1106 | GaimRequestField *f; | |
| 1107 | char tmp[512]; | |
| 1108 | int i; | |
| 1109 | ||
| 1110 | fields = gaim_request_fields_new(); | |
| 1111 | g = gaim_request_field_group_new(NULL); | |
| 1112 | f = gaim_request_field_list_new("list", NULL); | |
| 1113 | gaim_request_field_group_add_field(g, f); | |
| 1114 | gaim_request_field_list_set_multi_select(f, FALSE); | |
| 1115 | gaim_request_fields_add_group(fields, g); | |
| 1116 | ||
| 1117 | for (i = 0; i < clients_count; i++) { | |
| 1118 | g_snprintf(tmp, sizeof(tmp), "%s - %s (%s@%s)", | |
| 1119 | clients[i]->realname, clients[i]->nickname, | |
| 1120 | clients[i]->username, clients[i]->hostname ? | |
| 1121 | clients[i]->hostname : ""); | |
| 1122 | gaim_request_field_list_add(f, tmp, clients[i]); | |
| 1123 | } | |
| 1124 | ||
| 1125 | gaim_request_fields(NULL, _("Add Buddy"), | |
| 8891 | 1126 | _("Select correct user"), |
| 1127 | r->pubkey_search | |
| 1128 | ? _("More than one user was found with the same public key. Select " | |
| 1129 | "the correct user from the list to add to the buddy list.") | |
| 1130 | : _("More than one user was found with the same name. Select " | |
| 1131 | "the correct user from the list to add to the buddy list."), | |
| 1132 | fields, | |
| 1133 | _("OK"), G_CALLBACK(silcgaim_add_buddy_select_cb), | |
| 1134 | _("Cancel"), G_CALLBACK(silcgaim_add_buddy_select_cancel), r); | |
| 8849 | 1135 | } |
| 1136 | ||
| 1137 | static void | |
| 1138 | silcgaim_add_buddy_resolved(SilcClient client, | |
| 1139 | SilcClientConnection conn, | |
| 1140 | SilcClientEntry *clients, | |
| 1141 | SilcUInt32 clients_count, | |
| 1142 | void *context) | |
| 1143 | { | |
| 1144 | SilcGaimBuddyRes r = context; | |
| 1145 | GaimBuddy *b = r->b; | |
| 1146 | SilcAttributePayload pub; | |
| 1147 | SilcAttributeObjPk userpk; | |
| 1148 | unsigned char *pk; | |
| 1149 | SilcUInt32 pk_len; | |
| 1150 | const char *filename; | |
| 1151 | ||
| 1152 | /* If the buddy is offline/nonexistent, we will require user | |
| 1153 | to associate a public key with the buddy or the buddy | |
| 1154 | cannot be added. */ | |
| 1155 | if (!clients_count) { | |
| 1156 | if (r->init) { | |
| 1157 | silc_free(r); | |
| 1158 | return; | |
| 1159 | } | |
| 1160 | ||
| 1161 | r->offline = TRUE; | |
| 1162 | silcgaim_add_buddy_ask_pk(r); | |
| 1163 | return; | |
| 1164 | } | |
| 1165 | ||
| 1166 | /* If more than one client was found with nickname, we need to verify | |
| 1167 | from user which one is the correct. */ | |
| 1168 | if (clients_count > 1 && !r->pubkey_search) { | |
| 1169 | if (r->init) { | |
| 1170 | silc_free(r); | |
| 1171 | return; | |
| 1172 | } | |
| 1173 | ||
| 1174 | silcgaim_add_buddy_select(r, clients, clients_count); | |
| 1175 | return; | |
| 1176 | } | |
| 1177 | ||
| 1178 | /* If we searched using public keys and more than one entry was found | |
| 1179 | the same person is logged on multiple times. */ | |
| 1180 | if (clients_count > 1 && r->pubkey_search && b->name) { | |
| 1181 | if (r->init) { | |
| 1182 | /* Find the entry that closest matches to the | |
| 1183 | buddy nickname. */ | |
| 1184 | int i; | |
| 1185 | for (i = 0; i < clients_count; i++) { | |
| 1186 | if (!strncasecmp(b->name, clients[i]->nickname, | |
| 1187 | strlen(b->name))) { | |
| 1188 | clients[0] = clients[i]; | |
| 1189 | break; | |
| 1190 | } | |
| 1191 | } | |
| 1192 | } else { | |
| 1193 | /* Verify from user which one is correct */ | |
| 1194 | silcgaim_add_buddy_select(r, clients, clients_count); | |
| 1195 | return; | |
| 1196 | } | |
| 1197 | } | |
| 1198 | ||
| 1199 | /* The client was found. Now get its public key and verify | |
| 1200 | that before adding the buddy. */ | |
| 1201 | memset(&userpk, 0, sizeof(userpk)); | |
| 1202 | b->proto_data = silc_memdup(clients[0]->id, sizeof(*clients[0]->id)); | |
| 1203 | r->client_id = *clients[0]->id; | |
| 1204 | ||
| 1205 | filename = gaim_blist_node_get_string((GaimBlistNode *)b, "public-key"); | |
| 1206 | ||
| 1207 | /* Get the public key from attributes, if not present then | |
| 1208 | resolve it with GETKEY unless we have it cached already. */ | |
| 1209 | if (clients[0]->attrs && !clients[0]->public_key) { | |
| 1210 | pub = silcgaim_get_attr(clients[0]->attrs, | |
| 1211 | SILC_ATTRIBUTE_USER_PUBLIC_KEY); | |
| 1212 | if (!pub || !silc_attribute_get_object(pub, (void *)&userpk, | |
| 1213 | sizeof(userpk))) { | |
| 1214 | /* Get public key with GETKEY */ | |
| 1215 | silc_client_command_call(client, conn, NULL, | |
| 1216 | "GETKEY", clients[0]->nickname, NULL); | |
| 1217 | silc_client_command_pending(conn, SILC_COMMAND_GETKEY, | |
| 1218 | conn->cmd_ident, | |
| 1219 | (SilcCommandCb)silcgaim_add_buddy_getkey_cb, | |
| 1220 | r); | |
| 1221 | return; | |
| 1222 | } | |
| 1223 | if (!silc_pkcs_public_key_decode(userpk.data, userpk.data_len, | |
| 1224 | &clients[0]->public_key)) | |
| 1225 | return; | |
| 1226 | silc_free(userpk.data); | |
| 1227 | } else if (filename && !clients[0]->public_key) { | |
| 1228 | if (!silc_pkcs_load_public_key(filename, &clients[0]->public_key, | |
| 1229 | SILC_PKCS_FILE_PEM) && | |
| 1230 | !silc_pkcs_load_public_key(filename, &clients[0]->public_key, | |
| 1231 | SILC_PKCS_FILE_BIN)) { | |
| 1232 | /* Get public key with GETKEY */ | |
| 1233 | silc_client_command_call(client, conn, NULL, | |
| 1234 | "GETKEY", clients[0]->nickname, NULL); | |
| 1235 | silc_client_command_pending(conn, SILC_COMMAND_GETKEY, | |
| 1236 | conn->cmd_ident, | |
| 1237 | (SilcCommandCb)silcgaim_add_buddy_getkey_cb, | |
| 1238 | r); | |
| 1239 | return; | |
| 1240 | } | |
| 1241 | } else if (!clients[0]->public_key) { | |
| 1242 | /* Get public key with GETKEY */ | |
| 1243 | silc_client_command_call(client, conn, NULL, | |
| 1244 | "GETKEY", clients[0]->nickname, NULL); | |
| 1245 | silc_client_command_pending(conn, SILC_COMMAND_GETKEY, | |
| 1246 | conn->cmd_ident, | |
| 1247 | (SilcCommandCb)silcgaim_add_buddy_getkey_cb, | |
| 1248 | r); | |
| 1249 | return; | |
| 1250 | } | |
| 1251 | ||
| 1252 | /* We have the public key, verify it. */ | |
| 1253 | pk = silc_pkcs_public_key_encode(clients[0]->public_key, &pk_len); | |
| 1254 | silcgaim_verify_public_key(client, conn, clients[0]->nickname, | |
| 1255 | SILC_SOCKET_TYPE_CLIENT, | |
| 1256 | pk, pk_len, SILC_SKE_PK_TYPE_SILC, | |
| 1257 | silcgaim_add_buddy_save, r); | |
| 1258 | silc_free(pk); | |
| 1259 | } | |
| 1260 | ||
| 1261 | static void | |
| 1262 | silcgaim_add_buddy_i(GaimConnection *gc, GaimBuddy *b, gboolean init) | |
| 1263 | { | |
| 1264 | SilcGaim sg = gc->proto_data; | |
| 1265 | SilcClient client = sg->client; | |
| 1266 | SilcClientConnection conn = sg->conn; | |
| 1267 | SilcGaimBuddyRes r; | |
| 1268 | SilcBuffer attrs; | |
| 1269 | const char *filename, *name = b->name; | |
| 1270 | ||
| 1271 | r = silc_calloc(1, sizeof(*r)); | |
| 1272 | if (!r) | |
| 1273 | return; | |
| 1274 | r->client = client; | |
| 1275 | r->conn = conn; | |
| 1276 | r->b = b; | |
| 1277 | r->init = init; | |
| 1278 | ||
| 1279 | /* See if we have this buddy's public key. If we do use that | |
| 1280 | to search the details. */ | |
| 1281 | filename = gaim_blist_node_get_string((GaimBlistNode *)b, "public-key"); | |
| 1282 | if (filename) { | |
| 1283 | SilcPublicKey public_key; | |
| 1284 | SilcAttributeObjPk userpk; | |
| 1285 | ||
| 1286 | if (!silc_pkcs_load_public_key(filename, &public_key, | |
| 1287 | SILC_PKCS_FILE_PEM) && | |
| 1288 | !silc_pkcs_load_public_key(filename, &public_key, | |
| 1289 | SILC_PKCS_FILE_BIN)) | |
| 1290 | return; | |
| 1291 | ||
| 1292 | /* Get all attributes, and use the public key to search user */ | |
| 1293 | name = NULL; | |
| 1294 | attrs = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO, | |
| 1295 | SILC_ATTRIBUTE_SERVICE, | |
| 1296 | SILC_ATTRIBUTE_STATUS_MOOD, | |
| 1297 | SILC_ATTRIBUTE_STATUS_FREETEXT, | |
| 1298 | SILC_ATTRIBUTE_STATUS_MESSAGE, | |
| 1299 | SILC_ATTRIBUTE_PREFERRED_LANGUAGE, | |
| 1300 | SILC_ATTRIBUTE_PREFERRED_CONTACT, | |
| 1301 | SILC_ATTRIBUTE_TIMEZONE, | |
| 1302 | SILC_ATTRIBUTE_GEOLOCATION, | |
| 1303 | SILC_ATTRIBUTE_DEVICE_INFO, 0); | |
| 1304 | userpk.type = "silc-rsa"; | |
| 1305 | userpk.data = silc_pkcs_public_key_encode(public_key, &userpk.data_len); | |
| 1306 | attrs = silc_attribute_payload_encode(attrs, | |
| 1307 | SILC_ATTRIBUTE_USER_PUBLIC_KEY, | |
| 1308 | SILC_ATTRIBUTE_FLAG_VALID, | |
| 1309 | &userpk, sizeof(userpk)); | |
| 1310 | silc_free(userpk.data); | |
| 1311 | silc_pkcs_public_key_free(public_key); | |
| 1312 | r->pubkey_search = TRUE; | |
| 1313 | } else { | |
| 1314 | /* Get all attributes */ | |
| 1315 | attrs = silc_client_attributes_request(0); | |
| 1316 | } | |
| 1317 | ||
| 1318 | /* Resolve */ | |
| 1319 | silc_client_get_clients_whois(client, conn, name, NULL, attrs, | |
| 1320 | silcgaim_add_buddy_resolved, r); | |
| 1321 | silc_buffer_free(attrs); | |
| 1322 | } | |
| 1323 | ||
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
9272
diff
changeset
|
1324 | void silcgaim_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
| 8849 | 1325 | { |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
9272
diff
changeset
|
1326 | silcgaim_add_buddy_i(gc, buddy, FALSE); |
| 8849 | 1327 | } |
| 1328 | ||
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
9272
diff
changeset
|
1329 | void silcgaim_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, |
|
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
9272
diff
changeset
|
1330 | GaimGroup *group) |
| 8849 | 1331 | { |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
9272
diff
changeset
|
1332 | silc_free(buddy->proto_data); |
| 8849 | 1333 | } |
| 1334 | ||
| 1335 | void silcgaim_idle_set(GaimConnection *gc, int idle) | |
| 1336 | ||
| 1337 | { | |
| 1338 | SilcGaim sg = gc->proto_data; | |
| 1339 | SilcClient client = sg->client; | |
| 1340 | SilcClientConnection conn = sg->conn; | |
| 1341 | SilcAttributeObjService service; | |
| 1342 | const char *server; | |
| 1343 | int port; | |
| 1344 | ||
| 1345 | server = gaim_account_get_string(sg->account, "server", | |
| 1346 | "silc.silcnet.org"); | |
| 1347 | port = gaim_account_get_int(sg->account, "port", 706), | |
| 1348 | ||
| 1349 | memset(&service, 0, sizeof(service)); | |
| 1350 | silc_client_attribute_del(client, conn, | |
| 1351 | SILC_ATTRIBUTE_SERVICE, NULL); | |
| 1352 | service.port = port; | |
| 1353 | g_snprintf(service.address, sizeof(service.address), "%s", server); | |
| 1354 | service.idle = idle; | |
| 1355 | silc_client_attribute_add(client, conn, SILC_ATTRIBUTE_SERVICE, | |
| 1356 | &service, sizeof(service)); | |
| 1357 | } | |
| 1358 | ||
| 1359 | char *silcgaim_status_text(GaimBuddy *b) | |
| 1360 | { | |
| 1361 | SilcGaim sg = b->account->gc->proto_data; | |
| 1362 | SilcClient client = sg->client; | |
| 1363 | SilcClientConnection conn = sg->conn; | |
| 1364 | SilcClientID *client_id = b->proto_data; | |
| 1365 | SilcClientEntry client_entry; | |
| 1366 | SilcAttributePayload attr; | |
| 1367 | SilcAttributeMood mood = 0; | |
| 1368 | ||
| 1369 | /* Get the client entry. */ | |
| 1370 | client_entry = silc_client_get_client_by_id(client, conn, client_id); | |
| 1371 | if (!client_entry) | |
| 1372 | return NULL; | |
| 1373 | ||
| 1374 | /* If user is online, we show the mood status, if available. | |
| 1375 | If user is offline or away that status is indicated. */ | |
| 1376 | ||
| 1377 | if (client_entry->mode & SILC_UMODE_DETACHED) | |
| 1378 | return g_strdup(_("Detached")); | |
| 1379 | if (client_entry->mode & SILC_UMODE_GONE) | |
| 1380 | return g_strdup(_("Away")); | |
| 1381 | if (client_entry->mode & SILC_UMODE_INDISPOSED) | |
| 1382 | return g_strdup(_("Indisposed")); | |
| 1383 | if (client_entry->mode & SILC_UMODE_BUSY) | |
| 1384 | return g_strdup(_("Busy")); | |
| 1385 | if (client_entry->mode & SILC_UMODE_PAGE) | |
| 1386 | return g_strdup(_("Wake Me Up")); | |
| 1387 | if (client_entry->mode & SILC_UMODE_HYPER) | |
| 1388 | return g_strdup(_("Hyper Active")); | |
| 1389 | if (client_entry->mode & SILC_UMODE_ROBOT) | |
| 1390 | return g_strdup(_("Robot")); | |
| 1391 | ||
| 1392 | attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_STATUS_MOOD); | |
| 1393 | if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) { | |
| 1394 | /* The mood is a bit mask, so we could show multiple moods, | |
| 1395 | but let's show only one for now. */ | |
| 1396 | if (mood & SILC_ATTRIBUTE_MOOD_HAPPY) | |
| 1397 | return g_strdup(_("Happy")); | |
| 1398 | if (mood & SILC_ATTRIBUTE_MOOD_SAD) | |
| 1399 | return g_strdup(_("Sad")); | |
| 1400 | if (mood & SILC_ATTRIBUTE_MOOD_ANGRY) | |
| 1401 | return g_strdup(_("Angry")); | |
| 1402 | if (mood & SILC_ATTRIBUTE_MOOD_JEALOUS) | |
| 1403 | return g_strdup(_("Jealous")); | |
| 1404 | if (mood & SILC_ATTRIBUTE_MOOD_ASHAMED) | |
| 1405 | return g_strdup(_("Ashamed")); | |
| 1406 | if (mood & SILC_ATTRIBUTE_MOOD_INVINCIBLE) | |
| 1407 | return g_strdup(_("Invincible")); | |
| 1408 | if (mood & SILC_ATTRIBUTE_MOOD_INLOVE) | |
| 1409 | return g_strdup(_("In Love")); | |
| 1410 | if (mood & SILC_ATTRIBUTE_MOOD_SLEEPY) | |
| 1411 | return g_strdup(_("Sleepy")); | |
| 1412 | if (mood & SILC_ATTRIBUTE_MOOD_BORED) | |
| 1413 | return g_strdup(_("Bored")); | |
| 1414 | if (mood & SILC_ATTRIBUTE_MOOD_EXCITED) | |
| 1415 | return g_strdup(_("Excited")); | |
| 1416 | if (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS) | |
| 1417 | return g_strdup(_("Anxious")); | |
| 1418 | } | |
| 1419 | ||
| 1420 | return NULL; | |
| 1421 | } | |
| 1422 | ||
| 1423 | char *silcgaim_tooltip_text(GaimBuddy *b) | |
| 1424 | { | |
| 1425 | SilcGaim sg = b->account->gc->proto_data; | |
| 1426 | SilcClient client = sg->client; | |
| 1427 | SilcClientConnection conn = sg->conn; | |
| 1428 | SilcClientID *client_id = b->proto_data; | |
| 1429 | SilcClientEntry client_entry; | |
| 1430 | SilcAttributePayload attr; | |
| 1431 | SilcAttributeMood mood = 0; | |
| 1432 | SilcAttributeContact contact; | |
| 1433 | SilcAttributeObjDevice device; | |
| 1434 | SilcAttributeObjGeo geo; | |
| 1435 | GString *s; | |
| 1436 | char *buf; | |
| 1437 | char tmp[256]; | |
| 1438 | ||
| 1439 | s = g_string_new(""); | |
| 1440 | ||
| 1441 | /* Get the client entry. */ | |
| 1442 | client_entry = silc_client_get_client_by_id(client, conn, client_id); | |
| 1443 | if (!client_entry) | |
| 1444 | return NULL; | |
| 1445 | ||
| 1446 | if (client_entry->nickname) | |
| 9272 | 1447 | g_string_append_printf(s, "\n<b>%s:</b> %s", _("Nickname"), |
| 8849 | 1448 | client_entry->nickname); |
| 1449 | if (client_entry->username && client_entry->hostname) | |
| 9272 | 1450 | g_string_append_printf(s, "\n<b>%s:</b> %s@%s", _("Username"), |
| 8849 | 1451 | client_entry->username, client_entry->hostname); |
| 1452 | if (client_entry->mode) { | |
| 9272 | 1453 | g_string_append_printf(s, "\n<b>%s:</b> ", _("Modes")); |
| 8849 | 1454 | memset(tmp, 0, sizeof(tmp)); |
| 1455 | silcgaim_get_umode_string(client_entry->mode, | |
| 1456 | tmp, sizeof(tmp) - strlen(tmp)); | |
| 9272 | 1457 | g_string_append_printf(s, "%s", tmp); |
| 8849 | 1458 | } |
| 1459 | ||
| 1460 | attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_STATUS_MOOD); | |
| 1461 | if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) { | |
| 1462 | if (mood) | |
| 9272 | 1463 | g_string_append_printf(s, "\n<b>%s:</b> ", _("Mood")); |
| 8849 | 1464 | if (mood & SILC_ATTRIBUTE_MOOD_HAPPY) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1465 | g_string_append_printf(s, "[%s] ", _("Happy")); |
| 8849 | 1466 | if (mood & SILC_ATTRIBUTE_MOOD_SAD) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1467 | g_string_append_printf(s, "[%s] ", _("Sad")); |
| 8849 | 1468 | if (mood & SILC_ATTRIBUTE_MOOD_ANGRY) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1469 | g_string_append_printf(s, "[%s] ", _("Angry")); |
| 8849 | 1470 | if (mood & SILC_ATTRIBUTE_MOOD_JEALOUS) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1471 | g_string_append_printf(s, "[%s] ", _("Jealous")); |
| 8849 | 1472 | if (mood & SILC_ATTRIBUTE_MOOD_ASHAMED) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1473 | g_string_append_printf(s, "[%s] ", _("Ashamed")); |
| 8849 | 1474 | if (mood & SILC_ATTRIBUTE_MOOD_INVINCIBLE) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1475 | g_string_append_printf(s, "[%s] ", _("Invincible")); |
| 8849 | 1476 | if (mood & SILC_ATTRIBUTE_MOOD_INLOVE) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1477 | g_string_append_printf(s, "[%s] ", _("In Love")); |
| 8849 | 1478 | if (mood & SILC_ATTRIBUTE_MOOD_SLEEPY) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1479 | g_string_append_printf(s, "[%s] ", _("Sleepy")); |
| 8849 | 1480 | if (mood & SILC_ATTRIBUTE_MOOD_BORED) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1481 | g_string_append_printf(s, "[%s] ", _("Bored")); |
| 8849 | 1482 | if (mood & SILC_ATTRIBUTE_MOOD_EXCITED) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1483 | g_string_append_printf(s, "[%s] ", _("Excited")); |
| 8849 | 1484 | if (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1485 | g_string_append_printf(s, "[%s] ", _("Anxious")); |
| 8849 | 1486 | } |
| 1487 | ||
| 1488 | attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_STATUS_FREETEXT); | |
| 1489 | memset(tmp, 0, sizeof(tmp)); | |
| 1490 | if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) | |
| 9272 | 1491 | g_string_append_printf(s, "\n<b>%s:</b> %s", _("Status Text"), tmp); |
| 8849 | 1492 | |
| 1493 | attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_PREFERRED_CONTACT); | |
| 1494 | if (attr && silc_attribute_get_object(attr, &contact, sizeof(contact))) { | |
| 1495 | if (contact) | |
| 9272 | 1496 | g_string_append_printf(s, "\n<b>%s:</b> ", _("Preferred Contact")); |
| 8849 | 1497 | if (contact & SILC_ATTRIBUTE_CONTACT_CHAT) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1498 | g_string_append_printf(s, "[%s] ", _("Chat")); |
| 8849 | 1499 | if (contact & SILC_ATTRIBUTE_CONTACT_EMAIL) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1500 | g_string_append_printf(s, "[%s] ", _("Email")); |
| 8849 | 1501 | if (contact & SILC_ATTRIBUTE_CONTACT_CALL) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1502 | g_string_append_printf(s, "[%s] ", _("Phone")); |
| 8849 | 1503 | if (contact & SILC_ATTRIBUTE_CONTACT_PAGE) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1504 | g_string_append_printf(s, "[%s] ", _("Paging")); |
| 8849 | 1505 | if (contact & SILC_ATTRIBUTE_CONTACT_SMS) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1506 | g_string_append_printf(s, "[%s] ", _("SMS")); |
| 8849 | 1507 | if (contact & SILC_ATTRIBUTE_CONTACT_MMS) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1508 | g_string_append_printf(s, "[%s] ", _("MMS")); |
| 8849 | 1509 | if (contact & SILC_ATTRIBUTE_CONTACT_VIDEO) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1510 | g_string_append_printf(s, "[%s] ", _("Video Conferencing")); |
| 8849 | 1511 | } |
| 1512 | ||
| 1513 | attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_PREFERRED_LANGUAGE); | |
| 1514 | memset(tmp, 0, sizeof(tmp)); | |
| 1515 | if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) | |
| 9272 | 1516 | g_string_append_printf(s, "\n<b>%s:</b> %s", _("Preferred Language"), tmp); |
| 8849 | 1517 | |
| 1518 | attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_DEVICE_INFO); | |
| 1519 | memset(&device, 0, sizeof(device)); | |
| 1520 | if (attr && silc_attribute_get_object(attr, &device, sizeof(device))) { | |
| 9272 | 1521 | g_string_append_printf(s, "\n<b>%s:</b> ", _("Device")); |
| 8849 | 1522 | if (device.type == SILC_ATTRIBUTE_DEVICE_COMPUTER) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1523 | g_string_append_printf(s, "%s: ", _("Computer")); |
| 8849 | 1524 | if (device.type == SILC_ATTRIBUTE_DEVICE_MOBILE_PHONE) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1525 | g_string_append_printf(s, "%s: ", _("Mobile Phone")); |
| 8849 | 1526 | if (device.type == SILC_ATTRIBUTE_DEVICE_PDA) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1527 | g_string_append_printf(s, "%s: ", _("PDA")); |
| 8849 | 1528 | if (device.type == SILC_ATTRIBUTE_DEVICE_TERMINAL) |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1529 | g_string_append_printf(s, "%s: ", _("Terminal")); |
| 9272 | 1530 | g_string_append_printf(s, "%s %s %s %s", |
| 8849 | 1531 | device.manufacturer ? device.manufacturer : "", |
| 1532 | device.version ? device.version : "", | |
| 1533 | device.model ? device.model : "", | |
| 1534 | device.language ? device.language : ""); | |
| 1535 | } | |
| 1536 | ||
| 1537 | attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_TIMEZONE); | |
| 1538 | memset(tmp, 0, sizeof(tmp)); | |
| 1539 | if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) | |
| 9272 | 1540 | g_string_append_printf(s, "\n<b>%s:</b> %s", _("Timezone"), tmp); |
| 8849 | 1541 | |
| 1542 | attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_GEOLOCATION); | |
| 1543 | memset(&geo, 0, sizeof(geo)); | |
| 1544 | if (attr && silc_attribute_get_object(attr, &geo, sizeof(geo))) | |
| 9272 | 1545 | g_string_append_printf(s, "\n<b>%s:</b> %s %s %s (%s)", |
|
9039
2fb80b14dd95
[gaim-migrate @ 9815]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
9038
diff
changeset
|
1546 | _("Geolocation"), |
| 8849 | 1547 | geo.longitude ? geo.longitude : "", |
| 1548 | geo.latitude ? geo.latitude : "", | |
| 1549 | geo.altitude ? geo.altitude : "", | |
| 1550 | geo.accuracy ? geo.accuracy : ""); | |
| 1551 | ||
| 1552 | buf = g_string_free(s, FALSE); | |
| 1553 | return buf; | |
| 1554 | } | |
| 1555 | ||
| 1556 | static void | |
| 9038 | 1557 | silcgaim_buddy_kill(GaimBlistNode *node, gpointer data) |
| 8849 | 1558 | { |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1559 | GaimBuddy *b; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1560 | GaimConnection *gc; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1561 | SilcGaim sg; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1562 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1563 | g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1564 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1565 | b = (GaimBuddy *) node; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1566 | gc = gaim_account_get_connection(b->account); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1567 | sg = gc->proto_data; |
| 8849 | 1568 | |
| 1569 | /* Call KILL */ | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1570 | silc_client_command_call(sg->client, sg->conn, NULL, "KILL", |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1571 | b->name, "Killed by operator", NULL); |
| 8849 | 1572 | } |
| 1573 | ||
| 1574 | static void | |
| 9038 | 1575 | silcgaim_buddy_send_file(GaimBlistNode *node, gpointer data) |
| 8849 | 1576 | { |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1577 | GaimBuddy *b; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1578 | GaimConnection *gc; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1579 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1580 | g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1581 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1582 | b = (GaimBuddy *) node; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1583 | gc = gaim_account_get_connection(b->account); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1584 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1585 | silcgaim_ftp_send_file(gc, b->name); |
| 8849 | 1586 | } |
| 1587 | ||
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1588 | GList *silcgaim_buddy_menu(GaimBuddy *buddy) |
| 8849 | 1589 | { |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1590 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1591 | GaimConnection *gc = gaim_account_get_connection(buddy->account); |
| 8849 | 1592 | SilcGaim sg = gc->proto_data; |
| 1593 | SilcClientConnection conn = sg->conn; | |
| 1594 | const char *pkfile = NULL; | |
| 1595 | SilcClientEntry client_entry = NULL; | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1596 | GaimBlistNodeAction *act; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1597 | GList *m = NULL; |
| 8849 | 1598 | |
| 9038 | 1599 | pkfile = gaim_blist_node_get_string((GaimBlistNode *) buddy, "public-key"); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1600 | client_entry = silc_client_get_client_by_id(sg->client, |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1601 | sg->conn, |
| 9038 | 1602 | buddy->proto_data); |
| 8849 | 1603 | |
| 1604 | if (client_entry && client_entry->send_key) { | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1605 | act = gaim_blist_node_action_new(_("Reset IM Key"), |
| 9038 | 1606 | silcgaim_buddy_resetkey, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1607 | m = g_list_append(m, act); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1608 | |
| 8849 | 1609 | } else { |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1610 | act = gaim_blist_node_action_new(_("IM with Key Exchange"), |
| 9038 | 1611 | silcgaim_buddy_keyagr, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1612 | m = g_list_append(m, act); |
| 8849 | 1613 | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1614 | act = gaim_blist_node_action_new(_("IM with Password"), |
| 9038 | 1615 | silcgaim_buddy_privkey_menu, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1616 | m = g_list_append(m, act); |
| 8849 | 1617 | } |
| 1618 | ||
| 1619 | if (pkfile) { | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1620 | act = gaim_blist_node_action_new(_("Show Public Key"), |
| 9038 | 1621 | silcgaim_buddy_showkey, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1622 | m = g_list_append(m, act); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1623 | |
| 8849 | 1624 | } else { |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1625 | act = gaim_blist_node_action_new(_("Get Public Key..."), |
| 9038 | 1626 | silcgaim_buddy_getkey_menu, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1627 | m = g_list_append(m, act); |
| 8849 | 1628 | } |
| 1629 | ||
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1630 | act = gaim_blist_node_action_new(_("Send File..."), |
| 9038 | 1631 | silcgaim_buddy_send_file, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1632 | m = g_list_append(m, act); |
| 8849 | 1633 | |
| 1634 | if (conn && conn->local_entry->mode & SILC_UMODE_ROUTER_OPERATOR) { | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1635 | act = gaim_blist_node_action_new(_("Kill User"), |
| 9038 | 1636 | silcgaim_buddy_kill, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1637 | m = g_list_append(m, act); |
| 8849 | 1638 | } |
| 1639 | ||
| 1640 | return m; | |
| 1641 | } |