2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
23 #include "stg/store.h"
24 #include "stg/users.h"
25 #include "stg/plugin_creator.h"
34 PLUGIN_CREATOR<RADIUS> creator;
38 extern "C" PLUGIN * GetPlugin()
40 return creator.GetPlugin();
48 m_logger(GetPluginLogger(GetStgLogger(), "radius"))
52 int RADIUS::ParseSettings()
55 m_config = STG::Config(m_settings);
57 } catch (const std::runtime_error& ex) {
58 m_logger("Failed to parse settings. %s", ex.what());
68 int res = pthread_create(&m_thread, NULL, run, this);
72 m_error = strerror(res);
73 m_logger("Failed to create thread: '" + m_error + "'.");
84 for (size_t i = 0; i < 25 && !m_stopped; i++) {
85 struct timespec ts = {0, 200000000};
90 pthread_join(m_thread, NULL);
94 m_error = "Failed to stop thread.";
98 //-----------------------------------------------------------------------------
99 void* RADIUS::run(void* d)
102 sigfillset(&signalSet);
103 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
105 static_cast<RADIUS *>(d)->runImpl();
110 void RADIUS::runImpl()
123 int res = select(maxFD() + 1, &fds, NULL, NULL, &tv);
126 m_error = std::string("'select' is failed: '") + strerror(errno) + "'.";
143 int RADIUS::maxFD() const
145 int maxFD = m_listenSocket;
146 std::deque<STG::Conn *>::const_iterator it;
147 for (it = m_conns.begin(); it != m_conns.end(); ++it)
148 if (maxFD < (*it)->sock())
149 maxFD = (*it)->sock();
153 void RADIUS::buildFDSet(fd_set & fds) const
156 FD_SET(m_listenSocket, &fds);
157 std::deque<STG::Conn *>::const_iterator it;
158 for (it = m_conns.begin(); it != m_conns.end(); ++it)
159 FD_SET((*it)->sock(), &fds);
162 void RADIUS::cleanupConns()
164 std::deque<STG::Conn *>::iterator pos;
165 for (pos = m_conns.begin(); pos != m_conns.end(); ++pos)
166 if (((*pos)->isDone() && !(*pos)->isKeepAlive()) || !(*pos)->isOk()) {
171 pos = std::remove(m_conns.begin(), m_conns.end(), static_cast<STG::Conn *>(NULL));
172 m_conns.erase(pos, m_conns.end());
175 void RADIUS::handleEvents(const fd_set & fds)
177 if (FD_ISSET(m_listenSocket, &fds))
181 std::deque<STG::Conn *>::iterator it;
182 for (it = m_conns.begin(); it != m_conns.end(); ++it)
183 if (FD_ISSET((*it)->sock(), &fds))