diff options
| author | Adam <Adam@anope.org> | 2012-11-22 00:50:33 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2012-11-22 00:50:33 -0500 |
| commit | d33a0f75a5c0c584fbb7cc0076da36d494f39494 (patch) | |
| tree | 7b2274cc833c793c0f5595660cbd4d715de52ffd /include | |
| parent | 368d469631763e9c8bf399980d0ac7c5b5664d39 (diff) | |
Pretty large coding style cleanup, in source doc
cleanup, and allow protocol mods to depend on each
other
Diffstat (limited to 'include')
38 files changed, 1871 insertions, 1318 deletions
diff --git a/include/access.h b/include/access.h index 558dbeb5c..918dd7be6 100644 --- a/include/access.h +++ b/include/access.h @@ -8,7 +8,6 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. * - * */ #ifndef ACCESS_H @@ -25,19 +24,25 @@ enum ACCESS_FOUNDER = 10001 }; +/* A privilege, probably configured using a privilege{} block. Most + * commands require specific privileges to be executed. The AccessProvider + * backing each ChanAccess determines whether that ChanAccess has a given + * privilege. + */ struct CoreExport Privilege { Anope::string name; Anope::string desc; + /* Rank relative to other privileges */ int rank; - Privilege(const Anope::string &n, const Anope::string &d, int r); + Privilege(const Anope::string &name, const Anope::string &desc, int rank); bool operator==(const Privilege &other) const; }; class CoreExport PrivilegeManager { - static std::vector<Privilege> privs; + static std::vector<Privilege> Privileges; public: static void AddPrivilege(Privilege p); static void RemovePrivilege(Privilege &p); @@ -46,25 +51,34 @@ class CoreExport PrivilegeManager static void ClearPrivileges(); }; - +/* A provider of access. Only used for creating ChanAccesses, as + * they contain pure virtual functions. + */ class CoreExport AccessProvider : public Service { public: - AccessProvider(Module *o, const Anope::string &n); + AccessProvider(Module *owner, const Anope::string &name); virtual ~AccessProvider(); + + /** Creates a new ChanAccess entry using this provider. + * @return The new entry + */ virtual ChanAccess *Create() = 0; private: - static std::list<AccessProvider *> providers; + static std::list<AccessProvider *> Providers; public: static const std::list<AccessProvider *>& GetProviders(); }; +/* Represents one entry of an access list on a channel. */ class CoreExport ChanAccess : public Serializable { public: + /* The provider that created this access entry */ AccessProvider *provider; - serialize_obj<ChannelInfo> ci; + /* Channel this access entry is on */ + Serialize::Reference<ChannelInfo> ci; Anope::string mask; Anope::string creator; time_t last_seen; @@ -73,29 +87,69 @@ class CoreExport ChanAccess : public Serializable ChanAccess(AccessProvider *p); virtual ~ChanAccess(); - Serialize::Data serialize() const anope_override; - static Serializable* unserialize(Serializable *obj, Serialize::Data &); + Serialize::Data Serialize() const anope_override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); + /** Check if this access entry matches the given user or account + * @param u The user + * @param nc The account + */ virtual bool Matches(const User *u, const NickCore *nc) const; + + /** Check if this access entry has the given privilege. + * @param name The privilege name + */ virtual bool HasPriv(const Anope::string &name) const = 0; - virtual Anope::string Serialize() const = 0; - virtual void Unserialize(const Anope::string &data) = 0; + /** Serialize the access given by this access entry into a human + * readable form. chanserv/access will return a number, chanserv/xop + * will be AOP, SOP, etc. + */ + virtual Anope::string AccessSerialize() const = 0; + + /** Unserialize this access entry from the given data. This data + * will be fetched from AccessSerialize. + */ + virtual void AccessUnserialize(const Anope::string &data) = 0; + + /* Comparison operators to other Access entries */ bool operator>(const ChanAccess &other) const; bool operator<(const ChanAccess &other) const; bool operator>=(const ChanAccess &other) const; bool operator<=(const ChanAccess &other) const; }; +/* A group of access entries. This is used commonly, for example with ChannelInfo::AccessFor, + * to show what access a user has on a channel because users can match multiple access entries. + */ class CoreExport AccessGroup : public std::vector<ChanAccess *> { public: + /* Channel these access entries are on */ const ChannelInfo *ci; + /* Account these entries affect, if any */ const NickCore *nc; - bool SuperAdmin, Founder; + /* super_admin always gets all privs. founder is a special case where ci->founder == nc */ + bool super_admin, founder; + AccessGroup(); + + /** Check if this access group has a certain privilege. Eg, it + * will check every ChanAccess entry of this group for any that + * has the given privilege. + * @param priv The privilege + * @return true if any entry has the given privilege + */ bool HasPriv(const Anope::string &priv) const; + + /** Get the "highest" access entry from this group of entries. + * The highest entry is determined by the entry that has the privilege + * with the highest rank (see Privilege::rank). + * @return The "highest" entry + */ const ChanAccess *Highest() const; + + /* Comparison operators to other AccessGroups */ bool operator>(const AccessGroup &other) const; bool operator<(const AccessGroup &other) const; bool operator>=(const AccessGroup &other) const; diff --git a/include/account.h b/include/account.h index 8ed1f06a4..a45bf8c90 100644 --- a/include/account.h +++ b/include/account.h @@ -7,8 +7,7 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * + * */ #ifndef ACCOUNT_H @@ -23,10 +22,8 @@ typedef Anope::hash_map<NickAlias *> nickalias_map; typedef Anope::hash_map<NickCore *> nickcore_map; -extern CoreExport serialize_checker<nickalias_map> NickAliasList; -extern CoreExport serialize_checker<nickcore_map> NickCoreList; - -/* NickServ nickname structures. */ +extern CoreExport Serialize::Checker<nickalias_map> NickAliasList; +extern CoreExport Serialize::Checker<nickcore_map> NickCoreList; /** Flags set on NickAliases */ @@ -50,10 +47,6 @@ enum NickNameFlag NS_END }; -const Anope::string NickNameFlagStrings[] = { - "BEGIN", "NO_EXPIRE", "HELD", "COLLIDED", "" -}; - /** Flags set on NickCores */ enum NickCoreFlag @@ -101,40 +94,36 @@ enum NickCoreFlag NI_END }; -const Anope::string NickCoreFlagStrings[] = { - "BEGIN", "KILLPROTECT", "SECURE", "MSG", "MEMO_HARDMAX", "MEMO_SIGNON", "MEMO_RECEIVE", - "PRIVATE", "HIDE_EMAIL", "HIDE_MASK", "HIDE_QUIT", "KILL_QUICK", "KILL_IMMED", - "MEMO_MAIL", "HIDE_STATUS", "SUSPENDED", "AUTOOP", "UNCONFIRMED", "STATS", "" -}; - -/* It matters that Base is here before Extensible (it is inherited by Serializable) */ -class CoreExport NickAlias : public Serializable, public Extensible, public Flags<NickNameFlag, NS_END> +/* A registered nickname. + * It matters that Base is here before Extensible (it is inherited by Serializable) + */ +class CoreExport NickAlias : public Serializable, public Extensible, public Flags<NickNameFlag> { Anope::string vhost_ident, vhost_host, vhost_creator; time_t vhost_created; public: - /** Default constructor + Anope::string nick; + Anope::string last_quit; + Anope::string last_realname; + /* Last usermask this nick was seen on, eg user@host */ + Anope::string last_usermask; + /* Last uncloaked usermask, requires nickserv/auspex to see */ + Anope::string last_realhost; + time_t time_registered; + time_t last_seen; + /* Account this nick is tied to. Multiple nicks can be tied to a single account. */ + Serialize::Reference<NickCore> nc; + + /** Constructor * @param nickname The nick * @param nickcore The nickcore for this nick */ NickAlias(const Anope::string &nickname, NickCore *nickcore); - - /** Default destructor - */ ~NickAlias(); - Anope::string nick; /* Nickname */ - Anope::string last_quit; /* Last quit message */ - Anope::string last_realname; /* Last realname */ - Anope::string last_usermask; /* Last usermask */ - Anope::string last_realhost; /* Last uncloaked usermask, requires nickserv/auspex to see */ - time_t time_registered; /* When the nick was registered */ - time_t last_seen; /* When it was seen online for the last time */ - serialize_obj<NickCore> nc; /* I'm an alias of this */ - - Serialize::Data serialize() const anope_override; - static Serializable* unserialize(Serializable *obj, Serialize::Data &); + Serialize::Data Serialize() const anope_override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); /** Release a nick * See the comment in users.cpp @@ -184,41 +173,67 @@ class CoreExport NickAlias : public Serializable, public Extensible, public Flag * @return the time it was created */ time_t GetVhostCreated() const; + + /** Finds a registered nick + * @param nick The nick to lookup + * @return the nick, if found + */ + static NickAlias *Find(const Anope::string &nick); }; -/* It matters that Base is here before Extensible (it is inherited by Serializable) */ -class CoreExport NickCore : public Serializable, public Extensible, public Flags<NickCoreFlag, NI_END> +/* A registered account. Each account must have a NickAlias with the same nick as the + * account's display. + * It matters that Base is here before Extensible (it is inherited by Serializable) + */ +class CoreExport NickCore : public Serializable, public Extensible, public Flags<NickCoreFlag> { public: - /** Default constructor - * @param display The display nick - */ - NickCore(const Anope::string &nickdisplay); + /* Name of the account. Find(display)->nc == this. */ + Anope::string display; + /* User password in form of hashm:data */ + Anope::string pass; + Anope::string email; + /* Greet associated with the account, sometimes sent when the user joins a channel */ + Anope::string greet; + /* Locale name of the language of the user. Empty means default language */ + Anope::string language; + /* Access list, contains user@host masks of users who get certain privileges based + * on if NI_SECURE is set and what (if any) kill protection is enabled. */ + std::vector<Anope::string> access; + /* SSL certificate list. Users who have a matching certificate may be automatically logged in */ + std::vector<Anope::string> cert; + MemoInfo memos; - /** Default destructor + /* Nicknames registered that are grouped to this account. + * for n in aliases, n->nc == this. */ - ~NickCore(); - - std::list<User *> Users; - - Anope::string display; /* How the nick is displayed */ - Anope::string pass; /* Password of the nicks */ - Anope::string email; /* E-mail associated to the nick */ - Anope::string greet; /* Greet associated to the nick */ - Anope::string language; /* Language name */ - std::vector<Anope::string> access; /* Access list, vector of strings */ - std::vector<Anope::string> cert; /* ssl certificate list, vector of strings */ - MemoInfo memos; + std::list<Serialize::Reference<NickAlias> > aliases; + /* Set if this user is a services operattor. o->ot must exist. */ Oper *o; /* Unsaved data */ - uint16_t channelcount; /* Number of channels currently registered */ - time_t lastmail; /* Last time this nick record got a mail */ - std::list<serialize_obj<NickAlias> > aliases; /* List of aliases */ - Serialize::Data serialize() const anope_override; - static Serializable* unserialize(Serializable *obj, Serialize::Data &); + /* Number of channels registered by this account */ + uint16_t channelcount; + /* Last time an email was sent to this user */ + time_t lastmail; + /* Users online now logged into this account */ + std::list<User *> users; + + /** Constructor + * @param display The display nick + */ + NickCore(const Anope::string &nickdisplay); + ~NickCore(); + + Serialize::Data Serialize() const anope_override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); + + /** Changes the display for this account + * @param na The new display, must be grouped to this account. + */ + void SetDisplay(const NickAlias *na); /** Checks whether this account is a services oper or not. * @return True if this account is a services oper, false otherwise. @@ -265,6 +280,14 @@ class CoreExport NickCore : public Serializable, public Extensible, public Flags */ void ClearAccess(); + /** Is the given user on this accounts access list? + * + * @param u The user + * + * @return true if the user is on the access list + */ + bool IsOnAccess(const User *u) const; + /** Add an entry to the nick's certificate list * * @param entry The fingerprint to add to the cert list @@ -304,10 +327,21 @@ class CoreExport NickCore : public Serializable, public Extensible, public Flags * Deletes all the memory allocated in the certificate list vector and then clears the vector. */ void ClearCert(); + + /** Finds an account + * @param nick The account name to find + * @return The account, if it exists + */ + static NickCore* Find(const Anope::string &nick); }; +/* A request to check if an account/password is valid. These can exist for + * extended periods of time due to some authentication modules take. + */ class CoreExport IdentifyRequest { + /* Owner of this request, used to cleanup requests if a module is unloaded + * while a reqyest us pending */ Module *owner; Anope::string account; Anope::string password; @@ -316,35 +350,47 @@ class CoreExport IdentifyRequest bool dispatched; bool success; - static std::set<IdentifyRequest *> requests; + static std::set<IdentifyRequest *> Requests; protected: IdentifyRequest(Module *o, const Anope::string &acc, const Anope::string &pass); virtual ~IdentifyRequest(); public: + /* One of these is called when the request goes through */ virtual void OnSuccess() = 0; virtual void OnFail() = 0; const Anope::string &GetAccount() const { return account; } const Anope::string &GetPassword() const { return password; } - /* Hold this request. Once held it must be Release()d later on */ + /* Holds this request. When a request is held it must be Released later + * for the request to complete. Multiple modules may hold a request at any time, + * but the request is not complete until every module has released it. If you do not + * require holding this (eg, your password check is done in this thread and immediately) + * then you don't need to hold the request before Successing it. + * @param m The module holding this request + */ void Hold(Module *m); + + /** Releases a held request + * @param m The module releaseing the hold + */ void Release(Module *m); + /** Called by modules when this IdentifyRequest has successeded successfully. + * If this request is behind held it must still be Released after calling this. + * @param m The module confirming authentication + */ void Success(Module *m); + /** Used to either finalize this request or marks + * it as dispatched and begins waiting for the module(s) + * that have holds to finish. + */ void Dispatch(); static void ModuleUnload(Module *m); }; -extern CoreExport void change_core_display(NickCore *nc); -extern CoreExport void change_core_display(NickCore *nc, const Anope::string &newdisplay); - -extern CoreExport NickAlias *findnick(const Anope::string &nick); -extern CoreExport NickCore *findcore(const Anope::string &nick); -extern CoreExport bool is_on_access(const User *u, const NickCore *nc); - #endif // ACCOUNT_H diff --git a/include/anope.h b/include/anope.h index b6033b15c..2dda6cf76 100644 --- a/include/anope.h +++ b/include/anope.h @@ -1,4 +1,5 @@ /* + * * (C) 2003-2012 Anope Team * Contact us at team@anope.org * @@ -6,6 +7,7 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. + * */ #ifndef ANOPE_H @@ -304,11 +306,52 @@ namespace Anope static const char *const compiled = __TIME__ " " __DATE__; + /** The time Anope started. + */ + extern time_t StartTime; + + /** The value to return from main() + */ + extern int ReturnValue; + extern bool Quitting; + extern bool Restarting; + extern Anope::string QuitReason; + /** The current system time, which is pretty close to being accurate. * Use this unless you need very specific time checks */ extern CoreExport time_t CurTime; + /** The debug level we are running at. + */ + extern int Debug; + + /** Other comand line options. + */ + extern bool ReadOnly, NoFork, NoThird, NoExpire, ProtocolDebug; + + /** The root of the services installation. Usually ~/services + */ + extern Anope::string ServicesDir; + + /** Services binary name (eg services) + */ + extern Anope::string ServicesBin; + + /** Various directory paths. These can be set at runtime by command line args + */ + extern Anope::string ConfigDir; + extern Anope::string DataDir; + extern Anope::string ModuleDir; + extern Anope::string LocaleDir; + extern Anope::string LogDir; + + /** The uplink we are currently connected to + */ + extern int CurrentUplink; + + /** Various methods to determine the Anope version running + */ extern CoreExport string Version(); extern CoreExport string VersionShort(); extern CoreExport string VersionBuildString(); @@ -316,6 +359,29 @@ namespace Anope extern CoreExport int VersionMinor(); extern CoreExport int VersionPatch(); + /** Determines if we are still attached to the terminal, and can print + * messages to the user via stderr/stdout. + * @return true if still attached + */ + extern bool AtTerm(); + + /** Used to "fork" the process and go into the background during initial startup + * while we are AtTerm(). The actual fork is not done here, but earlier, and this + * simply notifys the parent via kill() to exit(). + */ + extern void Fork(); + + /** One of the first functions called, does general initialization such as reading + * command line args, loading the configuration, doing the initial fork() if necessary, + * initializating language support, loading modules, and loading databases. + * @throws CoreException if something bad went wrong + */ + extern void Init(int ac, char **av); + + /** Calls the save database event + */ + extern void SaveDatabases(); + /** Check whether two strings match. * @param str The string to check against the pattern (e.g. foobar) * @param mask The pattern to check (e.g. foo*bar) @@ -350,6 +416,20 @@ namespace Anope */ extern CoreExport void B64Decode(const string &src, string &target); + /** Encrypts what is in 'src' to 'dest' + * @param src The source string to encrypt + * @param dest The destination where the encrypted string is placed + */ + extern void Encrypt(const Anope::string &src, Anope::string &dest); + + /** Decrypts what is in 'src' to 'dest'. + * @param src The source string to decrypt + * @param dest The destination where the decrypted string is placed + * @return true if decryption was successful. This is usually not the case + * as most encryption methods we use are one way. + */ + extern bool Decrypt(const Anope::string &src, Anope::string &dest); + /** Returns a sequence of data formatted as the format argument specifies. ** After the format parameter, the function expects at least as many ** additional arguments as specified in format. @@ -368,6 +448,48 @@ namespace Anope * @return An error message */ extern CoreExport const string LastError(); + + /** Determines if a path is a file + */ + extern bool IsFile(const Anope::string &file); + + /** Converts a string into seconds + * @param s The string, eg 3d + * @return The time represented by the string, eg 259,200 + */ + extern time_t DoTime(const Anope::string &s); + + /** Retrieves a human readable string representing the time in seconds + * @param seconds The time on seconds, eg 60 + * @param nc The account to use langauge settings for to translate this string, if applicable + * @return A human readable string, eg "1 minute" + */ + extern Anope::string Duration(time_t seconds, const NickCore *nc = NULL); + + /** Generates a human readable string of type "expires in ..." + * @param expires time in seconds + * @param nc The account to use langauge settings for to translate this string, if applicable + * @return A human readable string, eg "expires in 5 days" + */ + extern Anope::string Expires(time_t seconds, const NickCore *nc = NULL); + + /** Converts a time in seconds (epoch) to a human readable format. + * @param t The time + * @param nc The account to use langauge settings for to translate this string, if applicable + * @param short_output If true, the output is just a date (eg, "Apr 12 20:18:22 2009 MSD"), else it includes the date and how long ago/from now that date is, (eg "Apr 12 20:18:22 2009 MSD (1313 days, 9 hours, 32 minutes ago)" + */ + extern Anope::string strftime(time_t t, const NickCore *nc = NULL, bool short_output = false); + + /** Normalize buffer, stripping control characters and colors + * @param A string to be parsed for control and color codes + * @return A string stripped of control and color codes + */ + extern Anope::string NormalizeBuffer(const Anope::string &); + + /** Main processing routine. Parses the message and takes the appropriate action. + * @param Raw message from the uplink + */ + extern void Process(const Anope::string &); } /** sepstream allows for splitting token seperated lists. @@ -394,23 +516,52 @@ class CoreExport sepstream /** Create a sepstream and fill it with the provided data */ sepstream(const Anope::string &source, char seperator); - virtual ~sepstream() { } /** Fetch the next token from the stream * @param token The next token from the stream is placed here * @return True if tokens still remain, false if there are none left */ - virtual bool GetToken(Anope::string &token); + bool GetToken(Anope::string &token); + + /** Gets token number 'num' from the stream + * @param token The token is placed here + * @param num The token number to featch + * @return True if the token was able to be detched + */ + bool GetToken(Anope::string &token, int num); + + /** Gets every token from this stream + * @param token Tokens are pushed back here + */ + template<typename T> void GetTokens(T& token) + { + token.clear(); + Anope::string t; + while (this->GetToken(t)) + token.push_back(t); + } + + /** Gets token number 'num' from the stream and all remaining tokens. + * @param token The token is placed here + * @param num The token number to featch + * @return True if the token was able to be detched + */ + bool GetTokenRemainder(Anope::string &token, int num); + + /** Determines the number of tokens in this stream. + * @return The number of tokens in this stream + */ + int NumTokens(); /** Fetch the entire remaining stream, without tokenizing * @return The remaining part of the stream */ - virtual const Anope::string GetRemaining(); + const Anope::string GetRemaining(); /** Returns true if the end of the stream has been reached * @return True if the end of the stream has been reached, otherwise false */ - virtual bool StreamEnd(); + bool StreamEnd(); }; /** A derived form of sepstream, which seperates on commas @@ -478,14 +629,6 @@ class CoreException : public std::exception } }; -class FatalException : public CoreException -{ - public: - FatalException(const Anope::string &reason = "") : CoreException(reason) { } - - virtual ~FatalException() throw() { } -}; - class ModuleException : public CoreException { public: @@ -600,39 +743,43 @@ template<typename T, typename O> inline T anope_dynamic_reinterpret_cast(O ptr) /** Class with the ability to keep flags on items, they should extend from this * where T is an enum. */ -template<typename T, size_t Size = 32> class Flags +template<typename T> class Flags { - protected: - std::bitset<Size> Flag_Values; - const Anope::string *Flag_Strings; + std::vector<bool> flags_values; + static const Anope::string *flags_strings; public: - Flags() : Flag_Strings(NULL) { } - Flags(const Anope::string *flag_strings) : Flag_Strings(flag_strings) { } - /** Add a flag to this item - * @param Value The flag + * @param value The flag */ - void SetFlag(T Value) + void SetFlag(T value) { - Flag_Values[Value] = true; + if (value < 0) + return; + + if (static_cast<unsigned>(value) >= flags_values.size()) + flags_values.resize(value + 1); + flags_values[value] = true; } /** Remove a flag from this item - * @param Value The flag + * @param value The flag */ - void UnsetFlag(T Value) + void UnsetFlag(T value) { - Flag_Values[Value] = false; + if (value >= 0 && static_cast<unsigned>(value) < flags_values.size()) + flags_values[value] = false; } /** Check if this item has a flag - * @param Value The flag + * @param value The flag * @return true or false */ - bool HasFlag(T Value) const + bool HasFlag(T value) const { - return Flag_Values.test(Value); + if (value >= 0 && static_cast<unsigned>(value) < flags_values.size()) + return flags_values[value]; + return false; } /** Check how many flags are set @@ -640,14 +787,23 @@ template<typename T, size_t Size = 32> class Flags */ size_t FlagCount() const { - return Flag_Values.count(); + size_t c = 0; + for (unsigned i = 0; i < flags_values.size(); ++i) + if (flags_values[i]) + ++c; + return c; } /** Unset all of the flags */ void ClearFlags() { - Flag_Values.reset(); + flags_values.clear(); + } + + static const Anope::string* GetFlagStrings() + { + return flags_strings; } Anope::string ToString() const @@ -675,9 +831,9 @@ template<typename T, size_t Size = 32> class Flags std::vector<Anope::string> ToVector() const { std::vector<Anope::string> ret; - for (unsigned i = 0; this->Flag_Strings && !this->Flag_Strings[i].empty(); ++i) + for (unsigned i = 0; this->flags_strings && !this->flags_strings[i].empty(); ++i) if (this->HasFlag(static_cast<T>(i))) - ret.push_back(this->Flag_Strings[i]); + ret.push_back(this->flags_strings[i]); return ret; } @@ -685,9 +841,9 @@ template<typename T, size_t Size = 32> class Flags { this->ClearFlags(); - for (unsigned i = 0; this->Flag_Strings && !this->Flag_Strings[i].empty(); ++i) + for (unsigned i = 0; this->flags_strings && !this->flags_strings[i].empty(); ++i) for (unsigned j = 0; j < strings.size(); ++j) - if (this->Flag_Strings[i] == strings[j]) + if (this->flags_strings[i] == strings[j]) this->SetFlag(static_cast<T>(i)); } }; diff --git a/include/base.h b/include/base.h index c09b97400..178bb1937 100644 --- a/include/base.h +++ b/include/base.h @@ -4,6 +4,7 @@ * Copyright (C) 2008-2012 Anope Team <team@anope.org> * * Please read COPYING and README for further details. + * */ #ifndef BASE_H @@ -16,48 +17,57 @@ class CoreExport Base { /* References to this base class */ - std::set<dynamic_reference_base *> References; + std::set<ReferenceBase *> references; public: Base(); virtual ~Base(); - void AddReference(dynamic_reference_base *r); - void DelReference(dynamic_reference_base *r); + + /** Adds a reference to this object. Eg, when a Reference + * is created referring to this object this is called. It is used to + * cleanup references when this object is destructed. + */ + void AddReference(ReferenceBase *r); + + void DelReference(ReferenceBase *r); }; -class dynamic_reference_base +class ReferenceBase { protected: bool invalid; public: - dynamic_reference_base() : invalid(false) { } - dynamic_reference_base(const dynamic_reference_base &other) : invalid(other.invalid) { } - virtual ~dynamic_reference_base() { } + ReferenceBase() : invalid(false) { } + ReferenceBase(const ReferenceBase &other) : invalid(other.invalid) { } + virtual ~ReferenceBase() { } inline void Invalidate() { this->invalid = true; } }; +/** Used to hold pointers to objects that may be deleted. A Reference will + * no longer be valid once the object it refers is destructed. + */ template<typename T> -class dynamic_reference : public dynamic_reference_base +class Reference : public ReferenceBase { protected: T *ref; public: - dynamic_reference() : ref(NULL) + Reference() : ref(NULL) { } - dynamic_reference(T *obj) : ref(obj) + Reference(T *obj) : ref(obj) { if (ref) ref->AddReference(this); } - dynamic_reference(const dynamic_reference<T> &other) : dynamic_reference_base(other), ref(other.ref) + Reference(const Reference<T> &other) : ReferenceBase(other), ref(other.ref) { if (operator bool()) ref->AddReference(this); } - virtual ~dynamic_reference() + virtual ~Reference() { if (operator bool()) ref->DelReference(this); @@ -105,12 +115,12 @@ class dynamic_reference : public dynamic_reference_base this->ref->AddReference(this); } - inline bool operator<(const dynamic_reference<T> &other) const + inline bool operator<(const Reference<T> &other) const { return this < &other; } - inline bool operator==(const dynamic_reference<T> &other) + inline bool operator==(const Reference<T> &other) { if (!this->invalid) return this->ref == other; diff --git a/include/bots.h b/include/bots.h index 888e8d217..3d44d08dd 100644 --- a/include/bots.h +++ b/include/bots.h @@ -1,8 +1,10 @@ /* + * * Copyright (C) 2008-2011 Robin Burchell <w00t@inspircd.org> * Copyright (C) 2008-2012 Anope Team <team@anope.org> * * Please read COPYING and README for further details. + * */ #ifndef BOTS_H @@ -16,7 +18,7 @@ typedef Anope::map<BotInfo *> botinfo_map; -extern CoreExport serialize_checker<botinfo_map> BotListByNick, BotListByUID; +extern CoreExport Serialize::Checker<botinfo_map> BotListByNick, BotListByUID; /** Flags settable on a bot */ @@ -24,8 +26,6 @@ enum BotFlag { BI_BEGIN, - /* This bot is a core bot. NickServ, ChanServ, etc */ - BI_CORE, /* This bot can only be assigned by IRCops */ BI_PRIVATE, /* This bot is defined in the config */ @@ -34,17 +34,21 @@ enum BotFlag BI_END }; -static const Anope::string BotFlagString[] = { "BEGIN", "CORE", "PRIVATE", "CONF", "" }; - -class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END>, public Serializable +/* A service bot (NickServ, ChanServ, a BotServ bot, etc). */ +class CoreExport BotInfo : public User, public Flags<BotFlag>, public Serializable { public: - time_t created; /* Birth date ;) */ - time_t lastmsg; /* Last time we said something */ - CommandInfo::map commands; /* Commands, actual name to service name */ - Anope::string botmodes; /* Modes the bot should have as configured in service:modes */ - std::vector<Anope::string> botchannels; /* Channels the bot should be in as configured in service:channels */ - bool introduced; /* Whether or not this bot is introduced */ + time_t created; + /* Last time this bot said something (via privmsg) */ + time_t lastmsg; + /* Map of actual command names -> service name/permission required */ + CommandInfo::map commands; + /* Modes the bot should have as configured in service:modes */ + Anope::string botmodes; + /* Channels the bot should be in as configured in service:channels */ + std::vector<Anope::string> botchannels; + /* Whether or not this bot is introduced to the network */ + bool introduced; /** Create a new bot. * @param nick The nickname to assign to the bot. @@ -59,8 +63,8 @@ class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END>, public Se */ virtual ~BotInfo(); - Serialize::Data serialize() const; - static Serializable* unserialize(Serializable *obj, Serialize::Data &); + Serialize::Data Serialize() const; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); void GenerateUID(); @@ -126,11 +130,13 @@ class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END>, public Se * @return A struct containing service name and permission */ CommandInfo *GetCommand(const Anope::string &cname); -}; -extern CoreExport BotInfo *findbot(const Anope::string &nick); - -extern CoreExport void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason); -extern CoreExport void bot_raw_kick(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason); + /** Find a bot by nick + * @param nick The nick + * @param nick_only True to only look by nick, and not by UID + * @return The bot, if it exists + */ + static BotInfo* Find(const Anope::string &nick, bool nick_only = false); +}; #endif // BOTS_H diff --git a/include/botserv.h b/include/botserv.h deleted file mode 100644 index e5ef2c8ba..000000000 --- a/include/botserv.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * - * (C) 2003-2012 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - * - */ - -#ifndef BOTSERV_H -#define BOTSERV_H - -#include "anope.h" - -/* BotServ SET flags */ -enum BotServFlag -{ - BS_BEGIN, - /* BotServ won't kick ops */ - BS_DONTKICKOPS, - /* BotServ won't kick voices */ - BS_DONTKICKVOICES, - /* BotServ bot accepts fantasy commands */ - BS_FANTASY, - /* BotServ should show greets */ - BS_GREET, - /* BotServ bots are not allowed to be in this channel */ - BS_NOBOT, - /* BotServ kicks for bolds */ - BS_KICK_BOLDS, - /* BotServ kicks for colors */ - BS_KICK_COLORS, - /* BOtServ kicks for reverses */ - BS_KICK_REVERSES, - /* BotServ kicks for underlines */ - BS_KICK_UNDERLINES, - /* BotServ kicks for badwords */ - BS_KICK_BADWORDS, - /* BotServ kicks for caps */ - BS_KICK_CAPS, - /* BotServ kicks for flood */ - BS_KICK_FLOOD, - /* BotServ kicks for repeating */ - BS_KICK_REPEAT, - /* BotServ kicks for italics */ - BS_KICK_ITALICS, - /* BotServ kicks for amsgs */ - BS_KICK_AMSGS, - BS_END -}; - -const Anope::string BotServFlagStrings[] = { - "BEGIN", "DONTKICKOPS", "DONTKICKVOICES", "FANTASY", "GREET", "NOBOT", - "KICK_BOLDs", "KICK_COLORS", "KICK_REVERSES", "KICK_UNDERLINES", "KICK_BADWORDS", "KICK_CAPS", - "KICK_FLOOD", "KICK_REPEAT", "KICK_ITALICS", "KICK_AMSGS", "MSG_PRIVMSG", "MSG_NOTICE", - "MSG_NOTICEOPS", "" -}; - -/* Indices for TTB (Times To Ban) */ -enum -{ - TTB_BOLDS, - TTB_COLORS, - TTB_REVERSES, - TTB_UNDERLINES, - TTB_BADWORDS, - TTB_CAPS, - TTB_FLOOD, - TTB_REPEAT, - TTB_ITALICS, - TTB_AMSGS, - TTB_SIZE -}; - -#endif // BOTSERV_H diff --git a/include/channels.h b/include/channels.h index 99ddf06b9..5cbea5ecc 100644 --- a/include/channels.h +++ b/include/channels.h @@ -4,6 +4,7 @@ * Contact us at team@anope.org * * Please read COPYING and README for further details. + * */ #ifndef CHANNELS_H @@ -18,10 +19,12 @@ typedef Anope::hash_map<Channel *> channel_map; extern CoreExport channel_map ChannelList; +/* A user container, there is one of these per user per channel. */ struct UserContainer : public Extensible { User *user; - ChannelStatus *Status; + /* Status the user has in the channel */ + ChannelStatus *status; UserContainer(User *u) : user(u) { } virtual ~UserContainer() { } @@ -39,9 +42,7 @@ enum ChannelFlag CH_SYNCING }; -const Anope::string ChannelFlagString[] = { "CH_INABIT", "CH_PERSIST", "CH_SYNCING", "" }; - -class CoreExport Channel : public virtual Base, public Extensible, public Flags<ChannelFlag, 3> +class CoreExport Channel : public Base, public Extensible, public Flags<ChannelFlag> { public: typedef std::multimap<ChannelModeName, Anope::string> ModeList; @@ -51,27 +52,27 @@ class CoreExport Channel : public virtual Base, public Extensible, public Flags< ModeList modes; public: - /** Default constructor - * @param name The channel name - * @param ts The time the channel was created - */ - Channel(const Anope::string &nname, time_t ts = Anope::CurTime); - - /** Default destructor - */ - ~Channel(); - - Anope::string name; /* Channel name */ - serialize_obj<ChannelInfo> ci; /* Corresponding ChannelInfo */ - time_t creation_time; /* When channel was created */ - - /* List of users in the channel */ + /* Channel name */ + Anope::string name; + /* Set if this channel is registered. ci->c == this. Contains information relevant to the registered channel */ + Serialize::Reference<ChannelInfo> ci; + /* When the channel was created */ + time_t creation_time; + + /* Users in the channel */ CUserList users; - Anope::string topic; /* Current topic of the channel */ - Anope::string topic_setter; /* Who set the topic */ - time_t topic_ts; /* The timestamp associated with the topic. Not necessarually anywhere close to Anope::CurTime */ - time_t topic_time; /* The actual time the topic was set, probably close to Anope::CurTime */ + /* Current topic of the channel */ + Anope::string topic; + /* Who set the topic */ + Anope::string topic_setter; + /* The timestamp associated with the topic. Not necessarually anywhere close to Anope::CurTime. + * This is the time the topic was *originally set*. When we restore the topic we want to change the TS back + * to this, but we can only do this on certain IRCds. + */ + time_t topic_ts; + /* The actual time the topic was set, probably close to Anope::CurTime */ + time_t topic_time; time_t server_modetime; /* Time of last server MODE */ time_t chanserv_modetime; /* Time of last check_modes() */ @@ -79,6 +80,16 @@ class CoreExport Channel : public virtual Base, public Extensible, public Flags< int16_t chanserv_modecount; /* Number of check_mode()'s this sec */ int16_t bouncy_modes; /* Did we fail to set modes here? */ + /** Constructor + * @param name The channel name + * @param ts The time the channel was created + */ + Channel(const Anope::string &nname, time_t ts = Anope::CurTime); + + /** Destructor + */ + ~Channel(); + /** Call if we need to unset all modes and clear all user status (internally). * Only useful if we get a SJOIN with a TS older than what we have here */ @@ -94,8 +105,9 @@ class CoreExport Channel : public virtual Base, public Extensible, public Flags< /** Join a user internally to the channel * @param u The user + * @return The UserContainer for the user */ - void JoinUser(User *u); + UserContainer* JoinUser(User *u); /** Remove a user internally from the channel * @param u The user @@ -118,94 +130,101 @@ class CoreExport Channel : public virtual Base, public Extensible, public Flags< /** Check if a user has a status on a channel * Use the overloaded function for ChannelModeStatus* to check for no status * @param u The user - * @param Name The Mode name, eg CMODE_OP, CMODE_VOICE + * @param name The mode name, eg CMODE_OP, CMODE_VOICE * @return true or false */ - bool HasUserStatus(const User *u, ChannelModeName Name) const; + bool HasUserStatus(const User *u, ChannelModeName name) const; /** See if a channel has a mode - * @param Name The mode name + * @param name The mode name * @return The number of modes set * @param param The optional mode param */ - size_t HasMode(ChannelModeName Name, const Anope::string ¶m = ""); + size_t HasMode(ChannelModeName name, const Anope::string ¶m = ""); /** Get a list of modes on a channel - * @param Name A mode name to get the list of + * @param name A mode name to get the list of * @return a pair of iterators for the beginning and end of the list */ - std::pair<ModeList::iterator, ModeList::iterator> GetModeList(ChannelModeName Name); + std::pair<ModeList::iterator, ModeList::iterator> GetModeList(ChannelModeName name); /** Set a mode internally on a channel, this is not sent out to the IRCd * @param setter The setter * @param cm The mode * @param param The param - * @param EnforceMLock true if mlocks should be enforced, false to override mlock + * @param enforce_mlock true if mlocks should be enforced, false to override mlock */ - void SetModeInternal(MessageSource &source, ChannelMode *cm, const Anope::string ¶m = "", bool EnforceMLock = true); + void SetModeInternal(MessageSource &source, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true); /** Remove a mode internally on a channel, this is not sent out to the IRCd * @param setter The Setter * @param cm The mode * @param param The param - * @param EnforceMLock true if mlocks should be enforced, false to override mlock + * @param enforce_mlock true if mlocks should be enforced, false to override mlock */ - void RemoveModeInternal(MessageSource &source, ChannelMode *cm, const Anope::string ¶m = "", bool EnforceMLock = true); + void RemoveModeInternal(MessageSource &source, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true); /** Set a mode on a channel * @param bi The client setting the modes * @param cm The mode * @param param Optional param arg for the mode - * @param EnforceMLock true if mlocks should be enforced, false to override mlock + * @param enforce_mlock true if mlocks should be enforced, false to override mlock */ - void SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool EnforceMLock = true); + void SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true); /** * Set a mode on a channel * @param bi The client setting the modes - * @param Name The mode name + * @param name The mode name * @param param Optional param arg for the mode - * @param EnforceMLock true if mlocks should be enforced, false to override mlock + * @param enforce_mlock true if mlocks should be enforced, false to override mlock */ - void SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m = "", bool EnforceMLock = true); + void SetMode(BotInfo *bi, ChannelModeName name, const Anope::string ¶m = "", bool enforce_mlock = true); /** Remove a mode from a channel * @param bi The client setting the modes * @param cm The mode * @param param Optional param arg for the mode - * @param EnforceMLock true if mlocks should be enforced, false to override mlock + * @param enforce_mlock true if mlocks should be enforced, false to override mlock */ - void RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool EnforceMLock = true); + void RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true); /** * Remove a mode from a channel * @param bi The client setting the modes - * @param Name The mode name + * @param name The mode name * @param param Optional param arg for the mode - * @param EnforceMLock true if mlocks should be enforced, false to override mlock + * @param enforce_mlock true if mlocks should be enforced, false to override mlock */ - void RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m = "", bool EnforceMLock = true); + void RemoveMode(BotInfo *bi, ChannelModeName name, const Anope::string ¶m = "", bool enforce_mlock = true); - /** Get a param from the channel - * @param Name The mode - * @param Target a string to put the param into - * @return true on success + /** Get a modes parameter for the channel + * @param name The mode + * @param target a string to put the param into + * @return true if the parameter was fetched, false if on error (mode not set) etc. */ - bool GetParam(ChannelModeName Name, Anope::string &Target) const; + bool GetParam(ChannelModeName name, Anope::string &target) const; /** Set a string of modes on the channel * @param bi The client setting the modes - * @param EnforceMLock Should mlock be enforced on this mode change + * @param enforce_mlock Should mlock be enforced on this mode change * @param cmodes The modes to set */ - void SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...); + void SetModes(BotInfo *bi, bool enforce_mlock, const char *cmodes, ...); /** Set a string of modes internally on a channel * @param source The setter * @param mode the modes - * @param EnforceMLock true to enforce mlock + * @param enforce_mlock true to enforce mlock + */ + void SetModesInternal(MessageSource &source, const Anope::string &mode, time_t ts = 0, bool enforce_mlock = true); + + /** Does the given user match the given list? (CMODE_BAN, CMODE_EXCEPT, etc, a list mode) + * @param u The user + * @param list The mode of the list to check (eg CMODE_BAN) + * @return true if the user matches the list */ - void SetModesInternal(MessageSource &source, const Anope::string &mode, time_t ts = 0, bool EnforceMLock = true); + bool MatchesList(User *u, ChannelModeName list); /** Kick a user from a channel internally * @param source The sender of the kick @@ -246,12 +265,26 @@ class CoreExport Channel : public virtual Base, public Extensible, public Flags< /** Hold the channel open using ChanServ */ void Hold(); -}; -extern CoreExport Channel *findchan(const Anope::string &chan); + /** Set the correct modes, or remove the ones granted without permission, + * for the specified user. + * @param user The user to give/remove modes to/from + * @param give_modes if true modes may be given to the user + * @param check_noop if true, CI_NOAUTOOP is checked before giving modes + */ + void SetCorrectModes(User *u, bool give_mode, bool check_noop); -extern CoreExport User *nc_on_chan(Channel *c, const NickCore *nc); + /** Unbans a user from this channel. + * @param u The user to unban + * @param full Whether or not to match using the user's real host and IP + */ + void Unban(const User *u, bool full = false); -extern CoreExport void chan_set_correct_modes(const User *user, Channel *c, int give_modes, bool check_noop); + /** Finds a channel + * @param name The channel to find + * @return The channel, if found + */ + static Channel* Find(const Anope::string &name); +}; #endif // CHANNELS_H diff --git a/include/commands.h b/include/commands.h index 333d6882a..5c8664147 100644 --- a/include/commands.h +++ b/include/commands.h @@ -22,20 +22,20 @@ enum CommandFlag CFLAG_STRIP_CHANNEL }; -const Anope::string CommandFlagStrings[] = { - "CFLAG_ALLOW_UNREGISTERED", - "CFLAG_STRIP_CHANNEL", - "" -}; - +/* Used in BotInfo::commands */ struct CommandInfo { typedef Anope::map<CommandInfo> map; + /* Service name of the command */ Anope::string name; + /* Permission required to execute the command */ Anope::string permission; }; +/* Where the replies from commands go to. User inheits from this and is the normal + * source of a CommandReply + */ struct CommandReply { virtual void SendMessage(const BotInfo *source, const Anope::string &msg) = 0; @@ -47,16 +47,16 @@ class CoreExport CommandSource /* The nick executing the command */ Anope::string nick; /* User executing the command, may be NULL */ - dynamic_reference<User> u; + Reference<User> u; public: /* The account executing the command */ - dynamic_reference<NickCore> nc; + Reference<NickCore> nc; /* Where the reply should go */ CommandReply *reply; /* Channel the command was executed on (fantasy) */ - dynamic_reference<Channel> c; + Reference<Channel> c; /* The service this command is on */ - dynamic_reference<BotInfo> service; + Reference<BotInfo> service; /* The actual name of the command being executed */ Anope::string command; /* The permission of the command being executed */ @@ -88,9 +88,9 @@ class CoreExport Command : public Service, public Flags<CommandFlag> public: /* Maximum paramaters accepted by this command */ - size_t MaxParams; + size_t max_params; /* Minimum parameters required to use this command */ - size_t MinParams; + size_t min_params; /* Module which owns us */ Module *module; diff --git a/include/config.h b/include/config.h index 86a232485..ad772033d 100644 --- a/include/config.h +++ b/include/config.h @@ -8,7 +8,6 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. * - * */ #ifndef CONFIG_H @@ -207,23 +206,6 @@ typedef bool (*MultiValidator)(ServerConfig *, const Anope::string &, const Anop */ typedef bool (*MultiNotify)(ServerConfig *, const Anope::string &); -bool ValidateNotEmpty(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidateNotZero(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidateEmailReg(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidatePort(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidateGuestPrefix(ServerConfig *conf, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidateBantype(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &data); -bool ValidateChanServ(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidateMemoServ(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidateBotServ(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidateHostServ(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidateLimitSessions(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidateOperServ(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidateGlobal(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidateNickLen(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &data); -bool ValidateMail(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data); -bool ValidateGlobalOnCycle(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data); - /** Represents a configuration file */ class ConfigurationFile @@ -463,8 +445,6 @@ class CoreExport ServerConfig bool UseServerSideTopicLock; /* Default botmodes on channels, defaults to ao */ Anope::string BotModes; - /* THe actual modes */ - ChannelStatus BotModeList; /* How long to wait between connection attempts */ int RetryWait; /* If services should hide unprivileged commands */ @@ -517,7 +497,7 @@ class CoreExport ServerConfig /* Don't allow nicks to use /ns group to regroup nicks */ bool NSNoGroupChange; /* Default flags for newly registered nicks */ - Flags<NickCoreFlag, NI_END> NSDefFlags; + Flags<NickCoreFlag> NSDefFlags; /* All languages Anope is aware about */ Anope::string Languages; /* Default language used by services */ @@ -578,7 +558,7 @@ class CoreExport ServerConfig /* Core ChanServ modules */ Anope::string ChanCoreModules; /* Default flags for newly registered channels */ - Flags<ChannelInfoFlag, CI_END> CSDefFlags; + Flags<ChannelInfoFlag> CSDefFlags; /* Max number of channels a user can own */ unsigned CSMaxReg; /* Time before a channel expires */ @@ -741,7 +721,7 @@ class ConfigException : public CoreException #define CONF_FILE_NOT_FOUND 0x000200 /** Allows reading of values from configuration files - * This class allows a module to read from either the main configuration file (inspircd.conf) or from + * This class allows a module to read from either the main configuration file (services.conf) or from * a module-specified configuration file. It may either be instantiated with one parameter or none. * Constructing the class using one parameter allows you to specify a path to your own configuration * file, otherwise, inspircd.conf is read. @@ -836,7 +816,7 @@ class CoreExport ConfigReader int EnumerateValues(const Anope::string &, int); }; -extern ConfigurationFile services_conf; +extern ConfigurationFile ServicesConf; extern CoreExport ServerConfig *Config; #endif // CONFIG_H diff --git a/include/defs.h b/include/defs.h index ed6795142..437f0f08d 100644 --- a/include/defs.h +++ b/include/defs.h @@ -23,21 +23,21 @@ class ClientSocket; class Command; class CommandSource; class ConnectionSocket; -class DNSPacket; -class dynamic_reference_base; +namespace DNS { class Packet; } class Entry; class IdentifyRequest; class InfoFormatter; +class IRCDProto; class ListenSocket; class Log; class LogInfo; class Memo; -class Message; class MessageSource; class Module; class NickAlias; class NickCore; class OperType; +class ReferenceBase; class Regex; class Serializable; class Server; @@ -48,7 +48,7 @@ class User; class XLine; class XLineManager; struct BadWord; -struct DNSQuery; +namespace DNS { struct Query; } struct Exception; struct MemoInfo; struct ModeLock; diff --git a/include/dns.h b/include/dns.h index 64067107b..fee9da8a9 100644 --- a/include/dns.h +++ b/include/dns.h @@ -8,260 +8,271 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. * - * */ - + #ifndef DNS_H #define DNS_H #include "sockets.h" #include "timers.h" -#include "extern.h" #include "config.h" - -/** Valid query types - */ -enum QueryType -{ - /* Nothing */ - DNS_QUERY_NONE, - /* A simple A lookup */ - DNS_QUERY_A = 1, - /* An authoritative name server */ - DNS_QUERY_NS = 2, - /* A CNAME lookup */ - DNS_QUERY_CNAME = 5, - /* Start of a zone of authority */ - DNS_QUERY_SOA = 6, - /* Reverse DNS lookup */ - DNS_QUERY_PTR = 12, - /* IPv6 AAAA lookup */ - DNS_QUERY_AAAA = 28, - /* Zone transfer */ - DNS_QUERY_AXFR = 252 -}; - -/** Flags that can be AND'd into DNSPacket::flags to receive certain values - */ -enum -{ - DNS_QUERYFLAGS_QR = 0x8000, - DNS_QUERYFLAGS_OPCODE = 0x7800, - DNS_QUERYFLAGS_AA = 0x400, - DBS_QUERYFLAGS_TC = 0x200, - DNS_QUERYFLAGS_RD = 0x100, - DNS_QUERYFLAGS_RA = 0x80, - DNS_QUERYFLAGS_Z = 0x70, - DNS_QUERYFLAGS_RCODE = 0xF -}; - -enum DNSError -{ - DNS_ERROR_NONE, - DNS_ERROR_UNKNOWN, - DNS_ERROR_UNLOADED, - DNS_ERROR_TIMEOUT, - DNS_ERROR_NOT_AN_ANSWER, - DNS_ERROR_NONSTANDARD_QUERY, - DNS_ERROR_FORMAT_ERROR, - DNS_ERROR_SERVER_FAILURE, - DNS_ERROR_DOMAIN_NOT_FOUND, - DNS_ERROR_NOT_IMPLEMENTED, - DNS_ERROR_REFUSED, - DNS_ERROR_NO_RECORDS, - DNS_ERROR_INVALIDTYPE -}; - - -struct CoreExport Question -{ - Anope::string name; - QueryType type; - unsigned short qclass; - - Question(); - Question(const Anope::string &, QueryType, unsigned short = 1); -}; - -struct CoreExport ResourceRecord : public Question -{ - unsigned int ttl; - Anope::string rdata; - time_t created; - - ResourceRecord(const Anope::string &, QueryType, unsigned short = 1); - ResourceRecord(const Question &); -}; - -struct CoreExport DNSQuery -{ - std::vector<Question> questions; - std::vector<ResourceRecord> answers, authorities, additional; - DNSError error; - - DNSQuery(); - DNSQuery(const Question &q); -}; - -/** The request - */ -class CoreExport DNSRequest : public Timer, public Question -{ - /* Use result cache if available */ - bool use_cache; - - public: - /* Request id */ - unsigned short id; - /* Creator of this request */ - Module *creator; - - DNSRequest(const Anope::string &addr, QueryType qt, bool cache = false, Module *c = NULL); - - virtual ~DNSRequest(); - - void Process(); - - virtual void OnLookupComplete(const DNSQuery *r) = 0; - - virtual void OnError(const DNSQuery *r); - void Tick(time_t) anope_override; -}; - -/** A full packet sent or recieved to/from the nameserver - */ -class DNSPacket : public DNSQuery +namespace DNS { - static const int DNS_POINTER = 0xC0; - static const int DNS_LABEL = 0x3F; - - void PackName(unsigned char *output, unsigned short output_size, unsigned short &pos, const Anope::string &name); - Anope::string UnpackName(const unsigned char *input, unsigned short input_size, unsigned short &pos); - Question UnpackQuestion(const unsigned char *input, unsigned short input_size, unsigned short &pos); - ResourceRecord UnpackResourceRecord(const unsigned char *input, unsigned short input_size, unsigned short &poss); - public: - static const int HEADER_LENGTH = 12; - - /* Source or destination of the packet */ - sockaddrs addr; - /* ID for this packet */ - unsigned short id; - /* Flags on the packet */ - unsigned short flags; - - DNSPacket(sockaddrs *a); - void Fill(const unsigned char *input, const unsigned short len); - unsigned short Pack(unsigned char *output, unsigned short output_size); -}; - -/** DNS manager - */ -class CoreExport DNSManager : public Timer -{ - class ReplySocket : public virtual Socket + /** Valid query types + */ + enum QueryType + { + /* Nothing */ + QUERY_NONE, + /* A simple A lookup */ + QUERY_A = 1, + /* An authoritative name server */ + QUERY_NS = 2, + /* A CNAME lookup */ + QUERY_CNAME = 5, + /* Start of a zone of authority */ + QUERY_SOA = 6, + /* Reverse DNS lookup */ + QUERY_PTR = 12, + /* IPv6 AAAA lookup */ + QUERY_AAAA = 28, + /* Zone transfer */ + QUERY_AXFR = 252 + }; + + /** Flags that can be AND'd into DNSPacket::flags to receive certain values + */ + enum { + QUERYFLAGS_QR = 0x8000, + QUERYFLAGS_OPCODE = 0x7800, + QUERYFLAGS_AA = 0x400, + QUERYFLAGS_TC = 0x200, + QUERYFLAGS_RD = 0x100, + QUERYFLAGS_RA = 0x80, + QUERYFLAGS_Z = 0x70, + QUERYFLAGS_RCODE = 0xF + }; + + enum Error + { + ERROR_NONE, + ERROR_UNKNOWN, + ERROR_UNLOADED, + ERROR_TIMEOUT, + ERROR_NOT_AN_ANSWER, + ERROR_NONSTANDARD_QUERY, + ERROR_FORMAT_ERROR, + ERROR_SERVER_FAILURE, + ERROR_DOMAIN_NOT_FOUND, + ERROR_NOT_IMPLEMENTED, + ERROR_REFUSED, + ERROR_NO_RECORDS, + ERROR_INVALIDTYPE + }; + + + struct CoreExport Question + { + Anope::string name; + QueryType type; + unsigned short qclass; + + Question(); + Question(const Anope::string &, QueryType, unsigned short = 1); + }; + + struct CoreExport ResourceRecord : public Question + { + unsigned int ttl; + Anope::string rdata; + time_t created; + + ResourceRecord(const Anope::string &, QueryType, unsigned short = 1); + ResourceRecord(const Question &); + }; + + struct CoreExport Query + { + std::vector<Question> questions; + std::vector<ResourceRecord> answers, authorities, additional; + Error error; + + Query(); + Query(const Question &q); + }; + + /** A DNS query. + */ + class CoreExport Request : public Timer, public Question + { + /* Use result cache if available */ + bool use_cache; + public: - virtual ~ReplySocket() { } - virtual void Reply(DNSPacket *p) = 0; + /* Request id */ + unsigned short id; + /* Creator of this request */ + Module *creator; + + Request(const Anope::string &addr, QueryType qt, bool cache = false, Module *c = NULL); + virtual ~Request(); + + void Process(); + + /** Called when this request succeeds + * @param r The query sent back from the nameserver + */ + virtual void OnLookupComplete(const Query *r) = 0; + + /** Called when this request fails or times out. + * @param r The query sent back from the nameserver, check the error code. + */ + virtual void OnError(const Query *r); + + /** Used to time out the query, Calls OnError and lets the TimerManager + * delete this request. + */ + void Tick(time_t) anope_override; }; - - /* Listens for TCP requests */ - class TCPSocket : public ListenSocket + + /** A full packet sent or recieved to/from the nameserver + */ + class Packet : public Query { - /* A TCP client */ - class Client : public ClientSocket, public Timer, public ReplySocket + static const int POINTER = 0xC0; + static const int LABEL = 0x3F; + + void PackName(unsigned char *output, unsigned short output_size, unsigned short &pos, const Anope::string &name); + Anope::string UnpackName(const unsigned char *input, unsigned short input_size, unsigned short &pos); + + Question UnpackQuestion(const unsigned char *input, unsigned short input_size, unsigned short &pos); + ResourceRecord UnpackResourceRecord(const unsigned char *input, unsigned short input_size, unsigned short &poss); + public: + static const int HEADER_LENGTH = 12; + + /* Source or destination of the packet */ + sockaddrs addr; + /* ID for this packet */ + unsigned short id; + /* Flags on the packet */ + unsigned short flags; + + Packet(sockaddrs *a); + void Fill(const unsigned char *input, const unsigned short len); + unsigned short Pack(unsigned char *output, unsigned short output_size); + }; + + /** DNS manager + */ + class CoreExport Manager : public Timer + { + class ReplySocket : public virtual Socket { - TCPSocket *tcpsock; - DNSPacket *packet; - unsigned char packet_buffer[524]; - int length; - public: - Client(TCPSocket *ls, int fd, const sockaddrs &addr); - ~Client(); - - /* Times out after a few seconds */ - void Tick(time_t) anope_override { } - void Reply(DNSPacket *p) anope_override; + virtual ~ReplySocket() { } + virtual void Reply(Packet *p) = 0; + }; + + /* Listens for TCP requests */ + class TCPSocket : public ListenSocket + { + /* A TCP client */ + class Client : public ClientSocket, public Timer, public ReplySocket + { + TCPSocket *tcpsock; + Packet *packet; + unsigned char packet_buffer[524]; + int length; + + public: + Client(TCPSocket *ls, int fd, const sockaddrs &addr); + ~Client(); + + /* Times out after a few seconds */ + void Tick(time_t) anope_override { } + void Reply(Packet *p) anope_override; + bool ProcessRead() anope_override; + bool ProcessWrite() anope_override; + }; + + public: + TCPSocket(const Anope::string &ip, int port); + + ClientSocket *OnAccept(int fd, const sockaddrs &addr) anope_override; + }; + + /* Listens for UDP requests */ + class UDPSocket : public ReplySocket + { + std::deque<Packet *> packets; + public: + + UDPSocket(const Anope::string &ip, int port); + ~UDPSocket(); + + void Reply(Packet *p) anope_override; + + std::deque<Packet *>& GetPackets() { return packets; } + bool ProcessRead() anope_override; + bool ProcessWrite() anope_override; }; - - public: - TCPSocket(const Anope::string &ip, int port); - - ClientSocket *OnAccept(int fd, const sockaddrs &addr) anope_override; - }; - - /* Listens for UDP requests */ - class UDPSocket : public ReplySocket - { - std::deque<DNSPacket *> packets; + + typedef std::multimap<Anope::string, ResourceRecord, ci::less> cache_map; + cache_map cache; + + bool listen; + uint32_t serial; + public: - - UDPSocket(const Anope::string &ip, int port); - ~UDPSocket(); - - void Reply(DNSPacket *p) anope_override; - - std::deque<DNSPacket *>& GetPackets() { return packets; } - - bool ProcessRead() anope_override; - - bool ProcessWrite() anope_override; + TCPSocket *tcpsock; + UDPSocket *udpsock; + + sockaddrs addrs; + std::map<unsigned short, Request *> requests; + + Manager(const Anope::string &nameserver, const Anope::string &ip, int port); + ~Manager(); + + bool HandlePacket(ReplySocket *s, const unsigned char *const data, int len, sockaddrs *from); + + /** Add a record to the dns cache + * @param r The record + */ + void AddCache(Query &r); + + /** Check the DNS cache to see if request can be handled by a cached result + * @return true if a cached result was found. + */ + bool CheckCache(Request *request); + + /** Tick this timer, used to clear the DNS cache. + */ + void Tick(time_t now) anope_override; + + /** Cleanup all pending DNS queries for a module + * @param mod The module + */ + void Cleanup(Module *mod); + + void UpdateSerial(); + uint32_t GetSerial() const; + + /** Does a BLOCKING DNS query and returns the first IP. + * Only use this if you know what you are doing. Unless you specifically + * need a blocking query use the DNSRequest system + */ + static Query BlockingQuery(const Anope::string &mask, QueryType qt); }; - - typedef std::multimap<Anope::string, ResourceRecord, ci::less> cache_map; - cache_map cache; - - bool listen; - uint32_t serial; - - public: - TCPSocket *tcpsock; - UDPSocket *udpsock; - - sockaddrs addrs; - std::map<unsigned short, DNSRequest *> requests; - - DNSManager(const Anope::string &nameserver, const Anope::string &ip, int port); - ~DNSManager(); - - bool HandlePacket(ReplySocket *s, const unsigned char *const data, int len, sockaddrs *from); - - /** Add a record to the dns cache - * @param r The record - */ - void AddCache(DNSQuery &r); - - /** Check the DNS cache to see if request can be handled by a cached result - * @return true if a cached result was found. - */ - bool CheckCache(DNSRequest *request); - - /** Tick this timer, used to clear the DNS cache. - */ - void Tick(time_t now) anope_override; - - /** Cleanup all pending DNS queries for a module - * @param mod The module - */ - void Cleanup(Module *mod); - - void UpdateSerial(); - uint32_t GetSerial() const; - - /** Does a BLOCKING DNS query and returns the first IP. - * Only use this if you know what you are doing. Unless you specifically - * need a blocking query use the DNSRequest system - */ - static DNSQuery BlockingQuery(const Anope::string &mask, QueryType qt); -}; - -extern CoreExport DNSManager *DNSEngine; - + + extern CoreExport Manager *Engine; + +} // namespace DNS + #endif // DNS_H - - + + diff --git a/include/extensible.h b/include/extensible.h index 6db4cf112..493dc20cf 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -1,7 +1,10 @@ /* - * Copyright (C) 2008-2012 Anope Team <team@anope.org> + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org * * Please read COPYING and README for further details. + * */ #ifndef EXTENSIBLE_H @@ -9,19 +12,28 @@ #include "anope.h" +/* All items added to Extensible must inherit from this. + */ class CoreExport ExtensibleItem { public: - ExtensibleItem(); - virtual ~ExtensibleItem(); - virtual void OnDelete(); + virtual ~ExtensibleItem() { } + + /* Called when this ExtensibleItem is being deleted. This should + * clean up things (eg, delete this;) if necessary. + */ + virtual void OnDelete() { delete this; } }; +/** Common class used to Extensible::Extend non-pointers from, as it doesn't delete + * itself when removed. Eg, obj->Extend(key, new ExtensibleItemClass<Anope::string>(value)); + */ template<typename T> struct CoreExport ExtensibleItemClass : T, ExtensibleItem { ExtensibleItemClass(const T& t) : T(t) { } }; +/* Used to attach arbitrary objects to this object using unique keys */ class CoreExport Extensible { private: @@ -33,7 +45,7 @@ class CoreExport Extensible */ Extensible() { } - /** Default destructor, deletes all of the extensible items in this object + /** Destructor, deletes all of the extensible items in this object * then clears the map */ virtual ~Extensible() diff --git a/include/extern.h b/include/extern.h deleted file mode 100644 index e8a47c209..000000000 --- a/include/extern.h +++ /dev/null @@ -1,108 +0,0 @@ -/* Prototypes and external variable declarations. - * - * (C) 2003-2012 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - */ - -#ifndef EXTERN_H -#define EXTERN_H - -#include "modes.h" - -#define E extern CoreExport -#define EI extern DllExport - - -/**** actions.c ****/ - -E bool bad_password(User *u); -E void common_unban(const ChannelInfo *ci, User *u, bool full = false); - -/**** encrypt.c ****/ - -E void enc_encrypt(const Anope::string &src, Anope::string &dest); -E bool enc_decrypt(const Anope::string &src, Anope::string &dest); - -/**** init.c ****/ - -E Anope::string conf_dir, db_dir, modules_dir, locale_dir, log_dir; - -E void introduce_user(const Anope::string &user); -E bool GetCommandLineArgument(const Anope::string &name, char shortname = 0); -E bool GetCommandLineArgument(const Anope::string &name, char shortname, Anope::string ¶m); -E bool AtTerm(); -E void Fork(); -E void Init(int ac, char **av); - -/**** language.cpp ****/ - -E std::vector<Anope::string> languages; -E std::vector<Anope::string> domains; -E void InitLanguages(); -E const char *translate(const char *string); -E const char *translate(User *u, const char *string); -E const char *translate(const NickCore *nc, const char *string); -E const char *anope_gettext(const char *lang, const char *string); - -/**** main.c ****/ - -E Anope::string services_dir; -E Anope::string services_bin; -E int debug; -E bool readonly; -E bool nofork; -E bool nothird; -E bool noexpire; -E bool protocoldebug; - -E bool quitting; -E int return_code; -E bool restarting; -E Anope::string quitmsg; -E time_t start_time; - -E int CurrentUplink; - -E void save_databases(); -E void sighandler(int signum); - -/**** misc.c ****/ - -E bool IsFile(const Anope::string &filename); - -E time_t dotime(const Anope::string &s); -E Anope::string duration(const time_t &seconds, const NickCore *nc = NULL); -E Anope::string expire_left(const NickCore *nc, time_t expires); -E Anope::string do_strftime(const time_t &t, const NickCore *nc = NULL, bool short_output = false); -E bool IsValidIdent(const Anope::string &ident); -E bool IsValidHost(const Anope::string &host); - -E Anope::string myStrGetToken(const Anope::string &str, char dilim, int token_number); -E Anope::string myStrGetTokenRemainder(const Anope::string &str, char dilim, int token_number); -E int myNumToken(const Anope::string &str, char dilim); -E bool nickIsServices(const Anope::string &nick, bool bot); - -E std::list<Anope::string> BuildStringList(const Anope::string &, char = ' '); -E std::vector<Anope::string> BuildStringVector(const Anope::string &, char = ' '); - -E bool str_is_wildcard(const Anope::string &str); -E bool str_is_pure_wildcard(const Anope::string &str); -E Anope::string normalizeBuffer(const Anope::string &); - -/**** modes.cpp ****/ - -/* Number of generic modes we support */ -E unsigned GenericChannelModes, GenericUserModes; -E std::multimap<ChannelModeName, ModeLock *> def_mode_locks; -E void SetDefaultMLock(ServerConfig *config); - -/**** process.c ****/ - -E void process(const Anope::string &buf); - -#endif /* EXTERN_H */ diff --git a/include/hashcomp.h b/include/hashcomp.h index 9f9be9793..74258151a 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -1,13 +1,10 @@ /* + * * Copyright (C) 2002-2011 InspIRCd Development Team * Copyright (C) 2009-2012 Anope Team <team@anope.org> * * Please read COPYING and README for further details. * - * These classes have been copied from InspIRCd and modified - * for use in Anope. - * - * */ #ifndef HASHCOMP_H @@ -28,13 +25,15 @@ namespace Anope { class string; + /* Casemap in use by Anope. ci::string's comparation functions use this (and thus Anope::string) */ extern std::locale casemap; - template<typename charT> - class ascii_ctype : public std::ctype<charT> + /* ASCII case insensitive ctype. */ + template<typename char_type> + class ascii_ctype : public std::ctype<char_type> { public: - charT do_toupper(charT c) const anope_override + char_type do_toupper(char_type c) const anope_override { if (c >= 'a' && c <= 'z') return c - 32; @@ -42,7 +41,7 @@ namespace Anope return c; } - charT do_tolower(charT c) const anope_override + char_type do_tolower(char_type c) const anope_override { if (c >= 'A' && c <= 'Z') return c + 32; @@ -51,29 +50,30 @@ namespace Anope } }; - template<typename charT> - class rfc1459_ctype : public ascii_ctype<charT> + /* rfc1459 case insensitive ctype, { = [, } = ], and | = \ */ + template<typename char_type> + class rfc1459_ctype : public ascii_ctype<char_type> { public: - charT do_toupper(charT c) const anope_override + char_type do_toupper(char_type c) const anope_override { if (c == '{' || c == '}' || c == '|') return c - 32; else - return ascii_ctype<charT>::do_toupper(c); + return ascii_ctype<char_type>::do_toupper(c); } - charT do_tolower(charT c) const anope_override + char_type do_tolower(char_type c) const anope_override { if (c == '[' || c == ']' || c == '\\') return c + 32; else - return ascii_ctype<charT>::do_tolower(c); + return ascii_ctype<char_type>::do_tolower(c); } }; } -/** The ci namespace contains a number of helper classes. +/** The ci namespace contains a number of helper classes relevant to case insensitive strings. */ namespace ci { diff --git a/include/language.h b/include/language.h index f48d9ce2d..eeb23af02 100644 --- a/include/language.h +++ b/include/language.h @@ -1,11 +1,67 @@ -/* Commonly used language strings +/* * * (C) 2008-2012 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. + * */ +namespace Language +{ + + /* Languages we support as configured in services.conf. They are + * added to this list if we detect a language exists in the correct + * location for each language. + */ + extern std::vector<Anope::string> Languages; + + /* Domains to search when looking for translations other than the + * default "anope domain. This is used by modules who add their own + * language files (and thus domains) to Anope. If a module is loaded + * and we detect a language file exists for at least one of the supported + * languages for the module, then we add the module's domain (its name) + * here. + * + * When strings are translated they are checked against all domains. + */ + extern std::vector<Anope::string> Domains; + + /** Initialize the language system. Finds valid language files and + * populates the Languages list. + */ + extern void InitLanguages(); + + /** Translates a string to the default language. + * @param string A string to translate + * @return The translated string if found, else the original string. + */ + extern const char *Translate(const char *string); + + /** Translates a string to the language of the given user. + * @param u The user to transate the string for + * @param string A string to translate + * @return The translated string if found, else the original string. + */ + extern const char *Translate(User *u, const char *string); + + /** Translates a string to the language of the given account. + * @param nc The account to translate the string for + * @param string A string to translate + * @return The translated string if count, else the original string + */ + extern const char *Translate(const NickCore *nc, const char *string); + + /** Translatesa string to the given language. + * @param lang The language to trnalsate to + * @param string The string to translate + * @return The translated string if found, else the original string. + */ + extern const char *Translate(const char *lang, const char *string); + +} // namespace Language + +/* Commonly used language strings */ #define MORE_INFO _("\002%s%s HELP %s\002 for more information.") #define BAD_USERHOST_MASK _("Mask must be in the form \037user\037@\037host\037.") #define BAD_EXPIRY_TIME _("Invalid expiry time.") diff --git a/include/lists.h b/include/lists.h index 841faf7a9..94d03aa4b 100644 --- a/include/lists.h +++ b/include/lists.h @@ -8,7 +8,6 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. * - * */ #ifndef LISTS_H @@ -48,9 +47,9 @@ class CoreExport NumberList void Process(); /** Called with a number from the list - * @param Number The number + * @param number The number */ - virtual void HandleNumber(unsigned 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 @@ -71,9 +70,9 @@ class CoreExport ListFormatter std::vector<Anope::string> columns; std::vector<ListEntry> entries; public: - ListFormatter &addColumn(const Anope::string &name); - void addEntry(const ListEntry &entry); - bool isEmpty() const; + ListFormatter &AddColumn(const Anope::string &name); + void AddEntry(const ListEntry &entry); + bool IsEmpty() const; void Process(std::vector<Anope::string> &); }; diff --git a/include/logger.h b/include/logger.h index 5df81a5bc..1f674467a 100644 --- a/include/logger.h +++ b/include/logger.h @@ -18,8 +18,13 @@ enum LogType { + /* Used whenever an administrator uses an administrative comand */ LOG_ADMIN, + /* Used whenever an administrator overides something, such as adding + * access to a channel where they don't have permission to. + */ LOG_OVERRIDE, + /* Any other command usage */ LOG_COMMAND, LOG_SERVER, LOG_CHANNEL, @@ -37,30 +42,37 @@ enum LogType struct LogFile { Anope::string filename; - - public: std::ofstream stream; LogFile(const Anope::string &name); Anope::string GetName() const; }; - +/* Represents a single log message */ class CoreExport Log { public: + /* Bot that should log this message */ const BotInfo *bi; + /* For commands, the user executing the command */ Anope::string nick; + /* For commands, the user executing the command, but might not always exist */ const User *u; + /* For commands, the account executing teh command, but will not always exist */ const NickCore *nc; + /* For commands, the command being executed */ Command *c; + /* Used for LOG_CHANNEL */ Channel *chan; + /* For commands, the channel the command was executed on, will not always exist */ const ChannelInfo *ci; + /* For LOG_SERVER */ Server *s; + /* For LOG_MODULE */ Module *m; - LogType Type; - Anope::string Category; - std::list<Anope::string> Sources; + LogType type; + Anope::string category; + std::list<Anope::string> sources; std::stringstream buf; @@ -93,22 +105,23 @@ class CoreExport Log } }; +/* Configured in the configuration file, actually does the message logging */ class CoreExport LogInfo { public: - std::list<Anope::string> Targets; - std::map<Anope::string, LogFile *> Logfiles; - std::list<Anope::string> Sources; - int LogAge; - std::list<Anope::string> Admin; - std::list<Anope::string> Override; - std::list<Anope::string> Commands; - std::list<Anope::string> Servers; - std::list<Anope::string> Users; - std::list<Anope::string> Channels; - std::list<Anope::string> Normal; - bool RawIO; - bool Debug; + std::list<Anope::string> targets; + std::map<Anope::string, LogFile *> logfiles; + std::list<Anope::string> sources; + int log_age; + std::list<Anope::string> admin; + std::list<Anope::string> override; + std::list<Anope::string> commands; + std::list<Anope::string> servers; + std::list<Anope::string> users; + std::list<Anope::string> channels; + std::list<Anope::string> normal; + bool raw_io; + bool debug; LogInfo(int logage, bool rawio, bool debug); @@ -118,6 +131,7 @@ class CoreExport LogInfo bool HasType(LogType ltype, const Anope::string &type) const; + /* Logs the message l if configured to */ void ProcessMessage(const Log *l); }; diff --git a/include/mail.h b/include/mail.h index 493002637..2b513c849 100644 --- a/include/mail.h +++ b/include/mail.h @@ -18,28 +18,41 @@ #include "threadengine.h" #include "serialize.h" -extern CoreExport bool Mail(User *u, NickCore *nc, const BotInfo *service, const Anope::string &subject, const Anope::string &message); -extern CoreExport bool Mail(NickCore *nc, const Anope::string &subject, const Anope::string &message); -extern CoreExport bool MailValidate(const Anope::string &email); - -class MailThread : public Thread +namespace Mail { - private: - Anope::string SendMailPath; - Anope::string SendFrom; - Anope::string MailTo; - Anope::string Addr; - Anope::string Subject; - Anope::string Message; - bool DontQuoteAddresses; - - bool Success; - public: - MailThread(const Anope::string &smpath, const Anope::string &sf, const Anope::string &mailto, const Anope::string &addr, const Anope::string &subject, const Anope::string &message); - - ~MailThread(); - - void Run(); -}; + extern CoreExport bool Send(User *from, NickCore *to, const BotInfo *service, const Anope::string &subject, const Anope::string &message); + extern CoreExport bool Send(NickCore *to, const Anope::string &subject, const Anope::string &message); + extern CoreExport bool Validate(const Anope::string &email); + + /* A email message being sent */ + class Message : public Thread + { + private: + Anope::string sendmail_path; + Anope::string send_from; + Anope::string mail_to; + Anope::string addr; + Anope::string subject; + Anope::string message; + bool dont_quote_addresses; + + bool success; + public: + /** Construct this message. Once constructed call Thread::Start to launch the mail sending. + * @param sf Config->SendFrom + * @param mailto Name of person being mailed (u->nick, nc->display, etc) + * @param addr Destination address to mail + * @param subject Message subject + * @param message The actual message + */ + Message(const Anope::string &sf, const Anope::string &mailto, const Anope::string &addr, const Anope::string &subject, const Anope::string &message); + + ~Message(); + + /* Called from within the thread to actually send the mail */ + void Run() anope_override; + }; + +} // namespace Mail #endif // MAIL_H diff --git a/include/memo.h b/include/memo.h index 1879f89b3..9fdbb3cab 100644 --- a/include/memo.h +++ b/include/memo.h @@ -8,7 +8,6 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. * - * */ #ifndef MEMO_H @@ -27,30 +26,28 @@ enum MemoFlag MF_RECEIPT }; -const Anope::string MemoFlagStrings[] = { - "MF_UNREAD", "MF_RECEIPT", "" -}; - -/* Memo info structures. Since both nicknames and channels can have memos, - * we encapsulate memo data in a MemoList to make it easier to handle. */ class CoreExport Memo : public Flags<MemoFlag>, public Serializable { public: Memo(); - Serialize::Data serialize() const anope_override; - static Serializable* unserialize(Serializable *obj, Serialize::Data &); + Serialize::Data Serialize() const anope_override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); Anope::string owner; - time_t time; /* When it was sent */ + /* When it was sent */ + time_t time; Anope::string sender; Anope::string text; }; +/* Memo info structures. Since both nicknames and channels can have memos, + * we encapsulate memo data in a MemoInfo to make it easier to handle. + */ struct CoreExport MemoInfo { int16_t memomax; - serialize_checker<std::vector<Memo *> > memos; + Serialize::Checker<std::vector<Memo *> > memos; std::vector<Anope::string> ignores; MemoInfo(); diff --git a/include/messages.h b/include/messages.h index 1a577ae85..1ef9638ff 100644 --- a/include/messages.h +++ b/include/messages.h @@ -1,126 +1,161 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + */ + #include "protocol.h" - + /* Common IRCD messages. * Protocol modules may chose to include some, none, or all of these handlers * as they see fit. */ - -struct CoreExport CoreIRCDMessageAway : IRCDMessage -{ - CoreIRCDMessageAway(const Anope::string &mname = "AWAY") : IRCDMessage(mname, 0) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageCapab : IRCDMessage -{ - CoreIRCDMessageCapab(const Anope::string &mname = "CAPAB") : IRCDMessage(mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageError : IRCDMessage -{ - CoreIRCDMessageError(const Anope::string &mname = "ERROR") : IRCDMessage(mname, 1) { } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageJoin : IRCDMessage -{ - CoreIRCDMessageJoin(const Anope::string &mname = "JOIN") : IRCDMessage(mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageKick : IRCDMessage -{ - CoreIRCDMessageKick(const Anope::string &mname = "KICK") : IRCDMessage(mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageKill : IRCDMessage -{ - CoreIRCDMessageKill(const Anope::string &mname = "KILL") : IRCDMessage(mname, 2) { } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageMOTD : IRCDMessage -{ - CoreIRCDMessageMOTD(const Anope::string &mname = "MOTD") : IRCDMessage(mname, 1) { } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessagePart : IRCDMessage -{ - CoreIRCDMessagePart(const Anope::string &mname = "PART") : IRCDMessage(mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessagePing : IRCDMessage -{ - CoreIRCDMessagePing(const Anope::string &mname = "PING") : IRCDMessage(mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessagePrivmsg : IRCDMessage -{ - CoreIRCDMessagePrivmsg(const Anope::string &mname = "PRIVMSG") : IRCDMessage(mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageQuit : IRCDMessage -{ - CoreIRCDMessageQuit(const Anope::string &mname = "QUIT") : IRCDMessage(mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageSQuit : IRCDMessage -{ - CoreIRCDMessageSQuit(const Anope::string &mname = "SQUIT") : IRCDMessage(mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageStats : IRCDMessage -{ - CoreIRCDMessageStats(const Anope::string &mname = "STATS") : IRCDMessage(mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageTime : IRCDMessage -{ - CoreIRCDMessageTime(const Anope::string &mname = "TIME") : IRCDMessage(mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageTopic : IRCDMessage -{ - CoreIRCDMessageTopic(const Anope::string &mname = "TOPIC") : IRCDMessage(mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageVersion : IRCDMessage -{ - CoreIRCDMessageVersion(const Anope::string &mname = "VERSION") : IRCDMessage(mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - -struct CoreExport CoreIRCDMessageWhois : IRCDMessage -{ - CoreIRCDMessageWhois(const Anope::string &mname = "WHOIS") : IRCDMessage(mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; -}; - + +namespace Message +{ + + struct CoreExport Away : IRCDMessage + { + Away(Module *creator, const Anope::string &mname = "AWAY") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Capab : IRCDMessage + { + Capab(Module *creator, const Anope::string &mname = "CAPAB") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Error : IRCDMessage + { + Error(Module *creator, const Anope::string &mname = "ERROR") : IRCDMessage(creator, mname, 1) { } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Join : IRCDMessage + { + Join(Module *creator, const Anope::string &mname = "JOIN") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + + typedef std::pair<ChannelStatus, User *> SJoinUser; + + /** Handle a SJOIN. + * @param source The source of the SJOIN + * @param chan The channel the users are joining to + * @param ts The TS for the channel + * @param modes The modes sent with the SJOIN, if any + * @param users The users and their status, if any + */ + static void SJoin(MessageSource &source, const Anope::string &chan, time_t ts, const Anope::string &modes, const std::list<SJoinUser> &users); + }; + + struct CoreExport Kick : IRCDMessage + { + Kick(Module *creator, const Anope::string &mname = "KICK") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Kill : IRCDMessage + { + Kill(Module *creator, const Anope::string &mname = "KILL") : IRCDMessage(creator, mname, 2) { } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Mode : IRCDMessage + { + Mode(Module *creator, const Anope::string &mname = "MODE") : IRCDMessage(creator, mname, 2) { } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport MOTD : IRCDMessage + { + MOTD(Module *creator, const Anope::string &mname = "MOTD") : IRCDMessage(creator, mname, 1) { } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Part : IRCDMessage + { + Part(Module *creator, const Anope::string &mname = "PART") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Ping : IRCDMessage + { + Ping(Module *creator, const Anope::string &mname = "PPING") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Privmsg : IRCDMessage + { + Privmsg(Module *creator, const Anope::string &mname = "PRIVMSG") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Quit : IRCDMessage + { + Quit(Module *creator, const Anope::string &mname = "QUIT") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport SQuit : IRCDMessage + { + SQuit(Module *creator, const Anope::string &mname = "SQUIT") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Stats : IRCDMessage + { + Stats(Module *creator, const Anope::string &mname = "STATS") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Time : IRCDMessage + { + Time(Module *creator, const Anope::string &mname = "TIME") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Topic : IRCDMessage + { + Topic(Module *creator, const Anope::string &mname = "TOPIC") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Version : IRCDMessage + { + Version(Module *creator, const Anope::string &mname = "VERSION") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + + struct CoreExport Whois : IRCDMessage + { + Whois(Module *creator, const Anope::string &mname = "WHOIS") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override; + }; + +} // namespace Message + diff --git a/include/modes.h b/include/modes.h index 1bd928ed1..b38ef3dc1 100644 --- a/include/modes.h +++ b/include/modes.h @@ -27,18 +27,6 @@ enum UserModeName UMODE_END }; -const Anope::string UserModeNameStrings[] = { - "UMODE_BEGIN", - - "UMODE_SERV_ADMIN", "UMODE_BOT", "UMODE_CO_ADMIN", "UMODE_FILTER", "UMODE_HIDEOPER", "UMODE_NETADMIN", - "UMODE_REGPRIV", "UMODE_PROTECTED", "UMODE_NOCTCP", "UMODE_WEBTV", "UMODE_WEBIRC", "UMODE_WHOIS", "UMODE_ADMIN", "UMODE_DEAF", - "UMODE_GLOBOPS", "UMODE_HELPOP", "UMODE_INVIS", "UMODE_OPER", "UMODE_PRIV", "UMODE_GOD", "UMODE_REGISTERED", - "UMODE_SNOMASK", "UMODE_VHOST", "UMODE_WALLOPS", "UMODE_CLOAK", "UMODE_SSL", "UMODE_SOFTCALLERID", "UMODE_CALLERID", - "UMODE_COMMONCHANS", "UMODE_HIDDEN", "UMODE_STRIPCOLOR", "UMODE_INVISIBLE_OPER", "UMODE_RESTRICTED", "UMODE_HIDEIDLE", - - "" -}; - /** All of the valid channel mode names */ enum ChannelModeName @@ -64,29 +52,6 @@ enum ChannelModeName CMODE_END }; -const Anope::string ChannelModeNameStrings[] = { - "CMODE_BEGIN", - - /* Channel modes */ - "CMODE_BLOCKCOLOR", "CMODE_FLOOD", "CMODE_INVITE", "CMODE_KEY", "CMODE_LIMIT", "CMODE_MODERATED", "CMODE_NOEXTERNAL", - "CMODE_PRIVATE", "CMODE_REGISTERED", "CMODE_SECRET", "CMODE_TOPIC", "CMODE_AUDITORIUM", "CMODE_SSL", "CMODE_ADMINONLY", - "CMODE_NOCTCP", "CMODE_FILTER", "CMODE_NOKNOCK", "CMODE_REDIRECT", "CMODE_REGMODERATED", "CMODE_NONICK", "CMODE_OPERONLY", - "CMODE_NOKICK", "CMODE_REGISTEREDONLY", "CMODE_STRIPCOLOR", "CMODE_NONOTICE", "CMODE_NOINVITE", "CMODE_ALLINVITE", - "CMODE_BLOCKCAPS", "CMODE_PERM", "CMODE_NICKFLOOD", "CMODE_JOINFLOOD", "CMODE_DELAYEDJOIN", "CMODE_NOREJOIN", - "CMODE_BANDWIDTH", - - /* b/e/I */ - "CMODE_BAN", "CMODE_EXCEPT", - "CMODE_INVITEOVERRIDE", - - /* v/h/o/a/q */ - "CMODE_VOICE", "CMODE_HALFOP", "CMODE_OP", - "CMODE_PROTECT", "CMODE_OWNER", - - "" -}; - - /** The different types of modes */ enum ModeType @@ -105,9 +70,7 @@ enum ModeType */ enum ModeClass { - /* Channel mode */ MC_CHANNEL, - /* User mode */ MC_USER }; @@ -116,22 +79,19 @@ enum ModeClass class CoreExport Mode : public Base { public: - /* Class of mode this is */ - ModeClass Class; - /* Mode char for this */ - char ModeChar; - /* Type of mode this is */ - ModeType Type; - - /** Default constructor - * @param mClass The type of mode this is - * @param modeChar The mode char + /* Class of mode this is (user/channel) */ + ModeClass mclass; + /* Mode char for this, eg 'b' */ + char mchar; + /* Type of mode this is, eg MODE_LIST */ + ModeType type; + + /** constructor + * @param mclass The type of mode this is + * @param mc The mode char * @param type The mode type */ - Mode(ModeClass mClass, char modeChar, ModeType type); - - /** Default destructor - */ + Mode(ModeClass mclass, char mc, ModeType type); virtual ~Mode(); }; @@ -141,16 +101,13 @@ class CoreExport UserMode : public Mode { public: /* Mode name */ - UserModeName Name; - - /** Default constructor - * @param nName The mode name - * @param modeChar The mode char - */ - UserMode(UserModeName mName, char modeChar); + UserModeName name; - /** Default destructor + /** constructor + * @param name The mode name + * @param mc The mode char */ + UserMode(UserModeName name, char mc); virtual ~UserMode(); /** Returns the mode name as a string @@ -161,11 +118,11 @@ class CoreExport UserMode : public Mode class CoreExport UserModeParam : public UserMode { public: - /** Default constructor - * @param mName The mode name - * @param modeChar The mode char + /** constructor + * @param name The mode name + * @param mc The mode char */ - UserModeParam(UserModeName mName, char modeChar); + UserModeParam(UserModeName name, char mc); /** Check if the param is valid * @param value The param @@ -180,16 +137,13 @@ class CoreExport ChannelMode : public Mode { public: /* Mode name */ - ChannelModeName Name; + ChannelModeName name; - /** Default constructor - * @param mName The mode name - * @param modeChar The mode char - */ - ChannelMode(ChannelModeName mName, char modeChar); - - /** Default destructor + /** constructor + * @param name The mode name + * @param mc The mode char */ + ChannelMode(ChannelModeName name, char mc); virtual ~ChannelMode(); /** Can a user set this mode, used for mlock @@ -209,13 +163,13 @@ class CoreExport ChannelMode : public Mode class CoreExport ChannelModeList : public ChannelMode { public: - /** Default constructor - * @param mName The mode name - * @param modeChar The mode char + /** constructor + * @param name The mode name + * @param mc The mode char */ - ChannelModeList(ChannelModeName mName, char modeChar); + ChannelModeList(ChannelModeName name, char mc); - /** Default destructor + /** destructor */ virtual ~ChannelModeList(); @@ -251,19 +205,19 @@ class CoreExport ChannelModeList : public ChannelMode class CoreExport ChannelModeParam : public ChannelMode { public: - /** Default constructor - * @param mName The mode name - * @param modeChar The mode char - * @param MinusArg true if this mode sends no arg when unsetting + /** constructor + * @param name The mode name + * @param mc The mode char + * @param minus_no_arg true if this mode sends no arg when unsetting */ - ChannelModeParam(ChannelModeName mName, char modeChar, bool MinusArg = false); + ChannelModeParam(ChannelModeName name, char mc, bool minus_no_arg = false); - /** Default destructor + /** destructor */ virtual ~ChannelModeParam(); /* Should we send an arg when unsetting this mode? */ - bool MinusNoArg; + bool minus_no_arg; /** Is the param valid * @param value The param @@ -284,25 +238,33 @@ class CoreExport ChannelModeStatus : public ChannelMode */ unsigned short Level; - /** Default constructor - * @param mName The mode name - * @param modeChar The mode char + /** constructor + * @param name The mode name + * @param mc The mode char * @param mSymbol The symbol for the mode, eg @ % * @param mLevel A level for the mode, which is usually determined by the PREFIX capab */ - ChannelModeStatus(ChannelModeName mName, char modeChar, char mSymbol, unsigned short mLevel = 0); + ChannelModeStatus(ChannelModeName name, char mc, char mSymbol, unsigned short mLevel = 0); - /** Default destructor + /** destructor */ virtual ~ChannelModeStatus(); }; +/* The status a user has on a channel (+v, +h, +o) etc */ +class CoreExport ChannelStatus : public Flags<ChannelModeName> +{ + public: + Anope::string BuildCharPrefixList() const; + Anope::string BuildModePrefixList() const; +}; + /** Channel mode +k (key) */ class CoreExport ChannelModeKey : public ChannelModeParam { public: - ChannelModeKey(char modeChar) : ChannelModeParam(CMODE_KEY, modeChar) { } + ChannelModeKey(char mc) : ChannelModeParam(CMODE_KEY, mc) { } bool IsValid(const Anope::string &value) const anope_override; }; @@ -313,7 +275,7 @@ class CoreExport ChannelModeKey : public ChannelModeParam class CoreExport ChannelModeAdmin : public ChannelMode { public: - ChannelModeAdmin(char modeChar) : ChannelMode(CMODE_ADMINONLY, modeChar) { } + ChannelModeAdmin(char mc) : ChannelMode(CMODE_ADMINONLY, mc) { } /* Opers only */ bool CanSet(User *u) const anope_override; @@ -325,7 +287,7 @@ class CoreExport ChannelModeAdmin : public ChannelMode class CoreExport ChannelModeOper : public ChannelMode { public: - ChannelModeOper(char modeChar) : ChannelMode(CMODE_OPERONLY, modeChar) { } + ChannelModeOper(char mc) : ChannelMode(CMODE_OPERONLY, mc) { } /* Opers only */ bool CanSet(User *u) const anope_override; @@ -337,7 +299,7 @@ class CoreExport ChannelModeOper : public ChannelMode class CoreExport ChannelModeRegistered : public ChannelMode { public: - ChannelModeRegistered(char modeChar) : ChannelMode(CMODE_REGISTERED, modeChar) { } + ChannelModeRegistered(char mc) : ChannelMode(CMODE_REGISTERED, mc) { } /* No one mlocks +r */ bool CanSet(User *u) const anope_override; @@ -355,17 +317,17 @@ class StackerInfo /** Add a mode to this object * @param mode The mode - * @param Set true if setting, false if unsetting - * @param Param The param for the mode + * @param set true if setting, false if unsetting + * @param param The param for the mode */ - void AddMode(Mode *mode, bool Set, const Anope::string &Param); + void AddMode(Mode *mode, bool set, const Anope::string ¶m); }; -/** This is mode manager +/** This is the mode manager * It contains functions for adding modes to Anope so Anope can track them * and do things such as MLOCK. * This also contains a mode stacker that will combine multiple modes and set - * them on a channel all at once + * them on a channel or user at once */ class CoreExport ModeManager { @@ -385,6 +347,13 @@ class CoreExport ModeManager static std::vector<ChannelMode *> ChannelModes; static std::vector<UserMode *> UserModes; + /* Number of generic channel and user modes we are tracking */ + static unsigned GenericChannelModes, GenericUserModes; + /* Default channel mode lock */ + static std::multimap<ChannelModeName, ModeLock *> DefaultModeLocks; + /* Default modes bots have on channels */ + static ChannelStatus DefaultBotModes; + /** Add a user mode to Anope * @param um A UserMode or UserMode derived class * @return true on success, false on error @@ -397,29 +366,39 @@ class CoreExport ModeManager */ static bool AddChannelMode(ChannelMode *cm); + /** Remove a user mode from Anope + * @param um A UserMode to remove + */ + static void RemoveUserMode(UserMode *um); + + /** Remove a channel mode from Anope + * @param um A ChanneMode to remove + */ + static void RemoveChannelMode(ChannelMode *cm); + /** Find a channel mode - * @param Mode The mode + * @param mode The mode * @return The mode class */ - static ChannelMode *FindChannelModeByChar(char Mode); + static ChannelMode *FindChannelModeByChar(char mode); /** Find a user mode - * @param Mode The mode + * @param mode The mode * @return The mode class */ - static UserMode *FindUserModeByChar(char Mode); + static UserMode *FindUserModeByChar(char mode); /** Find a channel mode - * @param Mode The modename + * @param name The modename * @return The mode class */ - static ChannelMode *FindChannelModeByName(ChannelModeName Name); + static ChannelMode *FindChannelModeByName(ChannelModeName name); /** Find a user mode - * @param Mode The modename + * @param name The modename * @return The mode class */ - static UserMode *FindUserModeByName(UserModeName Name); + static UserMode *FindUserModeByName(UserModeName name); /** Find channel mode by string * @param name The mode name @@ -434,37 +413,44 @@ class CoreExport ModeManager static UserMode *FindUserModeByString(const Anope::string &name); /** Gets the channel mode char for a symbol (eg + returns v) - * @param Value The symbol + * @param symbol The symbol * @return The char */ - static char GetStatusChar(char Value); + static char GetStatusChar(char symbol); /** Add a mode to the stacker to be set on a channel * @param bi The client to set the modes from * @param c The channel * @param cm The channel mode - * @param Set true for setting, false for removing - * @param Param The param, if there is one + * @param set true for setting, false for removing + * @param param The param, if there is one */ - static void StackerAdd(const BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param = ""); + static void StackerAdd(const BotInfo *bi, Channel *c, ChannelMode *cm, bool set, const Anope::string ¶m = ""); /** Add a mode to the stacker to be set on a user * @param bi The client to set the modes from * @param u The user * @param um The user mode - * @param Set true for setting, false for removing + * @param set true for setting, false for removing * @param param The param, if there is one */ - static void StackerAdd(const BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param = ""); + static void StackerAdd(const BotInfo *bi, User *u, UserMode *um, bool set, const Anope::string ¶m = ""); /** Process all of the modes in the stacker and send them to the IRCd to be set on channels/users */ static void ProcessModes(); - /** Delete a user or channel from the stacker + /** Delete a user, channel, or mode from the stacker */ static void StackerDel(User *u); static void StackerDel(Channel *c); + static void StackerDel(Mode *m); + + /** Updates the default mode locks and default bot modes + * @param config The configuration to read from. This is often called + * during a config reload. + */ + static void UpdateDefaultMLock(ServerConfig *config); }; /** Entry flags @@ -493,10 +479,10 @@ class CoreExport Entry : public Flags<EntryType> Anope::string nick, user, host; /** Constructor - * @param _host A full nick!ident@host/cidr mask * @param mode What mode this host is for - can be CMODE_BEGIN for unknown/no mode + * @param host A full nick!ident@host/cidr mask */ - Entry(ChannelModeName mode, const Anope::string &_host); + Entry(ChannelModeName mode, const Anope::string &host); /** Get the banned mask for this entry * @return The mask diff --git a/include/module.h b/include/module.h index bba901741..e6b63bdfb 100644 --- a/include/module.h +++ b/include/module.h @@ -18,13 +18,11 @@ #include "anope.h" #include "base.h" #include "bots.h" -#include "botserv.h" #include "channels.h" #include "commands.h" #include "config.h" #include "dns.h" #include "extensible.h" -#include "extern.h" #include "hashcomp.h" #include "language.h" #include "lists.h" @@ -34,7 +32,6 @@ #include "messages.h" #include "modes.h" #include "modules.h" -#include "oper.h" #include "opertype.h" #include "protocol.h" #include "regexpr.h" @@ -50,9 +47,14 @@ #include "timers.h" #include "uplink.h" #include "users.h" +#include "xline.h" +#include "chanserv.h" +#include "botserv.h" #include "global.h" +#include "hostserv.h" #include "memoserv.h" #include "nickserv.h" +#include "operserv.h" #endif // MODULE_H diff --git a/include/modules.h b/include/modules.h index cdaf53fc0..e62ed8e36 100644 --- a/include/modules.h +++ b/include/modules.h @@ -7,6 +7,7 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. + * */ #include "serialize.h" @@ -31,7 +32,7 @@ { \ return new x(modname, creator); \ } \ - BOOLEAN WINAPI DllMain(HINSTANCE, DWORD nReason, LPVOID) \ + BOOLEAN WINAPI DllMain(HINSTANCE, DWORD, LPVOID) \ { \ return TRUE; \ } \ @@ -120,7 +121,6 @@ enum EventReturn EVENT_ALLOW }; - enum ModuleReturn { MOD_ERR_OK, @@ -141,26 +141,23 @@ enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFOR /* Module types, in the order in which they are unloaded. The order these are in is IMPORTANT */ enum ModType { MT_BEGIN, THIRD, SUPPORTED, CORE, DATABASE, ENCRYPTION, PROTOCOL, MT_END }; -extern CoreExport std::list<Module *> Modules; - +/** Returned by Module::GetVersion, used to see what version of Anope + * a module is compiled against. + */ class ModuleVersion { private: - int Major; - int Minor; - int Patch; + int version_major; + int version_minor; + int version_patch; public: /** Constructor - * @param vMajor The major version numbber - * @param vMinor The minor version numbber - * @param vPatch The patch version numbber - */ - ModuleVersion(int vMajor, int vMinor, int vPatch); - - /** Destructor + * @param major The major version numbber + * @param minor The minor version numbber + * @param patch The patch version numbber */ - virtual ~ModuleVersion(); + ModuleVersion(int major, int minor, int patch); /** Get the major version of Anope this was built against * @return The major version @@ -200,7 +197,7 @@ class CoreExport Module : public Extensible /** Callbacks used in this module */ - std::list<CallBack *> CallBacks; + std::list<CallBack *> callbacks; /** Handle for this module, obtained from dlopen() */ @@ -259,6 +256,14 @@ class CoreExport Module : public Extensible */ ModuleVersion GetVersion() const; + /** Gets the IRCd protocol published by this module + */ + virtual IRCDProto *GetIRCDProto(); + + /* Everything below here are events. Modules must ModuleManager::Attach to these events + * before they will be called. + */ + /** Called when the ircd notifies that a user has been kicked from a channel. * @param c The channel the user has been kicked from. * @param target The user that has been kicked. @@ -290,7 +295,7 @@ class CoreExport Module : public Extensible * @param u The connecting user. * @param exempt set to true/is true if the user should be excepted from bans etc */ - virtual void OnUserConnect(dynamic_reference<User> &u, bool &exempt) { } + virtual void OnUserConnect(Reference<User> &u, bool &exempt) { } /** Called when a new server connects to the network. * @param s The server that has connected to the network @@ -649,9 +654,9 @@ class CoreExport Module : public Extensible * @param source The user requesting info * @param ci The channel the user is requesting info for * @param info Data to show the user requesting information - * @param ShowHidden true if we should show the user everything + * @param show_hidden true if we should show the user everything */ - virtual void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool ShowHidden) { } + virtual void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) { } /** Checks if access has the channel privilege 'priv'. * @param access THe access struct @@ -763,9 +768,9 @@ class CoreExport Module : public Extensible * @param source The user requesting info * @param na The nick the user is requesting info from * @param info Data to show the user requesting information - * @param ShowHidden true if we should show the user everything + * @param show_hidden true if we should show the user everything */ - virtual void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool ShowHidden) { } + virtual void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) { } /** Check whether a username and password is correct * @param u The user trying to identify, if applicable. @@ -824,32 +829,32 @@ class CoreExport Module : public Extensible /** Called when a mode is set on a channel * @param c The channel * @param setter The user or server that is setting the mode - * @param Name The mode name + * @param mname The mode name * @param param The mode param, if there is one * @return EVENT_STOP to make mlock/secureops etc checks not happen */ - virtual EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelModeName Name, const Anope::string ¶m) { return EVENT_CONTINUE; } + virtual EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelModeName mname, const Anope::string ¶m) { return EVENT_CONTINUE; } /** Called when a mode is unset on a channel * @param c The channel * @param setter The user or server that is unsetting the mode - * @param Name The mode name + * @param mname The mode name * @param param The mode param, if there is one * @return EVENT_STOP to make mlock/secureops etc checks not happen */ - virtual EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelModeName Name, const Anope::string ¶m) { return EVENT_CONTINUE; } + virtual EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelModeName mname, const Anope::string ¶m) { return EVENT_CONTINUE; } /** Called when a mode is set on a user * @param u The user - * @param Name The mode name + * @param mname The mode name */ - virtual void OnUserModeSet(User *u, UserModeName Name) { } + virtual void OnUserModeSet(User *u, UserModeName mname) { } /** Called when a mode is unset from a user * @param u The user - * @param Name The mode name + * @param mname The mode name */ - virtual void OnUserModeUnset(User *u, UserModeName Name) { } + virtual void OnUserModeUnset(User *u, UserModeName mname) { } /** Called when a channel mode is introducted into Anope * @param cm The mode @@ -921,7 +926,7 @@ class CoreExport Module : public Extensible * @param req The dns request * @param reply The reply that will be sent */ - virtual void OnDnsRequest(DNSPacket &req, DNSPacket *reply) { } + virtual void OnDnsRequest(DNS::Packet &req, DNS::Packet *reply) { } /** Called when a channels modes are being checked to see if they are allowed, * mostly to ensure mlock/+r are set. @@ -930,7 +935,7 @@ class CoreExport Module : public Extensible */ virtual EventReturn OnCheckModes(Channel *c) { return EVENT_CONTINUE; } - virtual void OnSerializeCheck(SerializeType *) { } + virtual void OnSerializeCheck(Serialize::Type *) { } virtual void OnSerializableConstruct(Serializable *) { } virtual void OnSerializableDestruct(Serializable *) { } virtual void OnSerializableUpdate(Serializable *) { } @@ -1012,6 +1017,10 @@ enum Implementation class CoreExport ModuleManager { public: + /** List of all modules loaded in Anope + */ + static CoreExport std::list<Module *> Modules; + /** Event handler hooks. * This needs to be public to be used by FOREACH_MOD and friends. */ @@ -1124,7 +1133,8 @@ class CoreExport ModuleManager static ModuleReturn DeleteModule(Module *m); }; -/** Class used for callbacks within modules +/** Class used for callbacks within modules. These are identical to Timers hwoever + * they will be cleaned up automatically when a module is unloaded, and Timers will not. */ class CoreExport CallBack : public Timer { diff --git a/include/opertype.h b/include/opertype.h index 4e3f01e28..ccba85141 100644 --- a/include/opertype.h +++ b/include/opertype.h @@ -3,6 +3,7 @@ * Copyright (C) 2008-2012 Anope Team <team@anope.org> * * Please read COPYING and README for further details. + * */ #ifndef OPERTYPE_H @@ -11,15 +12,22 @@ #include "services.h" #include "account.h" +/* A services operator. Usually made by the configuration file, but not always. + * NickAlias::Find(name)->nc->o == this + */ struct CoreExport Oper { + /* The oper's nick */ Anope::string name; + /* The type of operator this operator is */ OperType *ot; + /* Whether the user must be an IRC operator (umode +o) to be considered a services operator */ bool require_oper; Anope::string password; Anope::string certfp; + /* True if this operator is set in the config */ bool config; - + /* Hosts allowed to use this operator block */ std::vector<Anope::string> hosts; Anope::string vhost; diff --git a/include/protocol.h b/include/protocol.h index 4da0b5b3a..ec7061d38 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -8,7 +8,6 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. * - * */ #ifndef PROTOCOL_H @@ -16,14 +15,17 @@ #include "services.h" #include "anope.h" +#include "service.h" +/* Encapsultes the IRCd protocol we are speaking. */ class CoreExport IRCDProto { Anope::string proto_name; - IRCDProto() { } protected: IRCDProto(const Anope::string &proto_name); + public: + virtual ~IRCDProto(); virtual void SendSVSKillInternal(const BotInfo *, User *, const Anope::string &); virtual void SendModeInternal(const BotInfo *, const Channel *, const Anope::string &); @@ -37,8 +39,6 @@ class CoreExport IRCDProto virtual void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf); virtual void SendCTCPInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf); virtual void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf); - public: - virtual ~IRCDProto(); const Anope::string &GetProtocolName(); /* Modes used by default by our clients */ @@ -66,53 +66,135 @@ class CoreExport IRCDProto /* The maximum number of modes we are allowed to set with one MODE command */ unsigned MaxModes; - virtual void SendSVSNOOP(const Server *, bool) { } + /** Sets the server in NOOP mode. If NOOP mode is enabled, no users + * will be able to oper on the server. + * @param s The server + * @param mode Whether to turn NOOP on or off + */ + virtual void SendSVSNOOP(const Server *s, bool mode) { } + + /** Sets the topic on a channel + * @param bi The bot to set the topic from + * @param c The channel to set the topic on. The topic being set is Channel::topic + */ virtual void SendTopic(BotInfo *, Channel *); + + /** Sets a vhost on a user. + * @param u The user + * @param vident The ident to set + * @param vhost The vhost to set + */ + virtual void SendVhost(User *u, const Anope::string &vident, const Anope::string &vhost) { } virtual void SendVhostDel(User *) { } + + /** Sets an akill. This is a recursive function that can be called multiple times + * for the same xline, but for different users, if the xline is not one that can be + * enforced by the IRCd, such as a nick/user/host/realname combination ban. + * @param u The user affected by the akill, if known + * @param x The akill + */ virtual void SendAkill(User *, XLine *) = 0; virtual void SendAkillDel(const XLine *) = 0; + + /* Realname ban */ + virtual void SendSGLine(User *, const XLine *) { } + virtual void SendSGLineDel(const XLine *) { } + + /* IP ban */ + virtual void SendSZLine(User *u, const XLine *) { } + virtual void SendSZLineDel(const XLine *) { } + + /* Nick ban (and sometimes channel) */ + virtual void SendSQLine(User *, const XLine *x) { } + virtual void SendSQLineDel(const XLine *x) { } + + /** Kills a user + * @param source The client used to kill the user, if any + * @param user The user to be killed + * @param fmt Kill reason + */ virtual void SendSVSKill(const BotInfo *source, User *user, const char *fmt, ...); + virtual void SendMode(const BotInfo *bi, const Channel *dest, const char *fmt, ...); virtual void SendMode(const BotInfo *bi, const User *u, const char *fmt, ...); + + /** Introduces a client to the rest of the network + * @param u The client to introduce + */ virtual void SendClientIntroduction(const User *u) = 0; + virtual void SendKick(const BotInfo *bi, const Channel *chan, const User *user, const char *fmt, ...); + + /* Sends a message using SendPrivmsg or SendNotice, depending on the default message method. */ virtual void SendMessage(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); virtual void SendNotice(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); - virtual void SendAction(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); virtual void SendPrivmsg(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendAction(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendCTCP(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendGlobalNotice(const BotInfo *bi, const Server *dest, const Anope::string &msg) = 0; virtual void SendGlobalPrivmsg(const BotInfo *bi, const Server *desc, const Anope::string &msg) = 0; virtual void SendQuit(const User *u, const char *fmt, ...); virtual void SendPing(const Anope::string &servname, const Anope::string &who); virtual void SendPong(const Anope::string &servname, const Anope::string &who); - virtual void SendJoin(const User *, Channel *, const ChannelStatus *) = 0; - virtual void SendSQLineDel(const XLine *x) { } - virtual void SendInvite(const BotInfo *bi, const Channel *c, const User *u); + + /** Joins one of our users to a channel. + * @param u The user to join + * @param c The channel to join the user to + * @param status The status to set on the user after joining. This may or may not already internally + * be set on the user. This may include the modes in the join, but will usually place them on the mode + * stacker to be set "soon". + */ + virtual void SendJoin(const User *u, Channel *c, const ChannelStatus *status) = 0; virtual void SendPart(const BotInfo *bi, const Channel *chan, const char *fmt, ...); + + /** Force joins a user that isn't ours to a channel. + * @param bi The source of the message + * @param nick The user to join + * @param chan The channel to join the user to + * @param param Channel key? + */ + virtual void SendSVSJoin(const BotInfo *bi, const Anope::string &nick, const Anope::string &chan, const Anope::string ¶m) { } + + virtual void SendInvite(const BotInfo *bi, const Channel *c, const User *u); virtual void SendGlobops(const BotInfo *source, const char *fmt, ...); - virtual void SendSQLine(User *, const XLine *x) { } - virtual void SendSquit(Server *, const Anope::string &message); + + /** Sets oper flags on a user, currently only supported by Unreal + */ virtual void SendSVSO(const BotInfo *, const Anope::string &, const Anope::string &) { } - virtual void SendChangeBotNick(const BotInfo *bi, const Anope::string &newnick); + + /** Sends a nick change of one of our clients. + */ + virtual void SendNickChange(const User *u, const Anope::string &newnick); + + /** Forces a nick change of a user that isn't ours (SVSNICK) + */ virtual void SendForceNickChange(const User *u, const Anope::string &newnick, time_t when); - virtual void SendVhost(User *, const Anope::string &, const Anope::string &) { } + + /** Used to introduce ourselves to our uplink. Usually will SendServer(Me) and any other + * initial handshake requirements. + */ virtual void SendConnect() = 0; + + /** Called right before we begin our burst, after we have handshaked successfully with the uplink/ + * At this point none of our servesr, users, or channels exist on the uplink + */ + virtual void SendBOB() { } + virtual void SendEOB() { } + virtual void SendSVSHold(const Anope::string &) { } virtual void SendSVSHoldDel(const Anope::string &) { } - virtual void SendSGLineDel(const XLine *) { } - virtual void SendSZLineDel(const XLine *) { } - virtual void SendSZLine(User *u, const XLine *) { } - virtual void SendSGLine(User *, const XLine *) { } - virtual void SendCTCP(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); - virtual void SendSVSJoin(const BotInfo *bi, const Anope::string &, const Anope::string &, const Anope::string &) { } + virtual void SendSWhois(const BotInfo *bi, const Anope::string &, const Anope::string &) { } - virtual void SendBOB() { } - virtual void SendEOB() { } + + /** Introduces a server to the uplink + */ virtual void SendServer(const Server *) = 0; - virtual bool IsNickValid(const Anope::string &) { return true; } - virtual bool IsChannelValid(const Anope::string &); + virtual void SendSquit(Server *, const Anope::string &message); + virtual void SendNumeric(int numeric, const Anope::string &dest, const char *fmt, ...); + virtual void SendLogin(User *u) = 0; virtual void SendLogout(User *u) = 0; @@ -125,6 +207,11 @@ class CoreExport IRCDProto * Normally this is a simple +o, though some IRCds require us to send the oper type */ virtual void SendOper(User *u); + + virtual bool IsNickValid(const Anope::string &); + virtual bool IsChannelValid(const Anope::string &); + virtual bool IsIdentValid(const Anope::string &); + virtual bool IsHostValid(const Anope::string &); }; enum IRCDMessageFlag @@ -150,21 +237,16 @@ class CoreExport MessageSource Server *GetServer(); }; -class CoreExport IRCDMessage : public Flags<IRCDMessageFlag, 3> +class CoreExport IRCDMessage : public Flags<IRCDMessageFlag>, public Service { - static std::map<Anope::string, std::vector<IRCDMessage *> > messages; - Anope::string name; unsigned param_count; public: - static const std::vector<IRCDMessage *> *Find(const Anope::string &name); - - IRCDMessage(const Anope::string &n, unsigned p = 0); - ~IRCDMessage(); + IRCDMessage(Module *owner, const Anope::string &n, unsigned p = 0); unsigned GetParamCount() const; virtual bool Run(MessageSource &, const std::vector<Anope::string> ¶ms) = 0; }; -extern CoreExport IRCDProto *ircdproto; +extern CoreExport IRCDProto *IRCD; #endif // PROTOCOL_H diff --git a/include/regchannel.h b/include/regchannel.h index a692dda4a..9e01963b8 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -1,15 +1,15 @@ -/* Modular support +/* * * (C) 2008-2012 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. + * */ #ifndef REGCHANNEL_H #define REGCHANNEL_H -#include "botserv.h" #include "memo.h" #include "modes.h" #include "extensible.h" @@ -20,7 +20,7 @@ typedef Anope::hash_map<ChannelInfo *> registered_channel_map; -extern CoreExport serialize_checker<registered_channel_map> RegisteredChannelList; +extern CoreExport Serialize::Checker<registered_channel_map> RegisteredChannelList; /** Flags used for the ChannelInfo class */ @@ -68,10 +68,57 @@ enum ChannelInfoFlag CI_END }; -const Anope::string ChannelInfoFlagStrings[] = { - "BEGIN", "KEEPTOPIC", "SECUREOPS", "PRIVATE", "TOPICLOCK", "RESTRICTED", - "PEACE", "SECURE", "NO_EXPIRE", "MEMO_HARDMAX", "SECUREFOUNDER", - "SIGNKICK", "SIGNKICK_LEVEL", "SUSPENDED", "PERSIST", "STATS", "NOAUTOOP", "" +/* BotServ SET flags (ChannelInfo::botflags) */ +enum BotServFlag +{ + BS_BEGIN, + /* BotServ won't kick ops */ + BS_DONTKICKOPS, + /* BotServ won't kick voices */ + BS_DONTKICKVOICES, + /* BotServ bot accepts fantasy commands */ + BS_FANTASY, + /* BotServ should show greets */ + BS_GREET, + /* BotServ bots are not allowed to be in this channel */ + BS_NOBOT, + /* BotServ kicks for bolds */ + BS_KICK_BOLDS, + /* BotServ kicks for colors */ + BS_KICK_COLORS, + /* BOtServ kicks for reverses */ + BS_KICK_REVERSES, + /* BotServ kicks for underlines */ + BS_KICK_UNDERLINES, + /* BotServ kicks for badwords */ + BS_KICK_BADWORDS, + /* BotServ kicks for caps */ + BS_KICK_CAPS, + /* BotServ kicks for flood */ + BS_KICK_FLOOD, + /* BotServ kicks for repeating */ + BS_KICK_REPEAT, + /* BotServ kicks for italics */ + BS_KICK_ITALICS, + /* BotServ kicks for amsgs */ + BS_KICK_AMSGS, + BS_END +}; + +/* Indices for TTB (Times To Ban) */ +enum +{ + TTB_BOLDS, + TTB_COLORS, + TTB_REVERSES, + TTB_UNDERLINES, + TTB_BADWORDS, + TTB_CAPS, + TTB_FLOOD, + TTB_REPEAT, + TTB_ITALICS, + TTB_AMSGS, + TTB_SIZE }; /** Flags for badwords @@ -96,8 +143,8 @@ struct CoreExport BadWord : Serializable BadWordType type; BadWord() : Serializable("BadWord") { } - Serialize::Data serialize() const anope_override; - static Serializable* unserialize(Serializable *obj, Serialize::Data &); + Serialize::Data Serialize() const anope_override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); }; /** Flags for auto kick @@ -108,31 +155,31 @@ enum AutoKickFlag AK_ISNICK }; -const Anope::string AutoKickFlagString[] = { "AK_ISNICK", "" }; - /* AutoKick data. */ class CoreExport AutoKick : public Flags<AutoKickFlag>, public Serializable { public: - AutoKick(); - serialize_obj<ChannelInfo> ci; - /* Only one of these can be in use */ + /* Channel this autokick is on */ + Serialize::Reference<ChannelInfo> ci; + + /* Only one of these can be in use. if HasFlag(AK_ISNICK) then nc is in use */ Anope::string mask; - serialize_obj<NickCore> nc; + Serialize::Reference<NickCore> nc; Anope::string reason; Anope::string creator; time_t addtime; time_t last_used; - Serialize::Data serialize() const anope_override; - static Serializable* unserialize(Serializable *obj, Serialize::Data &); + AutoKick(); + Serialize::Data Serialize() const anope_override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); }; struct CoreExport ModeLock : Serializable { public: - serialize_obj<ChannelInfo> ci; + Serialize::Reference<ChannelInfo> ci; bool set; ChannelModeName name; Anope::string param; @@ -141,13 +188,13 @@ struct CoreExport ModeLock : Serializable ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se = "", time_t c = Anope::CurTime); - Serialize::Data serialize() const anope_override; - static Serializable* unserialize(Serializable *obj, Serialize::Data &); + Serialize::Data Serialize() const anope_override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); }; struct CoreExport LogSetting : Serializable { - serialize_obj<ChannelInfo> ci; + Serialize::Reference<ChannelInfo> ci; /* Our service name of the command */ Anope::string service_name; /* The name of the client the command is on */ @@ -159,67 +206,65 @@ struct CoreExport LogSetting : Serializable time_t created; LogSetting() : Serializable("LogSetting") { } - Serialize::Data serialize() const anope_override; - static Serializable* unserialize(Serializable *obj, Serialize::Data &); + Serialize::Data Serialize() const anope_override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); }; /* It matters that Base is here before Extensible (it is inherited by Serializable) */ -class CoreExport ChannelInfo : public Serializable, public Extensible, public Flags<ChannelInfoFlag, CI_END> +class CoreExport ChannelInfo : public Serializable, public Extensible, public Flags<ChannelInfoFlag> { private: - serialize_obj<NickCore> founder; /* Channel founder */ - serialize_checker<std::vector<ChanAccess *> > access; /* List of authorized users */ - serialize_checker<std::vector<AutoKick *> > akick; /* List of users to kickban */ - serialize_checker<std::vector<BadWord *> > badwords; /* List of badwords */ + Serialize::Reference<NickCore> founder; /* Channel founder */ + Serialize::Checker<std::vector<ChanAccess *> > access; /* List of authorized users */ + Serialize::Checker<std::vector<AutoKick *> > akick; /* List of users to kickban */ + Serialize::Checker<std::vector<BadWord *> > badwords; /* List of badwords */ std::map<Anope::string, int16_t> levels; public: typedef std::multimap<ChannelModeName, ModeLock *> ModeList; - serialize_checker<ModeList> mode_locks; - serialize_checker<std::vector<LogSetting *> > log_settings; - - /** Default constructor - * @param chname The channel name - */ - ChannelInfo(const Anope::string &chname); - - /** Copy constructor - * @param ci The ChannelInfo to copy settings to - */ - ChannelInfo(const ChannelInfo &ci); - - /** Default destructor - */ - ~ChannelInfo(); + Serialize::Checker<ModeList> mode_locks; + Serialize::Checker<std::vector<LogSetting *> > log_settings; - Anope::string name; /* Channel name */ - serialize_obj<NickCore> successor; /* Who gets the channel if the founder nick is dropped or expires */ + Anope::string name; /* Channel name */ + Serialize::Reference<NickCore> successor; /* Who gets the channel if the founder nick is dropped or expires */ Anope::string desc; time_t time_registered; time_t last_used; - Anope::string last_topic; /* The last topic that was set on this channel */ - Anope::string last_topic_setter; /* Setter */ - time_t last_topic_time; /* Time */ + Anope::string last_topic; /* The last topic that was set on this channel */ + Anope::string last_topic_setter; /* Setter */ + time_t last_topic_time; /* Time */ int16_t bantype; MemoInfo memos; - Channel *c; /* Pointer to channel record (if channel is currently in use) */ + Channel *c; /* Pointer to channel, if the channel exists */ /* For BotServ */ - serialize_obj<BotInfo> bi; /* Bot used on this channel */ + Serialize::Reference<BotInfo> bi; /* Bot used on this channel */ Flags<BotServFlag> botflags; - int16_t ttb[TTB_SIZE]; /* Times to ban for each kicker */ + int16_t ttb[TTB_SIZE]; /* Times to ban for each kicker */ + + int16_t capsmin, capspercent; /* For CAPS kicker */ + int16_t floodlines, floodsecs; /* For FLOOD kicker */ + int16_t repeattimes; /* For REPEAT kicker */ - int16_t capsmin, capspercent; /* For CAPS kicker */ - int16_t floodlines, floodsecs; /* For FLOOD kicker */ - int16_t repeattimes; /* For REPEAT kicker */ + /** Constructor + * @param chname The channel name + */ + ChannelInfo(const Anope::string &chname); - Serialize::Data serialize() const anope_override; - static Serializable* unserialize(Serializable *obj, Serialize::Data &); + /** Copy constructor + * @param ci The ChannelInfo to copy settings to + */ + ChannelInfo(const ChannelInfo &ci); + + ~ChannelInfo(); + + Serialize::Data Serialize() const anope_override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); /** Change the founder of the channek * @params nc The new founder @@ -440,11 +485,26 @@ class CoreExport ChannelInfo : public Serializable, public Extensible, public Fl /** Clear all privileges from the channel */ void ClearLevels(); + + /** Gets a ban mask for the given user based on the bantype + * of the channel. + * @param u The user + * @return A ban mask that affects the user + */ + Anope::string GetIdealBan(User *u) const; + + /** Finds a ChannelInfo + * @param name channel name to lookup + * @return the ChannelInfo associated with the channel + */ + static ChannelInfo* Find(const Anope::string &name); }; -extern CoreExport ChannelInfo *cs_findchan(const Anope::string &chan); +/** Is the user the real founder? + * @param user The user + * @param ci The channel + * @return true or false + */ extern CoreExport bool IsFounder(const User *user, const ChannelInfo *ci); -extern CoreExport void update_cs_lastseen(User *user, ChannelInfo *ci); -extern CoreExport int get_idealban(const ChannelInfo *ci, User *u, Anope::string &ret); #endif // REGCHANNEL_H diff --git a/include/serialize.h b/include/serialize.h index 53bd096de..8b8497c40 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -25,54 +25,65 @@ namespace Serialize DT_TEXT, DT_INT }; -} -class CoreExport stringstream : public std::stringstream -{ - private: - Serialize::DataType type; - unsigned _max; + class CoreExport stringstream : public std::stringstream + { + private: + Serialize::DataType type; + unsigned _max; - public: - stringstream(); - stringstream(const stringstream &ss); - Anope::string astr() const; + public: + stringstream(); + stringstream(const stringstream &ss); + Anope::string astr() const; - template<typename T> std::istream &operator>>(T &val) - { - std::istringstream is(this->str()); - is >> val; - return *this; - } - std::istream &operator>>(Anope::string &val); + template<typename T> std::istream &operator>>(T &val) + { + std::istringstream is(this->str()); + is >> val; + return *this; + } + std::istream &operator>>(Anope::string &val); - bool operator==(const stringstream &other) const; - bool operator!=(const stringstream &other) const; + bool operator==(const stringstream &other) const; + bool operator!=(const stringstream &other) const; - stringstream &setType(Serialize::DataType t); - Serialize::DataType getType() const; - stringstream &setMax(unsigned m); - unsigned getMax() const; -}; + stringstream &SetType(Serialize::DataType t); + Serialize::DataType GetType() const; + stringstream &SetMax(unsigned m); + unsigned GetMax() const; + }; -namespace Serialize -{ typedef std::map<Anope::string, stringstream> Data; -} -extern void RegisterTypes(); + extern void RegisterTypes(); -class SerializeType; + class Type; + template<typename T> class Checker; + template<typename T> class Reference; +} +/** A serialziable object. Serializable objects can be serialized into + * a map of stringstreams (Serialize::Data), and then reconstructed or + * updated later at any time. + */ class CoreExport Serializable : public virtual Base { private: - static std::list<Serializable *> *serializable_items; - SerializeType *s_type; + /* A list of every serializable item in Anope. + * Some of these are static and constructed at runtime, + * so this list must be on the heap, as it is not always + * constructed before other objects are if it isn't. + */ + static std::list<Serializable *> *SerializableItems; + /* The type of item this object is */ + Serialize::Type *s_type; private: - std::list<Serializable *>::iterator s_iter; // Iterator into serializable_items - + /* Iterator into serializable_items */ + std::list<Serializable *>::iterator s_iter; + /* The last serialized form of this object commited to the database */ Serialize::Data last_commit; + /* The last time this object was commited to the database */ time_t last_commit_time; Serializable(); @@ -85,10 +96,16 @@ class CoreExport Serializable : public virtual Base Serializable &operator=(const Serializable &); public: + /* Unique ID (per type, not globally) for this object */ unsigned int id; - void destroy(); + /* Destroys this object. This is effectively the same thing as + * delete, however it properly cleans up after this object. + */ + void Destroy(); + /** Marks the object as potentially being updated "soon". + */ void QueueUpdate(); bool IsCached(); @@ -97,27 +114,43 @@ class CoreExport Serializable : public virtual Base bool IsTSCached(); void UpdateTS(); - SerializeType* GetSerializableType() const; + /** Get the type of serializable object this is + * @return The serializable object type + */ + Serialize::Type* GetSerializableType() const; - virtual Serialize::Data serialize() const = 0; + virtual Serialize::Data Serialize() const = 0; static const std::list<Serializable *> &GetItems(); }; -class CoreExport SerializeType +/* A serializable type. There should be one of these classes for each type + * of class that inherits from Serialiable. Used for unserializing objects + * of this type, as it requires a function pointer to a static member function. + */ +class CoreExport Serialize::Type { typedef Serializable* (*unserialize_func)(Serializable *obj, Serialize::Data &); - static std::vector<Anope::string> type_order; - static std::map<Anope::string, SerializeType *> types; + static std::vector<Anope::string> TypeOrder; + static std::map<Anope::string, Serialize::Type *> Types; + /* The name of this type, should be a class name */ Anope::string name; unserialize_func unserialize; + /* Owner of this type. Used for placing objects of this type in separate databases + * based on what module, if any, owns it. + */ Module *owner; + /* The timesatmp for this type. All objects of this type are as up to date as + * this timestamp. if curtime == timestamp then we have the most up to date + * version of every object of this type. + */ time_t timestamp; public: + /* Map of Serializable::id to Serializable objects */ std::map<unsigned int, Serializable *> objects; /** Creates a new serializable type @@ -125,44 +158,67 @@ class CoreExport SerializeType * @param f Func to unserialize objects * @param owner Owner of this type. Leave NULL for the core. */ - SerializeType(const Anope::string &n, unserialize_func f, Module *owner = NULL); - ~SerializeType(); + Type(const Anope::string &n, unserialize_func f, Module *owner = NULL); + ~Type(); + /** Gets the name for this type + * @return The name, eg "NickAlias" + */ const Anope::string &GetName(); + /** Unserialized an object. + * @param obj NULL if this object doesn't yet exist. If this isn't NULL, instead + * update the contents of this object. + * @param data The data to unserialize + * @return The unserialized object. If obj != NULL this should be obj. + */ Serializable *Unserialize(Serializable *obj, Serialize::Data &data); + /** Check if this object type has any pending changes and update them. + */ void Check(); + /** Gets the timestamp for the object type. That is, the time we know + * all objects of this type are updated at least to. + */ time_t GetTimestamp() const; + + /** Bumps object type timestamp to current time + */ void UpdateTimestamp(); Module* GetOwner() const; - static SerializeType *Find(const Anope::string &name); + static Serialize::Type *Find(const Anope::string &name); static const std::vector<Anope::string> &GetTypeOrder(); }; +/** Should be used to hold lists and other objects of a specific type, + * but not a specific object. Used for ensuring that any access to + * this object type is always up to date. These are usually constructed + * at run time, before main is called, so no types are registered. This + * is why there are static Serialize::Type* variables in every function. + */ template<typename T> -class serialize_checker +class Serialize::Checker { Anope::string name; T obj; public: - serialize_checker(const Anope::string &n) : name(n) { } + Checker(const Anope::string &n) : name(n) { } inline const T* operator->() const { - static SerializeType *type = SerializeType::Find(this->name); + static Serialize::Type *type = Serialize::Type::Find(this->name); if (type) type->Check(); return &this->obj; } inline T* operator->() { - static SerializeType *type = SerializeType::Find(this->name); + static Serialize::Type *type = Serialize::Type::Find(this->name); if (type) type->Check(); return &this->obj; @@ -170,14 +226,14 @@ class serialize_checker inline const T& operator*() const { - static SerializeType *type = SerializeType::Find(this->name); + static Serialize::Type *type = Serialize::Type::Find(this->name); if (type) type->Check(); return this->obj; } inline T& operator*() { - static SerializeType *type = SerializeType::Find(this->name); + static Serialize::Type *type = Serialize::Type::Find(this->name); if (type) type->Check(); return this->obj; @@ -185,44 +241,50 @@ class serialize_checker inline operator const T&() const { - static SerializeType *type = SerializeType::Find(this->name); + static Serialize::Type *type = Serialize::Type::Find(this->name); if (type) type->Check(); return this->obj; } inline operator T&() { - static SerializeType *type = SerializeType::Find(this->name); + static Serialize::Type *type = Serialize::Type::Find(this->name); if (type) type->Check(); return this->obj; } }; +/** Used to hold references to serializable objects. Reference should always be + * used when holding references to serializable objects for extended periods of time + * to ensure that the object it refers to it always up to date. This also behaves like + * Reference in that it will invalidate itself if the object it refers to is + * destructed. + */ template<typename T> -class serialize_obj : public dynamic_reference_base +class Serialize::Reference : public ReferenceBase { protected: T *ref; public: - serialize_obj() : ref(NULL) + Reference() : ref(NULL) { } - serialize_obj(T *obj) : ref(obj) + Reference(T *obj) : ref(obj) { if (obj) obj->AddReference(this); } - serialize_obj(const serialize_obj<T> &other) : ref(other.ref) + Reference(const Reference<T> &other) : ref(other.ref) { if (*this) this->ref->AddReference(this); } - ~serialize_obj() + ~Reference() { if (*this) this->ref->DelReference(this); diff --git a/include/servers.h b/include/servers.h index 339b4db19..216679cc0 100644 --- a/include/servers.h +++ b/include/servers.h @@ -1,3 +1,15 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + */ + #ifndef SERVERS_H #define SERVERS_H @@ -5,13 +17,25 @@ #include "anope.h" #include "extensible.h" -/* Anope */ +/* Anope. We are at the top of the server tree, our uplink is + * almost always me->GetLinks()[0]. We never have an uplink. */ extern CoreExport Server *Me; -extern CoreExport const Anope::string ts6_uid_retrieve(); -extern CoreExport const Anope::string ts6_sid_retrieve(); +namespace Servers +{ + /* Retrieves the next free TS6 UID or SID */ + extern CoreExport const Anope::string TS6_UID_Retrieve(); + extern CoreExport const Anope::string TS6_SID_Retrieve(); + + /* Gets our uplink. Note we don't actually have an "uplink", this is just + * the only server whose uplink *is* Me that is not a juped server. + * @return Our uplink, or NULL if not uplinked to anything + */ + extern CoreExport Server* GetUplink(); -extern CoreExport std::set<Anope::string> Capab; + /* CAPAB/PROTOCTL given by the uplink */ + extern CoreExport std::set<Anope::string> Capab; +} /** Flags set on servers */ @@ -24,28 +48,26 @@ enum ServerFlag SERVER_JUPED }; -const Anope::string ServerFlagStrings[] = { "SERVER_NONE", "SERVER_SYNCING", "SERVER_JUPED", "" }; - /** Class representing a server */ class CoreExport Server : public Flags<ServerFlag>, public Extensible { private: /* Server name */ - Anope::string Name; + Anope::string name; /* Hops between services and server */ - unsigned int Hops; + unsigned int hops; /* Server description */ - Anope::string Description; + Anope::string description; /* Server ID */ - Anope::string SID; + Anope::string sid; /* Links for this server */ - std::vector<Server *> Links; + std::vector<Server *> links; /* Uplink for this server */ - Server *UplinkServer; + Server *uplink; /* Reason this server was quit */ - Anope::string QReason; + Anope::string quit_reason; public: /** Constructor @@ -65,7 +87,7 @@ class CoreExport Server : public Flags<ServerFlag>, public Extensible public: /* Number of users on the server */ - unsigned Users; + unsigned users; /** Delete this server with a reason * @param reason The reason @@ -125,7 +147,7 @@ class CoreExport Server : public Flags<ServerFlag>, public Extensible /** Finish syncing this server and optionally all links to it * @param SyncLinks True to sync the links for this server too (if any) */ - void Sync(bool SyncLinks); + void Sync(bool sync_links); /** Check if this server is synced * @return true or false diff --git a/include/service.h b/include/service.h index 95c650076..f2f553eb2 100644 --- a/include/service.h +++ b/include/service.h @@ -1,4 +1,5 @@ /* + * * (C) 2003-2012 Anope Team * Contact us at team@anope.org * @@ -6,6 +7,7 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. + * */ #ifndef SERVICE_H @@ -15,18 +17,34 @@ #include "anope.h" #include "modules.h" +/** Anything that inherits from this class can be referred to + * using ServiceReference. Any interfaces provided by modules, + * such as commands, use this. This is also used for modules + * that publish a service (m_ssl, etc). + */ class CoreExport Service : public virtual Base { - static std::map<Anope::string, std::map<Anope::string, Service *> > services; + static std::map<Anope::string, std::map<Anope::string, Service *> > Services; + static std::map<Anope::string, std::map<Anope::string, Anope::string> > Aliases; public: static Service *FindService(const Anope::string &t, const Anope::string &n) { - std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = services.find(t); - if (it != services.end()) + std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = Services.find(t); + if (it != Services.end()) { - std::map<Anope::string, Service *>::iterator it2 = it->second.find(n); - if (it2 != it->second.end()) - return it2->second; + Anope::string name = n; + + std::map<Anope::string, std::map<Anope::string, Anope::string> >::iterator it2 = Aliases.find(t); + if (it2 != Aliases.end()) + { + std::map<Anope::string, Anope::string>::iterator it3 = it2->second.find(n); + if (it3 != it2->second.end()) + name = it3->second; + } + + std::map<Anope::string, Service *>::iterator it4 = it->second.find(name); + if (it4 != it->second.end()) + return it4->second; } return NULL; @@ -35,15 +53,31 @@ class CoreExport Service : public virtual Base static std::vector<Anope::string> GetServiceKeys(const Anope::string &t) { std::vector<Anope::string> keys; - std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = services.find(t); - if (it != services.end()) + std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = Services.find(t); + if (it != Services.end()) for (std::map<Anope::string, Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) keys.push_back(it2->first); return keys; } + static void AddAlias(const Anope::string &t, const Anope::string &n, const Anope::string &v) + { + std::map<Anope::string, Anope::string> &smap = Aliases[t]; + smap[n] = v; + } + + static void DelAlias(const Anope::string &t, const Anope::string &n) + { + std::map<Anope::string, Anope::string> &smap = Aliases[t]; + smap.erase(n); + if (smap.empty()) + Aliases.erase(t); + } + Module *owner; + /* Service type, which should be the class name (eg "Command") */ Anope::string type; + /* Service name, commands are usually named service/command */ Anope::string name; Service(Module *o, const Anope::string &t, const Anope::string &n) : owner(o), type(t), name(n) @@ -58,7 +92,7 @@ class CoreExport Service : public virtual Base void Register() { - std::map<Anope::string, Service *> &smap = services[this->type]; + std::map<Anope::string, Service *> &smap = Services[this->type]; if (smap.find(this->name) != smap.end()) throw ModuleException("Service " + this->type + " with name " + this->name + " already exists"); smap[this->name] = this; @@ -66,29 +100,32 @@ class CoreExport Service : public virtual Base void Unregister() { - std::map<Anope::string, Service *> &smap = services[this->type]; + std::map<Anope::string, Service *> &smap = Services[this->type]; smap.erase(this->name); if (smap.empty()) - services.erase(this->type); + Services.erase(this->type); } }; +/** Like Reference, but used to refer to Services. + */ template<typename T> -class service_reference : public dynamic_reference<T> +class ServiceReference : public Reference<T> { Anope::string type; Anope::string name; public: - service_reference() : dynamic_reference<T>(NULL) { } + ServiceReference() { } - service_reference(const Anope::string &t, const Anope::string &n) : dynamic_reference<T>(NULL), type(t), name(n) + ServiceReference(const Anope::string &t, const Anope::string &n) : type(t), name(n) { } inline void operator=(const Anope::string &n) { this->name = n; + this->invalid = true; } operator bool() anope_override @@ -100,6 +137,10 @@ class service_reference : public dynamic_reference<T> } if (!this->ref) { + /* This really could be dynamic_cast in every case, except for when a module + * creates its own service type (that other modules must include the header file + * for), as the core is not compiled with it so there is no RTTI for it. + */ this->ref = static_cast<T *>(Service::FindService(this->type, this->name)); if (this->ref) this->ref->AddReference(this); @@ -108,5 +149,20 @@ class service_reference : public dynamic_reference<T> } }; +class ServiceAlias +{ + Anope::string t, f; + public: + ServiceAlias(const Anope::string &type, const Anope::string &from, const Anope::string &to) : t(type), f(from) + { + Service::AddAlias(type, from, to); + } + + ~ServiceAlias() + { + Service::DelAlias(t, f); + } +}; + #endif // SERVICE_H diff --git a/include/services.h b/include/services.h index 4b21bac2a..0405206d2 100644 --- a/include/services.h +++ b/include/services.h @@ -8,7 +8,6 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. * - * */ #ifndef SERVICES_H @@ -66,13 +65,4 @@ # include "anope_windows.h" #endif -/** - * RFC: defination of a valid nick - * nickname = ( letter / special ) *8( letter / digit / special / "-" ) - * letter = %x41-5A / %x61-7A ; A-Z / a-z - * digit = %x30-39 ; 0-9 - * special = %x5B-60 / %x7B-7D ; "[", "]", "\", "`", "_", "^", "{", "|", "}" - **/ -#define isvalidnick(c) (isalnum(c) || ((c) >= '\x5B' && (c) <= '\x60') || ((c) >= '\x7B' && (c) <= '\x7D') || (c) == '-') - #endif // SERVICES_H diff --git a/include/signals.h b/include/signals.h index f057bdfee..771404f52 100644 --- a/include/signals.h +++ b/include/signals.h @@ -8,7 +8,6 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. * - * */ #ifndef SIGNAL_H diff --git a/include/socketengine.h b/include/socketengine.h index 8effb79f1..5f4bc5980 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -7,6 +7,7 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. + * */ #ifndef SOCKETENGINE_H @@ -17,7 +18,7 @@ class CoreExport SocketEngine { - static const int DefaultSize = 4; // Uplink, DNS, Signal handler, Mode stacker + static const int DefaultSize = 8; // Uplink, DNS, Signal handlers, Mode stacker public: /* Map of sockets */ static std::map<int, Socket *> Sockets; diff --git a/include/sockets.h b/include/sockets.h index 6fa6c4075..24c993d9e 100644 --- a/include/sockets.h +++ b/include/sockets.h @@ -7,6 +7,7 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. + * */ #ifndef SOCKETS_H @@ -104,12 +105,12 @@ class CoreExport cidr class SocketException : public CoreException { public: - /** Default constructor for socket exceptions + /** Constructor for socket exceptions * @param message Error message */ SocketException(const Anope::string &message) : CoreException(message) { } - /** Default destructor + /** Destructor * @throws Nothing */ virtual ~SocketException() throw() { } @@ -126,9 +127,6 @@ enum SocketFlag SF_ACCEPTED }; -static const Anope::string SocketFlagStrings[] = { "SF_DEAD", "SF_WRITABLE", "SF_CONNECTING", "SF_CONNECTED", "SF_ACCEPTING", "SF_ACCEPTED", "" }; - - class CoreExport SocketIO { public: @@ -189,29 +187,29 @@ class CoreExport Socket : public Flags<SocketFlag> { protected: /* Socket FD */ - int Sock; + int sock; /* Is this an IPv6 socket? */ - bool IPv6; + bool ipv6; public: /* Sockaddrs for bind() (if it's bound) */ sockaddrs bindaddr; /* I/O functions used for this socket */ - SocketIO *IO; + SocketIO *io; /** Empty constructor, should not be called. */ Socket(); - /** Default constructor + /** Constructor, possibly creates the socket and adds it to the engine * @param sock The socket to use, -1 if we need to create our own * @param ipv6 true if using ipv6 * @param type The socket type, defaults to SOCK_STREAM */ Socket(int sock, bool ipv6 = false, int type = SOCK_STREAM); - /** Default destructor + /** Destructor, closes the socket and removes it from the engine */ virtual ~Socket(); @@ -225,7 +223,7 @@ class CoreExport Socket : public Flags<SocketFlag> */ bool IsIPv6() const; - /** Mark a socket as blockig + /** Mark a socket as blocking * @return true if the socket is now blocking */ bool SetBlocking(); @@ -266,19 +264,14 @@ class CoreExport BufferedSocket : public virtual Socket { protected: /* Things to be written to the socket */ - Anope::string WriteBuffer; + Anope::string write_buffer; /* Part of a message sent from the server, but not totally received */ - Anope::string extrabuf; - /* How much data was received from this socket */ - int RecvLen; + Anope::string extra_buf; + /* How much data was received from this socket on this recv() */ + int recv_len; public: - /** Constructor - */ BufferedSocket(); - - /** Default destructor - */ virtual ~BufferedSocket(); /** Called when there is something to be received for this socket @@ -330,15 +323,11 @@ class CoreExport BinarySocket : public virtual Socket ~DataBlock(); }; - std::deque<DataBlock *> WriteBuffer; + /* Data to be written out */ + std::deque<DataBlock *> write_buffer; public: - /** Constructor - */ BinarySocket(); - - /** Default destructor - */ virtual ~BinarySocket(); /** Called when there is something to be received for this socket @@ -376,9 +365,6 @@ class CoreExport ListenSocket : public virtual Socket * @param ipv6 true for ipv6 */ ListenSocket(const Anope::string &bindip, int port, bool ipv6); - - /** Destructor - */ virtual ~ListenSocket(); /** Process what has come in from the connection @@ -435,7 +421,7 @@ class CoreExport ClientSocket : public virtual Socket { public: /* Listen socket this connection came from */ - ListenSocket *LS; + ListenSocket *ls; /* Clients address */ sockaddrs clientaddr; @@ -469,19 +455,14 @@ class CoreExport Pipe : public Socket { public: /** The FD of the write pipe (if this isn't evenfd) - * this->Sock is the readfd + * this->sock is the readfd */ - int WritePipe; + int write_pipe; - /** Constructor - */ Pipe(); - - /** Destructor - */ ~Pipe(); - /** Called when data is to be read + /** Called when data is to be read, reads the data then calls OnNotify */ bool ProcessRead() anope_override; @@ -489,13 +470,13 @@ class CoreExport Pipe : public Socket */ void Notify(); - /** Overload to do something useful + /** Called after ProcessRead comes back from Notify(), overload to do something useful */ virtual void OnNotify() = 0; }; extern CoreExport uint32_t TotalRead; extern CoreExport uint32_t TotalWritten; -extern CoreExport SocketIO normalSocketIO; +extern CoreExport SocketIO NormalSocketIO; #endif // SOCKET_H diff --git a/include/threadengine.h b/include/threadengine.h index 5d1752a8f..7eebed22f 100644 --- a/include/threadengine.h +++ b/include/threadengine.h @@ -1,3 +1,15 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + */ + #ifndef THREADENGINE_H #define THREADENGINE_H @@ -12,7 +24,7 @@ class CoreExport Thread : public Pipe, public Extensible public: /* Handle for this thread */ - pthread_t Handle; + pthread_t handle; /** Threads constructor */ diff --git a/include/timers.h b/include/timers.h index d5fc66fb0..d2597178b 100644 --- a/include/timers.h +++ b/include/timers.h @@ -4,8 +4,10 @@ * Contact us at team@anope.org * * Please read COPYING and README for further details. + * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. + * */ #ifndef TIMERS_H @@ -33,14 +35,14 @@ class CoreExport Timer bool repeat; public: - /** Default constructor, initializes the triggering time + /** Constructor, initializes the triggering time * @param time_from_now The number of seconds from now to trigger the timer * @param now The time now * @param repeating Repeat this timer every time_from_now if this is true */ Timer(long time_from_now, time_t now = Anope::CurTime, bool repeating = false); - /** Default destructor, removes the timer from the list + /** Destructor, removes the timer from the list */ virtual ~Timer(); @@ -91,14 +93,14 @@ class CoreExport TimerManager static std::vector<Timer *> Timers; public: /** Add a timer to the list - * @param T A Timer derived class to add + * @param t A Timer derived class to add */ - static void AddTimer(Timer *T); + static void AddTimer(Timer *t); /** Deletes a timer - * @param T A Timer derived class to delete + * @param t A Timer derived class to delete */ - static void DelTimer(Timer *T); + static void DelTimer(Timer *t); /** Tick all pending timers * @param ctime The current time diff --git a/include/uplink.h b/include/uplink.h index 617a8aa1a..d635bd7d3 100644 --- a/include/uplink.h +++ b/include/uplink.h @@ -7,6 +7,7 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. + * */ #ifndef UPLINK_H @@ -14,6 +15,12 @@ #include "sockets.h" +namespace Uplink +{ + extern void Connect(); +} + +/* This is the socket to our uplink */ class UplinkSocket : public ConnectionSocket, public BufferedSocket { public: @@ -22,10 +29,12 @@ class UplinkSocket : public ConnectionSocket, public BufferedSocket bool Read(const Anope::string &); void OnConnect(); void OnError(const Anope::string &); - + + /* A message sent over the uplink socket */ class CoreExport Message { private: + /* The source of the message, can be a server (Me), or any user (one of our bots) */ const Server *server; const User *user; std::stringstream buffer; diff --git a/include/users.h b/include/users.h index 17f3fac9f..ab7edeee3 100644 --- a/include/users.h +++ b/include/users.h @@ -1,8 +1,14 @@ /* - * Copyright (C) 2008-2011 Robin Burchell <w00t@inspircd.org> - * Copyright (C) 2008-2012 Anope Team <team@anope.org> + * + * (C) 2008-2011 Robin Burchell <w00t@inspircd.org> + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org * * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * */ #ifndef USERS_H @@ -19,18 +25,15 @@ typedef Anope::hash_map<User *> user_map; extern CoreExport user_map UserListByNick, UserListByUID; -class CoreExport ChannelStatus : public Flags<ChannelModeName, CMODE_END * 2> -{ - public: - ChannelStatus(); - Anope::string BuildCharPrefixList() const; - Anope::string BuildModePrefixList() const; -}; +extern CoreExport int OperCount; +extern CoreExport unsigned MaxUserCount; +extern CoreExport time_t MaxUserTime; +/* One per channel per user. Channel and status */ struct ChannelContainer { Channel *chan; - ChannelStatus *Status; + ChannelStatus *status; ChannelContainer(Channel *c) : chan(c) { } virtual ~ChannelContainer() { } @@ -38,7 +41,6 @@ struct ChannelContainer typedef std::list<ChannelContainer *> UChannelList; - /* Online user and channel data. */ class CoreExport User : public virtual Base, public Extensible, public CommandReply { @@ -46,36 +48,55 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe Anope::string vident; Anope::string ident; Anope::string uid; - bool OnAccess; /* If the user is on the access list of the nick theyre on */ - Flags<UserModeName, UMODE_END * 2> modes; /* Bitset of mode names the user has set on them */ - std::map<UserModeName, Anope::string> Params; /* Map of user modes and the params this user has */ - serialize_obj<NickCore> nc; /* NickCore account the user is currently loggged in as */ + /* If the user is on the access list of the nick theyre on */ + bool on_access; + /* Bitset of mode names the user has set on them */ + Flags<UserModeName> modes; + /* Map of user modes and the params this user has */ + std::map<UserModeName, Anope::string> mode_params; + /* NickCore account the user is currently loggged in as, if they are logged in */ + Serialize::Reference<NickCore> nc; + + /* # of invalid password attempts */ + unsigned short invalid_pw_count; + /* Time of last invalid password */ + time_t invalid_pw_time; + public: // XXX: exposing a tiny bit too much - Anope::string nick; /* User's current nick */ - - Anope::string host; /* User's real hostname */ - Anope::string vhost; /* User's virtual hostname */ - Anope::string chost; /* User's cloaked hostname */ - Anope::string realname; /* Realname */ - Anope::string fingerprint; /* SSL Fingerprint */ - Anope::string ip; /* User's IP */ - Server *server; /* Server user is connected to */ - time_t signon; /* When the user signed on. Set on connect and never modified. */ - time_t timestamp; /* Timestamp of the nick. Updated when the nick changes. */ - bool SuperAdmin; /* is SuperAdmin on or off? */ + /* User's current nick */ + Anope::string nick; + + /* User's real hostname */ + Anope::string host; + /* User's virtual hostname */ + Anope::string vhost; + /* User's cloaked hostname */ + Anope::string chost; + /* Realname */ + Anope::string realname; + /* SSL Fingerprint */ + Anope::string fingerprint; + /* User's IP */ + Anope::string ip; + /* Server user is connected to */ + Server *server; + /* When the user signed on. Set on connect and never modified. */ + time_t signon; + /* Timestamp of the nick. Updated when the nick changes. */ + time_t timestamp; + /* Is the user as super admin? */ + bool super_admin; /* Channels the user is in */ UChannelList chans; - unsigned short invalid_pw_count; /* # of invalid password attempts */ - time_t invalid_pw_time; /* Time of last invalid password */ - - time_t lastmemosend; /* Last time MS SEND command used */ - time_t lastnickreg; /* Last time NS REGISTER cmd used */ - time_t lastmail; /* Last time this user sent a mail */ - - /****************************************************************/ + /* Last time this user sent a memo command used */ + time_t lastmemosend; + /* Last time this user registered */ + time_t lastnickreg; + /* Last time this user sent an email */ + time_t lastmail; /** Create a new user object, initialising necessary fields and * adds it to the hash @@ -152,7 +173,7 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe */ const Anope::string &GetIdent() const; - /** Get the full mask ( nick!ident@realhost ) of a user + /** Get the full mask (nick!ident@realhost) of a user */ Anope::string GetMask() const; @@ -201,16 +222,16 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe virtual NickCore *Account() const; /** Check if the user is identified for their nick - * @param CheckNick True to check if the user is identified to the nickname they are on too + * @param check_nick True to check if the user is identified to the nickname they are on too * @return true or false */ - bool IsIdentified(bool CheckNick = false) const; + bool IsIdentified(bool check_nick = false) const; /** Check if the user is recognized for their nick (on the nicks access list) - * @param CheckSecure Only returns true if the user has secure off + * @param check_nick Only returns true if the user has secure off * @return true or false */ - bool IsRecognized(bool CheckSecure = true) const; + bool IsRecognized(bool check_nick = true) const; /** Check if the user is a services oper * @return true if they are an oper @@ -243,7 +264,7 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe * @param um The user mode * @param Param The param, if there is one */ - void SetModeInternal(UserMode *um, const Anope::string &Param = ""); + void SetModeInternal(UserMode *um, const Anope::string ¶m = ""); /** Remove a mode internally on the user, the IRCd is not informed * @param um The user mode @@ -255,14 +276,14 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe * @param um The user mode * @param Param Optional param for the mode */ - void SetMode(const BotInfo *bi, UserMode *um, const Anope::string &Param = ""); + void SetMode(const BotInfo *bi, UserMode *um, const Anope::string ¶m = ""); /** Set a mode on the user * @param bi The client setting the mode - * @param Name The mode name + * @param name The mode name * @param Param Optional param for the mode */ - void SetMode(const BotInfo *bi, UserModeName Name, const Anope::string &Param = ""); + void SetMode(const BotInfo *bi, UserModeName name, const Anope::string ¶m = ""); /** Remove a mode on the user * @param bi The client setting the mode @@ -272,9 +293,9 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe /** Remove a mode from the user * @param bi The client setting the mode - * @param Name The mode name + * @param name The mode name */ - void RemoveMode(const BotInfo *bi, UserModeName Name); + void RemoveMode(const BotInfo *bi, UserModeName name); /** Set a string of modes on a user * @param bi The client setting the modes @@ -316,16 +337,28 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe * @param reason The reason for the kill */ void KillInternal(const Anope::string &source, const Anope::string &reason); -}; - -extern CoreExport int32_t opcnt; -extern CoreExport uint32_t maxusercnt, usercnt; -extern CoreExport time_t maxusertime; -extern CoreExport User *finduser(const Anope::string &nick); + /* Returns a mask that will most likely match any address the + * user will have from that location. For IP addresses, wildcards the + * appropriate subnet mask (e.g. 35.1.1.1 -> 35.*; 128.2.1.1 -> 128.2.*); + * for named addresses, wildcards the leftmost part of the name unless the + * name only contains two parts. If the username begins with a ~, delete + * it. + */ + Anope::string Mask() const; -extern CoreExport bool matches_list(Channel *c, User *user, ChannelModeName mode); + /** Notes the usage of an incorrect password. If too many + * incorrect passwords are used the user might be killed. + * @return true if the user was killed + */ + bool BadPassword(); -extern CoreExport Anope::string create_mask(User *u); + /** Finds a user by nick, or possibly UID + * @param name The nick, or possibly UID, to lookup + * @param nick_only set to true to only look up by nick, not UID + * @return the user, if they exist + */ + static User* Find(const Anope::string &name, bool nick_only = false); +}; #endif // USERS_H diff --git a/include/oper.h b/include/xline.h index 6a18d3e2b..5d407d4ba 100644 --- a/include/oper.h +++ b/include/xline.h @@ -1,29 +1,31 @@ -/* OperServ support +/* * * (C) 2008-2012 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. + * */ -#ifndef OPER_H -#define OPER_H +#ifndef XLINE_H +#define XLINE_H #include "serialize.h" #include "service.h" +/* An Xline, eg, anything added with operserv/akill, or any of the operserv/sxline commands */ class CoreExport XLine : public Serializable { void InitRegex(); public: - Anope::string Mask; + Anope::string mask; Regex *regex; - Anope::string By; - time_t Created; - time_t Expires; - Anope::string Reason; + Anope::string by; + time_t created; + time_t expires; + Anope::string reason; XLineManager *manager; - Anope::string UID; + Anope::string id; XLine(const Anope::string &mask, const Anope::string &reason = "", const Anope::string &uid = ""); @@ -40,17 +42,18 @@ class CoreExport XLine : public Serializable bool HasNickOrReal() const; bool IsRegex() const; - Serialize::Data serialize() const anope_override; - static Serializable* unserialize(Serializable *obj, Serialize::Data &data); + Serialize::Data Serialize() const anope_override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &data); }; +/* Managers XLines. There is one XLineManager per type of XLine. */ class CoreExport XLineManager : public Service { char type; /* List of XLines in this XLineManager */ - serialize_checker<std::vector<XLine *> > XLines; + Serialize::Checker<std::vector<XLine *> > xlines; /* Akills can have the same IDs, sometimes */ - static serialize_checker<std::multimap<Anope::string, XLine *, ci::less> > XLinesByUID; + static Serialize::Checker<std::multimap<Anope::string, XLine *, ci::less> > XLinesByUID; public: /* List of XLine managers we check users against in XLineManager::CheckAll */ static std::list<XLineManager *> XLineManagers; @@ -174,4 +177,4 @@ class CoreExport XLineManager : public Service virtual void SendDel(XLine *x) = 0; }; -#endif // OPER_H +#endif // XLINE_H |
