#include <yaz/tokenizer.h>
#include <yaz/zoom.h>
#include <yaz/otherinfo.h>
+#include <yaz/match_glob.h>
namespace mp = metaproxy_1;
namespace yf = mp::filter;
public:
std::string authentication;
std::string authenticationMode;
+ std::string contentAuthentication;
std::string cfAuth;
std::string cfProxy;
std::string cfSubDB;
std::string sortStrategy;
std::string extraArgs;
std::string rpn2cql_fname;
+ std::string retry_on_failure;
+ std::map<std::string, std::string> cf_param;
bool use_turbomarc;
bool piggyback;
CCL_bibset ccl_bibset;
class Zoom::Backend : boost::noncopyable {
friend class Impl;
friend class Frontend;
- std::string zurl;
mp::wrbuf m_apdu_wrbuf;
ZOOM_connection m_connection;
ZOOM_resultset m_resultset;
xmlDoc *explain_doc;
std::string m_proxy;
cql_transform_t cqlt;
+ std::string retry_on_failure;
public:
Backend();
~Backend();
std::string torus_searchable_url;
std::string torus_content_url;
std::string torus_auth_url;
+ std::string torus_allow_ip;
std::string default_realm;
+ std::string torus_auth_hostname;
std::map<std::string,std::string> fieldmap;
std::string xsldir;
std::string file_path;
piggyback = true;
use_turbomarc = true;
sortStrategy = "embed";
+ retry_on_failure = "1"; // existing default (should have been false)
ccl_bibset = ccl_qual_dup(base);
}
s->authenticationMode = mp::xml::get_text(ptr);
}
else if (!strcmp((const char *) ptr->name,
+ "contentAuthentication"))
+ {
+ s->contentAuthentication = mp::xml::get_text(ptr);
+ }
+ else if (!strcmp((const char *) ptr->name,
"cfAuth"))
{
s->cfAuth = mp::xml::get_text(ptr);
}
else if (!strcmp((const char *) ptr->name, "rpn2cql"))
s->rpn2cql_fname = mp::xml::get_text(ptr);
+ else if (!strcmp((const char *) ptr->name,
+ "retryOnFailure"))
+ {
+ s->retry_on_failure = mp::xml::get_text(ptr);
+ }
+ else if (strlen((const char *) ptr->name) > 3 &&
+ !memcmp((const char *) ptr->name, "cf_", 3))
+ {
+ s->cf_param[(const char *) ptr->name + 3] = mp::xml::get_text(ptr);
+ }
}
return s;
}
torus_content_url = mp::xml::get_text(attr->children);
else if (!strcmp((const char *) attr->name, "auth_url"))
torus_auth_url = mp::xml::get_text(attr->children);
+ else if (!strcmp((const char *) attr->name, "allow_ip"))
+ torus_allow_ip = 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, "auth_hostname"))
+ torus_auth_hostname = mp::xml::get_text(attr->children);
else if (!strcmp((const char *) attr->name, "xsldir"))
xsldir = mp::xml::get_text(attr->children);
else if (!strcmp((const char *) attr->name, "element_transform"))
else
torus_db = database;
- std::string authentication;
- std::string content_authentication;
std::string content_proxy;
std::string realm = session_realm;
if (realm.length() == 0)
const char *param_content_user = 0;
const char *param_content_password = 0;
const char *param_nocproxy = 0;
+ const char *param_retry = 0;
int no_parms = 0;
char **names;
if (input_args.length())
no_parms = yaz_uri_to_array(input_args.c_str(),
odr, &names, &values);
- // adding 10 because we'll be adding other URL args
+ // adding 20 because we'll be adding other URL args
const char **out_names = (const char **)
- odr_malloc(odr, (10 + no_parms) * sizeof(*out_names));
+ odr_malloc(odr, (20 + no_parms) * sizeof(*out_names));
const char **out_values = (const char **)
- odr_malloc(odr, (10 + no_parms) * sizeof(*out_values));
+ odr_malloc(odr, (20 + no_parms) * sizeof(*out_values));
// may be changed if it's a content connection
std::string torus_url = m_p->torus_searchable_url;
content_proxy = value;
else if (!strcmp(name, "nocproxy"))
param_nocproxy = value;
+ else if (!strcmp(name, "retry"))
+ param_retry = value;
else if (!strcmp(name, "proxy"))
{
char **dstr;
return m_backend;
}
- if (param_user)
- {
- authentication = std::string(param_user);
- if (param_password)
- authentication += "/" + std::string(param_password);
- }
- if (param_content_user)
- {
- content_authentication = std::string(param_content_user);
- if (param_content_password)
- content_authentication += "/" + std::string(param_content_password);
- }
-
if (torus_db.compare("IR-Explain---1") == 0)
return explain_search(package, database, error, addinfo, odr, torus_url,
torus_db, realm);
b->m_frontend_database = database;
b->enable_cproxy = param_nocproxy ? false : true;
+ if (param_retry)
+ b->retry_on_failure = param_retry;
+ else
+ b->retry_on_failure = b->sptr->retry_on_failure;
+
if (sptr->query_encoding.length())
b->set_option("rpnCharset", sptr->query_encoding);
maximumRecords > 0 */
b->set_option("piggyback", sptr->piggyback ? "1" : "0");
- if (authentication.length() == 0)
- authentication = sptr->authentication;
+ std::string authentication = sptr->authentication;
+ if (param_user)
+ {
+ authentication = std::string(param_user);
+ if (param_password)
+ authentication += "/" + std::string(param_password);
+ }
+ std::string content_authentication = sptr->contentAuthentication;
+ if (param_content_user)
+ {
+ content_authentication = std::string(param_content_user);
+ if (param_content_password)
+ content_authentication += "/" + std::string(param_content_password);
+ }
if (proxy.length() == 0)
proxy = sptr->cfProxy;
{
// A CF target
b->set_option("user", sptr->cfAuth);
- if (authentication.length())
+ if (param_user)
+ {
+ out_names[no_out_args] = "user";
+ out_values[no_out_args++] = odr_strdup(odr, param_user);
+ if (param_password)
+ {
+ out_names[no_out_args] = "password";
+ out_values[no_out_args++] = odr_strdup(odr, param_password);
+ }
+ }
+ else if (authentication.length())
{
size_t found = authentication.find('/');
if (found != std::string::npos)
out_names[no_out_args] = "nocproxy";
out_values[no_out_args++] = odr_strdup(odr, param_nocproxy);
}
+ std::map<std::string,std::string>::const_iterator it;
+ for (it = sptr->cf_param.begin(); it != sptr->cf_param.end(); it++)
+ {
+ int i;
+ const char *n = it->first.c_str();
+ for (i = 0; i < no_out_args; i++)
+ if (!strcmp(n, out_names[i]))
+ break;
+ if (i == no_out_args)
+ {
+ out_names[no_out_args] = odr_strdup(odr, n);
+ out_values[no_out_args++] = odr_strdup(odr, it->second.c_str());
+ }
+ }
}
else
{
if (!*error)
{
for (i = 0; i < number_to_present; i++)
+ {
if (!recs[i])
break;
+
+ const char *addinfo;
+ int sur_error = ZOOM_record_error(recs[i], 0 /* msg */,
+ &addinfo, 0 /* diagset */);
+ if (sur_error ==
+ YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS && addinfo &&
+ !strcmp(addinfo,
+ "ZOOM C generated. Present phase and no records"))
+ break;
+ }
}
if (i > 0)
{ // only return records if no error and at least one record
npl->num_records = i;
npl->records = (Z_NamePlusRecord **)
odr_malloc(odr, i * sizeof(*npl->records));
- for (i = 0; i < number_to_present; i++)
+ for (i = 0; i < npl->num_records; i++)
{
Z_NamePlusRecord *npr = 0;
const char *addinfo;
struct yaz_poll_fd pfd;
yaz_poll_add(pfd.input_mask, yaz_poll_except);
- if (cs->io_pending && CS_WANT_WRITE)
+ if (cs->io_pending & CS_WANT_WRITE)
yaz_poll_add(pfd.input_mask, yaz_poll_write);
if (cs->io_pending & CS_WANT_READ)
yaz_poll_add(pfd.input_mask, yaz_poll_read);
error = YAZ_BIB1_PROXY_FAILURE;
*addinfo = odr_strdup(odr, b->m_proxy.c_str());
}
- else if (same_retries == 0 && proxy_retries == 0)
+ else if (b && b->retry_on_failure.compare("0")
+ && same_retries == 0 && proxy_retries == 0)
{
log_diagnostic(package, error, *addinfo);
same_retries++;
case CCL_ERR_TRUNC_NOT_LEFT:
case CCL_ERR_TRUNC_NOT_RIGHT:
case CCL_ERR_TRUNC_NOT_BOTH:
-#ifdef CCL_ERR_TRUNC_NOT_EMBED
case CCL_ERR_TRUNC_NOT_EMBED:
-#endif
-#ifdef CCL_ERR_TRUNC_NOT_SINGLE
case CCL_ERR_TRUNC_NOT_SINGLE:
-#endif
error = YAZ_BIB1_UNSUPP_SEARCH;
break;
}
}
Z_OtherInformation **oi = &req->otherInfo;
- const char *ip =
+ const char *ip_cstr =
yaz_oi_get_string_oid(oi, yaz_oid_userinfo_client_ip, 1, 0);
- if (!ip)
- ip = package.origin().get_address().c_str();
+ std::string ip;
+ if (ip_cstr)
+ ip = ip_cstr;
+ else
+ ip = package.origin().get_address();
- yaz_log(YLOG_LOG, "IP=%s", ip);
+ yaz_log(YLOG_LOG, "IP=%s", ip.c_str());
+ {
+ NMEM nmem = nmem_create();
+ char **darray;
+ int i, num;
+ nmem_strsplit_blank(nmem, m_p->torus_allow_ip.c_str(), &darray, &num);
+ for (i = 0; i < num; i++)
+ {
+ yaz_log(YLOG_LOG, "check against %s+%s", darray[i], ip.c_str());
+ if (yaz_match_glob(darray[i], ip.c_str()))
+ break;
+ }
+ nmem_destroy(nmem);
+ if (i < num)
+ return; /* allow this IP */
+ }
std::string torus_query;
int failure_code;
}
else
{
- torus_query = "ip encloses/net.ipaddress \"";
+ torus_query = "ipRanges encloses/net.ipaddress \"";
torus_query += escape_cql_term(std::string(ip));
torus_query += "\"";
+
+ if (m_p->torus_auth_hostname.length())
+ {
+ torus_query += " AND hostName == \"";
+ torus_query += escape_cql_term(m_p->torus_auth_hostname);
+ torus_query += "\"";
+ }
failure_code = YAZ_BIB1_INIT_AC_BLOCKED_NETWORK_ADDRESS;
}