From 23d068e423a3d6f5295597226d0e18f2647810c5 Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Fri, 2 Jun 2006 16:03:25 +0000 Subject: [PATCH] Added explain handler. Input=DATABASE output=EXPLAIN --- SimpleServer.pm | 8 ++++++-- SimpleServer.xs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/SimpleServer.pm b/SimpleServer.pm index ba88897..1dc36d2 100644 --- a/SimpleServer.pm +++ b/SimpleServer.pm @@ -25,7 +25,7 @@ ## ## -## $Id: SimpleServer.pm,v 1.26 2006-04-19 13:17:52 sondberg Exp $ +## $Id: SimpleServer.pm,v 1.27 2006-06-02 16:03:25 quinn Exp $ package Net::Z3950::SimpleServer; @@ -86,6 +86,9 @@ sub launch_server { if (defined($self->{SORT})) { set_sort_handler($self->{SORT}); } + if (defined($self->{EXPLAIN})) { + set_explain_handler($self->{EXPLAIN}); + } start_server(@args); } @@ -212,7 +215,8 @@ means of the SimpleServer object constructor SEARCH => \&my_search_handler, PRESENT => \&my_present_handler, SCAN => \&my_scan_handler, - FETCH => \&my_fetch_handler); + FETCH => \&my_fetch_handler, + EXPLAIN => \&my_explain_handler); If you want your SimpleServer to start a thread (threaded mode) to handle each incoming Z39.50 request instead of forking a process diff --git a/SimpleServer.xs b/SimpleServer.xs index 778042d..5be5f73 100644 --- a/SimpleServer.xs +++ b/SimpleServer.xs @@ -1,5 +1,5 @@ /* - * $Id: SimpleServer.xs,v 1.45 2006-06-02 10:06:11 sondberg Exp $ + * $Id: SimpleServer.xs,v 1.46 2006-06-02 16:03:25 quinn Exp $ * ---------------------------------------------------------------------- * * Copyright (c) 2000-2004, Index Data. @@ -64,6 +64,7 @@ typedef struct { SV *esrequest_ref; SV *delete_ref; SV *scan_ref; + SV *explain_ref; NMEM nmem; int stop_flag; /* is used to stop server prematurely .. */ } Zfront_handle; @@ -79,6 +80,7 @@ SV *present_ref = NULL; SV *esrequest_ref = NULL; SV *delete_ref = NULL; SV *scan_ref = NULL; +SV *explain_ref = NULL; PerlInterpreter *root_perl_context; int MAX_OID = 15; @@ -1284,6 +1286,46 @@ int bend_scan(void *handle, bend_scan_rr *rr) return 0; } +int bend_explain(void *handle, bend_explain_rr *q) +{ + HV *href; + CV *handler_cv = 0; + SV **temp; + char *explain; + SV *explainsv; + STRLEN len; + + dSP; + ENTER; + SAVETMPS; + + href = newHV(); + hv_store(href, "EXPLAIN", 7, newSVpv("", 0), 0); + hv_store(href, "DATABASE", 8, newSVpv(q->database, 0), 0); + + PUSHMARK(sp); + XPUSHs(sv_2mortal(newRV((SV*) href))); + PUTBACK; + + handler_cv = simpleserver_sv2cv(explain_ref); + perl_call_sv((SV*) handler_cv, G_SCALAR | G_DISCARD); + + SPAGAIN; + + temp = hv_fetch(href, "EXPLAIN", 7, 1); + explainsv = newSVsv(*temp); + + PUTBACK; + FREETMPS; + LEAVE; + + explain = SvPV(explainsv, len); + q->explain_buf = (char*) odr_malloc(q->stream, len + 1); + strcpy(q->explain_buf, explain); + + return 0; +} + bend_initresult *bend_init(bend_initrequest *q) { int dummy = simpleserver_clone(); @@ -1328,6 +1370,10 @@ bend_initresult *bend_init(bend_initrequest *q) { q->bend_scan = bend_scan; } + if (explain_ref) + { + q->bend_explain = bend_explain; + } href = newHV(); hv_store(href, "IMP_ID", 6, newSVpv("", 0), 0); @@ -1520,6 +1566,11 @@ set_scan_handler(arg) CODE: scan_ref = newSVsv(arg); +void +set_explain_handler(arg) + SV *arg + CODE: + explain_ref = newSVsv(arg); int start_server(...) -- 1.7.10.4