]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add XLineFactory stuff.
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 31 Oct 2007 19:03:28 +0000 (19:03 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 31 Oct 2007 19:03:28 +0000 (19:03 +0000)
The idea is, a module or the core can register a class derived from XLineFactory. This class's job is to handle creation of an 'unknown' xline type given xline-specific mask data
(e.g. "*@host*" or any other such text) and a line type, currently char (i DO plan on changing this!!!). This way, spanningtree and friends can create an xline without knowing
its full details just by passing what all xlines share in common and a bit of semi-opaque metadata.

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8436 e03df62e-2008-0410-955e-edbf42e46eb7

include/xline.h

index b8b045fd57318ac1fa5bc9c43b5faac1c50c7a72..a94161738814063d86d226f0e349d0bbea17c254 100644 (file)
@@ -343,6 +343,24 @@ class CoreExport QLine : public XLine
        char* nick;
 };
 
+class XLineFactory
+{
+ protected:
+
+       const char type;
+       InspIRCd* ServerInstance;
+
+ public:
+
+       XLineFactory(const char t) : type(t) { }
+       
+       virtual const char GetType() { return type; }
+
+       virtual XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask) = 0;
+
+       virtual ~XLineFactory() { }
+};
+
 /* Required forward declarations
  */
 class ServerConfig;
@@ -371,6 +389,8 @@ class CoreExport XLineManager
 
        std::vector<XLine *> active_lines;
 
+       std::map<char, XLineFactory*> line_factory;
+
  public:
 
        std::map<char, std::map<std::string, XLine *> > lookup_lines;
@@ -407,6 +427,26 @@ class CoreExport XLineManager
         */
        bool DelLine(const char* hostmask, char type, bool simulate = false);
 
+       /** Registers an xline factory.
+        * An xline factory is a class which when given a particular xline type,
+        * will generate a new XLine specialized to that type. For example if you
+        * pass the XLineFactory that handles glines some data it will return a
+        * pointer to a GLine, polymorphically represented as XLine. This is used where
+        * you do not know the full details of the item you wish to create, e.g. in a 
+        * server protocol module like m_spanningtree, when you receive xlines from other
+        * servers.
+        */
+       bool RegisterFactory(XLineFactory* xlf);
+
+       /** Unregisters an xline factory
+        */
+       bool UnregisterFactory(XLineFactory* xlf);
+
+       /** Get the XLineFactory for a specific type.
+        * Returns NULL if there is no known handler for this xline type
+        */
+       XLineFactory* GetFactory(const char type);
+
        /** Check if a nickname matches a QLine
         * @return nick The nick to check against
         * @return The reason for the line if there is a match, or NULL if there is no match