From: Adam Dickmeiss Date: Wed, 11 Oct 2006 08:55:52 +0000 (+0000) Subject: Fixed bug #670: modulePath is not a path. Uses new utility X-Git-Tag: ZEBRA.2.0.6~97 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=aff82b142abbf5043865c30c735f30187db3bb91 Fixed bug #670: modulePath is not a path. Uses new utility yaz_filepath_comp - available in YAZ 2.1.35 and later. --- diff --git a/configure.ac b/configure.ac index 83c1658..fcac86b 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ dnl Zebra, Index Data ApS, 1995-2006 -dnl $Id: configure.ac,v 1.32 2006-10-10 14:45:41 adam Exp $ +dnl $Id: configure.ac,v 1.33 2006-10-11 08:55:52 adam Exp $ dnl AC_PREREQ(2.59) AC_INIT([idzebra],[2.0.3],[adam@indexdata.dk]) @@ -41,7 +41,7 @@ else fi dnl dnl ------ YAZ -YAZ_INIT($yazflag,2.1.20) +YAZ_INIT($yazflag,2.1.35) if test "$YAZVERSION" = "NONE"; then AC_MSG_ERROR([YAZ development libraries required]) fi diff --git a/index/recctrl.c b/index/recctrl.c index d68ded3..beadf14 100644 --- a/index/recctrl.c +++ b/index/recctrl.c @@ -1,4 +1,4 @@ -/* $Id: recctrl.c,v 1.2 2006-08-14 10:40:15 adam Exp $ +/* $Id: recctrl.c,v 1.3 2006-10-11 08:55:52 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -121,58 +121,73 @@ RecTypeClass recTypeClass_create (Res res, NMEM nmem) return rts; } -void recTypeClass_load_modules(RecTypeClass *rts, NMEM nmem, - const char *module_path) +static void load_from_dir(RecTypeClass *rts, NMEM nmem, const char *dirname) { #if HAVE_DLFCN_H - if (module_path) + DIR *dir = opendir(dirname); + if (dir) { - DIR *dir = opendir(module_path); - yaz_log(YLOG_LOG, "searching filters in %s", module_path); - if (dir) - { - struct dirent *de; - - while ((de = readdir(dir))) - { - size_t dlen = strlen(de->d_name); - if (dlen >= 5 && - !memcmp(de->d_name, "mod-", 4) && - !strcmp(de->d_name + dlen - 3, ".so")) - { - void *mod_p, *fl; - char fname[FILENAME_MAX*2+1]; - sprintf(fname, "%.*s/%.*s", - FILENAME_MAX, module_path, - FILENAME_MAX, de->d_name); - mod_p = dlopen(fname, RTLD_NOW|RTLD_GLOBAL); - if (mod_p && (fl = dlsym(mod_p, "idzebra_filter"))) - { - 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(YLOG_WARN, "dlsym failed %s %s", - fname, err ? err : "none"); - dlclose(mod_p); - } - else - { - const char *err = dlerror(); - yaz_log(YLOG_WARN, "dlopen failed %s %s", - fname, err ? err : "none"); - - } - } - } - closedir(dir); - } + struct dirent *de; + + while ((de = readdir(dir))) + { + size_t dlen = strlen(de->d_name); + if (dlen >= 5 && + !memcmp(de->d_name, "mod-", 4) && + !strcmp(de->d_name + dlen - 3, ".so")) + { + void *mod_p, *fl; + char fname[FILENAME_MAX*2+1]; + sprintf(fname, "%.*s/%.*s", + FILENAME_MAX, dirname, + FILENAME_MAX, de->d_name); + mod_p = dlopen(fname, RTLD_NOW|RTLD_GLOBAL); + if (mod_p && (fl = dlsym(mod_p, "idzebra_filter"))) + { + 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(YLOG_WARN, "dlsym failed %s %s", + fname, err ? err : "none"); + dlclose(mod_p); + } + else + { + const char *err = dlerror(); + yaz_log(YLOG_WARN, "dlopen failed %s %s", + fname, err ? err : "none"); + + } + } + } + closedir(dir); } #endif } +void recTypeClass_load_modules(RecTypeClass *rts, NMEM nmem, + const char *module_path) +{ + while (module_path) + { + const char *comp_ptr; + char comp[FILENAME_MAX+1]; + size_t len; + + len = yaz_filepath_comp(&module_path, &comp_ptr); + if (!len || len >= FILENAME_MAX) + break; + + memcpy(comp, comp_ptr, len); + comp[len] = '\0'; + + load_from_dir(rts, nmem, comp); + } +} + static void recTypeClass_add(struct recTypeClass **rts, RecType *rt, NMEM nmem, void *module_handle) { @@ -184,7 +199,6 @@ static void recTypeClass_add(struct recTypeClass **rts, RecType *rt, r->next = *rts; *rts = r; - 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;