]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/other/radius/radius.cpp
Sending attributes from <auth>/send section. (#13)
[stg.git] / projects / stargazer / plugins / other / radius / radius.cpp
index 78c80b4df9e32a2d832038f2da5acf6711d7a494..11fbcf7be132d9547732c0ad16b8f5b126d74b48 100644 (file)
@@ -1,13 +1,9 @@
 #include "radius.h"
-#include "server.h"
 #include "radproto/error.h"
-
 #include "stg/common.h"
+#include <boost/tokenizer.hpp>
 
-#include <boost/asio.hpp>
-#include <string>
-#include <iostream>
-#include <cstdint> //uint8_t, uint32_t
+#include <utility>
 
 using STG::RADIUS;
 
@@ -17,15 +13,25 @@ extern "C" STG::Plugin* GetPlugin()
     return &plugin;
 }
 
-std::string RADIUS::GetVersion() const
+RADIUS::RADIUS()
+    : m_running(false),
+      m_users(nullptr),
+      m_logger(PluginLogger::get("radius"))
 {
-    return "Radius v.1.0";
 }
 
-RADIUS::RADIUS()
-    : m_logger(PluginLogger::get("radius")),
-      m_running(false)
+int RADIUS::ParseSettings()
+{
+    auto ret = m_config.ParseSettings(m_settings);
+    if (ret != 0)
+        m_errorStr = m_config.GetStrError();
+
+    return ret;
+}
+
+std::string RADIUS::GetVersion() const
 {
+    return "Radius v.1.0";
 }
 
 int RADIUS::Start()
@@ -41,20 +47,23 @@ int RADIUS::Stop()
 
     m_thread.request_stop();
 
+    if (m_server)
+        m_server->stop();
+
     m_thread.join();
     return 0;
 }
 
-void RADIUS::SetRunning(bool val)
+bool RADIUS::IsRunning()
 {
     const std::lock_guard lock(m_mutex);
-    m_running = val;
+    return m_running;
 }
 
-bool RADIUS::IsRunning()
+void RADIUS::SetRunning(bool val)
 {
     const std::lock_guard lock(m_mutex);
-    return m_running;
+    m_running = val;
 }
 
 int RADIUS::Run(std::stop_token token)
@@ -63,9 +72,9 @@ int RADIUS::Run(std::stop_token token)
 
     try
     {
-        boost::asio::io_service ioService;
-        Server server(ioService, "secret", 1812, "/usr/share/freeradius/dictionary");
-        ioService.run();
+        if (!m_server)
+           m_server = std::make_unique<Server>(m_ioContext, m_config.GetSecret(), m_config.GetPort(), m_config.GetDictionaries(), std::move(token), m_logger, m_users, m_config);
+        m_ioContext.run();
     }
     catch (const std::exception& e)
     {