From becf6dfe4fe2ecd43792aa53a302c5866483f306 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 17 Mar 2011 12:24:14 +0200 Subject: [PATCH] Break internal classes to interface and implementation --- include/admin.h | 49 ++++++++ include/admins.h | 48 ++++++++ include/tariff.h | 56 +++++++++ include/tariffs.h | 46 ++++++++ include/user.h | 106 ++++++++++++++++++ include/users.h | 60 ++++++++++ .../stargazer/{admin.cpp => admin_impl.cpp} | 0 projects/stargazer/{admin.h => admin_impl.h} | 0 .../stargazer/{admins.cpp => admins_impl.cpp} | 0 .../stargazer/{admins.h => admins_impl.h} | 0 .../stargazer/{tariff.cpp => tariff_impl.cpp} | 0 .../stargazer/{tariff.h => tariff_impl.h} | 0 .../{tariffs.cpp => tariffs_impl.cpp} | 0 .../stargazer/{tariffs.h => tariffs_impl.h} | 0 .../stargazer/{user.cpp => user_impl.cpp} | 0 projects/stargazer/{user.h => user_impl.h} | 0 .../stargazer/{users.cpp => users_impl.cpp} | 0 projects/stargazer/{users.h => users_impl.h} | 0 18 files changed, 365 insertions(+) create mode 100644 include/admin.h create mode 100644 include/admins.h create mode 100644 include/tariff.h create mode 100644 include/tariffs.h create mode 100644 include/user.h create mode 100644 include/users.h rename projects/stargazer/{admin.cpp => admin_impl.cpp} (100%) rename projects/stargazer/{admin.h => admin_impl.h} (100%) rename projects/stargazer/{admins.cpp => admins_impl.cpp} (100%) rename projects/stargazer/{admins.h => admins_impl.h} (100%) rename projects/stargazer/{tariff.cpp => tariff_impl.cpp} (100%) rename projects/stargazer/{tariff.h => tariff_impl.h} (100%) rename projects/stargazer/{tariffs.cpp => tariffs_impl.cpp} (100%) rename projects/stargazer/{tariffs.h => tariffs_impl.h} (100%) rename projects/stargazer/{user.cpp => user_impl.cpp} (100%) rename projects/stargazer/{user.h => user_impl.h} (100%) rename projects/stargazer/{users.cpp => users_impl.cpp} (100%) rename projects/stargazer/{users.h => users_impl.h} (100%) diff --git a/include/admin.h b/include/admin.h new file mode 100644 index 00000000..7095bb62 --- /dev/null +++ b/include/admin.h @@ -0,0 +1,49 @@ +/* + * This program 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 Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef ADMIN_H +#define ADMIN_H + +#include + +#include "admin_conf.h" +#include "os_int.h" + +class ADMIN { +public: + virtual ADMIN & operator=(const ADMIN &) = 0; + virtual ADMIN & operator=(const ADMIN_CONF &) = 0; + virtual bool operator==(const ADMIN & rhs) const = 0; + virtual bool operator!=(const ADMIN & rhs) const = 0; + virtual bool operator<(const ADMIN & rhs) const = 0; + virtual bool operator<=(const ADMIN & rhs) const = 0; + + virtual const std::string & GetPassword() const = 0; + virtual const std::string & GetLogin() const = 0; + virtual PRIV const * GetPriv() const = 0; + virtual uint16_t GetPrivAsInt() const = 0; + virtual const ADMIN_CONF & GetConf() const = 0; + virtual uint32_t GetIP() const = 0; + virtual std::string GetIPStr() const = 0; + virtual void SetIP(uint32_t ip) = 0; + virtual const std::string GetLogStr() const = 0; +}; + +#endif diff --git a/include/admins.h b/include/admins.h new file mode 100644 index 00000000..48c02252 --- /dev/null +++ b/include/admins.h @@ -0,0 +1,48 @@ +/* + * This program 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 Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef ADMINS_H +#define ADMINS_H + +#include + +#include "admin.h" +#include "admin_conf.h" + +class ADMINS { +public: + virtual int Add(const std::string & login, const ADMIN & admin) = 0; + virtual int Del(const std::string & login, const ADMIN & admin) = 0; + virtual int Change(const ADMIN_CONF & ac, const ADMIN & admin) = 0; + virtual const ADMIN * GetSysAdmin() const = 0; + virtual const ADMIN * GetNoAdmin() const = 0; + virtual bool FindAdmin(const std::string & l, ADMIN ** admin) = 0; + virtual bool AdminExists(const std::string & login) const = 0; + virtual bool AdminCorrect(const std::string & login, + const std::string & password, + ADMIN * admin) const = 0; + virtual const std::string & GetStrError() const = 0; + + virtual int OpenSearch() const = 0; + virtual int SearchNext(int, ADMIN_CONF * ac) const = 0; + virtual int CloseSearch(int) const = 0; +}; + +#endif diff --git a/include/tariff.h b/include/tariff.h new file mode 100644 index 00000000..b19ec476 --- /dev/null +++ b/include/tariff.h @@ -0,0 +1,56 @@ +/* + * This program 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 Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef TARIFF_H +#define TARIFF_H + +#include + +#include + +#include "os_int.h" +#include "tariff_conf.h" + +class TARIFF { +public: + virtual double GetPriceWithTraffType(uint64_t up, + uint64_t down, + int dir, + time_t t) const = 0; + virtual double GetFreeMb() const = 0; + virtual double GetPassiveCost() const = 0; + virtual double GetFee() const = 0; + virtual double GetFree() const = 0; + + virtual const std::string & GetName() const = 0; + virtual void SetName(const std::string & name) = 0; + + virtual int GetTraffType() const = 0; + virtual int64_t GetTraffByType(uint64_t up, uint64_t down) const = 0; + virtual int GetThreshold(int dir) const = 0; + virtual const TARIFF_DATA & GetTariffData() const = 0; + + virtual TARIFF & operator=(const TARIFF_DATA & td) = 0; + virtual TARIFF & operator=(const TARIFF & t) = 0; + virtual bool operator==(const TARIFF & rhs) const = 0; + virtual bool operator!=(const TARIFF & rhs) const = 0; +}; + +#endif diff --git a/include/tariffs.h b/include/tariffs.h new file mode 100644 index 00000000..dfc47b48 --- /dev/null +++ b/include/tariffs.h @@ -0,0 +1,46 @@ +/* + * This program 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 Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef TARIFFS_H +#define TARIFFS_H + +#include +#include + +class ADMIN; +class TARIFF; +class TARIFF_DATA; + +class TARIFFS { +public: + virtual int ReadTariffs () = 0; + virtual const TARIFF * FindByName(const std::string & name) const = 0; + virtual const TARIFF * GetNoTariff() const = 0; + virtual int GetTariffsNum() const = 0; + virtual int Del(const std::string & name, const ADMIN & admin) = 0; + virtual int Add(const std::string & name, const ADMIN & admin) = 0; + virtual int Chg(const TARIFF_DATA & td, const ADMIN & admin) = 0; + + virtual void GetTariffsData(std::list * tdl) = 0; + + virtual const std::string & GetStrError() const = 0; +}; + +#endif diff --git a/include/user.h b/include/user.h new file mode 100644 index 00000000..cac12d57 --- /dev/null +++ b/include/user.h @@ -0,0 +1,106 @@ +/* + * This program 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 Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef USER_H +#define USER_H + +#include +#include + +#include "os_int.h" +#include "notifer.h" +#include "base_auth.h" +#include "stg_message.h" +#include "tariff.h" +#include "user_traff.h" + +class USER_PROPERTIES; + +class USER { +public: + virtual int WriteConf() = 0; + virtual int WriteStat() = 0; + + virtual const std::string & GetLogin() const = 0; + + virtual uint32_t GetCurrIP() const = 0; + virtual time_t GetCurrIPModificationTime() const = 0; + + virtual void AddCurrIPBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + virtual void DelCurrIPBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + + virtual void AddCurrIPAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + virtual void DelCurrIPAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + + virtual int GetID() const = 0; + + virtual double GetPassiveTimePart() const = 0; + + virtual const TARIFF * GetTariff() const = 0; + virtual void ResetNextTariff() = 0; + + #ifdef TRAFF_STAT_WITH_PORTS + virtual void AddTraffStatU(int dir, uint32_t ip, uint16_t port, uint32_t len) = 0; + virtual void AddTraffStatD(int dir, uint32_t ip, uint16_t port, uint32_t len) = 0; + #else + virtual void AddTraffStatU(int dir, uint32_t ip, uint32_t len) = 0; + virtual void AddTraffStatD(int dir, uint32_t ip, uint32_t len) = 0; + #endif + + virtual const DIR_TRAFF & GetSessionUpload() const = 0; + virtual const DIR_TRAFF & GetSessionDownload() const = 0; + + virtual bool GetConnected() const = 0; + virtual time_t GetConnectedModificationTime() const = 0; + virtual int GetAuthorized() const = 0; + virtual int Authorize(uint32_t ip, + const std::string & iface, + uint32_t enabledDirs, + const BASE_AUTH * auth) = 0; + virtual void Unauthorize(const BASE_AUTH * auth) = 0; + virtual bool IsAuthorizedBy(const BASE_AUTH * auth) const = 0; + + virtual int AddMessage(STG_MSG * msg) = 0; + + virtual void UpdatePingTime(time_t t = 0) = 0; + virtual time_t GetPingTime() const = 0; + + virtual void Run() = 0; + + virtual const std::string & GetStrError() const = 0; + + virtual USER_PROPERTIES & GetProperty() = 0; + virtual const USER_PROPERTIES & GetProperty() const = 0; + + virtual bool GetDeleted() const = 0; + virtual void SetDeleted() = 0; + + virtual time_t GetLastWriteStatTime() const = 0; + + virtual bool IsInetable() = 0; + virtual std::string GetEnabledDirs() = 0; + + virtual void OnAdd() = 0; + virtual void OnDelete() = 0; +}; + +typedef USER * USER_PTR; + +#endif diff --git a/include/users.h b/include/users.h new file mode 100644 index 00000000..b9454ce4 --- /dev/null +++ b/include/users.h @@ -0,0 +1,60 @@ +/* + * This program 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 Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef USERS_H +#define USERS_H + +#include + +#include "notifer.h" +#include "user.h" + +class ADMIN; + +class USERS { +public: + virtual int FindByName(const std::string & login, USER_PTR * user) = 0; + + virtual bool TariffInUse(const std::string & tariffName) const = 0; + + virtual void AddNotifierUserAdd(NOTIFIER_BASE * notifier) = 0; + virtual void DelNotifierUserAdd(NOTIFIER_BASE * notifier) = 0; + + virtual void AddNotifierUserDel(NOTIFIER_BASE * notifier) = 0; + virtual void DelNotifierUserDel(NOTIFIER_BASE * notifier) = 0; + + virtual int Add(const std::string & login, const ADMIN & admin) = 0; + virtual void Del(const std::string & login, const ADMIN & admin) = 0; + + virtual int ReadUsers() = 0; + virtual int GetUserNum() const = 0; + + virtual int FindByIPIdx(uint32_t ip, USER_PTR * user) const = 0; + virtual bool IsIPInIndex(uint32_t ip) const = 0; + + virtual int OpenSearch() = 0; + virtual int SearchNext(int handle, USER_PTR * u) = 0; + virtual int CloseSearch(int handle) = 0; + + virtual int Start() = 0; + virtual int Stop() = 0; +}; + +#endif diff --git a/projects/stargazer/admin.cpp b/projects/stargazer/admin_impl.cpp similarity index 100% rename from projects/stargazer/admin.cpp rename to projects/stargazer/admin_impl.cpp diff --git a/projects/stargazer/admin.h b/projects/stargazer/admin_impl.h similarity index 100% rename from projects/stargazer/admin.h rename to projects/stargazer/admin_impl.h diff --git a/projects/stargazer/admins.cpp b/projects/stargazer/admins_impl.cpp similarity index 100% rename from projects/stargazer/admins.cpp rename to projects/stargazer/admins_impl.cpp diff --git a/projects/stargazer/admins.h b/projects/stargazer/admins_impl.h similarity index 100% rename from projects/stargazer/admins.h rename to projects/stargazer/admins_impl.h diff --git a/projects/stargazer/tariff.cpp b/projects/stargazer/tariff_impl.cpp similarity index 100% rename from projects/stargazer/tariff.cpp rename to projects/stargazer/tariff_impl.cpp diff --git a/projects/stargazer/tariff.h b/projects/stargazer/tariff_impl.h similarity index 100% rename from projects/stargazer/tariff.h rename to projects/stargazer/tariff_impl.h diff --git a/projects/stargazer/tariffs.cpp b/projects/stargazer/tariffs_impl.cpp similarity index 100% rename from projects/stargazer/tariffs.cpp rename to projects/stargazer/tariffs_impl.cpp diff --git a/projects/stargazer/tariffs.h b/projects/stargazer/tariffs_impl.h similarity index 100% rename from projects/stargazer/tariffs.h rename to projects/stargazer/tariffs_impl.h diff --git a/projects/stargazer/user.cpp b/projects/stargazer/user_impl.cpp similarity index 100% rename from projects/stargazer/user.cpp rename to projects/stargazer/user_impl.cpp diff --git a/projects/stargazer/user.h b/projects/stargazer/user_impl.h similarity index 100% rename from projects/stargazer/user.h rename to projects/stargazer/user_impl.h diff --git a/projects/stargazer/users.cpp b/projects/stargazer/users_impl.cpp similarity index 100% rename from projects/stargazer/users.cpp rename to projects/stargazer/users_impl.cpp diff --git a/projects/stargazer/users.h b/projects/stargazer/users_impl.h similarity index 100% rename from projects/stargazer/users.h rename to projects/stargazer/users_impl.h -- 2.43.2