X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fyaz-proxy.cpp;h=17ed69ee52b4dd72d91f8ad1a76917d5e1d5492d;hb=6b6d0482e926e0e6de58ab13a2998cd93a4d6a58;hp=4400bbbe85386d242a4a6b9a2199b291c5f22b1a;hpb=c6ca4f0f79d5ea0ca391d420bcb6dd6b4d7935d2;p=yazproxy-moved-to-github.git diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index 4400bbb..17ed69e 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -1,4 +1,4 @@ -/* $Id: yaz-proxy.cpp,v 1.22 2005-02-11 15:19:08 adam Exp $ +/* $Id: yaz-proxy.cpp,v 1.24.2.1 2005-05-27 18:00:28 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -38,6 +38,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #endif #include +#include #include #include @@ -116,7 +117,6 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable, m_keepalive_limit_pdu = 1000; m_proxyTarget = 0; m_default_target = 0; - m_proxy_authentication = 0; m_proxy_negotiation_charset = 0; m_proxy_negotiation_lang = 0; m_max_clients = 150; @@ -140,7 +140,7 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable, m_referenceId = 0; m_referenceId_mem = nmem_create(); m_config = 0; - m_marcxml_flag = 0; + m_marcxml_mode = none; m_stylesheet_xsp = 0; m_stylesheet_nprl = 0; m_s2z_stylesheet = 0; @@ -196,7 +196,6 @@ Yaz_Proxy::~Yaz_Proxy() xfree(m_proxyTarget); xfree(m_default_target); - xfree(m_proxy_authentication); xfree(m_proxy_negotiation_charset); xfree(m_proxy_negotiation_lang); xfree(m_optimize); @@ -222,6 +221,11 @@ Yaz_Proxy::~Yaz_Proxy() delete m_config; } +void Yaz_Proxy::set_debug_mode(int mode) +{ + m_debug_mode = mode; +} + int Yaz_Proxy::set_config(const char *config) { delete m_config; @@ -242,14 +246,6 @@ void Yaz_Proxy::set_default_target(const char *target) m_default_target = (char *) xstrdup (target); } -void Yaz_Proxy::set_proxy_authentication (const char *auth) -{ - xfree (m_proxy_authentication); - m_proxy_authentication = 0; - if (auth) - m_proxy_authentication = (char *) xstrdup (auth); -} - void Yaz_Proxy::set_proxy_negotiation (const char *charset, const char *lang) { yaz_log(YLOG_LOG, "%sSet the proxy negotiation: charset to '%s', " @@ -310,7 +306,6 @@ IYaz_PDU_Observer *Yaz_Proxy::sessionNotify(IYaz_PDU_Observable new_proxy->set_APDU_yazlog(1); else new_proxy->set_APDU_yazlog(0); - new_proxy->set_proxy_authentication(m_proxy_authentication); new_proxy->set_proxy_negotiation(m_proxy_negotiation_charset, m_proxy_negotiation_lang); sprintf(new_proxy->m_session_str, "%ld:%d ", (long) time(0), m_session_no); @@ -393,12 +388,6 @@ const char *Yaz_Proxy::load_balance(const char **url) max_spare = zurl_in_spare[i]; } } - // use the one with minimum connections if spare is > 3 - if (spare_for_min > 3) - return ret_min; - // use one with most spares (if any) - if (max_spare > 0) - return ret_spare; return ret_min; } @@ -415,18 +404,18 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie, Yaz_ProxyConfig *cfg = check_reconfigure(); if (proxy_host) { -#if 0 -/* only to be enabled for debugging... */ - if (!strcmp(proxy_host, "stop")) - exit(0); -#endif + if (parent && parent->m_debug_mode) + { + // only to be enabled for debugging... + if (!strcmp(proxy_host, "stop")) + exit(0); + } xfree(m_default_target); m_default_target = xstrdup(proxy_host); } proxy_host = m_default_target; int client_idletime = -1; const char *cql2rpn_fname = 0; - const char *authentication = 0; const char *negotiation_charset = 0; const char *negotiation_lang = 0; url[0] = m_default_target; @@ -442,7 +431,6 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie, &m_keepalive_limit_pdu, &pre_init, &cql2rpn_fname, - &authentication, &negotiation_charset, &negotiation_lang); } @@ -453,11 +441,12 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie, } if (cql2rpn_fname) m_cql2rpn.set_pqf_file(cql2rpn_fname); - if (authentication) - set_proxy_authentication(authentication); if (negotiation_charset || negotiation_lang) + { + yaz_log(YLOG_LOG, "set_proxy_negotiation..."); set_proxy_negotiation(negotiation_charset, negotiation_lang); + } if (!url[0]) { yaz_log(YLOG_LOG, "%sNo default target", m_session_str); @@ -561,23 +550,9 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie, } Z_InitRequest *initRequest = apdu->u.initRequest; - if (!initRequest->idAuthentication) - { - if (m_proxy_authentication) - { - initRequest->idAuthentication = - (Z_IdAuthentication *) - odr_malloc (odr_encode(), - sizeof(*initRequest->idAuthentication)); - initRequest->idAuthentication->which = - Z_IdAuthentication_open; - initRequest->idAuthentication->u.open = - odr_strdup (odr_encode(), m_proxy_authentication); - } - } - else + if (initRequest->idAuthentication) { - // the client use authentication. We set the keepalive PDU + // the client uses authentication. We set the keepalive PDU // to 0 so we don't cache it in releaseClient m_keepalive_limit_pdu = 0; } @@ -844,6 +819,7 @@ void Yaz_Proxy::convert_to_frontend_type(Z_NamePlusRecordList *p) continue; } #endif +/* HAVE_USEMARCON */ npr->u.databaseRecord = z_ext_record(odr_encode(), m_frontend_type, @@ -871,7 +847,18 @@ void Yaz_Proxy::convert_to_marcxml(Z_NamePlusRecordList *p, if (npr->which == Z_NamePlusRecord_databaseRecord) { Z_External *r = npr->u.databaseRecord; - if (r->which == Z_External_octet) + if (r->which == Z_External_OPAC) + { + WRBUF w = wrbuf_alloc(); + + yaz_display_OPAC(w, r->u.opac, 0); + npr->u.databaseRecord = z_ext_record( + odr_encode(), VAL_TEXT_XML, + wrbuf_buf(w), wrbuf_len(w) + ); + wrbuf_free(w, 1); + } + else if (r->which == Z_External_octet) { int rlen; char *result; @@ -879,9 +866,8 @@ void Yaz_Proxy::convert_to_marcxml(Z_NamePlusRecordList *p, r->u.octet_aligned->len, &result, &rlen)) { - npr->u.databaseRecord = z_ext_record(odr_encode(), - VAL_TEXT_XML, - result, rlen); + npr->u.databaseRecord = + z_ext_record(odr_encode(), VAL_TEXT_XML, result, rlen); } } } @@ -1200,7 +1186,7 @@ int Yaz_Proxy::send_to_client(Z_APDU *apdu) #endif ) convert_to_frontend_type(p->u.databaseOrSurDiagnostics); - if (m_marcxml_flag) + if (m_marcxml_mode == marcxml) convert_to_marcxml(p->u.databaseOrSurDiagnostics, m_backend_charset); if (convert_xsl(p->u.databaseOrSurDiagnostics, apdu)) @@ -1245,7 +1231,7 @@ int Yaz_Proxy::send_to_client(Z_APDU *apdu) #endif ) convert_to_frontend_type(p->u.databaseOrSurDiagnostics); - if (m_marcxml_flag) + if (m_marcxml_mode == marcxml) convert_to_marcxml(p->u.databaseOrSurDiagnostics, m_backend_charset); if (convert_xsl(p->u.databaseOrSurDiagnostics, apdu)) @@ -1850,11 +1836,11 @@ int Yaz_Proxy::handle_authentication(Z_APDU *apdu) int ret; if (req->idAuthentication == 0) { - ret = cfg->check_authentication(0, 0, 0); + ret = cfg->client_authentication(m_default_target, 0, 0, 0); } else if (req->idAuthentication->which == Z_IdAuthentication_idPass) { - ret = cfg->check_authentication( + ret = cfg->client_authentication(m_default_target, req->idAuthentication->u.idPass->userId, req->idAuthentication->u.idPass->groupId, req->idAuthentication->u.idPass->password); @@ -1865,16 +1851,19 @@ int Yaz_Proxy::handle_authentication(Z_APDU *apdu) *user = '\0'; *pass = '\0'; sscanf(req->idAuthentication->u.open, "%63[^/]/%63s", user, pass); - ret = cfg->check_authentication(user, 0, pass); + ret = cfg->client_authentication(m_default_target, user, 0, pass); } else - ret = cfg->check_authentication(0, 0, 0); + ret = cfg->client_authentication(m_default_target, 0, 0, 0); + + cfg->target_authentication(m_default_target, odr_encode(), req); + return ret; } Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) { - m_marcxml_flag = 0; + m_marcxml_mode = none; if (apdu->which == Z_APDU_searchRequest) { Z_SearchRequest *sr = apdu->u.searchRequest; @@ -1927,6 +1916,7 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) { sr->smallSetElementSetNames = 0; sr->mediumSetElementSetNames = 0; + m_marcxml_mode = marcxml; if (m_backend_type) { @@ -1938,7 +1928,6 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) sr->preferredRecordSyntax = yaz_oidval_to_z3950oid(odr_encode(), CLASS_RECSYN, VAL_USMARC); - m_marcxml_flag = 1; } else if (err) { @@ -2003,6 +1992,7 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) if (err == -1) { pr->recordComposition = 0; + m_marcxml_mode = marcxml; if (m_backend_type) { @@ -2014,7 +2004,6 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) pr->preferredRecordSyntax = yaz_oidval_to_z3950oid(odr_encode(), CLASS_RECSYN, VAL_USMARC); - m_marcxml_flag = 1; } else if (err) {