-/* $Id: yaz-proxy.cpp,v 1.5 2004-08-10 09:02:16 adam Exp $
+/* $Id: yaz-proxy.cpp,v 1.11 2004-10-28 22:29:43 adam Exp $
Copyright (c) 1998-2004, Index Data.
This file is part of the yaz-proxy.
#include <yaz/diagbib1.h>
#include <yazproxy/proxy.h>
#include <yaz/pquery.h>
+#include <yaz/otherinfo.h>
#if HAVE_XSLT
#include <libxml/parser.h>
m_s2z_database = 0;
m_schema = 0;
m_backend_type = 0;
+ m_backend_charset = 0;
m_frontend_type = 0;
m_initRequest_apdu = 0;
m_initRequest_mem = 0;
nmem_destroy(m_mem_invalid_session);
nmem_destroy(m_referenceId_mem);
- xfree (m_proxyTarget);
- xfree (m_default_target);
- xfree (m_proxy_authentication);
- xfree (m_optimize);
+ xfree(m_proxyTarget);
+ xfree(m_default_target);
+ xfree(m_proxy_authentication);
+ xfree(m_optimize);
#if HAVE_XSLT
if (m_stylesheet_xsp)
xfree (m_schema);
xfree (m_backend_type);
+ xfree (m_backend_charset);
if (m_s2z_odr_init)
odr_destroy(m_s2z_odr_init);
if (m_s2z_odr_search)
#endif
xfree(m_default_target);
m_default_target = xstrdup(proxy_host);
- proxy_host = m_default_target;
}
+ proxy_host = m_default_target;
int client_idletime = -1;
const char *cql2rpn_fname = 0;
+ const char *authentication = 0;
url[0] = m_default_target;
url[1] = 0;
if (cfg)
&m_keepalive_limit_bw,
&m_keepalive_limit_pdu,
&pre_init,
- &cql2rpn_fname);
+ &cql2rpn_fname,
+ &authentication);
}
if (client_idletime != -1)
{
}
if (cql2rpn_fname)
m_cql2rpn.set_pqf_file(cql2rpn_fname);
+ if (authentication)
+ set_proxy_authentication(authentication);
if (!url[0])
{
yaz_log(LOG_LOG, "%sNo default target", m_session_str);
}
}
}
- else if (!c)
+ else if (!c && apdu->which == Z_APDU_initRequest
+ && apdu->u.initRequest->idAuthentication == 0)
{
- // don't have a client session yet. Search in session w/o cookie
+ // anonymous sessions without cookie.
+ // if authentication is set it is NOT anonymous se we can't share them.
for (c = parent->m_clientPool; c; c = c->m_next)
{
- assert (c->m_prev);
- assert (*c->m_prev == c);
+ assert(c->m_prev);
+ assert(*c->m_prev == c);
if (c->m_server == 0 && c->m_cookie == 0 &&
- c->m_waiting == 0 &&
+ c->m_waiting == 0 &&
!strcmp(m_proxyTarget, c->get_hostname()))
{
// found it in cache
odr_strdup (odr_encode(), m_proxy_authentication);
}
}
+ else
+ {
+ // the client use authentication. We set the keepalive PDU
+ // to 0 so we don't cache it in releaseClient
+ m_keepalive_limit_pdu = 0;
+ }
// go through list of clients - and find the lowest/oldest one.
Yaz_ProxyClient *c_min = 0;
int min_seq = -1;
}
}
-void Yaz_Proxy::convert_to_marcxml(Z_NamePlusRecordList *p)
+void Yaz_Proxy::convert_to_marcxml(Z_NamePlusRecordList *p,
+ const char *backend_charset)
{
int i;
- yaz_iconv_t cd = yaz_iconv_open("UTF-8", "MARC-8");
+ if (!backend_charset)
+ backend_charset = "MARC-8";
+ yaz_iconv_t cd = yaz_iconv_open("UTF-8", backend_charset);
yaz_marc_t mt = yaz_marc_create();
yaz_marc_xml(mt, YAZ_MARC_MARCXML);
yaz_marc_iconv(mt, cd);
if (cfg)
{
int len;
- char *b = cfg->get_explain(odr_encode(), 0 /* target */,
- m_s2z_database, &len);
+ char *b = cfg->get_explain_doc(odr_encode(), 0 /* target */,
+ m_s2z_database, &len);
if (b)
{
Z_SRW_PDU *res = yaz_srw_get(odr_encode(), Z_SRW_explain_response);
if (m_backend_type)
convert_to_frontend_type(p->u.databaseOrSurDiagnostics);
if (m_marcxml_flag)
- convert_to_marcxml(p->u.databaseOrSurDiagnostics);
+ convert_to_marcxml(p->u.databaseOrSurDiagnostics,
+ m_backend_charset);
if (convert_xsl(p->u.databaseOrSurDiagnostics, apdu))
return 0;
if (m_backend_type)
convert_to_frontend_type(p->u.databaseOrSurDiagnostics);
if (m_marcxml_flag)
- convert_to_marcxml(p->u.databaseOrSurDiagnostics);
+ convert_to_marcxml(p->u.databaseOrSurDiagnostics,
+ m_backend_charset);
if (convert_xsl(p->u.databaseOrSurDiagnostics, apdu))
return 0;
}
return 0;
}
Z_NamePlusRecordList *npr;
- int oclass = 0;
#if 0
yaz_log(LOG_LOG, "%sCache lookup %d+%d syntax=%s",
m_session_str, start, toget, yaz_z3950oid_to_str(
m_default_target,
sr->preferredRecordSyntax, rc,
&addinfo, &stylesheet_name, &m_schema,
- &m_backend_type);
+ &m_backend_type, &m_backend_charset);
if (stylesheet_name)
{
m_parent->low_socket_close();
pr->preferredRecordSyntax,
pr->recordComposition,
&addinfo, &stylesheet_name, &m_schema,
- &m_backend_type);
+ &m_backend_type, &m_backend_charset);
if (stylesheet_name)
{
m_parent->low_socket_close();
return esn;
}
+void Yaz_Proxy::srw_get_client(const char *db, const char **backend_db)
+{
+ const char *t = 0;
+ Yaz_ProxyConfig *cfg = check_reconfigure();
+ if (cfg)
+ t = cfg->get_explain_name(db, backend_db);
+
+ if (m_client && m_default_target && t && strcmp(m_default_target, t))
+ {
+ releaseClient();
+ }
+
+ if (t)
+ {
+ xfree(m_default_target);
+ m_default_target = xstrdup(t);
+ }
+}
+
void Yaz_Proxy::handle_incoming_HTTP(Z_HTTP_Request *hreq)
{
if (m_s2z_odr_init)
{
Z_SRW_searchRetrieveRequest *srw_req = srw_pdu->u.request;
+ const char *backend_db = srw_req->database;
+ srw_get_client(srw_req->database, &backend_db);
+
m_s2z_database = odr_strdup(m_s2z_odr_init, srw_req->database);
// recordXPath unsupported.
if (srw_req->recordXPath)
z_searchRequest->databaseNames = (char**)
odr_malloc(m_s2z_odr_search, sizeof(char *));
z_searchRequest->databaseNames[0] = odr_strdup(m_s2z_odr_search,
- srw_req->database);
+ backend_db);
// query transformation
Z_Query *query = (Z_Query *)
{
Z_SRW_explainRequest *srw_req = srw_pdu->u.explain_request;
+ const char *backend_db = srw_req->database;
+ srw_get_client(srw_req->database, &backend_db);
+
m_s2z_database = odr_strdup(m_s2z_odr_init, srw_req->database);
// save stylesheet
return;
}
- // delete other info part from PDU before sending to target
+ // delete other info construct completely if 0 elements
get_otherInfoAPDU(apdu, &oi);
- if (oi)
+ if (*oi && (*oi)->num_elements == 0)
*oi = 0;
if (apdu->which == Z_APDU_presentRequest &&
{
}
-void Yaz_Proxy::shutdown()
+void Yaz_Proxy::releaseClient()
{
+ xfree(m_proxyTarget);
+ m_proxyTarget = 0;
m_invalid_session = 0;
// only keep if keep_alive flag is set...
if (m_client &&
assert (m_client->m_waiting != 2);
// Tell client (if any) that no server connection is there..
m_client->m_server = 0;
- m_invalid_session = 0;
+ m_client = 0;
}
else if (m_client)
{
m_client->get_hostname());
assert (m_client->m_waiting != 2);
delete m_client;
+ m_client = 0;
}
else if (!m_parent)
{
}
if (m_parent)
m_parent->pre_init();
+}
+
+void Yaz_Proxy::shutdown()
+{
+ releaseClient();
delete this;
}
int keepalive_limit_bw, keepalive_limit_pdu;
int pre_init;
const char *cql2rpn = 0;
+ const char *authentication = 0;
Yaz_ProxyConfig *cfg = check_reconfigure();
&keepalive_limit_bw,
&keepalive_limit_pdu,
&pre_init,
- &cql2rpn) ; i++)
+ &cql2rpn,
+ &authentication) ; i++)
{
if (pre_init)
{