*/
class CoreExport XLine : public classbase
{
- public:
+ protected:
+
+ InspIRCd* ServerInstance;
+ void DefaultApply(User* u, char line);
+
+ public:
/** Create an XLine.
* @param s_time The set time
* @param src The sender of the xline
* @param re The reason of the xline
*/
- XLine(time_t s_time, long d, const char* src, const char* re)
- : set_time(s_time), duration(d)
+ XLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char t)
+ : ServerInstance(Instance), set_time(s_time), duration(d), type(t)
{
source = strdup(src);
reason = strdup(re);
free(reason);
free(source);
}
+
+ /** Returns true whether or not the given user is covered by this line.
+ */
+ virtual bool Matches(User *u) = 0;
+
+ /** Returns true wether or not the given string exactly matches the gline
+ * (no wildcard use in this method) -- used for removal of a line
+ */
+ virtual bool MatchesLiteral(const std::string &str) = 0;
+
+ virtual bool Matches(const std::string &str) = 0;
+
+ virtual void Apply(User* u);
+
+ virtual void Unset() { }
+
+ virtual void DisplayExpiry() = 0;
+
+ virtual const char* Displayable() = 0;
+
+ virtual void OnAdd() { }
+
/** The time the line was added.
*/
time_t set_time;
/** Expiry time
*/
time_t expiry;
+
+ /** Q, K, etc. Don't change this. Constructors set it.
+ */
+ const char type;
};
/** KLine class
* @param ident Ident to match
* @param host Host to match
*/
- KLine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
+ KLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(Instance, s_time, d, src, re, 'K')
{
identmask = strdup(ident);
hostmask = strdup(host);
+ matchtext = this->identmask;
+ matchtext.append("@").append(this->hostmask);
}
/** Destructor
free(hostmask);
}
+ virtual bool Matches(User *u);
+
+ virtual bool Matches(const std::string &str);
+
+ virtual bool MatchesLiteral(const std::string &str);
+
+ virtual void Apply(User* u);
+
+ virtual void DisplayExpiry();
+
+ virtual const char* Displayable();
+
/** Ident mask
*/
char* identmask;
/** Host mask
*/
char* hostmask;
+
+ std::string matchtext;
};
/** GLine class
* @param ident Ident to match
* @param host Host to match
*/
- GLine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
+ GLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(Instance, s_time, d, src, re, 'G')
{
identmask = strdup(ident);
hostmask = strdup(host);
+ matchtext = this->identmask;
+ matchtext.append("@").append(this->hostmask);
}
/** Destructor
free(hostmask);
}
+ virtual bool Matches(User *u);
+
+ virtual bool Matches(const std::string &str);
+
+ virtual bool MatchesLiteral(const std::string &str);
+
+ virtual void Apply(User* u);
+
+ virtual void DisplayExpiry();
+
+ virtual const char* Displayable();
+
/** Ident mask
*/
char* identmask;
/** Host mask
*/
char* hostmask;
+
+ std::string matchtext;
};
/** ELine class
* @param ident Ident to match
* @param host Host to match
*/
- ELine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
+ ELine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(Instance, s_time, d, src, re, 'E')
{
identmask = strdup(ident);
hostmask = strdup(host);
+ matchtext = this->identmask;
+ matchtext.append("@").append(this->hostmask);
}
~ELine()
free(hostmask);
}
+ virtual bool Matches(User *u);
+
+ virtual bool Matches(const std::string &str);
+
+ virtual bool MatchesLiteral(const std::string &str);
+
+ virtual void Unset();
+
+ virtual void DisplayExpiry();
+
+ virtual void OnAdd();
+
+ virtual const char* Displayable();
+
/** Ident mask
*/
char* identmask;
/** Host mask
*/
char* hostmask;
+
+ std::string matchtext;
};
/** ZLine class
* @param re The reason of the xline
* @param ip IP to match
*/
- ZLine(time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(s_time, d, src, re)
+ ZLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(Instance, s_time, d, src, re, 'Z')
{
ipaddr = strdup(ip);
}
free(ipaddr);
}
+ virtual bool Matches(User *u);
+
+ virtual bool Matches(const std::string &str);
+
+ virtual bool MatchesLiteral(const std::string &str);
+
+ virtual void Apply(User* u);
+
+ virtual void DisplayExpiry();
+
+ virtual const char* Displayable();
+
/** IP mask
*/
char* ipaddr;
* @param re The reason of the xline
* @param nickname Nickname to match
*/
- QLine(time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(s_time, d, src, re)
+ QLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(Instance, s_time, d, src, re, 'Q')
{
nick = strdup(nickname);
}
~QLine()
{
free(nick);
+
}
+ virtual bool Matches(User *u);
+
+ virtual bool Matches(const std::string &str);
+
+ virtual bool MatchesLiteral(const std::string &str);
+
+ virtual void Apply(User* u);
+
+ virtual void DisplayExpiry();
+
+ virtual const char* Displayable();
/** Nickname mask
*/
char* nick;
};
-/* Required forward declarations
+/** Contains an ident and host split into two strings
*/
-class ServerConfig;
-class InspIRCd;
+typedef std::pair<std::string, std::string> IdentHostPair;
-/** Initialize x line
- */
-bool InitXLine(ServerConfig* conf, const char* tag);
-/** Done adding zlines from the config
- */
-bool DoneZLine(ServerConfig* conf, const char* tag);
-/** Done adding qlines from the config
- */
-bool DoneQLine(ServerConfig* conf, const char* tag);
-/** Done adding klines from the config
- */
-bool DoneKLine(ServerConfig* conf, const char* tag);
-/** Done adding elines from the config
- */
-bool DoneELine(ServerConfig* conf, const char* tag);
+class CoreExport XLineFactory
+{
+ protected:
-/** Add a config-defined zline
- */
-bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
-/** Add a config-defined qline
- */
-bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
-/** Add a config-defined kline
- */
-bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
-/** Add a config-defined eline
- */
-bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
+ InspIRCd* ServerInstance;
+ const char type;
-/** Contains an ident and host split into two strings
+ public:
+
+ XLineFactory(InspIRCd* Instance, const char t) : ServerInstance(Instance), 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
*/
-typedef std::pair<std::string, std::string> IdentHostPair;
+class ServerConfig;
+class InspIRCd;
+
+class GLineFactory;
+class ELineFactory;
+class QLineFactory;
+class ZLineFactory;
+class KLineFactory;
/** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
*/
*/
InspIRCd* ServerInstance;
- /** This functor is used by the std::sort() function to keep glines in order
- */
- static bool GSortComparison ( const GLine* one, const GLine* two );
-
- /** This functor is used by the std::sort() function to keep elines in order
- */
- static bool ESortComparison ( const ELine* one, const ELine* two );
-
- /** This functor is used by the std::sort() function to keep zlines in order
+ /** This functor is used by the std::sort() function to keep all lines in order
*/
- static bool ZSortComparison ( const ZLine* one, const ZLine* two );
+ static bool XSortComparison (const XLine *one, const XLine *two);
- /** This functor is used by the std::sort() function to keep klines in order
+ /** Used to hold XLines which have not yet been applied.
*/
- static bool KSortComparison ( const KLine* one, const KLine* two );
-
- /** This functor is used by the std::sort() function to keep qlines in order
- */
- static bool QSortComparison ( const QLine* one, const QLine* two );
- public:
- /* Lists for temporary lines with an expiry time */
-
- /** Temporary KLines */
- std::vector<KLine*> klines;
-
- /** Temporary Glines */
- std::vector<GLine*> glines;
+ std::vector<XLine *> pending_lines;
- /** Temporary Zlines */
- std::vector<ZLine*> zlines;
+ std::vector<XLine *> active_lines;
- /** Temporary QLines */
- std::vector<QLine*> qlines;
+ std::map<char, XLineFactory*> line_factory;
- /** Temporary ELines */
- std::vector<ELine*> elines;
+ GLineFactory* GFact;
+ ELineFactory* EFact;
+ KLineFactory* KFact;
+ QLineFactory* QFact;
+ ZLineFactory* ZFact;
- /* Seperate lists for perm XLines that isnt checked by expiry functions */
+ unsigned int PermLines;
- /** Permenant KLines */
- std::vector<KLine*> pklines;
-
- /** Permenant GLines */
- std::vector<GLine*> pglines;
-
- /** Permenant ZLines */
- std::vector<ZLine*> pzlines;
+ public:
- /** Permenant QLines */
- std::vector<QLine*> pqlines;
+ std::map<char, std::map<std::string, XLine *> > lookup_lines;
- /** Permenant ELines */
- std::vector<ELine*> pelines;
-
/** Constructor
* @param Instance A pointer to the creator object
*/
XLineManager(InspIRCd* Instance);
+ ~XLineManager();
+
/** Split an ident and host into two seperate strings.
* This allows for faster matching.
*/
IdentHostPair IdentSplit(const std::string &ident_and_host);
- /** Add a new GLine
- * @param duration The duration of the line
- * @param source The source of the line
- * @param reason The reason for the line
- * @param hostmask The hostmask
- * @return True if the line was added successfully
- */
- bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
-
- /** Add a new QLine
- * @param duration The duration of the line
- * @param source The source of the line
- * @param reason The reason for the line
- * @param nickname The nickmask
- * @return True if the line was added successfully
+ /** Checks what users match a given list of ELines and sets their ban exempt flag accordingly.
+ * @param ELines List of E:Lines to check.
*/
- bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
+ void CheckELines(std::map<std::string, XLine *> &ELines);
- /** Add a new ZLine
- * @param duration The duration of the line
- * @param source The source of the line
- * @param reason The reason for the line
- * @param ipaddr The IP mask
- * @return True if the line was added successfully
- */
- bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
-
- /** Add a new KLine
- * @param duration The duration of the line
- * @param source The source of the line
- * @param reason The reason for the line
- * @param hostmask The hostmask
- * @return True if the line was added successfully
- */
- bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
-
- /** Add a new ELine
- * @param duration The duration of the line
- * @param source The source of the line
- * @param reason The reason for the line
- * @param hostmask The hostmask
+ /** Add a new GLine
+ * @param line The line to be added
+ * @param user The user adding the line or NULL for the local server
* @return True if the line was added successfully
*/
- bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
+ bool AddLine(XLine* line, User* user);
/** Delete a GLine
- * @param hostmask The host to remove
- * @param simulate If this is true, don't actually remove the line, just return
- * @return True if the line was deleted successfully
- */
- bool del_gline(const char* hostmask, bool simulate = false);
-
- /** Delete a QLine
- * @param nickname The nick to remove
+ * @param hostmask The xline-specific string identifying the line, e.g. "*@foo"
+ * @param type The type of xline
+ * @param user The user removing the line or NULL if its the local server
* @param simulate If this is true, don't actually remove the line, just return
* @return True if the line was deleted successfully
*/
- bool del_qline(const char* nickname, bool simulate = false);
+ bool DelLine(const char* hostmask, char type, User* user, bool simulate = false);
- /** Delete a ZLine
- * @param ipaddr The IP to remove
- * @param simulate If this is true, don't actually remove the line, just return
- * @return True if the line was deleted successfully
+ /** 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 del_zline(const char* ipaddr, bool simulate = false);
+ bool RegisterFactory(XLineFactory* xlf);
- /** Delete a KLine
- * @param hostmask The host to remove
- * @param simulate If this is true, don't actually remove the line, just return
- * @return True if the line was deleted successfully
+ /** Unregisters an xline factory
*/
- bool del_kline(const char* hostmask, bool simulate = false);
+ bool UnregisterFactory(XLineFactory* xlf);
- /** Delete a ELine
- * @param hostmask The host to remove
- * @param simulate If this is true, don't actually remove the line, just return
- * @return True if the line was deleted successfully
+ /** Get the XLineFactory for a specific type.
+ * Returns NULL if there is no known handler for this xline type
*/
- bool del_eline(const char* hostmask, bool simulate = false);
+ 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
*/
- QLine* matches_qline(const char* nick, bool permonly = false);
+ QLine* matches_qline(const char* nick);
/** Check if a hostname matches a GLine
* @param user The user to check against
* @return The reason for the line if there is a match, or NULL if there is no match
*/
- GLine* matches_gline(User* user, bool permonly = false);
+ GLine* matches_gline(User* user);
- /** Check if a IP matches a ZLine
- * @param ipaddr The IP to check against
+ /** Check if a user's IP matches a ZLine
+ * @param user The user to check against
* @return The reason for the line if there is a match, or NULL if there is no match
*/
- ZLine* matches_zline(const char* ipaddr, bool permonly = false);
+ ZLine* matches_zline(User *user);
/** Check if a hostname matches a KLine
* @param user The user to check against
* @return The reason for the line if there is a match, or NULL if there is no match
*/
- KLine* matches_kline(User* user, bool permonly = false);
+ KLine* matches_kline(User* user);
/** Check if a hostname matches a ELine
* @param user The user to check against
* @return The reason for the line if there is a match, or NULL if there is no match
*/
- ELine* matches_exception(User* user, bool permonly = false);
+ ELine* matches_exception(User* user);
- /** Expire any pending non-permenant lines
+ /** Expire any lines that should be expired.
*/
void expire_lines();
- /** Apply any new lines
- * @param What The types of lines to apply, from the set
- * APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES | APPLY_ALL
- * | APPLY_LOCAL_ONLY
+ /** Apply any new lines that are pending to be applied
*/
- void apply_lines(const int What);
+ void ApplyLines();
- /** Handle /STATS K
+ /** Handle /STATS for a given type.
+ * @param numeric The numeric to give to each result line
* @param user The username making the query
* @param results The string_list to receive the results
*/
- void stats_k(User* user, string_list &results);
-
- /** Handle /STATS G
- * @param user The username making the query
- * @param results The string_list to receive the results
- */
- void stats_g(User* user, string_list &results);
-
- /** Handle /STATS Q
- * @param user The username making the query
- * @param results The string_list to receive the results
- */
- void stats_q(User* user, string_list &results);
-
- /** Handle /STATS Z
- * @param user The username making the query
- * @param results The string_list to receive the results
- */
- void stats_z(User* user, string_list &results);
+ void InvokeStats(const char type, int numeric, User* user, string_list &results);
/** Handle /STATS E
* @param user The username making the query
void eline_set_creation_time(const char* host, time_t create_time);
};
-#endif
+class CoreExport GLineFactory : public XLineFactory
+{
+ public:
+ GLineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'G') { }
+
+ XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+ {
+ IdentHostPair ih = ServerInstance->XLines->IdentSplit(xline_specific_mask);
+ return new GLine(ServerInstance, set_time, duration, source, reason, ih.first.c_str(), ih.second.c_str());
+ }
+};
+
+class CoreExport ELineFactory : public XLineFactory
+{
+ public:
+ ELineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'E') { }
+ XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+ {
+ IdentHostPair ih = ServerInstance->XLines->IdentSplit(xline_specific_mask);
+ return new ELine(ServerInstance, set_time, duration, source, reason, ih.first.c_str(), ih.second.c_str());
+ }
+};
+
+class CoreExport KLineFactory : public XLineFactory
+{
+ public:
+ KLineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'K') { }
+
+ XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+ {
+ IdentHostPair ih = ServerInstance->XLines->IdentSplit(xline_specific_mask);
+ return new KLine(ServerInstance, set_time, duration, source, reason, ih.first.c_str(), ih.second.c_str());
+ }
+};
+
+class CoreExport QLineFactory : public XLineFactory
+{
+ public:
+ QLineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'Q') { }
+
+ XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+ {
+ return new QLine(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
+ }
+};
+
+class CoreExport ZLineFactory : public XLineFactory
+{
+ public:
+ ZLineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'Z') { }
+
+ XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+ {
+ return new ZLine(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
+ }
+};
+
+#endif