[Net-z3950] [PATCH] Net::Z3950 -a option (so to speak)

Dave Mitchell davem at fdgroup.com
Mon May 20 18:09:04 CEST 2002


On Mon, May 20, 2002 at 10:15:45AM +0100, Mike Taylor wrote:
> I guess the way forward with this would be for me to figure out how to
> provoke Net::Z3950 to produce an APDU trace, as the "-a -" options ask
> the Yaz client to do.  Then we could compare the network traffic
> generated in the two cases.  I'm not going to have time to do this any
> time soon, though -- sorry.

As if by magic...

The following patch allows you to set a global debugging filehandle
(STDERR by default), then allows you to globally turn on or off APDU
packet dumping to that filehandle. Eg:

    use Net::Z3950;
    use IO::File;

    my $fh = IO::File->new('/tmp/apdu.log','w') or die "open: $!\n";

    Net::Z3950::apdu_debug_file($fh);
    Net::Z3950::apdu_debug(1);
    ....
    $conn = $mgr->connect( ....);
    ....
    Net::Z3950::apdu_debug(0);
    ....

I must confess to not really understanding all the low-level Yaz stuff
(ODR etc) - I just blindly mimicked how yaz-client prints its debugging
stuff.

I've only tested this on Perl 5.6.1, Solaris 8, yaz 1.7.something.

Now, I really must get on and do some proper work for a change... ;-)

Dave.

-- 
"There's something wrong with our bloody ships today, Chatfield."
Admiral Beatty at the Battle of Jutland, 31st May 1916.


# This is a patch for Net-Z3950-0.29.orig to update it to Net-Z3950-0.29
# 
# To apply this patch:
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'applypatch' program with this patch file as input.
#
# If you do not have 'applypatch', it is part of the 'makepatch' package
# that you can fetch from the Comprehensive Perl Archive Network:
# http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz
# In the above URL, 'x' should be 2 or higher.
#
# To apply this patch without the use of 'applypatch':
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'patch' program with this file as input.
#
#### End of Preamble ####

#### Patch data follows ####
diff -u 'Net-Z3950-0.29.orig/Z3950.pm' 'Net-Z3950-0.29/Z3950.pm'
Index: ./Z3950.pm
Prereq:  1.15 
--- ./Z3950.pm	Fri May 17 16:08:35 2002
+++ ./Z3950.pm	Mon May 20 16:26:28 2002
@@ -252,6 +252,26 @@
     return "unknown op " . $op;
 }
 
+=head2 apdu_debug()
+
+    use IO::File;
+    my $fh = IO::File->new('/tmp/apdu.log','w') or die "open: $!\n";
+
+    Net::Z3950::apdu_debug_file($fh);
+    Net::Z3950::apdu_debug(1);
+    ...
+    Net::Z3950::apdu_debug(0);
+
+Enables or disables a global debugging flag which causes all incoming
+and outgoing APDUs (application protocol data units) to be written
+to a file in a human-readable format. Similar to the C<-a> option of
+the F<yaz_client>.
+
+=head2 apdu_debug_file($fh)
+
+Sets the current output file handle for APDU debugging. If not set,
+defaults to STDERR.
+
 
 =head1 AUTHOR
 
diff -u 'Net-Z3950-0.29.orig/Z3950.xs' 'Net-Z3950-0.29/Z3950.xs'
Index: ./Z3950.xs
Prereq:  1.2 
--- ./Z3950.xs	Fri Oct 12 16:16:13 2001
+++ ./Z3950.xs	Mon May 20 16:27:43 2002
@@ -188,3 +188,13 @@
 yaz_write(cs, buf)
 	COMSTACK cs
 	databuf buf
+
+void
+apdu_debug(SV *flag)
+	CODE:
+	apdu_debug(SvTRUE(flag));
+
+
+void
+apdu_debug_file(FILE *file)
+
diff -u 'Net-Z3950-0.29.orig/yazwrap/receive.c' 'Net-Z3950-0.29/yazwrap/receive.c'
Index: ./yazwrap/receive.c
Prereq:  1.7 
--- ./yazwrap/receive.c	Fri May 17 16:56:57 2002
+++ ./yazwrap/receive.c	Mon May 20 15:56:38 2002
@@ -144,6 +144,7 @@
  */
 static SV *translateAPDU(Z_APDU *apdu, int *reasonp)
 {
+    apdu_dump(apdu);
     switch (apdu->which) {
     case Z_APDU_initResponse:
 	return translateInitResponse(apdu->u.initResponse, reasonp);
diff -u 'Net-Z3950-0.29.orig/yazwrap/send.c' 'Net-Z3950-0.29/yazwrap/send.c'
Index: ./yazwrap/send.c
Prereq:  1.5 
--- ./yazwrap/send.c	Mon Feb 11 12:57:34 2002
+++ ./yazwrap/send.c	Mon May 20 15:55:54 2002
@@ -106,6 +106,7 @@
     if (implementationVersion != 0)
 	req->implementationVersion = implementationVersion;
 
+    apdu_dump(apdu);
     return encode_apdu(odr, apdu, errmsgp);
 }
 
@@ -216,6 +217,7 @@
 	return nodata(*errmsgp = "unknown queryType");
     }
 
+    apdu_dump(apdu);
     return encode_apdu(odr, apdu, errmsgp);
 }
 
@@ -255,6 +257,7 @@
 	 record_syntax(odr, preferredRecordSyntax)) == 0)
 	return nodata(*errmsgp = "can't convert record syntax");
 
+    apdu_dump(apdu);
     return encode_apdu(odr, apdu, errmsgp);
 }
 
diff -u 'Net-Z3950-0.29.orig/yazwrap/util.c' 'Net-Z3950-0.29/yazwrap/util.c'
Index: ./yazwrap/util.c
Prereq:  1.2 
--- ./yazwrap/util.c	Fri Jun 22 09:32:38 2001
+++ ./yazwrap/util.c	Mon May 20 16:03:28 2002
@@ -52,3 +52,37 @@
 
     return CS_DATA;
 }
+
+
+static ODR debug_odr;
+static FILE *debug_fh;
+static int debug_enabled;
+
+/* if we've got APDU debugging enabled, dump the contents of the APDU */
+
+void apdu_dump(Z_APDU *apdu)
+{
+    if (!debug_enabled)
+	return;
+    if (!debug_fh)
+	debug_fh = stderr;
+    if (!debug_odr) {
+	debug_odr = odr_createmem(ODR_PRINT);
+	odr_setprint(debug_odr, debug_fh);
+    }
+    z_APDU(debug_odr, &apdu, 0, 0);
+    fflush(debug_fh);
+    odr_reset(debug_odr);
+}
+
+void apdu_debug(int flag)
+{
+    debug_enabled = flag;
+}
+
+void apdu_debug_file(FILE *file)
+{
+    debug_fh = file;
+}
+
+
diff -u 'Net-Z3950-0.29.orig/yazwrap/yazwrap.h' 'Net-Z3950-0.29/yazwrap/yazwrap.h'
Index: ./yazwrap/yazwrap.h
Prereq:  1.2 
--- ./yazwrap/yazwrap.h	Fri Oct 12 16:16:14 2001
+++ ./yazwrap/yazwrap.h	Mon May 20 15:58:26 2002
@@ -8,6 +8,7 @@
 
 #include <yaz/diagbib1.h>	/* Provide declaration of diagbib1_str() */
 #include <yaz/comstack.h>	/* Need COMSTACK typedef to parse this file */
+#include <yaz/z-core.h>		/* Need Z_APDU typedef to parse this file */
 
 /* Simple counted-length data buffer (so it can contain NULs) */
 typedef struct databuf {
@@ -93,3 +94,7 @@
 #define REASON_ERROR 23955	/* some other error (consult errno) */
 
 int yaz_write(COMSTACK cs, databuf buf);
+
+void apdu_dump(Z_APDU *apdu);
+void apdu_debug(int flag);
+void apdu_debug_file(FILE *file);
#### End of Patch data ####

#### ApplyPatch data follows ####
# Data version        : 1.0
# Date generated      : Mon May 20 16:39:25 2002
# Generated by        : makepatch 2.00_07*
# Recurse directories : Yes
# Excluded files      : (\A|/).*\~\Z
#                       (\A|/).*\.a\Z
#                       (\A|/).*\.bak\Z
#                       (\A|/).*\.BAK\Z
#                       (\A|/).*\.elc\Z
#                       (\A|/).*\.exe\Z
#                       (\A|/).*\.gz\Z
#                       (\A|/).*\.ln\Z
#                       (\A|/).*\.o\Z
#                       (\A|/).*\.obj\Z
#                       (\A|/).*\.olb\Z
#                       (\A|/).*\.old\Z
#                       (\A|/).*\.orig\Z
#                       (\A|/).*\.rej\Z
#                       (\A|/).*\.so\Z
#                       (\A|/).*\.Z\Z
#                       (\A|/)\.del\-.*\Z
#                       (\A|/)\.make\.state\Z
#                       (\A|/)\.nse_depinfo\Z
#                       (\A|/)core\Z
#                       (\A|/)tags\Z
#                       (\A|/)TAGS\Z
# p 'Z3950.pm' 8102 1021908388 0100644
# p 'Z3950.xs' 3220 1021908463 0100644
# p 'yazwrap/receive.c' 19742 1021906598 0100644
# p 'yazwrap/send.c' 11231 1021906554 0100644
# p 'yazwrap/util.c' 1373 1021907008 0100644
# p 'yazwrap/yazwrap.h' 3026 1021906706 0100644
#### End of ApplyPatch data ####

#### End of Patch kit [created: Mon May 20 16:39:25 2002] ####
#### Patch checksum: 196 5482 61129 ####
#### Checksum: 214 6177 52646 ####




More information about the Net-z3950 mailing list