From 8085904b5f89768a01a4ddf5eb74b371b6999166 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 13 Dec 2011 16:03:15 +0100 Subject: [PATCH] zoom: allow list of proxies for proxy parameter Such a hack that goto seems proper. --- src/filter_zoom.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/filter_zoom.cpp b/src/filter_zoom.cpp index 60a8bab..45ead65 100644 --- a/src/filter_zoom.cpp +++ b/src/filter_zoom.cpp @@ -120,7 +120,8 @@ namespace metaproxy_1 { std::string &database, int *error, char **addinfo, - ODR odr); + ODR odr, + int *proxy_step); bool create_content_session(mp::Package &package, BackendPtr b, @@ -709,7 +710,8 @@ bool yf::Zoom::Frontend::create_content_session(mp::Package &package, yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( mp::Package &package, - std::string &database, int *error, char **addinfo, ODR odr) + std::string &database, int *error, char **addinfo, ODR odr, + int *proxy_step) { std::list::const_iterator map_it; if (m_backend && m_backend->m_frontend_database == database) @@ -770,7 +772,21 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( else if (!strcmp(name, "content-proxy")) content_proxy = value; else if (!strcmp(name, "proxy")) - proxy = value; + { + char **dstr; + int dnum = 0; + nmem_strsplit(odr->mem, ",", value, &dstr, &dnum); + 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_names[no_out_args] = name; @@ -1001,6 +1017,9 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( 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()) { @@ -1393,11 +1412,22 @@ void yf::Zoom::Frontend::handle_search(mp::Package &package) return; } + int proxy_step = 0; + +next_proxy: + int error = 0; char *addinfo = 0; std::string db(sr->databaseNames[0]); + BackendPtr b = get_backend_from_databases(package, db, &error, - &addinfo, odr); + &addinfo, odr, &proxy_step); + if (error && proxy_step) + { + package.log("zoom", YLOG_WARN, + "create backend failed: trying next proxy"); + goto next_proxy; + } if (error) { log_diagnostic(package, error, addinfo); @@ -1635,6 +1665,14 @@ void yf::Zoom::Frontend::handle_search(mp::Package &package) wrbuf_destroy(pqf_wrbuf); } + if (error && proxy_step) + { + // 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; + } + const char *element_set_name = 0; Odr_int number_to_present = 0; if (!error) -- 1.7.10.4