Mercurial > pidgin.yaz
comparison libpurple/protocols/silc/util.c @ 17806:980a104267da
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
SILC Toolkit 1.1
I added the fallback to SILC Toolkit 1.0 support (silc10 protocol
directory) and configure.ac adjustments, any problems with this are 100%
my fault.
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sat, 09 Jun 2007 17:31:28 +0000 |
parents | 25ef7db38f28 |
children | 9a96d8711303 |
comparison
equal
deleted
inserted
replaced
17805:ba1b50f114f6 | 17806:980a104267da |
---|---|
2 | 2 |
3 silcpurple_util.c | 3 silcpurple_util.c |
4 | 4 |
5 Author: Pekka Riikonen <priikone@silcnet.org> | 5 Author: Pekka Riikonen <priikone@silcnet.org> |
6 | 6 |
7 Copyright (C) 2004 - 2005 Pekka Riikonen | 7 Copyright (C) 2004 - 2007 Pekka Riikonen |
8 | 8 |
9 This program is free software; you can redistribute it and/or modify | 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 | 10 it under the terms of the GNU General Public License as published by |
11 the Free Software Foundation; version 2 of the License. | 11 the Free Software Foundation; version 2 of the License. |
12 | 12 |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 GNU General Public License for more details. | 16 GNU General Public License for more details. |
17 | 17 |
18 */ | 18 */ |
19 | 19 |
20 #include "silcincludes.h" | 20 #include "silc.h" |
21 #include "silcclient.h" | 21 #include "silcclient.h" |
22 #include "silcpurple.h" | 22 #include "silcpurple.h" |
23 #include "imgstore.h" | 23 #include "imgstore.h" |
24 | 24 |
25 /**************************** Utility Routines *******************************/ | 25 /**************************** Utility Routines *******************************/ |
204 if ((g_stat(file_public_key, &st)) == -1) { | 204 if ((g_stat(file_public_key, &st)) == -1) { |
205 /* If file doesn't exist */ | 205 /* If file doesn't exist */ |
206 if (errno == ENOENT) { | 206 if (errno == ENOENT) { |
207 purple_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); | 207 purple_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
208 if (!silc_create_key_pair(SILCPURPLE_DEF_PKCS, | 208 if (!silc_create_key_pair(SILCPURPLE_DEF_PKCS, |
209 SILCPURPLE_DEF_PKCS_LEN, | 209 SILCPURPLE_DEF_PKCS_LEN, |
210 file_public_key, file_private_key, NULL, | 210 file_public_key, |
211 (gc->password == NULL) ? "" : gc->password, | 211 file_private_key, NULL, |
212 NULL, NULL, NULL, FALSE)) { | 212 (gc->password == NULL) |
213 purple_debug_error("silc", "Couldn't create key pair\n"); | 213 ? "" : gc->password, |
214 NULL, NULL, FALSE)) { | |
215 purple_connection_error(gc, _("Cannot create SILC key pair\n")); | |
214 return FALSE; | 216 return FALSE; |
215 } | 217 } |
216 | 218 |
217 if ((g_stat(file_public_key, &st)) == -1) { | 219 if ((g_stat(file_public_key, &st)) == -1) { |
218 purple_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", | 220 purple_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
219 file_public_key, strerror(errno)); | 221 file_public_key, strerror(errno)); |
220 return FALSE; | 222 return FALSE; |
221 } | 223 } |
222 } else { | 224 } else { |
223 purple_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", | 225 purple_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
224 file_public_key, strerror(errno)); | 226 file_public_key, strerror(errno)); |
225 return FALSE; | 227 return FALSE; |
226 } | 228 } |
227 } | 229 } |
228 | 230 |
229 #ifndef _WIN32 | 231 #ifndef _WIN32 |
235 #endif | 237 #endif |
236 | 238 |
237 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { | 239 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
238 if ((fstat(fd, &st)) == -1) { | 240 if ((fstat(fd, &st)) == -1) { |
239 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", | 241 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
240 file_private_key, strerror(errno)); | 242 file_private_key, strerror(errno)); |
241 close(fd); | 243 close(fd); |
242 return FALSE; | 244 return FALSE; |
243 } | 245 } |
244 } else if ((g_stat(file_private_key, &st)) == -1) { | 246 } else if ((g_stat(file_private_key, &st)) == -1) { |
245 /* If file doesn't exist */ | 247 /* If file doesn't exist */ |
246 if (errno == ENOENT) { | 248 if (errno == ENOENT) { |
247 purple_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); | 249 purple_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
248 if (!silc_create_key_pair(SILCPURPLE_DEF_PKCS, | 250 if (!silc_create_key_pair(SILCPURPLE_DEF_PKCS, |
249 SILCPURPLE_DEF_PKCS_LEN, | 251 SILCPURPLE_DEF_PKCS_LEN, |
250 file_public_key, file_private_key, NULL, | 252 file_public_key, |
251 (gc->password == NULL) ? "" : gc->password, | 253 file_private_key, NULL, |
252 NULL, NULL, NULL, FALSE)) { | 254 (gc->password == NULL) |
253 purple_debug_error("silc", "Couldn't create key pair\n"); | 255 ? "" : gc->password, |
256 NULL, NULL, FALSE)) { | |
257 purple_connection_error(gc, _("Cannot create SILC key pair\n")); | |
254 return FALSE; | 258 return FALSE; |
255 } | 259 } |
256 | 260 |
257 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { | 261 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
258 if ((fstat(fd, &st)) == -1) { | 262 if ((fstat(fd, &st)) == -1) { |
259 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", | 263 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
260 file_private_key, strerror(errno)); | 264 file_private_key, strerror(errno)); |
261 close(fd); | 265 close(fd); |
262 return FALSE; | 266 return FALSE; |
263 } | 267 } |
264 } | 268 } |
265 /* This shouldn't really happen because silc_create_key_pair() | 269 /* This shouldn't really happen because silc_create_key_pair() |
266 * will set the permissions */ | 270 * will set the permissions */ |
267 else if ((g_stat(file_private_key, &st)) == -1) { | 271 else if ((g_stat(file_private_key, &st)) == -1) { |
268 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", | 272 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
269 file_private_key, strerror(errno)); | 273 file_private_key, strerror(errno)); |
270 return FALSE; | 274 return FALSE; |
271 } | 275 } |
272 } else { | 276 } else { |
273 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", | 277 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
274 file_private_key, strerror(errno)); | 278 file_private_key, strerror(errno)); |
275 return FALSE; | 279 return FALSE; |
276 } | 280 } |
277 } | 281 } |
278 | 282 |
279 #ifndef _WIN32 | 283 #ifndef _WIN32 |
321 return 0; | 325 return 0; |
322 } | 326 } |
323 #endif | 327 #endif |
324 | 328 |
325 void silcpurple_show_public_key(SilcPurple sg, | 329 void silcpurple_show_public_key(SilcPurple sg, |
326 const char *name, SilcPublicKey public_key, | 330 const char *name, SilcPublicKey public_key, |
327 GCallback callback, void *context) | 331 GCallback callback, void *context) |
328 { | 332 { |
329 SilcPublicKeyIdentifier ident; | 333 SilcPublicKeyIdentifier ident; |
330 SilcPKCS pkcs; | 334 SilcSILCPublicKey silc_pubkey; |
331 char *fingerprint, *babbleprint; | 335 char *fingerprint, *babbleprint; |
332 unsigned char *pk; | 336 unsigned char *pk; |
333 SilcUInt32 pk_len, key_len = 0; | 337 SilcUInt32 pk_len, key_len = 0; |
334 GString *s; | 338 GString *s; |
335 char *buf; | 339 char *buf; |
336 | 340 |
337 ident = silc_pkcs_decode_identifier(public_key->identifier); | 341 /* We support showing only SILC public keys for now */ |
338 if (!ident) | 342 if (silc_pkcs_get_type(public_key) != SILC_PKCS_SILC) |
339 return; | 343 return; |
344 | |
345 silc_pubkey = silc_pkcs_get_context(SILC_PKCS_SILC, public_key); | |
346 ident = &silc_pubkey->identifier; | |
347 key_len = silc_pkcs_public_key_get_len(public_key); | |
340 | 348 |
341 pk = silc_pkcs_public_key_encode(public_key, &pk_len); | 349 pk = silc_pkcs_public_key_encode(public_key, &pk_len); |
342 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len); | 350 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len); |
343 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len); | 351 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len); |
344 | |
345 if (silc_pkcs_alloc((unsigned char *)public_key->name, &pkcs)) { | |
346 key_len = silc_pkcs_public_key_set(pkcs, public_key); | |
347 silc_pkcs_free(pkcs); | |
348 } | |
349 | 352 |
350 s = g_string_new(""); | 353 s = g_string_new(""); |
351 if (ident->realname) | 354 if (ident->realname) |
352 /* Hint for translators: Please check the tabulator width here and in | 355 /* Hint for translators: Please check the tabulator width here and in |
353 the next strings (short strings: 2 tabs, longer strings 1 tab, | 356 the next strings (short strings: 2 tabs, longer strings 1 tab, |
361 g_string_append_printf(s, _("Host Name: \t%s\n"), ident->host); | 364 g_string_append_printf(s, _("Host Name: \t%s\n"), ident->host); |
362 if (ident->org) | 365 if (ident->org) |
363 g_string_append_printf(s, _("Organization: \t%s\n"), ident->org); | 366 g_string_append_printf(s, _("Organization: \t%s\n"), ident->org); |
364 if (ident->country) | 367 if (ident->country) |
365 g_string_append_printf(s, _("Country: \t%s\n"), ident->country); | 368 g_string_append_printf(s, _("Country: \t%s\n"), ident->country); |
366 g_string_append_printf(s, _("Algorithm: \t%s\n"), public_key->name); | 369 g_string_append_printf(s, _("Algorithm: \t%s\n"), silc_pubkey->pkcs->name); |
367 g_string_append_printf(s, _("Key Length: \t%d bits\n"), (int)key_len); | 370 g_string_append_printf(s, _("Key Length: \t%d bits\n"), (int)key_len); |
371 if (ident->version) | |
372 g_string_append_printf(s, _("Version: \t%s\n"), ident->version); | |
368 g_string_append_printf(s, "\n"); | 373 g_string_append_printf(s, "\n"); |
369 g_string_append_printf(s, _("Public Key Fingerprint:\n%s\n\n"), fingerprint); | 374 g_string_append_printf(s, _("Public Key Fingerprint:\n%s\n\n"), fingerprint); |
370 g_string_append_printf(s, _("Public Key Babbleprint:\n%s"), babbleprint); | 375 g_string_append_printf(s, _("Public Key Babbleprint:\n%s"), babbleprint); |
371 | 376 |
372 buf = g_string_free(s, FALSE); | 377 buf = g_string_free(s, FALSE); |
373 | 378 |
374 purple_request_action(sg->gc, _("Public Key Information"), | 379 purple_request_action(sg->gc, _("Public Key Information"), |
375 _("Public Key Information"), | 380 _("Public Key Information"), |
376 buf, 0, purple_connection_get_account(sg->gc), | 381 buf, 0, purple_connection_get_account(sg->gc), |
377 NULL, NULL, context, 1, _("Close"), callback); | 382 NULL, NULL, context, 1, _("Close"), callback); |
378 | 383 |
379 g_free(buf); | 384 g_free(buf); |
380 silc_free(fingerprint); | 385 silc_free(fingerprint); |
381 silc_free(babbleprint); | 386 silc_free(babbleprint); |
382 silc_free(pk); | 387 silc_free(pk); |
383 silc_pkcs_free_identifier(ident); | |
384 } | 388 } |
385 | 389 |
386 SilcAttributePayload | 390 SilcAttributePayload |
387 silcpurple_get_attr(SilcDList attrs, SilcAttribute attribute) | 391 silcpurple_get_attr(SilcDList attrs, SilcAttribute attribute) |
388 { | 392 { |
398 | 402 |
399 return attr; | 403 return attr; |
400 } | 404 } |
401 | 405 |
402 void silcpurple_get_umode_string(SilcUInt32 mode, char *buf, | 406 void silcpurple_get_umode_string(SilcUInt32 mode, char *buf, |
403 SilcUInt32 buf_size) | 407 SilcUInt32 buf_size) |
404 { | 408 { |
405 memset(buf, 0, buf_size); | 409 memset(buf, 0, buf_size); |
406 if ((mode & SILC_UMODE_SERVER_OPERATOR) || | 410 if ((mode & SILC_UMODE_SERVER_OPERATOR) || |
407 (mode & SILC_UMODE_ROUTER_OPERATOR)) { | 411 (mode & SILC_UMODE_ROUTER_OPERATOR)) { |
408 strcat(buf, (mode & SILC_UMODE_SERVER_OPERATOR) ? | 412 strcat(buf, (mode & SILC_UMODE_SERVER_OPERATOR) ? |
433 if (mode & SILC_UMODE_BLOCK_INVITE) | 437 if (mode & SILC_UMODE_BLOCK_INVITE) |
434 strcat(buf, "[blocks invites] "); | 438 strcat(buf, "[blocks invites] "); |
435 } | 439 } |
436 | 440 |
437 void silcpurple_get_chmode_string(SilcUInt32 mode, char *buf, | 441 void silcpurple_get_chmode_string(SilcUInt32 mode, char *buf, |
438 SilcUInt32 buf_size) | 442 SilcUInt32 buf_size) |
439 { | 443 { |
440 memset(buf, 0, buf_size); | 444 memset(buf, 0, buf_size); |
441 if (mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) | 445 if (mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) |
442 strcat(buf, "[permanent] "); | 446 strcat(buf, "[permanent] "); |
443 if (mode & SILC_CHANNEL_MODE_PRIVATE) | 447 if (mode & SILC_CHANNEL_MODE_PRIVATE) |
480 strcat(buf, "[quieted] "); | 484 strcat(buf, "[quieted] "); |
481 } | 485 } |
482 | 486 |
483 void | 487 void |
484 silcpurple_parse_attrs(SilcDList attrs, char **moodstr, char **statusstr, | 488 silcpurple_parse_attrs(SilcDList attrs, char **moodstr, char **statusstr, |
485 char **contactstr, char **langstr, char **devicestr, | 489 char **contactstr, char **langstr, char **devicestr, |
486 char **tzstr, char **geostr) | 490 char **tzstr, char **geostr) |
487 { | 491 { |
488 SilcAttributePayload attr; | 492 SilcAttributePayload attr; |
489 SilcAttributeMood mood = 0; | 493 SilcAttributeMood mood = 0; |
490 SilcAttributeContact contact; | 494 SilcAttributeContact contact; |
491 SilcAttributeObjDevice device; | 495 SilcAttributeObjDevice device; |
618 const char *ct; | 622 const char *ct; |
619 | 623 |
620 ct = strrchr(filename, '.'); | 624 ct = strrchr(filename, '.'); |
621 if (!ct) | 625 if (!ct) |
622 return NULL; | 626 return NULL; |
623 else if (!g_ascii_strcasecmp(".png", ct)) | 627 else if (!strcasecmp(".png", ct)) |
624 return strdup("image/png"); | 628 return strdup("image/png"); |
625 else if (!g_ascii_strcasecmp(".jpg", ct)) | 629 else if (!strcasecmp(".jpg", ct)) |
626 return strdup("image/jpeg"); | 630 return strdup("image/jpeg"); |
627 else if (!g_ascii_strcasecmp(".jpeg", ct)) | 631 else if (!strcasecmp(".jpeg", ct)) |
628 return strdup("image/jpeg"); | 632 return strdup("image/jpeg"); |
629 else if (!g_ascii_strcasecmp(".gif", ct)) | 633 else if (!strcasecmp(".gif", ct)) |
630 return strdup("image/gif"); | 634 return strdup("image/gif"); |
631 else if (!g_ascii_strcasecmp(".tiff", ct)) | 635 else if (!strcasecmp(".tiff", ct)) |
632 return strdup("image/tiff"); | 636 return strdup("image/tiff"); |
633 | 637 |
634 return NULL; | 638 return NULL; |
635 } | 639 } |
636 | 640 |
637 /* Checks if message has images, and assembles MIME message if it has. | 641 /* Checks if message has images, and assembles MIME message if it has. |
638 If only one image is present, creates simple MIME image message. If | 642 If only one image is present, creates simple MIME image message. If |
639 there are multiple images and/or text with images multipart MIME | 643 there are multiple images and/or text with images multipart MIME |
640 message is created. */ | 644 message is created. */ |
641 | 645 |
642 SilcDList silcpurple_image_message(const char *msg, SilcUInt32 *mflags) | 646 SilcDList silcpurple_image_message(const char *msg, SilcUInt32 *mflags) |
643 { | 647 { |
644 SilcMime mime = NULL, p; | 648 SilcMime mime = NULL, p; |
664 "text/plain; charset=utf-8"); | 668 "text/plain; charset=utf-8"); |
665 | 669 |
666 tmp = g_strndup(last, start - last); | 670 tmp = g_strndup(last, start - last); |
667 text = purple_unescape_html(tmp); | 671 text = purple_unescape_html(tmp); |
668 g_free(tmp); | 672 g_free(tmp); |
673 | |
669 /* Add text */ | 674 /* Add text */ |
670 silc_mime_add_data(p, text, strlen(text)); | 675 silc_mime_add_data(p, (const unsigned char *)text, strlen(text)); |
671 g_free(text); | 676 g_free(text); |
672 | 677 |
673 if (!parts) | 678 if (!parts) |
674 parts = silc_dlist_init(); | 679 parts = silc_dlist_init(); |
675 silc_dlist_add(parts, p); | 680 silc_dlist_add(parts, p); |
718 /* Add content type */ | 723 /* Add content type */ |
719 silc_mime_add_field(p, "Content-Type", | 724 silc_mime_add_field(p, "Content-Type", |
720 "text/plain; charset=utf-8"); | 725 "text/plain; charset=utf-8"); |
721 | 726 |
722 /* Add text */ | 727 /* Add text */ |
723 silc_mime_add_data(p, tmp, strlen(tmp)); | 728 silc_mime_add_data(p, (const unsigned char *)tmp, strlen(tmp)); |
724 g_free(tmp); | 729 g_free(tmp); |
725 | 730 |
726 if (!parts) | 731 if (!parts) |
727 parts = silc_dlist_init(); | 732 parts = silc_dlist_init(); |
728 silc_dlist_add(parts, p); | 733 silc_dlist_add(parts, p); |
740 char b[32]; | 745 char b[32]; |
741 mime = silc_mime_alloc(); | 746 mime = silc_mime_alloc(); |
742 silc_mime_add_field(mime, "MIME-Version", "1.0"); | 747 silc_mime_add_field(mime, "MIME-Version", "1.0"); |
743 g_snprintf(b, sizeof(b), "b%4X%4X", | 748 g_snprintf(b, sizeof(b), "b%4X%4X", |
744 (unsigned int)time(NULL), | 749 (unsigned int)time(NULL), |
745 silc_dlist_count(parts)); | 750 silc_dlist_count(parts)); |
746 silc_mime_set_multipart(mime, "mixed", b); | 751 silc_mime_set_multipart(mime, "mixed", b); |
747 silc_dlist_start(parts); | 752 silc_dlist_start(parts); |
748 while ((p = silc_dlist_get(parts)) != SILC_LIST_END) | 753 while ((p = silc_dlist_get(parts)) != SILC_LIST_END) |
749 silc_mime_add_multipart(mime, p); | 754 silc_mime_add_multipart(mime, p); |
750 } else { | 755 } else { |