From: Maxim Mamontov Date: Mon, 25 Jul 2011 19:55:13 +0000 (+0300) Subject: Code deduplication (plugin creation via template PLUGIN_CREATOR) X-Git-Tag: 2.408-alpha~77 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/f7163d9c994af13f0f72f49f7203b7ac3e281a1e?hp=3a45cd9275dc9279e133deb0932402ae5f4d0b5f Code deduplication (plugin creation via template PLUGIN_CREATOR) --- diff --git a/projects/stargazer/plugins/authorization/ao/ao.cpp b/projects/stargazer/plugins/authorization/ao/ao.cpp index 193b20bc..004210d2 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.cpp +++ b/projects/stargazer/plugins/authorization/ao/ao.cpp @@ -34,32 +34,20 @@ $Author: faust $ #include "stg/users.h" #include "stg/user_property.h" #include "stg/common.h" +#include "stg/plugin_creator.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 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"; diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 33c23bce..58d9259f 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -44,6 +44,7 @@ #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; @@ -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); -//----------------------------------------------------------------------------- -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 iac; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/authorization/stress/stress.cpp b/projects/stargazer/plugins/authorization/stress/stress.cpp index 481444b5..5d41a91d 100644 --- a/projects/stargazer/plugins/authorization/stress/stress.cpp +++ b/projects/stargazer/plugins/authorization/stress/stress.cpp @@ -33,35 +33,14 @@ #include "stg/user.h" #include "stg/common.h" #include "stg/user_property.h" +#include "stg/plugin_creator.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 stressc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp b/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp index 799e399d..f4b4f8ae 100644 --- a/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp +++ b/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp @@ -37,6 +37,7 @@ $Author: faust $ #include #include +#include "stg/plugin_creator.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); } //----------------------------------------------------------------------------- - -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 cdc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- 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"; diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp index 23d6413c..3d6c55b5 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp @@ -42,28 +42,14 @@ $Author: faust $ #include "stg/common.h" #include "stg/raw_ip_packet.h" #include "stg/traffcounter.h" +#include "stg/plugin_creator.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 cnc; PLUGIN * GetPlugin() { -return cnc.GetCapturer(); +return cnc.GetPlugin(); } NF_CAP::NF_CAP() diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp index 61090de7..603c5209 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp @@ -45,6 +45,7 @@ $Date: 2010/09/10 06:43:03 $ #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?*/ @@ -60,35 +61,15 @@ char iface[10]; 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 dcc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- PLUGIN * GetPlugin() { -return dcc.GetCapturer(); +return dcc.GetPlugin(); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp index 07e38577..20ca2480 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp @@ -48,44 +48,24 @@ $Author: faust $ #include #include -#include "ether_cap.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 -//----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -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 bcc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- PLUGIN * GetPlugin() { -return bcc.GetCapturer(); +return bcc.GetPlugin(); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp index f6cdc067..bd075fee 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp @@ -44,43 +44,24 @@ $Date: 2009/12/13 13:45:13 $ #include #include -#include "ether_cap.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 -//----------------------------------------------------------------------------- -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 ecc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- PLUGIN * GetPlugin() { -return ecc.GetCapturer(); +return ecc.GetPlugin(); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp index 97b70a0b..de5cd0ed 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp @@ -25,6 +25,7 @@ #include "stg/raw_ip_packet.h" #include "stg/traffcounter.h" +#include "stg/plugin_creator.h" #include "ipq_cap.h" extern "C" @@ -32,35 +33,16 @@ extern "C" #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 icc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- PLUGIN * GetPlugin() { -return icc.GetCapturer(); +return icc.GetPlugin(); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp index 8afbd9cd..7968e0dc 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp @@ -10,6 +10,7 @@ #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" @@ -18,27 +19,7 @@ #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 rpcc; RPC_CONFIG_SETTINGS::RPC_CONFIG_SETTINGS() : errorStr(), diff --git a/projects/stargazer/plugins/configuration/sgconfig-ng/creator.cpp b/projects/stargazer/plugins/configuration/sgconfig-ng/creator.cpp index 042c2055..1faa7d60 100644 --- a/projects/stargazer/plugins/configuration/sgconfig-ng/creator.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig-ng/creator.cpp @@ -1,27 +1,7 @@ +#include "stg/plugin_creator.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 stgc; BASE_PLUGIN * GetPlugin() { diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp index 06e915c3..600f7d80 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp @@ -7,32 +7,13 @@ #include "stg/tariffs.h" #include "stg/admins.h" #include "stg/users.h" +#include "stg/plugin_creator.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 stgc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/configuration/sgconfig2/stgconfig.cpp b/projects/stargazer/plugins/configuration/sgconfig2/stgconfig.cpp index d83942dc..c5864cc4 100644 --- a/projects/stargazer/plugins/configuration/sgconfig2/stgconfig.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig2/stgconfig.cpp @@ -4,33 +4,13 @@ #include #include +#include "stg/plugin_creator.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 stgc; BASE_PLUGIN * GetPlugin() { diff --git a/projects/stargazer/plugins/configuration/xrconfig/xrconfig.cpp b/projects/stargazer/plugins/configuration/xrconfig/xrconfig.cpp index 856ae886..1b9237ca 100644 --- a/projects/stargazer/plugins/configuration/xrconfig/xrconfig.cpp +++ b/projects/stargazer/plugins/configuration/xrconfig/xrconfig.cpp @@ -2,35 +2,23 @@ #include #include +#include "stg/plugin_creator.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 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"; diff --git a/projects/stargazer/plugins/other/ping/ping.cpp b/projects/stargazer/plugins/other/ping/ping.cpp index ec137044..7abc53b9 100644 --- a/projects/stargazer/plugins/other/ping/ping.cpp +++ b/projects/stargazer/plugins/other/ping/ping.cpp @@ -7,32 +7,17 @@ #include "stg/user.h" #include "stg/locker.h" #include "stg/user_property.h" +#include "stg/plugin_creator.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 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) { diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index afcc46fd..1dfff791 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -34,6 +34,7 @@ #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; @@ -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 radc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index 1c2e97bb..b4bbb1a0 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -35,6 +35,7 @@ #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" @@ -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 rsc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/other/smux/smux.cpp b/projects/stargazer/plugins/other/smux/smux.cpp index 0cf56ff8..4629aeab 100644 --- a/projects/stargazer/plugins/other/smux/smux.cpp +++ b/projects/stargazer/plugins/other/smux/smux.cpp @@ -11,23 +11,12 @@ #include #include "stg/common.h" +#include "stg/plugin_creator.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 sac; PLUGIN * GetPlugin() { diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index 5fadbd4d..1a16ed91 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -51,6 +51,7 @@ #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" @@ -63,78 +64,15 @@ int GetFileList(vector * fileList, const string & directory, mode_t mode 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 fsc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- STORE * GetStore() { -return fsc.GetStore(); +return fsc.GetPlugin(); } //----------------------------------------------------------------------------- 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"; -//BAK_FILE bakFile(fileName, storeSettings.GetRemoveBak()); - CONFIGFILE cfstat(fileName, true); int e = cfstat.Error(); @@ -1037,8 +973,6 @@ char s[22]; string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/stat"; -//BAK_FILE bakFile(fileName, storeSettings.GetRemoveBak()); - { CONFIGFILE cfstat(fileName, true); int e = cfstat.Error(); diff --git a/projects/stargazer/plugins/store/firebird/firebird_store.cpp b/projects/stargazer/plugins/store/firebird/firebird_store.cpp index f8de3357..d0918716 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store.cpp @@ -30,27 +30,13 @@ #include #include -using namespace std; - -#include "firebird_store.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 frsc; //----------------------------------------------------------------------------- STORE * GetStore() { diff --git a/projects/stargazer/plugins/store/mysql/mysql_store.cpp b/projects/stargazer/plugins/store/mysql/mysql_store.cpp index 567d6950..122c9214 100644 --- a/projects/stargazer/plugins/store/mysql/mysql_store.cpp +++ b/projects/stargazer/plugins/store/mysql/mysql_store.cpp @@ -12,6 +12,7 @@ #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" @@ -95,26 +96,7 @@ int GetULongLongInt(const string & str, uint64_t * val, uint64_t defaultVal) 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 msc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp index 2210c951..19e3efec 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp @@ -44,30 +44,17 @@ #include -#include "postgresql_store.h" -#include "postgresql_store_utils.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 pqStoreeCreator; //----------------------------------------------------------------------------- STORE * GetStore() { -return pqStoreeCreator.GetStore(); +return pqStoreeCreator.GetPlugin(); } //-----------------------------------------------------------------------------