2 * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
3 * yaz.c - decoding and printing utility based on the YAZ Toolkit
5 * Copyright (c) 1998-2001 R. Carbone <rocco@ntop.org>
6 * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * Operating System include files
34 #include "yaz/proto.h"
39 void please_yaz_help_me (z3950apdu * hook)
41 extern unsigned char * z3950;
42 extern int z3950_size;
45 * Variable to keep the Z39.50 APDUs. The definitions are in the
46 * the structures defined by the YAZ Toolkit.
51 * Decoding/Printing streams
57 * The stream used for decoding
59 #define MAXBERSIZE (2048 * 2048)
60 unsigned char berbuffer [MAXBERSIZE];
63 * Allocate a stream for input data
65 decode = odr_createmem (ODR_DECODE);
68 printf ("Not enough memory to create an input stream\n");
73 * Allocate a stream for printing data
75 printing = odr_createmem (ODR_PRINT);
78 printf ("Not enough memory to create a printing stream\n");
84 * Initialize the decoding routines
86 memcpy (berbuffer, z3950, z3950_size);
88 odr_setbuf (decode, (char *) berbuffer, z3950_size, 0);
91 * Perform BER decoding
93 if (z_APDU (decode, & apdu, 0, 0))
98 printf ("Z3950: ----- Z39.50 APDU -----\n"),
99 printf ("Z3950: APDU %ld arrived at %s\n", z3950_apduno,
100 timestamp (hook -> t, ABS_FMT)),
101 printf ("Z3950: Total size = %d\n", z3950_size),
105 * save the time the last apdu was displayed
107 if (z3950_apduno == 1)
108 gettimeofday (& first_apdu, NULL);
111 * print standard summary information accordingly to the format
113 * id time source:port -> destination:port type
115 printf ("Z3950: %5ld %s %s:%d -> %s:%d %s\n",
116 z3950_apduno, timestamp (hook -> t, DELTA_FMT),
117 hook -> calling, hook -> srcport, hook -> called, hook -> dstport,
121 gettimeofday (& last_apdu, NULL);
124 fmemdmp (stdout, z3950, z3950_size, "Z39.50 APDU");
128 * Yup! We have the APDU now. Try to print it
130 odr_setbuf (printing, (char *) berbuffer, z3950_size, 0);
133 z_APDU (printing, & apdu, 0, 0);
136 odr_reset (printing);
137 printing -> buf = NULL;
141 * release memory previously allocated
143 odr_destroy (decode);
144 odr_destroy (printing);