* Sebastian Hammer, Adam Dickmeiss
*
* $Log: bfile.c,v $
- * Revision 1.32 2000-03-15 15:00:30 adam
+ * Revision 1.33 2002-04-04 14:14:13 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.32 2000/03/15 15:00:30 adam
* First work on threaded version.
*
* Revision 1.31 1999/12/08 15:03:11 adam
struct BFiles_struct {
MFile_area commit_area;
MFile_area_struct *register_area;
- char *lockDir;
+ char *base;
+ char *cache_fname;
};
-BFiles bfs_create (const char *spec)
+BFiles bfs_create (const char *spec, const char *base)
{
BFiles bfs = (BFiles) xmalloc (sizeof(*bfs));
bfs->commit_area = NULL;
- bfs->register_area = mf_init("register", spec);
- bfs->lockDir = NULL;
+ bfs->base = 0;
+ bfs->cache_fname = 0;
+ if (base)
+ bfs->base = xstrdup (base);
+ bfs->register_area = mf_init("register", spec, base);
if (!bfs->register_area)
{
bfs_destroy(bfs);
void bfs_destroy (BFiles bfs)
{
- xfree (bfs->lockDir);
+ xfree (bfs->cache_fname);
+ xfree (bfs->base);
mf_destroy (bfs->commit_area);
mf_destroy (bfs->register_area);
xfree (bfs);
static FILE *open_cache (BFiles bfs, const char *flags)
{
- char cacheFilename[1024];
FILE *file;
- sprintf (cacheFilename, "%scache",
- bfs->lockDir ? bfs->lockDir : "");
- file = fopen (cacheFilename, flags);
+ file = fopen (bfs->cache_fname, flags);
return file;
}
static void unlink_cache (BFiles bfs)
{
- char cacheFilename[1024];
-
- sprintf (cacheFilename, "%scache",
- bfs->lockDir ? bfs->lockDir : "");
- unlink (cacheFilename);
-}
-
-void bf_lockDir (BFiles bfs, const char *lockDir)
-{
- size_t len;
-
- xfree (bfs->lockDir);
- if (lockDir == NULL)
- lockDir = "";
- len = strlen(lockDir);
- bfs->lockDir = (char *) xmalloc (len+2);
- strcpy (bfs->lockDir, lockDir);
-
- if (len > 0 && bfs->lockDir[len-1] != '/')
- strcpy (bfs->lockDir + len, "/");
+ unlink (bfs->cache_fname);
}
void bf_cache (BFiles bfs, const char *spec)
{
if (spec)
{
+ yaz_log (LOG_LOG, "enabling cache spec=%s", spec);
if (!bfs->commit_area)
- bfs->commit_area = mf_init ("shadow", spec);
+ bfs->commit_area = mf_init ("shadow", spec, bfs->base);
+ if (bfs->commit_area)
+ {
+ bfs->cache_fname = xmalloc (strlen(bfs->commit_area->dirs->name)+
+ 8);
+ strcpy (bfs->cache_fname, bfs->commit_area->dirs->name);
+ strcat (bfs->cache_fname, "/cache");
+ yaz_log (LOG_LOG, "cache_fname = %s", bfs->cache_fname);
+ }
}
else
bfs->commit_area = NULL;
outf = open_cache (bfs, "ab");
if (!outf)
{
- logf (LOG_FATAL|LOG_ERRNO, "open %scache",
- bfs->lockDir ? bfs->lockDir : "");
+ logf (LOG_FATAL|LOG_ERRNO, "open %s", bfs->cache_fname);
exit (1);
}
fprintf (outf, "%s %d\n", name, block_size);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: mfile.c,v $
- * Revision 1.41 2000-11-29 14:24:01 adam
+ * Revision 1.42 2002-04-04 14:14:13 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.41 2000/11/29 14:24:01 adam
* Script configure uses yaz pthreads options. Added locking for
* zebra_register_{lock,unlock}.
*
#include <zebrautl.h>
#include <mfile.h>
-static int scan_areadef(MFile_area ma, const char *name, const char *ad)
+static int scan_areadef(MFile_area ma, const char *ad, const char *base)
{
/*
* If no definition is given, use current directory, unlimited.
mf_dir **dp = &ma->dirs, *dir = *dp;
if (!ad)
- ad = ".:-1b";
+ ad = ".:-1b";
for (;;)
{
const char *ad0 = ad;
ad++;
if (!*ad)
break;
+ if (!zebra_is_abspath(ad) && base)
+ {
+ strcpy (dirname, base);
+ i = strlen(dirname);
+ dirname[i++] = '/';
+ }
while (*ad)
{
if (*ad == ':' && strchr ("+-0123456789", ad[1]))
* Create a new area, cotaining metafiles in directories.
* Find the part-files in each directory, and inventory the existing metafiles.
*/
-MFile_area mf_init(const char *name, const char *spec)
+MFile_area mf_init(const char *name, const char *spec, const char *base)
{
MFile_area ma = (MFile_area) xmalloc(sizeof(*ma));
mf_dir *dirp;
strcpy(ma->name, name);
ma->mfiles = 0;
ma->dirs = 0;
- if (scan_areadef(ma, name, spec) < 0)
+ if (scan_areadef(ma, spec, base) < 0)
{
logf (LOG_WARN, "Failed to access description of '%s'", name);
return 0;
#!/bin/sh
-# $Id: buildconf.sh,v 1.5 2001-02-28 09:01:41 adam Exp $
+# $Id: buildconf.sh,v 1.6 2002-04-04 14:14:13 adam Exp $
dir=`aclocal --print-ac-dir`
if [ -f $dir/yaz.m4 ]; then
- aclocal || exit 1
+ aclocal
else
- aclocal -I . || exit 1
+ aclocal -I .
fi
test -d isamc || mkdir isamc
test -d isamb || mkdir isamb
test -d isam || mkdir isam
-automake -a >/dev/null 2>&1 || exit 2
-autoconf || exit 3
+automake -a >/dev/null 2>&1
+autoconf
if [ -f config.cache ]; then
rm config.cache
fi
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: dicttest.c,v $
- * Revision 1.25 2000-12-05 09:59:10 adam
+ * Revision 1.26 2002-04-04 14:14:13 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.25 2000/12/05 09:59:10 adam
* Work on dict_delete_subtree.
*
* Revision 1.24 2000/09/05 14:04:05 adam
logf (LOG_FATAL, "no config and/or dictionary specified");
exit (1);
}
- my_resource = res_open (config);
+ my_resource = res_open (config, 0);
if (!my_resource)
{
logf (LOG_FATAL, "cannot open resource `%s'", config);
exit (1);
}
- bfs = bfs_create (res_get(my_resource, "register"));
+ bfs = bfs_create (res_get(my_resource, "register"), 0);
if (!bfs)
{
logf (LOG_FATAL, "bfs_create fail");
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: bfile.h,v 1.19 2000-03-15 15:00:30 adam Exp $
+ * $Id: bfile.h,v 1.20 2002-04-04 14:14:13 adam Exp $
*/
#ifndef BFILE_H
typedef struct BFiles_struct *BFiles;
-BFiles bfs_create (const char *spec);
+BFiles bfs_create (const char *spec, const char *base);
void bfs_destroy (BFiles bfiles);
typedef struct BFile_struct
/* bf_cache: enables bfile cache if spec is not NULL */
void bf_cache (BFiles bfs, const char *spec);
-/* bf_lockDir: specifies locking directory for the cache system */
-void bf_lockDir (BFiles bfs, const char *lockDir);
-
/* bf_commitExists: returns 1 if commit is pending; 0 otherwise */
int bf_commitExists (BFiles bfs);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: direntz.h,v $
- * Revision 1.4 1999-05-26 07:49:13 adam
+ * Revision 1.5 2002-04-04 14:14:13 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.4 1999/05/26 07:49:13 adam
* C++ compilation.
*
* Revision 1.3 1999/02/02 14:50:33 adam
/* include UNIX version */
#include <dirent.h>
#endif
+
+int zebra_is_abspath (const char *p);
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: mfile.h,v 1.16 2001-01-14 13:41:06 adam Exp $
+ * $Id: mfile.h,v 1.17 2002-04-04 14:14:13 adam Exp $
*/
#ifndef MFILE_H
/*
* Open an area, cotaining metafiles in directories.
*/
-MFile_area mf_init(const char *name, const char *spec);
+MFile_area mf_init(const char *name, const char *spec, const char *base);
/*
* Release an area.
/*
- * Copyright (C) 1994-1999, Index Data
+ * Copyright (C) 1994-2002, Index Data
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Log: res.h,v $
- * Revision 1.10 1999-02-02 14:50:36 adam
- * Updated WIN32 code specific sections. Changed header.
- *
- * Revision 1.9 1997/11/18 10:04:03 adam
- * Function res_trav returns number of 'hits'.
- *
- * Revision 1.8 1997/09/17 12:19:10 adam
- * Zebra version corresponds to YAZ version 1.4.
- * Changed Zebra server so that it doesn't depend on global common_resource.
- *
- * Revision 1.7 1997/09/05 15:30:02 adam
- * Changed prototype for chr_map_input - added const.
- * Added support for C++, headers uses extern "C" for public definitions.
- *
- * Revision 1.6 1996/10/29 13:44:12 adam
- * Added res_get_match.
- *
- * Revision 1.5 1994/09/16 14:37:46 quinn
- * added res_get_def
- *
- * Revision 1.4 1994/09/06 13:02:29 quinn
- * Removed const from res_get
- *
- * Revision 1.3 1994/08/18 09:43:04 adam
- * Added res_trav. Major changes of prototypes.
- *
- * Revision 1.2 1994/08/18 08:22:26 adam
- * Res.h modified. xmalloc now declares xstrdup.
- *
+ * $Id: res.h,v 1.11 2002-04-04 14:14:13 adam Exp $
*/
#ifndef RES_H
extern "C" {
#endif
-struct res_entry {
- char *name;
- char *value;
- struct res_entry *next;
-};
-
-typedef struct res_struct {
- struct res_entry *first, *last;
- char *name;
- int init;
-} *Res;
+typedef struct res_struct *Res;
-Res res_open (const char *name);
+Res res_open (const char *name, Res res_def);
void res_close (Res r);
char *res_get (Res r, const char *name);
char *res_get_def (Res r, const char *name, char *def);
* Copyright (C) 1995-2000, Index Data
* All rights reserved.
*
- * $Header: /home/cvsroot/idis/index/Attic/apitest.c,v 1.10 2000-09-06 08:59:36 adam Exp $
+ * $Header: /home/cvsroot/idis/index/Attic/apitest.c,v 1.11 2002-04-04 14:14:13 adam Exp $
*/
#include <stdio.h>
ZebraHandle zh;
/* the database we specify in our example */
- char *base = "Default";
+ const char *base = "Default";
int argno;
nmem_init ();
printf ("zebras_open failed\n");
exit (1);
}
+ zebra_select_databases (zh, 1, &base);
/* Each argument to main will be a query */
for (argno = 1; argno < argc; argno++)
{
char setname[64];
int errCode;
int i;
- const char *errString;
- char *errAdd;
+ int hits;
+ char *errString;
ZebraRetrievalRecord *records;
int noOfRecordsToFetch;
sprintf (setname, "%d", argno);
/* fire up the search */
- zebra_search_rpn (zh, odr_input, odr_output, query, 1, &base, setname);
+ zebra_search_rpn (zh, odr_input, odr_output, query, setname, &hits);
/* status ... */
- errCode = zebra_errCode (zh);
- errString = zebra_errString (zh);
- errAdd = zebra_errAdd (zh);
+ zebra_result (zh, &errCode, &errString);
/* error? */
if (errCode)
{
- printf ("Zebra Search Error %d %s %s\n",
- errCode, errString, errAdd ? errAdd : "");
+ printf ("Zebra Search Error %d %s\n",
+ errCode, errString);
continue;
}
/* ok ... */
- printf ("Zebra Search gave %d hits\n", zebra_hits (zh));
+ printf ("Zebra Search gave %d hits\n", hits);
/* Deterimine number of records to fetch ... */
- if (zebra_hits(zh) > 10)
+ if (hits > 10)
noOfRecordsToFetch = 10;
else
- noOfRecordsToFetch = zebra_hits(zh);
+ noOfRecordsToFetch = hits;
/* reset our memory - we've finished dealing with search */
odr_reset (odr_input);
noOfRecordsToFetch, records);
/* status ... */
- errCode = zebra_errCode (zh);
- errString = zebra_errString (zh);
- errAdd = zebra_errAdd (zh);
-
+
+ zebra_result (zh, &errCode, &errString);
+
/* error ? */
if (errCode)
{
- printf ("Zebra Search Error %d %s %s\n",
- errCode, errString, errAdd ? errAdd : "");
+ printf ("Zebra Search Error %d %s\n",
+ errCode, errString);
}
else
{
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: attribute.c,v $
- * Revision 1.12 2000-03-15 15:00:30 adam
+ * Revision 1.13 2002-04-04 14:14:13 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.12 2000/03/15 15:00:30 adam
* First work on threaded version.
*
* Revision 1.11 1999/11/30 13:48:03 adam
#include <yaz/log.h>
#include <res.h>
#include <zebrautl.h>
-#include "zserver.h"
+#include "index.h"
static data1_att *getatt(data1_attset *p, int att)
{
data1_att *r;
data1_attset *p;
- if (!(p = data1_attset_search_id (zi->service->dh, set)))
+ if (!(p = data1_attset_search_id (zi->reg->dh, set)))
{
- zebraExplain_loadAttsets (zi->service->dh, zi->service->res);
- p = data1_attset_search_id (zi->service->dh, set);
+ zebraExplain_loadAttsets (zi->reg->dh, zi->res);
+ p = data1_attset_search_id (zi->reg->dh, set);
}
if (!p)
return -2;
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: extract.c,v 1.113 2002-03-15 20:20:55 adam Exp $
+ * $Id: extract.c,v 1.114 2002-04-04 14:14:13 adam Exp $
*/
#include <stdio.h>
#include <assert.h>
#endif
#include <fcntl.h>
-#include <recctrl.h>
-#include <charmap.h>
-#include <sortidx.h>
#include "index.h"
-#include "zserver.h"
-#include "zinfo.h"
+#include <charmap.h>
#if _FILE_OFFSET_BITS == 64
#define PRINTF_OFF_T "%Ld"
#define PRINTF_OFF_T "%ld"
#endif
-#ifndef ZEBRASDR
-#define ZEBRASDR 0
-#endif
-
-#if ZEBRASDR
-#include "zebrasdr.h"
-#endif
-
static int records_inserted = 0;
static int records_updated = 0;
static int records_deleted = 0;
ws[i] = NULL;
#if SU_SCHEME
- chS = zebraExplain_lookupSU (zh->service->zei, attrSetS, attrUseS);
+ chS = zebraExplain_lookupSU (zh->reg->zei, attrSetS, attrUseS);
if (chS < 0)
return ws;
#endif
p->file_moffset = offset;
}
-static char *fileMatchStr (ZebraHandle zh,
+static char *fileMatchStr (ZebraHandle zh,
struct recKeys *reckeys, struct recordGroup *rGroup,
const char *fname, const char *spec)
{
attname_str[i] = '\0';
}
- if ((attset = data1_get_attset (zh->service->dh, attset_str)))
+ if ((attset = data1_get_attset (zh->reg->dh, attset_str)))
{
data1_att *att;
attSet = attset->reference;
- att = data1_getattbyname(zh->service->dh, attset, attname_str);
+ att = data1_getattbyname(zh->reg->dh, attset, attname_str);
if (att)
attUse = att->value;
else
/* we are going to read from a file, so prepare the extraction */
int i;
- zh->keys.buf_used = 0;
- zh->keys.prevAttrUse = -1;
- zh->keys.prevAttrSet = -1;
- zh->keys.prevSeqNo = 0;
- zh->sortKeys = 0;
+ zh->reg->keys.buf_used = 0;
+ zh->reg->keys.prevAttrUse = -1;
+ zh->reg->keys.prevAttrSet = -1;
+ zh->reg->keys.prevSeqNo = 0;
+ zh->reg->sortKeys = 0;
recordOffset = fi->file_moffset;
extractCtrl.offset = fi->file_moffset;
extractCtrl.init = extract_init;
extractCtrl.tokenAdd = extract_token_add;
extractCtrl.schemaAdd = extract_schema_add;
- extractCtrl.dh = zh->service->dh;
+ extractCtrl.dh = zh->reg->dh;
extractCtrl.handle = zh;
for (i = 0; i<256; i++)
{
- if (zebra_maps_is_positioned(zh->service->zebra_maps, i))
+ if (zebra_maps_is_positioned(zh->reg->zebra_maps, i))
extractCtrl.seqno[i] = 1;
else
extractCtrl.seqno[i] = 0;
}
- extractCtrl.zebra_maps = zh->service->zebra_maps;
+ extractCtrl.zebra_maps = zh->reg->zebra_maps;
extractCtrl.flagShowRecords = !rGroup->flagRw;
if (!rGroup->flagRw)
}
return 0;
}
- if (zh->keys.buf_used == 0)
+ if (zh->reg->keys.buf_used == 0)
{
/* the extraction process returned no information - the record
is probably empty - unless flagShowRecords is in use */
{
char *rinfo;
- matchStr = fileMatchStr (zh, &zh->keys, rGroup, fname,
+ matchStr = fileMatchStr (zh, &zh->reg->keys, rGroup, fname,
rGroup->recordId);
if (matchStr)
{
- rinfo = dict_lookup (zh->service->matchDict, matchStr);
+ rinfo = dict_lookup (zh->reg->matchDict, matchStr);
if (rinfo)
memcpy (sysno, rinfo+1, sizeof(*sysno));
}
if (records_processed < rGroup->fileVerboseLimit)
logf (LOG_LOG, "add %s %s " PRINTF_OFF_T, rGroup->recordType,
fname, recordOffset);
- rec = rec_new (zh->service->records);
+ rec = rec_new (zh->reg->records);
*sysno = rec->sysno;
- recordAttr = rec_init_attr (zh->service->zei, rec);
+ recordAttr = rec_init_attr (zh->reg->zei, rec);
if (matchStr)
{
- dict_insert (zh->service->matchDict, matchStr, sizeof(*sysno), sysno);
+ dict_insert (zh->reg->matchDict, matchStr, sizeof(*sysno), sysno);
}
- extract_flushRecordKeys (zh, *sysno, 1, &zh->keys);
- extract_flushSortKeys (zh, *sysno, 1, &zh->sortKeys);
+ extract_flushRecordKeys (zh, *sysno, 1, &zh->reg->keys);
+ extract_flushSortKeys (zh, *sysno, 1, &zh->reg->sortKeys);
records_inserted++;
}
/* record already exists */
struct recKeys delkeys;
- rec = rec_get (zh->service->records, *sysno);
+ rec = rec_get (zh->reg->records, *sysno);
assert (rec);
- recordAttr = rec_init_attr (zh->service->zei, rec);
+ recordAttr = rec_init_attr (zh->reg->zei, rec);
if (recordAttr->runNumber ==
- zebraExplain_runNumberIncrement (zh->service->zei, 0))
+ zebraExplain_runNumberIncrement (zh->reg->zei, 0))
{
logf (LOG_LOG, "skipped %s %s " PRINTF_OFF_T, rGroup->recordType,
fname, recordOffset);
- extract_flushSortKeys (zh, *sysno, -1, &zh->sortKeys);
+ extract_flushSortKeys (zh, *sysno, -1, &zh->reg->sortKeys);
rec_rm (&rec);
logRecord (0);
return 1;
}
delkeys.buf_used = rec->size[recInfo_delKeys];
delkeys.buf = rec->info[recInfo_delKeys];
- extract_flushSortKeys (zh, *sysno, 0, &zh->sortKeys);
+ extract_flushSortKeys (zh, *sysno, 0, &zh->reg->sortKeys);
extract_flushRecordKeys (zh, *sysno, 0, &delkeys);
if (deleteFlag)
{
rGroup->recordType, fname, recordOffset);
records_deleted++;
if (matchStr)
- dict_delete (zh->service->matchDict, matchStr);
- rec_del (zh->service->records, &rec);
+ dict_delete (zh->reg->matchDict, matchStr);
+ rec_del (zh->reg->records, &rec);
}
rec_rm (&rec);
logRecord (0);
if (records_processed < rGroup->fileVerboseLimit)
logf (LOG_LOG, "update %s %s " PRINTF_OFF_T,
rGroup->recordType, fname, recordOffset);
- extract_flushRecordKeys (zh, *sysno, 1, &zh->keys);
+ extract_flushRecordKeys (zh, *sysno, 1, &zh->reg->keys);
records_updated++;
}
}
/* update delete keys */
xfree (rec->info[recInfo_delKeys]);
- if (zh->keys.buf_used > 0 && rGroup->flagStoreKeys == 1)
+ if (zh->reg->keys.buf_used > 0 && rGroup->flagStoreKeys == 1)
{
#if 1
- rec->size[recInfo_delKeys] = zh->keys.buf_used;
- rec->info[recInfo_delKeys] = zh->keys.buf;
- zh->keys.buf = NULL;
- zh->keys.buf_max = 0;
+ rec->size[recInfo_delKeys] = zh->reg->keys.buf_used;
+ rec->info[recInfo_delKeys] = zh->reg->keys.buf;
+ zh->reg->keys.buf = NULL;
+ zh->reg->keys.buf_max = 0;
#else
rec->info[recInfo_delKeys] = xmalloc (reckeys.buf_used);
rec->size[recInfo_delKeys] = reckeys.buf_used;
}
/* save file size of original record */
- zebraExplain_recordBytesIncrement (zh->service->zei,
+ zebraExplain_recordBytesIncrement (zh->reg->zei,
- recordAttr->recordSize);
recordAttr->recordSize = fi->file_moffset - recordOffset;
if (!recordAttr->recordSize)
recordAttr->recordSize = fi->file_max - recordOffset;
- zebraExplain_recordBytesIncrement (zh->service->zei,
+ zebraExplain_recordBytesIncrement (zh->reg->zei,
recordAttr->recordSize);
/* set run-number for this record */
- recordAttr->runNumber = zebraExplain_runNumberIncrement (zh->service->zei,
+ recordAttr->runNumber = zebraExplain_runNumberIncrement (zh->reg->zei,
0);
/* update store data */
recordAttr->recordOffset = recordOffset;
/* commit this record */
- rec_put (zh->service->records, &rec);
+ rec_put (zh->reg->records, &rec);
logRecord (0);
return 1;
}
if (!rGroup->recordType)
{
sprintf (ext_res, "%srecordType.%s", gprefix, ext);
- if (!(rGroup->recordType = res_get (zh->service->res, ext_res)))
+ if (!(rGroup->recordType = res_get (zh->res, ext_res)))
{
sprintf (ext_res, "%srecordType", gprefix);
- rGroup->recordType = res_get (zh->service->res, ext_res);
+ rGroup->recordType = res_get (zh->res, ext_res);
}
}
if (!rGroup->recordType)
if (!*rGroup->recordType)
return 0;
if (!(recType =
- recType_byName (zh->service->recTypes, rGroup->recordType, subType,
+ recType_byName (zh->reg->recTypes, rGroup->recordType, subType,
&clientData)))
{
logf (LOG_WARN, "No such record type: %s", rGroup->recordType);
if (!rGroup->recordId)
{
sprintf (ext_res, "%srecordId.%s", gprefix, ext);
- rGroup->recordId = res_get (zh->service->res, ext_res);
+ rGroup->recordId = res_get (zh->res, ext_res);
}
/* determine database name */
if (!rGroup->databaseName)
{
sprintf (ext_res, "%sdatabase.%s", gprefix, ext);
- if (!(rGroup->databaseName = res_get (zh->service->res, ext_res)))
+ if (!(rGroup->databaseName = res_get (zh->res, ext_res)))
{
sprintf (ext_res, "%sdatabase", gprefix);
- rGroup->databaseName = res_get (zh->service->res, ext_res);
+ rGroup->databaseName = res_get (zh->res, ext_res);
}
}
if (!rGroup->databaseName)
sprintf (ext_res, "%sexplainDatabase", gprefix);
rGroup->explainDatabase =
- atoi (res_get_def (zh->service->res, ext_res, "0"));
+ atoi (res_get_def (zh->res, ext_res, "0"));
/* announce database */
- if (zebraExplain_curDatabase (zh->service->zei, rGroup->databaseName))
+ if (zebraExplain_curDatabase (zh->reg->zei, rGroup->databaseName))
{
- if (zebraExplain_newDatabase (zh->service->zei, rGroup->databaseName,
+ if (zebraExplain_newDatabase (zh->reg->zei, rGroup->databaseName,
rGroup->explainDatabase))
return 0;
}
{
const char *sval;
sprintf (ext_res, "%sstoreData.%s", gprefix, ext);
- if (!(sval = res_get (zh->service->res, ext_res)))
+ if (!(sval = res_get (zh->res, ext_res)))
{
sprintf (ext_res, "%sstoreData", gprefix);
- sval = res_get (zh->service->res, ext_res);
+ sval = res_get (zh->res, ext_res);
}
if (sval)
rGroup->flagStoreData = atoi (sval);
const char *sval;
sprintf (ext_res, "%sstoreKeys.%s", gprefix, ext);
- sval = res_get (zh->service->res, ext_res);
+ sval = res_get (zh->res, ext_res);
if (!sval)
{
sprintf (ext_res, "%sstoreKeys", gprefix);
- sval = res_get (zh->service->res, ext_res);
+ sval = res_get (zh->res, ext_res);
}
if (!sval)
- sval = res_get (zh->service->res, "storeKeys");
+ sval = res_get (zh->res, "storeKeys");
if (sval)
rGroup->flagStoreKeys = atoi (sval);
}
extractCtrl.fh = &fc;
/* announce database */
- if (zebraExplain_curDatabase (zh->service->zei, databaseName))
+ if (zebraExplain_curDatabase (zh->reg->zei, databaseName))
{
- if (zebraExplain_newDatabase (zh->service->zei, databaseName, 0))
+ if (zebraExplain_newDatabase (zh->reg->zei, databaseName, 0))
return 0;
}
if (!(recType =
- recType_byName (zh->service->recTypes, recordType, subType,
+ recType_byName (zh->reg->recTypes, recordType, subType,
&clientData)))
{
logf (LOG_WARN, "No such record type: %s", recordType);
return 0;
}
- zh->keys.buf_used = 0;
- zh->keys.prevAttrUse = -1;
- zh->keys.prevAttrSet = -1;
- zh->keys.prevSeqNo = 0;
- zh->sortKeys = 0;
+ zh->reg->keys.buf_used = 0;
+ zh->reg->keys.prevAttrUse = -1;
+ zh->reg->keys.prevAttrSet = -1;
+ zh->reg->keys.prevSeqNo = 0;
+ zh->reg->sortKeys = 0;
extractCtrl.subType = subType;
extractCtrl.init = extract_init;
extractCtrl.tokenAdd = extract_token_add;
extractCtrl.schemaAdd = extract_schema_add;
- extractCtrl.dh = zh->service->dh;
+ extractCtrl.dh = zh->reg->dh;
extractCtrl.handle = zh;
- extractCtrl.zebra_maps = zh->service->zebra_maps;
+ extractCtrl.zebra_maps = zh->reg->zebra_maps;
extractCtrl.flagShowRecords = 0;
for (i = 0; i<256; i++)
{
- if (zebra_maps_is_positioned(zh->service->zebra_maps, i))
+ if (zebra_maps_is_positioned(zh->reg->zebra_maps, i))
extractCtrl.seqno[i] = 1;
else
extractCtrl.seqno[i] = 0;
#endif
return 0;
}
- if (zh->keys.buf_used == 0)
+ if (zh->reg->keys.buf_used == 0)
{
/* the extraction process returned no information - the record
is probably empty - unless flagShowRecords is in use */
}
logf (LOG_LOG, "add %s %s %ld", recordType, fname,
(long) recordOffset);
- rec = rec_new (zh->service->records);
+ rec = rec_new (zh->reg->records);
*sysno = rec->sysno;
- recordAttr = rec_init_attr (zh->service->zei, rec);
+ recordAttr = rec_init_attr (zh->reg->zei, rec);
if (matchStr)
{
- dict_insert (zh->service->matchDict, matchStr,
+ dict_insert (zh->reg->matchDict, matchStr,
sizeof(*sysno), sysno);
}
- extract_flushRecordKeys (zh, *sysno, 1, &zh->keys);
- extract_flushSortKeys (zh, *sysno, 1, &zh->sortKeys);
+ extract_flushRecordKeys (zh, *sysno, 1, &zh->reg->keys);
+ extract_flushSortKeys (zh, *sysno, 1, &zh->reg->sortKeys);
}
else
{
/* record already exists */
struct recKeys delkeys;
- rec = rec_get (zh->service->records, *sysno);
+ rec = rec_get (zh->reg->records, *sysno);
assert (rec);
- recordAttr = rec_init_attr (zh->service->zei, rec);
+ recordAttr = rec_init_attr (zh->reg->zei, rec);
if (recordAttr->runNumber ==
- zebraExplain_runNumberIncrement (zh->service->zei, 0))
+ zebraExplain_runNumberIncrement (zh->reg->zei, 0))
{
logf (LOG_LOG, "skipped %s %s %ld", recordType,
fname, (long) recordOffset);
}
delkeys.buf_used = rec->size[recInfo_delKeys];
delkeys.buf = rec->info[recInfo_delKeys];
- extract_flushSortKeys (zh, *sysno, 0, &zh->sortKeys);
+ extract_flushSortKeys (zh, *sysno, 0, &zh->reg->sortKeys);
extract_flushRecordKeys (zh, *sysno, 0, &delkeys);
if (delete_flag)
{
if (matchStr)
dict_delete (matchDict, matchStr);
#endif
- rec_del (zh->service->records, &rec);
+ rec_del (zh->reg->records, &rec);
}
rec_rm (&rec);
return 1;
{
logf (LOG_LOG, "update %s %s %ld", recordType,
fname, (long) recordOffset);
- extract_flushRecordKeys (zh, *sysno, 1, &zh->keys);
+ extract_flushRecordKeys (zh, *sysno, 1, &zh->reg->keys);
}
}
}
/* update delete keys */
xfree (rec->info[recInfo_delKeys]);
- if (zh->keys.buf_used > 0 && store_keys == 1)
+ if (zh->reg->keys.buf_used > 0 && store_keys == 1)
{
- rec->size[recInfo_delKeys] = zh->keys.buf_used;
- rec->info[recInfo_delKeys] = zh->keys.buf;
- zh->keys.buf = NULL;
- zh->keys.buf_max = 0;
+ rec->size[recInfo_delKeys] = zh->reg->keys.buf_used;
+ rec->info[recInfo_delKeys] = zh->reg->keys.buf;
+ zh->reg->keys.buf = NULL;
+ zh->reg->keys.buf_max = 0;
}
else
{
}
/* save file size of original record */
- zebraExplain_recordBytesIncrement (zh->service->zei,
+ zebraExplain_recordBytesIncrement (zh->reg->zei,
- recordAttr->recordSize);
#if 0
recordAttr->recordSize = fi->file_moffset - recordOffset;
#else
recordAttr->recordSize = buf_size;
#endif
- zebraExplain_recordBytesIncrement (zh->service->zei,
+ zebraExplain_recordBytesIncrement (zh->reg->zei,
recordAttr->recordSize);
/* set run-number for this record */
recordAttr->runNumber =
- zebraExplain_runNumberIncrement (zh->service->zei, 0);
+ zebraExplain_runNumberIncrement (zh->reg->zei, 0);
/* update store data */
xfree (rec->info[recInfo_storeData]);
recordAttr->recordOffset = recordOffset;
/* commit this record */
- rec_put (zh->service->records, &rec);
+ rec_put (zh->reg->records, &rec);
return 0;
}
struct recExtractCtrl extractCtrl;
int i;
- if (zebraExplain_curDatabase (zh->service->zei,
+ if (zebraExplain_curDatabase (zh->reg->zei,
rec->info[recInfo_databaseName]))
{
abort();
- if (zebraExplain_newDatabase (zh->service->zei,
+ if (zebraExplain_newDatabase (zh->reg->zei,
rec->info[recInfo_databaseName], 0))
abort ();
}
- zh->keys.buf_used = 0;
- zh->keys.prevAttrUse = -1;
- zh->keys.prevAttrSet = -1;
- zh->keys.prevSeqNo = 0;
- zh->sortKeys = 0;
+ zh->reg->keys.buf_used = 0;
+ zh->reg->keys.prevAttrUse = -1;
+ zh->reg->keys.prevAttrSet = -1;
+ zh->reg->keys.prevSeqNo = 0;
+ zh->reg->sortKeys = 0;
extractCtrl.init = extract_init;
extractCtrl.tokenAdd = extract_token_add;
extractCtrl.schemaAdd = extract_schema_add;
- extractCtrl.dh = zh->service->dh;
+ extractCtrl.dh = zh->reg->dh;
for (i = 0; i<256; i++)
extractCtrl.seqno[i] = 0;
- extractCtrl.zebra_maps = zh->service->zebra_maps;
+ extractCtrl.zebra_maps = zh->reg->zebra_maps;
extractCtrl.flagShowRecords = 0;
extractCtrl.handle = handle;
extract_flushSortKeys (zh, rec->sysno, 0, &sortKeys);
extract_flushRecordKeys (zh, rec->sysno, 0, &delkeys);
}
- extract_flushRecordKeys (zh, rec->sysno, 1, &zh->keys);
- extract_flushSortKeys (zh, rec->sysno, 1, &zh->sortKeys);
+ extract_flushRecordKeys (zh, rec->sysno, 1, &zh->reg->keys);
+ extract_flushSortKeys (zh, rec->sysno, 1, &zh->reg->sortKeys);
xfree (rec->info[recInfo_delKeys]);
- rec->size[recInfo_delKeys] = zh->keys.buf_used;
- rec->info[recInfo_delKeys] = zh->keys.buf;
- zh->keys.buf = NULL;
- zh->keys.buf_max = 0;
+ rec->size[recInfo_delKeys] = zh->reg->keys.buf_used;
+ rec->info[recInfo_delKeys] = zh->reg->keys.buf;
+ zh->reg->keys.buf = NULL;
+ zh->reg->keys.buf_max = 0;
return 0;
}
int seqno = 0;
int off = 0;
int ch = 0;
- ZebraExplainInfo zei = zh->service->zei;
+ ZebraExplainInfo zei = zh->reg->zei;
- if (!zh->key_buf)
+ if (!zh->reg->key_buf)
{
int mem = 8*1024*1024;
- zh->key_buf = (char**) xmalloc (mem);
- zh->ptr_top = mem/sizeof(char*);
- zh->ptr_i = 0;
- zh->key_buf_used = 0;
- zh->key_file_no = 0;
+ zh->reg->key_buf = (char**) xmalloc (mem);
+ zh->reg->ptr_top = mem/sizeof(char*);
+ zh->reg->ptr_i = 0;
+ zh->reg->key_buf_used = 0;
+ zh->reg->key_file_no = 0;
}
zebraExplain_recordCountIncrement (zei, cmd ? 1 : -1);
while (off < reckeys->buf_used)
src += sizeof(attrUse);
}
#endif
- if (zh->key_buf_used + 1024 > (zh->ptr_top-zh->ptr_i)*sizeof(char*))
+ if (zh->reg->key_buf_used + 1024 >
+ (zh->reg->ptr_top -zh->reg->ptr_i)*sizeof(char*))
extract_flushWriteKeys (zh);
- ++(zh->ptr_i);
- (zh->key_buf)[zh->ptr_top - zh->ptr_i] =
- (char*)zh->key_buf + zh->key_buf_used;
+ ++(zh->reg->ptr_i);
+ (zh->reg->key_buf)[zh->reg->ptr_top - zh->reg->ptr_i] =
+ (char*)zh->reg->key_buf + zh->reg->key_buf_used;
#if SU_SCHEME
#else
ch = zebraExplain_lookupSU (zei, attrSet, attrUse);
ch = zebraExplain_addSU (zei, attrSet, attrUse);
#endif
assert (ch > 0);
- zh->key_buf_used +=
- key_SU_encode (ch,((char*)zh->key_buf) + zh->key_buf_used);
+ zh->reg->key_buf_used +=
+ key_SU_encode (ch,((char*)zh->reg->key_buf) +
+ zh->reg->key_buf_used);
while (*src)
- ((char*)zh->key_buf) [(zh->key_buf_used)++] = *src++;
+ ((char*)zh->reg->key_buf) [(zh->reg->key_buf_used)++] = *src++;
src++;
- ((char*)(zh->key_buf))[(zh->key_buf_used)++] = '\0';
- ((char*)(zh->key_buf))[(zh->key_buf_used)++] = cmd;
+ ((char*)(zh->reg->key_buf))[(zh->reg->key_buf_used)++] = '\0';
+ ((char*)(zh->reg->key_buf))[(zh->reg->key_buf_used)++] = cmd;
if (lead & 60)
seqno += ((lead>>2) & 15)-1;
}
key.seqno = seqno;
key.sysno = sysno;
- memcpy ((char*)zh->key_buf + zh->key_buf_used, &key, sizeof(key));
- (zh->key_buf_used) += sizeof(key);
+ memcpy ((char*)zh->reg->key_buf + zh->reg->key_buf_used, &key, sizeof(key));
+ (zh->reg->key_buf_used) += sizeof(key);
off = src - reckeys->buf;
}
assert (off == reckeys->buf_used);
char out_fname[200];
char *prevcp, *cp;
struct encode_info encode_info;
- int ptr_i = zh->ptr_i;
+ int ptr_i = zh->reg->ptr_i;
#if SORT_EXTRA
int i;
#endif
- if (!zh->key_buf || ptr_i <= 0)
+ if (!zh->reg->key_buf || ptr_i <= 0)
return;
- (zh->key_file_no)++;
- logf (LOG_LOG, "sorting section %d", (zh->key_file_no));
+ (zh->reg->key_file_no)++;
+ logf (LOG_LOG, "sorting section %d", (zh->reg->key_file_no));
#if !SORT_EXTRA
- qsort (zh->key_buf + zh->ptr_top - ptr_i, ptr_i, sizeof(char*),
+ qsort (zh->reg->key_buf + zh->reg->ptr_top - ptr_i, ptr_i, sizeof(char*),
key_qsort_compare);
- extract_get_fname_tmp (zh, out_fname, zh->key_file_no);
+ extract_get_fname_tmp (zh, out_fname, zh->reg->key_file_no);
if (!(outf = fopen (out_fname, "wb")))
{
logf (LOG_FATAL|LOG_ERRNO, "fopen %s", out_fname);
exit (1);
}
- logf (LOG_LOG, "writing section %d", zh->key_file_no);
- prevcp = cp = (zh->key_buf)[zh->ptr_top - ptr_i];
+ logf (LOG_LOG, "writing section %d", zh->reg->key_file_no);
+ prevcp = cp = (zh->reg->key_buf)[zh->reg->ptr_top - ptr_i];
encode_key_init (&encode_info);
encode_key_write (cp, &encode_info, outf);
while (--ptr_i > 0)
{
- cp = (zh->key_buf)[zh->ptr_top - ptr_i];
+ cp = (zh->reg->key_buf)[zh->reg->ptr_top - ptr_i];
if (strcmp (cp, prevcp))
{
encode_key_init (&encode_info);
logf (LOG_FATAL|LOG_ERRNO, "fclose %s", out_fname);
exit (1);
}
- logf (LOG_LOG, "finished section %d", zh->key_file_no);
- zh->ptr_i = 0;
- zh->key_buf_used = 0;
+ logf (LOG_LOG, "finished section %d", zh->reg->key_file_no);
+ zh->reg->ptr_i = 0;
+ zh->reg->key_buf_used = 0;
}
void extract_add_index_string (RecWord *p, const char *string,
int diff = 0;
int *pseqno = &p->seqnos[p->reg_type];
ZebraHandle zh = p->extractCtrl->handle;
- ZebraExplainInfo zei = zh->service->zei;
- struct recKeys *keys = &zh->keys;
+ ZebraExplainInfo zei = zh->reg->zei;
+ struct recKeys *keys = &zh->reg->keys;
if (keys->buf_used+1024 > keys->buf_max)
{
struct sortKey *sk;
ZebraHandle zh = p->extractCtrl->handle;
- for (sk = zh->sortKeys; sk; sk = sk->next)
+ for (sk = zh->reg->sortKeys; sk; sk = sk->next)
if (sk->attrSet == p->attrSet && sk->attrUse == p->attrUse)
return;
sk = (struct sortKey *) xmalloc (sizeof(*sk));
- sk->next = zh->sortKeys;
- zh->sortKeys = sk;
+ sk->next = zh->reg->sortKeys;
+ zh->reg->sortKeys = sk;
sk->string = (char *) xmalloc (length);
sk->length = length;
void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid)
{
ZebraHandle zh = (ZebraHandle) (p->handle);
- zebraExplain_addSchema (zh->service->zei, oid);
+ zebraExplain_addSchema (zh->reg->zei, oid);
}
void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
int cmd, struct sortKey **skp)
{
struct sortKey *sk = *skp;
- SortIdx sortIdx = zh->service->sortIdx;
+ SortIdx sortIdx = zh->reg->sortIdx;
sortIdx_sysno (sortIdx, sysno);
while (sk)
* Copyright (C) 1995-2002, Index Data
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
- * $Id: index.h,v 1.74 2002-03-21 10:25:42 adam Exp $
+ * $Id: index.h,v 1.75 2002-04-04 14:14:13 adam Exp $
*/
#ifndef INDEX_H
#include <zebraver.h>
#include <zebrautl.h>
#include <zebramap.h>
+#include <sortidx.h>
+
+#if HAVE_SYS_TIMES_H
+#include <sys/times.h>
+#endif
#include <dict.h>
#include <isams.h>
#endif
#include <yaz/data1.h>
#include <recctrl.h>
+#include "recindex.h"
#include "zebraapi.h"
+#include "zinfo.h"
+#include <passwddb.h>
+#include <rset.h>
YAZ_BEGIN_CDECL
time_t mtime;
};
-struct recordGroup {
- char *groupName;
- char *databaseName;
- char *path;
- char *recordId;
- char *recordType;
- int flagStoreData;
- int flagStoreKeys;
- int flagRw;
- int fileVerboseLimit;
- int databaseNamePath;
- int explainDatabase;
-};
-
void getFnameTmp (Res res, char *fname, int no);
struct dirs_info *dirs_open (Dict dict, const char *rep, int rw);
int index_word_prefix (char *string, int attset_ordinal,
int local_attribute, const char *databaseName);
-int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname,
- const struct recordGroup *rGroup, int deleteFlag);
void zebraIndexLockMsg (ZebraHandle zh, const char *str);
void zebraIndexUnlock (ZebraHandle zh);
char *encode_key_int (int d, char *bp);
void encode_key_write (char *k, struct encode_info *i, FILE *outf);
+typedef struct {
+ char *term;
+ char *db;
+ int sysno;
+ int score;
+} *ZebraPosSet;
+
+typedef struct zebra_set *ZebraSet;
+
+typedef struct zebra_rank_class {
+ struct rank_control *control;
+ int init_flag;
+ void *class_handle;
+ struct zebra_rank_class *next;
+} *ZebraRankClass;
+
+struct recKeys {
+ int buf_used;
+ int buf_max;
+ char *buf;
+ char prevAttrSet;
+ short prevAttrUse;
+ int prevSeqNo;
+};
+
+struct sortKey {
+ char *string;
+ int length;
+ int attrSet;
+ int attrUse;
+ struct sortKey *next;
+};
+
+struct zebra_register {
+ char *name;
+
+ ISAMS isams;
+#if ZMBOL
+ ISAM isam;
+ ISAMC isamc;
+ ISAMD isamd;
+#endif
+ Dict dict;
+ Dict matchDict;
+ SortIdx sortIdx;
+ int registerState; /* 0 (no commit pages), 1 (use commit pages) */
+ time_t registerChange;
+ BFiles bfs;
+ Records records;
+ ZebraExplainInfo zei;
+
+ char *server_path_prefix;
+ data1_handle dh;
+ ZebraMaps zebra_maps;
+ ZebraRankClass rank_classes;
+ RecTypes recTypes;
+ int seqno;
+ int last_val;
+ int stop_flag;
+ int active; /* 0=shutdown, 1=enabled and inactive, 2=activated */
+
+
+
+ struct recKeys keys;
+ struct sortKey *sortKeys;
+
+ char **key_buf;
+ size_t ptr_top;
+ size_t ptr_i;
+ size_t key_buf_used;
+ int key_file_no;
+};
+
+struct zebra_service {
+ int stop_flag;
+ Res global_res;
+ char *configName;
+ struct zebra_session *sessions;
+ struct zebra_register *regs;
+ Zebra_mutex_cond session_lock;
+ Passwd_db passwd_db;
+ char *path_root;
+};
+
+
+struct zebra_session {
+ struct zebra_session *next;
+ struct zebra_service *service;
+ struct zebra_register *reg;
+
+ char *admin_databaseName;
+
+ char **basenames;
+ int num_basenames;
+ char *reg_name;
+ char *path_reg;
+
+ ZebraLockHandle lock_normal;
+ ZebraLockHandle lock_shadow;
+
+ int trans_no;
+ int destroyed;
+ ZebraSet sets;
+ Res res;
+ int errCode;
+ int hits;
+ char *errString;
+#if HAVE_SYS_TIMES_H
+ struct tms tms1;
+ struct tms tms2;
+#endif
+ struct recordGroup rGroup;
+};
+
+struct rank_control {
+ char *name;
+ void *(*create)(struct zebra_register *reg);
+ void (*destroy)(struct zebra_register *reg, void *class_handle);
+ void *(*begin)(struct zebra_register *reg, void *class_handle, RSET rset);
+ void (*end)(struct zebra_register *reg, void *set_handle);
+ int (*calc)(void *set_handle, int sysno);
+ void (*add)(void *set_handle, int seqno, int term_index);
+};
+
+struct term_set_entry {
+ char *term;
+ struct term_set_entry *next;
+};
+
+struct term_set_list {
+ struct term_set_entry *first;
+ struct term_set_entry *last;
+};
+
+RSET rpn_search (ZebraHandle zh, NMEM mem,
+ Z_RPNQuery *rpn, int num_bases, char **basenames,
+ const char *setname, ZebraSet sset);
+
+
+void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
+ oid_value attributeset,
+ int num_bases, char **basenames,
+ int *position, int *num_entries, ZebraScanEntry **list,
+ int *is_partial);
+
+RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no,
+ const char *term, int length_term, const char *flags);
+
+void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
+ const char *db, int set,
+ int use, const char *term);
+ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
+ZebraSet resultSetGet (ZebraHandle zh, const char *name);
+ZebraSet resultSetAddRPN (ZebraHandle zh, ODR stream, ODR decode,
+ Z_RPNQuery *rpn, int num_bases,
+ char **basenames, const char *setname);
+RSET resultSetRef (ZebraHandle zh, Z_ResultSetId *resultSetId);
+void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
+ int *statuses);
+
+
+ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name,
+ int num, int *positions);
+void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num);
+
+void resultSetSort (ZebraHandle zh, NMEM nmem,
+ int num_input_setnames, const char **input_setnames,
+ const char *output_setname,
+ Z_SortKeySpecList *sort_sequence, int *sort_status);
+void resultSetSortSingle (ZebraHandle zh, NMEM nmem,
+ ZebraSet sset, RSET rset,
+ Z_SortKeySpecList *sort_sequence, int *sort_status);
+void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset);
+void resultSetInvalidate (ZebraHandle zh);
+
+int zebra_server_lock_init (ZebraService zh);
+int zebra_server_lock_destroy (ZebraService zh);
+int zebra_server_lock (ZebraService zh, int lockCommit);
+void zebra_server_unlock (ZebraService zh, int commitPhase);
+int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
+
+typedef struct attent
+{
+ int attset_ordinal;
+ data1_local_attribute *local_attributes;
+} attent;
+
+void zebraRankInstall (struct zebra_register *reg, struct rank_control *ctrl);
+ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
+void zebraRankDestroy (struct zebra_register *reg);
+
+int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att);
+
+extern struct rank_control *rank1_class;
+
+int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
+ oid_value input_format, Z_RecordComposition *comp,
+ oid_value *output_format, char **rec_bufp,
+ int *rec_lenp, char **basenamep);
+
+void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
+void zebra_index_merge (ZebraHandle zh);
+
+
+int extract_rec_in_mem (ZebraHandle zh, const char *recordType,
+ const char *buf, size_t buf_size,
+ const char *databaseName, int delete_flag,
+ int test_mode, int *sysno,
+ int store_keys, int store_data,
+ const char *match_criteria);
+
+void extract_flushWriteKeys (ZebraHandle zh);
+
+struct zebra_fetch_control {
+ off_t offset_end;
+ off_t record_offset;
+ off_t record_int_pos;
+ const char *record_int_buf;
+ int record_int_len;
+ int fd;
+};
+
+int zebra_record_ext_read (void *fh, char *buf, size_t count);
+off_t zebra_record_ext_seek (void *fh, off_t offset);
+off_t zebra_record_ext_tell (void *fh);
+off_t zebra_record_int_seek (void *fh, off_t offset);
+off_t zebra_record_int_tell (void *fh);
+int zebra_record_int_read (void *fh, char *buf, size_t count);
+void zebra_record_int_end (void *fh, off_t offset);
+
+void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno,
+ int cmd, struct recKeys *reckeys);
+void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
+ int cmd, struct sortKey **skp);
+void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid);
+void extract_token_add (RecWord *p);
+int explain_extract (void *handle, Record rec, data1_node *n);
+
+int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname,
+ const struct recordGroup *rGroup, int deleteFlag);
YAZ_END_CDECL
#include <string.h>
#include "index.h"
-#include "recindex.h"
#if ZMBOL
#include "../isamc/isamd-p.h"
#endif
-#include "zserver.h"
struct inv_stat_info {
ISAMS isams;
void inv_prstat (ZebraHandle zh)
{
- BFiles bfs = zh->service->bfs;
+ Res res = zh->res;
+ BFiles bfs;
Dict dict;
ISAMS isams = NULL;
#if ZMBOL
int after = 1000000000;
struct inv_stat_info stat_info;
char term_dict[2*IT_MAX_WORD+2];
+
+ if (!res || !zh->reg)
+ return;
+
+ bfs = zh->reg->bfs;
term_dict[0] = 1;
term_dict[1] = 0;
logf (LOG_FATAL, "dict_open fail");
exit (1);
}
- if (res_get_match (zh->service->res, "isam", "s", ISAM_DEFAULT))
+ if (res_get_match (res, "isam", "s", ISAM_DEFAULT))
{
struct ISAMS_M_s isams_m;
isams = isams_open (bfs, FNAME_ISAMS, 0,
- key_isams_m(zh->service->res, &isams_m));
+ key_isams_m(res, &isams_m));
if (!isams)
{
logf (LOG_FATAL, "isams_open fail");
}
}
#if ZMBOL
- else if (res_get_match (zh->service->res, "isam", "i", ISAM_DEFAULT))
+ else if (res_get_match (res, "isam", "i", ISAM_DEFAULT))
{
isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
- sizeof(struct it_key), zh->service->res);
+ sizeof(struct it_key), res);
if (!isam)
{
logf (LOG_FATAL, "is_open fail");
exit (1);
}
}
- else if (res_get_match (zh->service->res, "isam", "d", ISAM_DEFAULT))
+ else if (res_get_match (res, "isam", "d", ISAM_DEFAULT))
{
struct ISAMD_M_s isamd_m;
isamd = isamd_open (bfs, FNAME_ISAMD, 0,
- key_isamd_m(zh->service->res,&isamd_m));
+ key_isamd_m(res,&isamd_m));
if (!isamd)
{
logf (LOG_FATAL, "isamd_open fail");
exit (1);
}
}
- else if (res_get_match (zh->service->res, "isam", "c", ISAM_DEFAULT))
+ else if (res_get_match (res, "isam", "c", ISAM_DEFAULT))
{
struct ISAMC_M_s isamc_m;
isamc = isc_open (bfs, FNAME_ISAMC, 0,
- key_isamc_m (zh->service->res, &isamc_m));
+ key_isamc_m (res, &isamc_m));
if (!isamc)
{
logf (LOG_FATAL, "isc_open fail");
/*
*
* $Log: invstat.c,v $
- * Revision 1.22 2002-02-20 17:30:01 adam
+ * Revision 1.23 2002-04-04 14:14:13 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.22 2002/02/20 17:30:01 adam
* Work on new API. Locking system re-implemented
*
* Revision 1.21 2000/07/13 10:14:20 heikki
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: kdump.c,v $
- * Revision 1.19 2000-12-05 10:01:44 adam
+ * Revision 1.20 2002-04-04 14:14:13 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.19 2000/12/05 10:01:44 adam
* Fixed bug regarding user-defined attribute sets.
*
* Revision 1.18 1999/09/07 07:19:21 adam
}
else if (ret == 'c')
{
- if (!(res = res_open (arg)))
+ if (!(res = res_open (arg, 0)))
{
logf(LOG_FATAL, "Failed to open resource file %s", arg);
exit (1);
exit (1);
}
if (!res)
- res = res_open ("zebra.cfg");
+ res = res_open ("zebra.cfg", 0);
zm = zebra_maps_open (res);
if (!(inf = fopen (key_fname, "r")))
{
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
*
- * $Id: kinput.c,v 1.46 2002-02-20 23:07:54 adam Exp $
+ * $Id: kinput.c,v 1.47 2002-04-04 14:14:13 adam Exp $
*
* Bugs
* - Allocates a lot of memory for the merge process, but never releases it.
#include <assert.h>
#include "index.h"
-#include "zserver.h"
#define KEY_SIZE (1+sizeof(struct it_key))
#define INP_NAME_MAX 768
{
const char *pre;
- pre = res_get_def (zh->service->res, "keyTmpDir", ".");
+ pre = res_get_def (zh->res, "keyTmpDir", ".");
sprintf (fname, "%s/key%d.tmp", pre, no);
}
int i, r;
struct heap_info *hi;
struct progressInfo progressInfo;
- int nkeys = zh->key_file_no;
+ int nkeys = zh->reg->key_file_no;
if (nkeys < 0)
{
time (&progressInfo.lastTime);
for (i = 1; i<=nkeys; i++)
{
- kf[i] = key_file_init (i, 8192, zh->service->res);
+ kf[i] = key_file_init (i, 8192, zh->res);
kf[i]->readHandler = progressFunc;
kf[i]->readInfo = &progressInfo;
progressInfo.totalBytes += kf[i]->length;
progressInfo.totalOffset += kf[i]->buf_size;
}
hi = key_heap_init (nkeys, key_qsort_compare);
- hi->dict = zh->service->dict;
- hi->isams = zh->service->isams;
+ hi->dict = zh->reg->dict;
+ hi->isams = zh->reg->isams;
#if ZMBOL
- hi->isam = zh->service->isam;
- hi->isamc = zh->service->isamc;
- hi->isamd = zh->service->isamd;
+ hi->isam = zh->reg->isam;
+ hi->isamc = zh->reg->isamc;
+ hi->isamd = zh->reg->isamd;
#endif
for (i = 1; i<=nkeys; i++)
if ((r = key_file_read (kf[i], rbuf)))
key_heap_insert (hi, rbuf, r, kf[i]);
- if (zh->service->isams)
+ if (zh->reg->isams)
heap_inps (hi);
#if ZMBOL
- else if (zh->service->isamc)
+ else if (zh->reg->isamc)
heap_inpc (hi);
- else if (zh->service->isam)
+ else if (zh->reg->isam)
heap_inp (hi);
- else if (zh->service->isamd)
+ else if (zh->reg->isamd)
heap_inpd (hi);
#endif
logf (LOG_LOG, "Updates. . . . .%7d", no_updates);
logf (LOG_LOG, "Deletions. . . .%7d", no_deletions);
logf (LOG_LOG, "Insertions . . .%7d", no_insertions);
- zh->key_file_no = 0;
+ zh->reg->key_file_no = 0;
key_heap_destroy (hi, nkeys);
for (i = 1; i<=nkeys; i++)
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: lockutil.c,v 1.14 2002-03-21 10:25:42 adam Exp $
+ * $Id: lockutil.c,v 1.15 2002-04-04 14:14:13 adam Exp $
*/
#include <stdio.h>
#include <assert.h>
ZebraLockHandle zebra_lock_create (const char *dir,
const char *name, int excl_flag)
{
- int dlen = dir ? strlen(dir) : 0;
char *fname = zebra_mk_fname(dir, name);
ZebraLockHandle h = (ZebraLockHandle) xmalloc (sizeof(*h));
* Copyright (C) 1994-2002, Index Data
* All rights reserved.
*
- * $Id: main.c,v 1.82 2002-02-20 17:30:01 adam Exp $
+ * $Id: main.c,v 1.83 2002-04-04 14:14:13 adam Exp $
*/
#include <stdio.h>
#include <string.h>
#include <yaz/data1.h>
#include "zebraapi.h"
-#include "zserver.h"
-#include "index.h"
-#include "recindex.h"
char *prog;
logf (LOG_LOG, "zebra version %s %s",
ZEBRAVER, ZEBRADATE);
#endif
- zs = zebra_start (configName ? configName : FNAME_CONFIG);
+ zs = zebra_start (configName ? configName : "zebra.cfg");
zh = zebra_open (zs);
}
+ if (rGroupDef.databaseName)
+ zebra_select_database (zh, rGroupDef.databaseName);
+ else
+ zebra_select_database (zh, "Default");
+
if (!strcmp (arg, "update"))
cmd = 'u';
else if (!strcmp (arg, "update1"))
}
else
{
- memcpy (&zh->rGroup, &rGroupDef, sizeof(rGroupDef));
+ rGroupDef.path = arg;
+ zebra_set_group (zh, &rGroupDef);
zebra_begin_trans (zh);
- zh->rGroup.path = arg;
switch (cmd)
{
case 'u':
zebra_repository_delete (zh);
break;
case 's':
- logf (LOG_LOG, "dumping %s", zh->rGroup.path);
+ logf (LOG_LOG, "dumping %s", rGroupDef.path);
zebra_repository_show (zh);
nsections = 0;
break;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rank1.c,v $
- * Revision 1.7 2001-11-14 22:06:27 adam
+ * Revision 1.8 2002-04-04 14:14:13 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.7 2001/11/14 22:06:27 adam
* Rank-weight may be controlled via query.
*
* Revision 1.6 2000/03/15 15:00:30 adam
#include <unistd.h>
#endif
-#include "zserver.h"
+#include "index.h"
struct rank_class_info {
int dummy;
* create: Creates/Initialises this rank handler. This routine is
* called exactly once. The routine returns the class_handle.
*/
-static void *create (ZebraService zh)
+static void *create (struct zebra_register *reg)
{
struct rank_class_info *ci = (struct rank_class_info *)
xmalloc (sizeof(*ci));
* when the handler is no longer needed - i.e. when the server
* dies. The class_handle was previously returned by create.
*/
-static void destroy (ZebraService zh, void *class_handle)
+static void destroy (struct zebra_register *reg, void *class_handle)
{
struct rank_class_info *ci = (struct rank_class_info *) class_handle;
* each result set. The returned handle is a "set handle" and
* will be used in each of the handlers below.
*/
-static void *begin (ZebraHandle zh, void *class_handle, RSET rset)
+static void *begin (struct zebra_register *reg, void *class_handle, RSET rset)
{
struct rank_set_info *si = (struct rank_set_info *) xmalloc (sizeof(*si));
int i;
* end: Terminates ranking process. Called after a result set
* has been ranked.
*/
-static void end (ZebraHandle zh, void *set_handle)
+static void end (struct zebra_register *reg, void *set_handle)
{
struct rank_set_info *si = (struct rank_set_info *) set_handle;
logf (LOG_DEBUG, "rank-1 end");
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: retrieve.c,v $
- * Revision 1.14 2001-01-22 11:41:41 adam
+ * Revision 1.15 2002-04-04 14:14:13 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.14 2001/01/22 11:41:41 adam
* Added support for raw retrieval (element set name "R").
*
* Revision 1.13 2000/03/20 19:08:36 adam
#include <unistd.h>
#endif
-#include <recctrl.h>
-#include "zserver.h"
-
-#ifndef ZEBRASDR
-#define ZEBRASDR 0
-#endif
-
-#if ZEBRASDR
-#include "zebrasdr.h"
-#endif
+#include "index.h"
int zebra_record_ext_read (void *fh, char *buf, size_t count)
{
RecordAttr *recordAttr;
void *clientData;
- rec = rec_get (zh->service->records, sysno);
+ rec = rec_get (zh->reg->records, sysno);
if (!rec)
{
logf (LOG_DEBUG, "rec_get fail on sysno=%d", sysno);
*basenamep = 0;
return 14;
}
- recordAttr = rec_init_attr (zh->service->zei, rec);
+ recordAttr = rec_init_attr (zh->reg->zei, rec);
file_type = rec->info[recInfo_fileType];
fname = rec->info[recInfo_filename];
if (!strcmp (comp->u.simple->u.generic, "R"))
file_type = "text";
}
- if (!(rt = recType_byName (zh->service->recTypes,
+ if (!(rt = recType_byName (zh->reg->recTypes,
file_type, subType, &clientData)))
{
logf (LOG_WARN, "Retrieve: Cannot handle type %s", file_type);
retrieveCtrl.input_format = retrieveCtrl.output_format = input_format;
retrieveCtrl.comp = comp;
retrieveCtrl.diagnostic = 0;
- retrieveCtrl.dh = zh->service->dh;
- retrieveCtrl.res = zh->service->res;
+ retrieveCtrl.dh = zh->reg->dh;
+ retrieveCtrl.res = zh->res;
(*rt->retrieve)(clientData, &retrieveCtrl);
*output_format = retrieveCtrl.output_format;
*rec_bufp = (char *) retrieveCtrl.rec_buf;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: trav.c,v $
- * Revision 1.37 2002-02-20 17:30:01 adam
+ * Revision 1.38 2002-04-04 14:14:13 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.37 2002/02/20 17:30:01 adam
* Work on new API. Locking system re-implemented
*
* Revision 1.36 1999/05/15 14:36:38 adam
#include <time.h>
#include "index.h"
-#include "zserver.h"
static int repComp (const char *a, const char *b, size_t len)
{
dir_free (&e_src);
}
-static void groupRes (ZebraService zs, struct recordGroup *rGroup)
+static void groupRes (ZebraHandle zh, struct recordGroup *rGroup)
{
char resStr[256];
char gPrefix[256];
sprintf (gPrefix, "%s.", rGroup->groupName);
sprintf (resStr, "%srecordId", gPrefix);
- rGroup->recordId = res_get (zs->res, resStr);
+ rGroup->recordId = res_get (zh->res, resStr);
sprintf (resStr, "%sdatabasePath", gPrefix);
rGroup->databaseNamePath =
- atoi (res_get_def (zs->res, resStr, "0"));
+ atoi (res_get_def (zh->res, resStr, "0"));
}
void repositoryShow (ZebraHandle zh)
Dict dict;
struct dirs_info *di;
- if (!(dict = dict_open (zh->service->bfs, FMATCH_DICT, 50, 0, 0)))
+ if (!(dict = dict_open (zh->reg->bfs, FMATCH_DICT, 50, 0, 0)))
{
logf (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT);
return;
void repositoryUpdate (ZebraHandle zh)
{
struct recordGroup *rGroup = &zh->rGroup;
- groupRes (zh->service, rGroup);
+ groupRes (zh, rGroup);
assert (rGroup->path);
if (rGroup->recordId && !strcmp (rGroup->recordId, "file"))
{
Dict dict;
- if (!(dict = dict_open (zh->service->bfs, FMATCH_DICT, 50,
+ if (!(dict = dict_open (zh->reg->bfs, FMATCH_DICT, 50,
rGroup->flagRw, 0)))
{
logf (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: trunc.c,v $
- * Revision 1.20 2002-03-20 20:24:29 adam
+ * Revision 1.21 2002-04-04 14:14:13 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.20 2002/03/20 20:24:29 adam
* Hits per term. Returned in SearchResult-1
*
* Revision 1.19 2001/01/16 16:56:15 heikki
#define NEW_TRUNC 1
-#include "zserver.h"
+#include "index.h"
#include <rstemp.h>
#include <rsnull.h>
#include <rsisams.h>
parms.cmp = key_compare_it;
parms.key_size = sizeof(struct it_key);
- parms.temp_path = res_get (zi->service->res, "setTmpDir");
+ parms.temp_path = res_get (zi->res, "setTmpDir");
parms.rset_term = rset_term_create (term, length, flags);
result = rset_create (rset_kind_temp, &parms);
result_rsfd = rset_open (result, RSETF_WRITE);
heap_close (ti);
}
#if ZMBOL
- else if (zi->service->isam)
+ else if (zi->reg->isam)
{
ISPT *ispt;
int i;
key_compare_it);
for (i = to-from; --i >= 0; )
{
- ispt[i] = is_position (zi->service->isam, isam_p[from+i]);
+ ispt[i] = is_position (zi->reg->isam, isam_p[from+i]);
if (is_readkey (ispt[i], ti->tmpbuf))
heap_insert (ti, ti->tmpbuf, i);
else
heap_close (ti);
xfree (ispt);
}
- else if (zi->service->isamc)
+ else if (zi->reg->isamc)
{
ISAMC_PP *ispt;
int i;
key_compare_it);
for (i = to-from; --i >= 0; )
{
- ispt[i] = isc_pp_open (zi->service->isamc, isam_p[from+i]);
+ ispt[i] = isc_pp_open (zi->reg->isamc, isam_p[from+i]);
if (isc_pp_read (ispt[i], ti->tmpbuf))
heap_insert (ti, ti->tmpbuf, i);
else
xfree (ispt);
}
- else if (zi->service->isamd)
+ else if (zi->reg->isamd)
{
ISAMD_PP *ispt;
int i;
key_compare_it);
for (i = to-from; --i >= 0; )
{
- ispt[i] = isamd_pp_open (zi->service->isamd, isam_p[from+i]);
+ ispt[i] = isamd_pp_open (zi->reg->isamd, isam_p[from+i]);
if (isamd_pp_read (ispt[i], ti->tmpbuf))
heap_insert (ti, ti->tmpbuf, i);
else
}
#endif
- else if (zi->service->isams)
+ else if (zi->reg->isams)
{
ISAMS_PP *ispt;
int i;
key_compare_it);
for (i = to-from; --i >= 0; )
{
- ispt[i] = isams_pp_open (zi->service->isams, isam_p[from+i]);
+ ispt[i] = isams_pp_open (zi->reg->isams, isam_p[from+i]);
if (isams_pp_read (ispt[i], ti->tmpbuf))
heap_insert (ti, ti->tmpbuf, i);
else
parms.rset_term = rset_term_create (term, length, flags);
return rset_create (rset_kind_null, &parms);
}
- if (zi->service->isams)
+ if (zi->reg->isams)
{
if (no == 1)
{
rset_isams_parms parms;
parms.pos = *isam_p;
- parms.is = zi->service->isams;
+ parms.is = zi->reg->isams;
parms.rset_term = rset_term_create (term, length, flags);
return rset_create (rset_kind_isams, &parms);
}
qsort (isam_p, no, sizeof(*isam_p), isams_trunc_cmp);
}
#if ZMBOL
- else if (zi->service->isam)
+ else if (zi->reg->isam)
{
if (no == 1)
{
rset_isam_parms parms;
parms.pos = *isam_p;
- parms.is = zi->service->isam;
+ parms.is = zi->reg->isam;
parms.rset_term = rset_term_create (term, length, flags);
return rset_create (rset_kind_isam, &parms);
}
qsort (isam_p, no, sizeof(*isam_p), isam_trunc_cmp);
}
- else if (zi->service->isamc)
+ else if (zi->reg->isamc)
{
if (no == 1)
{
parms.key_size = sizeof(struct it_key);
parms.cmp = key_compare_it;
parms.pos = *isam_p;
- parms.is = zi->service->isamc;
+ parms.is = zi->reg->isamc;
parms.rset_term = rset_term_create (term, length, flags);
return rset_create (rset_kind_isamc, &parms);
}
parms.key_size = sizeof(struct it_key);
parms.cmp = key_compare_it;
- parms.isc = zi->service->isamc;
+ parms.isc = zi->reg->isamc;
parms.isam_positions = isam_p;
parms.no_isam_positions = no;
parms.no_save_positions = 100000;
#endif
qsort (isam_p, no, sizeof(*isam_p), isamc_trunc_cmp);
}
- else if (zi->service->isamd)
+ else if (zi->reg->isamd)
{
if (no == 1)
{
rset_isamd_parms parms;
parms.pos = *isam_p;
- parms.is = zi->service->isamd;
+ parms.is = zi->reg->isamd;
parms.rset_term = rset_term_create (term, length, flags);
return rset_create (rset_kind_isamd, &parms);
}
parms.key_size = sizeof(struct it_key);
parms.cmp = key_compare_it;
parms.isc = 0;
- parms.isamd=zi->service->isamd;
+ parms.isamd=zi->reg->isamd;
parms.isam_positions = isam_p;
parms.no_isam_positions = no;
parms.no_save_positions = 100000;
* Copyright (C) 1995-2002, Index Data
* All rights reserved.
*
- * $Id: zebraapi.c,v 1.50 2002-03-27 07:53:13 adam Exp $
+ * $Id: zebraapi.c,v 1.51 2002-04-04 14:14:13 adam Exp $
*/
#include <assert.h>
#endif
#include <yaz/diagbib1.h>
-#include "zserver.h"
+#include "index.h"
#include <charmap.h>
+static Res zebra_open_res (ZebraHandle zh);
+static void zebra_close_res (ZebraHandle zh);
+
static void zebra_chdir (ZebraService zh)
{
- const char *dir = res_get (zh->res, "chdir");
+ const char *dir = res_get (zh->global_res, "chdir");
if (!dir)
return;
logf (LOG_DEBUG, "chdir %s", dir);
#endif
}
+
static void zebra_flush_reg (ZebraHandle zh)
{
- zebraExplain_flush (zh->service->zei, 1, zh);
+ zebraExplain_flush (zh->reg->zei, 1, zh);
extract_flushWriteKeys (zh);
zebra_index_merge (zh);
}
-static int zebra_register_activate (ZebraHandle zh, int rw, int useshadow);
-static int zebra_register_deactivate (ZebraHandle zh);
+static struct zebra_register *zebra_register_open (ZebraService zs,
+ const char *name,
+ int rw, int useshadow,
+ Res res,
+ const char *reg_path);
+static void zebra_register_close (ZebraService zs, struct zebra_register *reg);
static int zebra_begin_read (ZebraHandle zh);
static void zebra_end_read (ZebraHandle zh);
ZebraHandle zh;
assert (zs);
- if (zs->stop_flag)
- return 0;
zh = (ZebraHandle) xmalloc (sizeof(*zh));
yaz_log (LOG_LOG, "zebra_open zs=%p returns %p", zs, zh);
zh->service = zs;
+ zh->reg = 0; /* no register attached yet */
zh->sets = 0;
zh->destroyed = 0;
zh->errCode = 0;
zh->errString = 0;
+ zh->res = 0;
+
+ zh->reg_name = xstrdup ("");
+ zh->path_reg = 0;
+ zh->num_basenames = 0;
+ zh->basenames = 0;
zh->trans_no = 0;
- zh->lock_normal = zebra_lock_create (res_get(zs->res, "lockDir"),
- "norm.LCK", 0);
- zh->lock_shadow = zebra_lock_create (res_get(zs->res, "lockDir"),
- "shadow.LCK", 0);
+ zh->lock_normal = 0;
+ zh->lock_shadow = 0;
- zh->key_buf = 0;
zh->admin_databaseName = 0;
- zh->keys.buf_max = 0;
- zh->keys.buf = 0;
-
zebra_mutex_cond_lock (&zs->session_lock);
zh->next = zs->sessions;
return zh;
}
-
ZebraService zebra_start (const char *configName)
{
ZebraService zh = xmalloc (sizeof(*zh));
zh->configName = xstrdup(configName);
zh->sessions = 0;
- zh->stop_flag = 0;
- zh->active = 1;
- zh->registerState = -1;
- zh->registerChange = 0;
-
- zh->seqno = 0;
- zh->last_val = 0;
-
- if (!(zh->res = res_open (zh->configName)))
+ if (!(zh->global_res = res_open (zh->configName, 0)))
{
logf (LOG_WARN, "Failed to read resources `%s'", zh->configName);
-// return zh;
+ }
+ else
+ {
+ logf (LOG_LOG, "Read resources `%s'", zh->configName);
}
zebra_chdir (zh);
zebra_mutex_cond_init (&zh->session_lock);
- if (!res_get (zh->res, "passwd"))
+ if (!res_get (zh->global_res, "passwd"))
zh->passwd_db = NULL;
else
{
if (!zh->passwd_db)
logf (LOG_WARN|LOG_ERRNO, "passwd_db_open failed");
else
- passwd_db_file (zh->passwd_db, res_get (zh->res, "passwd"));
+ passwd_db_file (zh->passwd_db, res_get (zh->global_res, "passwd"));
}
-
+ zh->path_root = res_get (zh->global_res, "root");
return zh;
}
-static int zebra_register_activate (ZebraHandle zh, int rw, int useshadow)
+static
+struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
+ int rw, int useshadow, Res res,
+ const char *reg_path)
{
- ZebraService zs = zh->service;
+ struct zebra_register *reg;
int record_compression = REC_COMPRESS_NONE;
char *recordCompression = 0;
- yaz_log (LOG_LOG, "zebra_open_register_activate rw = %d useshadow=%d",
- rw, useshadow);
+ reg = xmalloc (sizeof(*reg));
- zs->dh = data1_create ();
- if (!zs->dh)
- return -1;
- zs->bfs = bfs_create (res_get (zs->res, "register"));
- if (!zs->bfs)
+ assert (name);
+ reg->name = xstrdup (name);
+
+ reg->seqno = 0;
+ reg->last_val = 0;
+
+ assert (res);
+
+ yaz_log (LOG_LOG, "zebra_register_open rw = %d useshadow=%d p=%p",
+ rw, useshadow, reg);
+
+ reg->dh = data1_create ();
+ if (!reg->dh)
+ return 0;
+ reg->bfs = bfs_create (res_get (res, "register"), reg_path);
+ if (!reg->bfs)
{
- data1_destroy(zs->dh);
- return -1;
+ data1_destroy(reg->dh);
+ return 0;
}
- bf_lockDir (zs->bfs, res_get (zs->res, "lockDir"));
if (useshadow)
- bf_cache (zs->bfs, res_get (zs->res, "shadow"));
- data1_set_tabpath (zs->dh, res_get(zs->res, "profilePath"));
- zs->recTypes = recTypes_init (zs->dh);
- recTypes_default_handlers (zs->recTypes);
-
- zs->zebra_maps = zebra_maps_open (zs->res);
- zs->rank_classes = NULL;
-
- zs->records = 0;
- zs->dict = 0;
- zs->sortIdx = 0;
- zs->isams = 0;
- zs->matchDict = 0;
+ bf_cache (reg->bfs, res_get (res, "shadow"));
+ data1_set_tabpath (reg->dh, res_get(res, "profilePath"));
+ reg->recTypes = recTypes_init (reg->dh);
+ recTypes_default_handlers (reg->recTypes);
+
+ reg->zebra_maps = zebra_maps_open (res);
+ reg->rank_classes = NULL;
+
+ reg->key_buf = 0;
+
+ reg->keys.buf_max = 0;
+ reg->keys.buf = 0;
+
+ reg->records = 0;
+ reg->dict = 0;
+ reg->sortIdx = 0;
+ reg->isams = 0;
+ reg->matchDict = 0;
#if ZMBOL
- zs->isam = 0;
- zs->isamc = 0;
- zs->isamd = 0;
+ reg->isam = 0;
+ reg->isamc = 0;
+ reg->isamd = 0;
#endif
- zs->zei = 0;
- zs->matchDict = 0;
+ reg->zei = 0;
+ reg->matchDict = 0;
- zebraRankInstall (zs, rank1_class);
+ zebraRankInstall (reg, rank1_class);
- recordCompression = res_get_def (zh->service->res,
- "recordCompression", "none");
+ recordCompression = res_get_def (res, "recordCompression", "none");
if (!strcmp (recordCompression, "none"))
record_compression = REC_COMPRESS_NONE;
if (!strcmp (recordCompression, "bzip2"))
record_compression = REC_COMPRESS_BZIP2;
- if (!(zs->records = rec_open (zs->bfs, rw, record_compression)))
+ if (!(reg->records = rec_open (reg->bfs, rw, record_compression)))
{
logf (LOG_WARN, "rec_open");
- return -1;
+ return 0;
}
if (rw)
{
- zs->matchDict = dict_open (zs->bfs, GMATCH_DICT, 20, 1, 0);
+ reg->matchDict = dict_open (reg->bfs, GMATCH_DICT, 20, 1, 0);
}
- if (!(zs->dict = dict_open (zs->bfs, FNAME_DICT, 40, rw, 0)))
+ if (!(reg->dict = dict_open (reg->bfs, FNAME_DICT, 40, rw, 0)))
{
logf (LOG_WARN, "dict_open");
- return -1;
+ return 0;
}
- if (!(zs->sortIdx = sortIdx_open (zs->bfs, rw)))
+ if (!(reg->sortIdx = sortIdx_open (reg->bfs, rw)))
{
logf (LOG_WARN, "sortIdx_open");
- return -1;
+ return 0;
}
- if (res_get_match (zs->res, "isam", "s", ISAM_DEFAULT))
+ if (res_get_match (res, "isam", "s", ISAM_DEFAULT))
{
struct ISAMS_M_s isams_m;
- if (!(zs->isams = isams_open (zs->bfs, FNAME_ISAMS, rw,
- key_isams_m(zs->res, &isams_m))))
+ if (!(reg->isams = isams_open (reg->bfs, FNAME_ISAMS, rw,
+ key_isams_m(res, &isams_m))))
{
logf (LOG_WARN, "isams_open");
- return -1;
+ return 0;
}
}
#if ZMBOL
- else if (res_get_match (zs->res, "isam", "i", ISAM_DEFAULT))
+ else if (res_get_match (res, "isam", "i", ISAM_DEFAULT))
{
- if (!(zs->isam = is_open (zs->bfs, FNAME_ISAM, key_compare, rw,
- sizeof (struct it_key), zs->res)))
+ if (!(reg->isam = is_open (reg->bfs, FNAME_ISAM, key_compare, rw,
+ sizeof (struct it_key), res)))
{
logf (LOG_WARN, "is_open");
- return -1;
+ return 0;
}
}
- else if (res_get_match (zs->res, "isam", "c", ISAM_DEFAULT))
+ else if (res_get_match (res, "isam", "c", ISAM_DEFAULT))
{
struct ISAMC_M_s isamc_m;
- if (!(zs->isamc = isc_open (zs->bfs, FNAME_ISAMC,
- rw, key_isamc_m(zs->res, &isamc_m))))
+ if (!(reg->isamc = isc_open (reg->bfs, FNAME_ISAMC,
+ rw, key_isamc_m(res, &isamc_m))))
{
logf (LOG_WARN, "isc_open");
- return -1;
+ return 0;
}
}
- else if (res_get_match (zs->res, "isam", "d", ISAM_DEFAULT))
+ else if (res_get_match (res, "isam", "d", ISAM_DEFAULT))
{
struct ISAMD_M_s isamd_m;
- if (!(zs->isamd = isamd_open (zs->bfs, FNAME_ISAMD,
- rw, key_isamd_m(zs->res, &isamd_m))))
+ if (!(reg->isamd = isamd_open (reg->bfs, FNAME_ISAMD,
+ rw, key_isamd_m(res, &isamd_m))))
{
logf (LOG_WARN, "isamd_open");
- return -1;
+ return 0;
}
}
#endif
- zs->zei = zebraExplain_open (zs->records, zs->dh,
- zs->res, rw, zh,
- explain_extract);
- if (!zs->zei)
+ reg->zei = zebraExplain_open (reg->records, reg->dh,
+ res, rw, reg,
+ explain_extract);
+ if (!reg->zei)
{
logf (LOG_WARN, "Cannot obtain EXPLAIN information");
- return -1;
+ return 0;
}
- zs->active = 2;
- yaz_log (LOG_LOG, "zebra_register_activate ok");
- return 0;
+ reg->active = 2;
+ yaz_log (LOG_LOG, "zebra_register_open ok p=%p", reg);
+ return reg;
}
void zebra_admin_shutdown (ZebraHandle zh)
{
zebra_mutex_cond_lock (&zh->service->session_lock);
zh->service->stop_flag = 1;
- if (!zh->service->sessions)
- zebra_register_deactivate(zh);
- zh->service->active = 0;
zebra_mutex_cond_unlock (&zh->service->session_lock);
}
ZebraService zs = zh->service;
zh->errCode = 0;
zebra_mutex_cond_lock (&zs->session_lock);
- if (!zs->stop_flag)
- zh->service->active = 1;
zebra_mutex_cond_unlock (&zs->session_lock);
}
-static int zebra_register_deactivate (ZebraHandle zh)
+static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
{
- ZebraService zs = zh->service;
- zs->stop_flag = 0;
- if (zs->active <= 1)
- {
- yaz_log(LOG_LOG, "zebra_register_deactivate (ignored since active=%d)",
- zs->active);
- return 0;
- }
- yaz_log(LOG_LOG, "zebra_register_deactivate");
+ yaz_log(LOG_LOG, "zebra_register_close p=%p", reg);
+ reg->stop_flag = 0;
zebra_chdir (zs);
- if (zs->records)
- {
- zebraExplain_close (zs->zei, 0);
- dict_close (zs->dict);
- if (zs->matchDict)
- dict_close (zs->matchDict);
- sortIdx_close (zs->sortIdx);
- if (zs->isams)
- isams_close (zs->isams);
+ if (reg->records)
+ {
+ zebraExplain_close (reg->zei, 0);
+ dict_close (reg->dict);
+ if (reg->matchDict)
+ dict_close (reg->matchDict);
+ sortIdx_close (reg->sortIdx);
+ if (reg->isams)
+ isams_close (reg->isams);
#if ZMBOL
- if (zs->isam)
- is_close (zs->isam);
- if (zs->isamc)
- isc_close (zs->isamc);
- if (zs->isamd)
- isamd_close (zs->isamd);
+ if (reg->isam)
+ is_close (reg->isam);
+ if (reg->isamc)
+ isc_close (reg->isamc);
+ if (reg->isamd)
+ isamd_close (reg->isamd);
#endif
- rec_close (&zs->records);
+ rec_close (®->records);
}
- resultSetInvalidate (zh);
- recTypes_destroy (zs->recTypes);
- zebra_maps_close (zs->zebra_maps);
- zebraRankDestroy (zs);
- bfs_destroy (zs->bfs);
- data1_destroy (zs->dh);
+ recTypes_destroy (reg->recTypes);
+ zebra_maps_close (reg->zebra_maps);
+ zebraRankDestroy (reg);
+ bfs_destroy (reg->bfs);
+ data1_destroy (reg->dh);
- if (zs->passwd_db)
- passwd_db_close (zs->passwd_db);
- zs->active = 1;
- return 0;
+ xfree (reg->key_buf);
+ xfree (reg->name);
+ xfree (reg);
+ yaz_log (LOG_LOG, "zebra_register_close 2");
}
void zebra_stop(ZebraService zs)
zebra_mutex_cond_lock (&zs->session_lock);
while (zs->sessions)
{
- zebra_register_deactivate(zs->sessions);
zebra_close (zs->sessions);
}
zebra_mutex_cond_destroy (&zs->session_lock);
- res_close (zs->res);
+ if (zs->passwd_db)
+ passwd_db_close (zs->passwd_db);
+
+ res_close (zs->global_res);
xfree (zs->configName);
+ xfree (zs->path_root);
xfree (zs);
}
return ;
resultSetDestroy (zh, -1, 0, 0);
- if (zh->key_buf)
- {
- xfree (zh->key_buf);
- zh->key_buf = 0;
- }
-
+
+ if (zh->reg)
+ zebra_register_close (zh->service, zh->reg);
+ zebra_close_res (zh);
+
xfree (zh->admin_databaseName);
zebra_mutex_cond_lock (&zs->session_lock);
zebra_lock_destroy (zh->lock_normal);
// if (!zs->sessions && zs->stop_flag)
// zebra_register_deactivate(zs);
zebra_mutex_cond_unlock (&zs->session_lock);
+ xfree (zh->reg_name);
xfree (zh);
-}
+ yaz_log (LOG_LOG, "zebra_close zh=%p end", zh);}
struct map_baseinfo {
ZebraHandle zh;
char **new_basenames;
int new_num_max;
};
-
+
+static Res zebra_open_res (ZebraHandle zh)
+{
+ Res res = 0;
+ char fname[512];
+ if (*zh->reg_name == 0)
+ {
+ res = zh->service->global_res;
+ yaz_log (LOG_LOG, "local res = global res");
+ }
+ else if (zh->path_reg)
+ {
+ sprintf (fname, "%.200s/zebra.cfg", zh->path_reg);
+ yaz_log (LOG_LOG, "res_open(%s)", fname);
+ res = res_open (fname, zh->service->global_res);
+ if (!res)
+ return 0;
+ }
+ else
+ return 0; /* no path for register - fail! */
+ return res;
+}
+
+static void zebra_close_res (ZebraHandle zh)
+{
+ if (zh->res != zh->service->global_res)
+ res_close (zh->res);
+ zh->res = 0;
+}
+
+static int zebra_select_register (ZebraHandle zh, const char *new_reg)
+{
+ if (zh->res && strcmp (zh->reg_name, new_reg) == 0)
+ return 0;
+ if (!zh->res)
+ {
+ assert (zh->reg == 0);
+ assert (*zh->reg_name == 0);
+ }
+ else
+ {
+ if (zh->reg)
+ {
+ resultSetInvalidate (zh);
+ zebra_register_close (zh->service, zh->reg);
+ zh->reg = 0;
+ }
+ zebra_close_res(zh);
+ }
+ xfree (zh->reg_name);
+ zh->reg_name = xstrdup (new_reg);
+
+ xfree (zh->path_reg);
+ zh->path_reg = 0;
+ if (zh->service->path_root)
+ {
+ zh->path_reg = xmalloc (strlen(zh->service->path_root) +
+ strlen(zh->reg_name) + 3);
+ strcpy (zh->path_reg, zh->service->path_root);
+ if (*zh->reg_name)
+ {
+ strcat (zh->path_reg, "/");
+ strcat (zh->path_reg, zh->reg_name);
+ }
+ }
+ zh->res = zebra_open_res (zh);
+
+ if (zh->lock_normal)
+ zebra_lock_destroy (zh->lock_normal);
+ zh->lock_normal = 0;
+
+ if (zh->lock_shadow)
+ zebra_lock_destroy (zh->lock_shadow);
+ zh->lock_shadow = 0;
+
+ if (zh->res)
+ {
+ char fname[512];
+ const char *lock_area =res_get (zh->res, "lockDir");
+
+ if (!lock_area && zh->path_reg)
+ res_put (zh->res, "lockDir", zh->path_reg);
+ sprintf (fname, "norm.%s.LCK", zh->reg_name);
+ zh->lock_normal =
+ zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
+
+ sprintf (fname, "shadow.%s.LCK", zh->reg_name);
+ zh->lock_shadow =
+ zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
+
+ }
+ return 1;
+}
+
void map_basenames_func (void *vp, const char *name, const char *value)
{
struct map_baseinfo *p = (struct map_baseinfo *) vp;
odr_malloc (stream, sizeof(*info.new_basenames) * info.new_num_max);
info.mem = stream->mem;
- res_trav (zh->service->res, "mapdb", &info, map_basenames_func);
+ res_trav (zh->service->global_res, "mapdb", &info, map_basenames_func);
for (i = 0; i<p->num_bases; i++)
if (p->basenames[i] && p->new_num_bases < p->new_num_max)
logf (LOG_LOG, "base %s", (*basenames)[i]);
}
-void zebra_search_rpn (ZebraHandle zh, ODR stream, ODR decode,
- Z_RPNQuery *query, int num_bases, char **basenames,
- const char *setname)
+int zebra_select_database (ZebraHandle zh, const char *basename)
+{
+ return zebra_select_databases (zh, 1, &basename);
+}
+
+int zebra_select_databases (ZebraHandle zh, int num_bases,
+ const char **basenames)
+{
+ int i;
+ const char *cp;
+ size_t len = 0;
+ char *new_reg = 0;
+
+ if (num_bases < 1)
+ {
+ zh->errCode = 23;
+ return -1;
+ }
+ for (i = 0; i < zh->num_basenames; i++)
+ xfree (zh->basenames[i]);
+ xfree (zh->basenames);
+
+ zh->num_basenames = num_bases;
+ zh->basenames = xmalloc (zh->num_basenames * sizeof(*zh->basenames));
+ for (i = 0; i < zh->num_basenames; i++)
+ zh->basenames[i] = xstrdup (basenames[i]);
+
+ cp = strrchr(basenames[0], '/');
+ if (cp)
+ {
+ len = cp - basenames[0];
+ new_reg = xmalloc (len + 1);
+ memcpy (new_reg, basenames[0], len);
+ new_reg[len] = '\0';
+ }
+ else
+ new_reg = xstrdup ("");
+ for (i = 1; i<num_bases; i++)
+ {
+ const char *cp1;
+
+ cp1 = strrchr (basenames[i], '/');
+ if (cp)
+ {
+ if (!cp1)
+ {
+ zh->errCode = 23;
+ return -1;
+ }
+ if (len != cp - basenames[i] ||
+ memcmp (basenames[i], new_reg, len))
+ {
+ zh->errCode = 23;
+ return -1;
+ }
+ }
+ else
+ {
+ if (cp1)
+ {
+ zh->errCode = 23;
+ return -1;
+ }
+ }
+ }
+ zebra_select_register (zh, new_reg);
+ xfree (new_reg);
+ if (!zh->res)
+ {
+ zh->errCode = 109;
+ return -1;
+ }
+ return 0;
+}
+
+void zebra_search_rpn (ZebraHandle zh, ODR decode, ODR stream,
+ Z_RPNQuery *query, const char *setname, int *hits)
{
zh->hits = 0;
+ *hits = 0;
+
if (zebra_begin_read (zh))
return;
- map_basenames (zh, stream, &num_bases, &basenames);
- resultSetAddRPN (zh, stream, decode, query, num_bases, basenames, setname);
+ resultSetAddRPN (zh, decode, stream, query,
+ zh->num_basenames, zh->basenames, setname);
zebra_end_read (zh);
logf(LOG_APP,"SEARCH:%d:",zh->hits);
+ *hits = zh->hits;
}
-
-
void zebra_records_retrieve (ZebraHandle zh, ODR stream,
const char *setname, Z_RecordComposition *comp,
oid_value input_format, int num_recs,
ZebraPosSet poset;
int i, *pos_array;
+ if (!zh->res)
+ {
+ zh->errCode = 30;
+ zh->errString = odr_strdup (stream, setname);
+ return;
+ }
+
if (zebra_begin_read (zh))
return;
sprintf (num_str, "%d", pos_array[i]);
zh->errCode = 13;
- zh->errString = nmem_strdup (stream->mem, num_str);
+ zh->errString = odr_strdup (stream, num_str);
break;
}
}
void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
oid_value attributeset,
- int num_bases, char **basenames,
int *position, int *num_entries, ZebraScanEntry **entries,
int *is_partial)
{
*num_entries = 0;
return;
}
- map_basenames (zh, stream, &num_bases, &basenames);
rpn_scan (zh, stream, zapt, attributeset,
- num_bases, basenames, position,
+ zh->num_basenames, zh->basenames, position,
num_entries, entries, is_partial);
zebra_end_read (zh);
}
return zh->errString;
}
-int zebra_hits (ZebraHandle zh)
+int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
{
- return zh->hits;
-}
-
-int zebra_auth (ZebraService zh, const char *user, const char *pass)
-{
- if (!zh->passwd_db || !passwd_db_auth (zh->passwd_db, user, pass))
+ ZebraService zs = zh->service;
+ if (!zs->passwd_db || !passwd_db_auth (zs->passwd_db, user, pass))
{
logf(LOG_APP,"AUTHOK:%s", user?user:"ANONYMOUS");
return 0;
{
int sysno;
int i;
- if (zh->service->active < 2)
- return;
for (i = 0; i<segment->num_segmentRecords; i++)
{
Z_NamePlusRecord *npr = segment->segmentRecords[i];
zs = zh->service;
/* announce database */
- if (zebraExplain_newDatabase (zh->service->zei, database, 0
+ if (zebraExplain_newDatabase (zh->reg->zei, database, 0
/* explainDatabase */))
{
zh->errCode = 224;
char *output_str, int output_len)
{
WRBUF wrbuf;
- if (!zh->service->zebra_maps)
+ if (!zh->reg->zebra_maps)
return -1;
- wrbuf = zebra_replace(zh->service->zebra_maps, reg_id, "",
+ wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, "",
input_str, input_len);
if (!wrbuf)
return -2;
void zebra_set_state (ZebraHandle zh, int val, int seqno)
{
- char *fname = zebra_mk_fname (res_get(zh->service->res, "lockDir"),
- "state.LCK");
+ char state_fname[256];
+ char *fname;
long p = getpid();
- FILE *f = fopen (fname, "w");
+ FILE *f;
+
+ sprintf (state_fname, "state.%s.LCK", zh->reg_name);
+ fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
+ f = fopen (fname, "w");
+
+ yaz_log (LOG_LOG, "%c %d %ld", val, seqno, p);
fprintf (f, "%c %d %ld\n", val, seqno, p);
fclose (f);
xfree (fname);
void zebra_get_state (ZebraHandle zh, char *val, int *seqno)
{
- char *fname = zebra_mk_fname (res_get(zh->service->res, "lockDir"),
- "state.LCK");
- FILE *f = fopen (fname, "r");
+ char state_fname[256];
+ char *fname;
+ FILE *f;
+ sprintf (state_fname, "state.%s.LCK", zh->reg_name);
+ fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
+ f = fopen (fname, "r");
*val = 'o';
*seqno = 0;
char val;
int seqno;
+ assert (zh->res);
(zh->trans_no)++;
zebra_flush_reg (zh);
return 0;
}
-
+ if (!zh->res)
+ {
+ (zh->trans_no)--;
+ zh->errCode = 109;
+ return -1;
+ }
zebra_get_state (zh, &val, &seqno);
if (val == 'd')
val = 'o';
- if (seqno != zh->service->seqno)
+
+ if (!zh->reg)
+ dirty = 1;
+ else if (seqno != zh->reg->seqno)
{
- yaz_log (LOG_LOG, "reopen seqno cur/old %d/%d", seqno, zh->service->seqno);
+ yaz_log (LOG_LOG, "reopen seqno cur/old %d/%d",
+ seqno, zh->reg->seqno);
dirty = 1;
}
- else if (zh->service->last_val != val)
+ else if (zh->reg->last_val != val)
{
- yaz_log (LOG_LOG, "reopen last cur/old %d/%d", val, zh->service->last_val);
+ yaz_log (LOG_LOG, "reopen last cur/old %d/%d",
+ val, zh->reg->last_val);
dirty = 1;
}
if (!dirty)
else
zebra_lock_r (zh->lock_normal);
- zh->service->last_val = val;
- zh->service->seqno = seqno;
-
- zebra_register_deactivate (zh);
+ if (zh->reg)
+ zebra_register_close (zh->service, zh->reg);
+ zh->reg = zebra_register_open (zh->service, zh->reg_name,
+ 0, val == 'c' ? 1 : 0,
+ zh->res, zh->path_reg);
+ if (!zh->reg)
+ {
+ zh->errCode = 109;
+ return -1;
+ }
+ zh->reg->last_val = val;
+ zh->reg->seqno = seqno;
- zebra_register_activate (zh, 0, val == 'c' ? 1 : 0);
return 0;
}
char val = '?';
const char *rval;
+ assert (zh->res);
+
(zh->trans_no++);
if (zh->trans_no != 1)
{
return;
}
-
+
yaz_log (LOG_LOG, "zebra_begin_trans");
#if HAVE_SYS_TIMES_H
times (&zh->tms1);
#endif
-
+
/* lock */
- rval = res_get (zh->service->res, "shadow");
+ rval = res_get (zh->res, "shadow");
for (pass = 0; pass < 2; pass++)
{
{
if (rval)
{
- BFiles bfs = bfs_create (res_get (zh->service->res, "shadow"));
+ BFiles bfs = bfs_create (res_get (zh->res, "shadow"),
+ zh->path_reg);
yaz_log (LOG_LOG, "previous transaction didn't reach commit");
bf_commitClean (bfs, rval);
bfs_destroy (bfs);
}
zebra_set_state (zh, 'd', seqno);
- zebra_register_activate (zh, 1, rval ? 1 : 0);
- zh->service->seqno = seqno;
+ zh->reg = zebra_register_open (zh->service, zh->reg_name,
+ 1, rval ? 1 : 0, zh->res,
+ zh->path_reg);
+
+ zh->reg->seqno = seqno;
}
void zebra_end_trans (ZebraHandle zh)
return;
yaz_log (LOG_LOG, "zebra_end_trans");
- rval = res_get (zh->service->res, "shadow");
+ rval = res_get (zh->res, "shadow");
zebra_flush_reg (zh);
- zebra_register_deactivate (zh);
+ zebra_register_close (zh->service, zh->reg);
+ zh->reg = 0;
zebra_get_state (zh, &val, &seqno);
if (val != 'd')
{
- BFiles bfs = bfs_create (res_get (zh->service->res, "shadow"));
+ BFiles bfs = bfs_create (rval, zh->path_reg);
+ yaz_log (LOG_LOG, "deleting shadow stuff val=%c", val);
bf_commitClean (bfs, rval);
bfs_destroy (bfs);
}
repositoryShow (zh);
}
-void zebra_commit (ZebraHandle zh)
+int zebra_commit (ZebraHandle zh)
{
int seqno;
char val;
- const char *rval = res_get (zh->service->res, "shadow");
+ const char *rval;
BFiles bfs;
+ if (!zh->res)
+ {
+ zh->errCode = 109;
+ return -1;
+ }
+ rval = res_get (zh->res, "shadow");
if (!rval)
{
logf (LOG_WARN, "Cannot perform commit");
logf (LOG_WARN, "No shadow area defined");
- return;
+ return 0;
}
zebra_lock_w (zh->lock_normal);
zebra_lock_r (zh->lock_shadow);
- bfs = bfs_create (res_get (zh->service->res, "register"));
+ bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg);
zebra_get_state (zh, &val, &seqno);
zebra_set_state (zh, 'c', seqno);
logf (LOG_LOG, "commit start");
+ sleep (2);
bf_commitExec (bfs);
#ifndef WIN32
sync ();
zebra_unlock (zh->lock_shadow);
zebra_unlock (zh->lock_normal);
+ return 0;
}
-void zebra_init (ZebraHandle zh)
+int zebra_init (ZebraHandle zh)
{
- const char *rval = res_get (zh->service->res, "shadow");
+ const char *rval;
BFiles bfs = 0;
- bfs = bfs_create (res_get (zh->service->res, "register"));
+ if (!zh->res)
+ {
+ zh->errCode = 109;
+ return -1;
+ }
+ rval = res_get (zh->res, "shadow");
+
+ bfs = bfs_create (res_get (zh->service->global_res, "register"),
+ zh->path_reg);
if (rval && *rval)
bf_cache (bfs, rval);
bf_reset (bfs);
bfs_destroy (bfs);
zebra_set_state (zh, 'o', 0);
+ return 0;
}
-void zebra_compact (ZebraHandle zh)
+int zebra_compact (ZebraHandle zh)
{
- BFiles bfs = bfs_create (res_get (zh->service->res, "register"));
+ BFiles bfs;
+ if (!zh->res)
+ {
+ zh->errCode = 109;
+ return -1;
+ }
+ bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg);
inv_compact (bfs);
bfs_destroy (bfs);
+ return 0;
}
int zebra_record_insert (ZebraHandle zh, const char *buf, int len)
zebra_end_trans (zh);
return sysno;
}
+
+void zebra_set_group (ZebraHandle zh, struct recordGroup *rg)
+{
+ memcpy (&zh->rGroup, rg, sizeof(*rg));
+}
+
+void zebra_result (ZebraHandle zh, int *code, char **addinfo)
+{
+ *code = zh->errCode;
+ *addinfo = zh->errString;
+}
+
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: zebraapi.h,v 1.13 2002-02-20 17:30:01 adam Exp $
+ * $Id: zebraapi.h,v 1.14 2002-04-04 14:14:13 adam Exp $
*/
#ifndef ZEBRAAPI_H
#include <yaz/odr.h>
#include <yaz/oid.h>
#include <yaz/proto.h>
+#include <zebraver.h>
YAZ_BEGIN_CDECL
+struct recordGroup {
+ char *groupName;
+ char *databaseName;
+ char *path;
+ char *recordId;
+ char *recordType;
+ int flagStoreData;
+ int flagStoreKeys;
+ int flagRw;
+ int fileVerboseLimit;
+ int databaseNamePath;
+ int explainDatabase;
+};
+
/* Retrieval Record Descriptor */
typedef struct {
int errCode; /* non-zero if error when fetching this */
/* Search using RPN-Query */
YAZ_EXPORT void zebra_search_rpn (ZebraHandle zh, ODR input, ODR output,
- Z_RPNQuery *query, int num_bases, char **basenames,
- const char *setname);
+ Z_RPNQuery *query,
+ const char *setname, int *hits);
/* Retrieve record(s) */
YAZ_EXPORT void zebra_records_retrieve (ZebraHandle zh, ODR stream,
YAZ_EXPORT void zebra_scan (ZebraHandle zh, ODR stream,
Z_AttributesPlusTerm *zapt,
oid_value attributeset,
- int num_bases, char **basenames,
int *position, int *num_entries,
ZebraScanEntry **list,
int *is_partial);
/* extra information associated with error */
YAZ_EXPORT char *zebra_errAdd (ZebraHandle zh);
-/* number of hits (after search) */
-YAZ_EXPORT int zebra_hits (ZebraHandle zh);
-
/* do authentication */
-YAZ_EXPORT int zebra_auth (ZebraService zh, const char *user, const char *pass);
+YAZ_EXPORT int zebra_auth (ZebraHandle zh, const char *user, const char *pass);
/* Character normalisation on specific register .
This routine is subject to change - do not use. */
void zebra_begin_trans (ZebraHandle zh);
void zebra_end_trans (ZebraHandle zh);
-void zebra_commit (ZebraHandle zh);
+int zebra_commit (ZebraHandle zh);
-void zebra_init (ZebraHandle zh);
-void zebra_compact (ZebraHandle zh);
+int zebra_init (ZebraHandle zh);
+int zebra_compact (ZebraHandle zh);
void zebra_repository_update (ZebraHandle zh);
void zebra_repository_delete (ZebraHandle zh);
void zebra_repository_show (ZebraHandle zh);
int zebra_record_insert (ZebraHandle zh, const char *buf, int len);
+YAZ_EXPORT void zebra_set_group (ZebraHandle zh, struct recordGroup *rg);
+
+YAZ_EXPORT void zebra_result (ZebraHandle zh, int *code, char **addinfo);
+
+YAZ_EXPORT const char *zebra_resultSetTerms (ZebraHandle zh,
+ const char *setname,
+ int no, int *count, int *no_max);
+
+YAZ_EXPORT void zebra_sort (ZebraHandle zh, ODR stream,
+ int num_input_setnames,
+ const char **input_setnames,
+ const char *output_setname,
+ Z_SortKeySpecList *sort_sequence,
+ int *sort_status);
+
+
+YAZ_EXPORT
+int zebra_select_databases (ZebraHandle zh, int num_bases,
+ const char **basenames);
+
+YAZ_EXPORT
+int zebra_select_database (ZebraHandle zh, const char *basename);
+
+
+
YAZ_END_CDECL
#endif
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: zinfo.c,v 1.24 2002-02-20 23:07:54 adam Exp $
+ * $Id: zinfo.c,v 1.25 2002-04-04 14:14:13 adam Exp $
*/
#include <stdlib.h>
int zebraExplain_curDatabase (ZebraExplainInfo zei, const char *database)
{
struct zebDatabaseInfoB *zdi;
+ const char *database_n = strrchr (database, '/');
+
+ if (database_n)
+ database_n++;
+ else
+ database_n = database;
assert (zei);
if (zei->curDatabaseInfo &&
return 0;
for (zdi = zei->databaseInfo; zdi; zdi=zdi->next)
{
- if (!strcmp (zdi->databaseName, database))
+ if (!strcmp (zdi->databaseName, database_n))
break;
}
if (!zdi)
{
struct zebDatabaseInfoB *zdi;
data1_node *node_dbinfo, *node_adinfo;
+ const char *database_n = strrchr (database, '/');
+
+ if (database_n)
+ database_n++;
+ else
+ database_n = database;
#if ZINFO_DEBUG
logf (LOG_LOG, "zebraExplain_newDatabase: %s", database);
assert (zei);
for (zdi = zei->databaseInfo; zdi; zdi=zdi->next)
{
- if (!strcmp (zdi->databaseName, database))
+ if (!strcmp (zdi->databaseName, database_n))
break;
}
if (zdi)
zdi->recordCount = 0;
zdi->recordBytes = 0;
zdi->readFlag = 0;
- zdi->databaseName = nmem_strdup (zei->nmem, database);
+ zdi->databaseName = nmem_strdup (zei->nmem, database_n);
zebraExplain_mergeAccessInfo (zei, 0, &zdi->accessInfo);
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: zrpn.c,v 1.111 2002-03-21 10:25:42 adam Exp $
+ * $Id: zrpn.c,v 1.112 2002-04-04 14:14:13 adam Exp $
*/
#include <stdio.h>
#include <assert.h>
#endif
#include <ctype.h>
-#include "zserver.h"
+#include "index.h"
#include <charmap.h>
#include <rstemp.h>
return zebra_maps_input (p->zm, p->reg_type, from, len);
}
-static void rpn_char_map_prepare (ZebraHandle zh, int reg_type,
+static void rpn_char_map_prepare (struct zebra_register *reg, int reg_type,
struct rpn_char_map_info *map_info)
{
- map_info->zm = zh->service->zebra_maps;
+ map_info->zm = reg->zebra_maps;
map_info->reg_type = reg_type;
- dict_grep_cmap (zh->service->dict, map_info, rpn_char_map_handler);
+ dict_grep_cmap (reg->dict, map_info, rpn_char_map_handler);
}
typedef struct {
{
while (*src)
{
- const char *cp = zebra_maps_output (zh->service->zebra_maps,
+ const char *cp = zebra_maps_output (zh->reg->zebra_maps,
reg_type, &src);
if (!cp)
*dst++ = *src++;
term_untrans (p->zh, p->reg_type, term_tmp, name+len+1);
logf (LOG_LOG, "grep: %d %c %s", su_code, name[len], term_tmp);
- zebraExplain_lookup_ord (p->zh->service->zei,
+ zebraExplain_lookup_ord (p->zh->reg->zei,
su_code, &db, &set, &use);
logf (LOG_LOG, "grep: set=%d use=%d db=%s", set, use, db);
switch (relation_value)
{
case 1:
- if (!term_100 (zh->service->zebra_maps, reg_type,
+ if (!term_100 (zh->reg->zebra_maps, reg_type,
term_sub, term_component,
space_split, term_dst))
return 0;
*term_tmp = '\0';
break;
case 2:
- if (!term_100 (zh->service->zebra_maps, reg_type,
+ if (!term_100 (zh->reg->zebra_maps, reg_type,
term_sub, term_component,
space_split, term_dst))
return 0;
*term_tmp = '\0';
break;
case 5:
- if (!term_100 (zh->service->zebra_maps, reg_type,
+ if (!term_100 (zh->reg->zebra_maps, reg_type,
term_sub, term_component, space_split, term_dst))
return 0;
logf (LOG_DEBUG, "Relation >");
*term_tmp = '\0';
break;
case 4:
- if (!term_100 (zh->service->zebra_maps, reg_type, term_sub,
+ if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub,
term_component, space_split, term_dst))
return 0;
logf (LOG_DEBUG, "Relation >=");
case 3:
default:
logf (LOG_DEBUG, "Relation =");
- if (!term_100 (zh->service->zebra_maps, reg_type, term_sub,
+ if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub,
term_component, space_split, term_dst))
return 0;
strcat (term_tmp, "(");
struct rpn_char_map_info rcmi;
int space_split = complete_flag ? 0 : 1;
- rpn_char_map_prepare (zh, reg_type, &rcmi);
+ rpn_char_map_prepare (zh->reg, reg_type, &rcmi);
attr_init (&use, zapt, 1);
use_value = attr_find (&use, &curAttributeSet);
logf (LOG_DEBUG, "string_term, use value %d", use_value);
}
return -1;
}
- if (zebraExplain_curDatabase (zh->service->zei, basenames[base_no]))
+ if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no]))
{
zh->errCode = 109; /* Database unavailable */
zh->errString = basenames[base_no];
char ord_buf[32];
int i, ord_len;
- ord = zebraExplain_lookupSU (zh->service->zei, attp.attset_ordinal,
+ ord = zebraExplain_lookupSU (zh->reg->zei, attp.attset_ordinal,
local_attr->local);
if (ord < 0)
continue;
reg_type, space_split, term_dst))
return 0;
logf (LOG_DEBUG, "dict_lookup_grep: %s", term_dict+prefix_len);
- r = dict_lookup_grep (zh->service->dict, term_dict, 0,
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0,
grep_info, &max_pos, 0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep fail, rel=gt: %d", r);
break;
case 1: /* right truncation */
term_dict[j++] = '(';
- if (!term_100 (zh->service->zebra_maps, reg_type,
+ if (!term_100 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
return 0;
strcat (term_dict, ".*)");
- dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
+ dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
break;
case 2: /* keft truncation */
term_dict[j++] = '('; term_dict[j++] = '.'; term_dict[j++] = '*';
- if (!term_100 (zh->service->zebra_maps, reg_type,
+ if (!term_100 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
return 0;
strcat (term_dict, ")");
- dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
+ dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
break;
case 3: /* left&right truncation */
term_dict[j++] = '('; term_dict[j++] = '.'; term_dict[j++] = '*';
- if (!term_100 (zh->service->zebra_maps, reg_type,
+ if (!term_100 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
return 0;
strcat (term_dict, ".*)");
- dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
+ dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
break;
zh->errCode = 120;
return -1;
case 101: /* process # in term */
term_dict[j++] = '(';
- if (!term_101 (zh->service->zebra_maps, reg_type,
+ if (!term_101 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
return 0;
strcat (term_dict, ")");
- r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep err, trunc=#: %d", r);
break;
case 102: /* Regexp-1 */
term_dict[j++] = '(';
- if (!term_102 (zh->service->zebra_maps, reg_type,
+ if (!term_102 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
return 0;
strcat (term_dict, ")");
logf (LOG_DEBUG, "Regexp-1 tolerance=%d", r);
- r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep err, trunc=regular: %d",
case 103: /* Regexp-2 */
r = 1;
term_dict[j++] = '(';
- if (!term_103 (zh->service->zebra_maps, reg_type,
+ if (!term_103 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, &r, space_split, term_dst))
return 0;
strcat (term_dict, ")");
logf (LOG_DEBUG, "Regexp-2 tolerance=%d", r);
- r = dict_lookup_grep (zh->service->dict, term_dict, r, grep_info,
+ r = dict_lookup_grep (zh->reg->dict, term_dict, r, grep_info,
&max_pos, 2, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep err, trunc=eregular: %d",
break;
case 104: /* process # and ! in term */
term_dict[j++] = '(';
- if (!term_104 (zh->service->zebra_maps, reg_type,
+ if (!term_104 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
return 0;
strcat (term_dict, ")");
- r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep err, trunc=#/!: %d", r);
break;
case 105: /* process * and ! in term */
term_dict[j++] = '(';
- if (!term_105 (zh->service->zebra_maps, reg_type,
+ if (!term_105 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst, 1))
return 0;
strcat (term_dict, ")");
- r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep err, trunc=*/!: %d", r);
break;
case 106: /* process * and ! in term */
term_dict[j++] = '(';
- if (!term_105 (zh->service->zebra_maps, reg_type,
+ if (!term_105 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst, 0))
return 0;
strcat (term_dict, ")");
- r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep err, trunc=*/!: %d", r);
while ((len = (cp_end - cp)) > 0)
{
- map = zebra_maps_input (zh->service->zebra_maps, reg_type, &cp, len);
+ map = zebra_maps_input (zh->reg->zebra_maps, reg_type, &cp, len);
if (**map == *CHR_SPACE)
space_map = *map;
else
parms.rset_term->nn = min_nn;
parms.cmp = key_compare_it;
parms.key_size = sizeof (struct it_key);
- parms.temp_path = res_get (zh->service->res, "setTmpDir");
+ parms.temp_path = res_get (zh->res, "setTmpDir");
result = rset_create (rset_kind_temp, &parms);
rsfd_result = rset_open (result, RSETF_WRITE);
parms.rset_term->nn = min_nn;
parms.cmp = key_compare_it;
parms.key_size = sizeof (struct it_key);
- parms.temp_path = res_get (zh->service->res, "setTmpDir");
+ parms.temp_path = res_get (zh->res, "setTmpDir");
result = rset_create (rset_kind_temp, &parms);
rsfd_result = rset_open (result, RSETF_WRITE);
break;
}
if (ex_list)
- wrbuf = zebra_replace(zh->service->zebra_maps, reg_id, ex_list,
+ wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, ex_list,
termz, strlen(termz));
if (!wrbuf)
return nmem_strdup(stream, termz);
logf (LOG_DEBUG, "numeric relation value=%d", relation_value);
- if (!term_100 (zh->service->zebra_maps, reg_type, term_sub, term_tmp, 1,
+ if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub, term_tmp, 1,
term_dst))
return 0;
term_value = atoi (term_tmp);
sprintf (term_tmp, "(0*%d)", term_value);
}
logf (LOG_DEBUG, "dict_lookup_grep: %s", term_tmp);
- r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, max_pos,
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info, max_pos,
0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep fail, rel=gt: %d", r);
const char *termp;
struct rpn_char_map_info rcmi;
- rpn_char_map_prepare (zh, reg_type, &rcmi);
+ rpn_char_map_prepare (zh->reg, reg_type, &rcmi);
attr_init (&use, zapt, 1);
use_value = attr_find (&use, &curAttributeSet);
logf (LOG_DEBUG, "numeric_term, use value %d", use_value);
zh->errCode = 121;
return -1;
}
- if (zebraExplain_curDatabase (zh->service->zei, basenames[base_no]))
+ if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no]))
{
zh->errCode = 109; /* Database unavailable */
zh->errString = basenames[base_no];
char ord_buf[32];
int i, ord_len;
- ord = zebraExplain_lookupSU (zh->service->zei, attp.attset_ordinal,
+ ord = zebraExplain_lookupSU (zh->reg->zei, attp.attset_ordinal,
local_attr->local);
if (ord < 0)
continue;
parms.rset_term = rset_term_create (termz, -1, rank_type);
parms.cmp = key_compare_it;
parms.key_size = sizeof (struct it_key);
- parms.temp_path = res_get (zh->service->res, "setTmpDir");
+ parms.temp_path = res_get (zh->res, "setTmpDir");
result = rset_create (rset_kind_temp, &parms);
rsfd = rset_open (result, RSETF_WRITE);
int sort_flag;
char termz[IT_MAX_WORD+1];
- zebra_maps_attr (zh->service->zebra_maps, zapt, ®_id, &search_type,
+ zebra_maps_attr (zh->reg->zebra_maps, zapt, ®_id, &search_type,
rank_type, &complete_flag, &sort_flag);
logf (LOG_DEBUG, "reg_id=%c", reg_id);
attr_init (&use, zapt, 1);
use_value = attr_find (&use, &attributeset);
- if (zebra_maps_attr (zh->service->zebra_maps, zapt, ®_id, &search_type,
+ if (zebra_maps_attr (zh->reg->zebra_maps, zapt, ®_id, &search_type,
rank_type, &complete_flag, &sort_flag))
{
*num_entries = 0;
*num_entries = 0;
return;
}
- if (zebraExplain_curDatabase (zh->service->zei, basenames[base_no]))
+ if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no]))
{
zh->errString = basenames[base_no];
zh->errCode = 109; /* Database unavailable */
{
int ord;
- ord = zebraExplain_lookupSU (zh->service->zei, attp.attset_ordinal,
+ ord = zebraExplain_lookupSU (zh->reg->zei, attp.attset_ordinal,
local_attr->local);
if (ord > 0)
ords[ord_no++] = ord;
struct scan_info *scan_info = scan_info_array + i;
struct rpn_char_map_info rcmi;
- rpn_char_map_prepare (zh, reg_id, &rcmi);
+ rpn_char_map_prepare (zh->reg, reg_id, &rcmi);
scan_info->before = before;
scan_info->after = after;
trans_scan_term (zh, zapt, termz+prefix_len, reg_id);
- dict_scan (zh->service->dict, termz, &before_tmp, &after_tmp,
+ dict_scan (zh->reg->dict, termz, &before_tmp, &after_tmp,
scan_info, scan_handle);
}
glist = (ZebraScanEntry *)
* Copyright (C) 1995-2000, Index Data
* All rights reserved.
*
- * $Id: zserver.c,v 1.84 2002-03-20 20:24:30 adam Exp $
+ * $Id: zserver.c,v 1.85 2002-04-04 14:14:13 adam Exp $
*/
#include <stdio.h>
#include "zserver.h"
-#ifndef ZEBRASDR
-#define ZEBRASDR 0
-#endif
-#if ZEBRASDR
-#include "zebrasdr.h"
-#endif
-
static int bend_sort (void *handle, bend_sort_rr *rr);
static int bend_delete (void *handle, bend_delete_rr *rr);
static int bend_esrequest (void *handle, bend_esrequest_rr *rr);
xfree (openpass);
}
}
- if (zebra_auth (zh->service, user, passwd))
+ if (zebra_auth (zh, user, passwd))
{
r->errcode = 222;
r->errstring = user;
r->errcode = 0;
r->errstring = NULL;
+ if (zebra_select_databases (zh, r->num_bases,
+ (const char **) r->basenames))
+ {
+ zebra_result (zh, &r->errcode, &r->errstring);
+ return 0;
+ }
logf (LOG_LOG, "ResultSet '%s'", r->setname);
switch (r->query->which)
{
case Z_Query_type_1: case Z_Query_type_101:
zebra_search_rpn (zh, r->decode, r->stream, r->query->u.type_1,
- r->num_bases, r->basenames, r->setname);
- r->errcode = zh->errCode;
- r->errstring = zh->errString;
- r->hits = zh->hits;
+ r->setname, &r->hits);
+ zebra_result (zh, &r->errcode, &r->errstring);
if (!r->errcode)
search_terms (zh, r);
break;
r->last_in_set = 0;
zebra_records_retrieve (zh, r->stream, r->setname, r->comp,
r->request_format, 1, &retrievalRecord);
- if (zh->errCode) /* non Surrogate Diagnostic */
- {
- r->errcode = zh->errCode;
- r->errstring = zh->errString;
- }
- else if (retrievalRecord.errCode) /* Surrogate Diagnostic */
+ zebra_result (zh, &r->errcode, &r->errstring);
+ /* non Surrogate Diagnostic OR Surrogate Diagnostic */
+ if (r->errcode == 0 && retrievalRecord.errCode)
{
r->surrogate_flag = 1;
r->errcode = retrievalRecord.errCode;
r->errstring = retrievalRecord.errString;
r->basename = retrievalRecord.base;
}
- else /* Database Record */
+ else if (r->errcode == 0) /* Database Record */
{
r->errcode = 0;
r->basename = retrievalRecord.base;
ZebraScanEntry *entries;
ZebraHandle zh = (ZebraHandle) handle;
int is_partial, i;
+
+ zebra_select_databases (zh, r->num_bases, (const char **) r->basenames);
r->entries = (struct scan_entry *)
odr_malloc (r->stream, sizeof(*r->entries) * r->num_entries);
zebra_scan (zh, r->stream, r->term,
r->attributeset,
- r->num_bases, r->basenames,
&r->term_position,
&r->num_entries, &entries, &is_partial);
if (is_partial)
r->entries[i].term = entries[i].term;
r->entries[i].occurrences = entries[i].occurrences;
}
- r->errcode = zh->errCode;
- r->errstring = zh->errString;
+ zebra_result (zh, &r->errcode, &r->errstring);
return 0;
}
zebra_sort (zh, rr->stream,
rr->num_input_setnames, (const char **) rr->input_setnames,
rr->output_setname, rr->sort_sequence, &rr->sort_status);
- rr->errcode = zh->errCode;
- rr->errstring = zh->errString;
+ zebra_result (zh, &rr->errcode, &rr->errstring);
return 0;
}
break;
default:
yaz_log(LOG_LOG, "unknown admin");
- zh->errCode = 1001;
}
if (r->toKeep->databaseName)
{
yaz_log (LOG_LOG, "adm taskpackage (unhandled)");
break;
default:
- zh->errCode = 1001;
break;
}
else if (rr->esr->taskSpecificParameters->which == Z_External_ESAdmin)
{
es_admin (zh, rr->esr->taskSpecificParameters->u.adminService);
- rr->errcode = zh->errCode;
- rr->errstring = zh->errString;
+
+ zebra_result (zh, &rr->errcode, &rr->errstring);
}
else if (rr->esr->taskSpecificParameters->which == Z_External_itemOrder)
{
struct statserv_options_block *sob;
sob = statserv_getcontrol ();
- strcpy (sob->configname, FNAME_CONFIG);
+ strcpy (sob->configname, "zebra.cfg");
sob->bend_start = bend_start;
sob->bend_stop = bend_stop;
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: zserver.h,v 1.54 2002-03-27 07:53:13 adam Exp $
+ * $Id: zserver.h,v 1.55 2002-04-04 14:14:13 adam Exp $
*/
-#if HAVE_SYS_TIMES_H
-#include <sys/times.h>
-#endif
-
#include <yaz/backend.h>
-#include <rset.h>
-
-#include <sortidx.h>
-#include <passwddb.h>
-#include "index.h"
#include "zebraapi.h"
-#include "zinfo.h"
YAZ_BEGIN_CDECL
-typedef struct {
- char *term;
- char *db;
- int sysno;
- int score;
-} *ZebraPosSet;
-
-typedef struct zebra_set *ZebraSet;
-
-typedef struct zebra_rank_class {
- struct rank_control *control;
- int init_flag;
- void *class_handle;
- struct zebra_rank_class *next;
-} *ZebraRankClass;
-
-struct zebra_service {
- char *configName;
- struct zebra_session *sessions;
- ISAMS isams;
-#if ZMBOL
- ISAM isam;
- ISAMC isamc;
- ISAMD isamd;
-#endif
- Dict dict;
- Dict matchDict;
- SortIdx sortIdx;
- int registerState; /* 0 (no commit pages), 1 (use commit pages) */
- time_t registerChange;
- BFiles bfs;
- Records records;
- ZebraExplainInfo zei;
- Res res;
- ZebraLockHandle server_lock_cmt;
- ZebraLockHandle server_lock_org;
-
- char *server_path_prefix;
- data1_handle dh;
- ZebraMaps zebra_maps;
- ZebraRankClass rank_classes;
- RecTypes recTypes;
- Passwd_db passwd_db;
- Zebra_mutex_cond session_lock;
- int seqno;
- int last_val;
- int stop_flag;
- int active; /* 0=shutdown, 1=enabled and inactive, 2=activated */
-};
-
-struct recKeys {
- int buf_used;
- int buf_max;
- char *buf;
- char prevAttrSet;
- short prevAttrUse;
- int prevSeqNo;
-};
-
-struct sortKey {
- char *string;
- int length;
- int attrSet;
- int attrUse;
- struct sortKey *next;
-};
-
-struct zebra_session {
- struct zebra_session *next;
- struct zebra_service *service;
-
- struct recKeys keys;
- struct sortKey *sortKeys;
-
- char **key_buf;
- size_t ptr_top;
- size_t ptr_i;
- size_t key_buf_used;
- int key_file_no;
- char *admin_databaseName;
-
- ZebraLockHandle lock_normal;
- ZebraLockHandle lock_shadow;
-
- int trans_no;
- int destroyed;
- ZebraSet sets;
- int errCode;
- int hits;
- char *errString;
-#if HAVE_SYS_TIMES_H
- struct tms tms1;
- struct tms tms2;
-#endif
- struct recordGroup rGroup;
-};
-
-struct rank_control {
- char *name;
- void *(*create)(ZebraService zh);
- void (*destroy)(ZebraService zh, void *class_handle);
- void *(*begin)(ZebraHandle zh, void *class_handle, RSET rset);
- void (*end)(ZebraHandle zh, void *set_handle);
- int (*calc)(void *set_handle, int sysno);
- void (*add)(void *set_handle, int seqno, int term_index);
-};
-
-struct term_set_entry {
- char *term;
- struct term_set_entry *next;
-};
-
-struct term_set_list {
- struct term_set_entry *first;
- struct term_set_entry *last;
-};
-
-RSET rpn_search (ZebraHandle zh, NMEM mem,
- Z_RPNQuery *rpn, int num_bases, char **basenames,
- const char *setname, ZebraSet sset);
-
-
-void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
- oid_value attributeset,
- int num_bases, char **basenames,
- int *position, int *num_entries, ZebraScanEntry **list,
- int *is_partial);
-
-RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no,
- const char *term, int length_term, const char *flags);
-
-void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
- const char *db, int set,
- int use, const char *term);
-ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
-ZebraSet resultSetGet (ZebraHandle zh, const char *name);
-ZebraSet resultSetAddRPN (ZebraHandle zh, ODR stream, ODR decode,
- Z_RPNQuery *rpn, int num_bases, char **basenames,
- const char *setname);
-RSET resultSetRef (ZebraHandle zh, Z_ResultSetId *resultSetId);
-void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
- int *statuses);
-
-const char *zebra_resultSetTerms (ZebraHandle zh, const char *setname,
- int no, int *count, int *no_max);
-
-ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name,
- int num, int *positions);
-void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num);
-
-void resultSetSort (ZebraHandle zh, NMEM nmem,
- int num_input_setnames, const char **input_setnames,
- const char *output_setname,
- Z_SortKeySpecList *sort_sequence, int *sort_status);
-void resultSetSortSingle (ZebraHandle zh, NMEM nmem,
- ZebraSet sset, RSET rset,
- Z_SortKeySpecList *sort_sequence, int *sort_status);
-void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset);
-void resultSetInvalidate (ZebraHandle zh);
-
-void zebra_sort (ZebraHandle zh, ODR stream,
- int num_input_setnames, const char **input_setnames,
- const char *output_setname, Z_SortKeySpecList *sort_sequence,
- int *sort_status);
-
-int zebra_server_lock_init (ZebraService zh);
-int zebra_server_lock_destroy (ZebraService zh);
-int zebra_server_lock (ZebraService zh, int lockCommit);
-void zebra_server_unlock (ZebraService zh, int commitPhase);
-int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
-
-typedef struct attent
-{
- int attset_ordinal;
- data1_local_attribute *local_attributes;
-} attent;
-
-void zebraRankInstall (ZebraService zh, struct rank_control *ctrl);
-ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
-void zebraRankDestroy (ZebraService zh);
-
-int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att);
-
-extern struct rank_control *rank1_class;
-
-int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
- oid_value input_format, Z_RecordComposition *comp,
- oid_value *output_format, char **rec_bufp,
- int *rec_lenp, char **basenamep);
-
-void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
-void zebra_index_merge (ZebraHandle zh);
-
-
-int extract_rec_in_mem (ZebraHandle zh, const char *recordType,
- const char *buf, size_t buf_size,
- const char *databaseName, int delete_flag,
- int test_mode, int *sysno,
- int store_keys, int store_data,
- const char *match_criteria);
-
-void extract_flushWriteKeys (ZebraHandle zh);
-
-struct zebra_fetch_control {
- off_t offset_end;
- off_t record_offset;
- off_t record_int_pos;
- const char *record_int_buf;
- int record_int_len;
- int fd;
-};
-
-int zebra_record_ext_read (void *fh, char *buf, size_t count);
-off_t zebra_record_ext_seek (void *fh, off_t offset);
-off_t zebra_record_ext_tell (void *fh);
-off_t zebra_record_int_seek (void *fh, off_t offset);
-off_t zebra_record_int_tell (void *fh);
-int zebra_record_int_read (void *fh, char *buf, size_t count);
-void zebra_record_int_end (void *fh, off_t offset);
-
-void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno,
- int cmd, struct recKeys *reckeys);
-void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
- int cmd, struct sortKey **skp);
-void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid);
-void extract_token_add (RecWord *p);
-int explain_extract (void *handle, Record rec, data1_node *n);
-
YAZ_END_CDECL
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: zsets.c,v 1.33 2002-03-20 20:24:30 adam Exp $
+ * $Id: zsets.c,v 1.34 2002-04-04 14:14:13 adam Exp $
*/
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#endif
-#include "zserver.h"
+#include "index.h"
#include <rstemp.h>
#define SORT_IDX_ENTRYSIZE 64
};
ZebraSet resultSetAddRPN (ZebraHandle zh, ODR input, ODR output,
- Z_RPNQuery *rpn, int num_bases, char **basenames,
+ Z_RPNQuery *rpn, int num_bases,
+ char **basenames,
const char *setname)
{
ZebraSet zebraSet;
+ int i;
zh->errCode = 0;
zh->errString = NULL;
return 0;
zebraSet->locked = 1;
zebraSet->rpn = 0;
+ zebraSet->nmem = nmem_create ();
+
zebraSet->num_bases = num_bases;
- zebraSet->basenames = basenames;
- zebraSet->nmem = odr_extract_mem (input);
+ zebraSet->basenames =
+ nmem_malloc (zebraSet->nmem, num_bases * sizeof(*zebraSet->basenames));
+ for (i = 0; i<num_bases; i++)
+ zebraSet->basenames[i] = nmem_strdup (zebraSet->nmem, basenames[i]);
+
zebraSet->rset = rpn_search (zh, output->mem, rpn,
zebraSet->num_bases,
sr = (ZebraPosSet) xmalloc (sizeof(*sr) * num);
for (i = 0; i<num; i++)
{
- struct zebra_set_term_entry *entry = sset->term_entries;
-
sr[i].sysno = 0;
sr[i].score = -1;
sr[i].term = 0;
struct zset_sort_info *sort_info = sset->sort_info;
int i, j;
- sortIdx_sysno (zh->service->sortIdx, sysno);
+ sortIdx_sysno (zh->reg->sortIdx, sysno);
for (i = 0; i<num_criteria; i++)
{
- sortIdx_type (zh->service->sortIdx, criteria[i].attrUse);
- sortIdx_read (zh->service->sortIdx, this_entry.buf[i]);
+ sortIdx_type (zh->reg->sortIdx, criteria[i].attrUse);
+ sortIdx_read (zh->reg->sortIdx, this_entry.buf[i]);
}
i = sort_info->num_entries;
while (--i >= 0)
case Z_SortKey_sortAttributes:
logf (LOG_DEBUG, "Sort: key %d is of type sortAttributes", i+1);
sort_criteria[i].attrUse =
- zebra_maps_sort (zh->service->zebra_maps,
+ zebra_maps_sort (zh->reg->zebra_maps,
sk->u.sortAttributes,
&sort_criteria[i].numerical);
logf (LOG_DEBUG, "use value = %d", sort_criteria[i].attrUse);
zh->errCode = 116;
return;
}
- if (sortIdx_type (zh->service->sortIdx, sort_criteria[i].attrUse))
+ if (sortIdx_type (zh->reg->sortIdx, sort_criteria[i].attrUse))
{
zh->errCode = 207;
return;
int psysno = key.sysno;
int score;
void *handle =
- (*rc->begin) (zh, rank_class->class_handle, rset);
+ (*rc->begin) (zh->reg, rank_class->class_handle, rset);
(zebraSet->hits)++;
do
{
while (rset_read (rset, rfd, &key, &term_index));
score = (*rc->calc) (handle, psysno);
resultSetInsertRank (zh, sort_info, psysno, score, 'A');
- (*rc->end) (zh, handle);
+ (*rc->end) (zh->reg, handle);
}
rset_close (rset, rfd);
ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name)
{
- ZebraRankClass p = zh->service->rank_classes;
+ ZebraRankClass p = zh->reg->rank_classes;
while (p && strcmp (p->control->name, name))
p = p->next;
if (p && !p->init_flag)
{
if (p->control->create)
- p->class_handle = (*p->control->create)(zh->service);
+ p->class_handle = (*p->control->create)(zh->reg);
p->init_flag = 1;
}
return p;
}
-void zebraRankInstall (ZebraService zh, struct rank_control *ctrl)
+void zebraRankInstall (struct zebra_register *reg, struct rank_control *ctrl)
{
ZebraRankClass p = (ZebraRankClass) xmalloc (sizeof(*p));
p->control = (struct rank_control *) xmalloc (sizeof(*p->control));
memcpy (p->control, ctrl, sizeof(*p->control));
p->control->name = xstrdup (ctrl->name);
p->init_flag = 0;
- p->next = zh->rank_classes;
- zh->rank_classes = p;
+ p->next = reg->rank_classes;
+ reg->rank_classes = p;
}
-void zebraRankDestroy (ZebraService zh)
+void zebraRankDestroy (struct zebra_register *reg)
{
- ZebraRankClass p = zh->rank_classes;
+ ZebraRankClass p = reg->rank_classes;
while (p)
{
ZebraRankClass p_next = p->next;
if (p->init_flag && p->control->destroy)
- (*p->control->destroy)(zh, p->class_handle);
+ (*p->control->destroy)(reg, p->class_handle);
xfree (p->control->name);
xfree (p->control);
xfree (p);
p = p_next;
}
- zh->rank_classes = NULL;
+ reg->rank_classes = NULL;
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rsisamc.c,v $
- * Revision 1.9 2002-03-20 20:24:30 adam
+ * Revision 1.10 2002-04-04 14:14:13 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.9 2002/03/20 20:24:30 adam
* Hits per term. Returned in SearchResult-1
*
* Revision 1.8 1999/11/30 13:48:04 adam
info->is = pt->is;
info->pos = pt->pos;
info->key_size = pt->key_size;
- yaz_log (LOG_LOG, "info->key_size = %d\n", info->key_size);
info->cmp = pt->cmp;
info->ispt_list = NULL;
ct->no_rset_terms = 1;
t1_SOURCES = t1.c
t2_SOURCES = t2.c
-CFLAGS = -I$(top_srcdir)/index $(YAZINC)
+CFLAGS = -I$(top_srcdir)/index -I$(top_srcdir)/include $(YAZINC)
LDADD = ../../index/libzebra.a $(YAZLIB) $(TCL_LIB)
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: dirent.c,v $
- * Revision 1.3 1999-02-02 14:51:38 adam
+ * Revision 1.4 2002-04-04 14:14:14 adam
+ * Multiple registers (alpha early)
+ *
+ * Revision 1.3 1999/02/02 14:51:38 adam
* Updated WIN32 code specific sections. Changed header.
*
* Revision 1.2 1997/09/17 12:19:24 adam
}
#endif
+
+int zebra_is_abspath (const char *p)
+{
+ if (*p == '/')
+ return 1;
+#ifdef WIN32
+ if (*p == '\\')
+ return 1;
+ if (*p && p[1] == ':' && isalpha(*p))
+ return 1;
+#endif
+ return 0;
+}
/*
- * Copyright (C) 1994-1999, Index Data
+ * Copyright (C) 1994-2002, Index Data
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Log: res.c,v $
- * Revision 1.28 2000-12-01 17:59:08 adam
- * Fixed bug regarding online updates on WIN32.
- * When zebra.cfg is not available the server will not abort.
- *
- * Revision 1.27 1999/11/30 13:48:04 adam
- * Improved installation. Updated for inclusion of YAZ header files.
- *
- * Revision 1.26 1999/10/07 09:48:36 adam
- * Allow res_get / res_get_def with NULL res.
- *
- * Revision 1.25 1999/05/26 07:49:14 adam
- * C++ compilation.
- *
- * Revision 1.24 1999/02/02 14:51:42 adam
- * Updated WIN32 code specific sections. Changed header.
- *
- * Revision 1.23 1998/10/28 15:18:55 adam
- * Fix for DOS-formatted configuration files.
- *
- * Revision 1.22 1998/01/12 15:04:32 adam
- * Removed exit - call.
- *
- * Revision 1.21 1997/11/18 10:04:03 adam
- * Function res_trav returns number of 'hits'.
- *
- * Revision 1.20 1997/10/31 12:39:15 adam
- * Resouce name can be terminated with either white-space or colon.
- *
- * Revision 1.19 1997/10/27 14:27:59 adam
- * Fixed memory leak.
- *
- * Revision 1.18 1997/09/17 12:19:24 adam
- * Zebra version corresponds to YAZ version 1.4.
- * Changed Zebra server so that it doesn't depend on global common_resource.
- *
- * Revision 1.17 1997/09/09 13:38:19 adam
- * Partial port to WIN95/NT.
- *
- * Revision 1.16 1996/10/29 13:47:49 adam
- * Implemented res_get_match. Updated to use zebrautl instead of alexpath.
- *
- * Revision 1.15 1996/05/22 08:23:43 adam
- * Bug fix: trailing blanks in resource values where not removed.
- *
- * Revision 1.14 1996/04/26 11:51:20 adam
- * Resource names are matched by the yaz_matchstr routine instead of strcmp.
- *
- * Revision 1.13 1995/09/04 12:34:05 adam
- * Various cleanup. YAZ util used instead.
- *
- * Revision 1.12 1995/01/24 16:40:32 adam
- * Bug fix.
- *
- * Revision 1.11 1994/10/05 16:54:52 adam
- * Minor changes.
- *
- * Revision 1.10 1994/10/05 10:47:31 adam
- * Small bug fix.
- *
- * Revision 1.9 1994/09/16 14:41:12 quinn
- * Added log warning to res_get_def
- *
- * Revision 1.8 1994/09/16 14:37:12 quinn
- * added res_get_def
- *
- * Revision 1.7 1994/09/06 13:01:03 quinn
- * Removed const from declaration of res_get
- *
- * Revision 1.6 1994/09/01 17:45:14 adam
- * Work on resource manager.
- *
- * Revision 1.5 1994/08/18 11:02:28 adam
- * Implementation of res_write.
- *
- * Revision 1.4 1994/08/18 10:02:01 adam
- * Module alexpath moved from res.c to alexpath.c. Minor changes in res-test.c
- *
- * Revision 1.3 1994/08/18 09:43:51 adam
- * Development of resource manager. Only missing is res_write.
- *
- * Revision 1.2 1994/08/18 08:23:26 adam
- * Res.c now use handles. xmalloc defines xstrdup.
- *
- * Revision 1.1 1994/08/17 15:34:23 adam
- * Initial version of resource manager.
- *
+ * $Id: res.c,v 1.29 2002-04-04 14:14:14 adam Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <zebrautl.h>
#include <yaz/yaz-util.h>
+struct res_entry {
+ char *name;
+ char *value;
+ struct res_entry *next;
+};
+
+struct res_struct {
+ struct res_entry *first, *last;
+ char *name;
+ int init;
+ Res def_res;
+};
+
static struct res_entry *add_entry (Res r)
{
struct res_entry *resp;
fclose (fr);
}
-Res res_open (const char *name)
+Res res_open (const char *name, Res def_res)
{
Res r;
#ifdef WIN32
#endif
{
logf (LOG_LOG|LOG_ERRNO, "Cannot access resource file `%s'", name);
- return NULL;
+ return 0;
}
r = (Res) xmalloc (sizeof(*r));
r->init = 0;
r->first = r->last = NULL;
r->name = xstrdup (name);
+ r->def_res = def_res;
return r;
}
struct res_entry *re;
if (!r)
- return NULL;
+ return 0;
if (!r->init)
reread (r);
for (re = r->first; re; re=re->next)
if (re->value && !yaz_matchstr (re->name, name))
return re->value;
- return NULL;
+
+ return res_get (r->def_res, name);
}
char *res_get_def (Res r, const char *name, char *def)
(*f)(p, re->name, re->value);
no++;
}
+ if (!no)
+ return res_trav (r->def_res, prefix, p, f);
return no;
}