Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/lib/util/charset/iconv.c

    r414 r745  
    2424#include "system/filesys.h"
    2525
     26#ifdef strcasecmp
     27#undef strcasecmp
     28#endif
     29
     30#ifdef static_decl_charset
     31static_decl_charset;
     32#endif
    2633
    2734/**
     
    5057static size_t ascii_pull  (void *,const char **, size_t *, char **, size_t *);
    5158static size_t ascii_push  (void *,const char **, size_t *, char **, size_t *);
     59static size_t latin1_push(void *,const char **, size_t *, char **, size_t *);
    5260static size_t utf8_pull   (void *,const char **, size_t *, char **, size_t *);
    5361static size_t utf8_push   (void *,const char **, size_t *, char **, size_t *);
     
    7381
    7482        {"ASCII", ascii_pull, ascii_push},
     83        {"646", ascii_pull, ascii_push},
     84        {"ISO-8859-1", ascii_pull, latin1_push},
    7585        {"UCS2-HEX", ucs2hex_pull, ucs2hex_push}
    7686};
     
    7888static struct charset_functions *charsets = NULL;
    7989
    80 bool charset_register_backend(const void *_funcs)
    81 {
    82         struct charset_functions *funcs = (struct charset_functions *)memdup(_funcs,sizeof(struct charset_functions));
     90static struct charset_functions *find_charset_functions(const char *name)
     91{
    8392        struct charset_functions *c;
    8493
    8594        /* Check whether we already have this charset... */
    8695        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
     105bool 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;
    92122
    93123        funcs->next = funcs->prev = NULL;
     124        DEBUG(5, ("Registered charset %s\n", funcs->name));
    94125        DLIST_ADD(charsets, funcs);
    95126        return true;
    96127}
     128
     129static 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
     144typedef struct os2_iconv_t
     145{
     146    UconvObject from;
     147} os2_iconv_t;
     148
     149iconv_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
    97170
    98171#ifdef HAVE_NATIVE_ICONV
     
    159232}
    160233
    161 int smb_iconv_t_destructor(smb_iconv_t hwd)
    162 { 
     234static int smb_iconv_t_destructor(smb_iconv_t hwd)
     235{
    163236#ifdef HAVE_NATIVE_ICONV
    164237        if (hwd->cd_pull != NULL && hwd->cd_pull != (iconv_t)-1)
     
    180253        int i;
    181254
     255        lazy_initialize_iconv();
     256
    182257        ret = (smb_iconv_t)talloc_named(mem_ctx,
    183258                                        sizeof(*ret),
     
    261336        if (is_utf16(tocode)) {
    262337                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);
    266338                ret->cd_direct = ret->cd_pull;
    267339                ret->cd_pull = NULL;
     
    286358_PUBLIC_ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
    287359{
    288         return smb_iconv_open_ex(talloc_autofree_context(), tocode, fromcode, true);
     360        return smb_iconv_open_ex(NULL, tocode, fromcode, true);
    289361}
    290362
     
    351423}
    352424
     425static 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}
    353451
    354452static size_t ucs2hex_pull(void *cd, const char **inbuf, size_t *inbytesleft,
     
    356454{
    357455        while (*inbytesleft >= 1 && *outbytesleft >= 2) {
    358                 uint_t v;
     456                unsigned int v;
    359457
    360458                if ((*inbuf)[0] != '@') {
Note: See TracChangeset for help on using the changeset viewer.