X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=perl%2FIDZebra.i;h=8b5f86e7d272f31aaf8de839546ab1d17c629f51;hb=4cea1b9769079a2cdc143f4fe483e69d5b77a813;hp=89020a76a645f5a74c52eef21373e9604474a358;hpb=806749525584c7598f8f239a6941ec5294547a20;p=idzebra-moved-to-github.git diff --git a/perl/IDZebra.i b/perl/IDZebra.i index 89020a7..8b5f86e 100644 --- a/perl/IDZebra.i +++ b/perl/IDZebra.i @@ -1,17 +1,58 @@ %module "IDZebra" +%include typemaps.i // Load the typemaps librayr -/* Module initialization and cleanup */ %{ -#include "zebraapi.h" -#include "rg.h" -#include "data1.h" +#include +#include "zebra_perl.h" +#include #include "yaz/odr.h" +#include "yaz/cql.h" %} -%include "rg.h" +/* == Typemaps ============================================================= */ -/* ----------------------------------------------------------------------------------- */ +%typemap(in) int * { + int i; + if (!SvIOK($input)) + croak("Argument $argnum is not an integer."); + i = SvIV($input); + $1 = &i; +} + +%typemap(out) int * { + $result=newSViv($1) + sv_2mortal($result); + argvi++; +} + +/* * * * * * Fix for broken swig implementation */ +%typemap(argout) long long *INOUT { + char temp[256]; + if (argvi >= items) { + EXTEND(sp,1); + } + /* sprintf(temp,"%lld", $1); */ + sprintf(temp,"%lld", *$1); + $result = sv_newmortal(); + sv_setpv($result,temp); + argvi++; +} + + +/* RetrievalRecordBuff is a special construct, to allow to map a char * buf + to non-null terminated perl string scalar value (SVpv). */ +%typemap(out) RetrievalRecordBuf * { + if ($1->len) { + $result = newSVpv($1->buf,$1->len); + } else { + $result = newSVpv("",0); + } + sv_2mortal($result); + argvi++; +} + +/* All char ** values are mapped in-out to array of strings. */ %typemap(in) char ** { AV *tempav; I32 len; @@ -32,53 +73,110 @@ $1[i] = NULL; }; -// This cleans up the char ** array after the function call +/* This cleans up the char ** array after the function call */ %typemap(freearg) char ** { free($1); } -// Creates a new Perl array and places a NULL-terminated char ** into it +/* Creates a new Perl array and places a NULL-terminated char ** into it */ %typemap(out) char ** { - AV *myav; - SV **svs; - int i = 0,len = 0; - /* Figure out how many elements we have */ - while ($1[len]) - len++; - svs = (SV **) malloc(len*sizeof(SV *)); - for (i = 0; i < len ; i++) { - svs[i] = sv_newmortal(); - sv_setpv((SV*)svs[i],$1[i]); - }; - myav = av_make(len,svs); - free(svs); + AV *myav; + SV **svs; + int i = 0,len = 0; + /* Figure out how many elements we have */ + while ($1[len]) + len++; + svs = (SV **) malloc(len*sizeof(SV *)); + for (i = 0; i < len ; i++) { + svs[i] = sv_newmortal(); + sv_setpv((SV*)svs[i],$1[i]); + }; + myav = av_make(len,svs); + free(svs); $result = newRV((SV*)myav); sv_2mortal($result); argvi++; } -/* ----------------------------------------------------------------------------------- */ + +/* == Structures for shadow classes ======================================= */ + + +/*%include "zebra_perl.h" */ + +typedef struct { + int noOfRecords; + ZebraRetrievalRecord *records; +} RetrievalObj; + +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,..) */ + char *base; + long long sysno; + int score; + char *format; /* record syntax */ + RetrievalRecordBuf *buf; +} RetrievalRecord; + +/* Scan Term Descriptor */ +typedef struct { + int occurrences; /* scan term occurrences */ + char *term; /* scan term string */ +} scanEntry; + +typedef struct { + int num_entries; + int position; + int is_partial; + scanEntry *entries; +} ScanObj; + + +typedef struct { + int processed; + int inserted; + int updated; + int deleted; + long utime; + long stime; +} ZebraTransactionStatus; + +/* == Module initialization and cleanup (zebra_perl.c) ===================== */ void init (void); void DESTROY (void); -/* Logging facilities from yaz */ -void logLevel (int level); -void logFile (const char *fname); +/* == Logging facilities (yaz/log.h) ======================================= */ + +%name(logLevel) +void yaz_log_init_level (int level); + +%name(logFile) +void yaz_log_init_file (const char *fname); + +%name(logMsg) void logMsg (int level, const char *message); +%name(logPrefix) +void yaz_log_init_prefix (const char *prefix); + +%name(logPrefix2) +void yaz_log_init_prefix2 (const char *prefix); + #define LOG_FATAL 0x0001 #define LOG_DEBUG 0x0002 #define LOG_WARN 0x0004 #define LOG_LOG 0x0008 #define LOG_ERRNO 0x0010 /* append strerror to message */ #define LOG_FILE 0x0020 -#define LOG_APP 0x0040 /* For application level events such as new-connection */ +#define LOG_APP 0x0040 /* For application level events */ #define LOG_MALLOC 0x0080 /* debugging mallocs */ -#define LOG_ALL 0xff7f +#define LOG_ALL 0xff7f #define LOG_DEFAULT_LEVEL (LOG_FATAL | LOG_ERRNO | LOG_LOG | LOG_WARN) +/* == ODR stuff (yaz/odr.h) ================================================ */ -/* ODR stuff */ #define ODR_DECODE 0 #define ODR_ENCODE 1 #define ODR_PRINT 2 @@ -87,90 +185,231 @@ void odr_reset(ODR o); void odr_destroy(ODR o); void *odr_malloc(ODR o, int size); -/* Session and service */ -%name(start) ZebraService zebra_start (const char *configName); -%name(open) ZebraHandle zebra_open (ZebraService zs); -%name(close) void zebra_close (ZebraHandle zh); -%name(stop) void zebra_stop (ZebraService zs); - - -/* Error handling and reporting */ -%name(errCode) int zebra_errCode (ZebraHandle zh); /* last error code */ -%name(errString) const char * zebra_errString (ZebraHandle zh); /* string representatio of above */ -%name(errAdd) char * zebra_errAdd (ZebraHandle zh); /* extra information associated with error */ - -/* Record groups */ -void describe_recordGroup (recordGroup *rg); -void init_recordGroup (recordGroup *rg); -void res_get_recordGroup (ZebraHandle zh, recordGroup *rg, const char *ext); -%name(set_group) void zebra_set_group (ZebraHandle zh, struct recordGroup *rg); -%name(select_databases) int zebra_select_databases (ZebraHandle zh, int num_bases, const char **basenames); -%name(select_database) int zebra_select_database (ZebraHandle zh, const char *basename); - -/* Transaction, shadow register */ -%name(begin_trans) void zebra_begin_trans (ZebraHandle zh); -%name(end_trans) void zebra_end_trans (ZebraHandle zh); -%name(commit) int zebra_commit (ZebraHandle zh); -%name(get_shadow_enable) int zebra_get_shadow_enable (ZebraHandle zh); -%name(set_shadow_enable) void zebra_set_shadow_enable (ZebraHandle zh, int value); - -/* Repository actions */ -%name(init) int zebra_init (ZebraHandle zh); -%name(compact) int zebra_compact (ZebraHandle zh); -%name(repository_update) void zebra_repository_update (ZebraHandle zh); -%name(repository_delete) void zebra_repository_delete (ZebraHandle zh); -%name(repository_show) void zebra_repository_show (ZebraHandle zh); -%name(update_record) int zebra_update_record (ZebraHandle zh, - recordGroup *rGroup, - int sysno, const char *match, const char *fname, - const char *buf, int buf_size); -%name(delete_record) int zebra_delete_record (ZebraHandle zh, - recordGroup *rGroup, - int sysno, const char *match, const char *fname, - const char *buf, int buf_size); - -/* Search and retrieval */ -%name(begin_read) int zebra_begin_read (ZebraHandle zh); -%name(end_read) void zebra_end_read (ZebraHandle zh); -%name(search_PQF) int zebra_search_PQF (ZebraHandle zh, - ODR odr_input, ODR odr_output, - const char *pqf_query, - const char *setname); -/* Admin functionality */ -%name(admin_start) void zebra_admin_start (ZebraHandle zh); -%name(admin_shutdown) void zebra_admin_shutdown (ZebraHandle zh); +/* == Zebra session and service (index/zebraapi.c) ========================= */ +%name(start) +ZebraService zebra_start (const char *configName); -/* Search using RPN-Query -YAZ_EXPORT void zebra_search_rpn (ZebraHandle zh, ODR input, ODR output, - Z_RPNQuery *query, - const char *setname, int *hits); -*/ +%name(open) +ZebraHandle zebra_open (ZebraService zs); -/* Retrieve record(s) -void zebra_records_retrieve (ZebraHandle zh, ODR stream, - const char *setname, Z_RecordComposition *comp, - oid_value input_format, - int num_recs, ZebraRetrievalRecord *recs); -*/ +%name(close) +void zebra_close (ZebraHandle zh); -/* Browse -void zebra_scan (ZebraHandle zh, ODR stream, - Z_AttributesPlusTerm *zapt, - oid_value attributeset, - int *position, int *num_entries, - ZebraScanEntry **list, - int *is_partial); -*/ +%name(stop) +void zebra_stop (ZebraService zs); -/* Delete Result Set(s) */ -/* + +/* == Error handling and reporting (index/zebraapi.c) ====================== */ + +/* last error code */ +%name(errCode) +int zebra_errCode (ZebraHandle zh); + +/* string representatio of above */ +%name(errString) +const char * zebra_errString (ZebraHandle zh); + +/* extra information associated with error */ +%name(errAdd) +char * zebra_errAdd (ZebraHandle zh); + + +/* == Zebra resources and database selection =============================== */ + +/* set a resource */ +%name(set_resource) +void zebra_set_resource(ZebraHandle zh, const char *name, const char *value); + +/* get a resource */ +%name(get_resource) +const char *zebra_set_resource(ZebraHandle zh, const char *name, + const char *defaultvalue); + +/* select database for update purposes (zebraapi.c) */ +%name(select_database) +int zebra_select_database (ZebraHandle zh, const char *basename); + +/* select databases for record retrieval (zebraapi.c) */ +%name(select_databases) +int zebra_select_databases (ZebraHandle zh, int num_bases, + const char **basenames); + + +/* == Transactions, locking, shadow register =============================== */ + +/* begin transaction (add write lock) (zebraapi.c) */ +%name(begin_trans) +int zebra_begin_trans (ZebraHandle zh, int rw); + +/* end transaction (remove write lock) (zebraapi.c) */ +%name(end_trans) +void zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *stat); + +%name(trans_no) +int zebra_trans_no (ZebraHandle zh); + +/* commit changes from shadow (zebraapi.c) */ +%name(commit) +int zebra_commit (ZebraHandle zh); + +/* get shadow status (zebra_api_ext.c) */ +%name(get_shadow_enable) +int zebra_get_shadow_enable (ZebraHandle zh); + +/* set shadow status (zebra_api_ext.c) */ +%name(set_shadow_enable) +void zebra_set_shadow_enable (ZebraHandle zh, int value); + + +/* == Repository actions (zebraapi.c) ====================================== */ + +%name(init) +int zebra_init (ZebraHandle zh); + +%name(compact) +int zebra_compact (ZebraHandle zh); + +%name(repository_update) +void zebra_repository_update (ZebraHandle zh, const char *path); + +%name(repository_delete) +void zebra_repository_delete (ZebraHandle zh, const char *path); + +%name(repository_show) +void zebra_repository_show (ZebraHandle zh, const char *path); + + +/* == Record update/delete (zebra_api_ext.c) =============================== */ + +/* 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 */ + +%apply long long *INOUT { long long *sysno }; + +%name(insert_record) +int zebra_insert_record (ZebraHandle zh, + const char *recordType, + long long *sysno, + const char *match, + const char *fname, + const char *buf, + int buf_size, + int force_update); +/* actually, sysno is only output param in insert_record, but kept */ +/* as inout for symmetry in the interface. The session class assures */ +/* that nothing goes in... */ + + +%name(update_record) +int zebra_update_record (ZebraHandle zh, + const char *recordType, + long long *sysno, + const char *match, + const char *fname, + const char *buf, + int buf_size, + int force_update); + +%name(delete_record) +int zebra_delete_record (ZebraHandle zh, + const char *recordType, + long long *sysno, + const char *match, + const char *fname, + const char *buf, + int buf_size, + int force_update); + +/* == Search (zebraapi.c) ================================================== */ +%include "typemaps.i" +%apply int *REFERENCE { int *hits }; +%name(search_PQF) +int zebra_search_PQF (ZebraHandle zh, + const char *pqf_query, + const char *setname, + int *hits); + +/* == YAZ - query tools ==================================================== */ + + +cql_transform_t cql_transform_open_fname(const char *fname); +void cql_transform_close(cql_transform_t ct); +int cql_transform_error(cql_transform_t ct, const char **addinfo); + +%name(cql2pqf) +int zebra_cql2pqf (cql_transform_t ct, + const char *query, char *res, int len); + +/* == Retrieval (zebra_api_ext.c) ========================================== */ + +/* will get a 'retrieval obj' (simple enough to pass to perl), which can be + used to get the individual records. Elementset, schema and format strings + are threated the same way yaz-client does. */ +void records_retrieve(ZebraHandle zh, + ODR stream, + const char *setname, // resultset name + const char *a_eset, // optional elementset + const char *a_schema, // optional schema + const char *a_format, // optional record syntax + int from, // range, 1 based + int to, + RetrievalObj *res + ); + +/* fetch a record from the retrieval object. pos is 1 based */ +void record_retrieve(RetrievalObj *ro, + ODR stream, + RetrievalRecord *res, + int pos); + +/* Delete Result Set(s) (zebraapi.c) */ +%name(deleteResultSet) int zebra_deleleResultSet(ZebraHandle zh, int function, int num_setnames, char **setnames, int *statuses); + + +/* Resultset terms */ +/* disabled +%name(resultSetTerms) +int zebra_resultSetTerms (ZebraHandle zh, const char *setname, + int no, int *REFERENCE, + int *REFERENCE, char *out, int *REFERENCE); */ +/* == Sort ================================================================= */ +%name(sort) +int zebra_sort_by_specstr (ZebraHandle zh, + ODR stream, + const char *sort_spec, + const char *output_setname, + const char **input_setnames + ); + +/* == Scan ================================================================= */ +%name(scan_PQF) +void zebra_scan_PQF (ZebraHandle zh, + ScanObj *so, + ODR stream, + const char *pqf_query); + +scanEntry *getScanEntry(ScanObj *so, int pos); + +%typemap(in) int * (int dvalue); +%typemap(argout) int *; + + +/* Admin functionality */ +/* +%name(admin_start) void zebra_admin_start (ZebraHandle zh); +%name(admin_shutdown) void zebra_admin_shutdown (ZebraHandle zh); +*/ + + + /* do authentication */ /* int zebra_auth (ZebraHandle zh, const char *user, const char *pass); @@ -185,14 +424,6 @@ int zebra_resultSetTerms (ZebraHandle zh, const char *setname, int no, int *count, int *type, char *out, size_t *len); */ -/* -void zebra_sort (ZebraHandle zh, ODR stream, - int num_input_setnames, - const char **input_setnames, - const char *output_setname, - Z_SortKeySpecList *sort_sequence, - int *sort_status); -*/ /* YAZ_EXPORT void zebra_admin_create (ZebraHandle zh, const char *db); @@ -258,7 +489,7 @@ data1_handle data1_create (void); data1_handle data1_createx (int flags); void data1_destroy(data1_handle dh); -// Data1 node +/* Data1 node */ data1_node *get_parent_tag(data1_handle dh, data1_node *n); data1_node *data1_read_node(data1_handle dh, const char **buf,NMEM m); data1_node *data1_read_nodex (data1_handle dh, NMEM m, int (*get_byte)(void *fh), void *fh, WRBUF wrbuf); @@ -430,11 +661,13 @@ const char *data1_get_tabroot(data1_handle dh); * ========================================================================= */ int grs_perl_readf(struct perl_context *context, size_t len); +int grs_perl_readline(struct perl_context *context); +char grs_perl_getc(struct perl_context *context); off_t grs_perl_seekf(struct perl_context *context, off_t offset); off_t grs_perl_tellf(struct perl_context *context); void grs_perl_endf(struct perl_context *context, off_t offset); -data1_handle grs_perl_get_dh(struct perl_context *context); -NMEM grs_perl_get_mem(struct perl_context *context); +data1_handle *grs_perl_get_dh(struct perl_context *context); +NMEM *grs_perl_get_mem(struct perl_context *context); void grs_perl_set_res(struct perl_context *context, data1_node *n);