-#include "inspstring.h"
-#include "helperfuncs.h"
-#include "hashcomp.h"
-
-extern int MODCOUNT;
-extern std::vector<Module*> modules;
-extern std::vector<ircd_module*> factory;
-
-extern int LogLevel;
-extern char ServerName[MAXBUF];
-extern char Network[MAXBUF];
-extern char ServerDesc[MAXBUF];
-extern char AdminName[MAXBUF];
-extern char AdminEmail[MAXBUF];
-extern char AdminNick[MAXBUF];
-extern char diepass[MAXBUF];
-extern char restartpass[MAXBUF];
-extern char motd[MAXBUF];
-extern char rules[MAXBUF];
-extern char list[MAXBUF];
-extern char PrefixQuit[MAXBUF];
-extern char DieValue[MAXBUF];
-
-extern int debugging;
-extern int WHOWAS_STALE;
-extern int WHOWAS_MAX;
-extern int DieDelay;
-extern time_t startup_time;
-extern int NetBufferSize;
-extern time_t nb_start;
-
-extern std::vector<std::string> module_names;
-
-extern int boundPortCount;
-extern int portCount;
-extern int SERVERportCount;
-extern int ports[MAXSOCKS];
-extern int defaultRoute;
-
-extern std::vector<long> auth_cookies;
-extern std::stringstream config_f;
-
-extern serverrec* me[32];
-
-extern FILE *log_file;
-
-typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, irc::StrHashComp> user_hash;
-typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, irc::StrHashComp> chan_hash;
-typedef nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, irc::InAddr_HashComp> address_cache;
-typedef nspace::hash_map<std::string, WhoWasUser*, nspace::hash<string>, irc::StrHashComp> whowas_hash;
-typedef std::deque<command_t> command_table;
-
-
-extern user_hash clientlist;
-extern chan_hash chanlist;
-extern whowas_hash whowas;
-extern command_table cmdlist;
-extern file_cache MOTD;
-extern file_cache RULES;
-extern address_cache IP;
-
-extern time_t TIME;
-
-std::vector<KLine> klines;
-std::vector<GLine> glines;
-std::vector<ZLine> zlines;
-std::vector<QLine> qlines;
-std::vector<ELine> elines;
-
-// Reads the default bans from the config file.
-// only a very small number of bans are defined
-// this way these days, such as qlines against
-// services nicks, etc.
-
-void read_xline_defaults()
-{
- char ipmask[MAXBUF];
- char nick[MAXBUF];
- char host[MAXBUF];
- char reason[MAXBUF];
-
- for (int i = 0; i < ConfValueEnum("badip",&config_f); i++)
- {
- ConfValue("badip","ipmask",i,ipmask,&config_f);
- ConfValue("badip","reason",i,reason,&config_f);
- add_zline(0,"<Config>",reason,ipmask);
- log(DEBUG,"Read Z line (badip tag): ipmask=%s reason=%s",ipmask,reason);
- }
-
- for (int i = 0; i < ConfValueEnum("badnick",&config_f); i++)
- {
- ConfValue("badnick","nick",i,nick,&config_f);
- ConfValue("badnick","reason",i,reason,&config_f);
- add_qline(0,"<Config>",reason,nick);
- log(DEBUG,"Read Q line (badnick tag): nick=%s reason=%s",nick,reason);
- }
-
- for (int i = 0; i < ConfValueEnum("badhost",&config_f); i++)
- {
- ConfValue("badhost","host",i,host,&config_f);
- ConfValue("badhost","reason",i,reason,&config_f);
- add_kline(0,"<Config>",reason,host);
- log(DEBUG,"Read K line (badhost tag): host=%s reason=%s",host,reason);
+
+/* Version two, now with optimized expiry!
+ *
+ * Because the old way was horrendously slow, the new way of expiring xlines is very
+ * very efficient. I have improved the efficiency of the algorithm in two ways:
+ *
+ * (1) There are now two lists of items for each linetype. One list holds temporary
+ * items, and the other list holds permanent items (ones which will expire).
+ * Items which are on the permanent list are NEVER checked at all by the
+ * expire_lines() function.
+ * (2) The temporary xline lists are always kept in strict numerical order, keyed by
+ * current time + duration. This means that the line which is due to expire the
+ * soonest is always pointed at by vector::begin(), so a simple while loop can
+ * very efficiently, very quickly and above all SAFELY pick off the first few
+ * items in the vector which need zapping.
+ *
+ * -- Brain
+ */
+
+bool InitXLine(ServerConfig* conf, const char* tag)
+{
+ return true;
+}
+
+bool DoneZLine(ServerConfig* conf, const char* tag)
+{
+ conf->GetInstance()->XLines->apply_lines(APPLY_ZLINES|APPLY_PERM_ONLY);
+ return true;
+}
+
+bool DoneQLine(ServerConfig* conf, const char* tag)
+{
+ conf->GetInstance()->XLines->apply_lines(APPLY_QLINES|APPLY_PERM_ONLY);
+ return true;
+}
+
+bool DoneKLine(ServerConfig* conf, const char* tag)
+{
+ conf->GetInstance()->XLines->apply_lines(APPLY_KLINES|APPLY_PERM_ONLY);
+ return true;
+}
+
+bool DoneELine(ServerConfig* conf, const char* tag)
+{
+ /* Yes, this is supposed to do nothing, we dont 'apply' these */
+ return true;
+}
+
+bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
+{
+ const char* reason = values[0].GetString();
+ const char* ipmask = values[1].GetString();
+
+ conf->GetInstance()->XLines->add_zline(0,"<Config>",reason,ipmask);
+ return true;
+}
+
+bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
+{
+ const char* reason = values[0].GetString();
+ const char* nick = values[1].GetString();
+
+ conf->GetInstance()->XLines->add_qline(0,"<Config>",reason,nick);
+ return true;
+}
+
+bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
+{
+ const char* reason = values[0].GetString();
+ const char* host = values[1].GetString();
+
+ conf->GetInstance()->XLines->add_kline(0,"<Config>",reason,host);
+ return true;
+}
+
+bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
+{
+ const char* reason = values[0].GetString();
+ const char* host = values[1].GetString();
+
+ conf->GetInstance()->XLines->add_eline(0,"<Config>",reason,host);
+ return true;
+}
+
+IdentHostPair XLineManager::IdentSplit(const std::string &ident_and_host)
+{
+ IdentHostPair n = std::make_pair<std::string,std::string>("*","*");
+ std::string::size_type x = ident_and_host.find('@');
+ if (x != std::string::npos)
+ {
+ n.second = ident_and_host.substr(x + 1,ident_and_host.length());
+ n.first = ident_and_host.substr(0, x);
+ if (!n.first.length())
+ n.first.assign("*");
+ if (!n.second.length())
+ n.second.assign("*");