2 %include typemaps.i // Load the typemaps librayr
6 #include <idzebra/api.h>
7 #include "zebra_perl.h"
8 #include <idzebra/data1.h>
13 /* == Typemaps ============================================================= */
18 croak("Argument $argnum is not an integer.");
29 /* * * * * * Fix for broken swig implementation */
30 %typemap(argout) long long *INOUT {
35 /* sprintf(temp,"%lld", $1); */
36 sprintf(temp,"%lld", *$1);
37 $result = sv_newmortal();
38 sv_setpv($result,temp);
43 /* RetrievalRecordBuff is a special construct, to allow to map a char * buf
44 to non-null terminated perl string scalar value (SVpv). */
45 %typemap(out) RetrievalRecordBuf * {
47 $result = newSVpv($1->buf,$1->len);
49 $result = newSVpv("",0);
55 /* All char ** values are mapped in-out to array of strings. */
56 %typemap(in) char ** {
63 croak("Argument $argnum is not a reference.");
64 if (SvTYPE(SvRV($input)) != SVt_PVAV)
65 croak("Argument $argnum is not an array.");
66 tempav = (AV*)SvRV($input);
68 $1 = (char **) malloc((len+2)*sizeof(char *));
69 for (i = 0; i <= len; i++) {
70 tv = av_fetch(tempav, i, 0);
71 $1[i] = (char *) SvPV(*tv,na);
76 /* This cleans up the char ** array after the function call */
77 %typemap(freearg) char ** {
81 /* Creates a new Perl array and places a NULL-terminated char ** into it */
82 %typemap(out) char ** {
86 /* Figure out how many elements we have */
89 svs = (SV **) malloc(len*sizeof(SV *));
90 for (i = 0; i < len ; i++) {
91 svs[i] = sv_newmortal();
92 sv_setpv((SV*)svs[i],$1[i]);
94 myav = av_make(len,svs);
96 $result = newRV((SV*)myav);
101 /* == Structures for shadow classes ======================================= */
104 /*%include "zebra_perl.h" */
108 ZebraRetrievalRecord *records;
112 int errCode; /* non-zero if error when fetching this */
113 char *errString; /* error string */
114 int position; /* position of record in result set (1,2,..) */
118 char *format; /* record syntax */
119 RetrievalRecordBuf *buf;
122 /* Scan Term Descriptor */
124 int occurrences; /* scan term occurrences */
125 char *term; /* scan term string */
143 } ZebraTransactionStatus;
145 /* == Module initialization and cleanup (zebra_perl.c) ===================== */
150 /* == Logging facilities (yaz/log.h) ======================================= */
153 void yaz_log_init_level (int level);
156 void yaz_log_init_file (const char *fname);
159 void logMsg (int level, const char *message);
162 void yaz_log_init_prefix (const char *prefix);
165 void yaz_log_init_prefix2 (const char *prefix);
167 #define LOG_FATAL 0x0001
168 #define LOG_DEBUG 0x0002
169 #define LOG_WARN 0x0004
170 #define LOG_LOG 0x0008
171 #define LOG_ERRNO 0x0010 /* append strerror to message */
172 #define LOG_FILE 0x0020
173 #define LOG_APP 0x0040 /* For application level events */
174 #define LOG_MALLOC 0x0080 /* debugging mallocs */
175 #define LOG_ALL 0xff7f
176 #define LOG_DEFAULT_LEVEL (LOG_FATAL | LOG_ERRNO | LOG_LOG | LOG_WARN)
178 /* == ODR stuff (yaz/odr.h) ================================================ */
183 ODR odr_createmem(int direction);
184 void odr_reset(ODR o);
185 void odr_destroy(ODR o);
186 void *odr_malloc(ODR o, int size);
189 /* == Zebra session and service (index/zebraapi.c) ========================= */
192 ZebraService zebra_start (const char *configName);
195 ZebraHandle zebra_open (ZebraService zs);
198 void zebra_close (ZebraHandle zh);
201 void zebra_stop (ZebraService zs);
204 /* == Error handling and reporting (index/zebraapi.c) ====================== */
206 /* last error code */
208 int zebra_errCode (ZebraHandle zh);
210 /* string representatio of above */
212 const char * zebra_errString (ZebraHandle zh);
214 /* extra information associated with error */
216 char * zebra_errAdd (ZebraHandle zh);
219 /* == Zebra resources and database selection =============================== */
223 void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
227 const char *zebra_set_resource(ZebraHandle zh, const char *name,
228 const char *defaultvalue);
230 /* select database for update purposes (zebraapi.c) */
231 %name(select_database)
232 int zebra_select_database (ZebraHandle zh, const char *basename);
234 /* select databases for record retrieval (zebraapi.c) */
235 %name(select_databases)
236 int zebra_select_databases (ZebraHandle zh, int num_bases,
237 const char **basenames);
240 /* == Transactions, locking, shadow register =============================== */
242 /* begin transaction (add write lock) (zebraapi.c) */
244 int zebra_begin_trans (ZebraHandle zh, int rw);
246 /* end transaction (remove write lock) (zebraapi.c) */
248 void zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *stat);
251 int zebra_trans_no (ZebraHandle zh);
253 /* commit changes from shadow (zebraapi.c) */
255 int zebra_commit (ZebraHandle zh);
257 /* get shadow status (zebra_api_ext.c) */
258 %name(get_shadow_enable)
259 int zebra_get_shadow_enable (ZebraHandle zh);
261 /* set shadow status (zebra_api_ext.c) */
262 %name(set_shadow_enable)
263 void zebra_set_shadow_enable (ZebraHandle zh, int value);
266 /* == Repository actions (zebraapi.c) ====================================== */
269 int zebra_init (ZebraHandle zh);
272 int zebra_compact (ZebraHandle zh);
274 %name(repository_update)
275 void zebra_repository_update (ZebraHandle zh, const char *path);
277 %name(repository_delete)
278 void zebra_repository_delete (ZebraHandle zh, const char *path);
280 %name(repository_show)
281 void zebra_repository_show (ZebraHandle zh, const char *path);
284 /* == Record update/delete (zebra_api_ext.c) =============================== */
286 /* If sysno is provided, then it's used to identify the reocord.
287 If not, and match_criteria is provided, then sysno is guessed
288 If not, and a record is provided, then sysno is got from there */
290 %apply long long *INOUT { long long *sysno };
293 int zebra_insert_record (ZebraHandle zh,
294 const char *recordType,
301 /* actually, sysno is only output param in insert_record, but kept */
302 /* as inout for symmetry in the interface. The session class assures */
303 /* that nothing goes in... */
307 int zebra_update_record (ZebraHandle zh,
308 const char *recordType,
317 int zebra_delete_record (ZebraHandle zh,
318 const char *recordType,
326 /* == Search (zebraapi.c) ================================================== */
327 %include "typemaps.i"
328 %apply int *REFERENCE { int *hits };
330 int zebra_search_PQF (ZebraHandle zh,
331 const char *pqf_query,
335 /* == YAZ - query tools ==================================================== */
338 cql_transform_t cql_transform_open_fname(const char *fname);
339 void cql_transform_close(cql_transform_t ct);
340 int cql_transform_error(cql_transform_t ct, const char **addinfo);
343 int zebra_cql2pqf (cql_transform_t ct,
344 const char *query, char *res, int len);
346 /* == Retrieval (zebra_api_ext.c) ========================================== */
348 /* will get a 'retrieval obj' (simple enough to pass to perl), which can be
349 used to get the individual records. Elementset, schema and format strings
350 are threated the same way yaz-client does. */
351 void records_retrieve(ZebraHandle zh,
353 const char *setname, // resultset name
354 const char *a_eset, // optional elementset
355 const char *a_schema, // optional schema
356 const char *a_format, // optional record syntax
357 int from, // range, 1 based
362 /* fetch a record from the retrieval object. pos is 1 based */
363 void record_retrieve(RetrievalObj *ro,
365 RetrievalRecord *res,
368 /* Delete Result Set(s) (zebraapi.c) */
369 %name(deleteResultSet)
370 int zebra_deleleResultSet(ZebraHandle zh, int function,
371 int num_setnames, char **setnames,
375 /* Resultset terms */
377 %name(resultSetTerms)
378 int zebra_resultSetTerms (ZebraHandle zh, const char *setname,
379 int no, int *REFERENCE,
380 int *REFERENCE, char *out, int *REFERENCE);
383 /* == Sort ================================================================= */
385 int zebra_sort_by_specstr (ZebraHandle zh,
387 const char *sort_spec,
388 const char *output_setname,
389 const char **input_setnames
392 /* == Scan ================================================================= */
394 void zebra_scan_PQF (ZebraHandle zh,
397 const char *pqf_query);
399 scanEntry *getScanEntry(ScanObj *so, int pos);
401 %typemap(in) int * (int dvalue);
402 %typemap(argout) int *;
405 /* Admin functionality */
407 %name(admin_start) void zebra_admin_start (ZebraHandle zh);
408 %name(admin_shutdown) void zebra_admin_shutdown (ZebraHandle zh);
413 /* do authentication */
415 int zebra_auth (ZebraHandle zh, const char *user, const char *pass);
422 void zebra_result (ZebraHandle zh, int *code, char **addinfo);
423 int zebra_resultSetTerms (ZebraHandle zh, const char *setname,
425 int *type, char *out, size_t *len);
429 YAZ_EXPORT void zebra_admin_create (ZebraHandle zh, const char *db);
431 YAZ_EXPORT void zebra_admin_import_begin (ZebraHandle zh, const char *database);
433 YAZ_EXPORT void zebra_admin_import_segment (ZebraHandle zh,
436 void zebra_admin_shutdown (ZebraHandle zh);
437 void zebra_admin_start (ZebraHandle zh);
438 void zebra_admin_import_end (ZebraHandle zh);
444 /* =========================================================================
446 * =========================================================================
449 NMEM nmem_create (void);
450 void nmem_destroy (NMEM handle);
452 /* =========================================================================
454 * =========================================================================
457 typedef enum data1_datatype
465 DATA1K_generalizedtime,
472 #define DATA1T_numeric 1
473 #define DATA1T_string 2
474 #define DATA1N_root 1
476 #define DATA1N_data 3
477 #define DATA1N_variant 4
478 #define DATA1N_comment 5
479 #define DATA1N_preprocess 6
480 #define DATA1I_inctxt 1
481 #define DATA1I_incbin 2
482 #define DATA1I_text 3
485 #define DATA1_LOCALDATA 12
486 #define DATA1_FLAG_XML 1
488 data1_handle data1_create (void);
489 data1_handle data1_createx (int flags);
490 void data1_destroy(data1_handle dh);
493 data1_node *get_parent_tag(data1_handle dh, data1_node *n);
494 data1_node *data1_read_node(data1_handle dh, const char **buf,NMEM m);
495 data1_node *data1_read_nodex (data1_handle dh, NMEM m, int (*get_byte)(void *fh), void *fh, WRBUF wrbuf);
496 data1_node *data1_read_record(data1_handle dh, int (*rf)(void *, char *, size_t), void *fh, NMEM m);
497 data1_absyn *data1_read_absyn(data1_handle dh, const char *file, int file_must_exist);
498 data1_tag *data1_gettagbynum(data1_handle dh, data1_tagset *s, int type, int value);
500 data1_tagset *data1_empty_tagset (data1_handle dh);
501 data1_tagset *data1_read_tagset(data1_handle dh, const char *file, int type);
502 data1_element *data1_getelementbytagname(data1_handle dh,
504 data1_element *parent,
505 const char *tagname);
507 Z_GenericRecord *data1_nodetogr(data1_handle dh, data1_node *n,
511 data1_tag *data1_gettagbyname(data1_handle dh, data1_tagset *s,
514 void data1_free_tree(data1_handle dh, data1_node *t);
516 char *data1_nodetobuf(data1_handle dh, data1_node *n,
517 int select, int *len);
519 data1_node *data1_mk_tag_data_wd(data1_handle dh,
521 const char *tagname, NMEM m);
522 data1_node *data1_mk_tag_data(data1_handle dh, data1_node *at,
523 const char *tagname, NMEM m);
524 data1_datatype data1_maptype(data1_handle dh, char *t);
525 data1_varset *data1_read_varset(data1_handle dh, const char *file);
526 data1_vartype *data1_getvartypebyct(data1_handle dh,
528 char *zclass, char *type);
529 Z_Espec1 *data1_read_espec1(data1_handle dh, const char *file);
530 int data1_doespec1(data1_handle dh, data1_node *n, Z_Espec1 *e);
532 data1_esetname *data1_getesetbyname(data1_handle dh,
535 data1_element *data1_getelementbyname(data1_handle dh,
538 data1_node *data1_mk_node2(data1_handle dh, NMEM m,
539 int type, data1_node *parent);
541 data1_node *data1_mk_tag (data1_handle dh, NMEM nmem,
542 const char *tag, const char **attr,
544 data1_node *data1_mk_tag_n (data1_handle dh, NMEM nmem,
545 const char *tag, size_t len,
548 void data1_tag_add_attr (data1_handle dh, NMEM nmem,
549 data1_node *res, const char **attr);
551 data1_node *data1_mk_text_n (data1_handle dh, NMEM mem,
552 const char *buf, size_t len,
554 data1_node *data1_mk_text_nf (data1_handle dh, NMEM mem,
555 const char *buf, size_t len,
557 data1_node *data1_mk_text (data1_handle dh, NMEM mem,
558 const char *buf, data1_node *parent);
560 data1_node *data1_mk_comment_n (data1_handle dh, NMEM mem,
561 const char *buf, size_t len,
564 data1_node *data1_mk_comment (data1_handle dh, NMEM mem,
565 const char *buf, data1_node *parent);
567 data1_node *data1_mk_preprocess (data1_handle dh, NMEM nmem,
572 data1_node *data1_mk_root (data1_handle dh, NMEM nmem,
574 void data1_set_root(data1_handle dh, data1_node *res,
575 NMEM nmem, const char *name);
577 data1_node *data1_mk_tag_data_int (data1_handle dh, data1_node *at,
578 const char *tag, int num,
580 data1_node *data1_mk_tag_data_oid (data1_handle dh, data1_node *at,
581 const char *tag, Odr_oid *oid,
583 data1_node *data1_mk_tag_data_text (data1_handle dh, data1_node *at,
587 data1_node *data1_mk_tag_data_text_uni (data1_handle dh,
593 data1_absyn *data1_get_absyn (data1_handle dh, const char *name);
595 data1_node *data1_search_tag (data1_handle dh, data1_node *n,
597 data1_node *data1_mk_tag_uni (data1_handle dh, NMEM nmem,
598 const char *tag, data1_node *at);
599 data1_attset *data1_get_attset (data1_handle dh, const char *name);
600 data1_maptab *data1_read_maptab(data1_handle dh, const char *file);
601 data1_node *data1_map_record(data1_handle dh, data1_node *n,
602 data1_maptab *map, NMEM m);
603 data1_marctab *data1_read_marctab (data1_handle dh,
605 char *data1_nodetomarc(data1_handle dh, data1_marctab *p,
606 data1_node *n, int selected, int *len);
607 char *data1_nodetoidsgml(data1_handle dh, data1_node *n,
608 int select, int *len);
609 Z_ExplainRecord *data1_nodetoexplain(data1_handle dh,
610 data1_node *n, int select,
612 Z_BriefBib *data1_nodetosummary(data1_handle dh,
613 data1_node *n, int select,
615 char *data1_nodetosoif(data1_handle dh, data1_node *n, int select,
617 WRBUF data1_get_wrbuf (data1_handle dp);
618 char **data1_get_read_buf (data1_handle dp, int **lenp);
619 char **data1_get_map_buf (data1_handle dp, int **lenp);
620 data1_absyn_cache *data1_absyn_cache_get (data1_handle dh);
621 data1_attset_cache *data1_attset_cache_get (data1_handle dh);
622 NMEM data1_nmem_get (data1_handle dh);
624 void data1_pr_tree (data1_handle dh, data1_node *n, FILE *out);
625 void data1_print_tree (data1_handle dh, data1_node *n);
628 char *data1_insert_string (data1_handle dh, data1_node *res,
629 NMEM m, const char *str);
630 char *data1_insert_string_n (data1_handle dh, data1_node *res,
631 NMEM m, const char *str, size_t len);
632 data1_node *data1_read_sgml (data1_handle dh, NMEM m,
635 data1_node *data1_read_xml (data1_handle dh,
636 int (*rf)(void *, char *, size_t),
639 void data1_absyn_trav (data1_handle dh, void *handle,
640 void (*fh)(data1_handle dh,
641 void *h, data1_absyn *a));
643 data1_attset *data1_attset_search_id (data1_handle dh, int id);
645 char *data1_getNodeValue(data1_node* node, char* pTagPath);
646 data1_node *data1_LookupNode(data1_node* node, char* pTagPath);
647 int data1_CountOccurences(data1_node* node, char* pTagPath);
650 FILE *data1_path_fopen (data1_handle dh, const char *file,
652 void data1_set_tabpath(data1_handle dh, const char *path);
653 void data1_set_tabroot (data1_handle dp, const char *p);
654 const char *data1_get_tabpath(data1_handle dh);
655 const char *data1_get_tabroot(data1_handle dh);
659 /* =========================================================================
661 * =========================================================================
663 int grs_perl_readf(struct perl_context *context, size_t len);
664 int grs_perl_readline(struct perl_context *context);
665 char grs_perl_getc(struct perl_context *context);
666 off_t grs_perl_seekf(struct perl_context *context, off_t offset);
667 off_t grs_perl_tellf(struct perl_context *context);
668 void grs_perl_endf(struct perl_context *context, off_t offset);
670 data1_handle *grs_perl_get_dh(struct perl_context *context);
671 NMEM *grs_perl_get_mem(struct perl_context *context);
672 void grs_perl_set_res(struct perl_context *context, data1_node *n);