From 85fcb12fe992e4dc0fa91e95fc320943c1c26cc5 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 9 Dec 2002 23:32:29 +0000 Subject: [PATCH] New ZOOM connection options: targetImplementation{Id,Name,Version} New function ZOOM_connection_error_x. --- CHANGELOG | 6 ++++ doc/zoom.xml | 44 ++++++++++++++++++---------- include/yaz/zoom.h | 6 +++- util/marcdisp.c | 19 ++++++------ zoom/zoomtst2.c | 9 +++--- zutil/zoom-c.c | 83 ++++++++++++++++++++++++++++++++++------------------ zutil/zoom-p.h | 3 +- 7 files changed, 110 insertions(+), 60 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a8647a7..2995857 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,11 @@ Possible compatibility problems with earlier versions marked with '*'. +For ZOOM connection, the options targetImplementation{Id,Name,Version} +are set when Init Response is received. + +New function ZOOM_connection_error_x similar to ZOOM_connection_error +but returns diagnostic set as well. + New function yaz_strerror which is a portable wrapper for strerror/strerror_r/GetLastMessage. diff --git a/doc/zoom.xml b/doc/zoom.xml index 8b442c0..549e16d 100644 --- a/doc/zoom.xml +++ b/doc/zoom.xml @@ -1,6 +1,5 @@ - + Building clients with ZOOM - &zoom; is an acronym for 'Z39.50 Object-Orientation Model' and is an initiative started by Mike Taylor (Mike is from the UK, which @@ -22,14 +21,14 @@ ZOOM web-site for more information. - + In order to fully understand this chapter you should read and try the example programs zoomtst1.c, zoomtst2.c, .. in the zoom directory. - + The C language misses features found in object oriented languages such as C++, Java, etc. For example, you'll have to manually, @@ -50,15 +49,15 @@ The Connection object is a session with a target. - #include <yaz/zoom.h> + #include <yaz/zoom.h> - ZOOM_connection ZOOM_connection_new (const char *host, int portnum); + ZOOM_connection ZOOM_connection_new (const char *host, int portnum); - ZOOM_connection ZOOM_connection_create (ZOOM_options options); - - void ZOOM_connection_connect(ZOOM_connection c, const char *host, + ZOOM_connection ZOOM_connection_create (ZOOM_options options); + + void ZOOM_connection_connect(ZOOM_connection c, const char *host, int portnum); - void ZOOM_connection_destroy (ZOOM_connection c); + void ZOOM_connection_destroy (ZOOM_connection c); Connection objects are created with either function @@ -91,7 +90,7 @@ The ZOOM_connection_option_set allows you to set an option given by key to the value value for the connection. - Function ZOOM_connection_option_get returns + Function ZOOM_connection_option_get returns the value for an option given by key. ZOOM Connection Options @@ -118,7 +117,7 @@ none passAuthentication password - none + none hostTarget host. This setting is "read-only". It's automatically set internally when connecting to a target. @@ -144,6 +143,16 @@ charset Character set for negotiation. none + + targetImplementationId Implementation ID of target. + none + + targetImplementationName Implementation Name of target. + none + + targetImplementationVersion Implementation Version + of target. + none
@@ -155,15 +164,20 @@
int ZOOM_connection_error (ZOOM_connection c, const char **cp, - const char **addinfo); + const char **addinfo); + int ZOOM_connection_error_x (ZOOM_connection c, const char **cp, + const char **addinfo, const char **dset); - Use ZOOM_connection_error to check for + Function ZOOM_connection_error checks for errors for the last operation(s) performed. The function returns zero if no errors occurred; non-zero otherwise indicating the error. Pointers cp and addinfo holds messages for the error and additional-info if passed as - non-NULL. + non-NULL. Function + ZOOM_connection_error_x is an extended version + of ZOOM_connection_error that is capable of + returning name of diagnostic set in dset. Protocol behavior diff --git a/include/yaz/zoom.h b/include/yaz/zoom.h index 0937a20..f0a9b74 100644 --- a/include/yaz/zoom.h +++ b/include/yaz/zoom.h @@ -1,6 +1,6 @@ /* * Public header for ZOOM C. - * $Id: zoom.h,v 1.14 2002-11-30 22:30:51 mike Exp $ + * $Id: zoom.h,v 1.15 2002-12-09 23:32:29 adam Exp $ */ #include @@ -66,6 +66,10 @@ ZOOM_API(int) ZOOM_connection_error (ZOOM_connection c, const char **cp, const char **addinfo); +ZOOM_API(int) +ZOOM_connection_error_x (ZOOM_connection c, const char **cp, + const char **addinfo, const char **diagset); + /* returns error code */ ZOOM_API(int) ZOOM_connection_errcode (ZOOM_connection c); diff --git a/util/marcdisp.c b/util/marcdisp.c index 7cadfcd..3e4e9d2 100644 --- a/util/marcdisp.c +++ b/util/marcdisp.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: marcdisp.c,v 1.24 2002-12-03 10:03:27 adam Exp $ + * $Id: marcdisp.c,v 1.25 2002-12-09 23:32:29 adam Exp $ */ #if HAVE_CONFIG_H @@ -93,9 +93,8 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml) case YAZ_MARC_MARCXML: wrbuf_printf( wr, - "\n" - " \n" - " %.24s\n", buf); + "\n" + " %.24s\n", buf); break; } } @@ -176,9 +175,9 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml) break; case YAZ_MARC_MARCXML: if (identifier_flag) - wrbuf_printf (wr, " "); break; case YAZ_MARC_MARCXML: - wrbuf_puts (wr, " "); @@ -294,9 +293,9 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml) break; case YAZ_MARC_MARCXML: if (identifier_flag) - wrbuf_puts (wr, " \n"); + wrbuf_puts (wr, " \n"); else - wrbuf_puts (wr, " \n"); + wrbuf_puts (wr, " \n"); break; } } @@ -312,7 +311,7 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml) wrbuf_puts (wr, "\n"); break; case YAZ_MARC_MARCXML: - wrbuf_puts (wr, " \n\n"); + wrbuf_puts (wr, "\n"); break; } return record_length; diff --git a/zoom/zoomtst2.c b/zoom/zoomtst2.c index 59f85f2..1ff3612 100644 --- a/zoom/zoomtst2.c +++ b/zoom/zoomtst2.c @@ -1,5 +1,5 @@ /* - * $Id: zoomtst2.c,v 1.4 2002-09-24 08:00:32 adam Exp $ + * $Id: zoomtst2.c,v 1.5 2002-12-09 23:32:29 adam Exp $ * * Asynchronous single-target client performing search (no retrieval) */ @@ -14,7 +14,7 @@ int main(int argc, char **argv) ZOOM_connection z; ZOOM_resultset r; int error; - const char *errmsg, *addinfo; + const char *errmsg, *addinfo, *diagset; if (argc < 3) { @@ -41,9 +41,10 @@ int main(int argc, char **argv) ; /* see if any error occurred */ - if ((error = ZOOM_connection_error(z, &errmsg, &addinfo))) + if ((error = ZOOM_connection_error_x(z, &errmsg, &addinfo, &diagset))) { - fprintf (stderr, "Error: %s (%d) %s\n", errmsg, error, addinfo); + fprintf (stderr, "Error: %s: %s (%d) %s\n", diagset, errmsg, error, + addinfo); exit (2); } else /* OK print hit count */ diff --git a/zutil/zoom-c.c b/zutil/zoom-c.c index 9ca55c1..1363725 100644 --- a/zutil/zoom-c.c +++ b/zutil/zoom-c.c @@ -1,5 +1,8 @@ /* - * $Id: zoom-c.c,v 1.9 2002-12-03 10:03:27 adam Exp $ + * Copyright (c) 2000-2002, Index Data + * See the file LICENSE for details. + * + * $Id: zoom-c.c,v 1.10 2002-12-09 23:32:29 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -77,6 +80,14 @@ static ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c) return event; } +static void set_bib1_error (ZOOM_connection c, int error) +{ + xfree (c->addinfo); + c->addinfo = 0; + c->error = error; + c->diagset = "Bib-1"; +} + static void clear_error (ZOOM_connection c) { @@ -90,9 +101,7 @@ static void clear_error (ZOOM_connection c) case ZOOM_ERROR_INTERNAL: break; default: - c->error = ZOOM_ERROR_NONE; - xfree (c->addinfo); - c->addinfo = 0; + set_bib1_error(c, ZOOM_ERROR_NONE); } } @@ -169,8 +178,8 @@ ZOOM_connection_create (ZOOM_options options) c->mask = 0; c->reconnect_ok = 0; c->state = STATE_IDLE; - c->error = ZOOM_ERROR_NONE; c->addinfo = 0; + set_bib1_error(c, ZOOM_ERROR_NONE); c->buf_in = 0; c->len_in = 0; c->buf_out = 0; @@ -324,7 +333,7 @@ ZOOM_connection_connect(ZOOM_connection c, c->async = ZOOM_options_get_bool (c->options, "async", 0); - c->error = ZOOM_ERROR_NONE; + set_bib1_error(c, ZOOM_ERROR_NONE); task = ZOOM_connection_add_task (c, ZOOM_TASK_CONNECT); @@ -627,7 +636,7 @@ static zoom_ret do_connect (ZOOM_connection c) } } c->state = STATE_IDLE; - c->error = ZOOM_ERROR_CONNECT; + set_bib1_error(c, ZOOM_ERROR_CONNECT); return zoom_complete; } @@ -706,7 +715,7 @@ static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out) odr_destroy(odr_pr); } yaz_log (LOG_DEBUG, "encoding failed"); - c->error = ZOOM_ERROR_ENCODE; + set_bib1_error(c, ZOOM_ERROR_ENCODE); odr_reset(out); return -1; } @@ -962,6 +971,7 @@ static zoom_ret ZOOM_connection_send_search (ZOOM_connection c) static void response_diag (ZOOM_connection c, Z_DiagRec *p) { + int oclass; Z_DefaultDiagFormat *r; char *addinfo = 0; @@ -969,10 +979,12 @@ static void response_diag (ZOOM_connection c, Z_DiagRec *p) c->addinfo = 0; if (p->which != Z_DiagRec_defaultFormat) { - c->error = ZOOM_ERROR_DECODE; + set_bib1_error(c, ZOOM_ERROR_DECODE); return; } r = p->u.defaultFormat; + c->diagset = yaz_z3950oid_to_str(r->diagnosticSetId, &oclass); + switch (r->which) { case Z_DefaultDiagFormat_v2Addinfo: @@ -1308,7 +1320,7 @@ static void handle_records (ZOOM_connection c, Z_Records *sr, if (sr->u.multipleNonSurDiagnostics->num_diagRecs >= 1) response_diag(c, sr->u.multipleNonSurDiagnostics->diagRecs[0]); else - c->error = ZOOM_ERROR_DECODE; + set_bib1_error(c, ZOOM_ERROR_DECODE); } else { @@ -1339,7 +1351,7 @@ static void handle_records (ZOOM_connection c, Z_Records *sr, else if (present_phase) { /* present response and we didn't get any records! */ - c->error = ZOOM_ERROR_DECODE; + set_bib1_error(c, ZOOM_ERROR_DECODE); } } } @@ -2011,9 +2023,18 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) { case Z_APDU_initResponse: initrs = apdu->u.initResponse; + ZOOM_connection_option_set(c, "targetImplementationId", + initrs->implementationId ? + initrs->implementationId : ""); + ZOOM_connection_option_set(c, "targetImplementationName", + initrs->implementationName ? + initrs->implementationName : ""); + ZOOM_connection_option_set(c, "targetImplementationVersion", + initrs->implementationVersion ? + initrs->implementationVersion : ""); if (!*initrs->result) { - c->error = ZOOM_ERROR_INIT; + set_bib1_error(c, ZOOM_ERROR_INIT); } else { @@ -2091,12 +2112,12 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) } else { - c->error = ZOOM_ERROR_CONNECTION_LOST; + set_bib1_error(c, ZOOM_ERROR_CONNECTION_LOST); do_close(c); } break; default: - c->error = ZOOM_ERROR_DECODE; + set_bib1_error(c, ZOOM_ERROR_DECODE); do_close(c); } } @@ -2140,7 +2161,7 @@ static int do_read (ZOOM_connection c) ZOOM_connection_put_event (c, event); if (!z_APDU (c->odr_in, &apdu, 0, 0)) { - c->error = ZOOM_ERROR_DECODE; + set_bib1_error(c, ZOOM_ERROR_DECODE); do_close (c); } else @@ -2171,9 +2192,9 @@ static zoom_ret do_write_ex (ZOOM_connection c, char *buf_out, int len_out) return zoom_complete; } if (c->state == STATE_CONNECTING) - c->error = ZOOM_ERROR_CONNECT; + set_bib1_error(c, ZOOM_ERROR_CONNECT); else - c->error = ZOOM_ERROR_CONNECTION_LOST; + set_bib1_error(c, ZOOM_ERROR_CONNECTION_LOST); do_close (c); return zoom_complete; } @@ -2278,8 +2299,8 @@ ZOOM_diag_str (int error) } ZOOM_API(int) -ZOOM_connection_error (ZOOM_connection c, const char **cp, - const char **addinfo) +ZOOM_connection_error_x (ZOOM_connection c, const char **cp, + const char **addinfo, const char **diagset) { int error = c->error; if (cp) @@ -2287,15 +2308,19 @@ ZOOM_connection_error (ZOOM_connection c, const char **cp, *cp = ZOOM_diag_str(error); } if (addinfo) - { - if (c->addinfo) - *addinfo = c->addinfo; - else - *addinfo = ""; - } + *addinfo = c->addinfo ? c->addinfo : ""; + if (diagset) + *diagset = c->diagset ? c->diagset : ""; return c->error; } +ZOOM_API(int) +ZOOM_connection_error (ZOOM_connection c, const char **cp, + const char **addinfo) +{ + return ZOOM_connection_error_x(c, cp, addinfo, 0); +} + static int ZOOM_connection_do_io(ZOOM_connection c, int mask) { ZOOM_Event event = 0; @@ -2306,7 +2331,7 @@ static int ZOOM_connection_do_io(ZOOM_connection c, int mask) if (r == CS_NONE) { event = ZOOM_Event_create (ZOOM_EVENT_CONNECT); - c->error = ZOOM_ERROR_CONNECT; + set_bib1_error(c, ZOOM_ERROR_CONNECT); do_close (c); ZOOM_connection_put_event (c, event); } @@ -2334,7 +2359,7 @@ static int ZOOM_connection_do_io(ZOOM_connection c, int mask) } else { - c->error = ZOOM_ERROR_CONNECT; + set_bib1_error(c, ZOOM_ERROR_CONNECT); do_close (c); ZOOM_connection_put_event (c, event); } @@ -2483,7 +2508,7 @@ ZOOM_event (int no, ZOOM_connection *cs) { ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_TIMEOUT); /* timeout and this connection was waiting */ - c->error = ZOOM_ERROR_TIMEOUT; + set_bib1_error(c, ZOOM_ERROR_TIMEOUT); do_close (c); ZOOM_connection_put_event(c, event); } @@ -2519,7 +2544,7 @@ ZOOM_event (int no, ZOOM_connection *cs) { ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_TIMEOUT); /* timeout and this connection was waiting */ - c->error = ZOOM_ERROR_TIMEOUT; + set_bib1_error(c, ZOOM_ERROR_TIMEOUT); do_close (c); yaz_log (LOG_DEBUG, "timeout"); ZOOM_connection_put_event(c, event); diff --git a/zutil/zoom-p.h b/zutil/zoom-p.h index b6cf2ae..c8210e0 100644 --- a/zutil/zoom-p.h +++ b/zutil/zoom-p.h @@ -1,6 +1,6 @@ /* * Private C header for ZOOM C. - * $Id: zoom-p.h,v 1.1 2002-09-16 18:45:14 adam Exp $ + * $Id: zoom-p.h,v 1.2 2002-12-09 23:32:29 adam Exp $ */ #include #include @@ -30,6 +30,7 @@ struct ZOOM_connection_p { char *host_port; int error; char *addinfo; + const char *diagset; int state; int mask; int reconnect_ok; -- 1.7.10.4