]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_regex_glob.cpp
Remove InspIRCd* parameters and fields
[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 /* $ModDep: m_regex.h */
19
20 class GlobRegex : public Regex
21 {
22 public:
23         GlobRegex(const std::string& rx) : Regex(rx)
24         {
25         }
26
27         virtual ~GlobRegex()
28         {
29         }
30
31         virtual bool Matches(const std::string& text)
32         {
33                 return InspIRCd::Match(text, this->regex_string);
34         }
35 };
36
37 class ModuleRegexGlob : public Module
38 {
39 public:
40         ModuleRegexGlob()       {
41                 ServerInstance->Modules->PublishInterface("RegularExpression", this);
42                 Implementation eventlist[] = { I_OnRequest };
43                 ServerInstance->Modules->Attach(eventlist, this, 1);
44         }
45
46         virtual Version GetVersion()
47         {
48                 return Version("Regex module using plain wildcard matching.", VF_COMMON | VF_VENDOR | VF_SERVICEPROVIDER, API_VERSION);
49         }
50
51         virtual ~ModuleRegexGlob()
52         {
53                 ServerInstance->Modules->UnpublishInterface("RegularExpression", this);
54         }
55
56         virtual const char* OnRequest(Request* request)
57         {
58                 if (strcmp("REGEX-NAME", request->GetId()) == 0)
59                 {
60                         return "glob";
61                 }
62                 else if (strcmp("REGEX", request->GetId()) == 0)
63                 {
64                         RegexFactoryRequest* rfr = (RegexFactoryRequest*)request;
65                         std::string rx = rfr->GetRegex();
66                         rfr->result = new GlobRegex(rx);
67                         return "OK";
68                 }
69                 return NULL;
70         }
71 };
72
73 MODULE_INIT(ModuleRegexGlob)