From fa3bd4d2a13db989a57262b42f105a4d4ba28025 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 4 Apr 2013 14:54:04 +0200 Subject: [PATCH] Torus setting authentiation signals auth type user/password/url uses x-username, x-password for SRU. user/password/basic or user/password uses HTTP Auth for SRU. --- src/filter_zoom.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/src/filter_zoom.cpp b/src/filter_zoom.cpp index 839a924..018f532 100644 --- a/src/filter_zoom.cpp +++ b/src/filter_zoom.cpp @@ -1407,16 +1407,59 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( } else { - size_t found = authentication.find('/'); - - if (sptr->sru.length() && found != std::string::npos) - { - b->set_option("user", authentication.substr(0, found)); - b->set_option("password", authentication.substr(found+1)); - } + if (sptr->sru.length() == 0) + b->set_option("user", authentication); /* Z39.50 */ else - b->set_option("user", authentication); + { + std::string user; + std::string password; + std::string authtype; + { + const char *cstr = authentication.c_str(); + const char *cp1 = strchr(cstr, '/'); + const char *cp2 = 0; + if (cp1) + { + cp2 = strchr(cp1 + 1, '/'); + if (cp2) + { + password.assign(cp1 + 1, cp2 - cp1 - 1); + authtype.assign(cp2 + 1); + } + else + password.assign(cp1 + 1); + user.assign(cstr, cp1 - cstr); + } + else + user.assign(cstr); + } + if (authtype.compare("url") == 0) + { + /* SRU URL encoding of auth stuff */ + ODR o = odr_createmem(ODR_ENCODE); + char *path = 0; + const char *names[3]; + const char *values[3]; + + names[0] = "x-username"; + values[0] = user.c_str(); + names[1] = "x-password"; + values[1] = password.c_str(); + names[2] = 0; + values[2] = 0; + + yaz_array_to_uri(&path, o, (char **) names, (char **) values); + b->set_option("extraArgs", path); + odr_destroy(o); + } + else + { + b->set_option("user", user); + if (password.length()) + b->set_option("password", password); + } + } if (proxy.length()) b->set_option("proxy", proxy); } -- 1.7.10.4