From 6e37e8e91bf35cb14c930e8988085cf78f11029a Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 7 Nov 1995 14:56:58 +0000 Subject: [PATCH] Work on search in multiple targets. New wtcl command: wlog. Optional timeout parameter to zwait. --- www/Makefile | 9 +++- www/mquery.egw | 93 ++++++++++++++++++++++++++++++++++++++ www/msearch.egw | 88 ++++++++++++++++++++++++++++++++++++ www/mtargets.egw | 4 +- www/search.egw | 6 +-- www/showfull.egw | 3 +- www/wirtcl.c | 32 +++++++++---- www/wtcl.c | 44 +++++++++++++++++- www/z39util.tcl | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 9 files changed, 388 insertions(+), 23 deletions(-) create mode 100644 www/mquery.egw create mode 100644 www/msearch.egw diff --git a/www/Makefile b/www/Makefile index 781e430..beb9aeb 100644 --- a/www/Makefile +++ b/www/Makefile @@ -2,7 +2,12 @@ # Europagate, 1995 # # $Log: Makefile,v $ -# Revision 1.10 1995/11/07 10:44:29 adam +# Revision 1.11 1995/11/07 14:56:58 adam +# Work on search in multiple targets. +# New wtcl command: wlog. +# Optional timeout parameter to zwait. +# +# Revision 1.10 1995/11/07 10:44:29 adam # Work on search in multiple targets. # # Revision 1.9 1995/11/06 17:44:20 adam @@ -48,7 +53,7 @@ OLIB=../lib/util.a ../lib/libres+log.a TCLLIB=/usr/local/lib/libtcl7.4.a # WSCRIPTS=egwscript targets.egw query.egw search.egw showfull.egw z39util.tcl \ - mtargets.egw + mtargets.egw mquery.egw msearch.egw HSCRIPTS=egwindex.html CONFFILES=ztargets.conf GIFFILES=webgate.gif diff --git a/www/mquery.egw b/www/mquery.egw new file mode 100644 index 0000000..27e6e32 --- /dev/null +++ b/www/mquery.egw @@ -0,0 +1,93 @@ + + + WWW/Z39.50 Gateway Query Form + + +{ +# $Id: mquery.egw,v 1.1 1995/11/07 14:56:58 adam Exp $ + + if {[info commands saveState] == ""} { + source z39util.tcl + } + + global setNo + global nextSetNo + global hist + + html {
} \n + + if {[catch {set setNo $nextSetNo}]} { + set nextSetNo 1 + set setNo 1 + } + set hosts [wform target] + html "hosts=$hosts
\n" + set i 1 + foreach host $hosts { + set hist($setNo,$i,host) $host + set hist($setNo,$i,database) [lindex [lindex $targets($host) 1] 0] + incr i + } + set hist($setNo,0,host) [expr $i - 1] + set host [lindex $hosts 0] +} +
+

Input your search criteria:


+{ + set fields [lindex $targets($host) 2] + for {set no 1} {$no < 4} {incr no} { + html {\n" + html {} \n + if {$no < 3} { + html {\n" + } + html "
\n" + } +} +

Various technical parameters:


+Max hits: +Records are shown in: + +
+

+ +

+
+This page is maintained by Peter Wad Hansen . +Last modified 29. september 1995.
+ This and the following pages are under construction +and will continue to be so until the end of December 1995. +
+ +{ + html { New target } +} +{ + html "
\n" + html "

Debug information

\n" + html "sessionId: $sessionId
\n" + html "sessionParms: $sessionParms
\n" + foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} { + html $e {: } $env($e) {
} \n + } + html "form: " [wform] "
\n" + html "target: " $host "
\n" + html "setNo: " $setNo "
\n" + html "nextSetNo: " $nextSetNo "
\n" +} + diff --git a/www/msearch.egw b/www/msearch.egw new file mode 100644 index 0000000..1d1238e --- /dev/null +++ b/www/msearch.egw @@ -0,0 +1,88 @@ + +{ +# $Id: msearch.egw,v 1.1 1995/11/07 14:56:58 adam Exp $ + + if {[info commands saveState] == ""} { + source z39util.tcl + } + global sessionWait + global nextSetNo + global setNo + global hist + global zstatus + + if {[wform menu1] == ""} { + set setNo [lindex $sessionParms 0] + } else { + if {![info exists hist($nextSetNo,0,host)]} { + set hist($nextSetNo,0,host) $hist($setNo,0,host) + for {set i 1} {$i <= $hist($setNo,0,host)} {incr i} { + set hist($nextSetNo,$i,host) $hist($setNo,$i,host) + set hist($nextSetNo,$i,database) $hist($setNo,$i,database) + } + } + set setNo $nextSetNo + incr nextSetNo + + for {set i 1} {$i <= $hist($setNo,0,host)} {incr i} { + set hist($setNo,$i,query) [build-query $hist($setNo,$i,host)] + } + set hist($setNo,maxPresent) [wform hits] + if {$hist($setNo,maxPresent) == ""} { + set hist($setNo,maxPresent) 30 + } + } + html " WWW/Z39.50 Gateway Search \n" + html "\n" + + z39msearch $setNo 1 + + html "
\n" + set not $hist($setNo,0,host) + for {set i 1} {$i <= $not} {incr i} { + if {$zstatus($i) != 2} continue + html "
" $hist($setNo,$i,host) ": " + set status [z39$i.$setNo responseStatus] + if {[lindex $status 0] == "NSD"} { + z39$i.$setNo nextResultSetPosition 0 + set code [lindex $status 1] + set msg [lindex $status 2] + set addinfo [lindex $status 3] + html "Error\n
NSD$code: $msg: $addinfo" + } else { + set r [z39$i.$setNo resultCount] + html "$r hits\n
\n" + + display-rec 1 $hist($setNo,$i,offset) display-brief z39$i + } + html "\n" + } + html "
\n" +} + + +
+{ + html { New target } " | \n" + html { New query } +} + +{ + html "
\n" + html "

Debug information

\n" + html "sessionId: $sessionId
\n" + html "sessionParms: $sessionParms
\n" + foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} { + html $e {: } $env($e) {
} \n + } + html "form: " [wform] "
\n" + html "target: " $host "
\n" + html "query: --" $hist($setNo,1,query) "--
" + html "setNo: " $setNo "
\n" + html "nextSetNo: " $nextSetNo "
\n" +} + + + diff --git a/www/mtargets.egw b/www/mtargets.egw index f23edd2..6c91b03 100644 --- a/www/mtargets.egw +++ b/www/mtargets.egw @@ -1,6 +1,6 @@ { -# $Id: mtargets.egw,v 1.1 1995/11/07 10:44:31 adam Exp $ +# $Id: mtargets.egw,v 1.2 1995/11/07 14:56:58 adam Exp $ set setNo 1 source /usr/local/etc/httpd/conf/ztargets.conf if {[info commands saveState] == ""} { @@ -16,7 +16,7 @@

Choose one or more Z39.50 targets:

{ html {

} \n + html / $sessionId {/mquery.egw/} $setNo {" method=post>
} \n foreach t [array names targets] { html { } $t \n diff --git a/www/search.egw b/www/search.egw index 08e0aa1..76a4434 100644 --- a/www/search.egw +++ b/www/search.egw @@ -1,6 +1,6 @@ { -# $Id: search.egw,v 1.8 1995/11/06 17:44:21 adam Exp $ +# $Id: search.egw,v 1.9 1995/11/07 14:56:59 adam Exp $ if {[info commands saveState] == ""} { source z39util.tcl @@ -22,7 +22,7 @@ html "using host " $hist($setNo,host) " Search result $r hits\n" wflush set setOffset [z39.$setNo numberOfRecordsReturned] - display-rec 1 $setOffset display-brief + display-rec 1 $setOffset display-brief z39 incr setOffset set setMax [z39.$setNo resultCount] if {$setMax > $hist($setNo,maxPresent)} { diff --git a/www/showfull.egw b/www/showfull.egw index 04f29ce..4eb9d66 100644 --- a/www/showfull.egw +++ b/www/showfull.egw @@ -1,6 +1,6 @@ { -# $Id: showfull.egw,v 1.3 1995/11/06 17:44:21 adam Exp $ +# $Id: showfull.egw,v 1.4 1995/11/07 14:56:59 adam Exp $ if {[info commands saveState] == ""} { source z39util.tcl @@ -48,7 +48,6 @@ { z39present $setNo $no $no display-full -# display-full z39.$sno $no }
{ diff --git a/www/wirtcl.c b/www/wirtcl.c index 672ca70..9939df8 100644 --- a/www/wirtcl.c +++ b/www/wirtcl.c @@ -41,7 +41,12 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wirtcl.c,v $ - * Revision 1.8 1995/11/06 17:44:22 adam + * Revision 1.9 1995/11/07 14:56:59 adam + * Work on search in multiple targets. + * New wtcl command: wlog. + * Optional timeout parameter to zwait. + * + * Revision 1.8 1995/11/06 17:44:22 adam * State reestablised when shell restarts. History of previous * result sets. * @@ -113,7 +118,7 @@ struct tcl_info { }; -static int events (struct tcl_info *p, char *waitVar); +static int events (struct tcl_info *p, char *waitVar, int tout); static int proc_zwait_invoke (ClientData clientData, Tcl_Interp *interp, int argc, char **argv) @@ -122,8 +127,7 @@ static int proc_zwait_invoke (ClientData clientData, Tcl_Interp *interp, if (argc < 2) return TCL_OK; - events (p, argv[1]); - return TCL_OK; + return events (p, argv[1], (argc == 3) ? atoi(argv[2]) : 0); } @@ -185,7 +189,7 @@ static int do_exec (const char *fname, char *parms, void *mydata) } -static int events (struct tcl_info *p, char *waitVar) +static int events (struct tcl_info *p, char *waitVar, int tout) { int r, i; char *cp; @@ -215,6 +219,16 @@ static int events (struct tcl_info *p, char *waitVar) gw_log (GW_LOG_DEBUG, mod, "Waiting %s=%s", waitVar, waitVarVal); while (1) { + struct timeval to, *top; + if (tout > 0) + { + to.tv_usec = 0; + to.tv_sec = tout; + top = &to; + } + else + top = 0; + if (!(cp = Tcl_GetVar (p->interp, waitVar, 0)) || strcmp (cp, waitVarVal)) { @@ -252,7 +266,7 @@ static int events (struct tcl_info *p, char *waitVar) FD_SET (fifo_in, &fdset_tcl_r); #endif if ((r = select(max_fd+1, &fdset_tcl_r, &fdset_tcl_w, - &fdset_tcl_x, NULL)) < 0) + &fdset_tcl_x, top)) < 0) { gw_log (GW_LOG_ERRNO|GW_LOG_FATAL, mod, "select"); exit(1); @@ -260,12 +274,14 @@ static int events (struct tcl_info *p, char *waitVar) if (!r) { gw_log (GW_LOG_DEBUG, mod, "timeout"); - break; + free (waitVarVal); + return TCL_ERROR; } if (FD_ISSET (fifo_in, &fdset_tcl_r)) { gw_log (GW_LOG_DEBUG, mod, "FIFO closed"); - break; + free (waitVarVal); + return TCL_ERROR; } for (i=0; i<=max_fd; i++) { diff --git a/www/wtcl.c b/www/wtcl.c index 9ed644c..bb2c34d 100644 --- a/www/wtcl.c +++ b/www/wtcl.c @@ -41,7 +41,12 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wtcl.c,v $ - * Revision 1.8 1995/11/06 17:44:23 adam + * Revision 1.9 1995/11/07 14:57:00 adam + * Work on search in multiple targets. + * New wtcl command: wlog. + * Optional timeout parameter to zwait. + * + * Revision 1.8 1995/11/06 17:44:23 adam * State reestablised when shell restarts. History of previous * result sets. * @@ -185,6 +190,42 @@ static int proc_wform_invoke (ClientData clientData, Tcl_Interp *interp, return TCL_OK; } +static int proc_wlog_invoke (ClientData clientData, Tcl_Interp *interp, + int argc, char **argv) +{ + unsigned mask; + + if (argc < 3) + return TCL_OK; + if (!strcmp (argv[1], "debug")) + mask = GW_LOG_DEBUG; + else if (!strcmp (argv[1], "fatal")) + mask = GW_LOG_FATAL; + else if (!strcmp (argv[1], "warn")) + mask = GW_LOG_WARN; + else if (!strcmp (argv[1], "acct")) + mask = GW_LOG_ACCT; + else + mask = GW_LOG_DEBUG; + switch (argc) + { + case 3: + gw_log (mask, mod, "%s", argv[2]); + break; + case 4: + gw_log (mask, mod, "%s %s", argv[2], argv[3]); + break; + case 5: + gw_log (mask, mod, "%s %s %s", argv[2], argv[3], argv[4]); + break; + case 6: + gw_log (mask, mod, "%s %s %s %s", argv[2], argv[3], argv[4], argv[5]); + break; + } + return TCL_OK; +} + + int Tcl_AppInit (Tcl_Interp *interp) { if (Tcl_Init (interp) == TCL_ERROR) @@ -220,6 +261,7 @@ static void *do_create (WCLIENT wcl, void *args) Tcl_CreateCommand (p->interp, "wform", proc_wform_invoke, p, NULL); Tcl_CreateCommand (p->interp, "wabort", proc_wabort_invoke, p, NULL); Tcl_CreateCommand (p->interp, "wflush", proc_wflush_invoke, p, NULL); + Tcl_CreateCommand (p->interp, "wlog", proc_wlog_invoke, p, NULL); sprintf (tmp_str, "%d", wcl->id); Tcl_SetVar (p->interp, "sessionId", tmp_str, TCL_GLOBAL_ONLY); return p; diff --git a/www/z39util.tcl b/www/z39util.tcl index 19b9a0e..796fdd2 100644 --- a/www/z39util.tcl +++ b/www/z39util.tcl @@ -1,5 +1,5 @@ # -# $Id: z39util.tcl,v 1.1 1995/11/06 17:44:23 adam Exp $ +# $Id: z39util.tcl,v 1.2 1995/11/07 14:57:00 adam Exp $ # proc saveState {} { uplevel #0 { @@ -137,18 +137,17 @@ proc display-full {zset no} { } } -proc display-rec {from to dfunc} { +proc display-rec {from to dfunc zz} { global setNo while {$from <= $to} { - eval "$dfunc z39.$setNo $from" + eval "$dfunc $zz.$setNo $from" incr from } } -proc build-query {} { +proc build-query {t} { global targets - global t set op {} set q {} @@ -255,6 +254,129 @@ proc z39search {setNo piggy} { return 1 } +proc init-m-response {i} { + global zstatus + global zleft + + wlog debug "init-m-response" + + set zstatus($i) 1 + incr zleft -1 +} + +proc connect-m-response {i} { + global zstatus + global zleft + + wlog debug "connect-m-response" + z39$i callback [list init-m-response $i] + if {[catch {z39$i init}]} { + set zstatus($i) -1 + incr zleft -1 + } +} + +proc fail-m-response {i} { + global zstatus + global zleft + + wlog debug "fail-m-response" + set zstatus($i) -1 + incr zleft -1 +} + +proc search-m-response {setNo i} { + global zleft + global zstatus + + incr zleft -1 + set zstatus($i) 2 +} + +proc z39msearch {setNo piggy} { + global zleft + global zstatus + global hist + + set not $hist($setNo,0,host) + + for {set i 1} {$i <= $not} {incr i} { + set host $hist($setNo,$i,host) + if {[catch {z39 failback fail-response}]} { + ir z39$i + } + if {[catch {set oldHost [z39$i connect]}]} { + set oldHost "" + } + if {$oldHost != $host} { + catch {z39$i disconnect} + } + z39$i callback [list connect-m-response $i] + z39$i failback [list fail-m-response $i] + } + set zleft 0 + for {set i 1} {$i <= $not} {incr i} { + set oldHost [z39$i connect] + set host $hist($setNo,$i,host) + if {$oldHost == $host} { + set zstatus($i) 1 + continue + } + html "Connecting to target " $host "
\n" + set zstatus($i) -1 + if {![catch {z39$i connect $host}]} { + incr zleft + } + } + while {$zleft > 0} { + wlog debug "Waiting for init response" + if {[catch {zwait zleft 10}]} { + break + } + } + set zleft 0 + for {set i 1} {$i <= $not} {incr i} { + html "host " $hist($setNo,$i,host) ": " + if {$zstatus($i) >= 1} { + html "ok
\n" + ir-set z39$i.$setNo z39$i + set hist($setNo,$i,offset) 0 + eval z39$i.$setNo databaseNames $hist($setNo,$i,database) + z39$i.$setNo preferredRecordSyntax USMARC + z39$i callback [list search-m-response $setNo $i] + + if {$piggy} { + z39$i.$setNo largeSetLowerBound 999999 + z39$i.$setNo smallSetUpperBound 0 + z39$i.$setNo mediumSetPresentNumber $hist($setNo,maxPresent) + } else { + z39$i.$setNo largeSetLowerBound 2 + z39$i.$setNo smallSetUpperBound 0 + z39$i.$setNo mediumSetPresentNumber 0 + } + set zstatus($i) 1 + wlog debug "search " $hist($setNo,$i,query) + z39$i.$setNo search $hist($setNo,$i,query) + incr zleft + } else { + html "fail
\n" + } + } + while {$zleft > 0} { + wlog debug "Waiting for search response" + if {[catch {zwait zleft 30}]} { + break + } + } + for {set i 1} {$i <= $not} {incr i} { + if {$zstatus($i) != 2} continue + set status [z39$i.$setNo responseStatus] + if {[lindex $status 0] != "NSD"} { + set hist($setNo,$i,offset) [z39$i.$setNo numberOfRecordsReturned] + } + } +} + proc z39present {setNo setOffset setMax dfunc} { global hist global sessionWait -- 1.7.10.4