Пример #1
0
idn_result_t
idn_checker_initialize(void) {
	idn_result_t r;
	check_scheme_t **scheme;

	TRACE(("idn_checker_initialize()\n"));

	if (scheme_hash != NULL) {
		r = idn_success;	/* already initialized */
		goto ret;
	}

	r = idn__strhash_create(&scheme_hash);
	if (r != idn_success) {
		goto ret;
	}

	for (scheme = (check_scheme_t **)standard_check_schemes;
		*scheme != NULL; scheme++) {
		r = idn__strhash_put(scheme_hash, (*scheme)->prefix, *scheme);
		if (r != idn_success)
			goto ret;
	}

	r = idn_success;
ret:
	if (r != idn_success) {
		if (scheme_hash != NULL) {
			idn__strhash_destroy(scheme_hash, NULL);
			scheme_hash = NULL;
		}
	}
	TRACE(("idn_checker_initialize(): %s\n", idn_result_tostring(r)));
	return (r);
}
Пример #2
0
idn_result_t
idn_normalizer_register(const char *scheme_name, idn_normalizer_proc_t proc) {
	idn_result_t r;
	normalize_scheme_t *scheme;

	assert(scheme_name != NULL && proc != NULL);

	TRACE(("idn_normalizer_register(scheme_name=%s)\n", scheme_name));

	assert(INITIALIZED);

	scheme = malloc(sizeof(*scheme) + strlen(scheme_name) + 1);
	if (scheme == NULL) {
		r = idn_nomemory;
		goto ret;
	}
	scheme->name = (char *)(scheme + 1);
	(void)strcpy(scheme->name, scheme_name);
	scheme->proc = proc;

	r = idn__strhash_put(scheme_hash, scheme_name, scheme);
	if (r != idn_success)
		goto ret;

	r = idn_success;
ret:
	TRACE(("idn_normalizer_register(): %s\n", idn_result_tostring(r)));
	return (r);
}
Пример #3
0
idn_result_t
idn_mapper_register(const char *prefix,		    
		    idn_mapper_createproc_t create,
		    idn_mapper_destroyproc_t destroy,
		    idn_mapper_mapproc_t map) {
	idn_result_t r;
	map_scheme_t *scheme = NULL;

	assert(scheme_hash != NULL);
	assert(prefix != NULL && create != NULL && destroy != NULL &&
		map != NULL);

	TRACE(("idn_mapper_register(prefix=%s)\n", prefix));

	scheme = (map_scheme_t *) malloc(sizeof(map_scheme_t));
	if (scheme == NULL) {
		r = idn_nomemory;
		goto ret;
	}

	scheme->prefix = (char *) malloc(strlen(prefix) + 1);
	if (scheme->prefix == NULL) {
		r = idn_nomemory;
		goto ret;
	}

	strcpy(scheme->prefix, prefix);
	scheme->parameter = NULL;
	scheme->create    = create;
	scheme->destroy   = destroy;
	scheme->map       = map;

	r = idn__strhash_put(scheme_hash, prefix, scheme);
	if (r != idn_success)
		goto ret;

	r = idn_success;
ret:
	if (r != idn_success) {
		if (scheme != NULL)
			free(scheme->prefix);
		free(scheme);
	}

	TRACE(("idn_mapper_register(): %s\n", idn_result_tostring(r)));
	return (r);
}
Пример #4
0
idn_result_t
idn_converter_register(const char *name,
		       idn_converter_openproc_t openfromucs4,
		       idn_converter_openproc_t opentoucs4,
		       idn_converter_convfromucs4proc_t convfromucs4,
		       idn_converter_convtoucs4proc_t convtoucs4,
		       idn_converter_closeproc_t close,
		       int encoding_type) {
	converter_ops_t *ops;
	idn_result_t r;

	assert(name != NULL && convfromucs4 != NULL && convtoucs4 != NULL);

	TRACE(("idn_converter_register(name=%s)\n", name));

	if ((ops = malloc(sizeof(*ops))) == NULL) {
		r = idn_nomemory;
		goto ret;
	}

	if (openfromucs4 == NULL)
		openfromucs4 = converter_none_open;
	if (opentoucs4 == NULL)
		opentoucs4 = converter_none_open;
	if (close == NULL)
		close = converter_none_close;

	ops->openfromucs4 = openfromucs4;
	ops->opentoucs4 = opentoucs4;
	ops->convfromucs4 = convfromucs4;
	ops->convtoucs4 = convtoucs4;
	ops->close = close;
	ops->encoding_type = encoding_type;

	r = idn__strhash_put(encoding_name_hash, name, ops);
	if (r != idn_success) {
		free(ops);
		goto ret;
	}

	r = idn_success;
ret:
	TRACE(("idn_converter_register(): %s\n", idn_result_tostring(r)));
	return (r);
}