/*
- * $Id: zoom-c.c,v 1.8 2002-11-30 22:30:51 mike Exp $
+ * Copyright (c) 2000-2002, Index Data
+ * See the file LICENSE for details.
+ *
+ * $Id: zoom-c.c,v 1.11 2002-12-10 13:14:14 adam Exp $
*
* ZOOM layer for C, connections, result sets, queries.
*/
#include <yaz/otherinfo.h>
#include <yaz/log.h>
#include <yaz/pquery.h>
+#include <yaz/marcdisp.h>
#include <yaz/diagbib1.h>
#include <yaz/charneg.h>
#include <yaz/ill.h>
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)
{
case ZOOM_ERROR_INTERNAL:
break;
default:
- c->error = ZOOM_ERROR_NONE;
- xfree (c->addinfo);
- c->addinfo = 0;
+ set_bib1_error(c, ZOOM_ERROR_NONE);
}
}
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;
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);
}
}
c->state = STATE_IDLE;
- c->error = ZOOM_ERROR_CONNECT;
+ set_bib1_error(c, ZOOM_ERROR_CONNECT);
return zoom_complete;
}
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;
}
static void response_diag (ZOOM_connection c, Z_DiagRec *p)
{
+ int oclass;
Z_DefaultDiagFormat *r;
char *addinfo = 0;
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:
}
return 0;
}
- else if (!strcmp (type, "xml") &&
- npr->which == Z_NamePlusRecord_databaseRecord)
+ else if (npr->which == Z_NamePlusRecord_databaseRecord &&
+ (!strcmp (type, "xml") || !strcmp(type, "oai")))
{
Z_External *r = (Z_External *) npr->u.databaseRecord;
oident *ent = oid_getentbyoid(r->direct_reference);
}
else if (r->which == Z_External_octet)
{
+ int marc_decode_type = YAZ_MARC_MARCXML;
+
+ if (!strcmp(type, "oai"))
+ marc_decode_type = YAZ_MARC_OAIMARC;
switch (ent->value)
{
case VAL_SOIF:
r->u.octet_aligned->buf,
rec->wrbuf_marc, 0,
r->u.octet_aligned->len,
- 2) > 0)
+ marc_decode_type) > 0)
{
if (len) *len = wrbuf_len(rec->wrbuf_marc);
return wrbuf_buf(rec->wrbuf_marc);
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
{
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);
}
}
}
{
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
{
}
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);
}
}
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
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;
}
}
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)
*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;
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);
}
}
else
{
- c->error = ZOOM_ERROR_CONNECT;
+ set_bib1_error(c, ZOOM_ERROR_CONNECT);
do_close (c);
ZOOM_connection_put_event (c, event);
}
{
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);
}
{
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);