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
Removed the term count stuff from all rsets, and fixed what ever that broke.
[idzebra-moved-to-github.git]
/
index
/
zebraapi.c
diff --git
a/index/zebraapi.c
b/index/zebraapi.c
index
df8b8af
..
ed643db
100644
(file)
--- a/
index/zebraapi.c
+++ b/
index/zebraapi.c
@@
-1,4
+1,4
@@
-/* $Id: zebraapi.c,v 1.117 2004-01-22 15:40:25 heikki Exp $
+/* $Id: zebraapi.c,v 1.126 2004-08-10 15:21:48 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
@@
-22,6
+22,7
@@
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include <assert.h>
#include <stdio.h>
#include <assert.h>
#include <stdio.h>
+#include <limits.h>
#ifdef WIN32
#include <io.h>
#include <process.h>
#ifdef WIN32
#include <io.h>
#include <process.h>
@@
-108,6
+109,7
@@
ZebraHandle zebra_open (ZebraService zs)
zh->errCode = 0;
zh->errString = 0;
zh->res = 0;
zh->errCode = 0;
zh->errString = 0;
zh->res = 0;
+ zh->user_perm = 0;
zh->reg_name = xstrdup ("");
zh->path_reg = 0;
zh->reg_name = xstrdup ("");
zh->path_reg = 0;
@@
-146,7
+148,12
@@
ZebraHandle zebra_open (ZebraService zs)
return zh;
}
return zh;
}
-ZebraService zebra_start (const char *configName, Res def_res, Res over_res)
+ZebraService zebra_start (const char *configName)
+{
+ return zebra_start_res(configName, 0, 0);
+}
+
+ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res)
{
Res res;
{
Res res;
@@
-243,6
+250,10
@@
struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
reg->keys.buf_max = 0;
reg->keys.buf = 0;
reg->keys.buf_max = 0;
reg->keys.buf = 0;
+#if IT_KEY_NEW
+ reg->keys.codec_handle = iscz1_start();
+#endif
+
reg->sortKeys.buf = 0;
reg->sortKeys.buf_max = 0;
reg->sortKeys.buf = 0;
reg->sortKeys.buf_max = 0;
@@
-251,9
+262,7
@@
struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
reg->sortIdx = 0;
reg->isams = 0;
reg->matchDict = 0;
reg->sortIdx = 0;
reg->isams = 0;
reg->matchDict = 0;
- reg->isam = 0;
reg->isamc = 0;
reg->isamc = 0;
- reg->isamd = 0;
reg->isamb = 0;
reg->zei = 0;
reg->matchDict = 0;
reg->isamb = 0;
reg->zei = 0;
reg->matchDict = 0;
@@
-299,15
+308,6
@@
struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
return 0;
}
}
return 0;
}
}
- if (res_get_match (res, "isam", "i", ISAM_DEFAULT))
- {
- if (!(reg->isam = is_open (reg->bfs, FNAME_ISAM, key_compare, rw,
- sizeof (struct it_key), res)))
- {
- logf (LOG_WARN, "is_open");
- return 0;
- }
- }
if (res_get_match (res, "isam", "c", ISAM_DEFAULT))
{
struct ISAMC_M_s isamc_m;
if (res_get_match (res, "isam", "c", ISAM_DEFAULT))
{
struct ISAMC_M_s isamc_m;
@@
-318,17
+318,6
@@
struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
return 0;
}
}
return 0;
}
}
- if (res_get_match (res, "isam", "d", ISAM_DEFAULT))
- {
- struct ISAMD_M_s isamd_m;
-
- if (!(reg->isamd = isamd_open (reg->bfs, FNAME_ISAMD,
- rw, key_isamd_m(res, &isamd_m))))
- {
- logf (LOG_WARN, "isamd_open");
- return 0;
- }
- }
if (res_get_match (res, "isam", "b", ISAM_DEFAULT))
{
struct ISAMC_M_s isamc_m;
if (res_get_match (res, "isam", "b", ISAM_DEFAULT))
{
struct ISAMC_M_s isamc_m;
@@
-414,12
+403,8
@@
static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
sortIdx_close (reg->sortIdx);
if (reg->isams)
isams_close (reg->isams);
sortIdx_close (reg->sortIdx);
if (reg->isams)
isams_close (reg->isams);
- if (reg->isam)
- is_close (reg->isam);
if (reg->isamc)
isc_close (reg->isamc);
if (reg->isamc)
isc_close (reg->isamc);
- if (reg->isamd)
- isamd_close (reg->isamd);
if (reg->isamb)
isamb_close (reg->isamb);
rec_close (®->records);
if (reg->isamb)
isamb_close (reg->isamb);
rec_close (®->records);
@@
-433,6
+418,10
@@
static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
xfree (reg->sortKeys.buf);
xfree (reg->keys.buf);
xfree (reg->sortKeys.buf);
xfree (reg->keys.buf);
+#if IT_KEY_NEW
+ if (reg->keys.codec_handle)
+ iscz1_stop(reg->keys.codec_handle);
+#endif
xfree (reg->key_buf);
xfree (reg->name);
xfree (reg->key_buf);
xfree (reg->name);
@@
-508,6
+497,7
@@
int zebra_close (ZebraHandle zh)
}
zebra_mutex_cond_unlock (&zs->session_lock);
xfree (zh->reg_name);
}
zebra_mutex_cond_unlock (&zs->session_lock);
xfree (zh->reg_name);
+ xfree (zh->user_perm);
zh->service=0; /* more likely to trigger an assert */
xfree (zh->path_reg);
xfree (zh);
zh->service=0; /* more likely to trigger an assert */
xfree (zh->path_reg);
xfree (zh);
@@
-776,6
+766,8
@@
int zebra_select_databases (ZebraHandle zh, int num_bases,
int zebra_search_RPN (ZebraHandle zh, ODR o,
Z_RPNQuery *query, const char *setname, int *hits)
{
int zebra_search_RPN (ZebraHandle zh, ODR o,
Z_RPNQuery *query, const char *setname, int *hits)
{
+ const char *max;
+ zint maxhits;
ASSERTZH;
yaz_log(LOG_API,"zebra_search_rpn");
zh->errCode=0;
ASSERTZH;
yaz_log(LOG_API,"zebra_search_rpn");
zh->errCode=0;
@@
-791,8
+783,21
@@
int zebra_search_RPN (ZebraHandle zh, ODR o,
zh->num_basenames, zh->basenames, setname);
zebra_end_read (zh);
zh->num_basenames, zh->basenames, setname);
zebra_end_read (zh);
-
- *hits = zh->hits;
+ max = res_get (zh->res, "maxhits");
+ if (max)
+ maxhits=atoi(max);
+ else {
+ int i=0;
+ maxhits=INT_MAX;
+ while (maxhits>100) { maxhits/=10; i++;}
+ while (i--) maxhits *= 10;
+ }
+ if (zh->hits > maxhits) { /* too large for yaz to handle */
+ logf(LOG_LOG,"limiting hits to "ZINT_FORMAT, maxhits);
+ *hits=maxhits; /* round it down to two digits, to look like rounded */
+ }
+ else
+ *hits = zh->hits;
return 0;
}
return 0;
}
@@
-919,10
+924,10
@@
int zebra_deleleResultSet(ZebraHandle zh, int function,
return Z_DeleteStatus_systemProblemAtTarget;
switch (function)
{
return Z_DeleteStatus_systemProblemAtTarget;
switch (function)
{
- case Z_DeleteRequest_list:
+ case Z_DeleteResultSetRequest_list:
resultSetDestroy (zh, num_setnames, setnames, statuses);
break;
resultSetDestroy (zh, num_setnames, setnames, statuses);
break;
- case Z_DeleteRequest_all:
+ case Z_DeleteResultSetRequest_all:
resultSetDestroy (zh, -1, 0, statuses);
break;
}
resultSetDestroy (zh, -1, 0, statuses);
break;
}
@@
-974,18
+979,25
@@
void zebra_clearError(ZebraHandle zh)
int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
{
int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
{
+ const char *p;
+ char u[40];
ZebraService zs;
ZebraService zs;
+
ASSERTZH;
ASSERTZH;
- yaz_log(LOG_API,"zebra_auth u=%s p=%s",user,pass);
zh->errCode=0;
zs= zh->service;
zh->errCode=0;
zs= zh->service;
+
+ sprintf(u, "perm.%.30s", user ? user : "anonymous");
+ p = res_get(zs->global_res, u);
+ xfree (zh->user_perm);
+ zh->user_perm = xstrdup(p ? p : "r");
+
+ /* users that don't require a password .. */
+ if (zh->user_perm && strchr(zh->user_perm, 'a'))
+ return 0;
+
if (!zs->passwd_db || !passwd_db_auth (zs->passwd_db, user, pass))
if (!zs->passwd_db || !passwd_db_auth (zs->passwd_db, user, pass))
- {
- logf(LOG_APP,"AUTHOK:%s", user?user:"ANONYMOUS");
return 0;
return 0;
- }
-
- logf(LOG_APP,"AUTHFAIL:%s", user?user:"ANONYMOUS");
return 1;
}
return 1;
}
@@
-998,7
+1010,8
@@
int zebra_admin_import_begin (ZebraHandle zh, const char *database,
zh->errCode=0;
if (zebra_select_database(zh, database))
return 1;
zh->errCode=0;
if (zebra_select_database(zh, database))
return 1;
- zebra_begin_trans (zh, 1);
+ if (zebra_begin_trans (zh, 1))
+ return 1;
return 0;
}
return 0;
}
@@
-1013,7
+1026,7
@@
int zebra_admin_import_end (ZebraHandle zh)
int zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
{
int zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
{
- int sysno;
+ SYSNO sysno;
int i;
ASSERTZH;
yaz_log(LOG_API,"zebra_admin_import_segment");
int i;
ASSERTZH;
yaz_log(LOG_API,"zebra_admin_import_segment");
@@
-1057,7
+1070,7
@@
int zebra_admin_exchange_record (ZebraHandle zh,
/* 3 = delete. Fail if does not exist */
/* 4 = update. Insert/replace */
{
/* 3 = delete. Fail if does not exist */
/* 4 = update. Insert/replace */
{
- int sysno = 0;
+ SYSNO sysno = 0;
char *rinfo = 0;
char recid_z[256];
ASSERTZH;
char *rinfo = 0;
char recid_z[256];
ASSERTZH;
@@
-1069,7
+1082,8
@@
int zebra_admin_exchange_record (ZebraHandle zh,
memcpy (recid_z, recid_buf, recid_len);
recid_z[recid_len] = 0;
memcpy (recid_z, recid_buf, recid_len);
recid_z[recid_len] = 0;
- zebra_begin_trans(zh,1);
+ if (zebra_begin_trans(zh, 1))
+ return -1;
rinfo = dict_lookup (zh->reg->matchDict, recid_z);
if (rinfo)
rinfo = dict_lookup (zh->reg->matchDict, recid_z);
if (rinfo)
@@
-1308,6
+1322,17
@@
int zebra_begin_trans (ZebraHandle zh, int rw)
}
ASSERTZHRES;
yaz_log(LOG_API,"zebra_begin_trans rw=%d",rw);
}
ASSERTZHRES;
yaz_log(LOG_API,"zebra_begin_trans rw=%d",rw);
+
+ if (zh->user_perm)
+ {
+ if (rw && !strchr(zh->user_perm, 'w'))
+ {
+ zh->errCode = 223;
+ zh->errString = 0;
+ return -1;
+ }
+ }
+
assert (zh->res);
if (rw)
{
assert (zh->res);
if (rw)
{
@@
-1318,7
+1343,10
@@
int zebra_begin_trans (ZebraHandle zh, int rw)
(zh->trans_no++);
if (zh->trans_w_no)
(zh->trans_no++);
if (zh->trans_w_no)
+ {
+ read_res_for_transaction(zh);
return 0;
return 0;
+ }
if (zh->trans_no != 1)
{
zh->errCode = 2;
if (zh->trans_no != 1)
{
zh->errCode = 2;
@@
-1549,7
+1577,8
@@
int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
zebra_register_close (zh->service, zh->reg);
zh->reg = 0;
zebra_register_close (zh->service, zh->reg);
zh->reg = 0;
- yaz_log (LOG_LOG, "Records: %7d i/u/d %d/%d/%d",
+ yaz_log (LOG_LOG, "Records: "ZINT_FORMAT" i/u/d "
+ ZINT_FORMAT"/"ZINT_FORMAT"/"ZINT_FORMAT,
zh->records_processed, zh->records_inserted,
zh->records_updated, zh->records_deleted);
zh->records_processed, zh->records_inserted,
zh->records_updated, zh->records_deleted);
@@
-1918,21
+1947,22
@@
NOTE: Now returns 0 at success and updates sysno, which is an int*
int zebra_add_record(ZebraHandle zh,
const char *buf, int buf_size)
{
int zebra_add_record(ZebraHandle zh,
const char *buf, int buf_size)
{
- int sysno = 0;
+ SYSNO sysno = 0;
return zebra_update_record(zh, 0, &sysno, 0, 0, buf, buf_size, 0);
}
int zebra_insert_record (ZebraHandle zh,
const char *recordType,
return zebra_update_record(zh, 0, &sysno, 0, 0, buf, buf_size, 0);
}
int zebra_insert_record (ZebraHandle zh,
const char *recordType,
- int *sysno, const char *match, const char *fname,
- const char *buf, int buf_size)
+ SYSNO *sysno, const char *match, const char *fname,
+ const char *buf, int buf_size, int force_update)
{
int res;
{
int res;
- yaz_log(LOG_API,"zebra_insert_record sysno=%d", *sysno);
+ yaz_log(LOG_API,"zebra_insert_record sysno=" ZINT_FORMAT, *sysno);
if (buf_size < 1) buf_size = strlen(buf);
if (buf_size < 1) buf_size = strlen(buf);
- zebra_begin_trans(zh, 1);
+ if (zebra_begin_trans(zh, 1))
+ return 1;
res = buffer_extract_record (zh, buf, buf_size,
0, /* delete_flag */
0, /* test_mode */
res = buffer_extract_record (zh, buf, buf_size,
0, /* delete_flag */
0, /* test_mode */
@@
-1947,17
+1977,18
@@
int zebra_insert_record (ZebraHandle zh,
int zebra_update_record (ZebraHandle zh,
const char *recordType,
int zebra_update_record (ZebraHandle zh,
const char *recordType,
- int* sysno, const char *match, const char *fname,
+ SYSNO* sysno, const char *match, const char *fname,
const char *buf, int buf_size,
int force_update)
{
int res;
const char *buf, int buf_size,
int force_update)
{
int res;
- yaz_log(LOG_API,"zebra_update_record sysno=%d", *sysno);
+ yaz_log(LOG_API,"zebra_update_record sysno=" ZINT_FORMAT, *sysno);
if (buf_size < 1) buf_size = strlen(buf);
if (buf_size < 1) buf_size = strlen(buf);
- zebra_begin_trans(zh, 1);
+ if (zebra_begin_trans(zh, 1))
+ return 1;
res = buffer_extract_record (zh, buf, buf_size,
0, /* delete_flag */
0, /* test_mode */
res = buffer_extract_record (zh, buf, buf_size,
0, /* delete_flag */
0, /* test_mode */
@@
-1972,16
+2003,17
@@
int zebra_update_record (ZebraHandle zh,
int zebra_delete_record (ZebraHandle zh,
const char *recordType,
int zebra_delete_record (ZebraHandle zh,
const char *recordType,
- int *sysno, const char *match, const char *fname,
+ SYSNO *sysno, const char *match, const char *fname,
const char *buf, int buf_size,
int force_update)
{
int res;
const char *buf, int buf_size,
int force_update)
{
int res;
- yaz_log(LOG_API,"zebra_delete_record sysno=%d", *sysno);
+ yaz_log(LOG_API,"zebra_delete_record sysno=" ZINT_FORMAT, *sysno);
if (buf_size < 1) buf_size = strlen(buf);
if (buf_size < 1) buf_size = strlen(buf);
- zebra_begin_trans(zh, 1);
+ if (zebra_begin_trans(zh, 1))
+ return 1;
res = buffer_extract_record (zh, buf, buf_size,
1, /* delete_flag */
0, /* test_mode */
res = buffer_extract_record (zh, buf, buf_size,
1, /* delete_flag */
0, /* test_mode */
@@
-2059,3
+2091,4
@@
int zebra_sort_by_specstr (ZebraHandle zh,
zebra_end_read(zh);
return sort_status;
}
zebra_end_read(zh);
return sort_status;
}
+