#include <metaproxy/package.hpp>
#include <metaproxy/util.hpp>
#include <metaproxy/xmlutil.hpp>
+#include <yaz/comstack.h>
+#include <yaz/poll.h>
#include "torus.hpp"
#include <libxslt/xsltutils.h>
std::string urlRecipe;
std::string contentConnector;
std::string sortStrategy;
+ std::string rpn2cql_fname;
bool use_turbomarc;
bool piggyback;
CCL_bibset ccl_bibset;
std::string m_frontend_database;
SearchablePtr sptr;
xsltStylesheetPtr xsp;
- std::string content_session_id;
+ std::string cproxy_host;
bool enable_cproxy;
bool enable_explain;
xmlDoc *explain_doc;
+ std::string m_proxy;
+ cql_transform_t cqlt;
public:
Backend();
~Backend();
Impl *m_p;
bool m_is_virtual;
bool m_in_use;
+ std::string session_realm;
yazpp_1::GDU m_init_gdu;
BackendPtr m_backend;
void handle_package(mp::Package &package);
void handle_search(mp::Package &package);
+ void auth(mp::Package &package, Z_InitRequest *req,
+ int *error, char **addinfo, ODR odr);
+
BackendPtr explain_search(mp::Package &package,
std::string &database,
int *error,
char **addinfo,
mp::odr &odr,
+ std::string torus_url,
std::string &torus_db,
std::string &realm);
void handle_present(mp::Package &package);
ODR odr, BackendPtr b,
Odr_oid *preferredRecordSyntax,
const char *element_set_name);
-
+ bool retry(mp::Package &package,
+ mp::odr &odr,
+ BackendPtr b,
+ int &error, char **addinfo,
+ int &proxy_step, int &same_retries,
+ int &proxy_retries);
void log_diagnostic(mp::Package &package,
int error, const char *addinfo);
public:
const char *path);
private:
void configure_local_records(const xmlNode * ptr, bool test_only);
+ bool check_proxy(const char *proxy);
+
+
+
FrontendPtr get_frontend(mp::Package &package);
void release_frontend(mp::Package &package);
SearchablePtr parse_torus_record(const xmlNode *ptr);
boost::condition m_cond_session_ready;
std::string torus_searchable_url;
std::string torus_content_url;
+ std::string torus_auth_url;
std::string default_realm;
std::map<std::string,std::string> fieldmap;
std::string xsldir;
std::string file_path;
std::string content_proxy_server;
std::string content_tmp_file;
+ std::string content_config_file;
bool apdu_log;
CCL_bibset bibset;
std::string element_transform;
xsltStylesheetPtr record_xsp;
std::map<std::string,SearchablePtr> s_map;
std::string zoom_timeout;
+ int proxy_timeout;
};
}
}
xsltFreeStylesheet(xsp);
if (explain_doc)
xmlFreeDoc(explain_doc);
+ cql_transform_close(cqlt);
ZOOM_connection_destroy(m_connection);
ZOOM_resultset_destroy(m_resultset);
}
*error = yaz_diag_srw_to_bib1(error0);
else if (!strcmp(dset, "Bib-1"))
*error = error0;
+ else if (!strcmp(dset, "ZOOM"))
+ {
+ *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+ if (error0 == ZOOM_ERROR_INIT)
+ *error = YAZ_BIB1_INIT_AC_AUTHENTICATION_SYSTEM_ERROR;
+ else if (error0 == ZOOM_ERROR_DECODE)
+ {
+ if (zoom_addinfo)
+ {
+ if (strstr(zoom_addinfo, "Authentication") ||
+ strstr(zoom_addinfo, "authentication"))
+ *error = YAZ_BIB1_INIT_AC_AUTHENTICATION_SYSTEM_ERROR;
+ }
+ }
+ }
else
*error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
yf::Zoom::Impl::Impl() :
apdu_log(false), element_transform("pz2") , element_raw("raw"),
- zoom_timeout("40")
+ zoom_timeout("40"), proxy_timeout(1)
{
bibset = ccl_qual_mk();
{
s->sortStrategy = mp::xml::get_text(ptr);
}
+ else if (!strcmp((const char *) ptr->name, "rpn2cql"))
+ s->rpn2cql_fname = mp::xml::get_text(ptr);
}
return s;
}
std::string explain_xslt_fname;
std::string record_xslt_fname;
- content_tmp_file = "/tmp/cf.XXXXXX.p";
if (path && *path)
{
file_path = path;
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, "auth_url"))
+ torus_auth_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"))
for (attr = ptr->properties; attr; attr = attr->next)
{
if (!strcmp((const char *) attr->name, "server"))
+ {
+ yaz_log(YLOG_WARN,
+ "contentProxy's server attribute is deprecated");
+ yaz_log(YLOG_LOG,
+ "Specify config_file instead. For example:");
+ yaz_log(YLOG_LOG,
+ " content_file=\"/etc/cf-proxy/cproxy.cfg\"");
content_proxy_server = mp::xml::get_text(attr->children);
+ }
else if (!strcmp((const char *) attr->name, "tmp_file"))
content_tmp_file = mp::xml::get_text(attr->children);
+ else if (!strcmp((const char *) attr->name, "config_file"))
+ content_config_file = mp::xml::get_text(attr->children);
else
throw mp::filter::FilterException(
"Bad attribute " + std::string((const char *)
{
if (!strcmp((const char *) attr->name, "timeout"))
zoom_timeout = mp::xml::get_text(attr->children);
+ else if (!strcmp((const char *) attr->name, "proxy_timeout"))
+ proxy_timeout = mp::xml::get_int(attr->children, 1);
else
throw mp::filter::FilterException(
"Bad attribute " + std::string((const char *)
{
if (b->sptr->contentConnector.length())
{
- char *fname = (char *) xmalloc(m_p->content_tmp_file.length() + 8);
- strcpy(fname, m_p->content_tmp_file.c_str());
+ std::string proxyhostname;
+ std::string tmp_file;
+ bool legacy_format = false;
+
+ if (m_p->content_proxy_server.length())
+ {
+ proxyhostname = m_p->content_proxy_server;
+ legacy_format = true;
+ }
+
+ if (m_p->content_tmp_file.length())
+ tmp_file = m_p->content_tmp_file;
+
+ if (m_p->content_config_file.length())
+ {
+ FILE *inf = fopen(m_p->content_config_file.c_str(), "r");
+ if (inf)
+ {
+ char buf[1024];
+ while (fgets(buf, sizeof(buf)-1, inf))
+ {
+ char *cp;
+ cp = strchr(buf, '#');
+ if (cp)
+ *cp = '\0';
+ cp = strchr(buf, '\n');
+ if (cp)
+ *cp = '\0';
+ cp = strchr(buf, ':');
+ if (cp)
+ {
+ char *cp1 = cp;
+ while (cp1 != buf && cp1[-1] == ' ')
+ cp1--;
+ *cp1 = '\0';
+ cp++;
+ while (*cp == ' ')
+ cp++;
+ if (!strcmp(buf, "proxyhostname"))
+ proxyhostname = cp;
+ if (!strcmp(buf, "sessiondir") && *cp)
+ {
+ if (cp[strlen(cp)-1] == '/')
+ cp[strlen(cp)-1] = '\0';
+ tmp_file = std::string(cp) + std::string("/cf.XXXXXX.p");
+ }
+ }
+ }
+ fclose(inf);
+ }
+ else
+ {
+ package.log("zoom", YLOG_WARN|YLOG_ERRNO,
+ "unable to open content config %s",
+ m_p->content_config_file.c_str());
+ *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+ *addinfo = (char *) odr_malloc(odr, 60 + tmp_file.length());
+ sprintf(*addinfo, "unable to open content config %s",
+ m_p->content_config_file.c_str());
+ return false;
+ }
+ }
+
+ if (proxyhostname.length() == 0)
+ {
+ package.log("zoom", YLOG_WARN, "no proxyhostname");
+ return true;
+ }
+ if (tmp_file.length() == 0)
+ {
+ package.log("zoom", YLOG_WARN, "no tmp_file");
+ return true;
+ }
+
+ char *fname = xstrdup(tmp_file.c_str());
char *xx = strstr(fname, "XXXXXX");
if (!xx)
{
- xx = fname + strlen(fname);
- strcat(fname, "XXXXXX");
+ package.log("zoom", YLOG_WARN, "bad tmp_file %s", tmp_file.c_str());
+ *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+ *addinfo = (char *) odr_malloc(odr, 60 + tmp_file.length());
+ sprintf(*addinfo, "bad format of content tmp_file: %s",
+ tmp_file.c_str());
+ xfree(fname);
+ return false;
}
char tmp_char = xx[6];
sprintf(xx, "%06d", ((unsigned) rand()) % 1000000);
+ if (legacy_format)
+ b->cproxy_host = std::string(xx) + "." + proxyhostname;
+ else
+ b->cproxy_host = proxyhostname + "/" + xx;
xx[6] = tmp_char;
FILE *file = fopen(fname, "w");
xfree(fname);
return false;
}
- b->content_session_id.assign(xx, 6);
mp::wrbuf w;
wrbuf_puts(w, "#content_proxy\n");
wrbuf_printf(w, "connector: %s\n", b->sptr->contentConnector.c_str());
std::string &database, int *error, char **addinfo, mp::odr &odr,
int *proxy_step)
{
+ bool connection_reuse = false;
+ std::string proxy;
+
std::list<BackendPtr>::const_iterator map_it;
if (m_backend && !m_backend->enable_explain &&
m_backend->m_frontend_database == database)
{
- m_backend->connect("", error, addinfo, odr);
- return m_backend;
+ connection_reuse = true;
+ proxy = m_backend->m_proxy;
}
std::string input_args;
std::string authentication;
std::string content_authentication;
- std::string proxy;
std::string content_proxy;
- std::string realm = m_p->default_realm;
+ std::string realm = session_realm;
+ if (realm.length() == 0)
+ realm = m_p->default_realm;
const char *param_user = 0;
const char *param_password = 0;
char **dstr;
int dnum = 0;
nmem_strsplit(((ODR) odr)->mem, ",", value, &dstr, &dnum);
- if (*proxy_step >= dnum)
- *proxy_step = 0;
+ if (connection_reuse)
+ {
+ // find the step after our current proxy
+ int i;
+ for (i = 0; i < dnum; i++)
+ if (!strcmp(proxy.c_str(), dstr[i]))
+ break;
+ if (i >= dnum - 1)
+ *proxy_step = 0;
+ else
+ *proxy_step = i + 1;
+ }
else
{
- proxy = dstr[*proxy_step];
-
- (*proxy_step)++;
- if (*proxy_step == dnum)
+ // step is known.. Guess our proxy from it
+ if (*proxy_step >= dnum)
*proxy_step = 0;
+ else
+ {
+ proxy = dstr[*proxy_step];
+
+ (*proxy_step)++;
+ if (*proxy_step == dnum)
+ *proxy_step = 0;
+ }
}
}
else if (!strcmp(name, "cproxysession"))
out_values[no_out_args++] = value;
torus_url = m_p->torus_content_url;
}
- else if (!strcmp(name, "realm"))
+ else if (!strcmp(name, "realm") && session_realm.length() == 0)
realm = value;
+ else if (!strcmp(name, "torus_url") && session_realm.length() == 0)
+ torus_url = value;
else if (name[0] == 'x' && name[1] == '-')
{
out_names[no_out_args] = name;
*addinfo = msg;
return notfound;
}
+ }
+ if (proxy.length())
+ package.log("zoom", YLOG_LOG, "proxy: %s", proxy.c_str());
+
+ if (connection_reuse)
+ {
+ m_backend->connect("", error, addinfo, odr);
+ return m_backend;
}
+
if (param_user)
{
authentication = std::string(param_user);
}
if (torus_db.compare("IR-Explain---1") == 0)
- return explain_search(package, database, error, addinfo, odr, torus_db,
- realm);
+ return explain_search(package, database, error, addinfo, odr, torus_url,
+ torus_db, realm);
SearchablePtr sptr;
realm, m_p->proxy);
if (!doc)
{
- *error = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
- *addinfo = odr_strdup(odr, torus_db.c_str());
+ *error = YAZ_BIB1_UNSPECIFIED_ERROR;
+ *addinfo = odr_strdup(odr, "Torus server unavailable or "
+ "incorrectly configured");
BackendPtr b;
return b;
}
const xmlNode *ptr = xmlDocGetRootElement(doc);
- if (ptr)
- { // presumably ptr is a records element node
- // parse first record in document
- for (ptr = ptr->children; ptr; ptr = ptr->next)
+ if (ptr && ptr->type == XML_ELEMENT_NODE)
+ {
+ if (!strcmp((const char *) ptr->name, "record"))
+ {
+ sptr = m_p->parse_torus_record(ptr);
+ }
+ else if (!strcmp((const char *) ptr->name, "records"))
{
- if (ptr->type == XML_ELEMENT_NODE
- && !strcmp((const char *) ptr->name, "record"))
+ for (ptr = ptr->children; ptr; ptr = ptr->next)
{
- if (sptr)
+ if (ptr->type == XML_ELEMENT_NODE
+ && !strcmp((const char *) ptr->name, "record"))
{
- *error = YAZ_BIB1_UNSPECIFIED_ERROR;
- *addinfo = (char*) odr_malloc(odr, 40 + database.length()),
- sprintf(*addinfo, "multiple records for udb=%s",
- database.c_str());
- xmlFreeDoc(doc);
- BackendPtr b;
- return b;
+ if (sptr)
+ {
+ *error = YAZ_BIB1_UNSPECIFIED_ERROR;
+ *addinfo = (char*)
+ odr_malloc(odr, 40 + torus_db.length());
+ sprintf(*addinfo, "multiple records for udb=%s",
+ database.c_str());
+ xmlFreeDoc(doc);
+ BackendPtr b;
+ return b;
+ }
+ sptr = m_p->parse_torus_record(ptr);
}
- sptr = m_p->parse_torus_record(ptr);
}
}
+ else
+ {
+ *error = YAZ_BIB1_UNSPECIFIED_ERROR;
+ *addinfo = (char*) odr_malloc(
+ odr, 40 + strlen((const char *) ptr->name));
+ sprintf(*addinfo, "bad root element for torus: %s", ptr->name);
+ xmlFreeDoc(doc);
+ BackendPtr b;
+ return b;
+ }
}
xmlFreeDoc(doc);
}
}
}
+ cql_transform_t cqlt = 0;
+ if (sptr->rpn2cql_fname.length())
+ {
+ char fullpath[1024];
+ char *cp = yaz_filepath_resolve(sptr->rpn2cql_fname.c_str(),
+ m_p->file_path.c_str(), 0, fullpath);
+ if (cp)
+ cqlt = cql_transform_open_fname(fullpath);
+ }
+ else
+ cqlt = cql_transform_create();
+
+ if (!cqlt)
+ {
+ *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+ *addinfo = odr_strdup(odr, "Missing/invalid cql2rpn file");
+ BackendPtr b;
+ xsltFreeStylesheet(xsp);
+ return b;
+ }
+
m_backend.reset();
BackendPtr b(new Backend);
+ b->cqlt = cqlt;
b->sptr = sptr;
b->xsp = xsp;
b->m_frontend_database = database;
if (proxy.length() == 0)
proxy = sptr->cfProxy;
+ b->m_proxy = proxy;
if (sptr->cfAuth.length())
{
if (proxy.length())
b->set_option("proxy", proxy);
}
- if (proxy.length())
- package.log("zoom", YLOG_LOG, "proxy: %s", proxy.c_str());
-
std::string url;
if (sptr->sru.length())
{
}
Z_Records *yf::Zoom::Frontend::get_explain_records(
- Package &package,
+ mp::Package &package,
Odr_int start,
Odr_int number_to_present,
int *error,
}
-Z_Records *yf::Zoom::Frontend::get_records(Package &package,
+Z_Records *yf::Zoom::Frontend::get_records(mp::Package &package,
Odr_int start,
Odr_int number_to_present,
int *error,
const char *xsl_parms[3];
mp::wrbuf cproxy_host;
- if (b->enable_cproxy && b->content_session_id.length())
+ if (b->enable_cproxy && b->cproxy_host.length())
{
- wrbuf_printf(cproxy_host, "\"%s.%s/\"",
- b->content_session_id.c_str(),
- m_p->content_proxy_server.c_str());
+ wrbuf_puts(cproxy_host, "\"");
+ wrbuf_puts(cproxy_host, b->cproxy_host.c_str());
+ wrbuf_puts(cproxy_host, "/\"");
+
xsl_parms[0] = "cproxyhost";
xsl_parms[1] = wrbuf_cstr(cproxy_host);
xsl_parms[2] = 0;
int *error,
char **addinfo,
mp::odr &odr,
+ std::string torus_url,
std::string &torus_db,
std::string &realm)
{
else if (query->which == Z_Query_type_104 &&
query->u.type_104->which == Z_External_CQL)
{
- std::string torus_url = m_p->torus_searchable_url;
std::string torus_query(query->u.type_104->u.cql);
xmlDoc *doc = mp::get_searchable(package, torus_url, "",
torus_query,
if (!doc)
{
*error = YAZ_BIB1_UNSPECIFIED_ERROR;
- *addinfo = odr_strdup(odr, "IR-Explain---1 problem. "
- "Could not obtain Torus records for Explain");
+ *addinfo = odr_strdup(odr, "Torus server unavailable or "
+ "incorrectly configured");
}
else
{
}
}
+static bool wait_conn(COMSTACK cs, int secs)
+{
+ struct yaz_poll_fd pfd;
+
+ yaz_poll_add(pfd.input_mask, yaz_poll_except);
+ 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);
+
+ pfd.fd = cs_fileno(cs);
+ pfd.client_data = 0;
+
+ int ret = yaz_poll(&pfd, 1, secs, 0);
+ return ret > 0;
+}
+
+bool yf::Zoom::Impl::check_proxy(const char *proxy)
+{
+ COMSTACK conn = 0;
+ const char *uri = "http://localhost/";
+ void *add;
+ mp::odr odr;
+ bool outcome = false;
+ conn = cs_create_host_proxy(uri, 0, &add, proxy);
+
+ if (!conn)
+ return false;
+
+ Z_GDU *gdu = z_get_HTTP_Request_uri(odr, uri, 0, 1);
+ gdu->u.HTTP_Request->method = odr_strdup(odr, "GET");
+
+ if (z_GDU(odr, &gdu, 0, 0))
+ {
+ int len;
+ char *buf = odr_getbuf(odr, &len, 0);
+
+ int ret = cs_connect(conn, add);
+ if (ret > 0 || (ret == 0 && wait_conn(conn, 1)))
+ {
+ while (1)
+ {
+ ret = cs_put(conn, buf, len);
+ if (ret != 1)
+ break;
+ if (!wait_conn(conn, proxy_timeout))
+ break;
+ }
+ if (ret == 0)
+ outcome = true;
+ }
+ }
+ cs_close(conn);
+ return outcome;
+}
+
+bool yf::Zoom::Frontend::retry(mp::Package &package,
+ mp::odr &odr,
+ BackendPtr b,
+ int &error, char **addinfo,
+ int &proxy_step, int &same_retries,
+ int &proxy_retries)
+{
+ if (b && b->m_proxy.length() && !m_p->check_proxy(b->m_proxy.c_str()))
+ {
+ log_diagnostic(package, error, *addinfo);
+ package.log("zoom", YLOG_LOG, "proxy %s fails", b->m_proxy.c_str());
+ m_backend.reset();
+ if (proxy_step) // there is a failover
+ {
+ proxy_retries++;
+ package.log("zoom", YLOG_WARN, "search failed: trying next proxy");
+ return true;
+ }
+ error = YAZ_BIB1_PROXY_FAILURE;
+ *addinfo = odr_strdup(odr, b->m_proxy.c_str());
+ }
+ else if (same_retries == 0 && proxy_retries == 0)
+ {
+ log_diagnostic(package, error, *addinfo);
+ same_retries++;
+ package.log("zoom", YLOG_WARN, "search failed: retry");
+ m_backend.reset();
+ proxy_step = 0;
+ return true;
+ }
+ return false;
+}
+
void yf::Zoom::Frontend::handle_search(mp::Package &package)
{
Z_GDU *gdu = package.request().get();
return;
}
int proxy_step = 0;
+ int same_retries = 0;
+ int proxy_retries = 0;
next_proxy:
BackendPtr b = get_backend_from_databases(package, db, &error,
&addinfo, odr, &proxy_step);
- if (error && proxy_step)
+ if (error)
{
- package.log("zoom", YLOG_WARN,
- "create backend failed: trying next proxy");
- goto next_proxy;
+ if (retry(package, odr, b, error, &addinfo, proxy_step,
+ same_retries, proxy_retries))
+ goto next_proxy;
}
if (error)
{
cql_parser_destroy(cp);
return;
}
- char ccl_buf[1024];
- r = cql_to_ccl_buf(cn, ccl_buf, sizeof(ccl_buf));
+ r = cql_to_ccl(cn, wrbuf_vp_puts, ccl_wrbuf);
if (r)
{
error = YAZ_BIB1_MALFORMED_QUERY;
mp::wrbuf sort_spec_wrbuf;
yaz_srw_sortkeys_to_sort_spec(wrbuf_cstr(sru_sortkeys_wrbuf),
sort_spec_wrbuf);
- wrbuf_puts(ccl_wrbuf, ccl_buf);
-
yaz_tok_cfg_t tc = yaz_tok_cfg_create();
yaz_tok_parse_t tp =
yaz_tok_parse_buf(tc, wrbuf_cstr(sort_spec_wrbuf));
}
else
{
- cql_transform_t cqlt = cql_transform_create();
-
- status = cql_transform_rpn2cql_wrbuf(cqlt, wrb, zquery);
-
- cql_transform_close(cqlt);
+ status = cql_transform_rpn2cql_wrbuf(b->cqlt, wrb, zquery);
}
if (status == 0)
{
ZOOM_query_destroy(q);
}
- if (error && proxy_step)
+ if (error)
{
- // reset below prevent reuse in get_backend_from_databases
- m_backend.reset();
- package.log("zoom", YLOG_WARN, "search failed: trying next proxy");
- goto next_proxy;
+ if (retry(package, odr, b, error, &addinfo, proxy_step,
+ same_retries, proxy_retries))
+ goto next_proxy;
}
const char *element_set_name = 0;
}
}
+std::string escape_cql_term(std::string inp)
+{
+ std::string res;
+ size_t l = inp.length();
+ size_t i;
+ for (i = 0; i < l; i++)
+ {
+ if (strchr("*?^\"", inp[i]))
+ res += "\\";
+ res += inp[i];
+ }
+ return res;
+}
+
+void yf::Zoom::Frontend::auth(mp::Package &package, Z_InitRequest *req,
+ int *error, char **addinfo, ODR odr)
+{
+ if (m_p->torus_auth_url.length() == 0)
+ return;
+
+ std::string user;
+ std::string password;
+ if (req->idAuthentication)
+ {
+ Z_IdAuthentication *auth = req->idAuthentication;
+ switch (auth->which)
+ {
+ case Z_IdAuthentication_open:
+ if (auth->u.open)
+ {
+ const char *cp = strchr(auth->u.open, '/');
+ if (cp)
+ {
+ user.assign(auth->u.open, cp - auth->u.open);
+ password.assign(cp + 1);
+ }
+ }
+ break;
+ case Z_IdAuthentication_idPass:
+ if (auth->u.idPass->userId)
+ user.assign(auth->u.idPass->userId);
+ if (auth->u.idPass->password)
+ password.assign(auth->u.idPass->password);
+ break;
+ }
+ }
+
+ std::string ip = package.origin().get_address();
+ yaz_log(YLOG_LOG, "IP=%s", ip.c_str());
+
+ std::string torus_query;
+
+ if (user.length() && password.length())
+ {
+ torus_query = "userName==\"" + escape_cql_term(user) +
+ "\" and password==\"" + escape_cql_term(password) + "\"";
+ }
+ else
+ {
+ const char *ip_cstr = ip.c_str();
+ const char *cp = strchr(ip_cstr, ':');
+ if (cp)
+ ip_cstr = cp + 1;
+
+ torus_query = "ip encloses/net.ipaddress \"";
+ torus_query += escape_cql_term(std::string(ip_cstr));
+ torus_query += "\"";
+ }
+
+ std::string dummy_db;
+ std::string dummy_realm;
+ xmlDoc *doc = mp::get_searchable(package, m_p->torus_auth_url, dummy_db,
+ torus_query, dummy_realm, m_p->proxy);
+ if (!doc)
+ {
+ *error = YAZ_BIB1_UNSPECIFIED_ERROR;
+ *addinfo = odr_strdup(odr, "Torus server unavailable or "
+ "incorrectly configured");
+ return;
+ }
+ const xmlNode *ptr = xmlDocGetRootElement(doc);
+ if (ptr && ptr->type == XML_ELEMENT_NODE)
+ {
+ if (strcmp((const char *) ptr->name, "records") == 0)
+ {
+ ptr = ptr->children;
+ while (ptr && ptr->type != XML_ELEMENT_NODE)
+ ptr = ptr->next;
+ }
+ if (ptr && strcmp((const char *) ptr->name, "record") == 0)
+ {
+ ptr = ptr->children;
+ while (ptr && ptr->type != XML_ELEMENT_NODE)
+ ptr = ptr->next;
+ }
+ if (ptr && strcmp((const char *) ptr->name, "layer") == 0)
+ {
+ ptr = ptr->children;
+ while (ptr && ptr->type != XML_ELEMENT_NODE)
+ ptr = ptr->next;
+ }
+ while (ptr)
+ {
+ if (ptr && ptr->type == XML_ELEMENT_NODE &&
+ !strcmp((const char *) ptr->name, "identityId"))
+ break;
+ ptr = ptr->next;
+ }
+ }
+ if (!ptr)
+ {
+ *error = YAZ_BIB1_INIT_AC_BAD_USERID_AND_OR_PASSWORD;
+ return;
+ }
+ session_realm = mp::xml::get_text(ptr);
+}
+
void yf::Zoom::Impl::process(mp::Package &package)
{
FrontendPtr f = get_frontend(package);
*resp->preferredMessageSize = *req->preferredMessageSize;
*resp->maximumRecordSize = *req->maximumRecordSize;
-
+
+ int error = 0;
+ char *addinfo = 0;
+ f->auth(package, req, &error, &addinfo, odr);
+ if (error)
+ {
+ resp->userInformationField =
+ zget_init_diagnostics(odr, error, addinfo);
+ *resp->result = 0;
+ package.session().close();
+ }
+ else
+ f->m_is_virtual = true;
package.response() = apdu;
- f->m_is_virtual = true;
}
else
package.move();