Beispiel #1
0
idn_result_t
idn_normalizer_addall(idn_normalizer_t ctx, const char **scheme_names,
		      int nschemes) {
	idn_result_t r;
	int i;

	assert(ctx != NULL && scheme_names != NULL);

	TRACE(("idn_normalizer_addall(nschemes=%d)\n", nschemes));

	for (i = 0; i < nschemes; i++) {
		r = idn_normalizer_add(ctx, (const char *)*scheme_names);
		if (r != idn_success)
			goto ret;
		scheme_names++;
	}

	r = idn_success;
ret:
	TRACE(("idn_normalizer_addall(): %s\n", idn_result_tostring(r)));
	return (r);
}
Beispiel #2
0
idn_result_t
idn_resconf_setnameprepversion(idn_resconf_t ctx, const char *version)
{
	char prohibit_scheme_name[MAX_CONF_LINE_LENGTH + 1];
	char unassigned_scheme_name[MAX_CONF_LINE_LENGTH + 1];
	char bidi_scheme_name[MAX_CONF_LINE_LENGTH + 1];
	idn_mapper_t mapper = NULL;
	idn_normalizer_t normalizer = NULL;
	idn_checker_t prohibit_checker = NULL;
	idn_checker_t unassigned_checker = NULL;
	idn_checker_t bidi_checker = NULL;
	idn_result_t r;

	assert(ctx != NULL && version != NULL);

	TRACE(("idn_resconf_setnameprepversion()\n"));

	/*
	 * Set canonical scheme names.
	 */
	if (strlen(version) + strlen(IDN_CHECKER_PROHIBIT_PREFIX)
	    > MAX_CONF_LINE_LENGTH) {
		r = idn_invalid_name;
		goto failure;
	}
	sprintf(prohibit_scheme_name, "%s%s",
	        IDN_CHECKER_PROHIBIT_PREFIX, version);

	if (strlen(version) + strlen(IDN_CHECKER_UNASSIGNED_PREFIX)
	    > MAX_CONF_LINE_LENGTH) {
		r = idn_invalid_name;
		goto failure;
	}
	sprintf(unassigned_scheme_name, "%s%s",
	        IDN_CHECKER_UNASSIGNED_PREFIX, version);

	if (strlen(version) + strlen(IDN_CHECKER_BIDI_PREFIX)
	    > MAX_CONF_LINE_LENGTH) {
		r = idn_invalid_name;
		goto failure;
	}
	sprintf(bidi_scheme_name, "%s%s",
	        IDN_CHECKER_BIDI_PREFIX, version);

	/*
	 * Create objects.
	 */
	r = idn_mapper_create(&mapper);
	if (r != idn_success)
		goto failure;
	r = idn_normalizer_create(&normalizer);
	if (r != idn_success)
		goto failure;
	r = idn_checker_create(&prohibit_checker);
	if (r != idn_success)
		goto failure;
	r = idn_checker_create(&unassigned_checker);
	if (r != idn_success)
		goto failure;
	r = idn_checker_create(&bidi_checker);
	if (r != idn_success)
		goto failure;

	r = idn_mapper_add(mapper, version);
	if (r != idn_success)
		goto failure;
	r = idn_normalizer_add(normalizer, version);
	if (r != idn_success)
		goto failure;
	r = idn_checker_add(prohibit_checker, prohibit_scheme_name);
	if (r != idn_success)
		goto failure;
	r = idn_checker_add(unassigned_checker, unassigned_scheme_name);
	if (r != idn_success)
		goto failure;
	r = idn_checker_add(bidi_checker, bidi_scheme_name);
	if (r != idn_success)
		goto failure;

	/*
	 * Set the objects.
	 */
	idn_resconf_setmapper(ctx, mapper);
	idn_resconf_setnormalizer(ctx, normalizer);
	idn_resconf_setprohibitchecker(ctx, prohibit_checker);
	idn_resconf_setunassignedchecker(ctx, unassigned_checker);
	idn_resconf_setbidichecker(ctx, bidi_checker);

	/*
	 * Destroy the objects.
	 */
	idn_mapper_destroy(mapper);
	idn_normalizer_destroy(normalizer);
	idn_checker_destroy(prohibit_checker);
	idn_checker_destroy(unassigned_checker);
	idn_checker_destroy(bidi_checker);

	return (idn_success);

failure:
	if (mapper != NULL)
		idn_mapper_destroy(mapper);
	if (normalizer != NULL)
		idn_normalizer_destroy(normalizer);
	if (prohibit_checker != NULL)
		idn_checker_destroy(prohibit_checker);
	if (unassigned_checker != NULL)
		idn_checker_destroy(unassigned_checker);
	if (bidi_checker != NULL)
		idn_checker_destroy(bidi_checker);

	return (r);
}
Beispiel #3
0
static idn_result_t
parse_nameprep(idn_resconf_t ctx, char *args, int lineno) {
	idn_result_t r;
	char *argv[MAX_CONF_LINE_ARGS + 1];
	char scheme_name[MAX_CONF_LINE_LENGTH + 1];
	int argc;

	argc = split_args(args, argv, MAX_CONF_LINE_ARGS + 1);

	if (argc != 1) {
		ERROR(("libidnkit: wrong # of args for nameprep, line %d\n",
		       lineno));
		return (idn_invalid_syntax);
	}

	/*
	 * Set mapper.
	 */
	r = idn_mapper_create(&ctx->mapper);
	if (r != idn_success) {
		ERROR(("libidnkit: cannot create mapper, %s, line %d\n",
		       idn_result_tostring(r), lineno));
		return (r);
	}

	r = idn_mapper_add(ctx->mapper, argv[0]);
	if (r == idn_invalid_name) {
		ERROR(("libidnkit: map scheme unavailable \"%-.30s\", "
		       "line %d\n", argv[0], lineno));
		return (r);
	} else if (r != idn_success) {
		return (r);
	}

	/*
	 * Set normalizer.
	 */
	r = idn_normalizer_create(&ctx->normalizer);
	if (r != idn_success) {
		ERROR(("libidnkit: cannot create normalizer, %s, line %d\n",
		       idn_result_tostring(r), lineno));
		return (r);
	}

	r = idn_normalizer_add(ctx->normalizer, argv[0]);
	if (r == idn_invalid_name) {
		ERROR(("libidnkit: unknown normalization scheme \"%-.30s\", "
		       "line %d\n", argv[0], lineno));
		return (r);
	} else if (r != idn_success) {
		return (r);
	}

	/*
	 * Set prohibit checker.
	 */
	r = idn_checker_create(&ctx->prohibit_checker);
	if (r != idn_success) {
		ERROR(("libidnkit: cannot create prohibit checker, %s, "
		       "line %d\n", idn_result_tostring(r), lineno));
		return (r);
	}

	sprintf(scheme_name, "%s%s", IDN_CHECKER_PROHIBIT_PREFIX, argv[0]);
	r = idn_checker_add(ctx->prohibit_checker, scheme_name);
	if (r == idn_invalid_name) {
		ERROR(("libidnkit: unknown prohibit scheme \"%-.30s\", "
		       "line %d\n", argv[0], lineno));
		return (r);
	} else if (r != idn_success) {
		return (r);
	}

	/*
	 * Set unassigned checker.
	 */
	r = idn_checker_create(&ctx->unassigned_checker);
	if (r != idn_success) {
		ERROR(("libidnkit: cannot create unassigned checker, %s, "
		       "line %d\n", idn_result_tostring(r), lineno));
		return (r);
	}

	sprintf(scheme_name, "%s%s", IDN_CHECKER_UNASSIGNED_PREFIX, argv[0]);
	r = idn_checker_add(ctx->unassigned_checker, scheme_name);
	if (r == idn_invalid_name) {
		ERROR(("libidnkit: unknown unassigned scheme \"%-.30s\", "
		       "line %d\n", argv[0], lineno));
		return (r);
	} else if (r != idn_success) {
		return (r);
	}

	/*
	 * Set bidi checker.
	 */
	r = idn_checker_create(&ctx->bidi_checker);
	if (r != idn_success) {
		ERROR(("libidnkit: cannot create bidi checker, %s, line %d\n",
		       idn_result_tostring(r), lineno));
		return (r);
	}

	sprintf(scheme_name, "%s%s", IDN_CHECKER_BIDI_PREFIX, argv[0]);
	r = idn_checker_add(ctx->bidi_checker, scheme_name);
	if (r == idn_invalid_name) {
		ERROR(("libidnkit: unknown bidi scheme \"%-.30s\", "
		       "line %d\n", argv[0], lineno));
		return (r);
	} else if (r != idn_success) {
		return (r);
	}

	return (idn_success);
}