#ifndef lint
#endif
/*
* Copyright (c) 2000 Japan Network Information Center. All rights reserved.
*
* By using this file, you agree to the terms and conditions set forth bellow.
*
* LICENSE TERMS AND CONDITIONS
*
* The following License Terms and Conditions apply, unless a different
* license is obtained from Japan Network Information Center ("JPNIC"),
* a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
* Chiyoda-ku, Tokyo 101-0047, Japan.
*
* 1. Use, Modification and Redistribution (including distribution of any
* under this License Terms and Conditions.
*
* 2. Redistribution of source code must retain the copyright notices as they
* appear in each source code file, this License Terms and Conditions.
*
* 3. Redistribution in binary form must reproduce the Copyright Notice,
* materials provided with the distribution. For the purposes of binary
* distribution the "Copyright Notice" refers to the following language:
* "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
*
* 4. The name of JPNIC may not be used to endorse or promote products
* derived from this Software without specific prior written approval of
* JPNIC.
*
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include <config.h>
#include <stddef.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#include <idn/logmacro.h>
#include <idn/converter.h>
#include <idn/nameprep.h>
#include <idn/normalizer.h>
#include <idn/mapselector.h>
#include <idn/delimitermap.h>
#include <idn/localencoding.h>
#ifdef WIN32
#else /* WIN32 */
#ifndef IDN_RESCONF_DIR
#endif
#endif /* WIN32 */
#ifdef ENABLE_MDNKIT_COMPAT
#endif
struct idn_resconf {
int reference_count;
};
static int initialized;
#ifndef WIN32
static const char * userhomedir(void);
#endif
int lineno);
int lineno);
int lineno);
#ifndef WITHOUT_ICONV
#endif
idn_resconf_initialize(void) {
idn_result_t r;
TRACE(("idn_resconf_initialize()\n"));
if (initialized) {
r = idn_success;
goto ret;
}
/*
* Initialize sub modules.
*/
if ((r = idn_converter_initialize()) != idn_success)
goto ret;
if ((r = idn_normalizer_initialize()) != idn_success)
goto ret;
if ((r = idn_checker_initialize()) != idn_success)
goto ret;
if ((r = idn_mapselector_initialize()) != idn_success)
goto ret;
if ((r = idn_mapper_initialize()) != idn_success)
goto ret;
r = idn_success;
initialized = 1;
ret:
return (r);
}
idn_result_t r;
TRACE(("idn_resconf_create()\n"));
if (!initialized) {
r = idn_failure;
goto ret;
}
r = idn_nomemory;
goto ret;
}
ctx->local_converter_is_static = 0;
if (r != idn_success)
goto ret;
r = idn_success;
ret:
return (r);
}
char *
#ifdef WIN32
sizeof(default_path))) {
return (default_path);
} else {
return (NULL);
}
#else
return (IDN_RESCONF_FILE);
#endif
}
#ifndef WIN32
static const char *
userhomedir() {
return (NULL);
}
}
#endif
static idn_result_t
#ifdef WIN32
TRACE(("open_userdefaultfile()\n"));
sizeof(user_path)) == 0) {
return (idn_nofile);
}
return (idn_nofile);
}
return (idn_success);
#else /* WIN32 */
const char *homedir;
char *file;
int len;
TRACE(("open_userdefaultfile()\n"));
homedir = userhomedir();
} else {
return (idn_notfound);
}
WARNING(("open_userdefaultfile(): malloc failed\n"));
return (idn_nomemory);
}
return (idn_nofile);
}
return (idn_success);
#endif /* WIN32 */
}
static idn_result_t
idn_result_t r;
const char *file;
r = open_userdefaultfile(fpp);
if (r == idn_nofile || r == idn_notfound) {
TRACE(("open_defaultfile: "
"cannot open user configuration file\n"));
#ifdef ENABLE_MDNKIT_COMPAT
#endif
TRACE(("open_defaultfile: "
"cannot open system configuration file\n"));
return (idn_nofile);
}
} else if (r != idn_success) {
return (r);
}
return (idn_success);
}
idn_result_t r;
TRACE(("idn_resconf_loadfile(file=%s)\n",
if (r != idn_success) {
goto ret;
}
r = open_defaultfile(&fp);
if (r == idn_nofile || r == idn_notfound) {
r = setdefaults_body(ctx, 0);
goto ret;
} else if (r != idn_success) {
goto ret;
}
} else {
TRACE(("idn_resconf_loadfile: cannot open %-.40s\n",
file));
r = idn_nofile;
goto ret;
}
}
ret:
return (r);
}
void
TRACE(("idn_resconf_destroy()\n"));
ctx->reference_count--;
if (ctx->reference_count <= 0) {
TRACE(("idn_resconf_destroy: the object is destroyed\n"));
} else {
TRACE(("idn_resconf_destroy(): "
"update reference count (%d->%d)\n",
}
}
void
TRACE(("idn_resconf_incrref()\n"));
TRACE(("idn_resconf_incrref: update reference count (%d->%d)\n",
ctx->reference_count++;
}
TRACE(("idn_resconf_getalternateconverter()\n"));
return (idn_resconf_getidnconverter(ctx));
}
TRACE(("idn_resconf_getdelimitermap()\n"));
return (ctx->delimiter_mapper);
}
TRACE(("idn_resconf_getidnconverter()\n"));
return (ctx->idn_converter);
}
TRACE(("idn_resconf_getauxidnconverter()\n"));
return (ctx->aux_idn_converter);
}
TRACE(("idn_resconf_getlocalconverter()\n"));
#ifdef WITHOUT_ICONV
return NULL;
#else /* WITHOUT_ICONV */
return (NULL);
return (ctx->local_converter);
#endif /* WITHOUT_ICONV */
}
TRACE(("idn_resconf_getlocalmapselector()\n"));
return (ctx->local_mapper);
}
TRACE(("idn_resconf_getmapper()\n"));
}
TRACE(("idn_resconf_getnormalizer()\n"));
return (ctx->normalizer);
}
TRACE(("idn_resconf_getprohibitchecker()\n"));
return (ctx->prohibit_checker);
}
TRACE(("idn_resconf_getunassignedchecker()\n"));
return (ctx->unassigned_checker);
}
TRACE(("idn_resconf_getbidichecker()\n"));
return (ctx->bidi_checker);
}
void
TRACE(("idn_resconf_setalternateconverter()\n"));
}
void
TRACE(("idn_resconf_setdelimitermap()\n"));
if (delimiter_mapper != NULL)
}
void
TRACE(("idn_resconf_setidnconverter()\n"));
if (idn_converter != NULL)
}
void
TRACE(("idn_resconf_setauxidnconverter()\n"));
if (aux_idn_converter != NULL)
}
void
#ifndef WITHOUT_ICONV
TRACE(("idn_resconf_setlocalconverter()\n"));
}
if (local_converter == NULL)
ctx->local_converter_is_static = 0;
else {
}
#endif /* WITHOUT_ICONV */
}
void
TRACE(("idn_resconf_setlocalmapselector()\n"));
if (local_mapper != NULL)
}
void
TRACE(("idn_resconf_setmapper()\n"));
}
void
TRACE(("idn_resconf_setnormalizer()\n"));
if (normalizer != NULL)
}
void
TRACE(("idn_resconf_setprohibitchecker()\n"));
if (prohibit_checker != NULL)
}
void
TRACE(("idn_resconf_setunassignedchecker()\n"));
if (unassigned_checker != NULL)
}
void
TRACE(("idn_resconf_setbidichecker()\n"));
if (bidi_checker != NULL)
}
{
idn_result_t r;
TRACE(("idn_resconf_setnameprepversion()\n"));
/*
* Set canonical scheme names.
*/
> MAX_CONF_LINE_LENGTH) {
r = idn_invalid_name;
goto failure;
}
> MAX_CONF_LINE_LENGTH) {
r = idn_invalid_name;
goto failure;
}
> MAX_CONF_LINE_LENGTH) {
r = idn_invalid_name;
goto failure;
}
/*
* Create objects.
*/
r = idn_mapper_create(&mapper);
if (r != idn_success)
goto failure;
r = idn_normalizer_create(&normalizer);
if (r != idn_success)
goto failure;
if (r != idn_success)
goto failure;
if (r != idn_success)
goto failure;
r = idn_checker_create(&bidi_checker);
if (r != idn_success)
goto failure;
if (r != idn_success)
goto failure;
if (r != idn_success)
goto failure;
if (r != idn_success)
goto failure;
if (r != idn_success)
goto failure;
if (r != idn_success)
goto failure;
/*
* Set the objects.
*/
/*
* Destroy the objects.
*/
return (idn_success);
if (normalizer != NULL)
if (prohibit_checker != NULL)
if (unassigned_checker != NULL)
if (bidi_checker != NULL)
return (r);
}
int flags) {
TRACE(("idn_resconf_setalternateconvertername(name=%s, flags=%d)\n",
return (idn_success);
}
int flags) {
idn_result_t r;
TRACE(("idn_resconf_setidnconvertername(name=%s, flags=%d)\n",
if (r != idn_success)
return (r);
return (idn_success);
}
int flags) {
const char *old_name;
idn_result_t r;
TRACE(("idn_resconf_setauxidnconvertername(name=%s, flags=%d)\n",
return (idn_success);
}
if (r != idn_success)
return (r);
return (idn_success);
}
int flags) {
#ifdef WITHOUT_ICONV
return idn_failure;
#else /* WITHOUT_ICONV */
idn_result_t r;
TRACE(("idn_resconf_setlocalconvertername(name=%s, flags=%d)\n",
}
ctx->local_converter_is_static = 0;
if (r != idn_success)
return (r);
}
return (idn_success);
#endif /* WITHOUT_ICONV */
}
int nv) {
idn_result_t r;
if (r != idn_success)
return (r);
}
return (r);
}
idn_result_t r;
TRACE(("idn_resconf_addalllocalmapselectorname(tld=%s, nnames=%d)\n",
if (r != idn_success)
return (r);
}
return (r);
}
int nnames) {
idn_result_t r;
TRACE(("idn_resconf_addallmappername()\n"));
if (r != idn_success)
return (r);
}
return (r);
}
int nnames) {
idn_result_t r;
if (r != idn_success)
return (r);
}
return (r);
}
int nnames) {
idn_result_t r;
int i;
if (r != idn_success)
return (r);
}
> MAX_CONF_LINE_LENGTH) {
return (idn_invalid_name);
}
if (r != idn_success)
return (r);
}
return (idn_success);
}
int nnames) {
idn_result_t r;
int i;
TRACE(("idn_resconf_addallunassignedcheckername(nnames=%d)\n",
nnames));
if (r != idn_success)
return (r);
}
> MAX_CONF_LINE_LENGTH) {
return (idn_invalid_name);
}
if (r != idn_success)
return (r);
}
return (idn_success);
}
int nnames) {
idn_result_t r;
int i;
if (r != idn_success)
return (r);
}
> MAX_CONF_LINE_LENGTH) {
return (idn_invalid_name);
}
if (r != idn_success)
return (r);
}
return (idn_success);
}
static idn_result_t
int lineno = 0;
int argc;
idn_result_t r;
int conf_mask = 0;
TRACE(("parse_conf()\n"));
/*
* Parse config file. parsing of 'idn-encoding' line is
* postponed because 'alias-file' line must be processed
* before them.
*/
char *newline;
lineno++;
*newline = '\0';
ERROR(("libidnkit: too long line \"%-.30s\", "
return (idn_invalid_syntax);
}
if (argc == -1) {
return (idn_invalid_syntax);
continue;
} else if (argc == 1) {
return (idn_invalid_syntax);
}
if (conf_mask & DEFAULT_CONF_IDN_ENCODING) {
ERROR(("libidnkit: \"%s\" redefined, "
r = idn_invalid_syntax;
} else {
}
if (conf_mask & DEFAULT_CONF_NAMEPREP) {
ERROR(("libidnkit: \"%s\" redefined, "
r = idn_invalid_syntax;
} else {
}
WARNING(("libidnkit: obsolete command \"%s\", line %d "
r = idn_success;
} else {
ERROR(("libidnkit: unknown command \"%-.30s\", "
r = idn_invalid_syntax;
}
if (r != idn_success)
return (r);
}
lineno++;
if (conf_mask != DEFAULT_CONF_ALL) {
}
return (idn_success);
}
static idn_result_t
idn_result_t r;
int argc;
if (argc != 1) {
ERROR(("libidnkit: wrong # of args for idn-encoding, "
"line %d\n", lineno));
return (idn_invalid_syntax);
}
if (r != idn_success) {
ERROR(("libidnkit: cannot create idn converter, %s, "
}
return (r);
}
static idn_result_t
idn_result_t r;
int argc;
int i;
ERROR(("libidnkit: wrong # of args for local-map, line %d\n",
lineno));
return (idn_invalid_syntax);
}
if (r != idn_success) {
ERROR(("libidnkit: cannot create local mapper, %s, "
return (r);
}
}
for (i = 1; i < argc; i++) {
if (r == idn_invalid_name) {
ERROR(("libidnkit: map scheme unavailable \"%-.30s\""
" or invalid TLD \"%-.30s\", line %d\n",
return (r);
} else if (r != idn_success) {
return (r);
}
}
return (idn_success);
}
static idn_result_t
idn_result_t r;
int argc;
if (argc != 1) {
ERROR(("libidnkit: wrong # of args for nameprep, line %d\n",
lineno));
return (idn_invalid_syntax);
}
/*
* Set mapper.
*/
if (r != idn_success) {
ERROR(("libidnkit: cannot create mapper, %s, line %d\n",
idn_result_tostring(r), lineno));
return (r);
}
if (r == idn_invalid_name) {
ERROR(("libidnkit: map scheme unavailable \"%-.30s\", "
return (r);
} else if (r != idn_success) {
return (r);
}
/*
* Set normalizer.
*/
if (r != idn_success) {
ERROR(("libidnkit: cannot create normalizer, %s, line %d\n",
idn_result_tostring(r), lineno));
return (r);
}
if (r == idn_invalid_name) {
ERROR(("libidnkit: unknown normalization scheme \"%-.30s\", "
return (r);
} else if (r != idn_success) {
return (r);
}
/*
* Set prohibit checker.
*/
if (r != idn_success) {
ERROR(("libidnkit: cannot create prohibit checker, %s, "
return (r);
}
if (r == idn_invalid_name) {
ERROR(("libidnkit: unknown prohibit scheme \"%-.30s\", "
return (r);
} else if (r != idn_success) {
return (r);
}
/*
* Set unassigned checker.
*/
if (r != idn_success) {
ERROR(("libidnkit: cannot create unassigned checker, %s, "
return (r);
}
if (r == idn_invalid_name) {
ERROR(("libidnkit: unknown unassigned scheme \"%-.30s\", "
return (r);
} else if (r != idn_success) {
return (r);
}
/*
* Set bidi checker.
*/
if (r != idn_success) {
ERROR(("libidnkit: cannot create bidi checker, %s, line %d\n",
idn_result_tostring(r), lineno));
return (r);
}
if (r == idn_invalid_name) {
ERROR(("libidnkit: unknown bidi scheme \"%-.30s\", "
return (r);
} else if (r != idn_success) {
return (r);
}
return (idn_success);
}
static int
int ac;
int i;
if (ac > 0)
*s++ = '\0';
while (isspace((unsigned char)*s))
s++;
if (*s == '\0')
break;
if (*s == '"' || *s == '\'') {
int qc = *s++;
while (*s != qc) {
if (*s == '\0')
return (-1);
s++;
}
} else {
while (*s != '\0' && !isspace((unsigned char)*s))
s++;
}
}
return (ac);
}
static void
#ifndef WITHOUT_ICONV
#endif
}
#ifndef WITHOUT_ICONV
static idn_result_t
idn_result_t r;
const char *old_encoding;
const char *new_encoding;
/*
* We don't update local converter, if the converter is set
* by idn_resconf_setlocalconverter() or
* idn_resconf_setlocalconvertername().
*/
if (ctx->local_converter_is_static)
return (idn_success);
/*
* Update the local converter if the local encoding is changed.
*/
NULL;
if (new_encoding == NULL) {
ERROR(("cannot determine local codeset name\n"));
return (idn_notfound);
}
if (old_encoding != NULL &&
new_encoding != NULL &&
return (idn_success);
}
}
return (r);
}
#endif
{
idn_result_t r;
TRACE(("idn_resconf_setdefaults()\n"));
if (r != idn_success) {
ERROR(("libidnkit: cannot create delimiter mapper, %s\n",
idn_result_tostring(r)));
return (r);
}
return setdefaults_body(ctx, 0);
}
static idn_result_t
idn_result_t r;
TRACE(("setdefaults_body()\n"));
if (!(conf_mask & DEFAULT_CONF_NAMEPREP)) {
TRACE(("set default nameprep\n"));
if (r != idn_success) {
return (r);
}
}
if (!(conf_mask & DEFAULT_CONF_IDN_ENCODING)) {
TRACE(("set default idn encoding\n"));
&ctx->idn_converter,
if (r != idn_success) {
ERROR(("libidnkit: cannot create idn converter, %s\n",
idn_result_tostring(r)));
return (r);
}
}
return (idn_success);
}