X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fyaz-proxy.cpp;h=5864a12e8ca4d67647d2913c4b1d571df535170a;hb=d8c09f27e7a06712a0c76adb1ff3a366fb69edf0;hp=5f323b7343ecbcf710edd93cdad3329e01e495d6;hpb=50fbcf20ab48480e819ec5aef312a72c684bf213;p=yazpp-moved-to-github.git diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index 5f323b7..5864a12 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy.cpp,v 1.62 2003-10-16 16:10:43 adam Exp $ + * $Id: yaz-proxy.cpp,v 1.69 2003-10-23 13:59:37 adam Exp $ */ #include @@ -72,7 +72,7 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable, m_client_idletime = 600; m_target_idletime = 600; m_optimize = xstrdup ("1"); - strcpy(m_session_str, "0"); + strcpy(m_session_str, "0 "); m_session_no=0; m_bytes_sent = m_bytes_recv = 0; m_bw_hold_PDU = 0; @@ -258,6 +258,11 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) Yaz_ProxyConfig *cfg = check_reconfigure(); if (proxy_host) { +#if 0 +/* only to be enabled for debugging... */ + if (!strcmp(proxy_host, "stop")) + exit(0); +#endif xfree(m_default_target); m_default_target = xstrdup(proxy_host); proxy_host = m_default_target; @@ -350,9 +355,8 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) !strcmp(m_proxyTarget, c->get_hostname())) { // found it in cache - yaz_log (LOG_LOG, "%sREUSE %d %d %s", - m_session_str, - c->m_seqno, parent->m_seqno, c->get_hostname()); + yaz_log (LOG_LOG, "%sREUSE %s", + m_session_str, c->get_hostname()); c->m_seqno = parent->m_seqno; assert(c->m_server == 0); @@ -660,7 +664,6 @@ Z_APDU *Yaz_Proxy::result_set_optimize(Z_APDU *apdu) if (apdu->which == Z_APDU_presentRequest) { Z_PresentRequest *pr = apdu->u.presentRequest; - Z_NamePlusRecordList *npr; int toget = *pr->numberOfRecordsRequested; int start = *pr->resultSetStartPoint; @@ -679,6 +682,7 @@ Z_APDU *Yaz_Proxy::result_set_optimize(Z_APDU *apdu) send_to_client(new_apdu); return 0; } +#if 0 if (!strcmp(m_client->m_last_resultSetId, pr->resultSetId)) { if (start+toget-1 > m_client->m_last_resultCount) @@ -712,6 +716,7 @@ Z_APDU *Yaz_Proxy::result_set_optimize(Z_APDU *apdu) return 0; } } +#endif } if (apdu->which != Z_APDU_searchRequest) @@ -1005,37 +1010,34 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) if (apdu->which == Z_APDU_searchRequest) { Z_SearchRequest *sr = apdu->u.searchRequest; - if (*sr->smallSetUpperBound > 0 || *sr->mediumSetPresentNumber > 0) + int err = 0; + char *addinfo = 0; + Yaz_ProxyConfig *cfg = check_reconfigure(); + + if (cfg) + err = cfg->check_syntax(odr_encode(), + m_default_target, + sr->preferredRecordSyntax, + &addinfo); + if (err == -1) { - int err = 0; - char *addinfo = 0; - Yaz_ProxyConfig *cfg = check_reconfigure(); - - if (cfg) - err = cfg->check_syntax(odr_encode(), - m_default_target, - sr->preferredRecordSyntax, - &addinfo); - if (err == -1) - { - sr->preferredRecordSyntax = - yaz_oidval_to_z3950oid(odr_decode(), CLASS_RECSYN, - VAL_USMARC); - m_marcxml_flag = 1; - } - else if (err) - { - Z_APDU *new_apdu = create_Z_PDU(Z_APDU_searchResponse); - - new_apdu->u.searchResponse->referenceId = sr->referenceId; - new_apdu->u.searchResponse->records = - create_nonSurrogateDiagnostics(odr_encode(), err, addinfo); - *new_apdu->u.searchResponse->searchStatus = 0; - - send_to_client(new_apdu); - - return 0; - } + sr->preferredRecordSyntax = + yaz_oidval_to_z3950oid(odr_decode(), CLASS_RECSYN, + VAL_USMARC); + m_marcxml_flag = 1; + } + else if (err) + { + Z_APDU *new_apdu = create_Z_PDU(Z_APDU_searchResponse); + + new_apdu->u.searchResponse->referenceId = sr->referenceId; + new_apdu->u.searchResponse->records = + create_nonSurrogateDiagnostics(odr_encode(), err, addinfo); + *new_apdu->u.searchResponse->searchStatus = 0; + + send_to_client(new_apdu); + + return 0; } } else if (apdu->which == Z_APDU_presentRequest) @@ -1321,15 +1323,26 @@ void Yaz_Proxy::pre_init() { Yaz_ProxyClient *c; int spare = 0; + int in_use = 0; + int other = 0; for (c = m_clientPool; c; c = c->m_next) { - if (!strcmp(zurl_in_use[j], c->get_hostname()) - && c->m_server == 0 && c->m_cookie == 0) - spare++; + if (!strcmp(zurl_in_use[j], c->get_hostname())) + { + if (c->m_cookie == 0) + { + if (c->m_server == 0) + spare++; + else + in_use++; + } + else + other++; + } } - yaz_log(LOG_LOG, "%s pre-init %s %s spare=%d pre_init=%d", - m_session_str, - name, zurl_in_use[j], spare, pre_init); + yaz_log(LOG_LOG, "%spre-init %s %s use=%d other=%d spare=%d " + "preinit=%d",m_session_str, + name, zurl_in_use[j], in_use, other, spare, pre_init); if (spare < pre_init) { c = new Yaz_ProxyClient(m_PDU_Observable->clone(), this); @@ -1516,10 +1529,14 @@ void Yaz_ProxyClient::recv_Z_PDU(Z_APDU *apdu, int len) } } -void Yaz_Proxy::server(const char *addr) +int Yaz_Proxy::server(const char *addr) { - Yaz_Z_Assoc::server(addr); - - timeout(1); + int r = Yaz_Z_Assoc::server(addr); + if (!r) + { + yaz_log(LOG_LOG, "%sStarted listener on %s", m_session_str, addr); + timeout(1); + } + return r; }