Changeset 208

Show
Ignore:
Timestamp:
06/14/08 20:45:38 (5 months ago)
Author:
zany
Message:

adding proper unicode functions

Location:
trunk
Files:
2 added
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/configure.in

    r205 r208  
    3232 
    3333AM_ICONV 
     34AC_CHECK_HEADERS([langinfo.h]) 
    3435dnl IRDA_CHECK 
    3536BLUETOOTH_CHECK 
  • trunk/obexftp/Makefile.am

    r193 r208  
    1212                                cache.c cache.h \ 
    1313                                uuid.h obexftp.h \ 
     14                                unicode.c unicode.h \ 
    1415                                bt_kit.c bt_kit.h 
    1516 
  • trunk/obexftp/cache.c

    r192 r208  
    3737#endif 
    3838 
    39 #ifdef HAVE_ICONV 
    40 #include <iconv.h> 
    41 #include <locale.h> 
    42 #include <langinfo.h> 
    43 #endif 
    44  
    4539#include <openobex/obex.h> 
    4640 
     
    4842#include "client.h" 
    4943#include "object.h" 
     44#include "unicode.h" 
    5045#include "cache.h" 
    5146 
     
    261256 
    262257        stat_entry_t *dir_start, *dir; 
    263         int i; 
    264 #ifdef HAVE_ICONV 
    265         iconv_t utf8; 
    266         char *xml_latin1, *xml_end; 
    267         size_t ni, no, nrc; 
    268         int ret; 
    269 #endif 
     258        int ret, n, i; 
     259        char *xml_conv; 
    270260                 
    271261        if (!xml) 
    272262                return NULL; 
    273 #ifdef HAVE_ICONV 
    274         setlocale(LC_CTYPE, ""); 
    275         DEBUG(2, "Iconv to %s\n", nl_langinfo(CODESET)); 
    276         utf8 = iconv_open (nl_langinfo(CODESET), "UTF-8"); 
    277         ni = strlen(xml); 
    278         no = ni; 
    279         xml_latin1 = xml_end = malloc(no+1); 
    280         p = xml; 
    281         if (xml_latin1) { 
    282                 nrc = iconv (utf8, (char* *)&p, &ni, &xml_end, &no); 
    283                 ret = iconv_close (utf8); 
    284                 if (nrc != (size_t)(-1)) { 
    285                         xml = xml_latin1; 
    286                 } else { 
    287                         DEBUG(1, "Iconv conversion error: '%s'\n", p); 
    288                 } 
    289         } 
    290 #endif 
     263        n = strlen(xml) + 1; 
     264        xml_conv = malloc(n); 
     265        ret = Utf8ToChar(xml_conv, xml, n); 
     266        if (ret > 0) { 
     267                xml = xml_conv; 
     268        } else { 
     269                DEBUG(1, "UTF-8 conversion error\n"); 
     270        } 
    291271         
    292272        DEBUG(4, "Converted cache xml: '%s'\n", xml); 
     
    343323        dir->name[0] = '\0'; 
    344324 
    345 #ifdef HAVE_ICONV 
    346         if (xml_latin1) 
    347                 free (xml_latin1); 
    348 #endif 
     325        if (xml_conv) 
     326                free (xml_conv); 
     327 
    349328        return dir_start; 
    350329} 
  • trunk/obexftp/object.c

    r186 r208  
    44        ObexFTP library - language bindings for OBEX file transfer. 
    55 
    6         Copyright (c) 2002 Christian W. Zuckschwerdt <zany@triq.net> 
     6        Copyright (c) 2002-2007 Christian W. Zuckschwerdt <zany@triq.net> 
    77 
    88        ObexFTP is free software; you can redistribute it and/or modify 
     
    2424#include <string.h> 
    2525 
     26#include "unicode.h" 
    2627#include "object.h" 
     28 
    2729 
    2830/** 
     
    99101                } 
    100102 
    101                 ucname_len = OBEX_CharToUnicode(ucname, (uint8_t*)name, ucname_len); 
     103                ucname_len = CharToUnicode(ucname, (uint8_t*)name, ucname_len); 
    102104 
    103105                hv.bs = (const uint8_t *) ucname; 
     
    159161 
    160162        *appstr_p++ = 0x35; 
    161         ucname_len = OBEX_CharToUnicode(appstr_p + 1, (uint8_t*)from, strlen(from)*2 + 2); 
     163        ucname_len = CharToUnicode(appstr_p + 1, (uint8_t*)from, strlen(from)*2 + 2); 
    162164        *appstr_p = ucname_len - 2; /* no trailing 0 */ 
    163165        appstr_p += ucname_len - 1; 
    164166 
    165167        *appstr_p++ = 0x36; 
    166         ucname_len = OBEX_CharToUnicode(appstr_p + 1, (uint8_t*)to, strlen(to)*2 + 2); 
     168        ucname_len = CharToUnicode(appstr_p + 1, (uint8_t*)to, strlen(to)*2 + 2); 
    167169        *appstr_p = ucname_len - 2; /* no trailing 0 */ 
    168170         
     
    211213        } 
    212214 
    213         ucname_len = OBEX_CharToUnicode(ucname, (uint8_t*)name, ucname_len); 
     215        ucname_len = CharToUnicode(ucname, (uint8_t*)name, ucname_len); 
    214216 
    215217        hv.bs = (const uint8_t *) ucname; 
     
    264266                        return NULL; 
    265267                } 
    266                 ucname_len = OBEX_CharToUnicode(ucname, (uint8_t*)name, ucname_len); 
     268                ucname_len = CharToUnicode(ucname, (uint8_t*)name, ucname_len); 
    267269 
    268270                /* apparently the empty name header is meant to be really empty... */ 
     
    318320        } 
    319321 
    320         ucname_len = OBEX_CharToUnicode(ucname, (uint8_t*)name, ucname_len); 
     322        ucname_len = CharToUnicode(ucname, (uint8_t*)name, ucname_len); 
    321323 
    322324        hv.bs = (const uint8_t *) ucname;