Fix Metaproxy stops logging after check config failed MP-590
[metaproxy-moved-to-github.git] / src / filter_auth_simple.cpp
index 93f5f18..dcf5805 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Metaproxy.
-   Copyright (C) 2005-2012 Index Data
+   Copyright (C) Index Data
 
 Metaproxy is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -22,7 +22,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <metaproxy/package.hpp>
 
 #include <boost/thread/mutex.hpp>
-#include <boost/algorithm/string.hpp>
 
 #include <metaproxy/util.hpp>
 #include "filter_auth_simple.hpp"
@@ -72,6 +71,36 @@ yf::AuthSimple::~AuthSimple()
 static void die(std::string s) { throw mp::filter::FilterException(s); }
 
 
+static std::string get_user(Z_InitRequest *initReq, std::string &password)
+{
+    Z_IdAuthentication *auth = initReq->idAuthentication;
+    std::string user;
+    if (auth)
+    {
+        const char *cp;
+        switch (auth->which)
+        {
+        case Z_IdAuthentication_open:
+            cp = strchr(auth->u.open, '/');
+            if (cp)
+            {
+                user.assign(auth->u.open, cp - auth->u.open);
+                password.assign(cp + 1);
+            }
+            else
+                user = auth->u.open;
+            break;
+        case Z_IdAuthentication_idPass:
+            if (auth->u.idPass->userId)
+                user = auth->u.idPass->userId;
+            if (auth->u.idPass->password)
+                password = auth->u.idPass->password;
+            break;
+        }
+    }
+    return user;
+}
+
 // Read XML config.. Put config info in m_p.
 void mp::filter::AuthSimple::configure(const xmlNode * ptr, bool test_only,
                                        const char *path)
@@ -107,6 +136,17 @@ void mp::filter::AuthSimple::configure(const xmlNode * ptr, bool test_only,
         config_targetRegister(targetRegisterName);
 }
 
+static void split_db(std::list<std::string> &dbs,
+                     const char *databasesp)
+{
+    const char *cp;
+    while ((cp = strchr(databasesp, ',')))
+    {
+        dbs.push_back(std::string(databasesp, cp - databasesp));
+        databasesp = cp + 1;
+    }
+    dbs.push_back(std::string(databasesp));
+}
 
 void mp::filter::AuthSimple::config_userRegister(std::string filename)
 {
@@ -132,7 +172,7 @@ void mp::filter::AuthSimple::config_userRegister(std::string filename)
                 "no databases on line: '" + buf + ":" + passwdp + "'");
         *databasesp++ = 0;
         yf::AuthSimple::Rep::PasswordAndDBs tmp(passwdp);
-        boost::split(tmp.dbs, databasesp, boost::is_any_of(","));
+        split_db(tmp.dbs, databasesp);
         m_p->userRegister[buf] = tmp;
 
         if (0)
@@ -168,7 +208,7 @@ void mp::filter::AuthSimple::config_targetRegister(std::string filename)
                 "no targets on line: '" + buf + "'");
         *targetsp++ = 0;
         std::list<std::string> tmp;
-        boost::split(tmp, targetsp, boost::is_any_of(","));
+        split_db(tmp, targetsp);
         m_p->targetsByUser[buf] = tmp;
 
         if (0) {                // debugging
@@ -338,37 +378,6 @@ static void reject_init(mp::Package &package, int err, const char *addinfo) {
     package.session().close();
 }
 
-std::string yf::AuthSimple::get_user(Z_InitRequest *initReq,
-                                     std::string &password) const
-{
-    Z_IdAuthentication *auth = initReq->idAuthentication;
-    std::string user;
-    if (auth)
-    {
-        const char *cp;
-        switch (auth->which)
-        {
-        case Z_IdAuthentication_open:
-            cp = strchr(auth->u.open, '/');
-            if (cp)
-            {
-                user.assign(auth->u.open, cp - auth->u.open);
-                password.assign(cp + 1);
-            }
-            else
-                user = auth->u.open;
-            break;
-        case Z_IdAuthentication_idPass:
-            if (auth->u.idPass->userId)
-                user = auth->u.idPass->userId;
-            if (auth->u.idPass->password)
-                password = auth->u.idPass->password;
-            break;
-        }
-    }
-    return user;
-}
-
 void yf::AuthSimple::check_targets(mp::Package & package) const
 {
     Z_InitRequest *initReq = package.request().get()->u.z3950->u.initRequest;