]> git.stg.codes - stg.git/commitdiff
Code deduplication (plugin creation via template PLUGIN_CREATOR)
authorMaxim Mamontov <faust.madf@gmail.com>
Mon, 25 Jul 2011 19:55:13 +0000 (22:55 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Mon, 25 Jul 2011 19:55:13 +0000 (22:55 +0300)
22 files changed:
projects/stargazer/plugins/authorization/ao/ao.cpp
projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp
projects/stargazer/plugins/authorization/stress/stress.cpp
projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp
projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp
projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp
projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp
projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp
projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp
projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp
projects/stargazer/plugins/configuration/sgconfig-ng/creator.cpp
projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp
projects/stargazer/plugins/configuration/sgconfig2/stgconfig.cpp
projects/stargazer/plugins/configuration/xrconfig/xrconfig.cpp
projects/stargazer/plugins/other/ping/ping.cpp
projects/stargazer/plugins/other/radius/radius.cpp
projects/stargazer/plugins/other/rscript/rscript.cpp
projects/stargazer/plugins/other/smux/smux.cpp
projects/stargazer/plugins/store/files/file_store.cpp
projects/stargazer/plugins/store/firebird/firebird_store.cpp
projects/stargazer/plugins/store/mysql/mysql_store.cpp
projects/stargazer/plugins/store/postgresql/postgresql_store.cpp

index 193b20bc2e5ffe3160b6182b4c170541a9ab6caa..004210d2b5b030f18c13496e2906704f804af45c 100644 (file)
@@ -34,32 +34,20 @@ $Author: faust $
 #include "stg/users.h"
 #include "stg/user_property.h"
 #include "stg/common.h"
 #include "stg/users.h"
 #include "stg/user_property.h"
 #include "stg/common.h"
+#include "stg/plugin_creator.h"
 #include "ao.h"
 
 #include "ao.h"
 
-class AO_CREATOR
-{
-private:
-    AUTH_AO * ao;
-
-public:
-    AO_CREATOR()
-        : ao(new AUTH_AO())
-        {
-        };
-    ~AO_CREATOR()
-        {
-        delete ao;
-        };
-
-    AUTH_AO * GetPlugin()
-        {
-        return ao;
-        };
-};
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-AO_CREATOR aoc;
+PLUGIN_CREATOR<AUTH_AO> aoc;
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+PLUGIN * GetPlugin()
+{
+return aoc.GetPlugin();
+}
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -75,13 +63,6 @@ public:
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-PLUGIN * GetPlugin()
-{
-return aoc.GetPlugin();
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
 const string AUTH_AO::GetVersion() const
 {
 return "Always Online authorizator v.1.0";
 const string AUTH_AO::GetVersion() const
 {
 return "Always Online authorizator v.1.0";
index 33c23bced70f38ecee79b512d9ebe5832c6567a2..58d9259f68f124a433b00ec44ff4e6ce54991287 100644 (file)
@@ -44,6 +44,7 @@
 #include "stg/tariff.h"
 #include "stg/user_property.h"
 #include "stg/settings.h"
 #include "stg/tariff.h"
 #include "stg/user_property.h"
 #include "stg/settings.h"
+#include "stg/plugin_creator.h"
 #include "inetaccess.h"
 
 extern volatile const time_t stgTime;
 #include "inetaccess.h"
 
 extern volatile const time_t stgTime;
@@ -52,31 +53,10 @@ void InitEncrypt(BLOWFISH_CTX * ctx, const string & password);
 void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
 void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
 
 void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
 void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
 
-//-----------------------------------------------------------------------------
-class IA_CREATOR
-{
-private:
-    AUTH_IA * ia;
-
-public:
-    IA_CREATOR()
-        : ia(new AUTH_IA())
-        {
-        };
-    ~IA_CREATOR()
-        {
-        delete ia;
-        };
-
-    AUTH_IA * GetPlugin()
-    {
-        return ia;
-    };
-};
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-IA_CREATOR iac;
+PLUGIN_CREATOR<AUTH_IA> iac;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
index 481444b520e983eada0d1bb59548a8f3b8f562a7..5d41a91dacf60b86167fe89ebc1a327daccd9f07 100644 (file)
 #include "stg/user.h"
 #include "stg/common.h"
 #include "stg/user_property.h"
 #include "stg/user.h"
 #include "stg/common.h"
 #include "stg/user_property.h"
+#include "stg/plugin_creator.h"
 
 #include "stress.h"
 
 
 #include "stress.h"
 
-class STRESS_CREATOR
-{
-private:
-    AUTH_STRESS * dc;
-
-public:
-    STRESS_CREATOR()
-        {
-        printfd(__FILE__, "constructor STRESS_CREATOR\n");
-        dc = new AUTH_STRESS();
-        };
-    ~STRESS_CREATOR()
-        {
-        printfd(__FILE__, "destructor STRESS_CREATOR\n");
-        delete dc;
-        };
-
-    PLUGIN * GetPlugin()
-    {
-        return dc;
-    };
-};
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-STRESS_CREATOR stressc;
+PLUGIN_CREATOR<AUTH_STRESS> stressc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
index 799e399d39c9884541f37a6e9109b386b3671923..f4b4f8ae373af102877d7c03b1ec3fa4fde8b6e1 100644 (file)
@@ -37,6 +37,7 @@ $Author: faust $
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
+#include "stg/plugin_creator.h"
 #include "debug_cap.h"
 #include "../../../traffcounter.h"
 #include "libpal.h"
 #include "debug_cap.h"
 #include "../../../traffcounter.h"
 #include "libpal.h"
@@ -53,46 +54,26 @@ fprintf(f, "up %5.2f Mbit, down %5.2f Mbit, sum %5.2f Mbit\n",
 fclose(f);
 }
 //-----------------------------------------------------------------------------
 fclose(f);
 }
 //-----------------------------------------------------------------------------
-
-class CAP_DEBUG_CREATOR
-{
-private:
-    DEBUG_CAP * dc;
-
-public:
-    CAP_DEBUG_CREATOR()
-        : dc(new DEBUG_CAP())
-        {
-        };
-    ~CAP_DEBUG_CREATOR()
-        {
-        delete dc;
-        };
-
-    DEBUG_CAP * GetCapturer()
-    {
-        return dc;
-    };
-};
-//-----------------------------------------------------------------------------
-RAW_PACKET MakeTCPPacket(const char * src,
-                         const char * dst,
-                         uint16_t sport,
-                         uint16_t dport,
-                         uint16_t len);
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-CAP_DEBUG_CREATOR cdc;
+PLUGIN_CREATOR<DEBUG_CAP> cdc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 BASE_PLUGIN * GetPlugin()
 {
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 BASE_PLUGIN * GetPlugin()
 {
-return cdc.GetCapturer();
+return cdc.GetPlugin();
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+RAW_PACKET MakeTCPPacket(const char * src,
+                         const char * dst,
+                         uint16_t sport,
+                         uint16_t dport,
+                         uint16_t len);
 const string DEBUG_CAP::GetVersion() const
 {
 return "Debug_cap v.0.01a";
 const string DEBUG_CAP::GetVersion() const
 {
 return "Debug_cap v.0.01a";
index 23d6413c7bf132d1602d9400857eba4ac653ce92..3d6c55b5b7139b2ac037db4f25a65266a1dfaa01 100644 (file)
@@ -42,28 +42,14 @@ $Author: faust $
 #include "stg/common.h" 
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
 #include "stg/common.h" 
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
+#include "stg/plugin_creator.h"
 #include "cap_nf.h"
 
 #include "cap_nf.h"
 
-class CAP_NF_CREATOR {
-public:
-    CAP_NF_CREATOR()
-        : nf(new NF_CAP())
-        {
-        }
-
-    ~CAP_NF_CREATOR()
-        {
-        delete nf;
-        }
-
-    NF_CAP * GetCapturer() { return nf; }
-private:
-    NF_CAP * nf;
-} cnc;
+PLUGIN_CREATOR<NF_CAP> cnc;
 
 PLUGIN * GetPlugin()
 {
 
 PLUGIN * GetPlugin()
 {
-return cnc.GetCapturer();
+return cnc.GetPlugin();
 }
 
 NF_CAP::NF_CAP()
 }
 
 NF_CAP::NF_CAP()
index 61090de7c1997cc297991dc353f32fb0649ecb5e..603c520994bf11fa8075f4f36a0ab41ffa7d4343 100644 (file)
@@ -45,6 +45,7 @@ $Date: 2010/09/10 06:43:03 $
 
 #include "stg/common.h"
 #include "stg/traffcounter.h"
 
 #include "stg/common.h"
 #include "stg/traffcounter.h"
+#include "sg/plugin_creator.h"
 #include "divert_cap.h"
 
 #define BUFF_LEN (16384) /* max mtu -> lo=16436  TODO why?*/
 #include "divert_cap.h"
 
 #define BUFF_LEN (16384) /* max mtu -> lo=16436  TODO why?*/
@@ -60,35 +61,15 @@ char iface[10];
 pollfd pollddiv;
 DIVERT_DATA cddiv;  //capture data
 //-----------------------------------------------------------------------------
 pollfd pollddiv;
 DIVERT_DATA cddiv;  //capture data
 //-----------------------------------------------------------------------------
-class DIVERT_CAP_CREATOR {
-private:
-    DIVERT_CAP * divc;
-
-public:
-    DIVERT_CAP_CREATOR()
-        : divc(new DIVERT_CAP())
-        {
-        }
-    ~DIVERT_CAP_CREATOR()
-        {
-        delete divc;
-        }
-
-    DIVERT_CAP * GetCapturer()
-    {
-    return divc;
-    }
-};
-//-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-DIVERT_CAP_CREATOR dcc;
+PLUGIN_CREATOR<DIVERT_CAP> dcc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PLUGIN * GetPlugin()
 {
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PLUGIN * GetPlugin()
 {
-return dcc.GetCapturer();
+return dcc.GetPlugin();
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
index 07e3857713c8ba4204c0823960226a1ac6da65f9..20ca24809a3696abd9eb540818751f4f44b17108 100644 (file)
@@ -48,44 +48,24 @@ $Author: faust $
 #include <signal.h>
 #include <unistd.h>
 
 #include <signal.h>
 #include <unistd.h>
 
-#include "ether_cap.h"
 #include "stg/common.h"
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
 #include "stg/common.h"
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
+#include "stg/plugin_creator.h"
+#include "ether_cap.h"
 
 //#define CAP_DEBUG 1
 
 //#define CAP_DEBUG 1
-//-----------------------------------------------------------------------------
-
-//-----------------------------------------------------------------------------
-class BPF_CAP_CREATOR {
-private:
-    BPF_CAP * bpfc;
-
-public:
-    BPF_CAP_CREATOR()
-        : bpfc(new BPF_CAP())
-        {
-        }
-    ~BPF_CAP_CREATOR()
-        {
-        delete bpfc;
-        }
 
 
-    BPF_CAP * GetCapturer()
-    {
-    return bpfc;
-    }
-};
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-BPF_CAP_CREATOR bcc;
+PLUGIN_CREATOR<BPF_CAP> bcc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PLUGIN * GetPlugin()
 {
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PLUGIN * GetPlugin()
 {
-return bcc.GetCapturer();
+return bcc.GetPlugin();
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
index f6cdc067aca9b5e02eb654b5202370b3121ed906..bd075feead63b7faf4ebd5b27b27185e96ca60a4 100644 (file)
@@ -44,43 +44,24 @@ $Date: 2009/12/13 13:45:13 $
 #include <sys/ioctl.h>
 #include <net/if.h>
 
 #include <sys/ioctl.h>
 #include <net/if.h>
 
-#include "ether_cap.h"
 #include "stg/common.h"
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
 #include "stg/common.h"
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
+#include "stg/plugin_creator.h"
+#include "ether_cap.h"
 
 //#define CAP_DEBUG 1
 
 
 //#define CAP_DEBUG 1
 
-//-----------------------------------------------------------------------------
-class ETHER_CAP_CREATOR {
-private:
-    ETHER_CAP * ec;
-
-public:
-    ETHER_CAP_CREATOR()
-        : ec(new ETHER_CAP())
-        {
-        }
-    ~ETHER_CAP_CREATOR()
-        {
-        delete ec;
-        }
-
-    ETHER_CAP * GetCapturer()
-        {
-        return ec;
-        }
-};
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-ETHER_CAP_CREATOR ecc;
+PLUGIN_CREATOR<ETHER_CAP> ecc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PLUGIN * GetPlugin()
 {
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PLUGIN * GetPlugin()
 {
-return ecc.GetCapturer();
+return ecc.GetPlugin();
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
index 97b70a0b55cc5b6392a5af8364c78077a47cc03e..de5cd0ed2cdde2bfb23efc3caaccb54167fc0102 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
 
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
+#include "stg/plugin_creator.h"
 #include "ipq_cap.h"
 
 extern "C"
 #include "ipq_cap.h"
 
 extern "C"
@@ -32,35 +33,16 @@ extern "C"
 #include "libipq.h"
 }
 
 #include "libipq.h"
 }
 
-class IPQ_CAP_CREATOR {
-private:
-    IPQ_CAP * ic;
-
-public:
-    IPQ_CAP_CREATOR()
-        : ic(new IPQ_CAP())
-        {
-        }
-    ~IPQ_CAP_CREATOR()
-        {
-        delete ic;
-        }
-
-    IPQ_CAP * GetCapturer()
-        {
-        return ic;
-        }
-};
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-IPQ_CAP_CREATOR icc;
+PLUGIN_CREATOR<IPQ_CAP> icc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PLUGIN * GetPlugin()
 {
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PLUGIN * GetPlugin()
 {
-return icc.GetCapturer();
+return icc.GetPlugin();
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
index 8afbd9cdda8f1bf8acab5880f1c5e625956a495e..7968e0dc74249845b6e75e9268d6ca4626c4a9b3 100644 (file)
@@ -10,6 +10,7 @@
 #include "stg/admin.h"
 #include "stg/module_settings.h"
 #include "stg/settings.h"
 #include "stg/admin.h"
 #include "stg/module_settings.h"
 #include "stg/settings.h"
+#include "stg/plugin_creator.h"
 
 #include "rpcconfig.h"
 #include "info_methods.h"
 
 #include "rpcconfig.h"
 #include "info_methods.h"
 #include "admins_methods.h"
 #include "messages_methods.h"
 
 #include "admins_methods.h"
 #include "messages_methods.h"
 
-class RPC_CONFIG_CREATOR {
-private:
-    RPC_CONFIG * rpcconfig;
-
-public:
-    RPC_CONFIG_CREATOR()
-        : rpcconfig(new RPC_CONFIG())
-        {
-        }
-    ~RPC_CONFIG_CREATOR()
-        {
-        delete rpcconfig;
-        }
-
-    RPC_CONFIG * GetPlugin()
-        {
-        return rpcconfig;
-        }
-};
-
-RPC_CONFIG_CREATOR rpcc;
+PLUGIN_CREATOR<RPC_CONFIG> rpcc;
 
 RPC_CONFIG_SETTINGS::RPC_CONFIG_SETTINGS()
     : errorStr(),
 
 RPC_CONFIG_SETTINGS::RPC_CONFIG_SETTINGS()
     : errorStr(),
index 042c20558a4463d9931ccce380a220b4b2015ec7..1faa7d6054cf32fdb905bdc46fe66464457744f8 100644 (file)
@@ -1,27 +1,7 @@
+#include "stg/plugin_creator.h"
 #include "stgconfig.h"
 
 #include "stgconfig.h"
 
-class STGCONFIG_CREATOR
-{
-private:
-    STGCONFIG2 * stgconfig;
-
-public:
-    STGCONFIG_CREATOR()
-        : stgconfig(new STGCONFIG2())
-        {
-        };
-    ~STGCONFIG_CREATOR()
-        {
-        delete stgconfig;
-        };
-
-    STGCONFIG2 * GetPlugin()
-        {
-        return stgconfig;
-        };
-};
-
-STGCONFIG_CREATOR stgc;
+PLUGIN_CREATOR<STGCONFIG2> stgc;
 
 BASE_PLUGIN * GetPlugin()
 {
 
 BASE_PLUGIN * GetPlugin()
 {
index 06e915c37e873e11461453f4a02f836405f4d74f..600f7d8092e4b260d71a18e5e4093a1a3a0d81db 100644 (file)
@@ -7,32 +7,13 @@
 #include "stg/tariffs.h"
 #include "stg/admins.h"
 #include "stg/users.h"
 #include "stg/tariffs.h"
 #include "stg/admins.h"
 #include "stg/users.h"
+#include "stg/plugin_creator.h"
 #include "stgconfig.h"
 
 #include "stgconfig.h"
 
-class STGCONFIG_CREATOR
-{
-private:
-    STG_CONFIG * stgconfig;
-
-public:
-    STGCONFIG_CREATOR()
-        : stgconfig(new STG_CONFIG())
-        {
-        };
-    ~STGCONFIG_CREATOR()
-        {
-        delete stgconfig;
-        };
-
-    STG_CONFIG * GetPlugin()
-        {
-        return stgconfig;
-        };
-};
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-STGCONFIG_CREATOR stgc;
+PLUGIN_CREATOR<STG_CONFIG> stgc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
index d83942dc3a78065c172a8a5475643da9090a8609..c5864cc4c7b3540ef4da0f05a16bb638dc088573 100644 (file)
@@ -4,33 +4,13 @@
 #include <functional>
 #include <algorithm>
 
 #include <functional>
 #include <algorithm>
 
+#include "stg/plugin_creator.h"
 #include "stgconfig.h"
 #include "../../../tariffs.h"
 #include "../../../admins.h"
 #include "../../../users.h"
 
 #include "stgconfig.h"
 #include "../../../tariffs.h"
 #include "../../../admins.h"
 #include "../../../users.h"
 
-class STGCONFIG_CREATOR
-{
-private:
-    STG_CONFIG * stgconfig;
-
-public:
-    STGCONFIG_CREATOR()
-        : stgconfig(new STG_CONFIG())
-        {
-        };
-    ~STGCONFIG_CREATOR()
-        {
-        delete stgconfig;
-        };
-
-    STG_CONFIG * GetPlugin()
-        {
-        return stgconfig;
-        };
-};
-
-STGCONFIG_CREATOR stgc;
+PLUGIN_CREATOR<STG_CONFIG> stgc;
 
 BASE_PLUGIN * GetPlugin()
 {
 
 BASE_PLUGIN * GetPlugin()
 {
index 856ae88689679c04baef6d2fae7e55b9e942e4dd..1b9237cacea80256c661bdc0c277cf489dc12905 100644 (file)
@@ -2,35 +2,23 @@
 #include <unistd.h>
 #include <signal.h>
 
 #include <unistd.h>
 #include <signal.h>
 
+#include "stg/plugin_creator.h"
 #include "xrconfig.h"
 #include "../../../tariff2.h"
 #include "../../../admins.h"
 #include "../../../users.h"
 
 #include "xrconfig.h"
 #include "../../../tariff2.h"
 #include "../../../admins.h"
 #include "../../../users.h"
 
-class XR_CONFIG_CREATOR
-{
-private:
-    XR_CONFIG * xrconfig;
-
-public:
-    XR_CONFIG_CREATOR()
-        : xrconfig(new XR_CONFIG())
-        {
-        };
-    ~XR_CONFIG_CREATOR()
-        {
-        delete xrconfig;
-        };
-
-    XR_CONFIG * GetPlugin()
-        {
-        return xrconfig;
-        };
-};
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-XRCONFIG_CREATOR xrc;
+PLUGIN_CREATOR<XR_CONFIG> xrc;
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+BASE_PLUGIN * GetPlugin()
+{
+return xrc.GetPlugin();
+}
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -57,13 +45,6 @@ return port;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
-{
-return xrc.GetPlugin();
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
 const string XR_CONFIG::GetVersion() const
 {
 return "XR_configurator v.0.01";
 const string XR_CONFIG::GetVersion() const
 {
 return "XR_configurator v.0.01";
index ec13704443db2f193fd06ce80089f77fed9c5292..7abc53b9f5b1757b3157754255f788c69ee4e05b 100644 (file)
@@ -7,32 +7,17 @@
 #include "stg/user.h"
 #include "stg/locker.h"
 #include "stg/user_property.h"
 #include "stg/user.h"
 #include "stg/locker.h"
 #include "stg/user_property.h"
+#include "stg/plugin_creator.h"
 #include "ping.h"
 
 #include "ping.h"
 
-class PING_CREATOR
-{
-private:
-    PING * ping;
-
-public:
-    PING_CREATOR()
-        : ping(new PING())
-        {
-        };
-    ~PING_CREATOR()
-        {
-        delete ping;
-        };
-
-    PING * GetPlugin()
-        {
-        return ping;
-        };
-};
+PLUGIN_CREATOR<PING> pc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-PING_CREATOR pc;
+PLUGIN * GetPlugin()
+{
+return pc.GetPlugin();
+}
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -52,13 +37,6 @@ private:
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-PLUGIN * GetPlugin()
-{
-return pc.GetPlugin();
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
 PING_SETTINGS::PING_SETTINGS()
     : pingDelay(0)
 {
 PING_SETTINGS::PING_SETTINGS()
     : pingDelay(0)
 {
index afcc46fd65d446265436146d47211e8a2f098f26..1dfff791afe4eb386a19ee0d34f19aebbdb17611 100644 (file)
@@ -34,6 +34,7 @@
 #include "stg/common.h"
 #include "stg/user_conf.h"
 #include "stg/user_property.h"
 #include "stg/common.h"
 #include "stg/user_conf.h"
 #include "stg/user_property.h"
+#include "stg/plugin_creator.h"
 #include "radius.h"
 
 extern volatile const time_t stgTime;
 #include "radius.h"
 
 extern volatile const time_t stgTime;
@@ -45,29 +46,7 @@ void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-class RAD_CREATOR {
-private:
-    RADIUS * rad;
-
-public:
-    RAD_CREATOR()
-        : rad(new RADIUS())
-        {
-        }
-    ~RAD_CREATOR()
-        {
-        delete rad;
-        }
-
-    RADIUS * GetPlugin()
-        {
-        return rad;
-        }
-};
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-RAD_CREATOR radc;
+PLUGIN_CREATOR<RADIUS> radc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
index 1c2e97bbb81da3fbebe4895db52bc487b4e1f2fb..b4bbb1a0b40e177a1aca6c688cbeed2d4fd37a61 100644 (file)
@@ -35,6 +35,7 @@
 #include "stg/common.h"
 #include "stg/locker.h"
 #include "stg/user_property.h"
 #include "stg/common.h"
 #include "stg/locker.h"
 #include "stg/user_property.h"
+#include "stg/plugin_creator.h"
 #include "rscript.h"
 #include "ur_functor.h"
 #include "send_functor.h"
 #include "rscript.h"
 #include "ur_functor.h"
 #include "send_functor.h"
@@ -46,30 +47,7 @@ extern volatile const time_t stgTime;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-class RS_CREATOR
-{
-private:
-    REMOTE_SCRIPT * rs;
-
-public:
-    RS_CREATOR()
-        : rs(new REMOTE_SCRIPT())
-        {
-        };
-    ~RS_CREATOR()
-        {
-        delete rs;
-        };
-
-    REMOTE_SCRIPT * GetPlugin()
-        {
-        return rs;
-        };
-};
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-RS_CREATOR rsc;
+PLUGIN_CREATOR<REMOTE_SCRIPT> rsc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
index 0cf56ff80cdc1a7c7d3ef2ed457673e847f0ca38..4629aeab236b97777e051bd09890918922938b27 100644 (file)
 #include <algorithm>
 
 #include "stg/common.h"
 #include <algorithm>
 
 #include "stg/common.h"
+#include "stg/plugin_creator.h"
 
 #include "smux.h"
 #include "utils.h"
 
 
 #include "smux.h"
 #include "utils.h"
 
-class SMUX_CREATOR
-{
-private:
-    SMUX * smux;
-
-public:
-    SMUX_CREATOR() : smux(new SMUX()) {}
-    ~SMUX_CREATOR() { delete smux; }
-
-    SMUX * GetPlugin() { return smux; }
-};
-
-SMUX_CREATOR sac;
+PLUGIN_CREATOR<SMUX> sac;
 
 PLUGIN * GetPlugin()
 {
 
 PLUGIN * GetPlugin()
 {
index 5fadbd4d1457e54e2cef61a2c0c01bfab16d0d45..1a16ed91146d178fef2a15c5e1ed9aa7b8dab324 100644 (file)
@@ -51,6 +51,7 @@
 #include "stg/blowfish.h"
 #include "stg/logger.h"
 #include "stg/locker.h"
 #include "stg/blowfish.h"
 #include "stg/logger.h"
 #include "stg/locker.h"
+#include "stg/plugin_creator.h"
 #include "file_store.h"
 
 #define DELETED_USERS_DIR   "deleted_users"
 #include "file_store.h"
 
 #define DELETED_USERS_DIR   "deleted_users"
@@ -63,78 +64,15 @@ int GetFileList(vector<string> * fileList, const string & directory, mode_t mode
 
 const int pt_mega = 1024 * 1024;
 //-----------------------------------------------------------------------------
 
 const int pt_mega = 1024 * 1024;
 //-----------------------------------------------------------------------------
-class BAK_FILE
-{
-public:
-
-    //-------------------------------------------------------------------------
-    BAK_FILE(const string & fileName, bool removeBak)
-            : f(NULL),
-              removeBak(false)
-        {
-        bakSuccessed = false;
-        BAK_FILE::removeBak = removeBak;
-        fileNameBak = fileName + ".bak";
-        if (rename(fileName.c_str(), fileNameBak.c_str()))
-            {
-            printfd(__FILE__, "BAK_FILE::BAK_FILE - rename failed. Message: '%s'\n", strerror(errno));
-            }
-        else
-            {
-            bakSuccessed = true;
-            }
-
-        }
-    //-------------------------------------------------------------------------
-    ~BAK_FILE()
-        {
-        if(bakSuccessed && removeBak)
-            {
-            if (unlink(fileNameBak.c_str()))
-                {
-                printfd(__FILE__, "BAK_FILE::~BAK_FILE - unlink failed. Message: '%s'\n", strerror(errno));
-                }
-            }
-        }
-    //-------------------------------------------------------------------------
-
-private:
-    FILE * f;
-    bool bakSuccessed;
-    string fileNameBak;
-    bool removeBak;
-};
-//-----------------------------------------------------------------------------
-class FILES_STORE_CREATOR
-{
-private:
-    FILES_STORE * fs;
-
-public:
-    FILES_STORE_CREATOR()
-        : fs(new FILES_STORE())
-        {
-        };
-    ~FILES_STORE_CREATOR()
-        {
-        delete fs;
-        };
-
-    FILES_STORE * GetStore()
-    {
-        return fs;
-    };
-};
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-FILES_STORE_CREATOR fsc;
+PLUGIN_CREATOR<FILES_STORE> fsc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 STORE * GetStore()
 {
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 STORE * GetStore()
 {
-return fsc.GetStore();
+return fsc.GetPlugin();
 }
 //-----------------------------------------------------------------------------
 FILES_STORE_SETTINGS::FILES_STORE_SETTINGS()
 }
 //-----------------------------------------------------------------------------
 FILES_STORE_SETTINGS::FILES_STORE_SETTINGS()
@@ -978,8 +916,6 @@ int FILES_STORE::SaveUserConf(const USER_CONF & conf, const string & login) cons
 string fileName;
 fileName = storeSettings.GetUsersDir() + "/" + login + "/conf";
 
 string fileName;
 fileName = storeSettings.GetUsersDir() + "/" + login + "/conf";
 
-//BAK_FILE bakFile(fileName, storeSettings.GetRemoveBak());
-
 CONFIGFILE cfstat(fileName, true);
 
 int e = cfstat.Error();
 CONFIGFILE cfstat(fileName, true);
 
 int e = cfstat.Error();
@@ -1037,8 +973,6 @@ char s[22];
 string fileName;
 fileName = storeSettings.GetUsersDir() + "/" + login + "/stat";
 
 string fileName;
 fileName = storeSettings.GetUsersDir() + "/" + login + "/stat";
 
-//BAK_FILE bakFile(fileName, storeSettings.GetRemoveBak());
-
     {
     CONFIGFILE cfstat(fileName, true);
     int e = cfstat.Error();
     {
     CONFIGFILE cfstat(fileName, true);
     int e = cfstat.Error();
index f8de335702593a2460e64ad133c8d78d1fd00b1b..d0918716b2cb5d7feb9981448c04205706497f58 100644 (file)
 #include <vector>
 #include <algorithm>
 
 #include <vector>
 #include <algorithm>
 
-using namespace std;
-
-#include "firebird_store.h"
 #include "stg/ibpp.h"
 #include "stg/ibpp.h"
+#include "stg/plugin_creator.h"
+#include "firebird_store.h"
 
 
-class FIREBIRD_STORE_CREATOR
-{
-public:
-    FIREBIRD_STORE_CREATOR()
-        : frb(new FIREBIRD_STORE())
-        {
-        };
-    ~FIREBIRD_STORE_CREATOR()
-        {
-        delete frb;
-        };
-    FIREBIRD_STORE * GetStore() { return frb; };
-private:
-    FIREBIRD_STORE * frb;
-} frsc;
+using namespace std;
 
 
+PLUGIN_CREATOR<FIREBIRD_STORE> frsc;
 //-----------------------------------------------------------------------------
 STORE * GetStore()
 {
 //-----------------------------------------------------------------------------
 STORE * GetStore()
 {
index 567d69503d2d3f3da10cb01a84ff80258c3bfc08..122c921478590184b82859eb3c44bb0f0d25fc70 100644 (file)
@@ -12,6 +12,7 @@
 #include "stg/user_conf.h"
 #include "stg/user_stat.h"
 #include "stg/blowfish.h"
 #include "stg/user_conf.h"
 #include "stg/user_stat.h"
 #include "stg/blowfish.h"
+#include "stg/plugin_creator.h"
 #include "mysql_store.h"
 
 #define adm_enc_passwd "cjeifY8m3"
 #include "mysql_store.h"
 
 #define adm_enc_passwd "cjeifY8m3"
@@ -95,26 +96,7 @@ int GetULongLongInt(const string & str, uint64_t * val, uint64_t defaultVal)
     return 0;
 } 
 
     return 0;
 } 
 
-class MYSQL_STORE_CREATOR
-{
-private:
-    MYSQL_STORE * ms;
-
-public:
-    MYSQL_STORE_CREATOR()
-        : ms(new MYSQL_STORE())
-        {
-        };
-    ~MYSQL_STORE_CREATOR()
-        {
-        delete ms;
-        };
-
-    MYSQL_STORE * GetStore()
-        {
-        return ms;
-        };
-} msc;
+PLUGIN_CREATOR<MYSQL_STORE> msc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
index 2210c9511a4965e4a124a9b217a9bc9d269d3169..19e3efec8941797e64a64f181b607f5bb056f47a 100644 (file)
 
 #include <libpq-fe.h>
 
 
 #include <libpq-fe.h>
 
-#include "postgresql_store.h"
-#include "postgresql_store_utils.h"
 #include "stg/module_settings.h"
 #include "stg/module_settings.h"
+#include "stg/plugin_creator.h"
+#include "postgresql_store_utils.h"
+#include "postgresql_store.h"
 
 
-class POSTGRESQL_STORE_CREATOR
-{
-public:
-    POSTGRESQL_STORE_CREATOR()
-        : pqStore(new POSTGRESQL_STORE())
-        {
-        };
-    ~POSTGRESQL_STORE_CREATOR()
-        {
-        delete pqStore;
-        };
-    POSTGRESQL_STORE * GetStore() { return pqStore; };
-private:
-    POSTGRESQL_STORE * pqStore;
-} pqStoreeCreator;
+PLUGIN_CREATOR<POSTGRESQL_STORE> pqStoreeCreator;
 
 //-----------------------------------------------------------------------------
 STORE * GetStore()
 {
 
 //-----------------------------------------------------------------------------
 STORE * GetStore()
 {
-return pqStoreeCreator.GetStore();
+return pqStoreeCreator.GetPlugin();
 }
 
 //-----------------------------------------------------------------------------
 }
 
 //-----------------------------------------------------------------------------