2 %include typemaps.i // Load the typemaps librayr
7 #include "zebra_perl.h"
13 /* == Typemaps ============================================================= */
18 croak("Argument $argnum is not an integer.");
29 /* RetrievalRecordBuff is a special construct, to allow to map a char * buf
30 to non-null terminated perl string scalar value (SVpv). */
31 %typemap(out) RetrievalRecordBuf * {
33 $result = newSVpv($1->buf,$1->len);
35 $result = newSVpv("",0);
41 /* All char ** values are mapped in-out to array of strings. */
42 %typemap(in) char ** {
49 croak("Argument $argnum is not a reference.");
50 if (SvTYPE(SvRV($input)) != SVt_PVAV)
51 croak("Argument $argnum is not an array.");
52 tempav = (AV*)SvRV($input);
54 $1 = (char **) malloc((len+2)*sizeof(char *));
55 for (i = 0; i <= len; i++) {
56 tv = av_fetch(tempav, i, 0);
57 $1[i] = (char *) SvPV(*tv,na);
62 /* This cleans up the char ** array after the function call */
63 %typemap(freearg) char ** {
67 /* Creates a new Perl array and places a NULL-terminated char ** into it */
68 %typemap(out) char ** {
72 /* Figure out how many elements we have */
75 svs = (SV **) malloc(len*sizeof(SV *));
76 for (i = 0; i < len ; i++) {
77 svs[i] = sv_newmortal();
78 sv_setpv((SV*)svs[i],$1[i]);
80 myav = av_make(len,svs);
82 $result = newRV((SV*)myav);
87 /* == Structures for shadow classes ======================================= */
90 /*%include "zebra_perl.h" */
100 int fileVerboseLimit;
101 int databaseNamePath;
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 /* == Record groups and database selection ================================= */
221 /* initialize a recordGroup (zebra_api_ext.c); */
222 void init_recordGroup (recordGroup *rg);
224 /* set up a recordGroup for a specific file extension from zebra.cfg
225 (zebra_api_ext.c); */
226 void res_get_recordGroup (ZebraHandle zh, recordGroup *rg,
228 /* set current record group for update purposes (zebraapi.c) */
230 void zebra_set_group (ZebraHandle zh, struct recordGroup *rg);
232 /* select database for update purposes (zebraapi.c) */
233 %name(select_database)
234 int zebra_select_database (ZebraHandle zh, const char *basename);
236 /* select databases for record retrieval (zebraapi.c) */
237 %name(select_databases)
238 int zebra_select_databases (ZebraHandle zh, int num_bases,
239 const char **basenames);
242 /* == Transactions, locking, shadow register =============================== */
244 /* begin transaction (add write lock) (zebraapi.c) */
246 int zebra_begin_trans (ZebraHandle zh, int rw);
248 /* end transaction (remove write lock) (zebraapi.c) */
250 void zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *stat);
253 int zebra_trans_no (ZebraHandle zh);
255 /* commit changes from shadow (zebraapi.c) */
257 int zebra_commit (ZebraHandle zh);
259 /* get shadow status (zebra_api_ext.c) */
260 %name(get_shadow_enable)
261 int zebra_get_shadow_enable (ZebraHandle zh);
263 /* set shadow status (zebra_api_ext.c) */
264 %name(set_shadow_enable)
265 void zebra_set_shadow_enable (ZebraHandle zh, int value);
268 /* == Repository actions (zebraapi.c) ====================================== */
271 int zebra_init (ZebraHandle zh);
274 int zebra_compact (ZebraHandle zh);
276 %name(repository_update)
277 void zebra_repository_update (ZebraHandle zh);
279 %name(repository_delete)
280 void zebra_repository_delete (ZebraHandle zh);
282 %name(repository_show)
283 void zebra_repository_show (ZebraHandle zh);
286 /* == Record update/delete (zebra_api_ext.c) =============================== */
288 /* If sysno is provided, then it's used to identify the reocord.
289 If not, and match_criteria is provided, then sysno is guessed
290 If not, and a record is provided, then sysno is got from there */
292 %apply int *REFERENCE { int *sysno };
294 int zebra_insert_record (ZebraHandle zh,
296 const char *recordType,
305 int zebra_update_record (ZebraHandle zh,
307 const char *recordType,
316 int zebra_delete_record (ZebraHandle zh,
318 const char *recordType,
327 /* == Search (zebraapi.c) ================================================== */
328 %include "typemaps.i"
329 %apply int *REFERENCE { int *hits };
331 int zebra_search_PQF (ZebraHandle zh,
332 const char *pqf_query,
336 /* == YAZ - query tools ==================================================== */
339 cql_transform_t cql_transform_open_fname(const char *fname);
340 void cql_transform_close(cql_transform_t ct);
341 int cql_transform_error(cql_transform_t ct, const char **addinfo);
344 int zebra_cql2pqf (cql_transform_t ct,
345 const char *query, char *res, int len);
347 /* == Retrieval (zebra_api_ext.c) ========================================== */
349 /* will get a 'retrieval obj' (simple enough to pass to perl), which can be
350 used to get the individual records. Elementset, schema and format strings
351 are threated the same way yaz-client does. */
352 void records_retrieve(ZebraHandle zh,
354 const char *setname, // resultset name
355 const char *a_eset, // optional elementset
356 const char *a_schema, // optional schema
357 const char *a_format, // optional record syntax
358 int from, // range, 1 based
363 /* fetch a record from the retrieval object. pos is 1 based */
364 void record_retrieve(RetrievalObj *ro,
366 RetrievalRecord *res,
369 /* Delete Result Set(s) (zebraapi.c) */
370 %name(deleteResultSet)
371 int zebra_deleleResultSet(ZebraHandle zh, int function,
372 int num_setnames, char **setnames,
376 /* 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);
382 /* == Sort ================================================================= */
384 int zebra_sort_by_specstr (ZebraHandle zh,
386 const char *sort_spec,
387 const char *output_setname,
388 const char **input_setnames
391 /* == Scan ================================================================= */
393 void zebra_scan_PQF (ZebraHandle zh,
396 const char *pqf_query);
398 scanEntry *getScanEntry(ScanObj *so, int pos);
400 %typemap(in) int * (int dvalue);
401 %typemap(argout) int *;
404 /* Admin functionality */
406 %name(admin_start) void zebra_admin_start (ZebraHandle zh);
407 %name(admin_shutdown) void zebra_admin_shutdown (ZebraHandle zh);
412 /* do authentication */
414 int zebra_auth (ZebraHandle zh, const char *user, const char *pass);
421 void zebra_result (ZebraHandle zh, int *code, char **addinfo);
422 int zebra_resultSetTerms (ZebraHandle zh, const char *setname,
424 int *type, char *out, size_t *len);
428 YAZ_EXPORT void zebra_admin_create (ZebraHandle zh, const char *db);
430 YAZ_EXPORT void zebra_admin_import_begin (ZebraHandle zh, const char *database);
432 YAZ_EXPORT void zebra_admin_import_segment (ZebraHandle zh,
435 void zebra_admin_shutdown (ZebraHandle zh);
436 void zebra_admin_start (ZebraHandle zh);
437 void zebra_admin_import_end (ZebraHandle zh);
443 /* =========================================================================
445 * =========================================================================
448 NMEM nmem_create (void);
449 void nmem_destroy (NMEM handle);
451 /* =========================================================================
453 * =========================================================================
456 typedef enum data1_datatype
464 DATA1K_generalizedtime,
471 #define DATA1T_numeric 1
472 #define DATA1T_string 2
473 #define DATA1N_root 1
475 #define DATA1N_data 3
476 #define DATA1N_variant 4
477 #define DATA1N_comment 5
478 #define DATA1N_preprocess 6
479 #define DATA1I_inctxt 1
480 #define DATA1I_incbin 2
481 #define DATA1I_text 3
484 #define DATA1_LOCALDATA 12
485 #define DATA1_FLAG_XML 1
487 data1_handle data1_create (void);
488 data1_handle data1_createx (int flags);
489 void data1_destroy(data1_handle dh);
492 data1_node *get_parent_tag(data1_handle dh, data1_node *n);
493 data1_node *data1_read_node(data1_handle dh, const char **buf,NMEM m);
494 data1_node *data1_read_nodex (data1_handle dh, NMEM m, int (*get_byte)(void *fh), void *fh, WRBUF wrbuf);
495 data1_node *data1_read_record(data1_handle dh, int (*rf)(void *, char *, size_t), void *fh, NMEM m);
496 data1_absyn *data1_read_absyn(data1_handle dh, const char *file, int file_must_exist);
497 data1_tag *data1_gettagbynum(data1_handle dh, data1_tagset *s, int type, int value);
499 data1_tagset *data1_empty_tagset (data1_handle dh);
500 data1_tagset *data1_read_tagset(data1_handle dh, const char *file, int type);
501 data1_element *data1_getelementbytagname(data1_handle dh,
503 data1_element *parent,
504 const char *tagname);
506 Z_GenericRecord *data1_nodetogr(data1_handle dh, data1_node *n,
510 data1_tag *data1_gettagbyname(data1_handle dh, data1_tagset *s,
513 void data1_free_tree(data1_handle dh, data1_node *t);
515 char *data1_nodetobuf(data1_handle dh, data1_node *n,
516 int select, int *len);
518 data1_node *data1_mk_tag_data_wd(data1_handle dh,
520 const char *tagname, NMEM m);
521 data1_node *data1_mk_tag_data(data1_handle dh, data1_node *at,
522 const char *tagname, NMEM m);
523 data1_datatype data1_maptype(data1_handle dh, char *t);
524 data1_varset *data1_read_varset(data1_handle dh, const char *file);
525 data1_vartype *data1_getvartypebyct(data1_handle dh,
527 char *zclass, char *type);
528 Z_Espec1 *data1_read_espec1(data1_handle dh, const char *file);
529 int data1_doespec1(data1_handle dh, data1_node *n, Z_Espec1 *e);
531 data1_esetname *data1_getesetbyname(data1_handle dh,
534 data1_element *data1_getelementbyname(data1_handle dh,
537 data1_node *data1_mk_node2(data1_handle dh, NMEM m,
538 int type, data1_node *parent);
540 data1_node *data1_mk_tag (data1_handle dh, NMEM nmem,
541 const char *tag, const char **attr,
543 data1_node *data1_mk_tag_n (data1_handle dh, NMEM nmem,
544 const char *tag, size_t len,
547 void data1_tag_add_attr (data1_handle dh, NMEM nmem,
548 data1_node *res, const char **attr);
550 data1_node *data1_mk_text_n (data1_handle dh, NMEM mem,
551 const char *buf, size_t len,
553 data1_node *data1_mk_text_nf (data1_handle dh, NMEM mem,
554 const char *buf, size_t len,
556 data1_node *data1_mk_text (data1_handle dh, NMEM mem,
557 const char *buf, data1_node *parent);
559 data1_node *data1_mk_comment_n (data1_handle dh, NMEM mem,
560 const char *buf, size_t len,
563 data1_node *data1_mk_comment (data1_handle dh, NMEM mem,
564 const char *buf, data1_node *parent);
566 data1_node *data1_mk_preprocess (data1_handle dh, NMEM nmem,
571 data1_node *data1_mk_root (data1_handle dh, NMEM nmem,
573 void data1_set_root(data1_handle dh, data1_node *res,
574 NMEM nmem, const char *name);
576 data1_node *data1_mk_tag_data_int (data1_handle dh, data1_node *at,
577 const char *tag, int num,
579 data1_node *data1_mk_tag_data_oid (data1_handle dh, data1_node *at,
580 const char *tag, Odr_oid *oid,
582 data1_node *data1_mk_tag_data_text (data1_handle dh, data1_node *at,
586 data1_node *data1_mk_tag_data_text_uni (data1_handle dh,
592 data1_absyn *data1_get_absyn (data1_handle dh, const char *name);
594 data1_node *data1_search_tag (data1_handle dh, data1_node *n,
596 data1_node *data1_mk_tag_uni (data1_handle dh, NMEM nmem,
597 const char *tag, data1_node *at);
598 data1_attset *data1_get_attset (data1_handle dh, const char *name);
599 data1_maptab *data1_read_maptab(data1_handle dh, const char *file);
600 data1_node *data1_map_record(data1_handle dh, data1_node *n,
601 data1_maptab *map, NMEM m);
602 data1_marctab *data1_read_marctab (data1_handle dh,
604 char *data1_nodetomarc(data1_handle dh, data1_marctab *p,
605 data1_node *n, int selected, int *len);
606 char *data1_nodetoidsgml(data1_handle dh, data1_node *n,
607 int select, int *len);
608 Z_ExplainRecord *data1_nodetoexplain(data1_handle dh,
609 data1_node *n, int select,
611 Z_BriefBib *data1_nodetosummary(data1_handle dh,
612 data1_node *n, int select,
614 char *data1_nodetosoif(data1_handle dh, data1_node *n, int select,
616 WRBUF data1_get_wrbuf (data1_handle dp);
617 char **data1_get_read_buf (data1_handle dp, int **lenp);
618 char **data1_get_map_buf (data1_handle dp, int **lenp);
619 data1_absyn_cache *data1_absyn_cache_get (data1_handle dh);
620 data1_attset_cache *data1_attset_cache_get (data1_handle dh);
621 NMEM data1_nmem_get (data1_handle dh);
623 void data1_pr_tree (data1_handle dh, data1_node *n, FILE *out);
624 void data1_print_tree (data1_handle dh, data1_node *n);
627 char *data1_insert_string (data1_handle dh, data1_node *res,
628 NMEM m, const char *str);
629 char *data1_insert_string_n (data1_handle dh, data1_node *res,
630 NMEM m, const char *str, size_t len);
631 data1_node *data1_read_sgml (data1_handle dh, NMEM m,
634 data1_node *data1_read_xml (data1_handle dh,
635 int (*rf)(void *, char *, size_t),
638 void data1_absyn_trav (data1_handle dh, void *handle,
639 void (*fh)(data1_handle dh,
640 void *h, data1_absyn *a));
642 data1_attset *data1_attset_search_id (data1_handle dh, int id);
644 char *data1_getNodeValue(data1_node* node, char* pTagPath);
645 data1_node *data1_LookupNode(data1_node* node, char* pTagPath);
646 int data1_CountOccurences(data1_node* node, char* pTagPath);
649 FILE *data1_path_fopen (data1_handle dh, const char *file,
651 void data1_set_tabpath(data1_handle dh, const char *path);
652 void data1_set_tabroot (data1_handle dp, const char *p);
653 const char *data1_get_tabpath(data1_handle dh);
654 const char *data1_get_tabroot(data1_handle dh);
658 /* =========================================================================
660 * =========================================================================
662 int grs_perl_readf(struct perl_context *context, size_t len);
663 int grs_perl_readline(struct perl_context *context);
664 char grs_perl_getc(struct perl_context *context);
665 off_t grs_perl_seekf(struct perl_context *context, off_t offset);
666 off_t grs_perl_tellf(struct perl_context *context);
667 void grs_perl_endf(struct perl_context *context, off_t offset);
669 data1_handle *grs_perl_get_dh(struct perl_context *context);
670 NMEM *grs_perl_get_mem(struct perl_context *context);
671 void grs_perl_set_res(struct perl_context *context, data1_node *n);