]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_regex_glob.cpp
8d7eaafc3b2cda9ab2c05f5401efe9d015891dfa
[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, InspIRCd* Me) : Regex(rx, Me)
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(InspIRCd* Me) : Module(Me)
41         {
42                 Me->Modules->PublishInterface("RegularExpression", this);
43                 Implementation eventlist[] = { I_OnRequest };
44                 Me->Modules->Attach(eventlist, this, 1);
45         }
46
47         virtual Version GetVersion()
48         {
49                 return Version("Regex module using plain wildcard matching.", VF_COMMON | VF_VENDOR | VF_SERVICEPROVIDER, API_VERSION);
50         }
51
52         virtual ~ModuleRegexGlob()
53         {
54                 ServerInstance->Modules->UnpublishInterface("RegularExpression", this);
55         }
56
57         virtual const char* OnRequest(Request* request)
58         {
59                 if (strcmp("REGEX-NAME", request->GetId()) == 0)
60                 {
61                         return "glob";
62                 }
63                 else if (strcmp("REGEX", request->GetId()) == 0)
64                 {
65                         RegexFactoryRequest* rfr = (RegexFactoryRequest*)request;
66                         std::string rx = rfr->GetRegex();
67                         rfr->result = (Regex*)new GlobRegex(rx, ServerInstance);
68                         return "OK";
69                 }
70                 return NULL;
71         }
72 };
73
74 MODULE_INIT(ModuleRegexGlob)