1 /* $Id: ZOOM.xs,v 1.16 2005-10-24 16:39:55 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_
84 ZOOM_connection_new(host, portnum)
90 ZOOM_connection_create(options)
95 ZOOM_connection_connect(c, host, portnum)
102 ZOOM_connection_destroy(c)
107 ZOOM_connection_option_get(c, key)
113 ZOOM_connection_option_getl(c, key, len)
118 RETVAL.data = (char*) ZOOM_connection_option_getl(c, key, &len);
126 ZOOM_connection_option_set(c, key, val)
131 # In ZOOM-C, the `val' parameter is const char*. However, our typemap
132 # treats this as T_PV, i.e. it's "known" that it points to a
133 # NUL-terminated string. Instead, then, I here use opaquechar*, which
134 # is an opaque pointer. The underlying C function can then use this
135 # along with `len' to Do The Right Thing.
139 ZOOM_connection_option_setl(c, key, val, len)
145 # The reference parameters, `cp' and `addinfo', need to already have
146 # values when this function is called, otherwise an "uninitialised
147 # value" warning is generated. As far as I can see, there is no way
148 # around this: no way to specify in a prototype that an argument is
149 # allowed to be undefined, for example. Since these function will
150 # never be called directly by well-behaved client code, but only by
151 # our own wrapper classes, I think we can live with that.
153 # The poxing about with cpp and caddinfo is due to Perl XS's lack of
154 # support for const char**, but who can blame it? If you ask me, the
155 # whole "const" thing was well-intentioned by ghastly mistake.
159 ZOOM_connection_error(c, cp, addinfo)
164 const char *ccp, *caddinfo;
165 RETVAL = ZOOM_connection_error(c, &ccp, &caddinfo);
167 addinfo = (char*) caddinfo;
173 # See comments for ZOOM_connection_error() above
176 ZOOM_connection_error_x(c, cp, addinfo, diagset)
179 const char * &addinfo
180 const char * &diagset
182 const char *ccp, *caddinfo, *cdset;
183 RETVAL = ZOOM_connection_error_x(c, &ccp, &caddinfo, &cdset);
185 addinfo = (char*) caddinfo;
186 diagset = (char*) cdset;
195 ZOOM_connection_errcode(c)
200 ZOOM_connection_errmsg(c)
205 ZOOM_connection_addinfo(c)
215 ZOOM_connection_last_event(cs)
220 ZOOM_connection_search(arg0, q)
226 ZOOM_connection_search_pqf(c, q)
232 ZOOM_resultset_destroy(r)
237 ZOOM_resultset_option_get(r, key)
243 ZOOM_resultset_option_set(r, key, val)
250 ZOOM_resultset_size(r)
255 ZOOM_resultset_records(r, recs, start, count)
263 ZOOM_resultset_record(s, pos)
269 ZOOM_resultset_record_immediate(s, pos)
275 ZOOM_resultset_cache_reset(r)
278 # See "typemap" for discussion of the "const char *" return-type.
281 ### but should use datachunk for in some (not all!) cases.
283 ZOOM_record_get(rec, type, len)
293 ZOOM_record_destroy(rec)
298 ZOOM_record_clone(srec)
307 ZOOM_query_destroy(s)
312 ZOOM_query_cql(s, str)
318 ZOOM_query_prefix(s, str)
324 ZOOM_query_sortby(s, criteria)
326 const char * criteria
330 ZOOM_connection_scan(c, startterm)
332 const char * startterm
336 ZOOM_scanset_term(scan, pos, occ, len)
344 ZOOM_scanset_display_term(scan, pos, occ, len)
352 ZOOM_scanset_size(scan)
357 ZOOM_scanset_destroy(scan)
362 ZOOM_scanset_option_get(scan, key)
368 ZOOM_scanset_option_set(scan, key, val)
375 ZOOM_connection_package(c, options)
381 ZOOM_package_destroy(p)
386 ZOOM_package_send(p, type)
392 ZOOM_package_option_get(p, key)
398 ZOOM_package_option_set(p, key, val)
405 ZOOM_resultset_sort(r, sort_type, sort_spec)
407 const char * sort_type
408 const char * sort_spec
410 # We ignore the return value of ZOOM_options_set_callback(), since it
411 # is always just the address of the __ZOOM_option_callback() function.
412 # The information that we actually want -- the address of the Perl
413 # function in the callback_block -- is unavailable to us, as the
414 # underlying C function doesn't give the block back.
418 ZOOM_options_set_callback(opt, function, handle)
423 /* The tiny amount of memory allocated here is never
424 * released, as options_destroy() doesn't do anything
425 * to the callback information. Not a big deal.
426 * Also, I have no idea how to drive the Perl "mortal"
427 * reference-counting stuff, so I am just allocating
428 * copies which also never get released. Don't sue!
430 struct callback_block *block = (struct callback_block*)
431 xmalloc(sizeof *block);
432 block->function = function;
433 block->handle = handle;
434 SvREFCNT(block->function);
435 SvREFCNT(block->handle);
436 ZOOM_options_set_callback(opt, __ZOOM_option_callback,
441 ZOOM_options_create()
445 ZOOM_options_create_with_parent(parent)
450 ZOOM_options_create_with_parent2(parent1, parent2)
456 ZOOM_options_get(opt, name)
462 ZOOM_options_getl(opt, name, len)
467 RETVAL.data = (char*) ZOOM_options_getl(opt, name, &len);
475 ZOOM_options_set(opt, name, v)
482 ZOOM_options_setl(opt, name, value, len)
490 ZOOM_options_destroy(opt)
495 ZOOM_options_get_bool(opt, name, defa)
502 ZOOM_options_get_int(opt, name, defa)
509 ZOOM_options_set_int(opt, name, value)