X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=recctrl%2Frecctrl.c;h=410effc8ad2eae08515f4298b1eff2bd7a77c0c2;hb=ecb3935e78cd9bcfdebafdee0834cfb1060d7b5e;hp=5205cd3fc1e5a7d46d80c63826b3c984181ebf97;hpb=b673999f9e517726d6e3789f3cefd194ce89ef15;p=idzebra-moved-to-github.git diff --git a/recctrl/recctrl.c b/recctrl/recctrl.c index 5205cd3..410effc 100644 --- a/recctrl/recctrl.c +++ b/recctrl/recctrl.c @@ -1,6 +1,6 @@ -/* $Id: recctrl.c,v 1.11 2004-09-30 07:23:15 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 - Index Data Aps +/* $Id: recctrl.c,v 1.25 2006-05-10 08:13:28 adam Exp $ + Copyright (C) 1995-2006 + Index Data ApS This file is part of the Zebra server. @@ -24,10 +24,12 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include +#if HAVE_DLFCN_H #include +#endif #include -#include +#include #include struct recTypeClass { @@ -48,57 +50,110 @@ struct recTypes { struct recTypeInstance *entries; }; -#ifdef IDZEBRA_STATIC_TEXT - extern RecType idzebra_filter_text[]; -#endif -#ifdef IDZEBRA_STATIC_GRS_XML -#if HAVE_EXPAT_H - extern RecType idzebra_filter_grs_xml[]; -#endif -#endif -#ifdef IDZEBRA_STATIC_GRS_REGX - extern RecType idzebra_filter_grs_regx[]; -#endif -#ifdef IDZEBRA_STATIC_GRS_MARC - extern RecType idzebra_filter_grs_marc[]; -#endif -#ifdef IDZEBRA_STATIC_GRS_DANBIB - extern RecType idzebra_filter_grs_danbib[]; -#endif - static void recTypeClass_add (struct recTypeClass **rts, RecType *rt, NMEM nmem, void *module_handle); + RecTypeClass recTypeClass_create (Res res, NMEM nmem) { struct recTypeClass *rts = 0; - const char *module_path = res_get_def(res, "modulePath", - DEFAULT_MODULE_PATH); - extern RecType idzebra_filter_grs_sgml[]; - recTypeClass_add (&rts, idzebra_filter_grs_sgml, nmem, 0); +#ifdef IDZEBRA_STATIC_GRS_SGML + if (1) + { + extern RecType idzebra_filter_grs_sgml[]; + recTypeClass_add (&rts, idzebra_filter_grs_sgml, nmem, 0); + } +#endif + #ifdef IDZEBRA_STATIC_TEXT - recTypeClass_add (&rts, idzebra_filter_text, nmem, 0); + if (1) + { + extern RecType idzebra_filter_text[]; + recTypeClass_add (&rts, idzebra_filter_text, nmem, 0); + } #endif + #ifdef IDZEBRA_STATIC_GRS_XML #if HAVE_EXPAT_H - recTypeClass_add (&rts, idzebra_filter_grs_xml, nmem, 0); + if (1) + { + extern RecType idzebra_filter_grs_xml[]; + recTypeClass_add (&rts, idzebra_filter_grs_xml, nmem, 0); + } #endif #endif + #ifdef IDZEBRA_STATIC_GRS_REGX - recTypeClass_add (&rts, idzebra_filter_grs_regx, nmem, 0); + if (1) + { + extern RecType idzebra_filter_grs_regx[]; + recTypeClass_add (&rts, idzebra_filter_grs_regx, nmem, 0); + } #endif + #ifdef IDZEBRA_STATIC_GRS_MARC - recTypeClass_add (&rts, idzebra_filter_grs_marc, nmem, 0); + if (1) + { + extern RecType idzebra_filter_grs_marc[]; + recTypeClass_add (&rts, idzebra_filter_grs_marc, nmem, 0); + } #endif + +#ifdef IDZEBRA_STATIC_GRS_CSV + if (1) + { + extern RecType idzebra_filter_grs_csv[]; + recTypeClass_add (&rts, idzebra_filter_grs_csv, nmem, 0); + } +#endif + #ifdef IDZEBRA_STATIC_GRS_DANBIB - recTypeClass_add (&rts, idzebra_filter_grs_danbib, nmem, 0); + if (1) + { + extern RecType idzebra_filter_grs_danbib[]; + recTypeClass_add (&rts, idzebra_filter_grs_danbib, nmem, 0); + } +#endif + +#ifdef IDZEBRA_STATIC_SAFARI + if (1) + { + extern RecType idzebra_filter_safari[]; + recTypeClass_add (&rts, idzebra_filter_safari, nmem, 0); + } +#endif + +#ifdef IDZEBRA_STATIC_ALVIS +#if HAVE_XSLT + if (1) + { + extern RecType idzebra_filter_alvis[]; + recTypeClass_add (&rts, idzebra_filter_alvis, nmem, 0); + } +#endif #endif +#ifdef IDZEBRA_STATIC_XSLT +#if HAVE_XSLT + if (1) + { + extern RecType idzebra_filter_xslt[]; + recTypeClass_add (&rts, idzebra_filter_xslt, nmem, 0); + } +#endif +#endif + return rts; +} + +void recTypeClass_load_modules(RecTypeClass *rts, NMEM nmem, + const char *module_path) +{ +#if HAVE_DLFCN_H if (module_path) { DIR *dir = opendir(module_path); - yaz_log(LOG_LOG, "searching filters in %s", module_path); + yaz_log(YLOG_LOG, "searching filters in %s", module_path); if (dir) { struct dirent *de; @@ -106,8 +161,7 @@ RecTypeClass recTypeClass_create (Res res, NMEM nmem) while ((de = readdir(dir))) { size_t dlen = strlen(de->d_name); - if ((de->d_type == DT_REG || de->d_type == DT_LNK) - && dlen >= 5 && + if (dlen >= 5 && !memcmp(de->d_name, "mod-", 4) && !strcmp(de->d_name + dlen - 3, ".so")) { @@ -119,20 +173,20 @@ RecTypeClass recTypeClass_create (Res res, NMEM nmem) mod_p = dlopen(fname, RTLD_NOW|RTLD_GLOBAL); if (mod_p && (fl = dlsym(mod_p, "idzebra_filter"))) { - yaz_log(LOG_LOG, "Loaded filter module %s", fname); - recTypeClass_add(&rts, fl, nmem, mod_p); + yaz_log(YLOG_LOG, "Loaded filter module %s", fname); + recTypeClass_add(rts, fl, nmem, mod_p); } else if (mod_p) { const char *err = dlerror(); - yaz_log(LOG_WARN, "dlsym failed %s %s", + yaz_log(YLOG_WARN, "dlsym failed %s %s", fname, err ? err : "none"); dlclose(mod_p); } else { const char *err = dlerror(); - yaz_log(LOG_WARN, "dlopen failed %s %s", + yaz_log(YLOG_WARN, "dlopen failed %s %s", fname, err ? err : "none"); } @@ -141,11 +195,11 @@ RecTypeClass recTypeClass_create (Res res, NMEM nmem) closedir(dir); } } - return rts; +#endif } -static void recTypeClass_add (struct recTypeClass **rts, RecType *rt, - NMEM nmem, void *module_handle) +static void recTypeClass_add(struct recTypeClass **rts, RecType *rt, + NMEM nmem, void *module_handle) { while (*rt) { @@ -155,7 +209,7 @@ static void recTypeClass_add (struct recTypeClass **rts, RecType *rt, r->next = *rts; *rts = r; - yaz_log(LOG_LOG, "Adding filter %s", (*rt)->name); + yaz_log(YLOG_LOG, "Adding filter %s", (*rt)->name); r->module_handle = module_handle; module_handle = 0; /* so that we only store module_handle once */ r->recType = *rt; @@ -175,8 +229,10 @@ void recTypeClass_destroy(RecTypeClass rtc) { for (; rtc; rtc = rtc->next) { +#if HAVE_DLFCN_H if (rtc->module_handle) dlclose(rtc->module_handle); +#endif } } @@ -232,10 +288,22 @@ RecType recType_byName (RecTypes rts, Res res, const char *name, slen++; /* skip . */ if (rti->recType->config) - (*(rti->recType)->config)(rti->clientData, res, name+slen); + { + if ((*(rti->recType)->config) + (rti->clientData, res, name+slen) != ZEBRA_OK) + return 0; + } return rti->recType; } } return 0; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +