1
0
mirror of https://github.com/anope/anope.git synced 2026-07-04 13:33:13 +02:00

Burned slist, rewrote operservs XLine code

This commit is contained in:
Adam
2010-05-24 23:36:40 -05:00
committed by Adam
parent 3a2c2a916a
commit 2fba686904
72 changed files with 3346 additions and 3809 deletions
-3
View File
@@ -7,9 +7,6 @@ version.h: Makefile version.sh services.h $(SRCS)
services.h: sysconf.h config.h extern.h
touch $@
extern.h: slist.h
touch $@
clean:
(rm -f language.h)
+1 -1
View File
@@ -161,7 +161,7 @@ class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag>
/* Unsaved data */
time_t lastmail; /* Last time this nick record got a mail */
SList aliases; /* List of aliases */
std::list<NickAlias *> aliases; /* List of aliases */
/** Check whether this opertype has access to run the given command string.
* @param cmdstr The string to check, e.g. botserv/set/private.
+8 -8
View File
@@ -623,16 +623,16 @@ class ServerConfig
time_t AutokillExpiry;
/* Default expiry time for chan kills */
time_t ChankillExpiry;
/* Default expiry time for SGLine Expire */
time_t SGLineExpiry;
/* Default expiry time for SNLine Expire */
time_t SNLineExpiry;
/* Default expiry time for SQLines */
time_t SQLineExpiry;
/* Default expiry time for SZLine */
time_t SZLineExpiry;
/* Actually akill the user when the akill is added */
bool AkillOnAdd;
/* Kill users on SGline */
bool KillonSGline;
/* Kill users on SNLine */
bool KillonSNline;
/* Kill users on SQline */
bool KillonSQline;
/* Send a WALLOPS/GLOBOPS when a user opers */
@@ -649,8 +649,8 @@ class ServerConfig
bool WallOSKick;
/* Send a WALLOPS/GLOBOPS when someone uses the AKILL command */
bool WallOSAkill;
/* Send a WALLOPS/GLOBOPS when someone uses the SGLINE command */
bool WallOSSGLine;
/* Send a WALLOPS/GLOBOPS when someone uses the SNLINE command */
bool WallOSSNLine;
/* Send a WALLOPS/GLOBOPS when someone uses the SQLINE command */
bool WallOSSQLine;
/* Send a WALLOPS/GLOBOPS when someone uses the SZLINE command */
@@ -661,8 +661,8 @@ class ServerConfig
bool WallOSJupe;
/* Send a WALLOPS/GLOBOPS when an akill expires */
bool WallAkillExpire;
/* Send a WALLOPS/GLOBOPS when SGLines expire */
bool WallSGLineExpire;
/* Send a WALLOPS/GLOBOPS when SNLines expire */
bool WallSNLineExpire;
/* Send a WALLOPS/GLOBOPS when SQLines expire */
bool WallSQLineExpire;
/* Send a WALLOPS/GLOBOPS when SZLines expire */
-59
View File
@@ -17,7 +17,6 @@
#define E extern CoreExport
#define EI extern DllExport
#include "slist.h"
#include "hashcomp.h"
E void ModuleRunTimeDirCleanUp();
@@ -33,7 +32,6 @@ E IRCDProto *ircdproto;
E void kill_user(const std::string &source, const std::string &user, const std::string &reason);
E bool bad_password(User *u);
E void sqline(const std::string &mask, const std::string &reason);
E void common_unban(ChannelInfo *ci, const std::string &nick);
E BotInfo *BotServ;
@@ -372,50 +370,6 @@ E NickCore *findcore(const std::string &nick);
E NickCore *findcore(const ci::string &nick);
E bool is_on_access(User *u, NickCore *nc);
/**** operserv.c ****/
E SList akills, sglines, sqlines, szlines;
E int DefConModesSet;
E Flags<ChannelModeName> DefConModesOn;
E Flags<ChannelModeName> DefConModesOff;
E std::map<ChannelModeName, std::string> DefConModesOnParams;
E bool SetDefConParam(ChannelModeName, std::string &);
E bool GetDefConParam(ChannelModeName, std::string *);
E void UnsetDefConParam(ChannelModeName);
E void operserv(User *u, char *buf);
E void os_init();
E int add_akill(User *u, const char *mask, const char *by, const time_t expires, const char *reason);
E int check_akill(const char *nick, const char *username, const char *host, const char *vhost, const char *ip);
E void expire_akills();
E void oper_global(char *nick, const char *fmt, ...);
E int add_sgline(User *u, const char *mask, const char *by, time_t expires, const char *reason);
E int check_sgline(const char *nick, const char *realname);
E void expire_sglines();
E int add_sqline(User *u, const char *mask, const char *by, time_t expires, const char *reason);
E int check_sqline(const char *nick, int nick_change);
E void expire_sqlines();
E int check_chan_sqline(const char *chan);
E int add_szline(User * u, const char *mask, const char *by,
time_t expires, const char *reason);
E void expire_szlines();
E int check_szline(const char *nick, char *ip);
E void server_global(Server *s, const std::string &message);
E std::vector<NewsItem *> News;
E bool CheckDefCon(DefconLevel Level);
E bool CheckDefCon(int level, DefconLevel Level);
E void AddDefCon(int level, DefconLevel Level);
E void DelDefCon(int level, DefconLevel Level);
E std::vector<std::bitset<32> > DefCon;
/**** process.c ****/
E int allow_ignore;
@@ -463,19 +417,6 @@ E int exception_add(User * u, const char *mask, const int limit,
const char *reason, const char *who,
const time_t expires);
/**** slist.c ****/
E int slist_add(SList *slist, void *item);
E void slist_clear(SList *slist, int free);
E int slist_delete(SList *slist, int index);
E int slist_delete_range(SList *slist, const char *range, slist_delcheckcb_t cb, ...);
E int slist_enum(SList *slist, const char *range, slist_enumcb_t cb, ...);
E int slist_full(SList *slist);
E int slist_indexof(SList *slist, void *item);
E void slist_init(SList *slist);
E void slist_pack(SList *slist);
E int slist_remove(SList *slist, void *item);
E int slist_setcapacity(SList *slist, int16 capacity);
/**** sockets.cpp ****/
E SocketEngine socketEngine;
E int32 TotalRead;
+13 -13
View File
@@ -713,13 +713,13 @@ class CoreExport Module
* @param ak The akill
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
virtual EventReturn OnAddAkill(User *u, Akill *ak) { return EVENT_CONTINUE; }
virtual EventReturn OnAddAkill(User *u, XLine *ak) { return EVENT_CONTINUE; }
/** Called before an akill is deleted
* @param u The user removing the akill
* @param ak The akill, can be NULL for all akills!
*/
virtual void OnDelAkill(User *u, Akill *ak) { }
virtual void OnDelAkill(User *u, XLine *ak) { }
/** Called after an exception has been added
* @param u The user who added it
@@ -734,20 +734,20 @@ class CoreExport Module
*/
virtual void OnExceptionDel(User *u, Exception *ex) { }
/** Called before a SXLine is added
* @param u The user adding the SXLine
* @param sx The SXLine
* @param Type The type of SXLine this is
/** Called before a XLine is added
* @param u The user adding the XLine
* @param sx The XLine
* @param Type The type of XLine this is
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
virtual EventReturn OnAddSXLine(User *u, SXLine *sx, SXLineType Type) { return EVENT_CONTINUE; }
virtual EventReturn OnAddXLine(User *u, XLine *x, XLineType Type) { return EVENT_CONTINUE; }
/** Called before a SXLine is deleted
* @param u The user deleting the SXLine
* @param sx The SXLine, can be NULL for all SXLines
* @param Type The type of SXLine this is
/** Called before a XLine is deleted
* @param u The user deleting the XLine
* @param sx The XLine, can be NULL for all XLines
* @param Type The type of XLine this is
*/
virtual void OnDelSXLine(User *u, SXLine *sx, SXLineType Type) { }
virtual void OnDelXLine(User *u, XLine *x, XLineType Type) { }
/** Called when a server quits
* @param server The server
@@ -1118,7 +1118,7 @@ enum Implementation
/* OperServ */
I_OnOperServHelp, I_OnDefconLevel, I_OnAddAkill, I_OnDelAkill, I_OnExceptionAdd, I_OnExceptionDel,
I_OnAddSXLine, I_OnDelSXLine,
I_OnAddXLine, I_OnDelXLine,
/* Database */
I_OnPostLoadDatabases, I_OnSaveDatabase, I_OnLoadDatabase,
+231
View File
@@ -0,0 +1,231 @@
/* OperServ support
*
* (C) 2008-2010 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
* $Id$
*
*/
extern CoreExport std::vector<NewsItem *> News;
extern CoreExport std::vector<std::bitset<32> > DefCon;
extern CoreExport bool DefConModesSet;
extern CoreExport Flags<ChannelModeName> DefConModesOn;
extern CoreExport Flags<ChannelModeName> DefConModesOff;
extern CoreExport std::map<ChannelModeName, std::string> DefConModesOnParams;
class XLineManager;
extern CoreExport XLineManager *SGLine;
extern CoreExport XLineManager *SZLine;
extern CoreExport XLineManager *SQLine;
extern CoreExport XLineManager *SNLine;
extern CoreExport bool SetDefConParam(ChannelModeName, std::string &);
extern CoreExport bool GetDefConParam(ChannelModeName, std::string &);
extern CoreExport void UnsetDefConParam(ChannelModeName);
extern CoreExport bool CheckDefCon(DefconLevel Level);
extern CoreExport bool CheckDefCon(int level, DefconLevel Level);
extern CoreExport void AddDefCon(int level, DefconLevel Level);
extern CoreExport void DelDefCon(int level, DefconLevel Level);
extern CoreExport void operserv(User *u, char *buf);
extern CoreExport void os_init();
extern CoreExport void oper_global(char *nick, const char *fmt, ...);
extern CoreExport void server_global(Server *s, const std::string &message);
enum XLineType
{
X_SNLINE,
X_SQLINE,
X_SZLINE
};
struct XLine
{
ci::string Mask;
ci::string By;
time_t Created;
time_t Expires;
std::string Reason;
XLine(const ci::string &mask, const std::string &reason = "");
XLine(const ci::string &mask, const ci::string &by, const time_t expires, const std::string &reason);
ci::string GetNick() const;
ci::string GetUser() const;
ci::string GetHost() const;
};
class CoreExport XLineManager
{
private:
/* List of XLine managers we check users against in XLineManager::CheckAll */
static std::list<XLineManager *> XLineManagers;
protected:
/* List of XLines in this XLineManager */
std::deque<XLine *> XLines;
public:
/** Constructor
*/
XLineManager();
/** Destructor
*/
virtual ~XLineManager();
/** Register a XLineManager, places it in XLineManagers for use in XLineManager::CheckAll
* It is important XLineManagers are registered in the proper order. Eg, if you had one akilling
* clients and one handing them free olines, you would want the akilling one first. This way if a client
* matches an entry on both of the XLineManagers, they would be akilled.
* @param xlm THe XLineManager
*/
static void RegisterXLineManager(XLineManager *xlm);
/** Unregister a XLineManager
* @param xlm The XLineManager
*/
static void UnregisterXLineManager(XLineManager *xlm);
/** Check a user against all known XLineManagers
* Wparam u The user
* @return A pair of the XLineManager the user was found in and the XLine they matched, both may be NULL for no match
*/
static std::pair<XLineManager *, XLine *> CheckAll(User *u);
/** Get the number of XLines in this XLineManager
* @return The number of XLines
*/
const size_t GetCount() const;
/** Get the XLine list
* @return The list
*/
const std::deque<XLine *>& GetList() const;
/** Add an entry to this XLineManager
* @param x The entry
*/
void AddXLine(XLine *x);
/** Delete an entry from this XLineManager
* @param x The entry
* @return true if the entry was found and deleted, else false
*/
bool DelXLine(XLine *x);
/** Gets an entry by index
* @param index The index
* @return The XLine, or NULL if the index is out of bounds
*/
XLine *GetEntry(unsigned index) const;
/** Clear the XLine list
*/
void Clear();
/** Add an entry to this XLine Manager
* @param bi The bot error replies should be sent from
* @param u The user adding the XLine
* @param mask The mask of the XLine
* @param expires When this should expire
* @param reaosn The reason
* @return A pointer to the XLine
*/
virtual XLine *Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason);
/** Delete an XLine, eg, remove it from the IRCd.
* @param x The xline
*/
virtual void Del(XLine *x);
/** Checks if a mask can/should be added to the XLineManager
* @param mask The mask
* @param expires When the mask would expire
* @return A pair of int and XLine*.
* 1 - Mask already exists
* 2 - Mask already exists, but the expiry time was changed
* 3 - Mask is already covered by another mask
* In each case the XLine it matches/is covered by is returned in XLine*
*/
std::pair<int, XLine *> CanAdd(const ci::string &mask, time_t expires);
/** Checks if this list has an entry
* @param mask The mask
* @return The XLine the user matches, or NULL
*/
XLine *HasEntry(const ci::string &mask) const;
/** Check a user against all of the xlines in this XLineManager
* @param u The user
* @return The xline the user marches, if any. Also calls OnMatch()
*/
virtual XLine *Check(User *u);
/** Called when a user matches a xline in this XLineManager
* @param u The user
* @param x The XLine they match
*/
virtual void OnMatch(User *u, XLine *x);
/** Called when an XLine expires
* @param x The xline
*/
virtual void OnExpire(XLine *x);
};
/* This is for AKILLS */
class SGLineManager : public XLineManager
{
public:
XLine *Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason);
void Del(XLine *x);
void OnMatch(User *u, XLine *x);
void OnExpire(XLine *x);
};
class SNLineManager : public XLineManager
{
public:
XLine *Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason);
void Del(XLine *x);
void OnMatch(User *u, XLine *x);
void OnExpire(XLine *x);
};
class SQLineManager : public XLineManager
{
public:
XLine *Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason);
void Del(XLine *x);
void OnMatch(User *u, XLine *x);
void OnExpire(XLine *x);
static bool Check(Channel *c);
};
class SZLineManager : public XLineManager
{
public:
XLine *Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason);
void Del(XLine *x);
void OnMatch(User *u, XLine *x);
void OnExpire(XLine *x);
};
+25 -46
View File
@@ -202,7 +202,6 @@ extern int strncasecmp(const char *, const char *, size_t);
/* Miscellaneous definitions. */
#include "hashcomp.h"
#include "slist.h"
/* Pull in the various bits of STL */
#include <iostream>
@@ -359,7 +358,6 @@ struct Session;
typedef struct bandata_ BanData;
typedef struct mailinfo_ MailInfo;
typedef struct akill_ Akill;
typedef struct exception_ Exception;
#include "extensible.h"
@@ -381,7 +379,7 @@ struct ircdvars_ {
const char *botchanumode; /* Modes set when botserv joins a channel */
int svsnick; /* Supports SVSNICK */
int vhost; /* Supports vhost */
int sgline; /* Supports SGline */
int snline; /* Supports SNline */
int sqline; /* Supports SQline */
int szline; /* Supports SZline */
int numservargs; /* Number of Server Args */
@@ -780,39 +778,6 @@ struct mailinfo_ {
/*************************************************************************/
struct akill_ {
char *user; /* User part of the AKILL */
char *host; /* Host part of the AKILL */
char *by; /* Who set the akill */
char *reason; /* Why they got akilled */
time_t seton; /* When it was set */
time_t expires; /* When it expires */
};
/*************************************************************************/
/* Structure for OperServ SGLINE and SZLINE commands */
enum SXLineType
{
SX_SGLINE,
SX_SQLINE,
SX_SZLINE
};
struct SXLine {
char *mask;
char *by;
char *reason;
time_t seton;
time_t expires;
};
/************************************************************************/
struct exception_ {
char *mask; /* Hosts to which this exception applies */
int limit; /* Session limit for exception */
@@ -906,6 +871,7 @@ struct Uplink;
class ServerConfig;
#include "extern.h"
#include "operserv.h"
#include "mail.h"
#include "servers.h"
#include "config.h"
@@ -933,8 +899,8 @@ class CoreExport IRCDProto
virtual void SendSVSNOOP(const char *, int) { }
virtual void SendTopic(BotInfo *, Channel *, const char *, const char *) = 0;
virtual void SendVhostDel(User *) { }
virtual void SendAkill(Akill *) = 0;
virtual void SendAkillDel(Akill *) = 0;
virtual void SendAkill(XLine *) = 0;
virtual void SendAkillDel(XLine *) = 0;
virtual void SendSVSKill(BotInfo *source, User *user, const char *fmt, ...);
virtual void SendSVSMode(User *, int, const char **) = 0;
virtual void SendMode(BotInfo *bi, Channel *dest, const char *fmt, ...);
@@ -959,11 +925,11 @@ class CoreExport IRCDProto
virtual void SendPing(const char *servname, const char *who);
virtual void SendPong(const char *servname, const char *who);
virtual void SendJoin(BotInfo *bi, const char *, time_t) = 0;
virtual void SendSQLineDel(const std::string &) = 0;
virtual void SendSQLineDel(XLine *x) = 0;
virtual void SendInvite(BotInfo *bi, const char *chan, const char *nick);
virtual void SendPart(BotInfo *bi, Channel *chan, const char *fmt, ...);
virtual void SendGlobops(BotInfo *source, const char *fmt, ...);
virtual void SendSQLine(const std::string &, const std::string &) = 0;
virtual void SendSQLine(XLine *x) = 0;
virtual void SendSquit(const char *servname, const char *message);
virtual void SendSVSO(const char *, const char *, const char *) { }
virtual void SendChangeBotNick(BotInfo *bi, const char *newnick);
@@ -972,10 +938,10 @@ class CoreExport IRCDProto
virtual void SendConnect() = 0;
virtual void SendSVSHold(const char *) { }
virtual void SendSVSHoldDel(const char *) { }
virtual void SendSGLineDel(SXLine *) { }
virtual void SendSZLineDel(SXLine *) { }
virtual void SendSZLine(SXLine *) { }
virtual void SendSGLine(SXLine *) { }
virtual void SendSGLineDel(XLine *) { }
virtual void SendSZLineDel(XLine *) { }
virtual void SendSZLine(XLine *) { }
virtual void SendSGLine(XLine *) { }
virtual void SendBanDel(Channel *, const std::string &) { }
virtual void SendSVSModeChan(Channel *, const char *, const char *) { }
virtual void SendUnregisteredNick(User *) { }
@@ -1064,8 +1030,8 @@ class CoreExport Anope
{
public:
/** Check whether two strings match.
* @param mask The pattern to check (e.g. foo*bar)
* @param str The string to check against the pattern (e.g. foobar)
* @param mask The pattern to check (e.g. foo*bar)
* @param case_sensitive Whether or not the match is case sensitive, default false.
*/
static bool Match(const std::string &str, const std::string &mask, bool case_sensitive = false);
@@ -1162,7 +1128,7 @@ class ChanServTimer : public Timer
void Tick(time_t);
};
/** A class to process numbered lists (passed to most DEL commands).
/** A class to process numbered lists (passed to most DEL/LIST/VIEW commands).
* The function HandleNumber is called for every number in the list. Note that
* it *always* gets called in descending order. This is so deleting the index passed
* to the function from an array will not cause the other indexes passed to the function
@@ -1178,12 +1144,25 @@ class NumberList
*/
NumberList(const std::string &list);
/** Destructor, does nothing
*/
virtual ~NumberList();
/** Should be called after the constructors are done running. This calls the callbacks.
*/
void Process();
/** Called with a number from the list
* @param Number The number
*/
virtual void HandleNumber(unsigned Number);
/** Called when there is an error with the numbered list
* Return false to immediatly stop processing the list and return
* This is all done before we start calling HandleNumber, so no numbers will have been processed yet
* @param The list
* @return false to stop processing
*/
virtual bool InvalidRange(const std::string &list);
};
-49
View File
@@ -1,49 +0,0 @@
/* Header for Services list handler.
*
* (C) 2003-2010 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for furhter details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*
*
*/
#ifndef SLIST_H
#define SLIST_H
typedef struct slist_ SList;
typedef struct slistopts_ SListOpts;
struct slist_ {
void **list;
int16 count; /* Total entries of the list */
int16 capacity; /* Capacity of the list */
int16 limit; /* Maximum possible entries on the list */
SListOpts *opts;
};
struct slistopts_ {
int32 flags; /* Flags for the list. See below. */
int (*compareitem) (SList *slist, void *item1, void *item2); /* Called to compare two items */
int (*isequal) (SList *slist, void *item1, void *item2); /* Called by slist_indexof. item1 can be an arbitrary pointer. */
void (*freeitem) (SList *slist, void *item); /* Called when an item is removed */
};
#define SLIST_DEFAULT_LIMIT 32767
#define SLISTF_NODUP 0x00000001 /* No duplicates in the list. */
#define SLISTF_SORT 0x00000002 /* Automatically sort the list. Used with compareitem member. */
/* Note that number is the index in the array + 1 */
typedef int (*slist_enumcb_t) (SList *slist, int number, void *item, va_list args);
/* Callback to know whether we can delete the entry. */
typedef int (*slist_delcheckcb_t) (SList *slist, void *item, va_list args);
#endif /* SLIST_H */