By adding this, we move code from both ZOOM C and Metaproxy to YAZ.
YAZ_EXPORT
void yaz_set_esn(Z_RecordComposition **comp_p, const char *esn, NMEM nmem);
+/** \brief returns diagnostics from an init response
+ \param no number of diagnotic entry to get. 0=first, 1=second, ..
+ \param initrs InitResponse structure
+ \retuns diag entry or 0 (NULL) if none could be found
+*/
+YAZ_EXPORT
+Z_DefaultDiagFormat *yaz_decode_init_diag(int no, Z_InitResponse *initrs);
YAZ_END_CDECL
ill-get.c \
zget.c yaz-ccl.c diag-entry.c diag-entry.h \
logrpn.c \
- otherinfo.c pquery.c sortspec.c charneg.c initopt.c \
+ otherinfo.c pquery.c sortspec.c charneg.c initopt.c init_diag.c \
zoom-c.c zoom-z3950.c zoom-sru.c zoom-query.c zoom-record-cache.c \
zoom-event.c \
record_render.c zoom-socket.c zoom-opt.c zoom-p.h sru-p.h \
--- /dev/null
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2012 Index Data
+ * See the file LICENSE for details.
+ */
+/**
+ * \file init_diag.c
+ * \brief Decoding of diagnostics embedded in init response
+ */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <yaz/proto.h>
+
+static Z_DefaultDiagFormat *interpret_init_diag2(int *no,
+ Z_DiagnosticFormat *diag)
+{
+ int i;
+ for (i = 0; i < diag->num; i++)
+ {
+ Z_DiagnosticFormat_s *ds = diag->elements[i];
+ if (ds->which == Z_DiagnosticFormat_s_defaultDiagRec)
+ {
+ if (*no == 0)
+ return ds->u.defaultDiagRec;
+ (*no)--;
+ }
+ }
+ return 0;
+}
+
+Z_DefaultDiagFormat *yaz_decode_init_diag(int no, Z_InitResponse *initrs)
+{
+ Z_External *uif = initrs->userInformationField;
+ if (uif && uif->which == Z_External_userInfo1)
+ {
+ int i;
+ Z_OtherInformation *ui = uif->u.userInfo1;
+ 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)
+ {
+ Z_DefaultDiagFormat *r =
+ interpret_init_diag2
+ (&no, unit->information.externallyDefinedInfo->u.diag1);
+ if (r)
+ return r;
+ }
+ }
+ }
+ return 0;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
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 char *get_term_cstr(ODR odr, Z_Term *term) {
switch (term->which) {
if (!*initrs->result)
{
- Z_External *uif = initrs->userInformationField;
-
- ZOOM_set_error(c, ZOOM_ERROR_INIT, 0); /* default error */
-
- if (uif && uif->which == Z_External_userInfo1)
- interpret_otherinformation_field(c, uif->u.userInfo1);
+ Z_DefaultDiagFormat *df = yaz_decode_init_diag(0, initrs);
+ if (df)
+ response_default_diag(c, df);
+ else
+ ZOOM_set_error(c, ZOOM_ERROR_INIT, 0); /* default error */
}
else
{
$(OBJDIR)\zoom-opt.obj \
$(OBJDIR)\zoom-socket.obj \
$(OBJDIR)\initopt.obj \
+ $(OBJDIR)\init_diag.obj \
$(OBJDIR)\xmlquery.obj \
$(OBJDIR)\xmlerror.obj \
$(OBJDIR)\mime.obj \