-/* +------------------------------------+
- * | Inspire Internet Relay Chat Daemon |
- * +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
*
- * InspIRCd: (C) 2002-2009 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
*
- * This program is free but copyrighted software; see
- * the file COPYING for details.
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
*
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
#include "inspircd.h"
#include "m_regex.h"
#include <sys/types.h>
{
public:
POSIXRegexException(const std::string& rx, const std::string& error)
- : ModuleException(std::string("Error in regex ") + rx + ": " + error)
+ : ModuleException("Error in regex " + rx + ": " + error)
{
}
};
regex_t regbuf;
public:
- POSIXRegex(const std::string& rx, InspIRCd* Me, bool extended) : Regex(rx, Me)
+ POSIXRegex(const std::string& rx, bool extended) : Regex(rx)
{
int flags = (extended ? REG_EXTENDED : 0) | REG_NOSUB;
int errcode;
}
};
-class ModuleRegexPOSIX : public Module
+class PosixFactory : public RegexFactory
{
-private:
+ public:
bool extended;
-public:
- ModuleRegexPOSIX(InspIRCd* Me) : Module(Me)
+ PosixFactory(Module* m) : RegexFactory(m, "regex/posix") {}
+ Regex* Create(const std::string& expr)
{
- Me->Modules->PublishInterface("RegularExpression", this);
- Implementation eventlist[] = { I_OnRequest, I_OnRehash };
- Me->Modules->Attach(eventlist, this, 2);
- OnRehash(NULL, "");
- }
-
- virtual Version GetVersion()
- {
- return Version("$Id$", VF_COMMON | VF_VENDOR | VF_SERVICEPROVIDER, API_VERSION);
+ return new POSIXRegex(expr, extended);
}
+};
- virtual ~ModuleRegexPOSIX()
- {
- ServerInstance->Modules->UnpublishInterface("RegularExpression", this);
+class ModuleRegexPOSIX : public Module
+{
+ PosixFactory ref;
+public:
+ ModuleRegexPOSIX() : ref(this) {
+ ServerInstance->Modules->AddService(ref);
+ Implementation eventlist[] = { I_OnRehash };
+ ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
+ OnRehash(NULL);
}
- virtual void OnRehash(User* u, const std::string& parameter)
+ Version GetVersion()
{
- ConfigReader Conf(ServerInstance);
- extended = Conf.ReadFlag("posix", "extended", 0);
+ return Version("Regex Provider Module for POSIX Regular Expressions", VF_VENDOR);
}
- virtual const char* OnRequest(Request* request)
+ void OnRehash(User* u)
{
- if (strcmp("REGEX-NAME", request->GetId()) == 0)
- {
- return "posix";
- }
- else if (strcmp("REGEX", request->GetId()) == 0)
- {
- RegexFactoryRequest* rfr = (RegexFactoryRequest*)request;
- std::string rx = rfr->GetRegex();
- rfr->result = new POSIXRegex(rx, ServerInstance, extended);
- return "OK";
- }
- return NULL;
+ ref.extended = ServerInstance->Config->ConfValue("posix")->getBool("extended");
}
};