bool &enable_pz2_transform,
bool &assume_marc8_charset);
- Z_Records *get_records(Odr_int start,
+ Z_Records *get_records(Package &package,
+ Odr_int start,
Odr_int number_to_present,
int *error,
char **addinfo,
ODR odr, BackendPtr b,
Odr_oid *preferredRecordSyntax,
const char *element_set_name);
+
+ void log_diagnostic(mp::Package &package,
+ int error, const char *addinfo);
public:
Frontend(Impl *impl);
~Frontend();
std::map<mp::Session, FrontendPtr> m_clients;
boost::mutex m_mutex;
boost::condition m_cond_session_ready;
- std::string torus_url;
+ std::string torus_searchable_url;
+ std::string torus_content_url;
std::string default_realm;
std::map<std::string,std::string> fieldmap;
std::string xsldir;
const char *msg = 0;
const char *zoom_addinfo = 0;
const char *dset = 0;
- *error = ZOOM_connection_error_x(m_connection, &msg, &zoom_addinfo, &dset);
- if (*error)
+ int error0 = ZOOM_connection_error_x(m_connection, &msg,
+ &zoom_addinfo, &dset);
+ if (error0)
{
- if (*error >= ZOOM_ERROR_CONNECT)
- {
- // turn ZOOM diagnostic into a Bib-1 2: with addinfo=zoom err msg
- *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
- *addinfo = (char *) odr_malloc(
- odr, 20 + strlen(msg) +
- (zoom_addinfo ? strlen(zoom_addinfo) : 0));
- strcpy(*addinfo, msg);
- if (zoom_addinfo)
- {
- strcat(*addinfo, ": ");
- strcat(*addinfo, zoom_addinfo);
- }
- }
+ if (!dset)
+ dset = "Unknown";
+
+ if (!strcmp(dset, "info:srw/diagnostic/1"))
+ *error = yaz_diag_srw_to_bib1(error0);
+ else if (!strcmp(dset, "Bib-1"))
+ *error = error0;
else
+ *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+
+ *addinfo = (char *) odr_malloc(
+ odr, 30 + strlen(dset) + strlen(msg) +
+ (zoom_addinfo ? strlen(zoom_addinfo) : 0));
+ **addinfo = '\0';
+ if (zoom_addinfo && *zoom_addinfo)
{
- if (dset && !strcmp(dset, "info:srw/diagnostic/1"))
- *error = yaz_diag_srw_to_bib1(*error);
- *addinfo = (char *) odr_malloc(
- odr, 20 + (zoom_addinfo ? strlen(zoom_addinfo) : 0));
- **addinfo = '\0';
- if (zoom_addinfo && *zoom_addinfo)
- {
- strcpy(*addinfo, zoom_addinfo);
- strcat(*addinfo, " ");
- }
- strcat(*addinfo, "(backend)");
+ strcpy(*addinfo, zoom_addinfo);
+ strcat(*addinfo, " ");
}
+ sprintf(*addinfo + strlen(*addinfo), "(%s %d %s)", dset, error0, msg);
}
}
for (attr = ptr->properties; attr; attr = attr->next)
{
if (!strcmp((const char *) attr->name, "url"))
- torus_url = mp::xml::get_text(attr->children);
+ torus_searchable_url = mp::xml::get_text(attr->children);
+ else if (!strcmp((const char *) attr->name, "content_url"))
+ torus_content_url = mp::xml::get_text(attr->children);
else if (!strcmp((const char *) attr->name, "realm"))
default_realm = mp::xml::get_text(attr->children);
else if (!strcmp((const char *) attr->name, "xsldir"))
"Bad attribute " + std::string((const char *)
attr->name));
}
+ // If content_url is not given, use value of searchable, to
+ // ensure backwards compatibility
+ if (!torus_content_url.length())
+ torus_content_url = torus_searchable_url;
configure_local_records(ptr->children, test_only);
}
else if (!strcmp((const char *) ptr->name, "cclmap"))
std::string authentication;
std::string content_authentication;
std::string proxy;
+ std::string content_proxy;
std::string realm = m_p->default_realm;
const char *param_user = 0;
const char **out_values = (const char **)
odr_malloc(odr, (10 + no_parms) * sizeof(*out_values));
+ // may be changed if it's a content connection
+ std::string torus_url = m_p->torus_searchable_url;
int i;
for (i = 0; i < no_parms; i++)
{
param_content_user = value;
else if (!strcmp(name, "content-password"))
param_content_password = value;
+ else if (!strcmp(name, "content-proxy"))
+ content_proxy = value;
else if (!strcmp(name, "proxy"))
proxy = value;
else if (!strcmp(name, "cproxysession"))
{
out_names[no_out_args] = name;
out_values[no_out_args++] = value;
+ torus_url = m_p->torus_content_url;
}
else if (!strcmp(name, "realm"))
realm = value;
it = m_p->s_map.find(torus_db);
if (it != m_p->s_map.end())
sptr = it->second;
- else if (m_p->torus_url.length() > 0)
+ else if (torus_url.length() > 0)
{
- xmlDoc *doc = mp::get_searchable(m_p->torus_url, torus_db, realm,
- m_p->proxy);
+ xmlDoc *doc = mp::get_searchable(package,torus_url, torus_db,
+ realm, m_p->proxy);
if (!doc)
{
*error = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
if (m_p->apdu_log)
b->set_option("apdulog", "1");
- if (sptr->piggyback)
+ if (sptr->piggyback && sptr->sru.length())
b->set_option("count", "1"); /* some SRU servers INSIST on getting
maximumRecords > 0 */
b->set_option("piggyback", sptr->piggyback ? "1" : "0");
if (*error == 0)
create_content_session(package, b, error, addinfo, odr,
content_authentication.length() ?
- content_authentication : authentication, proxy);
+ content_authentication : authentication,
+ content_proxy.length() ? content_proxy : proxy);
if (*error == 0)
m_backend = b;
return b;
b->set_option("schema", element_set_name);
}
-Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
+Z_Records *yf::Zoom::Frontend::get_records(Package &package,
+ Odr_int start,
Odr_int number_to_present,
int *error,
char **addinfo,
enable_pz2_transform,
assume_marc8_charset);
+ package.log("zoom", YLOG_LOG, "pz2_retrieval: %s . pz2_transform: %s",
+ enable_pz2_retrieval ? "yes" : "no",
+ enable_pz2_transform ? "yes" : "no");
+
if (start < 0 || number_to_present <=0)
return records;
{
Z_NamePlusRecord *npr = 0;
const char *addinfo;
+
+ package.log("zoom", YLOG_LOG, "Inspecting record at position %d",
+ start + i);
int sur_error = ZOOM_record_error(recs[i], 0 /* msg */,
&addinfo, 0 /* diagset */);
if (sur_error)
{
+ log_diagnostic(package, sur_error, addinfo);
npr = zget_surrogateDiagRec(odr, odr_database, sur_error,
addinfo);
}
strcat(rec_type_str, "; charset=");
strcat(rec_type_str, record_encoding);
}
-
+
+ package.log("zoom", YLOG_LOG, "Getting record of type %s",
+ rec_type_str);
int rec_len;
xmlChar *xmlrec_buf = 0;
const char *rec_buf = ZOOM_record_get(recs[i], rec_type_str,
{
std::string addinfo("ZOOM_record_get failed for type ");
+ int error = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
addinfo += rec_type_str;
- npr = zget_surrogateDiagRec(
- odr, odr_database,
- YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
- addinfo.c_str());
+ log_diagnostic(package, error, addinfo.c_str());
+ npr = zget_surrogateDiagRec(odr, odr_database,
+ error, addinfo.c_str());
+ }
+ else
+ {
+ package.log_write(rec_buf, rec_len);
+ package.log_write("\r\n", 2);
}
if (rec_buf && b->xsp && enable_pz2_transform)
xmlDoc *rec_doc = xmlParseMemory(rec_buf, rec_len);
if (!rec_doc)
{
+ const char *addinfo = "xml parse failed for record";
+ int error = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+ log_diagnostic(package, error, addinfo);
npr = zget_surrogateDiagRec(
- odr, odr_database,
- YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
- "xml parse failed for record");
+ odr, odr_database, error, addinfo);
}
else
{
xsltSaveResultToString(&xmlrec_buf, &rec_len,
rec_res, b->xsp);
rec_buf = (const char *) xmlrec_buf;
+ package.log("zoom", YLOG_LOG, "xslt successful");
+ package.log_write(rec_buf, rec_len);
xmlFreeDoc(rec_res);
}
if (!rec_buf)
{
std::string addinfo;
+ int error =
+ YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
addinfo = "xslt apply failed for "
+ b->sptr->transform_xsl_fname;
+ log_diagnostic(package, error, addinfo.c_str());
npr = zget_surrogateDiagRec(
- odr, odr_database,
- YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
- addinfo.c_str());
+ odr, odr_database, error, addinfo.c_str());
}
xmlFreeDoc(rec_doc);
}
return r;
}
+void yf::Zoom::Frontend::log_diagnostic(mp::Package &package,
+ int error, const char *addinfo)
+{
+ const char *err_msg = yaz_diag_bib1_str(error);
+ if (addinfo)
+ package.log("zoom", YLOG_WARN, "Diagnostic %d %s: %s",
+ error, err_msg, addinfo);
+ else
+ package.log("zoom", YLOG_WARN, "Diagnostic %d %s:",
+ error, err_msg);
+}
+
void yf::Zoom::Frontend::handle_search(mp::Package &package)
{
Z_GDU *gdu = package.request().get();
Z_SearchRequest *sr = apdu_req->u.searchRequest;
if (sr->num_databaseNames != 1)
{
- apdu_res = odr.create_searchResponse(
- apdu_req, YAZ_BIB1_TOO_MANY_DATABASES_SPECIFIED, 0);
+ int error = YAZ_BIB1_TOO_MANY_DATABASES_SPECIFIED;
+ log_diagnostic(package, error, 0);
+ apdu_res = odr.create_searchResponse(apdu_req, error, 0);
package.response() = apdu_res;
return;
}
&addinfo, odr);
if (error)
{
- apdu_res =
- odr.create_searchResponse(apdu_req, error, addinfo);
+ log_diagnostic(package, error, addinfo);
+ apdu_res = odr.create_searchResponse(apdu_req, error, addinfo);
package.response() = apdu_res;
return;
}
if (r)
{
cql_parser_destroy(cp);
- package.log("zoom", YLOG_WARN, "CQL syntax error");
+ error = YAZ_BIB1_MALFORMED_QUERY;
+ const char *addinfo = "CQL syntax error";
+ log_diagnostic(package, error, addinfo);
apdu_res =
- odr.create_searchResponse(apdu_req,
- YAZ_BIB1_MALFORMED_QUERY,
- "CQL syntax error");
+ odr.create_searchResponse(apdu_req, error, addinfo);
package.response() = apdu_res;
return;
}
if (cn_error)
{
// hopefully we are getting a ptr to a index+relation+term node
+ error = YAZ_BIB1_UNSUPP_USE_ATTRIBUTE;
addinfo = 0;
if (cn_error->which == CQL_NODE_ST)
addinfo = cn_error->u.st.index;
-
- apdu_res =
- odr.create_searchResponse(apdu_req,
- YAZ_BIB1_UNSUPP_USE_ATTRIBUTE,
- addinfo);
+
+ log_diagnostic(package, error, addinfo);
+ apdu_res = odr.create_searchResponse(apdu_req, error, addinfo);
package.response() = apdu_res;
return;
}
cql_parser_destroy(cp);
if (r)
{
- apdu_res =
- odr.create_searchResponse(apdu_req,
- YAZ_BIB1_MALFORMED_QUERY,
- "CQL to CCL conversion error");
+ error = YAZ_BIB1_MALFORMED_QUERY;
+ const char *addinfo = "CQL to CCL conversion error";
+
+ log_diagnostic(package, error, addinfo);
+ apdu_res = odr.create_searchResponse(apdu_req, error, addinfo);
package.response() = apdu_res;
return;
}
}
else
{
- apdu_res =
- odr.create_searchResponse(apdu_req, YAZ_BIB1_QUERY_TYPE_UNSUPP, 0);
+ error = YAZ_BIB1_QUERY_TYPE_UNSUPP;
+ const char *addinfo = 0;
+ log_diagnostic(package, error, addinfo);
+ apdu_res = odr.create_searchResponse(apdu_req, error, addinfo);
package.response() = apdu_res;
return;
}
if (!cn)
{
char *addinfo = odr_strdup(odr, ccl_err_msg(cerror));
- int z3950_diag = YAZ_BIB1_MALFORMED_QUERY;
+ error = YAZ_BIB1_MALFORMED_QUERY;
switch (cerror)
{
case CCL_ERR_UNKNOWN_QUAL:
- z3950_diag = YAZ_BIB1_UNSUPP_USE_ATTRIBUTE;
+ error = YAZ_BIB1_UNSUPP_USE_ATTRIBUTE;
break;
case CCL_ERR_TRUNC_NOT_LEFT:
case CCL_ERR_TRUNC_NOT_RIGHT:
case CCL_ERR_TRUNC_NOT_BOTH:
- z3950_diag = YAZ_BIB1_UNSUPP_TRUNCATION_ATTRIBUTE;
+ error = YAZ_BIB1_UNSUPP_TRUNCATION_ATTRIBUTE;
break;
}
- apdu_res =
- odr.create_searchResponse(apdu_req, z3950_diag, addinfo);
+ log_diagnostic(package, error, addinfo);
+ apdu_res = odr.create_searchResponse(apdu_req, error, addinfo);
package.response() = apdu_res;
return;
}
wrbuf_destroy(pqf_wrbuf);
if (status)
{
- apdu_res =
- odr.create_searchResponse(apdu_req, YAZ_BIB1_MALFORMED_QUERY,
- "can not convert from RPN to CQL/SOLR");
+ error = YAZ_BIB1_MALFORMED_QUERY;
+ const char *addinfo = "can not convert from RPN to CQL/SOLR";
+ log_diagnostic(package, error, addinfo);
+ apdu_res = odr.create_searchResponse(apdu_req, error, addinfo);
package.response() = apdu_res;
return;
}
Odr_int number_of_records_returned = 0;
Z_Records *records = get_records(
+ package,
0, number_to_present, &error, &addinfo,
&number_of_records_returned, odr, b, sr->preferredRecordSyntax,
element_set_name);
+ if (error)
+ log_diagnostic(package, error, addinfo);
apdu_res = odr.create_searchResponse(apdu_req, error, addinfo);
if (records)
{
Odr_int number_of_records_returned = 0;
int error = 0;
char *addinfo = 0;
- Z_Records *records = get_records(
+ Z_Records *records = get_records(package,
*pr->resultSetStartPoint - 1, *pr->numberOfRecordsRequested,
&error, &addinfo, &number_of_records_returned, odr, m_backend,
pr->preferredRecordSyntax, element_set_name);