コード例 #1
0
ファイル: charcnv.c プロジェクト: ennarr/debian-netatalk
static struct charset_functions* get_charset_functions (charset_t ch)
{
    if (charsets[ch] != NULL)
        return charsets[ch];

    charsets[ch] = find_charset_functions(charset_name(ch));

    return charsets[ch];
}
コード例 #2
0
ファイル: iconv.c プロジェクト: NTmatter/Netatalk
int atalk_register_charset(struct charset_functions *funcs) 
{
	if (!funcs) {
		return -1;
	}

	/* Check whether we already have this charset... */
	if (find_charset_functions(funcs->name)) {
		LOG (log_debug, logtype_default, "Duplicate charset %s, not registering", funcs->name);
		return -2;
	}

	funcs->next = funcs->prev = NULL;
	DLIST_ADD(charsets, funcs);
	return 0;
}
コード例 #3
0
bool smb_register_charset(const struct charset_functions *funcs_in)
{
    struct charset_functions *funcs;

    DEBUG(5, ("Attempting to register new charset %s\n", funcs_in->name));
    /* Check whether we already have this charset... */
    if (find_charset_functions(funcs_in->name)) {
        DEBUG(0, ("Duplicate charset %s, not registering\n", funcs_in->name));
        return false;
    }

    funcs = talloc(NULL, struct charset_functions);
    if (!funcs) {
        DEBUG(0, ("Out of memory duplicating charset %s\n", funcs_in->name));
        return false;
    }
    *funcs = *funcs_in;

    funcs->next = funcs->prev = NULL;
    DEBUG(5, ("Registered charset %s\n", funcs->name));
    DLIST_ADD(charsets, funcs);
    return true;
}
コード例 #4
0
ファイル: iconv.c プロジェクト: NTmatter/Netatalk
/*
  simple iconv_open() wrapper
 */
atalk_iconv_t atalk_iconv_open(const char *tocode, const char *fromcode)
{
	atalk_iconv_t ret;
	struct charset_functions *from, *to;


	lazy_initialize_iconv();
	from = charsets;
	to = charsets;

	ret = (atalk_iconv_t)malloc(sizeof(*ret));
	if (!ret) {
		errno = ENOMEM;
		return (atalk_iconv_t)-1;
	}
	memset(ret, 0, sizeof(*ret));

	ret->from_name = strdup(fromcode);
	ret->to_name = strdup(tocode);

	/* check for the simplest null conversion */
	if (strcasecmp(fromcode, tocode) == 0) {
		ret->direct = iconv_copy;
		return ret;
	}

	/* check if we have a builtin function for this conversion */
	from = find_charset_functions(fromcode);
	if (from) ret->pull = from->pull;
	
	to = find_charset_functions(tocode);
	if (to) ret->push = to->push;

	/* check if we can use iconv for this conversion */
#ifdef HAVE_USABLE_ICONV
	if (!from || (from->flags & CHARSET_ICONV)) {
	  ret->cd_pull = iconv_open(UCS2ICONV, from && from->iname ? from->iname : fromcode);
	  if (ret->cd_pull != (iconv_t)-1) {
	    if (!ret->pull) ret->pull = sys_iconv;
	  } else ret->pull = NULL;
	}
	if (ret->pull) {
	  if (!to || (to->flags & CHARSET_ICONV)) {
	    ret->cd_push = iconv_open(to && to->iname ? to->iname : tocode, UCS2ICONV);
	    if (ret->cd_push != (iconv_t)-1) {
	      if (!ret->push) ret->push = sys_iconv;
	    } else ret->push = NULL;
	  }
	  if (!ret->push && ret->cd_pull) iconv_close((iconv_t)ret->cd_pull);
	}
#endif
	
	if (!ret->push || !ret->pull) {
		SAFE_FREE(ret->from_name);
		SAFE_FREE(ret->to_name);
		SAFE_FREE(ret);
		errno = EINVAL;
		return (atalk_iconv_t)-1;
	}

	/* check for conversion to/from ucs2 */
	if (strcasecmp(fromcode, "UCS-2") == 0) {
	  ret->direct = ret->push;
	  ret->cd_direct = ret->cd_push;
	  ret->cd_push = NULL;
	}
	if (strcasecmp(tocode, "UCS-2") == 0) {
	  ret->direct = ret->pull;
	  ret->cd_direct = ret->cd_pull;
	  ret->cd_pull = NULL;
	}

	return ret;
}