* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: zoom-c.c,v 1.38 2005-05-02 19:17:48 adam Exp $
+ * $Id: zoom-c.c,v 1.41 2005-05-17 11:48:36 adam Exp $
*/
/**
* \file zoom-c.c
xfree (c->charset);
val = ZOOM_options_get (c->options, "charset");
if (val && *val)
- {
c->charset = xstrdup (val);
- yaz_log(YLOG_LOG, "connect charset=%s", c->charset);
- }
else
c->charset = 0;
ZOOM_options_get(c->options, "implementationName"),
odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName));
- version = odr_strdup(c->odr_out, "$Revision: 1.38 $");
+ version = odr_strdup(c->odr_out, "$Revision: 1.41 $");
if (strlen(version) > 10) /* check for unexpanded CVS strings */
version[strlen(version)-2] = '\0';
ireq->implementationVersion = odr_prepend(c->odr_out,
return send_APDU (c, apdu);
}
-static void response_diag (ZOOM_connection c, Z_DiagRec *p)
+static void response_default_diag(ZOOM_connection c, Z_DefaultDiagFormat *r)
{
int oclass;
- Z_DefaultDiagFormat *r;
char *addinfo = 0;
-
- xfree (c->addinfo);
- c->addinfo = 0;
- if (p->which != Z_DiagRec_defaultFormat)
- {
- set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0);
- return;
- }
- r = p->u.defaultFormat;
+
switch (r->which)
{
case Z_DefaultDiagFormat_v2Addinfo:
addinfo = r->u.v3Addinfo;
break;
}
+ xfree (c->addinfo);
+ c->addinfo = 0;
set_dset_error(c, *r->condition,
yaz_z3950oid_to_str(r->diagnosticSetId, &oclass),
addinfo, 0);
}
+static void response_diag(ZOOM_connection c, Z_DiagRec *p)
+{
+ if (p->which != Z_DiagRec_defaultFormat)
+ set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0);
+ else
+ response_default_diag(c, p->u.defaultFormat);
+}
+
ZOOM_API(ZOOM_record)
ZOOM_record_clone (ZOOM_record srec)
{
return;
}
if (sr && sr->which == Z_Records_NSD)
- {
- Z_DiagRec dr, *dr_p = &dr;
- dr.which = Z_DiagRec_defaultFormat;
- dr.u.defaultFormat = sr->u.nonSurrogateDiagnostic;
-
- response_diag (c, dr_p);
- }
+ response_default_diag(c, sr->u.nonSurrogateDiagnostic);
else if (sr && sr->which == Z_Records_multipleNSD)
{
if (sr->u.multipleNonSurDiagnostics->num_diagRecs >= 1)
Z_NamePlusRecord *myrec =
zget_surrogateDiagRec(resultset->odr, 0, 14, 0);
record_cache_add(resultset, myrec, resultset->start);
- yaz_log(YLOG_LOG, "pseudo record 1, at pos %d",
- resultset->start);
}
}
else if (present_phase)
Z_NamePlusRecord *myrec =
zget_surrogateDiagRec(resultset->odr, 0, 14, 0);
record_cache_add(resultset, myrec, resultset->start);
- yaz_log(YLOG_LOG, "pseudo record 1, at pos %d",
- resultset->start);
}
}
}
return 1;
}
+static void interpret_init_diag(ZOOM_connection c,
+ Z_DiagnosticFormat *diag)
+{
+ if (diag->num > 0)
+ {
+ Z_DiagnosticFormat_s *ds = diag->elements[0];
+ if (ds->which == Z_DiagnosticFormat_s_defaultDiagRec)
+ response_default_diag(c, ds->u.defaultDiagRec);
+ }
+}
+
+
+static void interpret_otherinformation_field(ZOOM_connection c,
+ Z_OtherInformation *ui)
+{
+ int i;
+ for (i = 0; i < ui->num_elements; i++)
+ {
+ Z_OtherInformationUnit *unit = ui->list[i];
+ if (unit->which == Z_OtherInfo_externallyDefinedInfo &&
+ unit->information.externallyDefinedInfo &&
+ unit->information.externallyDefinedInfo->which ==
+ Z_External_diag1)
+ {
+ interpret_init_diag(c, unit->information.externallyDefinedInfo->u.diag1);
+ }
+ }
+}
static void handle_apdu (ZOOM_connection c, Z_APDU *apdu)
{
initrs->implementationVersion : "");
if (!*initrs->result)
{
- set_ZOOM_error(c, ZOOM_ERROR_INIT, 0);
+ Z_External *uif = initrs->userInformationField;
+
+ set_ZOOM_error(c, ZOOM_ERROR_INIT, 0); /* default error */
+
+ if (uif && uif->which == Z_External_userInfo1)
+ interpret_otherinformation_field(c, uif->u.userInfo1);
}
else
{
ZOOM_API(int)
ZOOM_event (int no, ZOOM_connection *cs)
{
- int timeout = 5000;
+ int timeout = 30; /* default timeout in seconds */
+ int timeout_set = 0; /* whether it was overriden at all */
#if HAVE_SYS_POLL_H
struct pollfd pollfds[1024];
ZOOM_connection poll_cs[1024];
continue;
if (max_fd < fd)
max_fd = fd;
-
- this_timeout = ZOOM_options_get_int (c->options, "timeout", -1);
- if (this_timeout != -1 && this_timeout < timeout)
- timeout = this_timeout;
+
+ /* -1 is used for indefinite timeout (no timeout), so -2 here. */
+ this_timeout = ZOOM_options_get_int (c->options, "timeout", -2);
+ if (this_timeout != -2)
+ {
+ /* ensure the minimum timeout is used */
+ if (!timeout_set)
+ timeout = this_timeout;
+ else if (this_timeout != -1 && this_timeout < timeout)
+ timeout = this_timeout;
+ timeout_set = 1;
+ }
#if HAVE_SYS_POLL_H
if (mask)
{
}
#endif
}
- if (timeout >= 5000)
- timeout = 30;
-
if (!nfds)
return 0;
#if HAVE_SYS_POLL_H
- r = poll (pollfds, nfds, timeout * 1000);
+ r = poll (pollfds, nfds, (timeout == -1 ? -1 : timeout * 1000));
for (i = 0; i<nfds; i++)
{
ZOOM_connection c = poll_cs[i];
tv.tv_sec = timeout;
tv.tv_usec = 0;
yaz_log (log_level, "select start");
- r = select (max_fd+1, &input, &output, &except, &tv);
+ r = select (max_fd+1, &input, &output, &except, (timeout == -1 ? 0 : &tv));
yaz_log (log_level, "select stop, returned r=%d", r);
for (i = 0; i<no; i++)
{