Permalink
Browse files

Move the EModuleType into CModInfo

This also renames the values to shorter and more "well sounding" names.

Signed-off-by: Uli Schlachter <psychon@znc.in>
  • Loading branch information...
1 parent 5f53c35 commit cce40e9f711eafe06895ab57e7aa30af81f57905 @psychon psychon committed Aug 21, 2011
Showing with 76 additions and 76 deletions.
  1. +21 −21 ClientCommand.cpp
  2. +11 −11 Modules.cpp
  3. +18 −18 Modules.h
  4. +1 −1 Socket.cpp
  5. +4 −4 User.cpp
  6. +2 −2 WebModules.cpp
  7. +1 −1 modules/admin.cpp
  8. +6 −6 modules/modperl.cpp
  9. +4 −4 modules/modpython.cpp
  10. +1 −1 modules/modpython/module.h
  11. +4 −4 modules/webadmin.cpp
  12. +3 −3 znc.cpp
View
@@ -517,7 +517,7 @@ void CClient::UserCommand(CString& sLine) {
if (m_pUser->IsAdmin()) {
set<CModInfo> ssGlobalMods;
- CZNC::Get().GetModules().GetAvailableMods(ssGlobalMods, ModuleTypeGlobal);
+ CZNC::Get().GetModules().GetAvailableMods(ssGlobalMods, CModInfo::GlobalModule);
if (ssGlobalMods.empty()) {
PutStatus("No global modules available.");
@@ -562,21 +562,21 @@ void CClient::UserCommand(CString& sLine) {
}
return;
} else if (sCommand.Equals("LOADMOD") || sCommand.Equals("LOADMODULE")) {
- EModuleType eType;
+ CModInfo::EModuleType eType;
CString sType = sLine.Token(1);
CString sMod = sLine.Token(2);
CString sArgs = sLine.Token(3, true);
if (sType.Equals("global")) {
- eType = ModuleTypeGlobal;
+ eType = CModInfo::GlobalModule;
} else if (sType.Equals("user")) {
- eType = ModuleTypeUser;
+ eType = CModInfo::UserModule;
} else {
sMod = sType;
sArgs = sLine.Token(2, true);
sType = "default";
// Will be set correctly later
- eType = ModuleTypeUser;
+ eType = CModInfo::UserModule;
}
if (m_pUser->DenyLoadMod()) {
@@ -600,7 +600,7 @@ void CClient::UserCommand(CString& sLine) {
eType = ModInfo.DefaultType();
}
- if (eType == ModuleTypeGlobal && !m_pUser->IsAdmin()) {
+ if (eType == CModInfo::GlobalModule && !m_pUser->IsAdmin()) {
PutStatus("Unable to load global module [" + sMod + "]: Access Denied.");
return;
}
@@ -609,10 +609,10 @@ void CClient::UserCommand(CString& sLine) {
bool b = false;
switch (eType) {
- case ModuleTypeGlobal:
+ case CModInfo::GlobalModule:
b = CZNC::Get().GetModules().LoadModule(sMod, sArgs, eType, NULL, sModRet);
break;
- case ModuleTypeUser:
+ case CModInfo::UserModule:
b = m_pUser->GetModules().LoadModule(sMod, sArgs, eType, m_pUser, sModRet);
break;
default:
@@ -625,14 +625,14 @@ void CClient::UserCommand(CString& sLine) {
PutStatus(sModRet);
return;
} else if (sCommand.Equals("UNLOADMOD") || sCommand.Equals("UNLOADMODULE")) {
- EModuleType eType = ModuleTypeUser;
+ CModInfo::EModuleType eType = CModInfo::UserModule;
CString sType = sLine.Token(1);
CString sMod = sLine.Token(2);
if (sType.Equals("global")) {
- eType = ModuleTypeGlobal;
+ eType = CModInfo::GlobalModule;
} else if (sType.Equals("user")) {
- eType = ModuleTypeUser;
+ eType = CModInfo::UserModule;
} else {
sMod = sType;
sType = "default";
@@ -659,18 +659,18 @@ void CClient::UserCommand(CString& sLine) {
eType = ModInfo.DefaultType();
}
- if (eType == ModuleTypeGlobal && !m_pUser->IsAdmin()) {
+ if (eType == CModInfo::GlobalModule && !m_pUser->IsAdmin()) {
PutStatus("Unable to unload global module [" + sMod + "]: Access Denied.");
return;
}
CString sModRet;
switch (eType) {
- case ModuleTypeGlobal:
+ case CModInfo::GlobalModule:
CZNC::Get().GetModules().UnloadModule(sMod, sModRet);
break;
- case ModuleTypeUser:
+ case CModInfo::UserModule:
m_pUser->GetModules().UnloadModule(sMod, sModRet);
break;
default:
@@ -680,7 +680,7 @@ void CClient::UserCommand(CString& sLine) {
PutStatus(sModRet);
return;
} else if (sCommand.Equals("RELOADMOD") || sCommand.Equals("RELOADMODULE")) {
- EModuleType eType;
+ CModInfo::EModuleType eType;
CString sType = sLine.Token(1);
CString sMod = sLine.Token(2);
CString sArgs = sLine.Token(3, true);
@@ -691,15 +691,15 @@ void CClient::UserCommand(CString& sLine) {
}
if (sType.Equals("global")) {
- eType = ModuleTypeGlobal;
+ eType = CModInfo::GlobalModule;
} else if (sType.Equals("user")) {
- eType = ModuleTypeUser;
+ eType = CModInfo::UserModule;
} else {
sMod = sType;
sArgs = sLine.Token(2, true);
sType = "default";
// Will be set correctly later
- eType = ModuleTypeUser;
+ eType = CModInfo::UserModule;
}
if (sMod.empty()) {
@@ -718,18 +718,18 @@ void CClient::UserCommand(CString& sLine) {
eType = ModInfo.DefaultType();
}
- if (eType == ModuleTypeGlobal && !m_pUser->IsAdmin()) {
+ if (eType == CModInfo::GlobalModule && !m_pUser->IsAdmin()) {
PutStatus("Unable to reload global module [" + sMod + "]: Access Denied.");
return;
}
CString sModRet;
switch (eType) {
- case ModuleTypeGlobal:
+ case CModInfo::GlobalModule:
CZNC::Get().GetModules().ReloadModule(sMod, sArgs, NULL, sModRet);
break;
- case ModuleTypeUser:
+ case CModInfo::UserModule:
m_pUser->GetModules().ReloadModule(sMod, sArgs, m_pUser, sModRet);
break;
default:
View
@@ -100,7 +100,7 @@ const CString& CTimer::GetDescription() const { return m_sDescription; }
CModule::CModule(ModHandle pDLL, CUser* pUser, const CString& sModName, const CString& sDataDir) {
- m_eType = ModuleTypeUser;
+ m_eType = CModInfo::UserModule;
m_pDLL = pDLL;
m_pManager = &(CZNC::Get().GetManager());;
m_pUser = pUser;
@@ -577,13 +577,13 @@ void CModule::OnClientCapLs(SCString& ssCaps) {}
bool CModule::IsClientCapSupported(const CString& sCap, bool bState) { return false; }
void CModule::OnClientCapRequest(const CString& sCap, bool bState) {}
CModule::EModRet CModule::OnModuleLoading(const CString& sModName, const CString& sArgs,
- EModuleType eType, bool& bSuccess, CString& sRetMsg) { return CONTINUE; }
+ CModInfo::EModuleType eType, bool& bSuccess, CString& sRetMsg) { return CONTINUE; }
CModule::EModRet CModule::OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg) {
return CONTINUE;
}
CModule::EModRet CModule::OnGetModInfo(CModInfo& ModInfo, const CString& sModule,
bool& bSuccess, CString& sRetMsg) { return CONTINUE; }
-void CModule::OnGetAvailableMods(set<CModInfo>& ssMods, EModuleType eType) {}
+void CModule::OnGetAvailableMods(set<CModInfo>& ssMods, CModInfo::EModuleType eType) {}
CModules::CModules() {
@@ -770,7 +770,7 @@ bool CModules::OnClientCapRequest(const CString& sCap, bool bState) {
}
bool CModules::OnModuleLoading(const CString& sModName, const CString& sArgs,
- EModuleType eType, bool& bSuccess, CString& sRetMsg) {
+ CModInfo::EModuleType eType, bool& bSuccess, CString& sRetMsg) {
MODHALTCHK(OnModuleLoading(sModName, sArgs, eType, bSuccess, sRetMsg));
}
@@ -783,7 +783,7 @@ bool CModules::OnGetModInfo(CModInfo& ModInfo, const CString& sModule,
MODHALTCHK(OnGetModInfo(ModInfo, sModule, bSuccess, sRetMsg));
}
-bool CModules::OnGetAvailableMods(set<CModInfo>& ssMods, EModuleType eType) {
+bool CModules::OnGetAvailableMods(set<CModInfo>& ssMods, CModInfo::EModuleType eType) {
MODUNLOADCHK(OnGetAvailableMods(ssMods, eType));
return false;
}
@@ -799,7 +799,7 @@ CModule* CModules::FindModule(const CString& sModule) const {
return NULL;
}
-bool CModules::LoadModule(const CString& sModule, const CString& sArgs, EModuleType eType, CUser* pUser, CString& sRetMsg) {
+bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CModInfo::EModuleType eType, CUser* pUser, CString& sRetMsg) {
sRetMsg = "";
if (FindModule(sModule) != NULL) {
@@ -837,7 +837,7 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, EModuleT
return false;
}
- if (!pUser && eType == ModuleTypeUser) {
+ if (!pUser && eType == CModInfo::UserModule) {
dlclose(p);
sRetMsg = "Module [" + sModule + "] requires a user.";
return false;
@@ -846,10 +846,10 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, EModuleT
CModule* pModule = NULL;
switch (eType) {
- case ModuleTypeUser:
+ case CModInfo::UserModule:
pModule = Info.GetLoader()(p, pUser, sModule, sDataPath);
break;
- case ModuleTypeGlobal:
+ case CModInfo::GlobalModule:
pModule = Info.GetGlobalLoader()(p, sModule, sDataPath);
break;
default:
@@ -937,7 +937,7 @@ bool CModules::ReloadModule(const CString& sModule, const CString& sArgs, CUser*
return false;
}
- EModuleType eType = pModule->GetType();
+ CModInfo::EModuleType eType = pModule->GetType();
pModule = NULL;
sRetMsg = "";
@@ -987,7 +987,7 @@ bool CModules::GetModPathInfo(CModInfo& ModInfo, const CString& sModule, const C
return true;
}
-void CModules::GetAvailableMods(set<CModInfo>& ssMods, EModuleType eType) {
+void CModules::GetAvailableMods(set<CModInfo>& ssMods, CModInfo::EModuleType eType) {
ssMods.clear();
unsigned int a = 0;
View
@@ -39,11 +39,6 @@ class CModInfo;
#endif
#endif
-typedef enum {
- ModuleTypeGlobal,
- ModuleTypeUser
-} EModuleType;
-
typedef void* ModHandle;
template<class M> void TModInfo(CModInfo& Info) {}
@@ -105,7 +100,7 @@ template<class M> CModule* TModLoadGlobal(ModHandle p,
* @see For global modules you need GLOBALMODULEDEFS.
*/
#define MODULEDEFS(CLASS, DESCRIPTION) \
- MODCOMMONDEFS(CLASS, DESCRIPTION, ModuleTypeUser, Info.SetLoader(TModLoad<CLASS>))
+ MODCOMMONDEFS(CLASS, DESCRIPTION, CModInfo::UserModule, Info.SetLoader(TModLoad<CLASS>))
// !User Module Macros
// Global Module Macros
@@ -116,7 +111,7 @@ template<class M> CModule* TModLoadGlobal(ModHandle p,
/** This works exactly like MODULEDEFS, but for global modules. */
#define GLOBALMODULEDEFS(CLASS, DESCRIPTION) \
- MODCOMMONDEFS(CLASS, DESCRIPTION, ModuleTypeGlobal, Info.SetGlobalLoader(TModLoadGlobal<CLASS>))
+ MODCOMMONDEFS(CLASS, DESCRIPTION, CModInfo::GlobalModule, Info.SetGlobalLoader(TModLoadGlobal<CLASS>))
// !Global Module Macros
// Forward Declarations
@@ -179,6 +174,11 @@ class CModInfo {
typedef CModule* (*ModLoader)(ModHandle p, CUser* pUser, const CString& sModName, const CString& sModPath);
typedef CModule* (*GlobalModLoader)(ModHandle p, const CString& sModName, const CString& sModPath);
+ typedef enum {
+ GlobalModule,
+ UserModule
+ } EModuleType;
+
CModInfo() {
m_fGlobalLoader = NULL;
m_fLoader = NULL;
@@ -209,8 +209,8 @@ class CModInfo {
static CString ModuleTypeToString(EModuleType eType) {
switch (eType) {
- case ModuleTypeGlobal: return "Global";
- case ModuleTypeUser: return "User";
+ case GlobalModule: return "Global";
+ case UserModule: return "User";
default: return "UNKNOWN";
}
}
@@ -866,14 +866,14 @@ class CModule {
const CString& GetSavePath() const;
// Setters
- void SetType(EModuleType eType) { m_eType = eType; }
+ void SetType(CModInfo::EModuleType eType) { m_eType = eType; }
void SetDescription(const CString& s) { m_sDescription = s; }
void SetModPath(const CString& s) { m_sModPath = s; }
void SetArgs(const CString& s) { m_sArgs = s; }
// !Setters
// Getters
- EModuleType GetType() const { return m_eType; }
+ CModInfo::EModuleType GetType() const { return m_eType; }
const CString& GetDescription() const { return m_sDescription; }
const CString& GetArgs() const { return m_sArgs; }
const CString& GetModPath() const { return m_sModPath; }
@@ -958,7 +958,7 @@ class CModule {
* @return See CModule::EModRet.
*/
virtual EModRet OnModuleLoading(const CString& sModName, const CString& sArgs,
- EModuleType eType, bool& bSuccess, CString& sRetMsg);
+ CModInfo::EModuleType eType, bool& bSuccess, CString& sRetMsg);
/** Called when a module is going to be unloaded.
* @param pModule the module.
* @param[out] bSuccess the module was unloaded successfully
@@ -980,11 +980,11 @@ class CModule {
* @param ssMods put new modules here.
* @param bGlobal true if global modules are needed.
*/
- virtual void OnGetAvailableMods(set<CModInfo>& ssMods, EModuleType eType);
+ virtual void OnGetAvailableMods(set<CModInfo>& ssMods, CModInfo::EModuleType eType);
// !Global Modules
protected:
- EModuleType m_eType;
+ CModInfo::EModuleType m_eType;
CString m_sDescription;
set<CTimer*> m_sTimers;
set<CSocket*> m_sSockets;
@@ -1080,14 +1080,14 @@ class CModules : public vector<CModule*> {
bool OnServerCapResult(const CString& sCap, bool bSuccess);
CModule* FindModule(const CString& sModule) const;
- bool LoadModule(const CString& sModule, const CString& sArgs, EModuleType eType, CUser* pUser, CString& sRetMsg);
+ bool LoadModule(const CString& sModule, const CString& sArgs, CModInfo::EModuleType eType, CUser* pUser, CString& sRetMsg);
bool UnloadModule(const CString& sModule);
bool UnloadModule(const CString& sModule, CString& sRetMsg);
bool ReloadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg);
static bool GetModInfo(CModInfo& ModInfo, const CString& sModule, CString &sRetMsg);
static bool GetModPathInfo(CModInfo& ModInfo, const CString& sModule, const CString& sModPath, CString &sRetMsg);
- static void GetAvailableMods(set<CModInfo>& ssMods, EModuleType eType = ModuleTypeUser);
+ static void GetAvailableMods(set<CModInfo>& ssMods, CModInfo::EModuleType eType = CModInfo::UserModule);
// This returns the path to the .so and to the data dir
// which is where static data (webadmin skins) are saved
@@ -1109,11 +1109,11 @@ class CModules : public vector<CModule*> {
bool IsClientCapSupported(const CString& sCap, bool bState);
bool OnClientCapRequest(const CString& sCap, bool bState);
bool OnModuleLoading(const CString& sModName, const CString& sArgs,
- EModuleType eType, bool& bSuccess, CString& sRetMsg);
+ CModInfo::EModuleType eType, bool& bSuccess, CString& sRetMsg);
bool OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg);
bool OnGetModInfo(CModInfo& ModInfo, const CString& sModule,
bool& bSuccess, CString& sRetMsg);
- bool OnGetAvailableMods(set<CModInfo>& ssMods, EModuleType eType);
+ bool OnGetAvailableMods(set<CModInfo>& ssMods, CModInfo::EModuleType eType);
// !Global Modules
private:
View
@@ -59,7 +59,7 @@ CSocket::~CSocket() {
m_pModule->UnlinkSocket(this);
}
- if (pUser && m_pModule && (m_pModule->GetType() != ModuleTypeGlobal)) {
+ if (pUser && m_pModule && (m_pModule->GetType() != CModInfo::GlobalModule)) {
pUser->AddBytesWritten(GetBytesWritten());
pUser->AddBytesRead(GetBytesRead());
} else {
Oops, something went wrong.

0 comments on commit cce40e9

Please sign in to comment.