Changeset 745 for trunk/server/lib/util/charset/iconv.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/lib/util/charset/iconv.c
r414 r745 24 24 #include "system/filesys.h" 25 25 26 #ifdef strcasecmp 27 #undef strcasecmp 28 #endif 29 30 #ifdef static_decl_charset 31 static_decl_charset; 32 #endif 26 33 27 34 /** … … 50 57 static size_t ascii_pull (void *,const char **, size_t *, char **, size_t *); 51 58 static size_t ascii_push (void *,const char **, size_t *, char **, size_t *); 59 static size_t latin1_push(void *,const char **, size_t *, char **, size_t *); 52 60 static size_t utf8_pull (void *,const char **, size_t *, char **, size_t *); 53 61 static size_t utf8_push (void *,const char **, size_t *, char **, size_t *); … … 73 81 74 82 {"ASCII", ascii_pull, ascii_push}, 83 {"646", ascii_pull, ascii_push}, 84 {"ISO-8859-1", ascii_pull, latin1_push}, 75 85 {"UCS2-HEX", ucs2hex_pull, ucs2hex_push} 76 86 }; … … 78 88 static struct charset_functions *charsets = NULL; 79 89 80 bool charset_register_backend(const void *_funcs) 81 { 82 struct charset_functions *funcs = (struct charset_functions *)memdup(_funcs,sizeof(struct charset_functions)); 90 static struct charset_functions *find_charset_functions(const char *name) 91 { 83 92 struct charset_functions *c; 84 93 85 94 /* Check whether we already have this charset... */ 86 95 for (c = charsets; c != NULL; c = c->next) { 87 if(!strcasecmp(c->name, funcs->name)) { 88 DEBUG(2, ("Duplicate charset %s, not registering\n", funcs->name)); 89 return false; 90 } 91 } 96 if(strcasecmp(c->name, name) == 0) { 97 return c; 98 } 99 // c = c->next; 100 } 101 102 return NULL; 103 } 104 105 bool smb_register_charset(const struct charset_functions *funcs_in) 106 { 107 struct charset_functions *funcs; 108 109 DEBUG(5, ("Attempting to register new charset %s\n", funcs_in->name)); 110 /* Check whether we already have this charset... */ 111 if (find_charset_functions(funcs_in->name)) { 112 DEBUG(0, ("Duplicate charset %s, not registering\n", funcs_in->name)); 113 return false; 114 } 115 116 funcs = talloc(NULL, struct charset_functions); 117 if (!funcs) { 118 DEBUG(0, ("Out of memory duplicating charset %s\n", funcs_in->name)); 119 return false; 120 } 121 *funcs = *funcs_in; 92 122 93 123 funcs->next = funcs->prev = NULL; 124 DEBUG(5, ("Registered charset %s\n", funcs->name)); 94 125 DLIST_ADD(charsets, funcs); 95 126 return true; 96 127 } 128 129 static void lazy_initialize_iconv(void) 130 { 131 static bool initialized; 132 133 #ifdef static_init_charset 134 if (!initialized) { 135 static_init_charset; 136 initialized = true; 137 } 138 #endif 139 } 140 141 #if defined(__OS2__) && defined(__INNOTEK_LIBC__) 142 #include <uconv.h> 143 144 typedef struct os2_iconv_t 145 { 146 UconvObject from; 147 } os2_iconv_t; 148 149 iconv_t os2_iconv_open (const char *tocode, const char *fromcode) 150 { 151 os2_iconv_t *os2_cd = (os2_iconv_t *)iconv_open(tocode, fromcode); 152 153 if (os2_cd != (iconv_t)(-1)) 154 { 155 /* Assume strings contain pathnames */ 156 uconv_attribute_t attr; 157 158 UniQueryUconvObject(os2_cd->from, &attr, 159 sizeof(uconv_attribute_t), 160 NULL, NULL, NULL ); 161 attr.converttype |= CVTTYPE_PATH; 162 UniSetUconvObject(os2_cd->from, &attr); 163 } 164 165 return (iconv_t)os2_cd; 166 } 167 168 #define iconv_open os2_iconv_open 169 #endif 97 170 98 171 #ifdef HAVE_NATIVE_ICONV … … 159 232 } 160 233 161 int smb_iconv_t_destructor(smb_iconv_t hwd)162 { 234 static int smb_iconv_t_destructor(smb_iconv_t hwd) 235 { 163 236 #ifdef HAVE_NATIVE_ICONV 164 237 if (hwd->cd_pull != NULL && hwd->cd_pull != (iconv_t)-1) … … 180 253 int i; 181 254 255 lazy_initialize_iconv(); 256 182 257 ret = (smb_iconv_t)talloc_named(mem_ctx, 183 258 sizeof(*ret), … … 261 336 if (is_utf16(tocode)) { 262 337 ret->direct = sys_iconv; 263 /* could be set just above - so we need to close iconv */264 if (ret->cd_direct != NULL && ret->cd_direct != (iconv_t)-1)265 iconv_close(ret->cd_direct);266 338 ret->cd_direct = ret->cd_pull; 267 339 ret->cd_pull = NULL; … … 286 358 _PUBLIC_ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) 287 359 { 288 return smb_iconv_open_ex( talloc_autofree_context(), tocode, fromcode, true);360 return smb_iconv_open_ex(NULL, tocode, fromcode, true); 289 361 } 290 362 … … 351 423 } 352 424 425 static size_t latin1_push(void *cd, const char **inbuf, size_t *inbytesleft, 426 char **outbuf, size_t *outbytesleft) 427 { 428 int ir_count=0; 429 430 while (*inbytesleft >= 2 && *outbytesleft >= 1) { 431 (*outbuf)[0] = (*inbuf)[0]; 432 if ((*inbuf)[1]) ir_count++; 433 (*inbytesleft) -= 2; 434 (*outbytesleft) -= 1; 435 (*inbuf) += 2; 436 (*outbuf) += 1; 437 } 438 439 if (*inbytesleft == 1) { 440 errno = EINVAL; 441 return -1; 442 } 443 444 if (*inbytesleft > 1) { 445 errno = E2BIG; 446 return -1; 447 } 448 449 return ir_count; 450 } 353 451 354 452 static size_t ucs2hex_pull(void *cd, const char **inbuf, size_t *inbytesleft, … … 356 454 { 357 455 while (*inbytesleft >= 1 && *outbytesleft >= 2) { 358 u int_t v;456 unsigned int v; 359 457 360 458 if ((*inbuf)[0] != '@') {
Note:
See TracChangeset
for help on using the changeset viewer.