projects
/
idzebra-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Allow dict_close of 0 pointer
[idzebra-moved-to-github.git]
/
index
/
zebraapi.c
diff --git
a/index/zebraapi.c
b/index/zebraapi.c
index
9a24d0e
..
b036ff1
100644
(file)
--- a/
index/zebraapi.c
+++ b/
index/zebraapi.c
@@
-1,4
+1,4
@@
-/* $Id: zebraapi.c,v 1.199 2005-12-09 11:33:32 adam Exp $
+/* $Id: zebraapi.c,v 1.205 2006-03-25 15:33:29 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
Copyright (C) 1995-2005
Index Data ApS
@@
-36,6
+36,7
@@
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include <yaz/pquery.h>
#include <yaz/sortspec.h>
#include "index.h"
#include <yaz/pquery.h>
#include <yaz/sortspec.h>
#include "index.h"
+#include "orddict.h"
#include <charmap.h>
#include <idzebra/api.h>
#include <charmap.h>
#include <idzebra/api.h>
@@
-183,11
+184,18
@@
ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res)
const char *passwd_plain = 0;
const char *passwd_encrypt = 0;
const char *dbaccess = 0;
const char *passwd_plain = 0;
const char *passwd_encrypt = 0;
const char *dbaccess = 0;
- ZebraService zh = xmalloc(sizeof(*zh));
+ ZebraService zh = 0;
if (configName)
if (configName)
- res_read_file(res, configName);
-
+ {
+ ZEBRA_RES ret = res_read_file(res, configName);
+ if (ret != ZEBRA_OK)
+ {
+ res_close(res);
+ return 0;
+ }
+ }
+ zh = xmalloc(sizeof(*zh));
zh->global_res = res;
zh->sessions = 0;
zh->global_res = res;
zh->sessions = 0;
@@
-291,6
+299,7
@@
struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
reg->dh = data1_createx (DATA1_FLAG_XML);
if (!reg->dh)
{
reg->dh = data1_createx (DATA1_FLAG_XML);
if (!reg->dh)
{
+ xfree(reg->name);
xfree(reg);
return 0;
}
xfree(reg);
return 0;
}
@@
-298,6
+307,7
@@
struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
if (!reg->bfs)
{
data1_destroy(reg->dh);
if (!reg->bfs)
{
data1_destroy(reg->dh);
+ xfree(reg->name);
xfree(reg);
return 0;
}
xfree(reg);
return 0;
}
@@
-307,6
+317,7
@@
struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
{
bfs_destroy(reg->bfs);
data1_destroy(reg->dh);
{
bfs_destroy(reg->bfs);
data1_destroy(reg->dh);
+ xfree(reg->name);
xfree(reg);
return 0;
}
xfree(reg);
return 0;
}
@@
-320,7
+331,16
@@
struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
data1_set_tabroot (reg->dh, reg_path);
reg->recTypes = recTypes_init (zs->record_classes, reg->dh);
data1_set_tabroot (reg->dh, reg_path);
reg->recTypes = recTypes_init (zs->record_classes, reg->dh);
- reg->zebra_maps = zebra_maps_open (res, reg_path);
+ if ((reg->zebra_maps = zebra_maps_open (res, reg_path)) == 0)
+ {
+ recTypes_destroy(reg->recTypes);
+ bfs_destroy(reg->bfs);
+ data1_destroy(reg->dh);
+ xfree(reg->name);
+ xfree(reg);
+ return 0;
+ }
+
reg->rank_classes = NULL;
reg->key_buf = 0;
reg->rank_classes = NULL;
reg->key_buf = 0;
@@
-342,7
+362,6
@@
struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
reg->isamc = 0;
reg->isamb = 0;
reg->zei = 0;
reg->isamc = 0;
reg->isamb = 0;
reg->zei = 0;
- reg->matchDict = 0;
reg->key_file_no = 0;
reg->ptr_i = 0;
reg->key_file_no = 0;
reg->ptr_i = 0;
@@
-436,6
+455,7
@@
struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
yaz_log (YLOG_WARN, "Cannot obtain EXPLAIN information");
return 0;
}
yaz_log (YLOG_WARN, "Cannot obtain EXPLAIN information");
return 0;
}
+
reg->active = 2;
yaz_log (YLOG_DEBUG, "zebra_register_open ok p=%p", reg);
return reg;
reg->active = 2;
yaz_log (YLOG_DEBUG, "zebra_register_open ok p=%p", reg);
return reg;
@@
-686,11
+706,11
@@
static void zebra_select_register (ZebraHandle zh, const char *new_reg)
res_set (zh->res, "lockDir", zh->path_reg);
sprintf (fname, "norm.%s.LCK", zh->reg_name);
zh->lock_normal =
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);
+ zebra_lock_create (res_get(zh->res, "lockDir"), fname);
sprintf (fname, "shadow.%s.LCK", zh->reg_name);
zh->lock_shadow =
sprintf (fname, "shadow.%s.LCK", zh->reg_name);
zh->lock_shadow =
- zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
+ zebra_lock_create (res_get(zh->res, "lockDir"), fname);
if (!zh->lock_normal || !zh->lock_shadow)
{
if (!zh->lock_normal || !zh->lock_shadow)
{
@@
-1286,11
+1306,11
@@
ZEBRA_RES zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
return res;
}
return res;
}
-ZEBRA_RES zebra_admin_exchange_record (ZebraHandle zh,
- const char *rec_buf,
- size_t rec_len,
- const char *recid_buf, size_t recid_len,
- int action)
+ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh,
+ 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 */
/* 1 = insert. Fail it already exists */
/* 2 = replace. Fail it does not exist */
/* 3 = delete. Fail if does not exist */
@@
-1300,6
+1320,7
@@
ZEBRA_RES zebra_admin_exchange_record (ZebraHandle zh,
SYSNO sysno = 0;
char *rinfo = 0;
char recid_z[256];
SYSNO sysno = 0;
char *rinfo = 0;
char recid_z[256];
+ int db_ord;
ASSERTZH;
assert(action>0 && action <=4);
assert(rec_buf);
ASSERTZH;
assert(action>0 && action <=4);
assert(rec_buf);
@@
-1319,7
+1340,8
@@
ZEBRA_RES zebra_admin_exchange_record (ZebraHandle zh,
if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
return ZEBRA_FAIL;
if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
return ZEBRA_FAIL;
- rinfo = dict_lookup (zh->reg->matchDict, recid_z);
+ db_ord = zebraExplain_get_database_ord(zh->reg->zei);
+ rinfo = dict_lookup_ord(zh->reg->matchDict, db_ord, recid_z);
if (rinfo)
{
if (action == 1) /* fail if insert */
if (rinfo)
{
if (action == 1) /* fail if insert */
@@
-1360,11
+1382,12
@@
ZEBRA_RES zebra_admin_exchange_record (ZebraHandle zh,
}
if (action == 1)
{
}
if (action == 1)
{
- dict_insert (zh->reg->matchDict, recid_z, sizeof(sysno), &sysno);
+ dict_insert_ord(zh->reg->matchDict, db_ord, recid_z,
+ sizeof(sysno), &sysno);
}
else if (action == 3)
{
}
else if (action == 3)
{
- dict_delete (zh->reg->matchDict, recid_z);
+ dict_delete_ord(zh->reg->matchDict, db_ord, recid_z);
}
zebra_end_trans(zh);
return res;
}
zebra_end_trans(zh);
return res;
@@
-1411,8
+1434,11
@@
ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db)
return ZEBRA_FAIL;
if (zh->reg->isamb)
{
return ZEBRA_FAIL;
if (zh->reg->isamb)
{
+ int db_ord;
zebraExplain_curDatabase (zh->reg->zei, db);
zebraExplain_curDatabase (zh->reg->zei, db);
-
+ db_ord = zebraExplain_get_database_ord(zh->reg->zei);
+ dict_delete_subtree_ord(zh->reg->matchDict, db_ord,
+ 0 /* handle */, 0 /* func */);
zebraExplain_trav_ord(zh->reg->zei, zh, delete_SU_handle);
zebraExplain_removeDatabase(zh->reg->zei, zh);
}
zebraExplain_trav_ord(zh->reg->zei, zh, delete_SU_handle);
zebraExplain_removeDatabase(zh->reg->zei, zh);
}
@@
-1649,7
+1675,7
@@
ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw)
yaz_log (YLOG_WARN, "previous transaction didn't reach commit");
bf_commitClean (bfs, rval);
bfs_destroy (bfs);
yaz_log (YLOG_WARN, "previous transaction didn't reach commit");
bf_commitClean (bfs, rval);
bfs_destroy (bfs);
- }
+ }
else
{
yaz_log (YLOG_WARN, "your previous transaction didn't finish");
else
{
yaz_log (YLOG_WARN, "your previous transaction didn't finish");
@@
-1685,6
+1711,7
@@
ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw)
yaz_log(YLOG_FATAL, "%s", zh->errString);
return ZEBRA_FAIL;
}
yaz_log(YLOG_FATAL, "%s", zh->errString);
return ZEBRA_FAIL;
}
+ zebraExplain_curDatabase(zh->reg->zei, zh->basenames[0]);
}
else
{
}
else
{
@@
-2336,3
+2363,12
@@
void zebra_setError_zint(ZebraHandle zh, int code, zint i)
zh->errString = nmem_strdup(zh->nmem_error, vstr);
}
zh->errString = nmem_strdup(zh->nmem_error, vstr);
}
+void zebra_lock_prefix (Res res, char *path)
+{
+ const char *lock_dir = res_get_def (res, "lockDir", "");
+
+ strcpy (path, lock_dir);
+ if (*path && path[strlen(path)-1] != '/')
+ strcat (path, "/");
+}
+