Anope IRC Services  Version 2.0
module.cpp
Go to the documentation of this file.
1 /* Modular support
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  */
9 
10 #include "services.h"
11 #include "modules.h"
12 #include "language.h"
13 #include "account.h"
14 
15 #ifdef GETTEXT_FOUND
16 # include <libintl.h>
17 #endif
18 
19 Module::Module(const Anope::string &modname, const Anope::string &, ModType modtype) : name(modname), type(modtype)
20 {
21  this->handle = NULL;
22  this->permanent = false;
23  this->created = Anope::CurTime;
24  this->SetVersion(Anope::Version());
25 
26  if (type & VENDOR)
27  this->SetAuthor("Anope");
28  else
29  {
30  /* Not vendor implies third */
31  type |= THIRD;
32  this->SetAuthor("Unknown");
33  }
34 
36  throw CoreException("Module already exists!");
37 
38  if (Anope::NoThird && type & THIRD)
39  throw ModuleException("Third party modules may not be loaded");
40 
41  ModuleManager::Modules.push_back(this);
42 
43 #if GETTEXT_FOUND
44  for (unsigned i = 0; i < Language::Languages.size(); ++i)
45  {
46  /* Remove .UTF-8 or any other suffix */
47  Anope::string lang;
48  sepstream(Language::Languages[i], '.').GetToken(lang);
49 
50  if (Anope::IsFile(Anope::LocaleDir + "/" + lang + "/LC_MESSAGES/" + modname + ".mo"))
51  {
52  if (!bindtextdomain(this->name.c_str(), Anope::LocaleDir.c_str()))
53  Log() << "Error calling bindtextdomain, " << Anope::LastError();
54  else
55  {
56  Log() << "Found language file " << lang << " for " << modname;
57  Language::Domains.push_back(modname);
58  }
59  break;
60  }
61  }
62 #endif
63 }
64 
66 {
67  /* Detach all event hooks for this module */
70  /* Clear any active timers this module has */
72 
73  std::list<Module *>::iterator it = std::find(ModuleManager::Modules.begin(), ModuleManager::Modules.end(), this);
74  if (it != ModuleManager::Modules.end())
75  ModuleManager::Modules.erase(it);
76 
77 #if GETTEXT_FOUND
78  std::vector<Anope::string>::iterator dit = std::find(Language::Domains.begin(), Language::Domains.end(), this->name);
79  if (dit != Language::Domains.end())
80  Language::Domains.erase(dit);
81 #endif
82 }
83 
84 void Module::SetPermanent(bool state)
85 {
86  this->permanent = state;
87 }
88 
90 {
91  return this->permanent;
92 }
93 
94 void Module::SetVersion(const Anope::string &nversion)
95 {
96  this->version = nversion;
97 }
98 
99 void Module::SetAuthor(const Anope::string &nauthor)
100 {
101  this->author = nauthor;
102 }
103 
104 ModuleVersion::ModuleVersion(int maj, int min, int pa) : version_major(maj), version_minor(min), version_patch(pa)
105 {
106 }
107 
109 {
110  return this->version_major;
111 }
112 
114 {
115  return this->version_minor;
116 }
117 
119 {
120  return this->version_patch;
121 }
122 
void * handle
Definition: modules.h:233
Anope::string name
Definition: modules.h:221
static Module * FindModule(const Anope::string &name)
bool GetPermanent() const
Definition: module.cpp:89
int version_patch
Definition: modules.h:184
int GetMinor() const
Definition: module.cpp:113
time_t created
Definition: modules.h:237
CoreExport bool NoThird
Definition: main.cpp:28
void SetAuthor(const Anope::string &author)
Definition: module.cpp:99
CoreExport string Version()
Definition: misc.cpp:625
CoreExport const string LastError()
Definition: misc.cpp:606
CoreExport bool IsFile(const Anope::string &file)
Definition: misc.cpp:266
CoreExport time_t CurTime
Definition: main.cpp:41
Module(const Anope::string &modname, const Anope::string &loadernick, ModType type=THIRD)
Definition: module.cpp:19
ModType type
Definition: modules.h:225
int version_major
Definition: modules.h:182
Anope::string version
Definition: modules.h:241
virtual ~Module()
Definition: module.cpp:65
int GetPatch() const
Definition: module.cpp:118
CoreExport std::vector< Anope::string > Languages
Definition: language.cpp:23
bool permanent
Definition: modules.h:217
static void ModuleUnload(Module *m)
Definition: account.cpp:69
static std::list< Module * > Modules
Definition: modules.h:1118
static void DetachAll(Module *mod)
Definition: modules.h:157
bool GetToken(Anope::string &token)
Definition: hashcomp.cpp:99
Anope::string name
Definition: access.cpp:22
CoreExport Anope::string LocaleDir
Definition: init.cpp:33
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
void SetVersion(const Anope::string &version)
Definition: module.cpp:94
int GetMajor() const
Definition: module.cpp:108
unsigned short ModType
Definition: modules.h:174
void SetPermanent(bool state)
Definition: module.cpp:84
int version_minor
Definition: modules.h:183
static void DeleteTimersFor(Module *m)
Definition: timers.cpp:119
ModuleVersion(int major, int minor, int patch)
Definition: module.cpp:104
Anope::string author
Definition: modules.h:245
std::vector< Anope::string > Domains
Definition: language.cpp:24