1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2009 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <sys/types.h>
25 #define S_ISREG(x) (x & _S_IFREG)
26 #define S_ISDIR(x) (x & _S_IFDIR)
39 #include "indexplugin.h"
47 zebra_index_plugin_object *pluginObj = NULL;
49 static zebra_index_plugin_object *newZebraPlugin(void)
51 zebra_index_plugin_object *newPlugin = malloc(sizeof(zebra_index_plugin_object));
55 static void destroyZebraPlugin(zebra_index_plugin_object *zebraIdxPlugin)
60 void addDriverFunction(indexList function)
62 /* Assign the function to the object */
63 pluginObj->idxList = function;
67 void zebraIndexBuffer(ZebraHandle zh, char *data, int dataLength, enum zebra_recctrl_action_t action, char *name)
69 zebra_buffer_extract_record(zh, data, dataLength, action, zh->m_record_type, NULL, NULL, name);
73 /* I'm not even sure what this is for */
74 void repositoryShowDriver(ZebraHandle zh, const char *path)
78 struct dirs_entry *dst;
82 if (!(dict = dict_open_res(zh->reg->bfs, FMATCH_DICT, 50, 0, 0, zh->res)))
84 yaz_log(YLOG_FATAL, "dict_open fail of %s", FMATCH_DICT);
88 strncpy(src, path, sizeof(src)-1);
89 src[sizeof(src)-1]='\0';
90 src_len = strlen(src);
92 if (src_len && src[src_len-1] != '/')
95 src[++src_len] = '\0';
98 di = dirs_open(dict, src, zh->m_flag_rw);
100 while ((dst = dirs_read(di)))
101 yaz_log(YLOG_LOG, "%s", dst->path);
107 ZEBRA_RES zebra_update_from_driver(ZebraHandle zh, const char *path,
108 enum zebra_recctrl_action_t action, char *useIndexDriver)
110 /* delcair something to hold out remote call */
111 void (*idxPluginRegister)(void);
116 char driverName[100];
117 sprintf(driverName, "mod-%s.so", useIndexDriver);
119 yaz_log(YLOG_LOG, "Loading driver %s", useIndexDriver);
121 libHandle = dlopen(driverName, RTLD_LAZY);
124 yaz_log(YLOG_FATAL, "Unable to load index plugin %s", dlerror());
127 /* clear the error buffer */
130 idxPluginRegister = dlsym(libHandle, "indexPluginRegister");
132 if ((dlError = dlerror()) != NULL)
134 yaz_log(YLOG_FATAL, "Index plugin error: %s", dlError);
136 /* Although the documentation says this dlclose isn't needed
137 it seems better to put it in, incase there were memory
143 pluginObj = newZebraPlugin();
145 /* invoke the plugin starter */
148 pluginReturn = pluginObj->idxList(zh, path, action);
149 destroyZebraPlugin(pluginObj);
151 /* close the plugin handle */
154 /* repositoryExtract(zh, path, action);*/
161 * c-file-style: "Stroustrup"
162 * indent-tabs-mode: nil
164 * vim: shiftwidth=4 tabstop=8 expandtab