/* This file is part of Metaproxy.
- Copyright (C) 2005-2012 Index Data
+ Copyright (C) 2005-2013 Index Data
Metaproxy is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
#include "sru_util.hpp"
#include "filter_sru_to_z3950.hpp"
-#include <yaz/zgdu.h>
-#include <yaz/z-core.h>
#include <yaz/srw.h>
#include <yaz/pquery.h>
#include <yaz/oid_db.h>
#include <iostream>
#include <sstream>
#include <string>
-/* #include <algorithm> */
#include <map>
namespace mp = metaproxy_1;
// send Z3950 package
z3950_package.move();
- // dead Z3950 backend detection
- if (z3950_package.session().is_closed())
- {
- yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.response->diagnostics),
- &(sru_pdu_res->u.response->num_diagnostics),
- YAZ_SRW_SYSTEM_TEMPORARILY_UNAVAILABLE, 0);
- return false;
- }
-
// check successful initResponse
Z_GDU *z3950_gdu = z3950_package.response().get();
+ int error = YAZ_SRW_SYSTEM_TEMPORARILY_UNAVAILABLE;
+ const char *addinfo = 0;
if (z3950_gdu && z3950_gdu->which == Z_GDU_Z3950
- && z3950_gdu->u.z3950->which == Z_APDU_initResponse
- && *z3950_gdu->u.z3950->u.initResponse->result)
- return true;
+ && z3950_gdu->u.z3950->which == Z_APDU_initResponse)
+ {
+ Z_InitResponse *initrs = z3950_gdu->u.z3950->u.initResponse;
+ if (*initrs->result)
+ return true;
+ int no = 0;
+ while (1)
+ {
+ Z_DefaultDiagFormat *df = yaz_decode_init_diag(no, initrs);
+ if (!df)
+ break;
+ yaz_add_srw_diagnostic(odr_en,
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
+ yaz_diag_bib1_to_srw(*df->condition),
+ df->u.v2Addinfo);
+ no++;
+ }
+ if (no)
+ return false; // got least one diagnostic from init
+
+ // we just have result=false.
+ error = YAZ_SRW_AUTHENTICATION_ERROR;
+ }
+ else
+ addinfo = "sru_z3950: expected initResponse";
yaz_add_srw_diagnostic(odr_en,
&(sru_pdu_res->u.response->diagnostics),
&(sru_pdu_res->u.response->num_diagnostics),
- YAZ_SRW_SYSTEM_TEMPORARILY_UNAVAILABLE, 0);
+ error, addinfo);
return false;
}