Mercurial > gftp.yaz
comparison lib/protocols.c @ 845:8263cc35c027
2006-11-2 Brian Masney <masneyb@gftp.org>
* lib/gftp.h lib/local.c lib/misc.c lib/protocols.c lib/rfc959.c
lib/sshv2.c - added gftp_filename_to_utf8() and
gftp_filename_from_utf8().
(gftp_string_from_utf8) - added argument that will force the local
encoding to be used.
author | masneyb |
---|---|
date | Fri, 03 Nov 2006 03:02:51 +0000 |
parents | 0d6fba16c7db |
children | 1c8d6b6b7950 |
comparison
equal
deleted
inserted
replaced
844:1ece208d1357 | 845:8263cc35c027 |
---|---|
462 str, fromset, toset, error->message); | 462 str, fromset, toset, error->message); |
463 } | 463 } |
464 | 464 |
465 | 465 |
466 /*@null@*/ char * | 466 /*@null@*/ char * |
467 _do_convert_string (gftp_request * request, const char *str, | 467 _do_convert_string (gftp_request * request, int is_filename, int force_local, |
468 size_t *dest_len, int from_utf8) | 468 const char *str, size_t *dest_len, int from_utf8) |
469 { | 469 { |
470 char *remote_charsets, *ret, *fromset, *toset, *stpos, *cur_charset; | 470 char *remote_charsets, *ret, *fromset, *toset, *stpos, *cur_charset; |
471 GError * error; | 471 GError * error; |
472 gsize bread; | 472 gsize bread; |
473 | 473 |
477 if (g_utf8_validate (str, -1, NULL) != from_utf8) | 477 if (g_utf8_validate (str, -1, NULL) != from_utf8) |
478 return (NULL); | 478 return (NULL); |
479 | 479 |
480 error = NULL; | 480 error = NULL; |
481 gftp_lookup_request_option (request, "remote_charsets", &remote_charsets); | 481 gftp_lookup_request_option (request, "remote_charsets", &remote_charsets); |
482 if (*remote_charsets == '\0' || request->use_local_encoding) | 482 if (*remote_charsets == '\0' || request->use_local_encoding || |
483 force_local == 1) | |
483 { | 484 { |
484 if (from_utf8) | 485 if (from_utf8) |
485 ret = g_locale_from_utf8 (str, -1, &bread, dest_len, &error); | 486 { |
487 if (is_filename) | |
488 ret = g_filename_from_utf8 (str, -1, &bread, dest_len, &error); | |
489 else | |
490 ret = g_locale_from_utf8 (str, -1, &bread, dest_len, &error); | |
491 } | |
486 else | 492 else |
487 ret = g_locale_to_utf8 (str, -1, &bread, dest_len, &error); | 493 { |
494 if (is_filename) | |
495 ret = g_filename_to_utf8 (str, -1, &bread, dest_len, &error); | |
496 else | |
497 ret = g_locale_to_utf8 (str, -1, &bread, dest_len, &error); | |
498 } | |
488 | 499 |
489 if (ret == NULL) | 500 if (ret == NULL) |
490 _do_show_iconv_error (str, request->iconv_charset, from_utf8, error); | 501 _do_show_iconv_error (str, request->iconv_charset, from_utf8, error); |
491 | 502 |
492 return (ret); | 503 return (ret); |
538 } | 549 } |
539 | 550 |
540 return (NULL); | 551 return (NULL); |
541 } | 552 } |
542 | 553 |
543 /*@null@*/ char * | 554 char * |
544 gftp_string_to_utf8 (gftp_request * request, const char *str, size_t *dest_len) | 555 gftp_string_to_utf8 (gftp_request * request, const char *str, size_t *dest_len) |
545 { | 556 { |
546 return (_do_convert_string (request, str, dest_len, 0)); | 557 return (_do_convert_string (request, 0, 0, str, dest_len, 0)); |
547 } | 558 } |
548 | 559 |
549 | 560 |
550 char * | 561 char * |
551 gftp_string_from_utf8 (gftp_request * request, const char *str, | 562 gftp_string_from_utf8 (gftp_request * request, int force_local, const char *str, |
552 size_t *dest_len) | 563 size_t *dest_len) |
553 { | 564 { |
554 return (_do_convert_string (request, str, dest_len, 1)); | 565 return (_do_convert_string (request, 0, force_local, str, dest_len, 1)); |
566 } | |
567 | |
568 | |
569 char * | |
570 gftp_filename_to_utf8 (gftp_request * request, const char *str, | |
571 size_t *dest_len) | |
572 { | |
573 return (_do_convert_string (request, 1, 0, str, dest_len, 0)); | |
574 } | |
575 | |
576 | |
577 char * | |
578 gftp_filename_from_utf8 (gftp_request * request, const char *str, | |
579 size_t *dest_len) | |
580 { | |
581 return (_do_convert_string (request, 1, 0, str, dest_len, 1)); | |
555 } | 582 } |
556 | 583 |
557 #else | 584 #else |
558 | 585 |
559 char * | 586 char * |
562 return (NULL); | 589 return (NULL); |
563 } | 590 } |
564 | 591 |
565 | 592 |
566 char * | 593 char * |
567 gftp_string_from_utf8 (gftp_request * request, const char *str, size_t dest_len) | 594 gftp_string_from_utf8 (gftp_request * request, int force_local, const char *str, |
595 size_t dest_len) | |
596 { | |
597 return (NULL); | |
598 } | |
599 | |
600 | |
601 char * | |
602 gftp_filename_to_utf8 (gftp_request * request, const char *str, size_t dest_len) | |
603 { | |
604 return (NULL); | |
605 } | |
606 | |
607 | |
608 char * | |
609 gftp_filename_from_utf8 (gftp_request * request, int force_local, | |
610 const char *str, size_t dest_len) | |
568 { | 611 { |
569 return (NULL); | 612 return (NULL); |
570 } | 613 } |
571 | 614 |
572 #endif | 615 #endif |
616 fle->file = tmpfile; | 659 fle->file = tmpfile; |
617 } | 660 } |
618 | 661 |
619 if (ret >= 0 && fle->file != NULL) | 662 if (ret >= 0 && fle->file != NULL) |
620 { | 663 { |
621 utf8 = gftp_string_to_utf8 (request, fle->file, &destlen); | 664 utf8 = gftp_filename_to_utf8 (request, fle->file, &destlen); |
622 if (utf8 != NULL) | 665 if (utf8 != NULL) |
623 { | 666 { |
624 tmpfile = fle->file; | 667 tmpfile = fle->file; |
625 fle->file = utf8; | 668 fle->file = utf8; |
626 g_free (tmpfile); | 669 g_free (tmpfile); |