Example #1
0
apr_iconv_ces_open(const char *cesname, struct iconv_ces **cespp, apr_pool_t *ctx)
{
	struct iconv_module *mod;
	struct iconv_ces *ces;
	apr_status_t error;

	error = apr_iconv_mod_load(cesname, ICMOD_UC_CES, NULL, &mod, ctx);
	if (APR_STATUS_IS_EFTYPE(error))
		error = apr_iconv_mod_load("_tbl_simple", ICMOD_UC_CES, cesname, &mod, ctx);
	if (error != APR_SUCCESS)
		return (APR_STATUS_IS_EFTYPE(error)) ? APR_EINVAL : error;
	ces = malloc(sizeof(*ces));
	if (ces == NULL) {
		apr_iconv_mod_unload(mod, ctx);
		return APR_ENOMEM;
	}
	memset(ces,0, sizeof(*ces));
	ces->desc = (struct iconv_ces_desc*)mod->im_desc->imd_data;
	ces->data = mod->im_data;
	ces->mod = mod;
	error = ICONV_CES_OPEN(ces,ctx);
	if (error != APR_SUCCESS) {
		free(ces);
		apr_iconv_mod_unload(mod, ctx);
		return error;
	}
	*cespp = ces;
	return APR_SUCCESS;
}
Example #2
0
apr_iconv_mod_load(const char *modname, int modtype, const void *args,
	struct iconv_module **modpp, apr_pool_t *ctx)
{
	struct iconv_module_desc *mdesc;
	struct iconv_module *mod, *depmod;
	const struct iconv_module_depend *depend;
	char buffer[APR_PATH_MAX];
	void *handle;
	int error;

	if (iconv_getpath(buffer, modname, ctx) != 0)
		return EINVAL;

	error = iconv_dlopen(buffer, "iconv_module", &handle, (void**)&mdesc, ctx);
	if (error)
		return error;
	if (modtype != ICMOD_ANY && mdesc->imd_type != modtype) {
		apr_dso_unload(handle);
		return APR_EFTYPE;
	}
	mod = malloc(sizeof(*mod));
	if (mod == NULL) {
		apr_dso_unload(handle);
		return ENOMEM;
	}
	memset(mod, 0, sizeof(*mod));
	mod->im_handle = handle;
	mod->im_desc = mdesc;
	mod->im_args = args;
	depend = mdesc->imd_depend;
	if (depend) {
		while (depend->md_name) {
			error = apr_iconv_mod_load(depend->md_name, 
			    depend->md_type, NULL, &depmod, ctx);
			if (error)
				goto bad;
			depmod->im_depdata = depend->md_data;
			depmod->im_next = mod->im_deplist;
			mod->im_deplist = depmod;
			depend++;
		}
	}
	error = ICONV_MOD_DYN_LOAD(mod,ctx);
	if (error)
		goto bad;
	depmod = mod->im_deplist;
	while (depmod) {
		mod->im_depcnt++;
		depmod = depmod->im_next;
	}
	error = ICONV_MOD_LOAD(mod,ctx);
	if (error)
		goto bad;
	mod->im_flags |= ICMODF_LOADED;
	*modpp = mod;
	return 0;
bad:
	apr_iconv_mod_unload(mod,ctx);
	return error;
}