From: Adam Dickmeiss Date: Thu, 22 Jan 2004 11:27:20 +0000 (+0000) Subject: Revise resource API to take default/override resources. X-Git-Tag: ZEBRA.1.3.16~139 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=2a6f64379961f30bfe6376964ce279ab5242da1f Revise resource API to take default/override resources. Allow Remote insert/delete/replace/update with record, recordIdNumber (sysno) and/or recordIdOpaque(user supplied record Id). Server now returns zero hits rather than issue 'unsupported use attribute' if an attribute is supplied that is defined in .att but not being used. --- diff --git a/dict/dicttest.c b/dict/dicttest.c index a21bb26..85cce13 100644 --- a/dict/dicttest.c +++ b/dict/dicttest.c @@ -1,4 +1,4 @@ -/* $Id: dicttest.c,v 1.27 2002-08-02 19:26:55 adam Exp $ +/* $Id: dicttest.c,v 1.28 2004-01-22 11:27:20 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -160,7 +160,7 @@ int main (int argc, char **argv) logf (LOG_FATAL, "no config and/or dictionary specified"); exit (1); } - my_resource = res_open (config, 0); + my_resource = res_open (config, 0, 0); if (!my_resource) { logf (LOG_FATAL, "cannot open resource `%s'", config); diff --git a/include/res.h b/include/res.h index 9eb90de..4fb3bd7 100644 --- a/include/res.h +++ b/include/res.h @@ -1,5 +1,5 @@ -/* $Id: res.h,v 1.12 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: res.h,v 1.13 2004-01-22 11:27:21 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -29,17 +29,19 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA extern "C" { #endif -typedef struct res_struct *Res; - -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); -int res_get_match (Res r, const char *name, const char *value, const char *s); -void res_put (Res r, const char *name, const char *value); -int res_trav (Res r, const char *prefix, void *p, - void (*f)(void *p, const char *name, const char *value)); -int res_write (Res r); + typedef struct res_struct *Res; + + Res res_open (const char *name, Res res_def, Res over_res); + void res_close (Res r); + const char *res_get (Res r, const char *name); + const char *res_get_def (Res r, const char *name, const char *def); + int res_get_match (Res r, const char *name, const char *value, const char *s); + void res_set (Res r, const char *name, const char *value); + int res_trav (Res r, const char *prefix, void *p, + void (*f)(void *p, const char *name, const char *value)); + int res_write (Res r); + const char *res_get_prefix (Res r, const char *name, const char *prefix, + const char *def); #ifdef __cplusplus } diff --git a/include/rstemp.h b/include/rstemp.h index be4795d..edf1c4b 100644 --- a/include/rstemp.h +++ b/include/rstemp.h @@ -1,4 +1,4 @@ -/* $Id: rstemp.h,v 1.8 2002-08-02 19:26:55 adam Exp $ +/* $Id: rstemp.h,v 1.9 2004-01-22 11:27:21 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -37,7 +37,7 @@ typedef struct rset_temp_parms { int (*cmp)(const void *p1, const void *p2); int key_size; - char *temp_path; + const char *temp_path; RSET_TERM rset_term; } rset_temp_parms; diff --git a/include/zebraapi.h b/include/zebraapi.h index b83f79e..65faace 100644 --- a/include/zebraapi.h +++ b/include/zebraapi.h @@ -1,5 +1,5 @@ -/* $Id: zebraapi.h,v 1.11 2004-01-15 13:31:31 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 +/* $Id: zebraapi.h,v 1.12 2004-01-22 11:27:21 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -32,6 +32,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include +#include #include /* Fixme! Compare string (ignore case) */ @@ -43,21 +44,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 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; - int followLinks; -}; - typedef struct { int processed; int inserted; @@ -96,7 +82,8 @@ typedef struct zebra_service *ZebraService; /* Start Zebra using file 'configName' (usually zebra.cfg) */ /* There should be exactly one ZebraService */ -YAZ_EXPORT ZebraService zebra_start (const char *configName); +YAZ_EXPORT ZebraService zebra_start (const char *configName, + Res def_res, Res over_res); /* Close the whole Zebra */ YAZ_EXPORT int zebra_stop (ZebraService zs); @@ -200,7 +187,6 @@ YAZ_EXPORT int zebra_admin_import_segment (ZebraHandle zh, YAZ_EXPORT int zebra_admin_import_end (ZebraHandle zh); int zebra_admin_exchange_record (ZebraHandle zh, - const char *database, const char *rec_buf, size_t rec_len, const char *recid_buf, size_t recid_len, @@ -215,13 +201,26 @@ int zebra_clean (ZebraHandle zh); int zebra_init (ZebraHandle zh); int zebra_compact (ZebraHandle zh); -int zebra_repository_update (ZebraHandle zh); -int zebra_repository_delete (ZebraHandle zh); -int zebra_repository_show (ZebraHandle zh); -int zebra_record_insert (ZebraHandle zh, const char *buf, int len, int *sysno); - -YAZ_EXPORT int zebra_set_group (ZebraHandle zh, struct recordGroup *rg); - +int zebra_repository_update (ZebraHandle zh, const char *path); +int zebra_repository_delete (ZebraHandle zh, const char *path); +int zebra_repository_show (ZebraHandle zh, const char *path); + +int zebra_add_record (ZebraHandle zh, const char *buf, int buf_size); + +int zebra_insert_record (ZebraHandle zh, + const char *recordType, + int *sysno, const char *match, const char *fname, + const char *buf, int buf_size); +int zebra_update_record (ZebraHandle zh, + const char *recordType, + int* sysno, const char *match, const char *fname, + const char *buf, int buf_size, + int force_update); +int zebra_delete_record (ZebraHandle zh, + const char *recordType, + int *sysno, const char *match, const char *fname, + const char *buf, int buf_size, + int force_update); YAZ_EXPORT int zebra_resultSetTerms (ZebraHandle zh, const char *setname, int no, int *count, diff --git a/index/apitest.c b/index/apitest.c index ddc8c3a..2694eb8 100644 --- a/index/apitest.c +++ b/index/apitest.c @@ -1,4 +1,4 @@ -/* $Id: apitest.c,v 1.14 2003-06-18 11:46:33 adam Exp $ +/* $Id: apitest.c,v 1.15 2004-01-22 11:27:21 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -140,7 +140,7 @@ int main (int argc, char **argv) odr_input = odr_createmem (ODR_DECODE); odr_output = odr_createmem (ODR_ENCODE); - zs = zebra_start ("zebra.cfg"); + zs = zebra_start ("zebra.cfg", 0, 0); if (!zs) { printf ("zebra_start failed; missing zebra.cfg?\n"); diff --git a/index/extract.c b/index/extract.c index 557c2f2..09902fd 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,5 +1,5 @@ -/* $Id: extract.c,v 1.146 2003-10-07 09:18:43 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 +/* $Id: extract.c,v 1.147 2004-01-22 11:27:21 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -259,7 +259,7 @@ static void file_end (void *handle, off_t offset) } static char *fileMatchStr (ZebraHandle zh, - struct recKeys *reckeys, struct recordGroup *rGroup, + struct recKeys *reckeys, const char *fname, const char *spec) { static char dstBuf[2048]; /* static here ??? */ @@ -318,7 +318,7 @@ static char *fileMatchStr (ZebraHandle zh, else { logf (LOG_WARN, "Missing ) in match criteria %s in group %s", - spec, rGroup->groupName ? rGroup->groupName : "none"); + spec, zh->m_group ? zh->m_group : "none"); return NULL; } s++; @@ -358,14 +358,14 @@ static char *fileMatchStr (ZebraHandle zh, s = s1; if (!strcmp (special, "group")) - spec_src = rGroup->groupName; + spec_src = zh->m_group; else if (!strcmp (special, "database")) - spec_src = rGroup->databaseName; + spec_src = zh->basenames[0]; else if (!strcmp (special, "filename")) { spec_src = fname; } else if (!strcmp (special, "type")) - spec_src = rGroup->recordType; + spec_src = zh->m_record_type; else spec_src = NULL; if (spec_src) @@ -394,7 +394,7 @@ static char *fileMatchStr (ZebraHandle zh, else { logf (LOG_WARN, "Syntax error in match criteria %s in group %s", - spec, rGroup->groupName ? rGroup->groupName : "none"); + spec, zh->m_group ? zh->m_group : "none"); return NULL; } *dst++ = 1; @@ -402,7 +402,7 @@ static char *fileMatchStr (ZebraHandle zh, if (dst == dstBuf) { logf (LOG_WARN, "No match criteria for record %s in group %s", - fname, rGroup->groupName ? rGroup->groupName : "none"); + fname, zh->m_group ? zh->m_group : "none"); return NULL; } *dst = '\0'; @@ -415,12 +415,11 @@ struct recordLogInfo { struct recordGroup *rGroup; }; -static int recordExtract (ZebraHandle zh, - SYSNO *sysno, const char *fname, - struct recordGroup *rGroup, int deleteFlag, - struct file_read_info *fi, - RecType recType, char *subType, void *clientData, - int force_update) +static int file_extract_record(ZebraHandle zh, + SYSNO *sysno, const char *fname, + int deleteFlag, + struct file_read_info *fi, + int force_update) { RecordAttr *recordAttr; int r; @@ -428,6 +427,25 @@ static int recordExtract (ZebraHandle zh, SYSNO sysnotmp; Record rec; off_t recordOffset = 0; + RecType recType; + void *clientData; + char subType[128]; + + if (!(recType = + recType_byName (zh->reg->recTypes, zh->m_record_type, subType, + &clientData))) + { + logf (LOG_WARN, "No such record type: %s", zh->m_record_type); + return 0; + } + + /* announce database */ + if (zebraExplain_curDatabase (zh->reg->zei, zh->basenames[0])) + { + if (zebraExplain_newDatabase (zh->reg->zei, zh->basenames[0], + zh->m_explain_database)) + return 0; + } if (fi->fd != -1) { @@ -463,11 +481,11 @@ static int recordExtract (ZebraHandle zh, extractCtrl.seqno[i] = 0; } extractCtrl.zebra_maps = zh->reg->zebra_maps; - extractCtrl.flagShowRecords = !rGroup->flagRw; + extractCtrl.flagShowRecords = !zh->m_flag_rw; - if (!rGroup->flagRw) + if (!zh->m_flag_rw) printf ("File: %s " PRINTF_OFF_T "\n", fname, recordOffset); - if (rGroup->flagRw) + if (zh->m_flag_rw) { char msg[512]; sprintf (msg, "%s:" PRINTF_OFF_T , fname, recordOffset); @@ -482,10 +500,10 @@ static int recordExtract (ZebraHandle zh, else if (r == RECCTRL_EXTRACT_ERROR_GENERIC) { /* error occured during extraction ... */ - if (rGroup->flagRw && - zh->records_processed < rGroup->fileVerboseLimit) + if (zh->m_flag_rw && + zh->records_processed < zh->m_file_verbose_limit) { - logf (LOG_WARN, "fail %s %s " PRINTF_OFF_T, rGroup->recordType, + logf (LOG_WARN, "fail %s %s " PRINTF_OFF_T, zh->m_record_type, fname, recordOffset); } return 0; @@ -493,11 +511,11 @@ static int recordExtract (ZebraHandle zh, else if (r == RECCTRL_EXTRACT_ERROR_NO_SUCH_FILTER) { /* error occured during extraction ... */ - if (rGroup->flagRw && - zh->records_processed < rGroup->fileVerboseLimit) + if (zh->m_flag_rw && + zh->records_processed < zh->m_file_verbose_limit) { logf (LOG_WARN, "no filter for %s %s " - PRINTF_OFF_T, rGroup->recordType, + PRINTF_OFF_T, zh->m_record_type, fname, recordOffset); } return 0; @@ -506,10 +524,10 @@ static int recordExtract (ZebraHandle zh, { /* the extraction process returned no information - the record is probably empty - unless flagShowRecords is in use */ - if (!rGroup->flagRw) + if (!zh->m_flag_rw) return 1; - logf (LOG_WARN, "empty %s %s " PRINTF_OFF_T, rGroup->recordType, + logf (LOG_WARN, "empty %s %s " PRINTF_OFF_T, zh->m_record_type, fname, recordOffset); return 1; } @@ -522,12 +540,12 @@ static int recordExtract (ZebraHandle zh, { sysnotmp = 0; sysno = &sysnotmp; - if (rGroup->recordId && *rGroup->recordId) + if (zh->m_record_id && *zh->m_record_id) { char *rinfo; - matchStr = fileMatchStr (zh, &zh->reg->keys, rGroup, fname, - rGroup->recordId); + matchStr = fileMatchStr (zh, &zh->reg->keys, fname, + zh->m_record_id); if (matchStr) { rinfo = dict_lookup (zh->reg->matchDict, matchStr); @@ -547,13 +565,13 @@ static int recordExtract (ZebraHandle zh, /* new record */ if (deleteFlag) { - logf (LOG_LOG, "delete %s %s " PRINTF_OFF_T, rGroup->recordType, + logf (LOG_LOG, "delete %s %s " PRINTF_OFF_T, zh->m_record_type, fname, recordOffset); logf (LOG_WARN, "cannot delete record above (seems new)"); return 1; } - if (zh->records_processed < rGroup->fileVerboseLimit) - logf (LOG_LOG, "add %s %s " PRINTF_OFF_T, rGroup->recordType, + if (zh->records_processed < zh->m_file_verbose_limit) + logf (LOG_LOG, "add %s %s " PRINTF_OFF_T, zh->m_record_type, fname, recordOffset); rec = rec_new (zh->reg->records); @@ -586,7 +604,7 @@ static int recordExtract (ZebraHandle zh, { yaz_log (LOG_LOG, "run number = %d", recordAttr->runNumber); yaz_log (LOG_LOG, "skipped %s %s " PRINTF_OFF_T, - rGroup->recordType, fname, recordOffset); + zh->m_record_type, fname, recordOffset); extract_flushSortKeys (zh, *sysno, -1, &zh->reg->sortKeys); rec_rm (&rec); logRecord (zh); @@ -606,14 +624,14 @@ static int recordExtract (ZebraHandle zh, if (!delkeys.buf_used) { logf (LOG_LOG, "delete %s %s " PRINTF_OFF_T, - rGroup->recordType, fname, recordOffset); + zh->m_record_type, fname, recordOffset); logf (LOG_WARN, "cannot delete file above, storeKeys false"); } else { - if (zh->records_processed < rGroup->fileVerboseLimit) + if (zh->records_processed < zh->m_file_verbose_limit) logf (LOG_LOG, "delete %s %s " PRINTF_OFF_T, - rGroup->recordType, fname, recordOffset); + zh->m_record_type, fname, recordOffset); zh->records_deleted++; if (matchStr) dict_delete (zh->reg->matchDict, matchStr); @@ -629,14 +647,14 @@ static int recordExtract (ZebraHandle zh, if (!delkeys.buf_used) { logf (LOG_LOG, "update %s %s " PRINTF_OFF_T, - rGroup->recordType, fname, recordOffset); + zh->m_record_type, fname, recordOffset); logf (LOG_WARN, "cannot update file above, storeKeys false"); } else { - if (zh->records_processed < rGroup->fileVerboseLimit) + if (zh->records_processed < zh->m_file_verbose_limit) logf (LOG_LOG, "update %s %s " PRINTF_OFF_T, - rGroup->recordType, fname, recordOffset); + zh->m_record_type, fname, recordOffset); extract_flushSortKeys (zh, *sysno, 1, &zh->reg->sortKeys); extract_flushRecordKeys (zh, *sysno, 1, &zh->reg->keys); zh->records_updated++; @@ -646,7 +664,7 @@ static int recordExtract (ZebraHandle zh, /* update file type */ xfree (rec->info[recInfo_fileType]); rec->info[recInfo_fileType] = - rec_strdup (rGroup->recordType, &rec->size[recInfo_fileType]); + rec_strdup (zh->m_record_type, &rec->size[recInfo_fileType]); /* update filename */ xfree (rec->info[recInfo_filename]); @@ -655,7 +673,7 @@ static int recordExtract (ZebraHandle zh, /* update delete keys */ xfree (rec->info[recInfo_delKeys]); - if (zh->reg->keys.buf_used > 0 && rGroup->flagStoreKeys == 1) + if (zh->reg->keys.buf_used > 0 && zh->m_store_keys == 1) { rec->size[recInfo_delKeys] = zh->reg->keys.buf_used; rec->info[recInfo_delKeys] = zh->reg->keys.buf; @@ -691,7 +709,7 @@ static int recordExtract (ZebraHandle zh, /* update store data */ xfree (rec->info[recInfo_storeData]); - if (rGroup->flagStoreData == 1) + if (zh->m_store_data) { rec->size[recInfo_storeData] = recordAttr->recordSize; rec->info[recInfo_storeData] = (char *) @@ -718,7 +736,7 @@ static int recordExtract (ZebraHandle zh, /* update database name */ xfree (rec->info[recInfo_databaseName]); rec->info[recInfo_databaseName] = - rec_strdup (rGroup->databaseName, &rec->size[recInfo_databaseName]); + rec_strdup (zh->basenames[0], &rec->size[recInfo_databaseName]); /* update offset */ recordAttr->recordOffset = recordOffset; @@ -730,26 +748,19 @@ static int recordExtract (ZebraHandle zh, } int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, - const struct recordGroup *rGroupP, int deleteFlag) + int deleteFlag) { int r, i, fd; char gprefix[128]; char ext[128]; char ext_res[128]; - char subType[128]; - RecType recType; - struct recordGroup rGroupM; - struct recordGroup *rGroup = &rGroupM; struct file_read_info *fi; - void *clientData; - memcpy (rGroup, rGroupP, sizeof(*rGroupP)); - - if (!rGroup->groupName || !*rGroup->groupName) + if (!zh->m_group || !*zh->m_group) *gprefix = '\0'; else - sprintf (gprefix, "%s.", rGroup->groupName); - + sprintf (gprefix, "%s.", zh->m_group); + logf (LOG_DEBUG, "fileExtract %s", fname); /* determine file extension */ @@ -763,98 +774,23 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, break; } /* determine file type - depending on extension */ - if (!rGroup->recordType) + if (!zh->m_record_type) { sprintf (ext_res, "%srecordType.%s", gprefix, ext); - if (!(rGroup->recordType = res_get (zh->res, ext_res))) - { - sprintf (ext_res, "%srecordType", gprefix); - rGroup->recordType = res_get (zh->res, ext_res); - } + zh->m_record_type = res_get (zh->res, ext_res); } - if (!rGroup->recordType) + if (!zh->m_record_type) { - if (zh->records_processed < rGroup->fileVerboseLimit) + if (zh->records_processed < zh->m_file_verbose_limit) logf (LOG_LOG, "? %s", fname); return 0; } - if (!*rGroup->recordType) - return 0; - if (!(recType = - recType_byName (zh->reg->recTypes, rGroup->recordType, subType, - &clientData))) - { - logf (LOG_WARN, "No such record type: %s", rGroup->recordType); - return 0; - } - /* determine match criteria */ - if (!rGroup->recordId) + if (!zh->m_record_id) { sprintf (ext_res, "%srecordId.%s", gprefix, ext); - 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->res, ext_res))) - { - sprintf (ext_res, "%sdatabase", gprefix); - rGroup->databaseName = res_get (zh->res, ext_res); - } - } - if (!rGroup->databaseName) - rGroup->databaseName = "Default"; - - /* determine if explain database */ - - sprintf (ext_res, "%sexplainDatabase", gprefix); - rGroup->explainDatabase = - atoi (res_get_def (zh->res, ext_res, "0")); - - /* announce database */ - if (zebraExplain_curDatabase (zh->reg->zei, rGroup->databaseName)) - { - if (zebraExplain_newDatabase (zh->reg->zei, rGroup->databaseName, - rGroup->explainDatabase)) - return 0; - } - - if (rGroup->flagStoreData == -1) - { - const char *sval; - sprintf (ext_res, "%sstoreData.%s", gprefix, ext); - if (!(sval = res_get (zh->res, ext_res))) - { - sprintf (ext_res, "%sstoreData", gprefix); - sval = res_get (zh->res, ext_res); - } - if (sval) - rGroup->flagStoreData = atoi (sval); + zh->m_record_id = res_get (zh->res, ext_res); } - if (rGroup->flagStoreData == -1) - rGroup->flagStoreData = 0; - - if (rGroup->flagStoreKeys == -1) - { - const char *sval; - - sprintf (ext_res, "%sstoreKeys.%s", gprefix, ext); - sval = res_get (zh->res, ext_res); - if (!sval) - { - sprintf (ext_res, "%sstoreKeys", gprefix); - sval = res_get (zh->res, ext_res); - } - if (!sval) - sval = res_get (zh->res, "storeKeys"); - if (sval) - rGroup->flagStoreKeys = atoi (sval); - } - if (rGroup->flagStoreKeys == -1) - rGroup->flagStoreKeys = 0; if (sysno && deleteFlag) fd = -1; @@ -882,63 +818,30 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, do { file_begin (fi); - r = recordExtract (zh, sysno, fname, rGroup, deleteFlag, fi, - recType, subType, clientData, 1); + r = file_extract_record (zh, sysno, fname, deleteFlag, fi, 1); } while (r && !sysno && fi->file_more); file_read_stop (fi); if (fd != -1) close (fd); return r; } -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) -{ - struct recordGroup rGroup; - rGroup.groupName = NULL; - rGroup.databaseName = (char *)databaseName; - rGroup.path = NULL; - rGroup.recordId = NULL; - rGroup.recordType = (char *)recordType; - rGroup.flagStoreData = store_data; - rGroup.flagStoreKeys = store_keys; - rGroup.flagRw = 1; - rGroup.databaseNamePath = 0; - rGroup.explainDatabase = 0; - rGroup.fileVerboseLimit = 100000; - rGroup.followLinks = -1; - return (bufferExtractRecord (zh, - buf, buf_size, - &rGroup, - delete_flag, - test_mode, - recordType, - sysno, - match_criteria, - "", - 0,1)); -} + /* If sysno is provided, then it's used to identify the reocord. If not, and match_criteria is provided, then sysno is guessed If not, and a record is provided, then sysno is got from there */ -int bufferExtractRecord (ZebraHandle zh, - const char *buf, size_t buf_size, - struct recordGroup *rGroup, - int delete_flag, - int test_mode, - const char *recordType, - int *sysno, - const char *match_criteria, - const char *fname, - int force_update, - int allow_update) - +int buffer_extract_record (ZebraHandle zh, + const char *buf, size_t buf_size, + int delete_flag, + int test_mode, + const char *recordType, + int *sysno, + const char *match_criteria, + const char *fname, + int force_update, + int allow_update) { RecordAttr *recordAttr; struct recExtractCtrl extractCtrl; @@ -950,6 +853,10 @@ int bufferExtractRecord (ZebraHandle zh, Record rec; long recordOffset = 0; struct zebra_fetch_control fc; + const char *pr_fname = fname; /* filename to print .. */ + + if (!pr_fname) + pr_fname = ""; /* make it printable if file is omitted */ fc.fd = -1; fc.record_int_buf = buf; @@ -971,36 +878,30 @@ int bufferExtractRecord (ZebraHandle zh, zh->reg->keys.prevSeqNo = 0; zh->reg->sortKeys.buf_used = 0; - /* announce database */ - - if (!(rGroup->databaseName)) { - logf (LOG_WARN, "Invalid record group, no database name given"); - return 0; - } - - if (zebraExplain_curDatabase (zh->reg->zei, rGroup->databaseName)) + if (zebraExplain_curDatabase (zh->reg->zei, zh->basenames[0])) { - if (zebraExplain_newDatabase (zh->reg->zei, rGroup->databaseName, 0)) + if (zebraExplain_newDatabase (zh->reg->zei, zh->basenames[0], + zh->m_explain_database)) return 0; } - if (*recordType) { + if (recordType && *recordType) { logf (LOG_DEBUG, "Record type explicitly specified: %s", recordType); recType = recType_byName (zh->reg->recTypes, recordType, subType, &clientData); } else { - if (!(rGroup->recordType)) { + if (!(zh->m_record_type)) { logf (LOG_WARN, "No such record type defined"); return 0; } - logf (LOG_DEBUG, "Get record type from rgroup: %s",rGroup->recordType); - recType = recType_byName (zh->reg->recTypes, rGroup->recordType, subType, + logf (LOG_DEBUG, "Get record type from rgroup: %s",zh->m_record_type); + recType = recType_byName (zh->reg->recTypes, zh->m_record_type, subType, &clientData); - recordType = rGroup->recordType; + recordType = zh->m_record_type; } if (!recType) { - logf (LOG_WARN, "No such record type: %s", rGroup->recordType); + logf (LOG_WARN, "No such record type: %s", zh->m_record_type); return 0; } @@ -1049,14 +950,14 @@ int bufferExtractRecord (ZebraHandle zh, /* match criteria */ matchStr = NULL; - if (! *sysno && match_criteria) { + if (! *sysno) { char *rinfo; - if (*match_criteria) { + if (match_criteria && *match_criteria) { matchStr = (char *)match_criteria; } else { - if (rGroup->recordId && *rGroup->recordId) { - matchStr = fileMatchStr (zh, &zh->reg->keys, rGroup, fname, - rGroup->recordId); + if (zh->m_record_id && *zh->m_record_id) { + matchStr = fileMatchStr (zh, &zh->reg->keys, pr_fname, + zh->m_record_id); } } if (matchStr) { @@ -1075,11 +976,11 @@ int bufferExtractRecord (ZebraHandle zh, if (delete_flag) { logf (LOG_LOG, "delete %s %s %ld", recordType, - fname, (long) recordOffset); + pr_fname, (long) recordOffset); logf (LOG_WARN, "cannot delete record above (seems new)"); return 1; } - logf (LOG_LOG, "add %s %s %ld", recordType, fname, + logf (LOG_LOG, "add %s %s %ld", recordType, pr_fname, (long) recordOffset); rec = rec_new (zh->reg->records); @@ -1105,7 +1006,7 @@ int bufferExtractRecord (ZebraHandle zh, if (!allow_update) { logf (LOG_LOG, "skipped %s %s %ld", - recordType, fname, (long) recordOffset); + recordType, pr_fname, (long) recordOffset); logRecord(zh); return -1; } @@ -1114,17 +1015,17 @@ int bufferExtractRecord (ZebraHandle zh, assert (rec); recordAttr = rec_init_attr (zh->reg->zei, rec); - + if (!force_update) { - if (recordAttr->runNumber == - zebraExplain_runNumberIncrement (zh->reg->zei, 0)) + if (recordAttr->runNumber == + zebraExplain_runNumberIncrement (zh->reg->zei, 0)) { - logf (LOG_LOG, "skipped %s %s %ld", recordType, - fname, (long) recordOffset); - extract_flushSortKeys (zh, *sysno, -1, &zh->reg->sortKeys); - rec_rm (&rec); - logRecord(zh); - return 1; + logf (LOG_LOG, "skipped %s %s %ld", recordType, + pr_fname, (long) recordOffset); + extract_flushSortKeys (zh, *sysno, -1, &zh->reg->sortKeys); + rec_rm (&rec); + logRecord(zh); + return 0; } } @@ -1142,13 +1043,13 @@ int bufferExtractRecord (ZebraHandle zh, if (!delkeys.buf_used) { logf (LOG_LOG, "delete %s %s %ld", recordType, - fname, (long) recordOffset); + pr_fname, (long) recordOffset); logf (LOG_WARN, "cannot delete file above, storeKeys false"); } else { logf (LOG_LOG, "delete %s %s %ld", recordType, - fname, (long) recordOffset); + pr_fname, (long) recordOffset); zh->records_deleted++; if (matchStr) dict_delete (zh->reg->matchDict, matchStr); @@ -1156,7 +1057,7 @@ int bufferExtractRecord (ZebraHandle zh, } rec_rm (&rec); logRecord(zh); - return 1; + return 0; } else { @@ -1164,13 +1065,13 @@ int bufferExtractRecord (ZebraHandle zh, if (!delkeys.buf_used) { logf (LOG_LOG, "update %s %s %ld", recordType, - fname, (long) recordOffset); + pr_fname, (long) recordOffset); logf (LOG_WARN, "cannot update file above, storeKeys false"); } else { logf (LOG_LOG, "update %s %s %ld", recordType, - fname, (long) recordOffset); + pr_fname, (long) recordOffset); extract_flushSortKeys (zh, *sysno, 1, &zh->reg->sortKeys); extract_flushRecordKeys (zh, *sysno, 1, &zh->reg->keys); zh->records_updated++; @@ -1189,7 +1090,7 @@ int bufferExtractRecord (ZebraHandle zh, /* update delete keys */ xfree (rec->info[recInfo_delKeys]); - if (zh->reg->keys.buf_used > 0 && rGroup->flagStoreKeys == 1) + if (zh->reg->keys.buf_used > 0 && zh->m_store_keys == 1) { rec->size[recInfo_delKeys] = zh->reg->keys.buf_used; rec->info[recInfo_delKeys] = zh->reg->keys.buf; @@ -1229,28 +1130,12 @@ int bufferExtractRecord (ZebraHandle zh, /* update store data */ xfree (rec->info[recInfo_storeData]); - if (rGroup->flagStoreData == 1) + if (zh->m_store_data) { rec->size[recInfo_storeData] = recordAttr->recordSize; rec->info[recInfo_storeData] = (char *) xmalloc (recordAttr->recordSize); -#if 1 memcpy (rec->info[recInfo_storeData], buf, recordAttr->recordSize); -#else - if (lseek (fi->fd, recordOffset, SEEK_SET) < 0) - { - logf (LOG_ERRNO|LOG_FATAL, "seek to %ld in %s", - (long) recordOffset, fname); - exit (1); - } - if (read (fi->fd, rec->info[recInfo_storeData], recordAttr->recordSize) - < recordAttr->recordSize) - { - logf (LOG_ERRNO|LOG_FATAL, "read %d bytes of %s", - recordAttr->recordSize, fname); - exit (1); - } -#endif } else { @@ -1260,7 +1145,7 @@ int bufferExtractRecord (ZebraHandle zh, /* update database name */ xfree (rec->info[recInfo_databaseName]); rec->info[recInfo_databaseName] = - rec_strdup (rGroup->databaseName, &rec->size[recInfo_databaseName]); + rec_strdup (zh->basenames[0], &rec->size[recInfo_databaseName]); /* update offset */ recordAttr->recordOffset = recordOffset; @@ -1271,8 +1156,6 @@ int bufferExtractRecord (ZebraHandle zh, return 0; } - - int explain_extract (void *handle, Record rec, data1_node *n) { ZebraHandle zh = (ZebraHandle) handle; diff --git a/index/index.h b/index/index.h index efabadf..208ef3b 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $Id: index.h,v 1.102 2003-06-23 15:35:25 adam Exp $ +/* $Id: index.h,v 1.103 2004-01-22 11:27:21 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -98,10 +98,10 @@ struct dir_entry *dir_open (const char *rep, const char *base, void dir_sort (struct dir_entry *e); void dir_free (struct dir_entry **e_p); -void repositoryUpdate (ZebraHandle zh); -void repositoryAdd (ZebraHandle zh); -void repositoryDelete (ZebraHandle zh); -void repositoryShow (ZebraHandle zh); +void repositoryUpdate (ZebraHandle zh, const char *path); +void repositoryAdd (ZebraHandle zh, const char *path); +void repositoryDelete (ZebraHandle zh, const char *path); +void repositoryShow (ZebraHandle zh, const char *path); int key_open (ZebraHandle zh, int mem); int key_close (ZebraHandle zh); @@ -276,7 +276,7 @@ struct zebra_service { struct zebra_register *regs; Zebra_mutex_cond session_lock; Passwd_db passwd_db; - char *path_root; + const char *path_root; }; @@ -285,7 +285,7 @@ struct zebra_session { struct zebra_service *service; struct zebra_register *reg; - char *admin_databaseName; + char *xadmin_databaseName; char **basenames; int num_basenames; @@ -308,7 +308,6 @@ struct zebra_session { struct tms tms1; struct tms tms2; #endif - struct recordGroup rGroup; int shadow_enable; int records_inserted; @@ -319,6 +318,16 @@ struct zebra_session { yaz_iconv_t iconv_to_utf8; yaz_iconv_t iconv_from_utf8; + + int m_follow_links; + const char *m_group; + const char *m_record_id; + const char *m_record_type; + int m_store_data; + int m_store_keys; + int m_explain_database; + int m_flag_rw; + int m_file_verbose_limit; }; struct rank_control { @@ -413,24 +422,26 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no); void zebra_index_merge (ZebraHandle zh); -int bufferExtractRecord (ZebraHandle zh, - const char *buf, size_t buf_size, - struct recordGroup *rGroup, - int delete_flag, - int test_mode, - const char *recordType, - int *sysno, - const char *match_criteria, - const char *fname, - int force_update, - int allow_update); - +int buffer_extract_record (ZebraHandle zh, + const char *buf, size_t buf_size, + int delete_flag, + int test_mode, + const char *recordType, + int *sysno, + const char *match_criteria, + const char *fname, + int force_update, + int allow_update); + +#if 0 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); +#endif + void extract_flushWriteKeys (ZebraHandle zh); struct zebra_fetch_control { @@ -459,7 +470,7 @@ 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); + int deleteFlag); int zebra_begin_read (ZebraHandle zh); int zebra_end_read (ZebraHandle zh); diff --git a/index/kdump.c b/index/kdump.c index 46f4d8d..aab7f45 100644 --- a/index/kdump.c +++ b/index/kdump.c @@ -1,4 +1,4 @@ -/* $Id: kdump.c,v 1.23 2003-05-24 22:35:11 adam Exp $ +/* $Id: kdump.c,v 1.24 2004-01-22 11:27:21 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -125,7 +125,7 @@ int main (int argc, char **argv) } else if (ret == 'c') { - if (!(res = res_open (arg, 0))) + if (!(res = res_open (arg, 0, 0))) { logf(LOG_FATAL, "Failed to open resource file %s", arg); exit (1); @@ -143,7 +143,7 @@ int main (int argc, char **argv) exit (1); } if (!res) - res = res_open ("zebra.cfg", 0); + res = res_open ("zebra.cfg", 0, 0); zm = zebra_maps_open (res, 0); if (!(inf = fopen (key_fname, "r"))) { diff --git a/index/lockutil.c b/index/lockutil.c index 12821b3..2550322 100644 --- a/index/lockutil.c +++ b/index/lockutil.c @@ -1,4 +1,4 @@ -/* $Id: lockutil.c,v 1.17 2002-08-02 19:26:55 adam Exp $ +/* $Id: lockutil.c,v 1.18 2004-01-22 11:27:21 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -116,7 +116,7 @@ void zebra_lock_destroy (ZebraLockHandle h) void zebra_lock_prefix (Res res, char *path) { - char *lock_dir = res_get_def (res, "lockDir", ""); + const char *lock_dir = res_get_def (res, "lockDir", ""); strcpy (path, lock_dir); if (*path && path[strlen(path)-1] != '/') diff --git a/index/main.c b/index/main.c index 881e6a0..59ecac7 100644 --- a/index/main.c +++ b/index/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.109 2004-01-15 14:22:22 adam Exp $ +/* $Id: main.c,v 1.110 2004-01-22 11:27:21 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -56,7 +56,8 @@ int main (int argc, char **argv) char *configName = 0; int nsections = 0; int disableCommit = 0; - char *mem_max = 0; + char *database = "Default"; + Res res = res_open(0, 0, 0); int trans_started=0; #if HAVE_SYS_TIMES_H @@ -67,7 +68,6 @@ int main (int argc, char **argv) #ifndef WIN32 char nbuf[100]; #endif - struct recordGroup rGroupDef; ZebraService zs = 0; ZebraHandle zh = 0; @@ -82,20 +82,6 @@ int main (int argc, char **argv) times(&tms1); gettimeofday(&start_time, 0); #endif - - rGroupDef.groupName = NULL; - rGroupDef.databaseName = NULL; - rGroupDef.path = NULL; - rGroupDef.recordId = NULL; - rGroupDef.recordType = NULL; - rGroupDef.flagStoreData = -1; - rGroupDef.flagStoreKeys = -1; - rGroupDef.flagRw = 1; - rGroupDef.databaseNamePath = 0; - rGroupDef.explainDatabase = 0; - rGroupDef.fileVerboseLimit = 100000; - rGroupDef.followLinks = -1; - prog = *argv; if (argc < 2) { @@ -136,7 +122,7 @@ int main (int argc, char **argv) const char *config = configName ? configName : "zebra.cfg"; logf (LOG_LOG, "Zebra version %s %s", ZEBRAVER, ZEBRADATE); - zs = zebra_start (config); + zs = zebra_start (config, 0, res); if (!zs) { yaz_log (LOG_FATAL, "Cannot read config %s", config); @@ -147,27 +133,12 @@ int main (int argc, char **argv) zebra_shadow_enable (zh, 0); } - if (rGroupDef.databaseName) - { - if (zebra_select_database (zh, rGroupDef.databaseName)) - { - logf(LOG_FATAL, "Could not select database %s errCode=%d", - rGroupDef.databaseName, zebra_errCode(zh) ); - exit (1); - } - } - else - { - if (zebra_select_database (zh, "Default")) - { - logf(LOG_FATAL, "Could not select database Default errCode=%d", - zebra_errCode(zh) ); - exit (1); - } - } - if (mem_max) - zebra_set_resource(zh, "memmax",mem_max); - + if (zebra_select_database (zh, database)) + { + logf(LOG_FATAL, "Could not select database %s errCode=%d", + database, zebra_errCode(zh) ); + exit (1); + } if (!strcmp (arg, "update")) cmd = 'u'; else if (!strcmp (arg, "update1")) @@ -218,8 +189,6 @@ int main (int argc, char **argv) } else { - rGroupDef.path = arg; - zebra_set_group (zh, &rGroupDef); if (!trans_started) { trans_started=1; @@ -229,21 +198,20 @@ int main (int argc, char **argv) switch (cmd) { case 'u': - zebra_repository_update (zh); + zebra_repository_update (zh, arg); break; case 'd': - zebra_repository_delete (zh); + zebra_repository_delete (zh, arg); break; case 's': - logf (LOG_LOG, "dumping %s", rGroupDef.path); - zebra_repository_show (zh); + zebra_repository_show (zh, arg); nsections = 0; break; case 'C': - zebra_create_database(zh, rGroupDef.path); + zebra_create_database(zh, arg); break; case 'D': - zebra_drop_database(zh, rGroupDef.path); + zebra_drop_database(zh, arg); break; default: nsections = 0; @@ -282,23 +250,23 @@ int main (int argc, char **argv) else if (ret == 'l') yaz_log_init_file (arg); else if (ret == 'm') - mem_max = arg; + res_set(res, "memMax", arg); else if (ret == 'd') - rGroupDef.databaseName = arg; + database = arg; else if (ret == 's') - rGroupDef.flagRw = 0; + res_set(res, "openRW", "0"); else if (ret == 'g') - rGroupDef.groupName = arg; + res_set(res, "group", arg); else if (ret == 'f') - rGroupDef.fileVerboseLimit = atoi(arg); + res_set(res, "verboseLimit", arg); else if (ret == 'c') configName = arg; else if (ret == 't') - rGroupDef.recordType = arg; + res_set(res, "recordType", arg); else if (ret == 'n') - disableCommit = 1; + res_set(res, "disableCommit", "1"); else if (ret == 'L') - rGroupDef.followLinks = 0; + res_set(res, "followLinks", "0"); else logf (LOG_WARN, "unknown option '-%s'", arg); } /* while arg */ diff --git a/index/trav.c b/index/trav.c index 08003e4..bfa2a46 100644 --- a/index/trav.c +++ b/index/trav.c @@ -1,5 +1,5 @@ -/* $Id: trav.c,v 1.43 2003-10-20 19:26:05 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 +/* $Id: trav.c,v 1.44 2004-01-22 11:27:21 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -44,14 +44,13 @@ static int repComp (const char *a, const char *b, size_t len) } static void repositoryExtractR (ZebraHandle zh, int deleteFlag, char *rep, - struct recordGroup *rGroup, int level) { struct dir_entry *e; int i; size_t rep_len = strlen (rep); - e = dir_open (rep, zh->path_reg, rGroup->followLinks); + e = dir_open (rep, zh->path_reg, zh->m_follow_links); if (!e) return; yaz_log (LOG_LOG, "dir %s", rep); @@ -66,16 +65,14 @@ static void repositoryExtractR (ZebraHandle zh, int deleteFlag, char *rep, strcpy (rep +rep_len+1, e[i].name); if ((ecp = strrchr (e[i].name, '/'))) *ecp = '\0'; - if (level == 0 && rGroup->databaseNamePath) - rGroup->databaseName = e[i].name; switch (e[i].kind) { case dirs_file: - fileExtract (zh, NULL, rep, rGroup, deleteFlag); + fileExtract (zh, NULL, rep, deleteFlag); break; case dirs_dir: - repositoryExtractR (zh, deleteFlag, rep, rGroup, level+1); + repositoryExtractR (zh, deleteFlag, rep, level+1); break; } } @@ -85,8 +82,7 @@ static void repositoryExtractR (ZebraHandle zh, int deleteFlag, char *rep, static void fileDeleteR (ZebraHandle zh, struct dirs_info *di, struct dirs_entry *dst, - const char *base, char *src, - struct recordGroup *rGroup) + const char *base, char *src) { char tmppath[1024]; size_t src_len = strlen (src); @@ -97,7 +93,7 @@ static void fileDeleteR (ZebraHandle zh, { case dirs_file: sprintf (tmppath, "%s%s", base, dst->path); - fileExtract (zh, &dst->sysno, tmppath, rGroup, 1); + fileExtract (zh, &dst->sysno, tmppath, 1); strcpy (tmppath, dst->path); dst = dirs_read (di); @@ -117,7 +113,6 @@ static void fileDeleteR (ZebraHandle zh, static void fileUpdateR (ZebraHandle zh, struct dirs_info *di, struct dirs_entry *dst, const char *base, char *src, - struct recordGroup *rGroup, int level) { struct dir_entry *e_src; @@ -126,7 +121,7 @@ static void fileUpdateR (ZebraHandle zh, size_t src_len = strlen (src); sprintf (tmppath, "%s%s", base, src); - e_src = dir_open (tmppath, zh->path_reg, rGroup->followLinks); + e_src = dir_open (tmppath, zh->path_reg, zh->m_follow_links); yaz_log (LOG_LOG, "dir %s", tmppath); #if 0 @@ -150,7 +145,7 @@ static void fileUpdateR (ZebraHandle zh, else if (!e_src) { strcpy (src, dst->path); - fileDeleteR (zh, di, dst, base, src, rGroup); + fileDeleteR (zh, di, dst, base, src); return; } else @@ -185,8 +180,6 @@ static void fileUpdateR (ZebraHandle zh, break; yaz_log (LOG_DEBUG, "trav sd=%d", sd); - if (level == 0 && rGroup->databaseNamePath) - rGroup->databaseName = e_src[i_src].name; if (sd == 0) { strcpy (src + src_len, e_src[i_src].name); @@ -197,7 +190,7 @@ static void fileUpdateR (ZebraHandle zh, case dirs_file: if (e_src[i_src].mtime > dst->mtime) { - if (fileExtract (zh, &dst->sysno, tmppath, rGroup, 0)) + if (fileExtract (zh, &dst->sysno, tmppath, 0)) { dirs_add (di, src, dst->sysno, e_src[i_src].mtime); } @@ -207,7 +200,7 @@ static void fileUpdateR (ZebraHandle zh, dst = dirs_read (di); break; case dirs_dir: - fileUpdateR (zh, di, dst, base, src, rGroup, level+1); + fileUpdateR (zh, di, dst, base, src, level+1); dst = dirs_last (di); yaz_log (LOG_DEBUG, "last is %s", dst ? dst->path : "null"); break; @@ -225,11 +218,11 @@ static void fileUpdateR (ZebraHandle zh, switch (e_src[i_src].kind) { case dirs_file: - if (fileExtract (zh, &sysno, tmppath, rGroup, 0)) + if (fileExtract (zh, &sysno, tmppath, 0)) dirs_add (di, src, sysno, e_src[i_src].mtime); break; case dirs_dir: - fileUpdateR (zh, di, dst, base, src, rGroup, level+1); + fileUpdateR (zh, di, dst, base, src, level+1); if (dst) dst = dirs_last (di); break; @@ -244,12 +237,12 @@ static void fileUpdateR (ZebraHandle zh, switch (dst->kind) { case dirs_file: - fileExtract (zh, &dst->sysno, tmppath, rGroup, 1); + fileExtract (zh, &dst->sysno, tmppath, 1); dirs_del (di, dst->path); dst = dirs_read (di); break; case dirs_dir: - fileDeleteR (zh, di, dst, base, src, rGroup); + fileDeleteR (zh, di, dst, base, src); dst = dirs_last (di); } } @@ -257,51 +250,22 @@ static void fileUpdateR (ZebraHandle zh, dir_free (&e_src); } -static void groupRes (ZebraHandle zh, struct recordGroup *rGroup) +void repositoryShow (ZebraHandle zh, const char *path) { - char resStr[256]; - char gPrefix[256]; - - if (!rGroup->groupName || !*rGroup->groupName) - *gPrefix = '\0'; - else - sprintf (gPrefix, "%s.", rGroup->groupName); - - sprintf (resStr, "%srecordId", gPrefix); - rGroup->recordId = res_get (zh->res, resStr); - sprintf (resStr, "%sdatabasePath", gPrefix); - rGroup->databaseNamePath = - atoi (res_get_def (zh->res, resStr, "0")); - - rGroup->databaseNamePath = - atoi (res_get_def (zh->res, resStr, "0")); - - if (rGroup->followLinks == -1) - { - sprintf (resStr, "%sfollowLinks", gPrefix); - rGroup->followLinks = - atoi (res_get_def (zh->res, resStr, "1")); - } -} - -void repositoryShow (ZebraHandle zh) - -{ - struct recordGroup *rGroup = &zh->rGroup; char src[1024]; int src_len; struct dirs_entry *dst; Dict dict; struct dirs_info *di; - + if (!(dict = dict_open (zh->reg->bfs, FMATCH_DICT, 50, 0, 0))) { yaz_log (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT); return; } - assert (rGroup->path); - strcpy (src, rGroup->path); + strncpy(src, path, sizeof(src)-1); + src[sizeof(src)-1]='\0'; src_len = strlen (src); if (src_len && src[src_len-1] != '/') @@ -310,7 +274,7 @@ void repositoryShow (ZebraHandle zh) src[++src_len] = '\0'; } - di = dirs_open (dict, src, rGroup->flagRw); + di = dirs_open (dict, src, zh->m_flag_rw); while ( (dst = dirs_read (di)) ) yaz_log (LOG_LOG, "%s", dst->path); @@ -318,9 +282,7 @@ void repositoryShow (ZebraHandle zh) dict_close (dict); } -static void fileUpdate (ZebraHandle zh, - Dict dict, struct recordGroup *rGroup, - const char *path) +static void fileUpdate (ZebraHandle zh, Dict dict, const char *path) { struct dirs_info *di; struct stat sbuf; @@ -338,7 +300,7 @@ static void fileUpdate (ZebraHandle zh, else *src = '\0'; strcat (src, path); - ret = zebra_file_stat (src, &sbuf, rGroup->followLinks); + ret = zebra_file_stat (src, &sbuf, zh->m_follow_links); strcpy (src, path); src_len = strlen (src); @@ -356,13 +318,13 @@ static void fileUpdate (ZebraHandle zh, if (e_dst) { if (sbuf.st_mtime > e_dst->mtime) - if (fileExtract (zh, &e_dst->sysno, src, rGroup, 0)) + if (fileExtract (zh, &e_dst->sysno, src, 0)) dirs_add (di, src, e_dst->sysno, sbuf.st_mtime); } else { SYSNO sysno = 0; - if (fileExtract (zh, &sysno, src, rGroup, 0)) + if (fileExtract (zh, &sysno, src, 0)) dirs_add (di, src, sysno, sbuf.st_mtime); } dirs_free (&di); @@ -374,9 +336,9 @@ static void fileUpdate (ZebraHandle zh, src[src_len] = '/'; src[++src_len] = '\0'; } - di = dirs_open (dict, src, rGroup->flagRw); + di = dirs_open (dict, src, zh->m_flag_rw); *dst = '\0'; - fileUpdateR (zh, di, dirs_read (di), src, dst, rGroup, 0); + fileUpdateR (zh, di, dirs_read (di), src, dst, 0); dirs_free (&di); } else @@ -386,8 +348,7 @@ static void fileUpdate (ZebraHandle zh, } static void repositoryExtract (ZebraHandle zh, - int deleteFlag, struct recordGroup *rGroup, - const char *path) + int deleteFlag, const char *path) { struct stat sbuf; char src[1024]; @@ -403,67 +364,63 @@ static void repositoryExtract (ZebraHandle zh, else *src = '\0'; strcat (src, path); - ret = zebra_file_stat (src, &sbuf, rGroup->followLinks); + ret = zebra_file_stat (src, &sbuf, zh->m_follow_links); strcpy (src, path); if (ret == -1) yaz_log (LOG_WARN|LOG_ERRNO, "Cannot access path %s", src); else if (S_ISREG(sbuf.st_mode)) - fileExtract (zh, NULL, src, rGroup, deleteFlag); + fileExtract (zh, NULL, src, deleteFlag); else if (S_ISDIR(sbuf.st_mode)) - repositoryExtractR (zh, deleteFlag, src, rGroup, 0); + repositoryExtractR (zh, deleteFlag, src, 0); else yaz_log (LOG_WARN, "Skipping path %s", src); } -static void repositoryExtractG (ZebraHandle zh, - int deleteFlag, struct recordGroup *rGroup) +static void repositoryExtractG (ZebraHandle zh, const char *path, + int deleteFlag) { - if (*rGroup->path == '\0' || !strcmp(rGroup->path, "-")) + if (!strcmp(path, "") || !strcmp(path, "-")) { char src[1024]; - + while (scanf ("%1020s", src) == 1) - repositoryExtract (zh, deleteFlag, rGroup, src); + repositoryExtract (zh, deleteFlag, src); } else - repositoryExtract (zh, deleteFlag, rGroup, rGroup->path); + repositoryExtract (zh, deleteFlag, path); } -void repositoryUpdate (ZebraHandle zh) +void repositoryUpdate (ZebraHandle zh, const char *path) { - struct recordGroup *rGroup = &zh->rGroup; - groupRes (zh, rGroup); - assert (rGroup->path); - if (rGroup->recordId && !strcmp (rGroup->recordId, "file")) + assert (path); + if (zh->m_record_id && !strcmp (zh->m_record_id, "file")) { Dict dict; if (!(dict = dict_open (zh->reg->bfs, FMATCH_DICT, 50, - rGroup->flagRw, 0))) + zh->m_flag_rw, 0))) { yaz_log (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT); return ; } - if (*rGroup->path == '\0' || !strcmp(rGroup->path, "-")) + if (!strcmp(path, "") || !strcmp(path, "-")) { char src[1024]; while (scanf ("%s", src) == 1) - fileUpdate (zh, dict, rGroup, src); + fileUpdate (zh, dict, src); } else - fileUpdate (zh, dict, rGroup, rGroup->path); + fileUpdate (zh, dict, path); dict_close (dict); } else - repositoryExtractG (zh, 0, rGroup); + repositoryExtractG (zh, path, 0); } -void repositoryDelete (ZebraHandle zh) +void repositoryDelete (ZebraHandle zh, const char *path) { - struct recordGroup *rGroup = &zh->rGroup; - groupRes (zh, rGroup); - assert (rGroup->path); - repositoryExtractG (zh, 1, rGroup); + assert (path); + repositoryExtractG (zh, path, 1); } diff --git a/index/zebraapi.c b/index/zebraapi.c index f90d3f9..e4ea555 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,5 +1,5 @@ -/* $Id: zebraapi.c,v 1.115 2003-11-28 14:47:45 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 +/* $Id: zebraapi.c,v 1.116 2004-01-22 11:27:21 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -120,8 +120,6 @@ ZebraHandle zebra_open (ZebraService zs) zh->lock_normal = 0; zh->lock_shadow = 0; - zh->admin_databaseName = 0; - zh->shadow_enable = 1; default_encoding = res_get_def(zs->global_res, "encoding", "ISO-8859-1"); @@ -148,13 +146,13 @@ ZebraHandle zebra_open (ZebraService zs) return zh; } -ZebraService zebra_start (const char *configName) +ZebraService zebra_start (const char *configName, Res def_res, Res over_res) { Res res; yaz_log(LOG_API|LOG_LOG,"zebra_start %s",configName); - if ((res = res_open (configName, 0))) + if ((res = res_open (configName, def_res, over_res))) { ZebraService zh = xmalloc (sizeof(*zh)); @@ -198,7 +196,9 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, { struct zebra_register *reg; int record_compression = REC_COMPRESS_NONE; - char *recordCompression = 0; + const char *recordCompression = 0; + const char *profilePath; + char cwd[1024]; ASSERTZS; @@ -226,8 +226,12 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, } if (useshadow) bf_cache (reg->bfs, res_get (res, "shadow")); - data1_set_tabpath (reg->dh, res_get_def(res, "profilePath", - DEFAULT_PROFILE_PATH)); + + getcwd(cwd, sizeof(cwd)-1); + profilePath = res_get_def(res, "profilePath", DEFAULT_PROFILE_PATH); + yaz_log(LOG_LOG, "profilePath=%s cwd=%s", profilePath, cwd); + + data1_set_tabpath (reg->dh, profilePath); data1_set_tabroot (reg->dh, reg_path); reg->recTypes = recTypes_init (reg->dh); recTypes_default_handlers (reg->recTypes); @@ -452,7 +456,6 @@ int zebra_stop(ZebraService zs) res_close (zs->global_res); xfree (zs->configName); - xfree (zs->path_root); xfree (zs); return 0; } @@ -488,7 +491,6 @@ int zebra_close (ZebraHandle zh) if (zh->iconv_from_utf8 != 0) yaz_iconv_close (zh->iconv_from_utf8); - xfree (zh->admin_databaseName); zebra_mutex_cond_lock (&zs->session_lock); zebra_lock_destroy (zh->lock_normal); zebra_lock_destroy (zh->lock_shadow); @@ -506,6 +508,7 @@ int zebra_close (ZebraHandle zh) zebra_mutex_cond_unlock (&zs->session_lock); xfree (zh->reg_name); zh->service=0; /* more likely to trigger an assert */ + xfree (zh->path_reg); xfree (zh); return 0; } @@ -530,7 +533,7 @@ static Res zebra_open_res (ZebraHandle zh) if (zh->path_reg) { sprintf (fname, "%.200s/zebra.cfg", zh->path_reg); - res = res_open (fname, zh->service->global_res); + res = res_open (fname, zh->service->global_res, 0); if (!res) res = zh->service->global_res; } @@ -608,7 +611,7 @@ static int zebra_select_register (ZebraHandle zh, const char *new_reg) const char *lock_area =res_get (zh->res, "lockDir"); if (!lock_area && zh->path_reg) - res_put (zh->res, "lockDir", zh->path_reg); + res_set (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); @@ -995,8 +998,6 @@ int zebra_admin_import_begin (ZebraHandle zh, const char *database, if (zebra_select_database(zh, database)) return 1; zebra_begin_trans (zh, 1); - xfree (zh->admin_databaseName); - zh->admin_databaseName = xstrdup(database); return 0; } @@ -1019,10 +1020,7 @@ int zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment) for (i = 0; inum_segmentRecords; i++) { Z_NamePlusRecord *npr = segment->segmentRecords[i]; - const char *databaseName = npr->databaseName; - if (!databaseName) - databaseName = zh->admin_databaseName; printf ("--------------%d--------------------\n", i); if (npr->which == Z_NamePlusRecord_intermediateFragment) { @@ -1034,15 +1032,14 @@ int zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment) oct->buf); sysno = 0; - extract_rec_in_mem (zh, "grs.sgml", + + zebra_update_record(zh, + 0, /* record Type */ + &sysno, + 0, /* match */ + 0, /* fname */ oct->buf, oct->len, - databaseName, - 0 /* delete_flag */, - 0 /* test_mode */, - &sysno /* sysno */, - 1 /* store_keys */, - 1 /* store_data */, - 0 /* match criteria */); + 0); } } } @@ -1050,18 +1047,20 @@ int zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment) } int zebra_admin_exchange_record (ZebraHandle zh, - const char *database, const char *rec_buf, size_t rec_len, const char *recid_buf, size_t recid_len, int action) + /* 1 = insert. Fail it already exists */ + /* 2 = replace. Fail it does not exist */ + /* 3 = delete. Fail if does not exist */ + /* 4 = update. Insert/replace */ { int sysno = 0; char *rinfo = 0; char recid_z[256]; ASSERTZH; - yaz_log(LOG_API,"zebra_admin_exchange_record db=%s ac=%d", - database, action); + yaz_log(LOG_API,"zebra_admin_exchange_record ac=%d", action); zh->errCode=0; if (!recid_buf || recid_len <= 0 || recid_len >= sizeof(recid_z)) @@ -1089,10 +1088,18 @@ int zebra_admin_exchange_record (ZebraHandle zh, zebra_end_trans(zh); return -1; } - } - extract_rec_in_mem (zh, "grs.sgml", rec_buf, rec_len, database, - action == 3 ? 1 : 0 /* delete flag */, - 0, &sysno, 1, 1, 0); + action = 1; /* make it an insert (if it's an update).. */ + } + buffer_extract_record (zh, rec_buf, rec_len, + action == 3 ? 1 : 0 /* delete flag */, + 0, /* test mode */ + 0, /* recordType */ + &sysno, + 0, /* match */ + 0, /* fname */ + 0, /* force update */ + 1 /* allow update */ + ); if (action == 1) { dict_insert (zh->reg->matchDict, recid_z, sizeof(sysno), &sysno); @@ -1262,6 +1269,34 @@ int zebra_end_read (ZebraHandle zh) return zebra_end_trans(zh); } +static void read_res_for_transaction(ZebraHandle zh) +{ + const char *group = res_get(zh->res, "group"); + const char *v; + + zh->m_group = group; + v = res_get_prefix(zh->res, "followLinks", group, "1"); + zh->m_follow_links = atoi(v); + + zh->m_record_id = res_get_prefix(zh->res, "recordId", group, 0); + zh->m_record_type = res_get_prefix(zh->res, "recordType", group, 0); + + v = res_get_prefix(zh->res, "storeKeys", group, "1"); + zh->m_store_keys = atoi(v); + + v = res_get_prefix(zh->res, "storeData", group, "1"); + zh->m_store_data = atoi(v); + + v = res_get_prefix(zh->res, "explainDatabase", group, "0"); + zh->m_explain_database = atoi(v); + + v = res_get_prefix(zh->res, "openRW", group, "1"); + zh->m_flag_rw = atoi(v); + + v = res_get_prefix(zh->res, "fileVerboseLimit", group, "100000"); + zh->m_file_verbose_limit = atoi(v); +} + int zebra_begin_trans (ZebraHandle zh, int rw) { if (!zh->res) @@ -1452,6 +1487,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw) zh->reg->last_val = val; zh->reg->seqno = seqno; } + read_res_for_transaction(zh); return 0; } @@ -1549,30 +1585,30 @@ int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status) return 0; } -int zebra_repository_update (ZebraHandle zh) +int zebra_repository_update (ZebraHandle zh, const char *path) { ASSERTZH; zh->errCode=0; - logf (LOG_LOG|LOG_API, "updating %s", zh->rGroup.path); - repositoryUpdate (zh); + logf (LOG_LOG|LOG_API, "updating %s", path); + repositoryUpdate (zh, path); return zh->errCode; } -int zebra_repository_delete (ZebraHandle zh) +int zebra_repository_delete (ZebraHandle zh, const char *path) { ASSERTZH; zh->errCode=0; - logf (LOG_LOG|LOG_API, "deleting %s", zh->rGroup.path); - repositoryDelete (zh); + logf (LOG_LOG|LOG_API, "deleting %s", path); + repositoryDelete (zh, path); return zh->errCode; } -int zebra_repository_show (ZebraHandle zh) +int zebra_repository_show (ZebraHandle zh, const char *path) { ASSERTZH; yaz_log(LOG_API,"zebra_repository_show"); zh->errCode=0; - repositoryShow (zh); + repositoryShow (zh, path); return zh->errCode; } @@ -1692,41 +1728,6 @@ int zebra_compact (ZebraHandle zh) return 0; } -int zebra_record_insert (ZebraHandle zh, const char *buf, int len, int *sysno) -{ - int sysn=0; - ASSERTZH; - yaz_log(LOG_API,"zebra_record_insert"); - if (sysno) - *sysno=0; - zh->errCode=0; - if (zebra_begin_trans (zh, 1)) - return -1; - extract_rec_in_mem (zh, "grs.sgml", - buf, len, - "Default", /* database */ - 0 /* delete_flag */, - 0 /* test_mode */, - &sysn /* sysno */, - 1 /* store_keys */, - 1 /* store_data */, - 0 /* match criteria */); - if (zebra_end_trans (zh)) - return -1; - if (sysno) - *sysno=sysn; - return 0; -} - -int zebra_set_group (ZebraHandle zh, struct recordGroup *rg) -{ - ASSERTZH; - yaz_log(LOG_API,"zebra_set_group"); - zh->errCode=0; - memcpy (&zh->rGroup, rg, sizeof(*rg)); - return 0; -} - int zebra_result (ZebraHandle zh, int *code, char **addinfo) { ASSERTZH; @@ -1783,7 +1784,7 @@ int zebra_set_resource(ZebraHandle zh, const char *name, const char *value) ASSERTZH; yaz_log(LOG_API,"zebra_set_resource %s:%s",name,value); zh->errCode=0; - res_put(zh->res, name, value); + res_set(zh->res, name, value); return 0; } @@ -1821,112 +1822,6 @@ int zebra_set_shadow_enable (ZebraHandle zh, int value) return 0; } -int init_recordGroup (struct recordGroup *rg) -{ - assert(rg); - yaz_log(LOG_API,"init_recordGroup"); - rg->groupName = NULL; - rg->databaseName = NULL; - rg->path = NULL; - rg->recordId = NULL; - rg->recordType = NULL; - rg->flagStoreData = -1; - rg->flagStoreKeys = -1; - rg->flagRw = 1; - rg->databaseNamePath = 0; - rg->explainDatabase = 0; - rg->fileVerboseLimit = 100000; - rg->followLinks = -1; - return 0; -} - - -/* This is from extract.c... it seems useful, when extract_rec_in mem is - called... and in general... Should be moved to somewhere else */ -void res_get_recordGroup (ZebraHandle zh, - struct recordGroup *rGroup, - const char *ext) -{ - char gprefix[128]; - char ext_res[128]; - - yaz_log(LOG_API,"res_get_recordGroup e=%s",ext); - if (!rGroup->groupName || !*rGroup->groupName) - *gprefix = '\0'; - else - sprintf (gprefix, "%s.", rGroup->groupName); - - /* determine file type - depending on extension */ - if (!rGroup->recordType) { - sprintf (ext_res, "%srecordType.%s", gprefix, ext); - if (!(rGroup->recordType = res_get (zh->res, ext_res))) { - sprintf (ext_res, "%srecordType", gprefix); - rGroup->recordType = res_get (zh->res, ext_res); - } - } - /* determine match criteria */ - if (!rGroup->recordId) { - sprintf (ext_res, "%srecordId.%s", gprefix, ext); - if (!(rGroup->recordId = res_get (zh->res, ext_res))) { - sprintf (ext_res, "%srecordId", gprefix); - 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->res, ext_res))) { - sprintf (ext_res, "%sdatabase", gprefix); - rGroup->databaseName = res_get (zh->res, ext_res); - } - } - if (!rGroup->databaseName) - rGroup->databaseName = "Default"; - - /* determine if explain database */ - sprintf (ext_res, "%sexplainDatabase", gprefix); - rGroup->explainDatabase = - atoi (res_get_def (zh->res, ext_res, "0")); - - /* storeData */ - if (rGroup->flagStoreData == -1) - { - const char *sval; - sprintf (ext_res, "%sstoreData.%s", gprefix, ext); - if (!(sval = res_get (zh->res, ext_res))) - { - sprintf (ext_res, "%sstoreData", gprefix); - sval = res_get (zh->res, ext_res); - } - if (sval) - rGroup->flagStoreData = atoi (sval); - } - if (rGroup->flagStoreData == -1) - rGroup->flagStoreData = 0; - - /* storeKeys */ - if (rGroup->flagStoreKeys == -1) - { - const char *sval; - - sprintf (ext_res, "%sstoreKeys.%s", gprefix, ext); - sval = res_get (zh->res, ext_res); - if (!sval) - { - sprintf (ext_res, "%sstoreKeys", gprefix); - sval = res_get (zh->res, ext_res); - } - if (!sval) - sval = res_get (zh->res, "storeKeys"); - if (sval) - rGroup->flagStoreKeys = atoi (sval); - } - if (rGroup->flagStoreKeys == -1) - rGroup->flagStoreKeys = 0; -} - - /* almost the same as zebra_records_retrieve ... but how did it work? I mean for multiple records ??? CHECK ??? */ void api_records_retrieve (ZebraHandle zh, ODR stream, @@ -2012,20 +1907,24 @@ void api_records_retrieve (ZebraHandle zh, ODR stream, /* --------------------------------------------------------------------------- Record insert(=update), delete - If sysno is provided, then it's used to identify the reocord. + If sysno is provided, then it's used to identify the record. If not, and match_criteria is provided, then sysno is guessed If not, and a record is provided, then sysno is got from there NOTE: Now returns 0 at success and updates sysno, which is an int* 20-jun-2003 Heikki */ +int zebra_add_record(ZebraHandle zh, + const char *buf, int buf_size) +{ + int sysno = 0; + return zebra_update_record(zh, 0, &sysno, 0, 0, buf, buf_size, 0); +} + int zebra_insert_record (ZebraHandle zh, - struct recordGroup *rGroup, const char *recordType, int *sysno, const char *match, const char *fname, - const char *buf, int buf_size, - int force_update) /* This one is ignored */ - + const char *buf, int buf_size) { int res; yaz_log(LOG_API,"zebra_insert_record sysno=%d", *sysno); @@ -2033,21 +1932,19 @@ int zebra_insert_record (ZebraHandle zh, if (buf_size < 1) buf_size = strlen(buf); zebra_begin_trans(zh, 1); - res=bufferExtractRecord (zh, buf, buf_size, rGroup, - 0, /* delete_flag */ - 0, /* test_mode */ - recordType, - sysno, - match, fname, - force_update, - 0); /* allow_update */ + res = buffer_extract_record (zh, buf, buf_size, + 0, /* delete_flag */ + 0, /* test_mode */ + recordType, + sysno, + match, fname, + 0, + 0); /* allow_update */ zebra_end_trans(zh); - if (res < 0) return (res); return res; } int zebra_update_record (ZebraHandle zh, - struct recordGroup *rGroup, const char *recordType, int* sysno, const char *match, const char *fname, const char *buf, int buf_size, @@ -2060,20 +1957,19 @@ int zebra_update_record (ZebraHandle zh, if (buf_size < 1) buf_size = strlen(buf); zebra_begin_trans(zh, 1); - res=bufferExtractRecord (zh, buf, buf_size, rGroup, - 0, /* delete_flag */ - 0, /* test_mode */ - recordType, - sysno, - match, fname, - force_update, - 1); /* allow_update */ + res = buffer_extract_record (zh, buf, buf_size, + 0, /* delete_flag */ + 0, /* test_mode */ + recordType, + sysno, + match, fname, + force_update, + 1); /* allow_update */ zebra_end_trans(zh); return res; } int zebra_delete_record (ZebraHandle zh, - struct recordGroup *rGroup, const char *recordType, int *sysno, const char *match, const char *fname, const char *buf, int buf_size, @@ -2085,14 +1981,14 @@ int zebra_delete_record (ZebraHandle zh, if (buf_size < 1) buf_size = strlen(buf); zebra_begin_trans(zh, 1); - res=bufferExtractRecord (zh, buf, buf_size, rGroup, - 1, /* delete_flag */ - 0, /* test_mode */ - recordType, - sysno, - match,fname, - force_update, - 1); /* allow_update */ + res = buffer_extract_record (zh, buf, buf_size, + 1, /* delete_flag */ + 0, /* test_mode */ + recordType, + sysno, + match,fname, + force_update, + 1); /* allow_update */ zebra_end_trans(zh); return res; } diff --git a/index/zebrash.c b/index/zebrash.c index f29ff8a..51a09cd 100644 --- a/index/zebrash.c +++ b/index/zebrash.c @@ -1,5 +1,5 @@ -/* $Id: zebrash.c,v 1.24 2003-12-04 11:20:39 heikki Exp $ - Copyright (C) 2002,2003 +/* $Id: zebrash.c,v 1.25 2004-01-22 11:27:21 adam Exp $ + Copyright (C) 2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -163,7 +163,7 @@ static int cmd_zebra_start( char *args[], WRBUF outbuff) DEFAULTCONFIG "\n" ); conf=DEFAULTCONFIG; } - zs=zebra_start(conf); + zs=zebra_start(conf, 0, 0); if (!zs) { wrbuf_puts(outbuff, "zebra_start failed" ); return 2; @@ -348,7 +348,13 @@ static int cmd_record_insert( char *args[], WRBUF outbuff) int rc; char *rec=restargs(args,1); - rc=zebra_record_insert(zh,rec, strlen(rec), &sysno); + rc = zebra_insert_record(zh, + 0, /* record type */ + &sysno, + 0, /* match */ + 0, /* fname */ + rec, + strlen(rec)); if (0==rc) { wrbuf_printf(outbuff,"ok sysno=%d\n",sysno); @@ -359,18 +365,17 @@ static int cmd_record_insert( char *args[], WRBUF outbuff) static int cmd_exchange_record( char *args[], WRBUF outbuff) { - char *base=args[1]; - char *id = args[2]; - char *action = args[3]; + char *id = args[1]; + char *action = args[2]; int rc; - char *rec=restargs(args,4); - if (!(base && id && action && args[4] )) + char *rec=restargs(args,3); + if (!(id && action && args[4] )) { wrbuf_puts(outbuff,"Missing arguments!\n"); onecommand("help exchange_record", outbuff, ""); return -90; } - rc=zebra_admin_exchange_record(zh, base, rec, strlen(rec), + rc=zebra_admin_exchange_record(zh, rec, strlen(rec), id, strlen(id), atoi(action)); return rc; } diff --git a/index/zrpn.c b/index/zrpn.c index f09278d..99da03b 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -1,4 +1,4 @@ -/* $Id: zrpn.c,v 1.135 2004-01-15 13:31:31 adam Exp $ +/* $Id: zrpn.c,v 1.136 2004-01-22 11:27:21 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -966,7 +966,7 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, { /* set was found, but value wasn't defined */ char val_str[32]; - sprintf (val_str, "%d", use_value); + sprintf (val_str, "%d 1", use_value); errCode = 114; errString = nmem_strdup (stream, val_str); } @@ -1011,10 +1011,14 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, } if (!prefix_len) { +#if 1 + bases_ok++; +#else char val_str[32]; - sprintf (val_str, "%d", use_value); + sprintf (val_str, "%d 2", use_value); errCode = 114; errString = nmem_strdup (stream, val_str); +#endif continue; } bases_ok++; /* this has OK attributes */ diff --git a/index/zserver.c b/index/zserver.c index 5578959..b0f2be7 100644 --- a/index/zserver.c +++ b/index/zserver.c @@ -1,5 +1,5 @@ -/* $Id: zserver.c,v 1.112 2003-11-09 11:48:16 oleg Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 +/* $Id: zserver.c,v 1.113 2004-01-22 11:27:21 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -527,22 +527,21 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr) { Z_External *rec = notToKeep->elements[i]->record; struct oident *oident = 0; - Odr_oct *recid = notToKeep->elements[i]->u.opaque; + Odr_oct *opaque_recid = 0; + int sysno = 0; - if (!recid) - { - rr->errcode = 224; - rr->errstring = "record Id not supplied"; - break; - } - if (notToKeep->elements[i]->which != - Z_IUSuppliedRecords_elem_opaque) - { - rr->errcode = 224; - rr->errstring = "only opaque record ID supported"; - break; + if (notToKeep->elements[i]->u.opaque) + { + switch(notToKeep->elements[i]->which) + { + case Z_IUSuppliedRecords_elem_opaque: + opaque_recid = notToKeep->elements[i]->u.opaque; + break; /* OK, recid already set */ + case Z_IUSuppliedRecords_elem_number: + sysno = *notToKeep->elements[i]->u.number; + break; + } } - if (rec->direct_reference) { oident = oid_getentbyoid(rec->direct_reference); @@ -593,7 +592,7 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr) action = 3; if (*toKeep->action == Z_IUOriginPartToKeep_specialUpdate) - action = 1; + action = 4; if (!action) { @@ -601,31 +600,75 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr) rr->errstring = "unsupported ES Update action"; break; } - else - { + else if (opaque_recid) + { int r = zebra_admin_exchange_record ( - zh, toKeep->databaseName, + zh, rec->u.octet_aligned->buf, rec->u.octet_aligned->len, - recid->buf, recid->len, + opaque_recid->buf, opaque_recid->len, action); - if (r && *toKeep->action == - Z_IUOriginPartToKeep_specialUpdate) - { - r = zebra_admin_exchange_record ( - zh, toKeep->databaseName, - rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - recid->buf, recid->len, - 2); - } if (r) { rr->errcode = 224; rr->errstring = "record exchange failed"; break; } - } + } + else + { + int r = -1; + switch(action) { + case 1: + r = zebra_insert_record( + zh, + 0, /* recordType */ + &sysno, + 0, /* match */ + 0, /* fname */ + rec->u.octet_aligned->buf, + rec->u.octet_aligned->len); + if (r) + { + rr->errcode = 224; + rr->errstring = "insert_record failed"; + } + break; + case 2: + case 4: + r = zebra_update_record( + zh, + 0, /* recordType */ + &sysno, + 0, /* match */ + 0, /* fname */ + rec->u.octet_aligned->buf, + rec->u.octet_aligned->len, + 1); + if (r) + { + rr->errcode = 224; + rr->errstring = "update_record failed"; + } + break; + case 3: + r = zebra_delete_record( + zh, + 0, /* recordType */ + &sysno, + 0, /* match */ + 0, /* fname */ + rec->u.octet_aligned->buf, + rec->u.octet_aligned->len, + 0); + if (r) + { + rr->errcode = 224; + rr->errstring = "delete_record failed"; + } + break; + } + } } } zebra_end_trans (zh); @@ -646,7 +689,7 @@ static void bend_start (struct statserv_options_block *sob) { if (sob->handle) zebra_stop((ZebraService) sob->handle); - sob->handle = zebra_start(sob->configname); + sob->handle = zebra_start(sob->configname, 0, 0); if (!sob->handle) { yaz_log (LOG_FATAL, "Failed to read config `%s'", sob->configname); diff --git a/isam/isam.c b/isam/isam.c index 0d61f24..6b55f50 100644 --- a/isam/isam.c +++ b/isam/isam.c @@ -1,5 +1,5 @@ -/* $Id: isam.c,v 1.27 2002-08-02 19:26:56 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: isam.c,v 1.28 2004-01-22 11:27:21 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -104,8 +104,9 @@ ISAM is_open(BFiles bfs, const char *name, int writeflag, int keysize, Res res) { ISAM inew; - char *nm, *r, *pp[IS_MAX_BLOCKTYPES+1], m[2]; + char *nm, *pp[IS_MAX_BLOCKTYPES+1], m[2]; int num, size, rs, tmp, i; + const char *r; is_type_header th; logf (LOG_DEBUG, "is_open(%s, %s)", name, writeflag ? "RW" : "RDONLY"); diff --git a/rset/rset.c b/rset/rset.c index 901702a..a89191e 100644 --- a/rset/rset.c +++ b/rset/rset.c @@ -1,5 +1,5 @@ -/* $Id: rset.c,v 1.18 2004-01-16 15:27:35 heikki Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: rset.c,v 1.19 2004-01-22 11:27:22 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -65,7 +65,8 @@ RSET rset_dup (RSET rs) int rset_default_forward(RSFD rfd, void *buf, const void *untilbuf) { - logf (LOG_FATAL, "rset_default-forward not yet implemented (%s)"); + logf (LOG_FATAL, "rset_default-forward not yet implemented"); + return 0; } RSET_TERM *rset_terms(RSET rs, int *no) diff --git a/test/api/t1.c b/test/api/t1.c index c26ff02..89dd2ce 100644 --- a/test/api/t1.c +++ b/test/api/t1.c @@ -1,4 +1,4 @@ -/* $Id: t1.c,v 1.3 2003-05-20 13:52:41 adam Exp $ +/* $Id: t1.c,v 1.4 2004-01-22 11:27:22 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -30,7 +30,7 @@ int main(int argc, char **argv) yaz_log_init_file("t1.log"); nmem_init(); - zs = zebra_start("t1.cfg"); + zs = zebra_start("t1.cfg", 0, 0); zh = zebra_open (zs); zebra_close (zh); diff --git a/test/api/t2.c b/test/api/t2.c index d61ab16..03ac063 100644 --- a/test/api/t2.c +++ b/test/api/t2.c @@ -1,5 +1,5 @@ -/* $Id: t2.c,v 1.7 2003-06-20 14:21:24 heikki Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: t2.c,v 1.8 2004-01-22 11:27:22 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -38,11 +38,12 @@ int main(int argc, char **argv) nmem_init (); - zs = zebra_start("t2.cfg"); + zs = zebra_start("t2.cfg", 0, 0); zh = zebra_open (zs); zebra_select_database(zh, "Default"); zebra_begin_trans (zh, 1); - zebra_record_insert (zh, myrec, strlen(myrec),0); + + zebra_add_record (zh, myrec, strlen(myrec)); zebra_search_PQF (zh, "@attr 1=4 my", "set1", &hits); if (hits < 1) diff --git a/test/api/t2.cfg b/test/api/t2.cfg index b83ba0f..8db253e 100644 --- a/test/api/t2.cfg +++ b/test/api/t2.cfg @@ -1,5 +1,7 @@ -# $Id: t2.cfg,v 1.2 2003-04-24 19:35:52 adam Exp $ +# $Id: t2.cfg,v 1.3 2004-01-22 11:27:22 adam Exp $ profilepath: ../../tab attset: bib1.att +recordType: grs.sgml + diff --git a/test/api/t3.c b/test/api/t3.c index c8808ab..e22fe94 100644 --- a/test/api/t3.c +++ b/test/api/t3.c @@ -1,5 +1,5 @@ -/* $Id: t3.c,v 1.4 2003-06-20 14:21:24 heikki Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: t3.c,v 1.5 2004-01-22 11:27:22 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -38,12 +38,12 @@ int main(int argc, char **argv) nmem_init (); - zs = zebra_start("t2.cfg"); + zs = zebra_start("t2.cfg", 0, 0); zh = zebra_open (zs); zebra_select_database(zh, "Default"); zebra_begin_trans (zh, 1); - zebra_record_insert (zh, myrec, strlen(myrec),0); + zebra_add_record (zh, myrec, strlen(myrec)); zebra_end_trans (zh); for (i = 0; i<4; i++) diff --git a/test/api/t4.c b/test/api/t4.c index 5b716ea..5ad4140 100644 --- a/test/api/t4.c +++ b/test/api/t4.c @@ -1,5 +1,5 @@ -/* $Id: t4.c,v 1.4 2003-10-21 09:59:05 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: t4.c,v 1.5 2004-01-22 11:27:22 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -38,18 +38,18 @@ int main(int argc, char **argv) nmem_init (); - zs = zebra_start("t2.cfg"); + zs = zebra_start("t2.cfg", 0, 0); zh = zebra_open (zs); zebra_select_database(zh, "Default"); zebra_begin_trans (zh, 1); for (i = 0; i<1200; i++) - zebra_record_insert (zh, myrec, strlen(myrec),0); + zebra_add_record (zh, myrec, strlen(myrec)); zebra_end_trans (zh); zebra_close(zh); zebra_stop(zs); - zs = zebra_start("t2.cfg"); + zs = zebra_start("t2.cfg", 0, 0); zh = zebra_open (zs); zebra_select_database(zh, "Default"); diff --git a/test/zsh/zebra.cfg b/test/zsh/zebra.cfg index 02c6a95..945c3d9 100644 --- a/test/zsh/zebra.cfg +++ b/test/zsh/zebra.cfg @@ -1,10 +1,11 @@ -# $Id: zebra.cfg,v 1.1 2003-08-21 10:42:43 heikki Exp $ +# $Id: zebra.cfg,v 1.2 2004-01-22 11:27:22 adam Exp $ # A fairly minimal zebra.cfg profilepath: ../../tab register: reg:100M lockDir: reg +recordType: grs.sgml diff --git a/util/res.c b/util/res.c index c1f5c12..e221dc2 100644 --- a/util/res.c +++ b/util/res.c @@ -1,5 +1,5 @@ -/* $Id: res.c,v 1.33 2002-10-22 09:37:56 heikki Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: res.c,v 1.34 2004-01-22 11:27:22 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -45,6 +45,7 @@ struct res_struct { char *name; int init; Res def_res; + Res over_res; }; static struct res_entry *add_entry (Res r) @@ -175,7 +176,7 @@ static void reread (Res r) fclose (fr); } -Res res_open (const char *name, Res def_res) +Res res_open (const char *name, Res def_res, Res over_res) { Res r; @@ -199,6 +200,7 @@ Res res_open (const char *name, Res def_res) else r->name=0; r->def_res = def_res; + r->over_res = over_res; return r; } @@ -223,12 +225,40 @@ void res_close (Res r) xfree (r); } -char *res_get (Res r, const char *name) +const char *res_get_prefix (Res r, const char *name, const char *prefix, + const char *def) +{ + const char *v = 0;; + if (prefix) + { + char rname[128]; + + if (strlen(name) + strlen(prefix) >= (sizeof(rname)-2)) + return 0; + strcpy(rname, prefix); + strcat(rname, "."); + strcat(rname, name); + v = res_get(r, rname); + } + if (!v) + v = res_get(r, name); + if (!v) + v = def; + return v; +} + +const char *res_get (Res r, const char *name) { struct res_entry *re; + const char *v; if (!r) return 0; + + v = res_get(r->over_res, name); + if (v) + return v; + if (!r->init) reread (r); for (re = r->first; re; re=re->next) @@ -238,9 +268,9 @@ char *res_get (Res r, const char *name) return res_get (r->def_res, name); } -char *res_get_def (Res r, const char *name, char *def) +const char *res_get_def (Res r, const char *name, const char *def) { - char *t; + const char *t; if (!(t = res_get (r, name))) { @@ -262,7 +292,7 @@ int res_get_match (Res r, const char *name, const char *value, const char *s) return 0; } -void res_put (Res r, const char *name, const char *value) +void res_set (Res r, const char *name, const char *value) { struct res_entry *re; assert (r);