-/* $Id: zebraapi.c,v 1.86 2003-02-27 23:08:10 pop Exp $
+/* $Id: zebraapi.c,v 1.87 2003-03-04 23:05:30 pop Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
#include <yaz/diagbib1.h>
#include "index.h"
#include <charmap.h>
+#include "zebraapi.h"
/* simple asserts to validate the most essential input args */
#define ASSERTZH assert(zh && zh->service)
zh->errCode=0;
return res_get_def( zh->res, name, (char *)defaultvalue);
}
+
+/* moved from zebra_api_ext.c by pop */
+
+int zebra_trans_no (ZebraHandle zh) {
+ return (zh->trans_no);
+}
+
+
+
+int zebra_get_shadow_enable (ZebraHandle zh) {
+ return (zh->shadow_enable);
+}
+
+void zebra_set_shadow_enable (ZebraHandle zh, int value) {
+ zh->shadow_enable = value;
+}
+
+void init_recordGroup (struct recordGroup *rg) {
+ 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;
+}
+
+
+/* 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];
+
+ 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,
+ const char *setname, Z_RecordComposition *comp,
+ oid_value input_format, int num_recs,
+ ZebraRetrievalRecord *recs)
+{
+ ZebraPosSet poset;
+ int i, *pos_array;
+
+ if (!zh->res)
+ {
+ zh->errCode = 30;
+ zh->errString = odr_strdup (stream, setname);
+ return;
+ }
+
+ zh->errCode = 0;
+
+ if (zebra_begin_read (zh))
+ return;
+
+ pos_array = (int *) xmalloc (num_recs * sizeof(*pos_array));
+ for (i = 0; i<num_recs; i++)
+ pos_array[i] = recs[i].position;
+ poset = zebraPosSetCreate (zh, setname, num_recs, pos_array);
+ if (!poset)
+ {
+ logf (LOG_DEBUG, "zebraPosSetCreate error");
+ zh->errCode = 30;
+ zh->errString = nmem_strdup (stream->mem, setname);
+ }
+ else
+ {
+ for (i = 0; i<num_recs; i++)
+ {
+ if (poset[i].term)
+ {
+ recs[i].errCode = 0;
+ recs[i].format = VAL_SUTRS;
+ recs[i].len = strlen(poset[i].term);
+ recs[i].buf = poset[i].term;
+ recs[i].base = poset[i].db;
+ recs[i].sysno = 0;
+
+ }
+ else if (poset[i].sysno)
+ {
+ /* changed here ??? CHECK ??? */
+ char *b;
+ recs[i].errCode =
+ zebra_record_fetch (zh, poset[i].sysno, poset[i].score,
+ stream, input_format, comp,
+ &recs[i].format,
+ &b,
+ &recs[i].len,
+ &recs[i].base);
+ recs[i].buf = (char *) odr_malloc(stream,recs[i].len);
+ memcpy(recs[i].buf, b, recs[i].len);
+ recs[i].errString = 0; /* Hmmm !!! we should get this */
+ recs[i].sysno = poset[i].sysno;
+ recs[i].score = poset[i].score;
+ }
+ else
+ {
+ char num_str[20];
+
+ sprintf (num_str, "%d", pos_array[i]);
+ zh->errCode = 13;
+ zh->errString = odr_strdup (stream, num_str);
+ break;
+ }
+
+ }
+ zebraPosSetDestroy (zh, poset, num_recs);
+ }
+ zebra_end_read (zh);
+ xfree (pos_array);
+}
+
+
+/* ---------------------------------------------------------------------------
+ Record insert(=update), delete
+
+ 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 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)
+
+{
+ int res;
+
+ if (buf_size < 1) buf_size = strlen(buf);
+
+ zebra_begin_trans(zh);
+ res=bufferExtractRecord (zh, buf, buf_size, rGroup,
+ 0, // delete_flag
+ 0, // test_mode,
+ recordType,
+ &sysno,
+ match, fname);
+ zebra_end_trans(zh);
+ return sysno;
+}
+
+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)
+{
+ int res;
+
+ if (buf_size < 1) buf_size = strlen(buf);
+
+ zebra_begin_trans(zh);
+ res=bufferExtractRecord (zh, buf, buf_size, rGroup,
+ 1, // delete_flag
+ 0, // test_mode,
+ recordType,
+ &sysno,
+ match,fname);
+ zebra_end_trans(zh);
+ return sysno;
+}
+
+/* ---------------------------------------------------------------------------
+ Searching
+
+ zebra_search_RPN is the same as zebra_search_rpn, except that read locking
+ is not mandatory. (it's repeatable now, also in zebraapi.c)
+*/
+
+void zebra_search_RPN (ZebraHandle zh, ODR decode, ODR stream,
+ Z_RPNQuery *query, const char *setname, int *hits)
+{
+ zh->hits = 0;
+ *hits = 0;
+
+ if (zebra_begin_read (zh))
+ return;
+ resultSetAddRPN (zh, decode, stream, query,
+ zh->num_basenames, zh->basenames, setname);
+
+ zebra_end_read (zh);
+
+ *hits = zh->hits;
+}
+
+int zebra_search_PQF (ZebraHandle zh,
+ ODR odr_input, ODR odr_output,
+ const char *pqf_query,
+ const char *setname)
+
+{
+ int hits;
+ Z_RPNQuery *query;
+ query = p_query_rpn (odr_input, PROTO_Z3950, pqf_query);
+
+ if (!query) {
+ logf (LOG_WARN, "bad query %s\n", pqf_query);
+ odr_reset (odr_input);
+ return(0);
+ }
+ zebra_search_RPN (zh, odr_input, odr_output, query, setname, &hits);
+
+ odr_reset (odr_input);
+ odr_reset (odr_output);
+
+ return(hits);
+}
+
+/* ---------------------------------------------------------------------------
+ Sort - a simplified interface, with optional read locks.
+*/
+int sort (ZebraHandle zh,
+ ODR stream,
+ const char *sort_spec,
+ const char *output_setname,
+ const char **input_setnames
+ )
+{
+ int num_input_setnames = 0;
+ int sort_status = 0;
+ Z_SortKeySpecList *sort_sequence = yaz_sort_spec (stream, sort_spec);
+ if (!sort_sequence) {
+ logf(LOG_WARN,"invalid sort specs '%s'", sort_spec);
+ zh->errCode = 207;
+ return (-1);
+ }
+
+ /* we can do this, since the perl typemap code for char** will
+ put a NULL at the end of list */
+ while (input_setnames[num_input_setnames]) num_input_setnames++;
+
+ if (zebra_begin_read (zh))
+ return;
+
+ resultSetSort (zh, stream->mem, num_input_setnames, input_setnames,
+ output_setname, sort_sequence, &sort_status);
+
+ zebra_end_read(zh);
+ return (sort_status);
+}
%{
#include "zebraapi.h"
-#include "zebra_api_ext.h"
#include "zebra_perl.h"
#include "data1.h"
#include "yaz/odr.h"
%name(begin_read)
int zebra_begin_read (ZebraHandle zh);
-void zts_test (ZebraTransactionStatus *stat);
-
/* end retrieval (remove read lock) (zebraapi.c) */
%name(end_read)
void zebra_end_read (ZebraHandle zh);
* perl5.swg
*
* Perl5 runtime library
- * $Header: /home/cvsroot/idis/perl/Attic/IDZebra_wrap.c,v 1.10 2003-03-04 19:33:52 pop Exp $
+ * $Header: /home/cvsroot/idis/perl/Attic/IDZebra_wrap.c,v 1.11 2003-03-04 23:05:31 pop Exp $
* ----------------------------------------------------------------------------- */
#define SWIGPERL
#include "zebraapi.h"
-#include "zebra_api_ext.h"
#include "zebra_perl.h"
#include "data1.h"
#include "yaz/odr.h"
}
+XS(_wrap_RetrievalRecordBuf_buf_set) {
+ char _swigmsg[SWIG_MAX_ERRMSG] = "";
+ const char *_swigerr = _swigmsg;
+ {
+ RetrievalRecordBuf *arg1 ;
+ char *arg2 ;
+ int argvi = 0;
+ dXSARGS;
+
+ if ((items < 2) || (items > 2)) {
+ SWIG_croak("Usage: RetrievalRecordBuf_buf_set(self,buf);");
+ }
+ {
+ if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_RetrievalRecordBuf,0) < 0) {
+ SWIG_croak("Type error in argument 1 of RetrievalRecordBuf_buf_set. Expected _p_RetrievalRecordBuf");
+ }
+ }
+ if (!SvOK((SV*) ST(1))) arg2 = 0;
+ else arg2 = (char *) SvPV(ST(1), PL_na);
+ {
+ if (arg1->buf) free((char*)arg1->buf);
+ arg1->buf = (char *) malloc(strlen(arg2)+1);
+ strcpy((char*)arg1->buf,arg2);
+ }
+
+ XSRETURN(argvi);
+ fail:
+ (void) _swigerr;
+ }
+ croak(_swigerr);
+}
+
+
+XS(_wrap_RetrievalRecordBuf_buf_get) {
+ char _swigmsg[SWIG_MAX_ERRMSG] = "";
+ const char *_swigerr = _swigmsg;
+ {
+ RetrievalRecordBuf *arg1 ;
+ char *result;
+ int argvi = 0;
+ dXSARGS;
+
+ if ((items < 1) || (items > 1)) {
+ SWIG_croak("Usage: RetrievalRecordBuf_buf_get(self);");
+ }
+ {
+ if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_RetrievalRecordBuf,0) < 0) {
+ SWIG_croak("Type error in argument 1 of RetrievalRecordBuf_buf_get. Expected _p_RetrievalRecordBuf");
+ }
+ }
+ result = (char *) ((arg1)->buf);
+
+ ST(argvi) = sv_newmortal();
+ if (result) {
+ sv_setpv((SV*)ST(argvi++), (char *) result);
+ }else {
+ sv_setsv((SV*)ST(argvi++), &PL_sv_undef);
+ }
+ XSRETURN(argvi);
+ fail:
+ (void) _swigerr;
+ }
+ croak(_swigerr);
+}
+
+
+XS(_wrap_RetrievalRecordBuf_len_set) {
+ char _swigmsg[SWIG_MAX_ERRMSG] = "";
+ const char *_swigerr = _swigmsg;
+ {
+ RetrievalRecordBuf *arg1 ;
+ int arg2 ;
+ int argvi = 0;
+ dXSARGS;
+
+ if ((items < 2) || (items > 2)) {
+ SWIG_croak("Usage: RetrievalRecordBuf_len_set(self,len);");
+ }
+ {
+ if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_RetrievalRecordBuf,0) < 0) {
+ SWIG_croak("Type error in argument 1 of RetrievalRecordBuf_len_set. Expected _p_RetrievalRecordBuf");
+ }
+ }
+ arg2 = (int) SvIV(ST(1));
+ if (arg1) (arg1)->len = arg2;
+
+
+ XSRETURN(argvi);
+ fail:
+ (void) _swigerr;
+ }
+ croak(_swigerr);
+}
+
+
+XS(_wrap_RetrievalRecordBuf_len_get) {
+ char _swigmsg[SWIG_MAX_ERRMSG] = "";
+ const char *_swigerr = _swigmsg;
+ {
+ RetrievalRecordBuf *arg1 ;
+ int result;
+ int argvi = 0;
+ dXSARGS;
+
+ if ((items < 1) || (items > 1)) {
+ SWIG_croak("Usage: RetrievalRecordBuf_len_get(self);");
+ }
+ {
+ if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_RetrievalRecordBuf,0) < 0) {
+ SWIG_croak("Type error in argument 1 of RetrievalRecordBuf_len_get. Expected _p_RetrievalRecordBuf");
+ }
+ }
+ result = (int) ((arg1)->len);
+
+ ST(argvi) = sv_newmortal();
+ sv_setiv(ST(argvi++), (IV) result);
+ XSRETURN(argvi);
+ fail:
+ (void) _swigerr;
+ }
+ croak(_swigerr);
+}
+
+
+XS(_wrap_new_RetrievalRecordBuf) {
+ char _swigmsg[SWIG_MAX_ERRMSG] = "";
+ const char *_swigerr = _swigmsg;
+ {
+ RetrievalRecordBuf *result;
+ int argvi = 0;
+ dXSARGS;
+
+ if ((items < 0) || (items > 0)) {
+ SWIG_croak("Usage: new_RetrievalRecordBuf();");
+ }
+ result = (RetrievalRecordBuf *)(RetrievalRecordBuf *) calloc(1, sizeof(RetrievalRecordBuf));
+
+ {
+ if (result->len) {
+ ST(argvi) = newSVpv(result->buf,result->len);
+ }else {
+ ST(argvi) = newSVpv("",0);
+ }
+ sv_2mortal(ST(argvi));
+ argvi++;
+ }
+ XSRETURN(argvi);
+ fail:
+ (void) _swigerr;
+ }
+ croak(_swigerr);
+}
+
+
+XS(_wrap_delete_RetrievalRecordBuf) {
+ char _swigmsg[SWIG_MAX_ERRMSG] = "";
+ const char *_swigerr = _swigmsg;
+ {
+ RetrievalRecordBuf *arg1 ;
+ int argvi = 0;
+ dXSARGS;
+
+ if ((items < 1) || (items > 1)) {
+ SWIG_croak("Usage: delete_RetrievalRecordBuf(self);");
+ }
+ {
+ if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_RetrievalRecordBuf,0) < 0) {
+ SWIG_croak("Type error in argument 1 of delete_RetrievalRecordBuf. Expected _p_RetrievalRecordBuf");
+ }
+ }
+ free((char *) arg1);
+
+
+ XSRETURN(argvi);
+ fail:
+ (void) _swigerr;
+ }
+ croak(_swigerr);
+}
+
+
XS(_wrap_RetrievalRecord_errCode_set) {
char _swigmsg[SWIG_MAX_ERRMSG] = "";
const char *_swigerr = _swigmsg;
}
-XS(_wrap_zts_test) {
- char _swigmsg[SWIG_MAX_ERRMSG] = "";
- const char *_swigerr = _swigmsg;
- {
- ZebraTransactionStatus *arg1 ;
- int argvi = 0;
- dXSARGS;
-
- if ((items < 1) || (items > 1)) {
- SWIG_croak("Usage: zts_test(stat);");
- }
- {
- if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ZebraTransactionStatus,0) < 0) {
- SWIG_croak("Type error in argument 1 of zts_test. Expected _p_ZebraTransactionStatus");
- }
- }
- zts_test(arg1);
-
-
- XSRETURN(argvi);
- fail:
- (void) _swigerr;
- }
- croak(_swigerr);
-}
-
-
XS(_wrap_end_read) {
char _swigmsg[SWIG_MAX_ERRMSG] = "";
const char *_swigerr = _swigmsg;
static swig_type_info _swigt__p_off_t[] = {{"_p_off_t", 0, "off_t *", 0},{"_p_off_t"},{0}};
static swig_type_info _swigt__p_Odr_oid[] = {{"_p_Odr_oid", 0, "Odr_oid *", 0},{"_p_Odr_oid"},{0}};
static swig_type_info _swigt__p_data1_varset[] = {{"_p_data1_varset", 0, "data1_varset *", 0},{"_p_data1_varset"},{0}};
-static swig_type_info _swigt__p_RetrievalRecordBuf[] = {{"_p_RetrievalRecordBuf", 0, "RetrievalRecordBuf *", 0},{"_p_RetrievalRecordBuf"},{0}};
+static swig_type_info _swigt__p_RetrievalRecordBuf[] = {{"IDZebra::RetrievalRecordBuf", 0, "RetrievalRecordBuf *", 0},{"IDZebra::RetrievalRecordBuf"},{0}};
static swig_type_info _swigt__p_perl_context[] = {{"_p_perl_context", 0, "struct perl_context *", 0},{"_p_perl_context"},{0}};
static swig_type_info _swigt__p_data1_node[] = {{"_p_data1_node", 0, "data1_node *", 0},{"_p_data1_node"},{0}};
static swig_type_info _swigt__p_ScanObj[] = {{"IDZebra::ScanObj", 0, "ScanObj *", 0},{"IDZebra::ScanObj"},{0}};
{"IDZebrac::RetrievalObj_records_get", _wrap_RetrievalObj_records_get},
{"IDZebrac::new_RetrievalObj", _wrap_new_RetrievalObj},
{"IDZebrac::delete_RetrievalObj", _wrap_delete_RetrievalObj},
+{"IDZebrac::RetrievalRecordBuf_buf_set", _wrap_RetrievalRecordBuf_buf_set},
+{"IDZebrac::RetrievalRecordBuf_buf_get", _wrap_RetrievalRecordBuf_buf_get},
+{"IDZebrac::RetrievalRecordBuf_len_set", _wrap_RetrievalRecordBuf_len_set},
+{"IDZebrac::RetrievalRecordBuf_len_get", _wrap_RetrievalRecordBuf_len_get},
+{"IDZebrac::new_RetrievalRecordBuf", _wrap_new_RetrievalRecordBuf},
+{"IDZebrac::delete_RetrievalRecordBuf", _wrap_delete_RetrievalRecordBuf},
{"IDZebrac::RetrievalRecord_errCode_set", _wrap_RetrievalRecord_errCode_set},
{"IDZebrac::RetrievalRecord_errCode_get", _wrap_RetrievalRecord_errCode_get},
{"IDZebrac::RetrievalRecord_errString_set", _wrap_RetrievalRecord_errString_set},
{"IDZebrac::end_trans", _wrap_end_trans},
{"IDZebrac::trans_no", _wrap_trans_no},
{"IDZebrac::begin_read", _wrap_begin_read},
-{"IDZebrac::zts_test", _wrap_zts_test},
{"IDZebrac::end_read", _wrap_end_read},
{"IDZebrac::commit", _wrap_commit},
{"IDZebrac::get_shadow_enable", _wrap_get_shadow_enable},
SWIG_TypeClientData(SWIGTYPE_p_recordGroup, (void*) "IDZebra::recordGroup");
SWIG_TypeClientData(SWIGTYPE_p_RetrievalObj, (void*) "IDZebra::RetrievalObj");
+ SWIG_TypeClientData(SWIGTYPE_p_RetrievalRecordBuf, (void*) "IDZebra::RetrievalRecordBuf");
SWIG_TypeClientData(SWIGTYPE_p_RetrievalRecord, (void*) "IDZebra::RetrievalRecord");
SWIG_TypeClientData(SWIGTYPE_p_scanEntry, (void*) "IDZebra::scanEntry");
SWIG_TypeClientData(SWIGTYPE_p_ScanObj, (void*) "IDZebra::ScanObj");
demo/pod.abs
demo/pod.pm
demo/zebra.cfg
+demo/register
+demo/lock
+demo/tmp
lib/IDZebra.pm
lib/IDZebra/Data1.pm
lib/IDZebra/Filter.pm
*end_trans = *IDZebrac::end_trans;
*trans_no = *IDZebrac::trans_no;
*begin_read = *IDZebrac::begin_read;
-*zts_test = *IDZebrac::zts_test;
*end_read = *IDZebrac::end_read;
*commit = *IDZebrac::commit;
*get_shadow_enable = *IDZebrac::get_shadow_enable;
}
+############# Class : IDZebra::RetrievalRecordBuf ##############
+
+package IDZebra::RetrievalRecordBuf;
+@ISA = qw( IDZebra );
+%OWNER = ();
+%BLESSEDMEMBERS = (
+);
+
+%ITERATORS = ();
+*swig_buf_get = *IDZebrac::RetrievalRecordBuf_buf_get;
+*swig_buf_set = *IDZebrac::RetrievalRecordBuf_buf_set;
+*swig_len_get = *IDZebrac::RetrievalRecordBuf_len_get;
+*swig_len_set = *IDZebrac::RetrievalRecordBuf_len_set;
+sub new {
+ my $pkg = shift;
+ my @args = @_;
+ my $self = IDZebrac::new_RetrievalRecordBuf(@args);
+ return undef if (!defined($self));
+ $OWNER{$self} = 1;
+ my %retval;
+ tie %retval, "IDZebra::RetrievalRecordBuf", $self;
+ return bless \%retval, $pkg;
+}
+
+sub DESTROY {
+ return unless $_[0]->isa('HASH');
+ my $self = tied(%{$_[0]});
+ return unless defined $self;
+ delete $ITERATORS{$self};
+ if (exists $OWNER{$self}) {
+ IDZebrac::delete_RetrievalRecordBuf($self);
+ delete $OWNER{$self};
+ }
+}
+
+sub DISOWN {
+ my $self = shift;
+ my $ptr = tied(%$self);
+ delete $OWNER{$ptr};
+ };
+
+sub ACQUIRE {
+ my $self = shift;
+ my $ptr = tied(%$self);
+ $OWNER{$ptr} = 1;
+ };
+
+sub FETCH {
+ my ($self,$field) = @_;
+ my $member_func = "swig_${field}_get";
+ my $val = $self->$member_func();
+ if (exists $BLESSEDMEMBERS{$field}) {
+ return undef if (!defined($val));
+ my %retval;
+ tie %retval,$BLESSEDMEMBERS{$field},$val;
+ return bless \%retval, $BLESSEDMEMBERS{$field};
+ }
+ return $val;
+}
+
+sub STORE {
+ my ($self,$field,$newval) = @_;
+ my $member_func = "swig_${field}_set";
+ if (exists $BLESSEDMEMBERS{$field}) {
+ $self->$member_func(tied(%{$newval}));
+ } else {
+ $self->$member_func($newval);
+ }
+}
+
+
############# Class : IDZebra::RetrievalRecord ##############
package IDZebra::RetrievalRecord;
@ISA = qw( IDZebra );
%OWNER = ();
%BLESSEDMEMBERS = (
+ buf => 'IDZebra::RetrievalRecordBuf',
);
%ITERATORS = ();
#include "zebra_api_ext.h"
#include "yaz/log.h"
#include <yaz/pquery.h>
-#include <yaz/cql.h>
#include <yaz/sortspec.h>
-void data1_print_tree(data1_handle dh, data1_node *n, FILE *out) {
- data1_pr_tree(dh, n, stdout);
-}
-int zebra_get_shadow_enable (ZebraHandle zh) {
- return (zh->shadow_enable);
-}
-
-void zebra_set_shadow_enable (ZebraHandle zh, int value) {
- zh->shadow_enable = value;
-}
-
-void init_recordGroup (recordGroup *rg) {
- 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;
-}
-
-
-/* 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,
- recordGroup *rGroup,
- const char *ext) {
- char gprefix[128];
- char ext_res[128];
-
- 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;
-
-}
-
-int zebra_trans_processed(ZebraTransactionStatus s) {
- return (s.processed);
-}
-
-/* ---------------------------------------------------------------------------
- Record insert(=update), delete
-
- 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 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)
-
-{
- int res;
-
- if (buf_size < 1) buf_size = strlen(buf);
-
- zebra_begin_trans(zh);
- res=bufferExtractRecord (zh, buf, buf_size, rGroup,
- 0, // delete_flag
- 0, // test_mode,
- recordType,
- &sysno,
- match, fname);
- zebra_end_trans(zh);
- return sysno;
-}
-
-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)
-{
- int res;
-
- if (buf_size < 1) buf_size = strlen(buf);
-
- zebra_begin_trans(zh);
- res=bufferExtractRecord (zh, buf, buf_size, rGroup,
- 1, // delete_flag
- 0, // test_mode,
- recordType,
- &sysno,
- match,fname);
- zebra_end_trans(zh);
- return sysno;
-}
-
-/* ---------------------------------------------------------------------------
- Searching
-
- zebra_search_RPN is the same as zebra_search_rpn, except that read locking
- is not mandatory. (it's repeatable now, also in zebraapi.c)
-*/
-
-void zebra_search_RPN (ZebraHandle zh, ODR decode, ODR stream,
- Z_RPNQuery *query, const char *setname, int *hits)
-{
- zh->hits = 0;
- *hits = 0;
-
- if (zebra_begin_read (zh))
- return;
- resultSetAddRPN (zh, decode, stream, query,
- zh->num_basenames, zh->basenames, setname);
-
- zebra_end_read (zh);
-
- *hits = zh->hits;
-}
-
-int zebra_search_PQF (ZebraHandle zh,
- ODR odr_input, ODR odr_output,
- const char *pqf_query,
- const char *setname)
-
-{
- int hits;
- Z_RPNQuery *query;
- query = p_query_rpn (odr_input, PROTO_Z3950, pqf_query);
-
- if (!query) {
- logf (LOG_WARN, "bad query %s\n", pqf_query);
- odr_reset (odr_input);
- return(0);
- }
- zebra_search_RPN (zh, odr_input, odr_output, query, setname, &hits);
-
- odr_reset (odr_input);
- odr_reset (odr_output);
-
- return(hits);
-}
-
-int zebra_cql2pqf (cql_transform_t ct,
- const char *query, char *res, int len) {
-
- int status;
- const char *addinfo = "";
- CQL_parser cp = cql_parser_create();
-
- if (status = cql_parser_string(cp, query)) {
- cql_parser_destroy(cp);
- return (status);
- }
-
- if (cql_transform_buf(ct, cql_parser_result(cp), res, len)) {
- status = cql_transform_error(ct, &addinfo);
- logf (LOG_WARN,"Transform error %d %s\n", status, addinfo ? addinfo : "");
- cql_parser_destroy(cp);
- return (status);
- }
-
- cql_parser_destroy(cp);
- return (0);
-}
-
-void zebra_scan_PQF (ZebraHandle zh,
- ScanObj *so,
- ODR stream,
- const char *pqf_query)
-{
- Z_AttributesPlusTerm *zapt;
- Odr_oid *attrsetid;
- const char* oidname;
- oid_value attributeset;
- ZebraScanEntry *entries;
- int i, class;
-
- logf(LOG_DEBUG,
- "scan req: pos:%d, num:%d, partial:%d",
- so->position, so->num_entries, so->is_partial);
-
- zapt = p_query_scan (stream, PROTO_Z3950, &attrsetid, pqf_query);
-
- oidname = yaz_z3950oid_to_str (attrsetid, &class);
- logf (LOG_DEBUG, "Attributreset: %s", oidname);
- attributeset = oid_getvalbyname(oidname);
-
- if (!zapt) {
- logf (LOG_WARN, "bad query %s\n", pqf_query);
- odr_reset (stream);
- return;
- }
-
- so->entries = (scanEntry *)
- odr_malloc (stream, sizeof(so->entries) * (so->num_entries));
-
-
- zebra_scan (zh, stream, zapt, attributeset,
- &so->position, &so->num_entries,
- (ZebraScanEntry **) &so->entries, &so->is_partial);
-
- logf(LOG_DEBUG,
- "scan res: pos:%d, num:%d, partial:%d",
- so->position, so->num_entries, so->is_partial);
-}
-
-scanEntry *getScanEntry(ScanObj *so, int pos) {
- return (&so->entries[pos-1]);
-}
-
-/* ---------------------------------------------------------------------------
- Record retrieval
- 2 phase retrieval - I didn't manage to return array of blessed references
- to wrapped structures... it's feasible, but I'll need some time
- / pop - 2002-11-17
-*/
-
-void record_retrieve(RetrievalObj *ro,
- ODR stream,
- RetrievalRecord *res,
- int pos)
-{
- int i = pos - 1;
-
-
- RetrievalRecordBuf *buf =
- (RetrievalRecordBuf *) odr_malloc(stream, sizeof(*buf));
-
- res->errCode = ro->records[i].errCode;
- if (ro->records[i].errString) {
- res->errString = odr_strdup(stream, ro->records[i].errString);
- } else {
- res->errString = "";
- }
- res->position = ro->records[i].position;
- res->base = ro->records[i].base;
- res->format = (char *)
- yaz_z3950_oid_value_to_str(ro->records[i].format, CLASS_RECSYN);
- res->buf = buf;
- res->buf->len = ro->records[i].len;
- res->buf->buf = ro->records[i].buf;
- res->score = ro->records[i].score;
- res->sysno = ro->records[i].sysno;
-
-}
-
-/* most of the code here was copied from yaz-client */
-void records_retrieve(ZebraHandle zh,
- ODR stream,
- const char *setname,
- const char *a_eset,
- const char *a_schema,
- const char *a_format,
- int from,
- int to,
- RetrievalObj *res)
-{
- static enum oid_value recordsyntax = VAL_SUTRS;
- static enum oid_value schema = VAL_NONE;
- static Z_ElementSetNames *elementSetNames = 0;
- static Z_RecordComposition compo;
- static Z_ElementSetNames esn;
- static char what[100];
- int i;
- int oid[OID_SIZE];
-
- compo.which = -1;
-
- if (from < 1) from = 1;
- if (from > to) to = from;
- res->noOfRecords = to - from + 1;
-
- res->records = odr_malloc (stream,
- sizeof(*res->records) * (res->noOfRecords));
-
- for (i = 0; i<res->noOfRecords; i++) res->records[i].position = from+i;
-
- if (!a_eset || !*a_eset) {
- elementSetNames = 0;
- } else {
- strcpy(what, a_eset);
- esn.which = Z_ElementSetNames_generic;
- esn.u.generic = what;
- elementSetNames = &esn;
- }
-
- if (!a_schema || !*a_schema) {
- schema = VAL_NONE;
- } else {
- schema = oid_getvalbyname (a_schema);
- if (schema == VAL_NONE) {
- logf(LOG_WARN,"unknown schema '%s'",a_schema);
- }
- }
-
-
- if (!a_format || !*a_format) {
- recordsyntax = VAL_SUTRS;
- } else {
- recordsyntax = oid_getvalbyname (a_format);
- if (recordsyntax == VAL_NONE) {
- logf(LOG_WARN,"unknown record syntax '%s', using SUTRS",a_schema);
- recordsyntax = VAL_SUTRS;
- }
- }
-
- if (schema != VAL_NONE) {
- oident prefschema;
-
- prefschema.proto = PROTO_Z3950;
- prefschema.oclass = CLASS_SCHEMA;
- prefschema.value = schema;
-
- compo.which = Z_RecordComp_complex;
- compo.u.complex = (Z_CompSpec *)
- odr_malloc(stream, sizeof(*compo.u.complex));
- compo.u.complex->selectAlternativeSyntax = (bool_t *)
- odr_malloc(stream, sizeof(bool_t));
- *compo.u.complex->selectAlternativeSyntax = 0;
-
- compo.u.complex->generic = (Z_Specification *)
- odr_malloc(stream, sizeof(*compo.u.complex->generic));
- compo.u.complex->generic->which = Z_Schema_oid;
- compo.u.complex->generic->schema.oid = (Odr_oid *)
- odr_oiddup(stream, oid_ent_to_oid(&prefschema, oid));
- if (!compo.u.complex->generic->schema.oid)
- {
- /* OID wasn't a schema! Try record syntax instead. */
- prefschema.oclass = CLASS_RECSYN;
- compo.u.complex->generic->schema.oid = (Odr_oid *)
- odr_oiddup(stream, oid_ent_to_oid(&prefschema, oid));
- }
- if (!elementSetNames)
- compo.u.complex->generic->elementSpec = 0;
- else
- {
- compo.u.complex->generic->elementSpec = (Z_ElementSpec *)
- odr_malloc(stream, sizeof(Z_ElementSpec));
- compo.u.complex->generic->elementSpec->which =
- Z_ElementSpec_elementSetName;
- compo.u.complex->generic->elementSpec->u.elementSetName =
- elementSetNames->u.generic;
- }
- compo.u.complex->num_dbSpecific = 0;
- compo.u.complex->dbSpecific = 0;
- compo.u.complex->num_recordSyntax = 0;
- compo.u.complex->recordSyntax = 0;
- }
- else if (elementSetNames) {
- compo.which = Z_RecordComp_simple;
- compo.u.simple = elementSetNames;
- }
-
- if (compo.which == -1) {
- api_records_retrieve (zh, stream, setname,
- NULL,
- recordsyntax,
- res->noOfRecords, res->records);
- } else {
- api_records_retrieve (zh, stream, setname,
- &compo,
- recordsyntax,
- res->noOfRecords, res->records);
- }
-
-}
-
-int zebra_trans_no (ZebraHandle zh) {
- return (zh->trans_no);
-}
-
-/* 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,
- const char *setname, Z_RecordComposition *comp,
- oid_value input_format, int num_recs,
- ZebraRetrievalRecord *recs)
-{
- ZebraPosSet poset;
- int i, *pos_array;
-
- if (!zh->res)
- {
- zh->errCode = 30;
- zh->errString = odr_strdup (stream, setname);
- return;
- }
-
- zh->errCode = 0;
-
- if (zebra_begin_read (zh))
- return;
-
- pos_array = (int *) xmalloc (num_recs * sizeof(*pos_array));
- for (i = 0; i<num_recs; i++)
- pos_array[i] = recs[i].position;
- poset = zebraPosSetCreate (zh, setname, num_recs, pos_array);
- if (!poset)
- {
- logf (LOG_DEBUG, "zebraPosSetCreate error");
- zh->errCode = 30;
- zh->errString = nmem_strdup (stream->mem, setname);
- }
- else
- {
- for (i = 0; i<num_recs; i++)
- {
- if (poset[i].term)
- {
- recs[i].errCode = 0;
- recs[i].format = VAL_SUTRS;
- recs[i].len = strlen(poset[i].term);
- recs[i].buf = poset[i].term;
- recs[i].base = poset[i].db;
- recs[i].sysno = 0;
-
- }
- else if (poset[i].sysno)
- {
- /* changed here ??? CHECK ??? */
- char *b;
- recs[i].errCode =
- zebra_record_fetch (zh, poset[i].sysno, poset[i].score,
- stream, input_format, comp,
- &recs[i].format,
- &b,
- &recs[i].len,
- &recs[i].base);
- recs[i].buf = (char *) odr_malloc(stream,recs[i].len);
- memcpy(recs[i].buf, b, recs[i].len);
- recs[i].errString = 0; /* Hmmm !!! we should get this */
- recs[i].sysno = poset[i].sysno;
- recs[i].score = poset[i].score;
- }
- else
- {
- char num_str[20];
-
- sprintf (num_str, "%d", pos_array[i]);
- zh->errCode = 13;
- zh->errString = odr_strdup (stream, num_str);
- break;
- }
-
- }
- zebraPosSetDestroy (zh, poset, num_recs);
- }
- zebra_end_read (zh);
- xfree (pos_array);
-}
-
-
-/* ---------------------------------------------------------------------------
- Sort - a simplified interface, with optional read locks.
-*/
-int sort (ZebraHandle zh,
- ODR stream,
- const char *sort_spec,
- const char *output_setname,
- const char **input_setnames
- )
-{
- int num_input_setnames = 0;
- int sort_status = 0;
- Z_SortKeySpecList *sort_sequence = yaz_sort_spec (stream, sort_spec);
- if (!sort_sequence) {
- logf(LOG_WARN,"invalid sort specs '%s'", sort_spec);
- zh->errCode = 207;
- return (-1);
- }
-
- /* we can do this, since the typemap code for char** will
- put a NULL at the end of list */
- while (input_setnames[num_input_setnames]) num_input_setnames++;
-
- if (zebra_begin_read (zh))
- return;
-
- resultSetSort (zh, stream->mem, num_input_setnames, input_setnames,
- output_setname, sort_sequence, &sort_status);
-
- zebra_end_read(zh);
- return (sort_status);
-}
#include <yaz/yaz-util.h>
#include <yaz/proto.h>
+#include <yaz/log.h>
+#include <yaz/cql.h>
+#include <yaz/pquery.h>
+
#include "zebra_perl.h"
#include <data1.h>
-#include <yaz/log.h>
NMEM handles;
logf(level, "%s", message);
}
-void zts_test (ZebraTransactionStatus *stat) {
- stat->processed++;
+/* debug tool for data1... maybe should be moved to data1.
+ perl can't really pass filehandles */
+void data1_print_tree(data1_handle dh, data1_node *n) {
+ data1_pr_tree(dh, n, stdout);
}
+
+/* ---------------------------------------------------------------------------
+ Record retrieval
+ 2 phase retrieval - I didn't manage to return array of blessed references
+ to wrapped structures... it's feasible, but I'll need some time
+ / pop - 2002-11-17
+*/
+
+void record_retrieve(RetrievalObj *ro,
+ ODR stream,
+ RetrievalRecord *res,
+ int pos)
+{
+ int i = pos - 1;
+
+
+ RetrievalRecordBuf *buf =
+ (RetrievalRecordBuf *) odr_malloc(stream, sizeof(*buf));
+
+ res->errCode = ro->records[i].errCode;
+ if (ro->records[i].errString) {
+ res->errString = odr_strdup(stream, ro->records[i].errString);
+ } else {
+ res->errString = "";
+ }
+ res->position = ro->records[i].position;
+ res->base = ro->records[i].base;
+ res->format = (char *)
+ yaz_z3950_oid_value_to_str(ro->records[i].format, CLASS_RECSYN);
+ res->buf = buf;
+ res->buf->len = ro->records[i].len;
+ res->buf->buf = ro->records[i].buf;
+ res->score = ro->records[i].score;
+ res->sysno = ro->records[i].sysno;
+
+}
+
+
+
+/* most of the code here was copied from yaz-client */
+void records_retrieve(ZebraHandle zh,
+ ODR stream,
+ const char *setname,
+ const char *a_eset,
+ const char *a_schema,
+ const char *a_format,
+ int from,
+ int to,
+ RetrievalObj *res)
+{
+ static enum oid_value recordsyntax = VAL_SUTRS;
+ static enum oid_value schema = VAL_NONE;
+ static Z_ElementSetNames *elementSetNames = 0;
+ static Z_RecordComposition compo;
+ static Z_ElementSetNames esn;
+ static char what[100];
+ int i;
+ int oid[OID_SIZE];
+
+ compo.which = -1;
+
+ if (from < 1) from = 1;
+ if (from > to) to = from;
+ res->noOfRecords = to - from + 1;
+
+ res->records = odr_malloc (stream,
+ sizeof(*res->records) * (res->noOfRecords));
+
+ for (i = 0; i<res->noOfRecords; i++) res->records[i].position = from+i;
+
+ if (!a_eset || !*a_eset) {
+ elementSetNames = 0;
+ } else {
+ strcpy(what, a_eset);
+ esn.which = Z_ElementSetNames_generic;
+ esn.u.generic = what;
+ elementSetNames = &esn;
+ }
+
+ if (!a_schema || !*a_schema) {
+ schema = VAL_NONE;
+ } else {
+ schema = oid_getvalbyname (a_schema);
+ if (schema == VAL_NONE) {
+ logf(LOG_WARN,"unknown schema '%s'",a_schema);
+ }
+ }
+
+
+ if (!a_format || !*a_format) {
+ recordsyntax = VAL_SUTRS;
+ } else {
+ recordsyntax = oid_getvalbyname (a_format);
+ if (recordsyntax == VAL_NONE) {
+ logf(LOG_WARN,"unknown record syntax '%s', using SUTRS",a_schema);
+ recordsyntax = VAL_SUTRS;
+ }
+ }
+
+ if (schema != VAL_NONE) {
+ oident prefschema;
+
+ prefschema.proto = PROTO_Z3950;
+ prefschema.oclass = CLASS_SCHEMA;
+ prefschema.value = schema;
+
+ compo.which = Z_RecordComp_complex;
+ compo.u.complex = (Z_CompSpec *)
+ odr_malloc(stream, sizeof(*compo.u.complex));
+ compo.u.complex->selectAlternativeSyntax = (bool_t *)
+ odr_malloc(stream, sizeof(bool_t));
+ *compo.u.complex->selectAlternativeSyntax = 0;
+
+ compo.u.complex->generic = (Z_Specification *)
+ odr_malloc(stream, sizeof(*compo.u.complex->generic));
+ compo.u.complex->generic->which = Z_Schema_oid;
+ compo.u.complex->generic->schema.oid = (Odr_oid *)
+ odr_oiddup(stream, oid_ent_to_oid(&prefschema, oid));
+ if (!compo.u.complex->generic->schema.oid)
+ {
+ /* OID wasn't a schema! Try record syntax instead. */
+ prefschema.oclass = CLASS_RECSYN;
+ compo.u.complex->generic->schema.oid = (Odr_oid *)
+ odr_oiddup(stream, oid_ent_to_oid(&prefschema, oid));
+ }
+ if (!elementSetNames)
+ compo.u.complex->generic->elementSpec = 0;
+ else
+ {
+ compo.u.complex->generic->elementSpec = (Z_ElementSpec *)
+ odr_malloc(stream, sizeof(Z_ElementSpec));
+ compo.u.complex->generic->elementSpec->which =
+ Z_ElementSpec_elementSetName;
+ compo.u.complex->generic->elementSpec->u.elementSetName =
+ elementSetNames->u.generic;
+ }
+ compo.u.complex->num_dbSpecific = 0;
+ compo.u.complex->dbSpecific = 0;
+ compo.u.complex->num_recordSyntax = 0;
+ compo.u.complex->recordSyntax = 0;
+ }
+ else if (elementSetNames) {
+ compo.which = Z_RecordComp_simple;
+ compo.u.simple = elementSetNames;
+ }
+
+ if (compo.which == -1) {
+ api_records_retrieve (zh, stream, setname,
+ NULL,
+ recordsyntax,
+ res->noOfRecords, res->records);
+ } else {
+ api_records_retrieve (zh, stream, setname,
+ &compo,
+ recordsyntax,
+ res->noOfRecords, res->records);
+ }
+
+}
+
+int zebra_cql2pqf (cql_transform_t ct,
+ const char *query, char *res, int len) {
+
+ int status;
+ const char *addinfo = "";
+ CQL_parser cp = cql_parser_create();
+
+ if (status = cql_parser_string(cp, query)) {
+ cql_parser_destroy(cp);
+ return (status);
+ }
+
+ if (cql_transform_buf(ct, cql_parser_result(cp), res, len)) {
+ status = cql_transform_error(ct, &addinfo);
+ logf (LOG_WARN,"Transform error %d %s\n", status, addinfo ? addinfo : "");
+ cql_parser_destroy(cp);
+ return (status);
+ }
+
+ cql_parser_destroy(cp);
+ return (0);
+}
+
+void zebra_scan_PQF (ZebraHandle zh,
+ ScanObj *so,
+ ODR stream,
+ const char *pqf_query)
+{
+ Z_AttributesPlusTerm *zapt;
+ Odr_oid *attrsetid;
+ const char* oidname;
+ oid_value attributeset;
+ ZebraScanEntry *entries;
+ int i, class;
+
+ logf(LOG_DEBUG,
+ "scan req: pos:%d, num:%d, partial:%d",
+ so->position, so->num_entries, so->is_partial);
+
+ zapt = p_query_scan (stream, PROTO_Z3950, &attrsetid, pqf_query);
+
+ oidname = yaz_z3950oid_to_str (attrsetid, &class);
+ logf (LOG_DEBUG, "Attributreset: %s", oidname);
+ attributeset = oid_getvalbyname(oidname);
+
+ if (!zapt) {
+ logf (LOG_WARN, "bad query %s\n", pqf_query);
+ odr_reset (stream);
+ return;
+ }
+
+ so->entries = (scanEntry *)
+ odr_malloc (stream, sizeof(so->entries) * (so->num_entries));
+
+
+ zebra_scan (zh, stream, zapt, attributeset,
+ &so->position, &so->num_entries,
+ (ZebraScanEntry **) &so->entries, &so->is_partial);
+
+ logf(LOG_DEBUG,
+ "scan res: pos:%d, num:%d, partial:%d",
+ so->position, so->num_entries, so->is_partial);
+}
+
+scanEntry *getScanEntry(ScanObj *so, int pos) {
+ return (&so->entries[pos-1]);
+}
+
#define ZEBRA_PERL_H
#include "zebraapi.h"
-#include "zebra_api_ext.h"
typedef struct {
char *groupName;
} RetrievalObj;
typedef struct {
+ char *buf; /* record buffer (void pointer really) */
+ int len; /* length */
+} RetrievalRecordBuf;
+
+
+typedef struct {
int errCode; /* non-zero if error when fetching this */
char *errString; /* error string */
int position; /* position of record in result set (1,2,..) */