]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_regex_glob.cpp
Remove VF_SERVICEPROVIDER, prevent heap allocation of ConfigReader
[user/henk/code/inspircd.git] / src / modules / m_regex_glob.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "m_regex.h"
15 #include "inspircd.h"
16
17 /* $ModDesc: Regex module using plain wildcard matching. */
18
19 class GlobRegex : public Regex
20 {
21 public:
22         GlobRegex(const std::string& rx) : Regex(rx)
23         {
24         }
25
26         virtual ~GlobRegex()
27         {
28         }
29
30         virtual bool Matches(const std::string& text)
31         {
32                 return InspIRCd::Match(text, this->regex_string);
33         }
34 };
35
36 class ModuleRegexGlob : public Module
37 {
38 public:
39         ModuleRegexGlob()       {
40                 ServerInstance->Modules->PublishInterface("RegularExpression", this);
41         }
42
43         virtual Version GetVersion()
44         {
45                 return Version("Regex module using plain wildcard matching.", VF_OPTCOMMON | VF_VENDOR);
46         }
47
48         virtual ~ModuleRegexGlob()
49         {
50                 ServerInstance->Modules->UnpublishInterface("RegularExpression", this);
51         }
52
53         void OnRequest(Request& request)
54         {
55                 if (strcmp("REGEX-NAME", request.id) == 0)
56                 {
57                         static_cast<RegexNameRequest&>(request).result = "glob";
58                 }
59                 else if (strcmp("REGEX", request.id) == 0)
60                 {
61                         RegexFactoryRequest& rfr = (RegexFactoryRequest&)request;
62                         std::string rx = rfr.GetRegex();
63                         rfr.result = new GlobRegex(rx);
64                 }
65         }
66 };
67
68 MODULE_INIT(ModuleRegexGlob)