Blame contrib/idn/idnkit-1.0-src/lib/resconf.c

Packit Service ae04f2
#ifndef lint
Packit Service ae04f2
static char *rcsid = "$Id: resconf.c,v 1.1 2003/06/04 00:26:12 marka Exp $";
Packit Service ae04f2
#endif
Packit Service ae04f2
Packit Service ae04f2
/*
Packit Service ae04f2
 * Copyright (c) 2000 Japan Network Information Center.  All rights reserved.
Packit Service ae04f2
 *  
Packit Service ae04f2
 * By using this file, you agree to the terms and conditions set forth bellow.
Packit Service ae04f2
 * 
Packit Service ae04f2
 * 			LICENSE TERMS AND CONDITIONS 
Packit Service ae04f2
 * 
Packit Service ae04f2
 * The following License Terms and Conditions apply, unless a different
Packit Service ae04f2
 * license is obtained from Japan Network Information Center ("JPNIC"),
Packit Service ae04f2
 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
Packit Service ae04f2
 * Chiyoda-ku, Tokyo 101-0047, Japan.
Packit Service ae04f2
 * 
Packit Service ae04f2
 * 1. Use, Modification and Redistribution (including distribution of any
Packit Service ae04f2
 *    modified or derived work) in source and/or binary forms is permitted
Packit Service ae04f2
 *    under this License Terms and Conditions.
Packit Service ae04f2
 * 
Packit Service ae04f2
 * 2. Redistribution of source code must retain the copyright notices as they
Packit Service ae04f2
 *    appear in each source code file, this License Terms and Conditions.
Packit Service ae04f2
 * 
Packit Service ae04f2
 * 3. Redistribution in binary form must reproduce the Copyright Notice,
Packit Service ae04f2
 *    this License Terms and Conditions, in the documentation and/or other
Packit Service ae04f2
 *    materials provided with the distribution.  For the purposes of binary
Packit Service ae04f2
 *    distribution the "Copyright Notice" refers to the following language:
Packit Service ae04f2
 *    "Copyright (c) 2000-2002 Japan Network Information Center.  All rights reserved."
Packit Service ae04f2
 * 
Packit Service ae04f2
 * 4. The name of JPNIC may not be used to endorse or promote products
Packit Service ae04f2
 *    derived from this Software without specific prior written approval of
Packit Service ae04f2
 *    JPNIC.
Packit Service ae04f2
 * 
Packit Service ae04f2
 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
Packit Service ae04f2
 *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit Service ae04f2
 *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
Packit Service ae04f2
 *    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL JPNIC BE LIABLE
Packit Service ae04f2
 *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit Service ae04f2
 *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit Service ae04f2
 *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
Packit Service ae04f2
 *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Packit Service ae04f2
 *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
Packit Service ae04f2
 *    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
Packit Service ae04f2
 *    ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Packit Service ae04f2
 */
Packit Service ae04f2
Packit Service ae04f2
#include <config.h>
Packit Service ae04f2
Packit Service ae04f2
#include <stddef.h>
Packit Service ae04f2
#include <stdarg.h>
Packit Service ae04f2
#include <stdlib.h>
Packit Service ae04f2
#include <stdio.h>
Packit Service ae04f2
#include <string.h>
Packit Service ae04f2
#include <ctype.h>
Packit Service ae04f2
#include <errno.h>
Packit Service ae04f2
#ifdef HAVE_UNISTD_H
Packit Service ae04f2
#include <unistd.h>
Packit Service ae04f2
#endif
Packit Service ae04f2
#ifdef HAVE_PWD_H
Packit Service ae04f2
#include <pwd.h>
Packit Service ae04f2
#endif
Packit Service ae04f2
Packit Service ae04f2
#include <idn/result.h>
Packit Service ae04f2
#include <idn/assert.h>
Packit Service ae04f2
#include <idn/logmacro.h>
Packit Service ae04f2
#include <idn/converter.h>
Packit Service ae04f2
#include <idn/nameprep.h>
Packit Service ae04f2
#include <idn/normalizer.h>
Packit Service ae04f2
#include <idn/checker.h>
Packit Service ae04f2
#include <idn/mapper.h>
Packit Service ae04f2
#include <idn/mapselector.h>
Packit Service ae04f2
#include <idn/delimitermap.h>
Packit Service ae04f2
#include <idn/localencoding.h>
Packit Service ae04f2
#include <idn/resconf.h>
Packit Service ae04f2
#include <idn/debug.h>
Packit Service ae04f2
#include <idn/util.h>
Packit Service ae04f2
Packit Service ae04f2
#ifdef WIN32
Packit Service ae04f2
#define MAX_PATH_SIZE		500	/* a good longer than MAX_PATH */
Packit Service ae04f2
#define IDNVAL_CONFFILE		"ConfFile"
Packit Service ae04f2
#else /* WIN32 */
Packit Service ae04f2
Packit Service ae04f2
#ifndef IDN_RESCONF_DIR
Packit Service ae04f2
#define IDN_RESCONF_DIR		"/etc"
Packit Service ae04f2
#endif
Packit Service ae04f2
#define IDN_RESCONF_FILE	IDN_RESCONF_DIR "/idn.conf"
Packit Service ae04f2
#define IDN_USER_RESCONF_FILE	"/.idnrc"
Packit Service ae04f2
Packit Service ae04f2
#endif /* WIN32 */
Packit Service ae04f2
Packit Service ae04f2
#define MAX_CONF_LINE_LENGTH	255
Packit Service ae04f2
#define MAX_CONF_LINE_ARGS	63
Packit Service ae04f2
Packit Service ae04f2
#define DEFAULT_CONF_NAMEPREP		0x0001
Packit Service ae04f2
#define DEFAULT_CONF_IDN_ENCODING	0x0010
Packit Service ae04f2
#define DEFAULT_CONF_ALL		(DEFAULT_CONF_NAMEPREP | \
Packit Service ae04f2
					DEFAULT_CONF_IDN_ENCODING)
Packit Service ae04f2
Packit Service ae04f2
#define IDN_ENCODING_CURRENT	"Punycode"
Packit Service ae04f2
Packit Service ae04f2
#ifdef ENABLE_MDNKIT_COMPAT
Packit Service ae04f2
#define MDN_RESCONF_FILE	IDN_RESCONF_DIR "/mdn.conf"
Packit Service ae04f2
#endif
Packit Service ae04f2
Packit Service ae04f2
struct idn_resconf {
Packit Service ae04f2
	int local_converter_is_static;
Packit Service ae04f2
	idn_converter_t local_converter;
Packit Service ae04f2
	idn_converter_t idn_converter;
Packit Service ae04f2
        idn_converter_t aux_idn_converter;
Packit Service ae04f2
	idn_normalizer_t normalizer;
Packit Service ae04f2
	idn_checker_t prohibit_checker;
Packit Service ae04f2
	idn_checker_t unassigned_checker;
Packit Service ae04f2
	idn_checker_t bidi_checker;
Packit Service ae04f2
	idn_mapper_t mapper;
Packit Service ae04f2
	idn_mapselector_t local_mapper;
Packit Service ae04f2
	idn_delimitermap_t delimiter_mapper;
Packit Service ae04f2
	int reference_count;
Packit Service ae04f2
};
Packit Service ae04f2
Packit Service ae04f2
static int initialized;
Packit Service ae04f2
Packit Service ae04f2
#ifndef WIN32
Packit Service ae04f2
static const char *	userhomedir(void);
Packit Service ae04f2
#endif
Packit Service ae04f2
static idn_result_t	open_userdefaultfile(FILE **fpp);
Packit Service ae04f2
static idn_result_t	open_defaultfile(FILE **fpp);
Packit Service ae04f2
static idn_result_t	parse_conf(idn_resconf_t ctx, FILE *fp);
Packit Service ae04f2
static idn_result_t	parse_idn_encoding(idn_resconf_t ctx, char *args,
Packit Service ae04f2
					   int lineno);
Packit Service ae04f2
static idn_result_t	parse_local_map(idn_resconf_t ctx, char *args,
Packit Service ae04f2
					int lineno);
Packit Service ae04f2
static idn_result_t	parse_nameprep(idn_resconf_t ctx, char *args,
Packit Service ae04f2
				       int lineno);
Packit Service ae04f2
static int		split_args(char *s, char **av, int max_ac);
Packit Service ae04f2
static void		resetconf(idn_resconf_t ctx);
Packit Service ae04f2
#ifndef WITHOUT_ICONV
Packit Service ae04f2
static idn_result_t	update_local_converter(idn_resconf_t ctx);
Packit Service ae04f2
#endif
Packit Service ae04f2
static idn_result_t	setdefaults_body(idn_resconf_t ctx, int conf_mask);
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_initialize(void) {
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_initialize()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (initialized) {
Packit Service ae04f2
		r = idn_success;
Packit Service ae04f2
		goto ret;
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * Initialize sub modules.
Packit Service ae04f2
	 */
Packit Service ae04f2
	if ((r = idn_converter_initialize()) != idn_success)
Packit Service ae04f2
		goto ret;
Packit Service ae04f2
	if ((r = idn_normalizer_initialize()) != idn_success)
Packit Service ae04f2
		goto ret;
Packit Service ae04f2
	if ((r = idn_checker_initialize()) != idn_success)
Packit Service ae04f2
		goto ret;
Packit Service ae04f2
	if ((r = idn_mapselector_initialize()) != idn_success)
Packit Service ae04f2
		goto ret;
Packit Service ae04f2
	if ((r = idn_mapper_initialize()) != idn_success)
Packit Service ae04f2
		goto ret;
Packit Service ae04f2
Packit Service ae04f2
	r = idn_success;
Packit Service ae04f2
	initialized = 1;
Packit Service ae04f2
ret:
Packit Service ae04f2
	TRACE(("idn_resconf_initialize(): %s\n", idn_result_tostring(r)));
Packit Service ae04f2
	return (r);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_create(idn_resconf_t *ctxp) {
Packit Service ae04f2
	idn_resconf_t ctx = NULL;
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctxp != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_create()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (!initialized) {
Packit Service ae04f2
		r = idn_failure;
Packit Service ae04f2
		goto ret;
Packit Service ae04f2
	}
Packit Service ae04f2
	if ((ctx = malloc(sizeof(*ctx))) == NULL) {
Packit Service ae04f2
		r = idn_nomemory;
Packit Service ae04f2
		goto ret;
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	ctx->local_converter_is_static = 0;
Packit Service ae04f2
	ctx->local_converter = NULL;
Packit Service ae04f2
	ctx->idn_converter = NULL;
Packit Service ae04f2
	ctx->aux_idn_converter = NULL;
Packit Service ae04f2
	ctx->normalizer = NULL;
Packit Service ae04f2
	ctx->prohibit_checker = NULL;
Packit Service ae04f2
	ctx->unassigned_checker = NULL;
Packit Service ae04f2
	ctx->bidi_checker = NULL;
Packit Service ae04f2
	ctx->mapper = NULL;
Packit Service ae04f2
	ctx->local_mapper = NULL;
Packit Service ae04f2
	ctx->reference_count = 1;
Packit Service ae04f2
Packit Service ae04f2
	r = idn_delimitermap_create(&ctx->delimiter_mapper);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		goto ret;
Packit Service ae04f2
Packit Service ae04f2
	*ctxp = ctx;
Packit Service ae04f2
	r = idn_success;
Packit Service ae04f2
ret:
Packit Service ae04f2
	TRACE(("idn_resconf_create(): %s\n", idn_result_tostring(r)));
Packit Service ae04f2
	return (r);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
char *
Packit Service ae04f2
idn_resconf_defaultfile() {
Packit Service ae04f2
#ifdef WIN32
Packit Service ae04f2
	static char default_path[MAX_PATH_SIZE];
Packit Service ae04f2
Packit Service ae04f2
	if (idn__util_getregistrystring(idn__util_hkey_localmachine,
Packit Service ae04f2
					IDNVAL_CONFFILE, default_path,
Packit Service ae04f2
					sizeof(default_path))) {
Packit Service ae04f2
		return (default_path);
Packit Service ae04f2
	} else {
Packit Service ae04f2
		return (NULL);
Packit Service ae04f2
	}
Packit Service ae04f2
#else
Packit Service ae04f2
	return (IDN_RESCONF_FILE);
Packit Service ae04f2
#endif
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
#ifndef WIN32
Packit Service ae04f2
static const char *
Packit Service ae04f2
userhomedir() {
Packit Service ae04f2
	uid_t uid;
Packit Service ae04f2
	struct passwd *pwd;
Packit Service ae04f2
Packit Service ae04f2
	uid = getuid();
Packit Service ae04f2
	pwd = getpwuid(uid);
Packit Service ae04f2
	if (pwd == NULL) {
Packit Service ae04f2
		return (NULL);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (pwd->pw_dir);
Packit Service ae04f2
}
Packit Service ae04f2
#endif
Packit Service ae04f2
Packit Service ae04f2
static idn_result_t
Packit Service ae04f2
open_userdefaultfile(FILE **fpp) {
Packit Service ae04f2
#ifdef WIN32
Packit Service ae04f2
	char user_path[MAX_PATH_SIZE];
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("open_userdefaultfile()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (idn__util_getregistrystring(idn__util_hkey_currentuser,
Packit Service ae04f2
					IDNVAL_CONFFILE, user_path,
Packit Service ae04f2
					sizeof(user_path)) == 0) {
Packit Service ae04f2
		return (idn_nofile);
Packit Service ae04f2
	}
Packit Service ae04f2
	*fpp = fopen(user_path, "r");
Packit Service ae04f2
	if (*fpp == NULL) {
Packit Service ae04f2
		return (idn_nofile);
Packit Service ae04f2
	}
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
#else /* WIN32 */
Packit Service ae04f2
	const char *homedir;
Packit Service ae04f2
	char *file;
Packit Service ae04f2
	int len;
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("open_userdefaultfile()\n"));
Packit Service ae04f2
Packit Service ae04f2
	homedir = userhomedir();
Packit Service ae04f2
	len = strlen(IDN_USER_RESCONF_FILE) + 1;
Packit Service ae04f2
	if (homedir != NULL) {
Packit Service ae04f2
		len += strlen(homedir);
Packit Service ae04f2
	} else {
Packit Service ae04f2
		return (idn_notfound);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	file = (char *)malloc(sizeof(char) * len);
Packit Service ae04f2
	if (file == NULL) {
Packit Service ae04f2
		WARNING(("open_userdefaultfile(): malloc failed\n"));
Packit Service ae04f2
		return (idn_nomemory);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	(void)strcpy(file, homedir);
Packit Service ae04f2
	strcat(file, IDN_USER_RESCONF_FILE);
Packit Service ae04f2
	
Packit Service ae04f2
	*fpp = fopen(file, "r");
Packit Service ae04f2
	free(file);
Packit Service ae04f2
	if (*fpp == NULL) {
Packit Service ae04f2
		return (idn_nofile);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
#endif /* WIN32 */
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static idn_result_t
Packit Service ae04f2
open_defaultfile(FILE **fpp) {
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
	const char *file;
Packit Service ae04f2
Packit Service ae04f2
	r = open_userdefaultfile(fpp);
Packit Service ae04f2
	if (r == idn_nofile || r == idn_notfound) {
Packit Service ae04f2
		TRACE(("open_defaultfile: "
Packit Service ae04f2
		       "cannot open user configuration file\n"));
Packit Service ae04f2
		file = idn_resconf_defaultfile();
Packit Service ae04f2
		*fpp = fopen(file, "r");
Packit Service ae04f2
#ifdef ENABLE_MDNKIT_COMPAT
Packit Service ae04f2
		if (*fpp == NULL)
Packit Service ae04f2
			*fpp = fopen(MDN_RESCONF_FILE, "r");
Packit Service ae04f2
#endif
Packit Service ae04f2
		if (*fpp == NULL) {
Packit Service ae04f2
			TRACE(("open_defaultfile: "
Packit Service ae04f2
			       "cannot open system configuration file\n"));
Packit Service ae04f2
			return (idn_nofile);
Packit Service ae04f2
		}
Packit Service ae04f2
	} else if (r != idn_success) {
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_loadfile(idn_resconf_t ctx, const char *file) {
Packit Service ae04f2
	FILE *fp = NULL;
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_loadfile(file=%s)\n",
Packit Service ae04f2
	      file == NULL ? "<null>" : file));
Packit Service ae04f2
Packit Service ae04f2
	resetconf(ctx);
Packit Service ae04f2
	r = idn_delimitermap_create(&ctx->delimiter_mapper);
Packit Service ae04f2
	if (r != idn_success) {
Packit Service ae04f2
		goto ret;
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	if (file == NULL) {
Packit Service ae04f2
		r = open_defaultfile(&fp);
Packit Service ae04f2
		if (r == idn_nofile || r == idn_notfound) {
Packit Service ae04f2
			r = setdefaults_body(ctx, 0);
Packit Service ae04f2
			goto ret;
Packit Service ae04f2
		} else if (r != idn_success) {
Packit Service ae04f2
			goto ret;
Packit Service ae04f2
		}
Packit Service ae04f2
	} else {
Packit Service ae04f2
		fp = fopen(file, "r");
Packit Service ae04f2
		if (fp == NULL) {
Packit Service ae04f2
			TRACE(("idn_resconf_loadfile: cannot open %-.40s\n",
Packit Service ae04f2
			       file));
Packit Service ae04f2
			r = idn_nofile;
Packit Service ae04f2
			goto ret;
Packit Service ae04f2
		}
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	r = parse_conf(ctx, fp);
Packit Service ae04f2
	fclose(fp);
Packit Service ae04f2
Packit Service ae04f2
ret:
Packit Service ae04f2
	TRACE(("idn_resconf_loadfile(): %s\n", idn_result_tostring(r)));
Packit Service ae04f2
	return (r);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_destroy(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_destroy()\n"));
Packit Service ae04f2
Packit Service ae04f2
	ctx->reference_count--;
Packit Service ae04f2
	if (ctx->reference_count <= 0) {
Packit Service ae04f2
		resetconf(ctx);
Packit Service ae04f2
		free(ctx);
Packit Service ae04f2
		TRACE(("idn_resconf_destroy: the object is destroyed\n"));
Packit Service ae04f2
	} else {
Packit Service ae04f2
		TRACE(("idn_resconf_destroy(): "
Packit Service ae04f2
		       "update reference count (%d->%d)\n",
Packit Service ae04f2
		       ctx->reference_count + 1, ctx->reference_count));
Packit Service ae04f2
	}
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_incrref(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_incrref()\n"));
Packit Service ae04f2
	TRACE(("idn_resconf_incrref: update reference count (%d->%d)\n",
Packit Service ae04f2
		ctx->reference_count, ctx->reference_count + 1));
Packit Service ae04f2
Packit Service ae04f2
	ctx->reference_count++;
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_converter_t
Packit Service ae04f2
idn_resconf_getalternateconverter(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_getalternateconverter()\n"));
Packit Service ae04f2
Packit Service ae04f2
	return (idn_resconf_getidnconverter(ctx));
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_delimitermap_t
Packit Service ae04f2
idn_resconf_getdelimitermap(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_getdelimitermap()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->delimiter_mapper != NULL)
Packit Service ae04f2
		idn_delimitermap_incrref(ctx->delimiter_mapper);
Packit Service ae04f2
	return (ctx->delimiter_mapper);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_converter_t
Packit Service ae04f2
idn_resconf_getidnconverter(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_getidnconverter()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->idn_converter != NULL)
Packit Service ae04f2
		idn_converter_incrref(ctx->idn_converter);
Packit Service ae04f2
	return (ctx->idn_converter);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_converter_t
Packit Service ae04f2
idn_resconf_getauxidnconverter(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_getauxidnconverter()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->aux_idn_converter != NULL)
Packit Service ae04f2
		idn_converter_incrref(ctx->aux_idn_converter);
Packit Service ae04f2
	return (ctx->aux_idn_converter);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_converter_t
Packit Service ae04f2
idn_resconf_getlocalconverter(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_getlocalconverter()\n"));
Packit Service ae04f2
Packit Service ae04f2
#ifdef WITHOUT_ICONV
Packit Service ae04f2
	return NULL;
Packit Service ae04f2
Packit Service ae04f2
#else /* WITHOUT_ICONV */
Packit Service ae04f2
	if (update_local_converter(ctx) != idn_success)
Packit Service ae04f2
		return (NULL);
Packit Service ae04f2
Packit Service ae04f2
	idn_converter_incrref(ctx->local_converter);
Packit Service ae04f2
	return (ctx->local_converter);
Packit Service ae04f2
Packit Service ae04f2
#endif /* WITHOUT_ICONV */
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_mapselector_t
Packit Service ae04f2
idn_resconf_getlocalmapselector(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_getlocalmapselector()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->local_mapper != NULL)
Packit Service ae04f2
		idn_mapselector_incrref(ctx->local_mapper);
Packit Service ae04f2
	return (ctx->local_mapper);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_mapper_t
Packit Service ae04f2
idn_resconf_getmapper(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_getmapper()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->mapper != NULL)
Packit Service ae04f2
		idn_mapper_incrref(ctx->mapper);
Packit Service ae04f2
	return (ctx->mapper);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_normalizer_t
Packit Service ae04f2
idn_resconf_getnormalizer(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_getnormalizer()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->normalizer != NULL)
Packit Service ae04f2
		idn_normalizer_incrref(ctx->normalizer);
Packit Service ae04f2
	return (ctx->normalizer);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_checker_t
Packit Service ae04f2
idn_resconf_getprohibitchecker(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_getprohibitchecker()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->prohibit_checker != NULL)
Packit Service ae04f2
		idn_checker_incrref(ctx->prohibit_checker);
Packit Service ae04f2
	return (ctx->prohibit_checker);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_checker_t
Packit Service ae04f2
idn_resconf_getunassignedchecker(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_getunassignedchecker()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->unassigned_checker != NULL)
Packit Service ae04f2
		idn_checker_incrref(ctx->unassigned_checker);
Packit Service ae04f2
	return (ctx->unassigned_checker);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_checker_t
Packit Service ae04f2
idn_resconf_getbidichecker(idn_resconf_t ctx) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_getbidichecker()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->bidi_checker != NULL)
Packit Service ae04f2
		idn_checker_incrref(ctx->bidi_checker);
Packit Service ae04f2
	return (ctx->bidi_checker);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_setalternateconverter(idn_resconf_t ctx,
Packit Service ae04f2
				  idn_converter_t alternate_converter) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setalternateconverter()\n"));
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_setdelimitermap(idn_resconf_t ctx,
Packit Service ae04f2
			    idn_delimitermap_t delimiter_mapper) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setdelimitermap()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->delimiter_mapper != NULL)
Packit Service ae04f2
		idn_delimitermap_destroy(ctx->delimiter_mapper);
Packit Service ae04f2
	ctx->delimiter_mapper = delimiter_mapper;
Packit Service ae04f2
	if (delimiter_mapper != NULL)
Packit Service ae04f2
		idn_delimitermap_incrref(ctx->delimiter_mapper);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_setidnconverter(idn_resconf_t ctx, 
Packit Service ae04f2
			    idn_converter_t idn_converter) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setidnconverter()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->idn_converter != NULL)
Packit Service ae04f2
		idn_converter_destroy(ctx->idn_converter);
Packit Service ae04f2
	ctx->idn_converter = idn_converter;
Packit Service ae04f2
	if (idn_converter != NULL)
Packit Service ae04f2
		idn_converter_incrref(ctx->idn_converter);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_setauxidnconverter(idn_resconf_t ctx,
Packit Service ae04f2
				idn_converter_t aux_idn_converter) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setauxidnconverter()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->aux_idn_converter != NULL)
Packit Service ae04f2
		idn_converter_destroy(ctx->aux_idn_converter);
Packit Service ae04f2
	ctx->aux_idn_converter = aux_idn_converter;
Packit Service ae04f2
	if (aux_idn_converter != NULL)
Packit Service ae04f2
		idn_converter_incrref(ctx->aux_idn_converter);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_setlocalconverter(idn_resconf_t ctx,
Packit Service ae04f2
			      idn_converter_t local_converter) {
Packit Service ae04f2
#ifndef WITHOUT_ICONV
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setlocalconverter()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->local_converter != NULL) {
Packit Service ae04f2
		idn_converter_destroy(ctx->local_converter);
Packit Service ae04f2
		ctx->local_converter = NULL;
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	if (local_converter == NULL)
Packit Service ae04f2
		ctx->local_converter_is_static = 0;
Packit Service ae04f2
	else {
Packit Service ae04f2
		ctx->local_converter = local_converter;
Packit Service ae04f2
		idn_converter_incrref(local_converter);
Packit Service ae04f2
		ctx->local_converter_is_static = 1;
Packit Service ae04f2
	}
Packit Service ae04f2
#endif /* WITHOUT_ICONV */
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_setlocalmapselector(idn_resconf_t ctx,
Packit Service ae04f2
				idn_mapselector_t local_mapper) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setlocalmapselector()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->local_mapper != NULL)
Packit Service ae04f2
		idn_mapselector_destroy(ctx->local_mapper);
Packit Service ae04f2
	ctx->local_mapper = local_mapper;
Packit Service ae04f2
	if (local_mapper != NULL)
Packit Service ae04f2
		idn_mapselector_incrref(ctx->local_mapper);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_setmapper(idn_resconf_t ctx, idn_mapper_t mapper) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setmapper()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->mapper != NULL)
Packit Service ae04f2
		idn_mapper_destroy(ctx->mapper);
Packit Service ae04f2
	ctx->mapper = mapper;
Packit Service ae04f2
	if (mapper != NULL)
Packit Service ae04f2
		idn_mapper_incrref(ctx->mapper);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_setnormalizer(idn_resconf_t ctx, idn_normalizer_t normalizer) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setnormalizer()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->normalizer != NULL)
Packit Service ae04f2
		idn_normalizer_destroy(ctx->normalizer);
Packit Service ae04f2
	ctx->normalizer = normalizer;
Packit Service ae04f2
	if (normalizer != NULL)
Packit Service ae04f2
		idn_normalizer_incrref(ctx->normalizer);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_setprohibitchecker(idn_resconf_t ctx,
Packit Service ae04f2
			       idn_checker_t prohibit_checker) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setprohibitchecker()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->prohibit_checker != NULL)
Packit Service ae04f2
		idn_checker_destroy(ctx->prohibit_checker);
Packit Service ae04f2
	ctx->prohibit_checker = prohibit_checker;
Packit Service ae04f2
	if (prohibit_checker != NULL)
Packit Service ae04f2
		idn_checker_incrref(ctx->prohibit_checker);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_setunassignedchecker(idn_resconf_t ctx,
Packit Service ae04f2
				 idn_checker_t unassigned_checker) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setunassignedchecker()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->unassigned_checker != NULL)
Packit Service ae04f2
		idn_checker_destroy(ctx->unassigned_checker);
Packit Service ae04f2
	ctx->unassigned_checker = unassigned_checker;
Packit Service ae04f2
	if (unassigned_checker != NULL)
Packit Service ae04f2
		idn_checker_incrref(ctx->unassigned_checker);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
idn_resconf_setbidichecker(idn_resconf_t ctx,
Packit Service ae04f2
			   idn_checker_t bidi_checker) {
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setbidichecker()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->bidi_checker != NULL)
Packit Service ae04f2
		idn_checker_destroy(ctx->bidi_checker);
Packit Service ae04f2
	ctx->bidi_checker = bidi_checker;
Packit Service ae04f2
	if (bidi_checker != NULL)
Packit Service ae04f2
		idn_checker_incrref(ctx->bidi_checker);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_setnameprepversion(idn_resconf_t ctx, const char *version)
Packit Service ae04f2
{
Packit Service ae04f2
	char prohibit_scheme_name[MAX_CONF_LINE_LENGTH + 1];
Packit Service ae04f2
	char unassigned_scheme_name[MAX_CONF_LINE_LENGTH + 1];
Packit Service ae04f2
	char bidi_scheme_name[MAX_CONF_LINE_LENGTH + 1];
Packit Service ae04f2
	idn_mapper_t mapper = NULL;
Packit Service ae04f2
	idn_normalizer_t normalizer = NULL;
Packit Service ae04f2
	idn_checker_t prohibit_checker = NULL;
Packit Service ae04f2
	idn_checker_t unassigned_checker = NULL;
Packit Service ae04f2
	idn_checker_t bidi_checker = NULL;
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctx != NULL && version != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setnameprepversion()\n"));
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * Set canonical scheme names.
Packit Service ae04f2
	 */
Packit Service ae04f2
	if (strlen(version) + strlen(IDN_CHECKER_PROHIBIT_PREFIX)
Packit Service ae04f2
	    > MAX_CONF_LINE_LENGTH) {
Packit Service ae04f2
		r = idn_invalid_name;
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
	}
Packit Service ae04f2
	sprintf(prohibit_scheme_name, "%s%s",
Packit Service ae04f2
	        IDN_CHECKER_PROHIBIT_PREFIX, version);
Packit Service ae04f2
Packit Service ae04f2
	if (strlen(version) + strlen(IDN_CHECKER_UNASSIGNED_PREFIX)
Packit Service ae04f2
	    > MAX_CONF_LINE_LENGTH) {
Packit Service ae04f2
		r = idn_invalid_name;
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
	}
Packit Service ae04f2
	sprintf(unassigned_scheme_name, "%s%s",
Packit Service ae04f2
	        IDN_CHECKER_UNASSIGNED_PREFIX, version);
Packit Service ae04f2
Packit Service ae04f2
	if (strlen(version) + strlen(IDN_CHECKER_BIDI_PREFIX)
Packit Service ae04f2
	    > MAX_CONF_LINE_LENGTH) {
Packit Service ae04f2
		r = idn_invalid_name;
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
	}
Packit Service ae04f2
	sprintf(bidi_scheme_name, "%s%s",
Packit Service ae04f2
	        IDN_CHECKER_BIDI_PREFIX, version);
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * Create objects.
Packit Service ae04f2
	 */
Packit Service ae04f2
	r = idn_mapper_create(&mapper);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
	r = idn_normalizer_create(&normalizer);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
	r = idn_checker_create(&prohibit_checker);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
	r = idn_checker_create(&unassigned_checker);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
	r = idn_checker_create(&bidi_checker);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
Packit Service ae04f2
	r = idn_mapper_add(mapper, version);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
	r = idn_normalizer_add(normalizer, version);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
	r = idn_checker_add(prohibit_checker, prohibit_scheme_name);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
	r = idn_checker_add(unassigned_checker, unassigned_scheme_name);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
	r = idn_checker_add(bidi_checker, bidi_scheme_name);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		goto failure;
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * Set the objects.
Packit Service ae04f2
	 */
Packit Service ae04f2
	idn_resconf_setmapper(ctx, mapper);
Packit Service ae04f2
	idn_resconf_setnormalizer(ctx, normalizer);
Packit Service ae04f2
	idn_resconf_setprohibitchecker(ctx, prohibit_checker);
Packit Service ae04f2
	idn_resconf_setunassignedchecker(ctx, unassigned_checker);
Packit Service ae04f2
	idn_resconf_setbidichecker(ctx, bidi_checker);
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * Destroy the objects.
Packit Service ae04f2
	 */
Packit Service ae04f2
	idn_mapper_destroy(mapper);
Packit Service ae04f2
	idn_normalizer_destroy(normalizer);
Packit Service ae04f2
	idn_checker_destroy(prohibit_checker);
Packit Service ae04f2
	idn_checker_destroy(unassigned_checker);
Packit Service ae04f2
	idn_checker_destroy(bidi_checker);
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
Packit Service ae04f2
failure:
Packit Service ae04f2
	if (mapper != NULL)
Packit Service ae04f2
		idn_mapper_destroy(mapper);
Packit Service ae04f2
	if (normalizer != NULL)
Packit Service ae04f2
		idn_normalizer_destroy(normalizer);
Packit Service ae04f2
	if (prohibit_checker != NULL)
Packit Service ae04f2
		idn_checker_destroy(prohibit_checker);
Packit Service ae04f2
	if (unassigned_checker != NULL)
Packit Service ae04f2
		idn_checker_destroy(unassigned_checker);
Packit Service ae04f2
	if (bidi_checker != NULL)
Packit Service ae04f2
		idn_checker_destroy(bidi_checker);
Packit Service ae04f2
Packit Service ae04f2
	return (r);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_setalternateconvertername(idn_resconf_t ctx, const char *name,
Packit Service ae04f2
				      int flags) {
Packit Service ae04f2
	assert(ctx != NULL && name != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setalternateconvertername(name=%s, flags=%d)\n",
Packit Service ae04f2
	      name, flags));
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_setidnconvertername(idn_resconf_t ctx, const char *name,
Packit Service ae04f2
				int flags) {
Packit Service ae04f2
	idn_converter_t idn_converter;
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctx != NULL && name != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setidnconvertername(name=%s, flags=%d)\n",
Packit Service ae04f2
	      name, flags));
Packit Service ae04f2
Packit Service ae04f2
	r = idn_converter_create(name, &idn_converter, flags);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		return (r);
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->idn_converter != NULL)
Packit Service ae04f2
		idn_converter_destroy(ctx->idn_converter);
Packit Service ae04f2
	ctx->idn_converter = idn_converter;
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_setauxidnconvertername(idn_resconf_t ctx, const char *name,
Packit Service ae04f2
				    int flags) {
Packit Service ae04f2
	idn_converter_t aux_idn_converter;
Packit Service ae04f2
	const char *old_name;
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctx != NULL && name != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setauxidnconvertername(name=%s, flags=%d)\n",
Packit Service ae04f2
	      name, flags));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->aux_idn_converter != NULL) {
Packit Service ae04f2
	    old_name = idn_converter_localencoding(ctx->aux_idn_converter);
Packit Service ae04f2
	    if (old_name != NULL && strcmp(old_name, name) == 0)
Packit Service ae04f2
		return (idn_success);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	r = idn_converter_create(name, &aux_idn_converter, flags);
Packit Service ae04f2
	if (r != idn_success)
Packit Service ae04f2
		return (r);
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->aux_idn_converter != NULL)
Packit Service ae04f2
		idn_converter_destroy(ctx->aux_idn_converter);
Packit Service ae04f2
	ctx->aux_idn_converter = aux_idn_converter;
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_setlocalconvertername(idn_resconf_t ctx, const char *name,
Packit Service ae04f2
				  int flags) {
Packit Service ae04f2
#ifdef WITHOUT_ICONV
Packit Service ae04f2
	return idn_failure;
Packit Service ae04f2
Packit Service ae04f2
#else /* WITHOUT_ICONV */
Packit Service ae04f2
	idn_converter_t local_converter;
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setlocalconvertername(name=%s, flags=%d)\n",
Packit Service ae04f2
	      name == NULL ? "<null>" : name, flags));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->local_converter != NULL) {
Packit Service ae04f2
		idn_converter_destroy(ctx->local_converter);
Packit Service ae04f2
		ctx->local_converter = NULL;
Packit Service ae04f2
	}
Packit Service ae04f2
	ctx->local_converter_is_static = 0;
Packit Service ae04f2
Packit Service ae04f2
	if (name != NULL) {
Packit Service ae04f2
		r = idn_converter_create(name, &local_converter, flags);
Packit Service ae04f2
		if (r != idn_success)
Packit Service ae04f2
			return (r);
Packit Service ae04f2
		ctx->local_converter = local_converter;
Packit Service ae04f2
		ctx->local_converter_is_static = 1;
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
Packit Service ae04f2
#endif /* WITHOUT_ICONV */
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_addalldelimitermapucs(idn_resconf_t ctx, unsigned long *v,
Packit Service ae04f2
				  int nv) {
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_addalldelimitermapucs(nv=%d)\n", nv));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->delimiter_mapper == NULL) {
Packit Service ae04f2
		r = idn_delimitermap_create(&(ctx->delimiter_mapper));
Packit Service ae04f2
		if (r != idn_success)
Packit Service ae04f2
			return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	r = idn_delimitermap_addall(ctx->delimiter_mapper, v, nv);
Packit Service ae04f2
	return (r);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_addalllocalmapselectornames(idn_resconf_t ctx, const char *tld,
Packit Service ae04f2
					const char **names, int nnames) {
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctx != NULL && names != NULL && tld != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_addalllocalmapselectorname(tld=%s, nnames=%d)\n",
Packit Service ae04f2
	      tld, nnames));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->local_mapper == NULL) {
Packit Service ae04f2
		r = idn_mapselector_create(&(ctx->local_mapper));
Packit Service ae04f2
		if (r != idn_success)
Packit Service ae04f2
			return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	r = idn_mapselector_addall(ctx->local_mapper, tld, names, nnames);
Packit Service ae04f2
	return (r);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_addallmappernames(idn_resconf_t ctx, const char **names,
Packit Service ae04f2
			      int nnames) {
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctx != NULL && names != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_addallmappername()\n"));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->mapper == NULL) {
Packit Service ae04f2
		r = idn_mapper_create(&(ctx->mapper));
Packit Service ae04f2
		if (r != idn_success)
Packit Service ae04f2
			return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	r = idn_mapper_addall(ctx->mapper, names, nnames);
Packit Service ae04f2
	return (r);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_addallnormalizernames(idn_resconf_t ctx, const char **names,
Packit Service ae04f2
				  int nnames) {
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctx != NULL && names != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_addallnormalizername(nnames=%d)\n", nnames));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->normalizer == NULL) {
Packit Service ae04f2
		r = idn_normalizer_create(&(ctx->normalizer));
Packit Service ae04f2
		if (r != idn_success)
Packit Service ae04f2
			return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	r = idn_normalizer_addall(ctx->normalizer, names, nnames);
Packit Service ae04f2
	return (r);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_addallprohibitcheckernames(idn_resconf_t ctx, const char **names,
Packit Service ae04f2
				       int nnames) {
Packit Service ae04f2
	char long_name[MAX_CONF_LINE_LENGTH + 1];
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
	int i;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctx != NULL && names != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_addallprohibitcheckername(nnames=%d)\n", nnames));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->prohibit_checker == NULL) {
Packit Service ae04f2
		r = idn_checker_create(&(ctx->prohibit_checker));
Packit Service ae04f2
		if (r != idn_success)
Packit Service ae04f2
			return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	for (i = 0; i < nnames; i++, names++) {
Packit Service ae04f2
		if (strlen(*names) + strlen(IDN_CHECKER_PROHIBIT_PREFIX)
Packit Service ae04f2
			> MAX_CONF_LINE_LENGTH) {
Packit Service ae04f2
			return (idn_invalid_name);
Packit Service ae04f2
		}
Packit Service ae04f2
		strcpy(long_name, IDN_CHECKER_PROHIBIT_PREFIX);
Packit Service ae04f2
		strcat(long_name, *names);
Packit Service ae04f2
Packit Service ae04f2
		r = idn_checker_add(ctx->prohibit_checker, long_name);
Packit Service ae04f2
		if (r != idn_success)
Packit Service ae04f2
			return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_addallunassignedcheckernames(idn_resconf_t ctx, const char **names,
Packit Service ae04f2
					 int nnames) {
Packit Service ae04f2
	char long_name[MAX_CONF_LINE_LENGTH + 1];
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
	int i;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctx != NULL && names != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_addallunassignedcheckername(nnames=%d)\n",
Packit Service ae04f2
	      nnames));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->unassigned_checker == NULL) {
Packit Service ae04f2
		r = idn_checker_create(&(ctx->unassigned_checker));
Packit Service ae04f2
		if (r != idn_success)
Packit Service ae04f2
			return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	for (i = 0; i < nnames; i++, names++) {
Packit Service ae04f2
		if (strlen(*names) + strlen(IDN_CHECKER_UNASSIGNED_PREFIX)
Packit Service ae04f2
			> MAX_CONF_LINE_LENGTH) {
Packit Service ae04f2
			return (idn_invalid_name);
Packit Service ae04f2
		}
Packit Service ae04f2
		strcpy(long_name, IDN_CHECKER_UNASSIGNED_PREFIX);
Packit Service ae04f2
		strcat(long_name, *names);
Packit Service ae04f2
Packit Service ae04f2
		r = idn_checker_add(ctx->unassigned_checker, long_name);
Packit Service ae04f2
		if (r != idn_success)
Packit Service ae04f2
			return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_addallbidicheckernames(idn_resconf_t ctx, const char **names,
Packit Service ae04f2
				   int nnames) {
Packit Service ae04f2
	char long_name[MAX_CONF_LINE_LENGTH + 1];
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
	int i;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctx != NULL && names != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_addallbidicheckername(nnames=%d)\n", nnames));
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->bidi_checker == NULL) {
Packit Service ae04f2
		r = idn_checker_create(&(ctx->bidi_checker));
Packit Service ae04f2
		if (r != idn_success)
Packit Service ae04f2
			return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	for (i = 0; i < nnames; i++, names++) {
Packit Service ae04f2
		if (strlen(*names) + strlen(IDN_CHECKER_BIDI_PREFIX)
Packit Service ae04f2
			> MAX_CONF_LINE_LENGTH) {
Packit Service ae04f2
			return (idn_invalid_name);
Packit Service ae04f2
		}
Packit Service ae04f2
		strcpy(long_name, IDN_CHECKER_BIDI_PREFIX);
Packit Service ae04f2
		strcat(long_name, *names);
Packit Service ae04f2
Packit Service ae04f2
		r = idn_checker_add(ctx->bidi_checker, long_name);
Packit Service ae04f2
		if (r != idn_success)
Packit Service ae04f2
			return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static idn_result_t
Packit Service ae04f2
parse_conf(idn_resconf_t ctx, FILE *fp) {
Packit Service ae04f2
	char line[MAX_CONF_LINE_LENGTH + 1];
Packit Service ae04f2
	int lineno = 0;
Packit Service ae04f2
	char *argv[3];
Packit Service ae04f2
	int argc;
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
	int conf_mask = 0;
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("parse_conf()\n"));
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * Parse config file.  parsing of 'idn-encoding' line is
Packit Service ae04f2
	 * postponed because 'alias-file' line must be processed
Packit Service ae04f2
	 * before them.
Packit Service ae04f2
	 */
Packit Service ae04f2
	while (fgets(line, sizeof(line), fp) != NULL) {
Packit Service ae04f2
		char *newline;
Packit Service ae04f2
Packit Service ae04f2
		lineno++;
Packit Service ae04f2
		newline = strpbrk(line, "\r\n");
Packit Service ae04f2
		if (newline != NULL)
Packit Service ae04f2
			*newline = '\0';
Packit Service ae04f2
		else if (fgetc(fp) != EOF) {
Packit Service ae04f2
			ERROR(("libidnkit: too long line \"%-.30s\", "
Packit Service ae04f2
			       "line %d\n", line, lineno));
Packit Service ae04f2
			return (idn_invalid_syntax);
Packit Service ae04f2
		}
Packit Service ae04f2
Packit Service ae04f2
		argc = split_args(line, argv, 2);
Packit Service ae04f2
		if (argc == -1) {
Packit Service ae04f2
			ERROR(("libidnkit: syntax error, line %d\n", lineno));
Packit Service ae04f2
			return (idn_invalid_syntax);
Packit Service ae04f2
		} else if (argc == 0 || argv[0][0] == '#') {
Packit Service ae04f2
			continue;
Packit Service ae04f2
		} else if (argc == 1) {
Packit Service ae04f2
			ERROR(("libidnkit: syntax error, line %d\n", lineno));
Packit Service ae04f2
			return (idn_invalid_syntax);
Packit Service ae04f2
		}
Packit Service ae04f2
Packit Service ae04f2
		if (strcmp(argv[0], "idn-encoding") == 0) {
Packit Service ae04f2
			if (conf_mask & DEFAULT_CONF_IDN_ENCODING) {
Packit Service ae04f2
				ERROR(("libidnkit: \"%s\" redefined, "
Packit Service ae04f2
				       "line %d\n", argv[0], lineno));
Packit Service ae04f2
				r = idn_invalid_syntax;
Packit Service ae04f2
			} else {
Packit Service ae04f2
				conf_mask |= DEFAULT_CONF_IDN_ENCODING;
Packit Service ae04f2
				r = parse_idn_encoding(ctx, argv[1], lineno);
Packit Service ae04f2
			}
Packit Service ae04f2
		} else if (strcmp(argv[0], "local-map") == 0) {
Packit Service ae04f2
			r = parse_local_map(ctx, argv[1], lineno);
Packit Service ae04f2
Packit Service ae04f2
		} else if (strcmp(argv[0], "nameprep") == 0) {
Packit Service ae04f2
			if (conf_mask & DEFAULT_CONF_NAMEPREP) {
Packit Service ae04f2
				ERROR(("libidnkit: \"%s\" redefined, "
Packit Service ae04f2
				       "line %d\n", argv[0], lineno));
Packit Service ae04f2
				r = idn_invalid_syntax;
Packit Service ae04f2
			} else {
Packit Service ae04f2
				conf_mask |= DEFAULT_CONF_NAMEPREP;
Packit Service ae04f2
				r = parse_nameprep(ctx, argv[1], lineno);
Packit Service ae04f2
			}
Packit Service ae04f2
		} else if (strcmp(argv[0], "nameprep-map") == 0 ||
Packit Service ae04f2
			   strcmp(argv[0], "nameprep-normalize") == 0 ||
Packit Service ae04f2
			   strcmp(argv[0], "nameprep-prohibit") == 0 ||
Packit Service ae04f2
			   strcmp(argv[0], "nameprep-unassigned") == 0 ||
Packit Service ae04f2
			   strcmp(argv[0], "alias-file") == 0 ||
Packit Service ae04f2
			   strcmp(argv[0], "encoding-alias-file") == 0 ||
Packit Service ae04f2
			   strcmp(argv[0], "normalize") == 0 ||
Packit Service ae04f2
			   strcmp(argv[0], "server-encoding") == 0 ||
Packit Service ae04f2
		           strcmp(argv[0], "alternate-encoding") == 0 ||
Packit Service ae04f2
			   strcmp(argv[0], "delimiter-map") == 0) {
Packit Service ae04f2
			WARNING(("libidnkit: obsolete command \"%s\", line %d "
Packit Service ae04f2
			         "(ignored)\n", argv[0], lineno));
Packit Service ae04f2
			r = idn_success;
Packit Service ae04f2
		} else {
Packit Service ae04f2
			ERROR(("libidnkit: unknown command \"%-.30s\", "
Packit Service ae04f2
			       "line %d\n", argv[0], lineno));
Packit Service ae04f2
			r = idn_invalid_syntax;
Packit Service ae04f2
		}
Packit Service ae04f2
		if (r != idn_success)
Packit Service ae04f2
			return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	lineno++;
Packit Service ae04f2
Packit Service ae04f2
	if (conf_mask != DEFAULT_CONF_ALL) {
Packit Service ae04f2
		return setdefaults_body(ctx, conf_mask);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static idn_result_t
Packit Service ae04f2
parse_idn_encoding(idn_resconf_t ctx, char *args, int lineno) {
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
	char *argv[MAX_CONF_LINE_ARGS + 1];
Packit Service ae04f2
	int argc;
Packit Service ae04f2
Packit Service ae04f2
	argc = split_args(args, argv, MAX_CONF_LINE_ARGS + 1);
Packit Service ae04f2
Packit Service ae04f2
	if (argc != 1) {
Packit Service ae04f2
		ERROR(("libidnkit: wrong # of args for idn-encoding, "
Packit Service ae04f2
		       "line %d\n", lineno));
Packit Service ae04f2
		return (idn_invalid_syntax);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	r = idn_converter_create(argv[0], &ctx->idn_converter,
Packit Service ae04f2
				 IDN_CONVERTER_DELAYEDOPEN |
Packit Service ae04f2
				 IDN_CONVERTER_RTCHECK);
Packit Service ae04f2
	if (r != idn_success) {
Packit Service ae04f2
		ERROR(("libidnkit: cannot create idn converter, %s, "
Packit Service ae04f2
		       "line %d\n", idn_result_tostring(r), lineno));
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (r);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static idn_result_t
Packit Service ae04f2
parse_local_map(idn_resconf_t ctx, char *args, int lineno) {
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
	char *argv[MAX_CONF_LINE_ARGS + 1];
Packit Service ae04f2
	int argc;
Packit Service ae04f2
	int i;
Packit Service ae04f2
Packit Service ae04f2
	argc = split_args(args, argv, MAX_CONF_LINE_ARGS + 1);
Packit Service ae04f2
Packit Service ae04f2
	if (argc < 2 || argc > MAX_CONF_LINE_ARGS) {
Packit Service ae04f2
		ERROR(("libidnkit: wrong # of args for local-map, line %d\n",
Packit Service ae04f2
		       lineno));
Packit Service ae04f2
		return (idn_invalid_syntax);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->local_mapper == NULL) {
Packit Service ae04f2
		r = idn_mapselector_create(&ctx->local_mapper);
Packit Service ae04f2
		if (r != idn_success) {
Packit Service ae04f2
			ERROR(("libidnkit: cannot create local mapper, %s, "
Packit Service ae04f2
			       "line %d\n", idn_result_tostring(r), lineno));
Packit Service ae04f2
			return (r);
Packit Service ae04f2
		}
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	for (i = 1; i < argc; i++) {
Packit Service ae04f2
		r = idn_mapselector_add(ctx->local_mapper, argv[0], argv[i]);
Packit Service ae04f2
		if (r == idn_invalid_name) {
Packit Service ae04f2
			ERROR(("libidnkit: map scheme unavailable \"%-.30s\""
Packit Service ae04f2
			       " or invalid TLD \"%-.30s\", line %d\n",
Packit Service ae04f2
			       argv[i], argv[0], lineno));
Packit Service ae04f2
			return (r);
Packit Service ae04f2
		} else if (r != idn_success) {
Packit Service ae04f2
			return (r);
Packit Service ae04f2
		}
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static idn_result_t
Packit Service ae04f2
parse_nameprep(idn_resconf_t ctx, char *args, int lineno) {
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
	char *argv[MAX_CONF_LINE_ARGS + 1];
Packit Service ae04f2
	char scheme_name[MAX_CONF_LINE_LENGTH + 1];
Packit Service ae04f2
	int argc;
Packit Service ae04f2
Packit Service ae04f2
	argc = split_args(args, argv, MAX_CONF_LINE_ARGS + 1);
Packit Service ae04f2
Packit Service ae04f2
	if (argc != 1) {
Packit Service ae04f2
		ERROR(("libidnkit: wrong # of args for nameprep, line %d\n",
Packit Service ae04f2
		       lineno));
Packit Service ae04f2
		return (idn_invalid_syntax);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * Set mapper.
Packit Service ae04f2
	 */
Packit Service ae04f2
	r = idn_mapper_create(&ctx->mapper);
Packit Service ae04f2
	if (r != idn_success) {
Packit Service ae04f2
		ERROR(("libidnkit: cannot create mapper, %s, line %d\n",
Packit Service ae04f2
		       idn_result_tostring(r), lineno));
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	r = idn_mapper_add(ctx->mapper, argv[0]);
Packit Service ae04f2
	if (r == idn_invalid_name) {
Packit Service ae04f2
		ERROR(("libidnkit: map scheme unavailable \"%-.30s\", "
Packit Service ae04f2
		       "line %d\n", argv[0], lineno));
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	} else if (r != idn_success) {
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * Set normalizer.
Packit Service ae04f2
	 */
Packit Service ae04f2
	r = idn_normalizer_create(&ctx->normalizer);
Packit Service ae04f2
	if (r != idn_success) {
Packit Service ae04f2
		ERROR(("libidnkit: cannot create normalizer, %s, line %d\n",
Packit Service ae04f2
		       idn_result_tostring(r), lineno));
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	r = idn_normalizer_add(ctx->normalizer, argv[0]);
Packit Service ae04f2
	if (r == idn_invalid_name) {
Packit Service ae04f2
		ERROR(("libidnkit: unknown normalization scheme \"%-.30s\", "
Packit Service ae04f2
		       "line %d\n", argv[0], lineno));
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	} else if (r != idn_success) {
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * Set prohibit checker.
Packit Service ae04f2
	 */
Packit Service ae04f2
	r = idn_checker_create(&ctx->prohibit_checker);
Packit Service ae04f2
	if (r != idn_success) {
Packit Service ae04f2
		ERROR(("libidnkit: cannot create prohibit checker, %s, "
Packit Service ae04f2
		       "line %d\n", idn_result_tostring(r), lineno));
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	sprintf(scheme_name, "%s%s", IDN_CHECKER_PROHIBIT_PREFIX, argv[0]);
Packit Service ae04f2
	r = idn_checker_add(ctx->prohibit_checker, scheme_name);
Packit Service ae04f2
	if (r == idn_invalid_name) {
Packit Service ae04f2
		ERROR(("libidnkit: unknown prohibit scheme \"%-.30s\", "
Packit Service ae04f2
		       "line %d\n", argv[0], lineno));
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	} else if (r != idn_success) {
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * Set unassigned checker.
Packit Service ae04f2
	 */
Packit Service ae04f2
	r = idn_checker_create(&ctx->unassigned_checker);
Packit Service ae04f2
	if (r != idn_success) {
Packit Service ae04f2
		ERROR(("libidnkit: cannot create unassigned checker, %s, "
Packit Service ae04f2
		       "line %d\n", idn_result_tostring(r), lineno));
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	sprintf(scheme_name, "%s%s", IDN_CHECKER_UNASSIGNED_PREFIX, argv[0]);
Packit Service ae04f2
	r = idn_checker_add(ctx->unassigned_checker, scheme_name);
Packit Service ae04f2
	if (r == idn_invalid_name) {
Packit Service ae04f2
		ERROR(("libidnkit: unknown unassigned scheme \"%-.30s\", "
Packit Service ae04f2
		       "line %d\n", argv[0], lineno));
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	} else if (r != idn_success) {
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * Set bidi checker.
Packit Service ae04f2
	 */
Packit Service ae04f2
	r = idn_checker_create(&ctx->bidi_checker);
Packit Service ae04f2
	if (r != idn_success) {
Packit Service ae04f2
		ERROR(("libidnkit: cannot create bidi checker, %s, line %d\n",
Packit Service ae04f2
		       idn_result_tostring(r), lineno));
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	sprintf(scheme_name, "%s%s", IDN_CHECKER_BIDI_PREFIX, argv[0]);
Packit Service ae04f2
	r = idn_checker_add(ctx->bidi_checker, scheme_name);
Packit Service ae04f2
	if (r == idn_invalid_name) {
Packit Service ae04f2
		ERROR(("libidnkit: unknown bidi scheme \"%-.30s\", "
Packit Service ae04f2
		       "line %d\n", argv[0], lineno));
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	} else if (r != idn_success) {
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static int
Packit Service ae04f2
split_args(char *s, char **av, int max_ac) {
Packit Service ae04f2
	int ac;
Packit Service ae04f2
	int i;
Packit Service ae04f2
Packit Service ae04f2
	for (ac = 0; *s != '\0' && ac < max_ac; ac++) {
Packit Service ae04f2
		if (ac > 0)
Packit Service ae04f2
			*s++ = '\0';
Packit Service ae04f2
		while (isspace((unsigned char)*s))
Packit Service ae04f2
			s++;
Packit Service ae04f2
		if (*s == '\0')
Packit Service ae04f2
			break;
Packit Service ae04f2
		if (*s == '"' || *s == '\'') {
Packit Service ae04f2
			int qc = *s++;
Packit Service ae04f2
			av[ac] = s;
Packit Service ae04f2
			while (*s != qc) {
Packit Service ae04f2
				if (*s == '\0')
Packit Service ae04f2
					return (-1);
Packit Service ae04f2
				s++;
Packit Service ae04f2
			}
Packit Service ae04f2
		} else {
Packit Service ae04f2
			av[ac] = s;
Packit Service ae04f2
			while (*s != '\0' && !isspace((unsigned char)*s))
Packit Service ae04f2
				s++;
Packit Service ae04f2
		}
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	for (i = ac; i < max_ac; i++)
Packit Service ae04f2
		av[i] = NULL;
Packit Service ae04f2
Packit Service ae04f2
	return (ac);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static void
Packit Service ae04f2
resetconf(idn_resconf_t ctx) {
Packit Service ae04f2
#ifndef WITHOUT_ICONV
Packit Service ae04f2
	idn_resconf_setlocalconverter(ctx, NULL);
Packit Service ae04f2
#endif
Packit Service ae04f2
	idn_resconf_setidnconverter(ctx, NULL);
Packit Service ae04f2
	idn_resconf_setauxidnconverter(ctx, NULL);
Packit Service ae04f2
	idn_resconf_setdelimitermap(ctx, NULL);
Packit Service ae04f2
	idn_resconf_setlocalmapselector(ctx, NULL);
Packit Service ae04f2
	idn_resconf_setmapper(ctx, NULL);
Packit Service ae04f2
	idn_resconf_setnormalizer(ctx, NULL);
Packit Service ae04f2
	idn_resconf_setprohibitchecker(ctx, NULL);
Packit Service ae04f2
	idn_resconf_setunassignedchecker(ctx, NULL);
Packit Service ae04f2
	idn_resconf_setbidichecker(ctx, NULL);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
#ifndef WITHOUT_ICONV
Packit Service ae04f2
static idn_result_t
Packit Service ae04f2
update_local_converter(idn_resconf_t ctx) {
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
	const char *old_encoding;
Packit Service ae04f2
	const char *new_encoding;
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * We don't update local converter, if the converter is set
Packit Service ae04f2
	 * by idn_resconf_setlocalconverter() or
Packit Service ae04f2
	 * idn_resconf_setlocalconvertername().
Packit Service ae04f2
	 */
Packit Service ae04f2
	if (ctx->local_converter_is_static)
Packit Service ae04f2
		return (idn_success);
Packit Service ae04f2
Packit Service ae04f2
	/*
Packit Service ae04f2
	 * Update the local converter if the local encoding is changed.
Packit Service ae04f2
	 */
Packit Service ae04f2
	old_encoding = (ctx->local_converter != NULL) ?
Packit Service ae04f2
		       idn_converter_localencoding(ctx->local_converter) :
Packit Service ae04f2
		       NULL;
Packit Service ae04f2
	new_encoding = idn_localencoding_name();
Packit Service ae04f2
	if (new_encoding == NULL) {
Packit Service ae04f2
		ERROR(("cannot determine local codeset name\n"));
Packit Service ae04f2
		return (idn_notfound);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	if (old_encoding != NULL &&
Packit Service ae04f2
	    new_encoding != NULL &&
Packit Service ae04f2
	    strcmp(old_encoding, new_encoding) == 0) {
Packit Service ae04f2
		return (idn_success);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	if (ctx->local_converter != NULL) {
Packit Service ae04f2
		idn_converter_destroy(ctx->local_converter);
Packit Service ae04f2
		ctx->local_converter = NULL;
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	r = idn_converter_create(new_encoding,
Packit Service ae04f2
				 &ctx->local_converter,
Packit Service ae04f2
				 IDN_CONVERTER_RTCHECK);
Packit Service ae04f2
	return (r);
Packit Service ae04f2
}
Packit Service ae04f2
#endif
Packit Service ae04f2
Packit Service ae04f2
idn_result_t
Packit Service ae04f2
idn_resconf_setdefaults(idn_resconf_t ctx)
Packit Service ae04f2
{
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("idn_resconf_setdefaults()\n"));
Packit Service ae04f2
Packit Service ae04f2
	resetconf(ctx);
Packit Service ae04f2
	r = idn_delimitermap_create(&ctx->delimiter_mapper);
Packit Service ae04f2
	if (r != idn_success) {
Packit Service ae04f2
		ERROR(("libidnkit: cannot create delimiter mapper, %s\n",
Packit Service ae04f2
		       idn_result_tostring(r)));
Packit Service ae04f2
		return (r);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return setdefaults_body(ctx, 0);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static idn_result_t
Packit Service ae04f2
setdefaults_body(idn_resconf_t ctx, int conf_mask) {
Packit Service ae04f2
	idn_result_t r;
Packit Service ae04f2
Packit Service ae04f2
	TRACE(("setdefaults_body()\n"));
Packit Service ae04f2
	assert(ctx != NULL);
Packit Service ae04f2
Packit Service ae04f2
	if (!(conf_mask & DEFAULT_CONF_NAMEPREP)) {
Packit Service ae04f2
		TRACE(("set default nameprep\n"));
Packit Service ae04f2
		r = idn_resconf_setnameprepversion(ctx, IDN_NAMEPREP_CURRENT);
Packit Service ae04f2
		if (r != idn_success) {
Packit Service ae04f2
			return (r);
Packit Service ae04f2
		}
Packit Service ae04f2
	}
Packit Service ae04f2
	if (!(conf_mask & DEFAULT_CONF_IDN_ENCODING)) {
Packit Service ae04f2
		TRACE(("set default idn encoding\n"));
Packit Service ae04f2
		r = idn_converter_create(IDN_ENCODING_CURRENT,
Packit Service ae04f2
					 &ctx->idn_converter,
Packit Service ae04f2
					 IDN_CONVERTER_DELAYEDOPEN |
Packit Service ae04f2
					 IDN_CONVERTER_RTCHECK);
Packit Service ae04f2
		if (r != idn_success) {
Packit Service ae04f2
			ERROR(("libidnkit: cannot create idn converter, %s\n",
Packit Service ae04f2
			       idn_result_tostring(r)));
Packit Service ae04f2
			return (r);
Packit Service ae04f2
		}
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (idn_success);
Packit Service ae04f2
}