]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Allow modules to check if a user is on a callerid accept list.
authorPeter Powell <petpow@saberuk.com>
Sun, 9 Dec 2018 04:28:20 +0000 (04:28 +0000)
committerPeter Powell <petpow@saberuk.com>
Sun, 9 Dec 2018 04:28:20 +0000 (04:28 +0000)
include/modules/callerid.h [new file with mode: 0644]
src/modules/m_callerid.cpp

diff --git a/include/modules/callerid.h b/include/modules/callerid.h
new file mode 100644 (file)
index 0000000..ed03419
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2018 Peter Powell <petpow@saberuk.com>
+ *
+ * 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/>.
+ */
+
+
+#pragma once
+
+namespace CallerID
+{
+       class APIBase;
+       class API;
+}
+
+class CallerID::APIBase : public DataProvider
+{
+ public:
+       APIBase(Module* parent)
+               : DataProvider(parent, "m_callerid_api")
+       {
+       }
+
+       /** Determines whether \p source is on the accept list of \p target.
+        * @param source The user to search for in the accept list.
+        * @param target The user who's accept list to search in.
+        * @return True if \p source is on \p target's accept list; otherwise, false.
+        */
+       virtual bool IsOnAcceptList(User* source, User* target) = 0;
+};
+
+class CallerID::API : public dynamic_reference<CallerID::APIBase>
+{
+ public:
+       API(Module* parent)
+               : dynamic_reference<CallerID::APIBase>(parent, "m_callerid_api")
+       {
+       }
+};
index cdb10c04c79ebc197fed3d64a758582be5a8982a..40cbc3506f4f325fd5012f86ce71d8d16c829a7d 100644 (file)
@@ -21,6 +21,7 @@
 
 
 #include "inspircd.h"
+#include "modules/callerid.h"
 
 enum
 {
@@ -324,9 +325,30 @@ public:
        }
 };
 
+class CallerIDAPIImpl : public CallerID::APIBase
+{
+ private:
+       CallerIDExtInfo& ext;
+
+ public:
+       CallerIDAPIImpl(Module* Creator, CallerIDExtInfo& Ext)
+               : CallerID::APIBase(Creator)
+               , ext(Ext)
+       {
+       }
+
+       bool IsOnAcceptList(User* source, User* target) CXX11_OVERRIDE
+       {
+               callerid_data* dat = ext.get(target, true);
+               return dat->accepting.count(source);
+       }
+};
+
+
 class ModuleCallerID : public Module
 {
        CommandAccept cmd;
+       CallerIDAPIImpl api;
        SimpleUserModeHandler myumode;
 
        // Configuration variables:
@@ -359,6 +381,7 @@ class ModuleCallerID : public Module
 public:
        ModuleCallerID()
                : cmd(this)
+               , api(this, cmd.extInfo)
                , myumode(this, "callerid", 'g')
        {
        }