Fix uninit variable (hits_limit)
[idzebra-moved-to-github.git] / index / recctrl.c
index 24beaae..f24395e 100644 (file)
@@ -1,8 +1,5 @@
-/* $Id: recctrl.c,v 1.1 2006-07-03 14:27:09 adam Exp $
-   Copyright (C) 1995-2006
-   Index Data ApS
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+   Copyright (C) 1994-2011 Index Data
 
 Zebra is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -15,12 +12,15 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
 */
 
 
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <stdio.h>
 #include <assert.h>
 #include <string.h>
@@ -58,7 +58,7 @@ RecTypeClass recTypeClass_create (Res res, NMEM nmem)
 {
     struct recTypeClass *rts = 0;
 
-#ifdef IDZEBRA_STATIC_GRS_SGML
+#if IDZEBRA_STATIC_GRS_SGML
     if (1)
     {
        extern RecType idzebra_filter_grs_sgml[];
@@ -66,7 +66,7 @@ RecTypeClass recTypeClass_create (Res res, NMEM nmem)
     }
 #endif
 
-#ifdef IDZEBRA_STATIC_TEXT
+#if IDZEBRA_STATIC_TEXT
     if (1)
     {
        extern RecType idzebra_filter_text[];
@@ -74,7 +74,7 @@ RecTypeClass recTypeClass_create (Res res, NMEM nmem)
     }
 #endif
 
-#ifdef IDZEBRA_STATIC_GRS_XML
+#if IDZEBRA_STATIC_GRS_XML
 #if HAVE_EXPAT_H
     if (1)
     {
@@ -84,7 +84,7 @@ RecTypeClass recTypeClass_create (Res res, NMEM nmem)
 #endif
 #endif
 
-#ifdef IDZEBRA_STATIC_GRS_REGX
+#if IDZEBRA_STATIC_GRS_REGX
     if (1)
     {
        extern RecType idzebra_filter_grs_regx[];
@@ -92,7 +92,7 @@ RecTypeClass recTypeClass_create (Res res, NMEM nmem)
     }
 #endif
 
-#ifdef IDZEBRA_STATIC_GRS_MARC
+#if IDZEBRA_STATIC_GRS_MARC
     if (1)
     {
        extern RecType idzebra_filter_grs_marc[];
@@ -100,7 +100,7 @@ RecTypeClass recTypeClass_create (Res res, NMEM nmem)
     }
 #endif
 
-#ifdef IDZEBRA_STATIC_SAFARI
+#if IDZEBRA_STATIC_SAFARI
     if (1)
     {
        extern RecType idzebra_filter_safari[];
@@ -108,71 +108,92 @@ RecTypeClass recTypeClass_create (Res res, NMEM nmem)
     }
 #endif
 
-#ifdef IDZEBRA_STATIC_ALVIS
-#if HAVE_XSLT
+#if IDZEBRA_STATIC_ALVIS
     if (1)
     {
        extern RecType idzebra_filter_alvis[];
        recTypeClass_add (&rts, idzebra_filter_alvis, nmem, 0);
     }
 #endif
+
+#if IDZEBRA_STATIC_DOM
+    if (1)
+    {
+       extern RecType idzebra_filter_dom[];
+       recTypeClass_add (&rts, idzebra_filter_dom, nmem, 0);
+    }
 #endif
 
     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 +205,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;
@@ -277,6 +297,7 @@ RecType recType_byName (RecTypes rts, Res res, const char *name,
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab