1 /* $Id: ZOOM.xs,v 1.34 2005-12-19 17:46:52 mike Exp $ */
8 #include <yaz/xmalloc.h>
10 /* Used by the *_setl() functions */
11 typedef char opaquechar;
13 /* Used as the return value of the *_getl() functions */
19 /* Used to package Perl function-pointer and user-data together */
20 struct callback_block {
25 /* The callback function used for ZOOM_options_set_callback(). I do
26 * not claim to fully understand all the stack-hacking magic, and less
27 * still the reference-counting/mortality stuff. Accordingly, the
28 * memory management here is best characterised as What I Could Get To
31 const char *__ZOOM_option_callback (void *handle, const char *name)
33 struct callback_block *cb = (struct callback_block*) handle;
46 XPUSHs(sv_2mortal(newSVpv(name, 0)));
48 /* Perl_sv_dump(0, cb->function); */
50 count = call_sv(cb->function, G_SCALAR);
55 croak("callback function for ZOOM_options_get() returned %d values: should have returned exactly one", count);
60 /* ### `res' never gets freed! I think it is
61 * impossible to solve this problem "correctly"
62 * because the ZOOM-C option callback interface is
77 MODULE = Net::Z3950::ZOOM PACKAGE = Net::Z3950::ZOOM PREFIX=ZOOM_
83 ZOOM_connection_new(host, portnum)
88 ZOOM_connection_create(options)
92 ZOOM_connection_connect(c, host, portnum)
98 ZOOM_connection_destroy(c)
102 ZOOM_connection_option_get(c, key)
107 ZOOM_connection_option_getl(c, key, len)
112 RETVAL.data = (char*) ZOOM_connection_option_getl(c, key, &len);
119 ZOOM_connection_option_set(c, key, val)
124 # In ZOOM-C, the `val' parameter is const char*. However, our typemap
125 # treats this as T_PV, i.e. it's "known" that it points to a
126 # NUL-terminated string. Instead, then, I here use opaquechar*, which
127 # is an opaque pointer. The underlying C function can then use this
128 # along with `len' to Do The Right Thing.
131 ZOOM_connection_option_setl(c, key, val, len)
137 # The reference parameters, `cp' and `addinfo', need to already have
138 # values when this function is called, otherwise an "uninitialised
139 # value" warning is generated. As far as I can see, there is no way
140 # around this: no way to specify in a prototype that an argument is
141 # allowed to be undefined, for example. Since these function will
142 # never be called directly by well-behaved client code, but only by
143 # our own wrapper classes, I think we can live with that.
145 # The poxing about with cpp and caddinfo is due to Perl XS's lack of
146 # support for const char**, but who can blame it? If you ask me, the
147 # whole "const" thing was well-intentioned by ghastly mistake.
150 ZOOM_connection_error(c, cp, addinfo)
156 const char *ccp, *caddinfo;
157 RETVAL = ZOOM_connection_error(c, &ccp, &caddinfo);
159 addinfo = (char*) caddinfo;
166 # See comments for ZOOM_connection_error() above
168 ZOOM_connection_error_x(c, cp, addinfo, diagset)
171 const char * &addinfo
172 const char * &diagset
175 const char *ccp, *caddinfo, *cdset;
176 RETVAL = ZOOM_connection_error_x(c, &ccp, &caddinfo, &cdset);
178 addinfo = (char*) caddinfo;
179 diagset = (char*) cdset;
188 ZOOM_connection_errcode(c)
192 ZOOM_connection_errmsg(c)
196 ZOOM_connection_addinfo(c)
200 ZOOM_connection_diagset(c)
208 ZOOM_connection_search(arg0, q)
213 ZOOM_connection_search_pqf(c, q)
218 ZOOM_resultset_destroy(r)
222 ZOOM_resultset_option_get(r, key)
227 ZOOM_resultset_option_set(r, key, val)
233 ZOOM_resultset_size(r)
237 ZOOM_resultset_records(r, start, count, return_records)
244 ZOOM_record *recs = 0;
246 recs = (ZOOM_record*) xmalloc(count * sizeof *recs);
247 ZOOM_resultset_records(r, recs, start, count);
248 if (return_records) {
251 for (i = 0; i < count; i++) {
253 sv_setref_pv(tmp, "ZOOM_record", (void*) recs[i]);
256 RETVAL = newRV((SV*) av);
258 RETVAL = &PL_sv_undef;
265 ZOOM_resultset_record(s, pos)
270 ZOOM_resultset_record_immediate(s, pos)
275 ZOOM_resultset_cache_reset(r)
278 # TESTED (but deprecated)
280 ZOOM_resultset_sort(r, sort_type, sort_spec)
282 const char* sort_type
283 const char* sort_spec
286 ZOOM_resultset_sort1(r, sort_type, sort_spec)
288 const char* sort_type
289 const char* sort_spec
291 # See "typemap" for discussion of the "const char *" return-type.
293 ### but should use datachunk for in some (not all!) cases.
295 ZOOM_record_get(rec, type, len)
304 ZOOM_record_destroy(rec)
308 ZOOM_record_clone(srec)
315 ZOOM_query_destroy(s)
319 ZOOM_query_cql(s, str)
324 ZOOM_query_prefix(s, str)
329 ZOOM_query_sortby(s, criteria)
331 const char * criteria
334 ZOOM_connection_scan(c, startterm)
336 const char* startterm
339 ZOOM_connection_scan1(c, startterm)
344 ZOOM_scanset_term(scan, pos, occ, len)
355 ZOOM_scanset_display_term(scan, pos, occ, len)
366 ZOOM_scanset_size(scan)
370 ZOOM_scanset_destroy(scan)
374 ZOOM_scanset_option_get(scan, key)
379 ZOOM_scanset_option_set(scan, key, val)
384 # We ignore the return value of ZOOM_options_set_callback(), since it
385 # is always just the address of the __ZOOM_option_callback() function.
386 # The information that we actually want -- the address of the Perl
387 # function in the callback_block -- is unavailable to us, as the
388 # underlying C function doesn't give the block back.
391 ZOOM_options_set_callback(opt, function, handle)
397 /* The tiny amount of memory allocated here is never
398 * released, as options_destroy() doesn't do anything
399 * to the callback information. Not a big deal.
400 * Also, I have no idea how to drive the Perl "mortal"
401 * reference-counting stuff, so I am just allocating
402 * copies which also never get released. Don't sue!
404 struct callback_block *block = (struct callback_block*)
405 xmalloc(sizeof *block);
406 block->function = function;
407 block->handle = handle;
408 SvREFCNT(block->function);
409 SvREFCNT(block->handle);
410 ZOOM_options_set_callback(opt, __ZOOM_option_callback,
415 ZOOM_options_create()
418 ZOOM_options_create_with_parent(parent)
422 ZOOM_options_create_with_parent2(parent1, parent2)
427 ZOOM_options_get(opt, name)
432 ZOOM_options_getl(opt, name, len)
437 RETVAL.data = (char*) ZOOM_options_getl(opt, name, &len);
444 ZOOM_options_set(opt, name, v)
450 ZOOM_options_setl(opt, name, value, len)
457 ZOOM_options_destroy(opt)
461 ZOOM_options_get_bool(opt, name, defa)
467 ZOOM_options_get_int(opt, name, defa)
473 ZOOM_options_set_int(opt, name, value)
479 ZOOM_connection_package(c, options)
484 ZOOM_package_destroy(p)
488 ZOOM_package_send(p, type)
493 ZOOM_package_option_get(p, key)
498 ZOOM_package_option_set(p, key, val)
511 ZOOM_connection_last_event(cs)