diff options
author | Naram Qashat <cyberbotx@cyberbotx.com> | 2010-07-25 21:58:20 -0400 |
---|---|---|
committer | Naram Qashat <cyberbotx@cyberbotx.com> | 2010-07-25 21:58:20 -0400 |
commit | ae38212c1ce829c783edf971081c90137abb49a0 (patch) | |
tree | 5c652d9cdc38103dec6fa112d57fca882b4e3e44 | |
parent | 15d7f0f6fe8bb903275f603f734c13f65f3aa906 (diff) |
Epic commit to replace most of the strings in Anope with a single Anope::string class, plus some other little fixes here and there. If you follow 1.9.x development and are testing things, THIS is one of those things that NEEDS testing.
232 files changed, 7416 insertions, 8903 deletions
diff --git a/include/account.h b/include/account.h index 82ccb3871..11fcc6767 100644 --- a/include/account.h +++ b/include/account.h @@ -1,13 +1,15 @@ #ifndef ACCOUNT_H #define ACCOUNT_H +#include "anope.h" + class NickAlias; class NickCore; class NickRequest; -typedef unordered_map_namespace::unordered_map<ci::string, NickAlias *, hash_compare_ci_string> nickalias_map; -typedef unordered_map_namespace::unordered_map<ci::string, NickCore *, hash_compare_ci_string> nickcore_map; -typedef unordered_map_namespace::unordered_map<ci::string, NickRequest *, hash_compare_ci_string> nickrequest_map; +typedef unordered_map_namespace::unordered_map<Anope::string, NickAlias *, hash_compare_ci_string> nickalias_map; +typedef unordered_map_namespace::unordered_map<Anope::string, NickCore *, hash_compare_ci_string> nickcore_map; +typedef unordered_map_namespace::unordered_map<Anope::string, NickRequest *, hash_compare_ci_string> nickrequest_map; extern CoreExport nickalias_map NickAliasList; extern CoreExport nickcore_map NickCoreList; @@ -86,14 +88,14 @@ enum NickCoreFlag class CoreExport NickRequest : public Extensible { public: - NickRequest(const std::string &nickname); + NickRequest(const Anope::string &nickname); ~NickRequest(); - char *nick; - std::string passcode; - std::string password; - char *email; + Anope::string nick; + Anope::string passcode; + Anope::string password; + Anope::string email; time_t requested; time_t lastmail; /* Unsaved */ }; @@ -107,19 +109,19 @@ class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag, NS_EN * @param nickname The nick * @param nickcore The nickcofe for this nick */ - NickAlias(const std::string &nickname, NickCore *nickcore); + NickAlias(const Anope::string &nickname, NickCore *nickcore); /** Default destructor */ ~NickAlias(); - char *nick; /* Nickname */ - char *last_quit; /* Last quit message */ - char *last_realname; /* Last realname */ - char *last_usermask; /* Last usermask */ - time_t time_registered; /* When the nick was registered */ - time_t last_seen; /* When it was seen online for the last time */ - NickCore *nc; /* I'm an alias of this */ + Anope::string nick; /* Nickname */ + Anope::string last_quit; /* Last quit message */ + Anope::string last_realname; /* Last realname */ + Anope::string last_usermask; /* Last usermask */ + time_t time_registered; /* When the nick was registered */ + time_t last_seen; /* When it was seen online for the last time */ + NickCore *nc; /* I'm an alias of this */ HostInfo hostinfo; /** Release a nick @@ -138,10 +140,10 @@ class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag, NS_EN class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END> { public: - /** Default constructor + /** Default constructor * @param display The display nick */ - NickCore(const std::string &nickdisplay); + NickCore(const Anope::string &nickdisplay); /** Default destructor */ @@ -149,12 +151,12 @@ class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END std::list<User *> Users; - char *display; /* How the nick is displayed */ - std::string pass; /* Password of the nicks */ - char *email; /* E-mail associated to the nick */ - char *greet; /* Greet associated to the nick */ - uint16 language; /* Language selected by nickname owner (LANG_*) */ - std::vector<std::string> access; /* Access list, vector of strings */ + 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 */ + uint16 language; /* Language selected by nickname owner (LANG_*) */ + std::vector<Anope::string> access; /* Access list, vector of strings */ MemoInfo memos; uint16 channelcount; /* Number of channels currently registered */ @@ -168,7 +170,7 @@ class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END * @param cmdstr The string to check, e.g. botserv/set/private. * @return True if this opertype may run the specified command, false otherwise. */ - virtual bool HasCommand(const ci::string &cmdstr) const; + virtual bool HasCommand(const Anope::string &cmdstr) const; /** Checks whether this account is a services oper or not. * @return True if this account is a services oper, false otherwise. @@ -179,7 +181,7 @@ class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END * @param privstr The priv to check for, e.g. users/auspex. * @return True if this opertype has the specified priv, false otherwise. */ - virtual bool HasPriv(const ci::string &privstr) const; + virtual bool HasPriv(const Anope::string &privstr) const; /** Add an entry to the nick's access list * @@ -187,7 +189,7 @@ class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END * * Adds a new entry into the access list. */ - void AddAccess(const std::string &entry); + void AddAccess(const Anope::string &entry); /** Get an entry from the nick's access list by index * @@ -196,7 +198,7 @@ class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END * * Retrieves an entry from the access list corresponding to the given index. */ - std::string GetAccess(unsigned entry); + Anope::string GetAccess(unsigned entry); /** Find an entry in the nick's access list * @@ -205,7 +207,7 @@ class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END * * Search for an entry within the access list. */ - bool FindAccess(const std::string &entry); + bool FindAccess(const Anope::string &entry); /** Erase an entry from the nick's access list * @@ -213,7 +215,7 @@ class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END * * Removes the specified access list entry from the access list. */ - void EraseAccess(const std::string &entry); + void EraseAccess(const Anope::string &entry); /** Clears the entire nick's access list * diff --git a/include/anope.h b/include/anope.h new file mode 100644 index 000000000..e73f04157 --- /dev/null +++ b/include/anope.h @@ -0,0 +1,363 @@ +/* + * (C) 2003-2010 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for furhter details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +#ifndef ANOPE_H +#define ANOPE_H + +#include <string> +#include <vector> +#include "hashcomp.h" + +struct Message; + +namespace Anope +{ + /** + * A wrapper string class around all the other string classes, this class will + * allow us to only require one type of string everywhere that can be converted + * at any time to a specific type of string. + */ + class string + { + private: + /** + * The actual string is stored in an std::string as it can be converted to + * ci::string, irc::string, or a C-style string at any time. + */ + std::string _string; + public: + /** + * Extras. + */ + typedef std::string::iterator iterator; + typedef std::string::const_iterator const_iterator; + typedef std::string::reverse_iterator reverse_iterator; + typedef std::string::const_reverse_iterator const_reverse_iterator; + typedef std::string::size_type size_type; + static const size_type npos = static_cast<size_type>(-1); + + /** + * Constructors that can take in any type of string. + */ + string() : _string("") { } + string(char chr) : _string() { _string = chr; } + string(size_type n, char chr) : _string(n, chr) { } + string(const char *_str) : _string(_str) { } + string(const std::string &_str) : _string(_str) { } + string(const ci::string &_str) : _string(_str.c_str()) { } + string(const irc::string &_str) : _string(_str.c_str()) { } + string(const string &_str, size_type pos = 0, size_type n = npos) : _string(_str._string, pos, n) { } + template <class InputIterator> string(InputIterator first, InputIterator last) : _string(first, last) { } + + /** + * Assignment operators, so any type of string can be assigned to this class. + */ + inline string &operator=(char chr) { this->_string = chr; return *this; } + inline string &operator=(const char *_str) { this->_string = _str; return *this; } + inline string &operator=(const std::string &_str) { this->_string = _str; return *this; } + inline string &operator=(const ci::string &_str) { this->_string = _str.c_str(); return *this; } + inline string &operator=(const irc::string &_str) { this->_string = _str.c_str(); return *this; } + inline string &operator=(const string &_str) { if (this != &_str) this->_string = _str._string; return *this; } + + /** + * Equality operators, to compare to any type of string. + */ + inline bool operator==(const char *_str) const { return this->_string == _str; } + inline bool operator==(const std::string &_str) const { return this->_string == _str; } + inline bool operator==(const ci::string &_str) const { return ci::string(this->_string.c_str()) == _str; } + inline bool operator==(const irc::string &_str) const { return irc::string(this->_string.c_str()) == _str; } + inline bool operator==(const string &_str) const { return this->_string == _str._string; } + + inline bool equals_cs(const char *_str) const { return this->_string == _str; } + inline bool equals_cs(const std::string &_str) const { return this->_string == _str; } + inline bool equals_cs(const ci::string &_str) const { return this->_string == _str.c_str(); } + inline bool equals_cs(const irc::string &_str) const { return this->_string == _str.c_str(); } + inline bool equals_cs(const string &_str) const { return this->_string == _str._string; } + + inline bool equals_ci(const char *_str) const { return ci::string(this->_string.c_str()) == _str; } + inline bool equals_ci(const std::string &_str) const { return ci::string(this->_string.c_str()) == _str.c_str(); } + inline bool equals_ci(const ci::string &_str) const { return _str == this->_string.c_str(); } + inline bool equals_ci(const irc::string &_str) const { return ci::string(this->_string.c_str()) == _str.c_str(); } + inline bool equals_ci(const string &_str) const { return ci::string(this->_string.c_str()) == _str._string.c_str(); } + + inline bool equals_irc(const char *_str) const { return irc::string(this->_string.c_str()) == _str; } + inline bool equals_irc(const std::string &_str) const { return irc::string(this->_string.c_str()) == _str.c_str(); } + inline bool equals_irc(const ci::string &_str) const { return irc::string(this->_string.c_str()) == _str.c_str(); } + inline bool equals_irc(const irc::string &_str) const { return _str == this->_string.c_str(); } + inline bool equals_irc(const string &_str) const { return irc::string(this->_string.c_str()) == _str._string.c_str(); } + + /** + * Inequality operators, exact opposites of the above. + */ + inline bool operator!=(const char *_str) const { return !operator==(_str); } + inline bool operator!=(const std::string &_str) const { return !operator==(_str); } + inline bool operator!=(const ci::string &_str) const { return !operator==(_str); } + inline bool operator!=(const irc::string &_str) const { return !operator==(_str); } + inline bool operator!=(const string &_str) const { return !operator==(_str); } + + /** + * Compound addition operators, overloaded to do concatenation. + */ + inline string &operator+=(char chr) { this->_string += chr; return *this; } + inline string &operator+=(const char *_str) { this->_string += _str; return *this; } + inline string &operator+=(const std::string &_str) { this->_string += _str; return *this; } + inline string &operator+=(const ci::string &_str) { this->_string += _str.c_str(); return *this; } + inline string &operator+=(const irc::string &_str) { this->_string += _str.c_str(); return *this; } + inline string &operator+=(const string &_str) { if (this != &_str) this->_string += _str._string; return *this; } + + /** + * Addition operators, overloaded to do concatenation. + */ + inline const string operator+(char chr) const { return string(*this) += chr; } + inline const string operator+(const char *_str) const { return string(*this) += _str; } + inline const string operator+(const std::string &_str) const { return string(*this) += _str; } + inline const string operator+(const ci::string &_str) const { return string(*this) += _str; } + inline const string operator+(const irc::string &_str) const { return string(*this) += _str; } + inline const string operator+(const string &_str) const { return string(*this) += _str; } + + friend const string operator+(char chr, const string &str); + friend const string operator+(const char *_str, const string &str); + friend const string operator+(const std::string &_str, const string &str); + friend const string operator+(const ci::string &_str, const string &str); + friend const string operator+(const irc::string &_str, const string &str); + + /** + * Less-than operator. + */ + inline bool operator<(const string &_str) const { return this->_string < _str._string; } + + /** + * The following functions return the various types of strings. + */ + inline const char *c_str() const { return this->_string.c_str(); } + inline std::string &str() { return this->_string; } + inline const std::string &str() const { return this->_string; } + inline ci::string ci_str() const { return ci::string(this->_string.c_str()); } + inline irc::string irc_str() const { return irc::string(this->_string.c_str()); } + + /** + * Returns if the string is empty or not. + */ + inline bool empty() const { return this->_string.empty(); } + + /** + * Returns the string's length. + */ + inline size_type length() const { return this->_string.length(); } + + /** + * Erases characters from the string. + */ + inline iterator erase(const iterator &i) { return this->_string.erase(i); } + inline iterator erase(const iterator &first, const iterator &last) { return this->_string.erase(first, last); } + inline void erase(size_type pos = 0, size_type n = std::string::npos) { this->_string.erase(pos, n); } + + /** + * Clears the string. + */ + inline void clear() { this->_string.clear(); } + + /** + * Find substrings of the string. + */ + inline size_type find(const string &_str, size_type pos = 0) const { return this->_string.find(_str._string, pos); } + inline size_type find(char chr, size_type pos = 0) const { return this->_string.find(chr, pos); } + inline size_type find_ci(const string &_str, size_type pos = 0) const { return ci::string(this->_string.c_str()).find(ci::string(_str._string.c_str()), pos); } + inline size_type find_ci(char chr, size_type pos = 0) const { return ci::string(this->_string.c_str()).find(chr, pos); } + + inline size_type rfind(const string &_str, size_type pos = npos) const { return this->_string.rfind(_str._string, pos); } + inline size_type rfind(char chr, size_type pos = npos) const { return this->_string.rfind(chr, pos); } + inline size_type rfind_ci(const string &_str, size_type pos = npos) const { return ci::string(this->_string.c_str()).rfind(ci::string(_str._string.c_str()), pos); } + inline size_type rfind_ci(char chr, size_type pos = npos) const { return ci::string(this->_string.c_str()).rfind(chr, pos); } + + inline size_type find_first_of(const string &_str, size_type pos = 0) const { return this->_string.find_first_of(_str._string, pos); } + inline size_type find_first_of_ci(const string &_str, size_type pos = 0) const { return ci::string(this->_string.c_str()).find_first_of(ci::string(_str._string.c_str()), pos); } + + inline size_type find_first_not_of(const string &_str, size_type pos = 0) const { return this->_string.find_first_not_of(_str._string, pos); } + inline size_type find_first_not_of_ci(const string &_str, size_type pos = 0) const { return ci::string(this->_string.c_str()).find_first_not_of(ci::string(_str._string.c_str()), pos); } + + inline size_type find_last_of(const string &_str, size_type pos = npos) const { return this->_string.find_last_of(_str._string, pos); } + inline size_type find_last_of_ci(const string &_str, size_type pos = npos) const { return ci::string(this->_string.c_str()).find_last_of(ci::string(_str._string.c_str()), pos); } + + inline size_type find_last_not_of(const string &_str, size_type pos = npos) const { return this->_string.find_last_not_of(_str._string, pos); } + inline size_type find_last_not_of_ci(const string &_str, size_type pos = npos) const { return ci::string(this->_string.c_str()).find_last_not_of(ci::string(_str._string.c_str()), pos); } + + /** + * Determine if string consists of only numbers. + */ + inline bool is_number_only() const { return this->find_first_not_of("0123456789.-") == npos; } + + /** + * Replace parts of the string. + */ + inline string replace(size_type pos, size_type n, const string &_str) { return string(this->_string.replace(pos, n, _str._string)); } + inline string replace(size_type pos, size_type n, const string &_str, size_type pos1, size_type n1) { return string(this->_string.replace(pos, n, _str._string, pos1, n1)); } + inline string replace(size_type pos, size_type n, size_type n1, char chr) { return string(this->_string.replace(pos, n, n1, chr)); } + inline string replace(iterator first, iterator last, const string &_str) { return string(this->_string.replace(first, last, _str._string)); } + inline string replace(iterator first, iterator last, size_type n, char chr) { return string(this->_string.replace(first, last, n, chr)); } + template <class InputIterator> inline string replace(iterator first, iterator last, InputIterator f, InputIterator l) { return string(this->_string.replace(first, last, f, l)); } + inline string replace_all_cs(const string &_orig, const string &_repl) + { + Anope::string new_string = *this; + size_type pos = new_string.find(_orig), orig_length = _orig.length(); + while (pos != npos) + { + new_string.replace(pos, pos + orig_length, _repl); + pos = new_string.find(_orig, pos + orig_length); + } + return new_string; + } + inline string replace_all_ci(const string &_orig, const string &_repl) + { + Anope::string new_string = *this; + size_type pos = new_string.find_ci(_orig), orig_length = _orig.length(); + while (pos != npos) + { + new_string.replace(pos, pos + orig_length, _repl); + pos = new_string.find_ci(_orig, pos + orig_length); + } + return new_string; + } + + /** + * Get a substring of the string. + */ + inline string substr(size_type pos = 0, size_type n = npos) const { return string(this->_string.substr(pos, n)); } + + /** + * Iterators to the string. + */ + inline iterator begin() { return this->_string.begin(); } + inline const_iterator begin() const { return this->_string.begin(); } + inline iterator end() { return this->_string.end(); } + inline const_iterator end() const { return this->_string.end(); } + inline reverse_iterator rbegin() { return this->_string.rbegin(); } + inline const_reverse_iterator rbegin() const { return this->_string.rbegin(); } + inline reverse_iterator rend() { return this->_string.rend(); } + inline const_reverse_iterator rend() const { return this->_string.rend(); } + + /** + * Subscript operator, to access individual characters of the string. + */ + inline char &operator[](size_type n) { return this->_string[n]; } + inline const char &operator[](size_type n) const { return this->_string[n]; } + + /** + * Stream insertion operator, must be friend because they cannot be inside the class. + */ + friend std::ostream &operator<<(std::ostream &os, const string &_str); + }; + + inline std::ostream &operator<<(std::ostream &os, const string &_str) { return os << _str._string; } + + inline const string operator+(char chr, const string &str) { string tmp(chr); tmp += str; return tmp; } + inline const string operator+(const char *_str, const string &str) { string tmp(_str); tmp += str; return tmp; } + inline const string operator+(const std::string &_str, const string &str) { string tmp(_str); tmp += str; return tmp; } + inline const string operator+(const ci::string &_str, const string &str) { string tmp(_str); tmp += str; return tmp; } + inline const string operator+(const irc::string &_str, const string &str) { string tmp(_str); tmp += str; return tmp; } + + static const char *const compiled = __TIME__ " " __DATE__; + + extern string Version(); + + extern string Build(); + + /** 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) + * @param case_sensitive Whether or not the match is case sensitive, default false. + */ + extern bool Match(const Anope::string &str, const Anope::string &mask, bool case_sensitive = false); + + /** Add a message to Anope + * @param name The message name as sent by the IRCd + * @param func A callback function that will be called when this message is received + * @return The new message object + */ + extern Message *AddMessage(const string &name, int (*func)(const string &source, int ac, const char **av)); + + /** Deletes a message from Anope + * XXX Im not sure what will happen if this function is called indirectly from message function pointed to by this message.. must check + * @param m The message + * @return true if the message was found and deleted, else false + */ + extern bool DelMessage(Message *m); + + /** Returns a list of pointers to message handlers + * @param The message name as sent by the IRCd + * @return a vector with pointers to the messagehandlers (you can bind more than one handler to a message) + */ + extern std::vector<Message *> FindMessage(const string &name); +} + +/** sepstream allows for splitting token seperated lists. + * Each successive call to sepstream::GetToken() returns + * the next token, until none remain, at which point the method returns + * an empty string. + */ +class CoreExport sepstream +{ + private: + /** Original string. + */ + Anope::string tokens; + /** Last position of a seperator token + */ + Anope::string::iterator last_starting_position; + /** Current string position + */ + Anope::string::iterator n; + /** Seperator value + */ + char sep; + public: + /** 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); + + /** Fetch the entire remaining stream, without tokenizing + * @return The remaining part of the stream + */ + virtual 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(); +}; + +/** A derived form of sepstream, which seperates on commas + */ +class commasepstream : public sepstream +{ + public: + /** Initialize with comma seperator + */ + commasepstream(const Anope::string &source) : sepstream(source, ',') { } +}; + +/** A derived form of sepstream, which seperates on spaces + */ +class spacesepstream : public sepstream +{ + public: + /** Initialize with space seperator + */ + spacesepstream(const Anope::string &source) : sepstream(source, ' ') { } +}; + +#endif // ANOPE_H diff --git a/include/bots.h b/include/bots.h index cd95467b5..3d35f569e 100644 --- a/include/bots.h +++ b/include/bots.h @@ -12,8 +12,8 @@ class BotInfo; -typedef unordered_map_namespace::unordered_map<ci::string, BotInfo *, hash_compare_ci_string> botinfo_map; -typedef unordered_map_namespace::unordered_map<std::string, BotInfo *, hash_compare_std_string> botinfo_uid_map; +typedef unordered_map_namespace::unordered_map<Anope::string, BotInfo *, hash_compare_ci_string> botinfo_map; +typedef unordered_map_namespace::unordered_map<Anope::string, BotInfo *, hash_compare_std_string> botinfo_uid_map; extern CoreExport botinfo_map BotListByNick; extern CoreExport botinfo_uid_map BotListByUID; @@ -32,8 +32,8 @@ enum BotFlag class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END> { public: - time_t created; /* Birth date ;) */ - time_t lastmsg; /* Last time we said something */ + time_t created; /* Birth date ;) */ + time_t lastmsg; /* Last time we said something */ CommandMap Commands; /* Commands on this bot */ /** Create a new bot. @@ -42,7 +42,7 @@ class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END> * @param host The hostname to give the bot. * @param real The realname to give the bot. */ - BotInfo(const std::string &nick, const std::string &user = "", const std::string &host = "", const std::string &real = ""); + BotInfo(const Anope::string &nick, const Anope::string &user = "", const Anope::string &host = "", const Anope::string &real = ""); /** Destroy a bot, clearing up appropriately. */ @@ -51,7 +51,7 @@ class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END> /** Change the nickname for the bot. * @param newnick The nick to change to */ - void SetNewNick(const std::string &newnick); + void SetNewNick(const Anope::string &newnick); /** Rejoins all channels that this bot is assigned to. * Used on /kill, rename, etc. @@ -71,8 +71,8 @@ class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END> void UnAssign(User *u, ChannelInfo *ci); void Join(Channel *c); - void Join(const std::string &chname); - void Part(Channel *c, const std::string &reason = ""); + void Join(const Anope::string &chname); + void Part(Channel *c, const Anope::string &reason = ""); }; #endif // BOTS_H diff --git a/include/channels.h b/include/channels.h index 7cdc32de3..8bf98e4b9 100644 --- a/include/channels.h +++ b/include/channels.h @@ -9,20 +9,25 @@ #ifndef CHANNELS_H #define CHANNELS_H -typedef unordered_map_namespace::unordered_map<ci::string, Channel *, hash_compare_ci_string> channel_map; +typedef unordered_map_namespace::unordered_map<Anope::string, Channel *, hash_compare_ci_string> channel_map; extern CoreExport channel_map ChannelList; struct UserData { UserData() { - lastline = NULL; + Clear(); + } + + virtual ~UserData() { } + + void Clear() + { last_use = last_start = time(NULL); lines = times = 0; + lastline.clear(); } - virtual ~UserData() { delete [] lastline; } - /* Data validity */ time_t last_use; @@ -31,7 +36,7 @@ struct UserData time_t last_start; /* for repeat kicker */ - char *lastline; + Anope::string lastline; int16 times; }; @@ -60,7 +65,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags, CMODE_E private: /** A map of channel modes with their parameters set on this channel */ - std::map<ChannelModeName, std::string> Params; + std::map<ChannelModeName, Anope::string> Params; /* Modes set on the channel */ Flags<ChannelModeName, CMODE_END> modes; @@ -70,17 +75,17 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags, CMODE_E * @param name The channel name * @param ts The time the channel was created */ - Channel(const std::string &name, time_t ts = time(NULL)); + Channel(const Anope::string &name, time_t ts = time(NULL)); /** Default destructor */ ~Channel(); - std::string name; /* Channel name */ + Anope::string name; /* Channel name */ ChannelInfo *ci; /* Corresponding ChannelInfo */ time_t creation_time; /* When channel was created */ - char *topic; - std::string topic_setter; + Anope::string topic; + Anope::string topic_setter; time_t topic_time; /* When topic was set */ EList *bans; @@ -137,7 +142,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags, CMODE_E /** See if the channel has any modes at all * @return true or false */ - inline const bool HasModes() const { return modes.FlagCount(); } + inline bool HasModes() const { return modes.FlagCount(); } /** See if a channel has a mode * @param Name The mode name @@ -150,14 +155,14 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags, CMODE_E * @param param The param * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ - void SetModeInternal(ChannelMode *cm, const std::string ¶m = "", bool EnforceMLock = true); + void SetModeInternal(ChannelMode *cm, const Anope::string ¶m = "", bool EnforceMLock = true); /** Remove a mode internally on a channel, this is not sent out to the IRCd * @param cm The mode * @param param The param * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ - void RemoveModeInternal(ChannelMode *cm, const std::string ¶m = "", bool EnforceMLock = true); + void RemoveModeInternal(ChannelMode *cm, const Anope::string ¶m = "", bool EnforceMLock = true); /** Set a mode on a channel * @param bi The client setting the modes @@ -165,7 +170,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags, CMODE_E * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ - void SetMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m = "", bool EnforceMLock = true); + void SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool EnforceMLock = true); /** * Set a mode on a channel @@ -174,7 +179,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags, CMODE_E * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ - void SetMode(BotInfo *bi, ChannelModeName Name, const std::string ¶m = "", bool EnforceMLock = true); + void SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m = "", bool EnforceMLock = true); /** * Set a mode on a channel @@ -183,7 +188,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags, CMODE_E * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ - void SetMode(BotInfo *bi, char Mode, const std::string ¶m = "", bool EnforceMLock = true); + void SetMode(BotInfo *bi, char Mode, const Anope::string ¶m = "", bool EnforceMLock = true); /** Remove a mode from a channel * @param bi The client setting the modes @@ -191,7 +196,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags, CMODE_E * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ - void RemoveMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m = "", bool EnforceMLock = true); + void RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool EnforceMLock = true); /** * Remove a mode from a channel @@ -200,7 +205,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags, CMODE_E * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ - void RemoveMode(BotInfo *bi, ChannelModeName Name, const std::string ¶m = "", bool EnforceMLock = true); + void RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m = "", bool EnforceMLock = true); /** * Remove a mode from a channel * @param bi The client setting the modes @@ -208,7 +213,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags, CMODE_E * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ - void RemoveMode(BotInfo *bi, char Mode, const std::string ¶m = "", bool EnforceMLock = true); + void RemoveMode(BotInfo *bi, char Mode, const Anope::string ¶m = "", bool EnforceMLock = true); /** Clear all the modes from the channel * @param bi The client unsetting the modes @@ -235,7 +240,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags, CMODE_E * @param Target a string to put the param into * @return true on success */ - const bool GetParam(ChannelModeName Name, std::string &Target); + const bool GetParam(ChannelModeName Name, Anope::string &Target); /** Check if a mode is set and has a param * @param Name The mode @@ -253,7 +258,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags, CMODE_E * @param nick The nick being kicked * @param reason The reason for the kick */ - void KickInternal(const std::string &source, const std::string &nick, const std::string &reason); + void KickInternal(const Anope::string &source, const Anope::string &nick, const Anope::string &reason); /** Kick a user from the channel * @param bi The sender, can be NULL for the service bot for this channel diff --git a/include/commands.h b/include/commands.h index cfe2eddab..71fee7e42 100644 --- a/include/commands.h +++ b/include/commands.h @@ -18,7 +18,7 @@ class Module; class BotInfo; class Command; -typedef std::map<ci::string, Command *> CommandMap; +typedef std::map<Anope::string, Command *, hash_compare_ci_string> CommandMap; /** The return value from commands. */ @@ -28,10 +28,10 @@ enum CommandReturn MOD_STOP }; -extern CoreExport Command *FindCommand(BotInfo *bi, const ci::string &cmd); -extern CoreExport void mod_help_cmd(BotInfo *bi, User *u, const ci::string &cmd); -extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, const std::string &message); -extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, const ci::string &message); +extern CoreExport Command *FindCommand(BotInfo *bi, const Anope::string &cmd); +extern CoreExport void mod_help_cmd(BotInfo *bi, User *u, const Anope::string &cmd); +extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &message); +extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, const Anope::string &message); enum CommandFlag { @@ -53,9 +53,9 @@ class CoreExport Command : public Flags<CommandFlag> /* Minimum parameters required to use this command */ size_t MinParams; /* Command name */ - ci::string name; + Anope::string name; /* Permission needed to use this comand */ - ci::string permission; + Anope::string permission; /* Module which owns us */ Module *module; @@ -68,14 +68,14 @@ class CoreExport Command : public Flags<CommandFlag> * @param max_params The maximum number of parameters the parser will create, after max_params, all will be combined into the last argument. * NOTE: If max_params is not set (default), there is no limit to the max number of params. */ - Command(const ci::string &sname, size_t min_params, size_t max_params = 0, const ci::string &spermission = ""); + Command(const Anope::string &sname, size_t min_params, size_t max_params = 0, const Anope::string &spermission = ""); virtual ~Command(); /** Execute this command. * @param u The user executing the command. */ - virtual CommandReturn Execute(User *u, const std::vector<ci::string> &); + virtual CommandReturn Execute(User *u, const std::vector<Anope::string> &); /** Called when HELP is requsted for the client this command is on. * @param u The user requesting help @@ -87,18 +87,18 @@ class CoreExport Command : public Flags<CommandFlag> * @param subcommand The subcommand the user is requesting help on, or an empty string. (e.g. /ns help set foo bar lol gives a subcommand of "FOO BAR LOL") * @return true if help was provided to the user, false otherwise. */ - virtual bool OnHelp(User *u, const ci::string &subcommand); + virtual bool OnHelp(User *u, const Anope::string &subcommand); /** Requested when the user provides bad syntax to this command (not enough params, etc). * @param u The user executing the command. * @param subcommand The subcommand the user tried to use */ - virtual void OnSyntaxError(User *u, const ci::string &subcommand); + virtual void OnSyntaxError(User *u, const Anope::string &subcommand); /** Set which command permission (e.g. chanserv/forbid) is required for this command. * @param reststr The permission required to successfully execute this command */ - void SetPermission(const ci::string &reststr); + void SetPermission(const Anope::string &reststr); /** Add a subcommand to this command * @param c The command @@ -108,7 +108,7 @@ class CoreExport Command : public Flags<CommandFlag> /** Delete a subcommand from this command * @param cname The subcommand name */ - virtual bool DelSubcommand(const ci::string &cname); + virtual bool DelSubcommand(const Anope::string &cname); }; #endif // COMMANDS_H diff --git a/include/config.h b/include/config.h index 34315e3c8..ef7445041 100644 --- a/include/config.h +++ b/include/config.h @@ -8,9 +8,11 @@ #include <map> #include <deque> +#include "anope.h" + /** A configuration key and value pair */ -typedef std::pair<ci::string, ci::string> KeyVal; +typedef std::pair<Anope::string, Anope::string> KeyVal; /** A list of related configuration keys and values */ @@ -18,7 +20,7 @@ typedef std::vector<KeyVal> KeyValList; /** An entire config file, built up of KeyValLists */ -typedef std::multimap<ci::string, KeyValList> ConfigDataHash; +typedef std::multimap<Anope::string, KeyValList> ConfigDataHash; // Required forward definitions class ServerConfig; @@ -32,8 +34,9 @@ enum ConfigDataType DT_UINTEGER, // Unsigned Integer DT_LUINTEGER, // Long Unsigned Integer DT_CHARPTR, // Char pointer - DT_STRING, // std::string + DT_CSSTRING, // std::string DT_CISTRING, // ci::string + DT_STRING, // Anope::string DT_BOOLEAN, // Boolean DT_HOSTNAME, // Hostname syntax DT_NOSPACES, // No spaces @@ -54,7 +57,7 @@ class ValueItem { private: /** Actual data */ - std::string v; + Anope::string v; public: /** Initialize with an int */ ValueItem(int); @@ -64,8 +67,10 @@ class ValueItem ValueItem(const char *); /** Initialize with an std::string */ ValueItem(const std::string &); - /** Initialize with an std::string */ + /** Initialize with a ci::string */ ValueItem(const ci::string &); + /** Initialize with an Anope::string */ + ValueItem(const Anope::string &); /** Initialize with a long */ ValueItem(long); /** Change value to a char pointer */ @@ -76,16 +81,20 @@ class ValueItem void Set(const std::string &); /** Change value to a ci::string */ void Set(const ci::string &); + /** Change value to an Anope::string */ + void Set(const Anope::string &); /** Change value to an int */ void Set(int); /** Get value as an int */ int GetInteger(); /** Get value as a string */ const char *GetString() const; - /** Get value as a string */ - inline const std::string &GetValue() const { return v; } + /** Get value as an std::string */ + inline const std::string GetCSValue() const { return v.str(); } /** Get value as a ci::string */ - inline const ci::string GetCIValue() const { return v.c_str(); } + inline const ci::string GetCIValue() const { return v.ci_str(); } + /** Get value as a ci::string */ + inline const Anope::string &GetValue() const { return v; } /** Get value as a bool */ bool GetBool(); }; @@ -240,6 +249,47 @@ template<> class ValueContainer<ci::string *> : public ValueContainerBase } }; +/** This a specific version of ValueContainer to handle Anope::string specially + */ +template<> class ValueContainer<Anope::string *> : public ValueContainerBase +{ + private: + /** Contained item */ + Anope::string *val; + public: + /** Initialize with nothing */ + ValueContainer() : ValueContainerBase(), val(NULL) { } + /** Initialize with an std::string */ + ValueContainer(Anope::string *Val) : ValueContainerBase(), val(Val) { } + /** Initialize with a copy */ + ValueContainer(const ValueContainer &Val) : ValueContainerBase(), val(Val.val) { } + ValueContainer &operator=(const ValueContainer &Val) + { + val = Val.val; + return *this; + } + /** Change value to given std::string */ + void Set(const std::string &newval) + { + *val = newval; + } + /** Change value to given ci::string */ + void Set(const ci::string &newval) + { + *val = newval; + } + /** Change value to given Anope::string */ + void Set(const Anope::string &newval) + { + *val = newval; + } + /** Change value to given char pointer */ + void Set(const char *newval) + { + *val = newval; + } +}; + /** A specialization of ValueContainer to hold a pointer to a bool */ typedef ValueContainer<bool *> ValueContainerBool; @@ -272,37 +322,42 @@ typedef ValueContainer<time_t *> ValueContainerTime; /** A specialization of ValueContainer to hold a pointer to * an std::string */ -typedef ValueContainer<std::string *> ValueContainerString; +typedef ValueContainer<std::string *> ValueContainerCSString; /** A specialization of ValueContainer to hold a pointer to * an ci::string */ typedef ValueContainer<ci::string *> ValueContainerCIString; +/** A specialization of ValueContainer to hold a pointer to + * an Anope::string + */ +typedef ValueContainer<Anope::string *> ValueContainerString; + /** A set of ValueItems used by multi-value validator functions */ typedef std::deque<ValueItem> ValueList; /** A callback for validating a single value */ -typedef bool (*Validator)(ServerConfig *, const char *, const char *, ValueItem &); +typedef bool (*Validator)(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &); /** A callback for validating multiple value entries */ -typedef bool (*MultiValidator)(ServerConfig *, const char *, const char **, ValueList &, int *, bool); +typedef bool (*MultiValidator)(ServerConfig *, const Anope::string &, const Anope::string *, ValueList &, int *, bool); /** A callback indicating the end of a group of entries */ -typedef bool (*MultiNotify)(ServerConfig *, const char *, bool); +typedef bool (*MultiNotify)(ServerConfig *, const Anope::string &, bool); /** Holds a core configuration item and its callbacks */ struct InitialConfig { /** Tag name */ - const char *tag; + const Anope::string tag; /** Value name */ - const char *value; + const Anope::string value; /** Default, if not defined */ - const char *default_value; + const Anope::string default_value; /** Value containers */ ValueContainerBase *val; /** Data types */ @@ -317,11 +372,11 @@ struct InitialConfig struct MultiConfig { /** Tag name */ - const char *tag; + const Anope::string tag; /** One or more items within tag */ - const char *items[17]; + const Anope::string items[17]; /** One or more defaults for items within tags */ - const char *items_default[17]; + const Anope::string items_default[17]; /** One or more data types */ int datatype[17]; /** Initialization function */ @@ -348,7 +403,7 @@ class ServerConfig std::vector<std::string> include_stack; /** Check that there is only one of each configuration item */ - bool CheckOnce(const char *); + bool CheckOnce(const Anope::string &); public: std::ostringstream errstr; ConfigDataHash newconfig; @@ -373,98 +428,63 @@ class ServerConfig * this connection as SNOTICEs. * If the parameter is NULL, the messages are spooled to all connections via WriteOpers as SNOTICEs. */ - void ReportConfigError(const std::string &, bool); + void ReportConfigError(const Anope::string &, bool); /** Load 'filename' into 'target', with the new config parser everything is parsed into * tag/key/value at load-time rather than at read-value time. */ - bool LoadConf(ConfigDataHash &, const char *, std::ostringstream &); - /** Load 'filename' into 'target', with the new config parser everything is parsed into - * tag/key/value at load-time rather than at read-value time. - */ - bool LoadConf(ConfigDataHash &, const std::string &, std::ostringstream &); - /** Load 'filename' into 'target', with the new config parser everything is parsed into - * tag/key/value at load-time rather than at read-value time. - */ - bool LoadConf(ConfigDataHash &, const ci::string &, std::ostringstream &); + bool LoadConf(ConfigDataHash &, const Anope::string &, std::ostringstream &); // Both these return true if the value existed or false otherwise /** Writes 'length' chars into 'result' as a string */ - bool ConfValue(ConfigDataHash &, const char *, const char *, int, char *, int, bool = false); - /** Writes 'length' chars into 'result' as a string - */ - bool ConfValue(ConfigDataHash &, const char *, const char *, const char *, int, char *, int, bool = false); + bool ConfValue(ConfigDataHash &, const Anope::string &, const Anope::string &, int, Anope::string &, bool = false); /** Writes 'length' chars into 'result' as a string */ - bool ConfValue(ConfigDataHash &, const ci::string &, const ci::string &, int, ci::string &, bool = false); - /** Writes 'length' chars into 'result' as a string - */ - bool ConfValue(ConfigDataHash &, const ci::string &, const ci::string &, const ci::string &, int, ci::string &, bool = false); - /** Tries to convert the value to an integer and write it to 'result' - */ - bool ConfValueInteger(ConfigDataHash &, const char *, const char *, int, int &); + bool ConfValue(ConfigDataHash &, const Anope::string &, const Anope::string &, const Anope::string &, int, Anope::string &, bool = false); /** Tries to convert the value to an integer and write it to 'result' */ - bool ConfValueInteger(ConfigDataHash &, const char *, const char *, const char *, int, int &); + bool ConfValueInteger(ConfigDataHash &, const Anope::string &, const Anope::string &, int, int &); /** Tries to convert the value to an integer and write it to 'result' */ - bool ConfValueInteger(ConfigDataHash &, const ci::string &, const ci::string &, int, int &); - /** Tries to convert the value to an integer and write it to 'result' - */ - bool ConfValueInteger(ConfigDataHash &, const ci::string &, const ci::string &, const ci::string &, int, int &); - /** Returns true if the value exists and has a true value, false otherwise - */ - bool ConfValueBool(ConfigDataHash &, const char *, const char *, int); + bool ConfValueInteger(ConfigDataHash &, const Anope::string &, const Anope::string &, const Anope::string &, int, int &); /** Returns true if the value exists and has a true value, false otherwise */ - bool ConfValueBool(ConfigDataHash &, const char *, const char *, const char *, int); + bool ConfValueBool(ConfigDataHash &, const Anope::string &, const Anope::string &, int); /** Returns true if the value exists and has a true value, false otherwise */ - bool ConfValueBool(ConfigDataHash &, const ci::string &, const ci::string &, int); - /** Returns true if the value exists and has a true value, false otherwise - */ - bool ConfValueBool(ConfigDataHash &, const ci::string &, const ci::string &, const ci::string &, int); - /** Returns the number of occurences of tag in the config file - */ - int ConfValueEnum(ConfigDataHash &, const char *); + bool ConfValueBool(ConfigDataHash &, const Anope::string &, const Anope::string &, const Anope::string &, int); /** Returns the number of occurences of tag in the config file */ - int ConfValueEnum(ConfigDataHash &, const std::string &); - /** Returns the number of occurences of tag in the config file - */ - int ConfValueEnum(ConfigDataHash &, const ci::string &); - /** Returns the numbers of vars inside the index'th 'tag in the config file - */ - int ConfVarEnum(ConfigDataHash &, const char *, int); + int ConfValueEnum(ConfigDataHash &, const Anope::string &); /** Returns the numbers of vars inside the index'th 'tag in the config file */ - int ConfVarEnum(ConfigDataHash &, const ci::string &, int); - void ValidateHostname(const char *, const ci::string &, const ci::string &); - void ValidateIP(const char *p, const ci::string &, const ci::string &, bool); - void ValidateNoSpaces(const char *, const ci::string &, const ci::string &); + int ConfVarEnum(ConfigDataHash &, const Anope::string &, int); + void ValidateHostname(const Anope::string &, const Anope::string &, const Anope::string &); + void ValidateIP(const Anope::string &p, const Anope::string &, const Anope::string &, bool); + void ValidateNoSpaces(const Anope::string &, const Anope::string &, const Anope::string &); /** Below here is a list of variables which contain the config files values */ /* IRCd module in use */ - char *IRCDModule; + Anope::string IRCDModule; /* Host to connect to **/ - char *LocalHost; + Anope::string LocalHost; /* List of uplink servers to try and connect to */ std::list<Uplink *> Uplinks; /* Our server name */ - char *ServerName; + Anope::string ServerName; /* Our servers description */ - char *ServerDesc; + Anope::string ServerDesc; /* The username/ident of services clients */ - char *ServiceUser; + Anope::string ServiceUser; /* The hostname if services clients */ - char *ServiceHost; + Anope::string ServiceHost; /* Log channel */ - char *LogChannel; + Anope::string LogChannel; /* Name of the network were on */ - char *NetworkName; + Anope::string NetworkName; /* The max legnth of nicks */ unsigned NickLen; /* Max length of idents */ @@ -476,39 +496,39 @@ class ServerConfig unsigned PassLen; /* NickServ Name */ - char *s_NickServ; + Anope::string s_NickServ; /* ChanServ Name */ - char *s_ChanServ; + Anope::string s_ChanServ; /* MemoServ Name */ - char *s_MemoServ; + Anope::string s_MemoServ; /* BotServ Name */ - char *s_BotServ; + Anope::string s_BotServ; /* OperServ name */ - char *s_OperServ; + Anope::string s_OperServ; /* Global name */ - char *s_GlobalNoticer; + Anope::string s_GlobalNoticer; /* NickServs realname */ - char *desc_NickServ; + Anope::string desc_NickServ; /* ChanServ realname */ - char *desc_ChanServ; - /* MemoServ relname */ - char *desc_MemoServ; + Anope::string desc_ChanServ; + /* MemoServ realname */ + Anope::string desc_MemoServ; /* BotServ realname */ - char *desc_BotServ; + Anope::string desc_BotServ; /* OperServ realname */ - char *desc_OperServ; + Anope::string desc_OperServ; /* Global realname */ - char *desc_GlobalNoticer; + Anope::string desc_GlobalNoticer; /* HostServ Name */ - char *s_HostServ; + Anope::string s_HostServ; /* HostServ realname */ - char *desc_HostServ; + Anope::string desc_HostServ; /* Filename for the PID file */ - char *PIDFilename; + Anope::string PIDFilename; /* MOTD filename */ - char *MOTDFilename; + Anope::string MOTDFilename; /* True if its ok to not be able to save backs */ bool NoBackupOkay; @@ -548,9 +568,9 @@ class ServerConfig /* Max number if news items allowed in the list */ unsigned NewsCount; /* Default mlock modes */ - ci::string MLock; + Anope::string MLock; /* Default botmodes on channels, defaults to ao */ - ci::string BotModes; + Anope::string BotModes; /* How many times to try and reconnect to the uplink before giving up */ unsigned MaxRetries; /* How long to wait between connection attempts */ @@ -561,9 +581,9 @@ class ServerConfig /* Services can use email */ bool UseMail; /* Path to the sendmail executable */ - char *SendMailPath; + Anope::string SendMailPath; /* Address to send from */ - char *SendFrom; + Anope::string SendFrom; /* Only opers can have services send mail */ bool RestrictMail; /* Delay between sending mail */ @@ -572,7 +592,7 @@ class ServerConfig bool DontQuoteAddresses; /* Prefix of guest nicks when a user gets forced off of a nick */ - char *NSGuestNickPrefix; + Anope::string NSGuestNickPrefix; /* Allow users to set kill immed on */ bool NSAllowKillImmed; /* Don't allow nicks to use /ns group to regroup nicks */ @@ -597,9 +617,9 @@ class ServerConfig /* Max number of allowed strings on the access list */ unsigned NSAccessMax; /* Enforcer client user name */ - char *NSEnforcerUser; + Anope::string NSEnforcerUser; /* Enforcer client hostname */ - char *NSEnforcerHost; + Anope::string NSEnforcerHost; /* How long before recovered nicks are released */ time_t NSReleaseTimeout; /* /nickserv list is oper only */ @@ -630,7 +650,7 @@ class ServerConfig /* Max number of entries allowed on autokick lists */ unsigned CSAutokickMax; /* Default autokick reason */ - char *CSAutokickReason; + Anope::string CSAutokickReason; /* Time ChanServ should stay in the channel to hold it to keep users from getting in */ time_t CSInhabit; /* ChanServ's LIST command is oper only */ @@ -664,7 +684,7 @@ class ServerConfig /* Case sensitive badwords matching */ bool BSCaseSensitive; /* Char to use for the fantasy char, eg ! */ - char *BSFantasyCharacter; + Anope::string BSFantasyCharacter; /* Only show /stats o to opers */ bool HideStatsO; @@ -675,9 +695,9 @@ class ServerConfig /* Dont allow users to register nicks with oper names in them */ bool RestrictOperNicks; /* Message to send when shutting down */ - char *GlobalOnCycleMessage; + Anope::string GlobalOnCycleMessage; /* Message to send when starting up */ - char *GlobalOnCycleUP; + Anope::string GlobalOnCycleUP; /* Super admin is allowed */ bool SuperAdmin; /* Log things said through ACT/SAY */ @@ -758,30 +778,30 @@ class ServerConfig /* How long session akills should last */ time_t SessionAutoKillExpiry; /* Reason to use for session kills */ - char *SessionLimitExceeded; + Anope::string SessionLimitExceeded; /* Optional second reason */ - char *SessionLimitDetailsLoc; + Anope::string SessionLimitDetailsLoc; /* OperServ requires you to be an operator */ bool OSOpersOnly; /* List of modules to autoload */ - std::list<ci::string> ModulesAutoLoad; + std::list<Anope::string> ModulesAutoLoad; /* Encryption modules */ - std::list<ci::string> EncModuleList; + std::list<Anope::string> EncModuleList; /* Database modules */ - std::list<ci::string> DBModuleList; + std::list<Anope::string> DBModuleList; /* HostServ Core Modules */ - std::list<ci::string> HostServCoreModules; + std::list<Anope::string> HostServCoreModules; /* MemoServ Core Modules */ - std::list<ci::string> MemoServCoreModules; + std::list<Anope::string> MemoServCoreModules; /* BotServ Core Modules */ - std::list<ci::string> BotServCoreModules; + std::list<Anope::string> BotServCoreModules; /* OperServ Core Modules */ - std::list<ci::string> OperServCoreModules; + std::list<Anope::string> OperServCoreModules; /* NickServ Core Modules */ - std::list<ci::string> NickServCoreModules; + std::list<Anope::string> NickServCoreModules; /* ChanServ Core Modules */ - std::list<ci::string> ChanServCoreModules; + std::list<Anope::string> ChanServCoreModules; /* Default defcon level */ int DefConLevel; @@ -792,37 +812,35 @@ class ServerConfig /* How long to add akills for defcon */ time_t DefConAKILL; /* Chan modes for defcon */ - char *DefConChanModes; + Anope::string DefConChanModes; /* Should we global on defcon */ bool GlobalOnDefcon; /* Should we send DefconMessage aswell? */ bool GlobalOnDefconMore; /* Message to send when defcon is off */ - char *DefConOffMessage; + Anope::string DefConOffMessage; /* Message to send when defcon is on*/ - char *DefconMessage; + Anope::string DefconMessage; /* Reason to akill clients for defcon */ - char *DefConAkillReason; + Anope::string DefConAkillReason; /* The socket engine in use */ - ci::string SocketEngine; + Anope::string SocketEngine; /* User keys to use for generating random hashes for pass codes etc */ - long unsigned int UserKey1; - long unsigned int UserKey2; - long unsigned int UserKey3; + unsigned long UserKey1; + unsigned long UserKey2; + unsigned long UserKey3; /* Numeric */ - char *Numeric; + Anope::string Numeric; /* Array of ulined servers */ - char **Ulines; - /* Number of ulines */ - int NumUlines; + std::list<Anope::string> Ulines; /* List of available opertypes */ std::list<OperType *> MyOperTypes; /* List of pairs of opers and their opertype from the config */ - std::list<std::pair<ci::string, ci::string> > Opers; + std::list<std::pair<Anope::string, Anope::string> > Opers; }; /** This class can be used on its own to represent an exception, or derived to represent a module-specific exception. @@ -836,12 +854,10 @@ class ConfigException : public CoreException public: /** Default constructor, just uses the error mesage 'Config threw an exception'. */ - ConfigException() : CoreException("Config threw an exception", "Config Parser") {} + ConfigException() : CoreException("Config threw an exception", "Config Parser") { } /** This constructor can be used to specify an error message before throwing. */ - ConfigException(const char *message) : CoreException(message, "Config Parser") {} - ConfigException(const std::string &message) : CoreException(message, "Config Parser") {} - ConfigException(const ci::string &message) : CoreException(message, "Config Parser") {} + ConfigException(const Anope::string &message) : CoreException(message, "Config Parser") { } /** This destructor solves world hunger, cancels the world debt, and causes the world to end. * Actually no, it does nothing. Never mind. * @throws Nothing! @@ -890,7 +906,7 @@ class CoreExport ConfigReader /** Overloaded constructor. * This constructor initialises the ConfigReader class to read a user-specified config file */ - ConfigReader(const std::string &); + ConfigReader(const Anope::string &); /** Default destructor. * This method destroys the ConfigReader class. */ @@ -899,26 +915,26 @@ class CoreExport ConfigReader * This method retrieves a value from the config file. Where multiple copies of the tag * exist in the config file, index indicates which of the values to retrieve. */ - std::string ReadValue(const std::string &, const std::string &, int, bool = false); + Anope::string ReadValue(const Anope::string &, const Anope::string &, int, bool = false); /** Retrieves a value from the config file. * This method retrieves a value from the config file. Where multiple copies of the tag * exist in the config file, index indicates which of the values to retrieve. If the * tag is not found the default value is returned instead. */ - std::string ReadValue(const std::string &, const std::string &, const std::string &, int, bool = false); + Anope::string ReadValue(const Anope::string &, const Anope::string &, const Anope::string &, int, bool = false); /** Retrieves a boolean value from the config file. * This method retrieves a boolean value from the config file. Where multiple copies of the tag * exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" * and "true" in the config file count as true to ReadFlag, and any other value counts as false. */ - bool ReadFlag(const std::string &, const std::string &, int); + bool ReadFlag(const Anope::string &, const Anope::string &, int); /** Retrieves a boolean value from the config file. * This method retrieves a boolean value from the config file. Where multiple copies of the tag * exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" * and "true" in the config file count as true to ReadFlag, and any other value counts as false. * If the tag is not found, the default value is used instead. */ - bool ReadFlag(const std::string &, const std::string &, const std::string &, int); + bool ReadFlag(const Anope::string &, const Anope::string &, const Anope::string &, int); /** Retrieves an integer value from the config file. * This method retrieves an integer value from the config file. Where multiple copies of the tag * exist in the config file, index indicates which of the values to retrieve. Any invalid integer @@ -928,7 +944,7 @@ class CoreExport ConfigReader * will return CONF_INT_NEGATIVE. Note that need_positive is not suitable to get an unsigned int - you * should cast the result to achieve that effect. */ - int ReadInteger(const std::string &, const std::string &, int, bool); + int ReadInteger(const Anope::string &, const Anope::string &, int, bool); /** Retrieves an integer value from the config file. * This method retrieves an integer value from the config file. Where multiple copies of the tag * exist in the config file, index indicates which of the values to retrieve. Any invalid integer @@ -937,7 +953,7 @@ class CoreExport ConfigReader * If a signed number is placed into a tag which is specified unsigned, 0 will be returned and GetError() * will return CONF_NOT_UNSIGNED. If the tag is not found, the default value is used instead. */ - int ReadInteger(const std::string &, const std::string &, const std::string &, int, bool); + int ReadInteger(const Anope::string &, const Anope::string &, const Anope::string &, int, bool); /** Returns the last error to occur. * Valid errors can be found by looking in modules.h. Any nonzero value indicates an error condition. * A call to GetError() resets the error flag back to 0. @@ -949,7 +965,7 @@ class CoreExport ConfigReader * used with the index value of ConfigReader::ReadValue to loop through all copies of a * multiple instance tag. */ - int Enumerate(const std::string &); + int Enumerate(const Anope::string &); /** Returns true if a config file is valid. * This method is partially implemented and will only return false if the config * file does not exist or could not be opened. @@ -967,7 +983,7 @@ class CoreExport ConfigReader * function would return 2. Spaces and newlines both qualify as valid seperators * between values. */ - int EnumerateValues(const std::string &, int); + int EnumerateValues(const Anope::string &, int); }; #endif // CONFIG_H diff --git a/include/extensible.h b/include/extensible.h index d835dd865..523a25b6d 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -7,6 +7,8 @@ #ifndef EXTENSIBLE_H #define EXTENSIBLE_H +#include "hashcomp.h" + /** Dummy base class we use to cast everything to/from */ class ExtensibleItemBase @@ -58,7 +60,8 @@ template<typename T> class ExtensibleItemPointerArray : public ExtensibleItemBas class CoreExport Extensible { private: - std::map<std::string, ExtensibleItemBase *> Extension_Items; + typedef std::map<Anope::string, ExtensibleItemBase *, hash_compare_std_string> extensible_map; + extensible_map Extension_Items; public: /** Default constructor, does nothing @@ -70,7 +73,7 @@ class CoreExport Extensible */ virtual ~Extensible() { - for (std::map<std::string, ExtensibleItemBase *>::iterator it = Extension_Items.begin(), it_end = Extension_Items.end(); it != it_end; ++it) + for (extensible_map::iterator it = Extension_Items.begin(), it_end = Extension_Items.end(); it != it_end; ++it) delete it->second; Extension_Items.clear(); } @@ -86,7 +89,7 @@ class CoreExport Extensible * * @return Returns true on success, false if otherwise */ - bool Extend(const std::string &key, ExtensibleItemBase *p) + bool Extend(const Anope::string &key, ExtensibleItemBase *p) { bool Ret = this->Extension_Items.insert(std::make_pair(key, p)).second; if (!Ret) @@ -105,7 +108,7 @@ class CoreExport Extensible * * @return Returns true on success, false if otherwise */ - bool Extend(const std::string &key) + bool Extend(const Anope::string &key) { /* This will only add an item if it doesnt already exist, * the return value is a std::pair of an iterator to the @@ -122,9 +125,9 @@ class CoreExport Extensible * you provide a nonexistent key (case is important) then the function will return false. * @return Returns true on success. */ - bool Shrink(const std::string &key) + bool Shrink(const Anope::string &key) { - std::map<std::string, ExtensibleItemBase *>::iterator it = this->Extension_Items.find(key); + extensible_map::iterator it = this->Extension_Items.find(key); if (it != this->Extension_Items.end()) { delete it->second; @@ -144,9 +147,9 @@ class CoreExport Extensible * @param p If you provide a non-existent key, this value will be 0. Otherwise a copy to the item you requested will be placed in this templated parameter. * @return Returns true if the item was found and false if it was nor, regardless of wether 'p' is NULL. This allows you to store NULL values in Extensible. */ - template<typename T> bool GetExtRegular(const std::string &key, T &p) + template<typename T> bool GetExtRegular(const Anope::string &key, T &p) { - std::map<std::string, ExtensibleItemBase *>::iterator it = this->Extension_Items.find(key); + extensible_map::iterator it = this->Extension_Items.find(key); if (it != this->Extension_Items.end()) { @@ -163,9 +166,9 @@ class CoreExport Extensible * * @param p If you provide a non-existent key, this value will be NULL. Otherwise a pointer to the item you requested will be placed in this templated parameter. * @return Returns true if the item was found and false if it was nor, regardless of wether 'p' is NULL. This allows you to store NULL values in Extensible. */ - template<typename T> bool GetExtPointer(const std::string &key, T *&p) + template<typename T> bool GetExtPointer(const Anope::string &key, T *&p) { - std::map<std::string, ExtensibleItemBase *>::iterator it = this->Extension_Items.find(key); + extensible_map::iterator it = this->Extension_Items.find(key); if (it != this->Extension_Items.end()) { @@ -183,9 +186,9 @@ class CoreExport Extensible * @param p If you provide a non-existent key, this value will be NULL. Otherwise a pointer to the item you requested will be placed in this templated parameter. * @return Returns true if the item was found and false if it was nor, regardless of wether 'p' is NULL. This allows you to store NULL values in Extensible. */ - template<typename T> bool GetExtArray(const std::string &key, T *&p) + template<typename T> bool GetExtArray(const Anope::string &key, T *&p) { - std::map<std::string, ExtensibleItemBase *>::iterator it = this->Extension_Items.find(key); + extensible_map::iterator it = this->Extension_Items.find(key); if (it != this->Extension_Items.end()) { @@ -206,7 +209,7 @@ class CoreExport Extensible * the 'data' field and is probably only useful in conjunction with the single-parameter * version of Extend(). */ - bool GetExt(const std::string &key) + bool GetExt(const Anope::string &key) { return this->Extension_Items.find(key) != this->Extension_Items.end(); } @@ -216,9 +219,9 @@ class CoreExport Extensible * @return This function writes a list of all extension items stored * in this object by name into the given deque and returns void. */ - void GetExtList(std::deque<std::string> &list) + void GetExtList(std::deque<Anope::string> &list) { - for (std::map<std::string, ExtensibleItemBase *>::iterator it = Extension_Items.begin(), it_end = Extension_Items.end(); it != it_end; ++it) + for (extensible_map::iterator it = Extension_Items.begin(), it_end = Extension_Items.end(); it != it_end; ++it) list.push_back(it->first); } }; diff --git a/include/extern.h b/include/extern.h index a59ebc2b4..e323102a2 100644 --- a/include/extern.h +++ b/include/extern.h @@ -27,9 +27,9 @@ E IRCDProto *ircdproto; /**** actions.c ****/ -E void kill_user(const std::string &source, const std::string &user, const std::string &reason); +E void kill_user(const Anope::string &source, const Anope::string &user, const Anope::string &reason); E bool bad_password(User *u); -E void common_unban(ChannelInfo *ci, const std::string &nick); +E void common_unban(ChannelInfo *ci, const Anope::string &nick); E BotInfo *BotServ; E BotInfo *ChanServ; @@ -43,60 +43,56 @@ E BotInfo *OperServ; E void get_botserv_stats(long *nrec, long *memuse); E void bs_init(); -E void botserv(User *u, BotInfo *bi, const std::string &buf); -E void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf); -E BotInfo *findbot(const char *nick); -E BotInfo *findbot(const std::string &nick); -E BotInfo *findbot(const ci::string &nick); +E void botserv(User *u, BotInfo *bi, const Anope::string &buf); +E void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf); +E BotInfo *findbot(const Anope::string &nick); /** Finds a pseudoclient, given a UID. Useful for TS6 protocol modules. * @param uid The UID to search for * @return The pseudoclient structure, or NULL if one could not be found */ -E char *normalizeBuffer(const char *); +E Anope::string normalizeBuffer(const Anope::string &); -E void bot_raw_ban(User * requester, ChannelInfo *ci, char *nick, const char *reason); -E void bot_raw_kick(User * requester, ChannelInfo *ci, char *nick, const char *reason); -E void bot_raw_mode(User * requester, ChannelInfo *ci, const char *mode, char *nick); +E void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason); +E void bot_raw_kick(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason); +E void bot_raw_mode(User *requester, ChannelInfo *ci, const Anope::string &mode, const Anope::string &nick); /**** channels.c ****/ E void get_channel_stats(long *nrec, long *memuse); -E Channel *findchan(const char *chan); -E Channel *findchan(const std::string &chan); -E Channel *findchan(const ci::string &chan); +E Channel *findchan(const Anope::string &chan); E void ChanSetInternalModes(Channel *c, int ac, const char **av); -E User *nc_on_chan(Channel *c, NickCore *nc); +E User *nc_on_chan(Channel *c, const NickCore *nc); -E char *chan_get_modes(Channel *chan, int complete, int plus); +E Anope::string chan_get_modes(Channel *chan, int complete, int plus); E int get_access_level(ChannelInfo *ci, NickAlias *na); E int get_access_level(ChannelInfo *ci, NickCore *nc); -E const char *get_xop_level(int level); +E Anope::string get_xop_level(int level); -E void do_cmode(const char *source, int ac, const char **av); -E void do_join(const char *source, int ac, const char **av); -E void do_kick(const std::string &source, int ac, const char **av); -E void do_part(const char *source, int ac, const char **av); -E void do_topic(const char *source, int ac, const char **av); -E void MassChannelModes(BotInfo *bi, const std::string &modes); +E void do_cmode(const Anope::string &source, int ac, const char **av); +E void do_join(const Anope::string &source, int ac, const char **av); +E void do_kick(const Anope::string &source, int ac, const char **av); +E void do_part(const Anope::string &source, int ac, const char **av); +E void do_topic(const Anope::string &source, int ac, const char **av); +E void MassChannelModes(BotInfo *bi, const Anope::string &modes); E void chan_set_correct_modes(User *user, Channel *c, int give_modes); E void restore_unsynced_topics(); -E Entry *entry_create(char *mask); -E Entry *entry_add(EList *list, const char *mask); +E Entry *entry_create(const Anope::string &mask); +E Entry *entry_add(EList *list, const Anope::string &mask); E void entry_delete(EList *list, Entry *e); E EList *list_create(); -E int entry_match(Entry *e, const ci::string &nick, const ci::string &user, const ci::string &host, uint32 ip); -E int entry_match_mask(Entry *e, const char *mask, uint32 ip); -E Entry *elist_match(EList *list, const char *nick, const char *user, const char *host, uint32 ip); -E Entry *elist_match_mask(EList *list, const char *mask, uint32 ip); +E int entry_match(Entry *e, const Anope::string &nick, const Anope::string &user, const Anope::string &host, uint32 ip); +E int entry_match_mask(Entry *e, const Anope::string &mask, uint32 ip); +E Entry *elist_match(EList *list, const Anope::string &nick, const Anope::string &user, const Anope::string &host, uint32 ip); +E Entry *elist_match_mask(EList *list, const Anope::string &mask, uint32 ip); E Entry *elist_match_user(EList *list, User *u); -E Entry *elist_find_mask(EList *list, const char *mask); +E Entry *elist_find_mask(EList *list, const Anope::string &mask); E long get_memuse(EList *list); #define whosends(ci) (!(ci) || !((ci)->botflags.HasFlag(BS_SYMBIOSIS)) || !(ci)->bi || !(ci)->c || (ci)->c->FindUser((ci)->bi) ? findbot(Config.s_ChanServ) : (ci)->bi) @@ -109,57 +105,45 @@ E void get_chanserv_stats(long *nrec, long *memuse); E void reset_levels(ChannelInfo *ci); E void cs_init(); -E void chanserv(User *u, const std::string &buf); +E void chanserv(User *u, const Anope::string &buf); E void expire_chans(); E void cs_remove_nick(const NickCore *nc); E void check_modes(Channel *c); E int check_valid_admin(User *user, Channel *chan, int servermode); E int check_valid_op(User *user, Channel *chan, int servermode); -E void record_topic(const char *chan); -E void restore_topic(const char *chan); +E void record_topic(const Anope::string &chan); +E void restore_topic(const Anope::string &chan); E int check_topiclock(Channel *c, time_t topic_time); -E ChannelInfo *cs_findchan(const char *chan); -E ChannelInfo *cs_findchan(const std::string &chan); -E ChannelInfo *cs_findchan(const ci::string &chan); +E ChannelInfo *cs_findchan(const Anope::string &chan); E int check_access(User *user, ChannelInfo *ci, int what); E bool IsFounder(User *user, ChannelInfo *ci); E int get_access(User *user, ChannelInfo *ci); E void update_cs_lastseen(User *user, ChannelInfo *ci); -E int get_idealban(ChannelInfo *ci, User *u, char *ret, int retlen); -E AutoKick *is_stuck(ChannelInfo *ci, const char *mask); +E int get_idealban(ChannelInfo *ci, User *u, Anope::string &ret); +E AutoKick *is_stuck(ChannelInfo *ci, const Anope::string &mask); E void stick_mask(ChannelInfo *ci, AutoKick *akick); E void stick_all(ChannelInfo *ci); E int levelinfo_maxwidth; -E char *get_mlock_modes(ChannelInfo *ci, int complete); - -/**** compat.c ****/ - -#if !HAVE_STRICMP && !HAVE_STRCASECMP -E int stricmp(const char *s1, const char *s2); -E int strnicmp(const char *s1, const char *s2, size_t len); -#endif -#ifdef _WIN32 -char *sockstrerror(int error); -#endif +E Anope::string get_mlock_modes(ChannelInfo *ci, int complete); /**** config.c ****/ -E ci::string services_conf; +E Anope::string services_conf; E ServerConfig Config; E int read_config(int reload); /* hostserv.c */ E void do_on_id(User *u); -E void hostserv(User *u, const std::string &buf); +E void hostserv(User *u, const Anope::string &buf); E void HostServSyncVhosts(NickAlias *na); /**** encrypt.c ****/ -E int enc_encrypt(const std::string &src, std::string &dest); -E int enc_decrypt(const std::string &src, std::string &dest); -E int enc_check_password(std::string &plaintext, std::string &password); +E int enc_encrypt(const Anope::string &src, Anope::string &dest); +E int enc_decrypt(const Anope::string &src, Anope::string &dest); +E int enc_check_password(Anope::string &plaintext, Anope::string &password); /**** hostserv.c ****/ E void get_hostserv_stats(long *nrec, long *memuse); @@ -167,9 +151,9 @@ E void hostserv_init(); /**** init.c ****/ -E void introduce_user(const std::string &user); -E bool GetCommandLineArgument(const std::string &name, char shortname = 0); -E bool GetCommandLineArgument(const std::string &name, char shortname, std::string ¶m); +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 int init_primary(int ac, char **av); E int init_secondary(int ac, char **av); E Uplink *uplink_server; @@ -177,7 +161,7 @@ E Uplink *uplink_server; /**** ircd.c ****/ E void pmodule_ircd_proto(IRCDProto *); E void pmodule_ircd_var(IRCDVar *ircdvar); -E void pmodule_ircd_version(const char *version); +E void pmodule_ircd_version(const Anope::string &version); E void pmodule_ircd_useTSMode(int use); /**** language.c ****/ @@ -188,9 +172,9 @@ E int langlist[NUM_LANGS]; E void lang_init(); E int strftime_lang(char *buf, int size, User *u, int format, struct tm *tm); -E void syntax_error(char *service, User *u, const char *command, int msgnum); +E void syntax_error(const Anope::string &service, User *u, const Anope::string &command, int msgnum); E const char *getstring(NickAlias *na, int index); -E const char *getstring(NickCore *nc, int index); +E const char *getstring(const NickCore *nc, int index); E const char *getstring(User *nc, int index); E const char *getstring(int index); @@ -198,16 +182,16 @@ E const char *getstring(int index); E int open_log(); E void close_log(); -E void log_perror(const char *fmt, ...) FORMAT(printf,1,2); -E void fatal(const char *fmt, ...) FORMAT(printf,1,2); -E void fatal_perror(const char *fmt, ...) FORMAT(printf,1,2); +E void log_perror(const char *fmt, ...) FORMAT(printf, 1, 2); +E void fatal(const char *fmt, ...) FORMAT(printf, 1, 2); +E void fatal_perror(const char *fmt, ...) FORMAT(printf, 1, 2); /**** main.c ****/ -E char *version_protocol; +E Anope::string version_protocol; -E std::string services_dir; -E std::string log_filename; +E Anope::string services_dir; +E Anope::string log_filename; E int debug; E int readonly; E bool LogChan; @@ -220,7 +204,7 @@ E int protocoldebug; E int is44; E int quitting; E int shutting_down; -E const char *quitmsg; +E Anope::string quitmsg; E int save_data; E int got_alarm; E time_t start_time; @@ -234,36 +218,34 @@ E void do_restart_services(); /**** memory.c ****/ -E void *smalloc(long size); E void *scalloc(long elsize, long els); E void *srealloc(void *oldptr, long newsize); -E char *sstrdup(const char *s); /**** memoserv.c ****/ E void ms_init(); -E void memoserv(User *u, const std::string &buf); -E void rsend_notify(User *u, Memo *m, const char *chan); +E void memoserv(User *u, const Anope::string &buf); +E void rsend_notify(User *u, Memo *m, const Anope::string &chan); E void check_memos(User *u); -E MemoInfo *getmemoinfo(const char *name, int *ischan, int *isforbid); -E void memo_send(User *u, const char *name, const char *text, int z); +E MemoInfo *getmemoinfo(const Anope::string &name, int *ischan, int *isforbid); +E void memo_send(User *u, const Anope::string &name, const Anope::string &text, int z); E int delmemo(MemoInfo *mi, int num); /**** messages.c ****/ -E int m_nickcoll(const char *user); -E int m_away(const char *source, const char *msg); -E int m_kill(const std::string &nick, const char *msg); -E int m_motd(const char *source); -E int m_privmsg(const std::string &source, const std::string &receiver, const std::string &message); -E int m_stats(const char *source, int ac, const char **av); -E int m_whois(const char *source, const char *who); -E int m_time(const char *source, int ac, const char **av); -E int m_version(const char *source, int ac, const char **av); +E int m_nickcoll(const Anope::string &user); +E int m_away(const Anope::string &source, const Anope::string &msg); +E int m_kill(const Anope::string &nick, const Anope::string &msg); +E int m_motd(const Anope::string &source); +E int m_privmsg(const Anope::string &source, const Anope::string &receiver, const Anope::string &message); +E int m_stats(const Anope::string &source, int ac, const char **av); +E int m_whois(const Anope::string &source, const Anope::string &who); +E int m_time(const Anope::string &source, int ac, const char **av); +E int m_version(const Anope::string &source, int ac, const char **av); /**** misc.c ****/ -E bool IsFile(const std::string &filename); +E bool IsFile(const Anope::string &filename); E int toupper(char); E int tolower(char); E char *strscpy(char *d, const char *s, size_t len); @@ -273,28 +255,24 @@ E size_t strlcpy(char *, const char *, size_t); #ifndef HAVE_STRLCAT E size_t strlcat(char *, const char *, size_t); #endif -E const char *stristr(const char *s1, const char *s2); E char *strnrepl(char *s, int32 size, const char *old, const char *nstr); E const char *merge_args(int argc, char **argv); E const char *merge_args(int argc, const char **argv); -E time_t dotime(const char *s); -E const char *duration(NickCore *nc, char *buf, int bufsize, time_t seconds); -E const char *expire_left(NickCore *nc, char *buf, int len, time_t expires); -E int doValidHost(const char *host, int type); +E time_t dotime(const Anope::string &s); +E Anope::string duration(const NickCore *nc, time_t seconds); +E Anope::string expire_left(const NickCore *nc, time_t expires); +E int doValidHost(const Anope::string &host, int type); -E int isValidHost(const char *host, int type); +E int isValidHost(const Anope::string &host, int type); E int isvalidchar(const char c); -E char *myStrGetToken(const char *str, const char dilim, int token_number); -E char *myStrGetOnlyToken(const char *str, const char dilim, int token_number); -E char *myStrSubString(const char *src, int start, int end); -E char *myStrGetTokenRemainder(const char *str, const char dilim, int token_number); -E char *stripModePrefix(const char *str); -E int myNumToken(const char *str, const char dilim); +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 void doCleanBuffer(char *str); -E void EnforceQlinedNick(const std::string &nick, const char *killer); -E int nickIsServices(const char *nick, int bot); +E void EnforceQlinedNick(const Anope::string &nick, const Anope::string &killer); +E int nickIsServices(const Anope::string &nick, int bot); E void add_entropy_userkeys(); E void rand_init(); @@ -306,53 +284,44 @@ E char *str_signed(unsigned char *str); E void ntoa(struct in_addr addr, char *ipaddr, int len); -E std::list<std::string> BuildStringList(const std::string &); -E std::list<ci::string> BuildStringList(const ci::string &); -E std::vector<std::string> BuildStringVector(const std::string &); - -E void binary_to_hex(unsigned char *bin, char *hex, int length); +E std::list<Anope::string> BuildStringList(const Anope::string &); +E std::vector<Anope::string> BuildStringVector(const Anope::string &); E uint32 cidr_to_netmask(uint16 cidr); E uint16 netmask_to_cidr(uint32 mask); -E int str_is_wildcard(const char *str); -E int str_is_pure_wildcard(const char *str); +E int str_is_wildcard(const Anope::string &str); +E int str_is_pure_wildcard(const Anope::string &str); -E uint32 str_is_ip(char *str); -E int str_is_cidr(char *str, uint32 * ip, uint32 * mask, char **host); +E uint32 str_is_ip(const Anope::string &str); +E int str_is_cidr(const Anope::string &str, uint32 *ip, uint32 *mask, Anope::string &host); /**** modes.cpp ****/ /* Number of generic modes we support */ E unsigned GenericChannelModes, GenericUserModes; E Flags<ChannelModeName, CMODE_END> DefMLockOn; E Flags<ChannelModeName, CMODE_END> DefMLockOff; -E std::map<ChannelModeName, std::string> DefMLockParams; +E std::map<ChannelModeName, Anope::string> DefMLockParams; /* Modes to set on bots when they join the channel */ E std::list<ChannelModeStatus *> BotModes; E void SetDefaultMLock(); /**** nickserv.c ****/ -E NickRequest *findrequestnick(const char *nick); -E NickRequest *findrequestnick(const std::string &nick); -E NickRequest *findrequestnick(const ci::string &nick); +E NickRequest *findrequestnick(const Anope::string &nick); E void get_aliases_stats(long *nrec, long *memuse); E void get_core_stats(long *nrec, long *memuse); E void change_core_display(NickCore *nc); -E void change_core_display(NickCore *nc, const char *newdisplay); +E void change_core_display(NickCore *nc, const Anope::string &newdisplay); E int do_setmodes(User *u); E void ns_init(); -E void nickserv(User *u, const std::string &buf); +E void nickserv(User *u, const Anope::string &buf); E int validate_user(User *u); E void expire_nicks(); E void expire_requests(); -E NickAlias *findnick(const char *nick); -E NickAlias *findnick(const std::string &nick); -E NickAlias *findnick(const ci::string &nick); -E NickCore *findcore(const char *nick); -E NickCore *findcore(const std::string &nick); -E NickCore *findcore(const ci::string &nick); +E NickAlias *findnick(const Anope::string &nick); +E NickCore *findcore(const Anope::string &nick); E bool is_on_access(User *u, NickCore *nc); /**** process.c ****/ @@ -360,43 +329,40 @@ E bool is_on_access(User *u, NickCore *nc); E int allow_ignore; E IgnoreData *ignore; -E void add_ignore(const char *nick, time_t delta); -E IgnoreData *get_ignore(const char *nick); -E int delete_ignore(const char *nick); +E void add_ignore(const Anope::string &nick, time_t delta); +E IgnoreData *get_ignore(const Anope::string &nick); +E int delete_ignore(const Anope::string &nick); E int clear_ignores(); E int split_buf(char *buf, const char ***argv, int colon_special); -E void process(const std::string &buf); +E void process(const Anope::string &buf); /**** send.c ****/ -E void send_cmd(const char *source, const char *fmt, ...) FORMAT(printf,2,3); -E void send_cmd(const std::string &source, const char *fmt, ...) FORMAT(printf,2,3); +E void send_cmd(const Anope::string &source, const char *fmt, ...) FORMAT(printf, 2, 3); -E void notice_server(char *source, Server * s, const char *fmt, ...) FORMAT(printf,3,4); +E void notice_server(const Anope::string &source, Server * s, const char *fmt, ...) FORMAT(printf, 3, 4); -E void notice_list(const char *source, const char *dest, char **text); // MARK_DEPRECATED; -E void notice_lang(const std::string &source, User *dest, int message, ...); // MARK_DEPRECATED; -E void notice_help(const char *source, User *dest, int message, ...); // MARK_DEPRECATED; +E void notice_lang(const Anope::string &source, User *dest, int message, ...); // MARK_DEPRECATED; +E void notice_help(const Anope::string &source, User *dest, int message, ...); // MARK_DEPRECATED; /**** sessions.c ****/ -E Exception *exceptions; -E int16 nexceptions; +E std::vector<Exception *> exceptions; E void get_session_stats(long *nrec, long *memuse); E void get_exception_stats(long *nrec, long *memuse); -E int add_session(const char *nick, const char *host, char *hostip); -E void del_session(const char *host); +E int add_session(const Anope::string &nick, const Anope::string &host, const Anope::string &hostip); +E void del_session(const Anope::string &host); E void expire_exceptions(); -E Session *findsession(const std::string &host); +E Session *findsession(const Anope::string &host); -E Exception *find_host_exception(const char *host); -E Exception *find_hostip_exception(const char *host, const char *hostip); -E int exception_add(User *u, const char *mask, const int limit, const char *reason, const char *who, const time_t expires); +E Exception *find_host_exception(const Anope::string &host); +E Exception *find_hostip_exception(const Anope::string &host, const Anope::string &hostip); +E int exception_add(User *u, const Anope::string &mask, int limit, const Anope::string &reason, const Anope::string &who, time_t expires); /**** sockets.cpp ****/ @@ -412,43 +378,36 @@ E time_t maxusertime; E void get_user_stats(long *nusers, long *memuse); -E User *finduser(const char *nick); -E User *finduser(const std::string &nick); -E User *finduser(const ci::string &nick); +E User *finduser(const Anope::string &nick); -E Server *findserver_uid(Server *s, const char *name); -E char *TS6SID; +E Anope::string TS6SID; -E User *do_nick(const char *source, const char *nick, const char *username, const char *host, const char *server, const char *realname, time_t ts, uint32 ip, const char *vhost, const char *uid); +E User *do_nick(const Anope::string &source, const Anope::string &nick, const Anope::string &username, const Anope::string &host, const Anope::string &server, const Anope::string &realname, time_t ts, uint32 ip, const Anope::string &vhost, const Anope::string &uid); -E void do_umode(const char *source, int ac, const char **av); -E void do_quit(const char *source, int ac, const char **av); -E void do_kill(const std::string &source, const std::string &reason); +E void do_umode(const Anope::string &source, int ac, const char **av); +E void do_quit(const Anope::string &source, int ac, const char **av); +E void do_kill(const Anope::string &source, const Anope::string &reason); E int is_oper(User *user); E int is_excepted(ChannelInfo *ci, User * user); -E int is_excepted_mask(ChannelInfo *ci, const char *mask); +E int is_excepted_mask(ChannelInfo *ci, const Anope::string &mask); -E int match_usermask(const char *mask, User *user); -E char *create_mask(User *u); +E int match_usermask(const Anope::string &mask, User *user); +E Anope::string create_mask(User *u); E void UserSetInternalModes(User *user, int ac, const char **av); /******************************************************************************/ -E const char *base64enc(long i); -E long base64dec(const char *b64); -E long base64dects(const char *ts); -E int b64_encode(const char *src, size_t srclength, char *target, size_t targsize); -E int b64_decode(const char *src, char *target, size_t targsize); -E const char *encode_ip(unsigned char *ip); -E int decode_ip(const char *buf); +E void b64_encode(const Anope::string &src, Anope::string &target); +E void b64_decode(const Anope::string &src, Anope::string &target); +E int decode_ip(const Anope::string &buf); -E char *host_resolve(char *host); +E Anope::string host_resolve(const Anope::string &host); #ifdef _WIN32 -E char *GetWindowsVersion() ; +E Anope::string GetWindowsVersion(); E int SupportedWindowsVersion(); #endif diff --git a/include/hashcomp.h b/include/hashcomp.h index 8c503b0a2..3a7dae276 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -28,6 +28,11 @@ #include <string> +namespace Anope +{ + class string; +} + #ifndef _WIN32 //# ifdef HASHMAP_DEPRECATED /* If gcc ver > 4.3 */ # if 1 @@ -218,10 +223,6 @@ namespace ci /* This was endless fun. No. Really. */ /* It was also the first core change Ommeh made, if anyone cares */ -/** Operator << for irc::string - */ -inline std::ostream &operator<<(std::ostream &os, const irc::string &str) { return os << std::string(str.c_str()); } - /** Operator >> for irc::string */ inline std::istream &operator>>(std::istream &is, irc::string &str) @@ -232,10 +233,6 @@ inline std::istream &operator>>(std::istream &is, irc::string &str) return is; } -/** Operator << for ci::string - */ -inline std::ostream &operator<<(std::ostream &os, const ci::string &str) { return os << std::string(str.c_str()); } - /** Operator >> for ci::string */ inline std::istream &operator>>(std::istream &is, ci::string &str) @@ -408,106 +405,11 @@ inline bool operator!=(const ci::string &leftval, const irc::string &rightval) return !(leftval.c_str() == rightval); } -/** Assign an irc::string to a std::string. - */ -//inline std::string assign(const irc::string &other) { return other.c_str(); } - -/** Assign a std::string to an irc::string. - */ -//inline irc::string assign(const std::string &other) { return other.c_str(); } - -/** Assign an ci::string to a std::string. - */ -//inline std::string assign(const ci::string &other) { return other.c_str(); } - -/** Assign a std::string to an ci::string. - */ -//inline ci::string assign(const std::string &other) { return other.c_str(); } - -/** Assign an irc::string to a ci::string. - */ -//inline ci::string assign(const irc::string &other) { return other.c_str(); } - -/** Assign a ci::string to an irc::string. - */ -//inline irc::string assign(const ci::string &other) { return other.c_str(); } - -/** sepstream allows for splitting token seperated lists. - * Each successive call to sepstream::GetToken() returns - * the next token, until none remain, at which point the method returns - * an empty string. - */ -class CoreExport sepstream -{ - private: - /** Original string. - */ - std::string tokens; - /** Last position of a seperator token - */ - std::string::iterator last_starting_position; - /** Current string position - */ - std::string::iterator n; - /** Seperator value - */ - char sep; - public: - /** Create a sepstream and fill it with the provided data - */ - sepstream(const std::string &source, char seperator); - sepstream(const ci::string &source, char seperator); - sepstream(const char *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(std::string &token); - virtual bool GetToken(ci::string &token); - - /** Fetch the entire remaining stream, without tokenizing - * @return The remaining part of the stream - */ - virtual const std::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(); -}; - -/** A derived form of sepstream, which seperates on commas - */ -class commasepstream : public sepstream -{ - public: - /** Initialize with comma seperator - */ - commasepstream(const std::string &source) : sepstream(source, ',') { } - commasepstream(const ci::string &source) : sepstream(source, ',') { } - commasepstream(const char *source) : sepstream(source, ',') { } -}; - -/** A derived form of sepstream, which seperates on spaces - */ -class spacesepstream : public sepstream -{ - public: - /** Initialize with space seperator - */ - spacesepstream(const std::string &source) : sepstream(source, ' ') { } - spacesepstream(const ci::string &source) : sepstream(source, ' ') { } - spacesepstream(const char *source) : sepstream(source, ' ') { } -}; - /** Class used to hash a std::string, given as the third argument to the unordered_map template */ class CoreExport hash_compare_std_string { public: -#if defined(_WIN32) && _MSV_VER < 1600 enum { bucket_size = 4, min_buckets = 8 }; /** Compare two std::string's values for hashing in hash_map @@ -517,13 +419,14 @@ class CoreExport hash_compare_std_string * being less and greater than zero for str1 being greater than str2. */ bool operator()(const std::string &s1, const std::string &s2) const; -#endif + bool operator()(const Anope::string &s1, const Anope::string &s2) const; /** Return a hash value for a string * @param s The string * @return The hash value */ size_t operator()(const std::string &s) const; + size_t operator()(const Anope::string &s) const; }; /** Class used to hash a ci::string, given as the third argument to the unordered_map template @@ -531,7 +434,6 @@ class CoreExport hash_compare_std_string class CoreExport hash_compare_ci_string { public: -#if defined(_WIN32) && _MSV_VER < 1600 enum { bucket_size = 4, min_buckets = 8 }; /** Compare two ci::string's values for hashing in hash_map @@ -541,12 +443,14 @@ class CoreExport hash_compare_ci_string * being less and greater than zero for str1 being greater than str2. */ bool operator()(const ci::string &s1, const ci::string &s2) const; -#endif + bool operator()(const Anope::string &s1, const Anope::string &s2) const; + /** Return a hash value for a string using case insensitivity * @param s The string * @return The hash value */ size_t operator()(const ci::string &s) const; + size_t operator()(const Anope::string &s) const; }; /** Class used to hash a irc::string, given as the third argument to the unordered_map template @@ -554,7 +458,6 @@ class CoreExport hash_compare_ci_string class CoreExport hash_compare_irc_string { public: -#if defined(_WIN32) && _MSV_VER < 1600 enum { bucket_size = 4, min_buckets = 8 }; /** Compare two irc::string's values for hashing in hash_map @@ -564,12 +467,14 @@ class CoreExport hash_compare_irc_string * being less and greater than zero for str1 being greater than str2. */ bool operator()(const irc::string &s1, const irc::string &s2) const; -#endif + bool operator()(const Anope::string &s1, const Anope::string &s2) const; + /** Return a hash value for a string using RFC1459 case sensitivity rules * @param s The stirng * @return The hash value */ size_t operator()(const irc::string &s) const; + size_t operator()(const Anope::string &s) const; }; #endif // HASHCOMP_H diff --git a/include/mail.h b/include/mail.h index 7148b56d8..8a1f8e390 100644 --- a/include/mail.h +++ b/include/mail.h @@ -1,22 +1,24 @@ #ifndef MAIL_H #define MAIL_H -extern CoreExport bool Mail(User *u, NickRequest *nr, const std::string &service, const std::string &subject, const std::string &message); -extern CoreExport bool Mail(User *u, NickCore *nc, const std::string &service, const std::string &subject, const std::string &message); -extern CoreExport bool Mail(NickCore *nc, const std::string &subject, const std::string &message); -extern CoreExport bool MailValidate(const std::string &email); +#include "anope.h" + +extern CoreExport bool Mail(User *u, NickRequest *nr, const Anope::string &service, const Anope::string &subject, const Anope::string &message); +extern CoreExport bool Mail(User *u, NickCore *nc, const Anope::string &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 { private: - std::string MailTo; - std::string Addr; - std::string Subject; - std::string Message; + Anope::string MailTo; + Anope::string Addr; + Anope::string Subject; + Anope::string Message; bool Success; public: - MailThread(const std::string &mailto, const std::string &addr, const std::string &subject, const std::string &message) : Thread(), MailTo(mailto), Addr(addr), Subject(subject), Message(message), Success(false) + MailThread(const Anope::string &mailto, const Anope::string &addr, const Anope::string &subject, const Anope::string &message) : Thread(), MailTo(mailto), Addr(addr), Subject(subject), Message(message), Success(false) { } diff --git a/include/modes.h b/include/modes.h index e4b683572..ce5372117 100644 --- a/include/modes.h +++ b/include/modes.h @@ -80,7 +80,7 @@ class CoreExport Mode /* Class of mode this is */ ModeClass Class; /* The mode name, as a string */ - std::string NameAsString; + Anope::string NameAsString; /* Mode char for this */ char ModeChar; /* Type of mode this is */ @@ -92,7 +92,7 @@ class CoreExport Mode * @param modeChar The mode char * @param type The mode type */ - Mode(ModeClass mClass, const std::string &mNameAsString, char modeChar, ModeType type); + Mode(ModeClass mClass, const Anope::string &mNameAsString, char modeChar, ModeType type); /** Default destructor */ @@ -112,7 +112,7 @@ class CoreExport UserMode : public Mode * @param mNameAsString The mode name as a string * @param modeChar The mode char */ - UserMode(UserModeName mName, const std::string &mNameAsString, char modeChar); + UserMode(UserModeName mName, const Anope::string &mNameAsString, char modeChar); /** Default destructor */ @@ -127,13 +127,13 @@ class CoreExport UserModeParam : public UserMode * @param mNameAsString The mode name as a string * @param modeChar The mode char */ - UserModeParam(UserModeName mName, const std::string &mNameAsString, char modeChar); + UserModeParam(UserModeName mName, const Anope::string &mNameAsString, char modeChar); /** Check if the param is valid * @param value The param * @return true or false */ - virtual bool IsValid(const std::string &value) { return true; } + virtual bool IsValid(const Anope::string &value) { return true; } }; /** This class is a channel mode, all channel modes use this/inherit from this @@ -149,7 +149,7 @@ class CoreExport ChannelMode : public Mode * @param mNameAsString The mode name as a string * @param modeChar The mode char */ - ChannelMode(ChannelModeName mName, const std::string &mNameAsString, char modeChar); + ChannelMode(ChannelModeName mName, const Anope::string &mNameAsString, char modeChar); /** Default destructor */ @@ -173,7 +173,7 @@ class CoreExport ChannelModeList : public ChannelMode * @param mNameAsString The mode name as a string * @param modeChar The mode char */ - ChannelModeList(ChannelModeName mName, const std::string &mNameAsString, char modeChar); + ChannelModeList(ChannelModeName mName, const Anope::string &mNameAsString, char modeChar); /** Default destructor */ @@ -183,19 +183,19 @@ class CoreExport ChannelModeList : public ChannelMode * @param mask The mask * @return true for yes, false for no */ - virtual bool IsValid(const std::string &mask) { return true; } + virtual bool IsValid(const Anope::string &mask) { return true; } /** Add the mask to the channel, this should be overridden * @param chan The channel * @param mask The mask */ - virtual void AddMask(Channel *chan, const char *mask) { } + virtual void AddMask(Channel *chan, const Anope::string &mask) { } /** Delete the mask from the channel, this should be overridden * @param chan The channel * @param mask The mask */ - virtual void DelMask(Channel *chan, const char *mask) { } + virtual void DelMask(Channel *chan, const Anope::string &mask) { } }; @@ -210,7 +210,7 @@ class CoreExport ChannelModeParam : public ChannelMode * @param modeChar The mode char * @param MinusArg true if this mode sends no arg when unsetting */ - ChannelModeParam(ChannelModeName mName, const std::string &mNameAsString, char modeChar, bool MinusArg = false); + ChannelModeParam(ChannelModeName mName, const Anope::string &mNameAsString, char modeChar, bool MinusArg = false); /** Default destructor */ @@ -223,7 +223,7 @@ class CoreExport ChannelModeParam : public ChannelMode * @param value The param * @return true for yes, false for no */ - virtual bool IsValid(const std::string &value) { return true; } + virtual bool IsValid(const Anope::string &value) { return true; } }; /** This is a mode that is a channel status, eg +v/h/o/a/q. @@ -240,7 +240,7 @@ class CoreExport ChannelModeStatus : public ChannelMode * @param modeChar The mode char * @param mSymbol The symbol for the mode, eg @ % + */ - ChannelModeStatus(ChannelModeName mName, const std::string &mNameAsString, char modeChar, char mSymbol); + ChannelModeStatus(ChannelModeName mName, const Anope::string &mNameAsString, char modeChar, char mSymbol); /** Default destructor */ @@ -254,9 +254,9 @@ class CoreExport ChannelModeBan : public ChannelModeList public: ChannelModeBan(char modeChar) : ChannelModeList(CMODE_BAN, "CMODE_BAN", modeChar) { } - void AddMask(Channel *chan, const char *mask); + void AddMask(Channel *chan, const Anope::string &mask); - void DelMask(Channel *chan, const char *mask); + void DelMask(Channel *chan, const Anope::string &mask); }; /** Channel mode +e @@ -266,9 +266,9 @@ class CoreExport ChannelModeExcept : public ChannelModeList public: ChannelModeExcept(char modeChar) : ChannelModeList(CMODE_EXCEPT, "CMODE_EXCEPT", modeChar) { } - void AddMask(Channel *chan, const char *mask); + void AddMask(Channel *chan, const Anope::string &mask); - void DelMask(Channel *chan, const char *mask); + void DelMask(Channel *chan, const Anope::string &mask); }; /** Channel mode +I @@ -278,9 +278,9 @@ class CoreExport ChannelModeInvex : public ChannelModeList public: ChannelModeInvex(char modeChar) : ChannelModeList(CMODE_INVITEOVERRIDE, "CMODE_INVITEOVERRIDE", modeChar) { } - void AddMask(Channel *chan, const char *mask); + void AddMask(Channel *chan, const Anope::string &mask); - void DelMask(Channel *chan, const char *mask); + void DelMask(Channel *chan, const Anope::string &mask); }; @@ -291,7 +291,7 @@ class CoreExport ChannelModeKey : public ChannelModeParam public: ChannelModeKey(char modeChar) : ChannelModeParam(CMODE_KEY, "CMODE_KEY", modeChar) { } - bool IsValid(const std::string &value); + bool IsValid(const Anope::string &value); }; /** Channel mode +f (flood) @@ -301,7 +301,7 @@ class ChannelModeFlood : public ChannelModeParam public: ChannelModeFlood(char modeChar, bool minusNoArg = false) : ChannelModeParam(CMODE_FLOOD, "CMODE_FLOOD", modeChar, minusNoArg) { } - bool IsValid(const std::string &value); + bool IsValid(const Anope::string &value); }; /** This class is used for channel mode +A (Admin only) @@ -350,9 +350,9 @@ class StackerInfo { public: /* Modes to be added */ - std::list<std::pair<void *, std::string> > AddModes; + std::list<std::pair<void *, Anope::string> > AddModes; /* Modes to be deleted */ - std::list<std::pair<void *, std::string> > DelModes; + std::list<std::pair<void *, Anope::string> > DelModes; /* The type of object this stacker info is for */ StackerType Type; /* Bot this is sent from */ @@ -363,7 +363,7 @@ class StackerInfo * @param Set true if setting, false if unsetting * @param Param The param for the mode */ - void AddMode(void *Mode, bool Set, const std::string &Param); + void AddMode(void *Mode, bool Set, const Anope::string &Param); }; /** This is mode manager @@ -388,7 +388,7 @@ class CoreExport ModeManager * @param info The stacker info for a channel or user * @return a list of strings */ - static std::list<std::string> BuildModeStrings(StackerInfo *info); + static std::list<Anope::string> BuildModeStrings(StackerInfo *info); /** Add a mode to the stacker, internal use only * @param bi The client to set the modes from @@ -397,7 +397,7 @@ class CoreExport ModeManager * @param Set Adding or removing? * @param Param A param, if there is one */ - static void StackerAddInternal(BotInfo *bi, User *u, UserMode *um, bool Set, const std::string &Param); + static void StackerAddInternal(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param); /** Add a mode to the stacker, internal use only * @param bi The client to set the modes from @@ -406,7 +406,7 @@ class CoreExport ModeManager * @param Set Adding or removing? * @param Param A param, if there is one */ - static void StackerAddInternal(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const std::string &Param); + static void StackerAddInternal(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param); /** Really add a mode to the stacker, internal use only * @param bi The client to set the modes from @@ -416,7 +416,7 @@ class CoreExport ModeManager * @param Param A param, if there is one * @param Type The type this is, user or channel */ - static void StackerAddInternal(BotInfo *bi, void *Object, void *Mode, bool Set, const std::string &Param, StackerType Type); + static void StackerAddInternal(BotInfo *bi, void *Object, void *Mode, bool Set, const Anope::string &Param, StackerType Type); public: /* List of all modes Anope knows about */ @@ -481,7 +481,7 @@ class CoreExport ModeManager * @param Set true for setting, false for removing * @param Param The param, if there is one */ - static void StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const std::string &Param = ""); + static void StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param = ""); /** Add a mode to the stacker to be set on a channel * @param bi The client to set the modes from @@ -490,7 +490,7 @@ class CoreExport ModeManager * @param Set true for setting, false for removing * @param Param The param, if there is one */ - static void StackerAdd(BotInfo *bi, Channel *c, ChannelModeName Name, bool Set, const std::string &Param = ""); + static void StackerAdd(BotInfo *bi, Channel *c, ChannelModeName Name, bool Set, const Anope::string &Param = ""); /** Add a mode to the stacker to be set on a channel * @param bi The client to set the modes from @@ -499,7 +499,7 @@ class CoreExport ModeManager * @param Set true for setting, false for removing * @param Param The param, if there is one */ - static void StackerAdd(BotInfo *bi, Channel *c, const char Mode, bool Set, const std::string &Param = ""); + static void StackerAdd(BotInfo *bi, Channel *c, const char Mode, bool Set, const Anope::string &Param = ""); /** Add a mode to the stacker to be set on a user * @param bi The client to set the modes from @@ -508,7 +508,7 @@ class CoreExport ModeManager * @param Set true for setting, false for removing * @param param The param, if there is one */ - static void StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const std::string &Param = ""); + static void StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param = ""); /** Add a mode to the stacker to be set on a user * @param bi The client to set the modes from @@ -517,7 +517,7 @@ class CoreExport ModeManager * @param Set true for setting, false for removing * @param Param The param, if there is one */ - static void StackerAdd(BotInfo *bi, User *u, UserModeName Name, bool Set, const std::string &Param = ""); + static void StackerAdd(BotInfo *bi, User *u, UserModeName Name, bool Set, const Anope::string &Param = ""); /** Add a mode to the stacker to be set on a user * @param bi The client to set the modes from @@ -526,7 +526,7 @@ class CoreExport ModeManager * @param Set true for setting, false for removing * @param Param The param, if there is one */ - static void StackerAdd(BotInfo *bi, User *u, const char Mode, bool Set, const std::string &Param = ""); + static void StackerAdd(BotInfo *bi, User *u, const char Mode, bool Set, const Anope::string &Param = ""); /** Process all of the modes in the stacker and send them to the IRCd to be set on channels/users */ diff --git a/include/modules.h b/include/modules.h index c18c6b08d..1d944872a 100644 --- a/include/modules.h +++ b/include/modules.h @@ -127,12 +127,12 @@ else \ const char *ano_moderr(); #endif -extern CoreExport Module *FindModule(const char *name); -extern CoreExport Module *FindModule(const std::string &name); -extern CoreExport Module *FindModule(const ci::string &name); +struct Message; + +extern CoreExport Module *FindModule(const Anope::string &name); int protocol_module_init(); extern CoreExport Message *createMessage(const char *name, int (*func)(const char *source, int ac, const char **av)); -extern CoreExport bool moduleMinVersion(int major,int minor,int patch,int build); +extern CoreExport bool moduleMinVersion(int major, int minor, int patch, int build); enum ModuleReturn { @@ -158,7 +158,8 @@ enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFOR enum MODType { CORE, PROTOCOL, THIRD, SUPPORTED, QATESTED, ENCRYPTION, DATABASE, SOCKETENGINE }; struct Message; -extern CoreExport std::multimap<std::string, Message *> MessageMap; +typedef std::multimap<Anope::string, Message *, hash_compare_std_string> message_map; +extern CoreExport message_map MessageMap; class Module; extern CoreExport std::list<Module *> Modules; @@ -212,11 +213,11 @@ class CoreExport Module public: /** The module name (e.g. os_modload) */ - std::string name; + Anope::string name; /** The temporary path/filename */ - std::string filename; + Anope::string filename; /** Callbacks used in this module */ @@ -232,11 +233,11 @@ class CoreExport Module /** Version of this module */ - std::string version; + Anope::string version; /** Author of the module */ - std::string author; + Anope::string author; /** What type this module is */ @@ -251,7 +252,7 @@ class CoreExport Module /** Creates and initialises a new module. * @param loadernick The nickname of the user loading the module. */ - Module(const std::string &modname, const std::string &loadernick); + Module(const Anope::string &modname, const Anope::string &loadernick); /** Destroys a module, freeing resources it has allocated. */ @@ -279,12 +280,12 @@ class CoreExport Module /** Set the modules version info. * @param version the version of the module */ - void SetVersion(const std::string &version); + void SetVersion(const Anope::string &version); /** Set the modules author info * @param author the author of the module */ - void SetAuthor(const std::string &author); + void SetAuthor(const Anope::string &author); /** Get the version of Anope this module was * compiled against @@ -321,7 +322,7 @@ class CoreExport Module * @param number The message number * @param ... The argument list **/ - void NoticeLang(const char *source, User * u, int number, ...); + void NoticeLang(const Anope::string &source, User *u, int number, ...); /** * Add a module provided command to the given service. @@ -345,7 +346,7 @@ class CoreExport Module * @param source The nick of the sender. * @param kickmsg The reason for the kick. */ - virtual void OnUserKicked(Channel *c, User *target, const std::string &source, const std::string &kickmsg) { } + virtual void OnUserKicked(Channel *c, User *target, const Anope::string &source, const Anope::string &kickmsg) { } /** Called when Services' configuration has been loaded. * @param startup True if Services is starting for the first time, false otherwise. @@ -391,7 +392,7 @@ class CoreExport Module * @param u The user. * @param oldnick The old nick of the user */ - virtual void OnUserNickChange(User *u, const std::string &oldnick) { } + virtual void OnUserNickChange(User *u, const Anope::string &oldnick) { } /** Called immediatly when a user tries to run a command * @param u The user @@ -401,7 +402,7 @@ class CoreExport Module * @param c The command class (if it exists) * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it */ - virtual EventReturn OnPreCommandRun(User *u, BotInfo *bi, const ci::string &command, const ci::string &message, Command *c) { return EVENT_CONTINUE; } + virtual EventReturn OnPreCommandRun(User *u, BotInfo *bi, const Anope::string &command, const Anope::string &message, Command *c) { return EVENT_CONTINUE; } /** Called before a command is due to be executed. * @param u The user executing the command @@ -410,7 +411,7 @@ class CoreExport Module * @param params The parameters the user is sending * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it */ - virtual EventReturn OnPreCommand(User *u, BotInfo *service, const ci::string &command, const std::vector<ci::string> ¶ms) { return EVENT_CONTINUE; } + virtual EventReturn OnPreCommand(User *u, BotInfo *service, const Anope::string &command, const std::vector<Anope::string> ¶ms) { return EVENT_CONTINUE; } /** Called after a command has been executed. * @param u The user executing the command @@ -418,7 +419,7 @@ class CoreExport Module * @param command The command the user executed * @param params The parameters the user sent */ - virtual void OnPostCommand(User *u, BotInfo *service, const ci::string &command, const std::vector<ci::string> ¶ms) { } + virtual void OnPostCommand(User *u, BotInfo *service, const Anope::string &command, const std::vector<Anope::string> ¶ms) { } /** Called after the core has finished loading the databases, but before * we connect to the server @@ -438,9 +439,9 @@ class CoreExport Module /** Called when anope needs to check passwords against encryption * see src/encrypt.c for detailed informations */ - virtual EventReturn OnEncrypt(const std::string &src, std::string &dest) { return EVENT_CONTINUE; } - virtual EventReturn OnDecrypt(const std::string &hashm, const std::string &src, std::string &dest) { return EVENT_CONTINUE; } - virtual EventReturn OnCheckPassword(const std::string &hashm, std::string &plaintext, std::string &password) { return EVENT_CONTINUE; } + virtual EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) { return EVENT_CONTINUE; } + virtual EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) { return EVENT_CONTINUE; } + virtual EventReturn OnCheckPassword(const Anope::string &hashm, Anope::string &plaintext, Anope::string &password) { return EVENT_CONTINUE; } /** Called on fantasy command * @param command The command @@ -448,7 +449,7 @@ class CoreExport Module * @param ci The channel it's being used in * @param params The params */ - virtual void OnBotFantasy(const std::string &command, User *u, ChannelInfo *ci, const std::string ¶ms) { } + virtual void OnBotFantasy(const Anope::string &command, User *u, ChannelInfo *ci, const Anope::string ¶ms) { } /** Called on fantasy command without access * @param command The command @@ -456,7 +457,7 @@ class CoreExport Module * @param ci The channel it's being used in * @param params The params */ - virtual void OnBotNoFantasyAccess(const std::string &command, User *u, ChannelInfo *ci, const std::string ¶ms) { } + virtual void OnBotNoFantasyAccess(const Anope::string &command, User *u, ChannelInfo *ci, const Anope::string ¶ms) { } /** Called after a bot joins a channel * @param ci The channael @@ -469,7 +470,7 @@ class CoreExport Module * @param ci Channel the ban is placed on * @param mask The mask being banned */ - virtual void OnBotBan(User *u, ChannelInfo *ci, const char *mask) { } + virtual void OnBotBan(User *u, ChannelInfo *ci, const Anope::string &mask) { } /** Called before a badword is added to the badword list * @param ci The channel @@ -490,7 +491,7 @@ class CoreExport Module * @param reason The reason * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it */ - virtual EventReturn OnBotKick(BotInfo *bi, Channel *c, User *u, const std::string &reason) { return EVENT_CONTINUE; } + virtual EventReturn OnBotKick(BotInfo *bi, Channel *c, User *u, const Anope::string &reason) { return EVENT_CONTINUE; } /** Called before a user parts a channel * @param u The user @@ -504,7 +505,7 @@ class CoreExport Module * @param channel The channel name * @param msg The part reason */ - virtual void OnPartChannel(User *u, Channel *c, const std::string &channel, const std::string &msg) { } + virtual void OnPartChannel(User *u, Channel *c, const Anope::string &channel, const Anope::string &msg) { } /** Called before a user joins a channel * @param u The user @@ -523,7 +524,7 @@ class CoreExport Module * @param c The channel * @param topic The new topic */ - virtual void OnTopicUpdated(Channel *c, const char *topic) { } + virtual void OnTopicUpdated(Channel *c, const Anope::string &topic) { } /** Called before a channel expires * @param ci The channel @@ -534,7 +535,7 @@ class CoreExport Module /** Called when a channel expires * @param chname The channel name */ - virtual void OnChanExpire(const char *chname) { } + virtual void OnChanExpire(const Anope::string &chname) { } /** Called before Anope connects to its uplink * @param u The uplink we're going to connect to @@ -568,13 +569,13 @@ class CoreExport Module /** Called when the flatfile dbs are being written * @param Write A callback to the function used to insert a line into the database */ - virtual void OnDatabaseWrite(void (*Write)(const std::string &)) { } + virtual void OnDatabaseWrite(void (*Write)(const Anope::string &)) { } /** Called when a line is read from the database * @param params The params from the database * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing */ - virtual EventReturn OnDatabaseRead(const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; } + virtual EventReturn OnDatabaseRead(const std::vector<Anope::string> ¶ms) { return EVENT_CONTINUE; } /** Called when nickcore metadata is read from the database * @param nc The nickcore @@ -582,7 +583,7 @@ class CoreExport Module * @param params The params from the database * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing */ - virtual EventReturn OnDatabaseReadMetadata(NickCore *nc, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; } + virtual EventReturn OnDatabaseReadMetadata(NickCore *nc, const Anope::string &key, const std::vector<Anope::string> ¶ms) { return EVENT_CONTINUE; } /** Called when nickcore metadata is read from the database * @param na The nickalias @@ -590,7 +591,7 @@ class CoreExport Module * @param params The params from the database * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing */ - virtual EventReturn OnDatabaseReadMetadata(NickAlias *na, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; } + virtual EventReturn OnDatabaseReadMetadata(NickAlias *na, const Anope::string &key, const std::vector<Anope::string> ¶ms) { return EVENT_CONTINUE; } /** Called when nickrequest metadata is read from the database * @param nr The nickrequest @@ -598,7 +599,7 @@ class CoreExport Module * @param params The params from the database * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing */ - virtual EventReturn OnDatabaseReadMetadata(NickRequest *nr, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; } + virtual EventReturn OnDatabaseReadMetadata(NickRequest *nr, const Anope::string &key, const std::vector<Anope::string> ¶ms) { return EVENT_CONTINUE; } /** Called when botinfo metadata is read from the database * @param bi The botinfo @@ -606,7 +607,7 @@ class CoreExport Module * @param params The params from the database * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing */ - virtual EventReturn OnDatabaseReadMetadata(BotInfo *bi, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; } + virtual EventReturn OnDatabaseReadMetadata(BotInfo *bi, const Anope::string &key, const std::vector<Anope::string> ¶ms) { return EVENT_CONTINUE; } /** Called when chaninfo metadata is read from the database * @param ci The chaninfo @@ -614,37 +615,37 @@ class CoreExport Module * @param params The params from the database * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing */ - virtual EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; } + virtual EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, const std::vector<Anope::string> ¶ms) { return EVENT_CONTINUE; } /** Called when we are writing metadata for a nickcore * @param WriteMetata A callback function used to insert the metadata * @param nc The nickcore */ - virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), NickCore *nc) { } + virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const Anope::string &, const Anope::string &), NickCore *nc) { } /** Called when we are wrting metadata for a nickalias * @param WriteMetata A callback function used to insert the metadata * @param na The nick alias */ - virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), NickAlias *na) { } + virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const Anope::string &, const Anope::string &), NickAlias *na) { } /** Called when we are wrting metadata for a nickrequest * @param WriteMetata A callback function used to insert the metadata * @param nr The nick request */ - virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), NickRequest *nr) { } + virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const Anope::string &, const Anope::string &), NickRequest *nr) { } /** Called when we are writing metadata for a botinfo * @param WriteMetata A callback function used to insert the metadata * @param bi The botinfo */ - virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), BotInfo *bi) { } + virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const Anope::string &, const Anope::string &), BotInfo *bi) { } /** Called when are are writing metadata for a channelinfo * @param WriteMetata A callback function used to insert the metadata * @param bi The channelinfo */ - virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), ChannelInfo *ci) { } + virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const Anope::string &, const Anope::string &), ChannelInfo *ci) { } /** Called before services restart */ @@ -665,7 +666,7 @@ class CoreExport Module /** Called on signal * @param msg The quitmsg */ - virtual void OnSignal(const char *msg) { } + virtual void OnSignal(const Anope::string &msg) { } /** Called before a nick expires * @param na The nick @@ -733,7 +734,7 @@ class CoreExport Module * @param u The user * @param msg The quit message */ - virtual void OnUserQuit(User *u, const std::string &msg) { } + virtual void OnUserQuit(User *u, const Anope::string &msg) { } /** Called when a user disconnects * @param u The user @@ -795,7 +796,7 @@ class CoreExport Module /** Called when a channel is dropped * @param chname The channel name */ - virtual void OnChanDrop(const std::string &chname) { } + virtual void OnChanDrop(const Anope::string &chname) { } /** Called when a channel is forbidden * @param ci The channel @@ -856,7 +857,7 @@ class CoreExport Module /** Called when a nick is dropped * @param nick The nick */ - virtual void OnNickDrop(const char *nick) { } + virtual void OnNickDrop(const Anope::string &nick) { } /** Called when a nick is forbidden * @param na The nick alias of the forbidden nick @@ -908,7 +909,7 @@ class CoreExport Module * @param nc pointer to the NickCore * @param newdisplay the new display */ - virtual void OnChangeCoreDisplay(NickCore *nc, const std::string &newdisplay) { } + virtual void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) { } /** called from ns_register.c, after the NickRequest have been created * @param nr pointer to the NickRequest @@ -929,13 +930,13 @@ class CoreExport Module * @param nc The nick * @param entry The entry */ - virtual void OnNickAddAccess(NickCore *nc, const std::string &entry) { } + virtual void OnNickAddAccess(NickCore *nc, const Anope::string &entry) { } /** Called from NickCore::EraseAccess() * @param nc pointer to the NickCore * @param entry The access mask */ - virtual void OnNickEraseAccess(NickCore *nc, const std::string &entry) { } + virtual void OnNickEraseAccess(NickCore *nc, const Anope::string &entry) { } /** Called when a user requests info for a nick * @param u The user requesting info @@ -973,7 +974,7 @@ class CoreExport Module * @param mi The memo info * @param number What memo number is being deleted, can be 0 for all memos */ - virtual void OnMemoDel(NickCore *nc, MemoInfo *mi, int number) { } + virtual void OnMemoDel(const NickCore *nc, MemoInfo *mi, int number) { } /** Called when a memo is deleted * @param ci The channel of the memo being deleted @@ -988,7 +989,7 @@ class CoreExport Module * @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, ChannelModeName Name, const std::string ¶m) { return EVENT_CONTINUE; } + virtual EventReturn OnChannelModeSet(Channel *c, ChannelModeName Name, const Anope::string ¶m) { return EVENT_CONTINUE; } /** Called when a mode is unset on a channel * @param c The channel @@ -996,7 +997,7 @@ class CoreExport Module * @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, ChannelModeName Name, const std::string ¶m) { return EVENT_CONTINUE; } + virtual EventReturn OnChannelModeUnset(Channel *c, ChannelModeName Name, const Anope::string ¶m) { return EVENT_CONTINUE; } /** Called when a mode is set on a user * @param u The user @@ -1026,7 +1027,7 @@ class CoreExport Module * @param param The param, if there is one and if status is true * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock. */ - virtual EventReturn OnMLock(ChannelModeName Name, bool status, const std::string ¶m) { return EVENT_CONTINUE; } + virtual EventReturn OnMLock(ChannelModeName Name, bool status, const Anope::string ¶m) { return EVENT_CONTINUE; } /** Called when a mode is about to be unlocked * @param Name The mode being mlocked @@ -1132,26 +1133,17 @@ class CoreExport ModuleManager **/ static void LoadModuleList(std::list<ci::string> &ModList); - /** Loads a given module. - * @param m the module to load - * @param u the user who loaded it, NULL for auto-load - * @return MOD_ERR_OK on success, anything else on fail - */ - static int LoadModule(const char *modname, User *u); - - /** Loads a given module. - * @param m the module to load - * @param u the user who loaded it, NULL for auto-load - * @return MOD_ERR_OK on success, anything else on fail - */ - static int LoadModule(const std::string &modname, User *u); + /** Load up a list of modules. + * @param module_list The list of modules to load + **/ + static void LoadModuleList(std::list<Anope::string> &ModList); /** Loads a given module. * @param m the module to load * @param u the user who loaded it, NULL for auto-load * @return MOD_ERR_OK on success, anything else on fail */ - static int LoadModule(const ci::string &modname, User *u); + static int LoadModule(const Anope::string &modname, User *u); /** Unload the given module. * @param m the module to unload @@ -1252,8 +1244,8 @@ class CallBack : public Timer struct Message { - std::string name; - int (*func)(const char *source, int ac, const char **av); + Anope::string name; + int (*func)(const Anope::string &source, int ac, const char **av); }; #endif // MODULES_H diff --git a/include/operserv.h b/include/operserv.h index 9dbe8e7c3..b5025b007 100644 --- a/include/operserv.h +++ b/include/operserv.h @@ -14,7 +14,7 @@ extern CoreExport std::vector<std::bitset<32> > DefCon; extern CoreExport bool DefConModesSet; extern CoreExport Flags<ChannelModeName, CMODE_END> DefConModesOn; extern CoreExport Flags<ChannelModeName, CMODE_END> DefConModesOff; -extern CoreExport std::map<ChannelModeName, std::string> DefConModesOnParams; +extern CoreExport std::map<ChannelModeName, Anope::string> DefConModesOnParams; class XLineManager; extern CoreExport XLineManager *SGLine; @@ -22,19 +22,19 @@ extern CoreExport XLineManager *SZLine; extern CoreExport XLineManager *SQLine; extern CoreExport XLineManager *SNLine; -extern CoreExport bool SetDefConParam(ChannelModeName, std::string &); -extern CoreExport bool GetDefConParam(ChannelModeName, std::string &); +extern CoreExport bool SetDefConParam(ChannelModeName, const Anope::string &); +extern CoreExport bool GetDefConParam(ChannelModeName, Anope::string &); extern CoreExport void UnsetDefConParam(ChannelModeName); extern CoreExport bool CheckDefCon(DefconLevel Level); extern CoreExport bool CheckDefCon(int level, DefconLevel Level); extern CoreExport void AddDefCon(int level, DefconLevel Level); extern CoreExport void DelDefCon(int level, DefconLevel Level); -extern CoreExport void operserv(User *u, const std::string &message); +extern CoreExport void operserv(User *u, const Anope::string &message); extern CoreExport void os_init(); -extern CoreExport void oper_global(char *nick, const char *fmt, ...); -extern CoreExport void server_global(Server *s, const std::string &message); +extern CoreExport void oper_global(const Anope::string &nick, const char *fmt, ...); +extern CoreExport void server_global(Server *s, const Anope::string &message); enum XLineType { @@ -46,19 +46,19 @@ enum XLineType class CoreExport XLine { public: - ci::string Mask; - ci::string By; + Anope::string Mask; + Anope::string By; time_t Created; time_t Expires; - std::string Reason; + Anope::string Reason; - XLine(const ci::string &mask, const std::string &reason = ""); + XLine(const Anope::string &mask, const Anope::string &reason = ""); - XLine(const ci::string &mask, const ci::string &by, const time_t expires, const std::string &reason); + XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason); - ci::string GetNick() const; - ci::string GetUser() const; - ci::string GetHost() const; + Anope::string GetNick() const; + Anope::string GetUser() const; + Anope::string GetHost() const; }; class CoreExport XLineManager @@ -106,7 +106,7 @@ class CoreExport XLineManager /** Get the XLine vector * @return The vector */ - const std::vector<XLine *>& GetList() const; + const std::vector<XLine *> &GetList() const; /** Add an entry to this XLineManager * @param x The entry @@ -137,7 +137,7 @@ class CoreExport XLineManager * @param reaosn The reason * @return A pointer to the XLine */ - virtual XLine *Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason); + virtual XLine *Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason); /** Delete an XLine, eg, remove it from the IRCd. * @param x The xline @@ -153,13 +153,13 @@ class CoreExport XLineManager * 3 - Mask is already covered by another mask * In each case the XLine it matches/is covered by is returned in XLine* */ - std::pair<int, XLine *> CanAdd(const ci::string &mask, time_t expires); + std::pair<int, XLine *> CanAdd(const Anope::string &mask, time_t expires); /** Checks if this list has an entry * @param mask The mask * @return The XLine the user matches, or NULL */ - XLine *HasEntry(const ci::string &mask) const; + XLine *HasEntry(const Anope::string &mask) const; /** Check a user against all of the xlines in this XLineManager * @param u The user @@ -183,7 +183,7 @@ class CoreExport XLineManager class SGLineManager : public XLineManager { public: - XLine *Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason); + XLine *Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason); void Del(XLine *x); @@ -195,7 +195,7 @@ class SGLineManager : public XLineManager class SNLineManager : public XLineManager { public: - XLine *Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason); + XLine *Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason); void Del(XLine *x); @@ -207,7 +207,7 @@ class SNLineManager : public XLineManager class SQLineManager : public XLineManager { public: - XLine *Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason); + XLine *Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason); void Del(XLine *x); @@ -221,7 +221,7 @@ class SQLineManager : public XLineManager class SZLineManager : public XLineManager { public: - XLine *Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason); + XLine *Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason); void Del(XLine *x); diff --git a/include/opertype.h b/include/opertype.h index 1867e4113..40607b39f 100644 --- a/include/opertype.h +++ b/include/opertype.h @@ -15,12 +15,12 @@ class CoreExport OperType private: /** The name of this opertype, e.g. "sra". */ - ci::string name; + Anope::string name; /** Privs that this opertype may use, e.g. 'users/auspex'. * This *must* be std::list, see commands comment for details. */ - std::list<ci::string> privs; + std::list<Anope::string> privs; /** Commands this user may execute, e.g: * botserv/set/ *, botserv/set/private, botserv/ * @@ -30,7 +30,7 @@ class CoreExport OperType * we support full globbing here. This shouldn't be a problem * as we don't invoke it often. */ - std::list<ci::string> commands; + std::list<Anope::string> commands; /** Set of opertypes we inherit from */ @@ -39,33 +39,33 @@ class CoreExport OperType /** Create a new opertype of the given name. * @param nname The opertype name, e.g. "sra". */ - OperType(const ci::string &nname); + OperType(const Anope::string &nname); /** Check whether this opertype has access to run the given command string. * @param cmdstr The string to check, e.g. botserv/set/private. * @return True if this opertype may run the specified command, false otherwise. */ - bool HasCommand(const ci::string &cmdstr) const; + bool HasCommand(const Anope::string &cmdstr) const; /** Check whether this opertype has access to the given special permission. * @param privstr The priv to check for, e.g. users/auspex. * @return True if this opertype has the specified priv, false otherwise. */ - bool HasPriv(const ci::string &privstr) const; + bool HasPriv(const Anope::string &privstr) const; /** Add the specified command to this opertype. * @param cmdstr The command mask to grant this opertype access to, e.g: nickserv/ *, chanserv/set/ *, botserv/set/private. */ - void AddCommand(const ci::string &cmdstr); + void AddCommand(const Anope::string &cmdstr); /** Add the specified priv mask to this opertype. * @param privstr The specified mask of privs to grant this opertype access to, e.g. users/auspex, users/ *, etc. */ - void AddPriv(const ci::string &privstr); + void AddPriv(const Anope::string &privstr); /** Returns the name of this opertype. */ - const ci::string &GetName() const; + const Anope::string &GetName() const; /** Make this opertype inherit commands and privs from another opertype * @param ot The opertype to inherit from diff --git a/include/regchannel.h b/include/regchannel.h index 266b057d7..00a99e96d 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -9,7 +9,7 @@ #ifndef REGCHANNEL_H #define REGCHANNEL_H -typedef unordered_map_namespace::unordered_map<ci::string, ChannelInfo *, hash_compare_ci_string> registered_channel_map; +typedef unordered_map_namespace::unordered_map<Anope::string, ChannelInfo *, hash_compare_ci_string> registered_channel_map; extern CoreExport registered_channel_map RegisteredChannelList; /** Flags used for the ChannelInfo class @@ -65,41 +65,41 @@ enum ChannelInfoFlag class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, CI_END> { private: - std::map<ChannelModeName, std::string> Params; /* Map of parameters by mode name for mlock */ - std::vector<ChanAccess *> access; /* List of authorized users */ - std::vector<AutoKick *> akick; /* List of users to kickban */ - std::vector<BadWord *> badwords; /* List of badwords */ - Flags<ChannelModeName, CMODE_END> mlock_on; /* Modes mlocked on */ - Flags<ChannelModeName, CMODE_END> mlock_off; /* Modes mlocked off */ + std::map<ChannelModeName, Anope::string> Params; /* Map of parameters by mode name for mlock */ + std::vector<ChanAccess *> access; /* List of authorized users */ + std::vector<AutoKick *> akick; /* List of users to kickban */ + std::vector<BadWord *> badwords; /* List of badwords */ + Flags<ChannelModeName, CMODE_END> mlock_on; /* Modes mlocked on */ + Flags<ChannelModeName, CMODE_END> mlock_off; /* Modes mlocked off */ public: /** Default constructor * @param chname The channel name */ - ChannelInfo(const std::string &chname); + ChannelInfo(const Anope::string &chname); /** Default destructor */ ~ChannelInfo(); - std::string name; /* Channel name */ + Anope::string name; /* Channel name */ NickCore *founder; NickCore *successor; /* Who gets the channel if the founder nick is dropped or expires */ - char *desc; + Anope::string desc; time_t time_registered; time_t last_used; - char *last_topic; /* Last topic on the channel */ - std::string last_topic_setter; /* Who set the last topic */ - time_t last_topic_time; /* When the last topic was set */ + Anope::string last_topic; /* Last topic on the channel */ + Anope::string last_topic_setter; /* Who set the last topic */ + time_t last_topic_time; /* When the last topic was set */ - char *forbidby; - char *forbidreason; + Anope::string forbidby; + Anope::string forbidreason; int16 bantype; int16 *levels; /* Access levels for commands */ - char *entry_message; /* Notice sent on entering channel */ + Anope::string entry_message; /* Notice sent on entering channel */ MemoInfo memos; @@ -124,7 +124,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * * Creates a new access list entry and inserts it into the access list. */ - void AddAccess(NickCore *nc, int16 level, const std::string &creator, int32 last_seen = 0); + void AddAccess(NickCore *nc, int16 level, const Anope::string &creator, int32 last_seen = 0); /** Get an entry from the channel access list by index * @@ -143,7 +143,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * * Retrieves an entry from the access list that matches the given NickCore, optionally also matching a certain level. */ - ChanAccess *GetAccess(NickCore *nc, int16 level = 0); + ChanAccess *GetAccess(const NickCore *nc, int16 level = 0); /** Get the size of the accss vector for this channel * @return The access vector size @@ -171,7 +171,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * @param t The time the akick was added, defaults to now * @param lu The time the akick was last used, defaults to never */ - AutoKick *AddAkick(const std::string &user, NickCore *akicknc, const std::string &reason, time_t t = time(NULL), time_t lu = 0); + AutoKick *AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t = time(NULL), time_t lu = 0); /** Add an akick entry to the channel by reason * @param user The user who added the akick @@ -180,7 +180,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * @param t The time the akick was added, defaults to now * @param lu The time the akick was last used, defaults to never */ - AutoKick *AddAkick(const std::string &user, const std::string &mask, const std::string &reason, time_t t = time(NULL), time_t lu = 0); + AutoKick *AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = time(NULL), time_t lu = 0); /** Get an entry from the channel akick list * @param index The index in the akick vector @@ -207,7 +207,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * @param type The type (SINGLE START END) * @return The badword */ - BadWord *AddBadWord(const std::string &word, BadWordType type); + BadWord *AddBadWord(const Anope::string &word, BadWordType type); /** Get a badword structure by index * @param index The index @@ -247,7 +247,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * @param param An optional param arg for + mlocked modes * @return true on success, false on failure (module blocking) */ - bool SetMLock(ChannelModeName Name, bool status, const std::string param = ""); + bool SetMLock(ChannelModeName Name, bool status, const Anope::string ¶m = ""); /** Remove a mlock * @param Name The mode @@ -270,7 +270,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * @param Target a string to put the param into * @return true on success */ - const bool GetParam(ChannelModeName Name, std::string &Target); + const bool GetParam(ChannelModeName Name, Anope::string &Target); /** Check if a mode is set and has a param * @param Name The mode diff --git a/include/servers.h b/include/servers.h index 615705052..5c7d114f8 100644 --- a/include/servers.h +++ b/include/servers.h @@ -6,8 +6,8 @@ extern CoreExport Server *Me; extern CoreExport void CapabParse(int ac, const char **av); -extern CoreExport void do_server(const std::string &source, const std::string &servername, unsigned int hops, const std::string &descript, const std::string &numeric); -extern CoreExport void do_squit(const char *source, int ac, const char **av); +extern CoreExport void do_server(const Anope::string &source, const Anope::string &servername, unsigned int hops, const Anope::string &descript, const Anope::string &numeric); +extern CoreExport void do_squit(const Anope::string &source, int ac, const char **av); extern CoreExport const char *ts6_uid_retrieve(); extern CoreExport const char *ts6_sid_retrieve(); @@ -55,7 +55,7 @@ enum CapabType /* CAPAB stuffs */ struct CapabInfo { - std::string Token; + Anope::string Token; CapabType Flag; }; @@ -78,20 +78,20 @@ class CoreExport Server : public Flags<ServerFlag> { private: /* Server name */ - std::string Name; + Anope::string Name; /* Hops between services and server */ unsigned int Hops; /* Server description */ - std::string Description; + Anope::string Description; /* Server ID */ - std::string SID; + Anope::string SID; /* Links for this server */ - std::list<Server *>* Links; + std::list<Server *> *Links; /* Uplink for this server */ Server *UplinkServer; /* Reason this server was quit */ - std::string QReason; + Anope::string QReason; public: /** Constructor @@ -101,7 +101,7 @@ class CoreExport Server : public Flags<ServerFlag> * @param description Server rdescription * @param sid Server sid/numeric */ - Server(Server *uplink, const std::string &name, unsigned int hops, const std::string &description, const std::string &sid); + Server(Server *uplink, const Anope::string &name, unsigned int hops, const Anope::string &description, const Anope::string &sid); /** Destructor */ @@ -110,12 +110,12 @@ class CoreExport Server : public Flags<ServerFlag> /** Delete this server with a reason * @param reason The reason */ - void Delete(const std::string &reason); + void Delete(const Anope::string &reason); /** Get the name for this server * @return The name */ - const std::string &GetName() const; + const Anope::string &GetName() const; /** Get the number of hops this server is from services * @return Number of hops @@ -125,17 +125,17 @@ class CoreExport Server : public Flags<ServerFlag> /** Set the server description * @param desc The new description */ - void SetDescription(const std::string &desc); + void SetDescription(const Anope::string &desc); /** Get the server description * @return The server description */ - const std::string &GetDescription() const; + const Anope::string &GetDescription() const; /** Get the server numeric/SID * @return The numeric/SID */ - const std::string &GetSID() const; + const Anope::string &GetSID() const; /** Get the list of links this server has, or NULL if it has none * @return A list of servers @@ -177,7 +177,7 @@ class CoreExport Server : public Flags<ServerFlag> * @param s The server list to search for this server on, defaults to our Uplink * @return The server */ - static Server *Find(const std::string &name, Server *s = NULL); + static Server *Find(const Anope::string &name, Server *s = NULL); }; #endif // SERVERS_H diff --git a/include/services.h b/include/services.h index d42926245..5830107d5 100644 --- a/include/services.h +++ b/include/services.h @@ -22,18 +22,6 @@ /* Some SUN fixs */ #ifdef __sun -/* Solaris specific code, types that do not exist in Solaris' - * sys/types.h - */ -# undef u_int8_t -# undef u_int16_t -# undef u_int32_t -# undef u_int_64_t -# define u_int8_t uint8_t -# define u_int16_t uint16_t -# define u_int32_t uint32_t -# define u_int64_t uint64_t - # ifndef INADDR_NONE # define INADDR_NONE (-1) # endif @@ -114,16 +102,6 @@ extern CoreExport const char *inet_ntop(int af, const void *src, char *dst, size # include <sys/select.h> #endif -#ifndef va_copy -# ifdef __va_copy -# define VA_COPY(DEST,SRC) __va_copy((DEST), (SRC)) -# else -# define VA_COPY(DEST, SRC) memcpy ((&DEST), (&SRC), sizeof(va_list)) -# endif -#else -# define VA_COPY(DEST, SRC) va_copy((DEST), (SRC)) -#endif - #ifdef _AIX /* Some AIX boxes seem to have bogus includes that don't have these * prototypes. */ @@ -166,7 +144,7 @@ extern "C" void __pfnBkCheck() {} #ifdef _WIN32 # define MODULE_INIT(x) \ extern "C" DllExport Module *AnopeInit(const std::string &, const std::string &); \ - extern "C" Module *AnopeInit(const std::string &modname, const std::string &creator) \ + extern "C" Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \ { \ return new x(modname, creator); \ } \ @@ -187,7 +165,7 @@ extern "C" void __pfnBkCheck() {} } #else # define MODULE_INIT(x) \ - extern "C" DllExport Module *AnopeInit(const std::string &modname, const std::string &creator) \ + extern "C" DllExport Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \ { \ return new x(modname, creator); \ } \ @@ -212,6 +190,8 @@ extern "C" void __pfnBkCheck() {} #include <bitset> #include <set> +#include "anope.h" + /** This class can be used on its own to represent an exception, or derived to represent a module-specific exception. * When a module whishes to abort, e.g. within a constructor, it should throw an exception using ModuleException or * a class derived from ModuleException. If a module throws an exception during its constructor, the module will not @@ -223,45 +203,37 @@ class CoreException : public std::exception protected: /** Holds the error message to be displayed */ - std::string err; + Anope::string err; /** Source of the exception */ - std::string source; + Anope::string source; public: /** Default constructor, just uses the error mesage 'Core threw an exception'. */ - CoreException() : err("Core threw an exception"), source("The core") {} + CoreException() : err("Core threw an exception"), source("The core") { } /** This constructor can be used to specify an error message before throwing. */ - CoreException(const char *message) : err(message), source("The core") {} - CoreException(const std::string &message) : err(message), source("The core") {} - CoreException(const ci::string &message) : err(message.c_str()), source("The core") {} + CoreException(const Anope::string &message) : err(message), source("The core") { } /** This constructor can be used to specify an error message before throwing, * and to specify the source of the exception. */ - CoreException(const char *message, const char *src) : err(message), source(src) {} - CoreException(const std::string &message, const char *src) : err(message), source(src) {} - CoreException(const ci::string &message, const char *src) : err(message.c_str()), source(src) {} - CoreException(const std::string &message, const std::string &src) : err(message), source(src) {} - CoreException(const ci::string &message, const std::string &src) : err(message.c_str()), source(src) {} - CoreException(const std::string &message, const ci::string &src) : err(message), source(src.c_str()) {} - CoreException(const ci::string &message, const ci::string &src) : err(message.c_str()), source(src.c_str()) {} + CoreException(const Anope::string &message, const Anope::string &src) : err(message), source(src) { } /** This destructor solves world hunger, cancels the world debt, and causes the world to end. * Actually no, it does nothing. Never mind. * @throws Nothing! */ - virtual ~CoreException() throw() {} + virtual ~CoreException() throw() { } /** Returns the reason for the exception. * The module should probably put something informative here as the user will see this upon failure. */ - virtual const char *GetReason() const + virtual const Anope::string &GetReason() const { - return err.c_str(); + return err; } - virtual const char *GetSource() const + virtual const Anope::string &GetSource() const { - return source.c_str(); + return source; } }; @@ -270,18 +242,16 @@ class ModuleException : public CoreException public: /** Default constructor, just uses the error mesage 'Module threw an exception'. */ - ModuleException() : CoreException("Module threw an exception", "A Module") {} + ModuleException() : CoreException("Module threw an exception", "A Module") { } /** This constructor can be used to specify an error message before throwing. */ - ModuleException(const char *message) : CoreException(message, "A Module") {} - ModuleException(const std::string &message) : CoreException(message, "A Module") {} - ModuleException(const ci::string &message) : CoreException(message, "A Module") {} + ModuleException(const Anope::string &message) : CoreException(message, "A Module") { } /** This destructor solves world hunger, cancels the world debt, and causes the world to end. * Actually no, it does nothing. Never mind. * @throws Nothing! */ - virtual ~ModuleException() throw() {} + virtual ~ModuleException() throw() { } }; class DatabaseException : public CoreException @@ -290,7 +260,7 @@ class DatabaseException : public CoreException /** This constructor can be used to specify an error message before throwing. * @param mmessage The exception */ - DatabaseException(const std::string &message) : CoreException(message, "A database module") { } + DatabaseException(const Anope::string &message) : CoreException(message, "A database module") { } /** Destructor * @throws Nothing @@ -355,10 +325,9 @@ template<typename T, size_t Size = 32> class Flags /*************************************************************************/ -template<typename T> -inline const std::string stringify(const T &x) +template<typename T> inline Anope::string stringify(const T &x) { - std::stringstream stream; + std::ostringstream stream; if (!(stream << x)) throw CoreException("Stringify fail"); @@ -366,6 +335,47 @@ inline const std::string stringify(const T &x) return stream.str(); } +template<typename T> inline void convert(const Anope::string &s, T &x, Anope::string &leftover, bool failIfLeftoverChars = true) +{ + leftover.clear(); + std::istringstream i(s.str()); + char c; + bool res = i >> x; + if (!res) + throw CoreException("Convert fail"); + if (failIfLeftoverChars) + { + if (i.get(c)) + throw CoreException("Convert fail"); + } + else + { + std::string left; + getline(i, left); + leftover = left; + } +} + +template<typename T> inline void convert(const Anope::string &s, T &x, bool failIfLeftoverChars = true) +{ + Anope::string Unused; + convert(s, x, Unused, failIfLeftoverChars); +} + +template<typename T> inline T convertTo(const Anope::string &s, Anope::string &leftover, bool failIfLeftoverChars = true) +{ + T x; + convert(s, x, leftover, failIfLeftoverChars); + return x; +} + +template<typename T> inline T convertTo(const Anope::string &s, bool failIfLeftoverChars = true) +{ + T x; + convert(s, x, failIfLeftoverChars); + return x; +} + /*************************************************************************/ class User; @@ -415,7 +425,6 @@ struct IRCDVar int chgreal; /* Change RealName */ int knock_needs_i; /* Check if we needed +i when setting NOKNOCK */ int token; /* Does Anope support the tokens for the ircd */ - int sjb64; int svsmode_ucmode; /* Can remove User Channel Modes with SVSMODE */ int sglineenforce; int ts6; /* ircd is TS6 */ @@ -448,8 +457,8 @@ class Memo : public Flags<MemoFlag> public: uint32 number; /* Index number -- not necessarily array position! */ time_t time; /* When it was sent */ - std::string sender; - char *text; + Anope::string sender; + Anope::string text; }; struct MemoInfo @@ -463,9 +472,9 @@ struct MemoInfo class CoreExport HostInfo { private: - std::string Ident; - std::string Host; - std::string Creator; + Anope::string Ident; + Anope::string Host; + Anope::string Creator; time_t Time; public: @@ -475,7 +484,7 @@ class CoreExport HostInfo * @param creator Who created the vhost * @param time When the vhost was craated */ - void SetVhost(const std::string &ident, const std::string &host, const std::string &creator, time_t created = time(NULL)); + void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = time(NULL)); /** Remove a users vhost **/ @@ -489,17 +498,17 @@ class CoreExport HostInfo /** Retrieve the vhost ident * @return the ident */ - const std::string &GetIdent() const; + const Anope::string &GetIdent() const; /** Retrieve the vhost host * @return the host */ - const std::string &GetHost() const; + const Anope::string &GetHost() const; /** Retrieve the vhost creator * @return the creator */ - const std::string &GetCreator() const; + const Anope::string &GetCreator() const; /** Retrieve when the vhost was crated * @return the time it was created @@ -545,7 +554,7 @@ struct ChanAccess int16 level; NickCore *nc; /* Guaranteed to be non-NULL if in use, NULL if not */ time_t last_seen; - std::string creator; + Anope::string creator; }; /** Flags for auto kick @@ -563,11 +572,11 @@ class AutoKick : public Flags<AutoKickFlag> { public: /* Only one of these can be in use */ - std::string mask; + Anope::string mask; NickCore *nc; - std::string reason; - std::string creator; + Anope::string reason; + Anope::string creator; time_t addtime; time_t last_used; }; @@ -589,7 +598,7 @@ enum BadWordType /* Structure used to contain bad words. */ struct BadWord { - std::string word; + Anope::string word; BadWordType type; }; @@ -673,15 +682,18 @@ enum BotServFlag }; /* Indices for TTB (Times To Ban) */ -#define TTB_BOLDS 0 -#define TTB_COLORS 1 -#define TTB_REVERSES 2 -#define TTB_UNDERLINES 3 -#define TTB_BADWORDS 4 -#define TTB_CAPS 5 -#define TTB_FLOOD 6 -#define TTB_REPEAT 7 -#define TTB_SIZE 8 +enum +{ + TTB_BOLDS, + TTB_COLORS, + TTB_REVERSES, + TTB_UNDERLINES, + TTB_BADWORDS, + TTB_CAPS, + TTB_FLOOD, + TTB_REPEAT, + TTB_SIZE +}; #include "regchannel.h" @@ -690,11 +702,10 @@ enum BotServFlag struct LevelInfo { int what; - const char *name; + Anope::string name; int desc; }; - /*************************************************************************/ #include "users.h" @@ -708,7 +719,7 @@ struct BanData { BanData *next, *prev; - char *mask; /* Since a nick is unsure and a User structure is unsafe */ + Anope::string mask; /* Since a nick is unsure and a User structure is unsafe */ time_t last_use; /* Since time is the only way to check whether it's still useful */ int16 ttb[TTB_SIZE]; }; @@ -735,7 +746,7 @@ class Entry : public Flags<EntryType> Entry *next, *prev; uint32 cidr_ip; /* IP mask for CIDR matching */ uint32 cidr_mask; /* Netmask for CIDR matching */ - char *nick, *user, *host, *mask; + Anope::string nick, user, host, mask; }; struct EList @@ -751,7 +762,7 @@ struct EList struct IgnoreData { IgnoreData *prev, *next; - char *mask; + Anope::string mask; time_t time; /* When do we stop ignoring them? */ }; @@ -771,7 +782,7 @@ enum NewsType struct newsmsgs { NewsType type; - const char *name; + Anope::string name; int msgs[MSG_MAX + 1]; }; @@ -779,8 +790,8 @@ struct NewsItem { NewsType type; uint32 num; - std::string Text; - std::string who; + Anope::string Text; + Anope::string who; time_t time; }; @@ -800,26 +811,22 @@ struct MailInfo struct Exception { - char *mask; /* Hosts to which this exception applies */ - int limit; /* Session limit for exception */ - char *who; /* Nick of person who added the exception */ - char *reason; /* Reason for exception's addition */ - time_t time; /* When this exception was added */ - time_t expires; /* Time when it expires. 0 == no expiry */ - int num; /* Position in exception list; used to track - * positions when deleting entries. It is - * symbolic and used internally. It is - * calculated at load time and never saved. */ + Anope::string mask; /* Hosts to which this exception applies */ + int limit; /* Session limit for exception */ + Anope::string who; /* Nick of person who added the exception */ + Anope::string reason; /* Reason for exception's addition */ + time_t time; /* When this exception was added */ + time_t expires; /* Time when it expires. 0 == no expiry */ }; /*************************************************************************/ -typedef unordered_map_namespace::unordered_map<std::string, Session *, hash_compare_std_string> session_map; +typedef unordered_map_namespace::unordered_map<Anope::string, Session *, hash_compare_std_string> session_map; extern CoreExport session_map SessionList; struct Session { - char *host; + Anope::string host; int count; /* Number of clients with this host */ int hits; /* Number of subsequent kills for a host */ }; @@ -901,24 +908,24 @@ class ServerConfig; class CoreExport IRCDProto { private: - virtual void SendSVSKillInternal(BotInfo *, User *, const char *) = 0; - virtual void SendModeInternal(BotInfo *, Channel *, const char *) = 0; - virtual void SendModeInternal(BotInfo *, User *, const char *) = 0; - virtual void SendKickInternal(BotInfo *, Channel *, User *, const char *) = 0; - virtual void SendNoticeChanopsInternal(BotInfo *bi, Channel *, const char *) = 0; - virtual void SendMessageInternal(BotInfo *bi, const char *dest, const char *buf); - virtual void SendNoticeInternal(BotInfo *bi, const char *dest, const char *msg); - virtual void SendPrivmsgInternal(BotInfo *bi, const char *dest, const char *buf); - virtual void SendQuitInternal(BotInfo *bi, const char *buf); - virtual void SendPartInternal(BotInfo *bi, Channel *chan, const char *buf); - virtual void SendGlobopsInternal(BotInfo *source, const char *buf); - virtual void SendCTCPInternal(BotInfo *bi, const char *dest, const char *buf); - virtual void SendNumericInternal(const char *source, int numeric, const char *dest, const char *buf); + virtual void SendSVSKillInternal(BotInfo *, User *, const Anope::string &) = 0; + virtual void SendModeInternal(BotInfo *, Channel *, const Anope::string &) = 0; + virtual void SendModeInternal(BotInfo *, User *, const Anope::string &) = 0; + virtual void SendKickInternal(BotInfo *, Channel *, User *, const Anope::string &) = 0; + virtual void SendNoticeChanopsInternal(BotInfo *bi, Channel *, const Anope::string &) = 0; + virtual void SendMessageInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &buf); + virtual void SendNoticeInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &msg); + virtual void SendPrivmsgInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &buf); + virtual void SendQuitInternal(BotInfo *bi, const Anope::string &buf); + virtual void SendPartInternal(BotInfo *bi, Channel *chan, const Anope::string &buf); + virtual void SendGlobopsInternal(BotInfo *source, const Anope::string &buf); + virtual void SendCTCPInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &buf); + virtual void SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf); public: virtual ~IRCDProto() { } - virtual void SendSVSNOOP(const char *, int) { } - virtual void SendTopic(BotInfo *, Channel *, const char *, const char *) = 0; + virtual void SendSVSNOOP(const Anope::string &, int) { } + virtual void SendTopic(BotInfo *, Channel *, const Anope::string &, const Anope::string &) = 0; virtual void SendVhostDel(User *) { } virtual void SendAkill(XLine *) = 0; virtual void SendAkillDel(XLine *) = 0; @@ -926,67 +933,67 @@ class CoreExport IRCDProto virtual void SendSVSMode(User *, int, const char **) = 0; virtual void SendMode(BotInfo *bi, Channel *dest, const char *fmt, ...); virtual void SendMode(BotInfo *bi, User *u, const char *fmt, ...); - virtual void SendClientIntroduction(const std::string &, const std::string &, const std::string &, const std::string &, const char *, const std::string &uid) = 0; + virtual void SendClientIntroduction(const Anope::string &, const Anope::string &, const Anope::string &, const Anope::string &, const Anope::string &, const Anope::string &uid) = 0; virtual void SendKick(BotInfo *bi, Channel *chan, User *user, const char *fmt, ...); virtual void SendNoticeChanops(BotInfo *bi, Channel *dest, const char *fmt, ...); - virtual void SendMessage(BotInfo *bi, const char *dest, const char *fmt, ...); - virtual void SendNotice(BotInfo *bi, const char *dest, const char *fmt, ...); - virtual void SendAction(BotInfo *bi, const char *dest, const char *fmt, ...); - virtual void SendPrivmsg(BotInfo *bi, const char *dest, const char *fmt, ...); - virtual void SendGlobalNotice(BotInfo *bi, Server *dest, const char *msg); - virtual void SendGlobalPrivmsg(BotInfo *bi, Server *desc, const char *msg); + virtual void SendMessage(BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendNotice(BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendAction(BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendPrivmsg(BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendGlobalNotice(BotInfo *bi, Server *dest, const Anope::string &msg); + virtual void SendGlobalPrivmsg(BotInfo *bi, Server *desc, const Anope::string &msg); /** XXX: This is a hack for NickServ enforcers. It is deprecated. * If I catch any developer using this in new code, I will RIP YOUR BALLS OFF. * Thanks. * -- w00t */ - virtual void SendQuit(const char *nick, const char *) MARK_DEPRECATED; + virtual void SendQuit(const Anope::string &nick, const Anope::string &) MARK_DEPRECATED; virtual void SendQuit(BotInfo *bi, const char *fmt, ...); - virtual void SendPing(const char *servname, const char *who); - virtual void SendPong(const char *servname, const char *who); - virtual void SendJoin(BotInfo *bi, const char *, time_t) = 0; + virtual void SendPing(const Anope::string &servname, const Anope::string &who); + virtual void SendPong(const Anope::string &servname, const Anope::string &who); + virtual void SendJoin(BotInfo *bi, const Anope::string &, time_t) = 0; virtual void SendSQLineDel(XLine *x) = 0; - virtual void SendInvite(BotInfo *bi, const char *chan, const char *nick); + virtual void SendInvite(BotInfo *bi, const Anope::string &chan, const Anope::string &nick); virtual void SendPart(BotInfo *bi, Channel *chan, const char *fmt, ...); virtual void SendGlobops(BotInfo *source, const char *fmt, ...); virtual void SendSQLine(XLine *x) = 0; - virtual void SendSquit(const char *servname, const char *message); - virtual void SendSVSO(const char *, const char *, const char *) { } - virtual void SendChangeBotNick(BotInfo *bi, const char *newnick); - virtual void SendForceNickChange(User *u, const char *newnick, time_t when); - virtual void SendVhost(User *, const std::string &, const std::string &) { } + virtual void SendSquit(const Anope::string &servname, const Anope::string &message); + virtual void SendSVSO(const Anope::string &, const Anope::string &, const Anope::string &) { } + virtual void SendChangeBotNick(BotInfo *bi, const Anope::string &newnick); + virtual void SendForceNickChange(User *u, const Anope::string &newnick, time_t when); + virtual void SendVhost(User *, const Anope::string &, const Anope::string &) { } virtual void SendConnect() = 0; - virtual void SendSVSHold(const char *) { } - virtual void SendSVSHoldDel(const char *) { } + virtual void SendSVSHold(const Anope::string &) { } + virtual void SendSVSHoldDel(const Anope::string &) { } virtual void SendSGLineDel(XLine *) { } virtual void SendSZLineDel(XLine *) { } virtual void SendSZLine(XLine *) { } virtual void SendSGLine(XLine *) { } - virtual void SendBanDel(Channel *, const std::string &) { } - virtual void SendSVSModeChan(Channel *, const char *, const char *) { } + virtual void SendBanDel(Channel *, const Anope::string &) { } + virtual void SendSVSModeChan(Channel *, const Anope::string &, const Anope::string &) { } virtual void SendUnregisteredNick(User *) { } - virtual void SendCTCP(BotInfo *bi, const char *dest, const char *fmt, ...); - virtual void SendSVSJoin(const char *, const char *, const char *, const char *) { } - virtual void SendSVSPart(const char *, const char *, const char *) { } - virtual void SendSWhois(const char *, const char *, const char *) { } + virtual void SendCTCP(BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendSVSJoin(const Anope::string &, const Anope::string &, const Anope::string &, const Anope::string &) { } + virtual void SendSVSPart(const Anope::string &, const Anope::string &, const Anope::string &) { } + virtual void SendSWhois(const Anope::string &, const Anope::string &, const Anope::string &) { } virtual void SendEOB() { } virtual void SendServer(Server *) = 0; - virtual int IsNickValid(const char *) { return 1; } - virtual int IsChannelValid(const char *); - virtual void SendNumeric(const char *source, int numeric, const char *dest, const char *fmt, ...); + virtual bool IsNickValid(const Anope::string &) { return true; } + virtual bool IsChannelValid(const Anope::string &); + virtual void SendNumeric(const Anope::string &source, int numeric, const Anope::string &dest, const char *fmt, ...); /** Sends a message logging a user into an account, where ircds support such a feature. * @param u The user logging in * @param account The account the user is logging into */ - virtual void SendAccountLogin(User *u, NickCore *account) { } + virtual void SendAccountLogin(User *u, const NickCore *account) { } /** Sends a message logging a user out of an account, where ircds support such a feature. * @param u The user logging out * @param account The account the user is logging out of */ - virtual void SendAccountLogout(User *u, NickCore *account) { } + virtual void SendAccountLogout(User *u, const NickCore *account) { } /** Set a users auto identification token * @param u The user @@ -1002,23 +1009,12 @@ class IRCDTS6Proto : public IRCDProto struct Uplink { - char *host; + Anope::string host; unsigned port; - char *password; + Anope::string password; bool ipv6; - Uplink(const char *_host, int _port, const char *_password, bool _ipv6) - { - host = sstrdup(_host); - port = _port; - password = sstrdup(_password); - ipv6 = _ipv6; - } - ~Uplink() - { - delete [] host; - delete [] password; - } + Uplink(const Anope::string &_host, int _port, const Anope::string &_password, bool _ipv6) : host(_host), port(_port), password(_password), ipv6(_ipv6) { } }; enum LogLevel @@ -1046,46 +1042,6 @@ class CoreExport Alog } }; -struct Message; // XXX - -class CoreExport Anope -{ - private: - static const char * const compiled; - public: - static std::string Version(); - - static std::string Build(); - - /** 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) - * @param case_sensitive Whether or not the match is case sensitive, default false. - */ - static bool Match(const std::string &str, const std::string &mask, bool case_sensitive = false); - inline static bool Match(const ci::string &str, const ci::string &mask) { return Match(str.c_str(), mask.c_str(), false); } - - /** Add a message to Anope - * @param name The message name as sent by the IRCd - * @param func A callback function that will be called when this message is received - * @return The new message object - */ - static Message *AddMessage(const std::string &name, int (*func)(const char *source, int ac, const char **av)); - - /** Deletes a message from Anope - * XXX Im not sure what will happen if this function is called indirectly from message function pointed to by this message.. must check - * @param m The message - * @return true if the message was found and deleted, else false - */ - static bool DelMessage(Message *m); - - /** Returns a list of pointers to message handlers - * @param The message name as sent by the IRCd - * @return a vector with pointers to the messagehandlers (you can bind more than one handler to a message) - */ - static std::vector<Message *> FindMessage(const std::string &name); -}; - /*************************************************************************/ #include "timers.h" @@ -1095,14 +1051,14 @@ class CoreExport Anope class NickServCollide : public Timer { /* The nick */ - std::string nick; + Anope::string nick; public: /** Default constructor * @param _nick The nick were colliding * @param delay How long to delay before kicking the user off the nick */ - NickServCollide(const std::string &_nick, time_t delay); + NickServCollide(const Anope::string &_nick, time_t delay); /** Default destructor */ @@ -1119,18 +1075,18 @@ class NickServCollide : public Timer class NickServRelease : public Timer { /* The nick */ - std::string nick; + Anope::string nick; public: /* The uid of the services enforcer client (used for TS6 ircds) */ - std::string uid; + Anope::string uid; /** Default constructor * @param _nick The nick * @param _uid the uid of the enforcer, if any * @param delay The delay before the nick is released */ - NickServRelease(const std::string &_nick, const std::string &_uid, time_t delay); + NickServRelease(const Anope::string &_nick, const Anope::string &_uid, time_t delay); /** Default destructor */ @@ -1172,7 +1128,7 @@ class ChanServTimer : public Timer class CoreExport NumberList { private: - bool is_valid; + bool is_valid; std::set<unsigned> numbers; @@ -1182,7 +1138,7 @@ class CoreExport NumberList * @param list The list * @param descending True to make HandleNumber get called with numbers in descending order */ - NumberList(const std::string &list, bool descending); + NumberList(const Anope::string &list, bool descending); /** Destructor, does nothing */ @@ -1203,7 +1159,7 @@ class CoreExport NumberList * @param list The list * @return false to stop processing */ - virtual bool InvalidRange(const std::string &list); + virtual bool InvalidRange(const Anope::string &list); }; #endif /* SERVICES_H */ diff --git a/include/sockets.h b/include/sockets.h index 1bcafd79f..c1d102edc 100644 --- a/include/sockets.h +++ b/include/sockets.h @@ -12,6 +12,8 @@ #ifndef SOCKETS_H #define SOCKETS_H +#include "anope.h" + #define NET_BUFSIZE 65535 #ifdef _WIN32 @@ -26,7 +28,7 @@ class SocketException : public CoreException /** Default constructor for socket exceptions * @param message Error message */ - SocketException(const std::string &message) : CoreException(message) { } + SocketException(const Anope::string &message) : CoreException(message) { } /** Default destructor * @throws Nothing @@ -59,12 +61,14 @@ class CoreExport Socket : public Flags<SocketFlag, 1> * @param buf What to write * @return Number of bytes written */ - virtual const int SendInternal(const std::string &buf) const; + virtual const int SendInternal(const Anope::string &buf) const; protected: - /* Socket FD */ - int sock; - /* IPv6? */ + /* Socket FD */ + int Sock; + /* Port we're connected to */ + int Port; + /* Is this an IPv6 socket? */ bool IPv6; /* Things to be written to the socket */ std::string WriteBuffer; @@ -136,24 +140,24 @@ class CoreExport Socket : public Flags<SocketFlag, 1> * @param buf The line * @return true to continue reading, false to drop the socket */ - virtual bool Read(const std::string &buf); + virtual bool Read(const Anope::string &buf); /** Write to the socket * @param message The message */ void Write(const char *message, ...); - void Write(const std::string &message); + void Write(const Anope::string &message); }; class CoreExport ClientSocket : public Socket { protected: /* Target host we're connected to */ - std::string TargetHost; + Anope::string TargetHost; /* Target port we're connected to */ int Port; /* The host to bind to */ - std::string BindHost; + Anope::string BindHost; public: @@ -163,24 +167,24 @@ class CoreExport ClientSocket : public Socket * @param nBindHost The host to bind to for connecting * @param nIPv6 true to use IPv6 */ - ClientSocket(const std::string &nTargetHost, int nPort, const std::string &nBindHost, bool nIPv6); + ClientSocket(const Anope::string &nTargetHost, int nPort, const Anope::string &nBindHost, bool nIPv6); /** Default destructor */ virtual ~ClientSocket(); - /** Called with a line recieved from the socket + /** Called with a line recieved from the socket * @param buf The line * @return true to continue reading, false to drop the socket */ - virtual bool Read(const std::string &buf); + virtual bool Read(const Anope::string &buf); }; class CoreExport ListenSocket : public Socket { protected: /* Bind IP */ - std::string BindIP; + Anope::string BindIP; /* Port to bind to */ int Port; @@ -189,7 +193,7 @@ class CoreExport ListenSocket : public Socket * @param bind The IP to bind to * @param port The port to listen on */ - ListenSocket(const std::string &bind, int port); + ListenSocket(const Anope::string &bind, int port); /** Destructor */ @@ -209,7 +213,7 @@ class CoreExport ListenSocket : public Socket /** Get the bind IP for this socket * @return the bind ip */ - const std::string &GetBindIP() const; + const Anope::string &GetBindIP() const; /** Get the port this socket is bound to * @return The port diff --git a/include/users.h b/include/users.h index 870f4f230..6db093c32 100644 --- a/include/users.h +++ b/include/users.h @@ -11,8 +11,8 @@ /* Hash maps used for users. Note UserListByUID will not be used on non-TS6 IRCds, and should never * be assumed to have users */ -typedef unordered_map_namespace::unordered_map<ci::string, User *, hash_compare_ci_string> user_map; -typedef unordered_map_namespace::unordered_map<std::string, User *, hash_compare_std_string> user_uid_map; +typedef unordered_map_namespace::unordered_map<Anope::string, User *, hash_compare_ci_string> user_map; +typedef unordered_map_namespace::unordered_map<Anope::string, User *, hash_compare_std_string> user_uid_map; extern CoreExport user_map UserListByNick; extern CoreExport user_uid_map UserListByUID; @@ -32,27 +32,27 @@ typedef std::list<ChannelContainer *> UChannelList; class CoreExport User : public Extensible { protected: - std::string vident; - std::string ident; - std::string uid; + 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> modes; /* Bitset of mode names the user has set on them */ - std::map<UserModeName, std::string> Params; /* Map of user modes and the params this user has */ + std::map<UserModeName, Anope::string> Params; /* Map of user modes and the params this user has */ NickCore *nc; /* NickCore account the user is currently loggged in as */ public: // XXX: exposing a tiny bit too much - std::string nick; /* User's current nick */ + Anope::string nick; /* User's current nick */ - char *host; /* User's real hostname */ - char *hostip; /* User's IP number */ - char *vhost; /* User's virtual hostname */ - std::string chost; /* User's cloaked hostname */ - char *realname; /* Realname */ - Server *server; /* Server user is connected to */ - time_t timestamp; /* Timestamp of the nick */ - time_t my_signon; /* When did _we_ see the user? */ + Anope::string host; /* User's real hostname */ + Anope::string hostip; /* User's IP number */ + Anope::string vhost; /* User's virtual hostname */ + Anope::string chost; /* User's cloaked hostname */ + Anope::string realname; /* Realname */ + Server *server; /* Server user is connected to */ + time_t timestamp; /* Timestamp of the nick */ + time_t my_signon; /* When did _we_ see the user? */ - int isSuperAdmin; /* is SuperAdmin on or off? */ + int isSuperAdmin; /* is SuperAdmin on or off? */ /* Channels the user is in */ UChannelList chans; @@ -72,7 +72,7 @@ class CoreExport User : public Extensible * @param nick The nickname of the user. * @param uid The unique identifier of the user. */ - User(const std::string &nick, const std::string &uid); + User(const Anope::string &nick, const Anope::string &uid); /** Destroy a user. */ @@ -81,64 +81,64 @@ class CoreExport User : public Extensible /** Update the nickname of a user record accordingly, should be * called from ircd protocol. */ - virtual void SetNewNick(const std::string &newnick); + virtual void SetNewNick(const Anope::string &newnick); /** Update the displayed (vhost) of a user record. * This is used (if set) instead of real host. * @param host The new displayed host to give the user. */ - void SetDisplayedHost(const std::string &host); + void SetDisplayedHost(const Anope::string &host); /** Get the displayed vhost of a user record. * @return The displayed vhost of the user, where ircd-supported, or the user's real host. */ - const std::string GetDisplayedHost() const; + const Anope::string GetDisplayedHost() const; /** Update the cloaked host of a user * @param host The cloaked host */ - void SetCloakedHost(const std::string &newhost); + void SetCloakedHost(const Anope::string &newhost); /** Get the cloaked host of a user * @return The cloaked host */ - const std::string &GetCloakedHost() const; + const Anope::string &GetCloakedHost() const; /** Retrieves the UID of the user, where applicable, if set. * This is not used on some IRCds, but is for a lot e.g. P10, TS6 protocols. * @return The UID of the user. */ - const std::string &GetUID() const; + const Anope::string &GetUID() const; /** Update the displayed ident (username) of a user record. * @param ident The new ident to give this user. */ - void SetVIdent(const std::string &ident); + void SetVIdent(const Anope::string &ident); /** Get the displayed ident (username) of this user. * @return The displayed ident of this user. */ - const std::string &GetVIdent() const; + const Anope::string &GetVIdent() const; /** Update the real ident (username) of a user record. * @param ident The new ident to give this user. * NOTE: Where possible, you should use the Get/SetVIdent() equivilants. */ - void SetIdent(const std::string &ident); + void SetIdent(const Anope::string &ident); /** Get the real ident (username) of this user. * @return The displayed ident of this user. * NOTE: Where possible, you should use the Get/SetVIdent() equivilants. */ - const std::string &GetIdent() const; + const Anope::string &GetIdent() const; /** Get the full mask ( nick!ident@realhost ) of a user */ - const std::string GetMask(); + const Anope::string GetMask(); /** Updates the realname of the user record. */ - void SetRealname(const std::string &realname); + void SetRealname(const Anope::string &realname); /** * Send a message (notice or privmsg, depending on settings) to a user @@ -146,8 +146,8 @@ class CoreExport User : public Extensible * @param fmt Format of the Message * @param ... any number of parameters */ - virtual void SendMessage(const std::string &source, const char *fmt, ...); - virtual void SendMessage(const std::string &source, const std::string &msg); + virtual void SendMessage(const Anope::string &source, const char *fmt, ...); + virtual void SendMessage(const Anope::string &source, const Anope::string &msg); /** Collide a nick * See the comment in users.cpp @@ -159,12 +159,12 @@ class CoreExport User : public Extensible * their svid matches the one stored in their nickcore * @param svid Services id */ - void CheckAuthenticationToken(const char *svid); + void CheckAuthenticationToken(const Anope::string &svid); /** Auto identify the user to the given accountname. * @param account Display nick of account */ - void AutoID(const std::string &account); + void AutoID(const Anope::string &account); /** Login the user to a NickCore * @param core The account the user is useing @@ -178,19 +178,19 @@ class CoreExport User : public Extensible /** Get the account the user is logged in using * @reurn The account or NULL */ - virtual NickCore *Account() const; + virtual NickCore *Account(); /** 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 * @return true or false */ - virtual const bool IsIdentified(bool CheckNick = false) const; + virtual bool IsIdentified(bool CheckNick = 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 * @return true or false */ - virtual const bool IsRecognized(bool CheckSecure = false) const; + virtual bool IsRecognized(bool CheckSecure = false) const; /** Update the last usermask stored for a user, and check to see if they are recognized */ @@ -200,13 +200,13 @@ class CoreExport User : public Extensible * @param Name Mode name * @return true or false */ - const bool HasMode(UserModeName Name) const; + bool HasMode(UserModeName Name) const; /** Set a mode internally on the user, the IRCd is not informed * @param um The user mode * @param Param The param, if there is one */ - void SetModeInternal(UserMode *um, const std::string &Param = ""); + void SetModeInternal(UserMode *um, const Anope::string &Param = ""); /** Remove a mode internally on the user, the IRCd is not informed * @param um The user mode @@ -218,21 +218,21 @@ class CoreExport User : public Extensible * @param um The user mode * @param Param Optional param for the mode */ - void SetMode(BotInfo *bi, UserMode *um, const std::string &Param = ""); + void SetMode(BotInfo *bi, UserMode *um, const Anope::string &Param = ""); /** Set a mode on the user * @param bi The client setting the mode * @param Name The mode name * @param Param Optional param for the mode */ - void SetMode(BotInfo *bi, UserModeName Name, const std::string &Param = ""); + void SetMode(BotInfo *bi, UserModeName Name, const Anope::string &Param = ""); /* Set a mode on the user * @param bi The client setting the mode * @param ModeChar The mode char * @param param Optional param for the mode */ - void SetMode(BotInfo *bi, char ModeChar, const std::string &Param = ""); + void SetMode(BotInfo *bi, char ModeChar, const Anope::string &Param = ""); /** Remove a mode on the user * @param bi The client setting the mode diff --git a/modules/core/bs_act.cpp b/modules/core/bs_act.cpp index aa054d11b..ecfe76e94 100644 --- a/modules/core/bs_act.cpp +++ b/modules/core/bs_act.cpp @@ -20,10 +20,10 @@ class CommandBSAct : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - ci::string message = params[1]; + Anope::string message = params[1]; if (!check_access(u, ci, CA_SAY)) { @@ -44,22 +44,22 @@ class CommandBSAct : public Command } size_t i = 0; - while ((i = message.find_first_of("\001"), i) && i != std::string::npos) + while ((i = message.find(1)) && i != Anope::string::npos) message.erase(i, 1); - ircdproto->SendAction(ci->bi, ci->name.c_str(), "%s", message.c_str()); + ircdproto->SendAction(ci->bi, ci->name, "%s", message.c_str()); ci->bi->lastmsg = time(NULL); - if (Config.LogBot && Config.LogChannel && LogChan && !debug && findchan(Config.LogChannel)) + if (Config.LogBot && !Config.LogChannel.empty() && LogChan && !debug && findchan(Config.LogChannel)) ircdproto->SendPrivmsg(ci->bi, Config.LogChannel, "ACT %s %s %s", u->nick.c_str(), ci->name.c_str(), message.c_str()); return MOD_CONT; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "ACT", BOT_ACT_SYNTAX); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_ACT); return true; @@ -74,10 +74,11 @@ class CommandBSAct : public Command class BSAct : public Module { public: - BSAct(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSAct(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSAct()); } }; diff --git a/modules/core/bs_assign.cpp b/modules/core/bs_assign.cpp index 0695a7e6d..22f5f4487 100644 --- a/modules/core/bs_assign.cpp +++ b/modules/core/bs_assign.cpp @@ -20,10 +20,10 @@ class CommandBSAssign : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - const char *nick = params[1].c_str(); + Anope::string chan = params[0]; + Anope::string nick = params[1]; BotInfo *bi; ChannelInfo *ci; @@ -35,7 +35,7 @@ class CommandBSAssign : public Command if (!(bi = findbot(nick))) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, nick); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, nick.c_str()); return MOD_CONT; } @@ -53,9 +53,9 @@ class CommandBSAssign : public Command return MOD_CONT; } - if (ci->bi && ci::string(ci->bi->nick.c_str()) == nick) + if (ci->bi && nick.equals_ci(ci->bi->nick)) { - notice_lang(Config.s_BotServ, u, BOT_ASSIGN_ALREADY, ci->bi->nick.c_str(), chan); + notice_lang(Config.s_BotServ, u, BOT_ASSIGN_ALREADY, ci->bi->nick.c_str(), chan.c_str()); return MOD_CONT; } @@ -64,13 +64,13 @@ class CommandBSAssign : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_ASSIGN); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "ASSIGN", BOT_ASSIGN_SYNTAX); } @@ -84,10 +84,11 @@ class CommandBSAssign : public Command class BSAssign : public Module { public: - BSAssign(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSAssign); } }; diff --git a/modules/core/bs_badwords.cpp b/modules/core/bs_badwords.cpp index 822847a6a..e7dacb42b 100644 --- a/modules/core/bs_badwords.cpp +++ b/modules/core/bs_badwords.cpp @@ -19,7 +19,7 @@ class BadwordsListCallback : public NumberList ChannelInfo *ci; bool SentHeader; public: - BadwordsListCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list, false), u(_u), ci(_ci), SentHeader(false) + BadwordsListCallback(User *_u, ChannelInfo *_ci, const Anope::string &list) : NumberList(list, false), u(_u), ci(_ci), SentHeader(false) { } @@ -45,7 +45,7 @@ class BadwordsListCallback : public NumberList static void DoList(User *u, ChannelInfo *ci, unsigned Number, BadWord *bw) { - notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_FORMAT, Number + 1, bw->word.c_str(), ((bw->type == BW_SINGLE) ? "(SINGLE)" : ((bw->type == BW_START) ? "(START)" : ((bw->type == BW_END) ? "(END)" : "")))); + notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_FORMAT, Number + 1, bw->word.c_str(), bw->type == BW_SINGLE ? "(SINGLE)" : (bw->type == BW_START ? "(START)" : (bw->type == BW_END ? "(END)" : ""))); } }; @@ -55,7 +55,7 @@ class BadwordsDelCallback : public NumberList ChannelInfo *ci; unsigned Deleted; public: - BadwordsDelCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list, true), u(_u), ci(_ci), Deleted(0) + BadwordsDelCallback(User *_u, ChannelInfo *_ci, const Anope::string &list) : NumberList(list, true), u(_u), ci(_ci), Deleted(0) { } @@ -82,13 +82,13 @@ class BadwordsDelCallback : public NumberList class CommandBSBadwords : public Command { private: - CommandReturn DoList(User *u, ChannelInfo *ci, const ci::string &word) + CommandReturn DoList(User *u, ChannelInfo *ci, const Anope::string &word) { if (!ci->GetBadWordCount()) notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_EMPTY, ci->name.c_str()); - else if (!word.empty() && strspn(word.c_str(), "1234567890,-") == word.length()) + else if (!word.empty() && word.find_first_not_of("1234567890,-") == Anope::string::npos) { - BadwordsListCallback list(u, ci, word.c_str()); + BadwordsListCallback list(u, ci, word); list.Process(); } else @@ -99,7 +99,7 @@ class CommandBSBadwords : public Command { BadWord *bw = ci->GetBadWord(i); - if (!word.empty() && !Anope::Match(bw->word, word.c_str(), false)) + if (!word.empty() && !Anope::Match(bw->word, word)) continue; if (!SentHeader) @@ -118,25 +118,25 @@ class CommandBSBadwords : public Command return MOD_CONT; } - CommandReturn DoAdd(User *u, ChannelInfo *ci, const ci::string &word) + CommandReturn DoAdd(User *u, ChannelInfo *ci, const Anope::string &word) { - size_t pos = word.find_last_of(" "); + size_t pos = word.rfind(' '); BadWordType type = BW_ANY; - ci::string realword = word; + Anope::string realword = word; - if (pos != ci::string::npos) + if (pos != Anope::string::npos) { - ci::string opt = ci::string(word, pos + 1); + Anope::string opt = word.substr(pos + 1); if (!opt.empty()) { - if (opt == "SINGLE") + if (opt.equals_ci("SINGLE")) type = BW_SINGLE; - else if (opt == "START") + else if (opt.equals_ci("START")) type = BW_START; - else if (opt == "END") + else if (opt.equals_ci("END")) type = BW_END; } - realword = ci::string(word, 0, pos); + realword = word.substr(0, pos); } if (ci->GetBadWordCount() >= Config.BSBadWordsMax) @@ -149,26 +149,26 @@ class CommandBSBadwords : public Command { BadWord *bw = ci->GetBadWord(i); - if (!bw->word.empty() && ((Config.BSCaseSensitive && !stricmp(bw->word.c_str(), realword.c_str())) || (!Config.BSCaseSensitive && bw->word == realword.c_str()))) + if (!bw->word.empty() && ((Config.BSCaseSensitive && realword.equals_cs(bw->word)) || (!Config.BSCaseSensitive && realword.equals_ci(bw->word)))) { notice_lang(Config.s_BotServ, u, BOT_BADWORDS_ALREADY_EXISTS, bw->word.c_str(), ci->name.c_str()); return MOD_CONT; } } - ci->AddBadWord(realword.c_str(), type); + ci->AddBadWord(realword, type); notice_lang(Config.s_BotServ, u, BOT_BADWORDS_ADDED, realword.c_str(), ci->name.c_str()); return MOD_CONT; } - CommandReturn DoDelete(User *u, ChannelInfo *ci, const ci::string &word) + CommandReturn DoDelete(User *u, ChannelInfo *ci, const Anope::string &word) { /* Special case: is it a number/list? Only do search if it isn't. */ - if (!word.empty() && isdigit(word[0]) && strspn(word.c_str(), "1234567890,-") == word.length()) + if (!word.empty() && isdigit(word[0]) && word.find_first_not_of("1234567890,-") == Anope::string::npos) { - BadwordsDelCallback list(u, ci, word.c_str()); + BadwordsDelCallback list(u, ci, word); list.Process(); } else @@ -180,7 +180,7 @@ class CommandBSBadwords : public Command { badword = ci->GetBadWord(i); - if (badword->word == word) + if (word.equals_ci(badword->word)) break; } @@ -209,13 +209,13 @@ class CommandBSBadwords : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - ci::string cmd = params[1]; - ci::string word = params.size() > 2 ? params[2].c_str() : ""; + Anope::string chan = params[0]; + Anope::string cmd = params[1]; + Anope::string word = params.size() > 2 ? params[2] : ""; ChannelInfo *ci; - bool need_args = cmd == "LIST" || cmd == "CLEAR"; + bool need_args = cmd.equals_ci("LIST") || cmd.equals_ci("CLEAR"); if (!need_args && word.empty()) { @@ -237,13 +237,13 @@ class CommandBSBadwords : public Command return MOD_CONT; } - if (cmd == "ADD") + if (cmd.equals_ci("ADD")) return this->DoAdd(u, ci, word); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) return this->DoDelete(u, ci, word); - else if (cmd == "LIST") + else if (cmd.equals_ci("LIST")) return this->DoList(u, ci, word); - else if (cmd == "CLEAR") + else if (cmd.equals_ci("CLEAR")) return this->DoClear(u, ci); else this->OnSyntaxError(u, ""); @@ -251,13 +251,13 @@ class CommandBSBadwords : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_BADWORDS); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "BADWORDS", BOT_BADWORDS_SYNTAX); } @@ -271,10 +271,11 @@ class CommandBSBadwords : public Command class BSBadwords : public Module { public: - BSBadwords(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSBadwords(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSBadwords); } }; diff --git a/modules/core/bs_bot.cpp b/modules/core/bs_bot.cpp index 3af9fa685..3c5136bd5 100644 --- a/modules/core/bs_bot.cpp +++ b/modules/core/bs_bot.cpp @@ -16,34 +16,33 @@ class CommandBSBot : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[1].c_str(); - const char *user = params[2].c_str(); - const char *host = params[3].c_str(); - const char *real = params[4].c_str(); - const char *ch = NULL; + Anope::string nick = params[1]; + Anope::string user = params[2]; + Anope::string host = params[3]; + Anope::string real = params[4]; BotInfo *bi; if (findbot(nick)) { - notice_lang(Config.s_BotServ, u, BOT_BOT_ALREADY_EXISTS, nick); + notice_lang(Config.s_BotServ, u, BOT_BOT_ALREADY_EXISTS, nick.c_str()); return MOD_CONT; } - if (strlen(nick) > Config.NickLen) + if (nick.length() > Config.NickLen) { notice_lang(Config.s_BotServ, u, BOT_BAD_NICK); return MOD_CONT; } - if (strlen(user) > Config.UserLen) + if (user.length() > Config.UserLen) { notice_lang(Config.s_BotServ, u, BOT_LONG_IDENT, Config.UserLen); return MOD_CONT; } - if (strlen(user) > Config.HostLen) + if (host.length() > Config.HostLen) { notice_lang(Config.s_BotServ, u, BOT_LONG_HOST, Config.HostLen); return MOD_CONT; @@ -56,8 +55,8 @@ class CommandBSBot : public Command return MOD_CONT; } - for (ch = nick; *ch && ch - nick < Config.NickLen; ++ch) - if (!isvalidnick(*ch)) + for (unsigned i = 0, end = nick.length(); i < end && i < Config.NickLen; ++i) + if (!isvalidnick(nick[i])) { notice_lang(Config.s_BotServ, u, BOT_BAD_NICK); return MOD_CONT; @@ -77,8 +76,8 @@ class CommandBSBot : public Command return MOD_CONT; } - for (ch = user; *ch && ch - user < Config.UserLen; ++ch) - if (!isalnum(*ch)) + for (unsigned i = 0, end = user.length(); i < end && i < Config.UserLen; ++i) + if (!isalnum(user[i])) { notice_lang(Config.s_BotServ, u, BOT_BAD_IDENT, Config.UserLen); return MOD_CONT; @@ -90,7 +89,7 @@ class CommandBSBot : public Command */ if (findnick(nick)) { - notice_lang(Config.s_BotServ, u, NICK_ALREADY_REGISTERED, nick); + notice_lang(Config.s_BotServ, u, NICK_ALREADY_REGISTERED, nick.c_str()); return MOD_CONT; } @@ -100,23 +99,22 @@ class CommandBSBot : public Command return MOD_CONT; } - notice_lang(Config.s_BotServ, u, BOT_BOT_ADDED, bi->nick.c_str(), bi->GetIdent().c_str(), bi->host, bi->realname); + notice_lang(Config.s_BotServ, u, BOT_BOT_ADDED, bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); FOREACH_MOD(I_OnBotCreate, OnBotCreate(bi)); return MOD_CONT; } - CommandReturn DoChange(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoChange(User *u, const std::vector<Anope::string> ¶ms) { - const char *oldnick = params[1].c_str(); - const char *nick = params.size() > 2 ? params[2].c_str() : NULL; - const char *user = params.size() > 3 ? params[3].c_str() : NULL; - const char *host = params.size() > 4 ? params[4].c_str() : NULL; - const char *real = params.size() > 5 ? params[5].c_str() : NULL; - const char *ch = NULL; + Anope::string oldnick = params[1]; + Anope::string nick = params.size() > 2 ? params[2] : ""; + Anope::string user = params.size() > 3 ? params[3] : ""; + Anope::string host = params.size() > 4 ? params[4] : ""; + Anope::string real = params.size() > 5 ? params[5] : ""; BotInfo *bi; - if (!oldnick || !nick) + if (oldnick.empty() || nick.empty()) { this->OnSyntaxError(u, "CHANGE"); return MOD_CONT; @@ -124,37 +122,37 @@ class CommandBSBot : public Command if (!(bi = findbot(oldnick))) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick.c_str()); return MOD_CONT; } - if (stricmp(oldnick, nick) && nickIsServices(oldnick, 0)) + if (!oldnick.equals_ci(nick) && nickIsServices(oldnick, 0)) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick.c_str()); return MOD_CONT; } - if (strlen(nick) > Config.NickLen) + if (nick.length() > Config.NickLen) { notice_lang(Config.s_BotServ, u, BOT_BAD_NICK); return MOD_CONT; } - if (user && strlen(user) > Config.UserLen) + if (!user.empty() && user.length() > Config.UserLen) { notice_lang(Config.s_BotServ, u, BOT_LONG_IDENT, Config.UserLen); return MOD_CONT; } - if (host && strlen(host) > Config.HostLen) + if (!host.empty() && host.length() > Config.HostLen) { notice_lang(Config.s_BotServ, u, BOT_LONG_HOST, Config.HostLen); return MOD_CONT; } - if (stricmp(oldnick, nick) && nickIsServices(nick, 0)) + if (!oldnick.equals_ci(nick) && nickIsServices(nick, 0)) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick.c_str()); return MOD_CONT; } @@ -163,7 +161,7 @@ class CommandBSBot : public Command * And we must finally check that the nick is not already * taken by another bot. */ - if (bi->nick == nick && (user ? bi->GetIdent() == user : 1) && (host ? !strcmp(bi->host, host) : 1) && (real ? !strcmp(bi->realname, real) : 1)) + if (nick.equals_cs(bi->nick) && (!user.empty() ? user.equals_cs(bi->GetIdent()) : 1) && (!host.empty() ? host.equals_cs(bi->host) : 1) && (!real.empty() ? real.equals_cs(bi->realname) : 1)) { notice_lang(Config.s_BotServ, u, BOT_BOT_ANY_CHANGES); return MOD_CONT; @@ -176,8 +174,8 @@ class CommandBSBot : public Command return MOD_CONT; } - for (ch = nick; *ch && ch - nick < Config.NickLen; ++ch) - if (!isvalidnick(*ch)) + for (unsigned i = 0, end = nick.length(); i < end && i < Config.NickLen; ++i) + if (!isvalidnick(nick[i])) { notice_lang(Config.s_BotServ, u, BOT_BAD_NICK); return MOD_CONT; @@ -190,28 +188,27 @@ class CommandBSBot : public Command return MOD_CONT; } - if (host && !isValidHost(host, 3)) + if (!host.empty() && !isValidHost(host, 3)) { notice_lang(Config.s_BotServ, u, BOT_BAD_HOST); return MOD_CONT; } - if (user) - for (ch = user; *ch && ch - user < Config.UserLen; ++ch) - if (!isalnum(*ch)) + if (!user.empty()) + for (unsigned i = 0, end = user.length(); i < end && i < Config.UserLen; ++i) + if (!isalnum(user[i])) { notice_lang(Config.s_BotServ, u, BOT_BAD_IDENT, Config.UserLen); return MOD_CONT; } - ci::string ci_bi_nick(bi->nick.c_str()); - if (ci_bi_nick != nick && findbot(nick)) + if (!nick.equals_ci(bi->nick) && findbot(nick)) { - notice_lang(Config.s_BotServ, u, BOT_BOT_ALREADY_EXISTS, nick); + notice_lang(Config.s_BotServ, u, BOT_BOT_ALREADY_EXISTS, nick.c_str()); return MOD_CONT; } - if (ci_bi_nick != nick) + if (!nick.equals_ci(bi->nick)) { /* We check whether the nick is registered, and inform the user * if so. You need to drop the nick manually before you can use @@ -219,7 +216,7 @@ class CommandBSBot : public Command */ if (findnick(nick)) { - notice_lang(Config.s_BotServ, u, NICK_ALREADY_REGISTERED, nick); + notice_lang(Config.s_BotServ, u, NICK_ALREADY_REGISTERED, nick.c_str()); return MOD_CONT; } @@ -227,7 +224,7 @@ class CommandBSBot : public Command the old nick. */ if (ircd->sqline) { - XLine x(bi->nick.c_str()); + XLine x(bi->nick); ircdproto->SendSQLineDel(&x); } @@ -235,45 +232,45 @@ class CommandBSBot : public Command EnforceQlinedNick(nick, Config.s_BotServ); } - if (user) + if (!user.empty()) ircdproto->SendQuit(bi, "Quit: Be right back"); else { ircdproto->SendChangeBotNick(bi, nick); - XLine x(bi->nick.c_str(), "Reserved for services"); + XLine x(bi->nick, "Reserved for services"); ircdproto->SendSQLine(&x); } - if (bi->nick != nick) + if (!nick.equals_cs(bi->nick)) bi->SetNewNick(nick); - if (user && bi->GetIdent() != user) + if (!user.empty() && !user.equals_cs(bi->GetIdent())) bi->SetIdent(user); - if (host && strcmp(bi->host, host)) - bi->host = sstrdup(host); - if (real && strcmp(bi->realname, real)) - bi->realname = sstrdup(real); + if (!host.empty() && !host.equals_cs(bi->host)) + bi->host = host; + if (!real.empty() && !real.equals_cs(bi->realname)) + bi->realname = real; - if (user) + if (!user.empty()) { ircdproto->SendClientIntroduction(bi->nick, bi->GetIdent(), bi->host, bi->realname, ircd->pseudoclient_mode, bi->GetUID()); - XLine x(bi->nick.c_str(), "Reserved for services"); + XLine x(bi->nick, "Reserved for services"); ircdproto->SendSQLine(&x); bi->RejoinAll(); } - notice_lang(Config.s_BotServ, u, BOT_BOT_CHANGED, oldnick, bi->nick.c_str(), bi->GetIdent().c_str(), bi->host, bi->realname); + notice_lang(Config.s_BotServ, u, BOT_BOT_CHANGED, oldnick.c_str(), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); FOREACH_MOD(I_OnBotChange, OnBotChange(bi)); return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[1].c_str(); + Anope::string nick = params[1]; BotInfo *bi; - if (!nick) + if (nick.empty()) { this->OnSyntaxError(u, "DEL"); return MOD_CONT; @@ -281,24 +278,24 @@ class CommandBSBot : public Command if (!(bi = findbot(nick))) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, nick); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, nick.c_str()); return MOD_CONT; } if (nickIsServices(nick, 0)) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, nick); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, nick.c_str()); return MOD_CONT; } FOREACH_MOD(I_OnBotDelete, OnBotDelete(bi)); ircdproto->SendQuit(bi, "Quit: Help! I'm being deleted by %s!", u->nick.c_str()); - XLine x(bi->nick.c_str()); + XLine x(bi->nick); ircdproto->SendSQLineDel(&x); delete bi; - notice_lang(Config.s_BotServ, u, BOT_BOT_DELETED, nick); + notice_lang(Config.s_BotServ, u, BOT_BOT_DELETED, nick.c_str()); return MOD_CONT; } public: @@ -307,9 +304,9 @@ class CommandBSBot : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; + Anope::string cmd = params[0]; if (readonly) { @@ -317,7 +314,7 @@ class CommandBSBot : public Command return MOD_CONT; } - if (cmd == "ADD") + if (cmd.equals_ci("ADD")) { // ADD nick user host real - 5 if (!u->Account()->HasCommand("botserv/bot/add")) @@ -332,14 +329,14 @@ class CommandBSBot : public Command return MOD_CONT; } - std::vector<ci::string> tempparams = params; + std::vector<Anope::string> tempparams = params; // ADD takes less params than CHANGE, so we need to take 6 if given and append it with a space to 5. if (tempparams.size() >= 6) tempparams[4] = tempparams[4] + " " + tempparams[5]; return this->DoAdd(u, tempparams); } - else if (cmd == "CHANGE") + else if (cmd.equals_ci("CHANGE")) { // CHANGE oldn newn user host real - 6 // but only oldn and newn are required @@ -357,7 +354,7 @@ class CommandBSBot : public Command return this->DoChange(u, params); } - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) { // DEL nick if (!u->Account()->HasCommand("botserv/bot/del")) @@ -380,13 +377,13 @@ class CommandBSBot : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_lang(Config.s_BotServ, u, BOT_SERVADMIN_HELP_BOT); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "BOT", BOT_BOT_SYNTAX); } @@ -400,10 +397,11 @@ class CommandBSBot : public Command class BSBot : public Module { public: - BSBot(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSBot(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSBot()); } }; diff --git a/modules/core/bs_botlist.cpp b/modules/core/bs_botlist.cpp index 44848b5cb..a54b50154 100644 --- a/modules/core/bs_botlist.cpp +++ b/modules/core/bs_botlist.cpp @@ -20,7 +20,7 @@ class CommandBSBotList : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { unsigned count = 0; @@ -39,7 +39,7 @@ class CommandBSBotList : public Command if (!count) notice_lang(Config.s_BotServ, u, BOT_BOTLIST_HEADER); ++count; - u->SendMessage(Config.s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host); + u->SendMessage(Config.s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str()); } } @@ -53,7 +53,7 @@ class CommandBSBotList : public Command if (bi->HasFlag(BI_PRIVATE)) { - u->SendMessage(Config.s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host); + u->SendMessage(Config.s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str()); ++count; } } @@ -67,7 +67,7 @@ class CommandBSBotList : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_BOTLIST); return true; @@ -82,10 +82,11 @@ class CommandBSBotList : public Command class BSBotList : public Module { public: - BSBotList(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSBotList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSBotList()); } }; diff --git a/modules/core/bs_help.cpp b/modules/core/bs_help.cpp index 7183c6fe9..08146f827 100644 --- a/modules/core/bs_help.cpp +++ b/modules/core/bs_help.cpp @@ -22,13 +22,13 @@ class CommandBSHelp : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - mod_help_cmd(findbot(Config.s_BotServ), u, params[0].c_str()); + mod_help_cmd(findbot(Config.s_BotServ), u, params[0]); return MOD_CONT; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { // Abuse syntax error to display general list help. notice_help(Config.s_BotServ, u, BOT_HELP); @@ -42,10 +42,11 @@ class CommandBSHelp : public Command class BSHelp : public Module { public: - BSHelp(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSHelp(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSHelp()); } }; diff --git a/modules/core/bs_info.cpp b/modules/core/bs_info.cpp index 7d8e6aea7..65147d859 100644 --- a/modules/core/bs_info.cpp +++ b/modules/core/bs_info.cpp @@ -17,31 +17,26 @@ class CommandBSInfo : public Command { private: - void send_bot_channels(User * u, BotInfo * bi) + void send_bot_channels(User *u, BotInfo *bi) { - char buf[307], *end; - - *buf = 0; - end = buf; - + Anope::string buf; for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) { ChannelInfo *ci = it->second; if (ci->bi == bi) { - if (strlen(buf) + strlen(ci->name.c_str()) > 300) + if (buf.length() + ci->name.length() > 300) { - u->SendMessage(Config.s_BotServ, "%s", buf); - *buf = 0; - end = buf; + u->SendMessage(Config.s_BotServ, "%s", buf.c_str()); + buf.clear(); } - end += snprintf(end, sizeof(buf) - (end - buf), " %s ", ci->name.c_str()); + buf += " " + ci->name + " "; } } - if (*buf) - u->SendMessage(Config.s_BotServ, "%s", buf); + if (!buf.empty()) + u->SendMessage(Config.s_BotServ, "%s", buf.c_str()); return; } public: @@ -50,11 +45,11 @@ class CommandBSInfo : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { BotInfo *bi; ChannelInfo *ci; - const char *query = params[0].c_str(); + Anope::string query = params[0]; int need_comma = 0; char buf[BUFSIZE], *end; @@ -65,8 +60,8 @@ class CommandBSInfo : public Command struct tm *tm; notice_lang(Config.s_BotServ, u, BOT_INFO_BOT_HEADER, bi->nick.c_str()); - notice_lang(Config.s_BotServ, u, BOT_INFO_BOT_MASK, bi->GetIdent().c_str(), bi->host); - notice_lang(Config.s_BotServ, u, BOT_INFO_BOT_REALNAME, bi->realname); + notice_lang(Config.s_BotServ, u, BOT_INFO_BOT_MASK, bi->GetIdent().c_str(), bi->host.c_str()); + notice_lang(Config.s_BotServ, u, BOT_INFO_BOT_REALNAME, bi->realname.c_str()); tm = localtime(&bi->created); strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); notice_lang(Config.s_BotServ, u, BOT_INFO_BOT_CREATED, buf); @@ -198,17 +193,17 @@ class CommandBSInfo : public Command notice_lang(Config.s_BotServ, u, BOT_INFO_CHAN_OPTIONS, *buf ? buf : getstring(u, BOT_INFO_OPT_NONE)); } else - notice_lang(Config.s_BotServ, u, BOT_INFO_NOT_FOUND, query); + notice_lang(Config.s_BotServ, u, BOT_INFO_NOT_FOUND, query.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_INFO); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "INFO", BOT_INFO_SYNTAX); } @@ -222,10 +217,11 @@ class CommandBSInfo : public Command class BSInfo : public Module { public: - BSInfo(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSInfo()); } }; diff --git a/modules/core/bs_kick.cpp b/modules/core/bs_kick.cpp index 2f2784d93..4936f0112 100644 --- a/modules/core/bs_kick.cpp +++ b/modules/core/bs_kick.cpp @@ -21,20 +21,20 @@ class CommandBSKick : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - ci::string option = params[1]; - ci::string value = params[2]; - const char *ttb = params.size() > 3 ? params[3].c_str() : NULL; + Anope::string chan = params[0]; + Anope::string option = params[1]; + Anope::string value = params[2]; + Anope::string ttb = params.size() > 3 ? params[3] : ""; ChannelInfo *ci = cs_findchan(chan); if (readonly) notice_lang(Config.s_BotServ, u, BOT_KICK_DISABLED); - else if (!chan || option.empty() || value.empty()) + else if (chan.empty() || option.empty() || value.empty()) syntax_error(Config.s_BotServ, u, "KICK", BOT_KICK_SYNTAX); - else if (value != "ON" && value != "OFF") + else if (!value.equals_ci("ON") && !value.equals_ci("OFF")) syntax_error(Config.s_BotServ, u, "KICK", BOT_KICK_SYNTAX); else if (!check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration")) notice_lang(Config.s_BotServ, u, ACCESS_DENIED); @@ -42,22 +42,22 @@ class CommandBSKick : public Command notice_help(Config.s_BotServ, u, BOT_NOT_ASSIGNED); else { - if (option == "BADWORDS") + if (option.equals_ci("BADWORDS")) { - if (value == "ON") + if (value.equals_ci("ON")) { - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_BADWORDS] = strtol(ttb, NULL, 10); + Anope::string error; + ci->ttb[TTB_BADWORDS] = convertTo<int16>(ttb, error, false); /* Only error if errno returns ERANGE or EINVAL or we are less then 0 - TSL */ - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_BADWORDS] < 0) + if (!error.empty() || ci->ttb[TTB_BADWORDS] < 0) { /* leaving the debug behind since we might want to know what these are */ - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_BADWORDS]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_BADWORDS]; /* reset the value back to 0 - TSL */ ci->ttb[TTB_BADWORDS] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -75,19 +75,19 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_BADWORDS_OFF); } } - else if (option == "BOLDS") + else if (option.equals_ci("BOLDS")) { - if (value == "ON") + if (value.equals_ci("ON")) { - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_BOLDS] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_BOLDS] < 0) + Anope::string error; + ci->ttb[TTB_BOLDS] = convertTo<int16>(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_BOLDS] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_BOLDS]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_BOLDS]; ci->ttb[TTB_BOLDS] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -105,39 +105,39 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_BOLDS_OFF); } } - else if (option == "CAPS") + else if (option.equals_ci("CAPS")) { - if (value == "ON") + if (value.equals_ci("ON")) { - const char *min = params.size() > 4 ? params[4].c_str() : NULL; - const char *percent = params.size() > 5 ? params[5].c_str() : NULL; + Anope::string min = params.size() > 4 ? params[4] : ""; + Anope::string percent = params.size() > 5 ? params[5] : ""; - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_CAPS] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_CAPS] < 0) + Anope::string error; + ci->ttb[TTB_CAPS] = convertTo<int16>(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_CAPS] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_CAPS]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_CAPS]; ci->ttb[TTB_CAPS] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } else ci->ttb[TTB_CAPS] = 0; - if (!min) + if (min.empty()) ci->capsmin = 10; else - ci->capsmin = atol(min); + ci->capsmin = min.is_number_only() ? convertTo<int16>(min) : 10; if (ci->capsmin < 1) ci->capsmin = 10; - if (!percent) + if (percent.empty()) ci->capspercent = 25; else - ci->capspercent = atol(percent); + ci->capspercent = percent.is_number_only() ? convertTo<int16>(percent) : 25; if (ci->capspercent < 1 || ci->capspercent > 100) ci->capspercent = 25; @@ -153,19 +153,19 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_CAPS_OFF); } } - else if (option == "COLORS") + else if (option.equals_ci("COLORS")) { - if (value == "ON") + if (value.equals_ci("ON")) { - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_COLORS] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_COLORS] < 0) + Anope::string error; + ci->ttb[TTB_COLORS] = convertTo<int16>(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_COLORS] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_COLORS]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_COLORS]; ci->ttb[TTB_COLORS] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -183,39 +183,39 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_COLORS_OFF); } } - else if (option == "FLOOD") + else if (option.equals_ci("FLOOD")) { - if (value == "ON") + if (value.equals_ci("ON")) { - const char *lines = params.size() > 4 ? params[4].c_str() : NULL; - const char *secs = params.size() > 5 ? params[5].c_str() : NULL; + Anope::string lines = params.size() > 4 ? params[4] : ""; + Anope::string secs = params.size() > 5 ? params[5] : ""; - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_FLOOD] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_FLOOD] < 0) + Anope::string error; + ci->ttb[TTB_FLOOD] = convertTo<int16>(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_FLOOD] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_FLOOD]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_FLOOD]; ci->ttb[TTB_FLOOD] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } else ci->ttb[TTB_FLOOD] = 0; - if (!lines) + if (lines.empty()) ci->floodlines = 6; else - ci->floodlines = atol(lines); + ci->floodlines = lines.is_number_only() ? convertTo<int16>(lines) : 6; if (ci->floodlines < 2) ci->floodlines = 6; - if (!secs) + if (secs.empty()) ci->floodsecs = 10; else - ci->floodsecs = atol(secs); + ci->floodsecs = secs.is_number_only() ? convertTo<int16>(secs) : 10; if (ci->floodsecs < 1 || ci->floodsecs > Config.BSKeepData) ci->floodsecs = 10; @@ -231,31 +231,31 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_FLOOD_OFF); } } - else if (option == "REPEAT") + else if (option.equals_ci("REPEAT")) { - if (value == "ON") + if (value.equals_ci("ON")) { - const char *times = params.size() > 4 ? params[4].c_str() : NULL; + Anope::string times = params.size() > 4 ? params[4] : ""; - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_REPEAT] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_REPEAT] < 0) + Anope::string error; + ci->ttb[TTB_REPEAT] = convertTo<int16>(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_REPEAT] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_REPEAT]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_REPEAT]; ci->ttb[TTB_REPEAT] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } else ci->ttb[TTB_REPEAT] = 0; - if (!times) + if (times.empty()) ci->repeattimes = 3; else - ci->repeattimes = atol(times); + ci->repeattimes = times.is_number_only() ? convertTo<int16>(times) : 3; if (ci->repeattimes < 2) ci->repeattimes = 3; @@ -271,19 +271,19 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_REPEAT_OFF); } } - else if (option == "REVERSES") + else if (option.equals_ci("REVERSES")) { - if (value == "ON") + if (value.equals_ci("ON")) { - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_REVERSES] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_REVERSES] < 0) + Anope::string error; + ci->ttb[TTB_REVERSES] = convertTo<int16>(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_REVERSES] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_REVERSES]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_REVERSES]; ci->ttb[TTB_REVERSES] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -301,19 +301,19 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_REVERSES_OFF); } } - else if (option == "UNDERLINES") + else if (option.equals_ci("UNDERLINES")) { - if (value == "ON") + if (value.equals_ci("ON")) { - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_UNDERLINES] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_UNDERLINES] < 0) + Anope::string error; + ci->ttb[TTB_UNDERLINES] = convertTo<int16>(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_UNDERLINES] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_UNDERLINES]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_UNDERLINES]; ci->ttb[TTB_UNDERLINES] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -337,25 +337,25 @@ class CommandBSKick : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (subcommand.empty()) notice_help(Config.s_BotServ, u, BOT_HELP_KICK); - else if (subcommand == "BADWORDS") + else if (subcommand.equals_ci("BADWORDS")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_BADWORDS); - else if (subcommand == "BOLDS") + else if (subcommand.equals_ci("BOLDS")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_BOLDS); - else if (subcommand == "CAPS") + else if (subcommand.equals_ci("CAPS")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_CAPS); - else if (subcommand == "COLORS") + else if (subcommand.equals_ci("COLORS")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_COLORS); - else if (subcommand == "FLOOD") + else if (subcommand.equals_ci("FLOOD")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_FLOOD); - else if (subcommand == "REPEAT") + else if (subcommand.equals_ci("REPEAT")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_REPEAT); - else if (subcommand == "REVERSES") + else if (subcommand.equals_ci("REVERSES")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_REVERSES); - else if (subcommand == "UNDERLINES") + else if (subcommand.equals_ci("UNDERLINES")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_UNDERLINES); else return false; @@ -363,7 +363,7 @@ class CommandBSKick : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "KICK", BOT_KICK_SYNTAX); } @@ -377,10 +377,11 @@ class CommandBSKick : public Command class BSKick : public Module { public: - BSKick(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSKick()); } }; diff --git a/modules/core/bs_say.cpp b/modules/core/bs_say.cpp index 88b298544..81616cf32 100644 --- a/modules/core/bs_say.cpp +++ b/modules/core/bs_say.cpp @@ -20,12 +20,12 @@ class CommandBSSay : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci; - const char *chan = params[0].c_str(); - const char *text = params[1].c_str(); + Anope::string chan = params[0]; + Anope::string text = params[1]; ci = cs_findchan(chan); @@ -53,20 +53,20 @@ class CommandBSSay : public Command return MOD_CONT; } - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", text); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", text.c_str()); ci->bi->lastmsg = time(NULL); - if (Config.LogBot && Config.LogChannel && LogChan && !debug && findchan(Config.LogChannel)) - ircdproto->SendPrivmsg(ci->bi, Config.LogChannel, "SAY %s %s %s", u->nick.c_str(), ci->name.c_str(), text); + if (Config.LogBot && !Config.LogChannel.empty() && LogChan && !debug && findchan(Config.LogChannel)) + ircdproto->SendPrivmsg(ci->bi, Config.LogChannel, "SAY %s %s %s", u->nick.c_str(), ci->name.c_str(), text.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_SAY); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "SAY", BOT_SAY_SYNTAX); } @@ -80,10 +80,11 @@ class CommandBSSay : public Command class BSSay : public Module { public: - BSSay(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSSay(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSSay()); } }; diff --git a/modules/core/bs_set.cpp b/modules/core/bs_set.cpp index d6f70352a..9788c278c 100644 --- a/modules/core/bs_set.cpp +++ b/modules/core/bs_set.cpp @@ -21,11 +21,11 @@ class CommandBSSet : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - ci::string option = params[1]; - ci::string value = params[2]; + Anope::string chan = params[0]; + Anope::string option = params[1]; + Anope::string value = params[2]; ChannelInfo *ci; if (readonly) @@ -34,22 +34,22 @@ class CommandBSSet : public Command return MOD_CONT; } - if (u->Account()->HasCommand("botserv/set/private") && option == "PRIVATE") + if (u->Account()->HasCommand("botserv/set/private") && option.equals_ci("PRIVATE")) { BotInfo *bi; if (!(bi = findbot(chan))) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, chan); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, chan.c_str()); return MOD_CONT; } - if (value == "ON") + if (value.equals_ci("ON")) { bi->SetFlag(BI_PRIVATE); notice_lang(Config.s_BotServ, u, BOT_SET_PRIVATE_ON, bi->nick.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { bi->UnsetFlag(BI_PRIVATE); notice_lang(Config.s_BotServ, u, BOT_SET_PRIVATE_OFF, bi->nick.c_str()); @@ -59,19 +59,19 @@ class CommandBSSet : public Command return MOD_CONT; } else if (!(ci = cs_findchan(chan))) - notice_lang(Config.s_BotServ, u, CHAN_X_NOT_REGISTERED, chan); + notice_lang(Config.s_BotServ, u, CHAN_X_NOT_REGISTERED, chan.c_str()); else if (!u->Account()->HasPriv("botserv/administration") && !check_access(u, ci, CA_SET)) notice_lang(Config.s_BotServ, u, ACCESS_DENIED); else { - if (option == "DONTKICKOPS") + if (option.equals_ci("DONTKICKOPS")) { - if (value == "ON") + if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_DONTKICKOPS); notice_lang(Config.s_BotServ, u, BOT_SET_DONTKICKOPS_ON, ci->name.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_DONTKICKOPS); notice_lang(Config.s_BotServ, u, BOT_SET_DONTKICKOPS_OFF, ci->name.c_str()); @@ -79,14 +79,14 @@ class CommandBSSet : public Command else syntax_error(Config.s_BotServ, u, "SET DONTKICKOPS", BOT_SET_DONTKICKOPS_SYNTAX); } - else if (option == "DONTKICKVOICES") + else if (option.equals_ci("DONTKICKVOICES")) { - if (value == "ON") + if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_DONTKICKVOICES); notice_lang(Config.s_BotServ, u, BOT_SET_DONTKICKVOICES_ON, ci->name.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_DONTKICKVOICES); notice_lang(Config.s_BotServ, u, BOT_SET_DONTKICKVOICES_OFF, ci->name.c_str()); @@ -94,14 +94,14 @@ class CommandBSSet : public Command else syntax_error(Config.s_BotServ, u, "SET DONTKICKVOICES", BOT_SET_DONTKICKVOICES_SYNTAX); } - else if (option == "FANTASY") + else if (option.equals_ci("FANTASY")) { - if (value == "ON") + if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_FANTASY); notice_lang(Config.s_BotServ, u, BOT_SET_FANTASY_ON, ci->name.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_FANTASY); notice_lang(Config.s_BotServ, u, BOT_SET_FANTASY_OFF, ci->name.c_str()); @@ -109,14 +109,14 @@ class CommandBSSet : public Command else syntax_error(Config.s_BotServ, u, "SET FANTASY", BOT_SET_FANTASY_SYNTAX); } - else if (option == "GREET") + else if (option.equals_ci("GREET")) { - if (value == "ON") + if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_GREET); notice_lang(Config.s_BotServ, u, BOT_SET_GREET_ON, ci->name.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_GREET); notice_lang(Config.s_BotServ, u, BOT_SET_GREET_OFF, ci->name.c_str()); @@ -124,16 +124,16 @@ class CommandBSSet : public Command else syntax_error(Config.s_BotServ, u, "SET GREET", BOT_SET_GREET_SYNTAX); } - else if (u->Account()->HasCommand("botserv/set/nobot") && option == "NOBOT") + else if (u->Account()->HasCommand("botserv/set/nobot") && option.equals_ci("NOBOT")) { - if (value == "ON") + if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_NOBOT); if (ci->bi) ci->bi->UnAssign(u, ci); notice_lang(Config.s_BotServ, u, BOT_SET_NOBOT_ON, ci->name.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_NOBOT); notice_lang(Config.s_BotServ, u, BOT_SET_NOBOT_OFF, ci->name.c_str()); @@ -141,14 +141,14 @@ class CommandBSSet : public Command else syntax_error(Config.s_BotServ, u, "SET NOBOT", BOT_SET_NOBOT_SYNTAX); } - else if (option == "SYMBIOSIS") + else if (option.equals_ci("SYMBIOSIS")) { - if (value == "ON") + if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_SYMBIOSIS); notice_lang(Config.s_BotServ, u, BOT_SET_SYMBIOSIS_ON, ci->name.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_SYMBIOSIS); notice_lang(Config.s_BotServ, u, BOT_SET_SYMBIOSIS_OFF, ci->name.c_str()); @@ -162,7 +162,7 @@ class CommandBSSet : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (subcommand.empty()) { @@ -170,19 +170,19 @@ class CommandBSSet : public Command if (u->Account() && u->Account()->IsServicesOper()) notice_help(Config.s_BotServ, u, BOT_SERVADMIN_HELP_SET); } - else if (subcommand == "DONTKICKOPS") + else if (subcommand.equals_ci("DONTKICKOPS")) notice_help(Config.s_BotServ, u, BOT_HELP_SET_DONTKICKOPS); - else if (subcommand == "DONTKICKVOICES") + else if (subcommand.equals_ci("DONTKICKVOICES")) notice_help(Config.s_BotServ, u, BOT_HELP_SET_DONTKICKVOICES); - else if (subcommand == "FANTASY") + else if (subcommand.equals_ci("FANTASY")) notice_help(Config.s_BotServ, u, BOT_HELP_SET_FANTASY); - else if (subcommand == "GREET") + else if (subcommand.equals_ci("GREET")) notice_help(Config.s_BotServ, u, BOT_HELP_SET_GREET); - else if (subcommand == "SYMBIOSIS") - notice_lang(Config.s_BotServ, u, BOT_HELP_SET_SYMBIOSIS, Config.s_ChanServ); - else if (subcommand == "NOBOT") + else if (subcommand.equals_ci("SYMBIOSIS")) + notice_lang(Config.s_BotServ, u, BOT_HELP_SET_SYMBIOSIS, Config.s_ChanServ.c_str()); + else if (subcommand.equals_ci("NOBOT")) notice_lang(Config.s_BotServ, u, BOT_SERVADMIN_HELP_SET_NOBOT); - else if (subcommand == "PRIVATE") + else if (subcommand.equals_ci("PRIVATE")) notice_lang(Config.s_BotServ, u, BOT_SERVADMIN_HELP_SET_PRIVATE); else return false; @@ -190,7 +190,7 @@ class CommandBSSet : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "SET", BOT_SET_SYNTAX); } @@ -204,10 +204,11 @@ class CommandBSSet : public Command class BSSet : public Module { public: - BSSet(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSSet()); } }; diff --git a/modules/core/bs_unassign.cpp b/modules/core/bs_unassign.cpp index cf6d8d7ab..3c6a3ccb1 100644 --- a/modules/core/bs_unassign.cpp +++ b/modules/core/bs_unassign.cpp @@ -20,15 +20,15 @@ class CommandBSUnassign : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); + Anope::string chan = params[0]; ChannelInfo *ci = cs_findchan(chan); ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PERM); if (readonly) notice_lang(Config.s_BotServ, u, BOT_ASSIGN_READONLY); - else if (!u->Account()->HasPriv("botserv/administration") && !check_access(u, ci, CA_ASSIGN)) + else if (!u->Account()->HasPriv("botserv/administration") && !check_access(u, ci, CA_ASSIGN)) notice_lang(Config.s_BotServ, u, ACCESS_DENIED); else if (!ci->bi) notice_help(Config.s_BotServ, u, BOT_NOT_ASSIGNED); @@ -42,13 +42,13 @@ class CommandBSUnassign : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_UNASSIGN); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "UNASSIGN", BOT_UNASSIGN_SYNTAX); } @@ -62,10 +62,11 @@ class CommandBSUnassign : public Command class BSUnassign : public Module { public: - BSUnassign(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSUnassign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSUnassign); } }; diff --git a/modules/core/cs_access.cpp b/modules/core/cs_access.cpp index a6ae88d37..74c72fcbb 100644 --- a/modules/core/cs_access.cpp +++ b/modules/core/cs_access.cpp @@ -20,7 +20,7 @@ class AccessListCallback : public NumberList ChannelInfo *ci; bool SentHeader; public: - AccessListCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : NumberList(numlist, false), u(_u), ci(_ci), SentHeader(false) + AccessListCallback(User *_u, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), u(_u), ci(_ci), SentHeader(false) { } @@ -50,18 +50,18 @@ class AccessListCallback : public NumberList { if (ci->HasFlag(CI_XOP)) { - const char *xop = get_xop_level(access->level); - notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_XOP_FORMAT, Number + 1, xop, access->nc->display); + Anope::string xop = get_xop_level(access->level); + notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_XOP_FORMAT, Number + 1, xop.c_str(), access->nc->display.c_str()); } else - notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_AXS_FORMAT, Number + 1, access->level, access->nc->display); + notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_AXS_FORMAT, Number + 1, access->level, access->nc->display.c_str()); } }; class AccessViewCallback : public AccessListCallback { public: - AccessViewCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : AccessListCallback(_u, _ci, numlist) + AccessViewCallback(User *_u, ChannelInfo *_ci, const Anope::string &numlist) : AccessListCallback(_u, _ci, numlist) { } @@ -81,10 +81,9 @@ class AccessViewCallback : public AccessListCallback static void DoList(User *u, ChannelInfo *ci, unsigned Number, ChanAccess *access) { - char timebuf[64]; + char timebuf[64] = ""; struct tm tm; - memset(&timebuf, 0, sizeof(timebuf)); if (ci->c && u->Account() && nc_on_chan(ci->c, u->Account())) snprintf(timebuf, sizeof(timebuf), "Now"); else if (access->last_seen == 0) @@ -97,11 +96,11 @@ class AccessViewCallback : public AccessListCallback if (ci->HasFlag(CI_XOP)) { - const char *xop = get_xop_level(access->level); - notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_VIEW_XOP_FORMAT, Number + 1, xop, access->nc->display, access->creator.c_str(), timebuf); + Anope::string xop = get_xop_level(access->level); + notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_VIEW_XOP_FORMAT, Number + 1, xop.c_str(), access->nc->display.c_str(), access->creator.c_str(), timebuf); } else - notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_VIEW_AXS_FORMAT, Number + 1, access->level, access->nc->display, access->creator.c_str(), timebuf); + notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_VIEW_AXS_FORMAT, Number + 1, access->level, access->nc->display.c_str(), access->creator.c_str(), timebuf); } }; @@ -110,10 +109,10 @@ class AccessDelCallback : public NumberList User *u; ChannelInfo *ci; unsigned Deleted; - std::string Nicks; + Anope::string Nicks; bool Denied; public: - AccessDelCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : NumberList(numlist, true), u(_u), ci(_ci), Deleted(0), Denied(false) + AccessDelCallback(User *_u, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, true), u(_u), ci(_ci), Deleted(0), Denied(false) { } @@ -149,7 +148,7 @@ class AccessDelCallback : public NumberList ++Deleted; if (!Nicks.empty()) - Nicks += ", " + std::string(access->nc->display); + Nicks += ", " + access->nc->display; else Nicks = access->nc->display; @@ -161,10 +160,10 @@ class AccessDelCallback : public NumberList class CommandCSAccess : public Command { - CommandReturn DoAdd(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + CommandReturn DoAdd(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { - const ci::string nick = params[2]; - int level = atoi(params[3].c_str()); + Anope::string nick = params[2]; + int level = params[3].is_number_only() ? convertTo<int>(params[3]) : ACCESS_INVALID; int ulev = get_access(u, ci); if (level >= ulev && !u->Account()->HasPriv("chanserv/access/modify")) @@ -184,7 +183,7 @@ class CommandCSAccess : public Command return MOD_CONT; } - NickAlias *na = findnick(nick.c_str()); + NickAlias *na = findnick(nick); if (!na) { notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_NICKS_ONLY); @@ -208,7 +207,7 @@ class CommandCSAccess : public Command } if (access->level == level) { - notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LEVEL_UNCHANGED, access->nc->display, ci->name.c_str(), level); + notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LEVEL_UNCHANGED, access->nc->display.c_str(), ci->name.c_str(), level); return MOD_CONT; } access->level = level; @@ -216,7 +215,7 @@ class CommandCSAccess : public Command FOREACH_MOD(I_OnAccessChange, OnAccessChange(ci, u, na->nc, level)); Alog() << Config.s_ChanServ << ": " << u->GetMask() << " (level " << ulev << ") set access level " << access->level << " to " << na->nick << " (group " << nc->display << ") on channel " << ci->name; - notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LEVEL_CHANGED, nc->display, ci->name.c_str(), level); + notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LEVEL_CHANGED, nc->display.c_str(), ci->name.c_str(), level); return MOD_CONT; } @@ -231,20 +230,20 @@ class CommandCSAccess : public Command FOREACH_MOD(I_OnAccessAdd, OnAccessAdd(ci, u, nc, level)); Alog() << Config.s_ChanServ << ": " << u->GetMask() << " (level " << ulev << ") set access level " << level << " to " << na->nick << " (group " << nc->display << ") on channel " << ci->name; - notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_ADDED, nc->display, ci->name.c_str(), level); + notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_ADDED, nc->display.c_str(), ci->name.c_str(), level); return MOD_CONT; } - CommandReturn DoDel(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + CommandReturn DoDel(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { - const ci::string nick = params[2]; + Anope::string nick = params[2]; if (!ci->GetAccessCount()) notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_EMPTY, ci->name.c_str()); - else if (isdigit(*nick.c_str()) && strspn(nick.c_str(), "1234567890,-") == nick.length()) + else if (isdigit(nick[0]) && nick.find_first_not_of("1234567890,-") == Anope::string::npos) { - AccessDelCallback list(u, ci, nick.c_str()); + AccessDelCallback list(u, ci, nick); list.Process(); } else @@ -274,7 +273,7 @@ class CommandCSAccess : public Command notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else { - notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_DELETED, access->nc->display, ci->name.c_str()); + notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_DELETED, access->nc->display.c_str(), ci->name.c_str()); Alog() << Config.s_ChanServ << ": " << u->GetMask() << " (level " << get_access(u, ci) << ") deleted access of " << na->nick << " (group " << access->nc->display << ") on " << ci->name; FOREACH_MOD(I_OnAccessDel, OnAccessDel(ci, u, na->nc)); @@ -285,15 +284,15 @@ class CommandCSAccess : public Command return MOD_CONT; } - CommandReturn DoList(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + CommandReturn DoList(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { - const ci::string nick = params.size() > 2 ? params[2] : ""; + Anope::string nick = params.size() > 2 ? params[2] : ""; if (!ci->GetAccessCount()) notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_EMPTY, ci->name.c_str()); - else if (!nick.empty() && strspn(nick.c_str(), "1234567890,-") == nick.length()) + else if (!nick.empty() && nick.find_first_not_of("1234567890,-") == Anope::string::npos) { - AccessListCallback list(u, ci, nick.c_str()); + AccessListCallback list(u, ci, nick); list.Process(); } else @@ -325,15 +324,15 @@ class CommandCSAccess : public Command return MOD_CONT; } - CommandReturn DoView(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + CommandReturn DoView(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { - const ci::string nick = params.size() > 2 ? params[2] : ""; + Anope::string nick = params.size() > 2 ? params[2] : ""; if (!ci->GetAccessCount()) notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_EMPTY, ci->name.c_str()); - else if (!nick.empty() && strspn(nick.c_str(), "1234567890,-") == nick.length()) + else if (!nick.empty() && nick.find_first_not_of("1234567890,-") == Anope::string::npos) { - AccessViewCallback list(u, ci, nick.c_str()); + AccessViewCallback list(u, ci, nick); list.Process(); } else @@ -365,7 +364,7 @@ class CommandCSAccess : public Command return MOD_CONT; } - CommandReturn DoClear(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + CommandReturn DoClear(User *u, ChannelInfo *ci) { if (!IsFounder(u, ci) && !u->Account()->HasPriv("chanserv/access/modify")) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); @@ -387,59 +386,59 @@ class CommandCSAccess : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - ci::string cmd = params[1]; - const char *nick = params.size() > 2 ? params[2].c_str() : NULL; - const char *s = params.size() > 3 ? params[3].c_str() : NULL; + Anope::string chan = params[0]; + Anope::string cmd = params[1]; + Anope::string nick = params.size() > 2 ? params[2] : ""; + Anope::string s = params.size() > 3 ? params[3] : ""; ChannelInfo *ci = cs_findchan(chan); - bool is_list = cmd == "LIST" || cmd == "VIEW"; - bool is_clear = cmd == "CLEAR"; + bool is_list = cmd.equals_ci("LIST") || cmd.equals_ci("VIEW"); + bool is_clear = cmd.equals_ci("CLEAR"); /* If LIST, we don't *require* any parameters, but we can take any. * If DEL, we require a nick and no level. * Else (ADD), we require a level (which implies a nick). */ - if (is_list || is_clear ? 0 : (cmd == "DEL" ? (!nick || s) : !s)) + if (is_list || is_clear ? 0 : (cmd.equals_ci("DEL") ? (nick.empty() || !s.empty()) : s.empty())) this->OnSyntaxError(u, cmd); - /* We still allow LIST and CLEAR in xOP mode, but not others */ - else if ((ci->HasFlag(CI_XOP)) && !is_list && !is_clear) + /* We still allow LIST in xOP mode, but not others */ + else if (ci->HasFlag(CI_XOP) && !is_list && !is_clear) { if (ModeManager::FindChannelModeByName(CMODE_HALFOP)) - notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_XOP_HOP, Config.s_ChanServ); + notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_XOP_HOP, Config.s_ChanServ.c_str()); else - notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_XOP, Config.s_ChanServ); + notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_XOP, Config.s_ChanServ.c_str()); } else if ((is_list && !check_access(u, ci, CA_ACCESS_LIST) && !u->Account()->HasCommand("chanserv/access/list")) || (!is_list && !check_access(u, ci, CA_ACCESS_CHANGE) && !u->Account()->HasPriv("chanserv/access/modify"))) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); - else if (readonly && (cmd == "ADD" || cmd == "DEL" || cmd == "CLEAR")) + else if (readonly && (cmd.equals_ci("ADD") || cmd.equals_ci("DEL") || cmd.equals_ci("CLEAR"))) notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_DISABLED); - else if (cmd == "ADD") + else if (cmd.equals_ci("ADD")) this->DoAdd(u, ci, params); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) this->DoDel(u, ci, params); - else if (cmd == "LIST") + else if (cmd.equals_ci("LIST")) this->DoList(u, ci, params); - else if (cmd == "VIEW") + else if (cmd.equals_ci("VIEW")) this->DoView(u, ci, params); - else if (cmd == "CLEAR") - this->DoClear(u, ci, params); + else if (cmd.equals_ci("CLEAR")) + this->DoClear(u, ci); else this->OnSyntaxError(u, ""); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_ACCESS); notice_help(Config.s_ChanServ, u, CHAN_HELP_ACCESS_LEVELS); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "ACCESS", CHAN_ACCESS_SYNTAX); } @@ -447,77 +446,77 @@ class CommandCSAccess : public Command class CommandCSLevels : public Command { - CommandReturn DoSet(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + CommandReturn DoSet(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { - const ci::string what = params[2]; - const ci::string lev = params[3]; + Anope::string what = params[2]; + Anope::string lev = params[3]; - char *error; - int level = strtol(lev.c_str(), &error, 10); + Anope::string error; + int level = convertTo<int>(lev, error, false); - if (lev == "FONDER") + if (lev.equals_ci("FOUNDER")) { level = ACCESS_FOUNDER; - *error = '\0'; + error.clear(); } - if (*error) + if (!error.empty()) this->OnSyntaxError(u, "SET"); else if (level <= ACCESS_INVALID || level > ACCESS_FOUNDER) notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_RANGE, ACCESS_INVALID + 1, ACCESS_FOUNDER - 1); else for (int i = 0; levelinfo[i].what >= 0; ++i) { - if (levelinfo[i].name == what) + if (what.equals_ci(levelinfo[i].name)) { ci->levels[levelinfo[i].what] = level; FOREACH_MOD(I_OnLevelChange, OnLevelChange(u, ci, i, level)); Alog() << Config.s_ChanServ << ": " << u->GetMask() << " set level " << levelinfo[i].name << " on channel " << ci->name << " to " << level; if (level == ACCESS_FOUNDER) - notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_CHANGED_FOUNDER, levelinfo[i].name, ci->name.c_str()); + notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_CHANGED_FOUNDER, levelinfo[i].name.c_str(), ci->name.c_str()); else - notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_CHANGED, levelinfo[i].name, ci->name.c_str(), level); + notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_CHANGED, levelinfo[i].name.c_str(), ci->name.c_str(), level); return MOD_CONT; } } - notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_UNKNOWN, what.c_str(), Config.s_ChanServ); + notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_UNKNOWN, what.c_str(), Config.s_ChanServ.c_str()); return MOD_CONT; } - CommandReturn DoDisable(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + CommandReturn DoDisable(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { - const ci::string what = params[2]; + Anope::string what = params[2]; /* Don't allow disabling of the founder level. It would be hard to change it back if you dont have access to use this command */ - if (what != "FOUNDER") + if (what.equals_ci("FOUNDER")) for (int i = 0; levelinfo[i].what >= 0; ++i) { - if (levelinfo[i].name == what) + if (what.equals_ci(levelinfo[i].name)) { ci->levels[levelinfo[i].what] = ACCESS_INVALID; FOREACH_MOD(I_OnLevelChange, OnLevelChange(u, ci, i, levelinfo[i].what)); Alog() << Config.s_ChanServ << ": " << u->GetMask() << " disabled level " << levelinfo[i].name << " on channel " << ci->name; - notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_DISABLED, levelinfo[i].name, ci->name.c_str()); + notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_DISABLED, levelinfo[i].name.c_str(), ci->name.c_str()); return MOD_CONT; } } - notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_UNKNOWN, what.c_str(), Config.s_ChanServ); + notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_UNKNOWN, what.c_str(), Config.s_ChanServ.c_str()); return MOD_CONT; } - CommandReturn DoList(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + CommandReturn DoList(User *u, ChannelInfo *ci) { notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_LIST_HEADER, ci->name.c_str()); if (!levelinfo_maxwidth) for (int i = 0; levelinfo[i].what >= 0; ++i) { - int len = strlen(levelinfo[i].name); + int len = levelinfo[i].name.length(); if (len > levelinfo_maxwidth) levelinfo_maxwidth = len; } @@ -531,20 +530,20 @@ class CommandCSLevels : public Command j = levelinfo[i].what; if (j == CA_AUTOOP || j == CA_AUTODEOP || j == CA_AUTOVOICE || j == CA_NOJOIN) - notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_LIST_DISABLED, levelinfo_maxwidth, levelinfo[i].name); + notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_LIST_DISABLED, levelinfo_maxwidth, levelinfo[i].name.c_str()); else - notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_LIST_DISABLED, levelinfo_maxwidth, levelinfo[i].name); + notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_LIST_DISABLED, levelinfo_maxwidth, levelinfo[i].name.c_str()); } else if (j == ACCESS_FOUNDER) - notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_LIST_FOUNDER, levelinfo_maxwidth, levelinfo[i].name); + notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_LIST_FOUNDER, levelinfo_maxwidth, levelinfo[i].name.c_str()); else - notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_LIST_NORMAL, levelinfo_maxwidth, levelinfo[i].name, j); + notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_LIST_NORMAL, levelinfo_maxwidth, levelinfo[i].name.c_str(), j); } return MOD_CONT; } - CommandReturn DoReset(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + CommandReturn DoReset(User *u, ChannelInfo *ci) { reset_levels(ci); FOREACH_MOD(I_OnLevelChange, OnLevelChange(u, ci, -1, 0)); @@ -558,45 +557,45 @@ class CommandCSLevels : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - ci::string cmd = params[1]; - const char *what = params.size() > 2 ? params[2].c_str() : NULL; - const char *s = params.size() > 3 ? params[3].c_str() : NULL; + Anope::string chan = params[0]; + Anope::string cmd = params[1]; + Anope::string what = params.size() > 2 ? params[2] : ""; + Anope::string s = params.size() > 3 ? params[3] : ""; ChannelInfo *ci = cs_findchan(chan); /* If SET, we want two extra parameters; if DIS[ABLE] or FOUNDER, we want only * one; else, we want none. */ - if (cmd == "SET" ? !s : (cmd.substr(0, 3) == "DIS" ? (!what || s) : !!what)) + if (cmd.equals_ci("SET") ? s.empty() : (cmd.substr(0, 3).equals_ci("DIS") ? (what.empty() || !s.empty()) : !what.empty())) this->OnSyntaxError(u, cmd); else if (ci->HasFlag(CI_XOP)) notice_lang(Config.s_ChanServ, u, CHAN_LEVELS_XOP); else if (!check_access(u, ci, CA_FOUNDER) && !u->Account()->HasPriv("chanserv/access/modify")) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); - else if (cmd == "SET") + else if (cmd.equals_ci("SET")) this->DoSet(u, ci, params); - else if (cmd == "DIS" || cmd == "DISABLE") + else if (cmd.equals_ci("DIS") || cmd.equals_ci("DISABLE")) this->DoDisable(u, ci, params); - else if (cmd == "LIST") - this->DoList(u, ci, params); - else if (cmd == "RESET") - this->DoReset(u, ci, params); + else if (cmd.equals_ci("LIST")) + this->DoList(u, ci); + else if (cmd.equals_ci("RESET")) + this->DoReset(u, ci); else this->OnSyntaxError(u, ""); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_LEVELS); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "LEVELS", CHAN_LEVELS_SYNTAX); } @@ -611,7 +610,7 @@ class CommandCSLevels : public Command class CSAccess : public Module { public: - CSAccess(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_akick.cpp b/modules/core/cs_akick.cpp index 771389207..394669513 100644 --- a/modules/core/cs_akick.cpp +++ b/modules/core/cs_akick.cpp @@ -18,30 +18,37 @@ * missing parts. */ -static void split_usermask(const char *mask, const char **nick, const char **user, const char **host) +static void split_usermask(const Anope::string &mask, Anope::string &nick, Anope::string &user, Anope::string &host) { - char *mask2 = sstrdup(mask); - - *nick = strtok(mask2, "!"); - *user = strtok(NULL, "@"); - *host = strtok(NULL, ""); - /* Handle special case: mask == user@host */ - if (*nick && !*user && strchr(*nick, '@')) + size_t ex = mask.find('!'), at = mask.find('@', ex == Anope::string::npos ? 0 : ex + 1); + if (ex == Anope::string::npos) { - *nick = NULL; - *user = strtok(mask2, "@"); - *host = strtok(NULL, ""); + if (at == Anope::string::npos) + { + nick = mask; + user = host = "*"; + } + else + { + nick = "*"; + user = mask.substr(0, at); + host = mask.substr(at + 1); + } + } + else + { + nick = mask.substr(0, ex); + if (at == Anope::string::npos) + { + user = mask.substr(ex + 1); + host = "*"; + } + else + { + user = mask.substr(ex + 1, at - ex - 1); + host = mask.substr(at + 1); + } } - if (!*nick) - *nick = "*"; - if (!*user) - *user = "*"; - if (!*host) - *host = "*"; - *nick = sstrdup(*nick); - *user = sstrdup(*user); - *host = sstrdup(*host); - delete [] mask2; } class AkickListCallback : public NumberList @@ -51,7 +58,7 @@ class AkickListCallback : public NumberList ChannelInfo *ci; bool SentHeader; public: - AkickListCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : NumberList(numlist, false), u(_u), ci(_ci), SentHeader(false) + AkickListCallback(User *_u, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), u(_u), ci(_ci), SentHeader(false) { } @@ -77,14 +84,14 @@ class AkickListCallback : public NumberList static void DoList(User *u, ChannelInfo *ci, unsigned index, AutoKick *akick) { - notice_lang(Config.s_ChanServ, u, CHAN_AKICK_LIST_FORMAT, index + 1, akick->HasFlag(AK_ISNICK) ? akick->nc->display : akick->mask.c_str(), !akick->reason.empty() ? akick->reason.c_str() : getstring(u, NO_REASON)); + notice_lang(Config.s_ChanServ, u, CHAN_AKICK_LIST_FORMAT, index + 1, akick->HasFlag(AK_ISNICK) ? akick->nc->display.c_str() :akick->mask.c_str(), !akick->reason.empty() ? akick->reason.c_str() : getstring(u, NO_REASON)); } }; class AkickViewCallback : public AkickListCallback { public: - AkickViewCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : AkickListCallback(u, ci, numlist) + AkickViewCallback(User *_u, ChannelInfo *_ci, const Anope::string &numlist) : AkickListCallback(u, ci, numlist) { } @@ -104,11 +111,9 @@ class AkickViewCallback : public AkickListCallback static void DoList(User *u, ChannelInfo *ci, unsigned index, AutoKick *akick) { - char timebuf[64]; + char timebuf[64] = ""; struct tm tm; - memset(&timebuf, 0, sizeof(timebuf)); - if (akick->addtime) { tm = *localtime(&akick->addtime); @@ -117,7 +122,7 @@ class AkickViewCallback : public AkickListCallback else snprintf(timebuf, sizeof(timebuf), "%s", getstring(u, UNKNOWN)); - notice_lang(Config.s_ChanServ, u, (akick->HasFlag(AK_STUCK) ? CHAN_AKICK_VIEW_FORMAT_STUCK : CHAN_AKICK_VIEW_FORMAT), index + 1, (akick->HasFlag(AK_ISNICK)) ? akick->nc->display : akick->mask.c_str(), !akick->creator.empty() ? akick->creator.c_str() : getstring(u, UNKNOWN), timebuf, !akick->reason.empty() ? akick->reason.c_str() : getstring(u, NO_REASON)); + notice_lang(Config.s_ChanServ, u, akick->HasFlag(AK_STUCK) ? CHAN_AKICK_VIEW_FORMAT_STUCK : CHAN_AKICK_VIEW_FORMAT, index + 1, akick->HasFlag(AK_ISNICK) ? akick->nc->display.c_str() : akick->mask.c_str(), !akick->creator.empty() ? akick->creator.c_str() : getstring(u, UNKNOWN), timebuf, !akick->reason.empty() ? akick->reason.c_str() : getstring(u, NO_REASON)); if (akick->last_used) { @@ -135,7 +140,7 @@ class AkickDelCallback : public NumberList ChannelInfo *ci; unsigned Deleted; public: - AkickDelCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list, true), u(_u), ci(_ci), Deleted(0) + AkickDelCallback(User *_u, ChannelInfo *_ci, const Anope::string &list) : NumberList(list, true), u(_u), ci(_ci), Deleted(0) { } @@ -161,37 +166,34 @@ class AkickDelCallback : public NumberList class CommandCSAKick : public Command { - void DoAdd(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + void DoAdd(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { - ci::string mask = params[2]; - ci::string reason = params.size() > 3 ? params[3] : ""; + Anope::string mask = params[2]; + Anope::string reason = params.size() > 3 ? params[3] : ""; NickAlias *na = findnick(mask); NickCore *nc = NULL; AutoKick *akick; if (!na) { - const char *nick, *user, *host; + Anope::string nick, user, host; - split_usermask(mask.c_str(), &nick, &user, &host); - mask = ci::string(nick) + "!" + user + "@" + host; - delete [] nick; - delete [] user; - delete [] host; + split_usermask(mask, nick, user, host); + mask = nick + "!" + user + "@" + host; } else { - if (na->HasFlag(NS_FORBIDDEN)) - { + if (na->HasFlag(NS_FORBIDDEN)) + { notice_lang(Config.s_ChanServ, u, NICK_X_FORBIDDEN, mask.c_str()); return; - } + } - nc = na->nc; + nc = na->nc; } /* Check excepts BEFORE we get this far */ - if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && is_excepted_mask(ci, mask.c_str())) + if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && is_excepted_mask(ci, mask)) { notice_lang(Config.s_ChanServ, u, CHAN_EXCEPTED, mask.c_str(), ci->name.c_str()); return; @@ -215,7 +217,7 @@ class CommandCSAKick : public Command { User *u2 = it->second; - if ((check_access(u2, ci, CA_FOUNDER) || get_access(u2, ci) >= get_access(u, ci)) && match_usermask(mask.c_str(), u2)) + if ((check_access(u2, ci, CA_FOUNDER) || get_access(u2, ci) >= get_access(u, ci)) && match_usermask(mask, u2)) { notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); return; @@ -233,10 +235,8 @@ class CommandCSAKick : public Command if (na2->nc && (na2->nc == ci->founder || get_access_level(ci, na2->nc) >= get_access(u, ci))) { - char buf[BUFSIZE]; - - snprintf(buf, BUFSIZE, "%s!%s", na2->nick, na2->last_usermask); - if (Anope::Match(buf, mask.c_str(), false)) + Anope::string buf = na2->nick + "!" + na2->last_usermask; + if (Anope::Match(buf, mask)) { notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); return; @@ -248,37 +248,36 @@ class CommandCSAKick : public Command for (unsigned j = 0, end = ci->GetAkickCount(); j < end; ++j) { akick = ci->GetAkick(j); - if (akick->HasFlag(AK_ISNICK) ? akick->nc == nc : akick->mask == mask) + if (akick->HasFlag(AK_ISNICK) ? akick->nc == nc : mask.equals_ci(akick->mask)) { - notice_lang(Config.s_ChanServ, u, CHAN_AKICK_ALREADY_EXISTS, akick->HasFlag(AK_ISNICK) ? akick->nc->display : akick->mask.c_str(), ci->name.c_str()); + notice_lang(Config.s_ChanServ, u, CHAN_AKICK_ALREADY_EXISTS, akick->HasFlag(AK_ISNICK) ? akick->nc->display.c_str() : akick->mask.c_str(), ci->name.c_str()); return; } } - if (ci->GetAkickCount() >= Config.CSAutokickMax) { - notice_lang(Config.s_ChanServ, u, CHAN_AKICK_REACHED_LIMIT, Config.CSAutokickMax); - return; + notice_lang(Config.s_ChanServ, u, CHAN_AKICK_REACHED_LIMIT, Config.CSAutokickMax); + return; } if (nc) - akick = ci->AddAkick(u->nick, nc, !reason.empty() ? reason.c_str() : ""); + akick = ci->AddAkick(u->nick, nc, reason); else - akick = ci->AddAkick(u->nick, mask.c_str(), !reason.empty() ? reason.c_str() : ""); + akick = ci->AddAkick(u->nick, mask, reason); FOREACH_MOD(I_OnAkickAdd, OnAkickAdd(u, ci, akick)); notice_lang(Config.s_ChanServ, u, CHAN_AKICK_ADDED, mask.c_str(), ci->name.c_str()); - this->DoEnforce(u, ci, params); + this->DoEnforce(u, ci); } - void DoStick(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + void DoStick(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { NickAlias *na; NickCore *nc; - ci::string mask = params[2]; + Anope::string mask = params[2]; unsigned i, end; AutoKick *akick; @@ -297,7 +296,7 @@ class CommandCSAKick : public Command if (akick->HasFlag(AK_ISNICK)) continue; - if (akick->mask == mask) + if (mask.equals_ci(akick->mask)) break; } @@ -314,13 +313,13 @@ class CommandCSAKick : public Command stick_mask(ci, akick); } - void DoUnStick(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + void DoUnStick(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { NickAlias *na; NickCore *nc; AutoKick *akick; unsigned i, end; - ci::string mask = params[2]; + Anope::string mask = params[2]; if (!ci->GetAkickCount()) { @@ -337,7 +336,7 @@ class CommandCSAKick : public Command if (akick->HasFlag(AK_ISNICK)) continue; - if (akick->mask == mask) + if (mask.equals_ci(akick->mask)) break; } @@ -351,9 +350,9 @@ class CommandCSAKick : public Command notice_lang(Config.s_ChanServ, u, CHAN_AKICK_UNSTUCK, akick->mask.c_str(), ci->name.c_str()); } - void DoDel(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + void DoDel(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { - ci::string mask = params[2]; + Anope::string mask = params[2]; AutoKick *akick; unsigned i, end; @@ -364,21 +363,21 @@ class CommandCSAKick : public Command } /* Special case: is it a number/list? Only do search if it isn't. */ - if (isdigit(*mask.c_str()) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkickDelCallback list(u, ci, mask.c_str()); + AkickDelCallback list(u, ci, mask); list.Process(); } else { NickAlias *na = findnick(mask); - NickCore *nc = (na ? na->nc : NULL); + NickCore *nc = na ? na->nc : NULL; for (i = 0, end = ci->GetAkickCount(); i < end; ++i) { akick = ci->GetAkick(i); - if ((akick->HasFlag(AK_ISNICK) && akick->nc == nc) || (!akick->HasFlag(AK_ISNICK) && akick->mask == mask)) + if ((akick->HasFlag(AK_ISNICK) && akick->nc == nc) || (!akick->HasFlag(AK_ISNICK) && mask.equals_ci(akick->mask))) break; } @@ -394,9 +393,9 @@ class CommandCSAKick : public Command } } - void DoList(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + void DoList(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { - ci::string mask = params.size() > 2 ? params[2] : ""; + Anope::string mask = params.size() > 2 ? params[2] : ""; if (!ci->GetAkickCount()) { @@ -404,9 +403,9 @@ class CommandCSAKick : public Command return; } - if (!mask.empty() && isdigit(*mask.c_str()) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkickListCallback list(u, ci, mask.c_str()); + AkickListCallback list(u, ci, mask); list.Process(); } else @@ -419,9 +418,9 @@ class CommandCSAKick : public Command if (!mask.empty()) { - if (!akick->HasFlag(AK_ISNICK) && !Anope::Match(akick->mask.c_str(), mask.c_str(), false)) + if (!akick->HasFlag(AK_ISNICK) && !Anope::Match(akick->mask, mask)) continue; - if (akick->HasFlag(AK_ISNICK) && !Anope::Match(akick->nc->display, mask.c_str(), false)) + if (akick->HasFlag(AK_ISNICK) && !Anope::Match(akick->nc->display, mask)) continue; } @@ -439,9 +438,9 @@ class CommandCSAKick : public Command } } - void DoView(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + void DoView(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { - ci::string mask = params.size() > 2 ? params[2] : ""; + Anope::string mask = params.size() > 2 ? params[2] : ""; if (!ci->GetAkickCount()) { @@ -449,9 +448,9 @@ class CommandCSAKick : public Command return; } - if (!mask.empty() && isdigit(*mask.c_str()) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkickViewCallback list(u, ci, mask.c_str()); + AkickViewCallback list(u, ci, mask); list.Process(); } else @@ -464,9 +463,9 @@ class CommandCSAKick : public Command if (!mask.empty()) { - if (!akick->HasFlag(AK_ISNICK) && !Anope::Match(akick->mask.c_str(), mask.c_str(), false)) + if (!akick->HasFlag(AK_ISNICK) && !Anope::Match(akick->mask, mask)) continue; - if (akick->HasFlag(AK_ISNICK) && !Anope::Match(akick->nc->display, mask.c_str(), false)) + if (akick->HasFlag(AK_ISNICK) && !Anope::Match(akick->nc->display, mask)) continue; } @@ -484,7 +483,7 @@ class CommandCSAKick : public Command } } - void DoEnforce(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + void DoEnforce(User *u, ChannelInfo *ci) { Channel *c = ci->c; int count = 0; @@ -506,7 +505,7 @@ class CommandCSAKick : public Command notice_lang(Config.s_ChanServ, u, CHAN_AKICK_ENFORCE_DONE, ci->name.c_str(), count); } - void DoClear(User *u, ChannelInfo *ci, const std::vector<ci::string> ¶ms) + void DoClear(User *u, ChannelInfo *ci) { ci->ClearAkick(); notice_lang(Config.s_ChanServ, u, CHAN_AKICK_CLEAR, ci->name.c_str()); @@ -517,49 +516,49 @@ class CommandCSAKick : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string chan = params[0]; - ci::string cmd = params[1]; - ci::string mask = params.size() > 2 ? params[2] : ""; + Anope::string chan = params[0]; + Anope::string cmd = params[1]; + Anope::string mask = params.size() > 2 ? params[2] : ""; ChannelInfo *ci = cs_findchan(chan); - if (mask.empty() && (cmd == "ADD" || cmd == "STICK" || cmd == "UNSTICK" || cmd == "DEL")) + if (mask.empty() && (cmd.equals_ci("ADD") || cmd.equals_ci("STICK") || cmd.equals_ci("UNSTICK") || cmd.equals_ci("DEL"))) this->OnSyntaxError(u, cmd); else if (!check_access(u, ci, CA_AKICK) && !u->Account()->HasPriv("chanserv/access/modify")) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); - else if (cmd != "LIST" && cmd != "VIEW" && cmd != "ENFORCE" && readonly) + else if (!cmd.equals_ci("LIST") && !cmd.equals_ci("VIEW") && !cmd.equals_ci("ENFORCE") && readonly) notice_lang(Config.s_ChanServ, u, CHAN_AKICK_DISABLED); - else if (cmd == "ADD") + else if (cmd.equals_ci("ADD")) this->DoAdd(u, ci, params); - else if (cmd == "STICK") + else if (cmd.equals_ci("STICK")) this->DoStick(u, ci, params); - else if (cmd == "UNSTICK") + else if (cmd.equals_ci("UNSTICK")) this->DoUnStick(u, ci, params); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) this->DoDel(u, ci, params); - else if (cmd == "LIST") + else if (cmd.equals_ci("LIST")) this->DoList(u, ci, params); - else if (cmd == "VIEW") + else if (cmd.equals_ci("VIEW")) this->DoView(u, ci, params); - else if (cmd == "ENFORCE") - this->DoEnforce(u, ci, params); - else if (cmd == "CLEAR") - this->DoClear(u, ci, params); + else if (cmd.equals_ci("ENFORCE")) + this->DoEnforce(u, ci); + else if (cmd.equals_ci("CLEAR")) + this->DoClear(u, ci); else this->OnSyntaxError(u, ""); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_AKICK); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "AKICK", CHAN_AKICK_SYNTAX); } @@ -573,10 +572,11 @@ class CommandCSAKick : public Command class CSAKick : public Module { public: - CSAKick(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSAKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(ChanServ, new CommandCSAKick()); } }; diff --git a/modules/core/cs_ban.cpp b/modules/core/cs_ban.cpp index 17fbc1946..08cbc45ad 100644 --- a/modules/core/cs_ban.cpp +++ b/modules/core/cs_ban.cpp @@ -16,18 +16,15 @@ class CommandCSBan : public Command { public: - CommandCSBan(const ci::string &cname) : Command(cname, 2, 3) + CommandCSBan(const Anope::string &cname) : Command(cname, 2, 3) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - const char *target = params[1].c_str(); - const char *reason = NULL; - - if (params.size() > 2) - reason = params[2].c_str(); + Anope::string chan = params[0]; + Anope::string target = params[1]; + Anope::string reason = params.size() > 2 ? params[2] : "Requested"; Channel *c = findchan(chan); ChannelInfo *ci; @@ -35,18 +32,15 @@ class CommandCSBan : public Command int is_same; - if (!reason) - reason = "Requested"; - - is_same = !stricmp(target, u->nick.c_str()); + is_same = target.equals_ci(u->nick); if (c) ci = c->ci; if (!c) - notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); else if (is_same ? !(u2 = u) : !(u2 = finduser(target))) - notice_lang(Config.s_ChanServ, u, NICK_X_NOT_IN_USE, target); + notice_lang(Config.s_ChanServ, u, NICK_X_NOT_IN_USE, target.c_str()); else if (!is_same ? !check_access(u, ci, CA_BAN) : !check_access(u, ci, CA_BANME)) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else if (!is_same && (ci->HasFlag(CI_PEACE)) && (get_access(u2, ci) >= get_access(u, ci))) @@ -61,9 +55,9 @@ class CommandCSBan : public Command notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else { - char mask[BUFSIZE]; + Anope::string mask; - get_idealban(ci, u2, mask, sizeof(mask)); + get_idealban(ci, u2, mask); c->SetMode(NULL, CMODE_BAN, mask); /* We still allow host banning while not allowing to kick */ @@ -71,21 +65,21 @@ class CommandCSBan : public Command return MOD_CONT; if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !check_access(u, ci, CA_SIGNKICK))) - c->Kick(whosends(ci), u2, "%s (%s)", reason, u->nick.c_str()); + c->Kick(whosends(ci), u2, "%s (%s)", reason.c_str(), u->nick.c_str()); else - c->Kick(whosends(ci), u2, "%s", reason); + c->Kick(whosends(ci), u2, "%s", reason.c_str()); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_BAN); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "BAN", CHAN_BAN_SYNTAX); } @@ -99,10 +93,11 @@ class CommandCSBan : public Command class CSBan : public Module { public: - CSBan(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSBan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(ChanServ, new CommandCSBan("BAN")); this->AddCommand(ChanServ, new CommandCSBan("KB")); } diff --git a/modules/core/cs_clear.cpp b/modules/core/cs_clear.cpp index 7cc2631a4..910552ac2 100644 --- a/modules/core/cs_clear.cpp +++ b/modules/core/cs_clear.cpp @@ -20,13 +20,13 @@ class CommandCSClear : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - ci::string what = params[1]; + Anope::string chan = params[0]; + Anope::string what = params[1]; Channel *c = findchan(chan); ChannelInfo *ci = c ? c->ci : NULL; - std::string modebuf; + Anope::string modebuf; ChannelMode *owner = ModeManager::FindChannelModeByName(CMODE_OWNER); ChannelMode *admin = ModeManager::FindChannelModeByName(CMODE_PROTECT); @@ -35,58 +35,55 @@ class CommandCSClear : public Command ChannelMode *voice = ModeManager::FindChannelModeByName(CMODE_VOICE); if (!c) - notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); else if (!u || !check_access(u, ci, CA_CLEAR)) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); - else if (what == "bans") + else if (what.equals_ci("bans")) { c->ClearBans(); - notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_BANS, chan); + notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_BANS, chan.c_str()); } - else if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && what == "excepts") + else if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && what.equals_ci("excepts")) { c->ClearExcepts(); - notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_EXCEPTS, chan); + notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_EXCEPTS, chan.c_str()); } - else if (ModeManager::FindChannelModeByName(CMODE_INVITE) && what == "invites") + else if (ModeManager::FindChannelModeByName(CMODE_INVITE) && what.equals_ci("invites")) { c->ClearInvites(); - notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_INVITES, chan); + notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_INVITES, chan.c_str()); } - else if (what == "modes") + else if (what.equals_ci("modes")) { c->ClearModes(); check_modes(c); - notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_MODES, chan); + notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_MODES, chan.c_str()); } - else if (what == "ops") + else if (what.equals_ci("ops")) { if (ircd->svsmode_ucmode) { if (owner) { - modebuf = '-'; - modebuf += owner->ModeChar; + modebuf = "-" + owner->ModeChar; - ircdproto->SendSVSModeChan(c, modebuf.c_str(), NULL); + ircdproto->SendSVSModeChan(c, modebuf, ""); } if (admin) { - modebuf = '-'; - modebuf += admin->ModeChar; + modebuf = "-" + admin->ModeChar; - ircdproto->SendSVSModeChan(c, modebuf.c_str(), NULL); + ircdproto->SendSVSModeChan(c, modebuf, ""); } if (op) { - modebuf = "-"; - modebuf += op->ModeChar; + modebuf = "-" + op->ModeChar; - ircdproto->SendSVSModeChan(c, modebuf.c_str(), NULL); + ircdproto->SendSVSModeChan(c, modebuf, ""); } } else @@ -104,18 +101,17 @@ class CommandCSClear : public Command } } - notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_OPS, chan); + notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_OPS, chan.c_str()); } - else if ((halfop && what == "hops") || (voice && what == "voices")) + else if ((halfop && what.equals_ci("hops")) || (voice && what.equals_ci("voices"))) { - ChannelMode *cm = what == "hops" ? halfop : voice; + ChannelMode *cm = what.equals_ci("hops") ? halfop : voice; if (ircd->svsmode_ucmode) { - modebuf = "-"; - modebuf += cm->ModeChar; + modebuf = "-" + cm->ModeChar; - ircdproto->SendSVSModeChan(c, modebuf.c_str(), NULL); + ircdproto->SendSVSModeChan(c, modebuf, ""); } else { @@ -128,18 +124,18 @@ class CommandCSClear : public Command } } } - else if (what == "users") + else if (what.equals_ci("users")) { - std::string buf = "CLEAR USERS command from " + u->nick; + Anope::string buf = "CLEAR USERS command from " + u->nick; for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) { UserContainer *uc = *it++; - c->Kick(NULL, uc->user, buf.c_str()); + c->Kick(NULL, uc->user, "%s", buf.c_str()); } - notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_USERS, chan); + notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_USERS, chan.c_str()); } else syntax_error(Config.s_ChanServ, u, "CLEAR", CHAN_CLEAR_SYNTAX); @@ -147,13 +143,13 @@ class CommandCSClear : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_CLEAR); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "CLEAR", CHAN_CLEAR_SYNTAX); } @@ -167,10 +163,11 @@ class CommandCSClear : public Command class CSClear : public Module { public: - CSClear(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSClear(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(ChanServ, new CommandCSClear()); } }; diff --git a/modules/core/cs_drop.cpp b/modules/core/cs_drop.cpp index 98daaee4f..cfbad70fa 100644 --- a/modules/core/cs_drop.cpp +++ b/modules/core/cs_drop.cpp @@ -22,9 +22,9 @@ class CommandCSDrop : public Command this->SetFlag(CFLAG_ALLOW_SUSPENDED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); + Anope::string chan = params[0]; ChannelInfo *ci; if (readonly) @@ -37,13 +37,13 @@ class CommandCSDrop : public Command if (ci->HasFlag(CI_FORBIDDEN) && !u->Account()->HasCommand("chanserv/drop")) { - notice_lang(Config.s_ChanServ, u, CHAN_X_FORBIDDEN, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_FORBIDDEN, chan.c_str()); return MOD_CONT; } if (ci->HasFlag(CI_SUSPENDED) && !u->Account()->HasCommand("chanserv/drop")) { - notice_lang(Config.s_ChanServ, u, CHAN_X_FORBIDDEN, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_FORBIDDEN, chan.c_str()); return MOD_CONT; } @@ -58,9 +58,9 @@ class CommandCSDrop : public Command if (ci->c && ModeManager::FindChannelModeByName(CMODE_REGISTERED)) ci->c->RemoveMode(NULL, CMODE_REGISTERED, "", false); - if (ircd->chansqline && (ci->HasFlag(CI_FORBIDDEN))) + if (ircd->chansqline && ci->HasFlag(CI_FORBIDDEN)) { - XLine x(ci->name.c_str()); + XLine x(ci->name); ircdproto->SendSQLineDel(&x); } @@ -72,16 +72,16 @@ class CommandCSDrop : public Command * drop the channel before issuing the wallops. */ if (Config.WallDrop && (level < ACCESS_FOUNDER || (!IsFounder(u, ci) && ci->HasFlag(CI_SECUREFOUNDER)))) - ircdproto->SendGlobops(ChanServ, "\2%s\2 used DROP on channel \2%s\2", u->nick.c_str(), chan); + ircdproto->SendGlobops(ChanServ, "\2%s\2 used DROP on channel \2%s\2", u->nick.c_str(), chan.c_str()); - notice_lang(Config.s_ChanServ, u, CHAN_DROPPED, chan); + notice_lang(Config.s_ChanServ, u, CHAN_DROPPED, chan.c_str()); FOREACH_MOD(I_OnChanDrop, OnChanDrop(chan)); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (u->Account() && u->Account()->IsServicesOper()) notice_help(Config.s_ChanServ, u, CHAN_SERVADMIN_HELP_DROP); @@ -91,7 +91,7 @@ class CommandCSDrop : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "DROP", CHAN_DROP_SYNTAX); } @@ -105,10 +105,11 @@ class CommandCSDrop : public Command class CSDrop : public Module { public: - CSDrop(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(ChanServ, new CommandCSDrop()); } }; diff --git a/modules/core/cs_forbid.cpp b/modules/core/cs_forbid.cpp index a4e62eef7..94ad125b9 100644 --- a/modules/core/cs_forbid.cpp +++ b/modules/core/cs_forbid.cpp @@ -21,21 +21,21 @@ class CommandCSForbid : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTEREDCHANNEL); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci; - const char *chan = params[0].c_str(); - const char *reason = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string chan = params[0]; + Anope::string reason = params.size() > 1 ? params[1] : ""; Channel *c; - if (Config.ForceForbidReason && !reason) + if (Config.ForceForbidReason && reason.empty()) { syntax_error(Config.s_ChanServ, u, "FORBID", CHAN_FORBID_SYNTAX_REASON); return MOD_CONT; } - if (*chan != '#') + if (chan[0] != '#') { notice_lang(Config.s_ChanServ, u, CHAN_SYMBOL_REQUIRED); return MOD_CONT; @@ -54,14 +54,13 @@ class CommandCSForbid : public Command if (!ci) { Alog() << Config.s_ChanServ << ": Valid FORBID for " << ci->name << " by " << u->nick << " failed"; - notice_lang(Config.s_ChanServ, u, CHAN_FORBID_FAILED, chan); + notice_lang(Config.s_ChanServ, u, CHAN_FORBID_FAILED, chan.c_str()); return MOD_CONT; } ci->SetFlag(CI_FORBIDDEN); - ci->forbidby = sstrdup(u->nick.c_str()); - if (reason) - ci->forbidreason = sstrdup(reason); + ci->forbidby = u->nick; + ci->forbidreason = reason; if ((c = findchan(ci->name))) { @@ -77,7 +76,7 @@ class CommandCSForbid : public Command if (is_oper(uc->user)) continue; - c->Kick(ChanServ, uc->user, "%s", reason ? reason : getstring(uc->user->Account(), CHAN_FORBID_REASON)); + c->Kick(ChanServ, uc->user, "%s", !reason.empty() ? reason.c_str() : getstring(uc->user->Account(), CHAN_FORBID_REASON)); } } @@ -91,20 +90,20 @@ class CommandCSForbid : public Command } Alog() << Config.s_ChanServ << ": " << u->nick << " set FORBID for channel " << ci->name; - notice_lang(Config.s_ChanServ, u, CHAN_FORBID_SUCCEEDED, chan); + notice_lang(Config.s_ChanServ, u, CHAN_FORBID_SUCCEEDED, chan.c_str()); FOREACH_MOD(I_OnChanForbidden, OnChanForbidden(ci)); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_SERVADMIN_HELP_FORBID); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "FORBID", CHAN_FORBID_SYNTAX); } @@ -118,10 +117,11 @@ class CommandCSForbid : public Command class CSForbid : public Module { public: - CSForbid(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSForbid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(ChanServ, new CommandCSForbid()); } }; diff --git a/modules/core/cs_getkey.cpp b/modules/core/cs_getkey.cpp index dc2f74655..80fa564e8 100644 --- a/modules/core/cs_getkey.cpp +++ b/modules/core/cs_getkey.cpp @@ -20,11 +20,11 @@ class CommandCSGetKey : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); + Anope::string chan = params[0]; ChannelInfo *ci; - std::string key; + Anope::string key; ci = cs_findchan(chan); @@ -36,21 +36,21 @@ class CommandCSGetKey : public Command if (!ci->c || !ci->c->GetParam(CMODE_KEY, key)) { - notice_lang(Config.s_ChanServ, u, CHAN_GETKEY_NOKEY, chan); + notice_lang(Config.s_ChanServ, u, CHAN_GETKEY_NOKEY, chan.c_str()); return MOD_CONT; } - notice_lang(Config.s_ChanServ, u, CHAN_GETKEY_KEY, chan, key.c_str()); + notice_lang(Config.s_ChanServ, u, CHAN_GETKEY_KEY, chan.c_str(), key.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_GETKEY); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "GETKEY", CHAN_GETKEY_SYNTAX); } @@ -64,10 +64,11 @@ class CommandCSGetKey : public Command class CSGetKey : public Module { public: - CSGetKey(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSGetKey(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(ChanServ, new CommandCSGetKey()); } }; diff --git a/modules/core/cs_help.cpp b/modules/core/cs_help.cpp index 536a6e423..0a6ba7aaf 100644 --- a/modules/core/cs_help.cpp +++ b/modules/core/cs_help.cpp @@ -22,31 +22,31 @@ class CommandCSHelp : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; + Anope::string cmd = params[0]; - if (cmd == "LEVELS DESC") + if (cmd.equals_ci("LEVELS DESC")) { int i; notice_help(Config.s_ChanServ, u, CHAN_HELP_LEVELS_DESC); if (!levelinfo_maxwidth) for (i = 0; levelinfo[i].what >= 0; ++i) { - int len = strlen(levelinfo[i].name); + int len = levelinfo[i].name.length(); if (len > levelinfo_maxwidth) levelinfo_maxwidth = len; } for (i = 0; levelinfo[i].what >= 0; ++i) - notice_help(Config.s_ChanServ, u, CHAN_HELP_LEVELS_DESC_FORMAT, levelinfo_maxwidth, levelinfo[i].name, getstring(u, levelinfo[i].desc)); + notice_help(Config.s_ChanServ, u, CHAN_HELP_LEVELS_DESC_FORMAT, levelinfo_maxwidth, levelinfo[i].name.c_str(), getstring(u, levelinfo[i].desc)); } else - mod_help_cmd(ChanServ, u, cmd.c_str()); + mod_help_cmd(ChanServ, u, cmd); return MOD_CONT; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP); for (CommandMap::const_iterator it = ChanServ->Commands.begin(); it != ChanServ->Commands.end(); ++it) @@ -62,10 +62,11 @@ class CommandCSHelp : public Command class CSHelp : public Module { public: - CSHelp(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSHelp(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(ChanServ, new CommandCSHelp()); } }; diff --git a/modules/core/cs_info.cpp b/modules/core/cs_info.cpp index 9b70735dd..5f135ce4d 100644 --- a/modules/core/cs_info.cpp +++ b/modules/core/cs_info.cpp @@ -15,7 +15,7 @@ class CommandCSInfo : public Command { - void CheckOptStr(std::string &buf, ChannelInfoFlag opt, const std::string &str, ChannelInfo *ci, NickCore *nc) + void CheckOptStr(Anope::string &buf, ChannelInfoFlag opt, const Anope::string &str, ChannelInfo *ci, const NickCore *nc) { if (ci->HasFlag(opt)) { @@ -35,9 +35,9 @@ class CommandCSInfo : public Command this->SetFlag(CFLAG_ALLOW_FORBIDDEN); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); + Anope::string chan = params[0]; char buf[BUFSIZE]; struct tm *tm; bool has_auspex = u->IsIdentified() && u->Account()->HasPriv("chanserv/auspex"); @@ -48,10 +48,10 @@ class CommandCSInfo : public Command if (ci->HasFlag(CI_FORBIDDEN)) { - if (is_oper(u) && ci->forbidby) - notice_lang(Config.s_ChanServ, u, CHAN_X_FORBIDDEN_OPER, chan, ci->forbidby, ci->forbidreason ? ci->forbidreason : getstring(u, NO_REASON)); + if (is_oper(u) && !ci->forbidby.empty()) + notice_lang(Config.s_ChanServ, u, CHAN_X_FORBIDDEN_OPER, chan.c_str(), ci->forbidby.c_str(), !ci->forbidreason.empty() ? ci->forbidreason.c_str() : getstring(u, NO_REASON)); else - notice_lang(Config.s_ChanServ, u, CHAN_X_FORBIDDEN, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_FORBIDDEN, chan.c_str()); return MOD_CONT; } @@ -60,13 +60,13 @@ class CommandCSInfo : public Command if (has_auspex && check_access(u, ci, CA_INFO)) show_all = true; - notice_lang(Config.s_ChanServ, u, CHAN_INFO_HEADER, chan); - notice_lang(Config.s_ChanServ, u, CHAN_INFO_NO_FOUNDER, ci->founder->display); + notice_lang(Config.s_ChanServ, u, CHAN_INFO_HEADER, chan.c_str()); + notice_lang(Config.s_ChanServ, u, CHAN_INFO_NO_FOUNDER, ci->founder->display.c_str()); if (show_all && ci->successor) - notice_lang(Config.s_ChanServ, u, CHAN_INFO_NO_SUCCESSOR, ci->successor->display); + notice_lang(Config.s_ChanServ, u, CHAN_INFO_NO_SUCCESSOR, ci->successor->display.c_str()); - notice_lang(Config.s_ChanServ, u, CHAN_INFO_DESCRIPTION, ci->desc); + notice_lang(Config.s_ChanServ, u, CHAN_INFO_DESCRIPTION, ci->desc.c_str()); tm = localtime(&ci->time_registered); strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); notice_lang(Config.s_ChanServ, u, CHAN_INFO_TIME_REGGED, buf); @@ -74,38 +74,38 @@ class CommandCSInfo : public Command strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); notice_lang(Config.s_ChanServ, u, CHAN_INFO_LAST_USED, buf); - if (ci->last_topic && (show_all || (!ci->HasMLock(CMODE_SECRET, true) && (!ci->c || !ci->c->HasMode(CMODE_SECRET))))) + if (!ci->last_topic.empty() && (show_all || (!ci->HasMLock(CMODE_SECRET, true) && (!ci->c || !ci->c->HasMode(CMODE_SECRET))))) { - notice_lang(Config.s_ChanServ, u, CHAN_INFO_LAST_TOPIC, ci->last_topic); + notice_lang(Config.s_ChanServ, u, CHAN_INFO_LAST_TOPIC, ci->last_topic.c_str()); notice_lang(Config.s_ChanServ, u, CHAN_INFO_TOPIC_SET_BY, ci->last_topic_setter.c_str()); } - if (ci->entry_message && show_all) - notice_lang(Config.s_ChanServ, u, CHAN_INFO_ENTRYMSG, ci->entry_message); + if (!ci->entry_message.empty() && show_all) + notice_lang(Config.s_ChanServ, u, CHAN_INFO_ENTRYMSG, ci->entry_message.c_str()); if (show_all) { notice_lang(Config.s_ChanServ, u, CHAN_INFO_BANTYPE, ci->bantype); - std::string optbuf; - - CheckOptStr(optbuf, CI_KEEPTOPIC, getstring(u, CHAN_INFO_OPT_KEEPTOPIC), ci, u->Account()); - CheckOptStr(optbuf, CI_OPNOTICE, getstring(u, CHAN_INFO_OPT_OPNOTICE), ci, u->Account()); - CheckOptStr(optbuf, CI_PEACE, getstring(u, CHAN_INFO_OPT_PEACE), ci, u->Account()); - CheckOptStr(optbuf, CI_PRIVATE, getstring(u, CHAN_INFO_OPT_PRIVATE), ci, u->Account()); - CheckOptStr(optbuf, CI_RESTRICTED, getstring(u, CHAN_INFO_OPT_RESTRICTED), ci, u->Account()); - CheckOptStr(optbuf, CI_SECURE, getstring(u, CHAN_INFO_OPT_SECURE), ci, u->Account()); - CheckOptStr(optbuf, CI_SECUREFOUNDER, getstring(u, CHAN_INFO_OPT_SECUREFOUNDER), ci, u->Account()); - CheckOptStr(optbuf, CI_SECUREOPS, getstring(u, CHAN_INFO_OPT_SECUREOPS), ci, u->Account()); + Anope::string optbuf; + + CheckOptStr(optbuf, CI_KEEPTOPIC, getstring(u, CHAN_INFO_OPT_KEEPTOPIC), ci, u->Account()); + CheckOptStr(optbuf, CI_OPNOTICE, getstring(u, CHAN_INFO_OPT_OPNOTICE), ci, u->Account()); + CheckOptStr(optbuf, CI_PEACE, getstring(u, CHAN_INFO_OPT_PEACE), ci, u->Account()); + CheckOptStr(optbuf, CI_PRIVATE, getstring(u, CHAN_INFO_OPT_PRIVATE), ci, u->Account()); + CheckOptStr(optbuf, CI_RESTRICTED, getstring(u, CHAN_INFO_OPT_RESTRICTED), ci, u->Account()); + CheckOptStr(optbuf, CI_SECURE, getstring(u, CHAN_INFO_OPT_SECURE), ci, u->Account()); + CheckOptStr(optbuf, CI_SECUREFOUNDER, getstring(u, CHAN_INFO_OPT_SECUREFOUNDER), ci, u->Account()); + CheckOptStr(optbuf, CI_SECUREOPS, getstring(u, CHAN_INFO_OPT_SECUREOPS), ci, u->Account()); if (ci->HasFlag(CI_SIGNKICK)) - CheckOptStr(optbuf, CI_SIGNKICK, getstring(u, CHAN_INFO_OPT_SIGNKICK), ci, u->Account()); + CheckOptStr(optbuf, CI_SIGNKICK, getstring(u, CHAN_INFO_OPT_SIGNKICK), ci, u->Account()); else - CheckOptStr(optbuf, CI_SIGNKICK_LEVEL, getstring(u, CHAN_INFO_OPT_SIGNKICK), ci, u->Account()); - CheckOptStr(optbuf, CI_TOPICLOCK, getstring(u, CHAN_INFO_OPT_TOPICLOCK), ci, u->Account()); - CheckOptStr(optbuf, CI_XOP, getstring(u, CHAN_INFO_OPT_XOP), ci, u->Account()); + CheckOptStr(optbuf, CI_SIGNKICK_LEVEL, getstring(u, CHAN_INFO_OPT_SIGNKICK), ci, u->Account()); + CheckOptStr(optbuf, CI_TOPICLOCK, getstring(u, CHAN_INFO_OPT_TOPICLOCK), ci, u->Account()); + CheckOptStr(optbuf, CI_XOP, getstring(u, CHAN_INFO_OPT_XOP), ci, u->Account()); CheckOptStr(optbuf, CI_PERSIST, getstring(u, CHAN_INFO_OPT_PERSIST), ci, u->Account()); - notice_lang(Config.s_ChanServ, u, CHAN_INFO_OPTIONS, optbuf.empty() ? getstring(u, CHAN_INFO_OPT_NONE) : optbuf.c_str()); - notice_lang(Config.s_ChanServ, u, CHAN_INFO_MODE_LOCK, get_mlock_modes(ci, 1)); + notice_lang(Config.s_ChanServ, u, CHAN_INFO_OPTIONS, optbuf.empty() ? getstring(u, CHAN_INFO_OPT_NONE) : optbuf.c_str()); + notice_lang(Config.s_ChanServ, u, CHAN_INFO_MODE_LOCK, get_mlock_modes(ci, 1).c_str()); // XXX: we could just as easily (and tidily) merge this in with the flags display above. if (ci->HasFlag(CI_NO_EXPIRE)) @@ -119,21 +119,21 @@ class CommandCSInfo : public Command } } if (ci->HasFlag(CI_SUSPENDED)) - notice_lang(Config.s_ChanServ, u, CHAN_X_SUSPENDED, ci->forbidby, (ci->forbidreason ? ci->forbidreason : getstring(u, NO_REASON))); + notice_lang(Config.s_ChanServ, u, CHAN_X_SUSPENDED, ci->forbidby.c_str(), !ci->forbidreason.empty() ? ci->forbidreason.c_str() : getstring(u, NO_REASON)); FOREACH_MOD(I_OnChanInfo, OnChanInfo(u, ci, show_all)); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_lang(Config.s_ChanServ, u, CHAN_HELP_INFO); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "INFO", CHAN_INFO_SYNTAX); } @@ -147,10 +147,11 @@ class CommandCSInfo : public Command class CSInfo : public Module { public: - CSInfo(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(ChanServ, new CommandCSInfo()); } }; diff --git a/modules/core/cs_invite.cpp b/modules/core/cs_invite.cpp index 48425e387..011a0bcf3 100644 --- a/modules/core/cs_invite.cpp +++ b/modules/core/cs_invite.cpp @@ -20,16 +20,16 @@ class CommandCSInvite : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); + Anope::string chan = params[0]; Channel *c; ChannelInfo *ci; User *u2; if (!(c = findchan(chan))) { - notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); return MOD_CONT; } @@ -56,20 +56,20 @@ class CommandCSInvite : public Command notice_lang(Config.s_ChanServ, u, CHAN_INVITE_ALREADY_IN, c->name.c_str()); else { - ircdproto->SendInvite(whosends(ci), chan, u2->nick.c_str()); + ircdproto->SendInvite(whosends(ci), chan, u2->nick); notice_lang(whosends(ci)->nick, u, CHAN_INVITE_OTHER_SUCCESS, u2->nick.c_str(), c->name.c_str()); notice_lang(whosends(ci)->nick, u2, CHAN_INVITE_SUCCESS, c->name.c_str()); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_INVITE); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "INVITE", CHAN_INVITE_SYNTAX); } @@ -83,7 +83,7 @@ class CommandCSInvite : public Command class CSInvite : public Module { public: - CSInvite(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSInvite(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_kick.cpp b/modules/core/cs_kick.cpp index 9aa4d30f6..44bfc6d89 100644 --- a/modules/core/cs_kick.cpp +++ b/modules/core/cs_kick.cpp @@ -16,18 +16,15 @@ class CommandCSKick : public Command { public: - CommandCSKick(const ci::string &cname) : Command(cname, 2, 3) + CommandCSKick(const Anope::string &cname) : Command(cname, 2, 3) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - const char *target = params[1].c_str(); - const char *reason = NULL; - - if (params.size() > 2) - reason = params[2].c_str(); + Anope::string chan = params[0]; + Anope::string target = params[1]; + Anope::string reason = params.size() > 2 ? params[2] : "Requested"; Channel *c = findchan(chan); ChannelInfo *ci; @@ -35,18 +32,15 @@ class CommandCSKick : public Command int is_same; - if (!reason) - reason = "Requested"; - - is_same = target == u->nick.c_str() ? 1 : !stricmp(target, u->nick.c_str()); + is_same = target.equals_cs(u->nick) ? 1 : target.equals_ci(u->nick); if (c) ci = c->ci; if (!c) - notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); else if (is_same ? !(u2 = u) : !(u2 = finduser(target))) - notice_lang(Config.s_ChanServ, u, NICK_X_NOT_IN_USE, target); + notice_lang(Config.s_ChanServ, u, NICK_X_NOT_IN_USE, target.c_str()); else if (!is_same ? !check_access(u, ci, CA_KICK) : !check_access(u, ci, CA_KICKME)) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else if (!is_same && (ci->HasFlag(CI_PEACE)) && get_access(u2, ci) >= get_access(u, ci)) @@ -58,20 +52,20 @@ class CommandCSKick : public Command else { if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !check_access(u, ci, CA_SIGNKICK))) - ci->c->Kick(whosends(ci), u2, "%s (%s)", reason, u->nick.c_str()); + ci->c->Kick(whosends(ci), u2, "%s (%s)", reason.c_str(), u->nick.c_str()); else - ci->c->Kick(whosends(ci), u2, "%s", reason); + ci->c->Kick(whosends(ci), u2, "%s", reason.c_str()); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_KICK); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "KICK", CHAN_KICK_SYNTAX); } @@ -85,10 +79,11 @@ class CommandCSKick : public Command class CSKick : public Module { public: - CSKick(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(ChanServ, new CommandCSKick("KICK")); this->AddCommand(ChanServ, new CommandCSKick("K")); } diff --git a/modules/core/cs_list.cpp b/modules/core/cs_list.cpp index 5d7547499..d6a55d774 100644 --- a/modules/core/cs_list.cpp +++ b/modules/core/cs_list.cpp @@ -22,17 +22,13 @@ public: this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *pattern = params[0].c_str(); - int spattern_size; - char *spattern; + Anope::string pattern = params[0]; unsigned nchans; char buf[BUFSIZE]; bool is_servadmin = u->Account()->HasCommand("chanserv/list"); - int count = 0, from = 0, to = 0, tofree = 0; - char *tmp = NULL; - char *s = NULL; + int count = 0, from = 0, to = 0; bool forbidden = false, suspended = false, channoexpire = false; if (Config.CSListOpersOnly && !is_oper(u)) @@ -43,66 +39,57 @@ public: if (pattern[0] == '#') { - tmp = myStrGetOnlyToken((pattern + 1), '-', 0); /* Read FROM out */ - if (!tmp) + Anope::string tmp = myStrGetToken(pattern.substr(1), '-', 0); /* Read FROM out */ + if (tmp.empty()) { notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); notice_lang(Config.s_ChanServ, u, CS_LIST_INCORRECT_RANGE); return MOD_CONT; } - for (s = tmp; *s; ++s) - if (!isdigit(*s)) - { - delete [] tmp; - notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); - notice_lang(Config.s_ChanServ, u, CS_LIST_INCORRECT_RANGE); - return MOD_CONT; - } - from = atoi(tmp); - delete [] tmp; + if (!tmp.is_number_only()) + { + notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); + notice_lang(Config.s_ChanServ, u, CS_LIST_INCORRECT_RANGE); + return MOD_CONT; + } + from = convertTo<int>(tmp); tmp = myStrGetTokenRemainder(pattern, '-', 1); /* Read TO out */ - if (!tmp) + if (tmp.empty()) { notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); notice_lang(Config.s_ChanServ, u, CS_LIST_INCORRECT_RANGE); return MOD_CONT; } - for (s = tmp; *s; ++s) - if (!isdigit(*s)) - { - delete [] tmp; - notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); - notice_lang(Config.s_ChanServ, u, CS_LIST_INCORRECT_RANGE); - return MOD_CONT; - } - to = atoi(tmp); - delete [] tmp; - pattern = sstrdup("*"); - tofree = 1; + if (!tmp.is_number_only()) + { + notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); + notice_lang(Config.s_ChanServ, u, CS_LIST_INCORRECT_RANGE); + return MOD_CONT; + } + to = convertTo<int>(tmp); + pattern = "*"; } nchans = 0; if (is_servadmin && params.size() > 1) { - ci::string keyword; - spacesepstream keywords(params[1].c_str()); + Anope::string keyword; + spacesepstream keywords(params[1]); while (keywords.GetToken(keyword)) { - if (keyword == "FORBIDDEN") + if (keyword.equals_ci("FORBIDDEN")) forbidden = true; - if (keyword == "SUSPENDED") + if (keyword.equals_ci("SUSPENDED")) suspended = true; - if (keyword == "NOEXPIRE") + if (keyword.equals_ci("NOEXPIRE")) channoexpire = true; } } - spattern_size = (strlen(pattern) + 2) * sizeof(char); - spattern = new char[spattern_size]; - snprintf(spattern, spattern_size, "#%s", pattern); + Anope::string spattern = "#" + pattern; - notice_lang(Config.s_ChanServ, u, CHAN_LIST_HEADER, pattern); + notice_lang(Config.s_ChanServ, u, CHAN_LIST_HEADER, pattern.c_str()); for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) { @@ -117,7 +104,7 @@ public: else if (channoexpire && !ci->HasFlag(CI_NO_EXPIRE)) continue; - if (!stricmp(pattern, ci->name.c_str()) || !stricmp(spattern, ci->name.c_str()) || Anope::Match(ci->name, pattern, false) || Anope::Match(ci->name, spattern, false)) + if (pattern.equals_ci(ci->name) || ci->name.equals_ci(spattern) || Anope::Match(ci->name, pattern) || Anope::Match(ci->name, spattern)) { if (((count + 1 >= from && count + 1 <= to) || (!from && !to)) && ++nchans <= Config.CSListMax) { @@ -130,7 +117,7 @@ public: else if (ci->HasFlag(CI_SUSPENDED)) snprintf(buf, sizeof(buf), "%-20s [Suspended]", ci->name.c_str()); else - snprintf(buf, sizeof(buf), "%-20s %s", ci->name.c_str(), ci->desc ? ci->desc : ""); + snprintf(buf, sizeof(buf), "%-20s %s", ci->name.c_str(), !ci->desc.empty() ? ci->desc.c_str() : ""); u->SendMessage(Config.s_ChanServ, " %c%s", noexpire_char, buf); } @@ -139,19 +126,16 @@ public: } notice_lang(Config.s_ChanServ, u, CHAN_LIST_END, nchans > Config.CSListMax ? Config.CSListMax : nchans, nchans); - delete [] spattern; - if (tofree) - delete [] pattern; return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_LIST); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "LIST", CHAN_LIST_SYNTAX); } @@ -165,10 +149,11 @@ public: class CSList : public Module { public: - CSList(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(ChanServ, new CommandCSList()); } }; diff --git a/modules/core/cs_modes.cpp b/modules/core/cs_modes.cpp index dce79f50d..5825b7a97 100644 --- a/modules/core/cs_modes.cpp +++ b/modules/core/cs_modes.cpp @@ -24,26 +24,27 @@ * @param name The name, eg "OP" or "HALFOP" * @param notice Flag required on a channel to send a notice */ -static CommandReturn do_util(User *u, ChannelMode *cm, const char *chan, const char *nick, bool set, int level, int levelself, const std::string &name, ChannelInfoFlag notice) +static CommandReturn do_util(User *u, ChannelMode *cm, const Anope::string &chan, const Anope::string &nick, bool set, int level, int levelself, const Anope::string &name, ChannelInfoFlag notice) { Channel *c = findchan(chan); ChannelInfo *ci; User *u2; + Anope::string realnick = nick; int is_same; - if (!nick) - nick = u->nick.c_str(); + if (realnick.empty()) + realnick = u->nick; - is_same = nick == u->nick ? 1 : !stricmp(nick, u->nick.c_str()); + is_same = u->nick.equals_cs(realnick) ? 1 : u->nick.equals_ci(realnick); if (c) ci = c->ci; if (!c) - notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); - else if (is_same ? !(u2 = u) : !(u2 = finduser(nick))) - notice_lang(Config.s_ChanServ, u, NICK_X_NOT_IN_USE, nick); + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); + else if (is_same ? !(u2 = u) : !(u2 = finduser(realnick))) + notice_lang(Config.s_ChanServ, u, NICK_X_NOT_IN_USE, realnick.c_str()); else if (is_same ? !check_access(u, ci, levelself) : !check_access(u, ci, level)) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else if (!set && !is_same && (ci->HasFlag(CI_PEACE)) && (get_access(u2, ci) >= get_access(u, ci))) @@ -60,7 +61,7 @@ static CommandReturn do_util(User *u, ChannelMode *cm, const char *chan, const c c->RemoveMode(NULL, cm, u2->nick); if (notice && ci->HasFlag(notice)) - ircdproto->SendMessage(whosends(ci), c->name.c_str(), "%s command used for %s by %s", name.c_str(), u2->nick.c_str(), u->nick.c_str()); + ircdproto->SendMessage(whosends(ci), c->name, "%s command used for %s by %s", name.c_str(), u2->nick.c_str(), u->nick.c_str()); } return MOD_CONT; @@ -73,20 +74,20 @@ class CommandCSOp : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OP); - return do_util(u, cm, params.size() > 0 ? params[0].c_str() : NULL, params.size() > 1 ? params[1].c_str() : NULL, true, CA_OPDEOP, CA_OPDEOPME, "OP", CI_OPNOTICE); + return do_util(u, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", true, CA_OPDEOP, CA_OPDEOPME, "OP", CI_OPNOTICE); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_OP); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "OP", CHAN_OP_SYNTAX); } @@ -104,20 +105,20 @@ class CommandCSDeOp : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OP); - return do_util(u, cm, params.size() > 0 ? params[0].c_str() : NULL, params.size() > 1 ? params[1].c_str() : NULL, false, CA_OPDEOP, CA_OPDEOPME, "DEOP", CI_OPNOTICE); + return do_util(u, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", false, CA_OPDEOP, CA_OPDEOPME, "DEOP", CI_OPNOTICE); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_DEOP); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "DEOP", CHAN_DEOP_SYNTAX); } @@ -135,20 +136,20 @@ class CommandCSVoice : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_VOICE); - return do_util(u, cm, params.size() > 0 ? params[0].c_str() : NULL, params.size() > 1 ? params[1].c_str() : NULL, true, CA_VOICE, CA_VOICEME, "VOICE", CI_BEGIN); + return do_util(u, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", true, CA_VOICE, CA_VOICEME, "VOICE", CI_BEGIN); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_VOICE); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "VOICE", CHAN_VOICE_SYNTAX); } @@ -166,20 +167,20 @@ class CommandCSDeVoice : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_VOICE); - return do_util(u, cm, params.size() > 0 ? params[0].c_str() : NULL, params.size() > 1 ? params[1].c_str() : NULL, false, CA_VOICE, CA_VOICEME, "DEVOICE", CI_BEGIN); + return do_util(u, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", false, CA_VOICE, CA_VOICEME, "DEVOICE", CI_BEGIN); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_DEVOICE); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "DEVOICE", CHAN_DEVOICE_SYNTAX); } @@ -197,7 +198,7 @@ class CommandCSHalfOp : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_HALFOP); @@ -206,16 +207,16 @@ class CommandCSHalfOp : public Command return MOD_CONT; } - return do_util(u, cm, params.size() > 0 ? params[0].c_str() : NULL, params.size() > 1 ? params[1].c_str() : NULL, true, CA_HALFOP, CA_HALFOPME, "HALFOP", CI_BEGIN); + return do_util(u, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", true, CA_HALFOP, CA_HALFOPME, "HALFOP", CI_BEGIN); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_HALFOP); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "HALFOP", CHAN_HALFOP_SYNTAX); } @@ -233,23 +234,23 @@ class CommandCSDeHalfOp : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_HALFOP); if (!cm) return MOD_CONT; - return do_util(u, cm, params.size() > 0 ? params[0].c_str() : NULL, params.size() > 1 ? params[1].c_str() : NULL, false, CA_HALFOP, CA_HALFOPME, "DEHALFOP", CI_BEGIN); + return do_util(u, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", false, CA_HALFOP, CA_HALFOPME, "DEHALFOP", CI_BEGIN); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_DEHALFOP); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "DEHALFOP", CHAN_DEHALFOP_SYNTAX); } @@ -267,23 +268,23 @@ class CommandCSProtect : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PROTECT); if (!cm) return MOD_CONT; - return do_util(u, cm, params.size() > 0 ? params[0].c_str() : NULL, params.size() > 1 ? params[1].c_str() : NULL, true, CA_PROTECT, CA_PROTECTME, "PROTECT", CI_BEGIN); + return do_util(u, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", true, CA_PROTECT, CA_PROTECTME, "PROTECT", CI_BEGIN); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_PROTECT); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "PROTECT", CHAN_PROTECT_SYNTAX); } @@ -301,23 +302,23 @@ class CommandCSDeProtect : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PROTECT); if (!cm) return MOD_CONT; - return do_util(u, cm, params.size() > 0 ? params[0].c_str() : NULL, params.size() > 1 ? params[1].c_str() : NULL, false, CA_PROTECT, CA_PROTECTME, "DEPROTECT", CI_BEGIN); + return do_util(u, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", false, CA_PROTECT, CA_PROTECTME, "DEPROTECT", CI_BEGIN); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_DEPROTECT); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "DEPROTECT", CHAN_DEPROTECT_SYNTAX); } @@ -335,23 +336,23 @@ class CommandCSOwner : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OWNER); if (!cm) return MOD_CONT; - return do_util(u, cm, params.size() > 0 ? params[0].c_str() : NULL, params.size() > 1 ? params[1].c_str() : NULL, true, CA_OWNER, CA_OWNERME, "OWNER", CI_BEGIN); + return do_util(u, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", true, CA_OWNER, CA_OWNERME, "OWNER", CI_BEGIN); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_OWNER); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "OWNER", CHAN_OWNER_SYNTAX); } @@ -369,23 +370,23 @@ class CommandCSDeOwner : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OWNER); if (!cm) return MOD_CONT; - return do_util(u, cm, params.size() > 0 ? params[0].c_str() : NULL, params.size() > 1 ? params[1].c_str() : NULL, false, CA_OWNER, CA_OWNERME, "DEOWNER", CI_BEGIN); + return do_util(u, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", false, CA_OWNER, CA_OWNERME, "DEOWNER", CI_BEGIN); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_DEOWNER); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "DEOWNER", CHAN_DEOWNER_SYNTAX); } @@ -399,7 +400,7 @@ class CommandCSDeOwner : public Command class CSModes : public Module { public: - CSModes(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSModes(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_register.cpp b/modules/core/cs_register.cpp index 7bc146409..4bd7d34cc 100644 --- a/modules/core/cs_register.cpp +++ b/modules/core/cs_register.cpp @@ -21,10 +21,10 @@ class CommandCSRegister : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTEREDCHANNEL); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - const char *desc = params[1].c_str(); + Anope::string chan = params[0]; + Anope::string desc = params[1]; Channel *c = findchan(chan); ChannelInfo *ci; ChannelMode *cm; @@ -35,14 +35,14 @@ class CommandCSRegister : public Command return MOD_CONT; } - if (*chan == '&') + if (chan[0] == '&') notice_lang(Config.s_ChanServ, u, CHAN_REGISTER_NOT_LOCAL); - else if (*chan != '#') + else if (chan[0] != '#') notice_lang(Config.s_ChanServ, u, CHAN_SYMBOL_REQUIRED); else if (!ircdproto->IsChannelValid(chan)) - notice_lang(Config.s_ChanServ, u, CHAN_X_INVALID, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_INVALID, chan.c_str()); else if ((ci = cs_findchan(chan))) - notice_lang(Config.s_ChanServ, u, CHAN_ALREADY_REGISTERED, chan); + notice_lang(Config.s_ChanServ, u, CHAN_ALREADY_REGISTERED, chan.c_str()); else if (c && !c->HasUserStatus(u, CMODE_OP)) notice_lang(Config.s_ChanServ, u, CHAN_MUST_BE_CHANOP); else if (Config.CSMaxReg && u->Account()->channelcount >= Config.CSMaxReg && !u->Account()->HasPriv("chanserv/no-register-limit")) @@ -60,11 +60,11 @@ class CommandCSRegister : public Command ci->c = c; } ci->founder = u->Account(); - ci->desc = sstrdup(desc); + ci->desc = desc; - if (c && c->topic) + if (c && !c->topic.empty()) { - ci->last_topic = sstrdup(c->topic); + ci->last_topic = c->topic; ci->last_topic_setter = c->topic_setter; ci->last_topic_time = c->topic_time; } @@ -74,7 +74,7 @@ class CommandCSRegister : public Command ci->bi = NULL; ++ci->founder->channelcount; Alog() << Config.s_ChanServ << ": Channel '" << chan << "' registered by " << u->GetMask(); - notice_lang(Config.s_ChanServ, u, CHAN_REGISTERED, chan, u->nick.c_str()); + notice_lang(Config.s_ChanServ, u, CHAN_REGISTERED, chan.c_str(), u->nick.c_str()); /* Implement new mode lock */ if (c) @@ -99,9 +99,9 @@ class CommandCSRegister : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { - notice_help(Config.s_ChanServ, u, CHAN_HELP_REGISTER, Config.s_ChanServ); + notice_help(Config.s_ChanServ, u, CHAN_HELP_REGISTER, Config.s_ChanServ.c_str()); return true; } @@ -109,17 +109,12 @@ class CommandCSRegister : public Command { syntax_error(Config.s_ChanServ, u, "REGISTER", CHAN_REGISTER_SYNTAX); } - - void OnSyntaxError(User *u) - { - notice_lang(Config.s_ChanServ, u, CHAN_HELP_CMD_REGISTER); - } }; class CSRegister : public Module { public: - CSRegister(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_saset.cpp b/modules/core/cs_saset.cpp index 161bf6f7c..157304b50 100644 --- a/modules/core/cs_saset.cpp +++ b/modules/core/cs_saset.cpp @@ -15,21 +15,22 @@ class CommandCSSASet : public Command { - std::map<ci::string, Command *> subcommands; + typedef std::map<Anope::string, Command *, hash_compare_ci_string> subcommand_map; + subcommand_map subcommands; public: - CommandCSSASet(const ci::string &cname) : Command(cname, 2, 3) + CommandCSSASet(const Anope::string &cname) : Command(cname, 2, 3) { } ~CommandCSSASet() { - for (std::map<ci::string, Command *>::const_iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) + for (subcommand_map::const_iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) delete it->second; this->subcommands.clear(); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { if (readonly) { @@ -41,26 +42,26 @@ class CommandCSSASet : public Command if (c) { - ci::string cmdparams = cs_findchan(params[0])->name.c_str(); - for (std::vector<ci::string>::const_iterator it = params.begin() + 2, it_end = params.end(); it != it_end; ++it) + Anope::string cmdparams = cs_findchan(params[0])->name; + for (std::vector<Anope::string>::const_iterator it = params.begin() + 2, it_end = params.end(); it != it_end; ++it) cmdparams += " " + *it; mod_run_cmd(ChanServ, u, c, params[1], cmdparams); } else { notice_lang(Config.s_ChanServ, u, CHAN_SET_UNKNOWN_OPTION, params[1].c_str()); - notice_lang(Config.s_ChanServ, u, MORE_INFO, Config.s_ChanServ, "SET"); + notice_lang(Config.s_ChanServ, u, MORE_INFO, Config.s_ChanServ.c_str(), "SET"); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (subcommand.empty()) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SASET_HEAD); - for (std::map<ci::string, Command *>::iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) + for (subcommand_map::iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) it->second->OnServHelp(u); notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_TAIL); return true; @@ -76,7 +77,7 @@ class CommandCSSASet : public Command return false; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "SASET", CHAN_SASET_SYNTAX); } @@ -91,14 +92,14 @@ class CommandCSSASet : public Command return this->subcommands.insert(std::make_pair(c->name, c)).second; } - bool DelSubcommand(const ci::string &command) + bool DelSubcommand(const Anope::string &command) { return this->subcommands.erase(command); } - Command *FindCommand(const ci::string &subcommand) + Command *FindCommand(const Anope::string &subcommand) { - std::map<ci::string, Command *>::const_iterator it = this->subcommands.find(subcommand); + subcommand_map::const_iterator it = this->subcommands.find(subcommand); if (it != this->subcommands.end()) return it->second; @@ -110,7 +111,7 @@ class CommandCSSASet : public Command class CSSASet : public Module { public: - CSSASet(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSASet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_saset_noexpire.cpp b/modules/core/cs_saset_noexpire.cpp index bbed7f014..dd485bb40 100644 --- a/modules/core/cs_saset_noexpire.cpp +++ b/modules/core/cs_saset_noexpire.cpp @@ -16,21 +16,21 @@ class CommandCSSASetNoexpire : public Command { public: - CommandCSSASetNoexpire(const ci::string &cname) : Command(cname, 2, 2, "chanserv/saset/noexpire") + CommandCSSASetNoexpire(const Anope::string &cname) : Command(cname, 2, 2, "chanserv/saset/noexpire") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (params[0] == "ON") + if (params[1].equals_ci("ON")) { ci->SetFlag(CI_NO_EXPIRE); notice_lang(Config.s_ChanServ, u, CHAN_SET_NOEXPIRE_ON, ci->name.c_str()); } - else if (params[0] == "OFF") + else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_NO_EXPIRE); notice_lang(Config.s_ChanServ, u, CHAN_SET_NOEXPIRE_OFF, ci->name.c_str()); @@ -41,13 +41,13 @@ class CommandCSSASetNoexpire : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_SERVADMIN_HELP_SET_NOEXPIRE); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET NOEXPIRE", CHAN_SET_NOEXPIRE_SYNTAX); } @@ -61,7 +61,7 @@ class CommandCSSASetNoexpire : public Command class CSSetNoexpire : public Module { public: - CSSetNoexpire(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetNoexpire(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set.cpp b/modules/core/cs_set.cpp index c9331e6a3..b9acb2a53 100644 --- a/modules/core/cs_set.cpp +++ b/modules/core/cs_set.cpp @@ -15,21 +15,22 @@ class CommandCSSet : public Command { - std::map<ci::string, Command *> subcommands; + typedef std::map<Anope::string, Command *, hash_compare_ci_string> subcommand_map; + subcommand_map subcommands; public: - CommandCSSet(const ci::string &cname) : Command(cname, 2, 3) + CommandCSSet(const Anope::string &cname) : Command(cname, 2, 3) { } ~CommandCSSet() { - for (std::map<ci::string, Command *>::const_iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) + for (subcommand_map::const_iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) delete it->second; this->subcommands.clear(); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { if (readonly) { @@ -46,26 +47,26 @@ class CommandCSSet : public Command if (c) { - ci::string cmdparams = cs_findchan(params[0])->name.c_str(); - for (std::vector<ci::string>::const_iterator it = params.begin() + 2, it_end = params.end(); it != it_end; ++it) + Anope::string cmdparams = cs_findchan(params[0])->name; + for (std::vector<Anope::string>::const_iterator it = params.begin() + 2, it_end = params.end(); it != it_end; ++it) cmdparams += " " + *it; mod_run_cmd(ChanServ, u, c, params[1], cmdparams); } else { notice_lang(Config.s_ChanServ, u, CHAN_SET_UNKNOWN_OPTION, params[1].c_str()); - notice_lang(Config.s_ChanServ, u, MORE_INFO, Config.s_ChanServ, "SET"); + notice_lang(Config.s_ChanServ, u, MORE_INFO, Config.s_ChanServ.c_str(), "SET"); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (subcommand.empty()) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_HEAD); - for (std::map<ci::string, Command *>::iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) + for (subcommand_map::iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) it->second->OnServHelp(u); notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_TAIL); return true; @@ -81,7 +82,7 @@ class CommandCSSet : public Command return false; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "SET", CHAN_SET_SYNTAX); } @@ -96,14 +97,14 @@ class CommandCSSet : public Command return this->subcommands.insert(std::make_pair(c->name, c)).second; } - bool DelSubcommand(const ci::string &command) + bool DelSubcommand(const Anope::string &command) { return this->subcommands.erase(command); } - Command *FindCommand(const ci::string &subcommand) + Command *FindCommand(const Anope::string &subcommand) { - std::map<ci::string, Command *>::const_iterator it = this->subcommands.find(subcommand); + subcommand_map::const_iterator it = this->subcommands.find(subcommand); if (it != this->subcommands.end()) return it->second; @@ -115,7 +116,7 @@ class CommandCSSet : public Command class CSSet : public Module { public: - CSSet(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_bantype.cpp b/modules/core/cs_set_bantype.cpp index aad7841e6..3c7e1c11a 100644 --- a/modules/core/cs_set_bantype.cpp +++ b/modules/core/cs_set_bantype.cpp @@ -16,20 +16,20 @@ class CommandCSSetBanType : public Command { public: - CommandCSSetBanType(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetBanType(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - char *endptr; + Anope::string end; - int16 bantype = strtol(params[1].c_str(), &endptr, 10); + int16 bantype = convertTo<int16>(params[1], end, false); - if (*endptr || bantype < 0 || bantype > 3) + if (!end.empty() || bantype < 0 || bantype > 3) notice_lang(Config.s_ChanServ, u, CHAN_SET_BANTYPE_INVALID, params[1].c_str()); else { @@ -40,13 +40,13 @@ class CommandCSSetBanType : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_BANTYPE, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_ChanServ, u, "SET", CHAN_SET_SYNTAX); @@ -61,17 +61,17 @@ class CommandCSSetBanType : public Command class CommandCSSASetBanType : public CommandCSSetBanType { public: - CommandCSSASetBanType(const ci::string &cname) : CommandCSSetBanType(cname, "chanserv/saset/bantype") + CommandCSSASetBanType(const Anope::string &cname) : CommandCSSetBanType(cname, "chanserv/saset/bantype") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_BANTYPE, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_ChanServ, u, "SASET", CHAN_SASET_SYNTAX); @@ -81,7 +81,7 @@ class CommandCSSASetBanType : public CommandCSSetBanType class CSSetBanType : public Module { public: - CSSetBanType(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetBanType(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_description.cpp b/modules/core/cs_set_description.cpp index 57209ce2e..82260df63 100644 --- a/modules/core/cs_set_description.cpp +++ b/modules/core/cs_set_description.cpp @@ -16,31 +16,29 @@ class CommandCSSetDescription : public Command { public: - CommandCSSetDescription(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetDescription(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (ci->desc) - delete [] ci->desc; - ci->desc = sstrdup(params[1].c_str()); + ci->desc = params[1]; - notice_lang(Config.s_ChanServ, u, CHAN_DESC_CHANGED, ci->name.c_str(), ci->desc); + notice_lang(Config.s_ChanServ, u, CHAN_DESC_CHANGED, ci->name.c_str(), ci->desc.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_DESC, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_ChanServ, u, "SET", CHAN_SET_SYNTAX); @@ -55,17 +53,17 @@ class CommandCSSetDescription : public Command class CommandCSSASetDescription : public CommandCSSetDescription { public: - CommandCSSASetDescription(const ci::string &cname) : CommandCSSetDescription(cname, "chanserv/saset/description") + CommandCSSASetDescription(const Anope::string &cname) : CommandCSSetDescription(cname, "chanserv/saset/description") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_DESC, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_ChanServ, u, "SASET", CHAN_SASET_SYNTAX); @@ -75,7 +73,7 @@ class CommandCSSASetDescription : public CommandCSSetDescription class CSSetDescription : public Module { public: - CSSetDescription(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetDescription(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); @@ -84,7 +82,7 @@ class CSSetDescription : public Module if (c) c->AddSubcommand(new CommandCSSetDescription("DESC")); - c = FindCommand(ChanServ, "SASEt"); + c = FindCommand(ChanServ, "SASET"); if (c) c->AddSubcommand(new CommandCSSASetDescription("DESC")); } diff --git a/modules/core/cs_set_entrymsg.cpp b/modules/core/cs_set_entrymsg.cpp index d2ec2bccc..9784773e4 100644 --- a/modules/core/cs_set_entrymsg.cpp +++ b/modules/core/cs_set_entrymsg.cpp @@ -16,38 +16,36 @@ class CommandCSSetEntryMsg : public Command { public: - CommandCSSetEntryMsg(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 1, 2, cpermission) + CommandCSSetEntryMsg(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 1, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (ci->entry_message) - delete [] ci->entry_message; if (params.size() > 1) { - ci->entry_message = sstrdup(params[1].c_str()); - notice_lang(Config.s_ChanServ, u, CHAN_ENTRY_MSG_CHANGED, ci->name.c_str(), ci->entry_message); + ci->entry_message = params[1]; + notice_lang(Config.s_ChanServ, u, CHAN_ENTRY_MSG_CHANGED, ci->name.c_str(), ci->entry_message.c_str()); } else { - ci->entry_message = NULL; + ci->entry_message.clear(); notice_lang(Config.s_ChanServ, u, CHAN_ENTRY_MSG_UNSET, ci->name.c_str()); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_ENTRYMSG, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_ChanServ, u, "SET", CHAN_SET_SYNTAX); @@ -62,17 +60,17 @@ class CommandCSSetEntryMsg : public Command class CommandCSSASetEntryMsg : public CommandCSSetEntryMsg { public: - CommandCSSASetEntryMsg(const ci::string &cname) : CommandCSSetEntryMsg(cname, "/chanserv/saset/entrymsg") + CommandCSSASetEntryMsg(const Anope::string &cname) : CommandCSSetEntryMsg(cname, "chanserv/saset/entrymsg") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_ENTRYMSG, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_ChanServ, u, "SASET", CHAN_SASET_SYNTAX); @@ -82,7 +80,7 @@ class CommandCSSASetEntryMsg : public CommandCSSetEntryMsg class CSSetEntryMsg : public Module { public: - CSSetEntryMsg(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetEntryMsg(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_founder.cpp b/modules/core/cs_set_founder.cpp index 35422755e..3982764cc 100644 --- a/modules/core/cs_set_founder.cpp +++ b/modules/core/cs_set_founder.cpp @@ -16,11 +16,11 @@ class CommandCSSetFounder : public Command { public: - CommandCSSetFounder(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetFounder(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); @@ -34,7 +34,6 @@ class CommandCSSetFounder : public Command NickAlias *na = findnick(params[1]); NickCore *nc, *nc0 = ci->founder; - if (!na) { notice_lang(Config.s_ChanServ, u, NICK_X_NOT_REGISTERED, params[1].c_str()); @@ -42,14 +41,14 @@ class CommandCSSetFounder : public Command } else if (na->HasFlag(NS_FORBIDDEN)) { - notice_lang(Config.s_ChanServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_ChanServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); return MOD_CONT; } nc = na->nc; if (Config.CSMaxReg && nc->channelcount >= Config.CSMaxReg && !u->Account()->HasPriv("chanserv/no-register-limit")) { - notice_lang(Config.s_ChanServ, u, CHAN_SET_FOUNDER_TOO_MANY_CHANS, na->nick); + notice_lang(Config.s_ChanServ, u, CHAN_SET_FOUNDER_TOO_MANY_CHANS, na->nick.c_str()); return MOD_CONT; } @@ -63,18 +62,18 @@ class CommandCSSetFounder : public Command ci->founder = nc; ++nc->channelcount; - notice_lang(Config.s_ChanServ, u, CHAN_FOUNDER_CHANGED, ci->name.c_str(), na->nick); + notice_lang(Config.s_ChanServ, u, CHAN_FOUNDER_CHANGED, ci->name.c_str(), na->nick.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_FOUNDER, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_ChanServ, u, "SET", CHAN_SET_SYNTAX); @@ -89,17 +88,17 @@ class CommandCSSetFounder : public Command class CommandCSSASetFounder : public CommandCSSetFounder { public: - CommandCSSASetFounder(const ci::string &cname) : CommandCSSetFounder(cname, "chanserv/saset/founder") + CommandCSSASetFounder(const Anope::string &cname) : CommandCSSetFounder(cname, "chanserv/saset/founder") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_FOUNDER, "SASET"); return true; } - void OnSyntaxError(User *u) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_ChanServ, u, "SASET", CHAN_SASET_SYNTAX); @@ -109,7 +108,7 @@ class CommandCSSASetFounder : public CommandCSSetFounder class CSSetFounder : public Module { public: - CSSetFounder(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetFounder(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_keeptopic.cpp b/modules/core/cs_set_keeptopic.cpp index 10595373f..5eb907dbd 100644 --- a/modules/core/cs_set_keeptopic.cpp +++ b/modules/core/cs_set_keeptopic.cpp @@ -16,21 +16,21 @@ class CommandCSSetKeepTopic : public Command { public: - CommandCSSetKeepTopic(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetKeepTopic(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (params[1] == "ON") + if (params[1].equals_ci("ON")) { ci->SetFlag(CI_KEEPTOPIC); notice_lang(Config.s_ChanServ, u, CHAN_SET_KEEPTOPIC_ON, ci->name.c_str()); } - else if (params[1] == "OFF") + else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_KEEPTOPIC); notice_lang(Config.s_ChanServ, u, CHAN_SET_KEEPTOPIC_OFF, ci->name.c_str()); @@ -41,13 +41,13 @@ class CommandCSSetKeepTopic : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_KEEPTOPIC, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET KEEPTOPIC", CHAN_SET_KEEPTOPIC_SYNTAX); } @@ -61,17 +61,17 @@ class CommandCSSetKeepTopic : public Command class CommandCSSASetKeepTopic : public CommandCSSetKeepTopic { public: - CommandCSSASetKeepTopic(const ci::string &cname) : CommandCSSetKeepTopic(cname, "chanserv/saset/keeptopic") + CommandCSSASetKeepTopic(const Anope::string &cname) : CommandCSSetKeepTopic(cname, "chanserv/saset/keeptopic") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_KEEPTOPIC, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET KEEPTOPIC", CHAN_SASET_KEEPTOPIC_SYNTAX); } @@ -80,7 +80,7 @@ class CommandCSSASetKeepTopic : public CommandCSSetKeepTopic class CSSetKeepTopic : public Module { public: - CSSetKeepTopic(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetKeepTopic(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_mlock.cpp b/modules/core/cs_set_mlock.cpp index 5a31a8565..2dc1ef2a7 100644 --- a/modules/core/cs_set_mlock.cpp +++ b/modules/core/cs_set_mlock.cpp @@ -16,17 +16,16 @@ class CommandCSSetMLock : public Command { public: - CommandCSSetMLock(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 1, 0, cpermission) + CommandCSSetMLock(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 1, 0, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); int add = -1; /* 1 if adding, 0 if deleting, -1 if neither */ - unsigned char mode; ChannelMode *cm; unsigned paramcount = 2; @@ -36,10 +35,10 @@ class CommandCSSetMLock : public Command if (ModeManager::FindChannelModeByName(CMODE_REGISTERED)) ci->SetMLock(CMODE_REGISTERED, true); - const char *modes = params[1].c_str(); - while (modes && (mode = *modes++)) + Anope::string modes = params[1]; + for (Anope::string::const_iterator ch = modes.begin(), end = modes.end(); ch != end; ++ch) { - switch (mode) + switch (*ch) { case '+': add = 1; @@ -52,10 +51,10 @@ class CommandCSSetMLock : public Command continue; } - if ((cm = ModeManager::FindChannelModeByChar(mode))) + if ((cm = ModeManager::FindChannelModeByChar(*ch))) { if (cm->Type == MODE_STATUS || cm->Type == MODE_LIST || !cm->CanSet(u)) - notice_lang(Config.s_ChanServ, u, CHAN_SET_MLOCK_IMPOSSIBLE_CHAR, mode); + notice_lang(Config.s_ChanServ, u, CHAN_SET_MLOCK_IMPOSSIBLE_CHAR, *ch); else if (add) { ci->RemoveMLock(cm->Name); @@ -65,7 +64,7 @@ class CommandCSSetMLock : public Command if (paramcount >= params.size()) continue; - std::string param = params[paramcount].c_str(); + Anope::string param = params[paramcount]; ChannelModeParam *cmp = dynamic_cast<ChannelModeParam *>(cm); @@ -81,8 +80,8 @@ class CommandCSSetMLock : public Command ci->SetMLock(cm->Name, false); } else - notice_lang(Config.s_ChanServ, u, CHAN_SET_MLOCK_UNKNOWN_CHAR, mode); - } /* while (*modes) */ + notice_lang(Config.s_ChanServ, u, CHAN_SET_MLOCK_UNKNOWN_CHAR, *ch); + } /* We can't mlock +L if +l is not mlocked as well. */ if (ModeManager::FindChannelModeByName(CMODE_REDIRECT) && ci->HasMLock(CMODE_REDIRECT, true) && !ci->HasMLock(CMODE_LIMIT, true)) @@ -102,8 +101,8 @@ class CommandCSSetMLock : public Command /* Since we always enforce mode r there is no way to have no * mode lock at all. */ - if (get_mlock_modes(ci, 0)) - notice_lang(Config.s_ChanServ, u, CHAN_MLOCK_CHANGED, ci->name.c_str(), get_mlock_modes(ci, 0)); + if (!get_mlock_modes(ci, 0).empty()) + notice_lang(Config.s_ChanServ, u, CHAN_MLOCK_CHANGED, ci->name.c_str(), get_mlock_modes(ci, 0).c_str()); /* Implement the new lock. */ if (ci->c) @@ -112,13 +111,13 @@ class CommandCSSetMLock : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_MLOCK, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_ChanServ, u, "SET", CHAN_SET_SYNTAX); @@ -133,17 +132,17 @@ class CommandCSSetMLock : public Command class CommandCSSASetMLock : public CommandCSSetMLock { public: - CommandCSSASetMLock(const ci::string &cname) : CommandCSSetMLock(cname, "chanserv/saset/mlock") + CommandCSSASetMLock(const Anope::string &cname) : CommandCSSetMLock(cname, "chanserv/saset/mlock") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_MLOCK, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_ChanServ, u, "SASET", CHAN_SASET_SYNTAX); @@ -153,7 +152,7 @@ class CommandCSSASetMLock : public CommandCSSetMLock class CSSetMLock : public Module { public: - CSSetMLock(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetMLock(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_opnotice.cpp b/modules/core/cs_set_opnotice.cpp index 79e953ef2..a0d0a2ec8 100644 --- a/modules/core/cs_set_opnotice.cpp +++ b/modules/core/cs_set_opnotice.cpp @@ -16,21 +16,21 @@ class CommandCSSetOpNotice : public Command { public: - CommandCSSetOpNotice(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetOpNotice(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (params[1] == "ON") + if (params[1].equals_ci("ON")) { ci->SetFlag(CI_OPNOTICE); notice_lang(Config.s_ChanServ, u, CHAN_SET_OPNOTICE_ON, ci->name.c_str()); } - else if (params[1] == "OFF") + else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_OPNOTICE); notice_lang(Config.s_ChanServ, u, CHAN_SET_OPNOTICE_OFF, ci->name.c_str()); @@ -41,13 +41,13 @@ class CommandCSSetOpNotice : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_OPNOTICE, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET OPNOTICE", CHAN_SET_OPNOTICE_SYNTAX); } @@ -61,17 +61,17 @@ class CommandCSSetOpNotice : public Command class CommandCSSASetOpNotice : public CommandCSSetOpNotice { public: - CommandCSSASetOpNotice(const ci::string &cname) : CommandCSSetOpNotice(cname, "chanserv/saset/opnotice") + CommandCSSASetOpNotice(const Anope::string &cname) : CommandCSSetOpNotice(cname, "chanserv/saset/opnotice") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_OPNOTICE, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET OPNOTICE", CHAN_SASET_OPNOTICE_SYNTAX); } @@ -80,7 +80,7 @@ class CommandCSSASetOpNotice : public CommandCSSetOpNotice class CSSetOpNotice : public Module { public: - CSSetOpNotice(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetOpNotice(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_peace.cpp b/modules/core/cs_set_peace.cpp index 3dadcb5e3..b00bf26d5 100644 --- a/modules/core/cs_set_peace.cpp +++ b/modules/core/cs_set_peace.cpp @@ -16,21 +16,21 @@ class CommandCSSetPeace : public Command { public: - CommandCSSetPeace(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetPeace(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (params[1] == "ON") + if (params[1].equals_ci("ON")) { ci->SetFlag(CI_PEACE); notice_lang(Config.s_ChanServ, u, CHAN_SET_PEACE_ON, ci->name.c_str()); } - else if (params[1] == "OFF") + else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_PEACE); notice_lang(Config.s_ChanServ, u, CHAN_SET_PEACE_OFF, ci->name.c_str()); @@ -41,13 +41,13 @@ class CommandCSSetPeace : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_PEACE, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET PEACE", CHAN_SET_PEACE_SYNTAX); } @@ -61,17 +61,17 @@ class CommandCSSetPeace : public Command class CommandCSSASetPeace : public CommandCSSetPeace { public: - CommandCSSASetPeace(const ci::string &cname) : CommandCSSetPeace(cname, "chanserv/saset/peace") + CommandCSSASetPeace(const Anope::string &cname) : CommandCSSetPeace(cname, "chanserv/saset/peace") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_PEACE, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SASET PEACE", CHAN_SASET_PEACE_SYNTAX); } @@ -80,7 +80,7 @@ class CommandCSSASetPeace : public CommandCSSetPeace class CSSetPeace : public Module { public: - CSSetPeace(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetPeace(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_persist.cpp b/modules/core/cs_set_persist.cpp index d03e3874d..b2876d476 100644 --- a/modules/core/cs_set_persist.cpp +++ b/modules/core/cs_set_persist.cpp @@ -16,18 +16,18 @@ class CommandCSSetPersist : public Command { public: - CommandCSSetPersist(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetPersist(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PERM); - if (params[0] == "ON") + if (params[1].equals_ci("ON")) { if (!ci->HasFlag(CI_PERSIST)) { @@ -55,7 +55,7 @@ class CommandCSSetPersist : public Command notice_lang(Config.s_ChanServ, u, CHAN_SET_PERSIST_ON, ci->name.c_str()); } - else if (params[0] == "OFF") + else if (params[1].equals_ci("OFF")) { if (ci->HasFlag(CI_PERSIST)) { @@ -64,13 +64,13 @@ class CommandCSSetPersist : public Command /* Unset perm mode */ if (cm && ci->c && ci->c->HasMode(CMODE_PERM)) ci->c->RemoveMode(NULL, cm); - if (Config.s_BotServ && ci->bi && ci->c->FindUser(ci->bi)) + if (!Config.s_BotServ.empty() && ci->bi && ci->c->FindUser(ci->bi)) ci->bi->Part(ci->c); /* No channel mode, no BotServ, but using ChanServ as the botserv bot * which was assigned when persist was set on */ - if (!cm && !Config.s_BotServ && ci->bi) + if (!cm && Config.s_BotServ.empty() && ci->bi) /* Unassign bot */ ChanServ->UnAssign(NULL, ci); @@ -86,13 +86,13 @@ class CommandCSSetPersist : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_PERSIST, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET PERSIST", CHAN_SET_PERSIST_SYNTAX); } @@ -106,17 +106,17 @@ class CommandCSSetPersist : public Command class CommandCSSASetPersist : public CommandCSSetPersist { public: - CommandCSSASetPersist(const ci::string &cname) : CommandCSSetPersist(cname, "chanserv/saset/persist") + CommandCSSASetPersist(const Anope::string &cname) : CommandCSSetPersist(cname, "chanserv/saset/persist") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_PERSIST, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SASET PERSIST", CHAN_SASET_PERSIST_SYNTAX); } @@ -125,7 +125,7 @@ class CommandCSSASetPersist : public CommandCSSetPersist class CSSetPersist : public Module { public: - CSSetPersist(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetPersist(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_private.cpp b/modules/core/cs_set_private.cpp index ed618c6ca..8ade236c8 100644 --- a/modules/core/cs_set_private.cpp +++ b/modules/core/cs_set_private.cpp @@ -16,21 +16,21 @@ class CommandCSSetPrivate : public Command { public: - CommandCSSetPrivate(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetPrivate(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (params[1] == "ON") + if (params[1].equals_ci("ON")) { ci->SetFlag(CI_PRIVATE); notice_lang(Config.s_ChanServ, u, CHAN_SET_PRIVATE_ON, ci->name.c_str()); } - else if (params[1] == "OFF") + else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_PRIVATE); notice_lang(Config.s_ChanServ, u, CHAN_SET_PRIVATE_OFF, ci->name.c_str()); @@ -41,13 +41,13 @@ class CommandCSSetPrivate : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_PRIVATE, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET PRIVATE", CHAN_SET_PRIVATE_SYNTAX); } @@ -61,17 +61,17 @@ class CommandCSSetPrivate : public Command class CommandCSSASetPrivate : public CommandCSSetPrivate { public: - CommandCSSASetPrivate(const ci::string &cname) : CommandCSSetPrivate(cname, "chanserv/saset/private") + CommandCSSASetPrivate(const Anope::string &cname) : CommandCSSetPrivate(cname, "chanserv/saset/private") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_PRIVATE, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SASET PRIVATE", CHAN_SASET_PRIVATE_SYNTAX); } @@ -80,7 +80,7 @@ class CommandCSSASetPrivate : public CommandCSSetPrivate class CSSetPrivate : public Module { public: - CSSetPrivate(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetPrivate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_restricted.cpp b/modules/core/cs_set_restricted.cpp index 5d9537443..82520bbcc 100644 --- a/modules/core/cs_set_restricted.cpp +++ b/modules/core/cs_set_restricted.cpp @@ -15,23 +15,23 @@ class CommandCSSetRestricted : public Command { public: - CommandCSSetRestricted(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetRestricted(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (params[1] == "ON") + if (params[1].equals_ci("ON")) { ci->SetFlag(CI_RESTRICTED); if (ci->levels[CA_NOJOIN] < 0) ci->levels[CA_NOJOIN] = 0; notice_lang(Config.s_ChanServ, u, CHAN_SET_RESTRICTED_ON, ci->name.c_str()); } - else if (params[1] == "OFF") + else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_RESTRICTED); if (ci->levels[CA_NOJOIN] >= 0) @@ -44,13 +44,13 @@ class CommandCSSetRestricted : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_RESTRICTED, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET RESTRICTED", CHAN_SET_RESTRICTED_SYNTAX); } @@ -64,17 +64,17 @@ class CommandCSSetRestricted : public Command class CommandCSSASetRestricted : public CommandCSSetRestricted { public: - CommandCSSASetRestricted(const ci::string &cname) : CommandCSSetRestricted(cname, "chanserv/saset/restricted") + CommandCSSASetRestricted(const Anope::string &cname) : CommandCSSetRestricted(cname, "chanserv/saset/restricted") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_RESTRICTED, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SASET RESTRICTED", CHAN_SASET_RESTRICTED_SYNTAX); } @@ -83,7 +83,7 @@ class CommandCSSASetRestricted : public CommandCSSetRestricted class CSSetRestricted : public Module { public: - CSSetRestricted(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetRestricted(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_secure.cpp b/modules/core/cs_set_secure.cpp index d5f26fcba..817608987 100644 --- a/modules/core/cs_set_secure.cpp +++ b/modules/core/cs_set_secure.cpp @@ -16,21 +16,21 @@ class CommandCSSetSecure : public Command { public: - CommandCSSetSecure(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetSecure(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (params[1] == "ON") + if (params[1].equals_ci("ON")) { ci->SetFlag(CI_SECURE); notice_lang(Config.s_ChanServ, u, CHAN_SET_SECURE_ON, ci->name.c_str()); } - else if (params[1] == "OFF") + else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_SECURE); notice_lang(Config.s_ChanServ, u, CHAN_SET_SECURE_OFF, ci->name.c_str()); @@ -41,13 +41,13 @@ class CommandCSSetSecure : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_SECURE, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET SECURE", CHAN_SET_SECURE_SYNTAX); } @@ -61,17 +61,17 @@ class CommandCSSetSecure : public Command class CommandCSSASetSecure : public CommandCSSetSecure { public: - CommandCSSASetSecure(const ci::string &cname) : CommandCSSetSecure(cname, "chanserv/saset/secure") + CommandCSSASetSecure(const Anope::string &cname) : CommandCSSetSecure(cname, "chanserv/saset/secure") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_SECURE, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SASET SECURE", CHAN_SASET_SECURE_SYNTAX); } @@ -80,7 +80,7 @@ class CommandCSSASetSecure : public CommandCSSetSecure class CSSetSecure : public Module { public: - CSSetSecure(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetSecure(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_securefounder.cpp b/modules/core/cs_set_securefounder.cpp index cda7deef8..7c2e310d9 100644 --- a/modules/core/cs_set_securefounder.cpp +++ b/modules/core/cs_set_securefounder.cpp @@ -16,11 +16,11 @@ class CommandCSSetSecureFounder : public Command { public: - CommandCSSetSecureFounder(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetSecureFounder(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); @@ -31,12 +31,12 @@ class CommandCSSetSecureFounder : public Command return MOD_CONT; } - if (params[1] == "ON") + if (params[1].equals_ci("ON")) { ci->SetFlag(CI_SECUREFOUNDER); notice_lang(Config.s_ChanServ, u, CHAN_SET_SECUREFOUNDER_ON, ci->name.c_str()); } - else if (params[1] == "OFF") + else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_SECUREFOUNDER); notice_lang(Config.s_ChanServ, u, CHAN_SET_SECUREFOUNDER_OFF, ci->name.c_str()); @@ -47,13 +47,13 @@ class CommandCSSetSecureFounder : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_SECUREFOUNDER, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET SECUREFOUNDER", CHAN_SET_SECUREFOUNDER_SYNTAX); } @@ -67,17 +67,17 @@ class CommandCSSetSecureFounder : public Command class CommandCSSASetSecureFounder : public CommandCSSetSecureFounder { public: - CommandCSSASetSecureFounder(const ci::string &cname) : CommandCSSetSecureFounder(cname, "chanserv/saset/securefounder") + CommandCSSASetSecureFounder(const Anope::string &cname) : CommandCSSetSecureFounder(cname, "chanserv/saset/securefounder") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_SECUREFOUNDER, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SASET SECUREFOUNDER", CHAN_SASET_SECUREFOUNDER_SYNTAX); } @@ -86,7 +86,7 @@ class CommandCSSASetSecureFounder : public CommandCSSetSecureFounder class CSSetSecureFounder : public Module { public: - CSSetSecureFounder(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetSecureFounder(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_secureops.cpp b/modules/core/cs_set_secureops.cpp index 8409018d2..6d705dd6a 100644 --- a/modules/core/cs_set_secureops.cpp +++ b/modules/core/cs_set_secureops.cpp @@ -16,21 +16,21 @@ class CommandCSSetSecureOps : public Command { public: - CommandCSSetSecureOps(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetSecureOps(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (params[1] == "ON") + if (params[1].equals_ci("ON")) { ci->SetFlag(CI_SECUREOPS); notice_lang(Config.s_ChanServ, u, CHAN_SET_SECUREOPS_ON, ci->name.c_str()); } - else if (params[1] == "OFF") + else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_SECUREOPS); notice_lang(Config.s_ChanServ, u, CHAN_SET_SECUREOPS_OFF, ci->name.c_str()); @@ -41,13 +41,13 @@ class CommandCSSetSecureOps : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_SECUREOPS, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET SECUREOPS", CHAN_SET_SECUREOPS_SYNTAX); } @@ -61,17 +61,17 @@ class CommandCSSetSecureOps : public Command class CommandCSSASetSecureOps : public CommandCSSetSecureOps { public: - CommandCSSASetSecureOps(const ci::string &cname) : CommandCSSetSecureOps(cname, "chanserv/saset/secureops") + CommandCSSASetSecureOps(const Anope::string &cname) : CommandCSSetSecureOps(cname, "chanserv/saset/secureops") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_SECUREOPS, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SASET SECUREOPS", CHAN_SASET_SECUREOPS_SYNTAX); } @@ -80,7 +80,7 @@ class CommandCSSASetSecureOps : public CommandCSSetSecureOps class CSSetSecureOps : public Module { public: - CSSetSecureOps(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetSecureOps(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_signkick.cpp b/modules/core/cs_set_signkick.cpp index b792ec9c9..93e5c287a 100644 --- a/modules/core/cs_set_signkick.cpp +++ b/modules/core/cs_set_signkick.cpp @@ -16,28 +16,28 @@ class CommandCSSetSignKick : public Command { public: - CommandCSSetSignKick(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetSignKick(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (params[1] == "ON") + if (params[1].equals_ci("ON")) { ci->SetFlag(CI_SIGNKICK); ci->UnsetFlag(CI_SIGNKICK_LEVEL); notice_lang(Config.s_ChanServ, u, CHAN_SET_SIGNKICK_ON, ci->name.c_str()); } - else if (params[1] == "LEVEL") + else if (params[1].equals_ci("LEVEL")) { ci->SetFlag(CI_SIGNKICK_LEVEL); ci->UnsetFlag(CI_SIGNKICK); notice_lang(Config.s_ChanServ, u, CHAN_SET_SIGNKICK_LEVEL, ci->name.c_str()); } - else if (params[1] == "OFF") + else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_SIGNKICK); ci->UnsetFlag(CI_SIGNKICK_LEVEL); @@ -49,13 +49,13 @@ class CommandCSSetSignKick : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_SIGNKICK, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET SIGNKICK", CHAN_SET_SIGNKICK_SYNTAX); } @@ -69,17 +69,17 @@ class CommandCSSetSignKick : public Command class CommandCSSASetSignKick : public CommandCSSetSignKick { public: - CommandCSSASetSignKick(const ci::string &cname) : CommandCSSetSignKick(cname, "chanserv/saset/signkick") + CommandCSSASetSignKick(const Anope::string &cname) : CommandCSSetSignKick(cname, "chanserv/saset/signkick") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_SIGNKICK, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SASET SIGNKICK", CHAN_SASET_SIGNKICK_SYNTAX); } @@ -88,7 +88,7 @@ class CommandCSSASetSignKick : public CommandCSSetSignKick class CSSetSignKick : public Module { public: - CSSetSignKick(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetSignKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); @@ -96,6 +96,10 @@ class CSSetSignKick : public Module Command *c = FindCommand(ChanServ, "SET"); if (c) c->AddSubcommand(new CommandCSSetSignKick("SIGNKICK")); + + c = FindCommand(ChanServ, "SASET"); + if (c) + c->AddSubcommand(new CommandCSSASetSignKick("SIGNKICK")); } ~CSSetSignKick() @@ -103,6 +107,10 @@ class CSSetSignKick : public Module Command *c = FindCommand(ChanServ, "SET"); if (c) c->DelSubcommand("SIGNKICK"); + + c = FindCommand(ChanServ, "SASET"); + if (c) + c->DelSubcommand("SIGNKICK"); } }; diff --git a/modules/core/cs_set_successor.cpp b/modules/core/cs_set_successor.cpp index f5517b8a9..4ba445300 100644 --- a/modules/core/cs_set_successor.cpp +++ b/modules/core/cs_set_successor.cpp @@ -16,11 +16,11 @@ class CommandCSSetSuccessor : public Command { public: - CommandCSSetSuccessor(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 1, 2, cpermission) + CommandCSSetSuccessor(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 1, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); @@ -44,16 +44,15 @@ class CommandCSSetSuccessor : public Command } if (na->HasFlag(NS_FORBIDDEN)) { - notice_lang(Config.s_ChanServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_ChanServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); return MOD_CONT; } if (na->nc == ci->founder) { - notice_lang(Config.s_ChanServ, u, CHAN_SUCCESSOR_IS_FOUNDER, na->nick, ci->name.c_str()); + notice_lang(Config.s_ChanServ, u, CHAN_SUCCESSOR_IS_FOUNDER, na->nick.c_str(), ci->name.c_str()); return MOD_CONT; } nc = na->nc; - } else nc = NULL; @@ -63,20 +62,20 @@ class CommandCSSetSuccessor : public Command ci->successor = nc; if (nc) - notice_lang(Config.s_ChanServ, u, CHAN_SUCCESSOR_CHANGED, ci->name.c_str(), nc->display); + notice_lang(Config.s_ChanServ, u, CHAN_SUCCESSOR_CHANGED, ci->name.c_str(), nc->display.c_str()); else notice_lang(Config.s_ChanServ, u, CHAN_SUCCESSOR_UNSET, ci->name.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_SUCCESSOR, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_ChanServ, u, "SET", CHAN_SET_SYNTAX); @@ -91,27 +90,27 @@ class CommandCSSetSuccessor : public Command class CommandCSSASetSuccessor : public CommandCSSetSuccessor { public: - CommandCSSASetSuccessor(const ci::string &cname) : CommandCSSetSuccessor(cname, "chanserv/saset/successor") + CommandCSSASetSuccessor(const Anope::string &cname) : CommandCSSetSuccessor(cname, "chanserv/saset/successor") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_SUCCESSOR, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX - syntax_error(Config.s_ChanServ, u, "SASEt", CHAN_SASET_SYNTAX); + syntax_error(Config.s_ChanServ, u, "SASET", CHAN_SASET_SYNTAX); } }; class CSSetSuccessor : public Module { public: - CSSetSuccessor(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetSuccessor(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_topiclock.cpp b/modules/core/cs_set_topiclock.cpp index 5e89862f6..26f053b69 100644 --- a/modules/core/cs_set_topiclock.cpp +++ b/modules/core/cs_set_topiclock.cpp @@ -16,21 +16,21 @@ class CommandCSSetTopicLock : public Command { public: - CommandCSSetTopicLock(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetTopicLock(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (params[1] == "ON") + if (params[1].equals_ci("ON")) { ci->SetFlag(CI_TOPICLOCK); notice_lang(Config.s_ChanServ, u, CHAN_SET_TOPICLOCK_ON, ci->name.c_str()); } - else if (params[1] == "OFF") + else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_TOPICLOCK); notice_lang(Config.s_ChanServ, u, CHAN_SET_TOPICLOCK_OFF, ci->name.c_str()); @@ -41,13 +41,13 @@ class CommandCSSetTopicLock : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_TOPICLOCK, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET", CHAN_SET_TOPICLOCK_SYNTAX);; } @@ -61,17 +61,17 @@ class CommandCSSetTopicLock : public Command class CommandCSSASetTopicLock : public CommandCSSetTopicLock { public: - CommandCSSASetTopicLock(const ci::string &cname) : CommandCSSetTopicLock(cname, "chanserv/saset/topiclock") + CommandCSSASetTopicLock(const Anope::string &cname) : CommandCSSetTopicLock(cname, "chanserv/saset/topiclock") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_TOPICLOCK, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SASET", CHAN_SASET_TOPICLOCK_SYNTAX); } @@ -80,7 +80,7 @@ class CommandCSSASetTopicLock : public CommandCSSetTopicLock class CSSetTopicLock : public Module { public: - CSSetTopicLock(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetTopicLock(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_set_xop.cpp b/modules/core/cs_set_xop.cpp index 854989fba..37247f394 100644 --- a/modules/core/cs_set_xop.cpp +++ b/modules/core/cs_set_xop.cpp @@ -17,11 +17,11 @@ class CommandCSSetXOP : public Command { public: - CommandCSSetXOP(const ci::string &cname, const ci::string &cpermission = "") : Command(cname, 2, 2, cpermission) + CommandCSSetXOP(const Anope::string &cname, const Anope::string &cpermission = "") : Command(cname, 2, 2, cpermission) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { if (!FindModule("cs_xop")) { @@ -32,7 +32,7 @@ class CommandCSSetXOP : public Command ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - if (params[1] == "ON") + if (params[1].equals_ci("ON")) { if (!ci->HasFlag(CI_XOP)) { @@ -66,7 +66,7 @@ class CommandCSSetXOP : public Command Alog() << Config.s_ChanServ << ": " << u->GetMask() << " enabled XOP for " << ci->name; notice_lang(Config.s_ChanServ, u, CHAN_SET_XOP_ON, ci->name.c_str()); } - else if (params[1] == "OFF") + else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_XOP); @@ -79,13 +79,13 @@ class CommandCSSetXOP : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_XOP, "SET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET XOP", CHAN_SET_XOP_SYNTAX); } @@ -99,17 +99,17 @@ class CommandCSSetXOP : public Command class CommandCSSASetXOP : public CommandCSSetXOP { public: - CommandCSSASetXOP(const ci::string &cname) : CommandCSSetXOP(cname, "chanserv/saset/xop") + CommandCSSASetXOP(const Anope::string &cname) : CommandCSSetXOP(cname, "chanserv/saset/xop") { } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SET_XOP, "SASET"); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SASET XOP", CHAN_SASET_XOP_SYNTAX); } @@ -118,7 +118,7 @@ class CommandCSSASetXOP : public CommandCSSetXOP class CSSetXOP : public Module { public: - CSSetXOP(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetXOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); @@ -126,6 +126,10 @@ class CSSetXOP : public Module Command *c = FindCommand(ChanServ, "SET"); if (c) c->AddSubcommand(new CommandCSSetXOP("XOP")); + + c = FindCommand(ChanServ, "SASET"); + if (c) + c->AddSubcommand(new CommandCSSASetXOP("XOP")); } ~CSSetXOP() @@ -133,6 +137,10 @@ class CSSetXOP : public Module Command *c = FindCommand(ChanServ, "SET"); if (c) c->DelSubcommand("XOP"); + + c = FindCommand(ChanServ, "SASET"); + if (c) + c->DelSubcommand("XOP"); } }; diff --git a/modules/core/cs_status.cpp b/modules/core/cs_status.cpp index 31dab055c..01c95796d 100644 --- a/modules/core/cs_status.cpp +++ b/modules/core/cs_status.cpp @@ -20,13 +20,13 @@ class CommandCSStatus : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci; User *u2; - const char *chan = params[0].c_str(); - const char *nick = params[1].c_str(); - const char *temp = NULL; + Anope::string chan = params[0]; + Anope::string nick = params[1]; + Anope::string temp; if (!(ci = cs_findchan(chan))) { @@ -36,21 +36,21 @@ class CommandCSStatus : public Command ci = cs_findchan(chan); } if (!ci) - notice_lang(Config.s_ChanServ, u, CHAN_STATUS_NOT_REGGED, temp); + notice_lang(Config.s_ChanServ, u, CHAN_STATUS_NOT_REGGED, temp.c_str()); else if ((u2 = finduser(nick))) - notice_lang(Config.s_ChanServ, u, CHAN_STATUS_INFO, chan, nick, get_access(u2, ci)); + notice_lang(Config.s_ChanServ, u, CHAN_STATUS_INFO, chan.c_str(), nick.c_str(), get_access(u2, ci)); else /* !u2 */ - notice_lang(Config.s_ChanServ, u, CHAN_STATUS_NOTONLINE, nick); + notice_lang(Config.s_ChanServ, u, CHAN_STATUS_NOTONLINE, nick.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_SERVADMIN_HELP_STATUS); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "STATUS", CHAN_STATUS_SYNTAX); } @@ -64,10 +64,12 @@ class CommandCSStatus : public Command class CSStatus : public Module { public: - CSStatus(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSStatus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + + this->AddCommand(ChanServ, new CommandCSStatus()); } }; diff --git a/modules/core/cs_suspend.cpp b/modules/core/cs_suspend.cpp index 8878e5552..53bbaec92 100644 --- a/modules/core/cs_suspend.cpp +++ b/modules/core/cs_suspend.cpp @@ -20,16 +20,16 @@ class CommandCSSuspend : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - const char *reason = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string chan = params[0]; + Anope::string reason = params.size() > 1 ? params[1] : ""; ChannelInfo *ci = cs_findchan(chan); Channel *c; /* Assumes that permission checking has already been done. */ - if (Config.ForceForbidReason && !reason) + if (Config.ForceForbidReason && reason.empty()) { this->OnSyntaxError(u, ""); return MOD_CONT; @@ -44,7 +44,7 @@ class CommandCSSuspend : public Command /* You should not SUSPEND a FORBIDEN channel */ if (ci->HasFlag(CI_FORBIDDEN)) { - notice_lang(Config.s_ChanServ, u, CHAN_MAY_NOT_BE_REGISTERED, chan); + notice_lang(Config.s_ChanServ, u, CHAN_MAY_NOT_BE_REGISTERED, chan.c_str()); return MOD_CONT; } @@ -54,9 +54,9 @@ class CommandCSSuspend : public Command if (ci) { ci->SetFlag(CI_SUSPENDED); - ci->forbidby = sstrdup(u->nick.c_str()); - if (reason) - ci->forbidreason = sstrdup(reason); + ci->forbidby = u->nick; + if (!reason.empty()) + ci->forbidreason = reason; if ((c = findchan(ci->name))) { @@ -67,7 +67,7 @@ class CommandCSSuspend : public Command if (is_oper(uc->user)) continue; - c->Kick(NULL, uc->user, "%s", reason ? reason : getstring(uc->user->Account(), CHAN_SUSPEND_REASON)); + c->Kick(NULL, uc->user, "%s", !reason.empty() ? reason.c_str() : getstring(uc->user->Account(), CHAN_SUSPEND_REASON)); } } @@ -75,25 +75,25 @@ class CommandCSSuspend : public Command ircdproto->SendGlobops(ChanServ, "\2%s\2 used SUSPEND on channel \2%s\2", u->nick.c_str(), ci->name.c_str()); Alog() << Config.s_ChanServ << ": " << u->GetMask() << " set SUSPEND for channel " << ci->name; - notice_lang(Config.s_ChanServ, u, CHAN_SUSPEND_SUCCEEDED, chan); + notice_lang(Config.s_ChanServ, u, CHAN_SUSPEND_SUCCEEDED, chan.c_str()); FOREACH_MOD(I_OnChanSuspend, OnChanSuspend(ci)); } else { Alog() << Config.s_ChanServ << ": Valid SUSPEND for " << ci->name << " by " << u->GetMask() << " failed"; - notice_lang(Config.s_ChanServ, u, CHAN_SUSPEND_FAILED, chan); + notice_lang(Config.s_ChanServ, u, CHAN_SUSPEND_FAILED, chan.c_str()); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_SERVADMIN_HELP_SUSPEND); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "SUSPEND", Config.ForceForbidReason ? CHAN_SUSPEND_SYNTAX_REASON : CHAN_SUSPEND_SYNTAX); } @@ -112,9 +112,9 @@ class CommandCSUnSuspend : public Command this->SetFlag(CFLAG_ALLOW_SUSPENDED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); + Anope::string chan = params[0]; ChannelInfo *ci = cs_findchan(chan); if (chan[0] != '#') @@ -126,49 +126,41 @@ class CommandCSUnSuspend : public Command notice_lang(Config.s_ChanServ, u, READ_ONLY_MODE); /* Only UNSUSPEND already suspended channels */ - if (!(ci->HasFlag(CI_SUSPENDED))) + if (!ci->HasFlag(CI_SUSPENDED)) { - notice_lang(Config.s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan); + notice_lang(Config.s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan.c_str()); return MOD_CONT; } if (ci) { ci->UnsetFlag(CI_SUSPENDED); - if (ci->forbidreason) - { - delete [] ci->forbidreason; - ci->forbidreason = NULL; - } - if (ci->forbidby) - { - delete [] ci->forbidby; - ci->forbidby = NULL; - } + ci->forbidreason.clear(); + ci->forbidby.clear(); if (Config.WallForbid) ircdproto->SendGlobops(ChanServ, "\2%s\2 used UNSUSPEND on channel \2%s\2", u->nick.c_str(), ci->name.c_str()); Alog() << Config.s_ChanServ << ": " << u->GetMask() << " set UNSUSPEND for channel " << ci->name; - notice_lang(Config.s_ChanServ, u, CHAN_UNSUSPEND_SUCCEEDED, chan); + notice_lang(Config.s_ChanServ, u, CHAN_UNSUSPEND_SUCCEEDED, chan.c_str()); FOREACH_MOD(I_OnChanUnsuspend, OnChanUnsuspend(ci)); } else { Alog() << Config.s_ChanServ << ": Valid UNSUSPEND for " << chan << " by " << u->nick << " failed"; - notice_lang(Config.s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan); + notice_lang(Config.s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan.c_str()); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_SERVADMIN_HELP_UNSUSPEND); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "UNSUSPEND", CHAN_UNSUSPEND_SYNTAX); } @@ -182,7 +174,7 @@ class CommandCSUnSuspend : public Command class CSSuspend : public Module { public: - CSSuspend(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_topic.cpp b/modules/core/cs_topic.cpp index f408eaedf..d0a6843b5 100644 --- a/modules/core/cs_topic.cpp +++ b/modules/core/cs_topic.cpp @@ -20,10 +20,10 @@ class CommandCSTopic : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - const char *topic = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string chan = params[0]; + Anope::string topic = params.size() > 1 ? params[1] : ""; Channel *c; ChannelInfo *ci; @@ -32,20 +32,16 @@ class CommandCSTopic : public Command ci = c->ci; if (!c) - notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); else if (!check_access(u, ci, CA_TOPIC) && !u->Account()->HasCommand("chanserv/topic")) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else { - if (ci->last_topic) - delete [] ci->last_topic; - ci->last_topic = topic ? sstrdup(topic) : NULL; + ci->last_topic = topic; ci->last_topic_setter = u->nick; ci->last_topic_time = time(NULL); - if (c->topic) - delete [] c->topic; - c->topic = topic ? sstrdup(topic) : NULL; + c->topic = topic; c->topic_setter = u->nick; if (ircd->topictsbackward) c->topic_time = c->topic_time - 1; @@ -57,22 +53,22 @@ class CommandCSTopic : public Command if (ircd->join2set && whosends(ci) == ChanServ) { ChanServ->Join(c); - ircdproto->SendMode(NULL, c, "+o %s", Config.s_ChanServ); // XXX + ircdproto->SendMode(NULL, c, "+o %s", Config.s_ChanServ.c_str()); // XXX } - ircdproto->SendTopic(whosends(ci), c, u->nick.c_str(), topic ? topic : ""); + ircdproto->SendTopic(whosends(ci), c, u->nick, topic); if (ircd->join2set && whosends(ci) == ChanServ) ChanServ->Part(c); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_TOPIC); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "TOPIC", CHAN_TOPIC_SYNTAX); } @@ -86,7 +82,7 @@ class CommandCSTopic : public Command class CSTopic : public Module { public: - CSTopic(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSTopic(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_unban.cpp b/modules/core/cs_unban.cpp index 9085d46a1..0d248b8eb 100644 --- a/modules/core/cs_unban.cpp +++ b/modules/core/cs_unban.cpp @@ -20,15 +20,15 @@ class CommandCSUnban : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); + Anope::string chan = params[0]; Channel *c; User *u2; if (!(c = findchan(chan))) { - notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); return MOD_CONT; } @@ -56,13 +56,13 @@ class CommandCSUnban : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_UNBAN); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "UNBAN", CHAN_UNBAN_SYNTAX); } @@ -76,7 +76,7 @@ class CommandCSUnban : public Command class CSUnban : public Module { public: - CSUnban(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSUnban(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/cs_xop.cpp b/modules/core/cs_xop.cpp index b4c5cd24d..ca11c74fe 100644 --- a/modules/core/cs_xop.cpp +++ b/modules/core/cs_xop.cpp @@ -117,7 +117,7 @@ class XOPListCallback : public NumberList int *messages; bool SentHeader; public: - XOPListCallback(User *_u, ChannelInfo *_ci, const std::string &numlist, int _level, int *_messages) : NumberList(numlist, false), u(_u), ci(_ci), level(_level), messages(_messages), SentHeader(false) + XOPListCallback(User *_u, ChannelInfo *_ci, const Anope::string &numlist, int _level, int *_messages) : NumberList(numlist, false), u(_u), ci(_ci), level(_level), messages(_messages), SentHeader(false) { } @@ -142,7 +142,7 @@ class XOPListCallback : public NumberList static void DoList(User *u, ChannelInfo *ci, ChanAccess *access, unsigned index, int level, int *messages) { - notice_lang(Config.s_ChanServ, u, CHAN_XOP_LIST_FORMAT, index, access->nc->display); + notice_lang(Config.s_ChanServ, u, CHAN_XOP_LIST_FORMAT, index, access->nc->display.c_str()); } }; @@ -152,9 +152,9 @@ class XOPDelCallback : public NumberList ChannelInfo *ci; int *messages; unsigned Deleted; - std::string Nicks; + Anope::string Nicks; public: - XOPDelCallback(User *_u, ChannelInfo *_ci, int *_messages, const std::string &numlist) : NumberList(numlist, true), u(_u), ci(_ci), messages(_messages), Deleted(0) + XOPDelCallback(User *_u, ChannelInfo *_ci, int *_messages, const Anope::string &numlist) : NumberList(numlist, true), u(_u), ci(_ci), messages(_messages), Deleted(0) { } @@ -182,7 +182,7 @@ class XOPDelCallback : public NumberList ++Deleted; if (!Nicks.empty()) - Nicks += ", " + std::string(access->nc->display); + Nicks += ", " + access->nc->display; else Nicks = access->nc->display; @@ -195,13 +195,13 @@ class XOPDelCallback : public NumberList class XOPBase : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<ci::string> ¶ms, ChannelInfo *ci, int level, int *messages) + CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms, ChannelInfo *ci, int level, int *messages) { - const char *nick = params.size() > 2 ? params[2].c_str() : NULL; + Anope::string nick = params.size() > 2 ? params[2] : ""; ChanAccess *access; int change = 0; - if (!nick) + if (nick.empty()) { this->OnSyntaxError(u, "ADD"); return MOD_CONT; @@ -229,7 +229,7 @@ class XOPBase : public Command } else if (na->HasFlag(NS_FORBIDDEN)) { - notice_lang(Config.s_ChanServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_ChanServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); return MOD_CONT; } @@ -268,23 +268,23 @@ class XOPBase : public Command if (!change) { FOREACH_MOD(I_OnAccessAdd, OnAccessAdd(ci, u, nc, level)); - notice_lang(Config.s_ChanServ, u, messages[XOP_ADDED], nc->display, ci->name.c_str()); + notice_lang(Config.s_ChanServ, u, messages[XOP_ADDED], nc->display.c_str(), ci->name.c_str()); } else { FOREACH_MOD(I_OnAccessChange, OnAccessChange(ci, u, na->nc, level)); - notice_lang(Config.s_ChanServ, u, messages[XOP_MOVED], nc->display, ci->name.c_str()); + notice_lang(Config.s_ChanServ, u, messages[XOP_MOVED], nc->display.c_str(), ci->name.c_str()); } return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<ci::string> ¶ms, ChannelInfo *ci, int level, int *messages) + CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms, ChannelInfo *ci, int level, int *messages) { - const char *nick = params.size() > 2 ? params[2].c_str() : NULL; + Anope::string nick = params.size() > 2 ? params[2] : ""; ChanAccess *access; - if (!nick) + if (nick.empty()) { this->OnSyntaxError(u, "DEL"); return MOD_CONT; @@ -311,7 +311,7 @@ class XOPBase : public Command } /* Special case: is it a number/list? Only do search if it isn't. */ - if (isdigit(*nick) && strspn(nick, "1234567890,-") == strlen(nick)) + if (isdigit(nick[0]) && nick.find_first_not_of("1234567890,-") == Anope::string::npos) { XOPDelCallback list(u, ci, messages, nick); list.Process(); @@ -321,7 +321,7 @@ class XOPBase : public Command NickAlias *na = findnick(nick); if (!na) { - notice_lang(Config.s_ChanServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_ChanServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); return MOD_CONT; } NickCore *nc = na->nc; @@ -337,7 +337,7 @@ class XOPBase : public Command if (i == end) { - notice_lang(Config.s_ChanServ, u, messages[XOP_NOT_FOUND], nick, ci->name.c_str()); + notice_lang(Config.s_ChanServ, u, messages[XOP_NOT_FOUND], nick.c_str(), ci->name.c_str()); return MOD_CONT; } @@ -347,7 +347,7 @@ class XOPBase : public Command { Alog() << Config.s_ChanServ << ": " << u->GetMask() << " (level " << get_access(u, ci) << ") deleted access of user " << access->nc->display << " on " << ci->name; - notice_lang(Config.s_ChanServ, u, messages[XOP_DELETED], access->nc->display, ci->name.c_str()); + notice_lang(Config.s_ChanServ, u, messages[XOP_DELETED], access->nc->display.c_str(), ci->name.c_str()); FOREACH_MOD(I_OnAccessDel, OnAccessDel(ci, u, na->nc)); @@ -358,9 +358,9 @@ class XOPBase : public Command return MOD_CONT; } - CommandReturn DoList(User *u, const std::vector<ci::string> ¶ms, ChannelInfo *ci, int level, int *messages) + CommandReturn DoList(User *u, const std::vector<Anope::string> ¶ms, ChannelInfo *ci, int level, int *messages) { - const char *nick = params.size() > 2 ? params[2].c_str() : NULL; + Anope::string nick = params.size() > 2 ? params[2] : ""; if (!get_access(u, ci) && !u->Account()->HasCommand("chanserv/access/list")) { @@ -374,7 +374,7 @@ class XOPBase : public Command return MOD_CONT; } - if (nick && strspn(nick, "1234567890,-") == strlen(nick)) + if (!nick.empty() && nick.find_first_not_of("1234567890,-") == Anope::string::npos) { XOPListCallback list(u, ci, nick, level, messages); list.Process(); @@ -387,7 +387,7 @@ class XOPBase : public Command { ChanAccess *access = ci->GetAccess(i); - if (nick && access->nc && !Anope::Match(access->nc->display, nick, false)) + if (!nick.empty() && access->nc && !Anope::Match(access->nc->display, nick)) continue; if (!SentHeader) @@ -406,7 +406,7 @@ class XOPBase : public Command return MOD_CONT; } - CommandReturn DoClear(User *u, const std::vector<ci::string> ¶ms, ChannelInfo *ci, int level, int *messages) + CommandReturn DoClear(User *u, ChannelInfo *ci, int level, int *messages) { if (readonly) { @@ -440,29 +440,29 @@ class XOPBase : public Command return MOD_CONT; } protected: - CommandReturn DoXop(User *u, const std::vector<ci::string> ¶ms, int level, int *messages) + CommandReturn DoXop(User *u, const std::vector<Anope::string> ¶ms, int level, int *messages) { - const char *chan = params[0].c_str(); - ci::string cmd = params[1]; + Anope::string chan = params[0]; + Anope::string cmd = params[1]; ChannelInfo *ci = cs_findchan(chan); - if (!(ci->HasFlag(CI_XOP))) - notice_lang(Config.s_ChanServ, u, CHAN_XOP_ACCESS, Config.s_ChanServ); - else if (cmd == "ADD") + if (!ci->HasFlag(CI_XOP)) + notice_lang(Config.s_ChanServ, u, CHAN_XOP_ACCESS, Config.s_ChanServ.c_str()); + else if (cmd.equals_ci("ADD")) return this->DoAdd(u, params, ci, level, messages); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) return this->DoDel(u, params, ci, level, messages); - else if (cmd == "LIST") + else if (cmd.equals_ci("LIST")) return this->DoList(u, params, ci, level, messages); - else if (cmd == "CLEAR") - return this->DoClear(u, params, ci, level, messages); + else if (cmd.equals_ci("CLEAR")) + return this->DoClear(u, ci, level, messages); else this->OnSyntaxError(u, ""); return MOD_CONT; } public: - XOPBase(const ci::string &command) : Command(command, 2, 3) + XOPBase(const Anope::string &command) : Command(command, 2, 3) { } @@ -470,11 +470,11 @@ class XOPBase : public Command { } - virtual CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) = 0; + virtual CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) = 0; - virtual bool OnHelp(User *u, const ci::string &subcommand) = 0; + virtual bool OnHelp(User *u, const Anope::string &subcommand) = 0; - virtual void OnSyntaxError(User *u, const ci::string &subcommand) = 0; + virtual void OnSyntaxError(User *u, const Anope::string &subcommand) = 0; virtual void OnServHelp(User *u) = 0; }; @@ -486,18 +486,18 @@ class CommandCSQOP : public XOPBase { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { return this->DoXop(u, params, ACCESS_QOP, xop_msgs[XOP_QOP]); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_QOP); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "QOP", CHAN_QOP_SYNTAX); } @@ -515,18 +515,18 @@ class CommandCSAOP : public XOPBase { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { return this->DoXop(u, params, ACCESS_AOP, xop_msgs[XOP_AOP]); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_AOP); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "AOP", CHAN_AOP_SYNTAX); } @@ -544,18 +544,18 @@ class CommandCSHOP : public XOPBase { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { return this->DoXop(u, params, ACCESS_HOP, xop_msgs[XOP_HOP]); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_HOP); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "HOP", CHAN_HOP_SYNTAX); } @@ -573,18 +573,18 @@ class CommandCSSOP : public XOPBase { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { return this->DoXop(u, params, ACCESS_SOP, xop_msgs[XOP_SOP]); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_SOP); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "SOP", CHAN_SOP_SYNTAX); } @@ -602,18 +602,18 @@ class CommandCSVOP : public XOPBase { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { return this->DoXop(u, params, ACCESS_VOP, xop_msgs[XOP_VOP]); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_ChanServ, u, CHAN_HELP_VOP); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_ChanServ, u, "VOP", CHAN_VOP_SYNTAX); } @@ -627,7 +627,7 @@ class CommandCSVOP : public XOPBase class CSXOP : public Module { public: - CSXOP(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSXOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/db_plain.cpp b/modules/core/db_plain.cpp index 885faf41b..331901f86 100644 --- a/modules/core/db_plain.cpp +++ b/modules/core/db_plain.cpp @@ -13,7 +13,7 @@ #include "module.h" std::fstream db; -std::string DatabaseFile; +Anope::string DatabaseFile; /** Enum used for what METADATA type we are reading */ @@ -56,14 +56,14 @@ static void ReadDatabase(Module *m = NULL) BotInfo *bi = NULL; ChannelInfo *ci = NULL; - std::string buf; - while (std::getline(db, buf)) + Anope::string buf; + while (std::getline(db, buf.str())) { if (buf.empty()) continue; spacesepstream sep(buf); - std::vector<std::string> params; + std::vector<Anope::string> params; while (sep.GetToken(buf)) { if (buf[0] == ':') @@ -90,36 +90,34 @@ static void ReadDatabase(Module *m = NULL) if (!params.empty()) { - if (params[0] == "NC") + if (params[0].equals_ci("NC")) { nc = findcore(params[1]); Type = MD_NC; } - else if (params[0] == "NA") + else if (params[0].equals_ci("NA")) { na = findnick(params[2]); Type = MD_NA; } - else if (params[0] == "NR") + else if (params[0].equals_ci("NR")) { nr = findrequestnick(params[1]); Type = MD_NR; } - else if (params[0] == "BI") + else if (params[0].equals_ci("BI")) { bi = findbot(params[1]); Type = MD_BI; } - else if (params[0] == "CH") + else if (params[0].equals_ci("CH")) { ci = cs_findchan(params[1]); Type = MD_CH; } - else if (params[0] == "MD") + else if (params[0].equals_ci("MD")) { - std::string key = params[1]; - params.erase(params.begin()); - params.erase(params.begin()); + Anope::string key = params[1].substr(2); if (Type == MD_NC && nc) { @@ -130,7 +128,7 @@ static void ReadDatabase(Module *m = NULL) else FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(nc, key, params)); } - catch (DatabaseException& ex) + catch (const DatabaseException &ex) { Alog() << "[db_plain]: " << ex.GetReason(); } @@ -144,7 +142,7 @@ static void ReadDatabase(Module *m = NULL) else FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(na, key, params)); } - catch (DatabaseException& ex) + catch (const DatabaseException &ex) { Alog() << "[db_plain]: " << ex.GetReason(); } @@ -158,7 +156,7 @@ static void ReadDatabase(Module *m = NULL) else FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(nr, key, params)); } - catch (DatabaseException& ex) + catch (const DatabaseException &ex) { Alog() << "[db_plain]: " << ex.GetReason(); } @@ -172,7 +170,7 @@ static void ReadDatabase(Module *m = NULL) else FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(bi, key, params)); } - catch (DatabaseException& ex) + catch (const DatabaseException &ex) { Alog() << "[db_plain]: " << ex.GetReason(); } @@ -186,7 +184,7 @@ static void ReadDatabase(Module *m = NULL) else FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(ci, key, params)); } - catch (DatabaseException& ex) + catch (const DatabaseException &ex) { Alog() << "[db_plain]: " << ex.GetReason(); if (!ci->founder) @@ -205,31 +203,31 @@ static void ReadDatabase(Module *m = NULL) struct LangInfo { - std::string Name; + Anope::string Name; int LanguageId; }; struct ChannelFlagInfo { - std::string Name; + Anope::string Name; ChannelInfoFlag Flag; }; struct ChannelLevel { - std::string Name; + Anope::string Name; int Level; }; struct BotFlagInfo { - std::string Name; + Anope::string Name; BotServFlag Flag; }; struct NickCoreFlagInfo { - std::string Name; + Anope::string Name; NickCoreFlag Flag; }; @@ -353,7 +351,7 @@ NickCoreFlagInfo NickCoreFlags[] = { {"", static_cast<NickCoreFlag>(-1)} }; -static void LoadNickCore(const std::vector<std::string> ¶ms) +static void LoadNickCore(const std::vector<Anope::string> ¶ms) { NickCore *nc = new NickCore(params[0]); /* Clear default flags */ @@ -363,19 +361,19 @@ static void LoadNickCore(const std::vector<std::string> ¶ms) /* This is a forbidden nick */ return; - nc->pass.assign(params[1]); + nc->pass = params[1]; for (int i = 0; LangInfos[i].LanguageId != -1; ++i) - if (params[2] == LangInfos[i].Name) + if (params[2].equals_ci(LangInfos[i].Name)) nc->language = LangInfos[i].LanguageId; - nc->memos.memomax = atoi(params[3].c_str()); - nc->channelcount = atoi(params[4].c_str()); + nc->memos.memomax = params[3].is_number_only() ? convertTo<int16>(params[3]) : 1; + nc->channelcount = params[4].is_number_only() ? convertTo<uint16>(params[4]) : 0; Alog(LOG_DEBUG_2) << "[db_plain]: Loaded NickCore " << nc->display; } -static void LoadNickAlias(const std::vector<std::string> ¶ms) +static void LoadNickAlias(const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); if (!nc) @@ -386,40 +384,40 @@ static void LoadNickAlias(const std::vector<std::string> ¶ms) NickAlias *na = new NickAlias(params[1], nc); - na->time_registered = strtol(params[2].c_str(), NULL, 10); + na->time_registered = params[2].is_number_only() ? convertTo<time_t>(params[2]) : 0; - na->last_seen = strtol(params[3].c_str(), NULL, 10); + na->last_seen = params[3].is_number_only() ? convertTo<time_t>(params[3]) : 0; Alog(LOG_DEBUG_2) << "[db_plain}: Loaded nickalias for " << na->nick; } -static void LoadNickRequest(const std::vector<std::string> ¶ms) +static void LoadNickRequest(const std::vector<Anope::string> ¶ms) { NickRequest *nr = new NickRequest(params[0]); nr->passcode = params[1]; nr->password = params[2]; - nr->email = sstrdup(params[3].c_str()); - nr->requested = atol(params[4].c_str()); + nr->email = params[3]; + nr->requested = params[4].is_number_only() ? convertTo<time_t>(params[4]) : 0; Alog(LOG_DEBUG_2) << "[db_plain]: Loaded nickrequest for " << nr->nick; } -static void LoadBotInfo(const std::vector<std::string> ¶ms) +static void LoadBotInfo(const std::vector<Anope::string> ¶ms) { BotInfo *bi = findbot(params[0]); if (!bi) bi = new BotInfo(params[0]); bi->SetIdent(params[1]); - bi->host = sstrdup(params[2].c_str()); - bi->created = atol(params[3].c_str()); + bi->host = params[2]; + bi->created = params[3].is_number_only() ? convertTo<time_t>(params[3]) : 0; //bi no longer has a chancount, use bi->chans.size() //bi->chancount = atol(params[4].c_str()); - bi->realname = sstrdup(params[5].c_str()); + bi->realname = params[5]; Alog(LOG_DEBUG_2) << "[db_plain]: Loaded botinfo for " << bi->nick; } -static void LoadChanInfo(const std::vector<std::string> ¶ms) +static void LoadChanInfo(const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = new ChannelInfo(params[0]); /* CLear default mlock */ @@ -428,38 +426,38 @@ static void LoadChanInfo(const std::vector<std::string> ¶ms) ci->ClearFlags(); ci->botflags.ClearFlags(); - ci->time_registered = strtol(params[1].c_str(), NULL, 10); + ci->time_registered = params[1].is_number_only() ? convertTo<time_t>(params[1]) : 0; - ci->last_used = strtol(params[2].c_str(), NULL, 10); + ci->last_used = params[2].is_number_only() ? convertTo<time_t>(params[2]) : 0; - ci->bantype = atoi(params[3].c_str()); + ci->bantype = params[3].is_number_only() ? convertTo<int16>(params[3]) : Config.CSDefBantype; - ci->memos.memomax = atoi(params[4].c_str()); + ci->memos.memomax = params[4].is_number_only() ? convertTo<int16>(params[4]) : 1; Alog(LOG_DEBUG_2) << "[db_plain]: loaded channel " << ci->name; } -static void LoadOperInfo(const std::vector<std::string> ¶ms) +static void LoadOperInfo(const std::vector<Anope::string> ¶ms) { - if (params[0] == "STATS") + if (params[0].equals_ci("STATS")) { - maxusercnt = atol(params[1].c_str()); - maxusertime = strtol(params[2].c_str(), NULL, 10); + maxusercnt = params[1].is_number_only() ? convertTo<uint32>(params[1]) : 0; + maxusertime = params[2].is_number_only() ? convertTo<time_t>(params[2]) : 0; } - else if (params[0] == "SNLINE" || params[0] == "SQLINE" || params[0] == "SZLINE") + else if (params[0].equals_ci("SNLINE") || params[0].equals_ci("SQLINE") || params[0].equals_ci("SZLINE")) { - ci::string mask = params[1].c_str(); - ci::string by = params[2].c_str(); - time_t seton = atol(params[3].c_str()); - time_t expires = atol(params[4].c_str()); - std::string reason = params[5]; + Anope::string mask = params[1]; + Anope::string by = params[2]; + time_t seton = params[3].is_number_only() ? convertTo<time_t>(params[3]) : 0; + time_t expires = params[4].is_number_only() ? convertTo<time_t>(params[4]) : 0; + Anope::string reason = params[5]; XLine *x = NULL; - if (params[0] == "SNLINE" && SNLine) + if (params[0].equals_ci("SNLINE") && SNLine) x = SNLine->Add(NULL, NULL, mask, expires, reason); - else if (params[0] == "SQLINE" && SQLine) + else if (params[0].equals_ci("SQLINE") && SQLine) x = SQLine->Add(NULL, NULL, mask, expires, reason); - else if (params[0] == "SZLINE" && SZLine) + else if (params[0].equals_ci("SZLINE") && SZLine) x = SZLine->Add(NULL, NULL, mask, expires, reason); if (x) { @@ -467,14 +465,14 @@ static void LoadOperInfo(const std::vector<std::string> ¶ms) x->Created = seton; } } - else if (params[0] == "AKILL" && SGLine) + else if (params[0].equals_ci("AKILL") && SGLine) { - ci::string user = params[1].c_str(); - ci::string host = params[2].c_str(); - ci::string by = params[3].c_str(); - time_t seton = atol(params[4].c_str()); - time_t expires = atol(params[5].c_str()); - std::string reason = params[6]; + Anope::string user = params[1]; + Anope::string host = params[2]; + Anope::string by = params[3]; + time_t seton = params[4].is_number_only() ? convertTo<time_t>(params[4]) : 0; + time_t expires = params[5].is_number_only() ? convertTo<time_t>(params[5]) : 0; + Anope::string reason = params[6]; XLine *x = SGLine->Add(NULL, NULL, user + "@" + host, expires, reason); if (x) @@ -483,26 +481,25 @@ static void LoadOperInfo(const std::vector<std::string> ¶ms) x->Created = seton; } } - else if (params[0] == "EXCEPTION") + else if (params[0].equals_ci("EXCEPTION")) { - ++nexceptions; - exceptions = static_cast<Exception *>(srealloc(exceptions, sizeof(Exception) * nexceptions)); - exceptions[nexceptions - 1].mask = sstrdup(params[1].c_str()); - exceptions[nexceptions - 1].limit = atol(params[2].c_str()); - exceptions[nexceptions - 1].who = sstrdup(params[3].c_str()); - exceptions[nexceptions - 1].time = strtol(params[4].c_str(), NULL, 10); - exceptions[nexceptions - 1].expires = strtol(params[5].c_str(), NULL, 10); - exceptions[nexceptions - 1].reason = sstrdup(params[6].c_str()); - exceptions[nexceptions - 1].num = nexceptions - 1; + Exception *exception = new Exception(); + exception->mask = params[1]; + exception->limit = params[2].is_number_only() ? convertTo<int>(params[2]) : 1; + exception->who = params[3]; + exception->time = params[4].is_number_only() ? convertTo<time_t>(params[4]) : 0; + exception->expires = params[5].is_number_only() ? convertTo<time_t>(params[5]) : 0; + exception->reason = params[6]; + exceptions.push_back(exception); } } -void Write(const std::string &buf) +void Write(const Anope::string &buf) { db << buf << endl; } -void WriteMetadata(const std::string &key, const std::string &data) +void WriteMetadata(const Anope::string &key, const Anope::string &data) { Write("MD " + key + " " + data); } @@ -512,9 +509,9 @@ class DBPlain : public Module /* Day the last backup was on */ int LastDay; /* Backup file names */ - std::list<std::string> Backups; + std::list<Anope::string> Backups; public: - DBPlain(const std::string &modname, const std::string &creator) : Module(modname, creator) + DBPlain(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(DATABASE); @@ -543,18 +540,14 @@ class DBPlain : public Module if (tm->tm_mday != LastDay) { LastDay = tm->tm_mday; - char *newname = new char[DatabaseFile.length() + 30]; - snprintf(newname, DatabaseFile.length() + 30, "backups/%s.%d%d%d", DatabaseFile.c_str(), tm->tm_year, tm->tm_mon, tm->tm_mday); + Anope::string newname = "backups/" + DatabaseFile + "." + stringify(tm->tm_year) + stringify(tm->tm_mon) + stringify(tm->tm_mday); /* Backup already exists */ if (IsFile(newname)) - { - delete [] newname; return; - } Alog(LOG_DEBUG) << "db_plain: Attemping to rename " << DatabaseFile << " to " << newname; - if (rename(DatabaseFile.c_str(), newname) != 0) + if (rename(DatabaseFile.c_str(), newname.c_str())) { ircdproto->SendGlobops(OperServ, "Unable to backup database!"); Alog() << "Unable to back up database!"; @@ -562,15 +555,11 @@ class DBPlain : public Module if (!Config.NoBackupOkay) quitting = 1; - delete [] newname; - return; } Backups.push_back(newname); - delete [] newname; - unsigned KeepBackups = Config.KeepBackups; if (KeepBackups && Backups.size() > KeepBackups) { @@ -586,23 +575,23 @@ class DBPlain : public Module DatabaseFile = config.ReadValue("db_plain", "database", "anope.db", 0); } - EventReturn OnDatabaseRead(const std::vector<std::string> ¶ms) + EventReturn OnDatabaseRead(const std::vector<Anope::string> ¶ms) { - std::string key = params[0]; - std::vector<std::string> otherparams = params; + Anope::string key = params[0]; + std::vector<Anope::string> otherparams = params; otherparams.erase(otherparams.begin()); - if (key == "NC") + if (key.equals_ci("NC")) LoadNickCore(otherparams); - else if (key == "NA") + else if (key.equals_ci("NA")) LoadNickAlias(otherparams); - else if (key == "NR") + else if (key.equals_ci("NR")) LoadNickRequest(otherparams); - else if (key == "BI") + else if (key.equals_ci("BI")) LoadBotInfo(otherparams); - else if (key == "CH") + else if (key.equals_ci("CH")) LoadChanInfo(otherparams); - else if (key == "OS") + else if (key.equals_ci("OS")) LoadOperInfo(otherparams); return EVENT_CONTINUE; @@ -619,84 +608,80 @@ class DBPlain : public Module return EVENT_STOP; } - EventReturn OnDatabaseReadMetadata(NickCore *nc, const std::string &key, const std::vector<std::string> ¶ms) + EventReturn OnDatabaseReadMetadata(NickCore *nc, const Anope::string &key, const std::vector<Anope::string> ¶ms) { - if (key == "EMAIL") - nc->email = sstrdup(params[0].c_str()); - else if (key == "GREET") - nc->greet = sstrdup(params[0].c_str()); - else if (key == "ACCESS") + if (key.equals_ci("EMAIL")) + nc->email = params[0]; + else if (key.equals_ci("GREET")) + nc->greet = params[0]; + else if (key.equals_ci("ACCESS")) nc->AddAccess(params[0]); - else if (key == "FLAGS") + else if (key.equals_ci("FLAGS")) { for (unsigned j = 0, end = params.size(); j < end; ++j) for (int i = 0; NickCoreFlags[i].Flag != -1; ++i) - if (NickCoreFlags[i].Name == params[j]) + if (params[j].equals_ci(NickCoreFlags[i].Name)) nc->SetFlag(NickCoreFlags[i].Flag); } - else if (key == "MI") + else if (key.equals_ci("MI")) { Memo *m = new Memo; - m->number = atoi(params[0].c_str()); - m->time = strtol(params[1].c_str(), NULL, 10); + m->number = params[0].is_number_only() ? convertTo<uint32>(params[0]) : 0; + m->time = params[1].is_number_only() ? convertTo<time_t>(params[1]) : 0; m->sender = params[2]; - for (unsigned j = 3; params[j] == "UNREAD" || params[j] == "RECEIPT" || params[j] == "NOTIFYS"; ++j) + for (unsigned j = 3; params[j].equals_ci("UNREAD") || params[j].equals_ci("RECEIPT") || params[j].equals_ci("NOTIFYS"); ++j) { - if (params[j] == "UNREAD") + if (params[j].equals_ci("UNREAD")) m->SetFlag(MF_UNREAD); - else if (params[j] == "RECEIPT") + else if (params[j].equals_ci("RECEIPT")) m->SetFlag(MF_RECEIPT); - else if (params[j] == "NOTIFYS") + else if (params[j].equals_ci("NOTIFYS")) m->SetFlag(MF_NOTIFYS); } - m->text = sstrdup(params[params.size() - 1].c_str()); + m->text = params[params.size() - 1]; nc->memos.memos.push_back(m); } return EVENT_CONTINUE; } - EventReturn OnDatabaseReadMetadata(NickAlias *na, const std::string &key, const std::vector<std::string> ¶ms) + EventReturn OnDatabaseReadMetadata(NickAlias *na, const Anope::string &key, const std::vector<Anope::string> ¶ms) { - if (key == "LAST_USERMASK") - na->last_usermask = sstrdup(params[0].c_str()); - else if (key == "LAST_REALNAME") - na->last_realname = sstrdup(params[0].c_str()); - else if (key == "LAST_QUIT") - na->last_quit = sstrdup(params[0].c_str()); - else if (key == "FLAGS") + if (key.equals_ci("LAST_USERMASK")) + na->last_usermask = params[0]; + else if (key.equals_ci("LAST_REALNAME")) + na->last_realname = params[0]; + else if (key.equals_ci("LAST_QUIT")) + na->last_quit = params[0]; + else if (key.equals_ci("FLAGS")) { for (unsigned j = 0, end = params.size(); j < end; ++j) { - if (params[j] == "FORBIDDEN") + if (params[j].equals_ci("FORBIDDEN")) na->SetFlag(NS_FORBIDDEN); - else if (params[j] == "NOEXPIRE") + else if (params[j].equals_ci("NOEXPIRE")) na->SetFlag(NS_NO_EXPIRE); } } - else if (key == "VHOST") - na->hostinfo.SetVhost(params.size() > 3 ? params[3] : "", params[2], params[0], strtol(params[1].c_str(), NULL, 10)); + else if (key.equals_ci("VHOST")) + na->hostinfo.SetVhost(params.size() > 3 ? params[3] : "", params[2], params[0], params[1].is_number_only() ? convertTo<time_t>(params[1]) : 0); return EVENT_CONTINUE; } - EventReturn OnDatabaseReadMetadata(BotInfo *bi, const std::string &key, const std::vector<std::string> ¶ms) + EventReturn OnDatabaseReadMetadata(BotInfo *bi, const Anope::string &key, const std::vector<Anope::string> ¶ms) { - if (key == "FLAGS") - { + if (key.equals_ci("FLAGS")) for (unsigned j = 0, end = params.size(); j < end; ++j) - { - if (params[j] == "PRIVATE") + if (params[j].equals_ci("PRIVATE")) bi->SetFlag(BI_PRIVATE); - } - } return EVENT_CONTINUE; } - EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const std::string &key, const std::vector<std::string> ¶ms) + EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, const std::vector<Anope::string> ¶ms) { - if (key == "FOUNDER") + if (key.equals_ci("FOUNDER")) { ci->founder = findcore(params[0]); if (!ci->founder) @@ -706,36 +691,36 @@ class DBPlain : public Module throw DatabaseException(reason.str()); } } - else if (key == "SUCCESSOR") + else if (key.equals_ci("SUCCESSOR")) ci->successor = findcore(params[0]); - else if (key == "LEVELS") + else if (key.equals_ci("LEVELS")) { for (unsigned j = 0, end = params.size(); j < end; j += 2) for (int i = 0; ChannelLevels[i].Level != -1; ++i) - if (ChannelLevels[i].Name == params[j]) - ci->levels[ChannelLevels[i].Level] = atoi(params[j + 1].c_str()); + if (params[j].equals_ci(ChannelLevels[i].Name)) + ci->levels[ChannelLevels[i].Level] = params[j + 1].is_number_only() ? convertTo<int16>(params[j + 1]) : 0; } - else if (key == "FLAGS") + else if (key.equals_ci("FLAGS")) { for (unsigned j = 0, end = params.size(); j < end; ++j) for (int i = 0; ChannelInfoFlags[i].Flag != -1; ++i) - if (ChannelInfoFlags[i].Name == params[j]) + if (params[j].equals_ci(ChannelInfoFlags[i].Name)) ci->SetFlag(ChannelInfoFlags[i].Flag); } - else if (key == "DESC") - ci->desc = sstrdup(params[0].c_str()); - else if (key == "TOPIC") + else if (key.equals_ci("DESC")) + ci->desc = params[0]; + else if (key.equals_ci("TOPIC")) { ci->last_topic_setter = params[0]; - ci->last_topic_time = strtol(params[1].c_str(), NULL, 10); - ci->last_topic = sstrdup(params[2].c_str()); + ci->last_topic_time = params[1].is_number_only() ? convertTo<time_t>(params[1]) : 0; + ci->last_topic = params[2]; } - else if (key == "FORBID") + else if (key.equals_ci("FORBID")) { - ci->forbidby = sstrdup(params[0].c_str()); - ci->forbidreason = sstrdup(params[1].c_str()); + ci->forbidby = params[0]; + ci->forbidreason = params[1]; } - else if (key == "ACCESS") + else if (key.equals_ci("ACCESS")) { NickCore *nc = findcore(params[0]); if (!nc) @@ -745,14 +730,14 @@ class DBPlain : public Module throw DatabaseException(reason.str()); } - int level = atoi(params[1].c_str()); - time_t last_seen = strtol(params[2].c_str(), NULL, 10); + int level = params[1].is_number_only() ? convertTo<int>(params[1]) : 0; + time_t last_seen = params[2].is_number_only() ? convertTo<time_t>(params[2]) : 0; ci->AddAccess(nc, level, params[3], last_seen); } - else if (key == "AKICK") + else if (key.equals_ci("AKICK")) { - bool Stuck = params[0] == "STUCK" ? true : false; - bool Nick = params[1] == "NICK" ? true : false; + bool Stuck = params[0].equals_ci("STUCK"); + bool Nick = params[1].equals_ci("NICK"); NickCore *nc = NULL; if (Nick) { @@ -766,103 +751,103 @@ class DBPlain : public Module } AutoKick *ak; if (Nick) - ak = ci->AddAkick(params[3], nc, params.size() > 6 ? params[6] : "", atol(params[4].c_str()), atol(params[5].c_str())); + ak = ci->AddAkick(params[3], nc, params.size() > 6 ? params[6] : "", params[4].is_number_only() ? convertTo<time_t>(params[4]) : 0, params[5].is_number_only() ? convertTo<time_t>(params[5]) : 0); else - ak = ci->AddAkick(params[3], params[2], params.size() > 6 ? params[6] : "", atol(params[4].c_str()), atol(params[5].c_str())); + ak = ci->AddAkick(params[3], params[2], params.size() > 6 ? params[6] : "", params[4].is_number_only() ? convertTo<time_t>(params[4]) : 0, params[5].is_number_only() ? convertTo<time_t>(params[5]) : 0); if (Stuck) ak->SetFlag(AK_STUCK); if (Nick) ak->SetFlag(AK_ISNICK); } - else if (key == "MLOCK_ON" || key == "MLOCK_OFF") + else if (key.equals_ci("MLOCK_ON") || key.equals_ci("MLOCK_OFF")) { - bool Set = key == "MLOCK_ON" ? true : false; + bool Set = key.equals_ci("MLOCK_ON"); /* For now store mlock in extensible, Anope hasn't yet connected to the IRCd and doesn't know what modes exist */ - ci->Extend(Set ? "db_mlock_modes_on" : "db_mlock_modes_off", new ExtensibleItemRegular<std::vector<std::string> >(params)); + ci->Extend(Set ? "db_mlock_modes_on" : "db_mlock_modes_off", new ExtensibleItemRegular<std::vector<Anope::string> >(params)); } - else if (key == "MLP") + else if (key.equals_ci("MLP")) { - std::vector<std::pair<std::string, std::string> > mlp; + std::vector<std::pair<Anope::string, Anope::string> > mlp; for (unsigned j = 0, end = params.size(); j < end; j += 2) mlp.push_back(std::make_pair(params[j], params[j + 1])); /* For now store mlocked modes in extensible, Anope hasn't yet connected to the IRCd and doesn't know what modes exist */ - ci->Extend("db_mlp", new ExtensibleItemRegular<std::vector<std::pair<std::string, std::string> > >(mlp)); + ci->Extend("db_mlp", new ExtensibleItemRegular<std::vector<std::pair<Anope::string, Anope::string> > >(mlp)); } - else if (key == "MI") + else if (key.equals_ci("MI")) { Memo *m = new Memo; - m->number = atoi(params[0].c_str()); - m->time = strtol(params[1].c_str(), NULL, 10); + m->number = params[0].is_number_only() ? convertTo<uint32>(params[0]) : 0; + m->time = params[1].is_number_only() ? convertTo<time_t>(params[1]) : 0; m->sender = params[2]; - for (unsigned j = 3; params[j] == "UNREAD" || params[j] == "RECEIPT" || params[j] == "NOTIFYS"; ++j) + for (unsigned j = 3; params[j].equals_ci("UNREAD") || params[j].equals_ci("RECEIPT") || params[j].equals_ci("NOTIFYS"); ++j) { - if (params[j] == "UNREAD") + if (params[j].equals_ci("UNREAD")) m->SetFlag(MF_UNREAD); - else if (params[j] == "RECEIPT") + else if (params[j].equals_ci("RECEIPT")) m->SetFlag(MF_RECEIPT); - else if (params[j] == "NOTIFYS") + else if (params[j].equals_ci("NOTIFYS")) m->SetFlag(MF_NOTIFYS); } - m->text = sstrdup(params[params.size() - 1].c_str()); + m->text = params[params.size() - 1]; ci->memos.memos.push_back(m); } - else if (key == "ENTRYMSG") - ci->entry_message = sstrdup(params[0].c_str()); - else if (key == "BI") + else if (key.equals_ci("ENTRYMSG")) + ci->entry_message = params[0]; + else if (key.equals_ci("BI")) { - if (params[0] == "NAME") + if (params[0].equals_ci("NAME")) ci->bi = findbot(params[1]); - else if (params[0] == "FLAGS") + else if (params[0].equals_ci("FLAGS")) { for (unsigned j = 1, end = params.size(); j < end; ++j) for (int i = 0; BotFlags[i].Flag != -1; ++i) - if (BotFlags[i].Name == params[j]) + if (params[j].equals_ci(BotFlags[i].Name)) ci->botflags.SetFlag(BotFlags[i].Flag); } - else if (params[0] == "TTB") + else if (params[0].equals_ci("TTB")) { for (unsigned j = 1, end = params.size(); j < end; j += 2) { - if (params[j] == "BOLDS") - ci->ttb[0] = atoi(params[j + 1].c_str()); - else if (params[j] == "COLORS") - ci->ttb[1] = atoi(params[j + 1].c_str()); - else if (params[j] == "REVERSES") - ci->ttb[2] = atoi(params[j + 1].c_str()); - else if (params[j] == "UNDERLINES") - ci->ttb[3] = atoi(params[j + 1].c_str()); - else if (params[j] == "BADWORDS") - ci->ttb[4] = atoi(params[j + 1].c_str()); - else if (params[j] == "CAPS") - ci->ttb[5] = atoi(params[j + 1].c_str()); - else if (params[j] == "FLOOD") - ci->ttb[6] = atoi(params[j + 1].c_str()); - else if (params[j] == "REPEAT") - ci->ttb[7] = atoi(params[j + 1].c_str()); + if (params[j].equals_ci("BOLDS")) + ci->ttb[0] = params[j + 1].is_number_only() ? convertTo<int16>(params[j + 1]) : 0; + else if (params[j].equals_ci("COLORS")) + ci->ttb[1] = params[j + 1].is_number_only() ? convertTo<int16>(params[j + 1]) : 0; + else if (params[j].equals_ci("REVERSES")) + ci->ttb[2] = params[j + 1].is_number_only() ? convertTo<int16>(params[j + 1]) : 0; + else if (params[j].equals_ci("UNDERLINES")) + ci->ttb[3] = params[j + 1].is_number_only() ? convertTo<int16>(params[j + 1]) : 0; + else if (params[j].equals_ci("BADWORDS")) + ci->ttb[4] = params[j + 1].is_number_only() ? convertTo<int16>(params[j + 1]) : 0; + else if (params[j].equals_ci("CAPS")) + ci->ttb[5] = params[j + 1].is_number_only() ? convertTo<int16>(params[j + 1]) : 0; + else if (params[j].equals_ci("FLOOD")) + ci->ttb[6] = params[j + 1].is_number_only() ? convertTo<int16>(params[j + 1]) : 0; + else if (params[j].equals_ci("REPEAT")) + ci->ttb[7] = params[j + 1].is_number_only() ? convertTo<int16>(params[j + 1]) : 0; } } - else if (params[0] == "CAPSMIN") - ci->capsmin = atoi(params[1].c_str()); - else if (params[0] == "CAPSPERCENT") - ci->capspercent = atoi(params[1].c_str()); - else if (params[0] == "FLOODLINES") - ci->floodlines = atoi(params[1].c_str()); - else if (params[0] == "FLOODSECS") - ci->floodsecs = atoi(params[1].c_str()); - else if (params[0] == "REPEATTIMES") - ci->repeattimes = atoi(params[1].c_str()); - else if (params[0] == "BADWORD") + else if (params[0].equals_ci("CAPSMIN")) + ci->capsmin = params[1].is_number_only() ? convertTo<int16>(params[1]) : 0; + else if (params[0].equals_ci("CAPSPERCENT")) + ci->capspercent = params[1].is_number_only() ? convertTo<int16>(params[1]) : 0; + else if (params[0].equals_ci("FLOODLINES")) + ci->floodlines = params[1].is_number_only() ? convertTo<int16>(params[1]) : 0; + else if (params[0].equals_ci("FLOODSECS")) + ci->floodsecs = params[1].is_number_only() ? convertTo<int16>(params[1]) : 0; + else if (params[0].equals_ci("REPEATTIMES")) + ci->repeattimes = params[1].is_number_only() ? convertTo<int16>(params[1]) : 0; + else if (params[0].equals_ci("BADWORD")) { BadWordType Type; - if (params[1] == "SINGLE") + if (params[1].equals_ci("SINGLE")) Type = BW_SINGLE; - else if (params[1] == "START") + else if (params[1].equals_ci("START")) Type = BW_START; - else if (params[1] == "END") + else if (params[1].equals_ci("END")) Type = BW_END; else Type = BW_ANY; @@ -915,13 +900,14 @@ class DBPlain : public Module db << LangInfos[j].Name; db << " " << nc->memos.memomax << " " << nc->channelcount << endl; - if (nc->email) + if (!nc->email.empty()) db << "MD EMAIL " << nc->email << endl; - if (nc->greet) + if (!nc->greet.empty()) db << "MD GREET :" << nc->greet << endl; + if (!nc->access.empty()) { - for (std::vector<std::string>::iterator it = nc->access.begin(), it_end = nc->access.end(); it != it_end; ++it) + for (std::vector<Anope::string>::iterator it = nc->access.begin(), it_end = nc->access.end(); it != it_end; ++it) db << "MD ACCESS " << *it << endl; } if (nc->FlagCount()) @@ -955,11 +941,11 @@ class DBPlain : public Module NickAlias *na = it->second; db << "NA " << na->nc->display << " " << na->nick << " " << na->time_registered << " " << na->last_seen << endl; - if (na->last_usermask) + if (!na->last_usermask.empty()) db << "MD LAST_USERMASK " << na->last_usermask << endl; - if (na->last_realname) + if (!na->last_realname.empty()) db << "MD LAST_REALNAME :" << na->last_realname << endl; - if (na->last_quit) + if (!na->last_quit.empty()) db << "MD LAST_QUIT :" << na->last_quit << endl; if (na->HasFlag(NS_FORBIDDEN) || na->HasFlag(NS_NO_EXPIRE)) db << "MD FLAGS" << (na->HasFlag(NS_FORBIDDEN) ? " FORBIDDEN" : "") << (na->HasFlag(NS_NO_EXPIRE) ? " NOEXPIRE " : "") << endl; @@ -993,9 +979,9 @@ class DBPlain : public Module db << "MD FOUNDER " << ci->founder->display << endl; if (ci->successor) db << "MD SUCCESSOR " << ci->successor->display << endl; - if (ci->desc) + if (!ci->desc.empty()) db << "MD DESC :" << ci->desc << endl; - if (ci->last_topic) + if (!ci->last_topic.empty()) db << "MD TOPIC " << ci->last_topic_setter << " " << ci->last_topic_time << " :" << ci->last_topic << endl; db << "MD LEVELS"; for (int j = 0; ChannelLevels[j].Level != -1; ++j) @@ -1015,7 +1001,8 @@ class DBPlain : public Module db << "MD ACCESS " << ci->GetAccess(k)->nc->display << " " << ci->GetAccess(k)->level << " " << ci->GetAccess(k)->last_seen << " " << ci->GetAccess(k)->creator << endl; for (unsigned k = 0, end = ci->GetAkickCount(); k < end; ++k) { - db << "MD AKICK " << (ci->GetAkick(k)->HasFlag(AK_STUCK) ? "STUCK " : "UNSTUCK ") << (ci->GetAkick(k)->HasFlag(AK_ISNICK) ? "NICK " : "MASK ") << (ci->GetAkick(k)->HasFlag(AK_ISNICK) ? ci->GetAkick(k)->nc->display : ci->GetAkick(k)->mask) << " " << ci->GetAkick(k)->creator << " " << ci->GetAkick(k)->addtime << " " << ci->last_used << " :"; + db << "MD AKICK " << (ci->GetAkick(k)->HasFlag(AK_STUCK) ? "STUCK " : "UNSTUCK ") << (ci->GetAkick(k)->HasFlag(AK_ISNICK) ? "NICK " : "MASK ") << + (ci->GetAkick(k)->HasFlag(AK_ISNICK) ? ci->GetAkick(k)->nc->display : ci->GetAkick(k)->mask) << " " << ci->GetAkick(k)->creator << " " << ci->GetAkick(k)->addtime << " " << ci->last_used << " :"; if (!ci->GetAkick(k)->reason.empty()) db << ci->GetAkick(k)->reason; db << endl; @@ -1050,7 +1037,7 @@ class DBPlain : public Module } db << endl; } - std::string Param; + Anope::string Param; for (std::list<Mode *>::iterator it = ModeManager::Modes.begin(), it_end = ModeManager::Modes.end(); it != it_end; ++it) { if ((*it)->Class == MC_CHANNEL) @@ -1077,7 +1064,7 @@ class DBPlain : public Module db << " :" << memos->memos[k]->text << endl; } } - if (ci->entry_message) + if (!ci->entry_message.empty()) db << "MD ENTRYMSG :" << ci->entry_message << endl; if (ci->bi) db << "MD BI NAME " << ci->bi->nick << endl; @@ -1101,7 +1088,8 @@ class DBPlain : public Module if (ci->repeattimes) db << "MD BI REPEATTIMES " << ci->repeattimes << endl; for (unsigned k = 0, end = ci->GetBadWordCount(); k < end; ++k) - db << "MD BI BADWORD " << (ci->GetBadWord(k)->type == BW_ANY ? "ANY " : "") << (ci->GetBadWord(k)->type == BW_SINGLE ? "SINGLE " : "") << (ci->GetBadWord(k)->type == BW_START ? "START " : "") << (ci->GetBadWord(k)->type == BW_END ? "END " : "") << ":" << ci->GetBadWord(k)->word << endl; + db << "MD BI BADWORD " << (ci->GetBadWord(k)->type == BW_ANY ? "ANY " : "") << (ci->GetBadWord(k)->type == BW_SINGLE ? "SINGLE " : "") << (ci->GetBadWord(k)->type == BW_START ? "START " : "") << + (ci->GetBadWord(k)->type == BW_END ? "END " : "") << ":" << ci->GetBadWord(k)->word << endl; FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteMetadata, ci)); } @@ -1136,8 +1124,11 @@ class DBPlain : public Module db << "OS SZLINE " << x->Mask << " " << x->By << " " << x->Created << " " << x->Expires << " :" << x->Reason << endl; } - for (int i = 0; i < nexceptions; ++i) - db << "OS EXCEPTION " << exceptions[i].mask << " " << exceptions[i].limit << " " << exceptions[i].who << " " << exceptions[i].time << " " << exceptions[i].expires << " " << exceptions[i].reason << endl; + for (std::vector<Exception *>::iterator it = exceptions.begin(), it_end = exceptions.end(); it != it_end; ++it) + { + Exception *e = *it; + db << "OS EXCEPTION " << e->mask << " " << e->limit << " " << e->who << " " << e->time << " " << e->expires << " " << e->reason << endl; + } FOREACH_MOD(I_OnDatabaseWrite, OnDatabaseWrite(Write)); diff --git a/modules/core/enc_md5.cpp b/modules/core/enc_md5.cpp index fafb79309..fe9566d38 100644 --- a/modules/core/enc_md5.cpp +++ b/modules/core/enc_md5.cpp @@ -315,7 +315,7 @@ void Decode(unsigned *output, const unsigned char *input, unsigned len) class EMD5 : public Module { public: - EMD5(const std::string &modname, const std::string &creator) : Module(modname, creator) + EMD5(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(ENCRYPTION); @@ -325,18 +325,18 @@ class EMD5 : public Module ModuleManager::Attach(I_OnCheckPassword, this); } - EventReturn OnEncrypt(const std::string &src, std::string &dest) + EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) { MD5_CTX context; char *digest = new char[Config.PassLen]; - std::string buf = "md5:"; - char cpass[1000]; + Anope::string buf = "md5:"; + Anope::string cpass; MD5Init(&context); - MD5Update(&context, reinterpret_cast<const unsigned char *>(src.c_str()), src.size()); + MD5Update(&context, reinterpret_cast<const unsigned char *>(src.c_str()), src.length()); MD5Final(reinterpret_cast<unsigned char *>(digest), &context); - b64_encode(digest, 16, cpass, 1000); + b64_encode(digest, cpass); buf += cpass; Alog(LOG_DEBUG_2) << "(enc_md5) hashed password from [" << src << "] to [" << buf << "]"; dest = buf; @@ -344,25 +344,25 @@ class EMD5 : public Module return EVENT_ALLOW; } - EventReturn OnDecrypt(const std::string &hashm, const std::string &src, std::string &dest) + EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) { - if (hashm != "md5") + if (!hashm.equals_cs("md5")) return EVENT_CONTINUE; return EVENT_STOP; } - EventReturn OnCheckPassword(const std::string &hashm, std::string &plaintext, std::string &password) + EventReturn OnCheckPassword(const Anope::string &hashm, Anope::string &plaintext, Anope::string &password) { - if (hashm != "md5") + if (!hashm.equals_cs("md5")) return EVENT_CONTINUE; - std::string buf; + Anope::string buf; this->OnEncrypt(plaintext, buf); - if (password == buf) + if (password.equals_cs(buf)) { /* if we are NOT the first module in the list, * we want to re-encrypt the pass with the new encryption */ - if (Config.EncModuleList.front() != this->name) + if (!this->name.equals_ci(Config.EncModuleList.front())) enc_encrypt(plaintext, password); return EVENT_ALLOW; } diff --git a/modules/core/enc_none.cpp b/modules/core/enc_none.cpp index 58ccdaff1..510380aee 100644 --- a/modules/core/enc_none.cpp +++ b/modules/core/enc_none.cpp @@ -12,7 +12,7 @@ class ENone : public Module { public: - ENone(const std::string &modname, const std::string &creator) : Module(modname, creator) + ENone(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(ENCRYPTION); @@ -22,41 +22,39 @@ class ENone : public Module ModuleManager::Attach(I_OnCheckPassword, this); } - EventReturn OnEncrypt(const std::string &src, std::string &dest) + EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) { - std::string buf = "plain:"; - char cpass[1000]; - b64_encode(src.c_str(), src.size(), cpass, 1000); + Anope::string buf = "plain:"; + Anope::string cpass; + b64_encode(src, cpass); buf += cpass; Alog(LOG_DEBUG_2) << "(enc_none) hashed password from [" << src << "] to [" << buf << "]"; dest = buf; return EVENT_ALLOW; } - EventReturn OnDecrypt(const std::string &hashm, const std::string &src, std::string &dest) + EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) { - if (hashm != "plain") + if (!hashm.equals_cs("plain")) return EVENT_CONTINUE; - char cpass[1000] = ""; - size_t pos = src.find(":"); - std::string buf(src.begin() + pos + 1, src.end()); - b64_decode(buf.c_str(), cpass, 1000); - dest = cpass; + size_t pos = src.find(':'); + Anope::string buf = src.substr(pos + 1); + b64_decode(buf, dest); return EVENT_ALLOW; } - EventReturn OnCheckPassword(const std::string &hashm, std::string &plaintext, std::string &password) + EventReturn OnCheckPassword(const Anope::string &hashm, Anope::string &plaintext, Anope::string &password) { - if (hashm != "plain") + if (!hashm.equals_cs("plain")) return EVENT_CONTINUE; - std::string buf; + Anope::string buf; this->OnEncrypt(plaintext, buf); - if (password == buf) + if (password.equals_cs(buf)) { /* if we are NOT the first module in the list, * we want to re-encrypt the pass with the new encryption */ - if (Config.EncModuleList.front() != this->name) + if (!this->name.equals_ci(Config.EncModuleList.front())) enc_encrypt(plaintext, password); return EVENT_ALLOW; } diff --git a/modules/core/enc_old.cpp b/modules/core/enc_old.cpp index a53115628..10af018ce 100644 --- a/modules/core/enc_old.cpp +++ b/modules/core/enc_old.cpp @@ -320,7 +320,7 @@ inline static char XTOI(char c) { return c > 9 ? c - 'A' + 10 : c - '0'; } class EOld : public Module { public: - EOld(const std::string &modname, const std::string &creator) : Module(modname, creator) + EOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(ENCRYPTION); @@ -330,47 +330,48 @@ class EOld : public Module ModuleManager::Attach(I_OnCheckPassword, this); } - EventReturn OnEncrypt(const std::string &src, std::string &dest) + EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) { MD5_CTX context; - char digest[33] = "", digest2[33], cpass[1000]; + char digest[33] = "", digest2[33]; + Anope::string cpass; int i; - std::string buf = "oldmd5:"; + Anope::string buf = "oldmd5:"; memset(&context, 0, sizeof(context)); MD5Init(&context); - MD5Update(&context, reinterpret_cast<const unsigned char *>(src.c_str()), src.size()); + MD5Update(&context, reinterpret_cast<const unsigned char *>(src.c_str()), src.length()); MD5Final(reinterpret_cast<unsigned char *>(digest), &context); for (i = 0; i < 32; i += 2) digest2[i / 2] = XTOI(digest[i]) << 4 | XTOI(digest[i + 1]); - b64_encode(digest2, 16, cpass, 1000); + b64_encode(digest2, cpass); buf += cpass; Alog(LOG_DEBUG_2) << "(enc_old) hashed password from [" << src << "] to [" << buf << "]"; dest = buf; return EVENT_ALLOW; } - EventReturn OnDecrypt(const std::string &hashm, const std::string &src, std::string &dest ) + EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) { - if (hashm != "oldmd5") + if (!hashm.equals_cs("oldmd5")) return EVENT_CONTINUE; return EVENT_STOP; } - EventReturn OnCheckPassword(const std::string &hashm, std::string &plaintext, std::string &password) + EventReturn OnCheckPassword(const Anope::string &hashm, Anope::string &plaintext, Anope::string &password) { - if (hashm != "oldmd5") + if (!hashm.equals_cs("oldmd5")) return EVENT_CONTINUE; - std::string buf; + Anope::string buf; this->OnEncrypt(plaintext, buf); - if (password == buf) + if (password.equals_cs(buf)) { /* if we are NOT the first module in the list, * we want to re-encrypt the pass with the new encryption */ - if (Config.EncModuleList.front() != this->name) + if (!this->name.equals_ci(Config.EncModuleList.front())) enc_encrypt(plaintext, password); return EVENT_ALLOW; } diff --git a/modules/core/enc_sha1.cpp b/modules/core/enc_sha1.cpp index b986d6938..a5235c594 100644 --- a/modules/core/enc_sha1.cpp +++ b/modules/core/enc_sha1.cpp @@ -168,7 +168,7 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX *context) class ESHA1 : public Module { public: - ESHA1(const std::string &modname, const std::string &creator) : Module(modname, creator) + ESHA1(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(ENCRYPTION); @@ -179,20 +179,20 @@ class ESHA1 : public Module ModuleManager::Attach(I_OnCheckPassword, this); } - EventReturn OnEncrypt(const std::string &src, std::string &dest) + EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) { SHA1_CTX context; char *digest = new char[Config.PassLen]; - std::string buf = "sha1:"; - char cpass[1000]; + Anope::string buf = "sha1:"; + Anope::string cpass; memset(digest, 0, 32); SHA1Init(&context); - SHA1Update(&context, reinterpret_cast<const unsigned char *>(src.c_str()), src.size()); + SHA1Update(&context, reinterpret_cast<const unsigned char *>(src.c_str()), src.length()); SHA1Final(reinterpret_cast<unsigned char *>(digest), &context); - b64_encode(digest, 20, cpass, 1000); + b64_encode(digest, cpass); buf += cpass; Alog(LOG_DEBUG_2) << "(enc_sha1) hashed password from [" << src << "] to [" << buf << "]"; dest = buf; @@ -200,25 +200,25 @@ class ESHA1 : public Module return EVENT_ALLOW; } - EventReturn OnDecrypt(const std::string &hashm, std::string &src, std::string &dest) + EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) { - if (hashm != "sha1") + if (!hashm.equals_cs("sha1")) return EVENT_CONTINUE; return EVENT_STOP; } - EventReturn OnCheckPassword(const std::string &hashm, std::string &plaintext, std::string &password) + EventReturn OnCheckPassword(const Anope::string &hashm, Anope::string &plaintext, Anope::string &password) { - if (hashm != "sha1") + if (!hashm.equals_cs("sha1")) return EVENT_CONTINUE; - std::string buf; + Anope::string buf; this->OnEncrypt(plaintext, buf); - if (password == buf) + if (password.equals_cs(buf)) { /* when we are NOT the first module in the list, * we want to re-encrypt the pass with the new encryption */ - if (Config.EncModuleList.front() != this->name) + if (!this->name.equals_ci(Config.EncModuleList.front())) enc_encrypt(plaintext, password); return EVENT_ALLOW; } diff --git a/modules/core/enc_sha256.cpp b/modules/core/enc_sha256.cpp index fde7cf14c..b0369ee21 100644 --- a/modules/core/enc_sha256.cpp +++ b/modules/core/enc_sha256.cpp @@ -132,26 +132,26 @@ class ESHA256 : public Module } /* returns the IV as base64-encrypted string */ - std::string GetIVString() + Anope::string GetIVString() { - unsigned char buf[33]; - char buf2[512]; + char buf[33]; + Anope::string buf2; for (int i = 0; i < 8; ++i) - UNPACK32(iv[i], &buf[i << 2]); - b64_encode(reinterpret_cast<char *>(buf), 32, buf2, 512); + UNPACK32(iv[i], reinterpret_cast<unsigned char *>(&buf[i << 2])); + b64_encode(buf, buf2); return buf2; } /* splits the appended IV from the password string so it can be used for the next encryption */ /* password format: <hashmethod>:<password_b64>:<iv_b64> */ - void GetIVFromPass(std::string &password) + void GetIVFromPass(const Anope::string &password) { - size_t pos = password.find(":"); - std::string buf(password, password.find(":", pos + 1) + 1, password.size()); - unsigned char buf2[33]; - b64_decode(buf.c_str(), reinterpret_cast<char *>(buf2), 33); + size_t pos = password.find(':'); + Anope::string buf = password.substr(password.find(':', pos + 1) + 1, password.length()); + Anope::string buf2; + b64_decode(buf, buf2); for (int i = 0 ; i < 8; ++i) - PACK32(&buf2[i<<2], iv[i]); + PACK32(reinterpret_cast<unsigned char *>(&buf2[i << 2]), iv[i]); } void SHA256Init(SHA256Context *ctx) @@ -248,7 +248,7 @@ class ESHA256 : public Module /********** ANOPE ******/ public: - ESHA256(const std::string &modname, const std::string &creator) : Module(modname, creator) + ESHA256(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(ENCRYPTION); @@ -260,10 +260,10 @@ class ESHA256 : public Module use_iv = false; } - EventReturn OnEncrypt(const std::string &src, std::string &dest) + EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) { char digest[SHA256_DIGEST_SIZE]; - char cpass[1000]; + Anope::string cpass; SHA256Context ctx; std::stringstream buf; @@ -273,40 +273,40 @@ class ESHA256 : public Module use_iv = false; SHA256Init(&ctx); - SHA256Update(&ctx, reinterpret_cast<const unsigned char *>(src.c_str()), src.size()); + SHA256Update(&ctx, reinterpret_cast<const unsigned char *>(src.c_str()), src.length()); SHA256Final(&ctx, reinterpret_cast<unsigned char *>(digest)); - b64_encode(digest, SHA256_DIGEST_SIZE, cpass, 1000); + b64_encode(digest, cpass); buf << "sha256:" << cpass << ":" << GetIVString(); Alog(LOG_DEBUG_2) << "(enc_sha256) hashed password from [" << src << "] to [" << buf.str() << " ]"; dest = buf.str(); return EVENT_ALLOW; } - EventReturn OnDecrypt(const std::string &hashm, std::string &src, std::string &dest) + EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) { - if (hashm != "sha256") + if (!hashm.equals_cs("sha256")) return EVENT_CONTINUE; return EVENT_STOP; } - EventReturn OnCheckPassword(const std::string &hashm, std::string &plaintext, std::string &password) + EventReturn OnCheckPassword(const Anope::string &hashm, Anope::string &plaintext, Anope::string &password) { - if (hashm != "sha256") + if (!hashm.equals_cs("sha256")) return EVENT_CONTINUE; - std::string buf; + Anope::string buf; GetIVFromPass(password); use_iv = true; this->OnEncrypt(plaintext, buf); - if (password == buf) + if (password.equals_cs(buf)) { /* if we are NOT the first module in the list, * we want to re-encrypt the pass with the new encryption */ - if (Config.EncModuleList.front() != this->name) - enc_encrypt(plaintext, password ); + if (!this->name.equals_ci(Config.EncModuleList.front())) + enc_encrypt(plaintext, password); return EVENT_ALLOW; } return EVENT_STOP; diff --git a/modules/core/hs_del.cpp b/modules/core/hs_del.cpp index 9c3f8da62..2b6d90a10 100644 --- a/modules/core/hs_del.cpp +++ b/modules/core/hs_del.cpp @@ -20,34 +20,34 @@ class CommandHSDel : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na; - const char *nick = params[0].c_str(); + Anope::string nick = params[0]; if ((na = findnick(nick))) { if (na->HasFlag(NS_FORBIDDEN)) { - notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick); + notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick.c_str()); return MOD_CONT; } - Alog() << "vHost for user \002" << nick << "\002 deleted by oper \002" << u->nick << "\002"; + Alog() << "vHost for user \2" << nick << "\2 deleted by oper \2" << u->nick << "\2"; FOREACH_MOD(I_OnDeleteVhost, OnDeleteVhost(na)); na->hostinfo.RemoveVhost(); - notice_lang(Config.s_HostServ, u, HOST_DEL, nick); + notice_lang(Config.s_HostServ, u, HOST_DEL, nick.c_str()); } else - notice_lang(Config.s_HostServ, u, HOST_NOREG, nick); + notice_lang(Config.s_HostServ, u, HOST_NOREG, nick.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_HostServ, u, HOST_HELP_DEL); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_HostServ, u, "DEL", HOST_DEL_SYNTAX); } @@ -61,7 +61,7 @@ class CommandHSDel : public Command class HSDel : public Module { public: - HSDel(const std::string &modname, const std::string &creator) : Module(modname, creator) + HSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/hs_delall.cpp b/modules/core/hs_delall.cpp index cf249371a..caa02caad 100644 --- a/modules/core/hs_delall.cpp +++ b/modules/core/hs_delall.cpp @@ -20,15 +20,15 @@ class CommandHSDelAll : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); + Anope::string nick = params[0]; NickAlias *na; if ((na = findnick(nick))) { if (na->HasFlag(NS_FORBIDDEN)) { - notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick); + notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick.c_str()); return MOD_CONT; } FOREACH_MOD(I_OnDeleteVhost, OnDeleteVhost(na)); @@ -38,21 +38,21 @@ class CommandHSDelAll : public Command na = *it; na->hostinfo.RemoveVhost(); } - Alog() << "vHosts for all nicks in group \002" << nc->display << "\002 deleted by oper \002" << u->nick << "\002"; - notice_lang(Config.s_HostServ, u, HOST_DELALL, nc->display); + Alog() << "vHosts for all nicks in group \2" << nc->display << "\2 deleted by oper \2" << u->nick << "\2"; + notice_lang(Config.s_HostServ, u, HOST_DELALL, nc->display.c_str()); } else - notice_lang(Config.s_HostServ, u, HOST_NOREG, nick); + notice_lang(Config.s_HostServ, u, HOST_NOREG, nick.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_HostServ, u, HOST_HELP_DELALL); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_HostServ, u, "DELALL", HOST_DELALL_SYNTAX); } @@ -66,7 +66,7 @@ class CommandHSDelAll : public Command class HSDelAll : public Module { public: - HSDelAll(const std::string &modname, const std::string &creator) : Module(modname, creator) + HSDelAll(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/hs_group.cpp b/modules/core/hs_group.cpp index add5c1ecb..3aa0fc3c4 100644 --- a/modules/core/hs_group.cpp +++ b/modules/core/hs_group.cpp @@ -13,8 +13,6 @@ #include "module.h" -extern int do_hs_sync(NickCore *nc, char *vIdent, char *hostmask, char *creator, time_t time); - class CommandHSGroup : public Command { public: @@ -22,16 +20,16 @@ class CommandHSGroup : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na = findnick(u->nick); if (na && u->Account() == na->nc && na->hostinfo.HasVhost()) { HostServSyncVhosts(na); if (!na->hostinfo.GetIdent().empty()) - notice_lang(Config.s_HostServ, u, HOST_IDENT_GROUP, u->Account()->display, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); + notice_lang(Config.s_HostServ, u, HOST_IDENT_GROUP, u->Account()->display.c_str(), na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); else - notice_lang(Config.s_HostServ, u, HOST_GROUP, u->Account()->display, na->hostinfo.GetHost().c_str()); + notice_lang(Config.s_HostServ, u, HOST_GROUP, u->Account()->display.c_str(), na->hostinfo.GetHost().c_str()); } else notice_lang(Config.s_HostServ, u, HOST_NOT_ASSIGNED); @@ -39,7 +37,7 @@ class CommandHSGroup : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_HostServ, u, HOST_HELP_GROUP); return true; @@ -54,7 +52,7 @@ class CommandHSGroup : public Command class HSGroup : public Module { public: - HSGroup(const std::string &modname, const std::string &creator) : Module(modname, creator) + HSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/hs_help.cpp b/modules/core/hs_help.cpp index b4b20e149..4645590f5 100644 --- a/modules/core/hs_help.cpp +++ b/modules/core/hs_help.cpp @@ -21,15 +21,15 @@ class CommandHSHelp : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - mod_help_cmd(HostServ, u, params[0].c_str()); + mod_help_cmd(HostServ, u, params[0]); return MOD_CONT; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { - notice_help(Config.s_HostServ, u, HOST_HELP, Config.s_HostServ); + notice_help(Config.s_HostServ, u, HOST_HELP, Config.s_HostServ.c_str()); for (CommandMap::const_iterator it = HostServ->Commands.begin(), it_end = HostServ->Commands.end(); it != it_end; ++it) if (!Config.HidePrivilegedCommands || it->second->permission.empty() || (u->Account() && u->Account()->HasCommand(it->second->permission))) it->second->OnServHelp(u); @@ -39,7 +39,7 @@ class CommandHSHelp : public Command class HSHelp : public Module { public: - HSHelp(const std::string &modname, const std::string &creator) : Module(modname, creator) + HSHelp(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/hs_list.cpp b/modules/core/hs_list.cpp index 7e4d16cb8..9bb01e3c7 100644 --- a/modules/core/hs_list.cpp +++ b/modules/core/hs_list.cpp @@ -20,9 +20,9 @@ class CommandHSList : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string key = params.size() ? params[0] : ""; + Anope::string key = !params.empty() ? params[0] : ""; int from = 0, to = 0, counter = 1; unsigned display_counter = 0; tm *tm; @@ -35,20 +35,20 @@ class CommandHSList : public Command if (!key.empty() && key[0] == '#') { size_t tmp = key.find('-'); - if (tmp == ci::string::npos || tmp == key.size() || tmp == 1) + if (tmp == Anope::string::npos || tmp == key.length() || tmp == 1) { notice_lang(Config.s_HostServ, u, LIST_INCORRECT_RANGE); return MOD_CONT; } - for (unsigned i = 1, end = key.size(); i < end; ++i) + for (unsigned i = 1, end = key.length(); i < end; ++i) { if (!isdigit(key[i]) && i != tmp) { notice_lang(Config.s_HostServ, u, LIST_INCORRECT_RANGE); return MOD_CONT; } - from = atoi(key.substr(1, tmp - 1).c_str()); - to = atoi(key.substr(tmp + 1, key.size()).c_str()); + from = convertTo<int>(key.substr(1, tmp - 1)); + to = convertTo<int>(key.substr(tmp + 1)); } } @@ -61,16 +61,16 @@ class CommandHSList : public Command if (!key.empty() && key[0] != '#') { - if ((Anope::Match(na->nick, key) || Anope::Match(na->hostinfo.GetHost(), key.c_str())) && display_counter < Config.NSListMax) + if ((Anope::Match(na->nick, key) || Anope::Match(na->hostinfo.GetHost(), key)) && display_counter < Config.NSListMax) { ++display_counter; time_t time = na->hostinfo.GetTime(); tm = localtime(&time); strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); if (!na->hostinfo.GetIdent().empty()) - notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, na->nick, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf); + notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, na->nick.c_str(), na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf); else - notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, na->nick, na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf); + notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, na->nick.c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf); } } else @@ -86,9 +86,9 @@ class CommandHSList : public Command tm = localtime(&time); strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); if (!na->hostinfo.GetIdent().empty()) - notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, na->nick, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf); + notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, na->nick.c_str(), na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf); else - notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, na->nick, na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf); + notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, na->nick.c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf); } } ++counter; @@ -105,7 +105,7 @@ class CommandHSList : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_HostServ, u, HOST_HELP_LIST); return true; @@ -120,7 +120,7 @@ class CommandHSList : public Command class HSList : public Module { public: - HSList(const std::string &modname, const std::string &creator) : Module(modname, creator) + HSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/hs_off.cpp b/modules/core/hs_off.cpp index 6d87a1288..187854188 100644 --- a/modules/core/hs_off.cpp +++ b/modules/core/hs_off.cpp @@ -20,7 +20,7 @@ class CommandHSOff : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na = findnick(u->nick); @@ -35,7 +35,7 @@ class CommandHSOff : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_HostServ, u, HOST_HELP_OFF); return true; @@ -50,7 +50,7 @@ class CommandHSOff : public Command class HSOff : public Module { public: - HSOff(const std::string &modname, const std::string &creator) : Module(modname, creator) + HSOff(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/hs_on.cpp b/modules/core/hs_on.cpp index d58348d8d..25c21f8ec 100644 --- a/modules/core/hs_on.cpp +++ b/modules/core/hs_on.cpp @@ -20,7 +20,7 @@ class CommandHSOn : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na = findnick(u->nick); if (na && u->Account() == na->nc && na->hostinfo.HasVhost()) @@ -29,13 +29,9 @@ class CommandHSOn : public Command notice_lang(Config.s_HostServ, u, HOST_IDENT_ACTIVATED, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); else notice_lang(Config.s_HostServ, u, HOST_ACTIVATED, na->hostinfo.GetHost().c_str()); - ircdproto->SendVhost(u, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); + ircdproto->SendVhost(u, na->hostinfo.GetIdent(), na->hostinfo.GetHost()); if (ircd->vhost) - { - if (u->vhost) - delete [] u->vhost; - u->vhost = sstrdup(na->hostinfo.GetHost().c_str()); - } + u->vhost = na->hostinfo.GetHost(); if (ircd->vident) { if (!na->hostinfo.GetIdent().empty()) @@ -49,7 +45,7 @@ class CommandHSOn : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_HostServ, u, HOST_HELP_ON); return true; @@ -64,7 +60,7 @@ class CommandHSOn : public Command class HSOn : public Module { public: - HSOn(const std::string &modname, const std::string &creator) : Module(modname, creator) + HSOn(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/hs_set.cpp b/modules/core/hs_set.cpp index bf6c8788a..e492e9ff5 100644 --- a/modules/core/hs_set.cpp +++ b/modules/core/hs_set.cpp @@ -20,81 +20,55 @@ class CommandHSSet : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - const char *rawhostmask = params[1].c_str(); - char *hostmask = new char[Config.HostLen]; + Anope::string nick = params[0]; + Anope::string rawhostmask = params[1]; + Anope::string hostmask; NickAlias *na; int32 tmp_time; - char *s; - char *vIdent = NULL; - - vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ - if (vIdent) + Anope::string vIdent = myStrGetToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ + if (!vIdent.empty()) { rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */ - if (!rawhostmask) + if (rawhostmask.empty()) { - notice_lang(Config.s_HostServ, u, HOST_SET_SYNTAX, Config.s_HostServ); - delete [] vIdent; - delete [] hostmask; + notice_lang(Config.s_HostServ, u, HOST_SET_SYNTAX, Config.s_HostServ.c_str()); return MOD_CONT; } - if (strlen(vIdent) > Config.UserLen) + if (vIdent.length() > Config.UserLen) { notice_lang(Config.s_HostServ, u, HOST_SET_IDENTTOOLONG, Config.UserLen); - delete [] vIdent; - delete [] rawhostmask; - delete [] hostmask; return MOD_CONT; } else { - for (s = vIdent; *s; ++s) + for (Anope::string::iterator s = vIdent.begin(), s_end = vIdent.end(); s != s_end; ++s) if (!isvalidchar(*s)) { notice_lang(Config.s_HostServ, u, HOST_SET_IDENT_ERROR); - delete [] vIdent; - delete [] rawhostmask; - delete [] hostmask; return MOD_CONT; } } if (!ircd->vident) { notice_lang(Config.s_HostServ, u, HOST_NO_VIDENT); - delete [] vIdent; - delete [] rawhostmask; - delete [] hostmask; return MOD_CONT; } } - if (strlen(rawhostmask) < Config.HostLen) - snprintf(hostmask, Config.HostLen, "%s", rawhostmask); + if (rawhostmask.length() < Config.HostLen) + hostmask = rawhostmask; else { notice_lang(Config.s_HostServ, u, HOST_SET_TOOLONG, Config.HostLen); - if (vIdent) - { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; return MOD_CONT; } if (!isValidHost(hostmask, 3)) { notice_lang(Config.s_HostServ, u, HOST_SET_ERROR); - if (vIdent) - { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; return MOD_CONT; } @@ -104,42 +78,30 @@ class CommandHSSet : public Command { if (na->HasFlag(NS_FORBIDDEN)) { - notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick); - if (vIdent) - { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; + notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick.c_str()); return MOD_CONT; } - Alog() << "vHost for user \002" << nick << "\002 set to \002" << (vIdent && ircd->vident ? vIdent : "") << (vIdent && ircd->vident ? "@" : "") << hostmask << " \002 by oper \002" << u->nick << "\002"; + Alog() << "vHost for user \2" << nick << "\2 set to \2" << (!vIdent.empty() && ircd->vident ? vIdent : "") << (!vIdent.empty() && ircd->vident ? "@" : "") << hostmask << " \2 by oper \2" << u->nick << "\2"; - na->hostinfo.SetVhost(vIdent ? vIdent : "", hostmask, u->nick); + na->hostinfo.SetVhost(vIdent, hostmask, u->nick); FOREACH_MOD(I_OnSetVhost, OnSetVhost(na)); - if (vIdent) - notice_lang(Config.s_HostServ, u, HOST_IDENT_SET, nick, vIdent, hostmask); + if (!vIdent.empty()) + notice_lang(Config.s_HostServ, u, HOST_IDENT_SET, nick.c_str(), vIdent.c_str(), hostmask.c_str()); else - notice_lang(Config.s_HostServ, u, HOST_SET, nick, hostmask); + notice_lang(Config.s_HostServ, u, HOST_SET, nick.c_str(), hostmask.c_str()); } else - notice_lang(Config.s_HostServ, u, HOST_NOREG, nick); - delete [] hostmask; - if (vIdent) - { - delete [] vIdent; - delete [] rawhostmask; - } + notice_lang(Config.s_HostServ, u, HOST_NOREG, nick.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_HostServ, u, HOST_HELP_SET); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_HostServ, u, "SET", HOST_SET_SYNTAX); } @@ -153,7 +115,7 @@ class CommandHSSet : public Command class HSSet : public Module { public: - HSSet(const std::string &modname, const std::string &creator) : Module(modname, creator) + HSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/hs_setall.cpp b/modules/core/hs_setall.cpp index c0f3b1422..adf2f9610 100644 --- a/modules/core/hs_setall.cpp +++ b/modules/core/hs_setall.cpp @@ -20,125 +20,91 @@ class CommandHSSetAll : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - const char *rawhostmask = params[1].c_str(); - char *hostmask = new char[Config.HostLen]; + Anope::string nick = params[0]; + Anope::string rawhostmask = params[1]; + Anope::string hostmask; NickAlias *na; int32 tmp_time; - char *s; - - char *vIdent = NULL; if (!(na = findnick(nick))) { - delete [] hostmask; - notice_lang(Config.s_HostServ, u, HOST_NOREG, nick); + notice_lang(Config.s_HostServ, u, HOST_NOREG, nick.c_str()); return MOD_CONT; } else if (na->HasFlag(NS_FORBIDDEN)) { - delete [] hostmask; - notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick); + notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick.c_str()); return MOD_CONT; } - vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ - if (vIdent) + Anope::string vIdent = myStrGetToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ + if (!vIdent.empty()) { rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */ - if (!rawhostmask) + if (rawhostmask.empty()) { - notice_lang(Config.s_HostServ, u, HOST_SETALL_SYNTAX, Config.s_HostServ); - delete [] vIdent; - delete [] hostmask; + notice_lang(Config.s_HostServ, u, HOST_SETALL_SYNTAX, Config.s_HostServ.c_str()); return MOD_CONT; } - if (strlen(vIdent) > Config.UserLen) + if (vIdent.length() > Config.UserLen) { notice_lang(Config.s_HostServ, u, HOST_SET_IDENTTOOLONG, Config.UserLen); - delete [] vIdent; - delete [] rawhostmask; - delete [] hostmask; return MOD_CONT; } else { - for (s = vIdent; *s; ++s) + for (Anope::string::iterator s = vIdent.begin(), s_end = vIdent.end(); s != s_end; ++s) if (!isvalidchar(*s)) { notice_lang(Config.s_HostServ, u, HOST_SET_IDENT_ERROR); - delete [] vIdent; - delete [] rawhostmask; - delete [] hostmask; return MOD_CONT; } } if (!ircd->vident) { notice_lang(Config.s_HostServ, u, HOST_NO_VIDENT); - delete [] vIdent; - delete [] rawhostmask; - delete [] hostmask; return MOD_CONT; } } - if (strlen(rawhostmask) < Config.HostLen) - snprintf(hostmask, Config.HostLen, "%s", rawhostmask); + if (rawhostmask.length() < Config.HostLen) + hostmask = rawhostmask; else { notice_lang(Config.s_HostServ, u, HOST_SET_TOOLONG, Config.HostLen); - if (vIdent) - { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; return MOD_CONT; } if (!isValidHost(hostmask, 3)) { notice_lang(Config.s_HostServ, u, HOST_SET_ERROR); - if (vIdent) - { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; return MOD_CONT; } tmp_time = time(NULL); - Alog() << "vHost for all nicks in group \002" << nick << "\002 set to \002" << (vIdent && ircd->vident ? vIdent : "") << (vIdent && ircd->vident ? "@" : "") << hostmask << " \002 by oper \002" << u->nick << "\002"; + Alog() << "vHost for all nicks in group \2" << nick << "\2 set to \2" << (!vIdent.empty() && ircd->vident ? vIdent : "") << (!vIdent.empty() && ircd->vident ? "@" : "") << hostmask << " \2 by oper \2" << u->nick << "\2"; - na->hostinfo.SetVhost(vIdent ? vIdent : "", hostmask, u->nick); + na->hostinfo.SetVhost(vIdent, hostmask, u->nick); HostServSyncVhosts(na); FOREACH_MOD(I_OnSetVhost, OnSetVhost(na)); - if (vIdent) - notice_lang(Config.s_HostServ, u, HOST_IDENT_SETALL, nick, vIdent, hostmask); + if (!vIdent.empty()) + notice_lang(Config.s_HostServ, u, HOST_IDENT_SETALL, nick.c_str(), vIdent.c_str(), hostmask.c_str()); else - notice_lang(Config.s_HostServ, u, HOST_SETALL, nick, hostmask); - if (vIdent) - { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; + notice_lang(Config.s_HostServ, u, HOST_SETALL, nick.c_str(), hostmask.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_HostServ, u, HOST_HELP_SETALL); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_HostServ, u, "SETALL", HOST_SETALL_SYNTAX); } @@ -152,7 +118,7 @@ class CommandHSSetAll : public Command class HSSetAll : public Module { public: - HSSetAll(const std::string &modname, const std::string &creator) : Module(modname, creator) + HSSetAll(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ms_cancel.cpp b/modules/core/ms_cancel.cpp index af26ab6b8..9e3c52417 100644 --- a/modules/core/ms_cancel.cpp +++ b/modules/core/ms_cancel.cpp @@ -22,32 +22,32 @@ class CommandMSCancel : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { int ischan; int isforbid; - const char *name = params[0].c_str(); + Anope::string name = params[0]; MemoInfo *mi; if (!u->IsRecognized()) - notice_lang(Config.s_MemoServ, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ); + notice_lang(Config.s_MemoServ, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ.c_str()); else if (!(mi = getmemoinfo(name, &ischan, &isforbid))) { if (isforbid) - notice_lang(Config.s_MemoServ, u, ischan ? CHAN_X_FORBIDDEN : NICK_X_FORBIDDEN, name); + notice_lang(Config.s_MemoServ, u, ischan ? CHAN_X_FORBIDDEN : NICK_X_FORBIDDEN, name.c_str()); else - notice_lang(Config.s_MemoServ, u, ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, name); + notice_lang(Config.s_MemoServ, u, ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, name.c_str()); } else { int i; for (i = mi->memos.size() - 1; i >= 0; --i) - if ((mi->memos[i]->HasFlag(MF_UNREAD)) && !stricmp(mi->memos[i]->sender.c_str(), u->Account()->display) && !mi->memos[i]->HasFlag(MF_NOTIFYS)) + if (mi->memos[i]->HasFlag(MF_UNREAD) && u->Account()->display.equals_ci(mi->memos[i]->sender) && !mi->memos[i]->HasFlag(MF_NOTIFYS)) { FOREACH_MOD(I_OnMemoDel, OnMemoDel(findnick(name)->nc, mi, mi->memos[i]->number)); delmemo(mi, mi->memos[i]->number); - notice_lang(Config.s_MemoServ, u, MEMO_CANCELLED, name); + notice_lang(Config.s_MemoServ, u, MEMO_CANCELLED, name.c_str()); return MOD_CONT; } @@ -56,13 +56,13 @@ class CommandMSCancel : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_MemoServ, u, MEMO_HELP_CANCEL); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_MemoServ, u, "CANCEL", MEMO_CANCEL_SYNTAX); } @@ -76,10 +76,11 @@ class CommandMSCancel : public Command class MSCancel : public Module { public: - MSCancel(const std::string &modname, const std::string &creator) : Module(modname, creator) + MSCancel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(MemoServ, new CommandMSCancel()); } }; diff --git a/modules/core/ms_check.cpp b/modules/core/ms_check.cpp index 62400641b..9f237fa15 100644 --- a/modules/core/ms_check.cpp +++ b/modules/core/ms_check.cpp @@ -20,29 +20,29 @@ class CommandMSCheck : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na = NULL; MemoInfo *mi = NULL; int i, found = 0; - const char *recipient = params[0].c_str(); + Anope::string recipient = params[0]; struct tm *tm; char timebuf[64]; if (!u->IsRecognized()) { - notice_lang(Config.s_MemoServ, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ); + notice_lang(Config.s_MemoServ, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ.c_str()); return MOD_CONT; } else if (!(na = findnick(recipient))) { - notice_lang(Config.s_MemoServ, u, NICK_X_NOT_REGISTERED, recipient); + notice_lang(Config.s_MemoServ, u, NICK_X_NOT_REGISTERED, recipient.c_str()); return MOD_CONT; } if (na->HasFlag(NS_FORBIDDEN)) { - notice_lang(Config.s_MemoServ, u, NICK_X_FORBIDDEN, recipient); + notice_lang(Config.s_MemoServ, u, NICK_X_FORBIDDEN, recipient.c_str()); return MOD_CONT; } @@ -53,7 +53,7 @@ class CommandMSCheck : public Command for (i = mi->memos.size() - 1; i >= 0; --i) { - if (!stricmp(mi->memos[i]->sender.c_str(), u->Account()->display)) + if (u->Account()->display.equals_ci(mi->memos[i]->sender)) { found = 1; /* Yes, we've found the memo */ @@ -61,26 +61,26 @@ class CommandMSCheck : public Command strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_DATE_TIME_FORMAT, tm); if (mi->memos[i]->HasFlag(MF_UNREAD)) - notice_lang(Config.s_MemoServ, u, MEMO_CHECK_NOT_READ, na->nick, timebuf); + notice_lang(Config.s_MemoServ, u, MEMO_CHECK_NOT_READ, na->nick.c_str(), timebuf); else - notice_lang(Config.s_MemoServ, u, MEMO_CHECK_READ, na->nick, timebuf); + notice_lang(Config.s_MemoServ, u, MEMO_CHECK_READ, na->nick.c_str(), timebuf); break; } } if (!found) - notice_lang(Config.s_MemoServ, u, MEMO_CHECK_NO_MEMO, na->nick); + notice_lang(Config.s_MemoServ, u, MEMO_CHECK_NO_MEMO, na->nick.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_MemoServ, u, MEMO_HELP_CHECK); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_MemoServ, u, "CHECK", MEMO_CHECK_SYNTAX); } @@ -94,7 +94,7 @@ class CommandMSCheck : public Command class MSCheck : public Module { public: - MSCheck(const std::string &modname, const std::string &creator) : Module(modname, creator) + MSCheck(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ms_del.cpp b/modules/core/ms_del.cpp index 270bac4f3..f6e21269e 100644 --- a/modules/core/ms_del.cpp +++ b/modules/core/ms_del.cpp @@ -19,7 +19,7 @@ class MemoDelCallback : public NumberList ChannelInfo *ci; MemoInfo *mi; public: - MemoDelCallback(User *_u, ChannelInfo *_ci, MemoInfo *_mi, const std::string &list) : NumberList(list, true), u(_u), ci(_ci), mi(_mi) + MemoDelCallback(User *_u, ChannelInfo *_ci, MemoInfo *_mi, const Anope::string &list) : NumberList(list, true), u(_u), ci(_ci), mi(_mi) { } @@ -44,11 +44,11 @@ class CommandMSDel : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { MemoInfo *mi; ChannelInfo *ci = NULL; - ci::string numstr = params.size() ? params[0] : "", chan; + Anope::string numstr = !params.empty() ? params[0] : "", chan; unsigned i, end; int last; @@ -76,7 +76,7 @@ class CommandMSDel : public Command } else mi = &u->Account()->memos; - if (numstr.empty() || (!isdigit(numstr[0]) && numstr != "ALL" && numstr != "LAST")) + if (numstr.empty() || (!isdigit(numstr[0]) && !numstr.equals_ci("ALL") && !numstr.equals_ci("LAST"))) this->OnSyntaxError(u, numstr); else if (mi->memos.empty()) { @@ -89,10 +89,10 @@ class CommandMSDel : public Command { if (isdigit(numstr[0])) { - MemoDelCallback list(u, ci, mi, numstr.c_str()); + MemoDelCallback list(u, ci, mi, numstr); list.Process(); } - else if (numstr == "LAST") + else if (numstr.equals_ci("LAST")) { /* Delete last memo. */ for (i = 0, end = mi->memos.size(); i < end; ++i) @@ -112,10 +112,7 @@ class CommandMSDel : public Command FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, 0)); /* Delete all memos. */ for (i = 0, end = mi->memos.size(); i < end; ++i) - { - delete [] mi->memos[i]->text; delete mi->memos[i]; - } mi->memos.clear(); if (!chan.empty()) notice_lang(Config.s_MemoServ, u, MEMO_CHAN_DELETED_ALL, chan.c_str()); @@ -130,13 +127,13 @@ class CommandMSDel : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_MemoServ, u, MEMO_HELP_DEL); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_MemoServ, u, "DEL", MEMO_DEL_SYNTAX); } @@ -150,7 +147,7 @@ class CommandMSDel : public Command class MSDel : public Module { public: - MSDel(const std::string &modname, const std::string &creator) : Module(modname, creator) + MSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ms_help.cpp b/modules/core/ms_help.cpp index 41cdaafb3..793006a60 100644 --- a/modules/core/ms_help.cpp +++ b/modules/core/ms_help.cpp @@ -21,26 +21,26 @@ class CommandMSHelp : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - mod_help_cmd(MemoServ, u, params[0].c_str()); + mod_help_cmd(MemoServ, u, params[0]); return MOD_CONT; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { notice_help(Config.s_MemoServ, u, MEMO_HELP_HEADER); for (CommandMap::const_iterator it = MemoServ->Commands.begin(), it_end = MemoServ->Commands.end(); it != it_end; ++it) if (!Config.HidePrivilegedCommands || it->second->permission.empty() || (u->Account() && u->Account()->HasCommand(it->second->permission))) it->second->OnServHelp(u); - notice_help(Config.s_MemoServ, u, MEMO_HELP_FOOTER, Config.s_ChanServ); + notice_help(Config.s_MemoServ, u, MEMO_HELP_FOOTER, Config.s_ChanServ.c_str()); } }; class MSHelp : public Module { public: - MSHelp(const std::string &modname, const std::string &creator) : Module(modname, creator) + MSHelp(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ms_info.cpp b/modules/core/ms_info.cpp index 1a368baf9..f5a3f8c4c 100644 --- a/modules/core/ms_info.cpp +++ b/modules/core/ms_info.cpp @@ -20,35 +20,35 @@ class CommandMSInfo : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - MemoInfo *mi; + const MemoInfo *mi; NickAlias *na = NULL; ChannelInfo *ci = NULL; - const char *name = params.size() ? params[0].c_str() : NULL; + Anope::string name = !params.empty() ? params[0] : ""; int hardmax = 0; - if (name && *name != '#' && u->Account()->HasPriv("memoserv/info")) + if (!name.empty() && name[0] != '#' && u->Account()->HasPriv("memoserv/info")) { na = findnick(name); if (!na) { - notice_lang(Config.s_MemoServ, u, NICK_X_NOT_REGISTERED, name); + notice_lang(Config.s_MemoServ, u, NICK_X_NOT_REGISTERED, name.c_str()); return MOD_CONT; } else if (na->HasFlag(NS_FORBIDDEN)) { - notice_lang(Config.s_MemoServ, u, NICK_X_FORBIDDEN, name); + notice_lang(Config.s_MemoServ, u, NICK_X_FORBIDDEN, name.c_str()); return MOD_CONT; } mi = &na->nc->memos; hardmax = na->nc->HasFlag(NI_MEMO_HARDMAX) ? 1 : 0; } - else if (name && *name == '#') + else if (!name.empty() && name[0] == '#') { if (!(ci = cs_findchan(name))) { - notice_lang(Config.s_MemoServ, u, CHAN_X_NOT_REGISTERED, name); + notice_lang(Config.s_MemoServ, u, CHAN_X_NOT_REGISTERED, name.c_str()); return MOD_CONT; } else if (!check_access(u, ci, CA_MEMO)) @@ -59,7 +59,7 @@ class CommandMSInfo : public Command mi = &ci->memos; hardmax = ci->HasFlag(CI_MEMO_HARDMAX) ? 1 : 0; } - else if (name) /* It's not a chan and we aren't services admin */ + else if (!name.empty()) /* It's not a chan and we aren't services admin */ { notice_lang(Config.s_MemoServ, u, ACCESS_DENIED); return MOD_CONT; @@ -70,16 +70,16 @@ class CommandMSInfo : public Command hardmax = u->Account()->HasFlag(NI_MEMO_HARDMAX) ? 1 : 0; } - if (name && (ci || na->nc != u->Account())) + if (!name.empty() && (ci || na->nc != u->Account())) { if (mi->memos.empty()) - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_NO_MEMOS, name); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_NO_MEMOS, name.c_str()); else if (mi->memos.size() == 1) { if (mi->memos[0]->HasFlag(MF_UNREAD)) - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_MEMO_UNREAD, name); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_MEMO_UNREAD, name.c_str()); else - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_MEMO, name); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_MEMO, name.c_str()); } else { @@ -88,43 +88,43 @@ class CommandMSInfo : public Command if (mi->memos[i]->HasFlag(MF_UNREAD)) ++count; if (count == mi->memos.size()) - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_MEMOS_ALL_UNREAD, name, count); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_MEMOS_ALL_UNREAD, name.c_str(), count); else if (!count) - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_MEMOS, name, mi->memos.size()); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_MEMOS, name.c_str(), mi->memos.size()); else if (count == 1) - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_MEMOS_ONE_UNREAD, name, mi->memos.size()); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_MEMOS_ONE_UNREAD, name.c_str(), mi->memos.size()); else - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_MEMOS_SOME_UNREAD, name, mi->memos.size(), count); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_MEMOS_SOME_UNREAD, name.c_str(), mi->memos.size(), count); } if (!mi->memomax) { if (hardmax) - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_HARD_LIMIT, name, mi->memomax); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_HARD_LIMIT, name.c_str(), mi->memomax); else - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_LIMIT, name, mi->memomax); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_LIMIT, name.c_str(), mi->memomax); } else if (mi->memomax > 0) { if (hardmax) - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_HARD_LIMIT, name, mi->memomax); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_HARD_LIMIT, name.c_str(), mi->memomax); else - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_LIMIT, name, mi->memomax); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_LIMIT, name.c_str(), mi->memomax); } else - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_NO_LIMIT, name); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_NO_LIMIT, name.c_str()); /* I ripped this code out of ircservices 4.4.5, since I didn't want to rewrite the whole thing (it pisses me off). */ if (na) { if (na->nc->HasFlag(NI_MEMO_RECEIVE) && na->nc->HasFlag(NI_MEMO_SIGNON)) - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_NOTIFY_ON, name); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_NOTIFY_ON, name.c_str()); else if (na->nc->HasFlag(NI_MEMO_RECEIVE)) - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_NOTIFY_RECEIVE, name); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_NOTIFY_RECEIVE, name.c_str()); else if (na->nc->HasFlag(NI_MEMO_SIGNON)) - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_NOTIFY_SIGNON, name); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_NOTIFY_SIGNON, name.c_str()); else - notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_NOTIFY_OFF, name); + notice_lang(Config.s_MemoServ, u, MEMO_INFO_X_NOTIFY_OFF, name.c_str()); } } else /* !name || (!ci || na->nc == u->Account()) */ @@ -184,7 +184,7 @@ class CommandMSInfo : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (u->Account() && u->Account()->IsServicesOper()) notice_help(Config.s_MemoServ, u, MEMO_SERVADMIN_HELP_INFO); @@ -203,7 +203,7 @@ class CommandMSInfo : public Command class MSInfo : public Module { public: - MSInfo(const std::string &modname, const std::string &creator) : Module(modname, creator) + MSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ms_list.cpp b/modules/core/ms_list.cpp index 6630c28db..bf6eda5f9 100644 --- a/modules/core/ms_list.cpp +++ b/modules/core/ms_list.cpp @@ -17,10 +17,10 @@ class MemoListCallback : public NumberList { User *u; ChannelInfo *ci; - MemoInfo *mi; + const MemoInfo *mi; bool SentHeader; public: - MemoListCallback(User *_u, ChannelInfo *_ci, MemoInfo *_mi, const std::string &list) : NumberList(list, false), u(_u), ci(_ci), mi(_mi), SentHeader(false) + MemoListCallback(User *_u, ChannelInfo *_ci, const MemoInfo *_mi, const Anope::string &list) : NumberList(list, false), u(_u), ci(_ci), mi(_mi), SentHeader(false) { } @@ -33,9 +33,9 @@ class MemoListCallback : public NumberList { SentHeader = true; if (ci) - notice_lang(Config.s_MemoServ, u, MEMO_LIST_CHAN_MEMOS, ci->name.c_str(), Config.s_MemoServ, ci->name.c_str()); + notice_lang(Config.s_MemoServ, u, MEMO_LIST_CHAN_MEMOS, ci->name.c_str(), Config.s_MemoServ.c_str(), ci->name.c_str()); else - notice_lang(Config.s_MemoServ, u, MEMO_LIST_MEMOS, u->nick.c_str(), Config.s_MemoServ); + notice_lang(Config.s_MemoServ, u, MEMO_LIST_MEMOS, u->nick.c_str(), Config.s_MemoServ.c_str()); notice_lang(Config.s_MemoServ, u, MEMO_LIST_HEADER); } @@ -43,7 +43,7 @@ class MemoListCallback : public NumberList DoList(u, ci, mi, Number - 1); } - static void DoList(User *u, ChannelInfo *ci, MemoInfo *mi, unsigned index) + static void DoList(User *u, ChannelInfo *ci, const MemoInfo *mi, unsigned index) { Memo *m = mi->memos[index]; struct tm tm = *localtime(&m->time); @@ -61,11 +61,11 @@ class CommandMSList : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string param = params.size() ? params[0] : "", chan; + Anope::string param = !params.empty() ? params[0] : "", chan; ChannelInfo *ci; - MemoInfo *mi; + const MemoInfo *mi; int i, end; if (!param.empty() && param[0] == '#') @@ -87,7 +87,7 @@ class CommandMSList : public Command } else mi = &u->Account()->memos; - if (!param.empty() && !isdigit(param[0]) && param != "NEW") + if (!param.empty() && !isdigit(param[0]) && !param.equals_ci("NEW")) this->OnSyntaxError(u, param); else if (!mi->memos.size()) { @@ -100,7 +100,7 @@ class CommandMSList : public Command { if (!param.empty() && isdigit(param[0])) { - MemoListCallback list(u, ci, mi, param.c_str()); + MemoListCallback list(u, ci, mi, param); list.Process(); } else @@ -124,16 +124,16 @@ class CommandMSList : public Command for (i = 0, end = mi->memos.size(); i < end; ++i) { - if (!param.empty() && !(mi->memos[i]->HasFlag(MF_UNREAD))) + if (!param.empty() && !mi->memos[i]->HasFlag(MF_UNREAD)) continue; if (!SentHeader) { SentHeader = true; if (ci) - notice_lang(Config.s_MemoServ, u, !param.empty() ? MEMO_LIST_CHAN_NEW_MEMOS : MEMO_LIST_CHAN_MEMOS, ci->name.c_str(), Config.s_MemoServ, ci->name.c_str()); + notice_lang(Config.s_MemoServ, u, !param.empty() ? MEMO_LIST_CHAN_NEW_MEMOS : MEMO_LIST_CHAN_MEMOS, ci->name.c_str(), Config.s_MemoServ.c_str(), ci->name.c_str()); else - notice_lang(Config.s_MemoServ, u, !param.empty() ? MEMO_LIST_NEW_MEMOS : MEMO_LIST_MEMOS, u->nick.c_str(), Config.s_MemoServ); + notice_lang(Config.s_MemoServ, u, !param.empty() ? MEMO_LIST_NEW_MEMOS : MEMO_LIST_MEMOS, u->nick.c_str(), Config.s_MemoServ.c_str()); notice_lang(Config.s_MemoServ, u, MEMO_LIST_HEADER); } @@ -144,13 +144,13 @@ class CommandMSList : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_MemoServ, u, MEMO_HELP_LIST); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_MemoServ, u, "LIST", MEMO_LIST_SYNTAX); } @@ -164,7 +164,7 @@ class CommandMSList : public Command class MSList : public Module { public: - MSList(const std::string &modname, const std::string &creator) : Module(modname, creator) + MSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ms_read.cpp b/modules/core/ms_read.cpp index d779471b3..d2593daf1 100644 --- a/modules/core/ms_read.cpp +++ b/modules/core/ms_read.cpp @@ -18,7 +18,7 @@ class MemoListCallback : public NumberList User *u; MemoInfo *mi; public: - MemoListCallback(User *_u, MemoInfo *_mi, const std::string &numlist) : NumberList(numlist, false), u(_u), mi(_mi) + MemoListCallback(User *_u, MemoInfo *_mi, const Anope::string &numlist) : NumberList(numlist, false), u(_u), mi(_mi) { } @@ -38,15 +38,15 @@ class MemoListCallback : public NumberList strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_DATE_TIME_FORMAT, &tm); timebuf[sizeof(timebuf) - 1] = 0; if (ci) - notice_lang(Config.s_MemoServ, u, MEMO_CHAN_HEADER, m->number, m->sender.c_str(), timebuf, Config.s_MemoServ, ci->name.c_str(), m->number); + notice_lang(Config.s_MemoServ, u, MEMO_CHAN_HEADER, m->number, m->sender.c_str(), timebuf, Config.s_MemoServ.c_str(), ci->name.c_str(), m->number); else - notice_lang(Config.s_MemoServ, u, MEMO_HEADER, m->number, m->sender.c_str(), timebuf, Config.s_MemoServ, m->number); - notice_lang(Config.s_MemoServ, u, MEMO_TEXT, m->text); + notice_lang(Config.s_MemoServ, u, MEMO_HEADER, m->number, m->sender.c_str(), timebuf, Config.s_MemoServ.c_str(), m->number); + notice_lang(Config.s_MemoServ, u, MEMO_TEXT, m->text.c_str()); m->UnsetFlag(MF_UNREAD); /* Check if a receipt notification was requested */ if (m->HasFlag(MF_RECEIPT)) - rsend_notify(u, m, ci ? ci->name.c_str() : NULL); + rsend_notify(u, m, ci ? ci->name : ""); } }; @@ -57,11 +57,11 @@ class CommandMSRead : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { MemoInfo *mi; ChannelInfo *ci = NULL; - ci::string numstr = params.size() ? params[0] : "", chan; + Anope::string numstr = !params.empty() ? params[0] : "", chan; int num; if (!numstr.empty() && numstr[0] == '#') @@ -83,8 +83,8 @@ class CommandMSRead : public Command } else mi = &u->Account()->memos; - num = !numstr.empty() ? atoi(numstr.c_str()) : -1; - if (numstr.empty() || (numstr != "LAST" && numstr != "NEW" && num <= 0)) + num = !numstr.empty() && numstr.is_number_only() ? convertTo<int>(numstr) : -1; + if (numstr.empty() || (!numstr.equals_ci("LAST") && !numstr.equals_ci("NEW") && num <= 0)) this->OnSyntaxError(u, numstr); else if (mi->memos.empty()) { @@ -96,7 +96,7 @@ class CommandMSRead : public Command else { int i, end; - if (numstr == "NEW") + if (numstr.equals_ci("NEW")) { int readcount = 0; for (i = 0, end = mi->memos.size(); i < end; ++i) @@ -113,27 +113,27 @@ class CommandMSRead : public Command notice_lang(Config.s_MemoServ, u, MEMO_HAVE_NO_NEW_MEMOS); } } - else if (numstr == "LAST") + else if (numstr.equals_ci("LAST")) { for (i = 0, end = mi->memos.size() - 1; i < end; ++i); MemoListCallback::DoRead(u, mi, ci, i); } else /* number[s] */ { - MemoListCallback list(u, mi, numstr.c_str()); + MemoListCallback list(u, mi, numstr); list.Process(); } } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_MemoServ, u, MEMO_HELP_READ); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_MemoServ, u, "READ", MEMO_READ_SYNTAX); } @@ -147,7 +147,7 @@ class CommandMSRead : public Command class MSRead : public Module { public: - MSRead(const std::string &modname, const std::string &creator) : Module(modname, creator) + MSRead(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ms_rsend.cpp b/modules/core/ms_rsend.cpp index 0c21ac5fc..1caa9fe74 100644 --- a/modules/core/ms_rsend.cpp +++ b/modules/core/ms_rsend.cpp @@ -20,12 +20,11 @@ class CommandMSRSend : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - const char *text = params[1].c_str(); + Anope::string nick = params[0]; + Anope::string text = params[1]; NickAlias *na = NULL; - int z = 3; /* prevent user from rsend to themselves */ if ((na = findnick(nick)) && na->nc == u->Account()) @@ -38,13 +37,13 @@ class CommandMSRSend : public Command { /* Services opers and above can use rsend */ if (u->Account()->IsServicesOper()) - memo_send(u, nick, text, z); + memo_send(u, nick, text, 3); else notice_lang(Config.s_MemoServ, u, ACCESS_DENIED); } else if (Config.MSMemoReceipt == 2) /* Everybody can use rsend */ - memo_send(u, nick, text, z); + memo_send(u, nick, text, 3); else { /* rsend has been disabled */ @@ -55,13 +54,13 @@ class CommandMSRSend : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_MemoServ, u, MEMO_HELP_RSEND); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_MemoServ, u, "RSEND", MEMO_RSEND_SYNTAX); } @@ -75,7 +74,7 @@ class CommandMSRSend : public Command class MSRSend : public Module { public: - MSRSend(const std::string &modname, const std::string &creator) : Module(modname, creator) + MSRSend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { if (!Config.MSMemoReceipt) throw ModuleException("Don't like memo reciepts, or something."); diff --git a/modules/core/ms_send.cpp b/modules/core/ms_send.cpp index 5f55fc774..fd2f3636c 100644 --- a/modules/core/ms_send.cpp +++ b/modules/core/ms_send.cpp @@ -20,22 +20,21 @@ class CommandMSSend : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - const char *text = params[1].c_str(); - int z = 0; - memo_send(u, nick, text, z); + Anope::string nick = params[0]; + Anope::string text = params[1]; + memo_send(u, nick, text, 0); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_MemoServ, u, MEMO_HELP_SEND); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_MemoServ, u, "SEND", MEMO_SEND_SYNTAX); } @@ -49,7 +48,7 @@ class CommandMSSend : public Command class MSSend : public Module { public: - MSSend(const std::string &modname, const std::string &creator) : Module(modname, creator) + MSSend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ms_sendall.cpp b/modules/core/ms_sendall.cpp index 16b95f928..35efd2f1e 100644 --- a/modules/core/ms_sendall.cpp +++ b/modules/core/ms_sendall.cpp @@ -20,10 +20,9 @@ class CommandMSSendAll : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - int z = 1; - const char *text = params[0].c_str(); + Anope::string text = params[0]; if (readonly) { @@ -37,21 +36,21 @@ class CommandMSSendAll : public Command { NickCore *nc = it->second; - if ((na && na->nc == nc) || stricmp(u->nick.c_str(), nc->display)) - memo_send(u, nc->display, text, z); + if ((na && na->nc == nc) || !nc->display.equals_ci(u->nick)) + memo_send(u, nc->display, text, 1); } notice_lang(Config.s_MemoServ, u, MEMO_MASS_SENT); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_MemoServ, u, MEMO_HELP_SENDALL); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_MemoServ, u, "SENDALL", MEMO_SEND_SYNTAX); } @@ -65,7 +64,7 @@ class CommandMSSendAll : public Command class MSSendAll : public Module { public: - MSSendAll(const std::string &modname, const std::string &creator) : Module(modname, creator) + MSSendAll(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ms_set.cpp b/modules/core/ms_set.cpp index 11ba9d9cc..58f33b1ee 100644 --- a/modules/core/ms_set.cpp +++ b/modules/core/ms_set.cpp @@ -16,31 +16,31 @@ class CommandMSSet : public Command { private: - CommandReturn DoNotify(User *u, const std::vector<ci::string> ¶ms, MemoInfo *mi) + CommandReturn DoNotify(User *u, const std::vector<Anope::string> ¶ms, MemoInfo *mi) { - ci::string param = params[1]; + Anope::string param = params[1]; - if (param == "ON") + if (param.equals_ci("ON")) { u->Account()->SetFlag(NI_MEMO_SIGNON); u->Account()->SetFlag(NI_MEMO_RECEIVE); - notice_lang(Config.s_MemoServ, u, MEMO_SET_NOTIFY_ON, Config.s_MemoServ); + notice_lang(Config.s_MemoServ, u, MEMO_SET_NOTIFY_ON, Config.s_MemoServ.c_str()); } - else if (param == "LOGON") + else if (param.equals_ci("LOGON")) { u->Account()->SetFlag(NI_MEMO_SIGNON); u->Account()->UnsetFlag(NI_MEMO_RECEIVE); - notice_lang(Config.s_MemoServ, u, MEMO_SET_NOTIFY_LOGON, Config.s_MemoServ); + notice_lang(Config.s_MemoServ, u, MEMO_SET_NOTIFY_LOGON, Config.s_MemoServ.c_str()); } - else if (param == "NEW") + else if (param.equals_ci("NEW")) { u->Account()->UnsetFlag(NI_MEMO_SIGNON); u->Account()->SetFlag(NI_MEMO_RECEIVE); - notice_lang(Config.s_MemoServ, u, MEMO_SET_NOTIFY_NEW, Config.s_MemoServ); + notice_lang(Config.s_MemoServ, u, MEMO_SET_NOTIFY_NEW, Config.s_MemoServ.c_str()); } - else if (param == "MAIL") + else if (param.equals_ci("MAIL")) { - if (u->Account()->email) + if (!u->Account()->email.empty()) { u->Account()->SetFlag(NI_MEMO_MAIL); notice_lang(Config.s_MemoServ, u, MEMO_SET_NOTIFY_MAIL); @@ -48,29 +48,29 @@ class CommandMSSet : public Command else notice_lang(Config.s_MemoServ, u, MEMO_SET_NOTIFY_INVALIDMAIL); } - else if (param == "NOMAIL") + else if (param.equals_ci("NOMAIL")) { u->Account()->UnsetFlag(NI_MEMO_MAIL); notice_lang(Config.s_MemoServ, u, MEMO_SET_NOTIFY_NOMAIL); } - else if (param == "OFF") + else if (param.equals_ci("OFF")) { u->Account()->UnsetFlag(NI_MEMO_SIGNON); u->Account()->UnsetFlag(NI_MEMO_RECEIVE); u->Account()->UnsetFlag(NI_MEMO_MAIL); - notice_lang(Config.s_MemoServ, u, MEMO_SET_NOTIFY_OFF, Config.s_MemoServ); + notice_lang(Config.s_MemoServ, u, MEMO_SET_NOTIFY_OFF, Config.s_MemoServ.c_str()); } else syntax_error(Config.s_MemoServ, u, "SET NOTIFY", MEMO_SET_NOTIFY_SYNTAX); return MOD_CONT; } - CommandReturn DoLimit(User *u, const std::vector<ci::string> ¶ms, MemoInfo *mi) + CommandReturn DoLimit(User *u, const std::vector<Anope::string> ¶ms, MemoInfo *mi) { - ci::string p1 = params[1]; - ci::string p2 = params.size() > 2 ? params[2] : ""; - ci::string p3 = params.size() > 3 ? params[3] : ""; - ci::string user, chan; + Anope::string p1 = params[1]; + Anope::string p2 = params.size() > 2 ? params[2] : ""; + Anope::string p3 = params.size() > 3 ? params[3] : ""; + Anope::string user, chan; int32 limit; NickCore *nc = u->Account(); ChannelInfo *ci = NULL; @@ -96,7 +96,7 @@ class CommandMSSet : public Command } if (is_servadmin) { - if (!p2.empty() && p2 != "HARD" && chan.empty()) + if (!p2.empty() && !p2.equals_ci("HARD") && chan.empty()) { NickAlias *na; if (!(na = findnick(p1))) @@ -115,7 +115,7 @@ class CommandMSSet : public Command syntax_error(Config.s_MemoServ, u, "SET LIMIT", MEMO_SET_LIMIT_SERVADMIN_SYNTAX); return MOD_CONT; } - if ((!isdigit(p1[0]) && p1 != "NONE") || (!p2.empty() && p2 != "HARD")) + if ((!isdigit(p1[0]) && !p1.equals_ci("NONE")) || (!p2.empty() && !p2.equals_ci("HARD"))) { syntax_error(Config.s_MemoServ, u, "SET LIMIT", MEMO_SET_LIMIT_SERVADMIN_SYNTAX); return MOD_CONT; @@ -134,32 +134,33 @@ class CommandMSSet : public Command else nc->UnsetFlag(NI_MEMO_HARDMAX); } - limit = atoi(p1.c_str()); + limit = p1.is_number_only() ? convertTo<int32>(p1) : -1; if (limit < 0 || limit > 32767) { notice_lang(Config.s_MemoServ, u, MEMO_SET_LIMIT_OVERFLOW, 32767); limit = 32767; } - if (p1 == "NONE") + if (p1.equals_ci("NONE")) limit = -1; } else { - if (p1.empty() || !p2.empty() || !isdigit(p1[0])) { + if (p1.empty() || !p2.empty() || !isdigit(p1[0])) + { syntax_error(Config.s_MemoServ, u, "SET LIMIT", MEMO_SET_LIMIT_SYNTAX); return MOD_CONT; } - if (!chan.empty() && (ci->HasFlag(CI_MEMO_HARDMAX))) + if (!chan.empty() && ci->HasFlag(CI_MEMO_HARDMAX)) { notice_lang(Config.s_MemoServ, u, MEMO_SET_LIMIT_FORBIDDEN, chan.c_str()); return MOD_CONT; } - else if (chan.empty() && (nc->HasFlag(NI_MEMO_HARDMAX))) + else if (chan.empty() && nc->HasFlag(NI_MEMO_HARDMAX)) { notice_lang(Config.s_MemoServ, u, MEMO_SET_YOUR_LIMIT_FORBIDDEN); return MOD_CONT; } - limit = atoi(p1.c_str()); + limit = p1.is_number_only() ? convertTo<int32>(p1) : -1; /* The first character is a digit, but we could still go negative * from overflow... watch out! */ if (limit < 0 || (Config.MSMaxMemos > 0 && limit > Config.MSMaxMemos)) @@ -205,9 +206,9 @@ class CommandMSSet : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; + Anope::string cmd = params[0]; MemoInfo *mi = &u->Account()->memos; if (readonly) @@ -215,25 +216,25 @@ class CommandMSSet : public Command notice_lang(Config.s_MemoServ, u, MEMO_SET_DISABLED); return MOD_CONT; } - else if (cmd == "NOTIFY") + else if (cmd.equals_ci("NOTIFY")) return this->DoNotify(u, params, mi); - else if (cmd == "LIMIT") + else if (cmd.equals_ci("LIMIT")) return this->DoLimit(u, params, mi); else { notice_lang(Config.s_MemoServ, u, MEMO_SET_UNKNOWN_OPTION, cmd.c_str()); - notice_lang(Config.s_MemoServ, u, MORE_INFO, Config.s_MemoServ, "SET"); + notice_lang(Config.s_MemoServ, u, MORE_INFO, Config.s_MemoServ.c_str(), "SET"); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (subcommand.empty()) notice_help(Config.s_MemoServ, u, MEMO_HELP_SET); - else if (subcommand == "NOTIFY") + else if (subcommand.equals_ci("NOTIFY")) notice_help(Config.s_MemoServ, u, MEMO_HELP_SET_NOTIFY); - else if (subcommand == "LIMIT") + else if (subcommand.equals_ci("LIMIT")) { if (u->Account() && u->Account()->IsServicesOper()) notice_help(Config.s_MemoServ, u, MEMO_SERVADMIN_HELP_SET_LIMIT, Config.MSMaxMemos); @@ -246,7 +247,7 @@ class CommandMSSet : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_MemoServ, u, "SET", MEMO_SET_SYNTAX); } @@ -260,7 +261,7 @@ class CommandMSSet : public Command class MSSet : public Module { public: - MSSet(const std::string &modname, const std::string &creator) : Module(modname, creator) + MSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ms_staff.cpp b/modules/core/ms_staff.cpp index 481ad9db4..7f81aafe2 100644 --- a/modules/core/ms_staff.cpp +++ b/modules/core/ms_staff.cpp @@ -20,10 +20,9 @@ class CommandMSStaff : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - int z = 0; - const char *text = params[0].c_str(); + Anope::string text = params[0]; if (readonly) { @@ -36,19 +35,19 @@ class CommandMSStaff : public Command NickCore *nc = it->second; if (nc->IsServicesOper()) - memo_send(u, nc->display, text, z); + memo_send(u, nc->display, text, 0); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_MemoServ, u, MEMO_HELP_STAFF); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_MemoServ, u, "STAFF", MEMO_STAFF_SYNTAX); } @@ -62,7 +61,7 @@ class CommandMSStaff : public Command class MSStaff : public Module { public: - MSStaff(const std::string &modname, const std::string &creator) : Module(modname, creator) + MSStaff(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_access.cpp b/modules/core/ns_access.cpp index 4fc76903d..4f74d182d 100644 --- a/modules/core/ns_access.cpp +++ b/modules/core/ns_access.cpp @@ -16,28 +16,28 @@ class CommandNSAccess : public Command { private: - CommandReturn DoServAdminList(User *u, const std::vector<ci::string> ¶ms, NickCore *nc) + CommandReturn DoServAdminList(User *u, const std::vector<Anope::string> ¶ms, NickCore *nc) { - const char *mask = params.size() > 2 ? params[2].c_str() : NULL; + Anope::string mask = params.size() > 2 ? params[2] : ""; unsigned i, end; if (nc->access.empty()) { - notice_lang(Config.s_NickServ, u, NICK_ACCESS_LIST_X_EMPTY, nc->display); + notice_lang(Config.s_NickServ, u, NICK_ACCESS_LIST_X_EMPTY, nc->display.c_str()); return MOD_CONT; } if (nc->HasFlag(NI_SUSPENDED)) { - notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, nc->display); + notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, nc->display.c_str()); return MOD_CONT; } notice_lang(Config.s_NickServ, u, NICK_ACCESS_LIST_X, params[1].c_str()); for (i = 0, end = nc->access.size(); i < end; ++i) { - std::string access = nc->GetAccess(i); - if (mask && !Anope::Match(access, mask, true)) + Anope::string access = nc->GetAccess(i); + if (!mask.empty() && !Anope::Match(access, mask)) continue; u->SendMessage(Config.s_NickServ, " %s", access.c_str()); } @@ -45,9 +45,9 @@ class CommandNSAccess : public Command return MOD_CONT; } - CommandReturn DoAdd(User *u, NickCore *nc, const char *mask) + CommandReturn DoAdd(User *u, NickCore *nc, const Anope::string &mask) { - if (!mask) + if (mask.empty()) { this->OnSyntaxError(u, "ADD"); return MOD_CONT; @@ -61,19 +61,19 @@ class CommandNSAccess : public Command if (nc->FindAccess(mask)) { - notice_lang(Config.s_NickServ, u, NICK_ACCESS_ALREADY_PRESENT, *access); + notice_lang(Config.s_NickServ, u, NICK_ACCESS_ALREADY_PRESENT, mask.c_str()); return MOD_CONT; } nc->AddAccess(mask); - notice_lang(Config.s_NickServ, u, NICK_ACCESS_ADDED, mask); + notice_lang(Config.s_NickServ, u, NICK_ACCESS_ADDED, mask.c_str()); return MOD_CONT; } - CommandReturn DoDel(User *u, NickCore *nc, const char *mask) + CommandReturn DoDel(User *u, NickCore *nc, const Anope::string &mask) { - if (!mask) + if (mask.empty()) { this->OnSyntaxError(u, "DEL"); return MOD_CONT; @@ -81,17 +81,17 @@ class CommandNSAccess : public Command if (!nc->FindAccess(mask)) { - notice_lang(Config.s_NickServ, u, NICK_ACCESS_NOT_FOUND, mask); + notice_lang(Config.s_NickServ, u, NICK_ACCESS_NOT_FOUND, mask.c_str()); return MOD_CONT; } - notice_lang(Config.s_NickServ, u, NICK_ACCESS_DELETED, mask); + notice_lang(Config.s_NickServ, u, NICK_ACCESS_DELETED, mask.c_str()); nc->EraseAccess(mask); return MOD_CONT; } - CommandReturn DoList(User *u, NickCore *nc, const char *mask) + CommandReturn DoList(User *u, NickCore *nc, const Anope::string &mask) { unsigned i, end; @@ -104,8 +104,8 @@ class CommandNSAccess : public Command notice_lang(Config.s_NickServ, u, NICK_ACCESS_LIST); for (i = 0, end = nc->access.size(); i < end; ++i) { - std::string access = nc->GetAccess(i); - if (mask && !Anope::Match(access, mask, true)) + Anope::string access = nc->GetAccess(i); + if (!mask.empty() && !Anope::Match(access, mask)) continue; u->SendMessage(Config.s_NickServ, " %s", access.c_str()); } @@ -117,45 +117,44 @@ class CommandNSAccess : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; - const char *mask = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string cmd = params[0]; + Anope::string mask = params.size() > 1 ? params[1] : ""; NickAlias *na; - if (cmd == "LIST" && u->Account()->IsServicesOper() && mask && (na = findnick(params[1]))) + if (cmd.equals_ci("LIST") && u->Account()->IsServicesOper() && !mask.empty() && (na = findnick(params[1]))) return this->DoServAdminList(u, params, na->nc); - if (mask && !strchr(mask, '@')) + if (!mask.empty() && mask.find('@') == Anope::string::npos) { notice_lang(Config.s_NickServ, u, BAD_USERHOST_MASK); - notice_lang(Config.s_NickServ, u, MORE_INFO, Config.s_NickServ, "ACCESS"); - + notice_lang(Config.s_NickServ, u, MORE_INFO, Config.s_NickServ.c_str(), "ACCESS"); } /* else if (na->HasFlag(NS_FORBIDDEN)) notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick); */ else if (u->Account()->HasFlag(NI_SUSPENDED)) - notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, u->Account()->display); - else if (cmd == "ADD") + notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, u->Account()->display.c_str()); + else if (cmd.equals_ci("ADD")) return this->DoAdd(u, u->Account(), mask); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) return this->DoDel(u, u->Account(), mask); - else if (cmd == "LIST") + else if (cmd.equals_ci("LIST")) return this->DoList(u, u->Account(), mask); else this->OnSyntaxError(u, ""); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP_ACCESS); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "ACCESS", NICK_ACCESS_SYNTAX); } @@ -169,7 +168,7 @@ class CommandNSAccess : public Command class NSAccess : public Module { public: - NSAccess(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_alist.cpp b/modules/core/ns_alist.cpp index ebff3f0c8..a7d4d7e4a 100644 --- a/modules/core/ns_alist.cpp +++ b/modules/core/ns_alist.cpp @@ -20,7 +20,7 @@ class CommandNSAList : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { /* * List the channels that the given nickname has access on @@ -31,7 +31,7 @@ class CommandNSAList : public Command * -jester */ - const char *nick = NULL; + Anope::string nick; NickAlias *na; @@ -48,41 +48,38 @@ class CommandNSAList : public Command * The first argument for service admins must * always be a nickname. */ - nick = params.size() ? params[0].c_str() : NULL; + nick = !params.empty() ? params[0] : ""; lev_param = 1; /* If an argument was passed, use it as the nick to see levels * for, else check levels for the user calling the command */ - if (nick) - na = findnick(nick); - else - na = findnick(u->nick); + na = findnick(!nick.empty() ? nick : u->nick); } /* If available, get level from arguments */ - ci::string lev = params.size() > lev_param ? params[lev_param] : ""; + Anope::string lev = params.size() > lev_param ? params[lev_param] : ""; /* if a level was given, make sure it's an int for later */ if (!lev.empty()) { - if (lev == "FOUNDER") + if (lev.equals_ci("FOUNDER")) min_level = ACCESS_FOUNDER; - else if (lev == "SOP") + else if (lev.equals_ci("SOP")) min_level = ACCESS_SOP; - else if (lev == "AOP") + else if (lev.equals_ci("AOP")) min_level = ACCESS_AOP; - else if (lev == "HOP") + else if (lev.equals_ci("HOP")) min_level = ACCESS_HOP; - else if (lev == "VOP") + else if (lev.equals_ci("VOP")) min_level = ACCESS_VOP; else - min_level = atoi(lev.c_str()); + min_level = lev.is_number_only() ? convertTo<int>(lev) : ACCESS_INVALID; } if (!na) - notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); else if (min_level <= ACCESS_INVALID || min_level > ACCESS_FOUNDER) notice_lang(Config.s_NickServ, u, CHAN_ACCESS_LEVEL_RANGE, ACCESS_INVALID + 1, ACCESS_FOUNDER - 1); else @@ -91,7 +88,7 @@ class CommandNSAList : public Command int chan_count = 0; int match_count = 0; - notice_lang(Config.s_NickServ, u, is_servadmin ? NICK_ALIST_HEADER_X : NICK_ALIST_HEADER, na->nick); + notice_lang(Config.s_NickServ, u, is_servadmin ? NICK_ALIST_HEADER_X : NICK_ALIST_HEADER, na->nick.c_str()); for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) { @@ -108,14 +105,12 @@ class CommandNSAList : public Command if (ci->HasFlag(CI_XOP) || level == ACCESS_FOUNDER) { - const char *xop; - - xop = get_xop_level(level); + Anope::string xop = get_xop_level(level); - notice_lang(Config.s_NickServ, u, NICK_ALIST_XOP_FORMAT, match_count, ci->HasFlag(CI_NO_EXPIRE) ? '!' : ' ', ci->name.c_str(), xop, ci->desc ? ci->desc : ""); + notice_lang(Config.s_NickServ, u, NICK_ALIST_XOP_FORMAT, match_count, ci->HasFlag(CI_NO_EXPIRE) ? '!' : ' ', ci->name.c_str(), xop.c_str(), !ci->desc.empty() ? ci->desc.c_str() : ""); } else - notice_lang(Config.s_NickServ, u, NICK_ALIST_ACCESS_FORMAT, match_count, ci->HasFlag(CI_NO_EXPIRE) ? '!' : ' ', ci->name.c_str(), level, ci->desc ? ci->desc : ""); + notice_lang(Config.s_NickServ, u, NICK_ALIST_ACCESS_FORMAT, match_count, ci->HasFlag(CI_NO_EXPIRE) ? '!' : ' ', ci->name.c_str(), level, !ci->desc.empty() ? ci->desc.c_str() : ""); } } @@ -124,7 +119,7 @@ class CommandNSAList : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (u->Account() && u->Account()->IsServicesOper()) notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_ALIST); @@ -143,7 +138,7 @@ class CommandNSAList : public Command class NSAList : public Module { public: - NSAList(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSAList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_drop.cpp b/modules/core/ns_drop.cpp index e18492bfd..e85b2cebb 100644 --- a/modules/core/ns_drop.cpp +++ b/modules/core/ns_drop.cpp @@ -20,13 +20,13 @@ class CommandNSDrop : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params.size() ? params[0].c_str() : NULL; + Anope::string nick = !params.empty() ? params[0] : ""; NickAlias *na; NickRequest *nr = NULL; int is_mine; /* Does the nick being dropped belong to the user that is dropping? */ - char *my_nick = NULL; + Anope::string my_nick; if (readonly) { @@ -34,20 +34,20 @@ class CommandNSDrop : public Command return MOD_CONT; } - if (!(na = (nick ? findnick(nick) : findnick(u->nick)))) + if (!(na = findnick(!nick.empty() ? nick : u->nick))) { - if (nick) + if (!nick.empty()) { if ((nr = findrequestnick(nick)) && u->Account()->IsServicesOper()) { if (Config.WallDrop) - ircdproto->SendGlobops(NickServ, "\2%s\2 used DROP on \2%s\2", u->nick.c_str(), nick); + ircdproto->SendGlobops(NickServ, "\2%s\2 used DROP on \2%s\2", u->nick.c_str(), nick.c_str()); Alog() << Config.s_NickServ << ": " << u->GetMask() << " dropped nickname " << nr->nick << " (e-mail: " << nr->email << ")"; delete nr; - notice_lang(Config.s_NickServ, u, NICK_X_DROPPED, nick); + notice_lang(Config.s_NickServ, u, NICK_X_DROPPED, nick.c_str()); } else - notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); } else notice_lang(Config.s_NickServ, u, NICK_NOT_REGISTERED); @@ -55,8 +55,8 @@ class CommandNSDrop : public Command } is_mine = u->Account() && u->Account() == na->nc; - if (is_mine && !nick) - my_nick = sstrdup(na->nick); + if (is_mine && nick.empty()) + my_nick = na->nick; if (!is_mine && !u->Account()->HasPriv("nickserv/drop")) notice_lang(Config.s_NickServ, u, ACCESS_DENIED); @@ -67,39 +67,36 @@ class CommandNSDrop : public Command if (readonly) notice_lang(Config.s_NickServ, u, READ_ONLY_MODE); - if (ircd->sqline && (na->HasFlag(NS_FORBIDDEN))) + if (ircd->sqline && na->HasFlag(NS_FORBIDDEN)) { XLine x(na->nick); ircdproto->SendSQLineDel(&x); } - Alog() << Config.s_NickServ << ": " << u->GetMask() << " dropped nickname " << na->nick << " (group " << na->nc->display << ") (e-mail: " << (na->nc->email ? na->nc->email : "none") << ")"; + Alog() << Config.s_NickServ << ": " << u->GetMask() << " dropped nickname " << na->nick << " (group " << na->nc->display << ") (e-mail: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")"; delete na; - FOREACH_MOD(I_OnNickDrop, OnNickDrop(my_nick ? my_nick : nick)); + FOREACH_MOD(I_OnNickDrop, OnNickDrop(!my_nick.empty() ? my_nick : nick)); if (!is_mine) { if (Config.WallDrop) - ircdproto->SendGlobops(NickServ, "\2%s\2 used DROP on \2%s\2", u->nick.c_str(), nick); - notice_lang(Config.s_NickServ, u, NICK_X_DROPPED, nick); + ircdproto->SendGlobops(NickServ, "\2%s\2 used DROP on \2%s\2", u->nick.c_str(), nick.c_str()); + notice_lang(Config.s_NickServ, u, NICK_X_DROPPED, nick.c_str()); } else { - if (nick) - notice_lang(Config.s_NickServ, u, NICK_X_DROPPED, nick); + if (!nick.empty()) + notice_lang(Config.s_NickServ, u, NICK_X_DROPPED, nick.c_str()); else notice_lang(Config.s_NickServ, u, NICK_DROPPED); } } - if (my_nick) - delete [] my_nick; - return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (u->Account() && u->Account()->HasPriv("nickserv/drop")) notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_DROP); @@ -118,7 +115,7 @@ class CommandNSDrop : public Command class NSDrop : public Module { public: - NSDrop(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_forbid.cpp b/modules/core/ns_forbid.cpp index 6f05dcdfd..ad313d62b 100644 --- a/modules/core/ns_forbid.cpp +++ b/modules/core/ns_forbid.cpp @@ -20,14 +20,14 @@ class CommandNSForbid : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na; - const char *nick = params[0].c_str(); - const char *reason = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string nick = params[0]; + Anope::string reason = params.size() > 1 ? params[1] : ""; /* Assumes that permission checking has already been done. */ - if (Config.ForceForbidReason && !reason) + if (Config.ForceForbidReason && reason.empty()) { this->OnSyntaxError(u, ""); return MOD_CONT; @@ -37,7 +37,7 @@ class CommandNSForbid : public Command notice_lang(Config.s_NickServ, u, READ_ONLY_MODE); if (!ircdproto->IsNickValid(nick)) { - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, nick.c_str()); return MOD_CONT; } if ((na = findnick(nick))) @@ -55,9 +55,9 @@ class CommandNSForbid : public Command if (na) { na->SetFlag(NS_FORBIDDEN); - na->last_usermask = sstrdup(u->nick.c_str()); - if (reason) - na->last_realname = sstrdup(reason); + na->last_usermask = u->nick; + if (!reason.empty()) + na->last_realname = reason; User *curr = finduser(na->nick); @@ -67,36 +67,35 @@ class CommandNSForbid : public Command curr->Collide(na); } - if (ircd->sqline) { - XLine x(na->nick, reason ? reason : "Forbidden"); + XLine x(na->nick, !reason.empty() ? reason : "Forbidden"); ircdproto->SendSQLine(&x); } if (Config.WallForbid) - ircdproto->SendGlobops(NickServ, "\2%s\2 used FORBID on \2%s\2", u->nick.c_str(), nick); + ircdproto->SendGlobops(NickServ, "\2%s\2 used FORBID on \2%s\2", u->nick.c_str(), nick.c_str()); Alog() << Config.s_NickServ << ": " << u->nick << " set FORBID for nick " << nick; - notice_lang(Config.s_NickServ, u, NICK_FORBID_SUCCEEDED, nick); + notice_lang(Config.s_NickServ, u, NICK_FORBID_SUCCEEDED, nick.c_str()); FOREACH_MOD(I_OnNickForbidden, OnNickForbidden(na)); } else { Alog() << Config.s_NickServ << ": Valid FORBID for " << nick << " by " << u->nick << " failed"; - notice_lang(Config.s_NickServ, u, NICK_FORBID_FAILED, nick); + notice_lang(Config.s_NickServ, u, NICK_FORBID_FAILED, nick.c_str()); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_FORBID); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "FORBID", Config.ForceForbidReason ? NICK_FORBID_SYNTAX_REASON : NICK_FORBID_SYNTAX); } @@ -110,7 +109,7 @@ class CommandNSForbid : public Command class NSForbid : public Module { public: - NSForbid(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSForbid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_getemail.cpp b/modules/core/ns_getemail.cpp index 94653b856..eeb3c705d 100644 --- a/modules/core/ns_getemail.cpp +++ b/modules/core/ns_getemail.cpp @@ -24,9 +24,9 @@ class CommandNSGetEMail : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string email = params[0]; + Anope::string email = params[0]; int j = 0; Alog() << Config.s_NickServ << ": " << u->GetMask() << " used GETEMAIL on " << email; @@ -35,10 +35,10 @@ class CommandNSGetEMail : public Command { NickCore *nc = it->second; - if (nc->email && nc->email == email) + if (!nc->email.empty() && nc->email.equals_ci(email)) { ++j; - notice_lang(Config.s_NickServ, u, NICK_GETEMAIL_EMAILS_ARE, nc->display, email.c_str()); + notice_lang(Config.s_NickServ, u, NICK_GETEMAIL_EMAILS_ARE, nc->display.c_str(), email.c_str()); } } @@ -51,13 +51,13 @@ class CommandNSGetEMail : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_GETEMAIL); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "GETMAIL", NICK_GETEMAIL_SYNTAX); } @@ -71,7 +71,7 @@ class CommandNSGetEMail : public Command class NSGetEMail : public Module { public: - NSGetEMail(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSGetEMail(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_getpass.cpp b/modules/core/ns_getpass.cpp index e6f6533a3..97654d2d5 100644 --- a/modules/core/ns_getpass.cpp +++ b/modules/core/ns_getpass.cpp @@ -20,10 +20,10 @@ class CommandNSGetPass : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - std::string tmp_pass; + Anope::string nick = params[0]; + Anope::string tmp_pass; NickAlias *na; NickRequest *nr = NULL; @@ -33,14 +33,14 @@ class CommandNSGetPass : public Command { Alog() << Config.s_NickServ << ": " << u->GetMask() << " used GETPASS on " << nick; if (Config.WallGetpass) - ircdproto->SendGlobops(NickServ, "\2%s\2 used GETPASS on \2%s\2", u->nick.c_str(), nick); - notice_lang(Config.s_NickServ, u, NICK_GETPASS_PASSCODE_IS, nick, nr->passcode.c_str()); + ircdproto->SendGlobops(NickServ, "\2%s\2 used GETPASS on \2%s\2", u->nick.c_str(), nick.c_str()); + notice_lang(Config.s_NickServ, u, NICK_GETPASS_PASSCODE_IS, nick.c_str(), nr->passcode.c_str()); } else - notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); } else if (na->HasFlag(NS_FORBIDDEN)) - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); else if (Config.NSSecureAdmins && na->nc->IsServicesOper()) notice_lang(Config.s_NickServ, u, ACCESS_DENIED); else @@ -49,8 +49,8 @@ class CommandNSGetPass : public Command { Alog() << Config.s_NickServ << ": " << u->GetMask() << " used GETPASS on " << nick; if (Config.WallGetpass) - ircdproto->SendGlobops(NickServ, "\2%s\2 used GETPASS on \2%s\2", u->nick.c_str(), nick); - notice_lang(Config.s_NickServ, u, NICK_GETPASS_PASSWORD_IS, nick, tmp_pass.c_str()); + ircdproto->SendGlobops(NickServ, "\2%s\2 used GETPASS on \2%s\2", u->nick.c_str(), nick.c_str()); + notice_lang(Config.s_NickServ, u, NICK_GETPASS_PASSWORD_IS, nick.c_str(), tmp_pass.c_str()); } else notice_lang(Config.s_NickServ, u, NICK_GETPASS_UNAVAILABLE); @@ -58,13 +58,13 @@ class CommandNSGetPass : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_GETPASS); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "GETPASS", NICK_GETPASS_SYNTAX); } @@ -78,9 +78,9 @@ class CommandNSGetPass : public Command class NSGetPass : public Module { public: - NSGetPass(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSGetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { - std::string tmp_pass = "plain:tmp"; + Anope::string tmp_pass = "plain:tmp"; if (enc_decrypt(tmp_pass, tmp_pass) == -1) throw ModuleException("Incompatible with the encryption module being used"); diff --git a/modules/core/ns_ghost.cpp b/modules/core/ns_ghost.cpp index 44e71c0c1..ac1e0787f 100644 --- a/modules/core/ns_ghost.cpp +++ b/modules/core/ns_ghost.cpp @@ -21,30 +21,30 @@ class CommandNSGhost : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - std::string pass = params.size() > 1 ? params[1].c_str() : ""; + Anope::string nick = params[0]; + Anope::string pass = params.size() > 1 ? params[1] : ""; NickAlias *na = findnick(nick); if (!finduser(nick)) - notice_lang(Config.s_NickServ, u, NICK_X_NOT_IN_USE, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_IN_USE, nick.c_str()); else if (!na) - notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); else if (na->nc->HasFlag(NI_SUSPENDED)) - notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, na->nick); - else if (!stricmp(nick, u->nick.c_str())) + notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, na->nick.c_str()); + else if (nick.equals_ci(u->nick)) notice_lang(Config.s_NickServ, u, NICK_NO_GHOST_SELF); else if (!pass.empty()) { int res = enc_check_password(pass, na->nc->pass); if (res == 1) { - std::string buf = "GHOST command used by " + u->nick; - kill_user(Config.s_NickServ, nick, buf.c_str()); - notice_lang(Config.s_NickServ, u, NICK_GHOST_KILLED, nick); + Anope::string buf = "GHOST command used by " + u->nick; + kill_user(Config.s_NickServ, nick, buf); + notice_lang(Config.s_NickServ, u, NICK_GHOST_KILLED, nick.c_str()); } else { @@ -59,11 +59,11 @@ class CommandNSGhost : public Command } else { - if (u->Account() == na->nc || (!(na->nc->HasFlag(NI_SECURE)) && is_on_access(u, na->nc))) + if (u->Account() == na->nc || (!na->nc->HasFlag(NI_SECURE) && is_on_access(u, na->nc))) { - std::string buf = "GHOST command used by " + u->nick; - kill_user(Config.s_NickServ, nick, buf.c_str()); - notice_lang(Config.s_NickServ, u, NICK_GHOST_KILLED, nick); + Anope::string buf = "GHOST command used by " + u->nick; + kill_user(Config.s_NickServ, nick, buf); + notice_lang(Config.s_NickServ, u, NICK_GHOST_KILLED, nick.c_str()); } else notice_lang(Config.s_NickServ, u, ACCESS_DENIED); @@ -71,13 +71,13 @@ class CommandNSGhost : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP_GHOST); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "GHOST", NICK_GHOST_SYNTAX); } @@ -91,7 +91,7 @@ class CommandNSGhost : public Command class NSGhost : public Module { public: - NSGhost(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSGhost(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_group.cpp b/modules/core/ns_group.cpp index 6b3e56718..7cdac0a4f 100644 --- a/modules/core/ns_group.cpp +++ b/modules/core/ns_group.cpp @@ -21,12 +21,12 @@ class CommandNSGroup : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na, *target; - const char *nick = params[0].c_str(); - std::string pass = params[1].c_str(); - std::list<std::pair<ci::string, ci::string> >::iterator it, it_end; + Anope::string nick = params[0]; + Anope::string pass = params[1]; + std::list<std::pair<Anope::string, Anope::string> >::iterator it, it_end; if (Config.NSEmailReg && findrequestnick(u->nick)) { @@ -40,7 +40,7 @@ class CommandNSGroup : public Command return MOD_CONT; } - if (!ircdproto->IsNickValid(u->nick.c_str())) + if (!ircdproto->IsNickValid(u->nick)) { notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, u->nick.c_str()); return MOD_CONT; @@ -48,7 +48,7 @@ class CommandNSGroup : public Command if (Config.RestrictOperNicks) for (it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) - if (!is_oper(u) && u->nick.find(it->first.c_str()) != std::string::npos) + if (!is_oper(u) && u->nick.find_ci(it->first) != Anope::string::npos) { notice_lang(Config.s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); return MOD_CONT; @@ -56,7 +56,7 @@ class CommandNSGroup : public Command na = findnick(u->nick); if (!(target = findnick(nick))) - notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); else if (time(NULL) < u->lastnickreg + Config.NSRegDelay) notice_lang(Config.s_NickServ, u, NICK_GROUP_PLEASE_WAIT, (Config.NSRegDelay + u->lastnickreg) - time(NULL)); else if (u->Account() && u->Account()->HasFlag(NI_SUSPENDED)) @@ -67,78 +67,83 @@ class CommandNSGroup : public Command else if (target && target->nc->HasFlag(NI_SUSPENDED)) { Alog() << Config.s_NickServ << ": " << u->GetMask() << " tried to use GROUP for SUSPENDED nick " << target->nick; - notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, target->nick); + notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, target->nick.c_str()); } else if (target->HasFlag(NS_FORBIDDEN)) - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, nick.c_str()); else if (na && target->nc == na->nc) - notice_lang(Config.s_NickServ, u, NICK_GROUP_SAME, target->nick); + notice_lang(Config.s_NickServ, u, NICK_GROUP_SAME, target->nick.c_str()); else if (na && na->nc != u->Account()) - notice_lang(Config.s_NickServ, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ.c_str()); else if (Config.NSMaxAliases && (target->nc->aliases.size() >= Config.NSMaxAliases) && !target->nc->IsServicesOper()) - notice_lang(Config.s_NickServ, u, NICK_GROUP_TOO_MANY, target->nick, Config.s_NickServ, Config.s_NickServ); - else if (enc_check_password(pass, target->nc->pass) != 1) - { - Alog() << Config.s_NickServ << ": Failed GROUP for " << u->GetMask() << " (invalid password)"; - notice_lang(Config.s_NickServ, u, PASSWORD_INCORRECT); - if (bad_password(u)) - return MOD_STOP; - } + notice_lang(Config.s_NickServ, u, NICK_GROUP_TOO_MANY, target->nick.c_str(), Config.s_NickServ.c_str(), Config.s_NickServ.c_str()); else { - /* If the nick is already registered, drop it. - * If not, check that it is valid. - */ - if (na) - delete na; + int res = enc_check_password(pass, target->nc->pass); + if (res == -1) + { + Alog() << Config.s_NickServ << ": Failed GROUP for " << u->GetMask() << " (invalid password)"; + notice_lang(Config.s_NickServ, u, PASSWORD_INCORRECT); + if (bad_password(u)) + return MOD_STOP; + } else { - int prefixlen = strlen(Config.NSGuestNickPrefix); - int nicklen = u->nick.length(); - - if (nicklen <= prefixlen + 7 && nicklen >= prefixlen + 1 && stristr(u->nick.c_str(), Config.NSGuestNickPrefix) == u->nick.c_str() && strspn(u->nick.c_str() + prefixlen, "1234567890") == nicklen - prefixlen) + /* If the nick is already registered, drop it. + * If not, check that it is valid. + */ + if (na) + delete na; + else { - notice_lang(Config.s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); - return MOD_CONT; + size_t prefixlen = Config.NSGuestNickPrefix.length(); + size_t nicklen = u->nick.length(); + + if (nicklen <= prefixlen + 7 && nicklen >= prefixlen + 1 && !u->nick.find_ci(Config.NSGuestNickPrefix) && !u->nick.substr(prefixlen).find_first_not_of("1234567890")) + { + notice_lang(Config.s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); + return MOD_CONT; + } } - } - na = new NickAlias(u->nick, target->nc); + na = new NickAlias(u->nick, target->nc); - if (na) - { - std::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost(); - na->last_usermask = sstrdup(last_usermask.c_str()); - na->last_realname = sstrdup(u->realname); - na->time_registered = na->last_seen = time(NULL); + if (na) + { + Anope::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost(); + na->last_usermask = last_usermask; + na->last_realname = u->realname; + na->time_registered = na->last_seen = time(NULL); - u->Login(na->nc); - FOREACH_MOD(I_OnNickGroup, OnNickGroup(u, target)); - ircdproto->SetAutoIdentificationToken(u); + u->Login(na->nc); + FOREACH_MOD(I_OnNickGroup, OnNickGroup(u, target)); + ircdproto->SetAutoIdentificationToken(u); - Alog() << Config.s_NickServ << ": " << u->GetMask() << " makes " << u->nick << " join group of " << target->nick << " (" << target->nc->display << ") (e-mail: " << (target->nc->email ? target->nc->email : "none") << ")"; - notice_lang(Config.s_NickServ, u, NICK_GROUP_JOINED, target->nick); + Alog() << Config.s_NickServ << ": " << u->GetMask() << " makes " << u->nick << " join group of " << target->nick << " (" << target->nc->display << ") (e-mail: " << + (!target->nc->email.empty() ? target->nc->email : "none") << ")"; + notice_lang(Config.s_NickServ, u, NICK_GROUP_JOINED, target->nick.c_str()); - u->lastnickreg = time(NULL); + u->lastnickreg = time(NULL); - check_memos(u); - } - else - { - Alog() << Config.s_NickServ << ": makealias(" << u->nick << ") failed"; - notice_lang(Config.s_NickServ, u, NICK_GROUP_FAILED); + check_memos(u); + } + else + { + Alog() << Config.s_NickServ << ": makealias(" << u->nick << ") failed"; + notice_lang(Config.s_NickServ, u, NICK_GROUP_FAILED); + } } } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP_GROUP); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "GROUP", NICK_GROUP_SYNTAX); } @@ -156,17 +161,17 @@ class CommandNSUngroup : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params.size() ? params[0].c_str() : NULL; - NickAlias *na = nick ? findnick(nick) : findnick(u->nick); + Anope::string nick = !params.empty() ? params[0] : ""; + NickAlias *na = findnick(!nick.empty() ? nick : u->nick); if (u->Account()->aliases.size() == 1) notice_lang(Config.s_NickServ, u, NICK_UNGROUP_ONE_NICK); else if (!na) - notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick ? nick : u->nick.c_str()); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, !nick.empty() ? nick.c_str() : u->nick.c_str()); else if (na->nc != u->Account()) - notice_lang(Config.s_NickServ, u, NICK_UNGROUP_NOT_IN_GROUP, na->nick); + notice_lang(Config.s_NickServ, u, NICK_UNGROUP_NOT_IN_GROUP, na->nick.c_str()); else { NickCore *oldcore = na->nc; @@ -175,20 +180,20 @@ class CommandNSUngroup : public Command if (it != oldcore->aliases.end()) oldcore->aliases.erase(it); - if (!stricmp(oldcore->display, na->nick)) + if (na->nick.equals_ci(oldcore->display)) change_core_display(oldcore); na->nc = new NickCore(na->nick); na->nc->aliases.push_back(na); na->nc->pass = oldcore->pass; - if (oldcore->email) - na->nc->email = sstrdup(oldcore->email); - if (oldcore->greet) - na->nc->greet = sstrdup(oldcore->greet); + if (!oldcore->email.empty()) + na->nc->email = oldcore->email; + if (!oldcore->greet.empty()) + na->nc->greet = oldcore->greet; na->nc->language = oldcore->language; - notice_lang(Config.s_NickServ, u, NICK_UNGROUP_SUCCESSFUL, na->nick, oldcore->display); + notice_lang(Config.s_NickServ, u, NICK_UNGROUP_SUCCESSFUL, na->nick.c_str(), oldcore->display.c_str()); User *user = finduser(na->nick); if (user) @@ -199,7 +204,7 @@ class CommandNSUngroup : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP_UNGROUP); return true; @@ -218,16 +223,16 @@ class CommandNSGList : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params.size() ? params[0].c_str() : NULL; + Anope::string nick = !params.empty() ? params[0] : ""; - NickCore *nc = u->Account(); + const NickCore *nc = u->Account(); - if (nick && (stricmp(nick, u->nick.c_str()) && !u->Account()->IsServicesOper())) - notice_lang(Config.s_NickServ, u, ACCESS_DENIED, Config.s_NickServ); - else if (nick && (!findnick(nick) || !(nc = findnick(nick)->nc))) - notice_lang(Config.s_NickServ, u, !nick ? NICK_NOT_REGISTERED : NICK_X_NOT_REGISTERED, nick); + if (!nick.empty() && (!nick.equals_ci(u->nick) && !u->Account()->IsServicesOper())) + notice_lang(Config.s_NickServ, u, ACCESS_DENIED, Config.s_NickServ.c_str()); + else if (!nick.empty() && (!findnick(nick) || !(nc = findnick(nick)->nc))) + notice_lang(Config.s_NickServ, u, nick.empty() ? NICK_NOT_REGISTERED : NICK_X_NOT_REGISTERED, nick.c_str()); else { time_t expt; @@ -235,8 +240,8 @@ class CommandNSGList : public Command char buf[BUFSIZE]; int wont_expire; - notice_lang(Config.s_NickServ, u, nick ? NICK_GLIST_HEADER_X : NICK_GLIST_HEADER, nc->display); - for (std::list<NickAlias *>::iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it) + notice_lang(Config.s_NickServ, u, !nick.empty() ? NICK_GLIST_HEADER_X : NICK_GLIST_HEADER, nc->display.c_str()); + for (std::list<NickAlias *>::const_iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it) { NickAlias *na2 = *it; @@ -246,15 +251,14 @@ class CommandNSGList : public Command tm = localtime(&expt); strftime_lang(buf, sizeof(buf), finduser(na2->nick), STRFTIME_DATE_TIME_FORMAT, tm); } - notice_lang(Config.s_NickServ, u, wont_expire ? NICK_GLIST_REPLY_NOEXPIRE : NICK_GLIST_REPLY, na2->nick, buf); + notice_lang(Config.s_NickServ, u, wont_expire ? NICK_GLIST_REPLY_NOEXPIRE : NICK_GLIST_REPLY, na2->nick.c_str(), buf); } notice_lang(Config.s_NickServ, u, NICK_GLIST_FOOTER, nc->aliases.size()); } return MOD_CONT; } - - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (u->Account() && u->Account()->IsServicesOper()) notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_GLIST); @@ -273,7 +277,7 @@ class CommandNSGList : public Command class NSGroup : public Module { public: - NSGroup(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_help.cpp b/modules/core/ns_help.cpp index d23cbd208..ba4ad8a4c 100644 --- a/modules/core/ns_help.cpp +++ b/modules/core/ns_help.cpp @@ -21,11 +21,11 @@ class CommandNSHelp : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; + Anope::string cmd = params[0]; - if (cmd == "SET LANGUAGE") + if (cmd.equals_ci("SET LANGUAGE")) { int i; notice_help(Config.s_NickServ, u, NICK_HELP_SET_LANGUAGE); @@ -33,12 +33,12 @@ class CommandNSHelp : public Command u->SendMessage(Config.s_NickServ, " %2d) %s", i + 1, langnames[langlist[i]]); } else - mod_help_cmd(NickServ, u, cmd.c_str()); + mod_help_cmd(NickServ, u, cmd); return MOD_CONT; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP); for (CommandMap::const_iterator it = NickServ->Commands.begin(), it_end = NickServ->Commands.end(); it != it_end; ++it) @@ -55,7 +55,7 @@ class CommandNSHelp : public Command class NSHelp : public Module { public: - NSHelp(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSHelp(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_identify.cpp b/modules/core/ns_identify.cpp index 51a0716a4..bdf6beffa 100644 --- a/modules/core/ns_identify.cpp +++ b/modules/core/ns_identify.cpp @@ -16,14 +16,14 @@ class CommandNSIdentify : public Command { public: - CommandNSIdentify(const ci::string &cname) : Command(cname, 1, 1) + CommandNSIdentify(const Anope::string &cname) : Command(cname, 1, 1) { this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - std::string pass = params[0].c_str(); + Anope::string pass = params[0]; NickAlias *na; NickRequest *nr; int res; @@ -36,75 +36,77 @@ class CommandNSIdentify : public Command notice_lang(Config.s_NickServ, u, NICK_NOT_REGISTERED); } else if (na->HasFlag(NS_FORBIDDEN)) - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); else if (na->nc->HasFlag(NI_SUSPENDED)) - notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, na->nick.c_str()); /* You can now identify for other nicks without logging out first, * however you can not identify again for the group you're already * identified as */ else if (u->Account() && u->Account() == na->nc) notice_lang(Config.s_NickServ, u, NICK_ALREADY_IDENTIFIED); - else if (!(res = enc_check_password(pass, na->nc->pass))) - { - Alog() << Config.s_NickServ << ": Failed IDENTIFY for " << u->nick << "!" << u->GetIdent() << "@" << u->host; - notice_lang(Config.s_NickServ, u, PASSWORD_INCORRECT); - if (bad_password(u)) - return MOD_STOP; - } - else if (res == -1) - notice_lang(Config.s_NickServ, u, NICK_IDENTIFY_FAILED); else { - if (u->IsIdentified()) - Alog() << Config.s_NickServ << ": " << u->GetMask() << " logged out of account " << u->Account()->display; + res = enc_check_password(pass, na->nc->pass); + if (!res) + { + Alog() << Config.s_NickServ << ": Failed IDENTIFY for " << u->nick << "!" << u->GetIdent() << "@" << u->host; + notice_lang(Config.s_NickServ, u, PASSWORD_INCORRECT); + if (bad_password(u)) + return MOD_STOP; + } + else if (res == -1) + notice_lang(Config.s_NickServ, u, NICK_IDENTIFY_FAILED); + else + { + if (u->IsIdentified()) + Alog() << Config.s_NickServ << ": " << u->GetMask() << " logged out of account " << u->Account()->display; - if (na->last_realname) - delete [] na->last_realname; - na->last_realname = sstrdup(u->realname); - na->last_seen = time(NULL); + na->last_realname = u->realname; + na->last_seen = time(NULL); - u->Login(na->nc); - ircdproto->SendAccountLogin(u, u->Account()); - ircdproto->SetAutoIdentificationToken(u); + u->Login(na->nc); + ircdproto->SendAccountLogin(u, u->Account()); + ircdproto->SetAutoIdentificationToken(u); - u->UpdateHost(); + u->UpdateHost(); - FOREACH_MOD(I_OnNickIdentify, OnNickIdentify(u)); + FOREACH_MOD(I_OnNickIdentify, OnNickIdentify(u)); - Alog() << Config.s_NickServ << ": " << u->GetMask() << " identified for account " << u->Account()->display; - notice_lang(Config.s_NickServ, u, NICK_IDENTIFY_SUCCEEDED); - if (ircd->vhost) - do_on_id(u); - if (Config.NSModeOnID) - do_setmodes(u); + Alog() << Config.s_NickServ << ": " << u->GetMask() << " identified for account " << u->Account()->display; + notice_lang(Config.s_NickServ, u, NICK_IDENTIFY_SUCCEEDED); + if (ircd->vhost) + do_on_id(u); + if (Config.NSModeOnID) + do_setmodes(u); - if (Config.NSForceEmail && u->Account() && !u->Account()->email) - { - notice_lang(Config.s_NickServ, u, NICK_IDENTIFY_EMAIL_REQUIRED); - notice_help(Config.s_NickServ, u, NICK_IDENTIFY_EMAIL_HOWTO); - } + if (Config.NSForceEmail && u->Account() && u->Account()->email.empty()) + { + notice_lang(Config.s_NickServ, u, NICK_IDENTIFY_EMAIL_REQUIRED); + notice_help(Config.s_NickServ, u, NICK_IDENTIFY_EMAIL_HOWTO); + } - if (u->IsIdentified()) - check_memos(u); + if (u->IsIdentified()) + check_memos(u); + } } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP_IDENTIFY); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "IDENTIFY", NICK_IDENTIFY_SYNTAX); } void OnServHelp(User *u) { - if (this->name == "IDENTIFY") + if (this->name.equals_ci("IDENTIFY")) notice_lang(Config.s_NickServ, u, NICK_HELP_CMD_IDENTIFY); } }; @@ -112,7 +114,7 @@ class CommandNSIdentify : public Command class NSIdentify : public Module { public: - NSIdentify(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSIdentify(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_info.cpp b/modules/core/ns_info.cpp index 3109ad4ba..ce7f844b1 100644 --- a/modules/core/ns_info.cpp +++ b/modules/core/ns_info.cpp @@ -17,7 +17,7 @@ class CommandNSInfo : public Command { private: // cannot be const, as it is modified - void CheckOptStr(std::string &buf, NickCoreFlag opt, const std::string &str, NickCore *nc, bool reverse_logic = false) + void CheckOptStr(Anope::string &buf, NickCoreFlag opt, const Anope::string &str, NickCore *nc, bool reverse_logic = false) { if (reverse_logic ? !nc->HasFlag(opt) : nc->HasFlag(opt)) { @@ -34,9 +34,9 @@ class CommandNSInfo : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); + Anope::string nick = params[0]; NickAlias *na = findnick(nick); bool has_auspex = u->IsIdentified() && u->Account()->HasPriv("nickserv/auspex"); @@ -48,19 +48,19 @@ class CommandNSInfo : public Command { notice_lang(Config.s_NickServ, u, NICK_IS_PREREG); if (has_auspex) - notice_lang(Config.s_NickServ, u, NICK_INFO_EMAIL, nr->email); + notice_lang(Config.s_NickServ, u, NICK_INFO_EMAIL, nr->email.c_str()); } else if (nickIsServices(nick, 1)) - notice_lang(Config.s_NickServ, u, NICK_X_IS_SERVICES, nick); + notice_lang(Config.s_NickServ, u, NICK_X_IS_SERVICES, nick.c_str()); else - notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); } else if (na->HasFlag(NS_FORBIDDEN)) { - if (is_oper(u) && na->last_usermask) - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN_OPER, nick, na->last_usermask, na->last_realname ? na->last_realname : getstring(u, NO_REASON)); + if (is_oper(u) && !na->last_usermask.empty()) + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN_OPER, nick.c_str(), na->last_usermask.c_str(), !na->last_realname.empty() ? na->last_realname.c_str() : getstring(u, NO_REASON)); else - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, nick.c_str()); } else { @@ -77,22 +77,22 @@ class CommandNSInfo : public Command if (has_auspex || (u->Account() && na->nc == u->Account())) show_hidden = true; - notice_lang(Config.s_NickServ, u, NICK_INFO_REALNAME, na->nick, na->last_realname); + notice_lang(Config.s_NickServ, u, NICK_INFO_REALNAME, na->nick.c_str(), na->last_realname.c_str()); if (na->nc->IsServicesOper() && (show_hidden || !na->nc->HasFlag(NI_HIDE_STATUS))) - notice_lang(Config.s_NickServ, u, NICK_INFO_SERVICES_OPERTYPE, na->nick, na->nc->ot->GetName().c_str()); + notice_lang(Config.s_NickServ, u, NICK_INFO_SERVICES_OPERTYPE, na->nick.c_str(), na->nc->ot->GetName().c_str()); if (nick_online) { - if (show_hidden || !(na->nc->HasFlag(NI_HIDE_MASK))) - notice_lang(Config.s_NickServ, u, NICK_INFO_ADDRESS_ONLINE, na->last_usermask); + if (show_hidden || !na->nc->HasFlag(NI_HIDE_MASK)) + notice_lang(Config.s_NickServ, u, NICK_INFO_ADDRESS_ONLINE, na->last_usermask.c_str()); else - notice_lang(Config.s_NickServ, u, NICK_INFO_ADDRESS_ONLINE_NOHOST, na->nick); + notice_lang(Config.s_NickServ, u, NICK_INFO_ADDRESS_ONLINE_NOHOST, na->nick.c_str()); } else { - if (show_hidden || !(na->nc->HasFlag(NI_HIDE_MASK))) - notice_lang(Config.s_NickServ, u, NICK_INFO_ADDRESS, na->last_usermask); + if (show_hidden || !na->nc->HasFlag(NI_HIDE_MASK)) + notice_lang(Config.s_NickServ, u, NICK_INFO_ADDRESS, na->last_usermask.c_str()); } tm = localtime(&na->time_registered); @@ -106,25 +106,25 @@ class CommandNSInfo : public Command notice_lang(Config.s_NickServ, u, NICK_INFO_LAST_SEEN, buf); } - if (na->last_quit && (show_hidden || !(na->nc->HasFlag(NI_HIDE_QUIT)))) - notice_lang(Config.s_NickServ, u, NICK_INFO_LAST_QUIT, na->last_quit); + if (!na->last_quit.empty() && (show_hidden || !na->nc->HasFlag(NI_HIDE_QUIT))) + notice_lang(Config.s_NickServ, u, NICK_INFO_LAST_QUIT, na->last_quit.c_str()); - if (na->nc->email && (show_hidden || !(na->nc->HasFlag(NI_HIDE_EMAIL)))) - notice_lang(Config.s_NickServ, u, NICK_INFO_EMAIL, na->nc->email); + if (!na->nc->email.empty() && (show_hidden || !na->nc->HasFlag(NI_HIDE_EMAIL))) + notice_lang(Config.s_NickServ, u, NICK_INFO_EMAIL, na->nc->email.c_str()); if (show_hidden) { - if (Config.s_HostServ && ircd->vhost && na->hostinfo.HasVhost()) + if (!Config.s_HostServ.empty() && ircd->vhost && na->hostinfo.HasVhost()) { if (ircd->vident && !na->hostinfo.GetIdent().empty()) notice_lang(Config.s_NickServ, u, NICK_INFO_VHOST2, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); else notice_lang(Config.s_NickServ, u, NICK_INFO_VHOST, na->hostinfo.GetHost().c_str()); } - if (na->nc->greet) - notice_lang(Config.s_NickServ, u, NICK_INFO_GREET, na->nc->greet); + if (!na->nc->greet.empty()) + notice_lang(Config.s_NickServ, u, NICK_INFO_GREET, na->nc->greet.c_str()); - std::string optbuf; + Anope::string optbuf; CheckOptStr(optbuf, NI_KILLPROTECT, getstring(u, NICK_INFO_OPT_KILL), na->nc); CheckOptStr(optbuf, NI_SECURE, getstring(u, NICK_INFO_OPT_SECURE), na->nc); @@ -136,8 +136,8 @@ class CommandNSInfo : public Command if (na->nc->HasFlag(NI_SUSPENDED)) { - if (na->last_quit) - notice_lang(Config.s_NickServ, u, NICK_INFO_SUSPENDED, na->last_quit); + if (!na->last_quit.empty()) + notice_lang(Config.s_NickServ, u, NICK_INFO_SUSPENDED, na->last_quit.c_str()); else notice_lang(Config.s_NickServ, u, NICK_INFO_SUSPENDED_NO_REASON); } @@ -158,14 +158,14 @@ class CommandNSInfo : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP_INFO); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "INFO", NICK_INFO_SYNTAX); } @@ -179,7 +179,7 @@ class CommandNSInfo : public Command class NSInfo : public Module { public: - NSInfo(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_list.cpp b/modules/core/ns_list.cpp index d126bd104..324a3bceb 100644 --- a/modules/core/ns_list.cpp +++ b/modules/core/ns_list.cpp @@ -21,7 +21,7 @@ class CommandNSList : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { /* SADMINS can search for nicks based on their NS_FORBIDDEN and NS_NO_EXPIRE * status. The keywords FORBIDDEN and NOEXPIRE represent these two states @@ -36,15 +36,13 @@ class CommandNSList : public Command * * UPDATE: SUSPENDED keyword is now accepted as well. */ - const char *pattern = params[0].c_str(); - NickCore *mync; + Anope::string pattern = params[0]; + const NickCore *mync; unsigned nnicks; char buf[BUFSIZE]; bool is_servadmin = u->Account()->IsServicesOper(); char noexpire_char = ' '; - int count = 0, from = 0, to = 0, tofree = 0; - char *tmp = NULL; - char *s = NULL; + int count = 0, from = 0, to = 0; bool suspended, nsnoexpire, forbidden, unconfirmed; suspended = nsnoexpire = forbidden = unconfirmed = false; @@ -57,62 +55,55 @@ class CommandNSList : public Command if (pattern[0] == '#') { - tmp = myStrGetOnlyToken((pattern + 1), '-', 0); /* Read FROM out */ - if (!tmp) + Anope::string tmp = myStrGetToken(pattern.substr(1), '-', 0); /* Read FROM out */ + if (tmp.empty()) { - notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); + notice_lang(Config.s_NickServ, u, LIST_INCORRECT_RANGE); return MOD_CONT; } - for (s = tmp; *s; ++s) - if (!isdigit(*s)) - { - delete [] tmp; - notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); - return MOD_CONT; - } - from = atoi(tmp); - delete [] tmp; + if (!tmp.is_number_only()) + { + notice_lang(Config.s_NickServ, u, LIST_INCORRECT_RANGE); + return MOD_CONT; + } + from = convertTo<int>(tmp); tmp = myStrGetTokenRemainder(pattern, '-', 1); /* Read TO out */ - if (!tmp) + if (tmp.empty()) { - notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); + notice_lang(Config.s_NickServ, u, LIST_INCORRECT_RANGE); return MOD_CONT; } - for (s = tmp; *s; ++s) - if (!isdigit(*s)) - { - delete [] tmp; - notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); - return MOD_CONT; - } - to = atoi(tmp); - delete [] tmp; - pattern = sstrdup("*"); - tofree = 1; + if (!tmp.is_number_only()) + { + notice_lang(Config.s_NickServ, u, LIST_INCORRECT_RANGE); + return MOD_CONT; + } + to = convertTo<int>(tmp); + pattern = "*"; } nnicks = 0; if (is_servadmin && params.size() > 1) { - ci::string keyword; - spacesepstream keywords(params[1].c_str()); + Anope::string keyword; + spacesepstream keywords(params[1]); while (keywords.GetToken(keyword)) { - if (keyword == "FORBIDDEN") + if (keyword.equals_ci("FORBIDDEN")) forbidden = true; - if (keyword == "NOEXPIRE") + if (keyword.equals_ci("NOEXPIRE")) nsnoexpire = true; - if (keyword == "SUSPENDED") + if (keyword.equals_ci("SUSPENDED")) suspended = true; - if (keyword == "UNCONFIRMED") + if (keyword.equals_ci("UNCONFIRMED")) unconfirmed = true; } } mync = u->Account(); - notice_lang(Config.s_NickServ, u, NICK_LIST_HEADER, pattern); + notice_lang(Config.s_NickServ, u, NICK_LIST_HEADER, pattern.c_str()); if (!unconfirmed) { for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it) @@ -134,23 +125,23 @@ class CommandNSList : public Command /* We no longer compare the pattern against the output buffer. * Instead we build a nice nick!user@host buffer to compare. * The output is then generated separately. -TheShadow */ - snprintf(buf, sizeof(buf), "%s!%s", na->nick, na->last_usermask && !na->HasFlag(NS_FORBIDDEN) ? na->last_usermask : "*@*"); - if (!stricmp(pattern, na->nick) || Anope::Match(buf, pattern, false)) + snprintf(buf, sizeof(buf), "%s!%s", na->nick.c_str(), !na->last_usermask.empty() && !na->HasFlag(NS_FORBIDDEN) ? na->last_usermask.c_str() : "*@*"); + if (na->nick.equals_ci(pattern) || Anope::Match(buf, pattern)) { if (((count + 1 >= from && count + 1 <= to) || (!from && !to)) && ++nnicks <= Config.NSListMax) { - if (is_servadmin && (na->HasFlag(NS_NO_EXPIRE))) + if (is_servadmin && na->HasFlag(NS_NO_EXPIRE)) noexpire_char = '!'; else noexpire_char = ' '; - if ((na->nc->HasFlag(NI_HIDE_MASK)) && !is_servadmin && na->nc != mync) - snprintf(buf, sizeof(buf), "%-20s [Hostname Hidden]", na->nick); + if (na->nc->HasFlag(NI_HIDE_MASK) && !is_servadmin && na->nc != mync) + snprintf(buf, sizeof(buf), "%-20s [Hostname Hidden]", na->nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - snprintf(buf, sizeof(buf), "%-20s [Forbidden]", na->nick); + snprintf(buf, sizeof(buf), "%-20s [Forbidden]", na->nick.c_str()); else if (na->nc->HasFlag(NI_SUSPENDED)) - snprintf(buf, sizeof(buf), "%-20s [Suspended]", na->nick); + snprintf(buf, sizeof(buf), "%-20s [Suspended]", na->nick.c_str()); else - snprintf(buf, sizeof(buf), "%-20s %s", na->nick, na->last_usermask); + snprintf(buf, sizeof(buf), "%-20s %s", na->nick.c_str(), na->last_usermask.c_str()); u->SendMessage(Config.s_NickServ, " %c%s", noexpire_char, buf); } ++count; @@ -166,21 +157,19 @@ class CommandNSList : public Command { NickRequest *nr = it->second; - snprintf(buf, sizeof(buf), "%s!*@*", nr->nick); - if ((!stricmp(pattern, nr->nick) || Anope::Match(buf, pattern, false)) && ++nnicks <= Config.NSListMax) + snprintf(buf, sizeof(buf), "%s!*@*", nr->nick.c_str()); + if ((nr->nick.equals_ci(pattern) || Anope::Match(buf, pattern)) && ++nnicks <= Config.NSListMax) { - snprintf(buf, sizeof(buf), "%-20s [UNCONFIRMED]", nr->nick); + snprintf(buf, sizeof(buf), "%-20s [UNCONFIRMED]", nr->nick.c_str()); u->SendMessage(Config.s_NickServ, " %c%s", noexpire_char, buf); } } } notice_lang(Config.s_NickServ, u, NICK_LIST_RESULTS, nnicks > Config.NSListMax ? Config.NSListMax : nnicks, nnicks); - if (tofree) - delete [] pattern; return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (u->Account() && u->Account()->IsServicesOper()) notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_LIST); @@ -190,7 +179,7 @@ class CommandNSList : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { if (u->Account()->IsServicesOper()) syntax_error(Config.s_NickServ, u, "LIST", NICK_LIST_SERVADMIN_SYNTAX); @@ -207,7 +196,7 @@ class CommandNSList : public Command class NSList : public Module { public: - NSList(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_logout.cpp b/modules/core/ns_logout.cpp index cf49674d0..dc744bbad 100644 --- a/modules/core/ns_logout.cpp +++ b/modules/core/ns_logout.cpp @@ -20,32 +20,29 @@ class CommandNSLogout : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params.size() ? params[0].c_str() : NULL; - ci::string param = params.size() > 1 ? params[1] : ""; + Anope::string nick = !params.empty() ? params[0] : ""; + Anope::string param = params.size() > 1 ? params[1] : ""; User *u2; - NickAlias *na; - if (!u->Account()->IsServicesOper() && nick) + if (!u->Account()->IsServicesOper() && !nick.empty()) this->OnSyntaxError(u, ""); - else if (!(u2 = (nick ? finduser(nick) : u))) - notice_lang(Config.s_NickServ, u, NICK_X_NOT_IN_USE, nick); - else if (nick && u2->Account() && !u2->Account()->IsServicesOper()) - notice_lang(Config.s_NickServ, u, NICK_LOGOUT_SERVICESADMIN, nick); + else if (!(u2 = (!nick.empty() ? finduser(nick) : u))) + notice_lang(Config.s_NickServ, u, NICK_X_NOT_IN_USE, nick.c_str()); + else if (!nick.empty() && u2->Account() && !u2->Account()->IsServicesOper()) + notice_lang(Config.s_NickServ, u, NICK_LOGOUT_SERVICESADMIN, nick.c_str()); else { - na = findnick(u2->nick); - - if (nick && !param.empty() && param == "REVALIDATE") + if (!nick.empty() && !param.empty() && param.equals_ci("REVALIDATE")) validate_user(u2); u2->isSuperAdmin = 0; /* Dont let people logout and remain a SuperAdmin */ Alog() << Config.s_NickServ << ": " << u->GetMask() << " logged out nickname " << u2->nick; /* Remove founder status from this user in all channels */ - if (nick) - notice_lang(Config.s_NickServ, u, NICK_LOGOUT_X_SUCCEEDED, nick); + if (!nick.empty()) + notice_lang(Config.s_NickServ, u, NICK_LOGOUT_X_SUCCEEDED, nick.c_str()); else notice_lang(Config.s_NickServ, u, NICK_LOGOUT_SUCCEEDED); @@ -60,7 +57,7 @@ class CommandNSLogout : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (u->Account() && u->Account()->IsServicesOper()) notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_LOGOUT); @@ -70,7 +67,7 @@ class CommandNSLogout : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "LOGOUT", NICK_LOGOUT_SYNTAX); } @@ -84,7 +81,7 @@ class CommandNSLogout : public Command class NSLogout : public Module { public: - NSLogout(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSLogout(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_recover.cpp b/modules/core/ns_recover.cpp index acbc7073b..e3280c90d 100644 --- a/modules/core/ns_recover.cpp +++ b/modules/core/ns_recover.cpp @@ -21,22 +21,22 @@ class CommandNSRecover : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - std::string pass = params.size() > 1 ? params[1].c_str() : ""; + Anope::string nick = params[0]; + Anope::string pass = params.size() > 1 ? params[1] : ""; NickAlias *na; User *u2; if (!(u2 = finduser(nick))) - notice_lang(Config.s_NickServ, u, NICK_X_NOT_IN_USE, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_IN_USE, nick.c_str()); else if (!(na = findnick(u2->nick))) - notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); else if (na->nc->HasFlag(NI_SUSPENDED)) - notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, na->nick); - else if (!stricmp(nick, u->nick.c_str())) + notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, na->nick.c_str()); + else if (nick.equals_ci(u->nick)) notice_lang(Config.s_NickServ, u, NICK_NO_RECOVER_SELF); else if (!pass.empty()) { @@ -44,15 +44,13 @@ class CommandNSRecover : public Command if (res == 1) { - char relstr[192]; - notice_lang(Config.s_NickServ, u2, FORCENICKCHANGE_NOW); u2->Collide(na); /* Convert Config.NSReleaseTimeout seconds to string format */ - duration(na->nc, relstr, sizeof(relstr), Config.NSReleaseTimeout); + Anope::string relstr = duration(na->nc, Config.NSReleaseTimeout); - notice_lang(Config.s_NickServ, u, NICK_RECOVERED, Config.s_NickServ, nick, relstr); + notice_lang(Config.s_NickServ, u, NICK_RECOVERED, Config.s_NickServ.c_str(), nick.c_str(), relstr.c_str()); } else { @@ -69,15 +67,13 @@ class CommandNSRecover : public Command { if (u->Account() == na->nc || (!na->nc->HasFlag(NI_SECURE) && is_on_access(u, na->nc))) { - char relstr[192]; - notice_lang(Config.s_NickServ, u2, FORCENICKCHANGE_NOW); u2->Collide(na); /* Convert Config.NSReleaseTimeout seconds to string format */ - duration(na->nc, relstr, sizeof(relstr), Config.NSReleaseTimeout); + Anope::string relstr = duration(na->nc, Config.NSReleaseTimeout); - notice_lang(Config.s_NickServ, u, NICK_RECOVERED, Config.s_NickServ, nick, relstr); + notice_lang(Config.s_NickServ, u, NICK_RECOVERED, Config.s_NickServ.c_str(), nick.c_str(), relstr.c_str()); } else notice_lang(Config.s_NickServ, u, ACCESS_DENIED); @@ -85,20 +81,18 @@ class CommandNSRecover : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { - char relstr[192]; - /* Convert Config.NSReleaseTimeout seconds to string format */ - duration(u->Account(), relstr, sizeof(relstr), Config.NSReleaseTimeout); + Anope::string relstr = duration(u->Account(), Config.NSReleaseTimeout); - notice_help(Config.s_NickServ, u, NICK_HELP_RECOVER, relstr); + notice_help(Config.s_NickServ, u, NICK_HELP_RECOVER, relstr.c_str()); //do_help_limited(Config.s_NickServ, u, this); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "RECOVER", NICK_RECOVER_SYNTAX); } @@ -112,7 +106,7 @@ class CommandNSRecover : public Command class NSRecover : public Module { public: - NSRecover(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSRecover(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_register.cpp b/modules/core/ns_register.cpp index 3fba0407e..46764cd9e 100644 --- a/modules/core/ns_register.cpp +++ b/modules/core/ns_register.cpp @@ -29,7 +29,7 @@ class CommandNSConfirm : public Command return MOD_CONT; } - std::string tmp_pass; + Anope::string tmp_pass; na->nc->pass = nr->password; @@ -37,27 +37,27 @@ class CommandNSConfirm : public Command if (force) { - na->last_usermask = sstrdup("*@*"); - na->last_realname = sstrdup("unknown"); + na->last_usermask = "*@*"; + na->last_realname = "unknown"; } else { - std::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost(); - na->last_usermask = sstrdup(last_usermask.c_str()); - na->last_realname = sstrdup(u->realname); + Anope::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost(); + na->last_usermask = last_usermask; + na->last_realname = u->realname; if (Config.NSAddAccessOnReg) na->nc->AddAccess(create_mask(u)); } na->time_registered = na->last_seen = time(NULL); na->nc->language = Config.NSDefLanguage; - if (nr->email) - na->nc->email = sstrdup(nr->email); + if (!nr->email.empty()) + na->nc->email = nr->email; if (!force) { u->Login(na->nc); - Alog() << Config.s_NickServ << ": '" << u->nick << "' registered by " << u->GetIdent() << "@" << u->host << " (e-mail: " << (nr->email ? nr->email : "none") << ")"; + Alog() << Config.s_NickServ << ": '" << u->nick << "' registered by " << u->GetIdent() << "@" << u->host << " (e-mail: " << (!nr->email.empty() ? nr->email : "none") << ")"; if (Config.NSAddAccessOnReg) notice_lang(Config.s_NickServ, u, NICK_REGISTERED, u->nick.c_str(), na->nc->GetAccess(0).c_str()); else @@ -74,8 +74,8 @@ class CommandNSConfirm : public Command } else { - Alog() << Config.s_NickServ << ": '" << nr->nick << "' confirmed by " << u->GetMask() << " (email: " << (nr->email ? nr->email : "none") << " )"; - notice_lang(Config.s_NickServ, u, NICK_FORCE_REG, nr->nick); + Alog() << Config.s_NickServ << ": '" << nr->nick << "' confirmed by " << u->GetMask() << " (email: " << (!nr->email.empty() ? nr->email : "none") << " )"; + notice_lang(Config.s_NickServ, u, NICK_FORCE_REG, nr->nick.c_str()); User *user = finduser(nr->nick); /* Delrequest must be called before validate_user */ delete nr; @@ -86,12 +86,11 @@ class CommandNSConfirm : public Command FOREACH_MOD(I_OnNickRegister, OnNickRegister(na)); return MOD_CONT; - } - CommandReturn DoConfirm(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoConfirm(User *u, const std::vector<Anope::string> ¶ms) { - std::string passcode = !params.empty() ? params[0].c_str() : ""; + Anope::string passcode = !params.empty() ? params[0] : ""; NickRequest *nr = findrequestnick(u->nick); @@ -116,12 +115,12 @@ class CommandNSConfirm : public Command return MOD_CONT; } } - notice_lang(Config.s_NickServ, u, NICK_CONFIRM_NOT_FOUND, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, NICK_CONFIRM_NOT_FOUND, Config.s_NickServ.c_str()); return MOD_CONT; } - if (nr->passcode.compare(passcode)) + if (!nr->passcode.equals_cs(passcode)) { notice_lang(Config.s_NickServ, u, NICK_CONFIRM_INVALID); return MOD_CONT; @@ -139,17 +138,17 @@ class CommandNSConfirm : public Command } public: - CommandNSConfirm(const ci::string &cmdn, int min, int max) : Command(cmdn, min, max) + CommandNSConfirm(const Anope::string &cmdn, int min, int max) : Command(cmdn, min, max) { this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { return this->DoConfirm(u, params); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP_CONFIRM); if (u->Account() && u->Account()->HasPriv("nickserv/confirm")) @@ -157,7 +156,7 @@ class CommandNSConfirm : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { notice_lang(Config.s_NickServ, u, NICK_CONFIRM_INVALID); } @@ -176,15 +175,15 @@ class CommandNSRegister : public CommandNSConfirm this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickRequest *nr = NULL, *anr = NULL; NickAlias *na; - int prefixlen = strlen(Config.NSGuestNickPrefix); - int nicklen = u->nick.length(); - const char *pass = params[0].c_str(); - const char *email = params.size() > 1 ? params[1].c_str() : NULL; - char passcode[11]; + size_t prefixlen = Config.NSGuestNickPrefix.length(); + size_t nicklen = u->nick.length(); + Anope::string pass = params[0]; + Anope::string email = params.size() > 1 ? params[1] : ""; + Anope::string passcode; int idx, min = 1, max = 62; int chars[] = { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', @@ -193,7 +192,7 @@ class CommandNSRegister : public CommandNSConfirm 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; - std::list<std::pair<ci::string, ci::string> >::iterator it, it_end; + std::list<std::pair<Anope::string, Anope::string> >::iterator it, it_end; if (readonly) { @@ -218,13 +217,13 @@ class CommandNSRegister : public CommandNSConfirm /* Guest nick can now have a series of between 1 and 7 digits. * --lara */ - if (nicklen <= prefixlen + 7 && nicklen >= prefixlen + 1 && stristr(u->nick.c_str(), Config.NSGuestNickPrefix) == u->nick.c_str() && strspn(u->nick.c_str() + prefixlen, "1234567890") == nicklen - prefixlen) + if (nicklen <= prefixlen + 7 && nicklen >= prefixlen + 1 && !u->nick.find_ci(Config.NSGuestNickPrefix) && !u->nick.substr(prefixlen).find_first_not_of("1234567890")) { notice_lang(Config.s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); return MOD_CONT; } - if (!ircdproto->IsNickValid(u->nick.c_str())) + if (!ircdproto->IsNickValid(u->nick)) { notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, u->nick.c_str()); return MOD_CONT; @@ -233,16 +232,16 @@ class CommandNSRegister : public CommandNSConfirm if (Config.RestrictOperNicks) for (it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) { - ci::string nick = it->first; + Anope::string nick = it->first; - if (stristr(u->nick.c_str(), nick.c_str()) && !is_oper(u)) + if (u->nick.find_ci(nick) != Anope::string::npos && !is_oper(u)) { notice_lang(Config.s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); return MOD_CONT; } } - if (Config.NSForceEmail && !email) + if (Config.NSForceEmail && email.empty()) this->OnSyntaxError(u, ""); else if (time(NULL) < u->lastnickreg + Config.NSRegDelay) notice_lang(Config.s_NickServ, u, NICK_REG_PLEASE_WAIT, (u->lastnickreg + Config.NSRegDelay) - time(NULL)); @@ -257,29 +256,28 @@ class CommandNSRegister : public CommandNSConfirm else notice_lang(Config.s_NickServ, u, NICK_ALREADY_REGISTERED, u->nick.c_str()); } - else if (!stricmp(u->nick.c_str(), pass) || (Config.StrictPasswords && strlen(pass) < 5)) + else if (pass.equals_ci(u->nick) || (Config.StrictPasswords && pass.length() < 5)) notice_lang(Config.s_NickServ, u, MORE_OBSCURE_PASSWORD); - else if (strlen(pass) > Config.PassLen) + else if (pass.length() > Config.PassLen) notice_lang(Config.s_NickServ, u, PASSWORD_TOO_LONG); - else if (email && !MailValidate(email)) - notice_lang(Config.s_NickServ, u, MAIL_X_INVALID, email); + else if (!email.empty() && !MailValidate(email)) + notice_lang(Config.s_NickServ, u, MAIL_X_INVALID, email.c_str()); else { for (idx = 0; idx < 9; ++idx) - passcode[idx] = chars[1 + static_cast<int>((static_cast<float>(max - min)) * getrandom16() / 65536.0) + min]; - passcode[idx] = '\0'; + passcode += chars[1 + static_cast<int>((static_cast<float>(max - min)) * getrandom16() / 65536.0) + min]; nr = new NickRequest(u->nick); nr->passcode = passcode; enc_encrypt(pass, nr->password); - if (email) - nr->email = sstrdup(email); + if (!email.empty()) + nr->email = email; nr->requested = time(NULL); FOREACH_MOD(I_OnMakeNickRequest, OnMakeNickRequest(nr)); if (Config.NSEmailReg) { if (SendRegmail(u, nr)) { - notice_lang(Config.s_NickServ, u, NICK_ENTER_REG_CODE, email, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, NICK_ENTER_REG_CODE, email.c_str(), Config.s_NickServ.c_str()); Alog() << Config.s_NickServ << ": sent registration verification code to " << nr->email; } else @@ -292,7 +290,7 @@ class CommandNSRegister : public CommandNSConfirm } else { - std::vector<ci::string> empty_params; + std::vector<Anope::string> empty_params; return this->DoConfirm(u, empty_params); } } @@ -300,13 +298,13 @@ class CommandNSRegister : public CommandNSConfirm return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP_REGISTER); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { if (Config.NSForceEmail) syntax_error(Config.s_NickServ, u, "REGISTER", NICK_REGISTER_SYNTAX_EMAIL); @@ -328,7 +326,7 @@ class CommandNSResend : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickRequest *nr = NULL; if (Config.NSEmailReg) @@ -343,7 +341,7 @@ class CommandNSResend : public Command if (!SendRegmail(u, nr)) { nr->lastmail = time(NULL); - notice_lang(Config.s_NickServ, u, NICK_REG_RESENT, nr->email); + notice_lang(Config.s_NickServ, u, NICK_REG_RESENT, nr->email.c_str()); Alog() << Config.s_NickServ << ": re-sent registration verification code for " << nr->nick << " to " << nr->email; } else @@ -356,7 +354,7 @@ class CommandNSResend : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP_RESEND); return true; @@ -371,7 +369,7 @@ class CommandNSResend : public Command class NSRegister : public Module { public: - NSRegister(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); @@ -386,8 +384,8 @@ static bool SendRegmail(User *u, NickRequest *nr) { char subject[BUFSIZE], message[BUFSIZE]; - snprintf(subject, sizeof(subject), getstring(NICK_REG_MAIL_SUBJECT), nr->nick); - snprintf(message, sizeof(message), getstring(NICK_REG_MAIL), nr->nick, Config.NetworkName, Config.s_NickServ, nr->passcode.c_str(), Config.NetworkName); + snprintf(subject, sizeof(subject), getstring(NICK_REG_MAIL_SUBJECT), nr->nick.c_str()); + snprintf(message, sizeof(message), getstring(NICK_REG_MAIL), nr->nick.c_str(), Config.NetworkName.c_str(), Config.s_NickServ.c_str(), nr->passcode.c_str(), Config.NetworkName.c_str()); return Mail(u, nr, Config.s_NickServ, subject, message); } diff --git a/modules/core/ns_release.cpp b/modules/core/ns_release.cpp index d2b6eaa03..cb59ac6a1 100644 --- a/modules/core/ns_release.cpp +++ b/modules/core/ns_release.cpp @@ -21,20 +21,20 @@ class CommandNSRelease : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - std::string pass = params.size() > 1 ? params[1].c_str() : ""; + Anope::string nick = params[0]; + Anope::string pass = params.size() > 1 ? params[1] : ""; NickAlias *na; if (!(na = findnick(nick))) - notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); else if (na->nc->HasFlag(NI_SUSPENDED)) - notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, na->nick); - else if (!(na->HasFlag(NS_HELD))) - notice_lang(Config.s_NickServ, u, NICK_RELEASE_NOT_HELD, nick); + notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, na->nick.c_str()); + else if (!na->HasFlag(NS_HELD)) + notice_lang(Config.s_NickServ, u, NICK_RELEASE_NOT_HELD, nick.c_str()); else if (!pass.empty()) { int res = enc_check_password(pass, na->nc->pass); @@ -56,7 +56,7 @@ class CommandNSRelease : public Command } else { - if (u->Account() == na->nc || (!(na->nc->HasFlag(NI_SECURE)) && is_on_access(u, na->nc))) + if (u->Account() == na->nc || (!na->nc->HasFlag(NI_SECURE) && is_on_access(u, na->nc))) { na->Release(); notice_lang(Config.s_NickServ, u, NICK_RELEASED); @@ -67,20 +67,18 @@ class CommandNSRelease : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { - char relstr[192]; - /* Convert Config.NSReleaseTimeout seconds to string format */ - duration(u->Account(), relstr, sizeof(relstr), Config.NSReleaseTimeout); + Anope::string relstr = duration(u->Account(), Config.NSReleaseTimeout); - notice_help(Config.s_NickServ, u, NICK_HELP_RELEASE, relstr); + notice_help(Config.s_NickServ, u, NICK_HELP_RELEASE, relstr.c_str()); //do_help_limited(Config.s_NickServ, u, this); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "RELEASE", NICK_RELEASE_SYNTAX); } @@ -94,7 +92,7 @@ class CommandNSRelease : public Command class NSRelease : public Module { public: - NSRelease(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSRelease(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_resetpass.cpp b/modules/core/ns_resetpass.cpp index 25c598d13..23bb8095e 100644 --- a/modules/core/ns_resetpass.cpp +++ b/modules/core/ns_resetpass.cpp @@ -22,7 +22,7 @@ class CommandNSResetPass : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na; @@ -31,26 +31,26 @@ class CommandNSResetPass : public Command if (!(na = findnick(params[0]))) notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, params[0].c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); else { if (SendResetEmail(u, na)) { Alog() << Config.s_NickServ << ": " << u->GetMask() << " used RESETPASS on " << na->nick << " (" << na->nc->display << ")"; - notice_lang(Config.s_NickServ, u, NICK_RESETPASS_COMPLETE, na->nick); + notice_lang(Config.s_NickServ, u, NICK_RESETPASS_COMPLETE, na->nick.c_str()); } } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP_RESETPASS); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "RESETPASS", NICK_RESETPASS_SYNTAX); } @@ -64,7 +64,7 @@ class CommandNSResetPass : public Command class NSResetPass : public Module { public: - NSResetPass(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSResetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { if (!Config.UseMail) throw ModuleException("Not using mail."); @@ -77,14 +77,14 @@ class NSResetPass : public Module ModuleManager::Attach(I_OnPreCommand, this); } - EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms) + EventReturn OnPreCommand(User *u, BotInfo *service, const Anope::string &command, const std::vector<Anope::string> ¶ms) { - if (service == Config.s_NickServ && command == "CONFIRM" && !params.empty()) + if (service == findbot(Config.s_NickServ) && command.equals_ci("CONFIRM") && !params.empty()) { NickAlias *na = findnick(u->nick); time_t t; - std::string c; + Anope::string c; if (na && na->nc->GetExtRegular("ns_resetpass_code", c) && na->nc->GetExtRegular("ns_resetpass_time", t)) { if (t < time(NULL) - 3600) @@ -95,16 +95,14 @@ class NSResetPass : public Module return EVENT_STOP; } - std::string passcode = params[0].c_str(); - if (passcode == c) + Anope::string passcode = params[0]; + if (passcode.equals_cs(c)) { na->nc->Shrink("ns_resetpass_code"); na->nc->Shrink("ns_resetpass_time"); u->UpdateHost(); - if (na->last_realname) - delete [] na->last_realname; - na->last_realname = sstrdup(u->realname); + na->last_realname = u->realname; na->last_seen = time(NULL); u->Login(na->nc); ircdproto->SendAccountLogin(u, u->Account()); @@ -112,7 +110,7 @@ class NSResetPass : public Module FOREACH_MOD(I_OnNickIdentify, OnNickIdentify(u)); Alog() << Config.s_NickServ << ": " << u->GetMask() << " used CONFIRM with RESETPASS to forcefully identify to " << na->nick; - notice_lang(Config.s_NickServ, u, NICK_CONFIRM_SUCCESS, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, NICK_CONFIRM_SUCCESS, Config.s_NickServ.c_str()); if (ircd->vhost) do_on_id(u); @@ -137,9 +135,9 @@ class NSResetPass : public Module static bool SendResetEmail(User *u, NickAlias *na) { - char subject[BUFSIZE], message[BUFSIZE], passcode[20]; + char subject[BUFSIZE], message[BUFSIZE]; - snprintf(subject, sizeof(subject), getstring(na, NICK_RESETPASS_SUBJECT), na->nick); + snprintf(subject, sizeof(subject), getstring(na, NICK_RESETPASS_SUBJECT), na->nick.c_str()); int min = 1, max = 62; int chars[] = { @@ -150,17 +148,17 @@ static bool SendResetEmail(User *u, NickAlias *na) 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; + Anope::string passcode; int idx; for (idx = 0; idx < 20; ++idx) - passcode[idx] = chars[1 + static_cast<int>((static_cast<float>(max - min)) * getrandom16() / 65536.0) + min]; - passcode[idx] = '\0'; + passcode += chars[1 + static_cast<int>((static_cast<float>(max - min)) * getrandom16() / 65536.0) + min]; - snprintf(message, sizeof(message), getstring(na, NICK_RESETPASS_MESSAGE), na->nick, Config.s_NickServ, passcode, Config.NetworkName); + snprintf(message, sizeof(message), getstring(na, NICK_RESETPASS_MESSAGE), na->nick.c_str(), Config.s_NickServ.c_str(), passcode.c_str(), Config.NetworkName.c_str()); na->nc->Shrink("ns_resetpass_code"); na->nc->Shrink("ns_resetpass_time"); - na->nc->Extend("ns_resetpass_code", new ExtensibleItemRegular<std::string>(passcode)); + na->nc->Extend("ns_resetpass_code", new ExtensibleItemRegular<Anope::string>(passcode)); na->nc->Extend("ns_resetpass_time", new ExtensibleItemRegular<time_t>(time(NULL))); return Mail(u, na->nc, Config.s_NickServ, subject, message); diff --git a/modules/core/ns_saset.cpp b/modules/core/ns_saset.cpp index 2b8150f18..4beccbcad 100644 --- a/modules/core/ns_saset.cpp +++ b/modules/core/ns_saset.cpp @@ -15,23 +15,25 @@ class CommandNSSASet : public Command { - std::map<ci::string, Command *> subcommands; + typedef std::map<Anope::string, Command *, hash_compare_ci_string> subcommand_map; + subcommand_map subcommands; + public: - CommandNSSASet(const ci::string &cname) : Command(cname, 2, 4) + CommandNSSASet(const Anope::string &cname) : Command(cname, 2, 4) { } ~CommandNSSASet() { - for (std::map<ci::string, Command *>::const_iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) + for (subcommand_map::const_iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) delete it->second; this->subcommands.clear(); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - ci::string cmd = params[1]; + Anope::string nick = params[0]; + Anope::string cmd = params[1]; if (readonly) { @@ -41,19 +43,19 @@ class CommandNSSASet : public Command NickAlias *na = findnick(nick); if (!na) - notice_lang(Config.s_NickServ, u, NICK_SASET_BAD_NICK, nick); + notice_lang(Config.s_NickServ, u, NICK_SASET_BAD_NICK, nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); else if (na->nc->HasFlag(NI_SUSPENDED)) - notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, na->nick.c_str()); else { Command *c = this->FindCommand(params[1]); if (c) { - ci::string cmdparams = na->nc->display; - for (std::vector<ci::string>::const_iterator it = params.begin() + 1; it != params.end(); ++it) + Anope::string cmdparams = na->nc->display; + for (std::vector<Anope::string>::const_iterator it = params.begin() + 1; it != params.end(); ++it) cmdparams += " " + *it; mod_run_cmd(NickServ, u, c, params[1], cmdparams); } @@ -64,12 +66,12 @@ class CommandNSSASet : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (subcommand.empty()) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_HEAD); - for (std::map<ci::string, Command *>::iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) + for (subcommand_map::iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) it->second->OnServHelp(u); notice_help(Config.s_NickServ, u, NICK_HELP_SASET_TAIL); return true; @@ -85,7 +87,7 @@ class CommandNSSASet : public Command return false; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "SASET", NICK_SASET_SYNTAX); } @@ -100,14 +102,14 @@ class CommandNSSASet : public Command return this->subcommands.insert(std::make_pair(c->name, c)).second; } - bool DelSubcommand(const ci::string &command) + bool DelSubcommand(const Anope::string &command) { return this->subcommands.erase(command); } - Command *FindCommand(const ci::string &subcommand) + Command *FindCommand(const Anope::string &subcommand) { - std::map<ci::string, Command *>::const_iterator it = this->subcommands.find(subcommand); + subcommand_map::const_iterator it = this->subcommands.find(subcommand); if (it != this->subcommands.end()) return it->second; @@ -119,11 +121,11 @@ class CommandNSSASet : public Command class CommandNSSASetDisplay : public Command { public: - CommandNSSASetDisplay(const ci::string &cname) : Command(cname, 2, 2, "nickserv/saset/display") + CommandNSSASetDisplay(const Anope::string &cname) : Command(cname, 2, 2, "nickserv/saset/display") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); assert(nc); @@ -131,22 +133,22 @@ class CommandNSSASetDisplay : public Command NickAlias *na = findnick(params[1]); if (!na || na->nc != nc) { - notice_lang(Config.s_NickServ, u, NICK_SASET_DISPLAY_INVALID, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_DISPLAY_INVALID, nc->display.c_str()); return MOD_CONT; } - change_core_display(nc, params[1].c_str()); - notice_lang(Config.s_NickServ, u, NICK_SASET_DISPLAY_CHANGED, nc->display); + change_core_display(nc, params[1]); + notice_lang(Config.s_NickServ, u, NICK_SASET_DISPLAY_CHANGED, nc->display.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_DISPLAY); return true; } - void OnSyntaxError(User *u) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_NickServ, u, "SASET", NICK_SASET_SYNTAX); @@ -161,23 +163,23 @@ class CommandNSSASetDisplay : public Command class CommandNSSASetPassword : public Command { public: - CommandNSSASetPassword(const ci::string &cname) : Command(cname, 2, 2, "nickserv/saset/password") + CommandNSSASetPassword(const Anope::string &cname) : Command(cname, 2, 2, "nickserv/saset/password") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); assert(nc); - size_t len = params[1].size(); + size_t len = params[1].length(); if (Config.NSSecureAdmins && u->Account() != nc && nc->IsServicesOper()) { notice_lang(Config.s_NickServ, u, ACCESS_DENIED); return MOD_CONT; } - else if (nc->display == params[1] || (Config.StrictPasswords && len < 5)) + else if (nc->display.equals_ci(params[1]) || (Config.StrictPasswords && len < 5)) { notice_lang(Config.s_NickServ, u, MORE_OBSCURE_PASSWORD); return MOD_CONT; @@ -188,35 +190,34 @@ class CommandNSSASetPassword : public Command return MOD_CONT; } - std::string buf = params[1].c_str(); - if (enc_encrypt(buf, nc->pass)) + if (enc_encrypt(params[1], nc->pass)) { Alog() << Config.s_NickServ << ": Failed to encrypt password for " << nc->display << " (saset)"; - notice_lang(Config.s_NickServ, u, NICK_SASET_PASSWORD_FAILED, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_PASSWORD_FAILED, nc->display.c_str()); return MOD_CONT; } - std::string tmp_pass; + Anope::string tmp_pass; if (enc_decrypt(nc->pass, tmp_pass) == 1) - notice_lang(Config.s_NickServ, u, NICK_SASET_PASSWORD_CHANGED_TO, nc->display, tmp_pass.c_str()); + notice_lang(Config.s_NickServ, u, NICK_SASET_PASSWORD_CHANGED_TO, nc->display.c_str(), tmp_pass.c_str()); else - notice_lang(Config.s_NickServ, u, NICK_SASET_PASSWORD_CHANGED, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_PASSWORD_CHANGED, nc->display.c_str()); - Alog() << Config.s_NickServ << ": " << u->GetMask() << " used SASET PASSWORD on " << nc->display << " (e-mail: "<< (nc->email ? nc->email : "none") << ")"; + Alog() << Config.s_NickServ << ": " << u->GetMask() << " used SASET PASSWORD on " << nc->display << " (e-mail: "<< (!nc->email.empty() ? nc->email : "none") << ")"; if (Config.WallSetpass) - ircdproto->SendGlobops(NickServ, "\2%s\2 used SASET PASSWORD on \2%s\2", u->nick.c_str(), nc->display); + ircdproto->SendGlobops(NickServ, "\2%s\2 used SASET PASSWORD on \2%s\2", u->nick.c_str(), nc->display.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_PASSWORD); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SASET", NICK_SASET_SYNTAX); } @@ -230,7 +231,7 @@ class CommandNSSASetPassword : public Command class NSSASet : public Module { public: - NSSASet(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSASet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_saset_noexpire.cpp b/modules/core/ns_saset_noexpire.cpp index e68486350..2c8f93243 100644 --- a/modules/core/ns_saset_noexpire.cpp +++ b/modules/core/ns_saset_noexpire.cpp @@ -16,26 +16,26 @@ class CommandNSSASetNoexpire : public Command { public: - CommandNSSASetNoexpire(const ci::string &cname) : Command(cname, 1, 2, "nickserv/saset/noexpire") + CommandNSSASetNoexpire(const Anope::string &cname) : Command(cname, 1, 2, "nickserv/saset/noexpire") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na = findnick(params[0]); assert(na); - ci::string param = params.size() > 1 ? params[1] : ""; + Anope::string param = params.size() > 1 ? params[1] : ""; - if (param == "ON") + if (param.equals_ci("ON")) { na->SetFlag(NS_NO_EXPIRE); - notice_lang(Config.s_NickServ, u, NICK_SASET_NOEXPIRE_ON, na->nick); + notice_lang(Config.s_NickServ, u, NICK_SASET_NOEXPIRE_ON, na->nick.c_str()); } - else if (param == "OFF") + else if (param.equals_ci("OFF")) { na->UnsetFlag(NS_NO_EXPIRE); - notice_lang(Config.s_NickServ, u, NICK_SASET_NOEXPIRE_OFF, na->nick); + notice_lang(Config.s_NickServ, u, NICK_SASET_NOEXPIRE_OFF, na->nick.c_str()); } else this->OnSyntaxError(u, "NOEXPIRE"); @@ -43,13 +43,13 @@ class CommandNSSASetNoexpire : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_NOEXPIRE); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SASET NOEXPIRE", NICK_SASET_NOEXPIRE_SYNTAX); } @@ -63,7 +63,7 @@ class CommandNSSASetNoexpire : public Command class NSSASetNoexpire : public Module { public: - NSSASetNoexpire(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSASetNoexpire(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_sendpass.cpp b/modules/core/ns_sendpass.cpp index d75f38e8f..61a61f356 100644 --- a/modules/core/ns_sendpass.cpp +++ b/modules/core/ns_sendpass.cpp @@ -13,7 +13,7 @@ #include "module.h" -static bool SendPassMail(User *u, NickAlias *na, const std::string &pass); +static bool SendPassMail(User *u, NickAlias *na, const Anope::string &pass); class CommandNSSendPass : public Command { @@ -22,26 +22,26 @@ class CommandNSSendPass : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); + Anope::string nick = params[0]; NickAlias *na; if (Config.RestrictMail && !u->Account()->HasCommand("nickserv/sendpass")) notice_lang(Config.s_NickServ, u, ACCESS_DENIED); else if (!(na = findnick(nick))) - notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); else { - std::string tmp_pass; - if (enc_decrypt(na->nc->pass,tmp_pass) == 1) + Anope::string tmp_pass; + if (enc_decrypt(na->nc->pass, tmp_pass) == 1) { if (SendPassMail(u, na, tmp_pass)) { Alog() << Config.s_NickServ << ": " << u->GetMask() << " used SENDPASS on " << nick; - notice_lang(Config.s_NickServ, u, NICK_SENDPASS_OK, nick); + notice_lang(Config.s_NickServ, u, NICK_SENDPASS_OK, nick.c_str()); } } else @@ -51,13 +51,13 @@ class CommandNSSendPass : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP_SENDPASS); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "SENDPASS", NICK_SENDPASS_SYNTAX); } @@ -71,12 +71,12 @@ class CommandNSSendPass : public Command class NSSendPass : public Module { public: - NSSendPass(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSendPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { if (!Config.UseMail) throw ModuleException("Not using mail, whut."); - std::string tmp_pass = "plain:tmp"; + Anope::string tmp_pass = "plain:tmp"; if (enc_decrypt(tmp_pass, tmp_pass) == -1) throw ModuleException("Incompatible with the encryption module being used"); @@ -87,12 +87,12 @@ class NSSendPass : public Module } }; -static bool SendPassMail(User *u, NickAlias *na, const std::string &pass) +static bool SendPassMail(User *u, NickAlias *na, const Anope::string &pass) { char subject[BUFSIZE], message[BUFSIZE]; - snprintf(subject, sizeof(subject), getstring(na, NICK_SENDPASS_SUBJECT), na->nick); - snprintf(message, sizeof(message), getstring(na, NICK_SENDPASS), na->nick, pass.c_str(), Config.NetworkName); + snprintf(subject, sizeof(subject), getstring(na, NICK_SENDPASS_SUBJECT), na->nick.c_str()); + snprintf(message, sizeof(message), getstring(na, NICK_SENDPASS), na->nick.c_str(), pass.c_str(), Config.NetworkName.c_str()); return Mail(u, na->nc, Config.s_NickServ, subject, message); } diff --git a/modules/core/ns_set.cpp b/modules/core/ns_set.cpp index f858c6a9c..a55adefb4 100644 --- a/modules/core/ns_set.cpp +++ b/modules/core/ns_set.cpp @@ -15,20 +15,22 @@ class CommandNSSet : public Command { - std::map<ci::string, Command *> subcommands; + typedef std::map<Anope::string, Command *, hash_compare_ci_string> subcommand_map; + subcommand_map subcommands; + public: - CommandNSSet(const ci::string &cname) : Command(cname, 1, 3) + CommandNSSet(const Anope::string &cname) : Command(cname, 1, 3) { } ~CommandNSSet() { - for (std::map<ci::string, Command *>::const_iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) + for (subcommand_map::const_iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) delete it->second; this->subcommands.clear(); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { if (readonly) { @@ -38,7 +40,7 @@ class CommandNSSet : public Command if (u->Account()->HasFlag(NI_SUSPENDED)) { - notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, u->Account()->display); + notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, u->Account()->display.c_str()); return MOD_CONT; } @@ -46,8 +48,8 @@ class CommandNSSet : public Command if (c) { - ci::string cmdparams; - for (std::vector<ci::string>::const_iterator it = params.begin() + 1, it_end = params.end(); it != it_end; ++it) + Anope::string cmdparams; + for (std::vector<Anope::string>::const_iterator it = params.begin() + 1, it_end = params.end(); it != it_end; ++it) cmdparams += " " + *it; if (!cmdparams.empty()) cmdparams.erase(cmdparams.begin()); @@ -59,12 +61,12 @@ class CommandNSSet : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (subcommand.empty()) { notice_help(Config.s_NickServ, u, NICK_HELP_SET_HEAD); - for (std::map<ci::string, Command *>::iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) + for (subcommand_map::iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) it->second->OnServHelp(u); notice_help(Config.s_NickServ, u, NICK_HELP_SET_TAIL); return true; @@ -80,7 +82,7 @@ class CommandNSSet : public Command return false; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "SET", NICK_SET_SYNTAX); } @@ -95,14 +97,14 @@ class CommandNSSet : public Command return this->subcommands.insert(std::make_pair(c->name, c)).second; } - bool DelSubcommand(const ci::string &command) + bool DelSubcommand(const Anope::string &command) { return this->subcommands.erase(command); } - Command *FindCommand(const ci::string &subcommand) + Command *FindCommand(const Anope::string &subcommand) { - std::map<ci::string, Command *>::const_iterator it = this->subcommands.find(subcommand); + subcommand_map::const_iterator it = this->subcommands.find(subcommand); if (it != this->subcommands.end()) return it->second; @@ -114,11 +116,11 @@ class CommandNSSet : public Command class CommandNSSetDisplay : public Command { public: - CommandNSSetDisplay(const ci::string &cname) : Command(cname, 1) + CommandNSSetDisplay(const Anope::string &cname) : Command(cname, 1) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na = findnick(params[0]); @@ -128,18 +130,18 @@ class CommandNSSetDisplay : public Command return MOD_CONT; } - change_core_display(u->Account(), params[0].c_str()); - notice_lang(Config.s_NickServ, u, NICK_SET_DISPLAY_CHANGED, u->Account()->display); + change_core_display(u->Account(), params[0]); + notice_lang(Config.s_NickServ, u, NICK_SET_DISPLAY_CHANGED, u->Account()->display.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SET_DISPLAY); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_NickServ, u, "SET", NICK_SET_SYNTAX); @@ -154,17 +156,17 @@ class CommandNSSetDisplay : public Command class CommandNSSetPassword : public Command { public: - CommandNSSetPassword(const ci::string &cname) : Command(cname, 1) + CommandNSSetPassword(const Anope::string &cname) : Command(cname, 1) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string param = params[0]; + Anope::string param = params[0]; - int len = param.size(); + int len = param.length(); - if (u->Account()->display == param || (Config.StrictPasswords && len < 5)) + if (u->Account()->display.equals_ci(param) || (Config.StrictPasswords && len < 5)) { notice_lang(Config.s_NickServ, u, MORE_OBSCURE_PASSWORD); return MOD_CONT; @@ -175,31 +177,30 @@ class CommandNSSetPassword : public Command return MOD_CONT; } - std::string buf = param.c_str(); /* conversion from ci::string to std::string */ - if (enc_encrypt(buf, u->Account()->pass) < 0) + if (enc_encrypt(param, u->Account()->pass) < 0) { Alog() << Config.s_NickServ << ": Failed to encrypt password for " << u->Account()->display << " (set)"; notice_lang(Config.s_NickServ, u, NICK_SET_PASSWORD_FAILED); return MOD_CONT; } - std::string tmp_pass; + Anope::string tmp_pass; if (enc_decrypt(u->Account()->pass, tmp_pass) == 1) notice_lang(Config.s_NickServ, u, NICK_SET_PASSWORD_CHANGED_TO, tmp_pass.c_str()); else notice_lang(Config.s_NickServ, u, NICK_SET_PASSWORD_CHANGED); - Alog() << Config.s_NickServ << ": " << u->GetMask() << " (e-mail: " << (u->Account()->email ? u->Account()->email : "none") << ") changed its password."; + Alog() << Config.s_NickServ << ": " << u->GetMask() << " (e-mail: " << (!u->Account()->email.empty() ? u->Account()->email : "none") << ") changed its password."; return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SET_PASSWORD); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { // XXX syntax_error(Config.s_NickServ, u, "SET", NICK_SET_SYNTAX); @@ -214,7 +215,7 @@ class CommandNSSetPassword : public Command class NSSet : public Module { public: - NSSet(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_set_autoop.cpp b/modules/core/ns_set_autoop.cpp index 93e637f97..2c8c8b1c4 100644 --- a/modules/core/ns_set_autoop.cpp +++ b/modules/core/ns_set_autoop.cpp @@ -16,18 +16,18 @@ class CommandNSSetAutoOp : public Command { public: - CommandNSSetAutoOp(const ci::string &cname) : Command(cname, 2) + CommandNSSetAutoOp(const Anope::string &cname) : Command(cname, 2) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - if (params[0] == "ON") + if (params[0].equals_ci("ON")) { u->Account()->SetFlag(NI_AUTOOP); notice_lang(Config.s_NickServ, u, NICK_SET_AUTOOP_ON); } - else if (params[0] == "OFF") + else if (params[0].equals_ci("OFF")) { u->Account()->UnsetFlag(NI_AUTOOP); notice_lang(Config.s_NickServ, u, NICK_SET_AUTOOP_OFF); @@ -38,13 +38,13 @@ class CommandNSSetAutoOp : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SET_AUTOOP); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SET AUTOOP", NICK_SET_AUTOOP_SYNTAX); } @@ -58,26 +58,26 @@ class CommandNSSetAutoOp : public Command class CommandNSSASetAutoOp : public Command { public: - CommandNSSASetAutoOp(const ci::string &cname) : Command(cname, 2, 2, "nickserv/saset/autoop") + CommandNSSASetAutoOp(const Anope::string &cname) : Command(cname, 2, 2, "nickserv/saset/autoop") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); assert(nc); - ci::string param = params[1]; + Anope::string param = params[1]; - if (param == "ON") + if (param.equals_ci("ON")) { nc->SetFlag(NI_AUTOOP); - notice_lang(Config.s_NickServ, u, NICK_SASET_AUTOOP_ON, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_AUTOOP_ON, nc->display.c_str()); } - else if (param == "OFF") + else if (param.equals_ci("OFF")) { nc->UnsetFlag(NI_AUTOOP); - notice_lang(Config.s_NickServ, u, NICK_SASET_AUTOOP_OFF, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_AUTOOP_OFF, nc->display.c_str()); } else this->OnSyntaxError(u, "AUTOOP"); @@ -85,13 +85,13 @@ class CommandNSSASetAutoOp : public Command return MOD_CONT; } - bool Help(User *u, const ci::string &) + bool Help(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_AUTOOP); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SET AUTOOP", NICK_SASET_AUTOOP_SYNTAX); } @@ -105,23 +105,29 @@ class CommandNSSASetAutoOp : public Command class NSSetAutoOp : public Module { public: - NSSetAutoOp(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSetAutoOp(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); - Command *set = FindCommand(NickServ, "SET"); + Command *c = FindCommand(NickServ, "SET"); + if (c) + c->AddSubcommand(new CommandNSSetAutoOp("AUTOOP")); - if (set) - set->AddSubcommand(new CommandNSSetAutoOp("AUTOOP")); + c = FindCommand(NickServ, "SASET"); + if (c) + c->AddSubcommand(new CommandNSSASetAutoOp("AUTOOP")); } ~NSSetAutoOp() { - Command *set = FindCommand(NickServ, "SET"); + Command *c = FindCommand(NickServ, "SET"); + if (c) + c->DelSubcommand("AUTOOP"); - if (set) - set->DelSubcommand("AUTOOP"); + c = FindCommand(NickServ, "SASET"); + if (c) + c->DelSubcommand("AUTOOP"); } }; diff --git a/modules/core/ns_set_email.cpp b/modules/core/ns_set_email.cpp index 6d3e60ecb..bf3162611 100644 --- a/modules/core/ns_set_email.cpp +++ b/modules/core/ns_set_email.cpp @@ -16,43 +16,40 @@ class CommandNSSetEmail : public Command { public: - CommandNSSetEmail(const ci::string &cname) : Command(cname, 0) + CommandNSSetEmail(const Anope::string &cname) : Command(cname, 0) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { if (params.empty() && Config.NSForceEmail) { notice_lang(Config.s_NickServ, u, NICK_SET_EMAIL_UNSET_IMPOSSIBLE); return MOD_CONT; } - else if (!params.empty() && !MailValidate(params[0].c_str())) + else if (!params.empty() && !MailValidate(params[0])) { notice_lang(Config.s_NickServ, u, MAIL_X_INVALID, params[0].c_str()); return MOD_CONT; } - Alog() << Config.s_NickServ << ": " << u->GetMask() << " (e-mail: " << (u->Account()->email ? u->Account()->email : "none") << ") changed its e-mail to " << (!params.empty() ? params[0] : "none"); - - if (u->Account()->email) - delete [] u->Account()->email; + Alog() << Config.s_NickServ << ": " << u->GetMask() << " (e-mail: " << (!u->Account()->email.empty() ? u->Account()->email : "none") << ") changed its e-mail to " << (!params.empty() ? params[0] : "none"); if (!params.empty()) { - u->Account()->email = sstrdup(params[0].c_str()); + u->Account()->email = params[0]; notice_lang(Config.s_NickServ, u, NICK_SET_EMAIL_CHANGED, params[0].c_str()); } else { - u->Account()->email = NULL; + u->Account()->email.clear(); notice_lang(Config.s_NickServ, u, NICK_SET_EMAIL_UNSET); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SET_EMAIL); return true; @@ -67,18 +64,18 @@ class CommandNSSetEmail : public Command class CommandNSSASetEmail : public Command { public: - CommandNSSASetEmail(const ci::string &cname) : Command(cname, 1, 2, "nickserv/saset/email") + CommandNSSASetEmail(const Anope::string &cname) : Command(cname, 1, 2, "nickserv/saset/email") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); assert(nc); - const char *param = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string param = params.size() > 1 ? params[1] : ""; - if (!param && Config.NSForceEmail) + if (param.empty() && Config.NSForceEmail) { notice_lang(Config.s_NickServ, u, NICK_SASET_EMAIL_UNSET_IMPOSSIBLE); return MOD_CONT; @@ -88,32 +85,29 @@ class CommandNSSASetEmail : public Command notice_lang(Config.s_NickServ, u, ACCESS_DENIED); return MOD_CONT; } - else if (param && !MailValidate(param)) + else if (!param.empty() && !MailValidate(param)) { - notice_lang(Config.s_NickServ, u, MAIL_X_INVALID, param); + notice_lang(Config.s_NickServ, u, MAIL_X_INVALID, param.c_str()); return MOD_CONT; } - Alog() << Config.s_NickServ << ": " << u->GetMask() << " used SASET EMAIL on " << nc->display << " (e-mail: " << (nc->email ? nc->email : "none") << ")"; - - if (nc->email) - delete [] nc->email; + Alog() << Config.s_NickServ << ": " << u->GetMask() << " used SASET EMAIL on " << nc->display << " (e-mail: " << (!nc->email.empty() ? nc->email : "none") << ")"; - if (param) + if (!param.empty()) { - nc->email = sstrdup(param); - notice_lang(Config.s_NickServ, u, NICK_SASET_EMAIL_CHANGED, nc->display, param); + nc->email = param; + notice_lang(Config.s_NickServ, u, NICK_SASET_EMAIL_CHANGED, nc->display.c_str(), param.c_str()); } else { - nc->email = NULL; - notice_lang(Config.s_NickServ, u, NICK_SASET_EMAIL_UNSET, nc->display); + nc->email.clear(); + notice_lang(Config.s_NickServ, u, NICK_SASET_EMAIL_UNSET, nc->display.c_str()); } return MOD_CONT; } - bool OnHelp(User *u) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_EMAIL); return true; @@ -128,7 +122,7 @@ class CommandNSSASetEmail : public Command class NSSetEmail : public Module { public: - NSSetEmail(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSetEmail(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_set_greet.cpp b/modules/core/ns_set_greet.cpp index c33b90991..128257924 100644 --- a/modules/core/ns_set_greet.cpp +++ b/modules/core/ns_set_greet.cpp @@ -16,30 +16,27 @@ class CommandNSSetGreet : public Command { public: - CommandNSSetGreet(const ci::string &cname) : Command(cname, 0) + CommandNSSetGreet(const Anope::string &cname) : Command(cname, 0) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - if (u->Account()->greet) - delete [] u->Account()->greet; - if (!params.empty()) { - u->Account()->greet = sstrdup(params[0].c_str()); - notice_lang(Config.s_NickServ, u, NICK_SET_GREET_CHANGED, u->Account()->greet); + u->Account()->greet = params[0]; + notice_lang(Config.s_NickServ, u, NICK_SET_GREET_CHANGED, u->Account()->greet.c_str()); } else { - u->Account()->greet = NULL; + u->Account()->greet.clear(); notice_lang(Config.s_NickServ, u, NICK_SET_GREET_UNSET); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SET_GREET); return true; @@ -54,35 +51,32 @@ class CommandNSSetGreet : public Command class CommandNSSASetGreet : public Command { public: - CommandNSSASetGreet(const ci::string &cname) : Command(cname, 1, 2, "nickserv/saset/greet") + CommandNSSASetGreet(const Anope::string &cname) : Command(cname, 1, 2, "nickserv/saset/greet") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); assert(nc); - const char *param = params.size() > 1 ? params[1].c_str() : NULL; - - if (nc->greet) - delete [] nc->greet; + Anope::string param = params.size() > 1 ? params[1] : ""; - if (param) + if (!param.empty()) { - nc->greet = sstrdup(param); - notice_lang(Config.s_NickServ, u, NICK_SASET_GREET_CHANGED, nc->display, nc->greet); + nc->greet = param; + notice_lang(Config.s_NickServ, u, NICK_SASET_GREET_CHANGED, nc->display.c_str(), nc->greet.c_str()); } else { - nc->greet = NULL; - notice_lang(Config.s_NickServ, u, NICK_SASET_GREET_UNSET, nc->display); + nc->greet.clear(); + notice_lang(Config.s_NickServ, u, NICK_SASET_GREET_UNSET, nc->display.c_str()); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_GREET); return true; @@ -97,10 +91,9 @@ class CommandNSSASetGreet : public Command class NSSetGreet : public Module { public: - NSSetGreet(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSetGreet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); - this->SetVersion("$Id$"); this->SetType(CORE); Command *c = FindCommand(NickServ, "SET"); diff --git a/modules/core/ns_set_hide.cpp b/modules/core/ns_set_hide.cpp index 160b0f0fd..5eaa1f39c 100644 --- a/modules/core/ns_set_hide.cpp +++ b/modules/core/ns_set_hide.cpp @@ -16,34 +16,34 @@ class CommandNSSetHide : public Command { public: - CommandNSSetHide(const ci::string &cname) : Command(cname, 2) + CommandNSSetHide(const Anope::string &cname) : Command(cname, 2) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { int onmsg, offmsg; NickCoreFlag flag; - if (params[0] == "EMAIL") + if (params[0].equals_ci("EMAIL")) { flag = NI_HIDE_EMAIL; onmsg = NICK_SET_HIDE_EMAIL_ON; offmsg = NICK_SET_HIDE_EMAIL_OFF; } - else if (params[0] == "USERMASK") + else if (params[0].equals_ci("USERMASK")) { flag = NI_HIDE_MASK; onmsg = NICK_SET_HIDE_MASK_ON; offmsg = NICK_SET_HIDE_MASK_OFF; } - else if (params[0] == "STATUS") + else if (params[0].equals_ci("STATUS")) { flag = NI_HIDE_STATUS; onmsg = NICK_SET_HIDE_STATUS_ON; offmsg = NICK_SET_HIDE_STATUS_OFF; } - else if (params[0] == "QUIT") + else if (params[0].equals_ci("QUIT")) { flag = NI_HIDE_QUIT; onmsg = NICK_SET_HIDE_QUIT_ON; @@ -55,15 +55,15 @@ class CommandNSSetHide : public Command return MOD_CONT; } - if (params[1] == "ON") + if (params[1].equals_ci("ON")) { u->Account()->SetFlag(flag); - notice_lang(Config.s_NickServ, u, onmsg, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, onmsg, Config.s_NickServ.c_str()); } - else if (params[1] == "OFF") + else if (params[1].equals_ci("OFF")) { u->Account()->UnsetFlag(flag); - notice_lang(Config.s_NickServ, u, offmsg, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, offmsg, Config.s_NickServ.c_str()); } else this->OnSyntaxError(u, "HIDE"); @@ -71,13 +71,13 @@ class CommandNSSetHide : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SET_HIDE); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SET HIDE", NICK_SET_HIDE_SYNTAX); } @@ -91,39 +91,39 @@ class CommandNSSetHide : public Command class CommandNSSASetHide : public Command { public: - CommandNSSASetHide(const ci::string &cname) : Command(cname, 3, 3, "nickserv/saset/command") + CommandNSSASetHide(const Anope::string &cname) : Command(cname, 3, 3, "nickserv/saset/command") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); assert(nc); - ci::string param = params[1]; + Anope::string param = params[1]; int onmsg, offmsg; NickCoreFlag flag; - if (param == "EMAIL") + if (param.equals_ci("EMAIL")) { flag = NI_HIDE_EMAIL; onmsg = NICK_SASET_HIDE_EMAIL_ON; offmsg = NICK_SASET_HIDE_EMAIL_OFF; } - else if (param == "USERMASK") + else if (param.equals_ci("USERMASK")) { flag = NI_HIDE_MASK; onmsg = NICK_SASET_HIDE_MASK_ON; offmsg = NICK_SASET_HIDE_MASK_OFF; } - else if (param == "STATUS") + else if (param.equals_ci("STATUS")) { flag = NI_HIDE_STATUS; onmsg = NICK_SASET_HIDE_STATUS_ON; offmsg = NICK_SASET_HIDE_STATUS_OFF; } - else if (param == "QUIT") + else if (param.equals_ci("QUIT")) { flag = NI_HIDE_QUIT; onmsg = NICK_SASET_HIDE_QUIT_ON; @@ -138,15 +138,15 @@ class CommandNSSASetHide : public Command param = params[2]; if (param.empty()) this->OnSyntaxError(u, "HIDE"); - else if (param == "ON") + else if (param.equals_ci("ON")) { nc->SetFlag(flag); - notice_lang(Config.s_NickServ, u, onmsg, nc->display, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, onmsg, nc->display.c_str(), Config.s_NickServ.c_str()); } - else if (param == "OFF") + else if (param.equals_ci("OFF")) { nc->UnsetFlag(flag); - notice_lang(Config.s_NickServ, u, offmsg, nc->display, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, offmsg, nc->display.c_str(), Config.s_NickServ.c_str()); } else this->OnSyntaxError(u, "HIDE"); @@ -154,13 +154,13 @@ class CommandNSSASetHide : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_HIDE); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SASET HIDE", NICK_SASET_HIDE_SYNTAX); } @@ -174,23 +174,29 @@ class CommandNSSASetHide : public Command class NSSetHide : public Module { public: - NSSetHide(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSetHide(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); - Command *set = FindCommand(NickServ, "SET"); + Command *c = FindCommand(NickServ, "SET"); + if (c) + c->AddSubcommand(new CommandNSSetHide("HIDE")); - if (set) - set->AddSubcommand(new CommandNSSetHide("HIDE")); + c = FindCommand(NickServ, "SASET"); + if (c) + c->AddSubcommand(new CommandNSSASetHide("HIDE")); } ~NSSetHide() { - Command *set = FindCommand(NickServ, "SET"); + Command *c = FindCommand(NickServ, "SET"); + if (c) + c->DelSubcommand("HIDE"); - if (set) - set->DelSubcommand("HIDE"); + c = FindCommand(NickServ, "SASET"); + if (c) + c->DelSubcommand("HIDE"); } }; diff --git a/modules/core/ns_set_kill.cpp b/modules/core/ns_set_kill.cpp index f996fdb5b..f7312710f 100644 --- a/modules/core/ns_set_kill.cpp +++ b/modules/core/ns_set_kill.cpp @@ -16,27 +16,27 @@ class CommandNSSetKill : public Command { public: - CommandNSSetKill(const ci::string &cname) : Command(cname, 1) + CommandNSSetKill(const Anope::string &cname) : Command(cname, 1) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - if (params[0] == "ON") + if (params[0].equals_ci("ON")) { u->Account()->SetFlag(NI_KILLPROTECT); u->Account()->UnsetFlag(NI_KILL_QUICK); u->Account()->UnsetFlag(NI_KILL_IMMED); notice_lang(Config.s_NickServ, u, NICK_SET_KILL_ON); } - else if (params[0] == "QUICK") + else if (params[0].equals_ci("QUICK")) { u->Account()->SetFlag(NI_KILLPROTECT); u->Account()->SetFlag(NI_KILL_QUICK); u->Account()->UnsetFlag(NI_KILL_IMMED); notice_lang(Config.s_NickServ, u, NICK_SET_KILL_QUICK); } - else if (params[0] == "IMMED") + else if (params[0].equals_ci("IMMED")) { if (Config.NSAllowKillImmed) { @@ -48,7 +48,7 @@ class CommandNSSetKill : public Command else notice_lang(Config.s_NickServ, u, NICK_SET_KILL_IMMED_DISABLED); } - else if (params[0] == "OFF") + else if (params[0].equals_ci("OFF")) { u->Account()->UnsetFlag(NI_KILLPROTECT); u->Account()->UnsetFlag(NI_KILL_QUICK); @@ -61,13 +61,13 @@ class CommandNSSetKill : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SET_KILL); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SET KILL", Config.NSAllowKillImmed ? NICK_SET_KILL_IMMED_SYNTAX : NICK_SET_KILL_SYNTAX); } @@ -81,49 +81,49 @@ class CommandNSSetKill : public Command class CommandNSSASetKill : public Command { public: - CommandNSSASetKill(const ci::string &cname) : Command(cname, 2, 2, "nickserv/saset/kill") + CommandNSSASetKill(const Anope::string &cname) : Command(cname, 2, 2, "nickserv/saset/kill") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); assert(nc); - ci::string param = params[1]; + Anope::string param = params[1]; - if (param == "ON") + if (param.equals_ci("ON")) { nc->SetFlag(NI_KILLPROTECT); nc->UnsetFlag(NI_KILL_QUICK); nc->UnsetFlag(NI_KILL_IMMED); - notice_lang(Config.s_NickServ, u, NICK_SASET_KILL_ON, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_KILL_ON, nc->display.c_str()); } - else if (param == "QUICK") + else if (param.equals_ci("QUICK")) { nc->SetFlag(NI_KILLPROTECT); nc->SetFlag(NI_KILL_QUICK); nc->UnsetFlag(NI_KILL_IMMED); - notice_lang(Config.s_NickServ, u, NICK_SASET_KILL_QUICK, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_KILL_QUICK, nc->display.c_str()); } - else if (param == "IMMED") + else if (param.equals_ci("IMMED")) { if (Config.NSAllowKillImmed) { nc->SetFlag(NI_KILLPROTECT); nc->SetFlag(NI_KILL_IMMED); nc->UnsetFlag(NI_KILL_QUICK); - notice_lang(Config.s_NickServ, u, NICK_SASET_KILL_IMMED, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_KILL_IMMED, nc->display.c_str()); } else notice_lang(Config.s_NickServ, u, NICK_SASET_KILL_IMMED_DISABLED); } - else if (param == "OFF") + else if (param.equals_ci("OFF")) { nc->UnsetFlag(NI_KILLPROTECT); nc->UnsetFlag(NI_KILL_QUICK); nc->UnsetFlag(NI_KILL_IMMED); - notice_lang(Config.s_NickServ, u, NICK_SASET_KILL_OFF, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_KILL_OFF, nc->display.c_str()); } else this->OnSyntaxError(u, "KILL"); @@ -131,13 +131,13 @@ class CommandNSSASetKill : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_KILL); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SASET KILL", Config.NSAllowKillImmed ? NICK_SASET_KILL_IMMED_SYNTAX : NICK_SASET_KILL_SYNTAX); } @@ -151,7 +151,7 @@ class CommandNSSASetKill : public Command class NSSetKill : public Module { public: - NSSetKill(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSetKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_set_language.cpp b/modules/core/ns_set_language.cpp index 00d4f5864..06f29ae48 100644 --- a/modules/core/ns_set_language.cpp +++ b/modules/core/ns_set_language.cpp @@ -16,24 +16,24 @@ class CommandNSSetLanguage : public Command { public: - CommandNSSetLanguage(const ci::string &cname) : Command(cname, 1) + CommandNSSetLanguage(const Anope::string &cname) : Command(cname, 1) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *param = params[0].c_str(); + Anope::string param = params[0]; - if (param[strspn(param, "0123456789")]) /* i.e. not a number */ + if (param.find_first_not_of("0123456789") != Anope::string::npos) /* i.e. not a number */ { this->OnSyntaxError(u, ""); return MOD_CONT; } - int langnum = atoi(param) - 1; + int langnum = convertTo<int>(param) - 1; if (langnum < 0 || langnum >= NUM_LANGS || langlist[langnum] < 0) { - notice_lang(Config.s_NickServ, u, NICK_SET_LANGUAGE_UNKNOWN, langnum + 1, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, NICK_SET_LANGUAGE_UNKNOWN, langnum + 1, Config.s_NickServ.c_str()); return MOD_CONT; } @@ -43,13 +43,13 @@ class CommandNSSetLanguage : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SET_LANGUAGE); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SET LANGUAGE", NICK_SET_LANGUAGE_SYNTAX); } @@ -63,26 +63,26 @@ class CommandNSSetLanguage : public Command class CommandNSSASetLanguage : public Command { public: - CommandNSSASetLanguage(const ci::string &cname) : Command(cname, 2, 2, "nickserv/saset/language") + CommandNSSASetLanguage(const Anope::string &cname) : Command(cname, 2, 2, "nickserv/saset/language") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); assert(nc); - const char *param = params[1].c_str(); + Anope::string param = params[1]; - if (param[strspn(param, "0123456789")]) /* i.e. not a number */ + if (param.find_first_not_of("0123456789") != Anope::string::npos) /* i.e. not a number */ { this->OnSyntaxError(u, "LANGUAGE"); return MOD_CONT; } - int langnum = atoi(param) - 1; + int langnum = convertTo<int>(param) - 1; if (langnum < 0 || langnum >= NUM_LANGS || langlist[langnum] < 0) { - notice_lang(Config.s_NickServ, u, NICK_SASET_LANGUAGE_UNKNOWN, langnum + 1, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, NICK_SASET_LANGUAGE_UNKNOWN, langnum + 1, Config.s_NickServ.c_str()); return MOD_CONT; } nc->language = langlist[langnum]; @@ -91,13 +91,13 @@ class CommandNSSASetLanguage : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_LANGUAGE); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SASET LANGUAGE", NICK_SASET_LANGUAGE_SYNTAX); } @@ -111,7 +111,7 @@ class CommandNSSASetLanguage : public Command class NSSetLanguage : public Module { public: - NSSetLanguage(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSetLanguage(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_set_message.cpp b/modules/core/ns_set_message.cpp index 600872c01..25ad660d7 100644 --- a/modules/core/ns_set_message.cpp +++ b/modules/core/ns_set_message.cpp @@ -16,11 +16,11 @@ class CommandNSSetMessage : public Command { public: - CommandNSSetMessage(const ci::string &cname) : Command(cname, 1) + CommandNSSetMessage(const Anope::string &cname) : Command(cname, 1) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { if (!Config.UsePrivmsg) { @@ -28,12 +28,12 @@ class CommandNSSetMessage : public Command return MOD_CONT; } - if (params[0] == "ON") + if (params[0].equals_ci("ON")) { u->Account()->SetFlag(NI_MSG); notice_lang(Config.s_NickServ, u, NICK_SET_MSG_ON); } - else if (params[0] == "OFF") + else if (params[0].equals_ci("OFF")) { u->Account()->UnsetFlag(NI_MSG); notice_lang(Config.s_NickServ, u, NICK_SET_MSG_OFF); @@ -44,13 +44,13 @@ class CommandNSSetMessage : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SET_MSG); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SET MSG", NICK_SET_MSG_SYNTAX); } @@ -64,16 +64,16 @@ class CommandNSSetMessage : public Command class CommandNSSASetMessage : public Command { public: - CommandNSSASetMessage(const ci::string &cname) : Command(cname, 2, 2, "nickserv/saset/message") + CommandNSSASetMessage(const Anope::string &cname) : Command(cname, 2, 2, "nickserv/saset/message") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); assert(nc); - ci::string param = params[1]; + Anope::string param = params[1]; if (!Config.UsePrivmsg) { @@ -81,15 +81,15 @@ class CommandNSSASetMessage : public Command return MOD_CONT; } - if (param == "ON") + if (param.equals_ci("ON")) { nc->SetFlag(NI_MSG); - notice_lang(Config.s_NickServ, u, NICK_SASET_MSG_ON, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_MSG_ON, nc->display.c_str()); } - else if (param == "OFF") + else if (param.equals_ci("OFF")) { nc->UnsetFlag(NI_MSG); - notice_lang(Config.s_NickServ, u, NICK_SASET_MSG_OFF, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_MSG_OFF, nc->display.c_str()); } else this->OnSyntaxError(u, "MSG"); @@ -97,13 +97,13 @@ class CommandNSSASetMessage : public Command return MOD_CONT; } - bool OnHelp(User *u) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_MSG); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SASET MSG", NICK_SASET_MSG_SYNTAX); } @@ -117,7 +117,7 @@ class CommandNSSASetMessage : public Command class NSSetMessage : public Module { public: - NSSetMessage(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSetMessage(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_set_private.cpp b/modules/core/ns_set_private.cpp index da18a8b44..5e8aff432 100644 --- a/modules/core/ns_set_private.cpp +++ b/modules/core/ns_set_private.cpp @@ -16,18 +16,18 @@ class CommandNSSetPrivate : public Command { public: - CommandNSSetPrivate(const ci::string &cname) : Command(cname, 1) + CommandNSSetPrivate(const Anope::string &cname) : Command(cname, 1) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - if (params[0] == "ON") + if (params[0].equals_ci("ON")) { u->Account()->SetFlag(NI_PRIVATE); notice_lang(Config.s_NickServ, u, NICK_SET_PRIVATE_ON); } - else if (params[0] == "OFF") + else if (params[0].equals_ci("OFF")) { u->Account()->UnsetFlag(NI_PRIVATE); notice_lang(Config.s_NickServ, u, NICK_SET_PRIVATE_OFF); @@ -38,13 +38,13 @@ class CommandNSSetPrivate : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SET_PRIVATE); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SET PRIVATE", NICK_SET_PRIVATE_SYNTAX); } @@ -58,26 +58,26 @@ class CommandNSSetPrivate : public Command class CommandNSSASetPrivate : public Command { public: - CommandNSSASetPrivate(const ci::string &cname) : Command(cname, 2, 2, "nickserv/saset/private") + CommandNSSASetPrivate(const Anope::string &cname) : Command(cname, 2, 2, "nickserv/saset/private") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); assert(nc); - ci::string param = params[1]; + Anope::string param = params[1]; - if (param == "ON") + if (param.equals_ci("ON")) { nc->SetFlag(NI_PRIVATE); - notice_lang(Config.s_NickServ, u, NICK_SASET_PRIVATE_ON, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_PRIVATE_ON, nc->display.c_str()); } - else if (param == "OFF") + else if (param.equals_ci("OFF")) { nc->UnsetFlag(NI_PRIVATE); - notice_lang(Config.s_NickServ, u, NICK_SASET_PRIVATE_OFF, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_PRIVATE_OFF, nc->display.c_str()); } else this->OnSyntaxError(u, "PRIVATE"); @@ -85,13 +85,13 @@ class CommandNSSASetPrivate : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_PRIVATE); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SASET PRIVATE", NICK_SASET_PRIVATE_SYNTAX); } @@ -105,7 +105,7 @@ class CommandNSSASetPrivate : public Command class NSSetPrivate : public Module { public: - NSSetPrivate(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSetPrivate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_set_secure.cpp b/modules/core/ns_set_secure.cpp index ce627d9d4..66990f423 100644 --- a/modules/core/ns_set_secure.cpp +++ b/modules/core/ns_set_secure.cpp @@ -16,18 +16,18 @@ class CommandNSSetSecure : public Command { public: - CommandNSSetSecure(const ci::string &cname) : Command(cname, 1) + CommandNSSetSecure(const Anope::string &cname) : Command(cname, 1) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - if (params[0] == "ON") + if (params[0].equals_ci("ON")) { u->Account()->SetFlag(NI_SECURE); notice_lang(Config.s_NickServ, u, NICK_SET_SECURE_ON); } - else if (params[0] == "OFF") + else if (params[0].equals_ci("OFF")) { u->Account()->UnsetFlag(NI_SECURE); notice_lang(Config.s_NickServ, u, NICK_SET_SECURE_OFF); @@ -38,13 +38,13 @@ class CommandNSSetSecure : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SET_SECURE); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SET SECURE", NICK_SET_SECURE_SYNTAX); } @@ -58,26 +58,26 @@ class CommandNSSetSecure : public Command class CommandNSSASetSecure : public Command { public: - CommandNSSASetSecure(const ci::string &cname) : Command(cname, 2, 2, "nickserv/saset/secure") + CommandNSSASetSecure(const Anope::string &cname) : Command(cname, 2, 2, "nickserv/saset/secure") { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); assert(nc); - ci::string param = params[1]; + Anope::string param = params[1]; - if (param == "ON") + if (param.equals_ci("ON")) { nc->SetFlag(NI_SECURE); - notice_lang(Config.s_NickServ, u, NICK_SASET_SECURE_ON, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_SECURE_ON, nc->display.c_str()); } - else if (param == "OFF") + else if (param.equals_ci("OFF")) { nc->UnsetFlag(NI_SECURE); - notice_lang(Config.s_NickServ, u, NICK_SASET_SECURE_OFF, nc->display); + notice_lang(Config.s_NickServ, u, NICK_SASET_SECURE_OFF, nc->display.c_str()); } else this->OnSyntaxError(u, "SECURE"); @@ -85,13 +85,13 @@ class CommandNSSASetSecure : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_SASET_SECURE); return true; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SASET SECURE", NICK_SASET_SECURE_SYNTAX); } @@ -105,7 +105,7 @@ class CommandNSSASetSecure : public Command class NSSetSecure : public Module { public: - NSSetSecure(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSetSecure(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_status.cpp b/modules/core/ns_status.cpp index a213db474..074d80c23 100644 --- a/modules/core/ns_status.cpp +++ b/modules/core/ns_status.cpp @@ -21,36 +21,34 @@ class CommandNSStatus : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { User *u2; - NickAlias *na = NULL; - std::string nick = params.size() ? params[0].c_str() : u->nick; + Anope::string nick = !params.empty() ? params[0] : u->nick; + NickAlias *na = findnick(nick); spacesepstream sep(nick); - std::string nickbuf; + Anope::string nickbuf; while (sep.GetToken(nickbuf)) { - na = findnick(nick); - if (!(u2 = finduser(nickbuf))) /* Nick is not online */ notice_lang(Config.s_NickServ, u, NICK_STATUS_REPLY, nickbuf.c_str(), 0, ""); else if (u2->IsIdentified() && na && na->nc == u2->Account()) /* Nick is identified */ - notice_lang(Config.s_NickServ, u, NICK_STATUS_REPLY, nickbuf.c_str(), 3, u2->Account()->display); + notice_lang(Config.s_NickServ, u, NICK_STATUS_REPLY, nickbuf.c_str(), 3, u2->Account()->display.c_str()); else if (u2->IsRecognized()) /* Nick is recognised, but NOT identified */ - notice_lang(Config.s_NickServ, u, NICK_STATUS_REPLY, nickbuf.c_str(), 2, (u2->Account() ? u2->Account()->display : "")); + notice_lang(Config.s_NickServ, u, NICK_STATUS_REPLY, nickbuf.c_str(), 2, u2->Account() ? u2->Account()->display.c_str() : ""); else if (!na) /* Nick is online, but NOT a registered */ notice_lang(Config.s_NickServ, u, NICK_STATUS_REPLY, nickbuf.c_str(), 0, ""); else /* Nick is not identified for the nick, but they could be logged into an account, * so we tell the user about it */ - notice_lang(Config.s_NickServ, u, NICK_STATUS_REPLY, nickbuf.c_str(), 1, (u2->Account() ? u2->Account()->display : "")); + notice_lang(Config.s_NickServ, u, NICK_STATUS_REPLY, nickbuf.c_str(), 1, u2->Account() ? u2->Account()->display.c_str() : ""); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_HELP_STATUS); return true; @@ -65,7 +63,7 @@ class CommandNSStatus : public Command class NSStatus : public Module { public: - NSStatus(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSStatus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_suspend.cpp b/modules/core/ns_suspend.cpp index 6564ca9f8..375349fba 100644 --- a/modules/core/ns_suspend.cpp +++ b/modules/core/ns_suspend.cpp @@ -20,12 +20,12 @@ class CommandNSSuspend : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na; User *u2; - const char *nick = params[0].c_str(); - const char *reason = params[1].c_str(); + Anope::string nick = params[0]; + Anope::string reason = params[1]; if (readonly) { @@ -35,13 +35,13 @@ class CommandNSSuspend : public Command if (!(na = findnick(nick))) { - notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); return MOD_CONT; } if (na->HasFlag(NS_FORBIDDEN)) { - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); return MOD_CONT; } @@ -51,55 +51,46 @@ class CommandNSSuspend : public Command return MOD_CONT; } - if (na) + na->nc->SetFlag(NI_SUSPENDED); + na->nc->SetFlag(NI_SECURE); + na->nc->UnsetFlag(NI_KILLPROTECT); + na->nc->UnsetFlag(NI_KILL_QUICK); + na->nc->UnsetFlag(NI_KILL_IMMED); + + for (std::list<NickAlias *>::iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end; ++it) { - na->nc->SetFlag(NI_SUSPENDED); - na->nc->SetFlag(NI_SECURE); - na->nc->UnsetFlag(NI_KILLPROTECT); - na->nc->UnsetFlag(NI_KILL_QUICK); - na->nc->UnsetFlag(NI_KILL_IMMED); + NickAlias *na2 = *it; - for (std::list<NickAlias *>::iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end; ++it) + if (na2->nc == na->nc) { - NickAlias *na2 = *it; + na2->last_quit = reason; - if (na2->nc == na->nc) + if ((u2 = finduser(na2->nick))) { - if (na2->last_quit) - delete [] na2->last_quit; - na2->last_quit = sstrdup(reason); - - if ((u2 = finduser(na2->nick))) - { - u2->Logout(); - u2->Collide(na2); - } + u2->Logout(); + u2->Collide(na2); } } + } - if (Config.WallForbid) - ircdproto->SendGlobops(NickServ, "\2%s\2 used SUSPEND on \2%s\2", u->nick.c_str(), nick); + if (Config.WallForbid) + ircdproto->SendGlobops(NickServ, "\2%s\2 used SUSPEND on \2%s\2", u->nick.c_str(), nick.c_str()); - Alog() << Config.s_NickServ << ": " << u->nick << " set SUSPEND for nick " << nick; - notice_lang(Config.s_NickServ, u, NICK_SUSPEND_SUCCEEDED, nick); + Alog() << Config.s_NickServ << ": " << u->nick << " set SUSPEND for nick " << nick; + notice_lang(Config.s_NickServ, u, NICK_SUSPEND_SUCCEEDED, nick.c_str()); + + FOREACH_MOD(I_OnNickSuspended, OnNickSuspend(na)); - FOREACH_MOD(I_OnNickSuspended, OnNickSuspend(na)); - } - else - { - Alog() << Config.s_NickServ << ": Valid SUSPEND for " << nick << " by " << u->nick << " failed"; - notice_lang(Config.s_NickServ, u, NICK_SUSPEND_FAILED, nick); - } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_SUSPEND); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "SUSPEND", NICK_SUSPEND_SYNTAX); } @@ -117,10 +108,10 @@ class CommandNSUnSuspend : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na; - const char *nick = params[0].c_str(); + Anope::string nick = params[0]; if (readonly) { @@ -130,13 +121,13 @@ class CommandNSUnSuspend : public Command if (!(na = findnick(nick))) { - notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); return MOD_CONT; } if (na->HasFlag(NS_FORBIDDEN)) { - notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick); + notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick.c_str()); return MOD_CONT; } @@ -146,33 +137,26 @@ class CommandNSUnSuspend : public Command return MOD_CONT; } - if (na) - { - na->nc->UnsetFlag(NI_SUSPENDED); + na->nc->UnsetFlag(NI_SUSPENDED); - if (Config.WallForbid) - ircdproto->SendGlobops(NickServ, "\2%s\2 used UNSUSPEND on \2%s\2", u->nick.c_str(), nick); + if (Config.WallForbid) + ircdproto->SendGlobops(NickServ, "\2%s\2 used UNSUSPEND on \2%s\2", u->nick.c_str(), nick.c_str()); - Alog() << Config.s_NickServ << ": " << u->nick << " set UNSUSPEND for nick " << nick; - notice_lang(Config.s_NickServ, u, NICK_UNSUSPEND_SUCCEEDED, nick); + Alog() << Config.s_NickServ << ": " << u->nick << " set UNSUSPEND for nick " << nick; + notice_lang(Config.s_NickServ, u, NICK_UNSUSPEND_SUCCEEDED, nick.c_str()); + + FOREACH_MOD(I_OnNickUnsuspended, OnNickUnsuspended(na)); - FOREACH_MOD(I_OnNickUnsuspended, OnNickUnsuspended(na)); - } - else - { - Alog() << Config.s_NickServ << ": Valid UNSUSPEND for " << nick << " by " << u->nick << " failed"; - notice_lang(Config.s_NickServ, u, NICK_UNSUSPEND_FAILED, nick); - } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_UNSUSPEND); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_NickServ, u, "UNSUSPEND", NICK_UNSUSPEND_SYNTAX); } @@ -186,7 +170,7 @@ class CommandNSUnSuspend : public Command class NSSuspend : public Module { public: - NSSuspend(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ns_update.cpp b/modules/core/ns_update.cpp index 7a2e287b8..7192932e1 100644 --- a/modules/core/ns_update.cpp +++ b/modules/core/ns_update.cpp @@ -20,7 +20,7 @@ class CommandNSUpdate : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na = findnick(u->nick); @@ -30,17 +30,15 @@ class CommandNSUpdate : public Command do_setmodes(u); check_memos(u); - if (na->last_realname) - delete [] na->last_realname; - na->last_realname = sstrdup(u->realname); + na->last_realname = u->realname; na->last_seen = time(NULL); if (ircd->vhost) do_on_id(u); - notice_lang(Config.s_NickServ, u, NICK_UPDATE_SUCCESS, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, NICK_UPDATE_SUCCESS, Config.s_NickServ.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &) + bool OnHelp(User *u, const Anope::string &) { notice_help(Config.s_NickServ, u, NICK_HELP_UPDATE); return true; @@ -55,7 +53,7 @@ class CommandNSUpdate : public Command class NSUpdate : public Module { public: - NSUpdate(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_akill.cpp b/modules/core/os_akill.cpp index f572ec123..44ba85cfb 100644 --- a/modules/core/os_akill.cpp +++ b/modules/core/os_akill.cpp @@ -18,7 +18,7 @@ class AkillDelCallback : public NumberList User *u; unsigned Deleted; public: - AkillDelCallback(User *_u, const std::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) + AkillDelCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) { } @@ -55,7 +55,7 @@ class AkillListCallback : public NumberList User *u; bool SentHeader; public: - AkillListCallback(User *_u, const std::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) + AkillListCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) { } @@ -92,7 +92,7 @@ class AkillListCallback : public NumberList class AkillViewCallback : public AkillListCallback { public: - AkillViewCallback(User *_u, const std::string &numlist) : AkillListCallback(_u, numlist) + AkillViewCallback(User *_u, const Anope::string &numlist) : AkillListCallback(_u, numlist) { } @@ -114,45 +114,42 @@ class AkillViewCallback : public AkillListCallback static void DoList(User *u, XLine *x, unsigned Number) { - char timebuf[32], expirebuf[256]; + char timebuf[32]; struct tm tm; tm = *localtime(&x->Created); strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm); - expire_left(u->Account(), expirebuf, sizeof(expirebuf), x->Expires); + Anope::string expirebuf = expire_left(u->Account(), x->Expires); - notice_lang(Config.s_OperServ, u, OPER_AKILL_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, expirebuf, x->Reason.c_str()); + notice_lang(Config.s_OperServ, u, OPER_AKILL_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, expirebuf.c_str(), x->Reason.c_str()); } }; class CommandOSAKill : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) { unsigned last_param = 2; - const char *expiry, *mask; - char reason[BUFSIZE]; + Anope::string expiry, mask; time_t expires; - mask = params.size() > 1 ? params[1].c_str() : NULL; - if (mask && *mask == '+') + mask = params.size() > 1 ? params[1] : ""; + if (!mask.empty() && mask[0] == '+') { expiry = mask; - mask = params.size() > 2 ? params[2].c_str() : NULL; + mask = params.size() > 2 ? params[2] : ""; last_param = 3; } - else - expiry = NULL; - expires = expiry ? dotime(expiry) : Config.AutokillExpiry; + expires = !expiry.empty() ? dotime(expiry) : Config.AutokillExpiry; /* If the expiry given does not contain a final letter, it's in days, * said the doc. Ah well. */ - if (expiry && isdigit(expiry[strlen(expiry) - 1])) + if (!expiry.empty() && isdigit(expiry[expiry.length() - 1])) expires *= 86400; /* Do not allow less than a minute expiry time */ - if (expires != 0 && expires < 60) + if (expires && expires < 60) { notice_lang(Config.s_OperServ, u, BAD_EXPIRY_TIME); return MOD_CONT; @@ -165,26 +162,29 @@ class CommandOSAKill : public Command this->OnSyntaxError(u, "ADD"); return MOD_CONT; } - snprintf(reason, sizeof(reason), "%s%s%s", params[last_param].c_str(), last_param == 2 && params.size() > 3 ? " " : "", last_param == 2 && params.size() > 3 ? params[3].c_str() : ""); - if (mask && *reason) + + Anope::string reason = params[last_param]; + if (last_param == 2 && params.size() > 3) + reason += " " + params[3]; + if (!mask.empty() && !reason.empty()) { XLine *x = SGLine->Add(OperServ, u, mask, expires, reason); if (!x) return MOD_CONT; - notice_lang(Config.s_OperServ, u, OPER_AKILL_ADDED, mask); + notice_lang(Config.s_OperServ, u, OPER_AKILL_ADDED, mask.c_str()); if (Config.WallOSAkill) { - char buf[128]; + Anope::string buf; if (!expires) - strcpy(buf, "does not expire"); + buf = "does not expire"; else { int wall_expiry = expires - time(NULL); - const char *s = NULL; + Anope::string s; if (wall_expiry >= 86400) { @@ -202,10 +202,10 @@ class CommandOSAKill : public Command s = "minute"; } - snprintf(buf, sizeof(buf), "expires in %d %s%s", wall_expiry, s, wall_expiry == 1 ? "" : "s"); + buf = "expires in " + stringify(wall_expiry) + " " + s + (wall_expiry == 1 ? "" : "s"); } - ircdproto->SendGlobops(OperServ, "%s added an AKILL for %s (%s) (%s)", u->nick.c_str(), mask, reason, buf); + ircdproto->SendGlobops(OperServ, "%s added an AKILL for %s (%s) (%s)", u->nick.c_str(), mask.c_str(), reason.c_str(), buf.c_str()); } if (readonly) @@ -217,9 +217,9 @@ class CommandOSAKill : public Command return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) { - const ci::string mask = params.size() > 1 ? params[0] : ""; + Anope::string mask = params.size() > 1 ? params[0] : ""; if (mask.empty()) { @@ -233,9 +233,9 @@ class CommandOSAKill : public Command return MOD_CONT; } - if (isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkillDelCallback list(u, mask.c_str()); + AkillDelCallback list(u, mask); list.Process(); } else @@ -260,7 +260,7 @@ class CommandOSAKill : public Command return MOD_CONT; } - CommandReturn DoList(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoList(User *u, const std::vector<Anope::string> ¶ms) { if (SGLine->GetList().empty()) { @@ -268,11 +268,11 @@ class CommandOSAKill : public Command return MOD_CONT; } - const ci::string mask = params.size() > 1 ? params[1] : ""; + Anope::string mask = params.size() > 1 ? params[1] : ""; - if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkillListCallback list(u, mask.c_str()); + AkillListCallback list(u, mask); list.Process(); } else @@ -283,7 +283,7 @@ class CommandOSAKill : public Command { XLine *x = SGLine->GetEntry(i); - if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) + if (mask.empty() || mask.equals_ci(x->Mask) || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -304,7 +304,7 @@ class CommandOSAKill : public Command return MOD_CONT; } - CommandReturn DoView(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoView(User *u, const std::vector<Anope::string> ¶ms) { if (SGLine->GetList().empty()) { @@ -312,11 +312,11 @@ class CommandOSAKill : public Command return MOD_CONT; } - const ci::string mask = params.size() > 1 ? params[1] : ""; + Anope::string mask = params.size() > 1 ? params[1] : ""; - if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkillViewCallback list(u, mask.c_str()); + AkillViewCallback list(u, mask); list.Process(); } else @@ -327,7 +327,7 @@ class CommandOSAKill : public Command { XLine *x = SGLine->GetEntry(i); - if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) + if (mask.empty() || mask.equals_ci(x->Mask) || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -359,32 +359,32 @@ class CommandOSAKill : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; + Anope::string cmd = params[0]; - if (cmd == "ADD") + if (cmd.equals_ci("ADD")) return this->DoAdd(u, params); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) return this->DoDel(u, params); - else if (cmd == "LIST") + else if (cmd.equals_ci("LIST")) return this->DoList(u, params); - else if (cmd == "VIEW") + else if (cmd.equals_ci("VIEW")) return this->DoView(u, params); - else if (cmd == "CLEAR") + else if (cmd.equals_ci("CLEAR")) return this->DoClear(u); else this->OnSyntaxError(u, ""); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_AKILL); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "AKILL", OPER_AKILL_SYNTAX); } @@ -398,7 +398,7 @@ class CommandOSAKill : public Command class OSAKill : public Module { public: - OSAKill(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSAKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_chankill.cpp b/modules/core/os_chankill.cpp index f751d6dee..52eef6b1a 100644 --- a/modules/core/os_chankill.cpp +++ b/modules/core/os_chankill.cpp @@ -20,28 +20,25 @@ class CommandOSChanKill : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *expiry, *channel; - char reason[BUFSIZE]; + Anope::string expiry, channel; time_t expires; unsigned last_param = 1; Channel *c; - channel = params[0].c_str(); - if (channel && *channel == '+') + channel = params[0]; + if (!channel.empty() && channel[0] == '+') { expiry = channel; - channel = params[1].c_str(); + channel = params[1]; last_param = 2; } - else - expiry = NULL; - expires = expiry ? dotime(expiry) : Config.ChankillExpiry; - if (expiry && isdigit(expiry[strlen(expiry) - 1])) + expires = !expiry.empty() ? dotime(expiry) : Config.ChankillExpiry; + if (!expiry.empty() && isdigit(expiry[expiry.length() - 1])) expires *= 86400; - if (expires != 0 && expires < 60) + if (expires && expires < 60) { notice_lang(Config.s_OperServ, u, BAD_EXPIRY_TIME); return MOD_CONT; @@ -54,13 +51,15 @@ class CommandOSChanKill : public Command this->OnSyntaxError(u, ""); return MOD_CONT; } - snprintf(reason, sizeof(reason), "%s%s", params[last_param].c_str(), (params.size() > last_param + 1 ? params[last_param + 1].c_str() : "")); - if (*reason) - { - std::string realreason; + Anope::string reason = params[last_param]; + if (params.size() > last_param + 1) + reason += params[last_param + 1]; + if (!reason.empty()) + { + Anope::string realreason; if (Config.AddAkiller) - realreason = "[" + u->nick + "] " + std::string(reason); + realreason = "[" + u->nick + "] " + reason; else realreason = reason; @@ -73,25 +72,25 @@ class CommandOSChanKill : public Command if (is_oper(uc->user)) continue; - SGLine->Add(OperServ, u, ci::string("*@") + uc->user->host, expires, realreason); + SGLine->Add(OperServ, u, "*@" + uc->user->host, expires, realreason); SGLine->Check(uc->user); } if (Config.WallOSAkill) - ircdproto->SendGlobops(OperServ, "%s used CHANKILL on %s (%s)", u->nick.c_str(), channel, realreason.c_str()); + ircdproto->SendGlobops(OperServ, "%s used CHANKILL on %s (%s)", u->nick.c_str(), channel.c_str(), realreason.c_str()); } else - notice_lang(Config.s_OperServ, u, CHAN_X_NOT_IN_USE, channel); + notice_lang(Config.s_OperServ, u, CHAN_X_NOT_IN_USE, channel.c_str()); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_CHANKILL); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "CHANKILL", OPER_CHANKILL_SYNTAX); } @@ -105,7 +104,7 @@ class CommandOSChanKill : public Command class OSChanKill : public Module { public: - OSChanKill(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSChanKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_chanlist.cpp b/modules/core/os_chanlist.cpp index d1a154d2f..b8a4f7c83 100644 --- a/modules/core/os_chanlist.cpp +++ b/modules/core/os_chanlist.cpp @@ -20,20 +20,20 @@ class CommandOSChanList : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *pattern = params.size() > 0 ? params[0].c_str() : NULL; - ci::string opt = params.size() > 1 ? params[1] : ""; + Anope::string pattern = !params.empty() ? params[0] : ""; + Anope::string opt = params.size() > 1 ? params[1] : ""; std::list<ChannelModeName> Modes; User *u2; - if (!opt.empty() && opt == "SECRET") + if (!opt.empty() && opt.equals_ci("SECRET")) { Modes.push_back(CMODE_SECRET); Modes.push_back(CMODE_PRIVATE); } - if (pattern && (u2 = finduser(pattern))) + if (!pattern.empty() && (u2 = finduser(pattern))) { notice_lang(Config.s_OperServ, u, OPER_CHANLIST_HEADER_USER, u2->nick.c_str()); @@ -46,7 +46,7 @@ class CommandOSChanList : public Command if (!cc->chan->HasMode(*it)) continue; - notice_lang(Config.s_OperServ, u, OPER_CHANLIST_RECORD, cc->chan->name.c_str(), cc->chan->users.size(), chan_get_modes(cc->chan, 1, 1), cc->chan->topic ? cc->chan->topic : ""); + notice_lang(Config.s_OperServ, u, OPER_CHANLIST_RECORD, cc->chan->name.c_str(), cc->chan->users.size(), chan_get_modes(cc->chan, 1, 1).c_str(), !cc->chan->topic.empty() ? cc->chan->topic.c_str() : ""); } } else @@ -57,14 +57,14 @@ class CommandOSChanList : public Command { Channel *c = cit->second; - if (pattern && !Anope::Match(c->name, pattern, false)) + if (!pattern.empty() && !Anope::Match(c->name, pattern)) continue; if (!Modes.empty()) for (std::list<ChannelModeName>::iterator it = Modes.begin(), it_end = Modes.end(); it != it_end; ++it) if (!c->HasMode(*it)) continue; - notice_lang(Config.s_OperServ, u, OPER_CHANLIST_RECORD, c->name.c_str(), c->users.size(), chan_get_modes(c, 1, 1), c->topic ? c->topic : ""); + notice_lang(Config.s_OperServ, u, OPER_CHANLIST_RECORD, c->name.c_str(), c->users.size(), chan_get_modes(c, 1, 1).c_str(), !c->topic.empty() ? c->topic.c_str() : ""); } } @@ -72,7 +72,7 @@ class CommandOSChanList : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_CHANLIST); return true; @@ -87,7 +87,7 @@ class CommandOSChanList : public Command class OSChanList : public Module { public: - OSChanList(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSChanList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_clearmodes.cpp b/modules/core/os_clearmodes.cpp index 3c73846c4..c6f28c8e6 100644 --- a/modules/core/os_clearmodes.cpp +++ b/modules/core/os_clearmodes.cpp @@ -20,17 +20,17 @@ class CommandOSClearModes : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); + Anope::string chan = params[0]; Channel *c; int all = 0; ChannelMode *cm; - std::string buf; + Anope::string buf; if (!(c = findchan(chan))) { - notice_lang(Config.s_OperServ, u, CHAN_X_NOT_IN_USE, chan); + notice_lang(Config.s_OperServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); return MOD_CONT; } else if (c->bouncy_modes) @@ -40,10 +40,10 @@ class CommandOSClearModes : public Command } else { - ci::string s = params.size() > 1 ? params[1] : ""; + Anope::string s = params.size() > 1 ? params[1] : ""; if (!s.empty()) { - if (s == "ALL") + if (s.equals_ci("ALL")) all = 1; else { @@ -53,12 +53,12 @@ class CommandOSClearModes : public Command } if (Config.WallOSClearmodes) - ircdproto->SendGlobops(OperServ, "%s used CLEARMODES%s on %s", u->nick.c_str(), all ? " ALL" : "", chan); + ircdproto->SendGlobops(OperServ, "%s used CLEARMODES%s on %s", u->nick.c_str(), all ? " ALL" : "", chan.c_str()); if (all) { /* Clear mode +o */ if (ircd->svsmode_ucmode) - ircdproto->SendSVSModeChan(c, "-o", NULL); + ircdproto->SendSVSModeChan(c, "-o", ""); else { for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) @@ -72,7 +72,7 @@ class CommandOSClearModes : public Command /* Clear mode +v */ if (ircd->svsmode_ucmode) - ircdproto->SendSVSModeChan(c, "-v", NULL); + ircdproto->SendSVSModeChan(c, "-v", ""); else { for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) @@ -88,7 +88,7 @@ class CommandOSClearModes : public Command if (ModeManager::FindChannelModeByName(CMODE_HALFOP)) { if (ircd->svsmode_ucmode) - ircdproto->SendSVSModeChan(c, "-h", NULL); + ircdproto->SendSVSModeChan(c, "-h", ""); else { for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) @@ -104,11 +104,10 @@ class CommandOSClearModes : public Command /* Clear mode Owners */ if ((cm = ModeManager::FindChannelModeByName(CMODE_OWNER))) { - buf = '-'; - buf += cm->ModeChar; + buf = "-" + cm->ModeChar; if (ircd->svsmode_ucmode) - ircdproto->SendSVSModeChan(c, buf.c_str(), NULL); + ircdproto->SendSVSModeChan(c, buf, ""); else { for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) @@ -124,11 +123,10 @@ class CommandOSClearModes : public Command /* Clear mode protected or admins */ if ((cm = ModeManager::FindChannelModeByName(CMODE_PROTECT))) { - buf = '-'; - buf += cm->ModeChar; + buf = "-" + cm->ModeChar; if (ircd->svsmode_ucmode) - ircdproto->SendSVSModeChan(c, buf.c_str(), NULL); + ircdproto->SendSVSModeChan(c, buf, ""); else { for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) @@ -150,20 +148,20 @@ class CommandOSClearModes : public Command } if (all) - notice_lang(Config.s_OperServ, u, OPER_CLEARMODES_ALL_DONE, chan); + notice_lang(Config.s_OperServ, u, OPER_CLEARMODES_ALL_DONE, chan.c_str()); else - notice_lang(Config.s_OperServ, u, OPER_CLEARMODES_DONE, chan); + notice_lang(Config.s_OperServ, u, OPER_CLEARMODES_DONE, chan.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_CLEARMODES); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "CLEARMODES", OPER_CLEARMODES_SYNTAX); } @@ -177,7 +175,7 @@ class CommandOSClearModes : public Command class OSClearModes : public Module { public: - OSClearModes(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSClearModes(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_defcon.cpp b/modules/core/os_defcon.cpp index 78e366071..f7349aa99 100644 --- a/modules/core/os_defcon.cpp +++ b/modules/core/os_defcon.cpp @@ -15,17 +15,15 @@ void defcon_sendlvls(User *u); void runDefCon(); -void defconParseModeString(const char *str); +void defconParseModeString(const Anope::string &str); void resetDefCon(int level); -static char *defconReverseModes(const char *modes); -class DefConTimeout; -static DefConTimeout *timeout; +static Anope::string defconReverseModes(const Anope::string &modes); class DefConTimeout : public Timer { - int level; + int level; - public: + public: DefConTimeout(int newlevel) : Timer(Config.DefConTimeOut), level(newlevel) { } void Tick(time_t) @@ -35,23 +33,24 @@ class DefConTimeout : public Timer Config.DefConLevel = level; FOREACH_MOD(I_OnDefconLevel, OnDefconLevel(level)); Alog() << "Defcon level timeout, returning to lvl " << level; - ircdproto->SendGlobops(OperServ, getstring(OPER_DEFCON_WALL), Config.s_OperServ, level); + ircdproto->SendGlobops(OperServ, getstring(OPER_DEFCON_WALL), Config.s_OperServ.c_str(), level); if (Config.GlobalOnDefcon) { - if (Config.DefConOffMessage) - oper_global(NULL, "%s", Config.DefConOffMessage); + if (!Config.DefConOffMessage.empty()) + oper_global("", "%s", Config.DefConOffMessage.c_str()); else - oper_global(NULL, getstring(DEFCON_GLOBAL), Config.DefConLevel); + oper_global("", getstring(DEFCON_GLOBAL), Config.DefConLevel); - if (Config.GlobalOnDefconMore && !Config.DefConOffMessage) - oper_global(NULL, "%s", Config.DefconMessage); + if (Config.GlobalOnDefconMore && Config.DefConOffMessage.empty()) + oper_global("", "%s", Config.DefconMessage.c_str()); } runDefCon(); } } }; +static DefConTimeout *timeout; class CommandOSDEFCON : public Command { @@ -60,19 +59,19 @@ class CommandOSDEFCON : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *lvl = params[0].c_str(); + Anope::string lvl = params[0]; int newLevel = 0; const char *langglobal = getstring(DEFCON_GLOBAL); - if (!lvl) + if (lvl.empty()) { notice_lang(Config.s_OperServ, u, OPER_DEFCON_CHANGED, Config.DefConLevel); defcon_sendlvls(u); return MOD_CONT; } - newLevel = atoi(lvl); + newLevel = lvl.is_number_only() ? convertTo<int>(lvl) : 0; if (newLevel < 1 || newLevel > 5) { this->OnSyntaxError(u, ""); @@ -99,28 +98,28 @@ class CommandOSDEFCON : public Command the Admin would like to add. Set in config file. */ if (Config.GlobalOnDefcon) { - if (Config.DefConLevel == 5 && Config.DefConOffMessage) - oper_global(NULL, "%s", Config.DefConOffMessage); + if (Config.DefConLevel == 5 && !Config.DefConOffMessage.empty()) + oper_global("", "%s", Config.DefConOffMessage.c_str()); else - oper_global(NULL, langglobal, Config.DefConLevel); + oper_global("", langglobal, Config.DefConLevel); } if (Config.GlobalOnDefconMore) { - if (!Config.DefConOffMessage || Config.DefConLevel != 5) - oper_global(NULL, "%s", Config.DefconMessage); + if (Config.DefConOffMessage.empty() || Config.DefConLevel != 5) + oper_global("", "%s", Config.DefconMessage.c_str()); } /* Run any defcon functions, e.g. FORCE CHAN MODE */ runDefCon(); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_DEFCON); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "DEFCON", OPER_DEFCON_SYNTAX); } @@ -134,7 +133,7 @@ class CommandOSDEFCON : public Command class OSDEFCON : public Module { public: - OSDEFCON(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSDEFCON(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { if (!Config.DefConLevel) throw ModuleException("Invalid configuration settings"); @@ -157,7 +156,7 @@ class OSDEFCON : public Module if (CheckDefCon(DEFCON_AKILL_NEW_CLIENTS)) { Alog() << "DEFCON: adding akill for *@" << u->host; - XLine *x = SGLine->Add(NULL, NULL, ci::string("*@") + u->host, time(NULL) + Config.DefConAKILL, Config.DefConAkillReason ? Config.DefConAkillReason : "DEFCON AKILL"); + XLine *x = SGLine->Add(NULL, NULL, "*@" + u->host, time(NULL) + Config.DefConAKILL, !Config.DefConAkillReason.empty() ? Config.DefConAkillReason : "DEFCON AKILL"); if (x) x->By = Config.s_OperServ; } @@ -171,7 +170,7 @@ class OSDEFCON : public Module return EVENT_CONTINUE; } - EventReturn OnChannelModeSet(Channel *c, ChannelModeName Name, const std::string ¶m) + EventReturn OnChannelModeSet(Channel *c, ChannelModeName Name, const Anope::string ¶m) { ChannelMode *cm = ModeManager::FindChannelModeByName(Name); @@ -185,13 +184,13 @@ class OSDEFCON : public Module return EVENT_CONTINUE; } - EventReturn OnChannelModeUnset(Channel *c, ChannelModeName Name, const std::string &) + EventReturn OnChannelModeUnset(Channel *c, ChannelModeName Name, const Anope::string &) { ChannelMode *cm = ModeManager::FindChannelModeByName(Name); if (CheckDefCon(DEFCON_FORCE_CHAN_MODES) && cm && DefConModesOn.HasFlag(Name)) { - std::string param; + Anope::string param; if (GetDefConParam(Name, param)) c->SetMode(OperServ, Name, param); @@ -205,7 +204,7 @@ class OSDEFCON : public Module return EVENT_CONTINUE; } - EventReturn OnPreCommandRun(User *u, BotInfo *bi, const ci::string &command, const ci::string &message, Command *c) + EventReturn OnPreCommandRun(User *u, BotInfo *bi, const Anope::string &command, const ci::string &message, Command *c) { if (!c) { @@ -215,7 +214,7 @@ class OSDEFCON : public Module if ((CheckDefCon(DEFCON_OPER_ONLY) || CheckDefCon(DEFCON_SILENT_OPER_ONLY)) && !is_oper(u)) { if (!CheckDefCon(DEFCON_SILENT_OPER_ONLY)) - notice_lang(bi->nick.c_str(), u, OPER_DEFCON_DENIED); + notice_lang(bi->nick, u, OPER_DEFCON_DENIED); return EVENT_STOP; } @@ -223,30 +222,30 @@ class OSDEFCON : public Module return EVENT_CONTINUE; } - EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms) + EventReturn OnPreCommand(User *u, BotInfo *service, const Anope::string &command, const std::vector<Anope::string> ¶ms) { - if (service == Config.s_NickServ) + if (service == findbot(Config.s_NickServ)) { - if (command == "SET") + if (command.equals_ci("REGISTER") || command.equals_ci("GROUP")) { - if (!params.empty() && params[0] == "MLOCK" && CheckDefCon(DEFCON_NO_MLOCK_CHANGE)) + if (CheckDefCon(DEFCON_NO_NEW_NICKS)) { - notice_lang(Config.s_ChanServ, u, OPER_DEFCON_DENIED); + notice_lang(Config.s_NickServ, u, OPER_DEFCON_DENIED); return EVENT_STOP; } } - else if (command == "REGISTER" || command == "GROUP") + } + else if (service == findbot(Config.s_ChanServ)) + { + if (command.equals_ci("SET")) { - if (CheckDefCon(DEFCON_NO_NEW_NICKS)) + if (!params.empty() && params[0].equals_ci("MLOCK") && CheckDefCon(DEFCON_NO_MLOCK_CHANGE)) { - notice_lang(Config.s_NickServ, u, OPER_DEFCON_DENIED); + notice_lang(Config.s_ChanServ, u, OPER_DEFCON_DENIED); return EVENT_STOP; } } - } - else if (service == Config.s_ChanServ) - { - if (command == "REGISTER") + else if (command.equals_ci("REGISTER")) { if (CheckDefCon(DEFCON_NO_NEW_CHANNELS)) { @@ -255,9 +254,9 @@ class OSDEFCON : public Module } } } - else if (service == Config.s_MemoServ) + else if (service == findbot(Config.s_MemoServ)) { - if (command == "SEND" || command == "SENDALL") + if (command.equals_ci("SEND") || command.equals_ci("SENDALL")) { if (CheckDefCon(DEFCON_NO_NEW_MEMOS)) { @@ -279,17 +278,17 @@ class OSDEFCON : public Module { if (session && session->count > Config.DefConSessionLimit) { - if (Config.SessionLimitExceeded) - ircdproto->SendMessage(OperServ, u->nick.c_str(), Config.SessionLimitExceeded, u->host); - if (Config.SessionLimitDetailsLoc) - ircdproto->SendMessage(OperServ, u->nick.c_str(), "%s", Config.SessionLimitDetailsLoc); + if (!Config.SessionLimitExceeded.empty()) + ircdproto->SendMessage(OperServ, u->nick, Config.SessionLimitExceeded.c_str(), u->host.c_str()); + if (!Config.SessionLimitDetailsLoc.empty()) + ircdproto->SendMessage(OperServ, u->nick, "%s", Config.SessionLimitDetailsLoc.c_str()); kill_user(Config.s_OperServ, u->nick, "Session limit exceeded"); ++session->hits; if (Config.MaxSessionKill && session->hits >= Config.MaxSessionKill) { - SGLine->Add(NULL, NULL, ci::string("*@") + u->host, time(NULL) + Config.SessionAutoKillExpiry, "Session limit exceeded"); - ircdproto->SendGlobops(OperServ, "Added a temporary AKILL for \2*@%s\2 due to excessive connections", u->host); + SGLine->Add(NULL, NULL, "*@" + u->host, time(NULL) + Config.SessionAutoKillExpiry, "Session limit exceeded"); + ircdproto->SendGlobops(OperServ, "Added a temporary AKILL for \2*@%s\2 due to excessive connections", u->host.c_str()); } } } @@ -297,11 +296,11 @@ class OSDEFCON : public Module void OnChannelModeAdd(ChannelMode *cm) { - if (Config.DefConChanModes) + if (!Config.DefConChanModes.empty()) { - std::string modes = Config.DefConChanModes; + Anope::string modes = Config.DefConChanModes; - if (modes.find(cm->ModeChar) != std::string::npos) + if (modes.find(cm->ModeChar) != Anope::string::npos) /* New mode has been added to Anope, check to see if defcon * requires it */ @@ -312,7 +311,7 @@ class OSDEFCON : public Module void OnChannelCreate(Channel *c) { if (CheckDefCon(DEFCON_FORCE_CHAN_MODES)) - c->SetModes(OperServ, false, Config.DefConChanModes); + c->SetModes(OperServ, false, "%s", Config.DefConChanModes.c_str()); } }; @@ -327,8 +326,8 @@ void defcon_sendlvls(User *u) notice_lang(Config.s_OperServ, u, OPER_HELP_DEFCON_NO_NEW_NICKS); if (CheckDefCon(DEFCON_NO_MLOCK_CHANGE)) notice_lang(Config.s_OperServ, u, OPER_HELP_DEFCON_NO_MLOCK_CHANGE); - if (CheckDefCon(DEFCON_FORCE_CHAN_MODES) && Config.DefConChanModes) - notice_lang(Config.s_OperServ, u, OPER_HELP_DEFCON_FORCE_CHAN_MODES, Config.DefConChanModes); + if (CheckDefCon(DEFCON_FORCE_CHAN_MODES) && !Config.DefConChanModes.empty()) + notice_lang(Config.s_OperServ, u, OPER_HELP_DEFCON_FORCE_CHAN_MODES, Config.DefConChanModes.c_str()); if (CheckDefCon(DEFCON_REDUCE_SESSION)) notice_lang(Config.s_OperServ, u, OPER_HELP_DEFCON_REDUCE_SESSION, Config.DefConSessionLimit); if (CheckDefCon(DEFCON_NO_NEW_CLIENTS)) @@ -345,11 +344,9 @@ void defcon_sendlvls(User *u) void runDefCon() { - char *newmodes; - if (CheckDefCon(DEFCON_FORCE_CHAN_MODES)) { - if (Config.DefConChanModes && !DefConModesSet) + if (!Config.DefConChanModes.empty() && !DefConModesSet) { if (Config.DefConChanModes[0] == '+' || Config.DefConChanModes[0] == '-') { @@ -361,16 +358,16 @@ void runDefCon() } else { - if (Config.DefConChanModes && DefConModesSet) + if (!Config.DefConChanModes.empty() && DefConModesSet) { if (Config.DefConChanModes[0] == '+' || Config.DefConChanModes[0] == '-') { DefConModesSet = false; - if ((newmodes = defconReverseModes(Config.DefConChanModes))) + Anope::string newmodes = defconReverseModes(Config.DefConChanModes); + if (!newmodes.empty()) { Alog() << "DEFCON: setting " << newmodes << " on all channels"; MassChannelModes(OperServ, newmodes); - delete [] newmodes; } } } @@ -382,15 +379,15 @@ void runDefCon() * @param str mode string to parse * @return 1 if accepted, 0 if failed */ -void defconParseModeString(const char *str) +void defconParseModeString(const Anope::string &str) { int add = -1; /* 1 if adding, 0 if deleting, -1 if neither */ unsigned char mode; ChannelMode *cm; ChannelModeParam *cmp; - std::string modes, param; + Anope::string modes, param; - if (!str) + if (str.empty()) return; spacesepstream ss(str); @@ -400,7 +397,7 @@ void defconParseModeString(const char *str) ss.GetToken(modes); /* Loop while there are modes to set */ - for (unsigned i = 0, end = modes.size(); i < end; ++i) + for (unsigned i = 0, end = modes.length(); i < end; ++i) { mode = modes[i]; @@ -475,24 +472,20 @@ void defconParseModeString(const char *str) } } -static char *defconReverseModes(const char *modes) +static Anope::string defconReverseModes(const Anope::string &modes) { - char *newmodes = NULL; - unsigned i = 0; - if (!modes) - return NULL; - if (!(newmodes = new char[strlen(modes) + 1])) - return NULL; - for (i = 0; i < strlen(modes); ++i) + if (modes.empty()) + return ""; + Anope::string newmodes; + for (unsigned i = 0, end = modes.length(); i < end; ++i) { if (modes[i] == '+') - newmodes[i] = '-'; + newmodes += '-'; else if (modes[i] == '-') - newmodes[i] = '+'; + newmodes += '+'; else - newmodes[i] = modes[i]; + newmodes += modes[i]; } - newmodes[i] = '\0'; return newmodes; } diff --git a/modules/core/os_global.cpp b/modules/core/os_global.cpp index a5abde2ff..25c2dfe85 100644 --- a/modules/core/os_global.cpp +++ b/modules/core/os_global.cpp @@ -20,23 +20,23 @@ class CommandOSGlobal : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *msg = params[0].c_str(); + Anope::string msg = params[0]; if (Config.WallOSGlobal) ircdproto->SendGlobops(OperServ, "\2%s\2 just used GLOBAL command.", u->nick.c_str()); - oper_global(const_cast<char *>(u->nick.c_str()), "%s", msg); + oper_global(u->nick, "%s", msg.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { - notice_help(Config.s_OperServ, u, OPER_HELP_GLOBAL, Config.s_GlobalNoticer); + notice_help(Config.s_OperServ, u, OPER_HELP_GLOBAL, Config.s_GlobalNoticer.c_str()); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "GLOBAL", OPER_GLOBAL_SYNTAX); } @@ -50,7 +50,7 @@ class CommandOSGlobal : public Command class OSGlobal : public Module { public: - OSGlobal(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSGlobal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_help.cpp b/modules/core/os_help.cpp index d88119bd2..d2ab5412e 100644 --- a/modules/core/os_help.cpp +++ b/modules/core/os_help.cpp @@ -20,13 +20,13 @@ class CommandOSHelp : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - mod_help_cmd(OperServ, u, params[0].c_str()); + mod_help_cmd(OperServ, u, params[0]); return MOD_CONT; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP); for (CommandMap::const_iterator it = OperServ->Commands.begin(), it_end = OperServ->Commands.end(); it != it_end; ++it) @@ -39,7 +39,7 @@ class CommandOSHelp : public Command class OSHelp : public Module { public: - OSHelp(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSHelp(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_ignore.cpp b/modules/core/os_ignore.cpp index 881f79601..4c1d76bd1 100644 --- a/modules/core/os_ignore.cpp +++ b/modules/core/os_ignore.cpp @@ -16,13 +16,13 @@ class CommandOSIgnore : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) { - const char *time = params.size() > 1 ? params[1].c_str() : NULL; - const char *nick = params.size() > 2 ? params[2].c_str() : NULL; + Anope::string time = params.size() > 1 ? params[1] : ""; + Anope::string nick = params.size() > 2 ? params[2] : ""; time_t t; - if (!time || !nick) + if (time.empty() || nick.empty()) { this->OnSyntaxError(u, "ADD"); return MOD_CONT; @@ -39,12 +39,12 @@ class CommandOSIgnore : public Command else if (!t) { add_ignore(nick, t); - notice_lang(Config.s_OperServ, u, OPER_IGNORE_PERM_DONE, nick); + notice_lang(Config.s_OperServ, u, OPER_IGNORE_PERM_DONE, nick.c_str()); } else { add_ignore(nick, t); - notice_lang(Config.s_OperServ, u, OPER_IGNORE_TIME_DONE, nick, time); + notice_lang(Config.s_OperServ, u, OPER_IGNORE_TIME_DONE, nick.c_str(), time.c_str()); } } @@ -63,24 +63,24 @@ class CommandOSIgnore : public Command notice_lang(Config.s_OperServ, u, OPER_IGNORE_LIST); for (id = ignore; id; id = id->next) - u->SendMessage(Config.s_OperServ, "%s", id->mask); + u->SendMessage(Config.s_OperServ, "%s", id->mask.c_str()); return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params.size() > 1 ? params[1].c_str() : NULL; - if (!nick) + Anope::string nick = params.size() > 1 ? params[1] : ""; + if (nick.empty()) this->OnSyntaxError(u, "DEL"); else { if (delete_ignore(nick)) { - notice_lang(Config.s_OperServ, u, OPER_IGNORE_DEL_DONE, nick); + notice_lang(Config.s_OperServ, u, OPER_IGNORE_DEL_DONE, nick.c_str()); return MOD_CONT; } - notice_lang(Config.s_OperServ, u, OPER_IGNORE_LIST_NOMATCH, nick); + notice_lang(Config.s_OperServ, u, OPER_IGNORE_LIST_NOMATCH, nick.c_str()); } return MOD_CONT; @@ -98,17 +98,17 @@ class CommandOSIgnore : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; + Anope::string cmd = params[0]; - if (cmd == "ADD") + if (cmd.equals_ci("ADD")) return this->DoAdd(u, params); - else if (cmd == "LIST") + else if (cmd.equals_ci("LIST")) return this->DoList(u); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) return this->DoDel(u, params); - else if (cmd == "CLEAR") + else if (cmd.equals_ci("CLEAR")) return this->DoClear(u); else this->OnSyntaxError(u, ""); @@ -116,13 +116,13 @@ class CommandOSIgnore : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_IGNORE); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "IGNORE", OPER_IGNORE_SYNTAX); } @@ -136,7 +136,7 @@ class CommandOSIgnore : public Command class OSIgnore : public Module { public: - OSIgnore(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); @@ -147,19 +147,17 @@ class OSIgnore : public Module ModuleManager::Attach(i, this, 2); } - EventReturn OnDatabaseRead(const std::vector<std::string> ¶ms) + EventReturn OnDatabaseRead(const std::vector<Anope::string> ¶ms) { - std::string buf; - - if (params[0] == "OS" && params.size() >= 4 && params[1] == "IGNORE") + if (params[0].equals_ci("OS") && params.size() >= 4 && params[1].equals_ci("IGNORE")) { - IgnoreData *ign = new IgnoreData; - ign->mask = sstrdup(params[2].c_str()); - ign->time = strtol(params[3].c_str(), NULL, 10); + IgnoreData *ign = new IgnoreData(); + ign->mask = params[2]; + ign->time = params[3].is_number_only() ? convertTo<time_t>(params[3]) : 0; ign->prev = NULL; ign->next = ignore; if (ignore) - ignore->prev = ign; + ignore->prev = ign; ignore = ign; return EVENT_STOP; @@ -168,7 +166,7 @@ class OSIgnore : public Module return EVENT_CONTINUE; } - void OnDatabaseWrite(void (*Write)(const std::string &)) + void OnDatabaseWrite(void (*Write)(const Anope::string &)) { IgnoreData *ign, *next; time_t now = time(NULL); @@ -186,7 +184,6 @@ class OSIgnore : public Module ignore = ign->next; if (ign->next) ign->next->prev = ign->prev; - delete [] ign->mask; delete ign; ign = NULL; } diff --git a/modules/core/os_jupe.cpp b/modules/core/os_jupe.cpp index 341e2b28d..68ff2841a 100644 --- a/modules/core/os_jupe.cpp +++ b/modules/core/os_jupe.cpp @@ -20,10 +20,10 @@ class CommandOSJupe : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *jserver = params[0].c_str(); - const char *reason = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string jserver = params[0]; + Anope::string reason = params.size() > 1 ? params[1] : ""; Server *server = Server::Find(jserver); if (!isValidHost(jserver, 3)) @@ -32,8 +32,7 @@ class CommandOSJupe : public Command notice_lang(Config.s_OperServ, u, OPER_JUPE_INVALID_SERVER); else { - char rbuf[256]; - snprintf(rbuf, sizeof(rbuf), "Juped by %s%s%s", u->nick.c_str(), reason ? ": " : "", reason ? reason : ""); + Anope::string rbuf = "Juped by " + u->nick + (!reason.empty() ? ": " + reason : ""); if (server) ircdproto->SendSquit(jserver, rbuf); Server *juped_server = new Server(Me, jserver, 1, rbuf, ircd->ts6 ? ts6_sid_retrieve() : ""); @@ -41,18 +40,18 @@ class CommandOSJupe : public Command ircdproto->SendServer(juped_server); if (Config.WallOSJupe) - ircdproto->SendGlobops(OperServ, "\2%s\2 used JUPE on \2%s\2", u->nick.c_str(), jserver); + ircdproto->SendGlobops(OperServ, "\2%s\2 used JUPE on \2%s\2", u->nick.c_str(), jserver.c_str()); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_JUPE); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "JUPE", OPER_JUPE_SYNTAX); } @@ -66,7 +65,7 @@ class CommandOSJupe : public Command class OSJupe : public Module { public: - OSJupe(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSJupe(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_kick.cpp b/modules/core/os_kick.cpp index 2600814f3..edb92436a 100644 --- a/modules/core/os_kick.cpp +++ b/modules/core/os_kick.cpp @@ -20,15 +20,15 @@ class CommandOSKick : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(), *nick = params[1].c_str(), *s = params[2].c_str(); + Anope::string chan = params[0], nick = params[1], s = params[2]; Channel *c; User *u2; if (!(c = findchan(chan))) { - notice_lang(Config.s_OperServ, u, CHAN_X_NOT_IN_USE, chan); + notice_lang(Config.s_OperServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); return MOD_CONT; } else if (c->bouncy_modes) @@ -38,23 +38,23 @@ class CommandOSKick : public Command } else if (!(u2 = finduser(nick))) { - notice_lang(Config.s_OperServ, u, NICK_X_NOT_IN_USE, nick); + notice_lang(Config.s_OperServ, u, NICK_X_NOT_IN_USE, nick.c_str()); return MOD_CONT; } - c->Kick(OperServ, u2, "%s (%s)", u->nick.c_str(), s); + c->Kick(OperServ, u2, "%s (%s)", u->nick.c_str(), s.c_str()); if (Config.WallOSKick) - ircdproto->SendGlobops(OperServ, "%s used KICK on %s/%s", u->nick.c_str(), u2->nick.c_str(), chan); + ircdproto->SendGlobops(OperServ, "%s used KICK on %s/%s", u->nick.c_str(), u2->nick.c_str(), chan.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_KICK); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "KICK", OPER_KICK_SYNTAX); } @@ -68,7 +68,7 @@ class CommandOSKick : public Command class OSKick : public Module { public: - OSKick(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_mode.cpp b/modules/core/os_mode.cpp index 3f33257fe..40ed4cfe0 100644 --- a/modules/core/os_mode.cpp +++ b/modules/core/os_mode.cpp @@ -20,32 +20,32 @@ class CommandOSMode : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(), *modes = params[1].c_str(); + Anope::string chan = params[0], modes = params[1]; Channel *c; if (!(c = findchan(chan))) - notice_lang(Config.s_OperServ, u, CHAN_X_NOT_IN_USE, chan); + notice_lang(Config.s_OperServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); else if (c->bouncy_modes) notice_lang(Config.s_OperServ, u, OPER_BOUNCY_MODES_U_LINE); else { - c->SetModes(OperServ, false, modes); + c->SetModes(OperServ, false, modes.c_str()); if (Config.WallOSMode) - ircdproto->SendGlobops(OperServ, "%s used MODE %s on %s", u->nick.c_str(), modes, chan); + ircdproto->SendGlobops(OperServ, "%s used MODE %s on %s", u->nick.c_str(), modes.c_str(), chan.c_str()); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_MODE); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "MODE", OPER_MODE_SYNTAX); } @@ -59,7 +59,7 @@ class CommandOSMode : public Command class OSMode : public Module { public: - OSMode(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSMode(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_modinfo.cpp b/modules/core/os_modinfo.cpp index d71f146c7..e2dccc673 100644 --- a/modules/core/os_modinfo.cpp +++ b/modules/core/os_modinfo.cpp @@ -13,7 +13,7 @@ #include "module.h" -static int showModuleCmdLoaded(BotInfo *bi, const ci::string &mod_name, User *u); +static int showModuleCmdLoaded(BotInfo *bi, const Anope::string &mod_name, User *u); class CommandOSModInfo : public Command { @@ -22,25 +22,25 @@ class CommandOSModInfo : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const std::string file = params[0].c_str(); + Anope::string file = params[0]; struct tm tm; char timebuf[64]; - Module *m = FindModule(file.c_str()); + Module *m = FindModule(file); if (m) { tm = *localtime(&m->created); strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_DATE_TIME_FORMAT, &tm); notice_lang(Config.s_OperServ, u, OPER_MODULE_INFO_LIST, m->name.c_str(), !m->version.empty() ? m->version.c_str() : "?", !m->author.empty() ? m->author.c_str() : "?", timebuf); - showModuleCmdLoaded(HostServ, m->name.c_str(), u); - showModuleCmdLoaded(OperServ, m->name.c_str(), u); - showModuleCmdLoaded(NickServ, m->name.c_str(), u); - showModuleCmdLoaded(ChanServ, m->name.c_str(), u); - showModuleCmdLoaded(BotServ, m->name.c_str(), u); - showModuleCmdLoaded(MemoServ, m->name.c_str(), u); + showModuleCmdLoaded(HostServ, m->name, u); + showModuleCmdLoaded(OperServ, m->name, u); + showModuleCmdLoaded(NickServ, m->name, u); + showModuleCmdLoaded(ChanServ, m->name, u); + showModuleCmdLoaded(BotServ, m->name, u); + showModuleCmdLoaded(MemoServ, m->name, u); } else notice_lang(Config.s_OperServ, u, OPER_MODULE_NO_INFO, file.c_str()); @@ -48,13 +48,13 @@ class CommandOSModInfo : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_MODINFO); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "MODINFO", OPER_MODULE_INFO_SYNTAX); } @@ -68,7 +68,7 @@ class CommandOSModInfo : public Command class OSModInfo : public Module { public: - OSModInfo(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSModInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); @@ -77,18 +77,18 @@ class OSModInfo : public Module } }; -static int showModuleCmdLoaded(BotInfo *bi, const ci::string &mod_name, User *u) +static int showModuleCmdLoaded(BotInfo *bi, const Anope::string &mod_name, User *u) { if (!bi) return 0; int display = 0; - for (std::map<ci::string, Command *>::iterator it = bi->Commands.begin(), it_end = bi->Commands.end(); it != it_end; ++it) + for (CommandMap::iterator it = bi->Commands.begin(), it_end = bi->Commands.end(); it != it_end; ++it) { Command *c = it->second; - if (c->module && c->module->name == mod_name) + if (c->module && c->module->name.equals_ci(mod_name)) { notice_lang(Config.s_OperServ, u, OPER_MODULE_CMD_LIST, c->service, c->name.c_str()); ++display; diff --git a/modules/core/os_modlist.cpp b/modules/core/os_modlist.cpp index 8764188da..265776917 100644 --- a/modules/core/os_modlist.cpp +++ b/modules/core/os_modlist.cpp @@ -20,7 +20,7 @@ class CommandOSModList : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { int count = 0; int showCore = 0; @@ -32,7 +32,7 @@ class CommandOSModList : public Command int showDB = 1; int showSocketEngine = 1; - ci::string param = params.size() ? params[0] : ""; + Anope::string param = !params.empty() ? params[0] : ""; char core[] = "Core"; char third[] = "3rd"; @@ -45,7 +45,7 @@ class CommandOSModList : public Command if (!param.empty()) { - if (param == core) + if (param.equals_ci(core)) { showCore = 1; showThird = 0; @@ -56,7 +56,7 @@ class CommandOSModList : public Command showDB = 0; showSocketEngine = 0; } - else if (param == third) + else if (param.equals_ci(third)) { showCore = 0; showThird = 1; @@ -67,7 +67,7 @@ class CommandOSModList : public Command showDB = 0; showSocketEngine = 0; } - else if (param == proto) + else if (param.equals_ci(proto)) { showCore = 0; showThird = 0; @@ -78,7 +78,7 @@ class CommandOSModList : public Command showDB = 0; showSocketEngine = 0; } - else if (param == supported) + else if (param.equals_ci(supported)) { showCore = 0; showThird = 0; @@ -89,7 +89,7 @@ class CommandOSModList : public Command showDB = 0; showSocketEngine = 0; } - else if (param == qa) + else if (param.equals_ci(qa)) { showCore = 0; showThird = 0; @@ -100,7 +100,7 @@ class CommandOSModList : public Command showDB = 0; showSocketEngine = 0; } - else if (param == enc) + else if (param.equals_ci(enc)) { showCore = 0; showThird = 0; @@ -111,7 +111,7 @@ class CommandOSModList : public Command showDB = 0; showSocketEngine = 0; } - else if (param == db) + else if (param.equals_ci(db)) { showCore = 0; showThird = 0; @@ -203,7 +203,7 @@ class CommandOSModList : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_MODLIST); return true; @@ -218,7 +218,7 @@ class CommandOSModList : public Command class OSModList : public Module { public: - OSModList(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSModList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_modload.cpp b/modules/core/os_modload.cpp index f70c80c05..a75fa9489 100644 --- a/modules/core/os_modload.cpp +++ b/modules/core/os_modload.cpp @@ -20,9 +20,9 @@ class CommandOSModLoad : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const std::string mname = params[0].c_str(); + Anope::string mname = params[0]; Module *m = FindModule(mname); if (m) @@ -40,13 +40,13 @@ class CommandOSModLoad : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_MODLOAD); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "MODLOAD", OPER_MODULE_LOAD_SYNTAX); } @@ -60,7 +60,7 @@ class CommandOSModLoad : public Command class OSModLoad : public Module { public: - OSModLoad(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSModLoad(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_modunload.cpp b/modules/core/os_modunload.cpp index 0988d4473..50720459e 100644 --- a/modules/core/os_modunload.cpp +++ b/modules/core/os_modunload.cpp @@ -20,9 +20,9 @@ class CommandOSModUnLoad : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const std::string mname = params[0].c_str(); + Anope::string mname = params[0]; int status; Module *m = FindModule(mname); @@ -42,13 +42,13 @@ class CommandOSModUnLoad : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_MODUNLOAD); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "MODUNLOAD", OPER_MODULE_UNLOAD_SYNTAX); } @@ -62,7 +62,7 @@ class CommandOSModUnLoad : public Command class OSModUnLoad : public Module { public: - OSModUnLoad(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSModUnLoad(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_news.cpp b/modules/core/os_news.cpp index c3ebabf3a..42ca764c3 100644 --- a/modules/core/os_news.cpp +++ b/modules/core/os_news.cpp @@ -130,7 +130,7 @@ static void DisplayNews(User *u, NewsType Type) } } -static int add_newsitem(User *u, const char *text, NewsType type) +static int add_newsitem(User *u, const Anope::string &text, NewsType type) { int num = 0; @@ -141,7 +141,7 @@ static int add_newsitem(User *u, const char *text, NewsType type) break; } - NewsItem *news = new NewsItem; + NewsItem *news = new NewsItem(); news->type = type; news->num = num + 1; news->Text = text; @@ -168,13 +168,12 @@ static int del_newsitem(unsigned num, NewsType type) return count; } -static int *findmsgs(NewsType type, const char **type_name) +static int *findmsgs(NewsType type, Anope::string &type_name) { for (unsigned i = 0; i < lenof(msgarray); ++i) if (msgarray[i].type == type) { - if (type_name) - *type_name = msgarray[i].name; + type_name = msgarray[i].name; return msgarray[i].msgs; } return NULL; @@ -207,12 +206,12 @@ class NewsBase : public Command return MOD_CONT; } - CommandReturn DoAdd(User *u, const std::vector<ci::string> ¶ms, NewsType type, int *msgs) + CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms, NewsType type, int *msgs) { - const char *text = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string text = params.size() > 1 ? params[1] : ""; int n; - if (!text) + if (text.empty()) this->OnSyntaxError(u, "ADD"); else { @@ -231,12 +230,12 @@ class NewsBase : public Command return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<ci::string> ¶ms, NewsType type, int *msgs) + CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms, NewsType type, int *msgs) { - const char *text = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string text = params.size() > 1 ? params[1] : ""; unsigned num; - if (!text) + if (text.empty()) this->OnSyntaxError(u, "DEL"); else { @@ -245,9 +244,9 @@ class NewsBase : public Command notice_lang(Config.s_OperServ, u, READ_ONLY_MODE); return MOD_CONT; } - if (stricmp(text, "ALL")) + if (!text.equals_ci("ALL")) { - num = atoi(text); + num = text.is_number_only() ? convertTo<unsigned>(text) : 0; if (num > 0 && del_newsitem(num, type)) { notice_lang(Config.s_OperServ, u, msgs[MSG_DELETED], num); @@ -270,24 +269,24 @@ class NewsBase : public Command return MOD_CONT; } - CommandReturn DoNews(User *u, const std::vector<ci::string> ¶ms, NewsType type) + CommandReturn DoNews(User *u, const std::vector<Anope::string> ¶ms, NewsType type) { - ci::string cmd = params[0]; - const char *type_name; + Anope::string cmd = params[0]; + Anope::string type_name; int *msgs; - msgs = findmsgs(type, &type_name); + msgs = findmsgs(type, type_name); if (!msgs) { Alog() << "news: Invalid type to do_news()"; return MOD_CONT; } - if (cmd == "LIST") + if (cmd.equals_ci("LIST")) return this->DoList(u, type, msgs); - else if (cmd == "ADD") + else if (cmd.equals_ci("ADD")) return this->DoAdd(u, params, type, msgs); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) return this->DoDel(u, params, type, msgs); else this->OnSyntaxError(u, ""); @@ -295,7 +294,7 @@ class NewsBase : public Command return MOD_CONT; } public: - NewsBase(const ci::string &newstype) : Command(newstype, 1, 2, "operserv/news") + NewsBase(const Anope::string &newstype) : Command(newstype, 1, 2, "operserv/news") { } @@ -303,11 +302,11 @@ class NewsBase : public Command { } - virtual CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) = 0; + virtual CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) = 0; - virtual bool OnHelp(User *u, const ci::string &subcommand) = 0; + virtual bool OnHelp(User *u, const Anope::string &subcommand) = 0; - virtual void OnSyntaxError(User *u, const ci::string &subcommand) = 0; + virtual void OnSyntaxError(User *u, const Anope::string &subcommand) = 0; }; class CommandOSLogonNews : public NewsBase @@ -317,18 +316,18 @@ class CommandOSLogonNews : public NewsBase { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { return this->DoNews(u, params, NEWS_LOGON); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, NEWS_HELP_LOGON, Config.NewsCount); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "LOGONNEWS", NEWS_LOGON_SYNTAX); } @@ -346,18 +345,18 @@ class CommandOSOperNews : public NewsBase { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { return this->DoNews(u, params, NEWS_OPER); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, NEWS_HELP_OPER, Config.NewsCount); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "OPERNEWS", NEWS_OPER_SYNTAX); } @@ -375,18 +374,18 @@ class CommandOSRandomNews : public NewsBase { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { return this->DoNews(u, params, NEWS_RANDOM); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, NEWS_HELP_RANDOM); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "RANDOMNEWS", NEWS_RANDOM_SYNTAX); } @@ -400,7 +399,7 @@ class CommandOSRandomNews : public NewsBase class OSNews : public Module { public: - OSNews(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSNews(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); @@ -432,19 +431,19 @@ class OSNews : public Module DisplayNews(u, NEWS_RANDOM); } - EventReturn OnDatabaseRead(const std::vector<std::string> ¶ms) + EventReturn OnDatabaseRead(const std::vector<Anope::string> ¶ms) { - if (params[0] == "OS" && params.size() >= 7 && params[1] == "NEWS") + if (params[0].equals_ci("OS") && params.size() >= 7 && params[1].equals_ci("NEWS")) { - NewsItem *n = new NewsItem; - n->num = atoi(params[2].c_str()); - n->time = strtol(params[3].c_str(), NULL, 10); + NewsItem *n = new NewsItem(); + n->num = params[2].is_number_only() ? convertTo<unsigned>(params[2]) : 0; + n->time = params[3].is_number_only() ? convertTo<time_t>(params[3]) : 0; n->who = params[4]; - if (params[5] == "LOGON") + if (params[5].equals_ci("LOGON")) n->type = NEWS_LOGON; - else if (params[5] == "RANDOM") + else if (params[5].equals_ci("RANDOM")) n->type = NEWS_RANDOM; - else if (params[5] == "OPER") + else if (params[5].equals_ci("OPER")) n->type = NEWS_OPER; n->Text = params[6]; News.push_back(n); @@ -455,19 +454,19 @@ class OSNews : public Module return EVENT_CONTINUE; } - void OnDatabaseWrite(void (*Write)(const std::string &)) + void OnDatabaseWrite(void (*Write)(const Anope::string &)) { for (std::vector<NewsItem *>::iterator it = News.begin(); it != News.end(); ++it) { NewsItem *n = *it; - char buf[512]; const char* ntype; + Anope::string ntype; if (n->type == NEWS_LOGON) ntype = "LOGON"; else if (n->type == NEWS_RANDOM) ntype = "RANDOM"; else if (n->type == NEWS_OPER) ntype = "OPER"; - snprintf(buf, sizeof(buf), "OS NEWS %d %ld %s %s :%s", n->num, n->time, n->who.c_str(), ntype, n->Text.c_str()); + Anope::string buf = "OS NEWS " + stringify(n->num) + " " + stringify(n->time) + " " + n->who + " " + ntype + " :" + n->Text; Write(buf); } } diff --git a/modules/core/os_noop.cpp b/modules/core/os_noop.cpp index 51337106e..1cf480bc8 100644 --- a/modules/core/os_noop.cpp +++ b/modules/core/os_noop.cpp @@ -20,22 +20,22 @@ class CommandOSNOOP : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; - const char *server = params[1].c_str(); + Anope::string cmd = params[0]; + Anope::string server = params[1]; - if (cmd == "SET") + if (cmd.equals_ci("SET")) { - std::string reason; + Anope::string reason; /* Remove the O:lines */ ircdproto->SendSVSNOOP(server, 1); reason = "NOOP command used by " + u->nick; if (Config.WallOSNoOp) - ircdproto->SendGlobops(OperServ, "\2%s\2 used NOOP on \2%s\2", u->nick.c_str(), server); - notice_lang(Config.s_OperServ, u, OPER_NOOP_SET, server); + ircdproto->SendGlobops(OperServ, "\2%s\2 used NOOP on \2%s\2", u->nick.c_str(), server.c_str()); + notice_lang(Config.s_OperServ, u, OPER_NOOP_SET, server.c_str()); /* Kill all the IRCops of the server */ for (user_map::const_iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ) @@ -44,26 +44,26 @@ class CommandOSNOOP : public Command ++it; if (u2 && is_oper(u2) && Anope::Match(u2->server->GetName(), server, true)) - kill_user(Config.s_OperServ, u2->nick.c_str(), reason.c_str()); + kill_user(Config.s_OperServ, u2->nick, reason); } } - else if (cmd == "REVOKE") + else if (cmd.equals_ci("REVOKE")) { ircdproto->SendSVSNOOP(server, 0); - notice_lang(Config.s_OperServ, u, OPER_NOOP_REVOKE, server); + notice_lang(Config.s_OperServ, u, OPER_NOOP_REVOKE, server.c_str()); } else this->OnSyntaxError(u, ""); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_NOOP); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "NOOP", OPER_NOOP_SYNTAX); } @@ -77,7 +77,7 @@ class CommandOSNOOP : public Command class OSNOOP : public Module { public: - OSNOOP(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSNOOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_oline.cpp b/modules/core/os_oline.cpp index bceea1a49..4d90072ca 100644 --- a/modules/core/os_oline.cpp +++ b/modules/core/os_oline.cpp @@ -20,41 +20,41 @@ class CommandOSOLine : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - const char *flag = params[1].c_str(); + Anope::string nick = params[0]; + Anope::string flag = params[1]; User *u2 = NULL; /* let's check whether the user is online */ if (!(u2 = finduser(nick))) - notice_lang(Config.s_OperServ, u, NICK_X_NOT_IN_USE, nick); + notice_lang(Config.s_OperServ, u, NICK_X_NOT_IN_USE, nick.c_str()); else if (u2 && flag[0] == '+') { ircdproto->SendSVSO(Config.s_OperServ, nick, flag); u2->SetMode(OperServ, UMODE_OPER); notice_lang(Config.s_OperServ, u2, OPER_OLINE_IRCOP); - notice_lang(Config.s_OperServ, u, OPER_OLINE_SUCCESS, flag, nick); - ircdproto->SendGlobops(OperServ, "\2%s\2 used OLINE for %s", u->nick.c_str(), nick); + notice_lang(Config.s_OperServ, u, OPER_OLINE_SUCCESS, flag.c_str(), nick.c_str()); + ircdproto->SendGlobops(OperServ, "\2%s\2 used OLINE for %s", u->nick.c_str(), nick.c_str()); } else if (u2 && flag[0] == '-') { ircdproto->SendSVSO(Config.s_OperServ, nick, flag); - notice_lang(Config.s_OperServ, u, OPER_OLINE_SUCCESS, flag, nick); - ircdproto->SendGlobops(OperServ, "\2%s\2 used OLINE for %s", u->nick.c_str(), nick); + notice_lang(Config.s_OperServ, u, OPER_OLINE_SUCCESS, flag.c_str(), nick.c_str()); + ircdproto->SendGlobops(OperServ, "\2%s\2 used OLINE for %s", u->nick.c_str(), nick.c_str()); } else this->OnSyntaxError(u, ""); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_OLINE); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "OLINE", OPER_OLINE_SYNTAX); } @@ -68,7 +68,7 @@ class CommandOSOLine : public Command class OSOLine : public Module { public: - OSOLine(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSOLine(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { if (!ircd->omode) throw ModuleException("Your IRCd does not support OMODE."); diff --git a/modules/core/os_quit.cpp b/modules/core/os_quit.cpp index 1c5a073bc..fb8fce2fd 100644 --- a/modules/core/os_quit.cpp +++ b/modules/core/os_quit.cpp @@ -21,21 +21,17 @@ class CommandOSQuit : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - quitmsg = new char[28 + u->nick.length()]; - if (!quitmsg) - quitmsg = "QUIT command received, but out of memory!"; - else - sprintf(const_cast<char *>(quitmsg), "QUIT command received from %s", u->nick.c_str()); // XXX we know this is safe, but.. + quitmsg = "QUIT command received from " + u->nick; if (Config.GlobalOnCycle) - oper_global(NULL, "%s", Config.GlobalOnCycleMessage); + oper_global("", "%s", Config.GlobalOnCycleMessage.c_str()); quitting = 1; return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_QUIT); return true; @@ -50,7 +46,7 @@ class CommandOSQuit : public Command class OSQuit : public Module { public: - OSQuit(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSQuit(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_reload.cpp b/modules/core/os_reload.cpp index 15a45d0a2..4e64bba8d 100644 --- a/modules/core/os_reload.cpp +++ b/modules/core/os_reload.cpp @@ -20,15 +20,11 @@ class CommandOSReload : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { if (!read_config(1)) { - quitmsg = new char[28 + u->nick.length()]; - if (!quitmsg) - quitmsg = "Error during the reload of the configuration file, but out of memory!"; - else - sprintf(const_cast<char *>(quitmsg), /* XXX */ "Error during the reload of the configuration file!"); + quitmsg = "Error during the reload of the configuration file!"; quitting = 1; } @@ -37,7 +33,7 @@ class CommandOSReload : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_RELOAD); return true; @@ -52,7 +48,7 @@ class CommandOSReload : public Command class OSReload : public Module { public: - OSReload(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSReload(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_restart.cpp b/modules/core/os_restart.cpp index 04c6d02d6..ae7075661 100644 --- a/modules/core/os_restart.cpp +++ b/modules/core/os_restart.cpp @@ -20,22 +20,18 @@ class CommandOSRestart : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - quitmsg = new char[31 + u->nick.length()]; - if (!quitmsg) - quitmsg = "RESTART command received, but out of memory!"; - else - sprintf(const_cast<char *>(quitmsg), /* XXX */ "RESTART command received from %s", u->nick.c_str()); + quitmsg = "RESTART command received from " + u->nick; if (Config.GlobalOnCycle) - oper_global(NULL, "%s", Config.GlobalOnCycleMessage); + oper_global("", "%s", Config.GlobalOnCycleMessage.c_str()); /* raise(SIGHUP); */ do_restart_services(); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_RESTART); return true; @@ -50,7 +46,7 @@ class CommandOSRestart : public Command class OSRestart : public Module { public: - OSRestart(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSRestart(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_session.cpp b/modules/core/os_session.cpp index 4ec73460c..879dc6cf7 100644 --- a/modules/core/os_session.cpp +++ b/modules/core/os_session.cpp @@ -19,7 +19,7 @@ class ExceptionDelCallback : public NumberList User *u; unsigned Deleted; public: - ExceptionDelCallback(User *_u, const std::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) + ExceptionDelCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) { } @@ -35,7 +35,7 @@ class ExceptionDelCallback : public NumberList virtual void HandleNumber(unsigned Number) { - if (Number > nexceptions) + if (Number > exceptions.size()) return; ++Deleted; @@ -45,29 +45,26 @@ class ExceptionDelCallback : public NumberList static void DoDel(User *u, unsigned index) { - FOREACH_MOD(I_OnExceptionDel, OnExceptionDel(u, &exceptions[index])); + FOREACH_MOD(I_OnExceptionDel, OnExceptionDel(u, exceptions[index])); - delete [] exceptions[index].mask; - delete [] exceptions[index].reason; - --nexceptions; - memmove(exceptions + index, exceptions + index + 1, sizeof(Exception) * (nexceptions - index)); - exceptions = static_cast<Exception *>(srealloc(exceptions, sizeof(Exception) * nexceptions)); + delete exceptions[index]; + exceptions.erase(exceptions.begin() + index); } }; class ExceptionListCallback : public NumberList { protected: - User *u; + User *u; bool SentHeader; public: - ExceptionListCallback(User *_u, const std::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) + ExceptionListCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) { } virtual void HandleNumber(unsigned Number) { - if (Number > nexceptions) + if (Number > exceptions.size()) return; if (!SentHeader) @@ -82,23 +79,23 @@ class ExceptionListCallback : public NumberList static void DoList(User *u, unsigned index) { - if (index >= nexceptions) + if (index >= exceptions.size()) return; - notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_LIST_FORMAT, index + 1, exceptions[index].limit, exceptions[index].mask); + notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_LIST_FORMAT, index + 1, exceptions[index]->limit, exceptions[index]->mask.c_str()); } }; class ExceptionViewCallback : public ExceptionListCallback { public: - ExceptionViewCallback(User *_u, const std::string &numlist) : ExceptionListCallback(_u, numlist) + ExceptionViewCallback(User *_u, const Anope::string &numlist) : ExceptionListCallback(_u, numlist) { } void HandleNumber(unsigned Number) { - if (Number > nexceptions) + if (Number > exceptions.size()) return; if (!SentHeader) @@ -112,31 +109,31 @@ class ExceptionViewCallback : public ExceptionListCallback static void DoList(User *u, unsigned index) { - if (index >= nexceptions) + if (index >= exceptions.size()) return; - char timebuf[32], expirebuf[256]; + char timebuf[32]; struct tm tm; time_t t = time(NULL); - tm = *localtime(exceptions[index].time ? &exceptions[index].time : &t); + tm = *localtime(exceptions[index]->time ? &exceptions[index]->time : &t); strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm); - expire_left(u->Account(), expirebuf, sizeof(expirebuf), exceptions[index].expires); + Anope::string expirebuf = expire_left(u->Account(), exceptions[index]->expires); - notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_VIEW_FORMAT, index + 1, exceptions[index].mask, exceptions[index].who ? exceptions[index].who : "<unknown>", timebuf, expirebuf, exceptions[index].limit, exceptions[index].reason); + notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_VIEW_FORMAT, index + 1, exceptions[index]->mask.c_str(), !exceptions[index]->who.empty() ? exceptions[index]->who.c_str() : "<unknown>", timebuf, expirebuf.c_str(), exceptions[index]->limit, exceptions[index]->reason.c_str()); } }; class CommandOSSession : public Command { private: - CommandReturn DoList(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoList(User *u, const std::vector<Anope::string> ¶ms) { int mincount; - const char *param = params[1].c_str(); + Anope::string param = params[1]; - if ((mincount = atoi(param)) <= 1) + if ((mincount = (param.is_number_only() ? convertTo<int>(param) : 0)) <= 1) notice_lang(Config.s_OperServ, u, OPER_SESSION_INVALID_THRESHOLD); else { @@ -148,23 +145,24 @@ class CommandOSSession : public Command Session *session = it->second; if (session->count >= mincount) - notice_lang(Config.s_OperServ, u, OPER_SESSION_LIST_FORMAT, session->count, session->host); + notice_lang(Config.s_OperServ, u, OPER_SESSION_LIST_FORMAT, session->count, session->host.c_str()); } } return MOD_CONT; } - CommandReturn DoView(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoView(User *u, const std::vector<Anope::string> ¶ms) { - const char *param = params[1].c_str(); + Anope::string param = params[1]; Session *session = findsession(param); if (!session) - notice_lang(Config.s_OperServ, u, OPER_SESSION_NOT_FOUND, param); - else { + notice_lang(Config.s_OperServ, u, OPER_SESSION_NOT_FOUND, param.c_str()); + else + { Exception *exception = find_host_exception(param); - notice_lang(Config.s_OperServ, u, OPER_SESSION_VIEW_FORMAT, param, session->count, exception ? exception-> limit : Config.DefSessionLimit); + notice_lang(Config.s_OperServ, u, OPER_SESSION_VIEW_FORMAT, param.c_str(), session->count, exception ? exception-> limit : Config.DefSessionLimit); } return MOD_CONT; @@ -174,9 +172,9 @@ class CommandOSSession : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; + Anope::string cmd = params[0]; if (!Config.LimitSessions) { @@ -184,22 +182,22 @@ class CommandOSSession : public Command return MOD_CONT; } - if (cmd == "LIST") + if (cmd.equals_ci("LIST")) return this->DoList(u, params); - else if (cmd == "VIEW") + else if (cmd.equals_ci("VIEW")) return this->DoView(u, params); else this->OnSyntaxError(u, ""); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_SESSION); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "SESSION", OPER_SESSION_LIST_SYNTAX); } @@ -213,39 +211,38 @@ class CommandOSSession : public Command class CommandOSException : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) { - const char *mask, *expiry, *limitstr; - char reason[BUFSIZE]; + Anope::string mask, expiry, limitstr; unsigned last_param = 3; int x; - mask = params.size() > 1 ? params[1].c_str() : NULL; - if (mask && *mask == '+') + mask = params.size() > 1 ? params[1] : ""; + if (!mask.empty() && mask[0] == '+') { expiry = mask; - mask = params.size() > 2 ? params[2].c_str() : NULL; + mask = params.size() > 2 ? params[2] : ""; last_param = 4; } - else - expiry = NULL; - limitstr = params.size() > last_param - 1 ? params[last_param - 1].c_str() : NULL; + limitstr = params.size() > last_param - 1 ? params[last_param - 1] : ""; if (params.size() <= last_param) { this->OnSyntaxError(u, "ADD"); return MOD_CONT; } - snprintf(reason, sizeof(reason), "%s%s%s", params[last_param].c_str(), last_param == 3 && params.size() > 4 ? " " : "", last_param == 3 && params.size() > 4 ? params[4].c_str() : ""); - if (!*reason) + Anope::string reason = params[last_param]; + if (last_param == 3 && params.size() > 4) + reason += " " + params[4]; + if (reason.empty()) { this->OnSyntaxError(u, "ADD"); return MOD_CONT; } - time_t expires = expiry ? dotime(expiry) : Config.ExceptionExpiry; + time_t expires = !expiry.empty() ? dotime(expiry) : Config.ExceptionExpiry; if (expires < 0) { notice_lang(Config.s_OperServ, u, BAD_EXPIRY_TIME); @@ -254,7 +251,7 @@ class CommandOSException : public Command else if (expires > 0) expires += time(NULL); - int limit = limitstr && isdigit(*limitstr) ? atoi(limitstr) : -1; + int limit = !limitstr.empty() && limitstr.is_number_only() ? convertTo<int>(limitstr) : -1; if (limit < 0 || limit > static_cast<int>(Config.MaxSessionLimit)) { @@ -263,16 +260,16 @@ class CommandOSException : public Command } else { - if (strchr(mask, '!') || strchr(mask, '@')) + if (mask.find('!') == Anope::string::npos || mask.find('@') == Anope::string::npos) { notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_INVALID_HOSTMASK); return MOD_CONT; } - x = exception_add(u, mask, limit, reason, u->nick.c_str(), expires); + x = exception_add(u, mask, limit, reason, u->nick, expires); if (x == 1) - notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_ADDED, mask, limit); + notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_ADDED, mask.c_str(), limit); if (readonly) notice_lang(Config.s_OperServ, u, READ_ONLY_MODE); @@ -281,93 +278,63 @@ class CommandOSException : public Command return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) { - const char *mask = params.size() > 1 ? params[1].c_str() : NULL; - int i; + Anope::string mask = params.size() > 1 ? params[1] : ""; - if (!mask) + if (mask.empty()) { this->OnSyntaxError(u, "DEL"); return MOD_CONT; } - if (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask)) + if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { ExceptionDelCallback list(u, mask); list.Process(); } else { - int deleted = 0; - - for (i = 0; i < nexceptions; ++i) - if (!stricmp(mask, exceptions[i].mask)) + unsigned i = 0, end = exceptions.size(); + for (; i < end; ++i) + if (mask.equals_ci(exceptions[i]->mask)) { ExceptionDelCallback::DoDel(u, i); - notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_DELETED, mask); - deleted = 1; + notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_DELETED, mask.c_str()); break; } - if (!deleted && i == nexceptions) - notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_NOT_FOUND, mask); + if (i == end) + notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_NOT_FOUND, mask.c_str()); } - /* Renumber the exception list. I don't believe in having holes in - * lists - it makes code more complex, harder to debug and we end up - * with huge index numbers. Imho, fixed numbering is only beneficial - * when one doesn't have range capable manipulation. -TheShadow */ - - for (i = 0; i < nexceptions; ++i) - exceptions[i].num = i; - if (readonly) notice_lang(Config.s_OperServ, u, READ_ONLY_MODE); return MOD_CONT; } - CommandReturn DoMove(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoMove(User *u, const std::vector<Anope::string> ¶ms) { - Exception *exception; - const char *n1str = params.size() > 1 ? params[1].c_str() : NULL; /* From position */ - const char *n2str = params.size() > 2 ? params[2].c_str() : NULL; /* To position */ - int n1, n2, i; + Anope::string n1str = params.size() > 1 ? params[1] : ""; /* From position */ + Anope::string n2str = params.size() > 2 ? params[2] : ""; /* To position */ + int n1, n2; - if (!n2str) + if (n2str.empty()) { this->OnSyntaxError(u, "MOVE"); return MOD_CONT; } - n1 = atoi(n1str) - 1; - n2 = atoi(n2str) - 1; + n1 = n1str.is_number_only() ? convertTo<int>(n1str) - 1 : -1; + n2 = n2str.is_number_only() ? convertTo<int>(n2str) - 1 : -1; - if (n1 >= 0 && n1 < nexceptions && n2 >= 0 && n2 < nexceptions && n1 != n2) + if (n1 >= 0 && n1 < exceptions.size() && n2 >= 0 && n2 < exceptions.size() && n1 != n2) { - exception = static_cast<Exception *>(smalloc(sizeof(Exception))); - memcpy(exception, &exceptions[n1], sizeof(Exception)); - - if (n1 < n2) - { - /* Shift upwards */ - memmove(&exceptions[n1], &exceptions[n1 + 1], sizeof(Exception) * (n2 - n1)); - memmove(&exceptions[n2], exception, sizeof(Exception)); - } - else - { - /* Shift downwards */ - memmove(&exceptions[n2 + 1], &exceptions[n2], sizeof(Exception) * (n1 - n2)); - memmove(&exceptions[n2], exception, sizeof(Exception)); - } - - free(exception); - - notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_MOVED, exceptions[n1].mask, n1 + 1, n2 + 1); + Exception *temp = exceptions[n1]; + exceptions[n1] = exceptions[n2]; + exceptions[n2] = temp; - /* Renumber the exception list. See DoDel() above for why. */ - for (i = 0; i < nexceptions; ++i) - exceptions[i].num = i; + notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_MOVED, exceptions[n1]->mask.c_str(), n1 + 1, n2 + 1); if (readonly) notice_lang(Config.s_OperServ, u, READ_ONLY_MODE); @@ -378,13 +345,12 @@ class CommandOSException : public Command return MOD_CONT; } - CommandReturn DoList(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoList(User *u, const std::vector<Anope::string> ¶ms) { - int i; expire_exceptions(); - const char *mask = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string mask = params.size() > 1 ? params[1] : ""; - if (mask && strspn(mask, "1234567890,-") == strlen(mask)) + if (!mask.empty() && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { ExceptionListCallback list(u, mask); list.Process(); @@ -393,8 +359,8 @@ class CommandOSException : public Command { bool SentHeader = false; - for (i = 0; i < nexceptions; ++i) - if (!mask || Anope::Match(exceptions[i].mask, mask, false)) + for (unsigned i = 0, end = exceptions.size(); i < end; ++i) + if (mask.empty() || Anope::Match(exceptions[i]->mask, mask)) { if (!SentHeader) { @@ -413,13 +379,12 @@ class CommandOSException : public Command return MOD_CONT; } - CommandReturn DoView(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoView(User *u, const std::vector<Anope::string> ¶ms) { - int i; expire_exceptions(); - const char *mask = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string mask = params.size() > 1 ? params[1] : ""; - if (mask && strspn(mask, "1234567890,-") == strlen(mask)) + if (!mask.empty() && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { ExceptionViewCallback list(u, mask); list.Process(); @@ -428,8 +393,8 @@ class CommandOSException : public Command { bool SentHeader = false; - for (i = 0; i < nexceptions; ++i) - if (!mask || Anope::Match(exceptions[i].mask, mask, false)) + for (unsigned i = 0, end = exceptions.size(); i < end; ++i) + if (mask.empty() || Anope::Match(exceptions[i]->mask, mask)) { if (!SentHeader) { @@ -451,9 +416,9 @@ class CommandOSException : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; + Anope::string cmd = params[0]; if (!Config.LimitSessions) { @@ -461,28 +426,28 @@ class CommandOSException : public Command return MOD_CONT; } - if (cmd == "ADD") + if (cmd.equals_ci("ADD")) return this->DoAdd(u, params); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) return this->DoDel(u, params); - else if (cmd == "MOVE") + else if (cmd.equals_ci("MOVE")) return this->DoMove(u, params); - else if (cmd == "LIST") + else if (cmd.equals_ci("LIST")) return this->DoList(u, params); - else if (cmd == "VIEW") + else if (cmd.equals_ci("VIEW")) return this->DoView(u, params); else this->OnSyntaxError(u, ""); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_EXCEPTION); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "EXCEPTION", OPER_EXCEPTION_SYNTAX); } @@ -496,7 +461,7 @@ class CommandOSException : public Command class OSSession : public Module { public: - OSSession(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSSession(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_set.cpp b/modules/core/os_set.cpp index 06a5f6886..4bfdaa68a 100644 --- a/modules/core/os_set.cpp +++ b/modules/core/os_set.cpp @@ -34,9 +34,9 @@ class CommandOSSet : public Command return MOD_CONT; } - CommandReturn DoSetIgnore(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoSetIgnore(User *u, const std::vector<Anope::string> ¶ms) { - ci::string setting = params.size() > 1 ? params[1] : ""; + Anope::string setting = params.size() > 1 ? params[1] : ""; if (setting.empty()) { @@ -44,12 +44,12 @@ class CommandOSSet : public Command return MOD_CONT; } - if (setting == "ON") + if (setting.equals_ci("ON")) { allow_ignore = 1; notice_lang(Config.s_OperServ, u, OPER_SET_IGNORE_ON); } - else if (setting == "OFF") + else if (setting.equals_ci("OFF")) { allow_ignore = 0; notice_lang(Config.s_OperServ, u, OPER_SET_IGNORE_OFF); @@ -60,9 +60,9 @@ class CommandOSSet : public Command return MOD_CONT; } - CommandReturn DoSetReadOnly(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoSetReadOnly(User *u, const std::vector<Anope::string> ¶ms) { - ci::string setting = params.size() > 1 ? params[1] : ""; + Anope::string setting = params.size() > 1 ? params[1] : ""; if (setting.empty()) { @@ -70,14 +70,14 @@ class CommandOSSet : public Command return MOD_CONT; } - if (setting == "ON") + if (setting.equals_ci("ON")) { readonly = 1; Alog() << "Read-only mode activated"; close_log(); notice_lang(Config.s_OperServ, u, OPER_SET_READONLY_ON); } - else if (setting == "OFF") + else if (setting.equals_ci("OFF")) { readonly = 0; open_log(); @@ -90,9 +90,9 @@ class CommandOSSet : public Command return MOD_CONT; } - CommandReturn DoSetLogChan(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoSetLogChan(User *u, const std::vector<Anope::string> ¶ms) { - ci::string setting = params.size() > 1 ? params[1] : ""; + Anope::string setting = params.size() > 1 ? params[1] : ""; Channel *c; if (setting.empty()) @@ -107,7 +107,7 @@ class CommandOSSet : public Command * * -jester */ - if (Config.LogChannel && setting == "ON") + if (!Config.LogChannel.empty() && setting.equals_ci("ON")) { if (ircd->join2msg) { @@ -119,9 +119,9 @@ class CommandOSSet : public Command } LogChan = true; Alog() << "Now sending log messages to " << Config.LogChannel; - notice_lang(Config.s_OperServ, u, OPER_SET_LOGCHAN_ON, Config.LogChannel); + notice_lang(Config.s_OperServ, u, OPER_SET_LOGCHAN_ON, Config.LogChannel.c_str()); } - else if (Config.LogChannel && setting == "OFF") + else if (!Config.LogChannel.empty() && setting.equals_ci("OFF")) { Alog() << "No longer sending log messages to a channel"; c = findchan(Config.LogChannel); @@ -136,9 +136,9 @@ class CommandOSSet : public Command return MOD_CONT; } - CommandReturn DoSetSuperAdmin(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoSetSuperAdmin(User *u, const std::vector<Anope::string> ¶ms) { - ci::string setting = params.size() > 1 ? params[1] : ""; + Anope::string setting = params.size() > 1 ? params[1] : ""; if (setting.empty()) { @@ -153,14 +153,14 @@ class CommandOSSet : public Command **/ if (!Config.SuperAdmin) notice_lang(Config.s_OperServ, u, OPER_SUPER_ADMIN_NOT_ENABLED); - else if (setting == "ON") + else if (setting.equals_ci("ON")) { u->isSuperAdmin = 1; notice_lang(Config.s_OperServ, u, OPER_SUPER_ADMIN_ON); Alog() << Config.s_OperServ << ": " << u->nick << " is a SuperAdmin"; ircdproto->SendGlobops(OperServ, getstring(OPER_SUPER_ADMIN_WALL_ON), u->nick.c_str()); } - else if (setting == "OFF") + else if (setting.equals_ci("OFF")) { u->isSuperAdmin = 0; notice_lang(Config.s_OperServ, u, OPER_SUPER_ADMIN_OFF); @@ -173,9 +173,9 @@ class CommandOSSet : public Command return MOD_CONT; } - CommandReturn DoSetDebug(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoSetDebug(User *u, const std::vector<Anope::string> ¶ms) { - ci::string setting = params.size() > 1 ? params[1] : ""; + Anope::string setting = params.size() > 1 ? params[1] : ""; if (setting.empty()) { @@ -183,21 +183,21 @@ class CommandOSSet : public Command return MOD_CONT; } - if (setting == "ON") + if (setting.equals_ci("ON")) { debug = 1; Alog() << "Debug mode activated"; notice_lang(Config.s_OperServ, u, OPER_SET_DEBUG_ON); } - else if (setting == "OFF" || (setting[0] == '0' && !atoi(setting.c_str()))) + else if (setting.equals_ci("OFF") || (setting[0] == '0' && setting.is_number_only() && !convertTo<int>(setting))) { Alog() << "Debug mode deactivated"; debug = 0; notice_lang(Config.s_OperServ, u, OPER_SET_DEBUG_OFF); } - else if (isdigit(setting[0]) && atoi(setting.c_str()) > 0) + else if (setting.is_number_only() && convertTo<int>(setting) > 0) { - debug = atoi(setting.c_str()); + debug = convertTo<int>(setting); Alog() << "Debug mode activated (level " << debug << ")"; notice_lang(Config.s_OperServ, u, OPER_SET_DEBUG_LEVEL, debug); } @@ -207,9 +207,9 @@ class CommandOSSet : public Command return MOD_CONT; } - CommandReturn DoSetNoExpire(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoSetNoExpire(User *u, const std::vector<Anope::string> ¶ms) { - ci::string setting = params.size() > 1 ? params[1] : ""; + Anope::string setting = params.size() > 1 ? params[1] : ""; if (setting.empty()) { @@ -217,13 +217,13 @@ class CommandOSSet : public Command return MOD_CONT; } - if (setting == "ON") + if (setting.equals_ci("ON")) { noexpire = 1; Alog() << "No expire mode activated"; notice_lang(Config.s_OperServ, u, OPER_SET_NOEXPIRE_ON); } - else if (setting == "OFF") + else if (setting.equals_ci("OFF")) { noexpire = 0; Alog() << "No expire mode deactivated"; @@ -239,46 +239,46 @@ class CommandOSSet : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string option = params[0]; + Anope::string option = params[0]; - if (option == "LIST") + if (option.equals_ci("LIST")) return this->DoList(u); - else if (option == "IGNORE") + else if (option.equals_ci("IGNORE")) return this->DoSetIgnore(u, params); - else if (option == "READONLY") + else if (option.equals_ci("READONLY")) return this->DoSetReadOnly(u, params); - else if (option == "LOGCHAN") + else if (option.equals_ci("LOGCHAN")) return this->DoSetLogChan(u, params); - else if (option == "SUPERADMIN") + else if (option.equals_ci("SUPERADMIN")) return this->DoSetSuperAdmin(u, params); - else if (option == "DEBUG") + else if (option.equals_ci("DEBUG")) return this->DoSetDebug(u, params); - else if (option == "NOEXPIRE") + else if (option.equals_ci("NOEXPIRE")) return this->DoSetNoExpire(u, params); else notice_lang(Config.s_OperServ, u, OPER_SET_UNKNOWN_OPTION, option.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (subcommand.empty()) notice_help(Config.s_OperServ, u, OPER_HELP_SET); - else if (subcommand == "LIST") + else if (subcommand.equals_ci("LIST")) notice_help(Config.s_OperServ, u, OPER_HELP_SET_LIST); - else if (subcommand == "READONLY") + else if (subcommand.equals_ci("READONLY")) notice_help(Config.s_OperServ, u, OPER_HELP_SET_READONLY); - else if (subcommand == "LOGCHAN") + else if (subcommand.equals_ci("LOGCHAN")) notice_help(Config.s_OperServ, u, OPER_HELP_SET_LOGCHAN); - else if (subcommand == "DEBUG") + else if (subcommand.equals_ci("DEBUG")) notice_help(Config.s_OperServ, u, OPER_HELP_SET_DEBUG); - else if (subcommand == "NOEXPIRE") + else if (subcommand.equals_ci("NOEXPIRE")) notice_help(Config.s_OperServ, u, OPER_HELP_SET_NOEXPIRE); - else if (subcommand == "IGNORE") + else if (subcommand.equals_ci("IGNORE")) notice_help(Config.s_OperServ, u, OPER_HELP_SET_IGNORE); - else if (subcommand == "SUPERADMIN") + else if (subcommand.equals_ci("SUPERADMIN")) notice_help(Config.s_OperServ, u, OPER_HELP_SET_SUPERADMIN); else return false; @@ -286,7 +286,7 @@ class CommandOSSet : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "SET", OPER_SET_SYNTAX); } @@ -300,7 +300,7 @@ class CommandOSSet : public Command class OSSet : public Module { public: - OSSet(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_shutdown.cpp b/modules/core/os_shutdown.cpp index acdddac8e..afd04d1a9 100644 --- a/modules/core/os_shutdown.cpp +++ b/modules/core/os_shutdown.cpp @@ -20,21 +20,17 @@ class CommandOSShutdown : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - quitmsg = new char[32 + u->nick.length()]; - if (!quitmsg) - quitmsg = "SHUTDOWN command received, but out of memory!"; - else - sprintf(const_cast<char *>(quitmsg), /* XXX */ "SHUTDOWN command received from %s", u->nick.c_str()); + quitmsg = "SHUTDOWN command received from " + u->nick; if (Config.GlobalOnCycle) - oper_global(NULL, "%s", Config.GlobalOnCycleMessage); + oper_global("", "%s", Config.GlobalOnCycleMessage.c_str()); shutting_down = 1; return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_SHUTDOWN); return true; @@ -49,7 +45,7 @@ class CommandOSShutdown : public Command class OSShutdown : public Module { public: - OSShutdown(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSShutdown(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_snline.cpp b/modules/core/os_snline.cpp index 6dd252bec..c401a40c5 100644 --- a/modules/core/os_snline.cpp +++ b/modules/core/os_snline.cpp @@ -19,7 +19,7 @@ class SNLineDelCallback : public NumberList User *u; unsigned Deleted; public: - SNLineDelCallback(User *_u, const std::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) + SNLineDelCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) { } @@ -27,7 +27,7 @@ class SNLineDelCallback : public NumberList { if (!Deleted) notice_lang(Config.s_OperServ, u, OPER_SNLINE_NO_MATCH); - else if (Deleted == 0) + else if (Deleted == 1) notice_lang(Config.s_OperServ, u, OPER_SNLINE_DELETED_ONE); else notice_lang(Config.s_OperServ, u, OPER_SNLINE_DELETED_SEVERAL, Deleted); @@ -56,7 +56,7 @@ class SNLineListCallback : public NumberList User *u; bool SentHeader; public: - SNLineListCallback(User *_u, const std::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) + SNLineListCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) { } @@ -91,7 +91,7 @@ class SNLineListCallback : public NumberList class SNLineViewCallback : public SNLineListCallback { public: - SNLineViewCallback(User *_u, const std::string &numlist) : SNLineListCallback(_u, numlist) + SNLineViewCallback(User *_u, const Anope::string &numlist) : SNLineListCallback(_u, numlist) { } @@ -113,41 +113,38 @@ class SNLineViewCallback : public SNLineListCallback static void DoList(User *u, XLine *x, unsigned Number) { - char timebuf[32], expirebuf[256]; + char timebuf[32]; struct tm tm; tm = *localtime(&x->Created); strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm); - expire_left(u->Account(), expirebuf, sizeof(expirebuf), x->Expires); - notice_lang(Config.s_OperServ, u, OPER_SNLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, expirebuf, x->Reason.c_str()); + Anope::string expirebuf = expire_left(u->Account(), x->Expires); + notice_lang(Config.s_OperServ, u, OPER_SNLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, expirebuf.c_str(), x->Reason.c_str()); } }; class CommandOSSNLine : public Command { private: - CommandReturn OnAdd(User *u, const std::vector<ci::string> ¶ms) + CommandReturn OnAdd(User *u, const std::vector<Anope::string> ¶ms) { unsigned last_param = 2; - const char *param, *expiry; - char rest[BUFSIZE]; + Anope::string param, expiry; time_t expires; - param = params.size() > 1 ? params[1].c_str() : NULL; - if (param && *param == '+') + param = params.size() > 1 ? params[1] : ""; + if (!param.empty() && param[0] == '+') { expiry = param; - param = params.size() > 2 ? params[2].c_str() : NULL; + param = params.size() > 2 ? params[2] : ""; last_param = 3; } - else - expiry = NULL; - expires = expiry ? dotime(expiry) : Config.SNLineExpiry; + expires = !expiry.empty() ? dotime(expiry) : Config.SNLineExpiry; /* If the expiry given does not contain a final letter, it's in days, * said the doc. Ah well. */ - if (expiry && isdigit(expiry[strlen(expiry) - 1])) + if (!expiry.empty() && isdigit(expiry[expiry.length() - 1])) expires *= 86400; /* Do not allow less than a minute expiry time */ if (expires && expires < 60) @@ -158,30 +155,33 @@ class CommandOSSNLine : public Command else if (expires > 0) expires += time(NULL); - if (!param) + if (param.empty()) { this->OnSyntaxError(u, "ADD"); return MOD_CONT; } - snprintf(rest, sizeof(rest), "%s%s%s", param, params.size() > last_param ? " " : "", params.size() > last_param ? params[last_param].c_str() : ""); - if (std::string(rest).find(':') == std::string::npos) + Anope::string rest = param; + if (params.size() > last_param) + rest += " " + params[last_param]; + + if (rest.find(':') == Anope::string::npos) { this->OnSyntaxError(u, "ADD"); return MOD_CONT; } sepstream sep(rest, ':'); - ci::string mask; + Anope::string mask; sep.GetToken(mask); - std::string reason = sep.GetRemaining(); + Anope::string reason = sep.GetRemaining(); if (!mask.empty() && !reason.empty()) { /* Clean up the last character of the mask if it is a space * See bug #761 */ - unsigned masklen = mask.size(); + unsigned masklen = mask.length(); if (mask[masklen - 1] == ' ') mask.erase(masklen - 1); @@ -194,14 +194,14 @@ class CommandOSSNLine : public Command if (Config.WallOSSNLine) { - char buf[128]; + Anope::string buf; if (!expires) - strcpy(buf, "does not expire"); + buf = "does not expire"; else { int wall_expiry = expires - time(NULL); - const char *s = NULL; + Anope::string s; if (wall_expiry >= 86400) { @@ -219,10 +219,10 @@ class CommandOSSNLine : public Command s = "minute"; } - snprintf(buf, sizeof(buf), "expires in %d %s%s", wall_expiry, s, wall_expiry == 1 ? "" : "s"); + buf = "expires in " + stringify(wall_expiry) + " " + s + (wall_expiry == 1 ? "" : "s"); } - ircdproto->SendGlobops(findbot(Config.s_OperServ), "%s added an SNLINE for %s (%s)", u->nick.c_str(), mask.c_str(), buf); + ircdproto->SendGlobops(findbot(Config.s_OperServ), "%s added an SNLINE for %s (%s)", u->nick.c_str(), mask.c_str(), buf.c_str()); } if (readonly) @@ -235,7 +235,7 @@ class CommandOSSNLine : public Command return MOD_CONT; } - CommandReturn OnDel(User *u, const std::vector<ci::string> ¶ms) + CommandReturn OnDel(User *u, const std::vector<Anope::string> ¶ms) { if (SNLine->GetList().empty()) { @@ -243,7 +243,7 @@ class CommandOSSNLine : public Command return MOD_CONT; } - const ci::string mask = params.size() > 1 ? params[1] : ""; + Anope::string mask = params.size() > 1 ? params[1] : ""; if (mask.empty()) { @@ -251,9 +251,9 @@ class CommandOSSNLine : public Command return MOD_CONT; } - if (isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SNLineDelCallback list(u, mask.c_str()); + SNLineDelCallback list(u, mask); list.Process(); } else @@ -278,7 +278,7 @@ class CommandOSSNLine : public Command return MOD_CONT; } - CommandReturn OnList(User *u, const std::vector<ci::string> ¶ms) + CommandReturn OnList(User *u, const std::vector<Anope::string> ¶ms) { if (SNLine->GetList().empty()) { @@ -286,11 +286,11 @@ class CommandOSSNLine : public Command return MOD_CONT; } - const ci::string mask = params.size() > 1 ? params[1] : ""; + Anope::string mask = params.size() > 1 ? params[1] : ""; - if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SNLineListCallback list(u, mask.c_str()); + SNLineListCallback list(u, mask); list.Process(); } else @@ -301,7 +301,7 @@ class CommandOSSNLine : public Command { XLine *x = SNLine->GetEntry(i); - if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) + if (mask.empty() || mask.equals_ci(x->Mask) || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -322,7 +322,7 @@ class CommandOSSNLine : public Command return MOD_CONT; } - CommandReturn OnView(User *u, const std::vector<ci::string> ¶ms) + CommandReturn OnView(User *u, const std::vector<Anope::string> ¶ms) { if (SNLine->GetList().empty()) { @@ -330,11 +330,11 @@ class CommandOSSNLine : public Command return MOD_CONT; } - const ci::string mask = params.size() > 1 ? params[1] : ""; + Anope::string mask = params.size() > 1 ? params[1] : ""; - if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SNLineViewCallback list(u, mask.c_str()); + SNLineViewCallback list(u, mask); list.Process(); } else @@ -345,7 +345,7 @@ class CommandOSSNLine : public Command { XLine *x = SNLine->GetEntry(i); - if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) + if (mask.empty() || mask.equals_ci(x->Mask) || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -377,32 +377,32 @@ class CommandOSSNLine : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; + Anope::string cmd = params[0]; - if (cmd == "ADD") + if (cmd.equals_ci("ADD")) return this->OnAdd(u, params); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) return this->OnDel(u, params); - else if (cmd == "LIST") + else if (cmd.equals_ci("LIST")) return this->OnList(u, params); - else if (cmd == "VIEW") + else if (cmd.equals_ci("VIEW")) return this->OnView(u, params); - else if (cmd == "CLEAR") + else if (cmd.equals_ci("CLEAR")) return this->OnClear(u); else this->OnSyntaxError(u, ""); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_SNLINE); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "SNLINE", OPER_SNLINE_SYNTAX); } @@ -416,7 +416,7 @@ class CommandOSSNLine : public Command class OSSNLine : public Module { public: - OSSNLine(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSSNLine(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { if (!ircd->snline) throw ModuleException("Your IRCd does not support SNLine"); diff --git a/modules/core/os_sqline.cpp b/modules/core/os_sqline.cpp index 748625d26..c2e446b6b 100644 --- a/modules/core/os_sqline.cpp +++ b/modules/core/os_sqline.cpp @@ -18,7 +18,7 @@ class SQLineDelCallback : public NumberList User *u; unsigned Deleted; public: - SQLineDelCallback(User *_u, const std::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) + SQLineDelCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) { } @@ -55,7 +55,7 @@ class SQLineListCallback : public NumberList User *u; bool SentHeader; public: - SQLineListCallback(User *_u, const std::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) + SQLineListCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) { } @@ -90,7 +90,7 @@ class SQLineListCallback : public NumberList class SQLineViewCallback : public SQLineListCallback { public: - SQLineViewCallback(User *_u, const std::string &numlist) : SQLineListCallback(_u, numlist) + SQLineViewCallback(User *_u, const Anope::string &numlist) : SQLineListCallback(_u, numlist) { } @@ -112,45 +112,41 @@ class SQLineViewCallback : public SQLineListCallback static void DoList(User *u, XLine *x, unsigned Number) { - char timebuf[32], expirebuf[256]; + char timebuf[32]; struct tm tm; tm = *localtime(&x->Created); strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm); - expire_left(u->Account(), expirebuf, sizeof(expirebuf), x->Expires); - notice_lang(Config.s_OperServ, u, OPER_SQLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, expirebuf, x->Reason.c_str()); + Anope::string expirebuf = expire_left(u->Account(), x->Expires); + notice_lang(Config.s_OperServ, u, OPER_SQLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, expirebuf.c_str(), x->Reason.c_str()); } }; - class CommandOSSQLine : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) { unsigned last_param = 2; - const char *expiry, *mask; - char reason[BUFSIZE]; + Anope::string expiry, mask; time_t expires; - mask = params.size() > 1 ? params[1].c_str() : NULL; - if (mask && *mask == '+') + mask = params.size() > 1 ? params[1] : ""; + if (!mask.empty() && mask[0] == '+') { expiry = mask; - mask = params.size() > 2 ? params[2].c_str() : NULL; + mask = params.size() > 2 ? params[2] : ""; last_param = 3; } - else - expiry = NULL; - expires = expiry ? dotime(expiry) : Config.SQLineExpiry; + expires = !expiry.empty() ? dotime(expiry) : Config.SQLineExpiry; /* If the expiry given does not contain a final letter, it's in days, * said the doc. Ah well. */ - if (expiry && isdigit(expiry[strlen(expiry) - 1])) + if (!expiry.empty() && isdigit(expiry[expiry.length() - 1])) expires *= 86400; /* Do not allow less than a minute expiry time */ - if (expires != 0 && expires < 60) + if (expires && expires < 60) { notice_lang(Config.s_OperServ, u, BAD_EXPIRY_TIME); return MOD_CONT; @@ -163,26 +159,29 @@ class CommandOSSQLine : public Command this->OnSyntaxError(u, "ADD"); return MOD_CONT; } - snprintf(reason, sizeof(reason), "%s%s%s", params[last_param].c_str(), last_param == 2 && params.size() > 3 ? " " : "", last_param == 2 && params.size() > 3 ? params[3].c_str() : ""); - if (mask && *reason) + + Anope::string reason = params[last_param]; + if (last_param == 2 && params.size() > 3) + reason += " " + params[3]; + if (!mask.empty() && !reason.empty()) { XLine *x = SQLine->Add(OperServ, u, mask, expires, reason); if (!x) return MOD_CONT; - notice_lang(Config.s_OperServ, u, OPER_SQLINE_ADDED, mask); + notice_lang(Config.s_OperServ, u, OPER_SQLINE_ADDED, mask.c_str()); if (Config.WallOSSQLine) { - char buf[128]; + Anope::string buf; if (!expires) - strcpy(buf, "does not expire"); + buf = "does not expire"; else { int wall_expiry = expires - time(NULL); - const char *s = NULL; + Anope::string s; if (wall_expiry >= 86400) { @@ -200,10 +199,10 @@ class CommandOSSQLine : public Command s = "minute"; } - snprintf(buf, sizeof(buf), "expires in %d %s%s", wall_expiry, s, wall_expiry == 1 ? "" : "s"); + buf = "expires in " + stringify(wall_expiry) + " " + s + (wall_expiry == 1 ? "" : "s"); } - ircdproto->SendGlobops(OperServ, "%s added an SQLINE for %s (%s)", u->nick.c_str(), mask, buf); + ircdproto->SendGlobops(OperServ, "%s added an SQLINE for %s (%s)", u->nick.c_str(), mask.c_str(), buf.c_str()); } if (readonly) @@ -216,7 +215,7 @@ class CommandOSSQLine : public Command return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) { if (SQLine->GetList().empty()) { @@ -224,7 +223,7 @@ class CommandOSSQLine : public Command return MOD_CONT; } - const ci::string mask = params.size() > 1 ? params[1] : ""; + Anope::string mask = params.size() > 1 ? params[1] : ""; if (mask.empty()) { @@ -232,9 +231,9 @@ class CommandOSSQLine : public Command return MOD_CONT; } - if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SQLineDelCallback list(u, mask.c_str()); + SQLineDelCallback list(u, mask); list.Process(); } else @@ -259,7 +258,7 @@ class CommandOSSQLine : public Command return MOD_CONT; } - CommandReturn DoList(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoList(User *u, const std::vector<Anope::string> ¶ms) { if (SQLine->GetList().empty()) { @@ -267,11 +266,11 @@ class CommandOSSQLine : public Command return MOD_CONT; } - const ci::string mask = params.size() > 1 ? params[1] : ""; + Anope::string mask = params.size() > 1 ? params[1] : ""; - if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SQLineListCallback list(u, mask.c_str()); + SQLineListCallback list(u, mask); list.Process(); } else @@ -282,7 +281,7 @@ class CommandOSSQLine : public Command { XLine *x = SQLine->GetEntry(i); - if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) + if (mask.empty() || mask.equals_ci(x->Mask) || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -303,7 +302,7 @@ class CommandOSSQLine : public Command return MOD_CONT; } - CommandReturn DoView(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoView(User *u, const std::vector<Anope::string> ¶ms) { if (SQLine->GetList().empty()) { @@ -311,11 +310,11 @@ class CommandOSSQLine : public Command return MOD_CONT; } - const ci::string mask = params.size() > 1 ? params[1] : ""; + Anope::string mask = params.size() > 1 ? params[1] : ""; - if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SQLineViewCallback list(u, mask.c_str()); + SQLineViewCallback list(u, mask); list.Process(); } else @@ -326,7 +325,7 @@ class CommandOSSQLine : public Command { XLine *x = SQLine->GetEntry(i); - if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) + if (mask.empty() || mask.equals_ci(x->Mask) || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -358,32 +357,32 @@ class CommandOSSQLine : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; + Anope::string cmd = params[0]; - if (cmd == "ADD") + if (cmd.equals_ci("ADD")) return this->DoAdd(u, params); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) return this->DoDel(u, params); - else if (cmd == "LIST") + else if (cmd.equals_ci("LIST")) return this->DoList(u, params); - else if (cmd == "VIEW") + else if (cmd.equals_ci("VIEW")) return this->DoView(u, params); - else if (cmd == "CLEAR") + else if (cmd.equals_ci("CLEAR")) return this->DoClear(u); else this->OnSyntaxError(u, ""); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_SQLINE); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "SQLINE", OPER_SQLINE_SYNTAX); } @@ -397,7 +396,7 @@ class CommandOSSQLine : public Command class OSSQLine : public Module { public: - OSSQLine(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSSQLine(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { if (!ircd->sqline) throw ModuleException("Your IRCd does not support QLines."); diff --git a/modules/core/os_staff.cpp b/modules/core/os_staff.cpp index e36aadff8..db701fc55 100644 --- a/modules/core/os_staff.cpp +++ b/modules/core/os_staff.cpp @@ -20,14 +20,14 @@ class CommandOSStaff : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { notice_lang(Config.s_OperServ, u, OPER_STAFF_LIST_HEADER); - for (std::list<std::pair<ci::string, ci::string> >::iterator it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) + for (std::list<std::pair<Anope::string, Anope::string> >::iterator it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) { int found = 0; - ci::string nick = it->first, type = it->second; + Anope::string nick = it->first, type = it->second; NickAlias *na = findnick(nick); if (na) @@ -40,14 +40,14 @@ class CommandOSStaff : public Command if (u2->Account() && u2->Account() == na->nc) { found = 1; - if (na->nick == u2->nick) + if (na->nick.equals_ci(u2->nick)) notice_lang(Config.s_OperServ, u, OPER_STAFF_FORMAT, '*', type.c_str(), u2->nick.c_str()); else - notice_lang(Config.s_OperServ, u, OPER_STAFF_AFORMAT, '*', type.c_str(), na->nick, u2->nick.c_str()); + notice_lang(Config.s_OperServ, u, OPER_STAFF_AFORMAT, '*', type.c_str(), na->nick.c_str(), u2->nick.c_str()); } } if (!found) - notice_lang(Config.s_OperServ, u, OPER_STAFF_FORMAT, ' ', type.c_str(), na->nick); + notice_lang(Config.s_OperServ, u, OPER_STAFF_FORMAT, ' ', type.c_str(), na->nick.c_str()); } } @@ -55,7 +55,7 @@ class CommandOSStaff : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_STAFF); return true; @@ -70,7 +70,7 @@ class CommandOSStaff : public Command class OSStaff : public Module { public: - OSStaff(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSStaff(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_stats.cpp b/modules/core/os_stats.cpp index f660ffa15..b596c82e9 100644 --- a/modules/core/os_stats.cpp +++ b/modules/core/os_stats.cpp @@ -200,7 +200,7 @@ class CommandOSStats : public Command CommandReturn DoStatsUplink(User *u) { - std::string buf; + Anope::string buf; for (unsigned j = 0; !Capab_Info[j].Token.empty(); ++j) if (Capab.HasFlag(Capab_Info[j].Flag)) @@ -232,12 +232,12 @@ class CommandOSStats : public Command notice_lang(Config.s_OperServ, u, OPER_STATS_ALIASES_MEM, count, (mem + 512) / 1024); get_chanserv_stats(&count, &mem); notice_lang(Config.s_OperServ, u, OPER_STATS_CHANSERV_MEM, count, (mem + 512) / 1024); - if (Config.s_BotServ) + if (!Config.s_BotServ.empty()) { get_botserv_stats(&count, &mem); notice_lang(Config.s_OperServ, u, OPER_STATS_BOTSERV_MEM, count, (mem + 512) / 1024); } - if (Config.s_HostServ) + if (!Config.s_HostServ.empty()) { get_hostserv_stats(&count, &mem); notice_lang(Config.s_OperServ, u, OPER_STATS_HOSTSERV_MEM, count, (mem + 512) / 1024); @@ -254,33 +254,33 @@ class CommandOSStats : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string extra = params.size() ? params[0] : ""; + Anope::string extra = !params.empty() ? params[0] : ""; - if (!extra.empty() && extra != "ALL") + if (!extra.empty() && !extra.equals_ci("ALL")) { - if (extra == "AKILL") + if (extra.equals_ci("AKILL")) return this->DoStatsAkill(u); - else if (extra == "RESET") + else if (extra.equals_ci("RESET")) return this->DoStatsReset(u); - else if (extra != "MEMORY" && extra != "UPLINK") + else if (!extra.equals_ci("MEMORY") && !extra.equals_ci("UPLINK")) notice_lang(Config.s_OperServ, u, OPER_STATS_UNKNOWN_OPTION, extra.c_str()); } - if (extra.empty() || (extra != "MEMORY" && extra != "UPLINK")) + if (extra.empty() || (!extra.equals_ci("MEMORY") && !extra.equals_ci("UPLINK"))) this->DoStatsUptime(u); - if (!extra.empty() && (extra == "ALL" || extra == "UPLINK")) + if (!extra.empty() && (extra.equals_ci("ALL") || extra.equals_ci("UPLINK"))) this->DoStatsUplink(u); - if (!extra.empty() && (extra == "ALL" || extra == "MEMORY")) + if (!extra.empty() && (extra.equals_ci("ALL") || extra.equals_ci("MEMORY"))) this->DoStatsMemory(u); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_STATS); return true; @@ -295,7 +295,7 @@ class CommandOSStats : public Command class OSStats : public Module { public: - OSStats(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSStats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_svsnick.cpp b/modules/core/os_svsnick.cpp index a7a8e7a2c..0277aed76 100644 --- a/modules/core/os_svsnick.cpp +++ b/modules/core/os_svsnick.cpp @@ -20,10 +20,10 @@ class CommandOSSVSNick : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - ci::string newnick = params[1]; + Anope::string nick = params[0]; + Anope::string newnick = params[1]; User *u2; NickAlias *na; @@ -41,7 +41,7 @@ class CommandOSSVSNick : public Command notice_lang(Config.s_OperServ, u, NICK_X_ILLEGAL, newnick.c_str()); return MOD_CONT; } - for (unsigned i = 0, end = newnick.size(); i < end; ++i) + for (unsigned i = 0, end = newnick.length(); i < end; ++i) if (!isvalidnick(newnick[i])) { notice_lang(Config.s_OperServ, u, NICK_X_ILLEGAL, newnick.c_str()); @@ -50,27 +50,27 @@ class CommandOSSVSNick : public Command /* Check for a nick in use or a forbidden/suspended nick */ if (!(u2 = finduser(nick))) - notice_lang(Config.s_OperServ, u, NICK_X_NOT_IN_USE, nick); + notice_lang(Config.s_OperServ, u, NICK_X_NOT_IN_USE, nick.c_str()); else if (finduser(newnick)) notice_lang(Config.s_OperServ, u, NICK_X_IN_USE, newnick.c_str()); - else if ((na = findnick(newnick)) && (na->HasFlag(NS_FORBIDDEN))) + else if ((na = findnick(newnick)) && na->HasFlag(NS_FORBIDDEN)) notice_lang(Config.s_OperServ, u, NICK_X_FORBIDDEN, newnick.c_str()); else { - notice_lang(Config.s_OperServ, u, OPER_SVSNICK_NEWNICK, nick, newnick.c_str()); - ircdproto->SendGlobops(OperServ, "%s used SVSNICK to change %s to %s", u->nick.c_str(), nick, newnick.c_str()); - ircdproto->SendForceNickChange(u2, newnick.c_str(), time(NULL)); + notice_lang(Config.s_OperServ, u, OPER_SVSNICK_NEWNICK, nick.c_str(), newnick.c_str()); + ircdproto->SendGlobops(OperServ, "%s used SVSNICK to change %s to %s", u->nick.c_str(), nick.c_str(), newnick.c_str()); + ircdproto->SendForceNickChange(u2, newnick, time(NULL)); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_SVSNICK); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "SVSNICK", OPER_SVSNICK_SYNTAX); } @@ -84,7 +84,7 @@ class CommandOSSVSNick : public Command class OSSVSNick : public Module { public: - OSSVSNick(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSSVSNick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { if (!ircd->svsnick) throw ModuleException("Your IRCd does not support SVSNICK"); diff --git a/modules/core/os_szline.cpp b/modules/core/os_szline.cpp index 3b1a09009..94ef5f792 100644 --- a/modules/core/os_szline.cpp +++ b/modules/core/os_szline.cpp @@ -18,7 +18,7 @@ class SZLineDelCallback : public NumberList User *u; unsigned Deleted; public: - SZLineDelCallback(User *_u, const std::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) + SZLineDelCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) { } @@ -26,7 +26,7 @@ class SZLineDelCallback : public NumberList { if (!Deleted) notice_lang(Config.s_OperServ, u, OPER_SZLINE_NO_MATCH); - else if (Deleted == 0) + else if (Deleted == 1) notice_lang(Config.s_OperServ, u, OPER_SZLINE_DELETED_ONE); else notice_lang(Config.s_OperServ, u, OPER_SZLINE_DELETED_SEVERAL, Deleted); @@ -55,7 +55,7 @@ class SZLineListCallback : public NumberList User *u; bool SentHeader; public: - SZLineListCallback(User *_u, const std::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) + SZLineListCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) { } @@ -90,7 +90,7 @@ class SZLineListCallback : public NumberList class SZLineViewCallback : public SZLineListCallback { public: - SZLineViewCallback(User *_u, const std::string &numlist) : SZLineListCallback(_u, numlist) + SZLineViewCallback(User *_u, const Anope::string &numlist) : SZLineListCallback(_u, numlist) { } @@ -112,44 +112,41 @@ class SZLineViewCallback : public SZLineListCallback static void DoList(User *u, XLine *x, unsigned Number) { - char timebuf[32], expirebuf[256]; + char timebuf[32]; struct tm tm; tm = *localtime(&x->Created); strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm); - expire_left(u->Account(), expirebuf, sizeof(expirebuf), x->Expires); - notice_lang(Config.s_OperServ, u, OPER_SZLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, expirebuf, x->Reason.c_str()); + Anope::string expirebuf = expire_left(u->Account(), x->Expires); + notice_lang(Config.s_OperServ, u, OPER_SZLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, expirebuf.c_str(), x->Reason.c_str()); } }; class CommandOSSZLine : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) { unsigned last_param = 2; - const char *expiry, *mask; - char reason[BUFSIZE]; + Anope::string expiry, mask; time_t expires; - mask = params.size() > 1 ? params[1].c_str() : NULL; - if (mask && *mask == '+') + mask = params.size() > 1 ? params[1] : ""; + if (!mask.empty() && mask[0] == '+') { expiry = mask; - mask = params.size() > 2 ? params[2].c_str() : NULL; + mask = params.size() > 2 ? params[2] : ""; last_param = 3; } - else - expiry = NULL; - expires = expiry ? dotime(expiry) : Config.SZLineExpiry; + expires = !expiry.empty() ? dotime(expiry) : Config.SZLineExpiry; /* If the expiry given does not contain a final letter, it's in days, * said the doc. Ah well. */ - if (expiry && isdigit(expiry[strlen(expiry) - 1])) + if (!expiry.empty() && isdigit(expiry[expiry.length() - 1])) expires *= 86400; /* Do not allow less than a minute expiry time */ - if (expires != 0 && expires < 60) + if (expires && expires < 60) { notice_lang(Config.s_OperServ, u, BAD_EXPIRY_TIME); return MOD_CONT; @@ -162,26 +159,29 @@ class CommandOSSZLine : public Command this->OnSyntaxError(u, "ADD"); return MOD_CONT; } - snprintf(reason, sizeof(reason), "%s%s%s", params[last_param].c_str(), last_param == 2 && params.size() > 3 ? " " : "", last_param == 2 && params.size() > 3 ? params[3].c_str() : ""); - if (mask && *reason) + + Anope::string reason = params[last_param]; + if (last_param == 2 && params.size() > 3) + reason += " " + params[3]; + if (!mask.empty() && !reason.empty()) { XLine *x = SZLine->Add(OperServ, u, mask, expires, reason); if (!x) return MOD_CONT; - notice_lang(Config.s_OperServ, u, OPER_SZLINE_ADDED, mask); + notice_lang(Config.s_OperServ, u, OPER_SZLINE_ADDED, mask.c_str()); if (Config.WallOSSZLine) { - char buf[128]; + Anope::string buf; if (!expires) - strcpy(buf, "does not expire"); + buf = "does not expire"; else { int wall_expiry = expires - time(NULL); - const char *s = NULL; + Anope::string s; if (wall_expiry >= 86400) { @@ -199,10 +199,10 @@ class CommandOSSZLine : public Command s = "minute"; } - snprintf(buf, sizeof(buf), "expires in %d %s%s", wall_expiry, s, wall_expiry == 1 ? "" : "s"); + buf = "expires in " + stringify(wall_expiry) + " " + s + (wall_expiry == 1 ? "" : "s"); } - ircdproto->SendGlobops(OperServ, "%s added an SZLINE for %s (%s)", u->nick.c_str(), mask, buf); + ircdproto->SendGlobops(OperServ, "%s added an SZLINE for %s (%s)", u->nick.c_str(), mask.c_str(), buf.c_str()); } if (readonly) @@ -215,7 +215,7 @@ class CommandOSSZLine : public Command return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) { if (SZLine->GetList().empty()) { @@ -223,7 +223,7 @@ class CommandOSSZLine : public Command return MOD_CONT; } - const ci::string mask = params.size() > 1 ? params[1].c_str() : ""; + Anope::string mask = params.size() > 1 ? params[1] : ""; if (mask.empty()) { @@ -231,9 +231,9 @@ class CommandOSSZLine : public Command return MOD_CONT; } - if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SZLineDelCallback list(u, mask.c_str()); + SZLineDelCallback list(u, mask); list.Process(); } else @@ -258,7 +258,7 @@ class CommandOSSZLine : public Command return MOD_CONT; } - CommandReturn DoList(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoList(User *u, const std::vector<Anope::string> ¶ms) { if (SZLine->GetList().empty()) { @@ -266,11 +266,11 @@ class CommandOSSZLine : public Command return MOD_CONT; } - const ci::string mask = params.size() > 1 ? params[1] : ""; + Anope::string mask = params.size() > 1 ? params[1] : ""; - if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SZLineListCallback list(u, mask.c_str()); + SZLineListCallback list(u, mask); list.Process(); } else @@ -281,7 +281,7 @@ class CommandOSSZLine : public Command { XLine *x = SZLine->GetEntry(i); - if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) + if (mask.empty() || mask.equals_ci(x->Mask) || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -300,7 +300,7 @@ class CommandOSSZLine : public Command return MOD_CONT; } - CommandReturn DoView(User *u, const std::vector<ci::string> ¶ms) + CommandReturn DoView(User *u, const std::vector<Anope::string> ¶ms) { if (SZLine->GetList().empty()) { @@ -308,11 +308,11 @@ class CommandOSSZLine : public Command return MOD_CONT; } - const ci::string mask = params.size() > 1 ? params[1] : ""; + Anope::string mask = params.size() > 1 ? params[1] : ""; - if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SZLineViewCallback list(u, mask.c_str()); + SZLineViewCallback list(u, mask); list.Process(); } else @@ -323,7 +323,7 @@ class CommandOSSZLine : public Command { XLine *x = SZLine->GetEntry(i); - if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) + if (mask.empty() || mask.equals_ci(x->Mask) || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -355,32 +355,32 @@ class CommandOSSZLine : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ci::string cmd = params[0]; + Anope::string cmd = params[0]; - if (cmd == "ADD") + if (cmd.equals_ci("ADD")) return this->DoAdd(u, params); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) return this->DoDel(u, params); - else if (cmd == "LIST") + else if (cmd.equals_ci("LIST")) return this->DoList(u, params); - else if (cmd == "VIEW") + else if (cmd.equals_ci("VIEW")) return this->DoView(u, params); - else if (cmd == "CLEAR") + else if (cmd.equals_ci("CLEAR")) return this->DoClear(u); else this->OnSyntaxError(u, ""); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_SZLINE); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "SZLINE", OPER_SZLINE_SYNTAX); } @@ -394,7 +394,7 @@ class CommandOSSZLine : public Command class OSSZLine : public Module { public: - OSSZLine(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSSZLine(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { if (!ircd->szline) throw ModuleException("Your IRCd does not support ZLINEs"); diff --git a/modules/core/os_umode.cpp b/modules/core/os_umode.cpp index cb353a938..1f8f55ddb 100644 --- a/modules/core/os_umode.cpp +++ b/modules/core/os_umode.cpp @@ -20,10 +20,10 @@ class CommandOSUMode : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - const char *modes = params[1].c_str(); + Anope::string nick = params[0]; + Anope::string modes = params[1]; User *u2; @@ -37,27 +37,27 @@ class CommandOSUMode : public Command return MOD_CONT; } if (!(u2 = finduser(nick))) - notice_lang(Config.s_OperServ, u, NICK_X_NOT_IN_USE, nick); + notice_lang(Config.s_OperServ, u, NICK_X_NOT_IN_USE, nick.c_str()); else { - u2->SetModes(OperServ, modes); + u2->SetModes(OperServ, "%s", modes.c_str()); - notice_lang(Config.s_OperServ, u, OPER_UMODE_SUCCESS, nick); + notice_lang(Config.s_OperServ, u, OPER_UMODE_SUCCESS, nick.c_str()); notice_lang(Config.s_OperServ, u2, OPER_UMODE_CHANGED, u->nick.c_str()); if (Config.WallOSMode) - ircdproto->SendGlobops(OperServ, "\2%s\2 used UMODE on %s", u->nick.c_str(), nick); + ircdproto->SendGlobops(OperServ, "\2%s\2 used UMODE on %s", u->nick.c_str(), nick.c_str()); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_UMODE); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_OperServ, u, "UMODE", OPER_UMODE_SYNTAX); } @@ -71,7 +71,7 @@ class CommandOSUMode : public Command class OSUMode : public Module { public: - OSUMode(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSUMode(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { if (!ircd->umode) throw ModuleException("Your IRCd does not support setting umodes"); diff --git a/modules/core/os_update.cpp b/modules/core/os_update.cpp index 68cffd4ba..5f19d142d 100644 --- a/modules/core/os_update.cpp +++ b/modules/core/os_update.cpp @@ -20,14 +20,14 @@ class CommandOSUpdate : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { notice_lang(Config.s_OperServ, u, OPER_UPDATING); save_data = 1; return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_UPDATE); return true; @@ -42,7 +42,7 @@ class CommandOSUpdate : public Command class OSUpdate : public Module { public: - OSUpdate(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/os_userlist.cpp b/modules/core/os_userlist.cpp index 9005016d5..96ae9659b 100644 --- a/modules/core/os_userlist.cpp +++ b/modules/core/os_userlist.cpp @@ -20,19 +20,19 @@ class CommandOSUserList : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *pattern = params.size() > 0 ? params[0].c_str() : NULL; - ci::string opt = params.size() > 1 ? params[1] : ""; + Anope::string pattern = !params.empty() ? params[0] : ""; + Anope::string opt = params.size() > 1 ? params[1] : ""; Channel *c; std::list<UserModeName> Modes; - if (!opt.empty() && opt == "INVISIBLE") + if (!opt.empty() && opt.equals_ci("INVISIBLE")) Modes.push_back(UMODE_INVIS); - if (pattern && (c = findchan(pattern))) + if (!pattern.empty() && (c = findchan(pattern))) { - notice_lang(Config.s_OperServ, u, OPER_USERLIST_HEADER_CHAN, pattern); + notice_lang(Config.s_OperServ, u, OPER_USERLIST_HEADER_CHAN, pattern.c_str()); for (CUserList::iterator cuit = c->users.begin(), cuit_end = c->users.end(); cuit != cuit_end; ++cuit) { @@ -54,11 +54,10 @@ class CommandOSUserList : public Command { User *u2 = uit->second; - if (pattern) + if (!pattern.empty()) { - char mask[BUFSIZE]; - snprintf(mask, sizeof(mask), "%s!%s@%s", u2->nick.c_str(), u2->GetIdent().c_str(), u2->GetDisplayedHost().c_str()); - if (!Anope::Match(mask, pattern, false)) + Anope::string mask = u2->nick + "!" + u2->GetIdent() + "@" + u2->GetDisplayedHost(); + if (!Anope::Match(mask, pattern)) continue; if (!Modes.empty()) for (std::list<UserModeName>::iterator it = Modes.begin(), it_end = Modes.end(); it != it_end; ++it) @@ -73,7 +72,7 @@ class CommandOSUserList : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_USERLIST); return true; @@ -88,7 +87,7 @@ class CommandOSUserList : public Command class OSUserList : public Module { public: - OSUserList(const std::string &modname, const std::string &creator) : Module(modname, creator) + OSUserList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); diff --git a/modules/core/ss_main.cpp b/modules/core/ss_main.cpp index a48b77855..b15e8ce9e 100644 --- a/modules/core/ss_main.cpp +++ b/modules/core/ss_main.cpp @@ -20,9 +20,9 @@ class CommandSSHelp : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - ircdproto->SendMessage(statserv, u->nick.c_str(), "This is a test of the emergency StatServ system."); + ircdproto->SendMessage(statserv, u->nick, "This is a test of the emergency StatServ system."); return MOD_CONT; } }; @@ -30,7 +30,7 @@ class CommandSSHelp : public Command class SSMain : public Module { public: - SSMain(const std::string &modname, const std::string &creator) : Module(modname, creator) + SSMain(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); @@ -51,7 +51,7 @@ class SSMain : public Module { if (statserv) { - for (std::map<ci::string, Command *>::iterator it = statserv->Commands.begin(), it_end = statserv->Commands.end(); it != it_end; ++it) + for (CommandMap::iterator it = statserv->Commands.begin(), it_end = statserv->Commands.end(); it != it_end; ++it) this->DelCommand(statserv, it->second); ircdproto->SendQuit(statserv, "Quit due to module unload."); diff --git a/modules/extra/cs_appendtopic.cpp b/modules/extra/cs_appendtopic.cpp index 03f20ba6c..8d376e661 100644 --- a/modules/extra/cs_appendtopic.cpp +++ b/modules/extra/cs_appendtopic.cpp @@ -38,7 +38,7 @@ */ /* ---------------------------------------------------------------------- */ -/* DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING */ +/* DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING */ /* ---------------------------------------------------------------------- */ enum @@ -58,11 +58,11 @@ class CommandCSAppendTopic : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - const char *newtopic = params[1].c_str(); - char topic[1024]; + Anope::string chan = params[0]; + Anope::string newtopic = params[1]; + Anope::string topic; Channel *c = findchan(chan); ChannelInfo *ci; @@ -70,26 +70,24 @@ class CommandCSAppendTopic : public Command ci = c->ci; if (!c) - notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); else if (!check_access(u, ci, CA_TOPIC)) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else { - if (ci->last_topic) + if (!ci->last_topic.empty()) { - snprintf(topic, sizeof(topic), "%s %s", ci->last_topic, newtopic); - delete [] ci->last_topic; + topic = ci->last_topic + " " + newtopic; + ci->last_topic.clear(); } else - strscpy(topic, newtopic, sizeof(topic)); + topic = newtopic; - ci->last_topic = *topic ? sstrdup(topic) : NULL; + ci->last_topic = topic; ci->last_topic_setter = u->nick; ci->last_topic_time = time(NULL); - if (c->topic) - delete [] c->topic; - c->topic = *topic ? sstrdup(topic) : NULL; + c->topic = topic; c->topic_setter = u->nick; if (ircd->topictsbackward) c->topic_time = c->topic_time - 1; @@ -101,16 +99,16 @@ class CommandCSAppendTopic : public Command if (ircd->join2set && whosends(ci) == ChanServ) { ChanServ->Join(c); - ircdproto->SendMode(NULL, c, "+o %s", Config.s_ChanServ); // XXX + ircdproto->SendMode(NULL, c, "+o %s", Config.s_ChanServ.c_str()); // XXX } - ircdproto->SendTopic(whosends(ci), c, u->nick.c_str(), topic); + ircdproto->SendTopic(whosends(ci), c, u->nick, topic); if (ircd->join2set && whosends(ci) == ChanServ) ChanServ->Part(c); } return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_ChanServ, u, LNG_APPENDTOPIC_SYNTAX); u->SendMessage(Config.s_ChanServ, " "); @@ -119,7 +117,7 @@ class CommandCSAppendTopic : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_ChanServ, u, LNG_APPENDTOPIC_SYNTAX); } @@ -133,7 +131,7 @@ class CommandCSAppendTopic : public Command class CSAppendTopic : public Module { public: - CSAppendTopic(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSAppendTopic(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { me = this; @@ -143,7 +141,7 @@ class CSAppendTopic : public Module this->AddCommand(ChanServ, new CommandCSAppendTopic()); /* English (US) */ - const char* langtable_en_us[] = { + const char *langtable_en_us[] = { /* LNG_CHAN_HELP */ " APPENDTOPIC Add text to a channels topic", /* LNG_CHAN_HELP_APPENDTOPIC */ @@ -155,7 +153,7 @@ class CSAppendTopic : public Module }; /* Dutch (NL) */ - const char* langtable_nl[] = { + const char *langtable_nl[] = { /* LNG_CHAN_HELP */ " APPENDTOPIC Voeg tekst aan een kanaal onderwerp toe", /* LNG_CHAN_HELP_APPENDTOPIC */ @@ -168,7 +166,7 @@ class CSAppendTopic : public Module }; /* German (DE) */ - const char* langtable_de[] = { + const char *langtable_de[] = { /* LNG_CHAN_HELP */ " APPENDTOPIC Fügt einen Text zu einem Channel-Topic hinzu.", /* LNG_CHAN_HELP_APPENDTOPIC */ @@ -180,7 +178,7 @@ class CSAppendTopic : public Module }; /* Portuguese (PT) */ - const char* langtable_pt[] = { + const char *langtable_pt[] = { /* LNG_CHAN_HELP */ " APPENDTOPIC Adiciona texto ao tópico de um canal", /* LNG_CHAN_HELP_APPENDTOPIC */ @@ -192,7 +190,7 @@ class CSAppendTopic : public Module }; /* Russian (RU) */ - const char* langtable_ru[] = { + const char *langtable_ru[] = { /* LNG_CHAN_HELP */ " APPENDTOPIC Äîáàâëÿåò òåêñò ê òîïèêó êàíàëà", /* LNG_CHAN_HELP_APPENDTOPIC */ @@ -204,7 +202,7 @@ class CSAppendTopic : public Module }; /* Italian (IT) */ - const char* langtable_it[] = { + const char *langtable_it[] = { /* LNG_CHAN_HELP */ " APPENDTOPIC Aggiunge del testo al topic di un canale", /* LNG_CHAN_HELP_APPENDTOPIC */ diff --git a/modules/extra/cs_enforce.cpp b/modules/extra/cs_enforce.cpp index c4cfbecc9..a32d5a8f5 100644 --- a/modules/extra/cs_enforce.cpp +++ b/modules/extra/cs_enforce.cpp @@ -88,7 +88,7 @@ class CommandCSEnforce : public Command { ChannelInfo *ci; int16 old_nojoin_level; - char mask[BUFSIZE]; + Anope::string mask; const char *reason; if (!(ci = c->ci)) @@ -106,7 +106,7 @@ class CommandCSEnforce : public Command if (check_access(uc->user, ci, CA_NOJOIN)) { - get_idealban(ci, uc->user, mask, sizeof(mask)); + get_idealban(ci, uc->user, mask); reason = getstring(uc->user, CHAN_NOT_ALLOWED_TO_JOIN); c->SetMode(NULL, CMODE_BAN, mask); c->Kick(NULL, uc->user, "%s", reason); @@ -119,8 +119,7 @@ class CommandCSEnforce : public Command void DoCModeR(Channel *c) { ChannelInfo *ci; - char mask[BUFSIZE]; - const char *reason; + Anope::string mask; if (!(ci = c->ci)) return; @@ -133,11 +132,11 @@ class CommandCSEnforce : public Command if (!uc->user->IsIdentified()) { - get_idealban(ci, uc->user, mask, sizeof(mask)); - reason = getstring(uc->user, CHAN_NOT_ALLOWED_TO_JOIN); + get_idealban(ci, uc->user, mask); + Anope::string reason = getstring(uc->user, CHAN_NOT_ALLOWED_TO_JOIN); if (!c->HasMode(CMODE_REGISTERED)) c->SetMode(NULL, CMODE_BAN, mask); - c->Kick(NULL, uc->user, "%s", reason); + c->Kick(NULL, uc->user, "%s", reason.c_str()); } } } @@ -146,10 +145,10 @@ class CommandCSEnforce : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *chan = params[0].c_str(); - ci::string what = params.size() > 1 ? params[1] : ""; + Anope::string chan = params[0]; + Anope::string what = params.size() > 1 ? params[1] : ""; Channel *c = findchan(chan); ChannelInfo *ci; @@ -157,32 +156,32 @@ class CommandCSEnforce : public Command ci = c->ci; if (!c) - notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); else if (!check_access(u, ci, CA_AKICK)) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else { - if (what.empty() || what == "SET") + if (what.empty() || what.equals_ci("SET")) { this->DoSet(c); me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_RESPONSE, !what.empty() ? what.c_str() : "SET"); } - else if (what == "MODES") + else if (what.equals_ci("MODES")) { this->DoModes(c); me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_RESPONSE, what.c_str()); } - else if (what == "SECUREOPS") + else if (what.equals_ci("SECUREOPS")) { this->DoSecureOps(c); me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_RESPONSE, what.c_str()); } - else if (what == "RESTRICTED") + else if (what.equals_ci("RESTRICTED")) { this->DoRestricted(c); me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_RESPONSE, what.c_str()); } - else if (what == "+R") + else if (what.equals_ci("+R")) { this->DoCModeR(c); me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_RESPONSE, what.c_str()); @@ -194,7 +193,7 @@ class CommandCSEnforce : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_ChanServ, u, LNG_ENFORCE_SYNTAX); u->SendMessage(Config.s_ChanServ, " "); @@ -208,7 +207,7 @@ class CommandCSEnforce : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_ChanServ, u, LNG_ENFORCE_SYNTAX); } @@ -222,7 +221,7 @@ class CommandCSEnforce : public Command class CSEnforce : public Module { public: - CSEnforce(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSEnforce(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { me = this; @@ -232,7 +231,7 @@ class CSEnforce : public Module this->AddCommand(ChanServ, new CommandCSEnforce()); /* English (US) */ - const char* langtable_en_us[] = { + const char *langtable_en_us[] = { /* LNG_CHAN_HELP */ " ENFORCE Enforce various channel modes and set options", /* LNG_ENFORCE_SYNTAX */ @@ -266,7 +265,7 @@ class CSEnforce : public Module }; /* Dutch (NL) */ - const char* langtable_nl[] = { + const char *langtable_nl[] = { /* LNG_CHAN_HELP */ " ENFORCE Forceer enkele kanaalmodes en set-opties", /* LNG_ENFORCE_SYNTAX */ @@ -302,7 +301,7 @@ class CSEnforce : public Module }; /* German (DE) */ - const char* langtable_de[] = { + const char *langtable_de[] = { /* LNG_CHAN_HELP */ " ENFORCE Erzwingt verschieden Modes und SET Optionen", /* LNG_ENFORCE_SYNTAX */ @@ -335,7 +334,7 @@ class CSEnforce : public Module }; /* Portuguese (PT) */ - const char* langtable_pt[] = { + const char *langtable_pt[] = { /* LNG_CHAN_HELP */ " ENFORCE Verifica o cumprimento de vários modos de canal e opções ajustadas", /* LNG_ENFORCE_SYNTAX */ @@ -368,7 +367,7 @@ class CSEnforce : public Module }; /* Russian (RU) */ - const char* langtable_ru[] = { + const char *langtable_ru[] = { /* LNG_CHAN_HELP */ " ENFORCE Ïåðåïðîâåðêà è óñòàíîâêà ðàçëè÷íûõ ðåæèìîâ è îïöèé êàíàëà", /* LNG_ENFORCE_SYNTAX */ @@ -400,7 +399,7 @@ class CSEnforce : public Module }; /* Italian (IT) */ - const char* langtable_it[] = { + const char *langtable_it[] = { /* LNG_CHAN_HELP */ " ENFORCE Forza diversi modi di canale ed opzioni SET", /* LNG_ENFORCE_SYNTAX */ diff --git a/modules/extra/cs_set_misc.cpp b/modules/extra/cs_set_misc.cpp index 453e242a3..7cffe6866 100644 --- a/modules/extra/cs_set_misc.cpp +++ b/modules/extra/cs_set_misc.cpp @@ -1,5 +1,4 @@ /* - * * (C) 2003-2010 Anope Team * Contact us at team@anope.org * @@ -15,32 +14,30 @@ class CommandCSSetMisc : public Command { - std::string Desc; + Anope::string Desc; public: - CommandCSSetMisc(const ci::string &cname, const std::string &desc, const ci::string &cpermission = "") : Command(cname, 1, 2, cpermission), Desc(desc) + CommandCSSetMisc(const Anope::string &cname, const Anope::string &desc, const Anope::string &cpermission = "") : Command(cname, 1, 2, cpermission), Desc(desc) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); assert(ci); - ci->Shrink("chanserv:" + std::string(this->name.c_str())); + ci->Shrink("chanserv:" + this->name); if (params.size() > 1) { - ci->Extend("chanserv:" + std::string(this->name.c_str()), new ExtensibleItemRegular<ci::string>(params[1])); + ci->Extend("chanserv:" + this->name, new ExtensibleItemRegular<Anope::string>(params[1])); notice_lang(Config.s_ChanServ, u, CHAN_SETTING_CHANGED, this->name.c_str(), ci->name.c_str(), params[1].c_str()); } else - { notice_lang(Config.s_ChanServ, u, CHAN_SETTING_UNSET, this->name.c_str(), ci->name.c_str()); - } return MOD_CONT; } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SET", CHAN_SET_SYNTAX); } @@ -54,11 +51,11 @@ class CommandCSSetMisc : public Command class CommandCSSASetMisc : public CommandCSSetMisc { public: - CommandCSSASetMisc(const ci::string &cname, const std::string &desc) : CommandCSSetMisc(cname, desc, "chanserv/saset/" + cname) + CommandCSSASetMisc(const Anope::string &cname, const Anope::string &desc) : CommandCSSetMisc(cname, desc, "chanserv/saset/" + cname) { } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_ChanServ, u, "SASET", CHAN_SASET_SYNTAX); } @@ -68,14 +65,14 @@ class CSSetMisc : public Module { struct CommandInfo { - std::string Name; - std::string Desc; + Anope::string Name; + Anope::string Desc; bool ShowHidden; - CommandInfo(const std::string &name, const std::string &desc, bool showhidden) : Name(name), Desc(desc), ShowHidden(showhidden) { } + CommandInfo(const Anope::string &name, const Anope::string &desc, bool showhidden) : Name(name), Desc(desc), ShowHidden(showhidden) { } }; - std::map<std::string, CommandInfo *> Commands; + std::map<Anope::string, CommandInfo *> Commands; void RemoveAll() { @@ -88,12 +85,12 @@ class CSSetMisc : public Module if (!set && !saset) return; - for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) { if (set) - set->DelSubcommand(it->first.c_str()); + set->DelSubcommand(it->first); if (saset) - saset->DelSubcommand(it->first.c_str()); + saset->DelSubcommand(it->first); delete it->second; } @@ -101,7 +98,7 @@ class CSSetMisc : public Module } public: - CSSetMisc(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); @@ -128,12 +125,12 @@ class CSSetMisc : public Module ConfigReader config; - for (int i = 0; true; ++i) + for (int i = 0, num = config.Enumerate("cs_set_misc"); i < num; ++i) { - std::string cname = config.ReadValue("cs_set_misc", "name", "", i); + Anope::string cname = config.ReadValue("cs_set_misc", "name", "", i); if (cname.empty()) - break; - std::string desc = config.ReadValue("cs_set_misc", "desc", "", i); + continue; + Anope::string desc = config.ReadValue("cs_set_misc", "desc", "", i); bool showhidden = config.ReadFlag("cs_set_misc", "operonly", "no", i); CommandInfo *info = new CommandInfo(cname, desc, showhidden); @@ -145,49 +142,40 @@ class CSSetMisc : public Module } if (set) - set->AddSubcommand(new CommandCSSetMisc(cname.c_str(), desc)); + set->AddSubcommand(new CommandCSSetMisc(cname, desc)); if (saset) - saset->AddSubcommand(new CommandCSSASetMisc(cname.c_str(), desc)); + saset->AddSubcommand(new CommandCSSASetMisc(cname, desc)); } } void OnChanInfo(User *u, ChannelInfo *ci, bool ShowHidden) { - for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) { if (!ShowHidden && it->second->ShowHidden) continue; - ci::string value; + Anope::string value; if (ci->GetExtRegular("chanserv:" + it->first, value)) - { u->SendMessage(Config.s_ChanServ, " %s: %s", it->first.c_str(), value.c_str()); - } } } - void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), ChannelInfo *ci) + void OnDatabaseWriteMetadata(void (*WriteMetadata)(const Anope::string &, const Anope::string &), ChannelInfo *ci) { - for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) { - ci::string value; - + Anope::string value; if (ci->GetExtRegular("chanserv:" + it->first, value)) - { - WriteMetadata(it->first, ":" + std::string(value.c_str())); - } + WriteMetadata(it->first, ":" + value); } } - EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const std::string &key, const std::vector<std::string> ¶ms) + EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, const std::vector<Anope::string> ¶ms) { - for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) - { + for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) if (key == it->first) - { - ci->Extend("chanserv:" + it->first, new ExtensibleItemRegular<ci::string>(params[0].c_str())); - } - } + ci->Extend("chanserv:" + it->first, new ExtensibleItemRegular<Anope::string>(params[0])); return EVENT_CONTINUE; } diff --git a/modules/extra/cs_tban.cpp b/modules/extra/cs_tban.cpp index 844606222..55ab8d1cb 100644 --- a/modules/extra/cs_tban.cpp +++ b/modules/extra/cs_tban.cpp @@ -19,9 +19,9 @@ #define AUTHOR "Rob" -void mySendResponse(User *u, const char *channel, char *mask, const char *time); +void mySendResponse(User *u, const Anope::string &channel, const Anope::string &mask, const Anope::string &time); -void addBan(Channel *c, time_t timeout, char *banmask); +void addBan(Channel *c, time_t timeout, const Anope::string &banmask); int canBanUser(Channel *c, User *u, User *u2); void mAddLanguages(); @@ -44,24 +44,24 @@ class CommandCSTBan : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - char mask[BUFSIZE]; + Anope::string mask; Channel *c; User *u2 = NULL; - const char *chan = params[0].c_str(); - const char *nick = params[1].c_str(); - const char *time = params[2].c_str(); + Anope::string chan = params[0]; + Anope::string nick = params[1]; + Anope::string time = params[2]; if (!(c = findchan(chan))) - notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); else if (!(u2 = finduser(nick))) - notice_lang(Config.s_ChanServ, u, NICK_X_NOT_IN_USE, nick); + notice_lang(Config.s_ChanServ, u, NICK_X_NOT_IN_USE, nick.c_str()); else if (canBanUser(c, u, u2)) { - get_idealban(c->ci, u2, mask, sizeof(mask)); + get_idealban(c->ci, u2, mask); addBan(c, dotime(time), mask); mySendResponse(u, chan, mask, time); } @@ -69,7 +69,7 @@ class CommandCSTBan : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { this->OnSyntaxError(u, ""); u->SendMessage(Config.s_ChanServ, " "); @@ -78,7 +78,7 @@ class CommandCSTBan : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_ChanServ, u, TBAN_SYNTAX); } @@ -92,7 +92,7 @@ class CommandCSTBan : public Command class CSTBan : public Module { public: - CSTBan(const std::string &modname, const std::string &creator) : Module(modname, creator) + CSTBan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { me = this; @@ -101,7 +101,7 @@ class CSTBan : public Module this->SetAuthor(AUTHOR); this->SetType(SUPPORTED); - const char* langtable_en_us[] = { + const char *langtable_en_us[] = { " TBAN Bans the user for a given length of time", "Syntax: TBAN channel nick time", "Bans the given user from a channel for a specified length of\n" @@ -109,7 +109,7 @@ class CSTBan : public Module "%s banned from %s, will auto-expire in %s" }; - const char* langtable_nl[] = { + const char *langtable_nl[] = { " TBAN Verban een gebruiker voor een bepaalde tijd", "Syntax: TBAN kanaal nick tijd", "Verbant de gegeven gebruiken van het gegeven kanaal voor de\n" @@ -118,7 +118,7 @@ class CSTBan : public Module "%s verbannen van %s, zal verlopen in %s" }; - const char* langtable_de[] = { + const char *langtable_de[] = { " TBAN Bant ein User für eine bestimmte Zeit aus ein Channel", "Syntax: TBAN Channel Nickname Zeit", "Bant ein User für eine bestimmte Zeit aus ein Channel\n" @@ -126,7 +126,7 @@ class CSTBan : public Module "%s gebannt von %s, wird auto-auslaufen in %s" }; - const char* langtable_pt[] = { + const char *langtable_pt[] = { " TBAN Bane o usuário por um determinado período de tempo", "Sintaxe: TBAN canal nick tempo", "Bane de um canal o usuário especificado por um determinado período de\n" @@ -134,7 +134,7 @@ class CSTBan : public Module "%s foi banido do %s, irá auto-expirar em %s" }; - const char* langtable_ru[] = { + const char *langtable_ru[] = { " TBAN Áàíèò ïîëüçîâàòåëÿ íà óêàçàííûé ïðîìåæóòîê âðåìåíè", "Ñèíòàêñèñ: TBAN #êàíàë íèê âðåìÿ", "Áàíèò ïîëüçîâàòåëÿ íà óêàçàííûé ïðîìåæóòîê âðåìåíè â ñåêóíäàõ\n" @@ -143,7 +143,7 @@ class CSTBan : public Module "Óñòàíîâëåííûé áàí %s íà êàíàëå %s èñòå÷åò ÷åðåç %s ñåêóíä" }; - const char* langtable_it[] = { + const char *langtable_it[] = { " TBAN Banna l'utente per un periodo di tempo specificato", "Sintassi: TBAN canale nick tempo", "Banna l'utente specificato da un canale per un periodo di tempo\n" @@ -160,37 +160,37 @@ class CSTBan : public Module } }; -void mySendResponse(User *u, const char *channel, char *mask, const char *time) +void mySendResponse(User *u, const Anope::string &channel, const Anope::string &mask, const Anope::string &time) { - me->NoticeLang(Config.s_ChanServ, u, TBAN_RESPONSE, mask, channel, time); + me->NoticeLang(Config.s_ChanServ, u, TBAN_RESPONSE, mask.c_str(), channel.c_str(), time.c_str()); } class TempBan : public CallBack { - private: - std::string chan; - std::string mask; + private: + Anope::string chan; + Anope::string mask; - public: - TempBan(time_t seconds, const std::string &channel, const std::string &banmask) : CallBack(me, seconds), chan(channel), mask(banmask) { } + public: + TempBan(time_t seconds, const Anope::string &channel, const Anope::string &banmask) : CallBack(me, seconds), chan(channel), mask(banmask) { } - void Tick(time_t ctime) - { - Channel *c; + void Tick(time_t ctime) + { + Channel *c; - if ((c = findchan(chan)) && c->ci) - c->RemoveMode(NULL, CMODE_BAN, mask); - } + if ((c = findchan(chan)) && c->ci) + c->RemoveMode(NULL, CMODE_BAN, mask); + } }; -void addBan(Channel *c, time_t timeout, char *banmask) +void addBan(Channel *c, time_t timeout, Anope::string &banmask) { c->SetMode(NULL, CMODE_BAN, banmask); new TempBan(timeout, c->name, banmask); } -int canBanUser(Channel * c, User * u, User * u2) +int canBanUser(Channel *c, User *u, User *u2) { ChannelInfo *ci = c->ci; int ok = 0; diff --git a/modules/extra/hs_request.cpp b/modules/extra/hs_request.cpp index 7ca2bc9ca..82ec2daf5 100644 --- a/modules/extra/hs_request.cpp +++ b/modules/extra/hs_request.cpp @@ -51,22 +51,23 @@ enum LNG_NUM_STRINGS }; -void my_add_host_request(char *nick, char *vIdent, char *vhost, char *creator, time_t tmp_time); -int my_isvalidchar(const char c); -void my_memo_lang(User *u, const char *name, int z, int number, ...); -void req_send_memos(User *u, char *vIdent, char *vHost); +void my_add_host_request(const Anope::string &nick, const Anope::string &vIdent, const Anope::string &vhost, const Anope::string &creator, time_t tmp_time); +int my_isvalidchar(char c); +void my_memo_lang(User *u, const Anope::string &name, int z, int number, ...); +void req_send_memos(User *u, const Anope::string &vIdent, const Anope::string &vHost); void my_load_config(); void my_add_languages(); struct HostRequest { - std::string ident; - std::string host; + Anope::string ident; + Anope::string host; time_t time; }; -std::map<ci::string, HostRequest *> Requests; +typedef std::map<Anope::string, HostRequest *, hash_compare_ci_string> RequestMap; +RequestMap Requests; static Module *me; @@ -77,79 +78,52 @@ class CommandHSRequest : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick; - const char *rawhostmask = params[0].c_str(); - char *hostmask = new char[Config.HostLen]; + Anope::string nick = u->nick; + Anope::string rawhostmask = params[0]; + Anope::string hostmask; NickAlias *na; - char *s; - char *vIdent = NULL; time_t now = time(NULL); - nick = u->nick.c_str(); - - vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ - if (vIdent) + Anope::string vIdent = myStrGetToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ + if (!vIdent.empty()) { rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */ - if (!rawhostmask) + if (rawhostmask.empty()) { me->NoticeLang(Config.s_HostServ, u, LNG_REQUEST_SYNTAX); - delete [] vIdent; - delete [] hostmask; return MOD_CONT; } - if (strlen(vIdent) > Config.UserLen) + if (vIdent.length() > Config.UserLen) { notice_lang(Config.s_HostServ, u, HOST_SET_IDENTTOOLONG, Config.UserLen); - delete [] vIdent; - delete [] rawhostmask; - delete [] hostmask; return MOD_CONT; } else - for (s = vIdent; *s; ++s) + for (Anope::string::iterator s = vIdent.begin(), s_end = vIdent.end(); s != s_end; ++s) if (!my_isvalidchar(*s)) { notice_lang(Config.s_HostServ, u, HOST_SET_IDENT_ERROR); - delete [] vIdent; - delete [] rawhostmask; - delete [] hostmask; return MOD_CONT; } if (!ircd->vident) { notice_lang(Config.s_HostServ, u, HOST_NO_VIDENT); - delete [] vIdent; - delete [] rawhostmask; - delete [] hostmask; return MOD_CONT; } } - if (strlen(rawhostmask) < Config.HostLen) - snprintf(hostmask, Config.HostLen, "%s", rawhostmask); + if (rawhostmask.length() < Config.HostLen) + hostmask = rawhostmask; else { notice_lang(Config.s_HostServ, u, HOST_SET_TOOLONG, Config.HostLen); - if (vIdent) - { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; return MOD_CONT; } if (!isValidHost(hostmask, 3)) { notice_lang(Config.s_HostServ, u, HOST_SET_ERROR); - if (vIdent) - { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; return MOD_CONT; } @@ -159,34 +133,21 @@ class CommandHSRequest : public Command { me->NoticeLang(Config.s_HostServ, u, LNG_REQUEST_WAIT, Config.MSSendDelay); u->lastmemosend = now; - if (vIdent) - { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; return MOD_CONT; } - my_add_host_request(const_cast<char *>(nick), vIdent, hostmask, const_cast<char *>(u->nick.c_str()), now); + my_add_host_request(nick, vIdent, hostmask, u->nick, now); me->NoticeLang(Config.s_HostServ, u, LNG_REQUESTED); req_send_memos(u, vIdent, hostmask); Alog() << "New vHost Requested by " << nick; } else - notice_lang(Config.s_HostServ, u, HOST_NOREG, nick); - - if (vIdent) - { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; + notice_lang(Config.s_HostServ, u, HOST_NOREG, nick.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_HostServ, u, LNG_REQUEST_SYNTAX); u->SendMessage(Config.s_HostServ, " "); @@ -195,7 +156,7 @@ class CommandHSRequest : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_HostServ, u, LNG_REQUEST_SYNTAX); } @@ -213,14 +174,14 @@ class CommandHSActivate : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); + Anope::string nick = params[0]; NickAlias *na; if ((na = findnick(nick))) { - std::map<ci::string, HostRequest *>::iterator it = Requests.find(na->nick); + RequestMap::iterator it = Requests.find(na->nick); if (it != Requests.end()) { na->hostinfo.SetVhost(it->second->ident, it->second->host, u->nick, it->second->time); @@ -230,19 +191,19 @@ class CommandHSActivate : public Command if (HSRequestMemoUser) my_memo_lang(u, na->nick, 2, LNG_ACTIVATE_MEMO); - me->NoticeLang(Config.s_HostServ, u, LNG_ACTIVATED, nick); + me->NoticeLang(Config.s_HostServ, u, LNG_ACTIVATED, nick.c_str()); Alog() << "Host Request for " << nick << " activated by " << u->nick; } else - me->NoticeLang(Config.s_HostServ, u, LNG_NO_REQUEST, nick); + me->NoticeLang(Config.s_HostServ, u, LNG_NO_REQUEST, nick.c_str()); } else - notice_lang(Config.s_HostServ, u, NICK_X_NOT_REGISTERED, nick); + notice_lang(Config.s_HostServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_HostServ, u, LNG_ACTIVATE_SYNTAX); u->SendMessage(Config.s_HostServ, " "); @@ -253,7 +214,7 @@ class CommandHSActivate : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_HostServ, u, LNG_ACTIVATE_SYNTAX); } @@ -271,12 +232,12 @@ class CommandHSReject : public Command { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - const char *nick = params[0].c_str(); - const char *reason = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string nick = params[0]; + Anope::string reason = params.size() > 1 ? params[1] : ""; - std::map<ci::string, HostRequest *>::iterator it = Requests.find(nick); + RequestMap::iterator it = Requests.find(nick); if (it != Requests.end()) { delete it->second; @@ -284,22 +245,22 @@ class CommandHSReject : public Command if (HSRequestMemoUser) { - if (reason) - my_memo_lang(u, nick, 2, LNG_REJECT_MEMO_REASON, reason); + if (!reason.empty()) + my_memo_lang(u, nick, 2, LNG_REJECT_MEMO_REASON, reason.c_str()); else my_memo_lang(u, nick, 2, LNG_REJECT_MEMO); } - me->NoticeLang(Config.s_HostServ, u, LNG_REJECTED, nick); - Alog() << "Host Request for " << nick << " rejected by " << u->nick << " (" << (reason ? reason : "") << ")"; + me->NoticeLang(Config.s_HostServ, u, LNG_REJECTED, nick.c_str()); + Alog() << "Host Request for " << nick << " rejected by " << u->nick << " (" << (!reason.empty() ? reason : "") << ")"; } else - me->NoticeLang(Config.s_HostServ, u, LNG_NO_REQUEST, nick); + me->NoticeLang(Config.s_HostServ, u, LNG_NO_REQUEST, nick.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_HostServ, u, LNG_REJECT_SYNTAX); u->SendMessage(Config.s_HostServ, " "); @@ -310,7 +271,7 @@ class CommandHSReject : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_HostServ, u, LNG_REJECT_SYNTAX); } @@ -327,7 +288,7 @@ class HSListBase : public Command unsigned display_counter = 0; tm *tm; - for (std::map<ci::string, HostRequest *>::iterator it = Requests.begin(), it_end = Requests.end(); it != it_end; ++it) + for (RequestMap::iterator it = Requests.begin(), it_end = Requests.end(); it != it_end; ++it) { HostRequest *hr = it->second; if (((counter >= from && counter <= to) || (!from && !to)) && display_counter < Config.NSListMax) @@ -347,11 +308,11 @@ class HSListBase : public Command return MOD_CONT; } public: - HSListBase(const ci::string &cmd, int min, int max) : Command(cmd, min, max, "hostserv/set") + HSListBase(const Anope::string &cmd, int min, int max) : Command(cmd, min, max, "hostserv/set") { } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { // no-op } @@ -364,12 +325,12 @@ class CommandHSWaiting : public HSListBase { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { return this->DoList(u); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_HostServ, u, LNG_WAITING_SYNTAX); u->SendMessage(Config.s_HostServ, " "); @@ -382,7 +343,7 @@ class CommandHSWaiting : public HSListBase class HSRequest : public Module { public: - HSRequest(const std::string &modname, const std::string &creator) : Module(modname, creator) + HSRequest(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { me = this; @@ -396,7 +357,7 @@ class HSRequest : public Module my_load_config(); - const char* langtable_en_us[] = { + const char *langtable_en_us[] = { /* LNG_REQUEST_SYNTAX */ "Syntax: \002REQUEST \037vhost\037\002", /* LNG_REQUESTED */ @@ -446,7 +407,7 @@ class HSRequest : public Module "the same as performing a LIST +req ." }; - const char* langtable_nl[] = { + const char *langtable_nl[] = { /* LNG_REQUEST_SYNTAX */ "Gebruik: \002REQUEST \037vhost\037\002", /* LNG_REQUESTED */ @@ -496,7 +457,7 @@ class HSRequest : public Module "hetzelfde als LIST +req ." }; - const char* langtable_pt[] = { + const char *langtable_pt[] = { /* LNG_REQUEST_SYNTAX */ "Sintaxe: \002REQUEST \037vhost\037\002", /* LNG_REQUESTED */ @@ -546,7 +507,7 @@ class HSRequest : public Module "o mesmo que fazer um LIST +req" }; - const char* langtable_ru[] = { + const char *langtable_ru[] = { /* LNG_REQUEST_SYNTAX */ "Ñèíòàêñèñ: \002REQUEST \037vHost\037\002", /* LNG_REQUESTED */ @@ -596,7 +557,7 @@ class HSRequest : public Module "îæèäàþùèõ îáðàáîòêè. Àíàëîãè÷íàÿ êîìàíäà: LIST +req ." }; - const char* langtable_it[] = { + const char *langtable_it[] = { /* LNG_REQUEST_SYNTAX */ "Sintassi: \002REQUEST \037vhost\037\002", /* LNG_REQUESTED */ @@ -666,32 +627,32 @@ class HSRequest : public Module } } - EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms) + EventReturn OnPreCommand(User *u, BotInfo *service, const Anope::string &command, const std::vector<Anope::string> ¶ms) { - if (Config.s_HostServ && service == Config.s_HostServ) + if (!Config.s_HostServ.empty() && service == findbot(Config.s_HostServ)) { - if (command == "LIST") + if (command.equals_ci("LIST")) { - ci::string key = params.size() ? params[0] : ""; + Anope::string key = params.size() ? params[0] : ""; - if (!key.empty() && key == "+req") + if (!key.empty() && key.equals_ci("+req")) { - std::vector<ci::string> emptyParams; + std::vector<Anope::string> emptyParams; Command *c = FindCommand(HostServ, "WAITING"); c->Execute(u, emptyParams); return EVENT_STOP; } } } - else if (service == Config.s_NickServ) + else if (service == findbot(Config.s_NickServ)) { - if (command == "DROP") + if (command.equals_ci("DROP")) { NickAlias *na = findnick(u->nick); if (na) { - std::map<ci::string, HostRequest *>::iterator it = Requests.find(na->nick); + RequestMap::iterator it = Requests.find(na->nick); if (it != Requests.end()) { @@ -705,12 +666,12 @@ class HSRequest : public Module return EVENT_CONTINUE; } - EventReturn OnDatabaseRead(const std::vector<std::string> ¶ms) + EventReturn OnDatabaseRead(const std::vector<Anope::string> ¶ms) { - if (params[0] == "HS_REQUEST" && params.size() >= 5) + if (params[0].equals_ci("HS_REQUEST") && params.size() >= 5) { - char *vident = params[2] == "(null)" ? NULL : const_cast<char *>(params[2].c_str()); - my_add_host_request(const_cast<char *>(params[1].c_str()), vident, const_cast<char *>(params[3].c_str()), const_cast<char *>(params[1].c_str()), strtol(params[4].c_str(), NULL, 10)); + Anope::string vident = params[2].equals_ci("(null)") ? "" : params[2]; + my_add_host_request(params[1], vident, params[3], params[1], params[4].is_number_only() ? convertTo<time_t>(params[4]) : 0); return EVENT_STOP; } @@ -718,9 +679,9 @@ class HSRequest : public Module return EVENT_CONTINUE; } - void OnDatabaseWrite(void (*Write)(const std::string &)) + void OnDatabaseWrite(void (*Write)(const Anope::string &)) { - for (std::map<ci::string, HostRequest *>::iterator it = Requests.begin(), it_end = Requests.end(); it != it_end; ++it) + for (RequestMap::iterator it = Requests.begin(), it_end = Requests.end(); it != it_end; ++it) { HostRequest *hr = it->second; std::stringstream buf; @@ -730,7 +691,7 @@ class HSRequest : public Module } }; -void my_memo_lang(User *u, const char *name, int z, int number, ...) +void my_memo_lang(User *u, const Anope::string &name, int z, int number, ...) { va_list va; char buffer[4096], outbuf[4096]; @@ -753,7 +714,7 @@ void my_memo_lang(User *u, const char *name, int z, int number, ...) { fmt = me->lang[lang].argv[number]; - buf = sstrdup(fmt); + buf = strdup(fmt); s = buf; while (*s) { @@ -774,22 +735,21 @@ void my_memo_lang(User *u, const char *name, int z, int number, ...) Alog() << me->name << ": INVALID language string call, language: [" << lang << "], String [" << number << "]"; } -void req_send_memos(User *u, char *vIdent, char *vHost) +void req_send_memos(User *u, const Anope::string &vIdent, const Anope::string &vHost) { - int z = 2; - char host[BUFSIZE]; - std::list<std::pair<ci::string, ci::string> >::iterator it, it_end; + Anope::string host; + std::list<std::pair<Anope::string, Anope::string> >::iterator it, it_end; - if (vIdent) - snprintf(host, sizeof(host), "%s@%s", vIdent, vHost); + if (!vIdent.empty()) + host = vIdent + "@" + vHost; else - snprintf(host, sizeof(host), "%s", vHost); + host = vHost; if (HSRequestMemoOper == 1) for (it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) { - ci::string nick = it->first; - my_memo_lang(u, nick.c_str(), z, LNG_REQUEST_MEMO, host); + Anope::string nick = it->first; + my_memo_lang(u, nick, 2, LNG_REQUEST_MEMO, host.c_str()); } if (HSRequestMemoSetters == 1) { @@ -799,13 +759,13 @@ void req_send_memos(User *u, char *vIdent, char *vHost) } } -void my_add_host_request(char *nick, char *vIdent, char *vhost, char *creator, time_t tmp_time) +void my_add_host_request(const Anope::string &nick, const Anope::string &vIdent, const Anope::string &vhost, const Anope::string &creator, time_t tmp_time) { HostRequest *hr = new HostRequest; - hr->ident = vIdent ? vIdent : ""; + hr->ident = vIdent; hr->host = vhost; hr->time = tmp_time; - std::map<ci::string, HostRequest *>::iterator it = Requests.find(nick); + RequestMap::iterator it = Requests.find(nick); if (it != Requests.end()) { delete it->second; @@ -814,7 +774,7 @@ void my_add_host_request(char *nick, char *vIdent, char *vhost, char *creator, t Requests.insert(std::make_pair(nick, hr)); } -int my_isvalidchar(const char c) +int my_isvalidchar(char c) { if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-') return 1; diff --git a/modules/extra/m_helpchan.cpp b/modules/extra/m_helpchan.cpp index c63703f33..6d95cceca 100644 --- a/modules/extra/m_helpchan.cpp +++ b/modules/extra/m_helpchan.cpp @@ -9,10 +9,10 @@ class HelpChannel : public Module { - ci::string HelpChan; + Anope::string HelpChan; public: - HelpChannel(const std::string &modname, const std::string &creator) : Module(modname, creator) + HelpChannel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(SUPPORTED); @@ -23,9 +23,9 @@ class HelpChannel : public Module OnReload(true); } - EventReturn OnChannelModeSet(Channel *c, ChannelModeName Name, const std::string ¶m) + EventReturn OnChannelModeSet(Channel *c, ChannelModeName Name, const Anope::string ¶m) { - if (Name == CMODE_OP && c && c->ci && c->name == this->HelpChan) + if (Name == CMODE_OP && c && c->ci && c->name.equals_ci(this->HelpChan)) { User *u = finduser(param); @@ -40,7 +40,7 @@ class HelpChannel : public Module { ConfigReader config; - this->HelpChan = config.ReadValue("m_helpchan", "helpchannel", "", 0).c_str(); + this->HelpChan = config.ReadValue("m_helpchan", "helpchannel", "", 0); } }; diff --git a/modules/extra/m_ssl.cpp b/modules/extra/m_ssl.cpp index 599e76e8f..386dd0d5f 100644 --- a/modules/extra/m_ssl.cpp +++ b/modules/extra/m_ssl.cpp @@ -24,12 +24,12 @@ class SSLSocket : public ClientSocket return SSL_read(sslsock, buf, sz); } - const int SendInternal(const std::string &buf) const + const int SendInternal(const Anope::string &buf) const { - return SSL_write(sslsock, buf.c_str(), buf.size()); + return SSL_write(sslsock, buf.c_str(), buf.length()); } public: - SSLSocket(const std::string &nTargetHost, int nPort, const std::string &nBindHost = "", bool nIPv6 = false) : ClientSocket(nTargetHost, nPort, nBindHost, nIPv6) + SSLSocket(const Anope::string &nTargetHost, int nPort, const Anope::string &nBindHost = "", bool nIPv6 = false) : ClientSocket(nTargetHost, nPort, nBindHost, nIPv6) { this->SetBlocking(); @@ -39,7 +39,7 @@ class SSLSocket : public ClientSocket throw CoreException("Unable to initialize SSL socket"); SSL_set_connect_state(sslsock); - SSL_set_fd(sslsock, sock); + SSL_set_fd(sslsock, Sock); SSL_connect(sslsock); UplinkSock = this; @@ -55,7 +55,7 @@ class SSLSocket : public ClientSocket UplinkSock = NULL; } - bool Read(const std::string &buf) + bool Read(const Anope::string &buf) { process(buf); return true; @@ -65,7 +65,7 @@ class SSLSocket : public ClientSocket class SSLModule : public Module { public: - SSLModule(const std::string &modname, const std::string &creator) : Module(modname, creator) + SSLModule(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { SSL_load_error_strings(); SSLeay_add_ssl_algorithms(); @@ -128,10 +128,10 @@ class SSLModule : public Module { try { - new SSLSocket(u->host, u->port, Config.LocalHost ? Config.LocalHost : "", u->ipv6); + new SSLSocket(u->host, u->port, Config.LocalHost, u->ipv6); Alog() << "Connected to Server " << Number << " (" << u->host << ":" << u->port << ")"; } - catch (SocketException& ex) + catch (const SocketException &ex) { Alog() << "Unable to connect with SSL to server" << Number << " (" << u->host << ":" << u->port << "), " << ex.GetReason(); } diff --git a/modules/extra/mysql/db_mysql.h b/modules/extra/mysql/db_mysql.h index 32a2469c9..fcad2f24c 100644 --- a/modules/extra/mysql/db_mysql.h +++ b/modules/extra/mysql/db_mysql.h @@ -176,7 +176,7 @@ class DBMySQL : public Module unsigned int Port; unsigned int Delay; - DBMySQL(const std::string &modname, const std::string &creator) : Module(modname, creator) + DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { me = this; @@ -184,7 +184,7 @@ class DBMySQL : public Module this->SetType(DATABASE); if (!LoadConfig()) - throw ModuleException("Couldn't load config"); + throw ModuleException(Anope::string("Couldn't load config")); Con = new mysqlpp::Connection(false); Ne = new mysqlpp::NoExceptions(Con); @@ -193,7 +193,7 @@ class DBMySQL : public Module std::string Error = "MySQL: Error connecting to SQL server: "; Error += Con->error(); delete Con; - throw ModuleException(Error.c_str()); + throw ModuleException(Anope::string(Error)); } mysqlpp::Query query(Con); diff --git a/modules/extra/mysql/db_mysql_execute.cpp b/modules/extra/mysql/db_mysql_execute.cpp index 2cc6ab6df..079e88147 100644 --- a/modules/extra/mysql/db_mysql_execute.cpp +++ b/modules/extra/mysql/db_mysql_execute.cpp @@ -145,7 +145,7 @@ class DBMySQLExecute : public DBMySQL { SQLTimer *_SQLTimer; public: - DBMySQLExecute(const std::string &modname, const std::string &creator) : DBMySQL(modname, creator) + DBMySQLExecute(const Anope::string &modname, const Anope::string &creator) : DBMySQL(modname, creator) { _SQLTimer = new SQLTimer(); } diff --git a/modules/extra/mysql/db_mysql_read.cpp b/modules/extra/mysql/db_mysql_read.cpp index 3ffc82366..ff608b700 100644 --- a/modules/extra/mysql/db_mysql_read.cpp +++ b/modules/extra/mysql/db_mysql_read.cpp @@ -237,37 +237,37 @@ static void LoadDatabase() ci->bantype = atoi(qres[i]["bantype"].c_str()); if (qres[i]["mlock_on"].size()) { - std::vector<std::string> modes; + std::vector<Anope::string> modes; std::string buf; spacesepstream sep(SQLAssign(qres[i]["mlock_on"])); while (sep.GetToken(buf)) - modes.push_back(buf); + modes.push_back(Anope::string(buf)); - ci->Extend("db_mlock_modes_on", new ExtensibleItemRegular<std::vector<std::string> >(modes)); + ci->Extend("db_mlock_modes_on", new ExtensibleItemRegular<std::vector<Anope::string> >(modes)); } if (qres[i]["mlock_off"].size()) { - std::vector<std::string> modes; + std::vector<Anope::string> modes; std::string buf; spacesepstream sep(SQLAssign(qres[i]["mlock_off"])); while (sep.GetToken(buf)) - modes.push_back(buf); + modes.push_back(Anope::string(buf)); - ci->Extend("db_mlock_modes_off", new ExtensibleItemRegular<std::vector<std::string> >(modes)); + ci->Extend("db_mlock_modes_off", new ExtensibleItemRegular<std::vector<Anope::string> >(modes)); } if (qres[i]["mlock_params"].size()) { - std::vector<std::pair<std::string, std::string> > mlp; + std::vector<std::pair<Anope::string, Anope::string> > mlp; std::string buf, buf2; spacesepstream sep(SQLAssign(qres[i]["mlock_params"])); while (sep.GetToken(buf) && sep.GetToken(buf2)) - mlp.push_back(std::make_pair(buf, buf2)); + mlp.push_back(std::make_pair(Anope::string(buf), Anope::string(buf2))); - ci->Extend("db_mlp", new ExtensibleItemRegular<std::vector<std::pair<std::string, std::string> > >(mlp)); + ci->Extend("db_mlp", new ExtensibleItemRegular<std::vector<std::pair<Anope::string, Anope::string> > >(mlp)); } if (qres[i]["entry_message"].size()) ci->entry_message = sstrdup(qres[i]["entry_message"].c_str()); @@ -594,7 +594,7 @@ static void LoadDatabase() class DBMySQLRead : public DBMySQL { public: - DBMySQLRead(const std::string &modname, const std::string &creator) : DBMySQL(modname, creator) + DBMySQLRead(const Anope::string &modname, const Anope::string &creator) : DBMySQL(modname, creator) { Implementation i[] = { I_OnLoadDatabase }; ModuleManager::Attach(i, this, 1); diff --git a/modules/extra/mysql/db_mysql_write.cpp b/modules/extra/mysql/db_mysql_write.cpp index c5c002a7e..2d44450c1 100644 --- a/modules/extra/mysql/db_mysql_write.cpp +++ b/modules/extra/mysql/db_mysql_write.cpp @@ -161,7 +161,7 @@ void WriteMetadata(const std::string &key, const std::string &data) void WriteNickMetadata(const std::string &key, const std::string &data) { if (!CurNick) - throw CoreException("WriteNickMetadata without a nick to write"); + throw CoreException(Anope::string("WriteNickMetadata without a nick to write")); mysqlpp::Query query(me->Con); query << "INSERT DELAYED INTO `anope_ns_alias_metadata` (nick, name, value) VALUES(" << mysqlpp::quote << CurNick->nick << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; @@ -171,7 +171,7 @@ void WriteNickMetadata(const std::string &key, const std::string &data) void WriteCoreMetadata(const std::string &key, const std::string &data) { if (!CurCore) - throw CoreException("WritCoreMetadata without a core to write"); + throw CoreException(Anope::string("WritCoreMetadata without a core to write")); mysqlpp::Query query(me->Con); query << "INSERT DELAYED INTO `anope_ns_core_metadata` (nick, name, value) VALUES(" << mysqlpp::quote << CurCore->display << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; @@ -181,7 +181,7 @@ void WriteCoreMetadata(const std::string &key, const std::string &data) void WriteChannelMetadata(const std::string &key, const std::string &data) { if (!CurChannel) - throw CoreException("WriteChannelMetadata without a channel to write"); + throw CoreException(Anope::string("WriteChannelMetadata without a channel to write")); mysqlpp::Query query(me->Con); query << "INSERT DELAYED INTO `anope_cs_info_metadata` (channel, name, value) VALUES(" << mysqlpp::quote << CurChannel->name << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; @@ -191,7 +191,7 @@ void WriteChannelMetadata(const std::string &key, const std::string &data) void WriteBotMetadata(const std::string &key, const std::string &data) { if (!CurBot) - throw CoreException("WriteBotMetadata without a bot to write"); + throw CoreException(Anope::string("WriteBotMetadata without a bot to write")); mysqlpp::Query query(me->Con); query << "INSERT DELAYED INTO `anope_bs_info_metadata` (botname, name, value) VALUES(" << mysqlpp::quote << CurBot->nick << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; @@ -336,7 +336,7 @@ class CommandSyncSQL : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP_SYNC); return true; @@ -351,7 +351,7 @@ class CommandSyncSQL : public Command class DBMySQLWrite : public DBMySQL { public: - DBMySQLWrite(const std::string &modname, const std::string &creator) : DBMySQL(modname, creator) + DBMySQLWrite(const Anope::string &modname, const Anope::string &creator) : DBMySQL(modname, creator) { me = this; @@ -612,14 +612,14 @@ class DBMySQLWrite : public DBMySQL } } - void OnNickAddAccess(NickCore *nc, const std::string &entry) + void OnNickAddAccess(NickCore *nc, const Anope::string &entry) { mysqlpp::Query query(me->Con); query << "INSERT DELAYED INTO `anope_ns_access` (display, access) VALUES(" << mysqlpp::quote << nc->display << ", " << mysqlpp::quote << entry << ")"; ExecuteQuery(query); } - void OnNickEraseAccess(NickCore *nc, const std::string &entry) + void OnNickEraseAccess(NickCore *nc, const Anope::string &entry) { mysqlpp::Query query(me->Con); query << "DELETE FROM `anope_ns_access` WHERE `display` = " << mysqlpp::quote << nc->display << " AND `access` = " << mysqlpp::quote << entry; @@ -703,7 +703,7 @@ class DBMySQLWrite : public DBMySQL ExecuteQuery(query); } - void OnChangeCoreDisplay(NickCore *nc, const std::string &newdisplay) + void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) { mysqlpp::Query query(me->Con); query << "UPDATE `anope_ns_core` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display; diff --git a/modules/extra/ns_maxemail.cpp b/modules/extra/ns_maxemail.cpp index 89ffd90da..bcddc18f5 100644 --- a/modules/extra/ns_maxemail.cpp +++ b/modules/extra/ns_maxemail.cpp @@ -1,5 +1,5 @@ /* ns_maxemail.c - Limit the amount of times an email address - * can be used for a NickServ account. + * can be used for a NickServ account. * * (C) 2003-2010 Anope Team * Contact us at team@anope.org @@ -19,7 +19,7 @@ void my_load_config(); void my_add_languages(); -bool check_email_limit_reached(const char *email, User * u); +bool check_email_limit_reached(const Anope::string &email, User *u); int NSEmailMax = 0; @@ -35,7 +35,7 @@ static Module *me; class NSMaxEmail : public Module { public: - NSMaxEmail(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSMaxEmail(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { me = this; @@ -102,21 +102,21 @@ class NSMaxEmail : public Module my_load_config(); } - EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms) + EventReturn OnPreCommand(User *u, BotInfo *service, const Anope::string &command, const std::vector<Anope::string> ¶ms) { - if (service == Config.s_NickServ) + if (service == findbot(Config.s_NickServ)) { - if (command == "REGISTER") + if (command.equals_ci("REGISTER")) { - if (check_email_limit_reached(params.size() > 1 ? params[1].c_str() : NULL, u)) + if (check_email_limit_reached(params.size() > 1 ? params[1] : "", u)) return EVENT_STOP; } - else if (command == "SET") + else if (command.equals_ci("SET")) { - ci::string set = params[0]; - const char *email = params.size() > 1 ? params[1].c_str() : NULL; + Anope::string set = params[0]; + Anope::string email = params.size() > 1 ? params[1] : ""; - if (set == "email" && check_email_limit_reached(email, u)) + if (set.equals_ci("email") && check_email_limit_reached(email, u)) return EVENT_STOP; } } @@ -125,27 +125,27 @@ class NSMaxEmail : public Module } }; -int count_email_in_use(const char *email, User * u) +int count_email_in_use(const Anope::string &email, User *u) { int count = 0; - if (!email) + if (email.empty()) return 0; for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it) { NickCore *nc = it->second; - if (!(u->Account() && u->Account() == nc) && nc->email && !stricmp(nc->email, email)) + if (!(u->Account() && u->Account() == nc) && !nc->email.empty() && nc->email.equals_ci(email)) ++count; } return count; } -bool check_email_limit_reached(const char *email, User * u) +bool check_email_limit_reached(const Anope::string &email, User *u) { - if (NSEmailMax < 1 || !email) + if (NSEmailMax < 1 || email.empty()) return false; if (count_email_in_use(email, u) < NSEmailMax) diff --git a/modules/extra/ns_set_misc.cpp b/modules/extra/ns_set_misc.cpp index 00d7d2adf..9e0f23eb0 100644 --- a/modules/extra/ns_set_misc.cpp +++ b/modules/extra/ns_set_misc.cpp @@ -16,41 +16,39 @@ class CommandNSSetMisc : public Command { private: - std::string Desc; + Anope::string Desc; protected: - CommandReturn RealExecute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn RealExecute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); assert(nc); - nc->Shrink("nickserv:" + std::string(this->name.c_str())); + nc->Shrink("nickserv:" + this->name); if (params.size() > 1) { - nc->Extend("nickserv:" + std::string(this->name.c_str()), new ExtensibleItemRegular<ci::string>(params[1])); - notice_lang(Config.s_NickServ, u, CHAN_SETTING_CHANGED, this->name.c_str(), nc->display, params[1].c_str()); + nc->Extend("nickserv:" + this->name, new ExtensibleItemRegular<Anope::string>(params[1])); + notice_lang(Config.s_NickServ, u, CHAN_SETTING_CHANGED, this->name.c_str(), nc->display.c_str(), params[1].c_str()); } else - { - notice_lang(Config.s_NickServ, u, CHAN_SETTING_UNSET, this->name.c_str(), nc->display); - } + notice_lang(Config.s_NickServ, u, CHAN_SETTING_UNSET, this->name.c_str(), nc->display.c_str()); return MOD_CONT; } public: - CommandNSSetMisc(const ci::string &cname, const std::string &desc, const ci::string &cpermission = "") : Command(cname, 0, 1, cpermission), Desc(desc) + CommandNSSetMisc(const Anope::string &cname, const Anope::string &desc, const Anope::string &cpermission = "") : Command(cname, 0, 1, cpermission), Desc(desc) { } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { - std::vector<ci::string> realparams = params; + std::vector<Anope::string> realparams = params; realparams.insert(realparams.begin(), u->Account()->display); return RealExecute(u, realparams); } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SET", NICK_SET_SYNTAX); } @@ -64,18 +62,18 @@ class CommandNSSetMisc : public Command class CommandNSSASetMisc : public CommandNSSetMisc { public: - CommandNSSASetMisc(const ci::string &cname, const std::string &desc) : CommandNSSetMisc(cname, desc, "nickserv/saset/" + cname) + CommandNSSASetMisc(const Anope::string &cname, const Anope::string &desc) : CommandNSSetMisc(cname, desc, "nickserv/saset/" + cname) { this->MinParams = 1; this->MaxParams = 2; } - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { return RealExecute(u, params); } - void OnSyntaxError(User *u, const ci::string &) + void OnSyntaxError(User *u, const Anope::string &) { syntax_error(Config.s_NickServ, u, "SASET", NICK_SASET_SYNTAX); } @@ -85,14 +83,14 @@ class NSSetMisc : public Module { struct CommandInfo { - std::string Name; - std::string Desc; + Anope::string Name; + Anope::string Desc; bool ShowHidden; - CommandInfo(const std::string &name, const std::string &desc, bool showhidden) : Name(name), Desc(desc), ShowHidden(showhidden) { } + CommandInfo(const Anope::string &name, const Anope::string &desc, bool showhidden) : Name(name), Desc(desc), ShowHidden(showhidden) { } }; - std::map<std::string, CommandInfo *> Commands; + std::map<Anope::string, CommandInfo *> Commands; void RemoveAll() { @@ -105,12 +103,12 @@ class NSSetMisc : public Module if (!set && !saset) return; - for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) { if (set) - set->DelSubcommand(it->first.c_str()); + set->DelSubcommand(it->first); if (saset) - saset->DelSubcommand(it->first.c_str()); + saset->DelSubcommand(it->first); delete it->second; } @@ -118,7 +116,7 @@ class NSSetMisc : public Module } public: - NSSetMisc(const std::string &modname, const std::string &creator) : Module(modname, creator) + NSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); @@ -145,12 +143,12 @@ class NSSetMisc : public Module ConfigReader config; - for (int i = 0; true; ++i) + for (int i = 0, num = config.Enumerate("ns_set_misc"); i < num; ++i) { - std::string cname = config.ReadValue("ns_set_misc", "name", "", i); + Anope::string cname = config.ReadValue("ns_set_misc", "name", "", i); if (cname.empty()) - break; - std::string desc = config.ReadValue("ns_set_misc", "desc", "", i); + continue; + Anope::string desc = config.ReadValue("ns_set_misc", "desc", "", i); bool showhidden = config.ReadFlag("ns_set_misc", "operonly", "no", i); CommandInfo *info = new CommandInfo(cname, desc, showhidden); @@ -162,49 +160,40 @@ class NSSetMisc : public Module } if (set) - set->AddSubcommand(new CommandNSSetMisc(cname.c_str(), desc)); + set->AddSubcommand(new CommandNSSetMisc(cname, desc)); if (saset) - saset->AddSubcommand(new CommandNSSASetMisc(cname.c_str(), desc)); + saset->AddSubcommand(new CommandNSSASetMisc(cname, desc)); } } void OnNickInfo(User *u, NickAlias *na, bool ShowHidden) { - for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) { if (!ShowHidden && it->second->ShowHidden) continue; - ci::string value; + Anope::string value; if (na->nc->GetExtRegular("nickserv:" + it->first, value)) - { u->SendMessage(Config.s_NickServ, " %s: %s", it->first.c_str(), value.c_str()); - } } } - void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), NickCore *nc) + void OnDatabaseWriteMetadata(void (*WriteMetadata)(const Anope::string &, const Anope::string &), NickCore *nc) { - for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) { - ci::string value; - + Anope::string value; if (nc->GetExtRegular("nickserv:" + it->first, value)) - { - WriteMetadata(it->first, ":" + std::string(value.c_str())); - } + WriteMetadata(it->first, ":" + value); } } - EventReturn OnDatabaseReadMetadata(NickCore *nc, const std::string &key, const std::vector<std::string> ¶ms) + EventReturn OnDatabaseReadMetadata(NickCore *nc, const Anope::string &key, const std::vector<Anope::string> ¶ms) { - for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) - { + for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) if (key == it->first) - { - nc->Extend("nickserv:" + it->first, new ExtensibleItemRegular<ci::string>(params[0].c_str())); - } - } + nc->Extend("nickserv:" + it->first, new ExtensibleItemRegular<Anope::string>(params[0])); return EVENT_CONTINUE; } diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index d7849c940..1f8b70ef7 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -7,8 +7,6 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ /*************************************************************************/ @@ -45,7 +43,6 @@ IRCDVar myIrcd[] = { 0, /* Change RealName */ 1, /* No Knock requires +i */ 0, /* We support TOKENS */ - 0, /* TIME STAMPS are BASE64 */ 0, /* Can remove User Channel Modes with SVSMODE */ 0, /* Sglines are not enforced until user reconnects */ 0, /* ts6 */ @@ -60,7 +57,7 @@ IRCDVar myIrcd[] = { void bahamut_cmd_burst() { - send_cmd(NULL, "BURST"); + send_cmd("", "BURST"); } /* @@ -73,138 +70,131 @@ void bahamut_cmd_burst() */ void bahamut_cmd_svinfo() { - send_cmd(NULL, "SVINFO 3 1 0 :%ld", static_cast<long>(time(NULL))); + send_cmd("", "SVINFO 3 1 0 :%ld", static_cast<long>(time(NULL))); } /* PASS */ -void bahamut_cmd_pass(const char *pass) +void bahamut_cmd_pass(const Anope::string &pass) { - send_cmd(NULL, "PASS %s :TS", pass); + send_cmd("", "PASS %s :TS", pass.c_str()); } /* CAPAB */ void bahamut_cmd_capab() { - send_cmd(NULL, "CAPAB SSJOIN NOQUIT BURST UNCONNECT NICKIP TSMODE TS3"); -} - -/* this avoids "undefined symbol" messages of those whom try to load mods that - call on this function */ -void bahamut_cmd_chghost(const char *nick, const char *vhost) -{ - Alog(LOG_DEBUG) << "This IRCD does not support vhosting"; + send_cmd("", "CAPAB SSJOIN NOQUIT BURST UNCONNECT NICKIP TSMODE TS3"); } class BahamutIRCdProto : public IRCDProto { - void SendModeInternal(BotInfo *source, Channel *dest, const char *buf) + void SendModeInternal(BotInfo *source, Channel *dest, const Anope::string &buf) { - if (!buf) + if (buf.empty()) return; if (Capab.HasFlag(CAPAB_TSMODE)) - send_cmd(source->nick, "MODE %s 0 %s", dest->name.c_str(), buf); + send_cmd(source->nick, "MODE %s 0 %s", dest->name.c_str(), buf.c_str()); else - send_cmd(source->nick, "MODE %s %s", dest->name.c_str(), buf); + send_cmd(source->nick, "MODE %s %s", dest->name.c_str(), buf.c_str()); } - void SendModeInternal(BotInfo *bi, User *u, const char *buf) + void SendModeInternal(BotInfo *bi, User *u, const Anope::string &buf) { - if (!buf) + if (buf.empty()) return; - send_cmd(bi ? bi->nick : Config.ServerName, "SVSMODE %s %ld %s", u->nick.c_str(), static_cast<long>(u->timestamp), buf); + send_cmd(bi ? bi->nick : Config.ServerName, "SVSMODE %s %ld %s", u->nick.c_str(), static_cast<long>(u->timestamp), buf.c_str()); } /* SVSHOLD - set */ - void SendSVSHold(const char *nick) + void SendSVSHold(const Anope::string &nick) { - send_cmd(Config.ServerName, "SVSHOLD %s %u :%s", nick, static_cast<unsigned>(Config.NSReleaseTimeout), "Being held for registered user"); + send_cmd(Config.ServerName, "SVSHOLD %s %u :Being held for registered user", nick.c_str(), static_cast<unsigned>(Config.NSReleaseTimeout)); } /* SVSHOLD - release */ - void SendSVSHoldDel(const char *nick) + void SendSVSHoldDel(const Anope::string &nick) { - send_cmd(Config.ServerName, "SVSHOLD %s 0", nick); + send_cmd(Config.ServerName, "SVSHOLD %s 0", nick.c_str()); } /* SVSMODE -b */ - void SendBanDel(Channel *c, const std::string &nick) + void SendBanDel(Channel *c, const Anope::string &nick) { - SendSVSModeChan(c, "-b", nick.empty() ? NULL : nick.c_str()); + SendSVSModeChan(c, "-b", nick); } /* SVSMODE channel modes */ - void SendSVSModeChan(Channel *c, const char *mode, const char *nick) + void SendSVSModeChan(Channel *c, const Anope::string &mode, const Anope::string &nick) { - if (nick) - send_cmd(Config.ServerName, "SVSMODE %s %s %s", c->name.c_str(), mode, nick); + if (!nick.empty()) + send_cmd(Config.ServerName, "SVSMODE %s %s %s", c->name.c_str(), mode.c_str(), nick.c_str()); else - send_cmd(Config.ServerName, "SVSMODE %s %s", c->name.c_str(), mode); + send_cmd(Config.ServerName, "SVSMODE %s %s", c->name.c_str(), mode.c_str()); } /* SQLINE */ void SendSQLine(XLine *x) { - send_cmd(NULL, "SQLINE %s :%s", x->Mask.c_str(), x->Reason.c_str()); + send_cmd("", "SQLINE %s :%s", x->Mask.c_str(), x->Reason.c_str()); } /* UNSLINE */ void SendSGLineDel(XLine *x) { - send_cmd(NULL, "UNSGLINE 0 :%s", x->Mask.c_str()); + send_cmd("", "UNSGLINE 0 :%s", x->Mask.c_str()); } /* UNSZLINE */ void SendSZLineDel(XLine *x) { /* this will likely fail so its only here for legacy */ - send_cmd(NULL, "UNSZLINE 0 %s", x->Mask.c_str()); + send_cmd("", "UNSZLINE 0 %s", x->Mask.c_str()); /* this is how we are supposed to deal with it */ - send_cmd(NULL, "RAKILL %s *", x->Mask.c_str()); + send_cmd("", "RAKILL %s *", x->Mask.c_str()); } /* SZLINE */ void SendSZLine(XLine *x) { /* this will likely fail so its only here for legacy */ - send_cmd(NULL, "SZLINE %s :%s", x->Mask.c_str(), x->Reason.c_str()); + send_cmd("", "SZLINE %s :%s", x->Mask.c_str(), x->Reason.c_str()); /* this is how we are supposed to deal with it */ - send_cmd(NULL, "AKILL %s * %d %s %ld :%s", x->Mask.c_str(), 172800, x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd("", "AKILL %s * %d %s %ld :%s", x->Mask.c_str(), 172800, x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); } /* SVSNOOP */ - void SendSVSNOOP(const char *server, int set) + void SendSVSNOOP(const Anope::string &server, int set) { - send_cmd(NULL, "SVSNOOP %s %s", server, set ? "+" : "-"); + send_cmd("", "SVSNOOP %s %s", server.c_str(), set ? "+" : "-"); } /* SGLINE */ void SendSGLine(XLine *x) { - send_cmd(NULL, "SGLINE %d :%s:%s", static_cast<int>(x->Mask.length()), x->Mask.c_str(), x->Reason.c_str()); + send_cmd("", "SGLINE %d :%s:%s", static_cast<int>(x->Mask.length()), x->Mask.c_str(), x->Reason.c_str()); } /* RAKILL */ void SendAkillDel(XLine *x) { - send_cmd(NULL, "RAKILL %s %s", x->GetHost().c_str(), x->GetUser().c_str()); + send_cmd("", "RAKILL %s %s", x->GetHost().c_str(), x->GetUser().c_str()); } /* TOPIC */ - void SendTopic(BotInfo *whosets, Channel *c, const char *whosetit, const char *topic) + void SendTopic(BotInfo *whosets, Channel *c, const Anope::string &whosetit, const Anope::string &topic) { - send_cmd(whosets->nick, "TOPIC %s %s %lu :%s", c->name.c_str(), whosetit, static_cast<unsigned long>(c->topic_time), topic); + send_cmd(whosets->nick, "TOPIC %s %s %lu :%s", c->name.c_str(), whosetit.c_str(), static_cast<unsigned long>(c->topic_time), topic.c_str()); } /* UNSQLINE */ void SendSQLineDel(XLine *x) { - send_cmd(NULL, "UNSQLINE %s", x->Mask.c_str()); + send_cmd("", "UNSQLINE %s", x->Mask.c_str()); } /* JOIN - SJOIN */ - void SendJoin(BotInfo *user, const char *channel, time_t chantime) + void SendJoin(BotInfo *user, const Anope::string &channel, time_t chantime) { - send_cmd(user->nick, "SJOIN %ld %s", static_cast<long>(chantime), channel); + send_cmd(user->nick, "SJOIN %ld %s", static_cast<long>(chantime), channel.c_str()); } void SendAkill(XLine *x) @@ -213,15 +203,15 @@ class BahamutIRCdProto : public IRCDProto time_t timeleft = x->Expires - time(NULL); if (timeleft > 172800) timeleft = 172800; - send_cmd(NULL, "AKILL %s %s %d %s %ld :%s", x->GetHost().c_str(), x->GetUser().c_str(), static_cast<int>(timeleft), x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd("", "AKILL %s %s %d %s %ld :%s", x->GetHost().c_str(), x->GetUser().c_str(), static_cast<int>(timeleft), x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); } /* Note: if the stamp is null 0, the below usage is correct of Bahamut */ - void SendSVSKillInternal(BotInfo *source, User *user, const char *buf) + void SendSVSKillInternal(BotInfo *source, User *user, const Anope::string &buf) { - send_cmd(source ? source->nick : NULL, "SVSKILL %s :%s", user->nick.c_str(), buf); + send_cmd(source ? source->nick : "", "SVSKILL %s :%s", user->nick.c_str(), buf.c_str()); } /* SVSMODE */ @@ -238,28 +228,28 @@ class BahamutIRCdProto : public IRCDProto void SendEOB() { - send_cmd(NULL, "BURST 0"); + send_cmd("", "BURST 0"); } - void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const char *buf) + void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const Anope::string &buf) { - if (!buf) + if (buf.empty()) return; - send_cmd(NULL, "NOTICE @%s :%s", dest->name.c_str(), buf); + send_cmd("", "NOTICE @%s :%s", dest->name.c_str(), buf.c_str()); } - void SendKickInternal(BotInfo *source, Channel *chan, User *user, const char *buf) + void SendKickInternal(BotInfo *source, Channel *chan, User *user, const Anope::string &buf) { - if (buf) - send_cmd(source->nick, "KICK %s %s :%s", chan->name.c_str(), user->nick.c_str(), buf); + if (!buf.empty()) + send_cmd(source->nick, "KICK %s %s :%s", chan->name.c_str(), user->nick.c_str(), buf.c_str()); else send_cmd(source->nick, "KICK %s %s", chan->name.c_str(), user->nick.c_str()); } - void SendClientIntroduction(const std::string &nick, const std::string &user, const std::string &host, const std::string &real, const char *modes, const std::string &uid) + void SendClientIntroduction(const Anope::string &nick, const Anope::string &user, const Anope::string &host, const Anope::string &real, const Anope::string &modes, const Anope::string &) { EnforceQlinedNick(nick, Config.s_BotServ); - send_cmd(NULL, "NICK %s 1 %ld %s %s %s %s 0 0 :%s", nick.c_str(), static_cast<long>(time(NULL)), modes, user.c_str(), host.c_str(), Config.ServerName, real.c_str()); + send_cmd("", "NICK %s 1 %ld %s %s %s %s 0 0 :%s", nick.c_str(), static_cast<long>(time(NULL)), modes.c_str(), user.c_str(), host.c_str(), Config.ServerName.c_str(), real.c_str()); } /* SVSMODE +d */ @@ -274,7 +264,7 @@ class BahamutIRCdProto : public IRCDProto /* SERVER */ void SendServer(Server *server) { - send_cmd(NULL, "SERVER %s %d :%s", server->GetName().c_str(), server->GetHops(), server->GetDescription().c_str()); + send_cmd("", "SERVER %s %d :%s", server->GetName().c_str(), server->GetHops(), server->GetDescription().c_str()); } void SendConnect() @@ -288,28 +278,26 @@ class BahamutIRCdProto : public IRCDProto void SetAutoIdentificationToken(User *u) { - char svidbuf[15]; - if (!u->Account()) return; srand(time(NULL)); - snprintf(svidbuf, sizeof(svidbuf), "%d", rand()); + Anope::string svidbuf = stringify(rand()); u->Account()->Shrink("authenticationtoken"); - u->Account()->Extend("authenticationtoken", new ExtensibleItemPointerArray<char>(sstrdup(svidbuf))); + u->Account()->Extend("authenticationtoken", new ExtensibleItemRegular<Anope::string>(svidbuf)); BotInfo *bi = NickServ; u->SetMode(bi, UMODE_REGISTERED); - ircdproto->SendMode(bi, u, "+d %s", svidbuf); + ircdproto->SendMode(bi, u, "+d %s", svidbuf.c_str()); } } ircd_proto; /* EVENT: SJOIN */ -int anope_event_sjoin(const char *source, int ac, const char **av) +int anope_event_sjoin(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[1]); - time_t ts = atol(av[0]); + time_t ts = Anope::string(av[0]).is_number_only() ? convertTo<time_t>(av[0]) : 0; bool was_created = false; bool keep_their_modes = false; @@ -399,11 +387,10 @@ int anope_event_sjoin(const char *source, int ac, const char **av) else { spacesepstream sep(av[ac - 1]); - std::string buf; + Anope::string buf; while (sep.GetToken(buf)) { std::list<ChannelMode *> Status; - Status.clear(); char ch; /* Get prefixes from the nick */ @@ -488,13 +475,13 @@ int anope_event_sjoin(const char *source, int ac, const char **av) ** parv[0] = new nickname ** parv[1] = hopcount */ -int anope_event_nick(const char *source, int ac, const char **av) +int anope_event_nick(const Anope::string &source, int ac, const char **av) { User *user; if (ac != 2) { - user = do_nick(source, av[0], av[4], av[5], av[6], av[9], strtoul(av[2], NULL, 10), strtoul(av[8], NULL, 0), NULL, NULL); + user = do_nick(source, av[0], av[4], av[5], av[6], av[9], Anope::string(av[2]).is_number_only() ? convertTo<time_t>(av[2]) : 0, Anope::string(av[8]).is_number_only() ? convertTo<uint32>(av[8]) : 0, "", ""); if (user) { /* Check to see if the user should be identified because their @@ -506,19 +493,19 @@ int anope_event_nick(const char *source, int ac, const char **av) } } else - do_nick(source, av[0], NULL, NULL, NULL, NULL, strtoul(av[1], NULL, 10), 0, NULL, NULL); + do_nick(source, av[0], "", "", "", "", Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0, 0, "", ""); return MOD_CONT; } /* EVENT : CAPAB */ -int anope_event_capab(const char *source, int ac, const char **av) +int anope_event_capab(const Anope::string &source, int ac, const char **av) { CapabParse(ac, av); return MOD_CONT; } /* EVENT : OS */ -int anope_event_os(const char *source, int ac, const char **av) +int anope_event_os(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -527,7 +514,7 @@ int anope_event_os(const char *source, int ac, const char **av) } /* EVENT : NS */ -int anope_event_ns(const char *source, int ac, const char **av) +int anope_event_ns(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -536,7 +523,7 @@ int anope_event_ns(const char *source, int ac, const char **av) } /* EVENT : MS */ -int anope_event_ms(const char *source, int ac, const char **av) +int anope_event_ms(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -545,7 +532,7 @@ int anope_event_ms(const char *source, int ac, const char **av) } /* EVENT : HS */ -int anope_event_hs(const char *source, int ac, const char **av) +int anope_event_hs(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -554,7 +541,7 @@ int anope_event_hs(const char *source, int ac, const char **av) } /* EVENT : CS */ -int anope_event_cs(const char *source, int ac, const char **av) +int anope_event_cs(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -562,7 +549,7 @@ int anope_event_cs(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_436(const char *source, int ac, const char **av) +int anope_event_436(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -572,14 +559,14 @@ int anope_event_436(const char *source, int ac, const char **av) } /* EVENT : SERVER */ -int anope_event_server(const char *source, int ac, const char **av) +int anope_event_server(const Anope::string &source, int ac, const char **av) { - do_server(source, av[0], atoi(av[1]), av[2], ""); + do_server(source, av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, av[2], ""); return MOD_CONT; } /* EVENT : PRIVMSG */ -int anope_event_privmsg(const char *source, int ac, const char **av) +int anope_event_privmsg(const Anope::string &source, int ac, const char **av) { if (ac != 2) return MOD_CONT; @@ -587,7 +574,7 @@ int anope_event_privmsg(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_part(const char *source, int ac, const char **av) +int anope_event_part(const Anope::string &source, int ac, const char **av) { if (ac < 1 || ac > 2) return MOD_CONT; @@ -595,14 +582,14 @@ int anope_event_part(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_whois(const char *source, int ac, const char **av) +int anope_event_whois(const Anope::string &source, int ac, const char **av) { - if (source && ac >= 1) + if (!source.empty() && ac >= 1) m_whois(source, av[0]); return MOD_CONT; } -int anope_event_topic(const char *source, int ac, const char **av) +int anope_event_topic(const Anope::string &source, int ac, const char **av) { if (ac != 4) return MOD_CONT; @@ -610,7 +597,7 @@ int anope_event_topic(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_squit(const char *source, int ac, const char **av) +int anope_event_squit(const Anope::string &source, int ac, const char **av) { if (ac != 2) return MOD_CONT; @@ -618,7 +605,7 @@ int anope_event_squit(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_quit(const char *source, int ac, const char **av) +int anope_event_quit(const Anope::string &source, int ac, const char **av) { if (ac != 1) return MOD_CONT; @@ -627,7 +614,7 @@ int anope_event_quit(const char *source, int ac, const char **av) } /* EVENT: MODE */ -int anope_event_mode(const char *source, int ac, const char **av) +int anope_event_mode(const Anope::string &source, int ac, const char **av) { if (ac < 2) return MOD_CONT; @@ -640,7 +627,7 @@ int anope_event_mode(const char *source, int ac, const char **av) } /* EVENT: KILL */ -int anope_event_kill(const char *source, int ac, const char **av) +int anope_event_kill(const Anope::string &source, int ac, const char **av) { if (ac != 2) return MOD_CONT; @@ -650,7 +637,7 @@ int anope_event_kill(const char *source, int ac, const char **av) } /* EVENT: KICK */ -int anope_event_kick(const char *source, int ac, const char **av) +int anope_event_kick(const Anope::string &source, int ac, const char **av) { if (ac != 3) return MOD_CONT; @@ -659,7 +646,7 @@ int anope_event_kick(const char *source, int ac, const char **av) } /* EVENT: JOIN */ -int anope_event_join(const char *source, int ac, const char **av) +int anope_event_join(const Anope::string &source, int ac, const char **av) { if (ac != 1) return MOD_CONT; @@ -668,24 +655,24 @@ int anope_event_join(const char *source, int ac, const char **av) } /* EVENT: MOTD */ -int anope_event_motd(const char *source, int ac, const char **av) +int anope_event_motd(const Anope::string &source, int ac, const char **av) { - if (!source) + if (source.empty()) return MOD_CONT; m_motd(source); return MOD_CONT; } -int anope_event_away(const char *source, int ac, const char **av) +int anope_event_away(const Anope::string &source, int ac, const char **av) { - if (!source) + if (source.empty()) return MOD_CONT; - m_away(source, (ac ? av[0] : NULL)); + m_away(source, ac ? av[0] : ""); return MOD_CONT; } -int anope_event_ping(const char *source, int ac, const char **av) +int anope_event_ping(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -693,16 +680,16 @@ int anope_event_ping(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_error(const char *source, int ac, const char **av) +int anope_event_error(const Anope::string &source, int ac, const char **av) { if (ac >= 1) Alog(LOG_DEBUG) << av[0]; return MOD_CONT; } -int anope_event_burst(const char *source, int ac, const char **av) +int anope_event_burst(const Anope::string &source, int ac, const char **av) { - Server *s = Server::Find(source ? source : ""); + Server *s = Server::Find(source); if (!ac) { @@ -722,11 +709,10 @@ int anope_event_burst(const char *source, int ac, const char **av) return MOD_CONT; } -bool ChannelModeFlood::IsValid(const std::string &value) +bool ChannelModeFlood::IsValid(const Anope::string &value) { - char *dp, *end; - - if (!value.empty() && value[0] != ':' && strtoul((value[0] == '*' ? value.c_str() + 1 : value.c_str()), &dp, 10) > 0 && *dp == ':' && *(++dp) && strtoul(dp, &end, 10) > 0 && !*end) + Anope::string rest; + if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty()) return true; return false; @@ -769,7 +755,7 @@ static void AddModes() ModeManager::AddUserMode(new UserMode(UMODE_REGPRIV, "UMODE_REGPRIV", 'R')); ModeManager::AddUserMode(new UserMode(UMODE_ADMIN, "UMODE_ADMIN", 'a')); ModeManager::AddUserMode(new UserMode(UMODE_INVIS, "UMODE_INVIS", 'i')); - ModeManager::AddUserMode(new UserMode(UMODE_OPER,"UMODE_OPER", 'o')); + ModeManager::AddUserMode(new UserMode(UMODE_OPER, "UMODE_OPER", 'o')); ModeManager::AddUserMode(new UserMode(UMODE_REGISTERED, "UMODE_REGISTERED", 'r')); ModeManager::AddUserMode(new UserMode(UMODE_SNOMASK, "UMODE_SNOMASK", 's')); ModeManager::AddUserMode(new UserMode(UMODE_WALLOPS, "UMODE_WALLOPS", 'w')); @@ -802,7 +788,7 @@ static void AddModes() class ProtoBahamut : public Module { public: - ProtoBahamut(const std::string &modname, const std::string &creator) : Module(modname, creator) + ProtoBahamut(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(PROTOCOL); @@ -823,7 +809,7 @@ class ProtoBahamut : public Module ModuleManager::Attach(I_OnUserNickChange, this); } - void OnUserNickChange(User *u, const std::string &) + void OnUserNickChange(User *u, const Anope::string &) { u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED)); } diff --git a/modules/protocol/inspircd11.cpp b/modules/protocol/inspircd11.cpp index ac50f64b9..9e21516e6 100644 --- a/modules/protocol/inspircd11.cpp +++ b/modules/protocol/inspircd11.cpp @@ -15,22 +15,6 @@ #include "modules.h" #include "hashcomp.h" -#ifndef _WIN32 -# include <sys/socket.h> -# include <netinet/in.h> -# include <arpa/inet.h> -#endif - -#ifdef _WIN32 -# include <winsock.h> -int inet_aton(const char *name, struct in_addr *addr) -{ - uint32 a = inet_addr(name); - addr->s_addr = a; - return a != (uint32) - 1; -} -#endif - IRCDVar myIrcd[] = { {"InspIRCd 1.1", /* ircd name */ "+I", /* Modes used by pseudoclients */ @@ -60,7 +44,6 @@ IRCDVar myIrcd[] = { 0, /* Change RealName */ 1, /* No Knock requires +i */ 0, /* We support inspircd TOKENS */ - 0, /* TIME STAMPS are BASE64 */ 0, /* Can remove User Channel Modes with SVSMODE */ 0, /* Sglines are not enforced until user reconnects */ 0, /* ts6 */ @@ -81,31 +64,31 @@ static bool has_chgidentmod = false; static bool has_hidechansmod = false; /* CHGHOST */ -void inspircd_cmd_chghost(const char *nick, const char *vhost) +void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost) { if (has_chghostmod) { - if (!nick || !vhost) + if (nick.empty() || vhost.empty()) return; - send_cmd(Config.s_OperServ, "CHGHOST %s %s", nick, vhost); + send_cmd(Config.s_OperServ, "CHGHOST %s %s", nick.c_str(), vhost.c_str()); } else ircdproto->SendGlobops(OperServ, "CHGHOST not loaded!"); } -int anope_event_idle(const char *source, int ac, const char **av) +int anope_event_idle(const Anope::string &source, int ac, const char **av) { if (ac == 1) - send_cmd(av[0], "IDLE %s %ld 0", source, static_cast<long>(time(NULL))); + send_cmd(av[0], "IDLE %s %ld 0", source.c_str(), static_cast<long>(time(NULL))); return MOD_CONT; } -static char currentpass[1024]; +static Anope::string currentpass; /* PASS */ -void inspircd_cmd_pass(const char *pass) +void inspircd_cmd_pass(const Anope::string &pass) { - strlcpy(currentpass, pass, sizeof(currentpass)); + currentpass = pass; } class InspIRCdProto : public IRCDProto @@ -115,20 +98,20 @@ class InspIRCdProto : public IRCDProto send_cmd(Config.s_OperServ, "GLINE %s", x->Mask.c_str()); } - void SendTopic(BotInfo *whosets, Channel *c, const char *whosetit, const char *topic) + void SendTopic(BotInfo *whosets, Channel *c, const Anope::string &whosetit, const Anope::string &topic) { - send_cmd(whosets->nick, "FTOPIC %s %lu %s :%s", c->name.c_str(), static_cast<unsigned long>(c->topic_time), whosetit, topic); + send_cmd(whosets->nick, "FTOPIC %s %lu %s :%s", c->name.c_str(), static_cast<unsigned long>(c->topic_time), whosetit.c_str(), topic.c_str()); } void SendVhostDel(User *u) { if (u->HasMode(UMODE_CLOAK)) - inspircd_cmd_chghost(u->nick.c_str(), u->chost.c_str()); + inspircd_cmd_chghost(u->nick, u->chost); else - inspircd_cmd_chghost(u->nick.c_str(), u->host); + inspircd_cmd_chghost(u->nick, u->host); if (has_chgidentmod && u->GetIdent() != u->GetVIdent()) - inspircd_cmd_chgident(u->nick.c_str(), u->GetIdent().c_str()); + inspircd_cmd_chgident(u->nick, u->GetIdent()); } void SendAkill(XLine *x) @@ -140,9 +123,9 @@ class InspIRCdProto : public IRCDProto send_cmd(Config.ServerName, "ADDLINE G %s %s %ld %ld :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str()); } - void SendSVSKillInternal(BotInfo *source, User *user, const char *buf) + void SendSVSKillInternal(BotInfo *source, User *user, const Anope::string &buf) { - send_cmd(source ? source->nick : Config.ServerName, "KILL %s :%s", user->nick.c_str(), buf); + send_cmd(source ? source->nick : Config.ServerName, "KILL %s :%s", user->nick.c_str(), buf.c_str()); } void SendSVSMode(User *u, int ac, const char **av) @@ -150,61 +133,56 @@ class InspIRCdProto : public IRCDProto this->SendModeInternal(NULL, u, merge_args(ac, av)); } - void SendNumericInternal(const char *source, int numeric, const char *dest, const char *buf) - { - send_cmd(source, "PUSH %s ::%s %03d %s %s", dest, source, numeric, dest, buf); - } - - void SendGuestNick(const char *nick, const char *user, const char *host, const char *real, const char *modes) + void SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf) { - send_cmd(Config.ServerName, "NICK %ld %s %s %s %s +%s 0.0.0.0 :%s", static_cast<long>(time(NULL)), nick, host, host, user, modes, real); + send_cmd(source, "PUSH %s ::%s %03d %s %s", dest.c_str(), source.c_str(), numeric, dest.c_str(), buf.c_str()); } - void SendModeInternal(BotInfo *source, Channel *dest, const char *buf) + void SendModeInternal(BotInfo *source, Channel *dest, const Anope::string &buf) { - if (!buf) + if (buf.empty()) return; - send_cmd(source ? source->nick : Config.s_OperServ, "FMODE %s %u %s", dest->name.c_str(), static_cast<unsigned>(dest->creation_time), buf); + send_cmd(source ? source->nick : Config.s_OperServ, "FMODE %s %u %s", dest->name.c_str(), static_cast<unsigned>(dest->creation_time), buf.c_str()); } - void SendModeInternal(BotInfo *bi, User *u, const char *buf) + void SendModeInternal(BotInfo *bi, User *u, const Anope::string &buf) { - if (!buf) + if (buf.empty()) return; - send_cmd(bi ? bi->nick : Config.ServerName, "MODE %s %s", u->nick.c_str(), buf); + send_cmd(bi ? bi->nick : Config.ServerName, "MODE %s %s", u->nick.c_str(), buf.c_str()); } - void SendClientIntroduction(const std::string &nick, const std::string &user, const std::string &host, const std::string &real, const char *modes, const std::string &uid) + void SendClientIntroduction(const Anope::string &nick, const Anope::string &user, const Anope::string &host, const Anope::string &real, const Anope::string &modes, const Anope::string &) { - send_cmd(Config.ServerName, "NICK %ld %s %s %s %s %s 0.0.0.0 :%s", static_cast<long>(time(NULL)), nick.c_str(), host.c_str(), host.c_str(), user.c_str(), modes, real.c_str()); + send_cmd(Config.ServerName, "NICK %ld %s %s %s %s %s 0.0.0.0 :%s", static_cast<long>(time(NULL)), nick.c_str(), host.c_str(), host.c_str(), user.c_str(), modes.c_str(), real.c_str()); send_cmd(nick, "OPERTYPE Service"); } - void SendKickInternal(BotInfo *source, Channel *chan, User *user, const char *buf) + void SendKickInternal(BotInfo *source, Channel *chan, User *user, const Anope::string &buf) { - if (buf) - send_cmd(source->nick, "KICK %s %s :%s", chan->name.c_str(), user->nick.c_str(), buf); + if (!buf.empty()) + send_cmd(source->nick, "KICK %s %s :%s", chan->name.c_str(), user->nick.c_str(), buf.c_str()); else send_cmd(source->nick, "KICK %s %s :%s", chan->name.c_str(), user->nick.c_str(), user->nick.c_str()); } - void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const char *buf) + void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const Anope::string &buf) { - if (!buf) + if (buf.empty()) return; - send_cmd(Config.ServerName, "NOTICE @%s :%s", dest->name.c_str(), buf); + send_cmd(Config.ServerName, "NOTICE @%s :%s", dest->name.c_str(), buf.c_str()); } /* SERVER services-dev.chatspike.net password 0 :Description here */ void SendServer(Server *server) { - send_cmd(Config.ServerName, "SERVER %s %s %d :%s", server->GetName().c_str(), currentpass, server->GetHops(), server->GetDescription().c_str()); + send_cmd(Config.ServerName, "SERVER %s %s %d :%s", server->GetName().c_str(), currentpass.c_str(), server->GetHops(), server->GetDescription().c_str()); } /* JOIN */ - void SendJoin(BotInfo *user, const char *channel, time_t chantime) + void SendJoin(BotInfo *user, const Anope::string &channel, time_t chantime) { - send_cmd(user->nick, "JOIN %s %ld", channel, static_cast<long>(chantime)); + send_cmd(user->nick, "JOIN %s %ld", channel.c_str(), static_cast<long>(chantime)); } /* UNSQLINE */ @@ -216,58 +194,58 @@ class InspIRCdProto : public IRCDProto /* SQLINE */ void SendSQLine(XLine *x) { - send_cmd(Config.ServerName, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config.s_OperServ, static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd(Config.ServerName, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config.s_OperServ.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); } /* SQUIT */ - void SendSquit(const char *servname, const char *message) + void SendSquit(const Anope::string &servname, const Anope::string &message) { - if (!servname || !message) + if (servname.empty() || message.empty()) return; - send_cmd(Config.ServerName, "SQUIT %s :%s", servname, message); + send_cmd(Config.ServerName, "SQUIT %s :%s", servname.c_str(), message.c_str()); } /* Functions that use serval cmd functions */ - void SendVhost(User *u, const std::string &vIdent, const std::string &vhost) + void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) { if (!vIdent.empty()) - inspircd_cmd_chgident(u->nick.c_str(), vIdent.c_str()); + inspircd_cmd_chgident(u->nick, vIdent); if (!vhost.empty()) - inspircd_cmd_chghost(u->nick.c_str(), vhost.c_str()); + inspircd_cmd_chghost(u->nick, vhost); } void SendConnect() { inspircd_cmd_pass(uplink_server->password); SendServer(Me); - send_cmd(NULL, "BURST"); - send_cmd(Config.ServerName, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config.ServerName, ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str()); + send_cmd("", "BURST"); + send_cmd(Config.ServerName, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config.ServerName.c_str(), ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str()); } /* CHGIDENT */ - void inspircd_cmd_chgident(const char *nick, const char *vIdent) + void inspircd_cmd_chgident(const Anope::string &nick, const Anope::string &vIdent) { if (has_chgidentmod) { - if (!nick || !vIdent || !*vIdent) + if (nick.empty() || vIdent.empty()) return; - send_cmd(Config.s_OperServ, "CHGIDENT %s %s", nick, vIdent); + send_cmd(Config.s_OperServ, "CHGIDENT %s %s", nick.c_str(), vIdent.c_str()); } else ircdproto->SendGlobops(OperServ, "CHGIDENT not loaded!"); } /* SVSHOLD - set */ - void SendSVSHold(const char *nick) + void SendSVSHold(const Anope::string &nick) { - send_cmd(Config.s_OperServ, "SVSHOLD %s %ds :%s", nick, static_cast<int>(Config.NSReleaseTimeout), "Being held for registered user"); + send_cmd(Config.s_OperServ, "SVSHOLD %s %ds :Being held for registered user", nick.c_str(), static_cast<int>(Config.NSReleaseTimeout)); } /* SVSHOLD - release */ - void SendSVSHoldDel(const char *nick) + void SendSVSHoldDel(const Anope::string &nick) { - send_cmd(Config.s_OperServ, "SVSHOLD %s", nick); + send_cmd(Config.s_OperServ, "SVSHOLD %s", nick.c_str()); } /* UNSZLINE */ @@ -288,38 +266,37 @@ class InspIRCdProto : public IRCDProto u->RemoveMode(NickServ, UMODE_REGISTERED); } - void SendSVSJoin(const char *source, const char *nick, const char *chan, const char *param) + void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) { - send_cmd(source, "SVSJOIN %s %s", nick, chan); + send_cmd(source, "SVSJOIN %s %s", nick.c_str(), chan.c_str()); } - void SendSVSPart(const char *source, const char *nick, const char *chan) + void SendSVSPart(const Anope::string &source, const Anope::string &nick, const Anope::string &chan) { - send_cmd(source, "SVSPART %s %s", nick, chan); + send_cmd(source, "SVSPART %s %s", nick.c_str(), chan.c_str()); } void SendEOB() { - send_cmd(NULL, "ENDBURST"); + send_cmd("", "ENDBURST"); } void SetAutoIdentificationToken(User *u) { - char svidbuf[15]; if (!u->Account()) return; - snprintf(svidbuf, sizeof(svidbuf), "%ld", static_cast<long>(u->timestamp)); + Anope::string svidbuf = stringify(u->timestamp); u->Account()->Shrink("authenticationtoken"); - u->Account()->Extend("authenticationtoken", new ExtensibleItemPointerArray<char>(sstrdup(svidbuf))); + u->Account()->Extend("authenticationtoken", new ExtensibleItemRegular<Anope::string>(svidbuf)); u->SetMode(NickServ, UMODE_REGISTERED); } } ircd_proto; -int anope_event_ftopic(const char *source, int ac, const char **av) +int anope_event_ftopic(const Anope::string &source, int ac, const char **av) { /* :source FTOPIC channel ts setby :topic */ const char *temp; @@ -332,7 +309,7 @@ int anope_event_ftopic(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_mode(const char *source, int ac, const char **av) +int anope_event_mode(const Anope::string &source, int ac, const char **av) { if (ac < 2) return MOD_CONT; @@ -345,7 +322,7 @@ int anope_event_mode(const char *source, int ac, const char **av) users modes, we have to kludge this as it slightly breaks RFC1459 */ - if (!strcasecmp(source, av[0])) + if (source.equals_ci(av[0])) do_umode(source, ac, av); else do_umode(av[0], ac, av); @@ -353,7 +330,7 @@ int anope_event_mode(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_opertype(const char *source, int ac, const char **av) +int anope_event_opertype(const Anope::string &source, int ac, const char **av) { /* opertype is equivalent to mode +o because servers dont do this directly */ @@ -362,7 +339,7 @@ int anope_event_opertype(const char *source, int ac, const char **av) if (u && !is_oper(u)) { const char *newav[2]; - newav[0] = source; + newav[0] = source.c_str(); newav[1] = "+o"; return anope_event_mode(source, 2, newav); } @@ -370,7 +347,7 @@ int anope_event_opertype(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_fmode(const char *source, int ac, const char **av) +int anope_event_fmode(const Anope::string &source, int ac, const char **av) { const char *newav[128]; int n, o; @@ -383,10 +360,11 @@ int anope_event_fmode(const char *source, int ac, const char **av) /* Checking the TS for validity to avoid desyncs */ if ((c = findchan(av[0]))) { - if (c->creation_time > strtol(av[1], NULL, 10)) + time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0; + if (c->creation_time > ts) /* Our TS is bigger, we should lower it */ - c->creation_time = strtol(av[1], NULL, 10); - else if (c->creation_time < strtol(av[1], NULL, 10)) + c->creation_time = ts; + else if (c->creation_time < ts) /* The TS we got is bigger, we should ignore this message. */ return MOD_CONT; } @@ -410,10 +388,10 @@ int anope_event_fmode(const char *source, int ac, const char **av) return anope_event_mode(source, ac - 1, newav); } -int anope_event_fjoin(const char *source, int ac, const char **av) +int anope_event_fjoin(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); - time_t ts = atol(av[1]); + time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0; bool was_created = false; bool keep_their_modes = true; @@ -465,11 +443,10 @@ int anope_event_fjoin(const char *source, int ac, const char **av) c->SetFlag(CH_SYNCING); spacesepstream sep(av[ac - 1]); - std::string buf; + Anope::string buf; while (sep.GetToken(buf)) { std::list<ChannelMode *> Status; - Status.clear(); char ch; /* Loop through prefixes */ @@ -538,7 +515,7 @@ int anope_event_fjoin(const char *source, int ac, const char **av) } /* Events */ -int anope_event_ping(const char *source, int ac, const char **av) +int anope_event_ping(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -546,7 +523,7 @@ int anope_event_ping(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_436(const char *source, int ac, const char **av) +int anope_event_436(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -555,17 +532,17 @@ int anope_event_436(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_away(const char *source, int ac, const char **av) +int anope_event_away(const Anope::string &source, int ac, const char **av) { - if (!source) + if (source.empty()) return MOD_CONT; - m_away(source, (ac ? av[0] : NULL)); + m_away(source, ac ? av[0] : ""); return MOD_CONT; } /* Taken from hybrid.c, topic syntax is identical */ -int anope_event_topic(const char *source, int ac, const char **av) +int anope_event_topic(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); time_t topic_time = time(NULL); @@ -579,13 +556,9 @@ int anope_event_topic(const char *source, int ac, const char **av) if (check_topiclock(c, topic_time)) return MOD_CONT; - if (c->topic) - { - delete [] c->topic; - c->topic = NULL; - } + c->topic.clear(); if (ac > 1 && *av[1]) - c->topic = sstrdup(av[1]); + c->topic = av[1]; c->topic_setter = source; c->topic_time = topic_time; @@ -604,7 +577,7 @@ int anope_event_topic(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_squit(const char *source, int ac, const char **av) +int anope_event_squit(const Anope::string &source, int ac, const char **av) { if (ac != 2) return MOD_CONT; @@ -612,13 +585,13 @@ int anope_event_squit(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_rsquit(const char *source, int ac, const char **av) +int anope_event_rsquit(const Anope::string &source, int ac, const char **av) { if (ac < 1 || ac > 3) return MOD_CONT; /* Horrible workaround to an insp bug (#) in how RSQUITs are sent - mark */ - if (ac > 1 && !strcmp(Config.ServerName, av[0])) + if (ac > 1 && Config.ServerName.equals_cs(av[0])) do_squit(source, ac - 1, av + 1); else do_squit(source, ac, av); @@ -626,7 +599,7 @@ int anope_event_rsquit(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_quit(const char *source, int ac, const char **av) +int anope_event_quit(const Anope::string &source, int ac, const char **av) { if (ac != 1) return MOD_CONT; @@ -634,7 +607,7 @@ int anope_event_quit(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_kill(const char *source, int ac, const char **av) +int anope_event_kill(const Anope::string &source, int ac, const char **av) { if (ac != 2) return MOD_CONT; @@ -643,7 +616,7 @@ int anope_event_kill(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_kick(const char *source, int ac, const char **av) +int anope_event_kick(const Anope::string &source, int ac, const char **av) { if (ac != 3) return MOD_CONT; @@ -651,7 +624,7 @@ int anope_event_kick(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_join(const char *source, int ac, const char **av) +int anope_event_join(const Anope::string &source, int ac, const char **av) { if (ac != 2) return MOD_CONT; @@ -659,16 +632,16 @@ int anope_event_join(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_motd(const char *source, int ac, const char **av) +int anope_event_motd(const Anope::string &source, int ac, const char **av) { - if (!source) + if (source.empty()) return MOD_CONT; m_motd(source); return MOD_CONT; } -int anope_event_setname(const char *source, int ac, const char **av) +int anope_event_setname(const Anope::string &source, int ac, const char **av) { User *u; @@ -686,7 +659,7 @@ int anope_event_setname(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_chgname(const char *source, int ac, const char **av) +int anope_event_chgname(const Anope::string &source, int ac, const char **av) { User *u; @@ -704,7 +677,7 @@ int anope_event_chgname(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_setident(const char *source, int ac, const char **av) +int anope_event_setident(const Anope::string &source, int ac, const char **av) { User *u; @@ -722,7 +695,7 @@ int anope_event_setident(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_chgident(const char *source, int ac, const char **av) +int anope_event_chgident(const Anope::string &source, int ac, const char **av) { User *u; @@ -740,7 +713,7 @@ int anope_event_chgident(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_sethost(const char *source, int ac, const char **av) +int anope_event_sethost(const Anope::string &source, int ac, const char **av) { User *u; @@ -759,27 +732,20 @@ int anope_event_sethost(const char *source, int ac, const char **av) } -int anope_event_nick(const char *source, int ac, const char **av) +int anope_event_nick(const Anope::string &source, int ac, const char **av) { User *user; - struct in_addr addy; - uint32 *ad = reinterpret_cast<uint32 *>(&addy); if (ac != 1) { if (ac == 8) { - int ts = strtoul(av[0], NULL, 10); - - inet_aton(av[6], &addy); - user = do_nick("", av[1], /* nick */ - av[4], /* username */ - av[2], /* realhost */ - source, /* server */ - av[7], /* realname */ - ts, htonl(*ad), av[3], NULL); + time_t ts = Anope::string(av[0]).is_number_only() ? convertTo<time_t>(av[0]) : 0; + + user = do_nick("", av[1], av[4], av[2], source, av[7], ts, 0, av[3], ""); if (user) { + user->hostip = av[6]; /* InspIRCd1.1 has no user mode +d so we * use nick timestamp to check for auth - Adam */ @@ -791,12 +757,12 @@ int anope_event_nick(const char *source, int ac, const char **av) } } else - do_nick(source, av[0], NULL, NULL, NULL, NULL, 0, 0, NULL, NULL); + do_nick(source, av[0], "", "", "", "", 0, 0, "", ""); return MOD_CONT; } -int anope_event_chghost(const char *source, int ac, const char **av) +int anope_event_chghost(const Anope::string &source, int ac, const char **av) { User *u; @@ -815,13 +781,13 @@ int anope_event_chghost(const char *source, int ac, const char **av) } /* EVENT: SERVER */ -int anope_event_server(const char *source, int ac, const char **av) +int anope_event_server(const Anope::string &source, int ac, const char **av) { - do_server(source, av[0], atoi(av[1]), av[2], ""); + do_server(source, av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, av[2], ""); return MOD_CONT; } -int anope_event_privmsg(const char *source, int ac, const char **av) +int anope_event_privmsg(const Anope::string &source, int ac, const char **av) { if (ac != 2) return MOD_CONT; @@ -829,7 +795,7 @@ int anope_event_privmsg(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_part(const char *source, int ac, const char **av) +int anope_event_part(const Anope::string &source, int ac, const char **av) { if (ac < 1 || ac > 2) return MOD_CONT; @@ -837,14 +803,14 @@ int anope_event_part(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_whois(const char *source, int ac, const char **av) +int anope_event_whois(const Anope::string &source, int ac, const char **av) { - if (source && ac >= 1) + if (!source.empty() && ac >= 1) m_whois(source, av[0]); return MOD_CONT; } -int anope_event_capab(const char *source, int ac, const char **av) +int anope_event_capab(const Anope::string &source, int ac, const char **av) { if (!strcasecmp(av[0], "START")) { @@ -874,17 +840,17 @@ int anope_event_capab(const char *source, int ac, const char **av) else if (!strcasecmp(av[0], "CAPABILITIES")) { spacesepstream ssep(av[1]); - std::string capab; + Anope::string capab; while (ssep.GetToken(capab)) { - if (capab.find("CHANMODES") != std::string::npos) + if (capab.find("CHANMODES") != Anope::string::npos) { - std::string modes(capab.begin() + 10, capab.end()); + Anope::string modes(capab.begin() + 10, capab.end()); commasepstream sep(modes); - std::string modebuf; + Anope::string modebuf; sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -903,7 +869,7 @@ int anope_event_capab(const char *source, int ac, const char **av) } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -912,12 +878,11 @@ int anope_event_capab(const char *source, int ac, const char **av) continue; default: ModeManager::AddChannelMode(new ChannelModeParam(CMODE_END, "", modebuf[t])); - } } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -936,7 +901,7 @@ int anope_event_capab(const char *source, int ac, const char **av) } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -1005,12 +970,12 @@ int anope_event_capab(const char *source, int ac, const char **av) } } } - else if (capab.find("PREIX=(") != std::string::npos) + else if (capab.find("PREIX=(") != Anope::string::npos) { - std::string modes(capab.begin() + 8, capab.begin() + capab.find(")")); - std::string chars(capab.begin() + capab.find(")") + 1, capab.end()); + Anope::string modes(capab.begin() + 8, capab.begin() + capab.find(')')); + Anope::string chars(capab.begin() + capab.find(')') + 1, capab.end()); - for (size_t t = 0, end = modes.size(); t < end; ++t) + for (size_t t = 0, end = modes.length(); t < end; ++t) { switch (modes[t]) { @@ -1034,8 +999,8 @@ int anope_event_capab(const char *source, int ac, const char **av) } else if (capab.find("MAXMODES=") != std::string::npos) { - std::string maxmodes(capab.begin() + 9, capab.end()); - ircd->maxmodes = atoi(maxmodes.c_str()); + Anope::string maxmodes(capab.begin() + 9, capab.end()); + ircd->maxmodes = maxmodes.is_number_only() ? convertTo<unsigned>(maxmodes) : 3; } } } @@ -1043,21 +1008,21 @@ int anope_event_capab(const char *source, int ac, const char **av) { if (!has_globopsmod) { - send_cmd(NULL, "ERROR :m_globops is not loaded. This is required by Anope"); + send_cmd("", "ERROR :m_globops is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server does not have the m_globops module loaded, and this is required."; quitting = 1; return MOD_STOP; } if (!has_servicesmod) { - send_cmd(NULL, "ERROR :m_services is not loaded. This is required by Anope"); + send_cmd("", "ERROR :m_services is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server does not have the m_services module loaded, and this is required."; quitting = 1; return MOD_STOP; } if (!has_hidechansmod) { - send_cmd(NULL, "ERROR :m_hidechans.so is not loaded. This is required by Anope"); + send_cmd("", "ERROR :m_hidechans.so is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server deos not have the m_hidechans module loaded, and this is required."; quitting = 1; return MOD_STOP; @@ -1075,7 +1040,7 @@ int anope_event_capab(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_endburst(const char *source, int ac, const char **av) +int anope_event_endburst(const Anope::string &source, int ac, const char **av) { Me->GetUplink()->Sync(true); return MOD_CONT; @@ -1092,7 +1057,7 @@ void moduleAddIRCDMsgs() Anope::AddMessage("MODE", anope_event_mode); Anope::AddMessage("MOTD", anope_event_motd); Anope::AddMessage("NICK", anope_event_nick); - Anope::AddMessage("CAPAB",anope_event_capab); + Anope::AddMessage("CAPAB", anope_event_capab); Anope::AddMessage("PART", anope_event_part); Anope::AddMessage("PING", anope_event_ping); Anope::AddMessage("PRIVMSG", anope_event_privmsg); @@ -1116,11 +1081,10 @@ void moduleAddIRCDMsgs() Anope::AddMessage("IDLE", anope_event_idle); } -bool ChannelModeFlood::IsValid(const std::string &value) +bool ChannelModeFlood::IsValid(const Anope::string &value) { - char *dp, *end; - - if (!value.empty() && value[0] != ':' && strtoul((value[0] == '*' ? value.c_str() + 1 : value.c_str()), &dp, 10) > 0 && *dp == ':' && *(++dp) && strtoul(dp, &end, 10) > 0 && !*end) + Anope::string rest; + if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty()) return true; return false; @@ -1140,7 +1104,7 @@ static void AddModes() class ProtoInspIRCd : public Module { public: - ProtoInspIRCd(const std::string &modname, const std::string &creator) : Module(modname, creator) + ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(PROTOCOL); @@ -1161,11 +1125,10 @@ class ProtoInspIRCd : public Module ModuleManager::Attach(I_OnUserNickChange, this); } - void OnUserNickChange(User *u, const std::string &) + void OnUserNickChange(User *u, const Anope::string &) { u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED)); } - }; MODULE_INIT(ProtoInspIRCd) diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp index 465f0ffff..416a91c96 100644 --- a/modules/protocol/inspircd12.cpp +++ b/modules/protocol/inspircd12.cpp @@ -15,22 +15,6 @@ #include "modules.h" #include "hashcomp.h" -#ifndef _WIN32 -# include <sys/socket.h> -# include <netinet/in.h> -# include <arpa/inet.h> -#endif - -#ifdef _WIN32 -# include <winsock.h> -int inet_aton(const char *name, struct in_addr *addr) -{ - uint32 a = inet_addr(name); - addr->s_addr = a; - return a != (uint32) - 1; -} -#endif - IRCDVar myIrcd[] = { {"InspIRCd 1.2", /* ircd name */ "+I", /* Modes used by pseudoclients */ @@ -60,7 +44,6 @@ IRCDVar myIrcd[] = { 0, /* Change RealName */ 1, /* No Knock requires +i */ 0, /* We support inspircd TOKENS */ - 0, /* TIME STAMPS are BASE64 */ 0, /* Can remove User Channel Modes with SVSMODE */ 0, /* Sglines are not enforced until user reconnects */ 1, /* ts6 */ @@ -84,7 +67,7 @@ static bool has_hidechansmod = false; static User *prev_u_intro = NULL; /* CHGHOST */ -void inspircd_cmd_chghost(const char *nick, const char *vhost) +void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost) { if (!has_chghostmod) { @@ -92,50 +75,48 @@ void inspircd_cmd_chghost(const char *nick, const char *vhost) return; } - BotInfo *bi = OperServ; - send_cmd(bi->GetUID(), "CHGHOST %s %s", nick, vhost); + send_cmd(OperServ->GetUID(), "CHGHOST %s %s", nick.c_str(), vhost.c_str()); } -int anope_event_idle(const char *source, int ac, const char **av) +int anope_event_idle(const Anope::string &source, int ac, const char **av) { BotInfo *bi = findbot(av[0]); if (!bi) return MOD_CONT; - send_cmd(bi->GetUID(), "IDLE %s %ld %ld", source, static_cast<long>(start_time), static_cast<long>(time(NULL) - bi->lastmsg)); + send_cmd(bi->GetUID(), "IDLE %s %ld %ld", source.c_str(), static_cast<long>(start_time), static_cast<long>(time(NULL) - bi->lastmsg)); return MOD_CONT; } -static char currentpass[1024]; +static Anope::string currentpass; /* PASS */ -void inspircd_cmd_pass(const char *pass) +void inspircd_cmd_pass(const Anope::string &pass) { - strlcpy(currentpass, pass, sizeof(currentpass)); + currentpass = pass; } class InspIRCdProto : public IRCDProto { void SendAkillDel(XLine *x) { - BotInfo *bi = OperServ; - send_cmd(bi->GetUID(), "GLINE %s", x->Mask.c_str()); + send_cmd(OperServ->GetUID(), "GLINE %s", x->Mask.c_str()); } - void SendTopic(BotInfo *whosets, Channel *c, const char *whosetit, const char *topic) + void SendTopic(BotInfo *whosets, Channel *c, const Anope::string &whosetit, const Anope::string &topic) { - send_cmd(whosets->GetUID(), "FTOPIC %s %lu %s :%s", c->name.c_str(), static_cast<unsigned long>(c->topic_time), whosetit, topic); + send_cmd(whosets->GetUID(), "FTOPIC %s %lu %s :%s", c->name.c_str(), static_cast<unsigned long>(c->topic_time), whosetit.c_str(), topic.c_str()); } void SendVhostDel(User *u) { if (u->HasMode(UMODE_CLOAK)) - inspircd_cmd_chghost(u->nick.c_str(), u->chost.c_str()); + inspircd_cmd_chghost(u->nick, u->chost); else - inspircd_cmd_chghost(u->nick.c_str(), u->host); + inspircd_cmd_chghost(u->nick, u->host); if (has_chgidentmod && u->GetIdent() != u->GetVIdent()) - inspircd_cmd_chgident(u->nick.c_str(), u->GetIdent().c_str()); + inspircd_cmd_chgident(u->nick, u->GetIdent()); } void SendAkill(XLine *x) @@ -144,13 +125,12 @@ class InspIRCdProto : public IRCDProto time_t timeleft = x->Expires - time(NULL); if (timeleft > 172800 || !x->Expires) timeleft = 172800; - BotInfo *bi = OperServ; - send_cmd(bi->GetUID(), "ADDLINE G %s@%s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str()); + send_cmd(OperServ->GetUID(), "ADDLINE G %s@%s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str()); } - void SendSVSKillInternal(BotInfo *source, User *user, const char *buf) + void SendSVSKillInternal(BotInfo *source, User *user, const Anope::string &buf) { - send_cmd(source ? source->GetUID() : TS6SID, "KILL %s :%s", user->GetUID().c_str(), buf); + send_cmd(source ? source->GetUID() : TS6SID, "KILL %s :%s", user->GetUID().c_str(), buf.c_str()); } void SendSVSMode(User *u, int ac, const char **av) @@ -158,56 +138,51 @@ class InspIRCdProto : public IRCDProto this->SendModeInternal(NULL, u, merge_args(ac, av)); } - void SendNumericInternal(const char *source, int numeric, const char *dest, const char *buf) - { - send_cmd(TS6SID, "PUSH %s ::%s %03d %s %s", dest, source, numeric, dest, buf); - } - - void SendGuestNick(const char *nick, const char *user, const char *host, const char *real, const char *modes) + void SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf) { - send_cmd(TS6SID, "UID %ld %s %s %s %s +%s 0.0.0.0 :%s", static_cast<long>(time(NULL)), nick, host, host, user, modes, real); + send_cmd(TS6SID, "PUSH %s ::%s %03d %s %s", dest.c_str(), source.c_str(), numeric, dest.c_str(), buf.c_str()); } - void SendModeInternal(BotInfo *source, Channel *dest, const char *buf) + void SendModeInternal(BotInfo *source, Channel *dest, const Anope::string &buf) { - send_cmd(source ? source->GetUID() : TS6SID, "FMODE %s %u %s", dest->name.c_str(), static_cast<unsigned>(dest->creation_time), buf); + send_cmd(source ? source->GetUID() : TS6SID, "FMODE %s %u %s", dest->name.c_str(), static_cast<unsigned>(dest->creation_time), buf.c_str()); } - void SendModeInternal(BotInfo *bi, User *u, const char *buf) + void SendModeInternal(BotInfo *bi, User *u, const Anope::string &buf) { - if (!buf) + if (buf.empty()) return; - send_cmd(bi ? bi->GetUID() : TS6SID, "MODE %s %s", u->GetUID().c_str(), buf); + send_cmd(bi ? bi->GetUID() : TS6SID, "MODE %s %s", u->GetUID().c_str(), buf.c_str()); } - void SendClientIntroduction(const std::string &nick, const std::string &user, const std::string &host, const std::string &real, const char *modes, const std::string &uid) + void SendClientIntroduction(const Anope::string &nick, const Anope::string &user, const Anope::string &host, const Anope::string &real, const Anope::string &modes, const Anope::string &uid) { - send_cmd(TS6SID, "UID %s %ld %s %s %s %s 0.0.0.0 %ld %s :%s", uid.c_str(), static_cast<long>(time(NULL)), nick.c_str(), host.c_str(), host.c_str(), user.c_str(), static_cast<long>(time(NULL)), modes, real.c_str()); + send_cmd(TS6SID, "UID %s %ld %s %s %s %s 0.0.0.0 %ld %s :%s", uid.c_str(), static_cast<long>(time(NULL)), nick.c_str(), host.c_str(), host.c_str(), user.c_str(), static_cast<long>(time(NULL)), modes.c_str(), real.c_str()); } - void SendKickInternal(BotInfo *source, Channel *chan, User *user, const char *buf) + void SendKickInternal(BotInfo *source, Channel *chan, User *user, const Anope::string &buf) { - if (buf) - send_cmd(source->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), buf); + if (!buf.empty()) + send_cmd(source->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), buf.c_str()); else send_cmd(source->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), user->nick.c_str()); } - void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const char *buf) + void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const Anope::string &buf) { - send_cmd(TS6SID, "NOTICE @%s :%s", dest->name.c_str(), buf); + send_cmd(TS6SID, "NOTICE @%s :%s", dest->name.c_str(), buf.c_str()); } /* SERVER services-dev.chatspike.net password 0 :Description here */ void SendServer(Server *server) { - send_cmd(NULL, "SERVER %s %s %d %s :%s", server->GetName().c_str(), currentpass, server->GetHops(), server->GetSID().c_str(), server->GetDescription().c_str()); + send_cmd("", "SERVER %s %s %d %s :%s", server->GetName().c_str(), currentpass.c_str(), server->GetHops(), server->GetSID().c_str(), server->GetDescription().c_str()); } /* JOIN */ - void SendJoin(BotInfo *user, const char *channel, time_t chantime) + void SendJoin(BotInfo *user, const Anope::string &channel, time_t chantime) { - send_cmd(TS6SID, "FJOIN %s %ld + :,%s", channel, static_cast<long>(chantime), user->GetUID().c_str()); + send_cmd(TS6SID, "FJOIN %s %ld + :,%s", channel.c_str(), static_cast<long>(chantime), user->GetUID().c_str()); } /* UNSQLINE */ @@ -219,23 +194,23 @@ class InspIRCdProto : public IRCDProto /* SQLINE */ void SendSQLine(XLine *x) { - send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config.s_OperServ, static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config.s_OperServ.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); } /* SQUIT */ - void SendSquit(const char *servname, const char *message) + void SendSquit(const Anope::string &servname, const Anope::string &message) { - send_cmd(TS6SID, "SQUIT %s :%s", servname, message); + send_cmd(TS6SID, "SQUIT %s :%s", servname.c_str(), message.c_str()); } /* Functions that use serval cmd functions */ - void SendVhost(User *u, const std::string &vIdent, const std::string &vhost) + void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) { if (!vIdent.empty()) - inspircd_cmd_chgident(u->nick.c_str(), vIdent.c_str()); + inspircd_cmd_chgident(u->nick, vIdent); if (!vhost.empty()) - inspircd_cmd_chghost(u->nick.c_str(), vhost.c_str()); + inspircd_cmd_chghost(u->nick, vhost); } void SendConnect() @@ -243,33 +218,28 @@ class InspIRCdProto : public IRCDProto inspircd_cmd_pass(uplink_server->password); SendServer(Me); send_cmd(TS6SID, "BURST"); - send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config.ServerName, ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str()); + send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config.ServerName.c_str(), ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str()); } /* CHGIDENT */ - void inspircd_cmd_chgident(const char *nick, const char *vIdent) + void inspircd_cmd_chgident(const Anope::string &nick, const Anope::string &vIdent) { if (!has_chgidentmod) ircdproto->SendGlobops(OperServ, "CHGIDENT not loaded!"); else - { - BotInfo *bi = OperServ; - send_cmd(bi->GetUID(), "CHGIDENT %s %s", nick, vIdent); - } + send_cmd(OperServ->GetUID(), "CHGIDENT %s %s", nick.c_str(), vIdent.c_str()); } /* SVSHOLD - set */ - void SendSVSHold(const char *nick) + void SendSVSHold(const Anope::string &nick) { - BotInfo *bi = OperServ; - send_cmd(bi->GetUID(), "SVSHOLD %s %u :%s", nick, static_cast<unsigned>(Config.NSReleaseTimeout), "Being held for registered user"); + send_cmd(OperServ->GetUID(), "SVSHOLD %s %u :Being held for registered user", nick.c_str(), static_cast<unsigned>(Config.NSReleaseTimeout)); } /* SVSHOLD - release */ - void SendSVSHoldDel(const char *nick) + void SendSVSHoldDel(const Anope::string &nick) { - BotInfo *bi = OperServ; - send_cmd(bi->GetUID(), "SVSHOLD %s", nick); + send_cmd(OperServ->GetUID(), "SVSHOLD %s", nick.c_str()); } /* UNSZLINE */ @@ -290,25 +260,25 @@ class InspIRCdProto : public IRCDProto u->RemoveMode(NickServ, UMODE_REGISTERED); } - void SendSVSJoin(const char *source, const char *nick, const char *chan, const char *param) + void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) { User *u = finduser(nick); BotInfo *bi = findbot(source); - send_cmd(bi->GetUID(), "SVSJOIN %s %s", u->GetUID().c_str(), chan); + send_cmd(bi->GetUID(), "SVSJOIN %s %s", u->GetUID().c_str(), chan.c_str()); } - void SendSVSPart(const char *source, const char *nick, const char *chan) + void SendSVSPart(const Anope::string &source, const Anope::string &nick, const Anope::string &chan) { User *u = finduser(nick); BotInfo *bi = findbot(source); - send_cmd(bi->GetUID(), "SVSPART %s %s", u->GetUID().c_str(), chan); + send_cmd(bi->GetUID(), "SVSPART %s %s", u->GetUID().c_str(), chan.c_str()); } - void SendSWhois(const char *source, const char *who, const char *mask) + void SendSWhois(const Anope::string &, const Anope::string &who, const Anope::string &mask) { User *u = finduser(who); - send_cmd(TS6SID, "METADATA %s swhois :%s", u->GetUID().c_str(), mask); + send_cmd(TS6SID, "METADATA %s swhois :%s", u->GetUID().c_str(), mask.c_str()); } void SendEOB() @@ -316,30 +286,31 @@ class InspIRCdProto : public IRCDProto send_cmd(TS6SID, "ENDBURST"); } - void SendGlobopsInternal(BotInfo *source, const char *buf) + void SendGlobopsInternal(BotInfo *source, const Anope::string &buf) { if (has_globopsmod) - send_cmd(source ? source->GetUID() : TS6SID, "SNONOTICE g :%s", buf); + send_cmd(source ? source->GetUID() : TS6SID, "SNONOTICE g :%s", buf.c_str()); else - send_cmd(source ? source->GetUID() : TS6SID, "SNONOTICE A :%s", buf); + send_cmd(source ? source->GetUID() : TS6SID, "SNONOTICE A :%s", buf.c_str()); } - void SendAccountLogin(User *u, NickCore *account) + void SendAccountLogin(User *u, const NickCore *account) { - send_cmd(TS6SID, "METADATA %s accountname :%s", u->GetUID().c_str(), account->display); + send_cmd(TS6SID, "METADATA %s accountname :%s", u->GetUID().c_str(), account->display.c_str()); } - void SendAccountLogout(User *u, NickCore *account) + void SendAccountLogout(User *u, const NickCore *account) { send_cmd(TS6SID, "METADATA %s accountname :", u->GetUID().c_str()); } - int IsNickValid(const char *nick) + bool IsNickValid(const Anope::string &nick) { /* InspIRCd, like TS6, uses UIDs on collision, so... */ - if (isdigit(*nick)) - return 0; - return 1; + if (isdigit(nick[0])) + return false; + + return true; } void SetAutoIdentificationToken(User *u) @@ -351,7 +322,7 @@ class InspIRCdProto : public IRCDProto } } ircd_proto; -int anope_event_ftopic(const char *source, int ac, const char **av) +int anope_event_ftopic(const Anope::string &source, int ac, const char **av) { /* :source FTOPIC channel ts setby :topic */ const char *temp; @@ -364,7 +335,7 @@ int anope_event_ftopic(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_mode(const char *source, int ac, const char **av) +int anope_event_mode(const Anope::string &source, int ac, const char **av) { if (*av[0] == '#' || *av[0] == '&') do_cmode(source, ac, av); @@ -383,16 +354,16 @@ int anope_event_mode(const char *source, int ac, const char **av) // if it's still null, drop it like fire. // most likely situation was that server introduced a nick which we subsequently akilled - if (u == NULL) + if (!u) return MOD_CONT; av[0] = u2->nick.c_str(); - do_umode(u->nick.c_str(), ac, av); + do_umode(u->nick, ac, av); } return MOD_CONT; } -int anope_event_opertype(const char *source, int ac, const char **av) +int anope_event_opertype(const Anope::string &source, int ac, const char **av) { /* opertype is equivalent to mode +o because servers dont do this directly */ @@ -401,7 +372,7 @@ int anope_event_opertype(const char *source, int ac, const char **av) if (u && !is_oper(u)) { const char *newav[2]; - newav[0] = source; + newav[0] = source.c_str(); newav[1] = "+o"; return anope_event_mode(source, 2, newav); } @@ -409,7 +380,7 @@ int anope_event_opertype(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_fmode(const char *source, int ac, const char **av) +int anope_event_fmode(const Anope::string &source, int ac, const char **av) { const char *newav[128]; int n, o; @@ -422,10 +393,11 @@ int anope_event_fmode(const char *source, int ac, const char **av) /* Checking the TS for validity to avoid desyncs */ if ((c = findchan(av[0]))) { - if (c->creation_time > strtol(av[1], NULL, 10)) + time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0; + if (c->creation_time > ts) /* Our TS is bigger, we should lower it */ - c->creation_time = strtol(av[1], NULL, 10); - else if (c->creation_time < strtol(av[1], NULL, 10)) + c->creation_time = ts; + else if (c->creation_time < ts) /* The TS we got is bigger, we should ignore this message. */ return MOD_CONT; } @@ -457,10 +429,10 @@ int anope_event_fmode(const char *source, int ac, const char **av) * 2: channel modes + params (NOTE: this may definitely be more than one param!) * last: users */ -int anope_event_fjoin(const char *source, int ac, const char **av) +int anope_event_fjoin(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); - time_t ts = atol(av[1]); + time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0; bool was_created = false; bool keep_their_modes = true; @@ -519,11 +491,10 @@ int anope_event_fjoin(const char *source, int ac, const char **av) } spacesepstream sep(av[ac - 1]); - std::string buf; + Anope::string buf; while (sep.GetToken(buf)) { std::list<ChannelMode *> Status; - Status.clear(); /* Loop through prefixes and find modes for them */ while (buf[0] != ',') @@ -591,10 +562,10 @@ int anope_event_fjoin(const char *source, int ac, const char **av) } /* Events */ -int anope_event_ping(const char *source, int ac, const char **av) +int anope_event_ping(const Anope::string &source, int ac, const char **av) { if (ac == 1) - ircdproto->SendPong(NULL, av[0]); + ircdproto->SendPong("", av[0]); if (ac == 2) ircdproto->SendPong(av[1], av[0]); @@ -602,32 +573,32 @@ int anope_event_ping(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_time(const char *source, int ac, const char **av) +int anope_event_time(const Anope::string &source, int ac, const char **av) { if (ac !=2) return MOD_CONT; - send_cmd(TS6SID, "TIME %s %s %ld", source, av[1], static_cast<long>(time(NULL))); + send_cmd(TS6SID, "TIME %s %s %ld", source.c_str(), av[1], static_cast<long>(time(NULL))); /* We handled it, don't pass it on to the core.. * The core doesn't understand our syntax anyways.. ~ Viper */ return MOD_STOP; } -int anope_event_436(const char *source, int ac, const char **av) +int anope_event_436(const Anope::string &source, int ac, const char **av) { m_nickcoll(av[0]); return MOD_CONT; } -int anope_event_away(const char *source, int ac, const char **av) +int anope_event_away(const Anope::string &source, int ac, const char **av) { - m_away(source, (ac ? av[0] : NULL)); + m_away(source, ac ? av[0] : ""); return MOD_CONT; } /* Taken from hybrid.c, topic syntax is identical */ -int anope_event_topic(const char *source, int ac, const char **av) +int anope_event_topic(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); time_t topic_time = time(NULL); @@ -642,13 +613,9 @@ int anope_event_topic(const char *source, int ac, const char **av) if (check_topiclock(c, topic_time)) return MOD_CONT; - if (c->topic) - { - delete [] c->topic; - c->topic = NULL; - } + c->topic.clear(); if (ac > 1 && *av[1]) - c->topic = sstrdup(av[1]); + c->topic = av[1]; c->topic_setter = u ? u->nick : source; c->topic_time = topic_time; @@ -667,13 +634,13 @@ int anope_event_topic(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_squit(const char *source, int ac, const char **av) +int anope_event_squit(const Anope::string &source, int ac, const char **av) { do_squit(source, ac, av); return MOD_CONT; } -int anope_event_rsquit(const char *source, int ac, const char **av) +int anope_event_rsquit(const Anope::string &source, int ac, const char **av) { /* On InspIRCd we must send a SQUIT when we recieve RSQUIT for a server we have juped */ Server *s = Server::Find(av[0]); @@ -685,39 +652,39 @@ int anope_event_rsquit(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_quit(const char *source, int ac, const char **av) +int anope_event_quit(const Anope::string &source, int ac, const char **av) { do_quit(source, ac, av); return MOD_CONT; } -int anope_event_kill(const char *source, int ac, const char **av) +int anope_event_kill(const Anope::string &source, int ac, const char **av) { User *u = finduser(av[0]); BotInfo *bi = findbot(av[0]); - m_kill(u ? u->nick.c_str() : (bi ? bi->nick : av[0]), av[1]); + m_kill(u ? u->nick : (bi ? bi->nick : av[0]), av[1]); return MOD_CONT; } -int anope_event_kick(const char *source, int ac, const char **av) +int anope_event_kick(const Anope::string &source, int ac, const char **av) { do_kick(source, ac, av); return MOD_CONT; } -int anope_event_join(const char *source, int ac, const char **av) +int anope_event_join(const Anope::string &source, int ac, const char **av) { do_join(source, ac, av); return MOD_CONT; } -int anope_event_motd(const char *source, int ac, const char **av) +int anope_event_motd(const Anope::string &source, int ac, const char **av) { m_motd(source); return MOD_CONT; } -int anope_event_setname(const char *source, int ac, const char **av) +int anope_event_setname(const Anope::string &source, int ac, const char **av) { User *u; @@ -732,7 +699,7 @@ int anope_event_setname(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_chgname(const char *source, int ac, const char **av) +int anope_event_chgname(const Anope::string &source, int ac, const char **av) { User *u; @@ -747,7 +714,7 @@ int anope_event_chgname(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_setident(const char *source, int ac, const char **av) +int anope_event_setident(const Anope::string &source, int ac, const char **av) { User *u; @@ -762,7 +729,7 @@ int anope_event_setident(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_chgident(const char *source, int ac, const char **av) +int anope_event_chgident(const Anope::string &source, int ac, const char **av) { User *u; @@ -777,7 +744,7 @@ int anope_event_chgident(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_sethost(const char *source, int ac, const char **av) +int anope_event_sethost(const Anope::string &source, int ac, const char **av) { User *u; @@ -792,9 +759,9 @@ int anope_event_sethost(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_nick(const char *source, int ac, const char **av) +int anope_event_nick(const Anope::string &source, int ac, const char **av) { - do_nick(source, av[0], NULL, NULL, NULL, NULL, 0, 0, NULL, NULL); + do_nick(source, av[0], "", "", "", "", 0, 0, "", ""); return MOD_CONT; } @@ -812,20 +779,19 @@ int anope_event_nick(const char *source, int ac, const char **av) * last: realname */ -int anope_event_uid(const char *source, int ac, const char **av) +int anope_event_uid(const Anope::string &source, int ac, const char **av) { User *user; NickAlias *na; - struct in_addr addy; - Server *s = Server::Find(source ? source : ""); - uint32 *ad = reinterpret_cast<uint32 *>(&addy); + Server *s = Server::Find(source); int ts = strtoul(av[1], NULL, 10); /* Check if the previously introduced user was Id'd for the nickgroup of the nick he s currently using. * If not, validate the user. ~ Viper*/ user = prev_u_intro; prev_u_intro = NULL; - if (user) na = findnick(user->nick); + if (user) + na = findnick(user->nick); if (user && !user->server->IsSynced() && (!na || na->nc != user->Account())) { validate_user(user); @@ -834,15 +800,10 @@ int anope_event_uid(const char *source, int ac, const char **av) } user = NULL; - inet_aton(av[6], &addy); - user = do_nick("", av[2], /* nick */ - av[5], /* username */ - av[3], /* realhost */ - s->GetName().c_str(), /* server */ - av[ac - 1], /* realname */ - ts, htonl(*ad), av[4], av[0]); + user = do_nick("", av[2], av[5], av[3], s->GetName(), av[ac - 1], ts, 0, av[4], av[0]); if (user) { + user->host = av[6]; UserSetInternalModes(user, 1, &av[8]); user->SetCloakedHost(av[4]); if (!user->server->IsSynced()) @@ -854,7 +815,7 @@ int anope_event_uid(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_chghost(const char *source, int ac, const char **av) +int anope_event_chghost(const Anope::string &source, int ac, const char **av) { User *u; @@ -877,13 +838,13 @@ int anope_event_chghost(const char *source, int ac, const char **av) * 3: numeric * 4: desc */ -int anope_event_server(const char *source, int ac, const char **av) +int anope_event_server(const Anope::string &source, int ac, const char **av) { - do_server(source, av[0], atoi(av[2]), av[4], av[3]); + do_server(source, av[0], Anope::string(av[2]).is_number_only() ? convertTo<unsigned>(av[2]) : 0, av[4], av[3]); return MOD_CONT; } -int anope_event_privmsg(const char *source, int ac, const char **av) +int anope_event_privmsg(const Anope::string &source, int ac, const char **av) { if (!finduser(source)) return MOD_CONT; // likely a message from a server, which can happen. @@ -892,19 +853,19 @@ int anope_event_privmsg(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_part(const char *source, int ac, const char **av) +int anope_event_part(const Anope::string &source, int ac, const char **av) { do_part(source, ac, av); return MOD_CONT; } -int anope_event_whois(const char *source, int ac, const char **av) +int anope_event_whois(const Anope::string &source, int ac, const char **av) { m_whois(source, av[0]); return MOD_CONT; } -int anope_event_metadata(const char *source, int ac, const char **av) +int anope_event_metadata(const Anope::string &source, int ac, const char **av) { User *u; @@ -913,16 +874,14 @@ int anope_event_metadata(const char *source, int ac, const char **av) else if (!strcmp(av[1], "accountname")) { if ((u = finduser(av[0]))) - { /* Identify the user for this account - Adam */ u->AutoID(av[2]); - } } return MOD_CONT; } -int anope_event_capab(const char *source, int ac, const char **av) +int anope_event_capab(const Anope::string &source, int ac, const char **av) { if (!strcasecmp(av[0], "START")) { @@ -954,17 +913,17 @@ int anope_event_capab(const char *source, int ac, const char **av) else if (!strcasecmp(av[0], "CAPABILITIES")) { spacesepstream ssep(av[1]); - std::string capab; + Anope::string capab; while (ssep.GetToken(capab)) { - if (capab.find("CHANMODES") != std::string::npos) + if (capab.find("CHANMODES") != Anope::string::npos) { - std::string modes(capab.begin() + 10, capab.end()); + Anope::string modes(capab.begin() + 10, capab.end()); commasepstream sep(modes); - std::string modebuf; + Anope::string modebuf; sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -982,7 +941,7 @@ int anope_event_capab(const char *source, int ac, const char **av) ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OWNER, "CMODE_OWNER", 'q', '@')); continue; case 'a': - ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_PROTECT , "CMODE_PROTECT", 'a', '@')); + ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_PROTECT , "CMODE_PROTECT", 'a', '@')); continue; // XXX list modes needs a bit of a rewrite, we need to be able to support +g here default: @@ -991,7 +950,7 @@ int anope_event_capab(const char *source, int ac, const char **av) } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -1004,7 +963,7 @@ int anope_event_capab(const char *source, int ac, const char **av) } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -1032,7 +991,7 @@ int anope_event_capab(const char *source, int ac, const char **av) } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -1113,15 +1072,15 @@ int anope_event_capab(const char *source, int ac, const char **av) } } } - else if (capab.find("USERMODES") != std::string::npos) + else if (capab.find("USERMODES") != Anope::string::npos) { - std::string modes(capab.begin() + 10, capab.end()); + Anope::string modes(capab.begin() + 10, capab.end()); commasepstream sep(modes); - std::string modebuf; + Anope::string modebuf; while (sep.GetToken(modebuf)) { - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -1185,12 +1144,12 @@ int anope_event_capab(const char *source, int ac, const char **av) } } } - else if (capab.find("PREFIX=(") != std::string::npos) + else if (capab.find("PREFIX=(") != Anope::string::npos) { - std::string modes(capab.begin() + 8, capab.begin() + capab.find(")")); - std::string chars(capab.begin() + capab.find(")") + 1, capab.end()); + Anope::string modes(capab.begin() + 8, capab.begin() + capab.find(')')); + Anope::string chars(capab.begin() + capab.find(')') + 1, capab.end()); - for (size_t t = 0, end = modes.size(); t < end; ++t) + for (size_t t = 0, end = modes.length(); t < end; ++t) { switch (modes[t]) { @@ -1212,10 +1171,10 @@ int anope_event_capab(const char *source, int ac, const char **av) } } } - else if (capab.find("MAXMODES=") != std::string::npos) + else if (capab.find("MAXMODES=") != Anope::string::npos) { - std::string maxmodes(capab.begin() + 9, capab.end()); - ircd->maxmodes = atoi(maxmodes.c_str()); + Anope::string maxmodes(capab.begin() + 9, capab.end()); + ircd->maxmodes = maxmodes.is_number_only() ? convertTo<unsigned>(maxmodes) : 3; } } } @@ -1223,21 +1182,21 @@ int anope_event_capab(const char *source, int ac, const char **av) { if (!has_globopsmod) { - send_cmd(NULL, "ERROR :m_globops is not loaded. This is required by Anope"); + send_cmd("", "ERROR :m_globops is not loaded. This is required by Anope"); quitmsg = "Remote server does not have the m_globops module loaded, and this is required."; quitting = 1; return MOD_STOP; } if (!has_servicesmod) { - send_cmd(NULL, "ERROR :m_services_account.so is not loaded. This is required by Anope"); + send_cmd("", "ERROR :m_services_account.so is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; quitting = 1; return MOD_STOP; } if (!has_hidechansmod) { - send_cmd(NULL, "ERROR :m_hidechans.so is not loaded. This is required by Anope"); + send_cmd("", "ERROR :m_hidechans.so is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; quitting = 1; return MOD_STOP; @@ -1256,11 +1215,11 @@ int anope_event_capab(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_endburst(const char *source, int ac, const char **av) +int anope_event_endburst(const Anope::string &source, int ac, const char **av) { NickAlias *na; User *u = prev_u_intro; - Server *s = Server::Find(source ? source : ""); + Server *s = Server::Find(source); if (!s) throw new CoreException("Got ENDBURST without a source"); @@ -1321,30 +1280,31 @@ void moduleAddIRCDMsgs() Anope::AddMessage("METADATA", anope_event_metadata); } -bool ChannelModeFlood::IsValid(const std::string &value) +bool ChannelModeFlood::IsValid(const Anope::string &value) { - char *dp, *end; - if (!value.empty() && value[0] != ':' && strtoul((value[0] == '*' ? value.c_str() + 1 : value.c_str()), &dp, 10) > 0 && *dp == ':' && *(++dp) && strtoul(dp, &end, 10) > 0 && !*end) - return 1; - else return 0; + Anope::string rest; + if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty()) + return true; + else + return false; } class ProtoInspIRCd : public Module { public: - ProtoInspIRCd(const std::string &modname, const std::string &creator) : Module(modname, creator) + ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(PROTOCOL); - if (Config.Numeric) - TS6SID = sstrdup(Config.Numeric); + if (!Config.Numeric.empty()) + TS6SID = Config.Numeric; pmodule_ircd_version("InspIRCd 1.2"); pmodule_ircd_var(myIrcd); pmodule_ircd_useTSMode(0); - CapabType c[] = { CAPAB_NOQUIT, CAPAB_SSJ3, CAPAB_NICK2, CAPAB_VL, CAPAB_TLKEXT }; + CapabType c[] = { CAPAB_NOQUIT, CAPAB_SSJ3, CAPAB_NICK2, CAPAB_VL, CAPAB_TLKEXT }; for (unsigned i = 0; i < 5; ++i) Capab.SetFlag(c[i]); @@ -1354,12 +1314,7 @@ class ProtoInspIRCd : public Module ModuleManager::Attach(I_OnUserNickChange, this); } - ~ProtoInspIRCd() - { - delete [] TS6SID; - } - - void OnUserNickChange(User *u, const std::string &) + void OnUserNickChange(User *u, const Anope::string &) { /* InspIRCd 1.2 doesn't set -r on nick change, remove -r here. Note that if we have to set +r later * this will cancel out this -r, resulting in no mode changes. diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index f8ef3ee5c..8c3f14e67 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -15,22 +15,6 @@ #include "modules.h" #include "hashcomp.h" -#ifndef _WIN32 -# include <sys/socket.h> -# include <netinet/in.h> -# include <arpa/inet.h> -#endif - -#ifdef _WIN32 -# include <winsock.h> -int inet_aton(const char *name, struct in_addr *addr) -{ - uint32 a = inet_addr(name); - addr->s_addr = a; - return a != (uint32) - 1; -} -#endif - IRCDVar myIrcd[] = { {"InspIRCd 2.0", /* ircd name */ "+I", /* Modes used by pseudoclients */ @@ -60,7 +44,6 @@ IRCDVar myIrcd[] = { 0, /* Change RealName */ 1, /* No Knock requires +i */ 0, /* We support inspircd TOKENS */ - 0, /* TIME STAMPS are BASE64 */ 0, /* Can remove User Channel Modes with SVSMODE */ 0, /* Sglines are not enforced until user reconnects */ 1, /* ts6 */ @@ -82,7 +65,7 @@ static bool has_chgidentmod = false; static User *prev_u_intro = NULL; /* CHGHOST */ -void inspircd_cmd_chghost(const char *nick, const char *vhost) +void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost) { if (!has_chghostmod) { @@ -90,50 +73,48 @@ void inspircd_cmd_chghost(const char *nick, const char *vhost) return; } - BotInfo *bi = OperServ; - send_cmd(bi->GetUID(), "CHGHOST %s %s", nick, vhost); + send_cmd(OperServ->GetUID(), "CHGHOST %s %s", nick.c_str(), vhost.c_str()); } -int anope_event_idle(const char *source, int ac, const char **av) +int anope_event_idle(const Anope::string &source, int ac, const char **av) { BotInfo *bi = findbot(av[0]); if (!bi) return MOD_CONT; - send_cmd(bi->GetUID(), "IDLE %s %ld %ld", source, static_cast<long>(start_time), static_cast<long>(time(NULL) - bi->lastmsg)); + send_cmd(bi->GetUID(), "IDLE %s %ld %ld", source.c_str(), static_cast<long>(start_time), static_cast<long>(time(NULL) - bi->lastmsg)); return MOD_CONT; } -static char currentpass[1024]; +static Anope::string currentpass; /* PASS */ -void inspircd_cmd_pass(const char *pass) +void inspircd_cmd_pass(const Anope::string &pass) { - strlcpy(currentpass, pass, sizeof(currentpass)); + currentpass = pass; } class InspIRCdProto : public IRCDProto { void SendAkillDel(XLine *x) { - BotInfo *bi = OperServ; - send_cmd(bi->GetUID(), "GLINE %s", x->Mask.c_str()); + send_cmd(OperServ->GetUID(), "GLINE %s", x->Mask.c_str()); } - void SendTopic(BotInfo *whosets, Channel *c, const char *whosetit, const char *topic) + void SendTopic(BotInfo *whosets, Channel *c, const Anope::string &whosetit, const Anope::string &topic) { - send_cmd(whosets->GetUID(), "FTOPIC %s %lu %s :%s", c->name.c_str(), static_cast<unsigned long>(c->topic_time), whosetit, topic); + send_cmd(whosets->GetUID(), "FTOPIC %s %lu %s :%s", c->name.c_str(), static_cast<unsigned long>(c->topic_time), whosetit.c_str(), topic.c_str()); } void SendVhostDel(User *u) { if (u->HasMode(UMODE_CLOAK)) - inspircd_cmd_chghost(u->nick.c_str(), u->chost.c_str()); + inspircd_cmd_chghost(u->nick, u->chost); else - inspircd_cmd_chghost(u->nick.c_str(), u->host); + inspircd_cmd_chghost(u->nick, u->host); if (has_chgidentmod && u->GetIdent() != u->GetVIdent()) - inspircd_cmd_chgident(u->nick.c_str(), u->GetIdent().c_str()); + inspircd_cmd_chgident(u->nick, u->GetIdent()); } void SendAkill(XLine *x) @@ -142,13 +123,12 @@ class InspIRCdProto : public IRCDProto time_t timeleft = x->Expires - time(NULL); if (timeleft > 172800 || !x->Expires) timeleft = 172800; - BotInfo *bi = OperServ; - send_cmd(bi->GetUID(), "ADDLINE G %s@%s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str()); + send_cmd(OperServ->GetUID(), "ADDLINE G %s@%s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str()); } - void SendSVSKillInternal(BotInfo *source, User *user, const char *buf) + void SendSVSKillInternal(BotInfo *source, User *user, const Anope::string &buf) { - send_cmd(source ? source->GetUID() : TS6SID, "KILL %s :%s", user->GetUID().c_str(), buf); + send_cmd(source ? source->GetUID() : TS6SID, "KILL %s :%s", user->GetUID().c_str(), buf.c_str()); } void SendSVSMode(User *u, int ac, const char **av) @@ -156,56 +136,51 @@ class InspIRCdProto : public IRCDProto this->SendModeInternal(NULL, u, merge_args(ac, av)); } - void SendNumericInternal(const char *source, int numeric, const char *dest, const char *buf) - { - send_cmd(TS6SID, "PUSH %s ::%s %03d %s %s", dest, source, numeric, dest, buf); - } - - void SendGuestNick(const char *nick, const char *user, const char *host, const char *real, const char *modes) + void SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf) { - send_cmd(TS6SID, "UID %ld %s %s %s %s +%s 0.0.0.0 :%s", static_cast<long>(time(NULL)), nick, host, host, user, modes, real); + send_cmd(TS6SID, "PUSH %s ::%s %03d %s %s", dest.c_str(), source.c_str(), numeric, dest.c_str(), buf.c_str()); } - void SendModeInternal(BotInfo *source, Channel *dest, const char *buf) + void SendModeInternal(BotInfo *source, Channel *dest, const Anope::string &buf) { - send_cmd(source ? source->GetUID() : TS6SID, "FMODE %s %u %s", dest->name.c_str(), static_cast<unsigned>(dest->creation_time), buf); + send_cmd(source ? source->GetUID() : TS6SID, "FMODE %s %u %s", dest->name.c_str(), static_cast<unsigned>(dest->creation_time), buf.c_str()); } - void SendModeInternal(BotInfo *bi, User *u, const char *buf) + void SendModeInternal(BotInfo *bi, User *u, const Anope::string &buf) { - if (!buf) + if (buf.empty()) return; - send_cmd(bi ? bi->GetUID() : TS6SID, "MODE %s %s", u->GetUID().c_str(), buf); + send_cmd(bi ? bi->GetUID() : TS6SID, "MODE %s %s", u->GetUID().c_str(), buf.c_str()); } - void SendClientIntroduction(const std::string &nick, const std::string &user, const std::string &host, const std::string &real, const char *modes, const std::string &uid) + void SendClientIntroduction(const Anope::string &nick, const Anope::string &user, const Anope::string &host, const Anope::string &real, const Anope::string &modes, const Anope::string &uid) { - send_cmd(TS6SID, "UID %s %ld %s %s %s %s 0.0.0.0 %ld %s :%s", uid.c_str(), static_cast<long>(time(NULL)), nick.c_str(), host.c_str(), host.c_str(), user.c_str(), static_cast<long>(time(NULL)), modes, real.c_str()); + send_cmd(TS6SID, "UID %s %ld %s %s %s %s 0.0.0.0 %ld %s :%s", uid.c_str(), static_cast<long>(time(NULL)), nick.c_str(), host.c_str(), host.c_str(), user.c_str(), static_cast<long>(time(NULL)), modes.c_str(), real.c_str()); } - void SendKickInternal(BotInfo *source, Channel *chan, User *user, const char *buf) + void SendKickInternal(BotInfo *source, Channel *chan, User *user, const Anope::string &buf) { - if (buf) - send_cmd(source->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), buf); + if (!buf.empty()) + send_cmd(source->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), buf.c_str()); else send_cmd(source->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), user->nick.c_str()); } - void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const char *buf) + void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const Anope::string &buf) { - send_cmd(TS6SID, "NOTICE @%s :%s", dest->name.c_str(), buf); + send_cmd(TS6SID, "NOTICE @%s :%s", dest->name.c_str(), buf.c_str()); } /* SERVER services-dev.chatspike.net password 0 :Description here */ void SendServer(Server *server) { - send_cmd(NULL, "SERVER %s %s %d %s :%s", server->GetName().c_str(), currentpass, server->GetHops(), server->GetSID().c_str(), server->GetDescription().c_str()); + send_cmd("", "SERVER %s %s %d %s :%s", server->GetName().c_str(), currentpass.c_str(), server->GetHops(), server->GetSID().c_str(), server->GetDescription().c_str()); } /* JOIN */ - void SendJoin(BotInfo *user, const char *channel, time_t chantime) + void SendJoin(BotInfo *user, const Anope::string &channel, time_t chantime) { - send_cmd(TS6SID, "FJOIN %s %ld + :,%s", channel, static_cast<long>(chantime), user->GetUID().c_str()); + send_cmd(TS6SID, "FJOIN %s %ld + :,%s", channel.c_str(), static_cast<long>(chantime), user->GetUID().c_str()); } /* UNSQLINE */ @@ -217,60 +192,55 @@ class InspIRCdProto : public IRCDProto /* SQLINE */ void SendSQLine(XLine *x) { - send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config.s_OperServ, static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config.s_OperServ.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); } /* SQUIT */ - void SendSquit(const char *servname, const char *message) + void SendSquit(const Anope::string &servname, const Anope::string &message) { - send_cmd(TS6SID, "SQUIT %s :%s", servname, message); + send_cmd(TS6SID, "SQUIT %s :%s", servname.c_str(), message.c_str()); } /* Functions that use serval cmd functions */ - void SendVhost(User *u, const std::string &vIdent, const std::string &vhost) + void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) { if (!vIdent.empty()) - inspircd_cmd_chgident(u->nick.c_str(), vIdent.c_str()); + inspircd_cmd_chgident(u->nick, vIdent); if (!vhost.empty()) - inspircd_cmd_chghost(u->nick.c_str(), vhost.c_str()); + inspircd_cmd_chghost(u->nick, vhost); } void SendConnect() { - send_cmd(NULL, "CAPAB START 1202"); - send_cmd(NULL, "CAPAB CAPABILITIES :PROTOCOL=1202"); - send_cmd(NULL, "CAPAB END"); + send_cmd("", "CAPAB START 1202"); + send_cmd("", "CAPAB CAPABILITIES :PROTOCOL=1202"); + send_cmd("", "CAPAB END"); inspircd_cmd_pass(uplink_server->password); SendServer(Me); send_cmd(TS6SID, "BURST"); - send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config.ServerName, ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str()); + send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config.ServerName.c_str(), ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str()); } /* CHGIDENT */ - void inspircd_cmd_chgident(const char *nick, const char *vIdent) + void inspircd_cmd_chgident(const Anope::string &nick, const Anope::string &vIdent) { if (!has_chgidentmod) ircdproto->SendGlobops(OperServ, "CHGIDENT not loaded!"); else - { - BotInfo *bi = OperServ; - send_cmd(bi->GetUID(), "CHGIDENT %s %s", nick, vIdent); - } + send_cmd(OperServ->GetUID(), "CHGIDENT %s %s", nick.c_str(), vIdent.c_str()); } /* SVSHOLD - set */ - void SendSVSHold(const char *nick) + void SendSVSHold(const Anope::string &nick) { - BotInfo *bi = OperServ; - send_cmd(bi->GetUID(), "SVSHOLD %s %u :%s", nick, static_cast<unsigned>(Config.NSReleaseTimeout), "Being held for registered user"); + send_cmd(OperServ->GetUID(), "SVSHOLD %s %u :Being held for registered user", nick.c_str(), static_cast<unsigned>(Config.NSReleaseTimeout)); } /* SVSHOLD - release */ - void SendSVSHoldDel(const char *nick) + void SendSVSHoldDel(const Anope::string &nick) { - BotInfo *bi = OperServ; - send_cmd(bi->GetUID(), "SVSHOLD %s", nick); + send_cmd(OperServ->GetUID(), "SVSHOLD %s", nick.c_str()); } /* UNSZLINE */ @@ -291,25 +261,25 @@ class InspIRCdProto : public IRCDProto u->RemoveMode(NickServ, UMODE_REGISTERED); } - void SendSVSJoin(const char *source, const char *nick, const char *chan, const char *param) + void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) { User *u = finduser(nick); BotInfo *bi = findbot(source); - send_cmd(bi->GetUID(), "SVSJOIN %s %s", u->GetUID().c_str(), chan); + send_cmd(bi->GetUID(), "SVSJOIN %s %s", u->GetUID().c_str(), chan.c_str()); } - void SendSVSPart(const char *source, const char *nick, const char *chan) + void SendSVSPart(const Anope::string &source, const Anope::string &nick, const Anope::string &chan) { User *u = finduser(nick); BotInfo *bi = findbot(source); - send_cmd(bi->GetUID(), "SVSPART %s %s", u->GetUID().c_str(), chan); + send_cmd(bi->GetUID(), "SVSPART %s %s", u->GetUID().c_str(), chan.c_str()); } - void SendSWhois(const char *source, const char *who, const char *mask) + void SendSWhois(const Anope::string &, const Anope::string &who, const Anope::string &mask) { User *u = finduser(who); - send_cmd(TS6SID, "METADATA %s swhois :%s", u->GetUID().c_str(), mask); + send_cmd(TS6SID, "METADATA %s swhois :%s", u->GetUID().c_str(), mask.c_str()); } void SendEOB() @@ -317,27 +287,28 @@ class InspIRCdProto : public IRCDProto send_cmd(TS6SID, "ENDBURST"); } - void SendGlobopsInternal(BotInfo *source, const char *buf) + void SendGlobopsInternal(BotInfo *source, const Anope::string &buf) { - send_cmd(source ? source->GetUID() : TS6SID, "SNONOTICE g :%s", buf); + send_cmd(source ? source->GetUID() : TS6SID, "SNONOTICE g :%s", buf.c_str()); } - void SendAccountLogin(User *u, NickCore *account) + void SendAccountLogin(User *u, const NickCore *account) { - send_cmd(TS6SID, "METADATA %s accountname :%s", u->GetUID().c_str(), account->display); + send_cmd(TS6SID, "METADATA %s accountname :%s", u->GetUID().c_str(), account->display.c_str()); } - void SendAccountLogout(User *u, NickCore *account) + void SendAccountLogout(User *u, const NickCore *account) { send_cmd(TS6SID, "METADATA %s accountname :", u->GetUID().c_str()); } - int IsNickValid(const char *nick) + bool IsNickValid(const Anope::string &nick) { /* InspIRCd, like TS6, uses UIDs on collision, so... */ - if (isdigit(*nick)) - return 0; - return 1; + if (isdigit(nick[0])) + return false; + + return true; } void SetAutoIdentificationToken(User *u) @@ -349,7 +320,7 @@ class InspIRCdProto : public IRCDProto } } ircd_proto; -int anope_event_ftopic(const char *source, int ac, const char **av) +int anope_event_ftopic(const Anope::string &source, int ac, const char **av) { /* :source FTOPIC channel ts setby :topic */ const char *temp; @@ -362,7 +333,7 @@ int anope_event_ftopic(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_mode(const char *source, int ac, const char **av) +int anope_event_mode(const Anope::string &source, int ac, const char **av) { if (*av[0] == '#' || *av[0] == '&') do_cmode(source, ac, av); @@ -381,16 +352,16 @@ int anope_event_mode(const char *source, int ac, const char **av) // if it's still null, drop it like fire. // most likely situation was that server introduced a nick which we subsequently akilled - if (u == NULL) + if (!u) return MOD_CONT; av[0] = u2->nick.c_str(); - do_umode(u->nick.c_str(), ac, av); + do_umode(u->nick, ac, av); } return MOD_CONT; } -int anope_event_opertype(const char *source, int ac, const char **av) +int anope_event_opertype(const Anope::string &source, int ac, const char **av) { /* opertype is equivalent to mode +o because servers dont do this directly */ @@ -399,7 +370,7 @@ int anope_event_opertype(const char *source, int ac, const char **av) if (u && !is_oper(u)) { const char *newav[2]; - newav[0] = source; + newav[0] = source.c_str(); newav[1] = "+o"; return anope_event_mode(source, 2, newav); } @@ -407,7 +378,7 @@ int anope_event_opertype(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_fmode(const char *source, int ac, const char **av) +int anope_event_fmode(const Anope::string &source, int ac, const char **av) { const char *newav[128]; int n, o; @@ -420,10 +391,11 @@ int anope_event_fmode(const char *source, int ac, const char **av) /* Checking the TS for validity to avoid desyncs */ if ((c = findchan(av[0]))) { - if (c->creation_time > strtol(av[1], NULL, 10)) + time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0; + if (c->creation_time > ts) /* Our TS is bigger, we should lower it */ - c->creation_time = strtol(av[1], NULL, 10); - else if (c->creation_time < strtol(av[1], NULL, 10)) + c->creation_time = ts; + else if (c->creation_time < ts) /* The TS we got is bigger, we should ignore this message. */ return MOD_CONT; } @@ -455,10 +427,10 @@ int anope_event_fmode(const char *source, int ac, const char **av) * 2: channel modes + params (NOTE: this may definitely be more than one param!) * last: users */ -int anope_event_fjoin(const char *source, int ac, const char **av) +int anope_event_fjoin(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); - time_t ts = atol(av[1]); + time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0; bool was_created = false; bool keep_their_modes = true; @@ -517,11 +489,10 @@ int anope_event_fjoin(const char *source, int ac, const char **av) } spacesepstream sep(av[ac - 1]); - std::string buf; + Anope::string buf; while (sep.GetToken(buf)) { std::list<ChannelMode *> Status; - Status.clear(); /* Loop through prefixes and find modes for them */ while (buf[0] != ',') @@ -589,10 +560,10 @@ int anope_event_fjoin(const char *source, int ac, const char **av) } /* Events */ -int anope_event_ping(const char *source, int ac, const char **av) +int anope_event_ping(const Anope::string &source, int ac, const char **av) { if (ac == 1) - ircdproto->SendPong(NULL, av[0]); + ircdproto->SendPong("", av[0]); if (ac == 2) ircdproto->SendPong(av[1], av[0]); @@ -600,32 +571,32 @@ int anope_event_ping(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_time(const char *source, int ac, const char **av) +int anope_event_time(const Anope::string &source, int ac, const char **av) { if (ac !=2) return MOD_CONT; - send_cmd(TS6SID, "TIME %s %s %ld", source, av[1], static_cast<long>(time(NULL))); + send_cmd(TS6SID, "TIME %s %s %ld", source.c_str(), av[1], static_cast<long>(time(NULL))); /* We handled it, don't pass it on to the core.. * The core doesn't understand our syntax anyways.. ~ Viper */ return MOD_STOP; } -int anope_event_436(const char *source, int ac, const char **av) +int anope_event_436(const Anope::string &source, int ac, const char **av) { m_nickcoll(av[0]); return MOD_CONT; } -int anope_event_away(const char *source, int ac, const char **av) +int anope_event_away(const Anope::string &source, int ac, const char **av) { - m_away(source, (ac ? av[0] : NULL)); + m_away(source, ac ? av[0] : ""); return MOD_CONT; } /* Taken from hybrid.c, topic syntax is identical */ -int anope_event_topic(const char *source, int ac, const char **av) +int anope_event_topic(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); time_t topic_time = time(NULL); @@ -640,13 +611,9 @@ int anope_event_topic(const char *source, int ac, const char **av) if (check_topiclock(c, topic_time)) return MOD_CONT; - if (c->topic) - { - delete [] c->topic; - c->topic = NULL; - } + c->topic.clear(); if (ac > 1 && *av[1]) - c->topic = sstrdup(av[1]); + c->topic = av[1]; c->topic_setter = u ? u->nick : source; c->topic_time = topic_time; @@ -665,13 +632,13 @@ int anope_event_topic(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_squit(const char *source, int ac, const char **av) +int anope_event_squit(const Anope::string &source, int ac, const char **av) { do_squit(source, ac, av); return MOD_CONT; } -int anope_event_rsquit(const char *source, int ac, const char **av) +int anope_event_rsquit(const Anope::string &source, int ac, const char **av) { /* On InspIRCd we must send a SQUIT when we recieve RSQUIT for a server we have juped */ Server *s = Server::Find(av[0]); @@ -683,39 +650,39 @@ int anope_event_rsquit(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_quit(const char *source, int ac, const char **av) +int anope_event_quit(const Anope::string &source, int ac, const char **av) { do_quit(source, ac, av); return MOD_CONT; } -int anope_event_kill(const char *source, int ac, const char **av) +int anope_event_kill(const Anope::string &source, int ac, const char **av) { User *u = finduser(av[0]); BotInfo *bi = findbot(av[0]); - m_kill(u ? u->nick.c_str() : (bi ? bi->nick : av[0]), av[1]); + m_kill(u ? u->nick : (bi ? bi->nick : av[0]), av[1]); return MOD_CONT; } -int anope_event_kick(const char *source, int ac, const char **av) +int anope_event_kick(const Anope::string &source, int ac, const char **av) { do_kick(source, ac, av); return MOD_CONT; } -int anope_event_join(const char *source, int ac, const char **av) +int anope_event_join(const Anope::string &source, int ac, const char **av) { do_join(source, ac, av); return MOD_CONT; } -int anope_event_motd(const char *source, int ac, const char **av) +int anope_event_motd(const Anope::string &source, int ac, const char **av) { m_motd(source); return MOD_CONT; } -int anope_event_setname(const char *source, int ac, const char **av) +int anope_event_setname(const Anope::string &source, int ac, const char **av) { User *u; @@ -730,7 +697,7 @@ int anope_event_setname(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_chgname(const char *source, int ac, const char **av) +int anope_event_chgname(const Anope::string &source, int ac, const char **av) { User *u; @@ -745,7 +712,7 @@ int anope_event_chgname(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_setident(const char *source, int ac, const char **av) +int anope_event_setident(const Anope::string &source, int ac, const char **av) { User *u; @@ -760,7 +727,7 @@ int anope_event_setident(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_chgident(const char *source, int ac, const char **av) +int anope_event_chgident(const Anope::string &source, int ac, const char **av) { User *u = finduser(source); @@ -774,7 +741,7 @@ int anope_event_chgident(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_sethost(const char *source, int ac, const char **av) +int anope_event_sethost(const Anope::string &source, int ac, const char **av) { User *u; @@ -789,9 +756,9 @@ int anope_event_sethost(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_nick(const char *source, int ac, const char **av) +int anope_event_nick(const Anope::string &source, int ac, const char **av) { - do_nick(source, av[0], NULL, NULL, NULL, NULL, 0, 0, NULL, NULL); + do_nick(source, av[0], "", "", "", "", 0, 0, "", ""); return MOD_CONT; } @@ -809,14 +776,12 @@ int anope_event_nick(const char *source, int ac, const char **av) * last: realname */ -int anope_event_uid(const char *source, int ac, const char **av) +int anope_event_uid(const Anope::string &source, int ac, const char **av) { User *user; NickAlias *na; - struct in_addr addy; - Server *s = Server::Find(source ? source : ""); - uint32 *ad = reinterpret_cast<uint32 *>(&addy); - int ts = strtoul(av[1], NULL, 10); + Server *s = Server::Find(source); + time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0; /* Check if the previously introduced user was Id'd for the nickgroup of the nick he s currently using. * If not, validate the user. ~ Viper*/ @@ -832,15 +797,10 @@ int anope_event_uid(const char *source, int ac, const char **av) } user = NULL; - inet_aton(av[6], &addy); - user = do_nick("", av[2], /* nick */ - av[5], /* username */ - av[3], /* realhost */ - s->GetName().c_str(), /* server */ - av[ac - 1], /* realname */ - ts, htonl(*ad), av[4], av[0]); + user = do_nick("", av[2], av[5], av[3], s->GetName(), av[ac - 1], ts, 0, av[4], av[0]); if (user) { + user->hostip = av[6]; UserSetInternalModes(user, 1, &av[8]); user->SetCloakedHost(av[4]); if (!user->server->IsSynced()) @@ -852,7 +812,7 @@ int anope_event_uid(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_chghost(const char *source, int ac, const char **av) +int anope_event_chghost(const Anope::string &source, int ac, const char **av) { User *u; @@ -875,13 +835,13 @@ int anope_event_chghost(const char *source, int ac, const char **av) * 3: numeric * 4: desc */ -int anope_event_server(const char *source, int ac, const char **av) +int anope_event_server(const Anope::string &source, int ac, const char **av) { - do_server(source, av[0], atoi(av[2]), av[4], av[3]); + do_server(source, av[0], Anope::string(av[2]).is_number_only() ? convertTo<unsigned>(av[2]) : 0, av[4], av[3]); return MOD_CONT; } -int anope_event_privmsg(const char *source, int ac, const char **av) +int anope_event_privmsg(const Anope::string &source, int ac, const char **av) { if (!finduser(source)) return MOD_CONT; // likely a message from a server, which can happen. @@ -890,19 +850,19 @@ int anope_event_privmsg(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_part(const char *source, int ac, const char **av) +int anope_event_part(const Anope::string &source, int ac, const char **av) { do_part(source, ac, av); return MOD_CONT; } -int anope_event_whois(const char *source, int ac, const char **av) +int anope_event_whois(const Anope::string &source, int ac, const char **av) { m_whois(source, av[0]); return MOD_CONT; } -int anope_event_metadata(const char *source, int ac, const char **av) +int anope_event_metadata(const Anope::string &source, int ac, const char **av) { User *u; @@ -911,22 +871,20 @@ int anope_event_metadata(const char *source, int ac, const char **av) else if (!strcmp(av[1], "accountname")) { if ((u = finduser(av[0]))) - { /* Identify the user for this account - Adam */ u->AutoID(av[2]); - } } return MOD_CONT; } -int anope_event_capab(const char *source, int ac, const char **av) +int anope_event_capab(const Anope::string &source, int ac, const char **av) { if (!strcasecmp(av[0], "START")) { - if (ac < 2 || atoi(av[1]) < 1202) + if (ac < 2 || (Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]): 0) < 1202) { - send_cmd(NULL, "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START"); + send_cmd("", "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START"); quitmsg = "Protocol mismatch, no or invalid protocol version given in CAPAB START"; quitting = 1; return MOD_STOP; @@ -941,103 +899,103 @@ int anope_event_capab(const char *source, int ac, const char **av) else if (!strcasecmp(av[0], "CHANMODES")) { spacesepstream ssep(av[1]); - std::string capab; + Anope::string capab; while (ssep.GetToken(capab)) { - std::string modename = capab.substr(0, capab.find('=')); - std::string modechar = capab.substr(capab.find('=') + 1); + Anope::string modename = capab.substr(0, capab.find('=')); + Anope::string modechar = capab.substr(capab.find('=') + 1); ChannelMode *cm = NULL; - if (modename == "admin") + if (modename.equals_cs("admin")) cm = new ChannelModeStatus(CMODE_PROTECT, "CMODE_PROTECT", modechar[1], modechar[0]); - else if (modename == "allowinvite") + else if (modename.equals_cs("allowinvite")) cm = new ChannelMode(CMODE_ALLINVITE, "CMODE_ALLINVITE", modechar[0]); - else if (modename == "auditorium") + else if (modename.equals_cs("auditorium")) cm = new ChannelMode(CMODE_AUDITORIUM, "CMODE_AUDITORIUM", modechar[0]); - else if (modename == "autoop") + else if (modename.equals_cs("autoop")) continue; // XXX Not currently tracked - else if (modename == "ban") + else if (modename.equals_cs("ban")) cm = new ChannelModeBan(modechar[0]); - else if (modename == "banexception") + else if (modename.equals_cs("banexception")) cm = new ChannelModeExcept(modechar[0]); - else if (modename == "blockcaps") + else if (modename.equals_cs("blockcaps")) cm = new ChannelMode(CMODE_BLOCKCAPS, "CMODE_BLOCKCAPS", modechar[0]); - else if (modename == "blockcolor") + else if (modename.equals_cs("blockcolor")) cm = new ChannelMode(CMODE_BLOCKCOLOR, "CMODE_BLOCKCOLOR", modechar[0]); - else if (modename == "c_registered") + else if (modename.equals_cs("c_registered")) cm = new ChannelModeRegistered(modechar[0]); - else if (modename == "censor") + else if (modename.equals_cs("censor")) cm = new ChannelMode(CMODE_FILTER, "CMODE_FILTER", modechar[0]); - else if (modename == "delayjoin") + else if (modename.equals_cs("delayjoin")) cm = new ChannelMode(CMODE_DELAYEDJOIN, "CMODE_DELAYEDJOIN", modechar[0]); - else if (modename == "delaymsg") + else if (modename.equals_cs("delaymsg")) continue; - else if (modename == "exemptchanops") + else if (modename.equals_cs("exemptchanops")) continue; // XXX - else if (modename == "filter") + else if (modename.equals_cs("filter")) continue; // XXX - else if (modename == "flood") + else if (modename.equals_cs("flood")) cm = new ChannelModeFlood(modechar[0], true); - else if (modename == "founder") + else if (modename.equals_cs("founder")) cm = new ChannelModeStatus(CMODE_OWNER, "CMODE_OWNER", modechar[1], modechar[0]); - else if (modename == "halfop") + else if (modename.equals_cs("halfop")) cm = new ChannelModeStatus(CMODE_HALFOP, "CMODE_HALFOP", modechar[1], modechar[0]); - else if (modename == "history") + else if (modename.equals_cs("history")) continue; // XXX - else if (modename == "invex") + else if (modename.equals_cs("invex")) cm = new ChannelModeInvex(modechar[0]); - else if (modename == "inviteonly") + else if (modename.equals_cs("inviteonly")) cm = new ChannelMode(CMODE_INVITE, "CMODE_INVITE", modechar[0]); - else if (modename == "joinflood") + else if (modename.equals_cs("joinflood")) cm = new ChannelModeParam(CMODE_JOINFLOOD, "CMODE_JOINFLOOD", modechar[0], true); - else if (modename == "key") + else if (modename.equals_cs("key")) cm = new ChannelModeKey(modechar[0]); - else if (modename == "kicknorejoin") + else if (modename.equals_cs("kicknorejoin")) cm = new ChannelModeParam(CMODE_NOREJOIN, "CMODE_NOREJOIN", modechar[0], true); - else if (modename == "limit") + else if (modename.equals_cs("limit")) cm = new ChannelModeParam(CMODE_LIMIT, "CMODE_LIMIT", modechar[0], true); - else if (modename == "moderated") + else if (modename.equals_cs("moderated")) cm = new ChannelMode(CMODE_MODERATED, "CMODE_MODERATED", modechar[0]); - else if (modename == "namebase") + else if (modename.equals_cs("namebase")) continue; // XXX - else if (modename == "nickflood") + else if (modename.equals_cs("nickflood")) cm = new ChannelModeParam(CMODE_NICKFLOOD, "CMODE_NICKFLOOD", modechar[0], true); - else if (modename == "noctcp") + else if (modename.equals_cs("noctcp")) cm = new ChannelMode(CMODE_NOCTCP, "CMODE_NOCTCP", modechar[0]); - else if (modename == "noextmsg") + else if (modename.equals_cs("noextmsg")) cm = new ChannelMode(CMODE_NOEXTERNAL, "CMODE_NOEXTERNAL", modechar[0]); - else if (modename == "nokick") + else if (modename.equals_cs("nokick")) cm = new ChannelMode(CMODE_NOKICK, "CMODE_NOKICK", modechar[0]); - else if (modename == "noknock") + else if (modename.equals_cs("noknock")) cm = new ChannelMode(CMODE_NOKNOCK, "CMODE_NOKNOCK", modechar[0]); - else if (modename == "nonick") + else if (modename.equals_cs("nonick")) cm = new ChannelMode(CMODE_NONICK, "CMODE_NONICK", modechar[0]); - else if (modename == "nonotice") + else if (modename.equals_cs("nonotice")) cm = new ChannelMode(CMODE_NONOTICE, "CMODE_NONOTICE", modechar[0]); - else if (modename == "op") + else if (modename.equals_cs("op")) cm = new ChannelModeStatus(CMODE_OP, "CMODE_OP", modechar[1], modechar[0]); - else if (modename == "operonly") + else if (modename.equals_cs("operonly")) cm = new ChannelModeOper(modechar[0]); - else if (modename == "permanent") + else if (modename.equals_cs("permanent")) cm = new ChannelMode(CMODE_PERM, "CMODE_PERM", modechar[0]); - else if (modename == "private") + else if (modename.equals_cs("private")) cm = new ChannelMode(CMODE_PRIVATE, "CMODE_PRIVATE", modechar[0]); - else if (modename == "redirect") + else if (modename.equals_cs("redirect")) cm = new ChannelModeParam(CMODE_REDIRECT, "CMODE_REDIRECT", modechar[0], true); - else if (modename == "reginvite") + else if (modename.equals_cs("reginvite")) cm = new ChannelMode(CMODE_REGISTEREDONLY, "CMODE_REGISTEREDONLY", modechar[0]); - else if (modename == "regmoderated") + else if (modename.equals_cs("regmoderated")) cm = new ChannelMode(CMODE_REGMODERATED, "CMODE_REGMODERATED", modechar[0]); - else if (modename == "secret") + else if (modename.equals_cs("secret")) cm = new ChannelMode(CMODE_SECRET, "CMODE_SECRET", modechar[0]); - else if (modename == "sslonly") + else if (modename.equals_cs("sslonly")) cm = new ChannelMode(CMODE_SSL, "CMODE_SSL", modechar[0]); - else if (modename == "stripcolor") + else if (modename.equals_cs("stripcolor")) cm = new ChannelMode(CMODE_STRIPCOLOR, "CMODE_STRIPCOLOR", modechar[0]); - else if (modename == "topiclock") + else if (modename.equals_cs("topiclock")) cm = new ChannelMode(CMODE_TOPIC, "CMODE_TOPIC", modechar[0]); - else if (modename == "voice") + else if (modename.equals_cs("voice")) cm = new ChannelModeStatus(CMODE_VOICE, "CMODE_VOICE", modechar[1], modechar[0]); /* Unknown status mode, (customprefix) - add it */ else if (modechar.length() == 2) @@ -1052,49 +1010,49 @@ int anope_event_capab(const char *source, int ac, const char **av) else if (!strcasecmp(av[0], "USERMODES")) { spacesepstream ssep(av[1]); - std::string capab; + Anope::string capab; while (ssep.GetToken(capab)) { - std::string modename = capab.substr(0, capab.find('=')); - std::string modechar = capab.substr(capab.find('=') + 1); + Anope::string modename = capab.substr(0, capab.find('=')); + Anope::string modechar = capab.substr(capab.find('=') + 1); UserMode *um = NULL; - if (modename == "bot") + if (modename.equals_cs("bot")) um = new UserMode(UMODE_BOT, "UMODE_BOT", modechar[0]); - else if (modename == "callerid") + else if (modename.equals_cs("callerid")) um = new UserMode(UMODE_CALLERID, "UMODE_CALLERID", modechar[0]); - else if (modename == "cloak") + else if (modename.equals_cs("cloak")) um = new UserMode(UMODE_CLOAK, "UMODE_CLOAK", modechar[0]); - else if (modename == "deaf") + else if (modename.equals_cs("deaf")) um = new UserMode(UMODE_DEAF, "UMODE_DEAF", modechar[0]); - else if (modename == "deaf_commonchan") + else if (modename.equals_cs("deaf_commonchan")) um = new UserMode(UMODE_COMMONCHANS, "UMODE_COMMONCHANS", modechar[0]); - else if (modename == "helpop") + else if (modename.equals_cs("helpop")) um = new UserMode(UMODE_HELPOP, "UMODE_HELPOP", modechar[0]); - else if (modename == "hidechans") + else if (modename.equals_cs("hidechans")) um = new UserMode(UMODE_PRIV, "UMODE_PRIV", modechar[0]); - else if (modename == "hideoper") + else if (modename.equals_cs("hideoper")) um = new UserMode(UMODE_HIDEOPER, "UMODE_HIDEOPER", modechar[0]); - else if (modename == "invisible") + else if (modename.equals_cs("invisible")) um = new UserMode(UMODE_INVIS, "UMODE_INVIS", modechar[0]); - else if (modename == "oper") + else if (modename.equals_cs("oper")) um = new UserMode(UMODE_OPER, "UMODE_OPER", modechar[0]); - else if (modename == "regdeaf") + else if (modename.equals_cs("regdeaf")) um = new UserMode(UMODE_REGPRIV, "UMODE_REGPRIV", modechar[0]); - else if (modename == "servprotect") + else if (modename.equals_cs("servprotect")) um = new UserMode(UMODE_PROTECTED, "UMODE_PROTECTED", modechar[0]); - else if (modename == "showwhois") + else if (modename.equals_cs("showwhois")) um = new UserMode(UMODE_WHOIS, "UMODE_WHOIS", modechar[0]); - else if (modename == "snomask") + else if (modename.equals_cs("snomask")) continue; // XXX - else if (modename == "u_censor") + else if (modename.equals_cs("u_censor")) um = new UserMode(UMODE_FILTER, "UMODE_FILTER", modechar[0]); - else if (modename == "u_registered") + else if (modename.equals_cs("u_registered")) um = new UserMode(UMODE_REGISTERED, "UMODE_REGISTERED", modechar[0]); - else if (modename == "u_stripcolor") + else if (modename.equals_cs("u_stripcolor")) um = new UserMode(UMODE_STRIPCOLOR, "UMODE_STRIPCOLOR", modechar[0]); - else if (modename == "wallops") + else if (modename.equals_cs("wallops")) um = new UserMode(UMODE_WALLOPS, "UMODE_WALLOPS", modechar[0]); if (um) @@ -1106,43 +1064,43 @@ int anope_event_capab(const char *source, int ac, const char **av) else if (!strcasecmp(av[0], "MODULES")) { spacesepstream ssep(av[1]); - std::string module; + Anope::string module; while (ssep.GetToken(module)) - if (module == "m_svshold.so") + if (module.equals_cs("m_svshold.so")) has_svsholdmod = true; } else if (!strcasecmp(av[0], "MODSUPPORT")) { spacesepstream ssep(av[1]); - std::string module; + Anope::string module; while (ssep.GetToken(module)) { - if (module == "m_services_account.so") + if (module.equals_cs("m_services_account.so")) has_servicesmod = true; - else if (module == "m_chghost.so") + else if (module.equals_cs("m_chghost.so")) has_chghostmod = true; - else if (module == "m_chgident.so") + else if (module.equals_cs("m_chgident.so")) has_chgidentmod = true; - else if (module == "m_servprotect.so") + else if (module.equals_cs("m_servprotect.so")) ircd->pseudoclient_mode = "+Ik"; } } else if (!strcasecmp(av[0], "CAPABILITIES")) { spacesepstream ssep(av[1]); - std::string capab; + Anope::string capab; while (ssep.GetToken(capab)) { - if (capab.find("CHANMODES") != std::string::npos) + if (capab.find("CHANMODES") != Anope::string::npos) { - std::string modes(capab.begin() + 10, capab.end()); + Anope::string modes(capab.begin() + 10, capab.end()); commasepstream sep(modes); - std::string modebuf; + Anope::string modebuf; sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { if (ModeManager::FindChannelModeByChar(modebuf[t])) continue; @@ -1151,7 +1109,7 @@ int anope_event_capab(const char *source, int ac, const char **av) } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { if (ModeManager::FindChannelModeByChar(modebuf[t])) continue; @@ -1159,7 +1117,7 @@ int anope_event_capab(const char *source, int ac, const char **av) } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { if (ModeManager::FindChannelModeByChar(modebuf[t])) continue; @@ -1167,42 +1125,34 @@ int anope_event_capab(const char *source, int ac, const char **av) } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { - if (ModeManager::FindChannelModeByChar(modebuf[t])); + if (ModeManager::FindChannelModeByChar(modebuf[t])) continue; ModeManager::AddChannelMode(new ChannelMode(CMODE_END, "", modebuf[t])); } } - else if (capab.find("USERMODES") != std::string::npos) + else if (capab.find("USERMODES") != Anope::string::npos) { - std::string modes(capab.begin() + 10, capab.end()); + Anope::string modes(capab.begin() + 10, capab.end()); commasepstream sep(modes); - std::string modebuf; + Anope::string modebuf; sep.GetToken(modebuf); sep.GetToken(modebuf); if (sep.GetToken(modebuf)) - { - for (size_t t = 0, end = modebuf.size(); t < end; ++t) - { + for (size_t t = 0, end = modebuf.length(); t < end; ++t) ModeManager::AddUserMode(new UserModeParam(UMODE_END, "", modebuf[t])); - } - } if (sep.GetToken(modebuf)) - { - for (size_t t = 0, end = modebuf.size(); t < end; ++t) - { + for (size_t t = 0, end = modebuf.length(); t < end; ++t) ModeManager::AddUserMode(new UserMode(UMODE_END, "", modebuf[t])); - } - } } - else if (capab.find("MAXMODES=") != std::string::npos) + else if (capab.find("MAXMODES=") != Anope::string::npos) { - std::string maxmodes(capab.begin() + 9, capab.end()); - ircd->maxmodes = atoi(maxmodes.c_str()); + Anope::string maxmodes(capab.begin() + 9, capab.end()); + ircd->maxmodes = maxmodes.is_number_only() ? convertTo<unsigned>(maxmodes) : 3; } } } @@ -1210,14 +1160,14 @@ int anope_event_capab(const char *source, int ac, const char **av) { if (!has_servicesmod) { - send_cmd(NULL, "ERROR :m_services_account.so is not loaded. This is required by Anope"); + send_cmd("", "ERROR :m_services_account.so is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; quitting = 1; return MOD_STOP; } if (!ModeManager::FindUserModeByName(UMODE_PRIV)) { - send_cmd(NULL, "ERROR :m_hidechans.so is not loaded. This is required by Anope"); + send_cmd("", "ERROR :m_hidechans.so is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; quitting = 1; return MOD_STOP; @@ -1236,11 +1186,11 @@ int anope_event_capab(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_endburst(const char *source, int ac, const char **av) +int anope_event_endburst(const Anope::string &source, int ac, const char **av) { NickAlias *na; User *u = prev_u_intro; - Server *s = Server::Find(source ? source : ""); + Server *s = Server::Find(source); if (!s) throw new CoreException("Got ENDBURST without a source"); @@ -1301,30 +1251,32 @@ void moduleAddIRCDMsgs() Anope::AddMessage("METADATA", anope_event_metadata); } -bool ChannelModeFlood::IsValid(const std::string &value) +bool ChannelModeFlood::IsValid(const Anope::string &value) { - char *dp, *end; - if (!value.empty() && value[0] != ':' && strtoul((value[0] == '*' ? value.c_str() + 1 : value.c_str()), &dp, 10) > 0 && *dp == ':' && *(++dp) && strtoul(dp, &end, 10) > 0 && !*end) - return 1; - else return 0; + //char *dp, *end; + Anope::string rest; + if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty()) + return true; + else + return false; } class ProtoInspIRCd : public Module { public: - ProtoInspIRCd(const std::string &modname, const std::string &creator) : Module(modname, creator) + ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(PROTOCOL); - if (Config.Numeric) - TS6SID = sstrdup(Config.Numeric); + if (!Config.Numeric.empty()) + TS6SID = Config.Numeric; pmodule_ircd_version("InspIRCd 2.0"); pmodule_ircd_var(myIrcd); pmodule_ircd_useTSMode(0); - CapabType c[] = { CAPAB_NOQUIT, CAPAB_SSJ3, CAPAB_NICK2, CAPAB_VL, CAPAB_TLKEXT }; + CapabType c[] = { CAPAB_NOQUIT, CAPAB_SSJ3, CAPAB_NICK2, CAPAB_VL, CAPAB_TLKEXT }; for (unsigned i = 0; i < 5; ++i) Capab.SetFlag(c[i]); @@ -1334,12 +1286,7 @@ class ProtoInspIRCd : public Module ModuleManager::Attach(I_OnUserNickChange, this); } - ~ProtoInspIRCd() - { - delete [] TS6SID; - } - - void OnUserNickChange(User *u, const std::string &) + void OnUserNickChange(User *u, const Anope::string &) { u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED)); } diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index 80065222d..a01207a5d 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -12,7 +12,7 @@ #include "services.h" #include "modules.h" -static char *TS6UPLINK = NULL; // XXX is this needed? +static Anope::string TS6UPLINK; // XXX is this needed? IRCDVar myIrcd[] = { {"Ratbox 2.0+", /* ircd name */ @@ -43,7 +43,6 @@ IRCDVar myIrcd[] = { 0, /* Change RealName */ 0, /* No Knock requires +i */ 0, /* We support TOKENS */ - 0, /* TIME STAMPS are BASE64 */ 0, /* Can remove User Channel Modes with SVSMODE */ 0, /* Sglines are not enforced until user reconnects */ 1, /* ts6 */ @@ -66,70 +65,51 @@ IRCDVar myIrcd[] = { */ void ratbox_cmd_svinfo() { - send_cmd(NULL, "SVINFO 6 3 0 :%ld", static_cast<long>(time(NULL))); + send_cmd("", "SVINFO 6 3 0 :%ld", static_cast<long>(time(NULL))); } void ratbox_cmd_svsinfo() { } -void ratbox_cmd_tmode(const char *source, const char *dest, const char *fmt, ...) -{ - va_list args; - char buf[BUFSIZE]; - *buf = '\0'; - - if (fmt) - { - va_start(args, fmt); - vsnprintf(buf, BUFSIZE - 1, fmt, args); - va_end(args); - } - if (!*buf) - return; - - send_cmd(NULL, "MODE %s %s", dest, buf); -} - - /* CAPAB */ /* - QS - Can handle quit storm removal - EX - Can do channel +e exemptions - CHW - Can do channel wall @# - LL - Can do lazy links - IE - Can do invite exceptions - EOB - Can do EOB message - KLN - Can do KLINE message - GLN - Can do GLINE message - HUB - This server is a HUB - UID - Can do UIDs - ZIP - Can do ZIPlinks - ENC - Can do ENCrypted links + QS - Can handle quit storm removal + EX - Can do channel +e exemptions + CHW - Can do channel wall @# + LL - Can do lazy links + IE - Can do invite exceptions + EOB - Can do EOB message + KLN - Can do KLINE message + GLN - Can do GLINE message + HUB - This server is a HUB + UID - Can do UIDs + ZIP - Can do ZIPlinks + ENC - Can do ENCrypted links KNOCK - supports KNOCK TBURST - supports TBURST - PARA - supports invite broadcasting for +p - ENCAP - ? + PARA - supports invite broadcasting for +p + ENCAP - ? */ void ratbox_cmd_capab() { - send_cmd(NULL, "CAPAB :QS EX CHW IE KLN GLN KNOCK TB UNKLN CLUSTER ENCAP"); + send_cmd("", "CAPAB :QS EX CHW IE KLN GLN KNOCK TB UNKLN CLUSTER ENCAP"); } /* PASS */ -void ratbox_cmd_pass(const char *pass) +void ratbox_cmd_pass(const Anope::string &pass) { - send_cmd(NULL, "PASS %s TS 6 :%s", pass, TS6SID); + send_cmd("", "PASS %s TS 6 :%s", pass.c_str(), TS6SID.c_str()); } class RatboxProto : public IRCDTS6Proto { - void SendGlobopsInternal(BotInfo *source, const char *buf) + void SendGlobopsInternal(BotInfo *source, const Anope::string &buf) { if (source) - send_cmd(source->GetUID(), "OPERWALL :%s", buf); + send_cmd(source->GetUID(), "OPERWALL :%s", buf.c_str()); else - send_cmd(TS6SID, "OPERWALL :%s", buf); + send_cmd(TS6SID, "OPERWALL :%s", buf.c_str()); } void SendSQLine(XLine *x) @@ -160,9 +140,9 @@ class RatboxProto : public IRCDTS6Proto send_cmd(TS6SID, "UNRESV * %s", x->Mask.c_str()); } - void SendJoin(BotInfo *user, const char *channel, time_t chantime) + void SendJoin(BotInfo *user, const Anope::string &channel, time_t chantime) { - send_cmd(NULL, "SJOIN %ld %s + :%s", static_cast<long>(chantime), channel, user->GetUID().c_str()); + send_cmd("", "SJOIN %ld %s + :%s", static_cast<long>(chantime), channel.c_str(), user->GetUID().c_str()); } void SendAkill(XLine *x) @@ -171,9 +151,9 @@ class RatboxProto : public IRCDTS6Proto send_cmd(bi ? bi->GetUID() : Config.s_OperServ, "KLINE * %ld %s %s :%s", static_cast<long>(x->Expires - time(NULL)), x->GetUser().c_str(), x->GetHost().c_str(), x->Reason.c_str()); } - void SendSVSKillInternal(BotInfo *source, User *user, const char *buf) + void SendSVSKillInternal(BotInfo *source, User *user, const Anope::string &buf) { - send_cmd(source ? source->GetUID() : TS6SID, "KILL %s :%s", user->GetUID().c_str(), buf); + send_cmd(source ? source->GetUID() : TS6SID, "KILL %s :%s", user->GetUID().c_str(), buf.c_str()); } void SendSVSMode(User *u, int ac, const char **av) @@ -184,7 +164,7 @@ class RatboxProto : public IRCDTS6Proto /* SERVER name hop descript */ void SendServer(Server *server) { - send_cmd(NULL, "SERVER %s %d :%s", server->GetName().c_str(), server->GetHops(), server->GetDescription().c_str()); + send_cmd("", "SERVER %s %d :%s", server->GetName().c_str(), server->GetHops(), server->GetDescription().c_str()); } void SendConnect() @@ -196,110 +176,111 @@ class RatboxProto : public IRCDTS6Proto ratbox_cmd_svinfo(); } - void SendClientIntroduction(const std::string &nick, const std::string &user, const std::string &host, const std::string &real, const char *modes, const std::string &uid) + void SendClientIntroduction(const Anope::string &nick, const Anope::string &user, const Anope::string &host, const Anope::string &real, const Anope::string &modes, const Anope::string &uid) { - EnforceQlinedNick(nick, NULL); - send_cmd(TS6SID, "UID %s 1 %ld %s %s %s 0 %s :%s", nick.c_str(), static_cast<long>(time(NULL)), modes, user.c_str(), host.c_str(), uid.c_str(), real.c_str()); + EnforceQlinedNick(nick, ""); + send_cmd(TS6SID, "UID %s 1 %ld %s %s %s 0 %s :%s", nick.c_str(), static_cast<long>(time(NULL)), modes.c_str(), user.c_str(), host.c_str(), uid.c_str(), real.c_str()); } - void SendPartInternal(BotInfo *bi, const char *chan, const char *buf) + void SendPartInternal(BotInfo *bi, Channel *chan, const Anope::string &buf) { - if (buf) - send_cmd(bi->GetUID(), "PART %s :%s", chan, buf); + if (!buf.empty()) + send_cmd(bi->GetUID(), "PART %s :%s", chan->name.c_str(), buf.c_str()); else - send_cmd(bi->GetUID(), "PART %s", chan); + send_cmd(bi->GetUID(), "PART %s", chan->name.c_str()); } - void SendNumericInternal(const char *source, int numeric, const char *dest, const char *buf) + void SendNumericInternal(const Anope::string &, int numeric, const Anope::string &dest, const Anope::string &buf) { // This might need to be set in the call to SendNumeric instead of here, will review later -- CyberBotX - send_cmd(TS6SID, "%03d %s %s", numeric, dest, buf); + send_cmd(TS6SID, "%03d %s %s", numeric, dest.c_str(), buf.c_str()); } - void SendModeInternal(BotInfo *bi, Channel *dest, const char *buf) + void SendModeInternal(BotInfo *bi, Channel *dest, const Anope::string &buf) { if (bi) - send_cmd(bi->GetUID(), "MODE %s %s", dest->name.c_str(), buf); - else send_cmd(TS6SID, "MODE %s %s", dest->name.c_str(), buf); + send_cmd(bi->GetUID(), "MODE %s %s", dest->name.c_str(), buf.c_str()); + else + send_cmd(TS6SID, "MODE %s %s", dest->name.c_str(), buf.c_str()); } - void SendModeInternal(BotInfo *bi, User *u, const char *buf) + void SendModeInternal(BotInfo *bi, User *u, const Anope::string &buf) { - if (!buf) + if (buf.empty()) return; - send_cmd(bi ? bi->GetUID() : TS6SID, "SVSMODE %s %s", u->nick.c_str(), buf); + send_cmd(bi ? bi->GetUID() : TS6SID, "SVSMODE %s %s", u->nick.c_str(), buf.c_str()); } - void SendKickInternal(BotInfo *bi, Channel *chan, User *user, const char *buf) + void SendKickInternal(BotInfo *bi, Channel *chan, User *user, const Anope::string &buf) { - if (buf) - send_cmd(bi->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), buf); + if (!buf.empty()) + send_cmd(bi->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), buf.c_str()); else send_cmd(bi->GetUID(), "KICK %s %s", chan->name.c_str(), user->GetUID().c_str()); } - void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const char *buf) + void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const Anope::string &buf) { - send_cmd(NULL, "NOTICE @%s :%s", dest->name.c_str(), buf); + send_cmd("", "NOTICE @%s :%s", dest->name.c_str(), buf.c_str()); } /* QUIT */ - void SendQuitInternal(BotInfo *bi, const char *buf) + void SendQuitInternal(BotInfo *bi, const Anope::string &buf) { - if (buf) - send_cmd(bi->GetUID(), "QUIT :%s", buf); + if (!buf.empty()) + send_cmd(bi->GetUID(), "QUIT :%s", buf.c_str()); else send_cmd(bi->GetUID(), "QUIT"); } /* INVITE */ - void SendInvite(BotInfo *source, const char *chan, const char *nick) + void SendInvite(BotInfo *source, const Anope::string &chan, const Anope::string &nick) { User *u = finduser(nick); - send_cmd(source->GetUID(), "INVITE %s %s", u ? u->GetUID().c_str(): nick, chan); + send_cmd(source->GetUID(), "INVITE %s %s", u ? u->GetUID().c_str() : nick.c_str(), chan.c_str()); } - void SendAccountLogin(User *u, NickCore *account) + void SendAccountLogin(User *u, const NickCore *account) { - send_cmd(TS6SID, "ENCAP * SU %s %s", u->GetUID().c_str(), account->display); + send_cmd(TS6SID, "ENCAP * SU %s %s", u->GetUID().c_str(), account->display.c_str()); } - void SendAccountLogout(User *u, NickCore *account) + void SendAccountLogout(User *u, const NickCore *account) { send_cmd(TS6SID, "ENCAP * SU %s", u->GetUID().c_str()); } - int IsNickValid(const char *nick) + bool IsNickValid(const Anope::string &nick) { /* TS6 Save extension -Certus */ - if (isdigit(*nick)) - return 0; - return 1; + if (isdigit(nick[0])) + return false; + + return true; } - void SendTopic(BotInfo *bi, Channel *c, const char *whosetit, const char *topic) + void SendTopic(BotInfo *bi, Channel *c, const Anope::string &, const Anope::string &topic) { - send_cmd(bi->GetUID(), "TOPIC %s :%s", c->name.c_str(), topic); + send_cmd(bi->GetUID(), "TOPIC %s :%s", c->name.c_str(), topic.c_str()); } void SetAutoIdentificationToken(User *u) { - char svidbuf[15]; if (!u->Account()) return; - snprintf(svidbuf, sizeof(svidbuf), "%ld", static_cast<long>(u->timestamp)); + Anope::string svidbuf = stringify(u->timestamp); u->Account()->Shrink("authenticationtoken"); - u->Account()->Extend("authenticationtoken", new ExtensibleItemPointerArray<char>(sstrdup(svidbuf))); + u->Account()->Extend("authenticationtoken", new ExtensibleItemRegular<Anope::string>(svidbuf)); } } ircd_proto; -int anope_event_sjoin(const char *source, int ac, const char **av) +int anope_event_sjoin(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[1]); - time_t ts = atol(av[0]); + time_t ts = Anope::string(av[0]).is_number_only() ? convertTo<time_t>(av[0]) : 0; bool was_created = false; bool keep_their_modes = true; @@ -358,11 +339,10 @@ int anope_event_sjoin(const char *source, int ac, const char **av) } spacesepstream sep(av[ac - 1]); - std::string buf; + Anope::string buf; while (sep.GetToken(buf)) { std::list<ChannelMode *> Status; - Status.clear(); char ch; /* Get prefixes from the nick */ @@ -452,15 +432,15 @@ int anope_event_sjoin(const char *source, int ac, const char **av) av[8] = info */ -int anope_event_nick(const char *source, int ac, const char **av) +int anope_event_nick(const Anope::string &source, int ac, const char **av) { User *user; if (ac == 9) { - Server *s = Server::Find(source ? source : ""); + Server *s = Server::Find(source); /* Source is always the server */ - user = do_nick("", av[0], av[4], av[5], s->GetName().c_str(), av[8], strtoul(av[2], NULL, 10), 0, "*", av[7]); + user = do_nick("", av[0], av[4], av[5], s->GetName(), av[8], Anope::string(av[2]).is_number_only() ? convertTo<time_t>(av[2]) : 0, 0, "*", av[7]); if (user) { /* No usermode +d on ratbox so we use @@ -472,11 +452,11 @@ int anope_event_nick(const char *source, int ac, const char **av) } } else if (ac == 2) - do_nick(source, av[0], NULL, NULL, NULL, NULL, strtoul(av[1], NULL, 10), 0, NULL, NULL); + do_nick(source, av[0], "", "", "", "", Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0, 0, "", ""); return MOD_CONT; } -int anope_event_topic(const char *source, int ac, const char **av) +int anope_event_topic(const Anope::string &source, int ac, const char **av) { User *u; @@ -496,13 +476,9 @@ int anope_event_topic(const char *source, int ac, const char **av) if (check_topiclock(c, topic_time)) return MOD_CONT; - if (c->topic) - { - delete [] c->topic; - c->topic = NULL; - } + c->topic.clear(); if (ac > 1 && *av[1]) - c->topic = sstrdup(av[1]); + c->topic = av[1]; u = finduser(source); c->topic_setter = u ? u->nick : source; @@ -522,53 +498,40 @@ int anope_event_topic(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_tburst(const char *source, int ac, const char **av) +int anope_event_tburst(const Anope::string &source, int ac, const char **av) { - char *setter; Channel *c; time_t topic_time; if (ac != 4) return MOD_CONT; - setter = myStrGetToken(av[2], '!', 0); + Anope::string setter = myStrGetToken(av[2], '!', 0); c = findchan(av[0]); - topic_time = strtol(av[1], NULL, 10); + topic_time = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0; if (!c) { Alog(LOG_DEBUG) << "debug: TOPIC " << merge_args(ac - 1, av + 1) << " for nonexistent channel " << av[0]; - if (setter) - delete [] setter; return MOD_CONT; } if (check_topiclock(c, topic_time)) - { - if (setter) - delete [] setter; return MOD_CONT; - } - if (c->topic) - { - delete [] c->topic; - c->topic = NULL; - } + c->topic.clear(); if (ac > 1 && *av[3]) - c->topic = sstrdup(av[3]); + c->topic = av[3]; c->topic_setter = setter; c->topic_time = topic_time; record_topic(av[0]); - if (setter) - delete [] setter; return MOD_CONT; } -int anope_event_436(const char *source, int ac, const char **av) +int anope_event_436(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -577,7 +540,7 @@ int anope_event_436(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_ping(const char *source, int ac, const char **av) +int anope_event_ping(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -585,16 +548,16 @@ int anope_event_ping(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_away(const char *source, int ac, const char **av) +int anope_event_away(const Anope::string &source, int ac, const char **av) { User *u = NULL; u = finduser(source); - m_away(u ? u->nick.c_str() : source, (ac ? av[0] : NULL)); + m_away(u ? u->nick : source, ac ? av[0] : ""); return MOD_CONT; } -int anope_event_kill(const char *source, int ac, const char **av) +int anope_event_kill(const Anope::string &source, int ac, const char **av) { if (ac != 2) return MOD_CONT; @@ -603,7 +566,7 @@ int anope_event_kill(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_kick(const char *source, int ac, const char **av) +int anope_event_kick(const Anope::string &source, int ac, const char **av) { if (ac != 3) return MOD_CONT; @@ -611,7 +574,7 @@ int anope_event_kick(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_join(const char *source, int ac, const char **av) +int anope_event_join(const Anope::string &source, int ac, const char **av) { if (ac != 1) { @@ -623,31 +586,26 @@ int anope_event_join(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_motd(const char *source, int ac, const char **av) +int anope_event_motd(const Anope::string &source, int ac, const char **av) { - if (!source) + if (source.empty()) return MOD_CONT; m_motd(source); return MOD_CONT; } -int anope_event_privmsg(const char *source, int ac, const char **av) +int anope_event_privmsg(const Anope::string &source, int ac, const char **av) { - User *u; - BotInfo *bi; - if (ac != 2) return MOD_CONT; - u = finduser(source); - bi = findbot(av[0]); // XXX: this is really the same as charybdis m_privmsg(source, av[0], av[1]); return MOD_CONT; } -int anope_event_part(const char *source, int ac, const char **av) +int anope_event_part(const Anope::string &source, int ac, const char **av) { User *u; @@ -655,57 +613,50 @@ int anope_event_part(const char *source, int ac, const char **av) return MOD_CONT; u = finduser(source); - do_part(u ? u->nick.c_str() : source, ac, av); + do_part(u ? u->nick : source, ac, av); return MOD_CONT; } -int anope_event_whois(const char *source, int ac, const char **av) +int anope_event_whois(const Anope::string &source, int ac, const char **av) { - BotInfo *bi; - - if (source && ac >= 1) + if (!source.empty() && ac >= 1) { - bi = findbot(av[0]); - m_whois(source, bi->GetUID().c_str()); + BotInfo *bi = findbot(av[0]); + m_whois(source, bi->GetUID()); } return MOD_CONT; } /* EVENT: SERVER */ -int anope_event_server(const char *source, int ac, const char **av) +int anope_event_server(const Anope::string &source, int ac, const char **av) { if (!stricmp(av[1], "1")) - { - if (TS6UPLINK) - do_server(source, av[0], atoi(av[1]), av[2], TS6UPLINK); - else - do_server(source, av[0], atoi(av[1]), av[2], ""); - } + do_server(source, av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, av[2], TS6UPLINK); else - do_server(source, av[0], atoi(av[1]), av[2], ""); + do_server(source, av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, av[2], ""); return MOD_CONT; } -int anope_event_sid(const char *source, int ac, const char **av) +int anope_event_sid(const Anope::string &source, int ac, const char **av) { /* :42X SID trystan.nomadirc.net 2 43X :ircd-ratbox test server */ - Server *s = Server::Find(source); - do_server(s->GetName(), av[0], atoi(av[1]), av[3], av[2]); + do_server(s->GetName(), av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, av[3], av[2]); return MOD_CONT; } -int anope_event_squit(const char *source, int ac, const char **av) +int anope_event_squit(const Anope::string &source, int ac, const char **av) { if (ac != 2) return MOD_CONT; + do_squit(source, ac, av); return MOD_CONT; } -int anope_event_quit(const char *source, int ac, const char **av) +int anope_event_quit(const Anope::string &source, int ac, const char **av) { User *u; @@ -714,11 +665,11 @@ int anope_event_quit(const char *source, int ac, const char **av) u = finduser(source); - do_quit(u ? u->nick.c_str() : source, ac, av); + do_quit(u ? u->nick : source, ac, av); return MOD_CONT; } -int anope_event_mode(const char *source, int ac, const char **av) +int anope_event_mode(const Anope::string &source, int ac, const char **av) { User *u, *u2; @@ -732,12 +683,12 @@ int anope_event_mode(const char *source, int ac, const char **av) u = finduser(source); u2 = finduser(av[0]); av[0] = u2->nick.c_str(); - do_umode(u->nick.c_str(), ac, av); + do_umode(u->nick, ac, av); } return MOD_CONT; } -int anope_event_tmode(const char *source, int ac, const char **av) +int anope_event_tmode(const Anope::string &source, int ac, const char **av) { if (*av[1] == '#' || *av[1] == '&') do_cmode(source, ac, av); @@ -745,37 +696,34 @@ int anope_event_tmode(const char *source, int ac, const char **av) } /* Event: PROTOCTL */ -int anope_event_capab(const char *source, int ac, const char **av) +int anope_event_capab(const Anope::string &source, int ac, const char **av) { CapabParse(ac, av); return MOD_CONT; } -int anope_event_pass(const char *source, int ac, const char **av) +int anope_event_pass(const Anope::string &source, int ac, const char **av) { - TS6UPLINK = sstrdup(av[3]); + TS6UPLINK = av[3]; return MOD_CONT; } -int anope_event_bmask(const char *source, int ac, const char **av) +int anope_event_bmask(const Anope::string &source, int ac, const char **av) { Channel *c; - char *bans; - char *b; - int count, i; ChannelModeList *cms; /* :42X BMASK 1106409026 #ircops b :*!*@*.aol.com */ - /* 0 1 2 3 */ + /* 0 1 2 3 */ c = findchan(av[1]); if (c) { - bans = sstrdup(av[3]); - count = myNumToken(bans, ' '); + Anope::string bans = av[3]; + int count = myNumToken(bans, ' '), i; for (i = 0; i <= count - 1; ++i) { - b = myStrGetToken(bans, ' ', i); + Anope::string b = myStrGetToken(bans, ' ', i); if (!stricmp(av[2], "b")) { cms = dynamic_cast<ChannelModeList *>(ModeManager::FindChannelModeByChar('b')); @@ -791,15 +739,12 @@ int anope_event_bmask(const char *source, int ac, const char **av) cms = dynamic_cast<ChannelModeList *>(ModeManager::FindChannelModeByChar('I')); cms->AddMask(c, b); } - if (b) - delete [] b; } - delete [] bans; } return MOD_CONT; } -int anope_event_error(const char *source, int ac, const char **av) +int anope_event_error(const Anope::string &source, int ac, const char **av) { if (ac >= 1) Alog(LOG_DEBUG) << av[0]; @@ -867,13 +812,13 @@ static void AddModes() class ProtoRatbox : public Module { public: - ProtoRatbox(const std::string &modname, const std::string &creator) : Module(modname, creator) + ProtoRatbox(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(PROTOCOL); - if (Config.Numeric) - TS6SID = sstrdup(Config.Numeric); + if (!Config.Numeric.empty()) + TS6SID = Config.Numeric; UseTSMODE = 1; /* TMODE */ pmodule_ircd_version("Ratbox IRCD 2.0+"); @@ -889,11 +834,6 @@ class ProtoRatbox : public Module pmodule_ircd_proto(&ircd_proto); moduleAddIRCDMsgs(); } - - ~ProtoRatbox() - { - delete [] TS6SID; - } }; MODULE_INIT(ProtoRatbox) diff --git a/modules/protocol/unreal32.cpp b/modules/protocol/unreal32.cpp index 0cfb0512e..f94e5bcbe 100644 --- a/modules/protocol/unreal32.cpp +++ b/modules/protocol/unreal32.cpp @@ -43,7 +43,6 @@ IRCDVar myIrcd[] = { 1, /* Change RealName */ 1, /* No Knock requires +i */ 1, /* We support Unreal TOKENS */ - 1, /* TIME STAMPS are BASE64 */ 1, /* Can remove User Channel Modes with SVSMODE */ 0, /* Sglines are not enforced until user reconnects */ 0, /* ts6 */ @@ -56,19 +55,9 @@ IRCDVar myIrcd[] = { {NULL} }; -/* svswatch - * parv[0] - sender - * parv[1] - target nick - * parv[2] - parameters - */ -void unreal_cmd_svswatch(const char *sender, const char *nick, const char *parm) -{ - send_cmd(sender, "Bw %s :%s", nick, parm); -} - void unreal_cmd_netinfo(int ac, const char **av) { - send_cmd(NULL, "AO %ld %ld %d %s 0 0 0 :%s", static_cast<long>(maxusercnt), static_cast<long>(time(NULL)), atoi(av[2]), av[3], av[7]); + send_cmd("", "AO %ld %ld %d %s 0 0 0 :%s", static_cast<long>(maxusercnt), static_cast<long>(time(NULL)), Anope::string(av[2]).is_number_only() ? convertTo<int>(av[2]) : 0, av[3], av[7]); } /* PROTOCTL */ @@ -88,50 +77,50 @@ void unreal_cmd_netinfo(int ac, const char **av) */ void unreal_cmd_capab() { - if (Config.Numeric) - send_cmd(NULL, "PROTOCTL NICKv2 VHP UMODE2 NICKIP TOKEN SJOIN SJOIN2 SJ3 NOQUIT TKLEXT SJB64 VL"); + if (!Config.Numeric.empty()) + send_cmd("", "PROTOCTL NICKv2 VHP UMODE2 NICKIP TOKEN SJOIN SJOIN2 SJ3 NOQUIT TKLEXT VL"); else - send_cmd(NULL, "PROTOCTL NICKv2 VHP UMODE2 NICKIP TOKEN SJOIN SJOIN2 SJ3 NOQUIT TKLEXT SJB64"); + send_cmd("", "PROTOCTL NICKv2 VHP UMODE2 NICKIP TOKEN SJOIN SJOIN2 SJ3 NOQUIT TKLEXT"); } /* PASS */ -void unreal_cmd_pass(const char *pass) +void unreal_cmd_pass(const Anope::string &pass) { - send_cmd(NULL, "PASS :%s", pass); + send_cmd("", "PASS :%s", pass.c_str()); } /* CHGHOST */ -void unreal_cmd_chghost(const char *nick, const char *vhost) +void unreal_cmd_chghost(const Anope::string &nick, const Anope::string &vhost) { - if (!nick || !vhost) + if (nick.empty() || vhost.empty()) return; - send_cmd(Config.ServerName, "AL %s %s", nick, vhost); + send_cmd(Config.ServerName, "AL %s %s", nick.c_str(), vhost.c_str()); } /* CHGIDENT */ -void unreal_cmd_chgident(const char *nick, const char *vIdent) +void unreal_cmd_chgident(const Anope::string &nick, const Anope::string &vIdent) { - if (!nick || !vIdent) + if (nick.empty() || vIdent.empty()) return; - send_cmd(Config.ServerName, "AZ %s %s", nick, vIdent); + send_cmd(Config.ServerName, "AZ %s %s", nick.c_str(), vIdent.c_str()); } class UnrealIRCdProto : public IRCDProto { /* SVSNOOP */ - void SendSVSNOOP(const char *server, int set) + void SendSVSNOOP(const Anope::string &server, int set) { - send_cmd(NULL, "f %s %s", server, set ? "+" : "-"); + send_cmd("", "f %s %s", server.c_str(), set ? "+" : "-"); } void SendAkillDel(XLine *x) { - send_cmd(NULL, "BD - G %s %s %s", x->GetUser().c_str(), x->GetHost().c_str(), Config.s_OperServ); + send_cmd("", "BD - G %s %s %s", x->GetUser().c_str(), x->GetHost().c_str(), Config.s_OperServ.c_str()); } - void SendTopic(BotInfo *whosets, Channel *c, const char *whosetit, const char *topic) + void SendTopic(BotInfo *whosets, Channel *c, const Anope::string &whosetit, const Anope::string &topic) { - send_cmd(whosets->nick, ") %s %s %lu :%s", c->name.c_str(), whosetit, static_cast<unsigned long>(c->topic_time), topic); + send_cmd(whosets->nick, ") %s %s %lu :%s", c->name.c_str(), whosetit.c_str(), static_cast<unsigned long>(c->topic_time), topic.c_str()); } void SendVhostDel(User *u) @@ -150,12 +139,12 @@ class UnrealIRCdProto : public IRCDProto time_t timeleft = x->Expires - time(NULL); if (timeleft > 172800) timeleft = 172800; - send_cmd(NULL, "BD + G %s %s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL) + timeleft), static_cast<long>(x->Expires), x->Reason.c_str()); + send_cmd("", "BD + G %s %s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL) + timeleft), static_cast<long>(x->Expires), x->Reason.c_str()); } - void SendSVSKillInternal(BotInfo *source, User *user, const char *buf) + void SendSVSKillInternal(BotInfo *source, User *user, const Anope::string &buf) { - send_cmd(source ? source->nick : Config.ServerName, "h %s :%s", user->nick.c_str(), buf); + send_cmd(source ? source->nick : Config.ServerName, "h %s :%s", user->nick.c_str(), buf.c_str()); } /* @@ -175,62 +164,62 @@ class UnrealIRCdProto : public IRCDProto } } - void SendModeInternal(BotInfo *source, Channel *dest, const char *buf) + void SendModeInternal(BotInfo *source, Channel *dest, const Anope::string &buf) { - if (!buf) + if (buf.empty()) return; - send_cmd(source->nick, "G %s %s", dest->name.c_str(), buf); + send_cmd(source->nick, "G %s %s", dest->name.c_str(), buf.c_str()); } - void SendModeInternal(BotInfo *bi, User *u, const char *buf) + void SendModeInternal(BotInfo *bi, User *u, const Anope::string &buf) { - if (!buf) + if (buf.empty()) return; - send_cmd(bi ? bi->nick : Config.ServerName, "v %s %s", u->nick.c_str(), buf); + send_cmd(bi ? bi->nick : Config.ServerName, "v %s %s", u->nick.c_str(), buf.c_str()); } - void SendClientIntroduction(const std::string &nick, const std::string &user, const std::string &host, const std::string &real, const char *modes, const std::string &uid) + void SendClientIntroduction(const Anope::string &nick, const Anope::string &user, const Anope::string &host, const Anope::string &real, const Anope::string &modes, const Anope::string &) { EnforceQlinedNick(nick, Config.ServerName); - send_cmd(NULL, "& %s 1 %ld %s %s %s 0 %s %s%s :%s", nick.c_str(), static_cast<long>(time(NULL)), user.c_str(), host.c_str(), Config.ServerName, modes, host.c_str(), myIrcd->nickip ? " *" : " ", real.c_str()); + send_cmd("", "& %s 1 %ld %s %s %s 0 %s %s%s :%s", nick.c_str(), static_cast<long>(time(NULL)), user.c_str(), host.c_str(), Config.ServerName.c_str(), modes.c_str(), host.c_str(), myIrcd->nickip ? " *" : "", real.c_str()); } - void SendKickInternal(BotInfo *source, Channel *chan, User *user, const char *buf) + void SendKickInternal(BotInfo *source, Channel *chan, User *user, const Anope::string &buf) { - if (buf) - send_cmd(source->nick, "H %s %s :%s", chan->name.c_str(), user->nick.c_str(), buf); + if (!buf.empty()) + send_cmd(source->nick, "H %s %s :%s", chan->name.c_str(), user->nick.c_str(), buf.c_str()); else send_cmd(source->nick, "H %s %s", chan->name.c_str(), user->nick.c_str()); } - void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const char *buf) + void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const Anope::string &buf) { - if (!buf) + if (buf.empty()) return; - send_cmd(source->nick, "B @%s :%s", dest->name.c_str(), buf); + send_cmd(source->nick, "B @%s :%s", dest->name.c_str(), buf.c_str()); } /* SERVER name hop descript */ /* Unreal 3.2 actually sends some info about itself in the descript area */ void SendServer(Server *server) { - if (Config.Numeric) - send_cmd(NULL, "SERVER %s %d :U0-*-%s %s", server->GetName().c_str(), server->GetHops(), Config.Numeric, server->GetDescription().c_str()); + if (!Config.Numeric.empty()) + send_cmd("", "SERVER %s %d :U0-*-%s %s", server->GetName().c_str(), server->GetHops(), Config.Numeric.c_str(), server->GetDescription().c_str()); else - send_cmd(NULL, "SERVER %s %d :%s", server->GetName().c_str(), server->GetHops(), server->GetDescription().c_str()); + send_cmd("", "SERVER %s %d :%s", server->GetName().c_str(), server->GetHops(), server->GetDescription().c_str()); } /* JOIN */ - void SendJoin(BotInfo *user, const char *channel, time_t chantime) + void SendJoin(BotInfo *user, const Anope::string &channel, time_t chantime) { - send_cmd(Config.ServerName, "~ !%s %s :%s", base64enc(static_cast<long>(chantime)), channel, user->nick.c_str()); + send_cmd(Config.ServerName, "~ %ld %s :%s", static_cast<long>(chantime), channel.c_str(), user->nick.c_str()); } /* unsqline */ void SendSQLineDel(XLine *x) { - send_cmd(NULL, "d %s", x->Mask.c_str()); + send_cmd("", "d %s", x->Mask.c_str()); } /* SQLINE */ @@ -240,7 +229,7 @@ class UnrealIRCdProto : public IRCDProto */ void SendSQLine(XLine *x) { - send_cmd(NULL, "c %s :%s", x->Mask.c_str(), x->Reason.c_str()); + send_cmd("", "c %s :%s", x->Mask.c_str(), x->Reason.c_str()); } /* @@ -249,29 +238,29 @@ class UnrealIRCdProto : public IRCDProto ** parv[1] = nick ** parv[2] = options */ - void SendSVSO(const char *source, const char *nick, const char *flag) + void SendSVSO(const Anope::string &source, const Anope::string &nick, const Anope::string &flag) { - if (!source || !nick || !flag) + if (source.empty() || nick.empty() || flag.empty()) return; - send_cmd(source, "BB %s %s", nick, flag); + send_cmd(source, "BB %s %s", nick.c_str(), flag.c_str()); } /* NICK <newnick> */ - void SendChangeBotNick(BotInfo *oldnick, const char *newnick) + void SendChangeBotNick(BotInfo *oldnick, const Anope::string &newnick) { - if (!oldnick || !newnick) + if (!oldnick || newnick.empty()) return; - send_cmd(oldnick->nick, "& %s %ld", newnick, static_cast<long>(time(NULL))); + send_cmd(oldnick->nick, "& %s %ld", newnick.c_str(), static_cast<long>(time(NULL))); } /* Functions that use serval cmd functions */ - void SendVhost(User *u, const std::string &vIdent, const std::string &vhost) + void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) { if (!vIdent.empty()) - unreal_cmd_chgident(u->nick.c_str(), vIdent.c_str()); + unreal_cmd_chgident(u->nick, vIdent); if (!vhost.empty()) - unreal_cmd_chghost(u->nick.c_str(), vhost.c_str()); + unreal_cmd_chghost(u->nick, vhost); } void SendConnect() @@ -282,15 +271,15 @@ class UnrealIRCdProto : public IRCDProto } /* SVSHOLD - set */ - void SendSVSHold(const char *nick) + void SendSVSHold(const Anope::string &nick) { - send_cmd(NULL, "BD + Q H %s %s %ld %ld :%s", nick, Config.ServerName, static_cast<long>(time(NULL) + Config.NSReleaseTimeout), static_cast<long>(time(NULL)), "Being held for registered user"); + send_cmd("", "BD + Q H %s %s %ld %ld :Being held for registered user", nick.c_str(), Config.ServerName.c_str(), static_cast<long>(time(NULL) + Config.NSReleaseTimeout), static_cast<long>(time(NULL))); } /* SVSHOLD - release */ - void SendSVSHoldDel(const char *nick) + void SendSVSHoldDel(const Anope::string &nick) { - send_cmd(NULL, "BD - Q * %s %s", nick, Config.ServerName); + send_cmd("", "BD - Q * %s %s", nick.c_str(), Config.ServerName.c_str()); } /* UNSGLINE */ @@ -299,19 +288,19 @@ class UnrealIRCdProto : public IRCDProto */ void SendSGLineDel(XLine *x) { - send_cmd(NULL, "BR - :%s", x->Mask.c_str()); + send_cmd("", "BR - :%s", x->Mask.c_str()); } /* UNSZLINE */ void SendSZLineDel(XLine *x) { - send_cmd(NULL, "BD - Z * %s %s", x->Mask.c_str(), Config.s_OperServ); + send_cmd("", "BD - Z * %s %s", x->Mask.c_str(), Config.s_OperServ.c_str()); } /* SZLINE */ void SendSZLine(XLine *x) { - send_cmd(NULL, "BD + Z * %s %s %ld %ld :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(time(NULL) + 172800), static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd("", "BD + Z * %s %s %ld %ld :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(time(NULL) + 172800), static_cast<long>(time(NULL)), x->Reason.c_str()); } /* SGLINE */ @@ -320,26 +309,25 @@ class UnrealIRCdProto : public IRCDProto */ void SendSGLine(XLine *x) { - char edited_reason[BUFSIZE]; - strlcpy(edited_reason, x->Reason.c_str(), BUFSIZE); - strnrepl(edited_reason, BUFSIZE, " ", "_"); - send_cmd(NULL, "BR + %s :%s", edited_reason, x->Mask.c_str()); + Anope::string edited_reason = x->Reason; + edited_reason = edited_reason.replace_all_cs(" ", "_"); + send_cmd("", "BR + %s :%s", edited_reason.c_str(), x->Mask.c_str()); } /* SVSMODE -b */ - void SendBanDel(Channel *c, const std::string &nick) + void SendBanDel(Channel *c, const Anope::string &nick) { - SendSVSModeChan(c, "-b", nick.empty() ? NULL : nick.c_str()); + SendSVSModeChan(c, "-b", nick); } /* SVSMODE channel modes */ - void SendSVSModeChan(Channel *c, const char *mode, const char *nick) + void SendSVSModeChan(Channel *c, const Anope::string &mode, const Anope::string &nick) { - if (nick) - send_cmd(Config.ServerName, "n %s %s %s", c->name.c_str(), mode, nick); + if (!nick.empty()) + send_cmd(Config.ServerName, "n %s %s %s", c->name.c_str(), mode.c_str(), nick.c_str()); else - send_cmd(Config.ServerName, "n %s %s", c->name.c_str(), mode); + send_cmd(Config.ServerName, "n %s %s", c->name.c_str(), mode.c_str()); } /* svsjoin @@ -351,12 +339,12 @@ class UnrealIRCdProto : public IRCDProto /* In older Unreal SVSJOIN and SVSNLINE tokens were mixed so SVSJOIN and SVSNLINE are broken when coming from a none TOKEN'd server */ - void SendSVSJoin(const char *source, const char *nick, const char *chan, const char *param) + void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string ¶m) { - if (param) - send_cmd(source, "BX %s %s :%s", nick, chan, param); + if (!param.empty()) + send_cmd(source, "BX %s %s :%s", nick.c_str(), chan.c_str(), param.c_str()); else - send_cmd(source, "BX %s :%s", nick, chan); + send_cmd(source, "BX %s :%s", nick.c_str(), chan.c_str()); } /* svspart @@ -364,14 +352,14 @@ class UnrealIRCdProto : public IRCDProto parv[1] - nick to make part parv[2] - channel(s) to part */ - void SendSVSPart(const char *source, const char *nick, const char *chan) + void SendSVSPart(const Anope::string &source, const Anope::string &nick, const Anope::string &chan) { - send_cmd(source, "BT %s :%s", nick, chan); + send_cmd(source, "BT %s :%s", nick.c_str(), chan.c_str()); } - void SendSWhois(const char *source, const char *who, const char *mask) + void SendSWhois(const Anope::string &source, const Anope::string &who, const Anope::string &mask) { - send_cmd(source, "BA %s :%s", who, mask); + send_cmd(source, "BA %s :%s", who.c_str(), mask.c_str()); } void SendEOB() @@ -379,40 +367,37 @@ class UnrealIRCdProto : public IRCDProto send_cmd(Config.ServerName, "ES"); } - /* - 1 = valid nick - 0 = nick is in valid - */ - int IsNickValid(const char *nick) + bool IsNickValid(const Anope::string &nick) { - if (!stricmp("ircd", nick) || !stricmp("irc", nick)) - return 0; - return 1; + if (nick.equals_ci("ircd") || nick.equals_ci("irc")) + return false; + + return true; } - int IsChannelValid(const char *chan) + bool IsChannelValid(const Anope::string &chan) { - if (strchr(chan, ':') || *chan != '#') - return 0; - return 1; + if (chan.find(':') != Anope::string::npos || chan[0] != '#') + return false; + + return true; } void SetAutoIdentificationToken(User *u) { - char svidbuf[15]; if (!u->Account()) return; srand(time(NULL)); - snprintf(svidbuf, sizeof(svidbuf), "%d", rand()); + Anope::string svidbuf = stringify(rand()); u->Account()->Shrink("authenticationtoken"); - u->Account()->Extend("authenticationtoken", new ExtensibleItemPointerArray<char>(sstrdup(svidbuf))); + u->Account()->Extend("authenticationtoken", new ExtensibleItemRegular<Anope::string>(svidbuf)); BotInfo *bi = NickServ; u->SetMode(bi, UMODE_REGISTERED); - ircdproto->SendMode(bi, u, "+d %s", svidbuf); + ircdproto->SendMode(bi, u, "+d %s", svidbuf.c_str()); } void SendUnregisteredNick(User *u) @@ -424,20 +409,20 @@ class UnrealIRCdProto : public IRCDProto } ircd_proto; /* Event: PROTOCTL */ -int anope_event_capab(const char *source, int ac, const char **av) +int anope_event_capab(const Anope::string &source, int ac, const char **av) { for (int i = 0; i < ac; ++i) { - std::string capab = av[i]; + Anope::string capab = av[i]; - if (capab.find("CHANMODES") != std::string::npos) + if (capab.find("CHANMODES") != Anope::string::npos) { - std::string modes(capab.begin() + 10, capab.end()); + Anope::string modes(capab.begin() + 10, capab.end()); commasepstream sep(modes); - std::string modebuf; + Anope::string modebuf; sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -456,7 +441,7 @@ int anope_event_capab(const char *source, int ac, const char **av) } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -475,7 +460,7 @@ int anope_event_capab(const char *source, int ac, const char **av) } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -491,7 +476,7 @@ int anope_event_capab(const char *source, int ac, const char **av) } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.size(); t < end; ++t) + for (size_t t = 0, end = modebuf.length(); t < end; ++t) { switch (modebuf[t]) { @@ -574,7 +559,7 @@ int anope_event_capab(const char *source, int ac, const char **av) } /* Events */ -int anope_event_ping(const char *source, int ac, const char **av) +int anope_event_ping(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -591,7 +576,7 @@ int anope_event_ping(const char *source, int ac, const char **av) * with their server "not syncing". We now send a PING immediatly when receiving a new server * and then finish sync once we get a pong back from that server */ -int anope_event_pong(const char *source, int ac, const char **av) +int anope_event_pong(const Anope::string &source, int ac, const char **av) { Server *s = Server::Find(source); if (s && !s->IsSynced()) @@ -609,13 +594,13 @@ int anope_event_pong(const char *source, int ac, const char **av) * argv[6] = free(**) * argv[7] = ircnet */ -int anope_event_netinfo(const char *source, int ac, const char **av) +int anope_event_netinfo(const Anope::string &source, int ac, const char **av) { unreal_cmd_netinfo(ac, av); return MOD_CONT; } -int anope_event_436(const char *source, int ac, const char **av) +int anope_event_436(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; @@ -629,11 +614,11 @@ int anope_event_436(const char *source, int ac, const char **av) ** parv[0] = sender prefix ** parv[1] = away message */ -int anope_event_away(const char *source, int ac, const char **av) +int anope_event_away(const Anope::string &source, int ac, const char **av) { - if (!source) + if (source.empty()) return MOD_CONT; - m_away(source, (ac ? av[0] : NULL)); + m_away(source, ac ? av[0] : ""); return MOD_CONT; } @@ -649,7 +634,7 @@ int anope_event_away(const char *source, int ac, const char **av) ** parv[3] = topic time ** parv[4] = topic text */ -int anope_event_topic(const char *source, int ac, const char **av) +int anope_event_topic(const Anope::string &source, int ac, const char **av) { if (ac != 4) return MOD_CONT; @@ -657,7 +642,7 @@ int anope_event_topic(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_squit(const char *source, int ac, const char **av) +int anope_event_squit(const Anope::string &source, int ac, const char **av) { if (ac != 2) return MOD_CONT; @@ -665,7 +650,7 @@ int anope_event_squit(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_quit(const char *source, int ac, const char **av) +int anope_event_quit(const Anope::string &source, int ac, const char **av) { if (ac != 1) return MOD_CONT; @@ -673,7 +658,7 @@ int anope_event_quit(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_mode(const char *source, int ac, const char **av) +int anope_event_mode(const Anope::string &source, int ac, const char **av) { if (ac < 2) return MOD_CONT; @@ -686,7 +671,7 @@ int anope_event_mode(const char *source, int ac, const char **av) } /* This is used to strip the TS from the end of the mode stirng */ -int anope_event_gmode(const char *source, int ac, const char **av) +int anope_event_gmode(const Anope::string &source, int ac, const char **av) { if (Server::Find(source)) --ac; @@ -699,19 +684,19 @@ int anope_event_gmode(const char *source, int ac, const char **av) parv[0] - sender parv[1] - modes to change */ -int anope_event_umode2(const char *source, int ac, const char **av) +int anope_event_umode2(const Anope::string &source, int ac, const char **av) { if (ac < 1) return MOD_CONT; const char *newav[4]; - newav[0] = source; + newav[0] = source.c_str(); newav[1] = av[0]; do_umode(source, ac, newav); return MOD_CONT; } -int anope_event_kill(const char *source, int ac, const char **av) +int anope_event_kill(const Anope::string &source, int ac, const char **av) { if (ac != 2) return MOD_CONT; @@ -720,7 +705,7 @@ int anope_event_kill(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_kick(const char *source, int ac, const char **av) +int anope_event_kick(const Anope::string &source, int ac, const char **av) { if (ac != 3) return MOD_CONT; @@ -728,7 +713,7 @@ int anope_event_kick(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_join(const char *source, int ac, const char **av) +int anope_event_join(const Anope::string &source, int ac, const char **av) { if (ac != 1) return MOD_CONT; @@ -736,16 +721,16 @@ int anope_event_join(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_motd(const char *source, int ac, const char **av) +int anope_event_motd(const Anope::string &source, int ac, const char **av) { - if (!source) + if (source.empty()) return MOD_CONT; m_motd(source); return MOD_CONT; } -int anope_event_setname(const char *source, int ac, const char **av) +int anope_event_setname(const Anope::string &source, int ac, const char **av) { User *u; @@ -763,7 +748,7 @@ int anope_event_setname(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_chgname(const char *source, int ac, const char **av) +int anope_event_chgname(const Anope::string &source, int ac, const char **av) { User *u; @@ -781,7 +766,7 @@ int anope_event_chgname(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_setident(const char *source, int ac, const char **av) +int anope_event_setident(const Anope::string &source, int ac, const char **av) { User *u; @@ -798,7 +783,8 @@ int anope_event_setident(const char *source, int ac, const char **av) u->SetVIdent(av[0]); return MOD_CONT; } -int anope_event_chgident(const char *source, int ac, const char **av) + +int anope_event_chgident(const Anope::string &source, int ac, const char **av) { User *u; @@ -816,7 +802,7 @@ int anope_event_chgident(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_sethost(const char *source, int ac, const char **av) +int anope_event_sethost(const Anope::string &source, int ac, const char **av) { User *u; @@ -870,7 +856,7 @@ int anope_event_sethost(const char *source, int ac, const char **av) char *server, char *realname, time_t ts, uint32 ip, char *vhost, char *uid) */ -int anope_event_nick(const char *source, int ac, const char **av) +int anope_event_nick(const Anope::string &source, int ac, const char **av) { User *user; @@ -884,11 +870,11 @@ int anope_event_nick(const char *source, int ac, const char **av) <codemastr> it's sent when a nick collision occurs - so we have to leave it around for now -TSL */ - do_nick(source, av[0], av[3], av[4], av[5], av[6], strtoul(av[2], NULL, 10), 0, "*", NULL); + do_nick(source, av[0], av[3], av[4], av[5], av[6], Anope::string(av[2]).is_number_only() ? convertTo<time_t>(av[2]) : 0, 0, "*", ""); } else if (ac == 11) { - user = do_nick(source, av[0], av[3], av[4], av[5], av[10], strtoul(av[2], NULL, 10), ntohl(decode_ip(av[9])), av[8], NULL); + user = do_nick(source, av[0], av[3], av[4], av[5], av[10], Anope::string(av[2]).is_number_only() ? convertTo<time_t>(av[2]) : 0, ntohl(decode_ip(av[9])), av[8], ""); if (user) { /* Check to see if the user should be identified because their @@ -902,7 +888,7 @@ int anope_event_nick(const char *source, int ac, const char **av) else { /* NON NICKIP */ - user = do_nick(source, av[0], av[3], av[4], av[5], av[9], strtoul(av[2], NULL, 10), 0, av[8], NULL); + user = do_nick(source, av[0], av[3], av[4], av[5], av[9], Anope::string(av[2]).is_number_only() ? convertTo<time_t>(av[2]) : 0, 0, av[8], ""); if (user) { /* Check to see if the user should be identified because their @@ -915,11 +901,11 @@ int anope_event_nick(const char *source, int ac, const char **av) } } else - do_nick(source, av[0], NULL, NULL, NULL, NULL, strtoul(av[1], NULL, 10), 0, NULL, NULL); + do_nick(source, av[0], "", "", "", "", Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0, 0, "", ""); return MOD_CONT; } -int anope_event_chghost(const char *source, int ac, const char **av) +int anope_event_chghost(const Anope::string &source, int ac, const char **av) { User *u; @@ -938,30 +924,23 @@ int anope_event_chghost(const char *source, int ac, const char **av) } /* EVENT: SERVER */ -int anope_event_server(const char *source, int ac, const char **av) +int anope_event_server(const Anope::string &source, int ac, const char **av) { - char *desc; - char *vl; - char *upnumeric; - if (!stricmp(av[1], "1")) { - vl = myStrGetToken(av[2], ' ', 0); - upnumeric = myStrGetToken(vl, '-', 2); - desc = myStrGetTokenRemainder(av[2], ' ', 1); - do_server(source, av[0], atoi(av[1]), desc, upnumeric); - delete [] vl; - delete [] desc; - delete [] upnumeric; + Anope::string vl = myStrGetToken(av[2], ' ', 0); + Anope::string upnumeric = myStrGetToken(vl, '-', 2); + Anope::string desc = myStrGetTokenRemainder(av[2], ' ', 1); + do_server(source, av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, desc, upnumeric); } else - do_server(source, av[0], atoi(av[1]), av[2], ""); + do_server(source, av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, av[2], ""); ircdproto->SendPing(Config.ServerName, av[0]); return MOD_CONT; } -int anope_event_privmsg(const char *source, int ac, const char **av) +int anope_event_privmsg(const Anope::string &source, int ac, const char **av) { if (ac != 2) return MOD_CONT; @@ -969,7 +948,7 @@ int anope_event_privmsg(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_part(const char *source, int ac, const char **av) +int anope_event_part(const Anope::string &source, int ac, const char **av) { if (ac < 1 || ac > 2) return MOD_CONT; @@ -977,14 +956,14 @@ int anope_event_part(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_whois(const char *source, int ac, const char **av) +int anope_event_whois(const Anope::string &source, int ac, const char **av) { - if (source && ac >= 1) + if (!source.empty() && ac >= 1) m_whois(source, av[0]); return MOD_CONT; } -int anope_event_error(const char *source, int ac, const char **av) +int anope_event_error(const Anope::string &source, int ac, const char **av) { if (av[0]) { @@ -993,12 +972,11 @@ int anope_event_error(const char *source, int ac, const char **av) Alog() << "Error: Your IRCD's link block may not be setup correctly, please check unrealircd.conf"; } return MOD_CONT; - } -int anope_event_sdesc(const char *source, int ac, const char **av) +int anope_event_sdesc(const Anope::string &source, int ac, const char **av) { - Server *s = Server::Find(source ? source : ""); + Server *s = Server::Find(source); if (s) s->SetDescription(av[0]); @@ -1006,10 +984,10 @@ int anope_event_sdesc(const char *source, int ac, const char **av) return MOD_CONT; } -int anope_event_sjoin(const char *source, int ac, const char **av) +int anope_event_sjoin(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[1]); - time_t ts = base64dects(av[0]); + time_t ts = Anope::string(av[0]).is_number_only() ? convertTo<time_t>(av[0]) : 0; bool keep_their_modes = true; bool was_created = false; @@ -1067,7 +1045,7 @@ int anope_event_sjoin(const char *source, int ac, const char **av) } spacesepstream sep(av[ac - 1]); - std::string buf; + Anope::string buf; while (sep.GetToken(buf)) { /* Ban */ @@ -1075,8 +1053,9 @@ int anope_event_sjoin(const char *source, int ac, const char **av) { buf.erase(buf.begin()); ChannelModeList *cml = dynamic_cast<ChannelModeList *>(ModeManager::FindChannelModeByName(CMODE_BAN)); + if (cml->IsValid(buf)) - cml->AddMask(c, buf.c_str()); + cml->AddMask(c, buf); } /* Except */ else if (keep_their_modes && buf[0] == '"') @@ -1085,7 +1064,7 @@ int anope_event_sjoin(const char *source, int ac, const char **av) ChannelModeList *cml = dynamic_cast<ChannelModeList *>(ModeManager::FindChannelModeByName(CMODE_EXCEPT)); if (cml->IsValid(buf)) - cml->AddMask(c, buf.c_str()); + cml->AddMask(c, buf); } /* Invex */ else if (keep_their_modes && buf[0] == '\'') @@ -1094,12 +1073,11 @@ int anope_event_sjoin(const char *source, int ac, const char **av) ChannelModeList *cml = dynamic_cast<ChannelModeList *>(ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE)); if (cml->IsValid(buf)) - cml->AddMask(c, buf.c_str()); + cml->AddMask(c, buf); } else { std::list<ChannelMode *> Status; - Status.clear(); char ch; /* Get prefixes from the nick */ @@ -1192,7 +1170,7 @@ void moduleAddIRCDMsgs() Anope::AddMessage("PRIVMSG", anope_event_privmsg); Anope::AddMessage("!", anope_event_privmsg); Anope::AddMessage("QUIT", anope_event_quit); - Anope::AddMessage(",", anope_event_quit); + Anope::AddMessage("),", anope_event_quit); Anope::AddMessage("SERVER", anope_event_server); Anope::AddMessage("'", anope_event_server); Anope::AddMessage("SQUIT", anope_event_squit); @@ -1237,41 +1215,37 @@ void moduleAddIRCDMsgs() } /* Borrowed part of this check from UnrealIRCd */ -bool ChannelModeFlood::IsValid(const std::string &value2) +bool ChannelModeFlood::IsValid(const Anope::string &value) { - const char *value = value2.c_str(); - char *dp, *end; - /* NEW +F */ - char xbuf[256], *p, *p2, *x = xbuf + 1; - int v; - if (!value) - return 0; - if (*value != ':' && strtoul((*value == '*' ? value + 1 : value), &dp, 10) > 0 && *dp == ':' && *(++dp) && strtoul(dp, &end, 10) > 0 && !*end) - return 1; + if (value.empty()) + return false; + Anope::string rest; + if (value[0] != ':' && convertTo<unsigned>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<unsigned>(rest.substr(1), rest, false) > 0 && rest.empty()) + return true; else { /* '['<number><1 letter>[optional: '#'+1 letter],[next..]']'':'<number> */ - strlcpy(xbuf, value, sizeof(xbuf)); - p2 = strchr(xbuf + 1, ']'); - if (!p2) return 0; - *p2 = '\0'; - if (*(p2 + 1) != ':') - return 0; - for (x = strtok(xbuf + 1, ","); x; x = strtok(NULL, ",")) + size_t end_bracket = value.find(']', 1); + if (end_bracket == Anope::string::npos) + return false; + Anope::string xbuf = value.substr(0, end_bracket); + if (value[end_bracket + 1] != ':') + return false; + commasepstream args(xbuf.substr(1)); + Anope::string arg; + while (args.GetToken(arg)) { /* <number><1 letter>[optional: '#'+1 letter] */ - p = x; - while (isdigit(*p)) + size_t p = 0; + while (p < arg.length() && isdigit(arg[p])) ++p; - if (!*p || !(*p == 'c' || *p == 'j' || *p == 'k' || *p == 'm' || *p == 'n' || *p == 't')) + if (p == arg.length() || !(arg[p] == 'c' || arg[p] == 'j' || arg[p] == 'k' || arg[p] == 'm' || arg[p] == 'n' || arg[p] == 't')) continue; /* continue instead of break for forward compatability. */ - *p = '\0'; - v = atoi(x); + int v = arg.substr(0, p).is_number_only() ? convertTo<int>(arg.substr(0, p)) : 0; if (v < 1 || v > 999) - return 0; - ++p; + return false; } - return 1; + return true; } } @@ -1282,7 +1256,7 @@ static void AddModes() ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OP, "CMODE_OP", 'o', '@')); /* Unreal sends +q as * and +a as ~ */ ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_PROTECT, "CMODE_PROTECT", 'a', '~')); - ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OWNER, "CMODE_OWNER", 'q', '*')); /* Unreal sends +q as * */ + ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OWNER, "CMODE_OWNER", 'q', '*')); /* Add user modes */ ModeManager::AddUserMode(new UserMode(UMODE_SERV_ADMIN, "UMODE_SERV_ADMIN", 'A')); @@ -1315,7 +1289,7 @@ static void AddModes() class ProtoUnreal : public Module { public: - ProtoUnreal(const std::string &modname, const std::string &creator) : Module(modname, creator) + ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(PROTOCOL); @@ -1324,7 +1298,7 @@ class ProtoUnreal : public Module pmodule_ircd_var(myIrcd); pmodule_ircd_useTSMode(0); - CapabType c[] = { CAPAB_NOQUIT, CAPAB_NICKIP, CAPAB_ZIP, CAPAB_TOKEN, CAPAB_SSJ3, CAPAB_NICK2, CAPAB_VL, CAPAB_TLKEXT, CAPAB_CHANMODE, CAPAB_SJB64, CAPAB_NICKCHARS }; + CapabType c[] = { CAPAB_NOQUIT, CAPAB_NICKIP, CAPAB_ZIP, CAPAB_TOKEN, CAPAB_SSJ3, CAPAB_NICK2, CAPAB_VL, CAPAB_TLKEXT, CAPAB_CHANMODE, CAPAB_NICKCHARS }; for (unsigned i = 0; i < 11; ++i) Capab.SetFlag(c[i]); @@ -1336,7 +1310,7 @@ class ProtoUnreal : public Module ModuleManager::Attach(I_OnUserNickChange, this); } - void OnUserNickChange(User *u, const std::string &) + void OnUserNickChange(User *u, const Anope::string &) { u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED)); } diff --git a/modules/socketengines/m_socketengine_epoll.cpp b/modules/socketengines/m_socketengine_epoll.cpp index c5e152af3..b65656554 100644 --- a/modules/socketengines/m_socketengine_epoll.cpp +++ b/modules/socketengines/m_socketengine_epoll.cpp @@ -17,7 +17,7 @@ class SocketEngineEPoll : public SocketEngineBase { SocketCount = 0; max = ulimit(4, 0); - + if (max <= 0) { Alog() << "Can't determine maximum number of open sockets"; @@ -29,7 +29,7 @@ class SocketEngineEPoll : public SocketEngineBase if (EngineHandle == -1) { Alog() << "Could not initialize epoll socket engine: " << strerror(errno); - throw ModuleException("Could not initialize epoll socket engine: " + std::string(strerror(errno))); + throw ModuleException(Anope::string("Could not initialize epoll socket engine: ") + strerror(errno)); } events = new epoll_event[max]; @@ -44,7 +44,7 @@ class SocketEngineEPoll : public SocketEngineBase void AddSocket(Socket *s) { epoll_event ev; - + memset(&ev, 0, sizeof(ev)); ev.events = EPOLLIN | EPOLLOUT; @@ -82,7 +82,7 @@ class SocketEngineEPoll : public SocketEngineBase void Process() { - int total = epoll_wait(EngineHandle, events, max - 1, (Config.ReadTimeout * 1000)); + int total = epoll_wait(EngineHandle, events, max - 1, Config.ReadTimeout * 1000); if (total == -1) { @@ -102,32 +102,20 @@ class SocketEngineEPoll : public SocketEngineBase continue; } - if (ev->events & EPOLLIN) - { - if (!s->ProcessRead()) - { - s->SetFlag(SF_DEAD); - } - } + if ((ev->events & EPOLLIN) && !s->ProcessRead()) + s->SetFlag(SF_DEAD); - if (ev->events & EPOLLOUT) - { - if (!s->ProcessWrite()) - { - s->SetFlag(SF_DEAD); - } - } + if ((ev->events & EPOLLOUT) && !s->ProcessWrite()) + s->SetFlag(SF_DEAD); } - for (std::map<int, Socket *>::iterator it = Sockets.begin(), it_end = Sockets.end(); it != it_end;) + for (std::map<int, Socket *>::iterator it = Sockets.begin(), it_end = Sockets.end(); it != it_end; ) { Socket *s = it->second; ++it; if (s->HasFlag(SF_DEAD)) - { delete s; - } } } }; @@ -137,8 +125,9 @@ class ModuleSocketEngineEPoll : public Module SocketEngineEPoll *engine; public: - ModuleSocketEngineEPoll(const std::string &modname, const std::string &creator) : Module(modname, creator) + ModuleSocketEngineEPoll(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { + this->SetAuthor("Anope"); this->SetPermanent(true); this->SetType(SOCKETENGINE); @@ -154,4 +143,3 @@ class ModuleSocketEngineEPoll : public Module }; MODULE_INIT(ModuleSocketEngineEPoll) - diff --git a/modules/socketengines/m_socketengine_select.cpp b/modules/socketengines/m_socketengine_select.cpp index c7346f87c..e713915a3 100644 --- a/modules/socketengines/m_socketengine_select.cpp +++ b/modules/socketengines/m_socketengine_select.cpp @@ -79,31 +79,19 @@ class SocketEngineSelect : public SocketEngineBase s->SetFlag(SF_DEAD); continue; } - if (FD_ISSET(s->GetSock(), &rfdset)) - { - if (!s->ProcessRead()) - { - s->SetFlag(SF_DEAD); - } - } - if (FD_ISSET(s->GetSock(), &wfdset)) - { - if (!s->ProcessWrite()) - { - s->SetFlag(SF_DEAD); - } - } + if (FD_ISSET(s->GetSock(), &rfdset) && !s->ProcessRead()) + s->SetFlag(SF_DEAD); + if (FD_ISSET(s->GetSock(), &wfdset) && !s->ProcessWrite()) + s->SetFlag(SF_DEAD); } - for (std::map<int, Socket *>::iterator it = Sockets.begin(), it_end = Sockets.end(); it != it_end;) + for (std::map<int, Socket *>::iterator it = Sockets.begin(), it_end = Sockets.end(); it != it_end; ) { Socket *s = it->second; ++it; if (s->HasFlag(SF_DEAD)) - { delete s; - } } } } @@ -114,8 +102,9 @@ class ModuleSocketEngineSelect : public Module SocketEngineSelect *engine; public: - ModuleSocketEngineSelect(const std::string &modname, const std::string &creator) : Module(modname, creator) + ModuleSocketEngineSelect(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { + this->SetAuthor("Anope"); this->SetPermanent(true); this->SetType(SOCKETENGINE); @@ -131,4 +120,3 @@ class ModuleSocketEngineSelect : public Module }; MODULE_INIT(ModuleSocketEngineSelect) - diff --git a/src/actions.cpp b/src/actions.cpp index bff5b36fa..17c0a2898 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -48,18 +48,16 @@ bool bad_password(User *u) * @param reason for the kill * @return void */ -void kill_user(const std::string &source, const std::string &user, const std::string &reason) +void kill_user(const Anope::string &source, const Anope::string &user, const Anope::string &reason) { - char buf[BUFSIZE]; - if (user.empty()) return; - std::string real_source = source.empty() ? Config.ServerName : source; + Anope::string real_source = source.empty() ? Config.ServerName : source; - snprintf(buf, sizeof(buf), "%s (%s)", source.c_str(), reason.c_str()); + Anope::string buf = real_source + " (" + reason + ")"; - ircdproto->SendSVSKill(findbot(source), finduser(user), buf); + ircdproto->SendSVSKill(findbot(source), finduser(user), "%s", buf.c_str()); if (!ircd->quitonkill && finduser(user)) do_kill(user, buf); @@ -73,9 +71,9 @@ void kill_user(const std::string &source, const std::string &user, const std::st * @param nick to remove the ban for * @return void */ -void common_unban(ChannelInfo *ci, const std::string &nick) +void common_unban(ChannelInfo *ci, const Anope::string &nick) { - char *host = NULL; + Anope::string host; uint32 ip = 0; User *u; Entry *ban, *next; @@ -89,18 +87,18 @@ void common_unban(ChannelInfo *ci, const std::string &nick) if (!ci->c->bans || !ci->c->bans->count) return; - if (!u->hostip) + if (u->hostip.empty()) { host = host_resolve(u->host); /* we store the just resolved hostname so we don't * need to do this again */ - if (host) - u->hostip = sstrdup(host); + if (!host.empty()) + u->hostip = host; } else - host = sstrdup(u->hostip); + host = u->hostip; /* Convert the host to an IP.. */ - if (host) + if (!host.empty()) ip = str_is_ip(host); if (ircd->svsmode_unban) @@ -109,12 +107,9 @@ void common_unban(ChannelInfo *ci, const std::string &nick) for (ban = ci->c->bans->entries; ban; ban = next) { next = ban->next; - if (entry_match(ban, u->nick.c_str(), u->GetIdent().c_str(), u->host, ip) || entry_match(ban, u->nick.c_str(), u->GetIdent().c_str(), u->GetDisplayedHost().c_str(), ip)) + if (entry_match(ban, u->nick, u->GetIdent(), u->host, ip) || entry_match(ban, u->nick, u->GetIdent(), u->GetDisplayedHost(), ip)) ci->c->RemoveMode(NULL, CMODE_BAN, ban->mask); } - /* host_resolve() sstrdup us this info so we gotta free it */ - if (host) - delete [] host; } /*************************************************************************/ diff --git a/src/base64.cpp b/src/base64.cpp index 2071ad40a..4f51eb5e8 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -9,31 +9,9 @@ * Based on the original code of Services by Andy Church. */ -/* - This is borrowed from Unreal -*/ - #include "services.h" -static char *int_to_base64(long); -static long base64_to_int(const char *); - -const char *base64enc(long i) -{ - if (i < 0) - return "0"; - return int_to_base64(i); -} - -long base64dec(const char *b64) -{ - if (b64) - return base64_to_int(b64); - else - return 0; -} - -static const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +static const Anope::string Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char Pad64 = '='; /* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) @@ -99,223 +77,97 @@ static const char Pad64 = '='; characters followed by one "=" padding character. */ -int b64_encode(const char *src, size_t srclength, char *target, size_t targsize) +void b64_encode(const Anope::string &src, Anope::string &target) { - size_t datalength = 0; + size_t src_pos = 0, src_len = src.length(); unsigned char input[3]; - unsigned char output[4]; - size_t i; - - while (srclength > 2) - { - input[0] = *src++; - input[1] = *src++; - input[2] = *src++; - srclength -= 3; - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - output[3] = input[2] & 0x3f; + target.clear(); - if (datalength + 4 > targsize) - return -1; - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - target[datalength++] = Base64[output[2]]; - target[datalength++] = Base64[output[3]]; + while (src_len - src_pos > 2) + { + input[0] = src[src_pos++]; + input[1] = src[src_pos++]; + input[2] = src[src_pos++]; + + target += Base64[input[0] >> 2]; + target += Base64[((input[0] & 0x03) << 4) + (input[1] >> 4)]; + target += Base64[((input[1] & 0x0f) << 2) + (input[2] >> 6)]; + target += Base64[input[2] & 0x3f]; } - /* Now we worry about padding. */ - if (srclength) + /* Now we worry about padding */ + if (src_pos != src_len) { - /* Get what's left. */ - input[0] = input[1] = input[2] = '\0'; - for (i = 0; i < srclength; ++i) - input[i] = *src++; - - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - - if (datalength + 4 > targsize) - return -1; - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - if (srclength == 1) - target[datalength++] = Pad64; + input[0] = input[1] = input[2] = 0; + for (size_t i = 0; i < src_len - src_pos; ++i) + input[i] = src[src_pos + i]; + + target += Base64[input[0] >> 2]; + target += Base64[((input[0] & 0x03) << 4) + (input[1] >> 4)]; + if (src_pos == src_len - 1) + target += Pad64; else - target[datalength++] = Base64[output[2]]; - target[datalength++] = Pad64; + target += Base64[((input[1] & 0x0f) << 2) + (input[2] >> 6)]; + target += Pad64; } - if (datalength >= targsize) - return -1; - target[datalength] = '\0'; /* Returned value doesn't count \0. */ - return datalength; } /* skips all whitespace anywhere. converts characters, four at a time, starting at (or after) src from base - 64 numbers into three 8 bit bytes in the target area. - it returns the number of data bytes stored at the target, or -1 on error. */ -int b64_decode(const char *src, char *target, size_t targsize) +void b64_decode(const Anope::string &src, Anope::string &target) { - int tarindex, state, ch; - char *pos; + target.clear(); - state = 0; - tarindex = 0; - - while ((ch = *src++) != '\0') + unsigned state = 0; + Anope::string::const_iterator ch = src.begin(), end = src.end(); + for (; ch != end; ++ch) { - if (isspace(ch)) /* Skip whitespace anywhere. */ + if (isspace(*ch)) /* Skip whitespace anywhere */ continue; - if (ch == Pad64) + if (*ch == Pad64) break; - pos = const_cast<char *>(strchr(Base64, ch)); - if (!pos) /* A non-base64 character. */ - return -1; + size_t pos = Base64.find(*ch); + if (pos == Anope::string::npos) /* A non-base64 character */ + return; switch (state) { case 0: - if (target) - { - if (static_cast<size_t>(tarindex) >= targsize) - return -1; - target[tarindex] = (pos - Base64) << 2; - } + target += pos << 2; state = 1; break; case 1: - if (target) - { - if (static_cast<size_t>(tarindex) + 1 >= targsize) - return -1; - target[tarindex] |= (pos - Base64) >> 4; - target[tarindex + 1] = ((pos - Base64) & 0x0f) << 4; - } - ++tarindex; + target[target.length() - 1] |= pos >> 4; + target += (pos & 0x0f) << 4; state = 2; break; case 2: - if (target) - { - if (static_cast<size_t>(tarindex) + 1 >= targsize) - return -1; - target[tarindex] |= (pos - Base64) >> 2; - target[tarindex + 1] = ((pos - Base64) & 0x03) << 6; - } - ++tarindex; + target[target.length() - 1] |= pos >> 2; + target += (pos & 0x03) << 6; state = 3; break; case 3: - if (target) - { - if (static_cast<size_t>(tarindex) >= targsize) - return -1; - target[tarindex] |= (pos - Base64); - } - ++tarindex; + target[target.length() - 1] |= pos; state = 0; - break; - default: - abort(); } } - - /* - * We are done decoding Base-64 chars. Let's see if we ended - * on a byte boundary, and/or with erroneous trailing characters. - */ - - if (ch == Pad64) /* We got a pad char. */ - { - ch = *src++; /* Skip it, get next. */ - switch (state) - { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ - return -1; - - case 2: /* Valid, means one byte of info */ - /* Skip any number of spaces. */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - break; - /* Make sure there is another trailing = sign. */ - if (ch != Pad64) - return -1; - ch = *src++; /* Skip the = */ - /* Fall through to "single trailing =" case. */ - /* FALLTHROUGH */ - - case 3: /* Valid, means two bytes of info */ - /* - * We know this char is an =. Is there anything but - * whitespace after it? - */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - return -1; - - /* - * Now make sure for cases 2 and 3 that the "extra" - * bits that slopped past the last full byte were - * zeros. If we don't check them, they become a - * subliminal channel. - */ - if (target && target[tarindex]) - return -1; - } - } - else - { - /* - * We ended by seeing the end of the string. Make sure we - * have no partial bytes lying around. - */ - if (state) - return -1; - } - - return tarindex; + if (!target[target.length() - 1]) + target.erase(target.length() - 1); } -const char *encode_ip(unsigned char *ip) +int decode_ip(const Anope::string &buf) { - static char buf[25]; - unsigned char *cp; - struct in_addr ia; /* For IPv4 */ - char *s_ip; /* Signed ip string */ - - if (!ip) - return "*"; + int len = buf.length(); + Anope::string targ; - if (strchr(reinterpret_cast<char *>(ip), ':')) - return NULL; - else - { - s_ip = str_signed(ip); - ia.s_addr = inet_addr(s_ip); - cp = reinterpret_cast<unsigned char *>(ia.s_addr); - b64_encode(reinterpret_cast<const char *>(&cp), sizeof(struct in_addr), buf, 25); - } - return buf; -} - -int decode_ip(const char *buf) -{ - int len = strlen(buf); - char targ[25]; - struct in_addr ia; - - b64_decode(buf, targ, 25); - ia = *reinterpret_cast<struct in_addr *>(targ); + b64_decode(buf, targ); + const struct in_addr ia = *reinterpret_cast<const struct in_addr *>(targ.c_str()); if (len == 24) /* IPv6 */ return 0; else if (len == 8) /* IPv4 */ @@ -323,91 +175,3 @@ int decode_ip(const char *buf) else /* Error?? */ return 0; } - -/* ':' and '#' and '&' and '+' and '@' must never be in this table. */ -/* these tables must NEVER CHANGE! >) */ -char int6_to_base64_map[] = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', - 'E', 'F', - 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', - 'U', 'V', - 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', - 'k', 'l', - 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '{', '}' -}; - -char base64_to_int6_map[] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, - -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, - -1, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, - 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, 63, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 -}; - -static char *int_to_base64(long val) -{ - /* 32/6 == max 6 bytes for representation, - * +1 for the null, +1 for byte boundaries - */ - static char base64buf[8]; - long i = 7; - - base64buf[i] = '\0'; - - /* Temporary debugging code.. remove before 2038 ;p. - * This might happen in case of 64bit longs (opteron/ia64), - * if the value is then too large it can easily lead to - * a buffer underflow and thus to a crash. -- Syzop - */ - if (val > 2147483647L) - abort(); - - do - { - base64buf[--i] = int6_to_base64_map[val & 63]; - } while (val >>= 6); - - return base64buf + i; -} - -static long base64_to_int(const char *b64) -{ - int v = base64_to_int6_map[static_cast<const unsigned char>(*b64++)]; - - if (!b64) - return 0; - - while (*b64) - { - v <<= 6; - v += base64_to_int6_map[static_cast<const unsigned char>(*b64++)]; - } - - return v; -} - -long base64dects(const char *ts) -{ - if (!ts) - return 0; - - char *token = myStrGetToken(ts, '!', 1); - if (!token) - return strtoul(ts, NULL, 10); - - long value = base64dec(token); - delete [] token; - return value; -} diff --git a/src/bots.cpp b/src/bots.cpp index 4114d4317..88b981dcc 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -20,32 +20,31 @@ BotInfo *MemoServ = NULL; BotInfo *NickServ = NULL; BotInfo *OperServ = NULL; -BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std::string &nhost, const std::string &nreal) : User(nnick, ts6_uid_retrieve()) +BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal) : User(nnick, ts6_uid_retrieve()) { this->ident = nuser; - this->host = sstrdup(nhost.c_str()); - this->realname = sstrdup(nreal.c_str()); + this->host = nhost; + this->realname = nreal; this->server = Me; this->lastmsg = this->created = time(NULL); - ci::string ci_nick(nnick.c_str()); - if (Config.s_ChanServ && ci_nick == Config.s_ChanServ) + if (!Config.s_ChanServ.empty() && nnick.equals_ci(Config.s_ChanServ)) ChanServ = this; - else if (Config.s_BotServ && ci_nick == Config.s_BotServ) + else if (!Config.s_BotServ.empty() && nnick.equals_ci(Config.s_BotServ)) BotServ = this; - else if (Config.s_HostServ && ci_nick == Config.s_HostServ) + else if (!Config.s_HostServ.empty() && nnick.equals_ci(Config.s_HostServ)) HostServ = this; - else if (Config.s_OperServ && ci_nick == Config.s_OperServ) + else if (!Config.s_OperServ.empty() && nnick.equals_ci(Config.s_OperServ)) OperServ = this; - else if (Config.s_MemoServ && ci_nick == Config.s_MemoServ) + else if (!Config.s_MemoServ.empty() && nnick.equals_ci(Config.s_MemoServ)) MemoServ = this; - else if (Config.s_NickServ && ci_nick == Config.s_NickServ) + else if (!Config.s_NickServ.empty() && nnick.equals_ci(Config.s_NickServ)) NickServ = this; - else if (Config.s_GlobalNoticer && ci_nick == Config.s_GlobalNoticer) + else if (!Config.s_GlobalNoticer.empty() && nnick.equals_ci(Config.s_GlobalNoticer)) Global = this; - BotListByNick[this->nick.c_str()] = this; + BotListByNick[this->nick] = this; if (!this->uid.empty()) BotListByUID[this->uid] = this; @@ -53,7 +52,7 @@ BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std:: if (Me && Me->GetUplink() && Me->GetUplink()->IsSynced()) { ircdproto->SendClientIntroduction(this->nick, this->GetIdent(), this->host, this->realname, ircd->pseudoclient_mode, this->uid); - XLine x(this->nick.c_str(), "Reserved for services"); + XLine x(this->nick, "Reserved for services"); ircdproto->SendSQLine(&x); } } @@ -68,21 +67,21 @@ BotInfo::~BotInfo() ci->bi = NULL; } - BotListByNick.erase(this->nick.c_str()); + BotListByNick.erase(this->nick); if (!this->uid.empty()) BotListByUID.erase(this->uid); } -void BotInfo::SetNewNick(const std::string &newnick) +void BotInfo::SetNewNick(const Anope::string &newnick) { - UserListByNick.erase(this->nick.c_str()); - BotListByNick.erase(this->nick.c_str()); + UserListByNick.erase(this->nick); + BotListByNick.erase(this->nick); this->nick = newnick; - UserListByNick[this->nick.c_str()] = this; - BotListByNick[this->nick.c_str()] = this; + UserListByNick[this->nick] = this; + BotListByNick[this->nick] = this; } void BotInfo::RejoinAll() @@ -142,14 +141,14 @@ void BotInfo::Join(Channel *c) { next = ban->next; - if (entry_match(ban, this->nick.c_str(), this->GetIdent().c_str(), this->host, 0)) + if (entry_match(ban, this->nick, this->GetIdent(), this->host, 0)) c->RemoveMode(NULL, CMODE_BAN, ban->mask); } - std::string Limit; + Anope::string Limit; int limit = 0; - if (c->GetParam(CMODE_LIMIT, Limit)) - limit = atoi(Limit.c_str()); + if (c->GetParam(CMODE_LIMIT, Limit) && Limit.is_number_only()) + limit = convertTo<int>(Limit); /* Should we be invited? */ if (c->HasMode(CMODE_INVITE) || (limit && c->users.size() >= limit)) @@ -157,21 +156,21 @@ void BotInfo::Join(Channel *c) } } - ircdproto->SendJoin(this, c->name.c_str(), c->creation_time); + ircdproto->SendJoin(this, c->name, c->creation_time); for (std::list<ChannelModeStatus *>::iterator it = BotModes.begin(), it_end = BotModes.end(); it != it_end; ++it) c->SetMode(this, *it, this->nick, false); c->JoinUser(this); FOREACH_MOD(I_OnBotJoin, OnBotJoin(c->ci, this)); } -void BotInfo::Join(const std::string &chname) +void BotInfo::Join(const Anope::string &chname) { Channel *c = findchan(chname); return this->Join(c ? c : new Channel(chname)); } -void BotInfo::Part(Channel *c, const std::string &reason) +void BotInfo::Part(Channel *c, const Anope::string &reason) { - ircdproto->SendPart(this, c, !reason.empty() ? reason.c_str() : ""); + ircdproto->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : ""); c->DeleteUser(this); } diff --git a/src/botserv.cpp b/src/botserv.cpp index 85f559f24..ae62e7e69 100644 --- a/src/botserv.cpp +++ b/src/botserv.cpp @@ -42,12 +42,12 @@ void get_botserv_stats(long *nrec, long *memuse) { BotInfo *bi = it->second; - count++; + ++count; mem += sizeof(*bi); - mem += bi->nick.size() + 1; - mem += bi->GetIdent().size() + 1; - mem += strlen(bi->host) + 1; - mem += strlen(bi->realname) + 1; + mem += bi->nick.length() + 1; + mem += bi->GetIdent().length() + 1; + mem += bi->host.length() + 1; + mem += bi->realname.length() + 1; } *nrec = count; @@ -61,7 +61,7 @@ void get_botserv_stats(long *nrec, long *memuse) void bs_init() { - if (Config.s_BotServ) + if (!Config.s_BotServ.empty()) moduleAddBotServCmds(); } @@ -69,17 +69,17 @@ void bs_init() /* Main BotServ routine. */ -void botserv(User *u, BotInfo *bi, const std::string &buf) +void botserv(User *u, BotInfo *bi, const Anope::string &buf) { if (!u || !bi || buf.empty()) return; - if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1') + if (buf.substr(0, 6).equals_ci("\1PING ") && buf[buf.length() - 1] == '\1') { - std::string command = buf; + Anope::string command = buf; command.erase(command.begin()); command.erase(command.end()); - ircdproto->SendCTCP(bi, u->nick.c_str(), "%s", command.c_str()); + ircdproto->SendCTCP(bi, u->nick, "%s", command.c_str()); } else mod_run_cmd(bi, u, buf); @@ -91,27 +91,27 @@ void botserv(User *u, BotInfo *bi, const std::string &buf) * bot is on. */ -void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) +void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) { if (!u || !ci || !ci->c || buf.empty()) return; /* Answer to ping if needed */ - if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1') + if (buf.substr(0, 6).equals_ci("\1PING ") && buf[buf.length() - 1] == '\1') { - std::string ctcp = buf; + Anope::string ctcp = buf; ctcp.erase(ctcp.begin()); ctcp.erase(ctcp.end()); - ircdproto->SendCTCP(ci->bi, u->nick.c_str(), "%s", ctcp.c_str()); + ircdproto->SendCTCP(ci->bi, u->nick, "%s", ctcp.c_str()); } bool was_action = false; - std::string realbuf = buf; + Anope::string realbuf = buf; /* If it's a /me, cut the CTCP part because the ACTION will cause * problems with the caps or badwords kicker */ - if (realbuf.find("\1ACTION ", 0, 8) && realbuf[buf.length() - 1] == '\1') + if (!realbuf.substr(0, 8).equals_ci("\1ACTION ") && realbuf[buf.length() - 1] == '\1') { realbuf.erase(0, 8); realbuf.erase(realbuf.end()); @@ -141,7 +141,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) if (!check_access(u, ci, CA_NOKICK) && Allow) { /* Bolds kicker */ - if (ci->botflags.HasFlag(BS_KICK_BOLDS) && realbuf.find_first_of(2) != std::string::npos) + if (ci->botflags.HasFlag(BS_KICK_BOLDS) && realbuf.find(2) != Anope::string::npos) { check_ban(ci, u, TTB_BOLDS); bot_kick(ci, u, BOT_REASON_BOLD); @@ -149,7 +149,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) } /* Color kicker */ - if (ci->botflags.HasFlag(BS_KICK_COLORS) && realbuf.find_first_of(3) != std::string::npos) + if (ci->botflags.HasFlag(BS_KICK_COLORS) && realbuf.find(3) != Anope::string::npos) { check_ban(ci, u, TTB_COLORS); bot_kick(ci, u, BOT_REASON_COLOR); @@ -157,7 +157,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) } /* Reverses kicker */ - if (ci->botflags.HasFlag(BS_KICK_REVERSES) && realbuf.find_first_of(22) != std::string::npos) + if (ci->botflags.HasFlag(BS_KICK_REVERSES) && realbuf.find(22) != Anope::string::npos) { check_ban(ci, u, TTB_REVERSES); bot_kick(ci, u, BOT_REASON_REVERSE); @@ -165,7 +165,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) } /* Underlines kicker */ - if (ci->botflags.HasFlag(BS_KICK_UNDERLINES) && realbuf.find_first_of(31) != std::string::npos) + if (ci->botflags.HasFlag(BS_KICK_UNDERLINES) && realbuf.find(31) != Anope::string::npos) { check_ban(ci, u, TTB_UNDERLINES); bot_kick(ci, u, BOT_REASON_UNDERLINE); @@ -204,39 +204,32 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) bool mustkick = false; /* Normalize the buffer */ - const char *nbuf = normalizeBuffer(realbuf.c_str()); + Anope::string nbuf = normalizeBuffer(realbuf); for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i) { BadWord *bw = ci->GetBadWord(i); - if (bw->type == BW_ANY && ((Config.BSCaseSensitive && strstr(nbuf, bw->word.c_str())) || (!Config.BSCaseSensitive && stristr(nbuf, bw->word.c_str())))) + if (bw->type == BW_ANY && ((Config.BSCaseSensitive && nbuf.find(bw->word) != Anope::string::npos) || (!Config.BSCaseSensitive && nbuf.find_ci(bw->word) != Anope::string::npos))) mustkick = true; else if (bw->type == BW_SINGLE) { size_t len = bw->word.length(); - if ((Config.BSCaseSensitive && nbuf == bw->word) || (!Config.BSCaseSensitive && (!stricmp(nbuf, bw->word.c_str())))) + if ((Config.BSCaseSensitive && bw->word.equals_cs(nbuf)) || (!Config.BSCaseSensitive && bw->word.equals_ci(nbuf))) mustkick = true; - else if ((strchr(nbuf, ' ') == nbuf + len) && ((Config.BSCaseSensitive && nbuf == bw->word) || (!Config.BSCaseSensitive && (stristr(nbuf, bw->word.c_str()) == nbuf)))) + else if (nbuf.find(' ') == len && ((Config.BSCaseSensitive && bw->word.equals_cs(nbuf)) || (!Config.BSCaseSensitive && bw->word.equals_ci(nbuf)))) mustkick = true; else { - if ((strrchr(nbuf, ' ') == nbuf + strlen(nbuf) - len - 1) && ((Config.BSCaseSensitive && (strstr(nbuf, bw->word.c_str()) == nbuf + strlen(nbuf) - len)) || (!Config.BSCaseSensitive && (stristr(nbuf, bw->word.c_str()) == nbuf + strlen(nbuf) - len)))) + if (nbuf.rfind(' ') == nbuf.length() - len - 1 && ((Config.BSCaseSensitive && nbuf.find(bw->word) == nbuf.length() - len) || (!Config.BSCaseSensitive && nbuf.find_ci(bw->word) == nbuf.length() - len))) mustkick = true; else { - char *wordbuf = new char[len + 3]; + Anope::string wordbuf = " " + bw->word + " "; - wordbuf[0] = ' '; - wordbuf[len + 1] = ' '; - wordbuf[len + 2] = '\0'; - memcpy(wordbuf + 1, bw->word.c_str(), len); - - if ((Config.BSCaseSensitive && strstr(nbuf, wordbuf)) || (!Config.BSCaseSensitive && stristr(nbuf, wordbuf))) + if ((Config.BSCaseSensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!Config.BSCaseSensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) mustkick = true; - - delete [] wordbuf; } } } @@ -244,40 +237,28 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) { size_t len = bw->word.length(); - if ((Config.BSCaseSensitive && !strncmp(nbuf, bw->word.c_str(), len)) || (!Config.BSCaseSensitive && !strnicmp(nbuf, bw->word.c_str(), len))) + if ((Config.BSCaseSensitive && nbuf.substr(0, len).equals_cs(bw->word)) || (!Config.BSCaseSensitive && nbuf.substr(0, len).equals_ci(bw->word))) mustkick = true; else { - char *wordbuf = new char[len + 2]; - - memcpy(wordbuf + 1, bw->word.c_str(), len); - wordbuf[0] = ' '; - wordbuf[len + 1] = '\0'; + Anope::string wordbuf = " " + bw->word; - if ((Config.BSCaseSensitive && strstr(nbuf, wordbuf)) || (!Config.BSCaseSensitive && stristr(nbuf, wordbuf))) + if ((Config.BSCaseSensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!Config.BSCaseSensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) mustkick = true; - - delete [] wordbuf; } } else if (bw->type == BW_END) { size_t len = bw->word.length(); - if ((Config.BSCaseSensitive && !strncmp(nbuf + strlen(nbuf) - len, bw->word.c_str(), len)) || (!Config.BSCaseSensitive && !strnicmp(nbuf + strlen(nbuf) - len, bw->word.c_str(), len))) + if ((Config.BSCaseSensitive && nbuf.substr(nbuf.length() - len).equals_cs(bw->word)) || (!Config.BSCaseSensitive && nbuf.substr(nbuf.length() - len).equals_ci(bw->word))) mustkick = true; else { - char *wordbuf = new char[len + 2]; - - memcpy(wordbuf, bw->word.c_str(), len); - wordbuf[len] = ' '; - wordbuf[len + 1] = '\0'; + Anope::string wordbuf = bw->word + " "; - if ((Config.BSCaseSensitive && strstr(nbuf, wordbuf)) || (!Config.BSCaseSensitive && stristr(nbuf, wordbuf))) + if ((Config.BSCaseSensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!Config.BSCaseSensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) mustkick = true; - - delete [] wordbuf; } } @@ -289,15 +270,9 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) else bot_kick(ci, u, BOT_REASON_BADWORD, bw->word.c_str()); - /* free the normalized buffer before return (#850) */ - delete [] nbuf; - return; } } - - /* Free the normalized buffer */ - delete [] nbuf; } /* Flood kicker */ @@ -331,16 +306,15 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) if (!ud) return; - if (ud->lastline && stricmp(ud->lastline, buf.c_str())) + if (!ud->lastline.empty() && !ud->lastline.equals_ci(buf)) { - delete [] ud->lastline; - ud->lastline = sstrdup(buf.c_str()); + ud->lastline = buf; ud->times = 0; } else { - if (!ud->lastline) - ud->lastline = sstrdup(buf.c_str()); + if (ud->lastline.empty()) + ud->lastline = buf; ++ud->times; } @@ -354,41 +328,35 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) } /* return if the user is on the ignore list */ - if (get_ignore(u->nick.c_str()) != NULL) + if (get_ignore(u->nick)) return; /* Fantaisist commands */ - if (ci->botflags.HasFlag(BS_FANTASY) && buf[0] == *Config.BSFantasyCharacter && !was_action) + if (ci->botflags.HasFlag(BS_FANTASY) && buf[0] == Config.BSFantasyCharacter[0] && !was_action) { spacesepstream sep(buf); - std::string token; + Anope::string token; - if (sep.GetToken(token) && token[0] == *Config.BSFantasyCharacter) + if (sep.GetToken(token) && token[0] == Config.BSFantasyCharacter[0]) { /* Strip off the fantasy character */ token.erase(token.begin()); if (check_access(u, ci, CA_FANTASIA)) { - Command *command = FindCommand(ChanServ, token.c_str()); + Command *command = FindCommand(ChanServ, token); /* Command exists and can not be called by fantasy */ if (command && !command->HasFlag(CFLAG_DISABLE_FANTASY)) { - std::string bbuf = std::string(token); + Anope::string bbuf = token; /* Some commands don't need the channel name added.. eg !help */ if (!command->HasFlag(CFLAG_STRIP_CHANNEL)) - { - bbuf += " "; - bbuf += ci->name; - } + bbuf += " " + ci->name; if (!sep.StreamEnd()) - { - bbuf += " "; - bbuf += sep.GetRemaining(); - } + bbuf += " " + sep.GetRemaining(); chanserv(u, bbuf); } @@ -405,21 +373,11 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) /*************************************************************************/ -BotInfo *findbot(const char *nick) -{ - return findbot(ci::string(nick)); -} - -BotInfo *findbot(const std::string &nick) -{ - return findbot(ci::string(nick.c_str())); -} - -BotInfo *findbot(const ci::string &nick) +BotInfo *findbot(const Anope::string &nick) { if (isdigit(nick[0]) && ircd->ts6) { - botinfo_uid_map::const_iterator it = BotListByUID.find(nick.c_str()); + botinfo_uid_map::const_iterator it = BotListByUID.find(nick); if (it != BotListByUID.end()) return it->second; @@ -440,14 +398,13 @@ BotInfo *findbot(const ci::string &nick) static BanData *get_ban_data(Channel *c, User *u) { - char mask[BUFSIZE]; BanData *bd, *next; time_t now = time(NULL); if (!c || !u) return NULL; - snprintf(mask, sizeof(mask), "%s@%s", u->GetIdent().c_str(), u->GetDisplayedHost().c_str()); + Anope::string mask = u->GetIdent() + "@" + u->GetDisplayedHost(); for (bd = c->bd; bd; bd = next) { @@ -459,13 +416,11 @@ static BanData *get_ban_data(Channel *c, User *u) bd->prev->next = bd->next; else c->bd = bd->next; - if (bd->mask) - delete [] bd->mask; next = bd->next; delete bd; continue; } - if (!stricmp(bd->mask, mask)) + if (bd->mask.equals_ci(mask)) { bd->last_use = now; return bd; @@ -475,7 +430,7 @@ static BanData *get_ban_data(Channel *c, User *u) /* If we fall here it is that we haven't found the record */ bd = new BanData; - bd->mask = sstrdup(mask); + bd->mask = mask; bd->last_use = now; for (int x = 0; x < TTB_SIZE; ++x) bd->ttb[x] = 0; @@ -511,11 +466,9 @@ static UserData *get_user_data(Channel *c, User *u) /* Checks whether data is obsolete */ if (now - uc->ud.last_use > Config.BSKeepData) { - if (uc->ud.lastline) - delete [] uc->ud.lastline; /* We should not free and realloc, but reset to 0 instead. */ - memset(&uc->ud, 0, sizeof(UserData)); + uc->ud.Clear(); uc->ud.last_use = now; } @@ -550,11 +503,11 @@ static void check_ban(ChannelInfo *ci, User *u, int ttbtype) /* Should not use == here because bd->ttb[ttbtype] could possibly be > ci->ttb[ttbtype] * if the TTB was changed after it was not set (0) before and the user had already been * kicked a few times. Bug #1056 - Adam */ - char mask[BUFSIZE]; + Anope::string mask; bd->ttb[ttbtype] = 0; - get_idealban(ci, u, mask, sizeof(mask)); + get_idealban(ci, u, mask); if (ci->c) ci->c->SetMode(NULL, CMODE_BAN, mask); @@ -589,9 +542,9 @@ static void bot_kick(ChannelInfo *ci, User *u, int message, ...) /* Makes a simple ban and kicks the target */ -void bot_raw_ban(User *requester, ChannelInfo *ci, char *nick, const char *reason) +void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason) { - char mask[BUFSIZE]; + Anope::string mask; User *u = finduser(nick); if (!u) @@ -599,35 +552,35 @@ void bot_raw_ban(User *requester, ChannelInfo *ci, char *nick, const char *reaso if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u) { - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(ACCESS_DENIED)); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", getstring(ACCESS_DENIED)); return; } - if (ci->HasFlag(CI_PEACE) && stricmp(requester->nick.c_str(), nick) && get_access(u, ci) >= get_access(requester, ci)) + if (ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(nick) && get_access(u, ci) >= get_access(requester, ci)) return; if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && is_excepted(ci, u) == 1) { - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(BOT_EXCEPT)); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", getstring(BOT_EXCEPT)); return; } - get_idealban(ci, u, mask, sizeof(mask)); + get_idealban(ci, u, mask); ci->c->SetMode(NULL, CMODE_BAN, mask); /* Check if we need to do a signkick or not -GD */ if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !check_access(requester, ci, CA_SIGNKICK))) - ci->c->Kick(ci->bi, u, "%s (%s)", reason ? reason : ci->bi->nick.c_str(), requester->nick.c_str()); + ci->c->Kick(ci->bi, u, "%s (%s)", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str(), requester->nick.c_str()); else - ci->c->Kick(ci->bi, u, "%s", reason ? reason : ci->bi->nick.c_str()); + ci->c->Kick(ci->bi, u, "%s", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str()); } /*************************************************************************/ /* Makes a kick with a "dynamic" reason ;) */ -void bot_raw_kick(User *requester, ChannelInfo *ci, char *nick, const char *reason) +void bot_raw_kick(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason) { User *u = finduser(nick); @@ -636,24 +589,24 @@ void bot_raw_kick(User *requester, ChannelInfo *ci, char *nick, const char *reas if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u) { - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(ACCESS_DENIED)); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", getstring(ACCESS_DENIED)); return; } - if (ci->HasFlag(CI_PEACE) && stricmp(requester->nick.c_str(), nick) && get_access(u, ci) >= get_access(requester, ci)) + if (ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(nick) && get_access(u, ci) >= get_access(requester, ci)) return; if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !check_access(requester, ci, CA_SIGNKICK))) - ci->c->Kick(ci->bi, u, "%s (%s)", reason ? reason : ci->bi->nick.c_str(), requester->nick.c_str()); + ci->c->Kick(ci->bi, u, "%s (%s)", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str(), requester->nick.c_str()); else - ci->c->Kick(ci->bi, u, "%s", reason ? reason : ci->bi->nick.c_str()); + ci->c->Kick(ci->bi, u, "%s", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str()); } /*************************************************************************/ /* Makes a mode operation on a channel for a nick */ -void bot_raw_mode(User *requester, ChannelInfo *ci, const char *mode, char *nick) +void bot_raw_mode(User *requester, ChannelInfo *ci, const Anope::string &mode, const Anope::string &nick) { char buf[BUFSIZE] = ""; User *u; @@ -665,16 +618,16 @@ void bot_raw_mode(User *requester, ChannelInfo *ci, const char *mode, char *nick snprintf(buf, BUFSIZE - 1, "%ld", static_cast<long>(time(NULL))); - if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && *mode == '-' && requester != u) + if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && mode[0] == '-' && requester != u) { - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(ACCESS_DENIED)); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", getstring(ACCESS_DENIED)); return; } - if (*mode == '-' && ci->HasFlag(CI_PEACE) && stricmp(requester->nick.c_str(), nick) && get_access(u, ci) >= get_access(requester, ci)) + if (mode[0] == '-' && ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(nick) && get_access(u, ci) >= get_access(requester, ci)) return; - ci->c->SetModes(NULL, "%s %s", mode, nick); + ci->c->SetModes(NULL, "%s %s", mode.c_str(), nick.c_str()); } /*************************************************************************/ @@ -683,15 +636,11 @@ void bot_raw_mode(User *requester, ChannelInfo *ci, const char *mode, char *nick * @param A string to be parsed for control and color codes * @return A string stripped of control and color codes */ -char *normalizeBuffer(const char *buf) +Anope::string normalizeBuffer(const Anope::string &buf) { - char *newbuf; - int i, len, j = 0; + Anope::string newbuf; - len = strlen(buf); - newbuf = new char[len + 1]; - - for (i = 0; i < len; ++i) + for (unsigned i = 0, end = buf.length(); i < end; ++i) { switch (buf[i]) { @@ -748,13 +697,9 @@ char *normalizeBuffer(const char *buf) break; /* A valid char gets copied into the new buffer */ default: - newbuf[j] = buf[i]; - ++j; + newbuf += buf[i]; } } - /* Terminate the string */ - newbuf[j] = 0; - return newbuf; } diff --git a/src/channels.cpp b/src/channels.cpp index e58655f58..862dfe152 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -19,17 +19,16 @@ channel_map ChannelList; * @param name The channel name * @param ts The time the channel was created */ -Channel::Channel(const std::string &name, time_t ts) +Channel::Channel(const Anope::string &name, time_t ts) { if (name.empty()) throw CoreException("A channel without a name ?"); this->name = name; - ChannelList[this->name.c_str()] = this; + ChannelList[this->name] = this; this->creation_time = ts; - this->topic = NULL; this->bans = this->excepts = this->invites = NULL; this->bd = NULL; this->server_modetime = this->chanserv_modetime = 0; @@ -54,8 +53,6 @@ Channel::~Channel() for (bd = this->bd; bd; bd = next) { - if (bd->mask) - delete [] bd->mask; next = bd->next; delete bd; } @@ -63,9 +60,6 @@ Channel::~Channel() if (this->ci) this->ci->c = NULL; - if (this->topic) - delete [] this->topic; - if (this->bans && this->bans->count) while (this->bans->entries) entry_delete(this->bans, this->bans->entries); @@ -78,7 +72,7 @@ Channel::~Channel() while (this->invites->entries) entry_delete(this->invites, this->invites->entries); - ChannelList.erase(this->name.c_str()); + ChannelList.erase(this->name); } void Channel::Sync() @@ -90,7 +84,7 @@ void Channel::Sync() } if (Me && Me->IsSynced() && !this->topic_sync) - restore_topic(name.c_str()); + restore_topic(name); } void Channel::JoinUser(User *user) @@ -106,7 +100,7 @@ void Channel::JoinUser(User *user) uc->Status = Status; this->users.push_back(uc); - if (!get_ignore(user->nick.c_str())) + if (!get_ignore(user->nick)) { if (this->ci && check_access(user, this->ci, CA_MEMO) && this->ci->memos.memos.size() > 0) { @@ -117,8 +111,8 @@ void Channel::JoinUser(User *user) } /* Added channelname to entrymsg - 30.03.2004, Certus */ /* Also, don't send the entrymsg when bursting -GD */ - if (this->ci && this->ci->entry_message && user->server->IsSynced()) - user->SendMessage(whosends(this->ci)->nick, "[%s] %s", this->name.c_str(), this->ci->entry_message); + if (this->ci && !this->ci->entry_message.empty() && user->server->IsSynced()) + user->SendMessage(whosends(this->ci)->nick, "[%s] %s", this->name.c_str(), this->ci->entry_message.c_str()); } /** @@ -129,16 +123,15 @@ void Channel::JoinUser(User *user) * But don't join the bot if the channel is persistant - Adam * But join persistant channels when syncing with our uplink- DP **/ - if (Config.s_BotServ && this->ci && this->ci->bi && (!Me->IsSynced() || !this->ci->HasFlag(CI_PERSIST)) && this->users.size() == Config.BSMinUsers) + if (!Config.s_BotServ.empty() && this->ci && this->ci->bi && (!Me->IsSynced() || !this->ci->HasFlag(CI_PERSIST)) && this->users.size() == Config.BSMinUsers) this->ci->bi->Join(this); /* Only display the greet if the main uplink we're connected * to has synced, or we'll get greet-floods when the net * recovers from a netsplit. -GD */ - if (Config.s_BotServ && this->ci && this->ci->bi && this->FindUser(this->ci->bi) && this->ci->botflags.HasFlag(BS_GREET) && user->Account() && user->Account()->greet && - check_access(user, this->ci, CA_GREET) && user->server->IsSynced()) + if (!Config.s_BotServ.empty() && this->ci && this->ci->bi && this->FindUser(this->ci->bi) && this->ci->botflags.HasFlag(BS_GREET) && user->Account() && !user->Account()->greet.empty() && check_access(user, this->ci, CA_GREET) && user->server->IsSynced()) { - ircdproto->SendPrivmsg(this->ci->bi, this->name.c_str(), "[%s] %s", user->Account()->display, user->Account()->greet); + ircdproto->SendPrivmsg(this->ci->bi, this->name, "[%s] %s", user->Account()->display.c_str(), user->Account()->greet.c_str()); this->ci->bi->lastmsg = time(NULL); } } @@ -150,7 +143,7 @@ void Channel::DeleteUser(User *user) { if (this->ci) update_cs_lastseen(user, this->ci); - + Alog(LOG_DEBUG) << user->nick << " leaves " << this->name; CUserList::iterator cit, cit_end = this->users.end(); @@ -190,7 +183,7 @@ void Channel::DeleteUser(User *user) if (this->ci && this->ci->HasFlag(CI_INHABIT)) return; - if (Config.s_BotServ && this->ci && this->ci->bi && this->FindUser(this->ci->bi)) + if (!Config.s_BotServ.empty() && this->ci && this->ci->bi && this->FindUser(this->ci->bi)) this->ci->bi->Part(this->ci->c); else if (this->users.empty()) delete this; @@ -257,7 +250,7 @@ bool Channel::HasMode(ChannelModeName Name) * @param param The param * @param EnforeMLock true if mlocks should be enforced, false to override mlock */ -void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool EnforceMLock) +void Channel::SetModeInternal(ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) { if (!cm) return; @@ -275,7 +268,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En } BotInfo *bi = NULL; - if (Config.s_BotServ) + if (!Config.s_BotServ.empty()) bi = findbot(param); User *u = bi ? bi : finduser(param); @@ -306,7 +299,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En } ChannelModeList *cml = dynamic_cast<ChannelModeList *>(cm); - cml->AddMask(this, param.c_str()); + cml->AddMask(this, param); return; } @@ -321,7 +314,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En } /* They could be resetting the mode to change its params */ - std::map<ChannelModeName, std::string>::iterator it = Params.find(cm->Name); + std::map<ChannelModeName, Anope::string>::iterator it = Params.find(cm->Name); if (it != Params.end()) Params.erase(it); @@ -354,7 +347,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En /* Remove the mode */ if (cm->Type == MODE_PARAM) { - std::string cparam; + Anope::string cparam; GetParam(cm->Name, cparam); RemoveMode(NULL, cm, cparam); } @@ -365,14 +358,14 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En else if (cm->Type == MODE_PARAM && ci->HasMLock(cm->Name, true)) { ChannelModeParam *cmp = dynamic_cast<ChannelModeParam *>(cm); - std::string cparam, ciparam; + Anope::string cparam, ciparam; /* Get the param currently set on this channel */ GetParam(cmp->Name, cparam); /* Get the param set in mlock */ ci->GetParam(cmp->Name, ciparam); /* We have the wrong param set */ - if (cparam.empty() || ciparam.empty() || cparam != ciparam) + if (cparam.empty() || ciparam.empty() || !cparam.equals_cs(ciparam)) /* Reset the mode with the correct param */ SetMode(NULL, cm, ciparam); } @@ -383,7 +376,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En * @param param The param * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool EnforceMLock) +void Channel::RemoveModeInternal(ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) { if (!cm) return; @@ -401,7 +394,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool } BotInfo *bi = NULL; - if (Config.s_BotServ) + if (!Config.s_BotServ.empty()) bi = findbot(param); User *u = bi ? bi : finduser(param); @@ -437,7 +430,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool } ChannelModeList *cml = dynamic_cast<ChannelModeList *>(cm); - cml->DelMask(this, param.c_str()); + cml->DelMask(this, param); return; } @@ -445,7 +438,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool if (cm->Type == MODE_PARAM) { - std::map<ChannelModeName, std::string>::iterator it = Params.find(cm->Name); + std::map<ChannelModeName, Anope::string>::iterator it = Params.find(cm->Name); if (it != Params.end()) Params.erase(it); } @@ -457,7 +450,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool if (ci) { ci->UnsetFlag(CI_PERSIST); - if (Config.s_BotServ && ci->bi && this->FindUser(ci->bi)) + if (!Config.s_BotServ.empty() && ci->bi && this->FindUser(ci->bi)) this->ci->bi->Part(this); } } @@ -486,7 +479,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool /* This is a param mode */ else if (cm->Type == MODE_PARAM) { - std::string cparam; + Anope::string cparam; /* Get the param stored in mlock for this mode */ if (ci->GetParam(cm->Name, cparam)) SetMode(NULL, cm, cparam); @@ -500,7 +493,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m, bool EnforceMLock) +void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) { if (!cm) return; @@ -509,8 +502,8 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m, bo return; else if (cm->Type == MODE_PARAM && HasMode(cm->Name)) { - std::string cparam; - if (GetParam(cm->Name, cparam) && cparam == param) + Anope::string cparam; + if (GetParam(cm->Name, cparam) && cparam.equals_cs(param)) return; } else if (cm->Type == MODE_STATUS) @@ -535,7 +528,7 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m, bo * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const std::string ¶m, bool EnforceMLock) +void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool EnforceMLock) { SetMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock); } @@ -547,7 +540,7 @@ void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const std::string ¶ * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::SetMode(BotInfo *bi, char Mode, const std::string ¶m, bool EnforceMLock) +void Channel::SetMode(BotInfo *bi, char Mode, const Anope::string ¶m, bool EnforceMLock) { SetMode(bi, ModeManager::FindChannelModeByChar(Mode), param, EnforceMLock); } @@ -558,7 +551,7 @@ void Channel::SetMode(BotInfo *bi, char Mode, const std::string ¶m, bool Enf * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m, bool EnforceMLock) +void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) { if (!cm) return; @@ -597,7 +590,7 @@ void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m, * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const std::string ¶m, bool EnforceMLock) +void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool EnforceMLock) { RemoveMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock); } @@ -609,7 +602,7 @@ void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const std::string &p * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::RemoveMode(BotInfo *bi, char Mode, const std::string ¶m, bool EnforceMLock) +void Channel::RemoveMode(BotInfo *bi, char Mode, const Anope::string ¶m, bool EnforceMLock) { RemoveMode(bi, ModeManager::FindChannelModeByChar(Mode), param, EnforceMLock); } @@ -619,9 +612,9 @@ void Channel::RemoveMode(BotInfo *bi, char Mode, const std::string ¶m, bool * @param Target a string to put the param into * @return true on success */ -const bool Channel::GetParam(ChannelModeName Name, std::string &Target) +const bool Channel::GetParam(ChannelModeName Name, Anope::string &Target) { - std::map<ChannelModeName, std::string>::iterator it = Params.find(Name); + std::map<ChannelModeName, Anope::string>::iterator it = Params.find(Name); Target.clear(); @@ -639,7 +632,7 @@ const bool Channel::GetParam(ChannelModeName Name, std::string &Target) */ const bool Channel::HasParam(ChannelModeName Name) { - std::map<ChannelModeName, std::string>::iterator it = Params.find(Name); + std::map<ChannelModeName, Anope::string>::iterator it = Params.find(Name); if (it != Params.end()) return true; @@ -666,7 +659,7 @@ void Channel::ClearModes(BotInfo *bi) this->RemoveMode(NULL, cm); else if (cm->Type == MODE_PARAM) { - std::string param; + Anope::string param; this->GetParam(cm->Name, param); this->RemoveMode(NULL, cm, param); } @@ -742,7 +735,7 @@ void Channel::SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...) { char buf[BUFSIZE] = ""; va_list args; - std::string modebuf, sbuf; + Anope::string modebuf, sbuf; int add = -1; va_start(args, cmodes); vsnprintf(buf, BUFSIZE - 1, cmodes, args); @@ -750,7 +743,7 @@ void Channel::SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...) spacesepstream sep(buf); sep.GetToken(modebuf); - for (unsigned i = 0, end = modebuf.size(); i < end; ++i) + for (unsigned i = 0, end = modebuf.length(); i < end; ++i) { ChannelMode *cm; @@ -859,10 +852,10 @@ void ChanSetInternalModes(Channel *c, int ac, const char **av) * @param nick The nick being kicked * @param reason The reason for the kick */ -void Channel::KickInternal(const std::string &source, const std::string &nick, const std::string &reason) +void Channel::KickInternal(const Anope::string &source, const Anope::string &nick, const Anope::string &reason) { BotInfo *bi = NULL; - if (Config.s_BotServ && this->ci) + if (!Config.s_BotServ.empty() && this->ci) bi = findbot(nick); User *user = bi ? bi : finduser(nick); if (!user) @@ -873,7 +866,7 @@ void Channel::KickInternal(const std::string &source, const std::string &nick, c Alog(LOG_DEBUG) << "Channel::KickInternal kicking " << user->nick << " from " << this->name; - std::string chname = this->name; + Anope::string chname = this->name; if (user->FindChannel(this)) { @@ -882,7 +875,7 @@ void Channel::KickInternal(const std::string &source, const std::string &nick, c } else Alog(LOG_DEBUG) << "Channel::KickInternal got kick for user " << user->nick << " who isn't on channel " << this->name << " ?"; - + /* Bots get rejoined */ if (bi) bi->Join(chname); @@ -923,12 +916,9 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) * eventual parameters won't be added to the string. */ -char *chan_get_modes(Channel * chan, int complete, int plus) +Anope::string chan_get_modes(Channel *chan, int complete, int plus) { - static char res[BUFSIZE]; - char params[BUFSIZE]; - char *end = res, *value, *pend = params, *pend2 = params; - std::string param; + Anope::string res, params, param; if (chan->HasModes()) { @@ -941,7 +931,7 @@ char *chan_get_modes(Channel * chan, int complete, int plus) if (chan->HasMode(cm->Name)) { - *end++ = cm->ModeChar; + res += cm->ModeChar; if (complete) { @@ -954,42 +944,22 @@ char *chan_get_modes(Channel * chan, int complete, int plus) chan->GetParam(cmp->Name, param); if (!param.empty()) - { - value = const_cast<char *>(param.c_str()); - - *pend++ = ' '; - - while (*value) - *pend++ = *value++; - } + params += " " + param; } } } } } - while (*pend2) - *end++ = *pend2++; + res += params; } - *end = 0; - return res; } /*************************************************************************/ -Channel *findchan(const char *chan) -{ - return findchan(ci::string(chan)); -} - -Channel *findchan(const std::string &chan) -{ - return findchan(ci::string(chan.c_str())); -} - -Channel *findchan(const ci::string &chan) +Channel *findchan(const Anope::string &chan) { channel_map::const_iterator it = ChannelList.find(chan); @@ -1006,7 +976,7 @@ void get_channel_stats(long *nrec, long *memuse) { long count = 0, mem = 0; BanData *bd; - std::string buf; + Anope::string buf; for (channel_map::const_iterator cit = ChannelList.begin(); cit != ChannelList.end(); ++cit) { @@ -1014,8 +984,8 @@ void get_channel_stats(long *nrec, long *memuse) ++count; mem += sizeof(*chan); - if (chan->topic) - mem += strlen(chan->topic) + 1; + if (!chan->topic.empty()) + mem += chan->topic.length() + 1; if (chan->GetParam(CMODE_KEY, buf)) mem += buf.length() + 1; if (chan->GetParam(CMODE_FLOOD, buf)) @@ -1031,13 +1001,13 @@ void get_channel_stats(long *nrec, long *memuse) { mem += sizeof(*it); mem += sizeof((*it)->ud); - if ((*it)->ud.lastline) - mem += strlen((*it)->ud.lastline) + 1; + if (!(*it)->ud.lastline.empty()) + mem += (*it)->ud.lastline.length() + 1; } for (bd = chan->bd; bd; bd = bd->next) { - if (bd->mask) - mem += strlen(bd->mask) + 1; + if (!bd->mask.empty()) + mem += bd->mask.length() + 1; mem += sizeof(*bd); } } @@ -1050,7 +1020,7 @@ void get_channel_stats(long *nrec, long *memuse) /* Is the given nick on the given channel? This function supports links. */ -User *nc_on_chan(Channel *c, NickCore *nc) +User *nc_on_chan(Channel *c, const NickCore *nc) { if (!c || !nc) return NULL; @@ -1073,7 +1043,7 @@ User *nc_on_chan(Channel *c, NickCore *nc) * av[0] = channels to join */ -void do_join(const char *source, int ac, const char **av) +void do_join(const Anope::string &source, int ac, const char **av) { User *user; Channel *chan; @@ -1087,7 +1057,7 @@ void do_join(const char *source, int ac, const char **av) } commasepstream sep(av[0]); - ci::string buf; + Anope::string buf; while (sep.GetToken(buf)) { if (buf[0] == '0') @@ -1096,7 +1066,7 @@ void do_join(const char *source, int ac, const char **av) { ChannelContainer *cc = *it++; - std::string channame = cc->chan->name; + Anope::string channame = cc->chan->name; FOREACH_MOD(I_OnPrePartChannel, OnPrePartChannel(user, cc->chan)); cc->chan->DeleteUser(user); FOREACH_MOD(I_OnPartChannel, OnPartChannel(user, findchan(channame), channame, "")); @@ -1114,7 +1084,7 @@ void do_join(const char *source, int ac, const char **av) /* Join came with a TS */ if (ac == 2) { - time_t ts = atol(av[1]); + time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0; /* Their time is older, we lose */ if (chan->creation_time > ts) @@ -1161,7 +1131,7 @@ void do_join(const char *source, int ac, const char **av) * @param ac number of args * @param av The channel, nick(s) being kicked, and reason */ -void do_kick(const std::string &source, int ac, const char **av) +void do_kick(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); if (!c) @@ -1170,7 +1140,7 @@ void do_kick(const std::string &source, int ac, const char **av) return; } - std::string buf; + Anope::string buf; commasepstream sep(av[1]); while (sep.GetToken(buf)) c->KickInternal(source, buf, av[2]); @@ -1183,7 +1153,7 @@ void do_kick(const std::string &source, int ac, const char **av) * av[1] = reason (optional) */ -void do_part(const char *source, int ac, const char **av) +void do_part(const Anope::string &source, int ac, const char **av) { User *user = finduser(source); if (!user) @@ -1193,7 +1163,7 @@ void do_part(const char *source, int ac, const char **av) } commasepstream sep(av[0]); - ci::string buf; + Anope::string buf; while (sep.GetToken(buf)) { Channel *c = findchan(buf); @@ -1204,7 +1174,7 @@ void do_part(const char *source, int ac, const char **av) if (user->FindChannel(c)) { FOREACH_MOD(I_OnPrePartChannel, OnPrePartChannel(user, c)); - std::string ChannelName = c->name; + Anope::string ChannelName = c->name; c->DeleteUser(user); FOREACH_MOD(I_OnPartChannel, OnPartChannel(user, findchan(ChannelName), ChannelName, av[1] ? av[1] : "")); } @@ -1221,7 +1191,7 @@ void do_part(const char *source, int ac, const char **av) * @param ac Number of args in array.. * @param av Array of args */ -void do_cmode(const char *source, int ac, const char **av) +void do_cmode(const Anope::string &source, int ac, const char **av) { Channel *c; ChannelInfo *ci; @@ -1248,8 +1218,8 @@ void do_cmode(const char *source, int ac, const char **av) /* :42XAAAAAO TMODE 1106409026 #ircops +b *!*@*.aol.com */ if (ircd->ts6 && isdigit(av[0][0])) { - --ac; - ++av; + --ac; + ++av; } c = findchan(av[0]); @@ -1264,7 +1234,7 @@ void do_cmode(const char *source, int ac, const char **av) return; } - if (strchr(source, '.') && !av[1][strcspn(av[1], "bovahq")]) + if (source.find('.') != Anope::string::npos && Anope::string(av[1]).find_first_of("bovahq") == Anope::string::npos) { if (time(NULL) != c->server_modetime) { @@ -1283,23 +1253,11 @@ void do_cmode(const char *source, int ac, const char **av) /* Handle a TOPIC command. */ -void do_topic(const char *source, int ac, const char **av) +void do_topic(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); ChannelInfo *ci; - int ts; - time_t topic_time; - char *topicsetter; - - if (ircd->sjb64) - { - ts = base64dects(av[2]); - Alog(LOG_DEBUG) << "encoded TOPIC TS " << av[2] << " converted to " << ts; - } - else - ts = strtoul(av[2], NULL, 10); - - topic_time = ts; + time_t topic_time = Anope::string(av[2]).is_number_only() ? convertTo<time_t>(av[2]) : 0; if (!c) { @@ -1315,35 +1273,25 @@ void do_topic(const char *source, int ac, const char **av) /* For Unreal, cut off the ! and any futher part of the topic setter. * This way, nick!ident@host setters will only show the nick. -GD */ - topicsetter = myStrGetToken(av[1], '!', 0); + Anope::string topicsetter = myStrGetToken(av[1], '!', 0); /* If the current topic we have matches the last known topic for this * channel exactly, there's no need to update anything and we can as * well just return silently without updating anything. -GD */ - if (ac > 3 && *av[3] && ci && ci->last_topic && !strcmp(av[3], ci->last_topic) && !strcmp(topicsetter, ci->last_topic_setter.c_str())) - { - delete [] topicsetter; + if (ac > 3 && *av[3] && ci && !ci->last_topic.empty() && ci->last_topic.equals_cs(av[3]) && ci->last_topic_setter.equals_cs(topicsetter)) return; - } if (check_topiclock(c, topic_time)) - { - delete [] topicsetter; return; - } - if (c->topic) - { - delete [] c->topic; - c->topic = NULL; - } + if (!c->topic.empty()) + c->topic.clear(); if (ac > 3 && *av[3]) - c->topic = sstrdup(av[3]); + c->topic = av[3]; c->topic_setter = topicsetter; c->topic_time = topic_time; - delete [] topicsetter; record_topic(av[0]); @@ -1377,12 +1325,12 @@ void chan_set_correct_modes(User *user, Channel *c, int give_modes) if (!c || !(ci = c->ci)) return; - if (ci->HasFlag(CI_FORBIDDEN) || *(c->name.c_str()) == '+') + if (ci->HasFlag(CI_FORBIDDEN) || c->name[0] == '+') return; Alog(LOG_DEBUG) << "Setting correct user modes for " << user->nick << " on " << c->name << " (" << (give_modes ? "" : "not ") << "giving modes)"; - if (give_modes && !get_ignore(user->nick.c_str()) && (!user->Account() || user->Account()->HasFlag(NI_AUTOOP))) + if (give_modes && !get_ignore(user->nick) && (!user->Account() || user->Account()->HasFlag(NI_AUTOOP))) { if (owner && check_access(user, ci, CA_AUTOOWNER)) c->SetMode(NULL, CMODE_OWNER, user->nick); @@ -1420,7 +1368,7 @@ void chan_set_correct_modes(User *user, Channel *c, int give_modes) * @param bi The bot to send the modes from * @param modes The modes */ -void MassChannelModes(BotInfo *bi, const std::string &modes) +void MassChannelModes(BotInfo *bi, const Anope::string &modes) { for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) { @@ -1428,7 +1376,7 @@ void MassChannelModes(BotInfo *bi, const std::string &modes) if (c->bouncy_modes) return; - c->SetModes(bi, false, modes.c_str()); + c->SetModes(bi, false, "%s", modes.c_str()); } } @@ -1441,7 +1389,7 @@ void restore_unsynced_topics() Channel *c = it->second; if (!c->topic_sync) - restore_topic(c->name.c_str()); + restore_topic(c->name); } } @@ -1453,60 +1401,52 @@ void restore_unsynced_topics() * @param mask Host/IP/CIDR mask to convert to an entry * @return Entry struct for the given mask, NULL if creation failed */ -Entry *entry_create(char *mask) +Entry *entry_create(const Anope::string &mask) { Entry *entry; - char *nick = NULL, *user, *host, *cidrhost; + Anope::string cidrhost; uint32 ip, cidr; entry = new Entry; entry->SetFlag(ENTRYTYPE_NONE); entry->prev = NULL; entry->next = NULL; - entry->nick = NULL; - entry->user = NULL; - entry->host = NULL; - entry->mask = sstrdup(mask); + entry->mask = mask; + + Anope::string newmask = mask, host, nick, user; - host = strchr(mask, '@'); - if (host) + size_t at = newmask.find('@'); + if (at != Anope::string::npos) { - *host++ = '\0'; + host = newmask.substr(at + 1); + newmask = newmask.substr(0, at); /* If the user is purely a wildcard, ignore it */ - if (str_is_pure_wildcard(mask)) - user = NULL; - else + if (!str_is_pure_wildcard(newmask)) { /* There might be a nick too */ - user = strchr(mask, '!'); - if (user) + //user = strchr(mask, '!'); + size_t ex = newmask.find('!'); + if (ex != Anope::string::npos) { - *user++ = '\0'; + user = newmask.substr(ex + 1); + newmask = newmask.substr(0, ex); /* If the nick is purely a wildcard, ignore it */ - if (str_is_pure_wildcard(mask)) - nick = NULL; - else - nick = mask; + if (!str_is_pure_wildcard(newmask)) + nick = newmask; } else - { - nick = NULL; - user = mask; - } + user = newmask; } } else - { /* It is possibly an extended ban/invite mask, but we do * not support these at this point.. ~ Viper */ /* If there's no user in the mask, assume a pure wildcard */ - user = NULL; - host = mask; - } + host = newmask; - if (nick) + if (!nick.empty()) { - entry->nick = sstrdup(nick); + entry->nick = nick; /* Check if we have a wildcard user */ if (str_is_wildcard(nick)) entry->SetFlag(ENTRYTYPE_NICK_WILD); @@ -1514,9 +1454,9 @@ Entry *entry_create(char *mask) entry->SetFlag(ENTRYTYPE_NICK); } - if (user) + if (!user.empty()) { - entry->user = sstrdup(user); + entry->user = user; /* Check if we have a wildcard user */ if (str_is_wildcard(user)) entry->SetFlag(ENTRYTYPE_USER_WILD); @@ -1525,16 +1465,16 @@ Entry *entry_create(char *mask) } /* Only check the host if it's not a pure wildcard */ - if (*host && !str_is_pure_wildcard(host)) + if (!host.empty() && !str_is_pure_wildcard(host)) { - if (ircd->cidrchanbei && str_is_cidr(host, &ip, &cidr, &cidrhost)) + if (ircd->cidrchanbei && str_is_cidr(host, &ip, &cidr, cidrhost)) { entry->cidr_ip = ip; entry->cidr_mask = cidr; entry->SetFlag(ENTRYTYPE_CIDR4); host = cidrhost; } - else if (ircd->cidrchanbei && strchr(host, '/')) + else if (ircd->cidrchanbei && host.find('/') != Anope::string::npos) { /* Most IRCd's don't enforce sane bans therefore it is not * so unlikely we will encounter this. @@ -1549,14 +1489,13 @@ Entry *entry_create(char *mask) } else { - entry->host = sstrdup(host); + entry->host = host; if (str_is_wildcard(host)) entry->SetFlag(ENTRYTYPE_HOST_WILD); else entry->SetFlag(ENTRYTYPE_HOST); } } - delete [] mask; return entry; } @@ -1567,13 +1506,11 @@ Entry *entry_create(char *mask) * @param mask The mask to parse and add to the list * @return Pointer to newly added entry. NULL if it fails. */ -Entry *entry_add(EList *list, const char *mask) +Entry *entry_add(EList *list, const Anope::string &mask) { Entry *e; - char *hostmask; - hostmask = sstrdup(mask); - e = entry_create(hostmask); + e = entry_create(mask); if (!e) return NULL; @@ -1607,13 +1544,6 @@ void entry_delete(EList *list, Entry *e) if (list->entries == e) list->entries = e->next; - if (e->nick) - delete [] e->nick; - if (e->user) - delete [] e->user; - if (e->host) - delete [] e->host; - delete [] e->mask; delete e; --list->count; @@ -1643,20 +1573,19 @@ EList *list_create() * @param ip IP to match against, set to 0 to not match this * @return 1 for a match, 0 for no match */ -int entry_match(Entry *e, const ci::string &nick, const ci::string &user, const ci::string &host, uint32 ip) +int entry_match(Entry *e, const Anope::string &nick, const Anope::string &user, const Anope::string &host, uint32 ip) { /* If we don't get an entry, or it s an invalid one, no match ~ Viper */ if (!e || !e->FlagCount()) return 0; - ci::string ci_nick(nick.c_str()), ci_user(user.c_str()), ci_host(host.c_str()); if (ircd->cidrchanbei && e->HasFlag(ENTRYTYPE_CIDR4) && (!ip || (ip && (ip & e->cidr_mask) != e->cidr_ip))) return 0; - if (e->HasFlag(ENTRYTYPE_NICK) && (nick.empty() || nick != e->nick)) + if (e->HasFlag(ENTRYTYPE_NICK) && (nick.empty() || e->nick.equals_ci(nick))) return 0; - if (e->HasFlag(ENTRYTYPE_USER) && (user.empty() || user != e->user)) + if (e->HasFlag(ENTRYTYPE_USER) && (user.empty() || e->user.equals_ci(user))) return 0; - if (e->HasFlag(ENTRYTYPE_HOST) && (host.empty() || host != e->host)) + if (e->HasFlag(ENTRYTYPE_HOST) && (host.empty() || e->host.equals_ci(host))) return 0; if (e->HasFlag(ENTRYTYPE_NICK_WILD) && !Anope::Match(nick, e->nick)) return 0; @@ -1675,40 +1604,30 @@ int entry_match(Entry *e, const ci::string &nick, const ci::string &user, const * @param ip IP to match against, set to 0 to not match this * @return 1 for a match, 0 for no match */ -int entry_match_mask(Entry *e, const char *mask, uint32 ip) +int entry_match_mask(Entry *e, const Anope::string &mask, uint32 ip) { - char *hostmask, *nick, *user, *host; int res; - hostmask = sstrdup(mask); + Anope::string hostmask = mask, host, user, nick; - host = strchr(hostmask, '@'); - if (host) + size_t at = hostmask.find('@'); + if (at != Anope::string::npos) { - *host++ = '\0'; - user = strchr(hostmask, '!'); - if (user) + host = hostmask.substr(at + 1); + hostmask = hostmask.substr(0, at); + size_t ex = hostmask.find('!'); + if (ex != Anope::string::npos) { - *user++ = '\0'; - nick = hostmask; + user = hostmask.substr(ex + 1); + nick = hostmask.substr(0, ex); } else - { - nick = NULL; user = hostmask; - } } else - { - nick = NULL; - user = NULL; host = hostmask; - } - res = entry_match(e, nick ? nick : "", user ? user : "", host ? host : "", ip); - - /* Free the destroyed mask. */ - delete [] hostmask; + res = entry_match(e, nick, user, host, ip); return res; } @@ -1722,7 +1641,7 @@ int entry_match_mask(Entry *e, const char *mask, uint32 ip) * @param ip The ip to match * @return Returns the first matching entry, if none, NULL is returned. */ -Entry *elist_match(EList *list, const char *nick, const char *user, const char *host, uint32 ip) +Entry *elist_match(EList *list, const Anope::string &nick, const Anope::string &user, const Anope::string &host, uint32 ip) { Entry *e; @@ -1730,7 +1649,7 @@ Entry *elist_match(EList *list, const char *nick, const char *user, const char * return NULL; for (e = list->entries; e; e = e->next) - if (entry_match(e, nick ? nick : "", user ? user : "", host ? host : "", ip)) + if (entry_match(e, nick, user, host, ip)) return e; /* We matched none */ @@ -1744,44 +1663,34 @@ Entry *elist_match(EList *list, const char *nick, const char *user, const char * * @param ip The ip to match * @return Returns the first matching entry, if none, NULL is returned. */ -Entry *elist_match_mask(EList *list, const char *mask, uint32 ip) +Entry *elist_match_mask(EList *list, const Anope::string &mask, uint32 ip) { - char *hostmask, *nick, *user, *host; Entry *res; - if (!list || !list->entries || !mask) + if (!list || !list->entries || mask.empty()) return NULL; - hostmask = sstrdup(mask); + Anope::string hostmask = mask, host, user, nick; - host = strchr(hostmask, '@'); - if (host) + size_t at = hostmask.find('@'); + if (at != Anope::string::npos) { - *host++ = '\0'; - user = strchr(hostmask, '!'); - if (user) + host = hostmask.substr(at + 1); + hostmask = hostmask.substr(0, at); + size_t ex = hostmask.find('!'); + if (ex != Anope::string::npos) { - *user++ = '\0'; - nick = hostmask; + user = hostmask.substr(ex + 1); + nick = hostmask.substr(0, ex); } else - { - nick = NULL; user = hostmask; - } } else - { - nick = NULL; - user = NULL; host = hostmask; - } res = elist_match(list, nick, user, host, ip); - /* Free the destroyed mask. */ - delete [] hostmask; - return res; } @@ -1794,36 +1703,33 @@ Entry *elist_match_mask(EList *list, const char *mask, uint32 ip) Entry *elist_match_user(EList *list, User *u) { Entry *res; - char *host; + Anope::string host; uint32 ip = 0; if (!list || !list->entries || !u) return NULL; - if (u->hostip == NULL) + if (u->hostip.empty()) { host = host_resolve(u->host); /* we store the just resolved hostname so we don't * need to do this again */ - if (host) - u->hostip = sstrdup(host); + if (!host.empty()) + u->hostip = host; } else - host = sstrdup(u->hostip); + host = u->hostip; /* Convert the host to an IP.. */ - if (host) + if (!host.empty()) ip = str_is_ip(host); /* Match what we ve got against the lists.. */ - res = elist_match(list, u->nick.c_str(), u->GetIdent().c_str(), u->host, ip); + res = elist_match(list, u->nick, u->GetIdent(), u->host, ip); if (!res) - res = elist_match(list, u->nick.c_str(), u->GetIdent().c_str(), u->GetDisplayedHost().c_str(), ip); - if (!res && !u->GetCloakedHost().empty() && u->GetCloakedHost() != u->GetDisplayedHost()) - res = elist_match(list, u->nick.c_str(), u->GetIdent().c_str(), u->GetCloakedHost().c_str(), ip); - - if (host) - delete [] host; + res = elist_match(list, u->nick, u->GetIdent(), u->GetDisplayedHost(), ip); + if (!res && !u->GetCloakedHost().empty() && !u->GetCloakedHost().equals_cs(u->GetDisplayedHost())) + res = elist_match(list, u->nick, u->GetIdent(), u->GetCloakedHost(), ip); return res; } @@ -1834,15 +1740,15 @@ Entry *elist_match_user(EList *list, User *u) * @param mask The *!*@* mask to match * @return Returns the first matching entry, if none, NULL is returned. */ -Entry *elist_find_mask(EList *list, const char *mask) +Entry *elist_find_mask(EList *list, const Anope::string &mask) { Entry *e; - if (!list || !list->entries || !mask) + if (!list || !list->entries || mask.empty()) return NULL; for (e = list->entries; e; e = e->next) - if (!stricmp(e->mask, mask)) + if (e->mask.equals_ci(mask)) return e; return NULL; @@ -1867,14 +1773,14 @@ long get_memuse(EList *list) { for (e = list->entries; e; e = e->next) { - if (e->nick) - mem += strlen(e->nick) + 1; - if (e->user) - mem += strlen(e->user) + 1; - if (e->host) - mem += strlen(e->host) + 1; - if (e->mask) - mem += strlen(e->mask) + 1; + if (!e->nick.empty()) + mem += e->nick.length() + 1; + if (!e->user.empty()) + mem += e->user.length() + 1; + if (!e->host.empty()) + mem += e->host.length() + 1; + if (!e->mask.empty()) + mem += e->mask.length() + 1; } } diff --git a/src/chanserv.cpp b/src/chanserv.cpp index 27cb159ce..bcfe239cd 100644 --- a/src/chanserv.cpp +++ b/src/chanserv.cpp @@ -66,16 +66,16 @@ LevelInfo levelinfo[] = { { CA_AUTOHALFOP, "AUTOHALFOP", CHAN_LEVEL_AUTOHALFOP }, { CA_AUTOOP, "AUTOOP", CHAN_LEVEL_AUTOOP }, { CA_AUTOPROTECT, "AUTOPROTECT", CHAN_LEVEL_AUTOPROTECT }, - { CA_AUTOVOICE, "AUTOVOICE", CHAN_LEVEL_AUTOVOICE }, + { CA_AUTOVOICE, "AUTOVOICE", CHAN_LEVEL_AUTOVOICE }, { CA_NOJOIN, "NOJOIN", CHAN_LEVEL_NOJOIN }, { CA_SIGNKICK, "SIGNKICK", CHAN_LEVEL_SIGNKICK }, { CA_ACCESS_LIST, "ACC-LIST", CHAN_LEVEL_ACCESS_LIST }, { CA_ACCESS_CHANGE, "ACC-CHANGE", CHAN_LEVEL_ACCESS_CHANGE }, - { CA_AKICK, "AKICK", CHAN_LEVEL_AKICK }, + { CA_AKICK, "AKICK", CHAN_LEVEL_AKICK }, { CA_SET, "SET", CHAN_LEVEL_SET }, { CA_BAN, "BAN", CHAN_LEVEL_BAN }, - { CA_BANME, "BANME", CHAN_LEVEL_BANME }, - { CA_CLEAR, "CLEAR", CHAN_LEVEL_CLEAR }, + { CA_BANME, "BANME", CHAN_LEVEL_BANME }, + { CA_CLEAR, "CLEAR", CHAN_LEVEL_CLEAR }, { CA_GETKEY, "GETKEY", CHAN_LEVEL_GETKEY }, { CA_HALFOP, "HALFOP", CHAN_LEVEL_HALFOP }, { CA_HALFOPME, "HALFOPME", CHAN_LEVEL_HALFOPME }, @@ -86,20 +86,20 @@ LevelInfo levelinfo[] = { { CA_OPDEOP, "OPDEOP", CHAN_LEVEL_OPDEOP }, { CA_OPDEOPME, "OPDEOPME", CHAN_LEVEL_OPDEOPME }, { CA_PROTECT, "PROTECT", CHAN_LEVEL_PROTECT }, - { CA_PROTECTME, "PROTECTME", CHAN_LEVEL_PROTECTME }, - { CA_TOPIC, "TOPIC", CHAN_LEVEL_TOPIC }, - { CA_UNBAN, "UNBAN", CHAN_LEVEL_UNBAN }, - { CA_VOICE, "VOICE", CHAN_LEVEL_VOICE }, + { CA_PROTECTME, "PROTECTME", CHAN_LEVEL_PROTECTME }, + { CA_TOPIC, "TOPIC", CHAN_LEVEL_TOPIC }, + { CA_UNBAN, "UNBAN", CHAN_LEVEL_UNBAN }, + { CA_VOICE, "VOICE", CHAN_LEVEL_VOICE }, { CA_VOICEME, "VOICEME", CHAN_LEVEL_VOICEME }, { CA_MEMO, "MEMO", CHAN_LEVEL_MEMO }, { CA_ASSIGN, "ASSIGN", CHAN_LEVEL_ASSIGN }, { CA_BADWORDS, "BADWORDS", CHAN_LEVEL_BADWORDS }, { CA_FANTASIA, "FANTASIA", CHAN_LEVEL_FANTASIA }, - { CA_GREET, "GREET", CHAN_LEVEL_GREET }, + { CA_GREET, "GREET", CHAN_LEVEL_GREET }, { CA_NOKICK, "NOKICK", CHAN_LEVEL_NOKICK }, { CA_SAY, "SAY", CHAN_LEVEL_SAY }, - { CA_AUTOOWNER, "AUTOOWNER", CHAN_LEVEL_AUTOOWNER }, - { CA_OWNER, "OWNER", CHAN_LEVEL_OWNER }, + { CA_AUTOOWNER, "AUTOOWNER", CHAN_LEVEL_AUTOOWNER }, + { CA_OWNER, "OWNER", CHAN_LEVEL_OWNER }, { CA_OWNERME, "OWNERME", CHAN_LEVEL_OWNERME }, { CA_FOUNDER, "FOUNDER", CHAN_LEVEL_FOUNDER }, { -1 } @@ -117,43 +117,38 @@ void moduleAddChanServCmds() /* Returns modes for mlock in a nice way. */ -char *get_mlock_modes(ChannelInfo *ci, int complete) +Anope::string get_mlock_modes(ChannelInfo *ci, int complete) { - static char res[BUFSIZE]; - char *end, *value; ChannelMode *cm; ChannelModeParam *cmp; std::map<char, ChannelMode *>::iterator it, it_end; - std::string param; - - memset(&res, '\0', sizeof(res)); - end = res; + Anope::string res, param; if (ci->GetMLockCount(true) || ci->GetMLockCount(false)) { if (ci->GetMLockCount(true)) { - *end++ = '+'; + res += '+'; for (it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it) { cm = it->second; if (ci->HasMLock(cm->Name, true)) - *end++ = it->first; + res += it->first; } } if (ci->GetMLockCount(false)) { - *end++ = '-'; + res += '-'; for (it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it) { cm = it->second; if (ci->HasMLock(cm->Name, false)) - *end++ = it->first; + res += it->first; } } @@ -170,13 +165,7 @@ char *get_mlock_modes(ChannelInfo *ci, int complete) ci->GetParam(cmp->Name, param); if (!param.empty()) - { - value = const_cast<char *>(param.c_str()); - - *end++ = ' '; - while (*value) - *end++ = *value++; - } + res += " " + param; } } } @@ -192,7 +181,7 @@ char *get_mlock_modes(ChannelInfo *ci, int complete) void get_chanserv_stats(long *nrec, long *memuse) { long count = 0, mem = 0; - std::string param; + Anope::string param; for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) { @@ -200,8 +189,8 @@ void get_chanserv_stats(long *nrec, long *memuse) ++count; mem += sizeof(*ci); - if (ci->desc) - mem += strlen(ci->desc) + 1; + if (!ci->desc.empty()) + mem += ci->desc.length() + 1; mem += ci->GetAccessCount() * sizeof(ChanAccess); mem += ci->GetAkickCount() * sizeof(AutoKick); @@ -214,21 +203,21 @@ void get_chanserv_stats(long *nrec, long *memuse) if (ci->GetParam(CMODE_REDIRECT, param)) mem += param.length() + 1; - if (ci->last_topic) - mem += strlen(ci->last_topic) + 1; - if (ci->entry_message) - mem += strlen(ci->entry_message) + 1; - if (ci->forbidby) - mem += strlen(ci->forbidby) + 1; - if (ci->forbidreason) - mem += strlen(ci->forbidreason) + 1; + if (!ci->last_topic.empty()) + mem += ci->last_topic.length() + 1; + if (!ci->entry_message.empty()) + mem += ci->entry_message.length() + 1; + if (!ci->forbidby.empty()) + mem += ci->forbidby.length() + 1; + if (!ci->forbidreason.empty()) + mem += ci->forbidreason.length() + 1; if (ci->levels) mem += sizeof(*ci->levels) * CA_SIZE; unsigned memos = ci->memos.memos.size(); mem += memos * sizeof(Memo); for (unsigned j = 0; j < memos; ++j) - if (ci->memos.memos[j]->text) - mem += strlen(ci->memos.memos[j]->text) + 1; + if (!ci->memos.memos[j]->text.empty()) + mem += ci->memos.memos[j]->text.length() + 1; if (ci->ttb) mem += sizeof(*ci->ttb) * TTB_SIZE; mem += ci->GetBadWordCount() * sizeof(BadWord); @@ -251,17 +240,17 @@ void cs_init() /* Main ChanServ routine. */ -void chanserv(User *u, const std::string &buf) +void chanserv(User *u, const Anope::string &buf) { if (!u || buf.empty()) return; - if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1') + if (buf.substr(0, 6).equals_ci("\1PING ") && buf[buf.length() - 1] == '\1') { - std::string command = buf; + Anope::string command = buf; command.erase(command.begin()); command.erase(command.end()); - ircdproto->SendCTCP(ChanServ, u->nick.c_str(), "%s", command.c_str()); + ircdproto->SendCTCP(ChanServ, u->nick, "%s", command.c_str()); } else mod_run_cmd(ChanServ, u, buf); @@ -279,7 +268,7 @@ void check_modes(Channel *c) ChannelInfo *ci; ChannelMode *cm; std::map<char, ChannelMode *>::iterator it, it_end; - std::string param, ciparam; + Anope::string param, ciparam; if (!c) { @@ -326,8 +315,8 @@ void check_modes(Channel *c) /* Add the eventual parameter and modify the Channel structure */ if (cm->Type == MODE_PARAM) { - if (ci->GetParam(cm->Name, param)) - c->SetMode(NULL, cm, param); + if (ci->GetParam(cm->Name, ciparam)) + c->SetMode(NULL, cm, ciparam); } else c->SetMode(NULL, cm); @@ -339,7 +328,7 @@ void check_modes(Channel *c) ci->GetParam(cm->Name, ciparam); /* If the channel doesnt have the mode, or it does and it isn't set correctly */ - if (!c->HasMode(cm->Name) || (!param.empty() && !ciparam.empty() && param != ciparam)) + if (!c->HasMode(cm->Name) || (!param.empty() && !ciparam.empty() && !param.equals_cs(ciparam))) c->SetMode(NULL, cm, ciparam); } } @@ -386,7 +375,7 @@ int check_valid_admin(User *user, Channel *chan, int servermode) if (servermode && !check_access(user, chan->ci, CA_AUTOPROTECT)) { - notice_lang(Config.s_ChanServ, user, CHAN_IS_REGISTERED, Config.s_ChanServ); + notice_lang(Config.s_ChanServ, user, CHAN_IS_REGISTERED, Config.s_ChanServ.c_str()); chan->RemoveMode(NULL, CMODE_PROTECT, user->nick); return 0; } @@ -422,7 +411,7 @@ int check_valid_op(User *user, Channel *chan, int servermode) if (servermode && !check_access(user, chan->ci, CA_AUTOOP)) { - notice_lang(Config.s_ChanServ, user, CHAN_IS_REGISTERED, Config.s_ChanServ); + notice_lang(Config.s_ChanServ, user, CHAN_IS_REGISTERED, Config.s_ChanServ.c_str()); if (owner) chan->RemoveMode(NULL, CMODE_OWNER, user->nick); @@ -456,7 +445,7 @@ int check_valid_op(User *user, Channel *chan, int servermode) /* Record the current channel topic in the ChannelInfo structure. */ -void record_topic(const char *chan) +void record_topic(const Anope::string &chan) { Channel *c; ChannelInfo *ci; @@ -468,14 +457,7 @@ void record_topic(const char *chan) if (!c || !(ci = c->ci)) return; - if (ci->last_topic) - delete [] ci->last_topic; - - if (c->topic) - ci->last_topic = sstrdup(c->topic); - else - ci->last_topic = NULL; - + ci->last_topic = c->topic; ci->last_topic_setter = c->topic_setter; ci->last_topic_time = c->topic_time; } @@ -484,7 +466,7 @@ void record_topic(const char *chan) /* Restore the topic in a channel when it's created, if we should. */ -void restore_topic(const char *chan) +void restore_topic(const Anope::string &chan) { Channel *c = findchan(chan); ChannelInfo *ci; @@ -493,27 +475,25 @@ void restore_topic(const char *chan) return; /* We can be sure that the topic will be in sync when we return -GD */ c->topic_sync = 1; - if (!(ci->HasFlag(CI_KEEPTOPIC))) + if (!ci->HasFlag(CI_KEEPTOPIC)) { /* We need to reset the topic here, since it's currently empty and * should be updated with a TOPIC from the IRCd soon. -GD */ - ci->last_topic = NULL; + ci->last_topic.clear(); ci->last_topic_setter = whosends(ci)->nick; ci->last_topic_time = time(NULL); return; } - if (c->topic) - delete [] c->topic; - if (ci->last_topic) + if (!ci->last_topic.empty()) { - c->topic = sstrdup(ci->last_topic); + c->topic = ci->last_topic; c->topic_setter = ci->last_topic_setter; c->topic_time = ci->last_topic_time; } else { - c->topic = NULL; + c->topic.clear(); c->topic_setter = whosends(ci)->nick; } if (ircd->join2set && whosends(ci) == ChanServ) @@ -521,7 +501,7 @@ void restore_topic(const char *chan) ChanServ->Join(chan); c->SetMode(NULL, CMODE_OP, Config.s_ChanServ); } - ircdproto->SendTopic(whosends(ci), c, c->topic_setter.c_str(), c->topic ? c->topic : ""); + ircdproto->SendTopic(whosends(ci), c, c->topic_setter, c->topic); if (ircd->join2set && whosends(ci) == ChanServ) ChanServ->Part(c); } @@ -544,16 +524,14 @@ int check_topiclock(Channel *c, time_t topic_time) if (!(ci = c->ci) || !ci->HasFlag(CI_TOPICLOCK)) return 0; - if (c->topic) - delete [] c->topic; - if (ci->last_topic) + if (!ci->last_topic.empty()) { - c->topic = sstrdup(ci->last_topic); + c->topic = ci->last_topic; c->topic_setter = ci->last_topic_setter; } else { - c->topic = NULL; + c->topic.clear(); /* Bot assigned & Symbiosis ON?, the bot will set the topic - doc */ /* Altough whosends() also checks for Config.BSMinUsers -GD */ c->topic_setter = whosends(ci)->nick; @@ -571,7 +549,7 @@ int check_topiclock(Channel *c, time_t topic_time) else { /* If no last topic, we can't use last topic time! - doc */ - if (ci->last_topic) + if (!ci->last_topic.empty()) c->topic_time = ci->last_topic_time; else c->topic_time = time(NULL) + 1; @@ -583,7 +561,7 @@ int check_topiclock(Channel *c, time_t topic_time) c->SetMode(NULL, CMODE_OP, Config.s_ChanServ); } - ircdproto->SendTopic(whosends(ci), c, c->topic_setter.c_str(), c->topic ? c->topic : ""); + ircdproto->SendTopic(whosends(ci), c, c->topic_setter, c->topic); if (ircd->join2set && whosends(ci) == ChanServ) ChanServ->Part(c); @@ -613,11 +591,10 @@ void expire_chans() if (MOD_RESULT == EVENT_STOP) continue; - char *chname = sstrdup(ci->name.c_str()); + Anope::string chname = ci->name; Alog() << "Expiring channel " << ci->name << " (founder: " << (ci->founder ? ci->founder->display : "(none)") << " )"; delete ci; FOREACH_MOD(I_OnChanExpire, OnChanExpire(chname)); - delete [] chname; } } } @@ -651,7 +628,7 @@ void cs_remove_nick(const NickCore *nc) Alog() << Config.s_ChanServ << ": Transferring foundership of " << ci->name << " from deleted nick " << nc->display << " to successor " << nc2->display; ci->founder = nc2; ci->successor = NULL; - nc2->channelcount++; + ++nc2->channelcount; } } else @@ -692,17 +669,7 @@ void cs_remove_nick(const NickCore *nc) /*************************************************************************/ -ChannelInfo *cs_findchan(const char *chan) -{ - return cs_findchan(ci::string(chan)); -} - -ChannelInfo *cs_findchan(const std::string &chan) -{ - return cs_findchan(ci::string(chan.c_str())); -} - -ChannelInfo *cs_findchan(const ci::string &chan) +ChannelInfo *cs_findchan(const Anope::string &chan) { registered_channel_map::const_iterator it = RegisteredChannelList.find(chan); @@ -744,7 +711,7 @@ int check_access(User *user, ChannelInfo *ci, int what) return what == CA_AUTODEOP || what == CA_NOJOIN ? 0 : 1; /* Hacks to make flags work */ - if (what == CA_AUTODEOP && (ci->HasFlag(CI_SECUREOPS)) && !level) + if (what == CA_AUTODEOP && ci->HasFlag(CI_SECUREOPS) && !level) return 1; if (what == CA_AUTODEOP || what == CA_NOJOIN) @@ -829,7 +796,7 @@ int get_access(User *user, ChannelInfo *ci) NickAlias *na = findnick(user->nick); if (na) access = ci->GetAccess(na->nc); - if (access && user->IsRecognized() && !(ci->HasFlag(CI_SECURE))) + if (access && user->IsRecognized() && !ci->HasFlag(CI_SECURE)) return access->level; } @@ -855,34 +822,33 @@ void update_cs_lastseen(User *user, ChannelInfo *ci) /* Returns the best ban possible for an user depending of the bantype value. */ -int get_idealban(ChannelInfo *ci, User *u, char *ret, int retlen) +int get_idealban(ChannelInfo *ci, User *u, Anope::string &ret) { - char *mask; + Anope::string mask; - if (!ci || !u || !ret || retlen == 0) + if (!ci || !u) return 0; - std::string vident = u->GetIdent(); + Anope::string vident = u->GetIdent(); switch (ci->bantype) { case 0: - snprintf(ret, retlen, "*!%s@%s", vident.c_str(), u->GetDisplayedHost().c_str()); + ret = "*!" + vident + "@" + u->GetDisplayedHost(); return 1; case 1: if (vident[0] == '~') - snprintf(ret, retlen, "*!*%s@%s", vident.c_str(), u->GetDisplayedHost().c_str()); + ret = "*!*" + vident + "@" + u->GetDisplayedHost(); else - snprintf(ret, retlen, "*!%s@%s", vident.c_str(), u->GetDisplayedHost().c_str()); + ret = "*!" + vident + "@" + u->GetDisplayedHost(); return 1; case 2: - snprintf(ret, retlen, "*!*@%s", u->GetDisplayedHost().c_str()); + ret = "*!*@" + u->GetDisplayedHost(); return 1; case 3: mask = create_mask(u); - snprintf(ret, retlen, "*!%s", mask); - delete [] mask; + ret = "*!" + mask; return 1; default: @@ -892,17 +858,15 @@ int get_idealban(ChannelInfo *ci, User *u, char *ret, int retlen) /*************************************************************************/ -int get_access_level(ChannelInfo *ci, NickAlias *na) +int get_access_level(ChannelInfo *ci, NickCore *nc) { - ChanAccess *access; - - if (!ci || !na) + if (!ci || !nc) return 0; - if (na->nc == ci->founder) + if (nc == ci->founder) return ACCESS_FOUNDER; - access = ci->GetAccess(na->nc); + ChanAccess *access = ci->GetAccess(nc); if (!access) return 0; @@ -910,23 +874,15 @@ int get_access_level(ChannelInfo *ci, NickAlias *na) return access->level; } -int get_access_level(ChannelInfo *ci, NickCore *nc) +int get_access_level(ChannelInfo *ci, NickAlias *na) { - if (!ci || !nc) + if (!na) return 0; - if (nc == ci->founder) - return ACCESS_FOUNDER; - - ChanAccess *access = ci->GetAccess(nc); - - if (!access) - return 0; - else - return access->level; + return get_access_level(ci, na->nc); } -const char *get_xop_level(int level) +Anope::string get_xop_level(int level) { ChannelMode *halfop = ModeManager::FindChannelModeByName(CMODE_HALFOP); @@ -954,7 +910,7 @@ const char *get_xop_level(int level) /* Is the mask stuck? */ -AutoKick *is_stuck(ChannelInfo * ci, const char *mask) +AutoKick *is_stuck(ChannelInfo *ci, const Anope::string &mask) { if (!ci) return NULL; @@ -966,11 +922,11 @@ AutoKick *is_stuck(ChannelInfo * ci, const char *mask) if (akick->HasFlag(AK_ISNICK) || !akick->HasFlag(AK_STUCK)) continue; - if (Anope::Match(akick->mask, mask, false)) + if (Anope::Match(akick->mask, mask)) return akick; if (ircd->reversekickcheck) - if (Anope::Match(mask, akick->mask, false)) + if (Anope::Match(mask, akick->mask)) return akick; } @@ -992,21 +948,21 @@ void stick_mask(ChannelInfo *ci, AutoKick *akick) { /* If akick is already covered by a wider ban. Example: c->bans[i] = *!*@*.org and akick->u.mask = *!*@*.epona.org */ - if (entry_match_mask(ban, akick->mask.c_str(), 0)) + if (entry_match_mask(ban, akick->mask, 0)) return; if (ircd->reversekickcheck) { /* If akick is wider than a ban already in place. Example: c->bans[i] = *!*@irc.epona.org and akick->u.mask = *!*@*.epona.org */ - if (Anope::Match(ban->mask, akick->mask.c_str(), false)) + if (Anope::Match(ban->mask, akick->mask)) return; } } } /* Falling there means set the ban */ - ci->c->SetMode(NULL, CMODE_BAN, akick->mask.c_str()); + ci->c->SetMode(NULL, CMODE_BAN, akick->mask); } /* Ban the stuck mask in a safe manner. */ @@ -1023,7 +979,7 @@ void stick_all(ChannelInfo *ci) if (akick->HasFlag(AK_ISNICK) || !akick->HasFlag(AK_STUCK)) continue; - ci->c->SetMode(NULL, CMODE_BAN, akick->mask.c_str()); + ci->c->SetMode(NULL, CMODE_BAN, akick->mask); } } diff --git a/src/command.cpp b/src/command.cpp index 5c4bc4ee4..de9842d78 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -8,7 +8,7 @@ #include "services.h" #include "modules.h" -Command::Command(const ci::string &sname, size_t min_params, size_t max_params, const ci::string &spermission) : MaxParams(max_params), MinParams(min_params), name(sname), permission(spermission) +Command::Command(const Anope::string &sname, size_t min_params, size_t max_params, const Anope::string &spermission) : MaxParams(max_params), MinParams(min_params), name(sname), permission(spermission) { this->module = NULL; this->service = NULL; @@ -18,20 +18,18 @@ Command::~Command() { } -CommandReturn Command::Execute(User *u, const std::vector<ci::string> &) +CommandReturn Command::Execute(User *u, const std::vector<Anope::string> &) { return MOD_CONT; } void Command::OnServHelp(User *u) { } -bool Command::OnHelp(User *u, const ci::string &subcommand) { return false; } +bool Command::OnHelp(User *u, const Anope::string &subcommand) { return false; } -void Command::OnSyntaxError(User *u, const ci::string &subcommand) -{ -} +void Command::OnSyntaxError(User *u, const Anope::string &subcommand) { } -void Command::SetPermission(const ci::string &reststr) +void Command::SetPermission(const Anope::string &reststr) { this->permission = reststr; } @@ -41,7 +39,7 @@ bool Command::AddSubcommand(Command *c) return false; } -bool Command::DelSubcommand(const ci::string &cname) +bool Command::DelSubcommand(const Anope::string &cname) { return false; } diff --git a/src/commands.cpp b/src/commands.cpp index ebe189fd4..2647ea952 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -14,12 +14,12 @@ #include "language.h" #include "hashcomp.h" -Command *FindCommand(BotInfo *bi, const ci::string &name) +Command *FindCommand(BotInfo *bi, const Anope::string &name) { if (!bi || bi->Commands.empty() || name.empty()) return NULL; - std::map<ci::string, Command *>::iterator it = bi->Commands.find(name); + CommandMap::iterator it = bi->Commands.find(name); if (it != bi->Commands.end()) return it->second; @@ -27,16 +27,16 @@ Command *FindCommand(BotInfo *bi, const ci::string &name) return NULL; } -void mod_run_cmd(BotInfo *bi, User *u, const std::string &message) +void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &message) { - spacesepstream sep(ci::string(message.c_str())); - ci::string cmd; + spacesepstream sep(message); + Anope::string cmd; if (sep.GetToken(cmd)) - mod_run_cmd(bi, u, FindCommand(bi, cmd), cmd, sep.GetRemaining().c_str()); + mod_run_cmd(bi, u, FindCommand(bi, cmd), cmd, sep.GetRemaining()); } -void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, const ci::string &message) +void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, const Anope::string &message) { if (!bi || !u) return; @@ -57,22 +57,19 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, co // Command requires registered users only if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !u->IsIdentified()) { - notice_lang(bi->nick, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ); + notice_lang(bi->nick, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ.c_str()); Alog() << "Access denied for unregistered user " << u->nick << " with service " << bi->nick << " and command " << command; return; } - std::vector<ci::string> params; - ci::string curparam, endparam; + std::vector<Anope::string> params; + Anope::string curparam, endparam; spacesepstream sep(message); while (sep.GetToken(curparam)) { // - 1 because params[0] corresponds with a maxparam of 1. - if (params.size() >= (c->MaxParams - 1)) - { - endparam += curparam; - endparam += " "; - } + if (params.size() >= c->MaxParams - 1) + endparam += curparam + " "; else params.push_back(curparam); } @@ -80,7 +77,7 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, co if (!endparam.empty()) { // Remove trailing space - endparam.erase(endparam.size() - 1, endparam.size()); + endparam.erase(endparam.length() - 1); // Add it params.push_back(endparam); @@ -98,7 +95,7 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, co if (params.size() > 0 && !c->HasFlag(CFLAG_STRIP_CHANNEL) && (bi == ChanServ || bi == BotServ)) { - if (ircdproto->IsChannelValid(params[0].c_str())) + if (ircdproto->IsChannelValid(params[0])) { ChannelInfo *ci = cs_findchan(params[0]); if (ci) @@ -142,7 +139,7 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, co if (ret == MOD_CONT) { - FOREACH_MOD(I_OnPostCommand, OnPostCommand(u, c->service, c->name.c_str(), params)); + FOREACH_MOD(I_OnPostCommand, OnPostCommand(u, c->service, c->name, params)); } } @@ -154,18 +151,18 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, co * @param cmd Command * @return void */ -void mod_help_cmd(BotInfo *bi, User *u, const ci::string &cmd) +void mod_help_cmd(BotInfo *bi, User *u, const Anope::string &cmd) { if (!bi || !u || cmd.empty()) return; spacesepstream tokens(cmd); - ci::string token; + Anope::string token; tokens.GetToken(token); Command *c = FindCommand(bi, token); - ci::string subcommand = tokens.StreamEnd() ? "" : tokens.GetRemaining().c_str(); + Anope::string subcommand = tokens.StreamEnd() ? "" : tokens.GetRemaining(); if (!c || (Config.HidePrivilegedCommands && !c->permission.empty() && (!u->Account() || !u->Account()->HasCommand(c->permission))) || !c->OnHelp(u, subcommand)) notice_lang(bi->nick, u, NO_HELP_AVAILABLE, cmd.c_str()); diff --git a/src/compat.cpp b/src/compat.cpp deleted file mode 100644 index 2fdb57b86..000000000 --- a/src/compat.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* Compatibility routines. - * - * (C) 2003-2010 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 "services.h" - -/*************************************************************************/ - -#if !HAVE_STRICMP && !HAVE_STRCASECMP - -/* stricmp, strnicmp: Case-insensitive versions of strcmp() and - * strncmp(). - */ - -int stricmp(const char *s1, const char *s2) -{ - register int c; - - while ((c = tolower(*s1)) == tolower(*s2)) - { - if (!c) - return 0; - ++s1; - ++s2; - } - if (c < tolower(*s2)) - return -1; - return 1; -} - -int strnicmp(const char *s1, const char *s2, size_t len) -{ - register int c; - - if (!len) - return 0; - while ((c = tolower(*s1)) == tolower(*s2) && len > 0) - { - if (!c || !--len) - return 0; - ++s1; - ++s2; - } - if (c < tolower(*s2)) - return -1; - return 1; -} - -#endif - -/*************************************************************************/ diff --git a/src/config.cpp b/src/config.cpp index 61f9d586f..c9dcf426a 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -15,29 +15,28 @@ /*************************************************************************/ -ci::string services_conf = "services.conf"; // Services configuration file name +Anope::string services_conf = "services.conf"; // Services configuration file name ServerConfig Config; -static ci::string Modules; -static ci::string EncModules; -static ci::string DBModules; -static ci::string SocketEngineModule; -static ci::string HostCoreModules; -static ci::string MemoCoreModules; -static ci::string BotCoreModules; -static ci::string OperCoreModules; -static ci::string NickCoreModules; -static ci::string ChanCoreModules; -static ci::string DefCon1; -static ci::string DefCon2; -static ci::string DefCon3; -static ci::string DefCon4; -static char *UlineServers; -static ci::string OSNotifications; -static ci::string BSDefaults; -static ci::string CSDefaults; -static char *temp_nsuserhost; -static ci::string NSDefaults; +static Anope::string Modules; +static Anope::string EncModules; +static Anope::string DBModules; +static Anope::string HostCoreModules; +static Anope::string MemoCoreModules; +static Anope::string BotCoreModules; +static Anope::string OperCoreModules; +static Anope::string NickCoreModules; +static Anope::string ChanCoreModules; +static Anope::string DefCon1; +static Anope::string DefCon2; +static Anope::string DefCon3; +static Anope::string DefCon4; +static Anope::string UlineServers; +static Anope::string OSNotifications; +static Anope::string BSDefaults; +static Anope::string CSDefaults; +static Anope::string temp_nsuserhost; +static Anope::string NSDefaults; /*************************************************************************/ @@ -51,48 +50,43 @@ void ServerConfig::ClearStack() include_stack.clear(); } -bool ServerConfig::CheckOnce(const char *tag) +bool ServerConfig::CheckOnce(const Anope::string &tag) { int count = ConfValueEnum(config_data, tag); if (count > 1) - throw ConfigException(std::string("You have more than one <") + tag + "> tag, this is not permitted."); + throw ConfigException("You have more than one <" + tag + "> tag, this is not permitted."); if (count < 1) - throw ConfigException(std::string("You have not defined a <") + tag + "> tag, this is required."); + throw ConfigException("You have not defined a <" + tag + "> tag, this is required."); return true; } -bool NoValidation(ServerConfig *, const char *, const char *, ValueItem &) +bool NoValidation(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &) { return true; } -bool DoneConfItem(ServerConfig *, const char *) +void ServerConfig::ValidateNoSpaces(const Anope::string &p, const Anope::string &tag, const Anope::string &val) { - return true; -} - -void ServerConfig::ValidateNoSpaces(const char *p, const ci::string &tag, const ci::string &val) -{ - for (const char *ptr = p; *ptr; ++ptr) + for (Anope::string::const_iterator ptr = p.begin(), end = p.end(); ptr != end; ++ptr) if (*ptr == ' ') - throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> cannot contain spaces"); + throw ConfigException("The value of <" + tag + ":" + val + "> cannot contain spaces"); } /* NOTE: Before anyone asks why we're not using inet_pton for this, it is because inet_pton and friends do not return so much detail, * even in strerror(errno). They just return 'yes' or 'no' to an address without such detail as to whats WRONG with the address. * Because ircd users arent as technical as they used to be (;)) we are going to give more of a useful error message. */ -void ServerConfig::ValidateIP(const char *p, const ci::string &tag, const ci::string &val, bool wild) +void ServerConfig::ValidateIP(const Anope::string &p, const Anope::string &tag, const Anope::string &val, bool wild) { int num_dots = 0, num_seps = 0; bool not_numbers = false, not_hex = false; - if (*p) + if (!p.empty()) { - if (*p == '.') - throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is not an IP address"); + if (p[0] == '.') + throw ConfigException("The value of <" + tag + ":" + val + "> is not an IP address"); - for (const char *ptr = p; *ptr; ++ptr) + for (Anope::string::const_iterator ptr = p.begin(), end = p.end(); ptr != end; ++ptr) { if (wild && (*ptr == '*' || *ptr == '?' || *ptr == '/')) continue; @@ -106,7 +100,7 @@ void ServerConfig::ValidateIP(const char *p, const ci::string &tag, const ci::st switch (*ptr) { case ' ': - throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is not an IP address"); + throw ConfigException("The value of <" + tag + ":" + val + "> is not an IP address"); case '.': ++num_dots; break; @@ -115,41 +109,41 @@ void ServerConfig::ValidateIP(const char *p, const ci::string &tag, const ci::st } } if (num_dots > 3) - throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is an IPv4 address with too many fields!"); + throw ConfigException("The value of <" + tag + ":" + val + "> is an IPv4 address with too many fields!"); if (num_seps > 8) - throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is an IPv6 address with too many fields!"); + throw ConfigException("The value of <" + tag + ":" + val + "> is an IPv6 address with too many fields!"); if (!num_seps && num_dots < 3 && !wild) - throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> looks to be a malformed IPv4 address"); + throw ConfigException("The value of <" + tag + ":" + val + "> looks to be a malformed IPv4 address"); if (!num_seps && num_dots == 3 && not_numbers) - throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> contains non-numeric characters in an IPv4 address"); + throw ConfigException("The value of <" + tag + ":" + val + "> contains non-numeric characters in an IPv4 address"); if (num_seps && not_hex) - throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> contains non-hexdecimal characters in an IPv6 address"); + throw ConfigException("The value of <" + tag + ":" + val + "> contains non-hexdecimal characters in an IPv6 address"); if (num_seps && num_dots != 3 && num_dots && !wild) - throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is a malformed IPv6 4in6 address"); + throw ConfigException("The value of <" + tag + ":" + val + "> is a malformed IPv6 4in6 address"); } } -void ServerConfig::ValidateHostname(const char *p, const ci::string &tag, const ci::string &val) +void ServerConfig::ValidateHostname(const Anope::string &p, const Anope::string &tag, const Anope::string &val) { - if (!strcasecmp(p, "localhost")) + if (p.equals_ci("localhost")) return; int num_dots = 0, num_seps = 0; - if (*p) + if (!p.empty()) { - if (*p == '.') - throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is not a valid hostname"); - for (const char *ptr = p; *ptr; ++ptr) + if (p[0] == '.') + throw ConfigException("The value of <" + tag + ":" + val + "> is not a valid hostname"); + for (unsigned i = 0, end = p.length(); i < end; ++i) { - switch (*ptr) + switch (p[i]) { case ' ': - throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is not a valid hostname"); + throw ConfigException("The value of <" + tag + ":" + val + "> is not a valid hostname"); case '.': ++num_dots; break; @@ -159,72 +153,70 @@ void ServerConfig::ValidateHostname(const char *p, const ci::string &tag, const } } if (!num_dots && !num_seps) - throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is not a valid hostname"); + throw ConfigException("The value of <" + tag + ":" + val + "> is not a valid hostname"); } } -bool ValidateNotEmpty(ServerConfig *, const char *tag, const char *value, ValueItem &data) +bool ValidateNotEmpty(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data) { if (data.GetValue().empty()) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty!"); + throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty!"); return true; } -bool ValidateNotZero(ServerConfig *, const char *tag, const char *value, ValueItem &data) +bool ValidateNotZero(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data) { - if (!data.GetInteger()) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be non-zero!"); + if (!data.GetInteger() && !dotime(data.GetValue())) + throw ConfigException("The value for <" + tag + ":" + value + "> must be non-zero!"); return true; } -bool ValidateEmailReg(ServerConfig *, const char *tag, const char *value, ValueItem &data) +bool ValidateEmailReg(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data) { if (Config.NSEmailReg) { - if (ci::string(value) == "preregexpire") + if (value.equals_ci("preregexpire")) { if (!data.GetInteger()) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be non-zero when e-mail registration are enabled!"); + throw ConfigException("The value for <" + tag + ":" + value + "> must be non-zero when e-mail registration are enabled!"); } else { if (!data.GetBool()) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be set to yes when e-mail registrations are enabled!"); + throw ConfigException("The value for <" + tag + ":" + value + "> must be set to yes when e-mail registrations are enabled!"); } } return true; } -bool ValidatePort(ServerConfig *, const char *tag, const char *value, ValueItem &data) +bool ValidatePort(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data) { int port = data.GetInteger(); if (!port) return true; if (port < 1 || port > 65535) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> is not a value port, it must be between 1 and 65535!"); + throw ConfigException("The value for <" + tag + ":" + value + "> is not a value port, it must be between 1 and 65535!"); return true; } -bool ValidateLanguage(ServerConfig *, const char *, const char *, ValueItem &data) +bool ValidateLanguage(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &data) { int language = data.GetInteger(); - char maxlang[3]; - snprintf(maxlang, 3, "%d", USED_LANGS); if (language < 1 || language > USED_LANGS) - throw ConfigException(std::string("The value for <nickserv:defaultlanguage> must be between 1 and ") + maxlang + "!"); + throw ConfigException("The value for <nickserv:defaultlanguage> must be between 1 and " + stringify(USED_LANGS) + "!"); data.Set(--language); return true; } -bool ValidateGuestPrefix(ServerConfig *conf, const char *tag, const char *value, ValueItem &data) +bool ValidateGuestPrefix(ServerConfig *conf, const Anope::string &tag, const Anope::string &value, ValueItem &data) { ValidateNotEmpty(conf, tag, value, data); - if (data.GetValue().size() > 21) + if (data.GetValue().length() > 21) throw ConfigException("The value for <nickserv:guestnickprefix> cannot exceed 21 characters in length!"); return true; } -bool ValidateBantype(ServerConfig *, const char *, const char *, ValueItem &data) +bool ValidateBantype(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &data) { int bantype = data.GetInteger(); if (bantype < 0 || bantype > 3) @@ -232,53 +224,53 @@ bool ValidateBantype(ServerConfig *, const char *, const char *, ValueItem &data return true; } -bool ValidateBotServ(ServerConfig *, const char *tag, const char *value, ValueItem &data) +bool ValidateBotServ(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data) { - if (Config.s_BotServ) + if (!Config.s_BotServ.empty()) { - if (ci::string(value) == "description") + if (value.equals_ci("description")) { if (data.GetValue().empty()) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty when BotServ is enabled!"); + throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when BotServ is enabled!"); } - else if (ci::string(value) == "minusers" || ci::string(value) == "badwordsmax" || ci::string(value) == "keepdata") + else if (value.equals_ci("minusers") || value.equals_ci("badwordsmax") || value.equals_ci("keepdata")) { - if (!data.GetInteger()) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be non-zero when BotServ is enabled!"); + if (!data.GetInteger() && !dotime(data.GetValue())) + throw ConfigException("The value for <" + tag + ":" + value + "> must be non-zero when BotServ is enabled!"); } } return true; } -bool ValidateHostServ(ServerConfig *, const char *tag, const char *value, ValueItem &data) +bool ValidateHostServ(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data) { - if (Config.s_HostServ) + if (!Config.s_HostServ.empty()) { - if (ci::string(value) == "description") + if (value.equals_ci("description")) { if (data.GetValue().empty()) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty when HostServ is enabled!"); + throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when HostServ is enabled!"); } } return true; } -bool ValidateLimitSessions(ServerConfig *, const char *tag, const char *value, ValueItem &data) +bool ValidateLimitSessions(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data) { if (Config.LimitSessions) { - if (ci::string(value) == "maxsessionlimit" || ci::string(value) == "exceptionexpiry") + if (value.equals_ci("maxsessionlimit") || value.equals_ci("exceptionexpiry")) { - if (!data.GetInteger()) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be non-zero when session limiting is enabled!"); + if (!data.GetInteger() && !dotime(data.GetValue())) + throw ConfigException("The value for <" + tag + ":" + value + "> must be non-zero when session limiting is enabled!"); } } return true; } -bool ValidateDefCon(ServerConfig *, const char *tag, const char *value, ValueItem &data) +bool ValidateDefCon(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data) { - if (ci::string(value) == "defaultlevel") + if (value.equals_ci("defaultlevel")) { int level = data.GetInteger(); if (!level) @@ -288,26 +280,26 @@ bool ValidateDefCon(ServerConfig *, const char *tag, const char *value, ValueIte } else if (Config.DefConLevel) { - if ((ci::string(value).substr(0, 5) == "level" && isdigit(value[5])) || ci::string(value) == "chanmodes" || ci::string(value) == "akillreason") + if ((value.substr(0, 5).equals_ci("level") && isdigit(value[5])) || value.equals_ci("chanmodes") || value.equals_ci("akillreason")) { if (data.GetValue().empty()) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty when DefCon is enabled!"); + throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when DefCon is enabled!"); } - else if (ci::string(value) == "message" && Config.GlobalOnDefconMore) + else if (value.equals_ci("message") && Config.GlobalOnDefconMore) { if (data.GetValue().empty()) throw ConfigException("The value for <defcon:message> cannot be empty when globalondefconmore is enabled!"); } - else if (ci::string(value) == "sessionlimit" || ci::string(value) == "akillexpire") + else if (value.equals_ci("sessionlimit") || value.equals_ci("akillexpire")) { - if (!data.GetInteger()) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be non-zero when DefCon is enabled!"); + if (!data.GetInteger() && !dotime(data.GetValue())) + throw ConfigException("The value for <" + tag + ":" + value + "> must be non-zero when DefCon is enabled!"); } } return true; } -bool ValidateNickLen(ServerConfig *, const char *, const char *, ValueItem &data) +bool ValidateNickLen(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &data) { int nicklen = data.GetInteger(); if (!nicklen) @@ -324,20 +316,20 @@ bool ValidateNickLen(ServerConfig *, const char *, const char *, ValueItem &data return true; } -bool ValidateMail(ServerConfig *, const char *tag, const char *value, ValueItem &data) +bool ValidateMail(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data) { if (Config.UseMail) { - if (ci::string(value) == "sendmailpath" || ci::string(value) == "sendfrom") + if (value.equals_ci("sendmailpath") || value.equals_ci("sendfrom")) { if (data.GetValue().empty()) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty when e-mail is enabled!"); + throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when e-mail is enabled!"); } } return true; } -bool ValidateGlobalOnCycle(ServerConfig *, const char *tag, const char *value, ValueItem &data) +bool ValidateGlobalOnCycle(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data) { if (Config.GlobalOnCycle) { @@ -350,7 +342,7 @@ bool ValidateGlobalOnCycle(ServerConfig *, const char *tag, const char *value, V return true; } -void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail) +void ServerConfig::ReportConfigError(const Anope::string &errormessage, bool bail) { Alog() << "There were errors in your configuration file: " << errormessage; if (bail) @@ -360,7 +352,7 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail) } } -bool InitUplinks(ServerConfig *, const char *, bool bail) +bool InitUplinks(ServerConfig *, const Anope::string &, bool bail) { // If bail is false, we were reloading, don't clear anything if (!bail) @@ -375,13 +367,13 @@ bool InitUplinks(ServerConfig *, const char *, bool bail) return true; } -bool DoUplink(ServerConfig *conf, const char *, const char **, ValueList &values, int *, bool bail) +bool DoUplink(ServerConfig *conf, const Anope::string &, const Anope::string *, ValueList &values, int *, bool bail) { // If bail is false, we were reloading, don't even try to add another uplink if (!bail) return true; // Validation variables - const char *host = values[0].GetString(), *password = values[3].GetString(); + Anope::string host = values[0].GetValue(), password = values[3].GetValue(); int port = values[2].GetInteger(); bool ipv6 = values[1].GetBool(); ValueItem vi_host(host), vi_port(port), vi_password(password); @@ -399,7 +391,7 @@ bool DoUplink(ServerConfig *conf, const char *, const char **, ValueList &values return true; } -bool DoneUplinks(ServerConfig *, const char *, bool bail) +bool DoneUplinks(ServerConfig *, const Anope::string &, bool bail) { // If bail is false, we were reloading, ignore this check if (!bail) @@ -409,7 +401,7 @@ bool DoneUplinks(ServerConfig *, const char *, bool bail) return true; } -static bool InitOperTypes(ServerConfig *, const char *, bool) +static bool InitOperTypes(ServerConfig *, const Anope::string &, bool) { for (std::list<OperType *>::iterator it = Config.MyOperTypes.begin(), it_end = Config.MyOperTypes.end(); it != it_end; ++it) delete *it; @@ -418,12 +410,12 @@ static bool InitOperTypes(ServerConfig *, const char *, bool) return true; } -static bool DoOperType(ServerConfig *conf, const char *, const char **, ValueList &values, int *, bool) +static bool DoOperType(ServerConfig *conf, const Anope::string &, const Anope::string *, ValueList &values, int *, bool) { - const char *name = values[0].GetString(); - const char *inherits = values[1].GetString(); - const char *commands = values[2].GetString(); - const char *privs = values[3].GetString(); + Anope::string name = values[0].GetValue(); + Anope::string inherits = values[1].GetValue(); + Anope::string commands = values[2].GetValue(); + Anope::string privs = values[3].GetValue(); ValueItem vi(name); if (!ValidateNotEmpty(conf, "opertype", "name", vi)) @@ -431,7 +423,7 @@ static bool DoOperType(ServerConfig *conf, const char *, const char **, ValueLis OperType *ot = new OperType(name); - ci::string tok; + Anope::string tok; spacesepstream cmdstr(commands); while (cmdstr.GetToken(tok)) ot->AddCommand(tok); @@ -444,11 +436,11 @@ static bool DoOperType(ServerConfig *conf, const char *, const char **, ValueLis while (inheritstr.GetToken(tok)) { /* Strip leading ' ' after , */ - if (tok.size() > 1 && tok[0] == ' ') + if (tok.length() > 1 && tok[0] == ' ') tok.erase(tok.begin()); for (std::list<OperType *>::iterator it = Config.MyOperTypes.begin(), it_end = Config.MyOperTypes.end(); it != it_end; ++it) { - if ((*it)->GetName() == tok) + if ((*it)->GetName().equals_ci(tok)) { Alog() << "Inheriting commands and privs from " << (*it)->GetName() << " to " << ot->GetName(); ot->Inherits(*it); @@ -461,14 +453,14 @@ static bool DoOperType(ServerConfig *conf, const char *, const char **, ValueLis return true; } -static bool DoneOperTypes(ServerConfig *, const char *, bool) +static bool DoneOperTypes(ServerConfig *, const Anope::string &, bool) { return true; } /*************************************************************************/ -static bool InitOpers(ServerConfig *, const char *, bool) +static bool InitOpers(ServerConfig *, const Anope::string &, bool) { for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it) it->second->ot = NULL; @@ -478,10 +470,10 @@ static bool InitOpers(ServerConfig *, const char *, bool) return true; } -static bool DoOper(ServerConfig *conf, const char *, const char **, ValueList &values, int *, bool) +static bool DoOper(ServerConfig *conf, const Anope::string &, const Anope::string *, ValueList &values, int *, bool) { - const char *name = values[0].GetString(); - const char *type = values[1].GetString(); + Anope::string name = values[0].GetValue(); + Anope::string type = values[1].GetValue(); ValueItem vi(name); if (!ValidateNotEmpty(conf, "oper", "name", vi)) @@ -495,12 +487,11 @@ static bool DoOper(ServerConfig *conf, const char *, const char **, ValueList &v return true; } -static bool DoneOpers(ServerConfig *, const char *, bool) +static bool DoneOpers(ServerConfig *, const Anope::string &, bool) { - // XXX: this is duplicated in config.c - for (std::list<std::pair<ci::string, ci::string> >::iterator it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) + for (std::list<std::pair<Anope::string, Anope::string> >::iterator it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) { - ci::string nick = it->first, type = it->second; + Anope::string nick = it->first, type = it->second; NickAlias *na = findnick(nick); if (!na) @@ -514,7 +505,7 @@ static bool DoneOpers(ServerConfig *, const char *, bool) for (std::list<OperType *>::iterator tit = Config.MyOperTypes.begin(), tit_end = Config.MyOperTypes.end(); tit != tit_end; ++tit) { OperType *ot = *tit; - if (ot->GetName() == type) + if (ot->GetName().equals_ci(type)) { Alog() << "Tied oper " << na->nc->display << " to type " << type; na->nc->ot = ot; @@ -526,16 +517,16 @@ static bool DoneOpers(ServerConfig *, const char *, bool) /*************************************************************************/ -bool InitModules(ServerConfig *, const char *, bool) +bool InitModules(ServerConfig *, const Anope::string &, bool) { Modules.clear(); return true; } -bool DoModule(ServerConfig *conf, const char *, const char **, ValueList &values, int *, bool) +bool DoModule(ServerConfig *conf, const Anope::string &, const Anope::string *, ValueList &values, int *, bool) { // First we validate that there was a name in the module block - const char *module = values[0].GetString(); + Anope::string module = values[0].GetValue(); ValueItem vi(module); if (!ValidateNotEmpty(conf, "module", "name", vi)) throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information."); @@ -543,11 +534,11 @@ bool DoModule(ServerConfig *conf, const char *, const char **, ValueList &values if (!Modules.empty()) Modules += " "; // Add the module name to the string - Modules += values[0].GetString(); + Modules += values[0].GetValue(); return true; } -bool DoneModules(ServerConfig *, const char *, bool) +bool DoneModules(ServerConfig *, const Anope::string &, bool) { return true; } @@ -556,7 +547,7 @@ int ServerConfig::Read(bool bail) { errstr.clear(); // These tags MUST occur and must ONLY occur once in the config file - static const char *Once[] = {"serverinfo", "networkinfo", "options", "nickserv", "chanserv", "memoserv", "operserv", NULL}; + static const Anope::string Once[] = {"serverinfo", "networkinfo", "options", "nickserv", "chanserv", "memoserv", "operserv", ""}; // These tags can occur ONCE or not at all InitialConfig Values[] = { /* The following comments are from CyberBotX to w00t as examples to use: @@ -612,25 +603,25 @@ int ServerConfig::Read(bool bail) * * We may need to add some other validation functions to handle certain things, we can handle that later. * Any questions about these, w00t, feel free to ask. */ - {"serverinfo", "name", "", new ValueContainerChar(&Config.ServerName), DT_HOSTNAME | DT_NORELOAD, ValidateNotEmpty}, - {"serverinfo", "description", "", new ValueContainerChar(&Config.ServerDesc), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"serverinfo", "localhost", "", new ValueContainerChar(&Config.LocalHost), DT_HOSTNAME | DT_NORELOAD, NoValidation}, - {"serverinfo", "type", "", new ValueContainerChar(&Config.IRCDModule), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"serverinfo", "id", "", new ValueContainerChar(&Config.Numeric), DT_NOSPACES | DT_NORELOAD, NoValidation}, - {"serverinfo", "ident", "", new ValueContainerChar(&Config.ServiceUser), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"serverinfo", "hostname", "", new ValueContainerChar(&Config.ServiceHost), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"serverinfo", "pid", "services.pid", new ValueContainerChar(&Config.PIDFilename), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"serverinfo", "motd", "services.motd", new ValueContainerChar(&Config.MOTDFilename), DT_CHARPTR, ValidateNotEmpty}, - {"networkinfo", "logchannel", "", new ValueContainerChar(&Config.LogChannel), DT_CHARPTR, NoValidation}, + {"serverinfo", "name", "", new ValueContainerString(&Config.ServerName), DT_HOSTNAME | DT_NORELOAD, ValidateNotEmpty}, + {"serverinfo", "description", "", new ValueContainerString(&Config.ServerDesc), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"serverinfo", "localhost", "", new ValueContainerString(&Config.LocalHost), DT_HOSTNAME | DT_NORELOAD, NoValidation}, + {"serverinfo", "type", "", new ValueContainerString(&Config.IRCDModule), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"serverinfo", "id", "", new ValueContainerString(&Config.Numeric), DT_NOSPACES | DT_NORELOAD, NoValidation}, + {"serverinfo", "ident", "", new ValueContainerString(&Config.ServiceUser), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"serverinfo", "hostname", "", new ValueContainerString(&Config.ServiceHost), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"serverinfo", "pid", "services.pid", new ValueContainerString(&Config.PIDFilename), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"serverinfo", "motd", "services.motd", new ValueContainerString(&Config.MOTDFilename), DT_STRING, ValidateNotEmpty}, + {"networkinfo", "logchannel", "", new ValueContainerString(&Config.LogChannel), DT_STRING, NoValidation}, {"networkinfo", "logbot", "no", new ValueContainerBool(&Config.LogBot), DT_BOOLEAN, NoValidation}, - {"networkinfo", "networkname", "", new ValueContainerChar(&Config.NetworkName), DT_CHARPTR, ValidateNotEmpty}, + {"networkinfo", "networkname", "", new ValueContainerString(&Config.NetworkName), DT_STRING, ValidateNotEmpty}, {"networkinfo", "nicklen", "0", new ValueContainerUInt(&Config.NickLen), DT_UINTEGER | DT_NORELOAD, ValidateNickLen}, {"networkinfo", "userlen", "10", new ValueContainerUInt(&Config.UserLen), DT_UINTEGER | DT_NORELOAD, NoValidation}, {"networkinfo", "hostlen", "64", new ValueContainerUInt(&Config.HostLen), DT_UINTEGER | DT_NORELOAD, NoValidation}, - {"options", "encryption", "", new ValueContainerCIString(&EncModules), DT_CISTRING | DT_NORELOAD, ValidateNotEmpty}, + {"options", "encryption", "", new ValueContainerString(&EncModules), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, {"options", "passlen", "32", new ValueContainerUInt(&Config.PassLen), DT_UINTEGER | DT_NORELOAD, NoValidation}, - {"options", "database", "", new ValueContainerCIString(&DBModules), DT_CISTRING | DT_NORELOAD, ValidateNotEmpty}, - {"options", "socketengine", "", new ValueContainerCIString(&Config.SocketEngine), DT_CISTRING | DT_NORELOAD, ValidateNotEmpty}, + {"options", "database", "", new ValueContainerString(&DBModules), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"options", "socketengine", "", new ValueContainerString(&Config.SocketEngine), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, {"options", "userkey1", "0", new ValueContainerLUInt(&Config.UserKey1), DT_LUINTEGER, NoValidation}, {"options", "userkey2", "0", new ValueContainerLUInt(&Config.UserKey2), DT_LUINTEGER, NoValidation}, {"options", "userkey3", "0", new ValueContainerLUInt(&Config.UserKey3), DT_LUINTEGER, NoValidation}, @@ -652,25 +643,25 @@ int ServerConfig::Read(bool bail) {"options", "logusers", "no", new ValueContainerBool(&Config.LogUsers), DT_BOOLEAN, NoValidation}, {"options", "hidestatso", "no", new ValueContainerBool(&Config.HideStatsO), DT_BOOLEAN, NoValidation}, {"options", "globaloncycle", "no", new ValueContainerBool(&Config.GlobalOnCycle), DT_BOOLEAN, NoValidation}, - {"options", "globaloncycledown", "", new ValueContainerChar(&Config.GlobalOnCycleMessage), DT_CHARPTR, ValidateGlobalOnCycle}, - {"options", "globaloncycleup", "", new ValueContainerChar(&Config.GlobalOnCycleUP), DT_CHARPTR, ValidateGlobalOnCycle}, + {"options", "globaloncycledown", "", new ValueContainerString(&Config.GlobalOnCycleMessage), DT_STRING, ValidateGlobalOnCycle}, + {"options", "globaloncycleup", "", new ValueContainerString(&Config.GlobalOnCycleUP), DT_STRING, ValidateGlobalOnCycle}, {"options", "anonymousglobal", "no", new ValueContainerBool(&Config.AnonymousGlobal), DT_BOOLEAN, NoValidation}, {"options", "nickregdelay", "0", new ValueContainerUInt(&Config.NickRegDelay), DT_UINTEGER, NoValidation}, {"options", "restrictopernicks", "no", new ValueContainerBool(&Config.RestrictOperNicks), DT_BOOLEAN, NoValidation}, {"options", "newscount", "3", new ValueContainerUInt(&Config.NewsCount), DT_UINTEGER, NoValidation}, - {"options", "ulineservers", "", new ValueContainerChar(&UlineServers), DT_CHARPTR, NoValidation}, + {"options", "ulineservers", "", new ValueContainerString(&UlineServers), DT_STRING, NoValidation}, {"options", "enablelogchannel", "no", new ValueContainerBool(&LogChan), DT_BOOLEAN, NoValidation}, - {"options", "mlock", "+nrt", new ValueContainerCIString(&Config.MLock), DT_CISTRING, NoValidation}, - {"options", "botmodes", "", new ValueContainerCIString(&Config.BotModes), DT_CISTRING, NoValidation}, + {"options", "mlock", "+nrt", new ValueContainerString(&Config.MLock), DT_STRING, NoValidation}, + {"options", "botmodes", "", new ValueContainerString(&Config.BotModes), DT_STRING, NoValidation}, {"options", "maxretries", "10", new ValueContainerUInt(&Config.MaxRetries), DT_UINTEGER, NoValidation}, {"options", "retrywait", "60", new ValueContainerInt(&Config.RetryWait), DT_INTEGER, ValidateNotZero}, {"options", "hideprivilegedcommands", "no", new ValueContainerBool(&Config.HidePrivilegedCommands), DT_BOOLEAN, ValidateEmailReg}, - {"nickserv", "nick", "NickServ", new ValueContainerChar(&Config.s_NickServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"nickserv", "description", "Nickname Registration Service", new ValueContainerChar(&Config.desc_NickServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, + {"nickserv", "nick", "NickServ", new ValueContainerString(&Config.s_NickServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"nickserv", "description", "Nickname Registration Service", new ValueContainerString(&Config.desc_NickServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, {"nickserv", "emailregistration", "no", new ValueContainerBool(&Config.NSEmailReg), DT_BOOLEAN, NoValidation}, - {"nickserv", "modules", "", new ValueContainerCIString(&NickCoreModules), DT_CISTRING, NoValidation}, + {"nickserv", "modules", "", new ValueContainerString(&NickCoreModules), DT_STRING, NoValidation}, {"nickserv", "forceemail", "no", new ValueContainerBool(&Config.NSForceEmail), DT_BOOLEAN, ValidateEmailReg}, - {"nickserv", "defaults", "secure memosignon memoreceive", new ValueContainerCIString(&NSDefaults), DT_CISTRING, NoValidation}, + {"nickserv", "defaults", "secure memosignon memoreceive", new ValueContainerString(&NSDefaults), DT_STRING, NoValidation}, {"nickserv", "defaultlanguage", "0", new ValueContainerUInt(&Config.NSDefLanguage), DT_UINTEGER, ValidateLanguage}, {"nickserv", "regdelay", "0", new ValueContainerTime(&Config.NSRegDelay), DT_TIME, NoValidation}, {"nickserv", "resenddelay", "0", new ValueContainerTime(&Config.NSResendDelay), DT_TIME, NoValidation}, @@ -678,63 +669,63 @@ int ServerConfig::Read(bool bail) {"nickserv", "preregexpire", "0", new ValueContainerTime(&Config.NSRExpire), DT_TIME, ValidateEmailReg}, {"nickserv", "maxaliases", "0", new ValueContainerInt(&Config.NSMaxAliases), DT_INTEGER, NoValidation}, {"nickserv", "accessmax", "0", new ValueContainerUInt(&Config.NSAccessMax), DT_UINTEGER, ValidateNotZero}, - {"nickserv", "enforceruser", "", new ValueContainerChar(&temp_nsuserhost), DT_CHARPTR, ValidateNotEmpty}, + {"nickserv", "enforceruser", "", new ValueContainerString(&temp_nsuserhost), DT_STRING, ValidateNotEmpty}, {"nickserv", "releasetimeout", "0", new ValueContainerTime(&Config.NSReleaseTimeout), DT_TIME, ValidateNotZero}, {"nickserv", "allowkillimmed", "no", new ValueContainerBool(&Config.NSAllowKillImmed), DT_BOOLEAN | DT_NORELOAD, NoValidation}, {"nickserv", "nogroupchange", "no", new ValueContainerBool(&Config.NSNoGroupChange), DT_BOOLEAN, NoValidation}, {"nickserv", "listopersonly", "no", new ValueContainerBool(&Config.NSListOpersOnly), DT_BOOLEAN, NoValidation}, {"nickserv", "listmax", "0", new ValueContainerUInt(&Config.NSListMax), DT_UINTEGER, ValidateNotZero}, - {"nickserv", "guestnickprefix", "", new ValueContainerChar(&Config.NSGuestNickPrefix), DT_CHARPTR, ValidateGuestPrefix}, + {"nickserv", "guestnickprefix", "", new ValueContainerString(&Config.NSGuestNickPrefix), DT_STRING, ValidateGuestPrefix}, {"nickserv", "secureadmins", "no", new ValueContainerBool(&Config.NSSecureAdmins), DT_BOOLEAN, NoValidation}, {"nickserv", "strictprivileges", "no", new ValueContainerBool(&Config.NSStrictPrivileges), DT_BOOLEAN, NoValidation}, {"nickserv", "modeonid", "no", new ValueContainerBool(&Config.NSModeOnID), DT_BOOLEAN, NoValidation}, {"nickserv", "addaccessonreg", "no", new ValueContainerBool(&Config.NSAddAccessOnReg), DT_BOOLEAN, NoValidation}, {"mail", "usemail", "no", new ValueContainerBool(&Config.UseMail), DT_BOOLEAN, ValidateEmailReg}, - {"mail", "sendmailpath", "", new ValueContainerChar(&Config.SendMailPath), DT_CHARPTR, ValidateMail}, - {"mail", "sendfrom", "", new ValueContainerChar(&Config.SendFrom), DT_CHARPTR, ValidateMail}, + {"mail", "sendmailpath", "", new ValueContainerString(&Config.SendMailPath), DT_STRING, ValidateMail}, + {"mail", "sendfrom", "", new ValueContainerString(&Config.SendFrom), DT_STRING, ValidateMail}, {"mail", "restrict", "no", new ValueContainerBool(&Config.RestrictMail), DT_BOOLEAN, NoValidation}, {"mail", "delay", "0", new ValueContainerTime(&Config.MailDelay), DT_TIME, NoValidation}, {"mail", "dontquoteaddresses", "no", new ValueContainerBool(&Config.DontQuoteAddresses), DT_BOOLEAN, NoValidation}, - {"chanserv", "nick", "ChanServ", new ValueContainerChar(&Config.s_ChanServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"chanserv", "description", "Channel Registration Service", new ValueContainerChar(&Config.desc_ChanServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"chanserv", "modules", "", new ValueContainerCIString(&ChanCoreModules), DT_CISTRING, NoValidation}, - {"chanserv", "defaults", "keeptopic secure securefounder signkick", new ValueContainerCIString(&CSDefaults), DT_CISTRING, NoValidation}, + {"chanserv", "nick", "ChanServ", new ValueContainerString(&Config.s_ChanServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"chanserv", "description", "Channel Registration Service", new ValueContainerString(&Config.desc_ChanServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"chanserv", "modules", "", new ValueContainerString(&ChanCoreModules), DT_STRING, NoValidation}, + {"chanserv", "defaults", "keeptopic secure securefounder signkick", new ValueContainerString(&CSDefaults), DT_STRING, NoValidation}, {"chanserv", "maxregistered", "0", new ValueContainerUInt(&Config.CSMaxReg), DT_UINTEGER, NoValidation}, {"chanserv", "expire", "14d", new ValueContainerTime(&Config.CSExpire), DT_TIME, NoValidation}, {"chanserv", "defbantype", "2", new ValueContainerInt(&Config.CSDefBantype), DT_INTEGER, ValidateBantype}, {"chanserv", "accessmax", "0", new ValueContainerUInt(&Config.CSAccessMax), DT_UINTEGER, ValidateNotZero}, {"chanserv", "autokickmax", "0", new ValueContainerUInt(&Config.CSAutokickMax), DT_UINTEGER, ValidateNotZero}, - {"chanserv", "autokickreason", "User has been banned from the channel", new ValueContainerChar(&Config.CSAutokickReason), DT_CHARPTR, ValidateNotEmpty}, + {"chanserv", "autokickreason", "User has been banned from the channel", new ValueContainerString(&Config.CSAutokickReason), DT_STRING, ValidateNotEmpty}, {"chanserv", "inhabit", "0", new ValueContainerTime(&Config.CSInhabit), DT_TIME, ValidateNotZero}, {"chanserv", "listopersonly", "no", new ValueContainerBool(&Config.CSListOpersOnly), DT_BOOLEAN, NoValidation}, {"chanserv", "listmax", "0", new ValueContainerUInt(&Config.CSListMax), DT_UINTEGER, ValidateNotZero}, {"chanserv", "opersonly", "no", new ValueContainerBool(&Config.CSOpersOnly), DT_BOOLEAN, NoValidation}, - {"memoserv", "nick", "MemoServ", new ValueContainerChar(&Config.s_MemoServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"memoserv", "description", "Memo Service", new ValueContainerChar(&Config.desc_MemoServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"memoserv", "modules", "", new ValueContainerCIString(&MemoCoreModules), DT_CISTRING, NoValidation}, + {"memoserv", "nick", "MemoServ", new ValueContainerString(&Config.s_MemoServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"memoserv", "description", "Memo Service", new ValueContainerString(&Config.desc_MemoServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"memoserv", "modules", "", new ValueContainerString(&MemoCoreModules), DT_STRING, NoValidation}, {"memoserv", "maxmemos", "0", new ValueContainerUInt(&Config.MSMaxMemos), DT_UINTEGER, NoValidation}, {"memoserv", "senddelay", "0", new ValueContainerTime(&Config.MSSendDelay), DT_TIME, NoValidation}, {"memoserv", "notifyall", "no", new ValueContainerBool(&Config.MSNotifyAll), DT_BOOLEAN, NoValidation}, {"memoserv", "memoreceipt", "0", new ValueContainerUInt(&Config.MSMemoReceipt), DT_UINTEGER, NoValidation}, - {"botserv", "nick", "", new ValueContainerChar(&Config.s_BotServ), DT_CHARPTR | DT_NORELOAD, NoValidation}, - {"botserv", "description", "Bot Service", new ValueContainerChar(&Config.desc_BotServ), DT_CHARPTR | DT_NORELOAD, ValidateBotServ}, - {"botserv", "modules", "", new ValueContainerCIString(&BotCoreModules), DT_CISTRING, NoValidation}, - {"botserv", "defaults", "", new ValueContainerCIString(&BSDefaults), DT_CISTRING, NoValidation}, + {"botserv", "nick", "", new ValueContainerString(&Config.s_BotServ), DT_STRING | DT_NORELOAD, NoValidation}, + {"botserv", "description", "Bot Service", new ValueContainerString(&Config.desc_BotServ), DT_STRING | DT_NORELOAD, ValidateBotServ}, + {"botserv", "modules", "", new ValueContainerString(&BotCoreModules), DT_STRING, NoValidation}, + {"botserv", "defaults", "", new ValueContainerString(&BSDefaults), DT_STRING, NoValidation}, {"botserv", "minusers", "0", new ValueContainerUInt(&Config.BSMinUsers), DT_UINTEGER, ValidateBotServ}, {"botserv", "badwordsmax", "0", new ValueContainerUInt(&Config.BSBadWordsMax), DT_UINTEGER, ValidateBotServ}, {"botserv", "keepdata", "0", new ValueContainerTime(&Config.BSKeepData), DT_TIME, ValidateBotServ}, {"botserv", "smartjoin", "no", new ValueContainerBool(&Config.BSSmartJoin), DT_BOOLEAN, NoValidation}, {"botserv", "gentlebadwordreason", "no", new ValueContainerBool(&Config.BSGentleBWReason), DT_BOOLEAN, NoValidation}, {"botserv", "casesensitive", "no", new ValueContainerBool(&Config.BSCaseSensitive), DT_BOOLEAN, NoValidation}, - {"botserv", "fantasycharacter", "!", new ValueContainerChar(&Config.BSFantasyCharacter), DT_CHARPTR, NoValidation}, - {"hostserv", "nick", "", new ValueContainerChar(&Config.s_HostServ), DT_CHARPTR | DT_NORELOAD, NoValidation}, - {"hostserv", "description", "vHost Service", new ValueContainerChar(&Config.desc_HostServ), DT_CHARPTR | DT_NORELOAD, ValidateHostServ}, - {"hostserv", "modules", "", new ValueContainerCIString(&HostCoreModules), DT_CISTRING, NoValidation}, - {"operserv", "nick", "OperServ", new ValueContainerChar(&Config.s_OperServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"operserv", "description", "Operator Service", new ValueContainerChar(&Config.desc_OperServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"operserv", "globalnick", "Global", new ValueContainerChar(&Config.s_GlobalNoticer), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"operserv", "globaldescription", "Global Noticer", new ValueContainerChar(&Config.desc_GlobalNoticer), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"operserv", "modules", "", new ValueContainerCIString(&OperCoreModules), DT_CISTRING, NoValidation}, + {"botserv", "fantasycharacter", "!", new ValueContainerString(&Config.BSFantasyCharacter), DT_STRING, NoValidation}, + {"hostserv", "nick", "", new ValueContainerString(&Config.s_HostServ), DT_STRING | DT_NORELOAD, NoValidation}, + {"hostserv", "description", "vHost Service", new ValueContainerString(&Config.desc_HostServ), DT_STRING | DT_NORELOAD, ValidateHostServ}, + {"hostserv", "modules", "", new ValueContainerString(&HostCoreModules), DT_STRING, NoValidation}, + {"operserv", "nick", "OperServ", new ValueContainerString(&Config.s_OperServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"operserv", "description", "Operator Service", new ValueContainerString(&Config.desc_OperServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"operserv", "globalnick", "Global", new ValueContainerString(&Config.s_GlobalNoticer), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"operserv", "globaldescription", "Global Noticer", new ValueContainerString(&Config.desc_GlobalNoticer), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"operserv", "modules", "", new ValueContainerString(&OperCoreModules), DT_STRING, NoValidation}, {"operserv", "superadmin", "no", new ValueContainerBool(&Config.SuperAdmin), DT_BOOLEAN, NoValidation}, {"operserv", "logmaxusers", "no", new ValueContainerBool(&Config.LogMaxUsers), DT_BOOLEAN, NoValidation}, {"operserv", "autokillexpiry", "0", new ValueContainerTime(&Config.AutokillExpiry), DT_TIME, ValidateNotZero}, @@ -745,60 +736,60 @@ int ServerConfig::Read(bool bail) {"operserv", "akillonadd", "no", new ValueContainerBool(&Config.AkillOnAdd), DT_BOOLEAN, NoValidation}, {"operserv", "killonsnline", "no", new ValueContainerBool(&Config.KillonSNline), DT_BOOLEAN, NoValidation}, {"operserv", "killonsqline", "no", new ValueContainerBool(&Config.KillonSQline), DT_BOOLEAN, NoValidation}, - {"operserv", "notifications", "", new ValueContainerCIString(&OSNotifications), DT_CISTRING, NoValidation}, + {"operserv", "notifications", "", new ValueContainerString(&OSNotifications), DT_STRING, NoValidation}, {"operserv", "limitsessions", "no", new ValueContainerBool(&Config.LimitSessions), DT_BOOLEAN, NoValidation}, {"operserv", "defaultsessionlimit", "0", new ValueContainerUInt(&Config.DefSessionLimit), DT_UINTEGER, NoValidation}, {"operserv", "maxsessionlimit", "0", new ValueContainerUInt(&Config.MaxSessionLimit), DT_UINTEGER, ValidateLimitSessions}, {"operserv", "exceptionexpiry", "0", new ValueContainerTime(&Config.ExceptionExpiry), DT_TIME, ValidateLimitSessions}, - {"operserv", "sessionlimitexceeded", "", new ValueContainerChar(&Config.SessionLimitExceeded), DT_CHARPTR, NoValidation}, - {"operserv", "sessionlimitdetailsloc", "", new ValueContainerChar(&Config.SessionLimitDetailsLoc), DT_CHARPTR, NoValidation}, + {"operserv", "sessionlimitexceeded", "", new ValueContainerString(&Config.SessionLimitExceeded), DT_STRING, NoValidation}, + {"operserv", "sessionlimitdetailsloc", "", new ValueContainerString(&Config.SessionLimitDetailsLoc), DT_STRING, NoValidation}, {"operserv", "maxsessionkill", "0", new ValueContainerInt(&Config.MaxSessionKill), DT_INTEGER, NoValidation}, {"operserv", "sessionautokillexpiry", "0", new ValueContainerTime(&Config.SessionAutoKillExpiry), DT_TIME, NoValidation}, {"operserv", "addakiller", "no", new ValueContainerBool(&Config.AddAkiller), DT_BOOLEAN, NoValidation}, {"operserv", "opersonly", "no", new ValueContainerBool(&Config.OSOpersOnly), DT_BOOLEAN, NoValidation}, {"defcon", "defaultlevel", "0", new ValueContainerInt(&DefConLevel), DT_INTEGER, ValidateDefCon}, - {"defcon", "level4", "", new ValueContainerCIString(&DefCon4), DT_CISTRING, ValidateDefCon}, - {"defcon", "level3", "", new ValueContainerCIString(&DefCon3), DT_CISTRING, ValidateDefCon}, - {"defcon", "level2", "", new ValueContainerCIString(&DefCon2), DT_CISTRING, ValidateDefCon}, - {"defcon", "level1", "", new ValueContainerCIString(&DefCon1), DT_CISTRING, ValidateDefCon}, + {"defcon", "level4", "", new ValueContainerString(&DefCon4), DT_STRING, ValidateDefCon}, + {"defcon", "level3", "", new ValueContainerString(&DefCon3), DT_STRING, ValidateDefCon}, + {"defcon", "level2", "", new ValueContainerString(&DefCon2), DT_STRING, ValidateDefCon}, + {"defcon", "level1", "", new ValueContainerString(&DefCon1), DT_STRING, ValidateDefCon}, {"defcon", "sessionlimit", "0", new ValueContainerInt(&Config.DefConSessionLimit), DT_INTEGER, ValidateDefCon}, {"defcon", "akillexpire", "0", new ValueContainerTime(&Config.DefConAKILL), DT_TIME, ValidateDefCon}, - {"defcon", "chanmodes", "", new ValueContainerChar(&Config.DefConChanModes), DT_CHARPTR, ValidateDefCon}, + {"defcon", "chanmodes", "", new ValueContainerString(&Config.DefConChanModes), DT_STRING, ValidateDefCon}, {"defcon", "timeout", "0", new ValueContainerTime(&Config.DefConTimeOut), DT_TIME, NoValidation}, {"defcon", "globalondefcon", "no", new ValueContainerBool(&Config.GlobalOnDefcon), DT_BOOLEAN, NoValidation}, {"defcon", "globalondefconmore", "no", new ValueContainerBool(&Config.GlobalOnDefconMore), DT_BOOLEAN, NoValidation}, - {"defcon", "message", "", new ValueContainerChar(&Config.DefconMessage), DT_CHARPTR, ValidateDefCon}, - {"defcon", "offmessage", "", new ValueContainerChar(&Config.DefConOffMessage), DT_CHARPTR, NoValidation}, - {"defcon", "akillreason", "", new ValueContainerChar(&Config.DefConAkillReason), DT_CHARPTR, ValidateDefCon}, - {NULL, NULL, NULL, NULL, DT_NOTHING, NoValidation} + {"defcon", "message", "", new ValueContainerString(&Config.DefconMessage), DT_STRING, ValidateDefCon}, + {"defcon", "offmessage", "", new ValueContainerString(&Config.DefConOffMessage), DT_STRING, NoValidation}, + {"defcon", "akillreason", "", new ValueContainerString(&Config.DefConAkillReason), DT_STRING, ValidateDefCon}, + {"", "", "", NULL, DT_NOTHING, NoValidation} }; /* These tags can occur multiple times, and therefore they have special code to read them * which is different to the code for reading the singular tags listed above. */ MultiConfig MultiValues[] = { {"uplink", - {"host", "ipv6", "port", "password", NULL}, - {"", "no", "0", "", NULL}, + {"host", "ipv6", "port", "password", ""}, + {"", "no", "0", "", ""}, {DT_HOSTNAME | DT_NORELOAD, DT_BOOLEAN | DT_NORELOAD, DT_UINTEGER | DT_NORELOAD, DT_NOSPACES | DT_NORELOAD}, InitUplinks, DoUplink, DoneUplinks}, {"module", - {"name", NULL}, - {"", NULL}, + {"name", ""}, + {"", ""}, {DT_CHARPTR}, InitModules, DoModule, DoneModules}, {"opertype", - {"name", "inherits", "commands", "privs", NULL}, - {"", "", "", "", NULL}, + {"name", "inherits", "commands", "privs", ""}, + {"", "", "", "", ""}, {DT_CHARPTR, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR}, InitOperTypes, DoOperType, DoneOperTypes}, {"oper", - {"name", "type", NULL}, - {"", "", NULL}, + {"name", "type", ""}, + {"", "", ""}, {DT_CHARPTR, DT_CHARPTR}, InitOpers, DoOper, DoneOpers}, - {NULL, - {NULL}, - {NULL}, + {"", + {""}, + {""}, {0}, NULL, NULL, NULL} }; @@ -821,9 +812,9 @@ int ServerConfig::Read(bool bail) try { // Read the values of all the tags which occur once or not at all, and call their callbacks. - for (int Index = 0; Values[Index].tag; ++Index) + for (int Index = 0; !Values[Index].tag.empty(); ++Index) { - char item[BUFSIZE]; + Anope::string item; int dt = Values[Index].datatype; bool allow_newlines = dt & DT_ALLOW_NEWLINE, allow_wild = dt & DT_ALLOW_WILD, noreload = dt & DT_NORELOAD; dt &= ~DT_ALLOW_NEWLINE; @@ -837,7 +828,7 @@ int ServerConfig::Read(bool bail) continue; } - ConfValue(config_data, Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, BUFSIZE, allow_newlines); + ConfValue(config_data, Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, allow_newlines); ValueItem vi(item); if (!Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, vi)) @@ -847,23 +838,23 @@ int ServerConfig::Read(bool bail) { case DT_NOSPACES: { - ValueContainerChar *vcc = dynamic_cast<ValueContainerChar *>(Values[Index].val); - ValidateNoSpaces(vi.GetString(), Values[Index].tag, Values[Index].value); - vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1); + ValueContainerString *vcs = dynamic_cast<ValueContainerString *>(Values[Index].val); + ValidateNoSpaces(vi.GetValue(), Values[Index].tag, Values[Index].value); + vcs->Set(vi.GetValue()); } break; case DT_HOSTNAME: { - ValueContainerChar *vcc = dynamic_cast<ValueContainerChar *>(Values[Index].val); - ValidateHostname(vi.GetString(), Values[Index].tag, Values[Index].value); - vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1); + ValueContainerString *vcs = dynamic_cast<ValueContainerString *>(Values[Index].val); + ValidateHostname(vi.GetValue(), Values[Index].tag, Values[Index].value); + vcs->Set(vi.GetValue()); } break; case DT_IPADDRESS: { - ValueContainerChar *vcc = dynamic_cast<ValueContainerChar *>(Values[Index].val); - ValidateIP(vi.GetString(), Values[Index].tag, Values[Index].value, allow_wild); - vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1); + ValueContainerString *vcs = dynamic_cast<ValueContainerString *>(Values[Index].val); + ValidateIP(vi.GetValue(), Values[Index].tag, Values[Index].value, allow_wild); + vcs->Set(vi.GetValue()); } break; case DT_CHARPTR: @@ -873,10 +864,10 @@ int ServerConfig::Read(bool bail) vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1); } break; - case DT_STRING: + case DT_CSSTRING: { - ValueContainerString *vcs = dynamic_cast<ValueContainerString *>(Values[Index].val); - vcs->Set(vi.GetValue()); + ValueContainerCSString *vcs = dynamic_cast<ValueContainerCSString *>(Values[Index].val); + vcs->Set(vi.GetCSValue()); } break; case DT_CISTRING: @@ -885,6 +876,12 @@ int ServerConfig::Read(bool bail) vcs->Set(vi.GetCIValue()); } break; + case DT_STRING: + { + ValueContainerString *vcs = dynamic_cast<ValueContainerString *>(Values[Index].val); + vcs->Set(vi.GetValue()); + } + break; case DT_INTEGER: { int val = vi.GetInteger(); @@ -908,7 +905,7 @@ int ServerConfig::Read(bool bail) break; case DT_TIME: { - time_t time = dotime(vi.GetString()); + time_t time = dotime(vi.GetValue()); ValueContainerTime *vci = dynamic_cast<ValueContainerTime *>(Values[Index].val); vci->Set(&time, sizeof(time_t)); } @@ -931,7 +928,7 @@ int ServerConfig::Read(bool bail) /* Read the multiple-tag items (class tags, connect tags, etc) * and call the callbacks associated with them. We have three * callbacks for these, a 'start', 'item' and 'end' callback. */ - for (int Index = 0; MultiValues[Index].tag; ++Index) + for (int Index = 0; !MultiValues[Index].tag.empty(); ++Index) { MultiValues[Index].init_function(this, MultiValues[Index].tag, bail); int number_of_tags = ConfValueEnum(config_data, MultiValues[Index].tag); @@ -939,7 +936,7 @@ int ServerConfig::Read(bool bail) { ValueList vl; vl.clear(); - for (int valuenum = 0; MultiValues[Index].items[valuenum]; ++valuenum) + for (int valuenum = 0; !MultiValues[Index].items[valuenum].empty(); ++valuenum) { int dt = MultiValues[Index].datatype[valuenum]; bool allow_newlines = dt & DT_ALLOW_NEWLINE, allow_wild = dt & DT_ALLOW_WILD, noreload = dt & DT_NORELOAD; @@ -953,47 +950,47 @@ int ServerConfig::Read(bool bail) { case DT_NOSPACES: { - char item[BUFSIZE]; - if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, BUFSIZE, allow_newlines)) + Anope::string item; + if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines)) vl.push_back(ValueItem(item)); else vl.push_back(ValueItem("")); - ValidateNoSpaces(vl[vl.size() - 1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]); + ValidateNoSpaces(vl[vl.size() - 1].GetValue(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]); } break; case DT_HOSTNAME: { - char item[BUFSIZE]; - if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, BUFSIZE, allow_newlines)) + Anope::string item; + if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines)) vl.push_back(ValueItem(item)); else vl.push_back(ValueItem("")); - ValidateHostname(vl[vl.size() - 1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]); + ValidateHostname(vl[vl.size() - 1].GetValue(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]); } break; case DT_IPADDRESS: { - char item[BUFSIZE]; - if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, BUFSIZE, allow_newlines)) + Anope::string item; + if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines)) vl.push_back(ValueItem(item)); else vl.push_back(ValueItem("")); - ValidateIP(vl[vl.size() - 1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum], allow_wild); + ValidateIP(vl[vl.size() - 1].GetValue(), MultiValues[Index].tag, MultiValues[Index].items[valuenum], allow_wild); } break; case DT_CHARPTR: { - char item[BUFSIZE]; - if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, BUFSIZE, allow_newlines)) - vl.push_back(ValueItem(item)); + Anope::string item; + if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines)) + vl.push_back(ValueItem(item.c_str())); else vl.push_back(ValueItem("")); } break; - case DT_STRING: + case DT_CSSTRING: { - ci::string item; - if (ConfValue(config_data, ci::string(MultiValues[Index].tag), ci::string(MultiValues[Index].items[valuenum]), ci::string(MultiValues[Index].items_default[valuenum]), tagnum, item, allow_newlines)) + Anope::string item; + if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines)) vl.push_back(ValueItem(item)); else vl.push_back(ValueItem("")); @@ -1001,8 +998,17 @@ int ServerConfig::Read(bool bail) break; case DT_CISTRING: { - ci::string item; - if (ConfValue(config_data, ci::string(MultiValues[Index].tag), ci::string(MultiValues[Index].items[valuenum]), ci::string(MultiValues[Index].items_default[valuenum]), tagnum, item, allow_newlines)) + Anope::string item; + if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines)) + vl.push_back(ValueItem(item)); + else + vl.push_back(ValueItem("")); + } + break; + case DT_STRING: + { + Anope::string item; + if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines)) vl.push_back(ValueItem(item)); else vl.push_back(ValueItem("")); @@ -1021,13 +1027,13 @@ int ServerConfig::Read(bool bail) break; case DT_TIME: { - ci::string item; - if (ConfValue(config_data, ci::string(MultiValues[Index].tag), ci::string(MultiValues[Index].items[valuenum]), ci::string(MultiValues[Index].items_default[valuenum]), tagnum, item, allow_newlines)) + Anope::string item; + if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines)) { #ifdef _WIN32 - long time = static_cast<long>(dotime(item.c_str())); + long time = static_cast<long>(dotime(item)); #else - time_t time = dotime(item.c_str()); + time_t time = dotime(item); #endif vl.push_back(ValueItem(time)); } @@ -1042,7 +1048,7 @@ int ServerConfig::Read(bool bail) } } } - MultiValues[Index].validation_function(this, MultiValues[Index].tag, static_cast<const char **>(MultiValues[Index].items), vl, MultiValues[Index].datatype, bail); + MultiValues[Index].validation_function(this, MultiValues[Index].tag, MultiValues[Index].items, vl, MultiValues[Index].datatype, bail); } MultiValues[Index].finish_function(this, MultiValues[Index].tag, bail); } @@ -1052,7 +1058,7 @@ int ServerConfig::Read(bool bail) ReportConfigError(ce.GetReason(), bail); if (!CheckedAllValues) { - for (int Index = 0; Values[Index].tag; ++Index) + for (int Index = 0; !Values[Index].tag.empty(); ++Index) { if (Values[Index].val) delete Values[Index].val; @@ -1061,18 +1067,18 @@ int ServerConfig::Read(bool bail) return 0; } Alog(LOG_DEBUG) << "End config"; - for (int Index = 0; Once[Index]; ++Index) + for (int Index = 0; !Once[Index].empty(); ++Index) if (!CheckOnce(Once[Index])) return 0; Alog() << "Done reading configuration file."; return 1; } -bool ServerConfig::LoadConf(ConfigDataHash &target, const char *filename, std::ostringstream &errorstream) +bool ServerConfig::LoadConf(ConfigDataHash &target, const Anope::string &filename, std::ostringstream &errorstream) { - std::string line; - ci::string section, wordbuffer, itemname; - std::ifstream conf(filename); + Anope::string line; + Anope::string section, wordbuffer, itemname; + std::ifstream conf(filename.c_str()); int linenumber = 0; bool in_word = false, in_quote = false, in_ml_comment = false; KeyValList sectiondata; @@ -1083,10 +1089,10 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char *filename, std::o } Alog(LOG_DEBUG) << "Start to read conf " << filename; // Start reading characters... - while (getline(conf, line)) + while (getline(conf, line.str())) { ++linenumber; - unsigned c = 0, len = line.size(); + unsigned c = 0, len = line.length(); for (; c < len; ++c) { char ch = line[c]; @@ -1190,7 +1196,7 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char *filename, std::o wordbuffer.clear(); itemname.clear(); } - target.insert(std::pair<ci::string, KeyValList>(section, sectiondata)); + target.insert(std::pair<Anope::string, KeyValList>(section, sectiondata)); section.clear(); sectiondata.clear(); } @@ -1256,35 +1262,12 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char *filename, std::o return true; } -bool ServerConfig::LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream) -{ - return LoadConf(target, filename.c_str(), errorstream); -} - -bool ServerConfig::LoadConf(ConfigDataHash &target, const ci::string &filename, std::ostringstream &errorstream) -{ - return LoadConf(target, filename.c_str(), errorstream); -} - -bool ServerConfig::ConfValue(ConfigDataHash &target, const char *tag, const char *var, int index, char *result, int length, bool allow_linefeeds) -{ - return ConfValue(target, tag, var, "", index, result, length, allow_linefeeds); -} - -bool ServerConfig::ConfValue(ConfigDataHash &target, const char *tag, const char *var, const char *default_value, int index, char *result, int length, bool allow_linefeeds) -{ - ci::string value; - bool r = ConfValue(target, ci::string(tag), ci::string(var), ci::string(default_value), index, value, allow_linefeeds); - strlcpy(result, value.c_str(), length); - return r; -} - -bool ServerConfig::ConfValue(ConfigDataHash &target, const ci::string &tag, const ci::string &var, int index, ci::string &result, bool allow_linefeeds) +bool ServerConfig::ConfValue(ConfigDataHash &target, const Anope::string &tag, const Anope::string &var, int index, Anope::string &result, bool allow_linefeeds) { return ConfValue(target, tag, var, "", index, result, allow_linefeeds); } -bool ServerConfig::ConfValue(ConfigDataHash &target, const ci::string &tag, const ci::string &var, const ci::string &default_value, int index, ci::string &result, bool allow_linefeeds) +bool ServerConfig::ConfValue(ConfigDataHash &target, const Anope::string &tag, const Anope::string &var, const Anope::string &default_value, int index, Anope::string &result, bool allow_linefeeds) { ConfigDataHash::size_type pos = index; if (pos < target.count(tag)) @@ -1297,15 +1280,12 @@ bool ServerConfig::ConfValue(ConfigDataHash &target, const ci::string &tag, cons KeyValList::iterator j = iter->second.begin(), jend = iter->second.end(); for (; j != jend; ++j) { - if (j->first == var) + if (j->first.equals_ci(var)) { - if (!allow_linefeeds && j->second.find('\n') != std::string::npos) + if (!allow_linefeeds && j->second.find('\n') != Anope::string::npos) { Alog(LOG_DEBUG) << "Value of <" << tag << ":" << var << "> contains a linefeed, and linefeeds in this value are not permitted -- stripped to spaces."; - ci::string::iterator n = j->second.begin(), nend = j->second.end(); - for (; n != nend; ++n) - if (*n == '\n') - *n = ' '; + j->second.replace_all_cs("\n", " "); } else { @@ -1331,34 +1311,24 @@ bool ServerConfig::ConfValue(ConfigDataHash &target, const ci::string &tag, cons return false; } -bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const char *tag, const char *var, int index, int &result) -{ - return ConfValueInteger(target, ci::string(tag), ci::string(var), "", index, result); -} - -bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const char *tag, const char *var, const char *default_value, int index, int &result) -{ - return ConfValueInteger(target, ci::string(tag), ci::string(var), ci::string(default_value), index, result); -} - -bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const ci::string &tag, const ci::string &var, int index, int &result) +bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const Anope::string &tag, const Anope::string &var, int index, int &result) { return ConfValueInteger(target, tag, var, "", index, result); } -bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const ci::string &tag, const ci::string &var, const ci::string &default_value, int index, int &result) +bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const Anope::string &tag, const Anope::string &var, const Anope::string &default_value, int index, int &result) { - ci::string value; + Anope::string value; std::istringstream stream; bool r = ConfValue(target, tag, var, default_value, index, value); - stream.str(value.c_str()); + stream.str(value.str()); if (!(stream >> result)) return false; else { if (!value.empty()) { - if (value.substr(0, 2) == "0x") + if (value.substr(0, 2).equals_ci("0x")) { char *endptr; @@ -1392,51 +1362,26 @@ bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const ci::string &ta return r; } -bool ServerConfig::ConfValueBool(ConfigDataHash &target, const char *tag, const char *var, int index) -{ - return ConfValueBool(target, ci::string(tag), ci::string(var), "", index); -} - -bool ServerConfig::ConfValueBool(ConfigDataHash &target, const char *tag, const char *var, const char *default_value, int index) -{ - return ConfValueBool(target, ci::string(tag), ci::string(var), ci::string(default_value), index); -} - -bool ServerConfig::ConfValueBool(ConfigDataHash &target, const ci::string &tag, const ci::string &var, int index) +bool ServerConfig::ConfValueBool(ConfigDataHash &target, const Anope::string &tag, const Anope::string &var, int index) { return ConfValueBool(target, tag, var, "", index); } -bool ServerConfig::ConfValueBool(ConfigDataHash &target, const ci::string &tag, const ci::string &var, const ci::string &default_value, int index) +bool ServerConfig::ConfValueBool(ConfigDataHash &target, const Anope::string &tag, const Anope::string &var, const Anope::string &default_value, int index) { - ci::string result; + Anope::string result; if (!ConfValue(target, tag, var, default_value, index, result)) return false; - return result == "yes" || result == "true" || result == "1"; -} - -int ServerConfig::ConfValueEnum(ConfigDataHash &target, const char *tag) -{ - return target.count(tag); -} - -int ServerConfig::ConfValueEnum(ConfigDataHash &target, const std::string &tag) -{ - return target.count(tag.c_str()); + return result.equals_ci("yes") || result.equals_ci("true") || result.equals_ci("1"); } -int ServerConfig::ConfValueEnum(ConfigDataHash &target, const ci::string &tag) +int ServerConfig::ConfValueEnum(ConfigDataHash &target, const Anope::string &tag) { return target.count(tag); } -int ServerConfig::ConfVarEnum(ConfigDataHash &target, const char *tag, int index) -{ - return ConfVarEnum(target, ci::string(tag), index); -} - -int ServerConfig::ConfVarEnum(ConfigDataHash &target, const ci::string &tag, int index) +int ServerConfig::ConfVarEnum(ConfigDataHash &target, const Anope::string &tag, int index) { ConfigDataHash::size_type pos = index; @@ -1478,7 +1423,9 @@ ValueItem::ValueItem(const char *value) : v(value) { } ValueItem::ValueItem(const std::string &value) : v(value) { } -ValueItem::ValueItem(const ci::string &value) : v(value.c_str()) { } +ValueItem::ValueItem(const ci::string &value) : v(value) { } + +ValueItem::ValueItem(const Anope::string &value) : v(value) { } void ValueItem::Set(const char *value) { @@ -1492,7 +1439,12 @@ void ValueItem::Set(const std::string &value) void ValueItem::Set(const ci::string &value) { - v = value.c_str(); + v = value; +} + +void ValueItem::Set(const Anope::string &value) +{ + v = value; } void ValueItem::Set(int value) @@ -1504,9 +1456,9 @@ void ValueItem::Set(int value) int ValueItem::GetInteger() { - if (v.empty()) + if (v.empty() || !v.is_number_only()) return 0; - return atoi(v.c_str()); + return convertTo<int>(v); } const char *ValueItem::GetString() const @@ -1548,26 +1500,6 @@ void error(int linenum, const char *message, ...) /*************************************************************************/ -#define CHECK(v) \ -do \ -{ \ - if (!v) \ - {\ - error(0, #v " missing"); \ - retval = 0; \ - } \ -} while (0) - -#define CHEK2(v, n) \ -do \ -{ \ - if (!v) \ - { \ - error(0, #n " missing"); \ - retval = 0; \ - } \ -} while (0) - /* Read the entire configuration file. If an error occurs while reading * the file or a required directive is not found, print and log an * appropriate error message and return 0; otherwise, return 1. @@ -1579,24 +1511,24 @@ do \ int read_config(int reload) { int retval = 1; - char *s; int defconCount = 0; retval = Config.Read(reload ? false : true); - if (!retval) return 0; // Temporary until most of the below is modified to use the new parser -- CyberBotX + if (!retval) + return 0; // Temporary until most of the below is modified to use the new parser -- CyberBotX - if (temp_nsuserhost) + if (!temp_nsuserhost.empty()) { - if (!(s = strchr(temp_nsuserhost, '@'))) + size_t at = temp_nsuserhost.find('@'); + if (at == Anope::string::npos) { Config.NSEnforcerUser = temp_nsuserhost; Config.NSEnforcerHost = Config.ServiceHost; } else { - *s++ = 0; - Config.NSEnforcerUser = temp_nsuserhost; - Config.NSEnforcerHost = s; + Config.NSEnforcerUser = temp_nsuserhost.substr(0, at); + Config.NSEnforcerHost = temp_nsuserhost.substr(at + 1); } } @@ -1606,38 +1538,38 @@ int read_config(int reload) Config.NSDefFlags.SetFlag(NI_MEMO_SIGNON); Config.NSDefFlags.SetFlag(NI_MEMO_RECEIVE); } - else if (NSDefaults != "none") + else if (!NSDefaults.equals_ci("none")) { spacesepstream options(NSDefaults); - ci::string option; + Anope::string option; while (options.GetToken(option)) { - if (option == "kill") + if (option.equals_ci("kill")) Config.NSDefFlags.SetFlag(NI_KILLPROTECT); - else if (option == "killquick") + else if (option.equals_ci("killquick")) Config.NSDefFlags.SetFlag(NI_KILL_QUICK); - else if (option == "secure") + else if (option.equals_ci("secure")) Config.NSDefFlags.SetFlag(NI_SECURE); - else if (option == "private") + else if (option.equals_ci("private")) Config.NSDefFlags.SetFlag(NI_PRIVATE); - else if (option == "msg") + else if (option.equals_ci("msg")) { if (!Config.UsePrivmsg) Alog() << "msg in <nickserv:defaults> can only be used when UsePrivmsg is set"; else Config.NSDefFlags.SetFlag(NI_MSG); } - else if (option == "hideemail") + else if (option.equals_ci("hideemail")) Config.NSDefFlags.SetFlag(NI_HIDE_EMAIL); - else if (option == "hideusermask") + else if (option.equals_ci("hideusermask")) Config.NSDefFlags.SetFlag(NI_HIDE_MASK); - else if (option == "hidequit") + else if (option.equals_ci("hidequit")) Config.NSDefFlags.SetFlag(NI_HIDE_QUIT); - else if (option == "memosignon") + else if (option.equals_ci("memosignon")) Config.NSDefFlags.SetFlag(NI_MEMO_SIGNON); - else if (option == "memoreceive") + else if (option.equals_ci("memoreceive")) Config.NSDefFlags.SetFlag(NI_MEMO_RECEIVE); - else if (option == "autoop") + else if (option.equals_ci("autoop")) Config.NSDefFlags.SetFlag(NI_AUTOOP); } } @@ -1661,37 +1593,37 @@ int read_config(int reload) Config.CSDefFlags.SetFlag(CI_SECUREFOUNDER); Config.CSDefFlags.SetFlag(CI_SIGNKICK); } - else if (CSDefaults != "none") + else if (!CSDefaults.equals_ci("none")) { spacesepstream options(CSDefaults); - ci::string option; + Anope::string option; while (options.GetToken(option)) { - if (option == "keeptopic") + if (option.equals_ci("keeptopic")) Config.CSDefFlags.SetFlag(CI_KEEPTOPIC); - else if (option == "topiclock") + else if (option.equals_ci("topiclock")) Config.CSDefFlags.SetFlag(CI_TOPICLOCK); - else if (option == "private") + else if (option.equals_ci("private")) Config.CSDefFlags.SetFlag(CI_PRIVATE); - else if (option == "restricted") + else if (option.equals_ci("restricted")) Config.CSDefFlags.SetFlag(CI_RESTRICTED); - else if (option == "secure") + else if (option.equals_ci("secure")) Config.CSDefFlags.SetFlag(CI_SECURE); - else if (option == "secureops") + else if (option.equals_ci("secureops")) Config.CSDefFlags.SetFlag(CI_SECUREOPS); - else if (option == "securefounder") + else if (option.equals_ci("securefounder")) Config.CSDefFlags.SetFlag(CI_SECUREFOUNDER); - else if (option == "signkick") + else if (option.equals_ci("signkick")) Config.CSDefFlags.SetFlag(CI_SIGNKICK); - else if (option == "signkicklevel") + else if (option.equals_ci("signkicklevel")) Config.CSDefFlags.SetFlag(CI_SIGNKICK_LEVEL); - else if (option == "opnotice") + else if (option.equals_ci("opnotice")) Config.CSDefFlags.SetFlag(CI_OPNOTICE); - else if (option == "xop") + else if (option.equals_ci("xop")) Config.CSDefFlags.SetFlag(CI_XOP); - else if (option == "peace") + else if (option.equals_ci("peace")) Config.CSDefFlags.SetFlag(CI_PEACE); - else if (option == "persist") + else if (option.equals_ci("persist")) Config.CSDefFlags.SetFlag(CI_PERSIST); } } @@ -1699,18 +1631,18 @@ int read_config(int reload) if (!BSDefaults.empty()) { spacesepstream options(BSDefaults); - ci::string option; + Anope::string option; while (options.GetToken(option)) { - if (option == "dontkickops") + if (option.equals_ci("dontkickops")) Config.BSDefFlags.SetFlag(BS_DONTKICKOPS); - else if (option == "dontkickvoices") + else if (option.equals_ci("dontkickvoices")) Config.BSDefFlags.SetFlag(BS_DONTKICKVOICES); - else if (option == "greet") + else if (option.equals_ci("greet")) Config.BSDefFlags.SetFlag(BS_GREET); - else if (option == "fantasy") + else if (option.equals_ci("fantasy")) Config.BSDefFlags.SetFlag(BS_FANTASY); - else if (option == "symbiosis") + else if (option.equals_ci("symbiosis")) Config.BSDefFlags.SetFlag(BS_SYMBIOSIS); } } @@ -1721,82 +1653,75 @@ int read_config(int reload) if (!OSNotifications.empty()) { spacesepstream notifications(OSNotifications); - ci::string notice; + Anope::string notice; while (notifications.GetToken(notice)) { - if (notice == "oper") + if (notice.equals_ci("oper")) Config.WallOper = true; - else if (notice == "bados") + else if (notice.equals_ci("bados")) Config.WallBadOS = true; - else if (notice == "osglobal") + else if (notice.equals_ci("osglobal")) Config.WallOSGlobal = true; - else if (notice == "osmode") + else if (notice.equals_ci("osmode")) Config.WallOSMode = true; - else if (notice == "osclearmodes") + else if (notice.equals_ci("osclearmodes")) Config.WallOSClearmodes = true; - else if (notice == "oskick") + else if (notice.equals_ci("oskick")) Config.WallOSKick = true; - else if (notice == "osakill") + else if (notice.equals_ci("osakill")) Config.WallOSAkill = true; - else if (notice == "ossnline") + else if (notice.equals_ci("ossnline")) Config.WallOSSNLine = true; - else if (notice == "ossqline") + else if (notice.equals_ci("ossqline")) Config.WallOSSQLine = true; - else if (notice == "osszline") + else if (notice.equals_ci("osszline")) Config.WallOSSZLine = true; - else if (notice == "osnoop") + else if (notice.equals_ci("osnoop")) Config.WallOSNoOp = true; - else if (notice == "osjupe") + else if (notice.equals_ci("osjupe")) Config.WallOSJupe = true; - else if (notice == "akillexpire") + else if (notice.equals_ci("akillexpire")) Config.WallAkillExpire = true; - else if (notice == "snlineexpire") + else if (notice.equals_ci("snlineexpire")) Config.WallSNLineExpire = true; - else if (notice == "sqlineexpire") + else if (notice.equals_ci("sqlineexpire")) Config.WallSQLineExpire = true; - else if (notice == "szlineexpire") + else if (notice.equals_ci("szlineexpire")) Config.WallSZLineExpire = true; - else if (notice == "exceptionexpire") + else if (notice.equals_ci("exceptionexpire")) Config.WallExceptionExpire = true; - else if (notice == "getpass") + else if (notice.equals_ci("getpass")) Config.WallGetpass = true; - else if (notice == "setpass") + else if (notice.equals_ci("setpass")) Config.WallSetpass = true; - else if (notice == "forbid") + else if (notice.equals_ci("forbid")) Config.WallForbid = true; - else if (notice == "drop") + else if (notice.equals_ci("drop")) Config.WallDrop = true; } } /* Ulines */ - - if (UlineServers) + if (!UlineServers.empty()) { - Config.NumUlines = 0; + Config.Ulines.clear(); - s = strtok(UlineServers, " "); - do - { - if (s) - { - ++Config.NumUlines; - Config.Ulines = static_cast<char **>(realloc(Config.Ulines, sizeof(char *) * Config.NumUlines)); - Config.Ulines[Config.NumUlines - 1] = sstrdup(s); - } - } while ((s = strtok(NULL, " "))); + spacesepstream ulines(UlineServers); + Anope::string uline; + while (ulines.GetToken(uline)) + Config.Ulines.push_back(uline); } /* Modules Autoload building... :P */ - Config.ModulesAutoLoad = BuildStringList(!Modules.empty() ? Modules : ""); - Config.EncModuleList = BuildStringList(!EncModules.empty() ? EncModules : ""); - Config.DBModuleList = BuildStringList(!DBModules.empty() ? DBModules : ""); - Config.HostServCoreModules = BuildStringList(!HostCoreModules.empty() ? HostCoreModules : ""); - Config.MemoServCoreModules = BuildStringList(!MemoCoreModules.empty() ? MemoCoreModules : ""); - Config.BotServCoreModules = BuildStringList(!BotCoreModules.empty() ? BotCoreModules : ""); - Config.OperServCoreModules = BuildStringList(!OperCoreModules.empty() ? OperCoreModules : ""); - Config.ChanServCoreModules = BuildStringList(!ChanCoreModules.empty() ? ChanCoreModules : ""); - Config.NickServCoreModules = BuildStringList(!NickCoreModules.empty() ? NickCoreModules : ""); + Config.ModulesAutoLoad = BuildStringList(Modules); + Config.EncModuleList = BuildStringList(EncModules); + Config.DBModuleList = BuildStringList(DBModules); + Config.HostServCoreModules = BuildStringList(HostCoreModules); + Config.MemoServCoreModules = BuildStringList(MemoCoreModules); + Config.BotServCoreModules = BuildStringList(BotCoreModules); + Config.OperServCoreModules = BuildStringList(OperCoreModules); + Config.ChanServCoreModules = BuildStringList(ChanCoreModules); + Config.NickServCoreModules = BuildStringList(NickCoreModules); if (Config.LimitSessions) { @@ -1804,12 +1729,12 @@ int read_config(int reload) Config.SessionAutoKillExpiry = 1800; /* 30 minutes */ } - if (Config.s_BotServ) + if (!Config.s_BotServ.empty()) { - if (!Config.BSFantasyCharacter || !*Config.BSFantasyCharacter) - Config.BSFantasyCharacter = sstrdup("!"); - if (*Config.BSFantasyCharacter && strlen(Config.BSFantasyCharacter) > 1) - printf("*** Config.BSFantasyCharacter is more than 1 character long. Only the first\n*** character ('%c') will be used. The others will be ignored.\n", *Config.BSFantasyCharacter); + if (Config.BSFantasyCharacter.empty()) + Config.BSFantasyCharacter = "!"; + if (Config.BSFantasyCharacter.length() > 1) + printf("*** Config.BSFantasyCharacter is more than 1 character long. Only the first\n*** character ('%c') will be used. The others will be ignored.\n", Config.BSFantasyCharacter[0]); } /* Check the user keys */ @@ -1827,7 +1752,7 @@ int read_config(int reload) for (unsigned int level = 1; level < 5; ++level) { DefCon[level] = 0; - ci::string *levelDefinition = NULL; + Anope::string *levelDefinition = NULL; switch (level) { case 1: @@ -1843,28 +1768,28 @@ int read_config(int reload) levelDefinition = &DefCon4; } spacesepstream operations(*levelDefinition); - ci::string operation; + Anope::string operation; while (operations.GetToken(operation)) { - if (operation == "nonewchannels") + if (operation.equals_ci("nonewchannels")) AddDefCon(level, DEFCON_NO_NEW_CHANNELS); - else if (operation == "nonewnicks") + else if (operation.equals_ci("nonewnicks")) AddDefCon(level, DEFCON_NO_NEW_NICKS); - else if (operation == "nomlockchanges") + else if (operation.equals_ci("nomlockchanges")) AddDefCon(level, DEFCON_NO_MLOCK_CHANGE); - else if (operation == "forcechanmodes") + else if (operation.equals_ci("forcechanmodes")) AddDefCon(level, DEFCON_FORCE_CHAN_MODES); - else if (operation == "reducedsessions") + else if (operation.equals_ci("reducedsessions")) AddDefCon(level, DEFCON_REDUCE_SESSION); - else if (operation == "nonewclients") + else if (operation.equals_ci("nonewclients")) AddDefCon(level, DEFCON_NO_NEW_CLIENTS); - else if (operation == "operonly") + else if (operation.equals_ci("operonly")) AddDefCon(level, DEFCON_OPER_ONLY); - else if (operation == "silentoperonly") + else if (operation.equals_ci("silentoperonly")) AddDefCon(level, DEFCON_SILENT_OPER_ONLY); - else if (operation == "akillnewclients") + else if (operation.equals_ci("akillnewclients")) AddDefCon(level, DEFCON_AKILL_NEW_CLIENTS); - else if (operation == "nonewmemos") + else if (operation.equals_ci("nonewmemos")) AddDefCon(level, DEFCON_NO_NEW_MEMOS); } } @@ -1873,21 +1798,41 @@ int read_config(int reload) for (defconCount = 1; defconCount <= 5; ++defconCount) { if (CheckDefCon(defconCount, DEFCON_REDUCE_SESSION)) - CHECK(Config.DefConSessionLimit); + { + if (!Config.DefConSessionLimit) + { + error(0, "Config.DefConSessionLimit missing"); + retval = 0; + } + } if (CheckDefCon(defconCount, DEFCON_AKILL_NEW_CLIENTS)) { - CHECK(Config.DefConAKILL); - CHECK(Config.DefConAkillReason); + if (!Config.DefConAKILL) + { + error(0, "Config.DefConAKILL missing"); + retval = 0; + } + if (Config.DefConAkillReason.empty()) + { + error(0, "Config.DefConAkillReason missing"); + retval = 0; + } } if (CheckDefCon(defconCount, DEFCON_FORCE_CHAN_MODES)) - CHECK(Config.DefConChanModes); + { + if (Config.DefConChanModes.empty()) + { + error(0, "Config.DefConChanModes missing"); + retval = 0; + } + } } } SetDefaultMLock(); /* Disable the log channel if its defined in the conf, but not enabled */ - if (!Config.LogChannel && LogChan) + if (Config.LogChannel.empty() && LogChan) LogChan = false; if (!retval) diff --git a/src/configreader.cpp b/src/configreader.cpp index fc9a7cb28..9e17b34be 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -25,42 +25,42 @@ ConfigReader::~ConfigReader() delete this->data; } -ConfigReader::ConfigReader(const std::string &filename) : data(new ConfigDataHash), errorlog(new std::ostringstream(std::stringstream::in | std::stringstream::out)), privatehash(true), error(CONF_NO_ERROR) +ConfigReader::ConfigReader(const Anope::string &filename) : data(new ConfigDataHash), errorlog(new std::ostringstream(std::stringstream::in | std::stringstream::out)), privatehash(true), error(CONF_NO_ERROR) { Config.ClearStack(); } -std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds) +Anope::string ConfigReader::ReadValue(const Anope::string &tag, const Anope::string &name, const Anope::string &default_value, int index, bool allow_linefeeds) { /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */ - ci::string result; + Anope::string result; - if (!Config.ConfValue(*this->data, ci::string(tag.c_str()), ci::string(name.c_str()), ci::string(default_value.c_str()), index, result, allow_linefeeds)) + if (!Config.ConfValue(*this->data, tag, name, default_value, index, result, allow_linefeeds)) this->error = CONF_VALUE_NOT_FOUND; - return result.c_str(); + return result; } -std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds) +Anope::string ConfigReader::ReadValue(const Anope::string &tag, const Anope::string &name, int index, bool allow_linefeeds) { return ReadValue(tag, name, "", index, allow_linefeeds); } -bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index) +bool ConfigReader::ReadFlag(const Anope::string &tag, const Anope::string &name, const Anope::string &default_value, int index) { - return Config.ConfValueBool(*this->data, ci::string(tag.c_str()), ci::string(name.c_str()), ci::string(default_value.c_str()), index); + return Config.ConfValueBool(*this->data, tag, name, default_value, index); } -bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index) +bool ConfigReader::ReadFlag(const Anope::string &tag, const Anope::string &name, int index) { return ReadFlag(tag, name, "", index); } -int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive) +int ConfigReader::ReadInteger(const Anope::string &tag, const Anope::string &name, const Anope::string &default_value, int index, bool need_positive) { int result; - if (!Config.ConfValueInteger(*this->data, ci::string(tag.c_str()), ci::string(name.c_str()), ci::string(default_value.c_str()), index, result)) + if (!Config.ConfValueInteger(*this->data, tag, name, default_value, index, result)) { this->error = CONF_VALUE_NOT_FOUND; return 0; @@ -75,7 +75,7 @@ int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, c return result; } -int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool need_positive) +int ConfigReader::ReadInteger(const Anope::string &tag, const Anope::string &name, int index, bool need_positive) { return ReadInteger(tag, name, "", index, need_positive); } @@ -92,14 +92,14 @@ void ConfigReader::DumpErrors(bool bail) Config.ReportConfigError(this->errorlog->str(), bail); } -int ConfigReader::Enumerate(const std::string &tag) +int ConfigReader::Enumerate(const Anope::string &tag) { return Config.ConfValueEnum(*this->data, tag); } -int ConfigReader::EnumerateValues(const std::string &tag, int index) +int ConfigReader::EnumerateValues(const Anope::string &tag, int index) { - return Config.ConfVarEnum(*this->data, ci::string(tag.c_str()), index); + return Config.ConfVarEnum(*this->data, tag, index); } bool ConfigReader::Verify() diff --git a/src/encrypt.cpp b/src/encrypt.cpp index f70d8fa8c..0121c0c4a 100644 --- a/src/encrypt.cpp +++ b/src/encrypt.cpp @@ -18,7 +18,7 @@ * Encrypt string `src' of length `len', placing the result in buffer * `dest' of size `size'. Returns 0 on success, -1 on error. **/ -int enc_encrypt(const std::string &src, std::string &dest) +int enc_encrypt(const Anope::string &src, Anope::string &dest) { EventReturn MOD_RESULT; FOREACH_RESULT(I_OnEncrypt, OnEncrypt(src, dest)); @@ -33,15 +33,15 @@ int enc_encrypt(const std::string &src, std::string &dest) * allow decryption, and -1 if another failure occurred (e.g. destination * buffer too small). **/ -int enc_decrypt(const std::string &src, std::string &dest) +int enc_decrypt(const Anope::string &src, Anope::string &dest) { - size_t pos = src.find(":"); - if (pos == std::string::npos) + size_t pos = src.find(':'); + if (pos == Anope::string::npos) { Alog() << "Error: enc_decrypt() called with invalid password string (" << src << ")"; return -1; } - std::string hashm(src.begin(), src.begin() + pos); + Anope::string hashm(src.begin(), src.begin() + pos); EventReturn MOD_RESULT; FOREACH_RESULT(I_OnDecrypt, OnDecrypt(hashm, src, dest)); @@ -57,16 +57,15 @@ int enc_decrypt(const std::string &src, std::string &dest) * 0 if the password does not match * 0 if an error occurred while checking **/ -int enc_check_password(std::string &plaintext, std::string &password) +int enc_check_password(Anope::string &plaintext, Anope::string &password) { - std::string hashm; - size_t pos = password.find(":"); - if (pos == std::string::npos) + size_t pos = password.find(':'); + if (pos == Anope::string::npos) { Alog() << "Error: enc_check_password() called with invalid password string (" << password << ")"; return 0; } - hashm.assign(password.begin(), password.begin() + pos); + Anope::string hashm(password.begin(), password.begin() + pos); EventReturn MOD_RESULT; FOREACH_RESULT(I_OnCheckPassword, OnCheckPassword(hashm, plaintext, password)); diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 3698ef565..72bcf0936 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -8,7 +8,7 @@ * for use in Anope. */ -#include "hashcomp.h" +#include "anope.h" /****************************************************** * @@ -103,33 +103,23 @@ const char *ci::ci_char_traits::find(const char *s1, int n, char c) return n >= 0 ? s1 : NULL; } -sepstream::sepstream(const std::string &source, char seperator) : tokens(source), sep(seperator) +sepstream::sepstream(const Anope::string &source, char seperator) : tokens(source), sep(seperator) { last_starting_position = n = tokens.begin(); } -sepstream::sepstream(const ci::string &source, char seperator) : tokens(source.c_str()), sep(seperator) +bool sepstream::GetToken(Anope::string &token) { - last_starting_position = n = tokens.begin(); -} - -sepstream::sepstream(const char *source, char seperator) : tokens(source), sep(seperator) -{ - last_starting_position = n = tokens.begin(); -} - -bool sepstream::GetToken(std::string &token) -{ - std::string::iterator lsp = last_starting_position; + Anope::string::iterator lsp = last_starting_position; while (n != tokens.end()) { if (*n == sep || n + 1 == tokens.end()) { last_starting_position = n + 1; - token = std::string(lsp, n + 1 == tokens.end() ? n + 1 : n); + token = Anope::string(lsp, n + 1 == tokens.end() ? n + 1 : n); - while (token.length() && token.find_last_of(sep) == token.length() - 1) + while (token.length() && token.rfind(sep) == token.length() - 1) token.erase(token.end() - 1); ++n; @@ -140,21 +130,13 @@ bool sepstream::GetToken(std::string &token) ++n; } - token = ""; + token.clear(); return false; } -bool sepstream::GetToken(ci::string &token) +const Anope::string sepstream::GetRemaining() { - std::string tmp_token; - bool result = GetToken(tmp_token); - token = tmp_token.c_str(); - return result; -} - -const std::string sepstream::GetRemaining() -{ - return std::string(n, tokens.end()); + return Anope::string(n, tokens.end()); } bool sepstream::StreamEnd() @@ -162,7 +144,6 @@ bool sepstream::StreamEnd() return n == tokens.end(); } -#if defined(_WIN32) && _MSV_VER < 1600 /** Compare two std::string's values for hashing in hash_map * @param s1 The first string * @param s2 The second string @@ -171,11 +152,16 @@ bool sepstream::StreamEnd() */ bool hash_compare_std_string::operator()(const std::string &s1, const std::string &s2) const { - if (s1.length() != s2.length()) - return true; - return (std::char_traits<char>::compare(s1.c_str(), s2.c_str(), s1.length()) < 0); + register int i = std::char_traits<char>::compare(s1.c_str(), s2.c_str(), s1.length() < s2.length() ? s1.length() : s2.length()); + if (!i) + return s1.length() < s2.length(); + return i < 0; +} + +bool hash_compare_std_string::operator()(const Anope::string &s1, const Anope::string &s2) const +{ + return operator()(s1.str(), s2.str()); } -#endif /** Return a hash value for a string * @param s The string @@ -191,7 +177,11 @@ size_t hash_compare_std_string::operator()(const std::string &s) const return t; } -#if defined(_WIN32) && _MSV_VER < 1600 +size_t hash_compare_std_string::operator()(const Anope::string &s) const +{ + return operator()(s.str()); +} + /** Compare two ci::string's values for hashing in hash_map * @param s1 The first string * @param s2 The second string @@ -200,11 +190,16 @@ size_t hash_compare_std_string::operator()(const std::string &s) const */ bool hash_compare_ci_string::operator()(const ci::string &s1, const ci::string &s2) const { - if (s1.length() != s2.length()) - return true; - return (ci::ci_char_traits::compare(s1.c_str(), s2.c_str(), s1.length()) < 0); + register int i = ci::ci_char_traits::compare(s1.c_str(), s2.c_str(), s1.length() < s2.length() ? s1.length() : s2.length()); + if (!i) + return s1.length() < s2.length(); + return i < 0; +} + +bool hash_compare_ci_string::operator()(const Anope::string &s1, const Anope::string &s2) const +{ + return operator()(s1.ci_str(), s2.ci_str()); } -#endif /** Return a hash value for a string using case insensitivity * @param s The string @@ -220,7 +215,11 @@ size_t hash_compare_ci_string::operator()(const ci::string &s) const return t; } -#if defined(_WIN32) && _MSV_VER < 1600 +size_t hash_compare_ci_string::operator()(const Anope::string &s) const +{ + return operator()(s.ci_str()); +} + /** Compare two irc::string's values for hashing in hash_map * @param s1 The first string * @param s2 The second string @@ -229,11 +228,16 @@ size_t hash_compare_ci_string::operator()(const ci::string &s) const */ bool hash_compare_irc_string::operator()(const irc::string &s1, const irc::string &s2) const { - if (s1.length() != s2.length()) - return true; - return (irc::irc_char_traits::compare(s1.c_str(), s2.c_str(), s1.length()) < 0); + register int i = irc::irc_char_traits::compare(s1.c_str(), s2.c_str(), s1.length() < s2.length() ? s1.length() : s2.length()); + if (!i) + return s1.length() < s2.length(); + return i < 0; +} + +bool hash_compare_irc_string::operator()(const Anope::string &s1, const Anope::string &s2) const +{ + return operator()(s1.irc_str(), s2.irc_str()); } -#endif /** Return a hash value for a string using RFC1459 case sensitivity rules * @param s The string @@ -248,3 +252,8 @@ size_t hash_compare_irc_string::operator()(const irc::string &s) const return t; } + +size_t hash_compare_irc_string::operator()(const Anope::string &s) const +{ + return operator()(s.irc_str()); +} diff --git a/src/hostserv.cpp b/src/hostserv.cpp index f59ac8c6e..b4ccabacb 100644 --- a/src/hostserv.cpp +++ b/src/hostserv.cpp @@ -13,8 +13,6 @@ #include "modules.h" #include "language.h" -E int do_hs_sync(NickCore *nc, char *vIdent, char *hostmask, char *creator, time_t time); - E void moduleAddHostServCmds(); /*************************************************************************/ @@ -43,11 +41,11 @@ void get_hostserv_stats(long *nrec, long *memuse) continue; if (!na->hostinfo.GetIdent().empty()) - mem += na->hostinfo.GetIdent().size(); + mem += na->hostinfo.GetIdent().length(); if (!na->hostinfo.GetHost().empty()) - mem += na->hostinfo.GetHost().size(); + mem += na->hostinfo.GetHost().length(); if (!na->hostinfo.GetCreator().empty()) - mem += na->hostinfo.GetCreator().size(); + mem += na->hostinfo.GetCreator().length(); ++count; } @@ -63,7 +61,7 @@ void get_hostserv_stats(long *nrec, long *memuse) */ void hostserv_init() { - if (Config.s_HostServ) + if (!Config.s_HostServ.empty()) moduleAddHostServCmds(); } @@ -75,20 +73,20 @@ void hostserv_init() * @param buf Buffer holding the message * @return void */ -void hostserv(User *u, const std::string &buf) +void hostserv(User *u, const Anope::string &buf) { if (!u || buf.empty()) return; - if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1') + if (buf.substr(0, 6).equals_ci("\1PING ") && buf[buf.length() - 1] == '\1') { - std::string command = buf; + Anope::string command = buf; command.erase(command.begin()); command.erase(command.end()); - ircdproto->SendCTCP(HostServ, u->nick.c_str(), "%s", command.c_str()); + ircdproto->SendCTCP(HostServ, u->nick, "%s", command.c_str()); } else if (!ircd->vhost) - notice_lang(Config.s_HostServ, u, SERVICE_OFFLINE, Config.s_HostServ); + notice_lang(Config.s_HostServ, u, SERVICE_OFFLINE, Config.s_HostServ.c_str()); else mod_run_cmd(HostServ, u, buf); } @@ -99,7 +97,7 @@ void hostserv(User *u, const std::string &buf) * @param creator Who created the vhost * @param time When the vhost was craated */ -void HostInfo::SetVhost(const std::string &ident, const std::string &host, const std::string &creator, time_t created) +void HostInfo::SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created) { Ident = ident; Host = host; @@ -128,7 +126,7 @@ bool HostInfo::HasVhost() const /** Retrieve the vhost ident * @return the ident */ -const std::string &HostInfo::GetIdent() const +const Anope::string &HostInfo::GetIdent() const { return Ident; } @@ -136,7 +134,7 @@ const std::string &HostInfo::GetIdent() const /** Retrieve the vhost host * @return the host */ -const std::string &HostInfo::GetHost() const +const Anope::string &HostInfo::GetHost() const { return Host; } @@ -144,7 +142,7 @@ const std::string &HostInfo::GetHost() const /** Retrieve the vhost creator * @return the creator */ -const std::string &HostInfo::GetCreator() const +const Anope::string &HostInfo::GetCreator() const { return Creator; } @@ -186,15 +184,11 @@ void do_on_id(User *u) if (!na || !na->hostinfo.HasVhost()) return; - if (!u->vhost || u->vhost != na->hostinfo.GetHost() || (!na->hostinfo.GetIdent().empty() && u->GetVIdent() != na->hostinfo.GetIdent())) + if (u->vhost.empty() || !u->vhost.equals_cs(na->hostinfo.GetHost()) || (!na->hostinfo.GetIdent().empty() && !u->GetVIdent().equals_cs(na->hostinfo.GetIdent()))) { ircdproto->SendVhost(u, na->hostinfo.GetIdent(), na->hostinfo.GetHost()); if (ircd->vhost) - { - if (u->vhost) - delete [] u->vhost; - u->vhost = sstrdup(na->hostinfo.GetHost().c_str()); - } + u->vhost = na->hostinfo.GetHost(); if (ircd->vident && !na->hostinfo.GetIdent().empty()) u->SetVIdent(na->hostinfo.GetIdent()); u->UpdateHost(); diff --git a/src/init.cpp b/src/init.cpp index 6ea0cab35..7388f7e79 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -19,7 +19,7 @@ extern void moduleAddIRCDMsgs(); /*************************************************************************/ -void introduce_user(const std::string &user) +void introduce_user(const Anope::string &user) { /* Watch out for infinite loops... */ #define LTSIZE 20 @@ -36,11 +36,10 @@ void introduce_user(const std::string &user) { BotInfo *bi = it->second; - ci::string ci_bi_nick(bi->nick.c_str()); - if (user.empty() || ci_bi_nick == user) + if (user.empty() || bi->nick.equals_ci(user)) { ircdproto->SendClientIntroduction(bi->nick, bi->GetIdent(), bi->host, bi->realname, ircd->pseudoclient_mode, bi->GetUID()); - XLine x(bi->nick.c_str(), "Reserved for services"); + XLine x(bi->nick, "Reserved for services"); ircdproto->SendSQLine(&x); } } @@ -58,7 +57,7 @@ static int set_group() struct group *gr; setgrent(); - while ((gr = getgrent()) != NULL) + while ((gr = getgrent())) { if (!strcmp(gr->gr_name, RUNGROUP)) break; @@ -82,7 +81,7 @@ static int set_group() /*************************************************************************/ /* Vector of pairs of command line arguments and their params */ -static std::vector<std::pair<std::string, std::string> > CommandLineArguments; +static std::vector<std::pair<Anope::string, Anope::string> > CommandLineArguments; /** Called on startup to organize our starting arguments in a better way * and check for errors @@ -93,12 +92,12 @@ static void ParseCommandLineArguments(int ac, char **av) { for (int i = 1; i < ac; ++i) { - std::string option = av[i]; - std::string param = ""; + Anope::string option = av[i]; + Anope::string param; while (!option.empty() && option[0] == '-') option.erase(option.begin()); size_t t = option.find('='); - if (t != std::string::npos) + if (t != Anope::string::npos) { param = option.substr(t + 1); option.erase(t); @@ -116,9 +115,9 @@ static void ParseCommandLineArguments(int ac, char **av) * @param shortname A shorter name, eg --debug and -d * @return true if name/shortname was found, false if not */ -bool GetCommandLineArgument(const std::string &name, char shortname) +bool GetCommandLineArgument(const Anope::string &name, char shortname) { - std::string Unused; + Anope::string Unused; return GetCommandLineArgument(name, shortname, Unused); } @@ -128,13 +127,13 @@ bool GetCommandLineArgument(const std::string &name, char shortname) * @param param A string to put the param, if any, of the argument * @return true if name/shortname was found, false if not */ -bool GetCommandLineArgument(const std::string &name, char shortname, std::string ¶m) +bool GetCommandLineArgument(const Anope::string &name, char shortname, Anope::string ¶m) { param.clear(); - for (std::vector<std::pair<std::string, std::string> >::iterator it = CommandLineArguments.begin(), it_end = CommandLineArguments.end(); it != it_end; ++it) + for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = CommandLineArguments.begin(), it_end = CommandLineArguments.end(); it != it_end; ++it) { - if (it->first == name || it->first[0] == shortname) + if (it->first.equals_ci(name) || it->first[0] == shortname) { param = it->second; return true; @@ -150,7 +149,7 @@ bool GetCommandLineArgument(const std::string &name, char shortname, std::string static void remove_pidfile() { - remove(Config.PIDFilename); + remove(Config.PIDFilename.c_str()); } /*************************************************************************/ @@ -161,7 +160,7 @@ static void write_pidfile() { FILE *pidfile; - pidfile = fopen(Config.PIDFilename, "w"); + pidfile = fopen(Config.PIDFilename.c_str(), "w"); if (pidfile) { #ifdef _WIN32 @@ -173,7 +172,7 @@ static void write_pidfile() atexit(remove_pidfile); } else - log_perror("Warning: cannot write to PID file %s", Config.PIDFilename); + log_perror("Warning: cannot write to PID file %s", Config.PIDFilename.c_str()); } /*************************************************************************/ @@ -246,12 +245,12 @@ int init_primary(int ac, char **av) if (GetCommandLineArgument("protocoldebug")) protocoldebug = 1; - std::string Arg; + Anope::string Arg; if (GetCommandLineArgument("debug", 'd', Arg)) { - if (!Arg.empty()) - { - int level = atoi(Arg.c_str()); + if (!Arg.empty()) + { + int level = Arg.is_number_only() ? convertTo<int>(Arg) : -1; if (level > 0) debug = level; else @@ -259,9 +258,9 @@ int init_primary(int ac, char **av) Alog(LOG_TERMINAL) << "Invalid option given to --debug"; return -1; } - } - else - ++debug; + } + else + ++debug; } if (GetCommandLineArgument("config", 'c', Arg)) @@ -271,7 +270,7 @@ int init_primary(int ac, char **av) Alog(LOG_TERMINAL) << "The --config option requires a file name"; return -1; } - services_conf = Arg.c_str(); + services_conf = Arg; } if (GetCommandLineArgument("dir", 0, Arg)) @@ -318,9 +317,9 @@ int init_primary(int ac, char **av) /* Add IRCD Protocol Module; exit if there are errors */ if (protocol_module_init()) return -1; - + /* Create me */ - Me = new Server(NULL, Config.ServerName, 0, Config.ServerDesc, (Config.Numeric ? Config.Numeric : "")); + Me = new Server(NULL, Config.ServerName, 0, Config.ServerDesc, Config.Numeric); /* First thing, add our core bots internally. Before modules are loaded and before the database is read * This is used for modules adding commands and for the BotInfo* poiners in the command classes. @@ -334,19 +333,19 @@ int init_primary(int ac, char **av) * Note that it is important this is after loading the protocol module. The ircd struct must exist for * the ts6_ functions */ - if (Config.s_OperServ) + if (!Config.s_OperServ.empty()) new BotInfo(Config.s_OperServ, Config.ServiceUser, Config.ServiceHost, Config.desc_OperServ); - if (Config.s_NickServ) + if (!Config.s_NickServ.empty()) new BotInfo(Config.s_NickServ, Config.ServiceUser, Config.ServiceHost, Config.desc_NickServ); - if (Config.s_ChanServ) + if (!Config.s_ChanServ.empty()) new BotInfo(Config.s_ChanServ, Config.ServiceUser, Config.ServiceHost, Config.desc_ChanServ); - if (Config.s_HostServ) + if (!Config.s_HostServ.empty()) new BotInfo(Config.s_HostServ, Config.ServiceUser, Config.ServiceHost, Config.desc_HostServ); - if (Config.s_MemoServ) + if (!Config.s_MemoServ.empty()) new BotInfo(Config.s_MemoServ, Config.ServiceUser, Config.ServiceHost, Config.desc_MemoServ); - if (Config.s_BotServ) + if (!Config.s_BotServ.empty()) new BotInfo(Config.s_BotServ, Config.ServiceUser, Config.ServiceHost, Config.desc_BotServ); - if (Config.s_GlobalNoticer) + if (!Config.s_GlobalNoticer.empty()) new BotInfo(Config.s_GlobalNoticer, Config.ServiceUser, Config.ServiceHost, Config.desc_GlobalNoticer); /* Add Encryption Modules */ @@ -399,11 +398,7 @@ int init_secondary(int ac, char **av) #else if (!SupportedWindowsVersion()) { - char *winver = GetWindowsVersion(); - - Alog() << winver << " is not a supported version of Windows"; - - delete [] winver; + Alog() << GetWindowsVersion() << " is not a supported version of Windows"; return -1; } diff --git a/src/ircd.cpp b/src/ircd.cpp index c06237a1b..e6ac76079 100644 --- a/src/ircd.cpp +++ b/src/ircd.cpp @@ -18,7 +18,7 @@ IRCDProto *ircdproto; * Globals we want from the protocol file **/ IRCDVar *ircd; -char *version_protocol; +Anope::string version_protocol; int UseTSMODE; void pmodule_ircd_proto(IRCDProto *proto) @@ -26,19 +26,6 @@ void pmodule_ircd_proto(IRCDProto *proto) ircdproto = proto; } -void anope_SendNumeric(const char *source, int numeric, const char *dest, const char *fmt, ...) -{ - va_list args; - char buf[BUFSIZE] = ""; - if (fmt) - { - va_start(args, fmt); - vsnprintf(buf, BUFSIZE - 1, fmt, args); - va_end(args); - } - ircdproto->SendNumeric(source, numeric, dest, buf); -} - /** * Set routines for modules to set the prefered function for dealing with things. **/ @@ -47,9 +34,9 @@ void pmodule_ircd_var(IRCDVar *ircdvar) ircd = ircdvar; } -void pmodule_ircd_version(const char *version) +void pmodule_ircd_version(const Anope::string &version) { - version_protocol = sstrdup(version); + version_protocol = version; } void pmodule_ircd_useTSMode(int use) diff --git a/src/language.cpp b/src/language.cpp index 473df39e8..558363f17 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -172,7 +172,7 @@ void lang_sanitize() strnrepl(tmp, sizeof(tmp), "%R", "/"); else strnrepl(tmp, sizeof(tmp), "%R", "/msg "); - newstr = sstrdup(tmp); + newstr = strdup(tmp); delete [] langtexts[i][j]; langtexts[i][j] = newstr; } @@ -303,7 +303,7 @@ int strftime_lang(char *buf, int size, User *u, int format, struct tm *tm) /* Send a syntax-error message to the user. */ -void syntax_error(char *service, User *u, const char *command, int msgnum) +void syntax_error(const Anope::string &service, User *u, const Anope::string &command, int msgnum) { const char *str; @@ -312,7 +312,7 @@ void syntax_error(char *service, User *u, const char *command, int msgnum) str = getstring(u, msgnum); notice_lang(service, u, SYNTAX_ERROR, str); - notice_lang(service, u, MORE_INFO, service, command); + notice_lang(service, u, MORE_INFO, service.c_str(), command.c_str()); } const char *getstring(NickAlias *na, int index) @@ -327,7 +327,7 @@ const char *getstring(NickAlias *na, int index) return langtexts[langidx][index]; } -const char *getstring(NickCore *nc, int index) +const char *getstring(const NickCore *nc, int index) { // Default to config int langidx = Config.NSDefLanguage; diff --git a/src/log.cpp b/src/log.cpp index 3ce47c526..9f5e05ebc 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -17,7 +17,7 @@ static int curday = 0; /*************************************************************************/ -static int get_logname(char *name, int count, struct tm *tm) +static int get_logname(Anope::string &name, struct tm *tm) { char timestamp[32]; time_t t; @@ -30,7 +30,7 @@ static int get_logname(char *name, int count, struct tm *tm) /* fix bug 577 */ strftime(timestamp, sizeof(timestamp), "%Y%m%d", tm); - snprintf(name, count, "logs/%s.%s", timestamp, log_filename.c_str()); + name = Anope::string("logs/") + timestamp + "." + log_filename; curday = tm->tm_yday; return 1; @@ -43,7 +43,7 @@ static void remove_log() time_t t; struct tm tm; - char name[PATH_MAX]; + Anope::string name; if (!Config.KeepLogs) return; @@ -53,8 +53,8 @@ static void remove_log() tm = *localtime(&t); /* removed if from here cause get_logchan is always 1 */ - get_logname(name, sizeof(name), &tm); - DeleteFile(name); + get_logname(name, &tm); + DeleteFile(name.c_str()); } /*************************************************************************/ @@ -82,18 +82,18 @@ static void checkday() int open_log() { - char name[PATH_MAX]; + Anope::string name; if (logfile) return 0; /* if removed again.. get_logname is always 1 */ - get_logname(name, sizeof(name), NULL); - logfile = fopen(name, "a"); + get_logname(name, NULL); + logfile = fopen(name.c_str(), "a"); if (logfile) setbuf(logfile, NULL); - return logfile != NULL ? 0 : -1; + return logfile ? 0 : -1; } /*************************************************************************/ @@ -111,11 +111,11 @@ void close_log() /*************************************************************************/ /* added cause this is used over and over in the code */ -char *log_gettimestamp() +Anope::string log_gettimestamp() { time_t t; struct tm tm; - static char tbuf[256]; + char tbuf[256]; time(&t); tm = *localtime(&t); @@ -145,7 +145,6 @@ char *log_gettimestamp() void log_perror(const char *fmt, ...) { va_list args; - char *buf; int errno_save = errno; char str[BUFSIZE]; @@ -158,12 +157,12 @@ void log_perror(const char *fmt, ...) vsnprintf(str, sizeof(str), fmt, args); va_end(args); - buf = log_gettimestamp(); + Anope::string buf = log_gettimestamp(); if (logfile) - fprintf(logfile, "%s %s : %s\n", buf, str, strerror(errno_save)); + fprintf(logfile, "%s %s : %s\n", buf.c_str(), str, strerror(errno_save)); if (nofork) - fprintf(stderr, "%s %s : %s\n", buf, str, strerror(errno_save)); + fprintf(stderr, "%s %s : %s\n", buf.c_str(), str, strerror(errno_save)); errno = errno_save; } @@ -176,7 +175,6 @@ void log_perror(const char *fmt, ...) void fatal(const char *fmt, ...) { va_list args; - char *buf; char buf2[4096]; checkday(); @@ -188,12 +186,12 @@ void fatal(const char *fmt, ...) vsnprintf(buf2, sizeof(buf2), fmt, args); va_end(args); - buf = log_gettimestamp(); + Anope::string buf = log_gettimestamp(); if (logfile) - fprintf(logfile, "%s FATAL: %s\n", buf, buf2); + fprintf(logfile, "%s FATAL: %s\n", buf.c_str(), buf2); if (nofork) - fprintf(stderr, "%s FATAL: %s\n", buf, buf2); + fprintf(stderr, "%s FATAL: %s\n", buf.c_str(), buf2); if (UplinkSock) ircdproto->SendGlobops(NULL, "FATAL ERROR! %s", buf2); @@ -210,7 +208,6 @@ void fatal(const char *fmt, ...) void fatal_perror(const char *fmt, ...) { va_list args; - char *buf; char buf2[4096]; int errno_save = errno; @@ -223,12 +220,12 @@ void fatal_perror(const char *fmt, ...) vsnprintf(buf2, sizeof(buf2), fmt, args); va_end(args); - buf = log_gettimestamp(); + Anope::string buf = log_gettimestamp(); if (logfile) - fprintf(logfile, "%s FATAL: %s: %s\n", buf, buf2, strerror(errno_save)); + fprintf(logfile, "%s FATAL: %s: %s\n", buf.c_str(), buf2, strerror(errno_save)); if (nofork) - fprintf(stderr, "%s FATAL: %s: %s\n", buf, buf2, strerror(errno_save)); + fprintf(stderr, "%s FATAL: %s: %s\n", buf.c_str(), buf2, strerror(errno_save)); if (UplinkSock) ircdproto->SendGlobops(NULL, "FATAL ERROR! %s: %s", buf2, strerror(errno_save)); @@ -249,20 +246,19 @@ Alog::~Alog() if (Level >= LOG_DEBUG && (Level - LOG_DEBUG + 1) > debug) return; - char *tbuf; int errno_save = errno; checkday(); - tbuf = log_gettimestamp(); + Anope::string tbuf = log_gettimestamp(); if (logfile) - fprintf(logfile, "%s %s\n", tbuf, buf.str().c_str()); + fprintf(logfile, "%s %s\n", tbuf.c_str(), buf.str().c_str()); if (nofork) std::cout << tbuf << " " << buf.str() << std::endl; else if (Level == LOG_TERMINAL) // XXX dont use this yet unless you know we're at terminal and not daemonized std::cout << buf.str() << std::endl; - if (Config.LogChannel && LogChan && !debug && findchan(Config.LogChannel)) + if (!Config.LogChannel.empty() && LogChan && !debug && findchan(Config.LogChannel)) ircdproto->SendPrivmsg(Global, Config.LogChannel, "%s", buf.str().c_str()); errno = errno_save; } diff --git a/src/mail.cpp b/src/mail.cpp index c7c8ebda7..b5e2149f9 100644 --- a/src/mail.cpp +++ b/src/mail.cpp @@ -11,12 +11,12 @@ MailThread::~MailThread() void MailThread::Run() { - FILE *pipe = popen(Config.SendMailPath, "w"); + FILE *pipe = popen(Config.SendMailPath.c_str(), "w"); if (!pipe) return; - fprintf(pipe, "From: %s\n", Config.SendFrom); + fprintf(pipe, "From: %s\n", Config.SendFrom.c_str()); if (Config.DontQuoteAddresses) fprintf(pipe, "To: %s <%s>\n", MailTo.c_str(), Addr.c_str()); else @@ -30,7 +30,7 @@ void MailThread::Run() Success = true; } -bool Mail(User *u, NickRequest *nr, const std::string &service, const std::string &subject, const std::string &message) +bool Mail(User *u, NickRequest *nr, const Anope::string &service, const Anope::string &subject, const Anope::string &message) { if (!u || !nr || subject.empty() || service.empty() || message.empty()) return false; @@ -38,11 +38,11 @@ bool Mail(User *u, NickRequest *nr, const std::string &service, const std::strin time_t t = time(NULL); if (!Config.UseMail) - notice_lang(service.c_str(), u, MAIL_DISABLED); + notice_lang(service, u, MAIL_DISABLED); else if (t - u->lastmail < Config.MailDelay) - notice_lang(service.c_str(), u, MAIL_DELAYED, t - u->lastmail); - else if (!nr->email) - notice_lang(service.c_str(), u, MAIL_INVALID, nr->nick); + notice_lang(service, u, MAIL_DELAYED, t - u->lastmail); + else if (nr->email.empty()) + notice_lang(service, u, MAIL_INVALID, nr->nick.c_str()); else { u->lastmail = nr->lastmail = t; @@ -53,7 +53,7 @@ bool Mail(User *u, NickRequest *nr, const std::string &service, const std::strin return false; } -bool Mail(User *u, NickCore *nc, const std::string &service, const std::string &subject, const std::string &message) +bool Mail(User *u, NickCore *nc, const Anope::string &service, const Anope::string &subject, const Anope::string &message) { if (!u || !nc || subject.empty() || service.empty() || message.empty()) return false; @@ -61,11 +61,11 @@ bool Mail(User *u, NickCore *nc, const std::string &service, const std::string & time_t t = time(NULL); if (!Config.UseMail) - notice_lang(service.c_str(), u, MAIL_DISABLED); + notice_lang(service, u, MAIL_DISABLED); else if (t - u->lastmail < Config.MailDelay) - notice_lang(service.c_str(), u, MAIL_DELAYED, t - u->lastmail); - else if (!nc->email) - notice_lang(service.c_str(), u, MAIL_INVALID, nc->display); + notice_lang(service, u, MAIL_DELAYED, t - u->lastmail); + else if (nc->email.empty()) + notice_lang(service, u, MAIL_INVALID, nc->display.c_str()); else { u->lastmail = nc->lastmail = t; @@ -76,9 +76,9 @@ bool Mail(User *u, NickCore *nc, const std::string &service, const std::string & return false; } -bool Mail(NickCore *nc, const std::string &subject, const std::string &message) +bool Mail(NickCore *nc, const Anope::string &subject, const Anope::string &message) { - if (!Config.UseMail || !nc || !nc->email || subject.empty() || message.empty()) + if (!Config.UseMail || !nc || nc->email.empty() || subject.empty() || message.empty()) return false; nc->lastmail = time(NULL); @@ -96,28 +96,28 @@ bool Mail(NickCore *nc, const std::string &subject, const std::string &message) * @param email Email to Validate * @return bool */ -bool MailValidate(const std::string &email) +bool MailValidate(const Anope::string &email) { bool has_period = false; - char copy[BUFSIZE]; static char specials[] = {'(', ')', '<', '>', '@', ',', ';', ':', '\\', '\"', '[', ']', ' '}; if (email.empty()) return false; - strlcpy(copy, email.c_str(), sizeof(copy)); + Anope::string copy = email; - char *domain = strchr(copy, '@'); - if (!domain) + size_t at = copy.find('@'); + if (at == Anope::string::npos) return false; - *domain++ = '\0'; + Anope::string domain = copy.substr(at + 1); + copy = copy.substr(0, at); - /* Don't accept NULL copy or domain. */ - if (!*copy || !*domain) + /* Don't accept empty copy or domain. */ + if (copy.empty() || domain.empty()) return false; /* Check for forbidden characters in the name */ - for (unsigned int i = 0; i < strlen(copy); ++i) + for (unsigned i = 0, end = copy.length(); i < end; ++i) { if (copy[i] <= 31 || copy[i] >= 127) return false; @@ -127,7 +127,7 @@ bool MailValidate(const std::string &email) } /* Check for forbidden characters in the domain */ - for (unsigned int i = 0; i < strlen(domain); ++i) + for (unsigned i = 0, end = domain.length(); i < end; ++i) { if (domain[i] <= 31 || domain[i] >= 127) return false; @@ -136,7 +136,7 @@ bool MailValidate(const std::string &email) return false; if (domain[i] == '.') { - if (!i || i == strlen(domain) - 1) + if (!i || i == end - 1) return false; has_period = true; } diff --git a/src/main.cpp b/src/main.cpp index dccfcc15f..5e29db9f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,15 +34,13 @@ # include <sys/resource.h> #endif -const char * const Anope::compiled = __TIME__ " " __DATE__; - /******** Global variables! ********/ /* Command-line options: (note that configuration variables are in config.c) */ -std::string services_dir; /* -dir dirname */ -std::string services_bin; /* Binary as specified by the user */ -std::string orig_cwd; /* Original current working directory */ -std::string log_filename = "services.log"; /* -log filename */ +Anope::string services_dir; /* -dir dirname */ +Anope::string services_bin; /* Binary as specified by the user */ +Anope::string orig_cwd; /* Original current working directory */ +Anope::string log_filename = "services.log"; /* -log filename */ int debug = 0; /* -debug */ int readonly = 0; /* -readonly */ bool LogChan = false; /* -logchan */ @@ -52,7 +50,7 @@ int nothird = 0; /* -nothrid */ int noexpire = 0; /* -noexpire */ int protocoldebug = 0; /* -protocoldebug */ -std::string binary_dir; /* Used to store base path for Anope */ +Anope::string binary_dir; /* Used to store base path for Anope */ #ifdef _WIN32 # include <process.h> # define execve _execve @@ -65,7 +63,7 @@ int quitting = 0; int shutting_down = 0; /* Contains a message as to why services is terminating */ -const char *quitmsg = NULL; +Anope::string quitmsg; /* Should we update the databases now? */ int save_data = 0; @@ -112,7 +110,7 @@ Socket *UplinkSock = NULL; class UplinkSocket : public ClientSocket { public: - UplinkSocket(const std::string &nTargetHost, int nPort, const std::string &nBindHost = "", bool nIPv6 = false) : ClientSocket(nTargetHost, nPort, nBindHost, nIPv6) + UplinkSocket(const Anope::string &nTargetHost, int nPort, const Anope::string &nBindHost = "", bool nIPv6 = false) : ClientSocket(nTargetHost, nPort, nBindHost, nIPv6) { UplinkSock = this; } @@ -124,7 +122,7 @@ class UplinkSocket : public ClientSocket UplinkSock = NULL; } - bool Read(const std::string &buf) + bool Read(const Anope::string &buf) { process(buf); return true; @@ -178,7 +176,7 @@ void do_restart_services() FOREACH_MOD(I_OnPreRestart, OnPreRestart()); - if (!quitmsg) + if (quitmsg.empty()) quitmsg = "Restarting"; /* Send a quit for all of our bots */ for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) @@ -186,9 +184,9 @@ void do_restart_services() /* Don't use quitmsg here, it may contain information you don't want people to see */ ircdproto->SendQuit(it->second, "Restarting"); /* Erase bots from the user list so they don't get nuked later on */ - UserListByNick.erase(it->second->nick.c_str()); + UserListByNick.erase(it->second->nick); if (!it->second->GetUID().empty()) - UserListByUID.erase(it->second->GetUID().c_str()); + UserListByUID.erase(it->second->GetUID()); } ircdproto->SendSquit(Config.ServerName, quitmsg); delete UplinkSock; @@ -218,7 +216,7 @@ static void services_shutdown() { FOREACH_MOD(I_OnPreShutdown, OnPreShutdown()); - if (!quitmsg) + if (quitmsg.empty()) quitmsg = "Terminating, reason unknown"; Alog() << quitmsg; if (started && UplinkSock) @@ -229,7 +227,7 @@ static void services_shutdown() /* Don't use quitmsg here, it may contain information you don't want people to see */ ircdproto->SendQuit(it->second, "Shutting down"); /* Erase bots from the user list so they don't get nuked later on */ - UserListByNick.erase(it->second->nick.c_str()); + UserListByNick.erase(it->second->nick); if (!it->second->GetUID().empty()) UserListByUID.erase(it->second->GetUID()); } @@ -258,7 +256,7 @@ void sighandler(int signum) * always set when we need it. It seems some signals slip through to the * QUIT code without having a valid quitmsg. -GD */ - if (!quitmsg) + if (quitmsg.empty()) quitmsg = "Services terminating via a signal."; if (started) @@ -324,7 +322,7 @@ void sighandler(int signum) else { if (isatty(2)) - fprintf(stderr, "%s\n", quitmsg); + fprintf(stderr, "%s\n", quitmsg.c_str()); else Alog() << quitmsg; @@ -336,7 +334,7 @@ void sighandler(int signum) /** The following comes from InspIRCd to get the full path of the Anope executable */ -std::string GetFullProgDir(char *argv0) +Anope::string GetFullProgDir(const Anope::string &argv0) { char buffer[PATH_MAX]; #ifdef _WIN32 @@ -346,31 +344,31 @@ std::string GetFullProgDir(char *argv0) */ if (GetModuleFileName(NULL, buffer, PATH_MAX)) { - std::string fullpath = buffer; - std::string::size_type n = fullpath.rfind("\\" SERVICES_BIN); - services_bin = fullpath.substr(n + 1, fullpath.size()); - return std::string(fullpath, 0, n); + Anope::string fullpath = buffer; + Anope::string::size_type n = fullpath.rfind("\\" SERVICES_BIN); + services_bin = fullpath.substr(n + 1, fullpath.length()); + return fullpath.substr(0, n); } #else // Get the current working directory if (getcwd(buffer, PATH_MAX)) { - std::string remainder = argv0; + Anope::string remainder = argv0; /* Does argv[0] start with /? If so, it's a full path, use it */ if (remainder[0] == '/') { - std::string::size_type n = remainder.rfind("/" SERVICES_BIN); - services_bin = remainder.substr(n + 1, remainder.size()); - return std::string(remainder, 0, n); + Anope::string::size_type n = remainder.rfind("/" SERVICES_BIN); + services_bin = remainder.substr(n + 1, remainder.length()); + return remainder.substr(0, n); } services_bin = remainder; - if (services_bin.substr(0, 2) == "./") + if (services_bin.substr(0, 2).equals_cs("./")) services_bin = services_bin.substr(2); - std::string fullpath = std::string(buffer) + "/" + remainder; - std::string::size_type n = fullpath.rfind("/" SERVICES_BIN); - return std::string(fullpath, 0, n); + Anope::string fullpath = Anope::string(buffer) + "/" + remainder; + Anope::string::size_type n = fullpath.rfind("/" SERVICES_BIN); + return fullpath.substr(0, n); } #endif return "/"; @@ -397,7 +395,7 @@ static bool Connect() try { - new UplinkSocket(uplink_server->host, uplink_server->port, Config.LocalHost ? Config.LocalHost : "", uplink_server->ipv6); + new UplinkSocket(uplink_server->host, uplink_server->port, Config.LocalHost, uplink_server->ipv6); } catch (const SocketException &ex) { @@ -444,13 +442,13 @@ int main(int ac, char **av, char **envp) #endif binary_dir = GetFullProgDir(av[0]); - if (binary_dir[binary_dir.size() - 1] == '.') - binary_dir = binary_dir.substr(0, binary_dir.size() - 2); + if (binary_dir[binary_dir.length() - 1] == '.') + binary_dir = binary_dir.substr(0, binary_dir.length() - 2); #ifdef _WIN32 - std::string::size_type n = binary_dir.rfind("\\"); + Anope::string::size_type n = binary_dir.rfind('\\'); services_dir = binary_dir.substr(0, n) + "\\data"; #else - std::string::size_type n = binary_dir.rfind("/"); + Anope::string::size_type n = binary_dir.rfind('/'); services_dir = binary_dir.substr(0, n) + "/data"; #endif @@ -580,12 +578,12 @@ int main(int ac, char **av, char **envp) return 0; } -inline std::string Anope::Version() +inline Anope::string Anope::Version() { return stringify(VERSION_MAJOR) + "." + stringify(VERSION_MINOR) + "." + stringify(VERSION_PATCH) + VERSION_EXTRA + " (" + stringify(VERSION_BUILD) + ")"; } -inline std::string Anope::Build() +inline Anope::string Anope::Build() { - return std::string("build #") + stringify(BUILD) + ", compiled " + compiled; + return "build #" + stringify(BUILD) + ", compiled " + Anope::compiled; } diff --git a/src/memory.cpp b/src/memory.cpp index 1fb1d2b21..12e0a1d08 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -21,25 +21,6 @@ /*************************************************************************/ /** - * malloc, replacement so we can trap for "out of memory" - * @param size to allocate - * @return void - */ -void *smalloc(long size) -{ - void *buf; - - if (!size) - size = 1; - buf = malloc(size); - if (!buf) - abort(); - return buf; -} - -/*************************************************************************/ - -/** * calloc, replacement so we can trap for "out of memory" * @param elsize to allocate * @param els size of members @@ -78,33 +59,6 @@ void *srealloc(void *oldptr, long newsize) } /*************************************************************************/ - -/** - * strdup, replacement so we can trap for "out of memory" - * @param oldptr Old Pointer - * @param newsize Size of new pointer - * @return void - */ -char *sstrdup(const char *src) -{ - char *ret = NULL; - if (src) - { - ret = new char[strlen(src) + 1]; - if (!ret) - abort(); - strcpy(ret, src); - } - else - { - Alog() << "sstrdup() called with NULL-arg"; - abort(); - } - - return ret; -} - -/*************************************************************************/ /*************************************************************************/ /* In the future: malloc() replacements that tell us if we're leaking and diff --git a/src/memoserv.cpp b/src/memoserv.cpp index 5ceca0c7a..cc7ee5db4 100644 --- a/src/memoserv.cpp +++ b/src/memoserv.cpp @@ -50,17 +50,17 @@ void ms_init() * @param buf Buffer containing the privmsg * @return void */ -void memoserv(User *u, const std::string &buf) +void memoserv(User *u, const Anope::string &buf) { if (!u || buf.empty()) return; - if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1') + if (buf.substr(0, 6).equals_ci("\1PING ") && buf[buf.length() - 1] == '\1') { - std::string command = buf; + Anope::string command = buf; command.erase(command.begin()); command.erase(command.end()); - ircdproto->SendCTCP(MemoServ, u->nick.c_str(), "%s", command.c_str()); + ircdproto->SendCTCP(MemoServ, u->nick, "%s", command.c_str()); } else mod_run_cmd(MemoServ, u, buf); @@ -70,14 +70,14 @@ void memoserv(User *u, const std::string &buf) /** * check_memos: See if the given user has any unread memos, and send a - * NOTICE to that user if so (and if the appropriate flag is - * set). + * NOTICE to that user if so (and if the appropriate flag is + * set). * @param u User Struct * @return void */ void check_memos(User *u) { - NickCore *nc; + const NickCore *nc; unsigned i, newcnt = 0; if (!u) @@ -86,7 +86,7 @@ void check_memos(User *u) return; } - if (!(nc = u->Account()) || !u->IsRecognized() || !(nc->HasFlag(NI_MEMO_SIGNON))) + if (!(nc = u->Account()) || !u->IsRecognized() || !nc->HasFlag(NI_MEMO_SIGNON)) return; for (i = 0; i < nc->memos.memos.size(); ++i) @@ -98,7 +98,7 @@ void check_memos(User *u) { notice_lang(Config.s_MemoServ, u, newcnt == 1 ? MEMO_HAVE_NEW_MEMO : MEMO_HAVE_NEW_MEMOS, newcnt); if (newcnt == 1 && (nc->memos.memos[i - 1]->HasFlag(MF_UNREAD))) - notice_lang(Config.s_MemoServ, u, MEMO_TYPE_READ_LAST, Config.s_MemoServ); + notice_lang(Config.s_MemoServ, u, MEMO_TYPE_READ_LAST, Config.s_MemoServ.c_str()); else if (newcnt == 1) { for (i = 0; i < nc->memos.memos.size(); ++i) @@ -106,10 +106,10 @@ void check_memos(User *u) if (nc->memos.memos[i]->HasFlag(MF_UNREAD)) break; } - notice_lang(Config.s_MemoServ, u, MEMO_TYPE_READ_NUM, Config.s_MemoServ, nc->memos.memos[i]->number); + notice_lang(Config.s_MemoServ, u, MEMO_TYPE_READ_NUM, Config.s_MemoServ.c_str(), nc->memos.memos[i]->number); } else - notice_lang(Config.s_MemoServ, u, MEMO_TYPE_LIST_NEW, Config.s_MemoServ); + notice_lang(Config.s_MemoServ, u, MEMO_TYPE_LIST_NEW, Config.s_MemoServ.c_str()); } if (nc->memos.memomax > 0 && nc->memos.memos.size() >= nc->memos.memomax) { @@ -132,9 +132,9 @@ void check_memos(User *u) * @return `ischan' 1 if the name was a channel name, else 0. * @return `isforbid' 1 if the name is forbidden, else 0. */ -MemoInfo *getmemoinfo(const char *name, int *ischan, int *isforbid) +MemoInfo *getmemoinfo(const Anope::string &name, int *ischan, int *isforbid) { - if (*name == '#') + if (name[0] == '#') { ChannelInfo *ci; if (ischan) @@ -200,19 +200,19 @@ MemoInfo *getmemoinfo(const char *name, int *ischan, int *isforbid) * 3 - reply to user and request read receipt * @return void */ -void memo_send(User *u, const char *name, const char *text, int z) +void memo_send(User *u, const Anope::string &name, const Anope::string &text, int z) { int ischan; int isforbid; Memo *m; MemoInfo *mi; time_t now = time(NULL); - char *source = u->Account()->display; + Anope::string source = u->Account()->display; int is_servoper = u->Account() && u->Account()->IsServicesOper(); if (readonly) notice_lang(Config.s_MemoServ, u, MEMO_SEND_DISABLED); - else if (!text) + else if (text.empty()) { if (!z) syntax_error(Config.s_MemoServ, u, "SEND", MEMO_SEND_SYNTAX); @@ -223,16 +223,16 @@ void memo_send(User *u, const char *name, const char *text, int z) else if (!u->IsIdentified() && !u->IsRecognized()) { if (!z || z == 3) - notice_lang(Config.s_MemoServ, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ); + notice_lang(Config.s_MemoServ, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ.c_str()); } else if (!(mi = getmemoinfo(name, &ischan, &isforbid))) { if (!z || z == 3) { if (isforbid) - notice_lang(Config.s_MemoServ, u, ischan ? CHAN_X_FORBIDDEN : NICK_X_FORBIDDEN, name); + notice_lang(Config.s_MemoServ, u, ischan ? CHAN_X_FORBIDDEN : NICK_X_FORBIDDEN, name.c_str()); else - notice_lang(Config.s_MemoServ, u, ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, name); + notice_lang(Config.s_MemoServ, u, ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, name.c_str()); } } else if (z != 2 && Config.MSSendDelay > 0 && u && u->lastmemosend + Config.MSSendDelay > now) @@ -247,12 +247,12 @@ void memo_send(User *u, const char *name, const char *text, int z) else if (!mi->memomax && !is_servoper) { if (!z || z == 3) - notice_lang(Config.s_MemoServ, u, MEMO_X_GETS_NO_MEMOS, name); + notice_lang(Config.s_MemoServ, u, MEMO_X_GETS_NO_MEMOS, name.c_str()); } else if (mi->memomax > 0 && mi->memos.size() >= mi->memomax && !is_servoper) { if (!z || z == 3) - notice_lang(Config.s_MemoServ, u, MEMO_X_HAS_TOO_MANY_MEMOS, name); + notice_lang(Config.s_MemoServ, u, MEMO_X_HAS_TOO_MANY_MEMOS, name.c_str()); } else { @@ -272,7 +272,7 @@ void memo_send(User *u, const char *name, const char *text, int z) else m->number = 1; m->time = time(NULL); - m->text = sstrdup(text); + m->text = text; m->SetFlag(MF_UNREAD); /* Set notify sent flag - DrStein */ if (z == 2) @@ -281,10 +281,10 @@ void memo_send(User *u, const char *name, const char *text, int z) if (z == 3) m->SetFlag(MF_RECEIPT); if (!z || z == 3) - notice_lang(Config.s_MemoServ, u, MEMO_SENT, name); + notice_lang(Config.s_MemoServ, u, MEMO_SENT, name.c_str()); if (!ischan) { - NickCore *nc = (findnick(name))->nc; + NickCore *nc = findnick(name)->nc; FOREACH_MOD(I_OnMemoSend, OnMemoSend(u, nc, m)); @@ -297,13 +297,13 @@ void memo_send(User *u, const char *name, const char *text, int z) NickAlias *na = *it; User *user = finduser(na->nick); if (user && user->IsIdentified()) - notice_lang(Config.s_MemoServ, user, MEMO_NEW_MEMO_ARRIVED, source, Config.s_MemoServ, m->number); + notice_lang(Config.s_MemoServ, user, MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config.s_MemoServ.c_str(), m->number); } } else { if ((u = finduser(name)) && u->IsIdentified() && nc->HasFlag(NI_MEMO_RECEIVE)) - notice_lang(Config.s_MemoServ, u, MEMO_NEW_MEMO_ARRIVED, source, Config.s_MemoServ, m->number); + notice_lang(Config.s_MemoServ, u, MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config.s_MemoServ.c_str(), m->number); } /* if (flags & MEMO_RECEIVE) */ } /* if (MSNotifyAll) */ @@ -325,8 +325,8 @@ void memo_send(User *u, const char *name, const char *text, int z) if (check_access(cu->user, c->ci, CA_MEMO)) { - if (cu->user->Account() && cu->user->Account()->HasFlag(NI_MEMO_RECEIVE) && !get_ignore(cu->user->nick.c_str())) - notice_lang(Config.s_MemoServ, cu->user, MEMO_NEW_X_MEMO_ARRIVED, c->ci->name.c_str(), Config.s_MemoServ, c->ci->name.c_str(), m->number); + if (cu->user->Account() && cu->user->Account()->HasFlag(NI_MEMO_RECEIVE) && !get_ignore(cu->user->nick)) + notice_lang(Config.s_MemoServ, cu->user, MEMO_NEW_X_MEMO_ARRIVED, c->ci->name.c_str(), Config.s_MemoServ.c_str(), c->ci->name.c_str(), m->number); } } } /* MSNotifyAll */ @@ -354,9 +354,8 @@ int delmemo(MemoInfo *mi, int num) } if (i < mi->memos.size()) { - delete [] mi->memos[i]->text; /* Deallocate memo text memory */ delete mi->memos[i]; /* Deallocate the memo itself */ - mi->memos.erase(mi->memos.begin() + i); /* Remove the memo pointer from the vector */ + mi->memos.erase(mi->memos.begin() + i); /* Remove the memo pointer from the vector */ return 1; } else @@ -369,7 +368,7 @@ static bool SendMemoMail(NickCore *nc, Memo *m) { char message[BUFSIZE]; - snprintf(message, sizeof(message), getstring(NICK_MAIL_TEXT), nc->display, m->sender.c_str(), m->number, m->text); + snprintf(message, sizeof(message), getstring(NICK_MAIL_TEXT), nc->display.c_str(), m->sender.c_str(), m->number, m->text.c_str()); return Mail(nc, getstring(MEMO_MAIL_SUBJECT), message); } @@ -378,7 +377,7 @@ static bool SendMemoMail(NickCore *nc, Memo *m) /* Send receipt notification to sender. */ -void rsend_notify(User *u, Memo *m, const char *chan) +void rsend_notify(User *u, Memo *m, const Anope::string &chan) { NickAlias *na; NickCore *nc; @@ -402,10 +401,10 @@ void rsend_notify(User *u, Memo *m, const char *chan) /* Text of the memo varies if the recepient was a nick or channel */ - if (chan) + if (!chan.empty()) { fmt = getstring(na, MEMO_RSEND_CHAN_MEMO_TEXT); - snprintf(text, sizeof(text), fmt, chan); + snprintf(text, sizeof(text), fmt, chan.c_str()); } else { @@ -414,11 +413,11 @@ void rsend_notify(User *u, Memo *m, const char *chan) } /* Send notification */ - memo_send(u, m->sender.c_str(), text, 2); + memo_send(u, m->sender, text, 2); /* Notify recepient of the memo that a notification has been sent to the sender */ - notice_lang(Config.s_MemoServ, u, MEMO_RSEND_USER_NOTIFICATION, nc->display); + notice_lang(Config.s_MemoServ, u, MEMO_RSEND_USER_NOTIFICATION, nc->display.c_str()); } /* Remove receipt flag from the original memo */ diff --git a/src/messages.cpp b/src/messages.cpp index 857229f65..49188ce93 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -15,7 +15,7 @@ /*************************************************************************/ -int m_nickcoll(const char *user) +int m_nickcoll(const Anope::string &user) { introduce_user(user); return MOD_CONT; @@ -23,25 +23,25 @@ int m_nickcoll(const char *user) /*************************************************************************/ -int m_away(const char *source, const char *msg) +int m_away(const Anope::string &source, const Anope::string &msg) { User *u; u = finduser(source); - if (u && !msg) /* un-away */ + if (u && msg.empty()) /* un-away */ check_memos(u); return MOD_CONT; } /*************************************************************************/ -int m_kill(const std::string &nick, const char *msg) +int m_kill(const Anope::string &nick, const Anope::string &msg) { BotInfo *bi; /* Recover if someone kills us. */ - if (Config.s_BotServ && (bi = findbot(nick))) + if (!Config.s_BotServ.empty() && (bi = findbot(nick))) { introduce_user(nick); bi->RejoinAll(); @@ -54,36 +54,36 @@ int m_kill(const std::string &nick, const char *msg) /*************************************************************************/ -int m_time(const char *source, int ac, const char **av) +int m_time(const Anope::string &source, int ac, const char **av) { time_t t; struct tm *tm; char buf[64]; - if (!source) + if (source.empty()) return MOD_CONT; time(&t); tm = localtime(&t); strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y %Z", tm); - ircdproto->SendNumeric(Config.ServerName, 391, source, "%s :%s", Config.ServerName, buf); + ircdproto->SendNumeric(Config.ServerName, 391, source, "%s :%s", Config.ServerName.c_str(), buf); return MOD_CONT; } /*************************************************************************/ -int m_motd(const char *source) +int m_motd(const Anope::string &source) { FILE *f; char buf[BUFSIZE]; - if (!source) + if (source.empty()) return MOD_CONT; - f = fopen(Config.MOTDFilename, "r"); + f = fopen(Config.MOTDFilename.c_str(), "r"); if (f) { - ircdproto->SendNumeric(Config.ServerName, 375, source, ":- %s Message of the Day", Config.ServerName); + ircdproto->SendNumeric(Config.ServerName, 375, source, ":- %s Message of the Day", Config.ServerName.c_str()); while (fgets(buf, sizeof(buf), f)) { buf[strlen(buf) - 1] = 0; @@ -99,9 +99,8 @@ int m_motd(const char *source) /*************************************************************************/ -int m_privmsg(const std::string &source, const std::string &receiver, const std::string &message) +int m_privmsg(const Anope::string &source, const Anope::string &receiver, const Anope::string &message) { - char *target; time_t starttime, stoptime; /* When processing started and finished */ if (source.empty() || receiver.empty() || message.empty()) @@ -115,12 +114,12 @@ int m_privmsg(const std::string &source, const std::string &receiver, const std: BotInfo *bi = findbot(receiver); if (bi) - ircdproto->SendMessage(bi, source.c_str(), "%s", getstring(USER_RECORD_NOT_FOUND)); + ircdproto->SendMessage(bi, source, "%s", getstring(USER_RECORD_NOT_FOUND)); return MOD_CONT; } - if (receiver[0] == '#' && Config.s_BotServ) + if (receiver[0] == '#' && !Config.s_BotServ.empty()) { ChannelInfo *ci = cs_findchan(receiver); if (ci) @@ -135,30 +134,29 @@ int m_privmsg(const std::string &source, const std::string &receiver, const std: /* Check if we should ignore. Operators always get through. */ if (allow_ignore && !is_oper(u)) { - if (get_ignore(source.c_str())) + if (get_ignore(source)) { - target = myStrGetToken(message.c_str(), ' ', 0); + Anope::string target = myStrGetToken(message, ' ', 0); Alog() << "Ignored message from " << source << " to " << receiver << " using command " << target; - delete [] target; return MOD_CONT; } } /* If a server is specified (nick@server format), make sure it matches * us, and strip it off. */ - std::string botname = receiver; + Anope::string botname = receiver; size_t s = receiver.find('@'); - if (s != std::string::npos) + if (s != Anope::string::npos) { - ci::string servername(receiver.begin() + s + 1, receiver.end()); - botname = botname.erase(s); - if (servername != Config.ServerName) + Anope::string servername(receiver.begin() + s + 1, receiver.end()); + botname = botname.substr(0, s); + if (!servername.equals_ci(Config.ServerName)) return MOD_CONT; } else if (Config.UseStrictPrivMsg) { Alog(LOG_DEBUG) << "Ignored PRIVMSG without @ from " << source; - notice_lang(receiver, u, INVALID_TARGET, receiver.c_str(), receiver.c_str(), Config.ServerName, receiver.c_str()); + notice_lang(receiver, u, INVALID_TARGET, receiver.c_str(), receiver.c_str(), Config.ServerName.c_str(), receiver.c_str()); return MOD_CONT; } @@ -169,32 +167,31 @@ int m_privmsg(const std::string &source, const std::string &receiver, const std: if (bi) { - ci::string ci_bi_nick(bi->nick.c_str()); - if (ci_bi_nick == Config.s_OperServ) + if (bi->nick.equals_ci(Config.s_OperServ)) { if (!is_oper(u) && Config.OSOpersOnly) { notice_lang(Config.s_OperServ, u, ACCESS_DENIED); if (Config.WallBadOS) - ircdproto->SendGlobops(OperServ, "Denied access to %s from %s!%s@%s (non-oper)", Config.s_OperServ, u->nick.c_str(), u->GetIdent().c_str(), u->host); + ircdproto->SendGlobops(OperServ, "Denied access to %s from %s!%s@%s (non-oper)", Config.s_OperServ.c_str(), u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str()); } else operserv(u, message); } - else if (ci_bi_nick == Config.s_NickServ) + else if (bi->nick.equals_ci(Config.s_NickServ)) nickserv(u, message); - else if (ci_bi_nick == Config.s_ChanServ) + else if (bi->nick.equals_ci(Config.s_ChanServ)) { if (!is_oper(u) && Config.CSOpersOnly) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else chanserv(u, message); } - else if (ci_bi_nick == Config.s_MemoServ) + else if (bi->nick.equals_ci(Config.s_MemoServ)) memoserv(u, message); - else if (Config.s_HostServ && ci_bi_nick == Config.s_HostServ) + else if (!Config.s_HostServ.empty() && bi->nick.equals_ci(Config.s_HostServ)) hostserv(u, message); - else if (Config.s_BotServ) + else if (!Config.s_BotServ.empty() && bi->nick.equals_ci(Config.s_BotServ)) botserv(u, bi, message); } @@ -202,8 +199,8 @@ int m_privmsg(const std::string &source, const std::string &receiver, const std: if (allow_ignore) { stoptime = time(NULL); - if (stoptime > starttime && source.find('.') == std::string::npos) - add_ignore(source.c_str(), stoptime - starttime); + if (stoptime > starttime && source.find('.') == Anope::string::npos) + add_ignore(source, stoptime - starttime); } } @@ -212,7 +209,7 @@ int m_privmsg(const std::string &source, const std::string &receiver, const std: /*************************************************************************/ -int m_stats(const char *source, int ac, const char **av) +int m_stats(const Anope::string &source, int ac, const char **av) { User *u; @@ -227,7 +224,7 @@ int m_stats(const char *source, int ac, const char **av) if (u && is_oper(u)) { ircdproto->SendNumeric(Config.ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime"); - ircdproto->SendNumeric(Config.ServerName, 211, source, "%s %d %d %d %d %d %d %ld", uplink_server->host, UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, time(NULL) - start_time); + ircdproto->SendNumeric(Config.ServerName, 211, source, "%s %d %d %d %d %d %d %ld", uplink_server->host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, time(NULL) - start_time); } ircdproto->SendNumeric(Config.ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*'); @@ -240,11 +237,11 @@ int m_stats(const char *source, int ac, const char **av) ircdproto->SendNumeric(Config.ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*'); else { - std::list<std::pair<ci::string, ci::string> >::iterator it, it_end; + std::list<std::pair<Anope::string, Anope::string> >::iterator it, it_end; for (it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) { - ci::string nick = it->first, type = it->second; + Anope::string nick = it->first, type = it->second; NickCore *nc = findcore(nick); if (nc) @@ -273,28 +270,28 @@ int m_stats(const char *source, int ac, const char **av) /*************************************************************************/ -int m_version(const char *source, int ac, const char **av) +int m_version(const Anope::string &source, int ac, const char **av) { - if (source) - ircdproto->SendNumeric(Config.ServerName, 351, source, "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Config.ServerName, ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str()); + if (!source.empty()) + ircdproto->SendNumeric(Config.ServerName, 351, source, "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Config.ServerName.c_str(), ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str()); return MOD_CONT; } /*************************************************************************/ -int m_whois(const char *source, const char *who) +int m_whois(const Anope::string &source, const Anope::string &who) { - if (source && who) + if (!source.empty() && !who.empty()) { NickAlias *na; BotInfo *bi = findbot(who); if (bi) { - ircdproto->SendNumeric(Config.ServerName, 311, source, "%s %s %s * :%s", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host, bi->realname); + ircdproto->SendNumeric(Config.ServerName, 311, source, "%s %s %s * :%s", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); ircdproto->SendNumeric(Config.ServerName, 307, source, "%s :is a registered nick", bi->nick.c_str()); - ircdproto->SendNumeric(Config.ServerName, 312, source, "%s %s :%s", bi->nick.c_str(), Config.ServerName, Config.ServerDesc); + ircdproto->SendNumeric(Config.ServerName, 312, source, "%s %s :%s", bi->nick.c_str(), Config.ServerName.c_str(), Config.ServerDesc.c_str()); ircdproto->SendNumeric(Config.ServerName, 317, source, "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), time(NULL) - bi->lastmsg, start_time); - ircdproto->SendNumeric(Config.ServerName, 318, source, "%s :End of /WHOIS list.", who); + ircdproto->SendNumeric(Config.ServerName, 318, source, "%s :End of /WHOIS list.", who.c_str()); } else if (!ircd->svshold && (na = findnick(who)) && na->HasFlag(NS_HELD)) { @@ -302,12 +299,12 @@ int m_whois(const char *source, const char *who) * We can't just say it doesn't exist here, even tho it does for * other servers :) -GD */ - ircdproto->SendNumeric(Config.ServerName, 311, source, "%s %s %s * :Services Enforcer", na->nick, Config.NSEnforcerUser, Config.NSEnforcerHost); - ircdproto->SendNumeric(Config.ServerName, 312, source, "%s %s :%s", na->nick, Config.ServerName, Config.ServerDesc); - ircdproto->SendNumeric(Config.ServerName, 318, source, "%s :End of /WHOIS list.", who); + ircdproto->SendNumeric(Config.ServerName, 311, source, "%s %s %s * :Services Enforcer", na->nick.c_str(), Config.NSEnforcerUser.c_str(), Config.NSEnforcerHost.c_str()); + ircdproto->SendNumeric(Config.ServerName, 312, source, "%s %s :%s", na->nick.c_str(), Config.ServerName.c_str(), Config.ServerDesc.c_str()); + ircdproto->SendNumeric(Config.ServerName, 318, source, "%s :End of /WHOIS list.", who.c_str()); } else - ircdproto->SendNumeric(Config.ServerName, 401, source, "%s :No such service.", who); + ircdproto->SendNumeric(Config.ServerName, 401, source, "%s :No such service.", who.c_str()); } return MOD_CONT; } diff --git a/src/misc.cpp b/src/misc.cpp index eb8b28f83..0e838695d 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -30,7 +30,7 @@ struct arc4_stream * @param filename The file * @return true if the file exists, false if it doens't */ -bool IsFile(const std::string &filename) +bool IsFile(const Anope::string &filename) { struct stat fileinfo; if (!stat(filename.c_str(), &fileinfo)) @@ -72,29 +72,8 @@ int tolower(char c) /*************************************************************************/ /** - * Simple function to convert binary data to hex. - * Taken from hybrid-ircd ( http://ircd-hybrid.com/ ) - */ -void binary_to_hex(unsigned char *bin, char *hex, int length) -{ - static const char trans[] = "0123456789ABCDEF"; - int i; - - for (i = 0; i < length; ++i) - { - hex[i << 1] = trans[bin[i] >> 4]; - hex[(i << 1) + 1] = trans[bin[i] & 0xf]; - } - - hex[i << 1] = '\0'; -} - - -/*************************************************************************/ - -/** * strscpy: Copy at most len-1 characters from a string to a buffer, and - * add a null terminator after the last character copied. + * add a null terminator after the last character copied. * @param d Buffer to copy into * @param s Data to copy int * @param len Length of data @@ -114,38 +93,6 @@ char *strscpy(char *d, const char *s, size_t len) /*************************************************************************/ /** - * stristr: Search case-insensitively for string s2 within string s1, - * returning the first occurrence of s2 or NULL if s2 was not - * found. - * @param s1 String 1 - * @param s2 String 2 - * @return first occurrence of s2 - */ -const char *stristr(const char *s1, const char *s2) -{ - register const char *s = s1, *d = s2; - - while (*s1) - { - if (tolower(*s1) == tolower(*d)) - { - ++s1; - ++d; - if (!*d) - return s; - } - else - { - s = ++s1; - d = s2; - } - } - return NULL; -} - -/*************************************************************************/ - -/** * strnrepl: Replace occurrences of `old' with `new' in string `s'. Stop * replacing if a replacement would cause the string to exceed * `size' bytes (including the null terminator). Return the @@ -223,11 +170,11 @@ const char *merge_args(int argc, char **argv) /*************************************************************************/ -NumberList::NumberList(const std::string &list, bool descending) : desc(descending), is_valid(true) +NumberList::NumberList(const Anope::string &list, bool descending) : is_valid(true), desc(descending) { - char *error; + Anope::string error; commasepstream sep(list); - std::string token; + Anope::string token; sep.GetToken(token); if (token.empty()) @@ -236,10 +183,10 @@ NumberList::NumberList(const std::string &list, bool descending) : desc(descendi { size_t t = token.find('-'); - if (t == std::string::npos) + if (t == Anope::string::npos) { - unsigned num = strtol(token.c_str(), &error, 10); - if (!*error) + unsigned num = convertTo<unsigned>(token, error, false); + if (error.empty()) numbers.insert(num); else { @@ -252,10 +199,10 @@ NumberList::NumberList(const std::string &list, bool descending) : desc(descendi } else { - char *error2; - unsigned num1 = strtol(token.substr(0, t).c_str(), &error, 10); - unsigned num2 = strtol(token.substr(t + 1).c_str(), &error2, 10); - if (!*error && !*error2) + Anope::string error2; + unsigned num1 = convertTo<unsigned>(token.substr(0, t), error, false); + unsigned num2 = convertTo<unsigned>(token.substr(t + 1), error2, false); + if (error.empty() && error2.empty()) { for (unsigned i = num1; i <= num2; ++i) numbers.insert(i); @@ -299,7 +246,7 @@ void NumberList::HandleNumber(unsigned) { } -bool NumberList::InvalidRange(const std::string &) +bool NumberList::InvalidRange(const Anope::string &) { return true; } @@ -315,17 +262,18 @@ bool NumberList::InvalidRange(const std::string &) * @param s String to convert * @return time_t */ -time_t dotime(const char *s) +time_t dotime(const Anope::string &s) { int amount; - if (!s || !*s) + if (s.empty()) return -1; - amount = strtol(s, const_cast<char **>(&s), 10); - if (*s) + Anope::string end; + amount = convertTo<int>(s, end, false); + if (!end.empty()) { - switch (*s) + switch (end[0]) { case 's': return amount; @@ -353,17 +301,16 @@ time_t dotime(const char *s) * Expresses in a string the period of time represented by a given amount * of seconds (with days/hours/minutes). * @param na Nick Alias - * @param buf buffer to store result into - * @param bufsize Size of the buffer * @param seconds time in seconds * @return buffer */ -const char *duration(NickCore *nc, char *buf, int bufsize, time_t seconds) +Anope::string duration(const NickCore *nc, time_t seconds) { int days = 0, hours = 0, minutes = 0; int need_comma = 0; - char buf2[64], *end; + char buf[64]; + Anope::string buffer; const char *comma = getstring(nc, COMMA_SPACE); /* We first calculate everything */ @@ -374,31 +321,32 @@ const char *duration(NickCore *nc, char *buf, int bufsize, time_t seconds) minutes = seconds / 60; if (!days && !hours && !minutes) - snprintf(buf, bufsize, getstring(nc, seconds <= 1 ? DURATION_SECOND : DURATION_SECONDS), seconds); + { + snprintf(buf, sizeof(buf), getstring(nc, seconds <= 1 ? DURATION_SECOND : DURATION_SECONDS), seconds); + buffer = buf; + } else { - end = buf; if (days) { - snprintf(buf2, sizeof(buf2), getstring(nc, days == 1 ? DURATION_DAY : DURATION_DAYS), days); - end += snprintf(end, bufsize - (end - buf), "%s", buf2); + snprintf(buf, sizeof(buf), getstring(nc, days == 1 ? DURATION_DAY : DURATION_DAYS), days); + buffer = buf; need_comma = 1; } if (hours) { - snprintf(buf2, sizeof(buf2), getstring(nc, hours == 1 ? DURATION_HOUR : DURATION_HOURS), hours); - end += snprintf(end, bufsize - (end - buf), "%s%s", need_comma ? comma : "", buf2); + snprintf(buf, sizeof(buf), getstring(nc, hours == 1 ? DURATION_HOUR : DURATION_HOURS), hours); + buffer += Anope::string(need_comma ? comma : "") + buf; need_comma = 1; } if (minutes) { - snprintf(buf2, sizeof(buf2), getstring(nc, minutes == 1 ? DURATION_MINUTE : DURATION_MINUTES), minutes); - end += snprintf(end, bufsize - (end - buf), "%s%s", need_comma ? comma : "", buf2); - need_comma = 1; + snprintf(buf, sizeof(buf), getstring(nc, minutes == 1 ? DURATION_MINUTE : DURATION_MINUTES), minutes); + buffer += Anope::string(need_comma ? comma : "") + buf; } } - return buf; + return buffer; } /*************************************************************************/ @@ -406,19 +354,19 @@ const char *duration(NickCore *nc, char *buf, int bufsize, time_t seconds) /** * Generates a human readable string of type "expires in ..." * @param na Nick Alias - * @param buf buffer to store result into - * @param bufsize Size of the buffer * @param seconds time in seconds * @return buffer */ -const char *expire_left(NickCore *nc, char *buf, int len, time_t expires) +Anope::string expire_left(const NickCore *nc, time_t expires) { time_t now = time(NULL); + char buf[256]; + if (!expires) - strlcpy(buf, getstring(nc, NO_EXPIRE), len); + strlcpy(buf, getstring(nc, NO_EXPIRE), sizeof(buf)); else if (expires <= now) - strlcpy(buf, getstring(nc, EXPIRES_SOON), len); + strlcpy(buf, getstring(nc, EXPIRES_SOON), sizeof(buf)); else { time_t diff = expires - now + 59; @@ -426,21 +374,21 @@ const char *expire_left(NickCore *nc, char *buf, int len, time_t expires) if (diff >= 86400) { int days = diff / 86400; - snprintf(buf, len, getstring(nc, days == 1 ? EXPIRES_1D : EXPIRES_D), days); + snprintf(buf, sizeof(buf), getstring(nc, days == 1 ? EXPIRES_1D : EXPIRES_D), days); } else { if (diff <= 3600) { int minutes = diff / 60; - snprintf(buf, len, getstring(nc, minutes == 1 ? EXPIRES_1M : EXPIRES_M), minutes); + snprintf(buf, sizeof(buf), getstring(nc, minutes == 1 ? EXPIRES_1M : EXPIRES_M), minutes); } else { int hours = diff / 3600, minutes; diff -= hours * 3600; minutes = diff / 60; - snprintf(buf, len, getstring(nc, hours == 1 && minutes == 1 ? EXPIRES_1H1M : (hours == 1 && minutes != 1 ? EXPIRES_1HM : (hours != 1 && minutes == 1 ? EXPIRES_H1M : EXPIRES_HM))), hours, minutes); + snprintf(buf, sizeof(buf), getstring(nc, hours == 1 && minutes == 1 ? EXPIRES_1H1M : (hours == 1 && minutes != 1 ? EXPIRES_1HM : (hours != 1 && minutes == 1 ? EXPIRES_H1M : EXPIRES_HM))), hours, minutes); } } } @@ -448,19 +396,18 @@ const char *expire_left(NickCore *nc, char *buf, int len, time_t expires) return buf; } - /*************************************************************************/ /** * Validate the host * shortname = ( letter / digit ) *( letter / digit / "-" ) *( letter / digit ) * hostname = shortname *( "." shortname ) - * ip4addr = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit + * ip4addr = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit * @param host = string to check * @param type = format, 1 = ip4addr, 2 = hostname * @return 1 if a host is valid, 0 if it isnt. */ -int doValidHost(const char *host, int type) +int doValidHost(const Anope::string &host, int type) { int idx = 0; int len = 0; @@ -468,10 +415,10 @@ int doValidHost(const char *host, int type) int dots = 1; if (type != 1 && type != 2) return 0; - if (!host) + if (host.empty()) return 0; - len = strlen(host); + len = host.length(); if (len > Config.HostLen) return 0; @@ -539,7 +486,7 @@ int doValidHost(const char *host, int type) * @param type = format, 1 = ip4addr, 2 = hostname * @return 1 if a host is valid, 0 if it isnt. */ -int isValidHost(const char *host, int type) +int isValidHost(const Anope::string &host, int type) { int status = 0; if (type == 3) @@ -576,54 +523,18 @@ int isvalidchar(const char c) * @param token_number the token number * @return token */ -char *myStrGetToken(const char *str, const char dilim, int token_number) +Anope::string myStrGetToken(const Anope::string &str, char delim, int token_number) { - int len, idx, counter = 0, start_pos = 0; - char *substring = NULL; - if (!str) - return NULL; - len = strlen(str); - for (idx = 0; idx <= len; ++idx) - { - if (str[idx] == dilim || idx == len) - { - if (counter == token_number) - substring = myStrSubString(str, start_pos, idx); - else - start_pos = idx + 1; - ++counter; - } - } - return substring; -} + if (str.empty()) + return ""; -/*************************************************************************/ - -/** - * Get the token only - * @param str String to search in - * @param dilim Character to search for - * @param token_number the token number - * @return token - */ -char *myStrGetOnlyToken(const char *str, const char dilim, int token_number) -{ - int len, idx, counter = 0, start_pos = 0; - char *substring = NULL; - if (!str) - return NULL; - len = strlen(str); - for (idx = 0; idx <= len; ++idx) + Anope::string substring; + for (size_t idx = 0, len = str.length(), start_pos = 0, counter = 0; idx <= len; ++idx) { - if (str[idx] == dilim) + if (str[idx] == delim || idx == len) { if (counter == token_number) - { - if (str[idx] == '\r') - substring = myStrSubString(str, start_pos, idx - 1); - else - substring = myStrSubString(str, start_pos, idx); - } + substring = str.substr(start_pos, idx - start_pos - 1); else start_pos = idx + 1; ++counter; @@ -641,20 +552,18 @@ char *myStrGetOnlyToken(const char *str, const char dilim, int token_number) * @param token_number the token number * @return token */ -char *myStrGetTokenRemainder(const char *str, const char dilim, int token_number) +Anope::string myStrGetTokenRemainder(const Anope::string &str, const char dilim, int token_number) { - int len, idx, counter = 0, start_pos = 0; - char *substring = NULL; - if (!str) - return NULL; - len = strlen(str); + if (str.empty()) + return ""; - for (idx = 0; idx <= len; ++idx) + Anope::string substring; + for (size_t idx = 0, len = str.length(), start_pos = 0, counter = 0; idx <= len; ++idx) { if (str[idx] == dilim || idx == len) { if (counter == token_number) - substring = myStrSubString(str, start_pos, len); + substring = str.substr(start_pos); else start_pos = idx + 1; ++counter; @@ -666,32 +575,6 @@ char *myStrGetTokenRemainder(const char *str, const char dilim, int token_number /*************************************************************************/ /** - * Get the string between point A and point B - * @param str String to search in - * @param start Point A - * @param end Point B - * @return the string in between - */ -char *myStrSubString(const char *src, int start, int end) -{ - char *substring = NULL; - int len, idx; - if (!src) - return NULL; - len = strlen(src); - if (start >= 0 && end <= len && end > start) - { - substring = new char[(end - start) + 1]; - for (idx = 0; idx <= end - start; ++idx) - substring[idx] = src[start + idx]; - substring[end - start] = '\0'; - } - return substring; -} - -/*************************************************************************/ - -/** * Clean up the buffer for extra spaces * @param str to clean up * @return void @@ -733,17 +616,17 @@ void doCleanBuffer(char *str) * @param killer whom is doing the killing * @return void */ -void EnforceQlinedNick(const std::string &nick, const char *killer) +void EnforceQlinedNick(const Anope::string &nick, const Anope::string &killer) { if (findbot(nick)) return; - + User *u2 = finduser(nick); if (u2) { Alog() << "Killed Q-lined nick: " << u2->GetMask(); - kill_user(killer, u2->nick.c_str(), "This nick is reserved for Services. Please use a non Q-Lined nick."); + kill_user(killer, u2->nick, "This nick is reserved for Services. Please use a non Q-Lined nick."); } } @@ -755,49 +638,45 @@ void EnforceQlinedNick(const std::string &nick, const char *killer) * @param int Check if botserv bots * @return int */ -int nickIsServices(const char *tempnick, int bot) +int nickIsServices(const Anope::string &tempnick, int bot) { int found = 0; - char *s, *nick; - if (!tempnick) + if (tempnick.empty()) return found; - nick = sstrdup(tempnick); + Anope::string nick = tempnick; - s = strchr(nick, '@'); - if (s) + size_t at = nick.find('@'); + if (at != Anope::string::npos) { - *s++ = 0; - if (stricmp(s, Config.ServerName)) - { - delete [] nick; + Anope::string servername = nick.substr(at + 1); + if (!servername.equals_ci(Config.ServerName)) return found; - } + nick = nick.substr(0, at); } - if (Config.s_NickServ && !stricmp(nick, Config.s_NickServ)) + if (!Config.s_NickServ.empty() && nick.equals_ci(Config.s_NickServ)) ++found; - else if (Config.s_ChanServ && !stricmp(nick, Config.s_ChanServ)) + else if (!Config.s_ChanServ.empty() && nick.equals_ci(Config.s_ChanServ)) ++found; - else if (Config.s_HostServ && !stricmp(nick, Config.s_HostServ)) + else if (!Config.s_HostServ.empty() && nick.equals_ci(Config.s_HostServ)) ++found; - else if (Config.s_MemoServ && !stricmp(nick, Config.s_MemoServ)) + else if (!Config.s_MemoServ.empty() && nick.equals_ci(Config.s_MemoServ)) ++found; - else if (Config.s_BotServ && !stricmp(nick, Config.s_BotServ)) + else if (!Config.s_BotServ.empty() && nick.equals_ci(Config.s_BotServ)) ++found; - else if (Config.s_OperServ && !stricmp(nick, Config.s_OperServ)) + else if (!Config.s_OperServ.empty() && nick.equals_ci(Config.s_OperServ)) ++found; - else if (Config.s_GlobalNoticer && !stricmp(nick, Config.s_GlobalNoticer)) + else if (!Config.s_GlobalNoticer.empty() && nick.equals_ci(Config.s_GlobalNoticer)) ++found; - else if (Config.s_BotServ && bot) + else if (!Config.s_BotServ.empty() && bot) { for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) { BotInfo *bi = it->second; - ci::string ci_bi_nick(bi->nick.c_str()); - if (ci_bi_nick == nick) + if (nick.equals_ci(bi->nick)) { ++found; break; @@ -805,9 +684,6 @@ int nickIsServices(const char *tempnick, int bot) } } - /* Somehow, something tells me we should free this :) -GD */ - delete [] nick; - return found; } @@ -967,20 +843,14 @@ uint32 getrandom32() * @param dilim Dilimiter * @return number of tokens */ -int myNumToken(const char *str, const char dilim) +int myNumToken(const Anope::string &str, char dilim) { - int len, idx, counter = 0, start_pos = 0; - if (!str) + if (str.empty()) return 0; - len = strlen(str); - for (idx = 0; idx <= len; ++idx) - { + int counter = 0; + for (size_t idx = 0, len = str.length(); idx <= len; ++idx) if (str[idx] == dilim || idx == len) - { - start_pos = idx + 1; ++counter; - } - } return counter; } @@ -991,24 +861,22 @@ int myNumToken(const char *str, const char dilim) * @param host to convert * @return ip address */ -char *host_resolve(char *host) +Anope::string host_resolve(const Anope::string &host) { struct hostent *hentp = NULL; uint32 ip = INADDR_NONE; char ipbuf[16]; - char *ipreturn; + Anope::string ipreturn; struct in_addr addr; - ipreturn = NULL; - - hentp = gethostbyname(host); + hentp = gethostbyname(host.c_str()); if (hentp) { memcpy(&ip, hentp->h_addr, sizeof(hentp->h_length)); addr.s_addr = ip; ntoa(addr, ipbuf, sizeof(ipbuf)); - ipreturn = sstrdup(ipbuf); + ipreturn = ipbuf; Alog(LOG_DEBUG) << "resolved " << host << " to " << ipbuf; } return ipreturn; @@ -1020,11 +888,11 @@ char *host_resolve(char *host) * @param src The source string * @return a list of strings */ -std::list<std::string> BuildStringList(const std::string &src) +std::list<Anope::string> BuildStringList(const Anope::string &src) { spacesepstream tokens(src); - std::string token; - std::list<std::string> Ret; + Anope::string token; + std::list<Anope::string> Ret; while (tokens.GetToken(token)) Ret.push_back(token); @@ -1032,23 +900,11 @@ std::list<std::string> BuildStringList(const std::string &src) return Ret; } -std::list<ci::string> BuildStringList(const ci::string &src) +std::vector<Anope::string> BuildStringVector(const Anope::string &src) { spacesepstream tokens(src); - ci::string token; - std::list<ci::string> Ret; - - while (tokens.GetToken(token)) - Ret.push_back(token); - - return Ret; -} - -std::vector<std::string> BuildStringVector(const std::string &src) -{ - spacesepstream tokens(src); - std::string token; - std::vector<std::string> Ret; + Anope::string token; + std::vector<Anope::string> Ret; while (tokens.GetToken(token)) Ret.push_back(token); @@ -1073,25 +929,13 @@ char *str_signed(unsigned char *str) while (*str) { *nstr = static_cast<char>(*str); - str++; - nstr++; + ++str; + ++nstr; } return nstr; } -/** - * Strip the mode prefix from the given string. - * Useful for using the modes stored in things like ircd->ownerset etc.. - **/ - -char *stripModePrefix(const char *str) -{ - if (str && (*str == '+' || *str == '-')) - return sstrdup(str + 1); - return NULL; -} - /* Equivalent to inet_ntoa */ void ntoa(struct in_addr addr, char *ipaddr, int len) @@ -1194,36 +1038,32 @@ size_t strlcpy(char *dst, const char *src, size_t siz) #endif #ifdef _WIN32 -char *GetWindowsVersion() +Anope::string GetWindowsVersion() { OSVERSIONINFOEX osvi; BOOL bOsVersionInfoEx; - char buf[BUFSIZE]; - char *extra; - char *cputype; + Anope::string buf, extra, cputype; SYSTEM_INFO si; ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); ZeroMemory(&si, sizeof(SYSTEM_INFO)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - if (!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi))) + if (!(bOsVersionInfoEx = GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&osvi)))) { osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - if (!GetVersionEx((OSVERSIONINFO *)&osvi)) - return sstrdup(""); + if (!GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&osvi))) + return ""; } GetSystemInfo(&si); /* Determine CPU type 32 or 64 */ if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) - cputype = sstrdup(" 64-bit"); + cputype = " 64-bit"; else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) - cputype = sstrdup(" 32-bit"); + cputype = " 32-bit"; else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) - cputype = sstrdup(" Itanium 64-bit"); - else - cputype = sstrdup(" "); + cputype = " Itanium 64-bit"; switch (osvi.dwPlatformId) { @@ -1233,96 +1073,78 @@ char *GetWindowsVersion() if (osvi.dwMajorVersion == 6 && !osvi.dwMinorVersion) { if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) - extra = sstrdup("Enterprise Edition"); + extra = " Enterprise Edition"; else if (osvi.wSuiteMask & VER_SUITE_DATACENTER) - extra = sstrdup("Datacenter Edition"); + extra = " Datacenter Edition"; else if (osvi.wSuiteMask & VER_SUITE_PERSONAL) - extra = sstrdup("Home Premium/Basic"); - else - extra = sstrdup(" "); + extra = " Home Premium/Basic"; if (osvi.wProductType & VER_NT_WORKSTATION) - snprintf(buf, sizeof(buf), "Microsoft Windows Vista %s%s", cputype, extra); + buf = "Microsoft Windows Vista" + cputype + extra; else - snprintf(buf, sizeof(buf), "Microsoft Windows Server 2008 %s%s", cputype, extra); - delete [] extra; + buf = "Microsoft Windows Server 2008" + cputype + extra; } /* Windows 2003 or Windows XP Pro 64 */ if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) { if (osvi.wSuiteMask & VER_SUITE_DATACENTER) - extra = sstrdup("Datacenter Edition"); + extra = " Datacenter Edition"; else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) - extra = sstrdup("Enterprise Edition"); + extra = " Enterprise Edition"; #ifdef VER_SUITE_COMPUTE_SERVER else if (osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER) - extra = sstrdup("Compute Cluster Edition"); + extra = " Compute Cluster Edition"; #endif else if (osvi.wSuiteMask == VER_SUITE_BLADE) - extra = sstrdup("Web Edition"); + extra = " Web Edition"; else - extra = sstrdup("Standard Edition"); + extra = " Standard Edition"; if (osvi.wProductType & VER_NT_WORKSTATION && si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) - snprintf(buf, sizeof(buf), "Windows XP Professional x64 Edition %s", extra); + buf = "Microsoft Windows XP Professional x64 Edition" + extra; else - snprintf(buf, sizeof(buf), "Microsoft Windows Server 2003 Family %s%s", cputype, extra); - delete [] extra; + buf = "Microsoft Windows Server 2003 Family" + cputype + extra; } if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) { if (osvi.wSuiteMask & VER_SUITE_EMBEDDEDNT) - extra = sstrdup("Embedded"); + extra = " Embedded"; else if (osvi.wSuiteMask & VER_SUITE_PERSONAL) - extra = sstrdup("Home Edition"); - else - extra = sstrdup(" "); - snprintf(buf, sizeof(buf), "Microsoft Windows XP %s", extra); - delete [] extra; + extra = " Home Edition"; + buf = "Microsoft Windows XP" + extra; } if (osvi.dwMajorVersion == 5 && !osvi.dwMinorVersion) { if (osvi.wSuiteMask & VER_SUITE_DATACENTER) - extra = sstrdup("Datacenter Server"); + extra = " Datacenter Server"; else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) - extra = sstrdup("Advanced Server"); + extra = " Advanced Server"; else - extra = sstrdup("Server"); - snprintf(buf, sizeof(buf), "Microsoft Windows 2000 %s", extra); - delete [] extra; + extra = " Server"; + buf = "Microsoft Windows 2000" + extra; } if (osvi.dwMajorVersion <= 4) { if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) - extra = sstrdup("Server 4.0, Enterprise Edition"); - else - extra = sstrdup("Server 4.0"); - snprintf(buf, sizeof(buf), "Microsoft Windows NT %s", extra); - delete [] extra; + extra = " Enterprise Edition"; + buf = "Microsoft Windows NT Server 4.0" + extra; } break; case VER_PLATFORM_WIN32_WINDOWS: if (osvi.dwMajorVersion == 4 && !osvi.dwMinorVersion) { if (osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B') - extra = sstrdup("OSR2"); - else - extra = sstrdup(" "); - snprintf(buf, sizeof(buf), "Microsoft Windows 95 %s", extra); - delete [] extra; + extra = " OSR2"; + buf = "Microsoft Windows 95" + extra; } if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) { if (osvi.szCSDVersion[1] == 'A') - extra = sstrdup("SE"); - else - extra = sstrdup(" "); - snprintf(buf, sizeof(buf), "Microsoft Windows 98 %s", extra); - delete [] extra; + extra = "SE"; + buf = "Microsoft Windows 98" + extra; } if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) - snprintf(buf, sizeof(buf), "Microsoft Windows Millennium Edition"); + buf = "Microsoft Windows Millenium Edition"; } - delete [] cputype; - return sstrdup(buf); + return buf; } int SupportedWindowsVersion() @@ -1333,10 +1155,10 @@ int SupportedWindowsVersion() ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - if (!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi))) + if (!(bOsVersionInfoEx = GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&osvi)))) { osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - if (!GetVersionEx((OSVERSIONINFO *)&osvi)) + if (!GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&osvi))) return 0; } @@ -1396,14 +1218,11 @@ uint16 netmask_to_cidr(uint32 mask) * @param str String to check * @return 1 for wildcard, 0 for anything else */ -int str_is_wildcard(const char *str) +int str_is_wildcard(const Anope::string &str) { - while (*str) - { - if (*str == '*' || *str == '?') + for (Anope::string::const_iterator c = str.begin(), c_end = str.end(); c != c_end; ++c) + if (*c == '*' || *c == '?') return 1; - ++str; - } return 0; } @@ -1413,14 +1232,11 @@ int str_is_wildcard(const char *str) * @param str String to check * @return 1 for pure wildcard, 0 for anything else */ -int str_is_pure_wildcard(const char *str) +int str_is_pure_wildcard(const Anope::string &str) { - while (*str) - { - if (*str != '*') + for (Anope::string::const_iterator c = str.begin(), c_end = str.end(); c != c_end; ++c) + if (*c != '*') return 0; - ++str; - } return 1; } @@ -1432,21 +1248,19 @@ int str_is_pure_wildcard(const char *str) * @param str String to check * @return The IP, if one found. 0 if none. */ -uint32 str_is_ip(char *str) +uint32 str_is_ip(const Anope::string &str) { int i; int octets[4] = { -1, -1, -1, -1 }; - char *s = str; + Anope::string s = str; uint32 ip; for (i = 0; i < 4; ++i) { - octets[i] = strtol(s, &s, 10); + octets[i] = convertTo<int>(s, s, false); /* Bail out if the octet is invalid or wrongly terminated */ - if (octets[i] < 0 || octets[i] > 255 || (i < 3 && *s != '.')) + if (octets[i] < 0 || octets[i] > 255 || (i < 3 && s[0] != '.')) return 0; - if (i < 3) - ++s; } /* Fill the IP - the dirty way */ @@ -1469,22 +1283,19 @@ uint32 str_is_ip(char *str) * @param host Displayed host * @return 1 for IP/CIDR, 0 for anything else */ -int str_is_cidr(char *str, uint32 *ip, uint32 *mask, char **host) +int str_is_cidr(const Anope::string &str, uint32 *ip, uint32 *mask, Anope::string &host) { int i; int octets[4] = { -1, -1, -1, -1 }; - char *s = str; - char buf[512]; + Anope::string s = str; uint16 cidr; for (i = 0; i < 4; ++i) { - octets[i] = strtol(s, &s, 10); + octets[i] = convertTo<int>(s, s, false); /* Bail out if the octet is invalid or wrongly terminated */ - if (octets[i] < 0 || octets[i] > 255 || (i < 3 && *s != '.')) + if (octets[i] < 0 || octets[i] > 255 || (i < 3 && s[0] != '.')) return 0; - if (i < 3) - ++s; } /* Fill the IP - the dirty way */ @@ -1493,13 +1304,12 @@ int str_is_cidr(char *str, uint32 *ip, uint32 *mask, char **host) *ip += octets[1] * 65536; *ip += octets[0] * 16777216; - if (*s == '/') + if (s[0] == '/') { - ++s; /* There's a CIDR mask here! */ - cidr = strtol(s, &s, 10); + cidr = convertTo<uint16>(s.substr(1), s, false); /* Bail out if the CIDR is invalid or the string isn't done yet */ - if (cidr > 32 || *s) + if (cidr > 32 || s[0]) return 0; } else @@ -1516,12 +1326,9 @@ int str_is_cidr(char *str, uint32 *ip, uint32 *mask, char **host) octets[2] = (*ip & 0x0000FF00) / 256; octets[3] = (*ip & 0x000000FF); - if (cidr == 32) - snprintf(buf, 512, "%d.%d.%d.%d", octets[0], octets[1], octets[2], octets[3]); - else - snprintf(buf, 512, "%d.%d.%d.%d/%d", octets[0], octets[1], octets[2], octets[3], cidr); - - *host = sstrdup(buf); + host = stringify(octets[0]) + "." + stringify(octets[1]) + "." + stringify(octets[2]) + "." + stringify(octets[3]); + if (cidr != 32) + host += "/" + stringify(cidr); return 1; } diff --git a/src/modes.cpp b/src/modes.cpp index 38ac2ad00..3642b977e 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -32,7 +32,7 @@ Flags<ChannelModeName, CMODE_END> DefMLockOn; /* Default mlocked modes off */ Flags<ChannelModeName, CMODE_END> DefMLockOff; /* Map for default mlocked mode parameters */ -std::map<ChannelModeName, std::string> DefMLockParams; +std::map<ChannelModeName, Anope::string> DefMLockParams; /* Modes to set on bots when they join the channel */ std::list<ChannelModeStatus *> BotModes; @@ -45,11 +45,11 @@ void SetDefaultMLock() DefMLockParams.clear(); Flags<ChannelModeName, CMODE_END> *ptr = NULL; - std::string modes, param; + Anope::string modes, param; spacesepstream sep(Config.MLock); sep.GetToken(modes); - for (unsigned i = 0, end_mode = modes.size(); i < end_mode; ++i) + for (unsigned i = 0, end_mode = modes.length(); i < end_mode; ++i) { if (modes[i] == '+') ptr = &DefMLockOn; @@ -82,7 +82,7 @@ void SetDefaultMLock() /* Set Bot Modes */ BotModes.clear(); - for (unsigned i = 0, end_mode = Config.BotModes.size(); i < end_mode; ++i) + for (unsigned i = 0, end_mode = Config.BotModes.length(); i < end_mode; ++i) { ChannelMode *cm = ModeManager::FindChannelModeByChar(Config.BotModes[i]); @@ -97,7 +97,7 @@ void SetDefaultMLock() * @param modeChar The mode char * @param modeType The mode type */ -Mode::Mode(ModeClass mClass, const std::string &mNameAsString, char modeChar, ModeType modeType) : Class(mClass), NameAsString(mNameAsString), ModeChar(modeChar), Type(modeType) +Mode::Mode(ModeClass mClass, const Anope::string &mNameAsString, char modeChar, ModeType modeType) : Class(mClass), NameAsString(mNameAsString), ModeChar(modeChar), Type(modeType) { } @@ -112,7 +112,7 @@ Mode::~Mode() * @param mNameAsString The mode name as a string * @param modeChar The mode char */ -UserMode::UserMode(UserModeName mName, const std::string &mNameAsString, char modeChar) : Mode(MC_USER, mNameAsString, modeChar, MODE_REGULAR), Name(mName) +UserMode::UserMode(UserModeName mName, const Anope::string &mNameAsString, char modeChar) : Mode(MC_USER, mNameAsString, modeChar, MODE_REGULAR), Name(mName) { } @@ -127,7 +127,7 @@ UserMode::~UserMode() * @param mNameAsString The mode name as a string * @param modeChar The mode char */ -UserModeParam::UserModeParam(UserModeName mName, const std::string &mNameAsString, char modeChar) : UserMode(mName, mNameAsString, modeChar) +UserModeParam::UserModeParam(UserModeName mName, const Anope::string &mNameAsString, char modeChar) : UserMode(mName, mNameAsString, modeChar) { this->Type = MODE_PARAM; } @@ -137,7 +137,7 @@ UserModeParam::UserModeParam(UserModeName mName, const std::string &mNameAsStrin * @param mNameAsString The mode name as a string * @param modeChar The mode char */ -ChannelMode::ChannelMode(ChannelModeName mName, const std::string &mNameAsString, char modeChar) : Mode(MC_CHANNEL, mNameAsString, modeChar, MODE_REGULAR), Name(mName) +ChannelMode::ChannelMode(ChannelModeName mName, const Anope::string &mNameAsString, char modeChar) : Mode(MC_CHANNEL, mNameAsString, modeChar, MODE_REGULAR), Name(mName) { } @@ -152,7 +152,7 @@ ChannelMode::~ChannelMode() * @param mNameAsString The mode name as a string * @param modeChar The mode char */ -ChannelModeList::ChannelModeList(ChannelModeName mName, const std::string &mNameAsString, char modeChar) : ChannelMode(mName, mNameAsString, modeChar) +ChannelModeList::ChannelModeList(ChannelModeName mName, const Anope::string &mNameAsString, char modeChar) : ChannelMode(mName, mNameAsString, modeChar) { this->Type = MODE_LIST; } @@ -169,7 +169,7 @@ ChannelModeList::~ChannelModeList() * @param modeChar The mode char * @param MinusArg true if the mode sends no arg when unsetting */ -ChannelModeParam::ChannelModeParam(ChannelModeName mName, const std::string &mNameAsString, char modeChar, bool MinusArg) : ChannelMode(mName, mNameAsString, modeChar), MinusNoArg(MinusArg) +ChannelModeParam::ChannelModeParam(ChannelModeName mName, const Anope::string &mNameAsString, char modeChar, bool MinusArg) : ChannelMode(mName, mNameAsString, modeChar), MinusNoArg(MinusArg) { this->Type = MODE_PARAM; } @@ -186,7 +186,7 @@ ChannelModeParam::~ChannelModeParam() * @param modeChar The mode char * @param mSymbol The symbol for the mode, eg @ % + */ -ChannelModeStatus::ChannelModeStatus(ChannelModeName mName, const std::string &mNameAsString, char modeChar, char mSymbol) : ChannelMode(mName, mNameAsString, modeChar), Symbol(mSymbol) +ChannelModeStatus::ChannelModeStatus(ChannelModeName mName, const Anope::string &mNameAsString, char modeChar, char mSymbol) : ChannelMode(mName, mNameAsString, modeChar), Symbol(mSymbol) { this->Type = MODE_STATUS; } @@ -201,9 +201,9 @@ ChannelModeStatus::~ChannelModeStatus() * @param value The key * @return true or false */ -bool ChannelModeKey::IsValid(const std::string &value) +bool ChannelModeKey::IsValid(const Anope::string &value) { - if (!value.empty() && value.find(':') != std::string::npos && value.find(',') != std::string::npos) + if (!value.empty() && value.find(':') != Anope::string::npos && value.find(',') != Anope::string::npos) return true; return false; @@ -246,12 +246,12 @@ bool ChannelModeRegistered::CanSet(User *u) * @param chan The channel * @param mask The ban */ -void ChannelModeBan::AddMask(Channel *chan, const char *mask) +void ChannelModeBan::AddMask(Channel *chan, const Anope::string &mask) { Entry *ban; /* check for NULL values otherwise we will segfault */ - if (!chan || !mask) + if (!chan || mask.empty()) { Alog(LOG_DEBUG) << "add_ban called with NULL values"; return; @@ -268,13 +268,13 @@ void ChannelModeBan::AddMask(Channel *chan, const char *mask) /* Check whether it matches a botserv bot after adding internally * and parsing it through cidr support. ~ Viper */ - if (Config.s_BotServ && Config.BSSmartJoin && chan->ci && chan->ci->bi && chan->FindUser(chan->ci->bi)) + if (!Config.s_BotServ.empty() && Config.BSSmartJoin && chan->ci && chan->ci->bi && chan->FindUser(chan->ci->bi)) { BotInfo *bi = chan->ci->bi; - if (entry_match(ban, bi->nick.c_str(), bi->GetIdent().c_str(), bi->host, 0)) + if (entry_match(ban, bi->nick, bi->GetIdent(), bi->host, 0)) { - ircdproto->SendMode(bi, chan, "-b %s", mask); + ircdproto->SendMode(bi, chan, "-b %s", mask.c_str()); entry_delete(chan->bans, ban); return; } @@ -287,13 +287,13 @@ void ChannelModeBan::AddMask(Channel *chan, const char *mask) * @param chan The channel * @param mask The ban */ -void ChannelModeBan::DelMask(Channel *chan, const char *mask) +void ChannelModeBan::DelMask(Channel *chan, const Anope::string &mask) { AutoKick *akick; Entry *ban; /* Sanity check as it seems some IRCD will just send -b without a mask */ - if (!mask || !chan->bans || !chan->bans->count) + if (mask.empty() || !chan->bans || !chan->bans->count) return; ban = elist_find_mask(chan->bans, mask); @@ -313,11 +313,11 @@ void ChannelModeBan::DelMask(Channel *chan, const char *mask) * @param chan The channel * @param mask The except */ -void ChannelModeExcept::AddMask(Channel *chan, const char *mask) +void ChannelModeExcept::AddMask(Channel *chan, const Anope::string &mask) { Entry *exception; - if (!chan || !mask) + if (!chan || mask.empty()) { Alog(LOG_DEBUG) << "add_exception called with NULL values"; return; @@ -339,12 +339,12 @@ void ChannelModeExcept::AddMask(Channel *chan, const char *mask) * @param chan The channel * @param mask The except */ -void ChannelModeExcept::DelMask(Channel *chan, const char *mask) +void ChannelModeExcept::DelMask(Channel *chan, const Anope::string &mask) { Entry *exception; /* Sanity check as it seems some IRCD will just send -e without a mask */ - if (!mask || !chan->excepts || !chan->excepts->count) + if (mask.empty() || !chan->excepts || !chan->excepts->count) return; exception = elist_find_mask(chan->excepts, mask); @@ -360,11 +360,11 @@ void ChannelModeExcept::DelMask(Channel *chan, const char *mask) * @param chan The channel * @param mask The invex */ -void ChannelModeInvex::AddMask(Channel *chan, const char *mask) +void ChannelModeInvex::AddMask(Channel *chan, const Anope::string &mask) { Entry *invite; - if (!chan || !mask) + if (!chan || mask.empty()) { Alog(LOG_DEBUG) << "add_invite called with NULL values"; return; @@ -387,12 +387,12 @@ void ChannelModeInvex::AddMask(Channel *chan, const char *mask) * @param chan The channel * @param mask The index */ -void ChannelModeInvex::DelMask(Channel *chan, const char *mask) +void ChannelModeInvex::DelMask(Channel *chan, const Anope::string &mask) { Entry *invite; /* Sanity check as it seems some IRCD will just send -I without a mask */ - if (!mask || !chan->invites || !chan->invites->count) + if (mask.empty() || !chan->invites || !chan->invites->count) return; invite = elist_find_mask(chan->invites, mask); @@ -404,12 +404,12 @@ void ChannelModeInvex::DelMask(Channel *chan, const char *mask) } } -void StackerInfo::AddMode(void *Mode, bool Set, const std::string &Param) +void StackerInfo::AddMode(void *Mode, bool Set, const Anope::string &Param) { ChannelMode *cm = NULL; UserMode *um = NULL; - std::list<std::pair<void *, std::string> > *list, *otherlist; - std::list<std::pair<void *, std::string > >::iterator it, it_end; + std::list<std::pair<void *, Anope::string> > *list, *otherlist; + std::list<std::pair<void *, Anope::string > >::iterator it, it_end; bool IsParam = false; if (Type == ST_CHANNEL) @@ -441,7 +441,7 @@ void StackerInfo::AddMode(void *Mode, bool Set, const std::string &Param) /* The param must match too (can have multiple status or list modes), but * if it is a param mode it can match no matter what the param is */ - if (it->first == Mode && (it->second == Param || IsParam)) + if (it->first == Mode && (Param.equals_cs(it->second) || IsParam)) { list->erase(it); /* It can only be on this list once */ @@ -454,7 +454,7 @@ void StackerInfo::AddMode(void *Mode, bool Set, const std::string &Param) /* The param must match too (can have multiple status or list modes), but * if it is a param mode it can match no matter what the param is */ - if (it->first == Mode && (it->second == Param || IsParam)) + if (it->first == Mode && (Param.equals_cs(it->second) || IsParam)) { otherlist->erase(it); return; @@ -491,11 +491,11 @@ StackerInfo *ModeManager::GetInfo(void *Item) * @param info The stacker info for a channel or user * @return a list of strings */ -std::list<std::string> ModeManager::BuildModeStrings(StackerInfo *info) +std::list<Anope::string> ModeManager::BuildModeStrings(StackerInfo *info) { - std::list<std::string> ret; - std::list<std::pair<void *, std::string> >::iterator it, it_end; - std::string buf, parambuf; + std::list<Anope::string> ret; + std::list<std::pair<void *, Anope::string> >::iterator it, it_end; + Anope::string buf, parambuf; ChannelMode *cm = NULL; UserMode *um = NULL; unsigned NModes = 0; @@ -571,7 +571,7 @@ std::list<std::string> ModeManager::BuildModeStrings(StackerInfo *info) * @param Set Adding or removing? * @param Param A param, if there is one */ -void ModeManager::StackerAddInternal(BotInfo *bi, User *u, UserMode *um, bool Set, const std::string &Param) +void ModeManager::StackerAddInternal(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param) { StackerAddInternal(bi, u, um, Set, Param, ST_USER); } @@ -583,7 +583,7 @@ void ModeManager::StackerAddInternal(BotInfo *bi, User *u, UserMode *um, bool Se * @param Set Adding or removing? * @param Param A param, if there is one */ -void ModeManager::StackerAddInternal(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const std::string &Param) +void ModeManager::StackerAddInternal(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param) { StackerAddInternal(bi, c, cm, Set, Param, ST_CHANNEL); } @@ -596,7 +596,7 @@ void ModeManager::StackerAddInternal(BotInfo *bi, Channel *c, ChannelMode *cm, b * @param Param A param, if there is one * @param Type The type this is, user or channel */ -void ModeManager::StackerAddInternal(BotInfo *bi, void *Object, void *Mode, bool Set, const std::string &Param, StackerType Type) +void ModeManager::StackerAddInternal(BotInfo *bi, void *Object, void *Mode, bool Set, const Anope::string &Param, StackerType Type) { StackerInfo *s = GetInfo(Object); s->Type = Type; @@ -747,7 +747,7 @@ char ModeManager::GetStatusChar(char Value) * @param Set true for setting, false for removing * @param Param The param, if there is one */ -void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const std::string &Param) +void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param) { StackerAddInternal(bi, c, cm, Set, Param); } @@ -759,7 +759,7 @@ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, * @param Set true for setting, false for removing * @param Param The param, if there is one */ -void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelModeName Name, bool Set, const std::string &Param) +void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelModeName Name, bool Set, const Anope::string &Param) { StackerAdd(bi, c, FindChannelModeByName(Name), Set, Param); } @@ -771,7 +771,7 @@ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelModeName Name, bool * @param Set true for setting, false for removing * @param Param The param, if there is one */ -void ModeManager::StackerAdd(BotInfo *bi, Channel *c, const char Mode, bool Set, const std::string &Param) +void ModeManager::StackerAdd(BotInfo *bi, Channel *c, const char Mode, bool Set, const Anope::string &Param) { StackerAdd(bi, c, FindChannelModeByChar(Mode), Set, Param); } @@ -783,7 +783,7 @@ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, const char Mode, bool Set, * @param Set true for setting, false for removing * @param param The param, if there is one */ -void ModeManager::StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const std::string &Param) +void ModeManager::StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param) { StackerAddInternal(bi, u, um, Set, Param); } @@ -795,7 +795,7 @@ void ModeManager::StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const * @param Set true for setting, false for removing * @param Param The param, if there is one */ -void ModeManager::StackerAdd(BotInfo *bi, User *u, UserModeName Name, bool Set, const std::string &Param) +void ModeManager::StackerAdd(BotInfo *bi, User *u, UserModeName Name, bool Set, const Anope::string &Param) { StackerAdd(bi, u, FindUserModeByName(Name), Set, Param); } @@ -807,7 +807,7 @@ void ModeManager::StackerAdd(BotInfo *bi, User *u, UserModeName Name, bool Set, * @param Set true for setting, false for removing * @param Param The param, if there is one */ -void ModeManager::StackerAdd(BotInfo *bi, User *u, const char Mode, bool Set, const std::string &Param) +void ModeManager::StackerAdd(BotInfo *bi, User *u, const char Mode, bool Set, const Anope::string &Param) { StackerAdd(bi, u, FindUserModeByChar(Mode), Set, Param); } @@ -823,7 +823,7 @@ void ModeManager::ProcessModes() StackerInfo *s = it->second; User *u = NULL; Channel *c = NULL; - std::list<std::string> ModeStrings = BuildModeStrings(s); + std::list<Anope::string> ModeStrings = BuildModeStrings(s); if (s->Type == ST_USER) u = static_cast<User *>(it->first); @@ -832,7 +832,7 @@ void ModeManager::ProcessModes() else throw CoreException("ModeManager::ProcessModes got invalid Stacker Info type"); - for (std::list<std::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit) + for (std::list<Anope::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit) { if (c) ircdproto->SendMode(s->bi, c, lit->c_str()); diff --git a/src/module.cpp b/src/module.cpp index d2382eb02..99233d7a3 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -9,7 +9,7 @@ #include "modules.h" #include "language.h" -Module::Module(const std::string &mname, const std::string &creator) +Module::Module(const Anope::string &mname, const Anope::string &creator) { this->name = mname; /* Our name */ this->type = THIRD; @@ -45,7 +45,7 @@ Module::~Module() **/ if (HostServ) { - for (std::map<ci::string, Command *>::iterator it = HostServ->Commands.begin(), it_end = HostServ->Commands.end(); it != it_end; ) + for (CommandMap::iterator it = HostServ->Commands.begin(), it_end = HostServ->Commands.end(); it != it_end; ) { Command *c = it->second; ++it; @@ -57,7 +57,7 @@ Module::~Module() if (BotServ) { - for (std::map<ci::string, Command *>::iterator it = BotServ->Commands.begin(), it_end = BotServ->Commands.end(); it != it_end; ) + for (CommandMap::iterator it = BotServ->Commands.begin(), it_end = BotServ->Commands.end(); it != it_end; ) { Command *c = it->second; ++it; @@ -69,7 +69,7 @@ Module::~Module() if (MemoServ) { - for (std::map<ci::string, Command *>::iterator it = MemoServ->Commands.begin(), it_end = MemoServ->Commands.end(); it != it_end; ) + for (CommandMap::iterator it = MemoServ->Commands.begin(), it_end = MemoServ->Commands.end(); it != it_end; ) { Command *c = it->second; ++it; @@ -81,7 +81,7 @@ Module::~Module() if (NickServ) { - for (std::map<ci::string, Command *>::iterator it = NickServ->Commands.begin(), it_end = NickServ->Commands.end(); it != it_end; ) + for (CommandMap::iterator it = NickServ->Commands.begin(), it_end = NickServ->Commands.end(); it != it_end; ) { Command *c = it->second; ++it; @@ -93,7 +93,7 @@ Module::~Module() if (ChanServ) { - for (std::map<ci::string, Command *>::iterator it = ChanServ->Commands.begin(), it_end = ChanServ->Commands.end(); it != it_end; ) + for (CommandMap::iterator it = ChanServ->Commands.begin(), it_end = ChanServ->Commands.end(); it != it_end; ) { Command *c = it->second; ++it; @@ -105,7 +105,7 @@ Module::~Module() if (OperServ) { - for (std::map<ci::string, Command *>::iterator it = OperServ->Commands.begin(), it_end = OperServ->Commands.end(); it != it_end; ) + for (CommandMap::iterator it = OperServ->Commands.begin(), it_end = OperServ->Commands.end(); it != it_end; ) { Command *c = it->second; ++it; @@ -117,9 +117,7 @@ Module::~Module() std::list<Module *>::iterator it = std::find(Modules.begin(), Modules.end(), this); if (it != Modules.end()) - { Modules.erase(it); - } } void Module::SetType(MODType ntype) @@ -137,12 +135,12 @@ bool Module::GetPermanent() return this->permanent; } -void Module::SetVersion(const std::string &nversion) +void Module::SetVersion(const Anope::string &nversion) { this->version = nversion; } -void Module::SetAuthor(const std::string &nauthor) +void Module::SetAuthor(const Anope::string &nauthor) { this->author = nauthor; } diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 884bba5a8..4e26289ec 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -25,6 +25,12 @@ void ModuleManager::LoadModuleList(std::list<ci::string> &ModuleList) ModuleManager::LoadModule(*it, NULL); } +void ModuleManager::LoadModuleList(std::list<Anope::string> &ModuleList) +{ + for (std::list<Anope::string>::iterator it = ModuleList.begin(), it_end = ModuleList.end(); it != it_end; ++it) + ModuleManager::LoadModule(*it, NULL); +} + /** * Copy the module from the modules folder to the runtime folder. * This will prevent module updates while the modules is loaded from @@ -34,39 +40,37 @@ void ModuleManager::LoadModuleList(std::list<ci::string> &ModuleList) * @param output the destination to copy the module to * @return MOD_ERR_OK on success */ -static int moduleCopyFile(const char *name, const char *output) +static int moduleCopyFile(const Anope::string &name, Anope::string &output) { int ch; FILE *source, *target; #ifndef _WIN32 int srcfp; #endif - char input[4096]; + Anope::string input = services_dir + "/modules/" + name + MODULE_EXT; - strlcpy(input, services_dir.c_str(), sizeof(input)); - strlcat(input, "/modules/", sizeof(input)); /* Get full path with module extension */ - strlcat(input, name, sizeof(input)); - strlcat(input, MODULE_EXT, sizeof(input)); - - if (!(source = fopen(input, "rb"))) + if (!(source = fopen(input.c_str(), "rb"))) return MOD_ERR_NOEXIST; + char *tmp_output = strdup(output.c_str()); #ifndef _WIN32 - if ((srcfp = mkstemp(const_cast<char *>(output))) == -1) + if ((srcfp = mkstemp(const_cast<char *>(tmp_output))) == -1) #else - if (!mktemp(const_cast<char *>(output))) + if (!mktemp(const_cast<char *>(tmp_output))) #endif { fclose(source); return MOD_ERR_FILE_IO; } + output = tmp_output; + delete [] tmp_output; Alog(LOG_DEBUG) << "Runtime module location: " << output; #ifndef _WIN32 if (!(target = fdopen(srcfp, "w"))) #else - if (!(target = fopen(output, "wb"))) + if (!(target = fopen(output.c_str(), "wb"))) #endif { fclose(source); @@ -116,35 +120,25 @@ template <class TYPE> TYPE function_cast(ano_module_t symbol) return cast.function; } -int ModuleManager::LoadModule(const std::string &modname, User *u) +int ModuleManager::LoadModule(const Anope::string &modname, User *u) { const char *err; - Module *(*func)(const std::string &, const std::string &); + Module *(*func)(const Anope::string &, const Anope::string &); int ret = 0; if (modname.empty()) return MOD_ERR_PARAMS; - if (FindModule(modname) != NULL) + if (FindModule(modname)) return MOD_ERR_EXISTS; Alog(LOG_DEBUG) << "trying to load [" << modname << "]"; /* Generate the filename for the temporary copy of the module */ - std::string pbuf; - pbuf = services_dir + "/modules/"; -#ifndef _WIN32 - pbuf += "runtime/"; -#else - pbuf += "runtime\\"; -#endif - pbuf += modname; - pbuf += MODULE_EXT; - pbuf += "."; - pbuf += "XXXXXX"; + Anope::string pbuf = services_dir + "/modules/runtime/" + modname + MODULE_EXT + ".XXXXXX"; /* Don't skip return value checking! -GD */ - if ((ret = moduleCopyFile(modname.c_str(), pbuf.c_str())) != MOD_ERR_OK) + if ((ret = moduleCopyFile(modname, pbuf)) != MOD_ERR_OK) { /* XXX: This used to assign filename here, but I don't think that was correct.. * even if it was, it makes life very fucking difficult, so. @@ -162,7 +156,7 @@ int ModuleManager::LoadModule(const std::string &modname, User *u) } ano_modclearerr(); - func = function_cast<Module *(*)(const std::string &, const std::string &)>(dlsym(handle, "AnopeInit")); + func = function_cast<Module *(*)(const Anope::string &, const Anope::string &)>(dlsym(handle, "AnopeInit")); if (!func && (err = dlerror())) { Alog() << "No init function found, not an Anope module"; @@ -174,11 +168,9 @@ int ModuleManager::LoadModule(const std::string &modname, User *u) throw CoreException("Couldn't find constructor, yet moderror wasn't set?"); /* Create module. */ - std::string nick; + Anope::string nick; if (u) nick = u->nick; - else - nick = ""; Module *m; @@ -238,16 +230,6 @@ int ModuleManager::LoadModule(const std::string &modname, User *u) return MOD_ERR_OK; } -int ModuleManager::LoadModule(const char *modname, User *u) -{ - return LoadModule(std::string(modname), u); -} - -int ModuleManager::LoadModule(const ci::string &modname, User *u) -{ - return LoadModule(std::string(modname.c_str()), u); -} - int ModuleManager::UnloadModule(Module *m, User *u) { if (!m || !m->handle) @@ -286,7 +268,7 @@ void ModuleManager::DeleteModule(Module *m) DetachAll(m); ano_module_t handle = m->handle; - std::string filename = m->filename; + Anope::string filename = m->filename; ano_modclearerr(); destroy_func = function_cast<void (*)(Module *)>(dlsym(m->handle, "AnopeFini")); @@ -479,4 +461,3 @@ void ModuleManager::UnloadAll(bool unload_proto) DeleteModule(m); } } - diff --git a/src/modules.cpp b/src/modules.cpp index fda941e50..b6115137d 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -13,14 +13,12 @@ #include "language.h" #include "version.h" -std::multimap<std::string, Message *> MessageMap; +message_map MessageMap; std::list<Module *> Modules; -char *mod_current_buffer = NULL; - -char *ModuleGetErrStr(int status) +Anope::string ModuleGetErrStr(int status) { - const char *module_err_str[] = { + Anope::string module_err_str[] = { "Module, Okay - No Error", /* MOD_ERR_OK */ "Module Error, Allocating memory", /* MOD_ERR_MEMORY */ "Module Error, Not enough parameters", /* MOD_ERR_PARAMS */ @@ -36,7 +34,7 @@ char *ModuleGetErrStr(int status) "Module Error, No Service found for request", /* MOD_ERR_NOSERVICE */ "Module Error, No module name for request" /* MOD_ERR_NO_MOD_NAME */ }; - return const_cast<char *>(module_err_str[status]); + return module_err_str[status]; } /************************************************/ @@ -60,7 +58,7 @@ int protocol_module_init() */ if (ircd->ts6) { - if (!Config.Numeric) + if (Config.Numeric.empty()) { Alog() << "This IRCd protocol requires a server id to be set in Anope's configuration."; ret = -1; @@ -83,7 +81,7 @@ void Module::InsertLanguage(int langNumber, int ac, const char **av) this->lang[langNumber].argc = ac; this->lang[langNumber].argv = new char *[ac]; for (i = 0; i < ac; ++i) - this->lang[langNumber].argv[i] = sstrdup(av[i]); + this->lang[langNumber].argv[i] = strdup(av[i]); } /** @@ -91,35 +89,25 @@ void Module::InsertLanguage(int langNumber, int ac, const char **av) * @param name the name of the module to find * @return a pointer to the module found, or NULL */ -Module *FindModule(const std::string &name) +Module *FindModule(const Anope::string &name) { for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) { Module *m = *it; - if (m->name == name) + if (m->name.equals_ci(name)) return m; } return NULL; } -Module *FindModule(const char *name) -{ - return FindModule(std::string(name)); -} - -Module *FindModule(const ci::string &name) -{ - return FindModule(std::string(name.c_str())); -} - /** Add a message to Anope * @param name The message name as sent by the IRCd * @param func A callback function that will be called when this message is received * @return The new message object */ -Message *Anope::AddMessage(const std::string &name, int (*func)(const char *source, int ac, const char **av)) +Message *Anope::AddMessage(const Anope::string &name, int (*func)(const Anope::string &source, int ac, const char **av)) { Message *m = new Message; @@ -139,12 +127,12 @@ Message *Anope::AddMessage(const std::string &name, int (*func)(const char *sour */ bool Anope::DelMessage(Message *m) { - std::multimap<std::string, Message *>::iterator it = MessageMap.find(m->name); + message_map::iterator it = MessageMap.find(m->name); if (it == MessageMap.end()) return false; - std::multimap<std::string, Message *>::iterator upper = MessageMap.upper_bound(m->name); + message_map::iterator upper = MessageMap.upper_bound(m->name); for (; it != upper; ++it) { @@ -158,20 +146,21 @@ bool Anope::DelMessage(Message *m) return false; } + /** Find message in the message table * @param name The name of the message were looking for * @return NULL if we cant find it, or a pointer to the Message if we can **/ -std::vector<Message *> Anope::FindMessage(const std::string &name) +std::vector<Message *> Anope::FindMessage(const Anope::string &name) { std::vector<Message *> messages; - std::multimap<std::string, Message *>::iterator it = MessageMap.find(name); + message_map::iterator it = MessageMap.find(name); if (it == MessageMap.end()) return messages; - std::multimap<std::string, Message *>::iterator upper = MessageMap.upper_bound(name); + message_map::iterator upper = MessageMap.upper_bound(name); for (; it != upper; ++it) messages.push_back(it->second); @@ -179,7 +168,6 @@ std::vector<Message *> Anope::FindMessage(const std::string &name) return messages; } - /******************************************************************************* * Command Functions *******************************************************************************/ @@ -192,7 +180,7 @@ int Module::AddCommand(BotInfo *bi, Command *c) c->module = this; c->service = bi; - std::pair<std::map<ci::string, Command *>::iterator, bool> it = bi->Commands.insert(std::make_pair(c->name, c)); + std::pair<CommandMap::iterator, bool> it = bi->Commands.insert(std::make_pair(c->name, c)); if (it.second != true) { @@ -266,7 +254,7 @@ bool moduleMinVersion(int major, int minor, int patch, int build) return ret; } -void Module::NoticeLang(const char *source, User *u, int number, ...) +void Module::NoticeLang(const Anope::string &source, User *u, int number, ...) { va_list va; char buffer[4096], outbuf[4096]; @@ -287,7 +275,7 @@ void Module::NoticeLang(const char *source, User *u, int number, ...) { fmt = this->lang[mlang].argv[number]; - buf = sstrdup(fmt); + buf = strdup(fmt); va_start(va, number); vsnprintf(buffer, 4095, buf, va); va_end(va); @@ -366,7 +354,7 @@ void ModuleRunTimeDirCleanUp() { if (!dp->d_ino) continue; - if (!stricmp(dp->d_name, ".") || !stricmp(dp->d_name, "..")) + if (Anope::string(dp->d_name).equals_cs(".") || Anope::string(dp->d_name).equals_cs("..")) continue; snprintf(filebuf, BUFSIZE, "%s/%s", dirbuf, dp->d_name); DeleteFile(filebuf); diff --git a/src/nickalias.cpp b/src/nickalias.cpp index 8ffbac891..c18f93005 100644 --- a/src/nickalias.cpp +++ b/src/nickalias.cpp @@ -1,15 +1,14 @@ #include "services.h" #include "modules.h" -NickRequest::NickRequest(const std::string &nickname) +NickRequest::NickRequest(const Anope::string &nickname) { if (nickname.empty()) throw CoreException("Empty nick passed to NickRequest constructor"); - email = NULL; requested = lastmail = 0; - this->nick = sstrdup(nickname.c_str()); + this->nick = nickname; NickRequestList[this->nick] = this; } @@ -19,45 +18,39 @@ NickRequest::~NickRequest() FOREACH_MOD(I_OnDelNickRequest, OnDelNickRequest(this)); NickRequestList.erase(this->nick); - - if (this->nick) - delete [] this->nick; - if (this->email) - delete [] this->email; } /** Default constructor * @param nick The nick * @param nickcore The nickcofe for this nick */ -NickAlias::NickAlias(const std::string &nickname, NickCore *nickcore) +NickAlias::NickAlias(const Anope::string &nickname, NickCore *nickcore) { if (nickname.empty()) throw CoreException("Empty nick passed to NickAlias constructor"); else if (!nickcore) throw CoreException("Empty nickcore passed to NickAlias constructor"); - nick = last_quit = last_realname = last_usermask = NULL; time_registered = last_seen = 0; - this->nick = sstrdup(nickname.c_str()); + this->nick = nickname; this->nc = nickcore; nc->aliases.push_back(this); NickAliasList[this->nick] = this; - for (std::list<std::pair<ci::string, ci::string> >::iterator it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) + for (std::list<std::pair<Anope::string, Anope::string> >::iterator it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) { if (nc->ot) break; - if (stricmp(it->first.c_str(), this->nick)) + if (!this->nick.equals_ci(it->first)) continue; for (std::list<OperType *>::iterator tit = Config.MyOperTypes.begin(), tit_end = Config.MyOperTypes.end(); tit != tit_end; ++tit) { OperType *ot = *tit; - if (ot->GetName() == it->second) + if (ot->GetName().equals_ci(it->second)) { Alog() << "Tied oper " << nc->display << " to type " << ot->GetName(); nc->ot = ot; @@ -99,21 +92,13 @@ NickAlias::~NickAlias() else { /* Display updating stuff */ - if (!stricmp(this->nick, this->nc->display)) + if (this->nick.equals_ci(this->nc->display)) change_core_display(this->nc); } } /* Remove us from the aliases list */ NickAliasList.erase(this->nick); - - delete [] this->nick; - if (this->last_usermask) - delete [] this->last_usermask; - if (this->last_realname) - delete [] this->last_realname; - if (this->last_quit) - delete [] this->last_quit; } /** Release a nick from being held. This can be called from the core (ns_release) @@ -127,7 +112,7 @@ void NickAlias::Release() if (ircd->svshold) ircdproto->SendSVSHoldDel(this->nick); else - ircdproto->SendQuit(this->nick, NULL); + ircdproto->SendQuit(this->nick, ""); this->UnsetFlag(NS_HELD); } @@ -148,7 +133,7 @@ void NickAlias::OnCancel(User *) ircdproto->SendSVSHold(this->nick); else { - std::string uid = (ircd->ts6 ? ts6_uid_retrieve() : ""); + Anope::string uid = ircd->ts6 ? ts6_uid_retrieve() : ""; ircdproto->SendClientIntroduction(this->nick, Config.NSEnforcerUser, Config.NSEnforcerHost, "Services Enforcer", "+", uid); new NickServRelease(this->nick, uid, Config.NSReleaseTimeout); diff --git a/src/nickcore.cpp b/src/nickcore.cpp index 6c9392aef..565a23a26 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -4,17 +4,16 @@ /** Default constructor * @param display The display nick */ -NickCore::NickCore(const std::string &coredisplay) +NickCore::NickCore(const Anope::string &coredisplay) { if (coredisplay.empty()) throw CoreException("Empty display passed to NickCore constructor"); - display = email = greet = NULL; ot = NULL; language = channelcount = 0; lastmail = 0; - this->display = sstrdup(coredisplay.c_str()); + this->display = coredisplay; /* Set default nick core flags */ for (size_t t = NI_BEGIN + 1; t != NI_END; ++t) @@ -55,32 +54,19 @@ NickCore::~NickCore() /* Clear access before deleting display name, we want to be able to use the display name in the clear access event */ this->ClearAccess(); - /* Now we can safely free it. */ - delete [] this->display; - - if (this->email) - delete [] this->email; - if (this->greet) - delete [] this->greet; if (!this->memos.memos.empty()) { for (unsigned i = 0, end = this->memos.memos.size(); i < end; ++i) - { - if (this->memos.memos[i]->text) - delete [] this->memos.memos[i]->text; delete this->memos.memos[i]; - } this->memos.memos.clear(); } } -bool NickCore::HasCommand(const ci::string &cmdstr) const +bool NickCore::HasCommand(const Anope::string &cmdstr) const { if (!this->ot) - { // No opertype. return false; - } return this->ot->HasCommand(cmdstr); } @@ -93,7 +79,7 @@ bool NickCore::IsServicesOper() const return false; } -bool NickCore::HasPriv(const ci::string &privstr) const +bool NickCore::HasPriv(const Anope::string &privstr) const { if (!this->ot) // No opertype. @@ -102,20 +88,20 @@ bool NickCore::HasPriv(const ci::string &privstr) const return this->ot->HasPriv(privstr); } -void NickCore::AddAccess(const std::string &entry) +void NickCore::AddAccess(const Anope::string &entry) { access.push_back(entry); FOREACH_MOD(I_OnNickAddAccess, OnNickAddAccess(this, entry)); } -std::string NickCore::GetAccess(unsigned entry) +Anope::string NickCore::GetAccess(unsigned entry) { if (access.empty() || entry >= access.size()) return ""; return access[entry]; } -bool NickCore::FindAccess(const std::string &entry) +bool NickCore::FindAccess(const Anope::string &entry) { for (unsigned i = 0, end = access.size(); i < end; ++i) if (access[i] == entry) @@ -124,7 +110,7 @@ bool NickCore::FindAccess(const std::string &entry) return false; } -void NickCore::EraseAccess(const std::string &entry) +void NickCore::EraseAccess(const Anope::string &entry) { for (unsigned i = 0, end = access.size(); i < end; ++i) if (access[i] == entry) diff --git a/src/nickserv.cpp b/src/nickserv.cpp index 70cc3d654..0397c8b32 100644 --- a/src/nickserv.cpp +++ b/src/nickserv.cpp @@ -17,13 +17,16 @@ nickalias_map NickAliasList; nickcore_map NickCoreList; nickrequest_map NickRequestList; -static std::map<std::string, NickServCollide *> NickServCollides; -static std::map<std::string, NickServRelease *> NickServReleases; +typedef std::map<Anope::string, NickServCollide *, hash_compare_std_string> nickservcollides_map; +typedef std::map<Anope::string, NickServRelease *, hash_compare_std_string> nickservreleases_map; -NickServCollide::NickServCollide(const std::string &_nick, time_t delay) : Timer(delay), nick(_nick) +static nickservcollides_map NickServCollides; +static nickservreleases_map NickServReleases; + +NickServCollide::NickServCollide(const Anope::string &_nick, time_t delay) : Timer(delay), nick(_nick) { /* Erase the current collide and use the new one */ - std::map<std::string, NickServCollide *>::iterator nit = NickServCollides.find(nick); + nickservcollides_map::iterator nit = NickServCollides.find(nick); if (nit != NickServCollides.end()) delete nit->second; @@ -46,10 +49,10 @@ void NickServCollide::Tick(time_t ctime) u->Collide(na); } -NickServRelease::NickServRelease(const std::string &_nick, const std::string &_uid, time_t delay) : Timer(delay), nick(_nick), uid(_uid) +NickServRelease::NickServRelease(const Anope::string &_nick, const Anope::string &_uid, time_t delay) : Timer(delay), nick(_nick), uid(_uid) { /* Erase the current release timer and use the new one */ - std::map<std::string, NickServRelease *>::iterator nit = NickServReleases.find(nick); + nickservreleases_map::iterator nit = NickServReleases.find(nick); if (nit != NickServReleases.end()) delete nit->second; @@ -90,14 +93,14 @@ void get_aliases_stats(long *nrec, long *memuse) ++count; mem += sizeof(*na); - if (na->nick) - mem += strlen(na->nick) + 1; - if (na->last_usermask) - mem += strlen(na->last_usermask) + 1; - if (na->last_realname) - mem += strlen(na->last_realname) + 1; - if (na->last_quit) - mem += strlen(na->last_quit) + 1; + if (!na->nick.empty()) + mem += na->nick.length() + 1; + if (!na->last_usermask.empty()) + mem += na->last_usermask.length() + 1; + if (!na->last_realname.empty()) + mem += na->last_realname.length() + 1; + if (!na->last_quit.empty()) + mem += na->last_quit.length() + 1; } *nrec = count; *memuse = mem; @@ -119,25 +122,22 @@ void get_core_stats(long *nrec, long *memuse) ++count; mem += sizeof(*nc); - if (nc->display) - mem += strlen(nc->display) + 1; + if (!nc->display.empty()) + mem += nc->display.length() + 1; if (!nc->pass.empty()) - mem += (nc->pass.capacity() + (2 * sizeof(size_t)) + (2 * sizeof(void *))); - if (nc->email) - mem += strlen(nc->email) + 1; - if (nc->greet) - mem += strlen(nc->greet) + 1; + mem += nc->pass.length() + 1; + if (!nc->greet.empty()) + mem += nc->greet.length() + 1; + + mem += sizeof(Anope::string) * nc->access.size(); - mem += sizeof(std::string) * nc->access.size(); for (j = 0, end = nc->access.size(); j < end; ++j) mem += nc->GetAccess(j).length() + 1; mem += nc->memos.memos.size() * sizeof(Memo); for (j = 0, end = nc->memos.memos.size(); j < end; ++j) - { - if (nc->memos.memos[j]->text) - mem += strlen(nc->memos.memos[j]->text) + 1; - } + if (!nc->memos.memos[j]->text.empty()) + mem += nc->memos.memos[j]->text.length() + 1; mem += sizeof(NickAlias *) * nc->aliases.size(); } @@ -159,17 +159,17 @@ void ns_init() /* Main NickServ routine. */ -void nickserv(User *u, const std::string &buf) +void nickserv(User *u, const Anope::string &buf) { if (!u || buf.empty()) return; - if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1') + if (buf.substr(0, 6).equals_ci("\1PING ") && buf[buf.length() - 1] == '\1') { - std::string command = buf; + Anope::string command = buf; command.erase(command.begin()); command.erase(command.end()); - ircdproto->SendCTCP(NickServ, u->nick.c_str(), "%s", command.c_str()); + ircdproto->SendCTCP(NickServ, u->nick, "%s", command.c_str()); } else mod_run_cmd(NickServ, u, buf); @@ -216,13 +216,9 @@ int validate_user(User *u) if (!na->nc->HasFlag(NI_SECURE) && u->IsRecognized()) { na->last_seen = time(NULL); - if (na->last_usermask) - delete [] na->last_usermask; - std::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost(); - na->last_usermask = sstrdup(last_usermask.c_str()); - if (na->last_realname) - delete [] na->last_realname; - na->last_realname = sstrdup(u->realname); + Anope::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost(); + na->last_usermask = last_usermask; + na->last_realname = u->realname; check_memos(u); @@ -232,9 +228,9 @@ int validate_user(User *u) if (u->IsRecognized() || !na->nc->HasFlag(NI_KILL_IMMED)) { if (na->nc->HasFlag(NI_SECURE)) - notice_lang(Config.s_NickServ, u, NICK_IS_SECURE, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, NICK_IS_SECURE, Config.s_NickServ.c_str()); else - notice_lang(Config.s_NickServ, u, NICK_IS_REGISTERED, Config.s_NickServ); + notice_lang(Config.s_NickServ, u, NICK_IS_REGISTERED, Config.s_NickServ.c_str()); } if (na->nc->HasFlag(NI_KILLPROTECT) && !u->IsRecognized()) @@ -288,7 +284,7 @@ void expire_nicks() FOREACH_RESULT(I_OnPreNickExpire, OnPreNickExpire(na)); if (MOD_RESULT == EVENT_STOP) continue; - Alog() << "Expiring nickname " << na->nick << " (group: " << na->nc->display << ") (e-mail: " << (na->nc->email ? na->nc->email : "none") << ")"; + Alog() << "Expiring nickname " << na->nick << " (group: " << na->nc->display << ") (e-mail: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")"; FOREACH_MOD(I_OnNickExpire, OnNickExpire(na)); delete na; } @@ -313,17 +309,7 @@ void expire_requests() /*************************************************************************/ -NickRequest *findrequestnick(const char *nick) -{ - return findrequestnick(ci::string(nick)); -} - -NickRequest *findrequestnick(const std::string &nick) -{ - return findrequestnick(ci::string(nick.c_str())); -} - -NickRequest *findrequestnick(const ci::string &nick) +NickRequest *findrequestnick(const Anope::string &nick) { nickrequest_map::const_iterator it = NickRequestList.find(nick); @@ -332,17 +318,7 @@ NickRequest *findrequestnick(const ci::string &nick) return NULL; } -NickAlias *findnick(const char *nick) -{ - return findnick(ci::string(nick)); -} - -NickAlias *findnick(const std::string &nick) -{ - return findnick(ci::string(nick.c_str())); -} - -NickAlias *findnick(const ci::string &nick) +NickAlias *findnick(const Anope::string &nick) { nickalias_map::const_iterator it = NickAliasList.find(nick); @@ -353,17 +329,7 @@ NickAlias *findnick(const ci::string &nick) /*************************************************************************/ -NickCore *findcore(const char *nick) -{ - return findcore(ci::string(nick)); -} - -NickCore *findcore(const std::string &nick) -{ - return findcore(ci::string(nick.c_str())); -} - -NickCore *findcore(const ci::string &nick) +NickCore *findcore(const Anope::string &nick) { nickcore_map::const_iterator it = NickCoreList.find(nick); @@ -383,54 +349,23 @@ NickCore *findcore(const ci::string &nick) */ bool is_on_access(User *u, NickCore *nc) { - unsigned i, end; - char *buf; - char *buf2 = NULL; - char *buf3 = NULL; - std::string tmp_buf; - if (!u || !nc || nc->access.empty()) return false; - tmp_buf = u->GetIdent() + "@" + u->host; - buf = sstrdup(tmp_buf.c_str()); + Anope::string buf = u->GetIdent() + "@" + u->host, buf2, buf3; if (ircd->vhost) { - if (u->vhost) - { - tmp_buf = u->GetIdent() + "@" + u->vhost; - buf2 = sstrdup(tmp_buf.c_str()); - } + if (!u->vhost.empty()) + buf2 = u->GetIdent() + "@" + u->vhost; if (!u->GetCloakedHost().empty()) - { - tmp_buf = u->GetIdent() + "@" + u->GetCloakedHost(); - buf3 = sstrdup(tmp_buf.c_str()); - } + buf3 = u->GetIdent() + "@" + u->GetCloakedHost(); } - for (i = 0, end = nc->access.size(); i < end; ++i) + for (unsigned i = 0, end = nc->access.size(); i < end; ++i) { - std::string access = nc->GetAccess(i); - if (Anope::Match(buf, access, false) || (buf2 && Anope::Match(buf2, access, false)) || (buf3 && Anope::Match(buf3, access, false))) - { - delete [] buf; - if (ircd->vhost) - { - if (u->vhost) - delete [] buf2; - if (!u->GetCloakedHost().empty()) - delete [] buf3; - } + Anope::string access = nc->GetAccess(i); + if (Anope::Match(buf, access) || (!buf2.empty() && Anope::Match(buf2, access)) || (!buf3.empty() && Anope::Match(buf3, access))) return true; - } - } - delete [] buf; - if (ircd->vhost) - { - if (buf2) - delete [] buf2; - if (buf3) - delete [] buf3; } return false; } @@ -441,7 +376,7 @@ bool is_on_access(User *u, NickCore *nc) * it to the first alias in the list. */ -void change_core_display(NickCore *nc, const char *newdisplay) +void change_core_display(NickCore *nc, const Anope::string &newdisplay) { /* Log ... */ FOREACH_MOD(I_OnChangeCoreDisplay, OnChangeCoreDisplay(nc, newdisplay)); @@ -450,8 +385,7 @@ void change_core_display(NickCore *nc, const char *newdisplay) /* Remove the core from the list */ NickCoreList.erase(nc->display); - delete [] nc->display; - nc->display = sstrdup(newdisplay); + nc->display = newdisplay; NickCoreList[nc->display] = nc; } @@ -462,7 +396,7 @@ void change_core_display(NickCore *nc) if (nc->aliases.empty()) return; na = nc->aliases.front(); - change_core_display(nc,na->nick); + change_core_display(nc, na->nick); } /*************************************************************************/ diff --git a/src/operserv.cpp b/src/operserv.cpp index b97f66072..e91ad113b 100644 --- a/src/operserv.cpp +++ b/src/operserv.cpp @@ -22,7 +22,7 @@ Flags<ChannelModeName, CMODE_END> DefConModesOn; /* Defcon modes mlocked off */ Flags<ChannelModeName, CMODE_END> DefConModesOff; /* Map of Modesa and Params for DefCon */ -std::map<ChannelModeName, std::string> DefConModesOnParams; +std::map<ChannelModeName, Anope::string> DefConModesOnParams; XLineManager *SGLine, *SZLine, *SQLine, *SNLine; @@ -37,32 +37,32 @@ void os_init() XLineManager::RegisterXLineManager(SNLine = new SNLineManager()); } -void operserv(User *u, const std::string &buf) +void operserv(User *u, const Anope::string &buf) { if (!u || buf.empty()) return; Alog() << Config.s_OperServ << ": " << u->nick << ": " << buf; - if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1') + if (buf.substr(0, 6).equals_cs("\1PING ") && buf[buf.length() - 1] == '\1') { - std::string command = buf; + Anope::string command = buf; command.erase(command.begin()); command.erase(command.end()); - ircdproto->SendCTCP(OperServ, u->nick.c_str(), "%s", command.c_str()); + ircdproto->SendCTCP(OperServ, u->nick, "%s", command.c_str()); } else mod_run_cmd(OperServ, u, buf); } -bool SetDefConParam(ChannelModeName Name, std::string &buf) +bool SetDefConParam(ChannelModeName Name, const Anope::string &buf) { return DefConModesOnParams.insert(std::make_pair(Name, buf)).second; } -bool GetDefConParam(ChannelModeName Name, std::string &buf) +bool GetDefConParam(ChannelModeName Name, Anope::string &buf) { - std::map<ChannelModeName, std::string>::iterator it = DefConModesOnParams.find(Name); + std::map<ChannelModeName, Anope::string>::iterator it = DefConModesOnParams.find(Name); buf.clear(); @@ -77,7 +77,7 @@ bool GetDefConParam(ChannelModeName Name, std::string &buf) void UnsetDefConParam(ChannelModeName Name) { - std::map<ChannelModeName, std::string>::iterator it = DefConModesOnParams.find(Name); + std::map<ChannelModeName, Anope::string>::iterator it = DefConModesOnParams.find(Name); if (it != DefConModesOnParams.end()) DefConModesOnParams.erase(it); @@ -122,7 +122,7 @@ void DelDefCon(int level, DefconLevel Level) DefCon[level][Level] = false; } -void server_global(Server *s, const std::string &message) +void server_global(Server *s, const Anope::string &message) { /* Do not send the notice to ourselves our juped servers */ if (s != Me && !s->HasFlag(SERVER_JUPED)) @@ -135,7 +135,7 @@ void server_global(Server *s, const std::string &message) } } -void oper_global(char *nick, const char *fmt, ...) +void oper_global(const Anope::string &nick, const char *fmt, ...) { va_list args; char msg[2048]; /* largest valid message is 512, this should cover any global */ @@ -144,14 +144,13 @@ void oper_global(char *nick, const char *fmt, ...) vsnprintf(msg, sizeof(msg), fmt, args); va_end(args); - if (nick && !Config.AnonymousGlobal) + if (!nick.empty() && !Config.AnonymousGlobal) { - std::string rmsg = std::string("[") + nick + std::string("] ") + msg; - server_global(Me->GetUplink(), rmsg.c_str()); + Anope::string rmsg = "[" + nick + "] " + msg; + server_global(Me->GetUplink(), rmsg); } else server_global(Me->GetUplink(), msg); - } /**************************************************************************/ @@ -159,42 +158,45 @@ void oper_global(char *nick, const char *fmt, ...) /* List of XLine managers we check users against in XLineManager::CheckAll */ std::list<XLineManager *> XLineManager::XLineManagers; -XLine::XLine(const ci::string &mask, const std::string &reason) : Mask(mask), Reason(reason) +XLine::XLine(const Anope::string &mask, const Anope::string &reason) : Mask(mask), Reason(reason) { Expires = Created = 0; } -XLine::XLine(const ci::string &mask, const ci::string &by, const time_t expires, const std::string &reason) : Mask(mask), By(by), Created(time(NULL)), Expires(expires), Reason(reason) +XLine::XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason) : Mask(mask), By(by), Created(time(NULL)), Expires(expires), Reason(reason) { } -ci::string XLine::GetNick() const +Anope::string XLine::GetNick() const { size_t nick_t = Mask.find('!'); - if (nick_t == ci::string::npos) + if (nick_t == Anope::string::npos) return ""; - return Mask.substr(0, nick_t - 1); + return Mask.substr(0, nick_t); } -ci::string XLine::GetUser() const +Anope::string XLine::GetUser() const { size_t user_t = Mask.find('!'), host_t = Mask.find('@'); - if (user_t == ci::string::npos) - return Mask.substr(0, host_t); - else if (host_t != ci::string::npos) - return Mask.substr((user_t != ci::string::npos ? user_t + 1 : 0), host_t); + if (host_t != Anope::string::npos) + { + if (user_t != Anope::string::npos) + return Mask.substr(user_t + 1, host_t - user_t - 1); + else + return Mask.substr(0, host_t); + } else return ""; } -ci::string XLine::GetHost() const +Anope::string XLine::GetHost() const { size_t host_t = Mask.find('@'); - if (host_t == ci::string::npos) + if (host_t == Anope::string::npos) return Mask; else return Mask.substr(host_t + 1); @@ -243,7 +245,7 @@ void XLineManager::UnregisterXLineManager(XLineManager *xlm) std::pair<XLineManager *, XLine *> XLineManager::CheckAll(User *u) { std::pair<XLineManager *, XLine *> ret; - + ret.first = NULL; ret.second = NULL; @@ -275,7 +277,7 @@ const size_t XLineManager::GetCount() const /** Get the XLine vector * @return The vecotr */ -const std::vector<XLine *>& XLineManager::GetList() const +const std::vector<XLine *> &XLineManager::GetList() const { return XLines; } @@ -336,7 +338,7 @@ void XLineManager::Clear() * @param reaosn The reason * @return A pointer to the XLine */ -XLine *XLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason) +XLine *XLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason) { return NULL; } @@ -357,10 +359,10 @@ void XLineManager::Del(XLine *x) * 3 - Mask is already covered by another mask * In each case the XLine it matches/is covered by is returned in XLine* */ -std::pair<int, XLine *> XLineManager::CanAdd(const ci::string &mask, time_t expires) +std::pair<int, XLine *> XLineManager::CanAdd(const Anope::string &mask, time_t expires) { std::pair<int, XLine *> ret; - + ret.first = 0; ret.second = NULL; @@ -369,7 +371,7 @@ std::pair<int, XLine *> XLineManager::CanAdd(const ci::string &mask, time_t expi XLine *x = GetEntry(i); ret.second = x; - if (x->Mask == mask) + if (x->Mask.equals_ci(mask)) { if (!x->Expires || x->Expires >= expires) { @@ -403,13 +405,13 @@ std::pair<int, XLine *> XLineManager::CanAdd(const ci::string &mask, time_t expi * @param mask The mask * @return The XLine the user matches, or NULL */ -XLine *XLineManager::HasEntry(const ci::string &mask) const +XLine *XLineManager::HasEntry(const Anope::string &mask) const { for (unsigned i = 0, end = XLines.size(); i < end; ++i) { XLine *x = XLines[i]; - if (x->Mask == mask) + if (x->Mask.equals_ci(mask)) return x; } @@ -437,13 +439,13 @@ XLine *XLineManager::Check(User *u) continue; } - if (!x->GetNick().empty() && !Anope::Match(u->nick.c_str(), x->GetNick())) + if (!x->GetNick().empty() && !Anope::Match(u->nick, x->GetNick())) continue; - if (!x->GetUser().empty() && !Anope::Match(u->GetIdent().c_str(), x->GetUser())) + if (!x->GetUser().empty() && !Anope::Match(u->GetIdent(), x->GetUser())) continue; - if (x->GetHost().empty() || (u->hostip && Anope::Match(u->hostip, x->GetHost())) || Anope::Match(u->host, x->GetHost()) || (!u->chost.empty() && Anope::Match(u->chost.c_str(), x->GetHost())) || (u->vhost && Anope::Match(u->vhost, x->GetHost()))) + if (x->GetHost().empty() || (!u->hostip.empty() && Anope::Match(u->hostip, x->GetHost())) || Anope::Match(u->host, x->GetHost()) || (!u->chost.empty() && Anope::Match(u->chost, x->GetHost())) || (!u->vhost.empty() && Anope::Match(u->vhost, x->GetHost()))) { OnMatch(u, x); return x; @@ -468,26 +470,26 @@ void XLineManager::OnExpire(XLine *x) { } -XLine *SGLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason) +XLine *SGLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason) { - if (mask.find('!') != ci::string::npos) + if (mask.find('!') != Anope::string::npos) { if (bi && u) - notice_lang(bi->nick.c_str(), u, OPER_AKILL_NO_NICK); + notice_lang(bi->nick, u, OPER_AKILL_NO_NICK); return NULL; } - if (mask.find('@') == ci::string::npos) + if (mask.find('@') == Anope::string::npos) { if (bi && u) - notice_lang(bi->nick.c_str(), u, BAD_USERHOST_MASK); + notice_lang(bi->nick, u, BAD_USERHOST_MASK); return NULL; } - if (strspn(mask.c_str(), "~@.*?") == mask.length()) + if (mask.find_first_not_of("~@.*?") == Anope::string::npos) { if (bi && u) - notice_lang(bi->nick.c_str(), u, USERHOST_MASK_TOO_WIDE, mask.c_str()); + notice_lang(bi->nick, u, USERHOST_MASK_TOO_WIDE, mask.c_str()); return NULL; } @@ -497,21 +499,21 @@ XLine *SGLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e if (bi && u) { if (canAdd.first == 1) - notice_lang(bi->nick.c_str(), u, OPER_AKILL_EXISTS, canAdd.second->Mask.c_str()); + notice_lang(bi->nick, u, OPER_AKILL_EXISTS, canAdd.second->Mask.c_str()); else if (canAdd.first == 2) - notice_lang(bi->nick.c_str(), u, OPER_AKILL_CHANGED, canAdd.second->Mask.c_str()); + notice_lang(bi->nick, u, OPER_AKILL_CHANGED, canAdd.second->Mask.c_str()); else if (canAdd.first == 3) - notice_lang(bi->nick.c_str(), u, OPER_AKILL_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str()); + notice_lang(bi->nick, u, OPER_AKILL_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str()); } return canAdd.second; } - std::string realreason = reason; + Anope::string realreason = reason; if (u && Config.AddAkiller) realreason = "[" + u->nick + "]" + reason; - XLine *x = new XLine(mask, u ? u->nick.c_str() : "", expires, realreason); + XLine *x = new XLine(mask, u ? u->nick : "", expires, realreason); EventReturn MOD_RESULT; FOREACH_RESULT(I_OnAddAkill, OnAddAkill(u, x)); @@ -545,12 +547,12 @@ void SGLineManager::OnExpire(XLine *x) ircdproto->SendGlobops(OperServ, "AKILL on %s has expired", x->Mask.c_str()); } -XLine *SNLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason) +XLine *SNLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason) { - if (!mask.empty() && strspn(mask.c_str(), "*?") == mask.length()) + if (!mask.empty() && mask.find_first_not_of("*?") == Anope::string::npos) { if (bi && u) - notice_lang(bi->nick.c_str(), u, USERHOST_MASK_TOO_WIDE, mask.c_str()); + notice_lang(bi->nick, u, USERHOST_MASK_TOO_WIDE, mask.c_str()); return NULL; } @@ -560,17 +562,17 @@ XLine *SNLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e if (bi && u) { if (canAdd.first == 1) - notice_lang(bi->nick.c_str(), u, OPER_SNLINE_EXISTS, canAdd.second->Mask.c_str()); + notice_lang(bi->nick, u, OPER_SNLINE_EXISTS, canAdd.second->Mask.c_str()); else if (canAdd.first == 2) - notice_lang(bi->nick.c_str(), u, OPER_SNLINE_CHANGED, canAdd.second->Mask.c_str()); + notice_lang(bi->nick, u, OPER_SNLINE_CHANGED, canAdd.second->Mask.c_str()); else if (canAdd.first == 3) - notice_lang(bi->nick.c_str(), u, OPER_SNLINE_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str()); + notice_lang(bi->nick, u, OPER_SNLINE_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str()); } return canAdd.second; } - XLine *x = new XLine(mask, u ? u->nick.c_str() : "", expires, reason); + XLine *x = new XLine(mask, u ? u->nick : "", expires, reason); EventReturn MOD_RESULT; FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, X_SNLINE)); @@ -584,7 +586,7 @@ XLine *SNLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e if (Config.KillonSNline && !ircd->sglineenforce) { - std::string rreason = "G-Lined: " + reason; + Anope::string rreason = "G-Lined: " + reason; for (user_map::const_iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ) { @@ -592,7 +594,7 @@ XLine *SNLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e ++it; if (!is_oper(user) && Anope::Match(user->realname, x->Mask)) - kill_user(Config.ServerName, user->nick, rreason.c_str()); + kill_user(Config.ServerName, user->nick, rreason); } } @@ -608,8 +610,8 @@ void SNLineManager::OnMatch(User *u, XLine *x) { ircdproto->SendSGLine(x); - std::string reason = "G-Lined: " + x->Reason; - kill_user(Config.s_OperServ, u->nick, reason.c_str()); + Anope::string reason = "G-Lined: " + x->Reason; + kill_user(Config.s_OperServ, u->nick, reason); } void SNLineManager::OnExpire(XLine *x) @@ -618,9 +620,9 @@ void SNLineManager::OnExpire(XLine *x) ircdproto->SendGlobops(OperServ, "SNLINE on \2%s\2 has expired", x->Mask.c_str()); } -XLine *SQLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason) +XLine *SQLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason) { - if (strspn(mask.c_str(), "*") == mask.length()) + if (mask.find_first_not_of("*") == Anope::string::npos) { if (bi && u) notice_lang(Config.s_OperServ, u, USERHOST_MASK_TOO_WIDE, mask.c_str()); @@ -640,17 +642,17 @@ XLine *SQLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e if (bi && u) { if (canAdd.first == 1) - notice_lang(bi->nick.c_str(), u, OPER_SQLINE_EXISTS, canAdd.second->Mask.c_str()); + notice_lang(bi->nick, u, OPER_SQLINE_EXISTS, canAdd.second->Mask.c_str()); else if (canAdd.first == 2) - notice_lang(bi->nick.c_str(), u, OPER_SQLINE_CHANGED, canAdd.second->Mask.c_str()); + notice_lang(bi->nick, u, OPER_SQLINE_CHANGED, canAdd.second->Mask.c_str()); else if (canAdd.first == 3) - notice_lang(bi->nick.c_str(), u, OPER_SQLINE_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str()); + notice_lang(bi->nick, u, OPER_SQLINE_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str()); } return canAdd.second; } - XLine *x = new XLine(mask, u ? u->nick.c_str() : "", expires, reason); + XLine *x = new XLine(mask, u ? u->nick : "", expires, reason); EventReturn MOD_RESULT; FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, X_SQLINE)); @@ -664,7 +666,7 @@ XLine *SQLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e if (Config.KillonSQline) { - std::string rreason = "Q-Lined: " + reason; + Anope::string rreason = "Q-Lined: " + reason; if (mask[0] == '#') { @@ -672,7 +674,7 @@ XLine *SQLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e { Channel *c = cit->second; - if (!Anope::Match(c->name.c_str(), mask)) + if (!Anope::Match(c->name, mask)) continue; for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) { @@ -692,8 +694,8 @@ XLine *SQLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e User *user = it->second; ++it; - if (!is_oper(user) && Anope::Match(user->nick.c_str(), x->Mask)) - kill_user(Config.ServerName, user->nick, rreason.c_str()); + if (!is_oper(user) && Anope::Match(user->nick, x->Mask)) + kill_user(Config.ServerName, user->nick, rreason); } } } @@ -712,8 +714,7 @@ void SQLineManager::OnMatch(User *u, XLine *x) { ircdproto->SendSQLine(x); - char reason[300]; - snprintf(reason, sizeof(reason), "Q-Lined: %s", x->Reason.c_str()); + Anope::string reason = "Q-Lined: " + x->Reason; kill_user(Config.s_OperServ, u->nick, reason); } @@ -731,7 +732,7 @@ bool SQLineManager::Check(Channel *c) { XLine *x = *it; - if (Anope::Match(c->name.c_str(), x->Mask)) + if (Anope::Match(c->name, x->Mask)) return true; } } @@ -739,15 +740,15 @@ bool SQLineManager::Check(Channel *c) return false; } -XLine *SZLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason) +XLine *SZLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason) { - if (mask.find('!') != ci::string::npos || mask.find('@') != ci::string::npos) + if (mask.find('!') != Anope::string::npos || mask.find('@') != Anope::string::npos) { notice_lang(Config.s_OperServ, u, OPER_SZLINE_ONLY_IPS); return NULL; } - if (strspn(mask.c_str(), "*?") == mask.length()) + if (mask.find_first_not_of("*?") == Anope::string::npos) { notice_lang(Config.s_OperServ, u, USERHOST_MASK_TOO_WIDE, mask.c_str()); return NULL; @@ -759,17 +760,17 @@ XLine *SZLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e if (bi && u) { if (canAdd.first == 1) - notice_lang(bi->nick.c_str(), u, OPER_SZLINE_EXISTS, canAdd.second->Mask.c_str()); + notice_lang(bi->nick, u, OPER_SZLINE_EXISTS, canAdd.second->Mask.c_str()); else if (canAdd.first == 2) - notice_lang(bi->nick.c_str(), u, OPER_SZLINE_CHANGED, canAdd.second->Mask.c_str()); + notice_lang(bi->nick, u, OPER_SZLINE_CHANGED, canAdd.second->Mask.c_str()); else if (canAdd.first == 3) - notice_lang(bi->nick.c_str(), u, OPER_SZLINE_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str()); + notice_lang(bi->nick, u, OPER_SZLINE_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str()); } return canAdd.second; } - XLine *x = new XLine(mask, u ? u->nick.c_str() : "", expires, reason); + XLine *x = new XLine(mask, u ? u->nick : "", expires, reason); EventReturn MOD_RESULT; FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, X_SZLINE)); diff --git a/src/opertype.cpp b/src/opertype.cpp index 968163003..a4ea94dd3 100644 --- a/src/opertype.cpp +++ b/src/opertype.cpp @@ -7,13 +7,13 @@ #include "services.h" -OperType::OperType(const ci::string &nname) : name(nname) +OperType::OperType(const Anope::string &nname) : name(nname) { } -bool OperType::HasCommand(const ci::string &cmdstr) const +bool OperType::HasCommand(const Anope::string &cmdstr) const { - for (std::list<ci::string>::const_iterator it = this->commands.begin(), it_end = this->commands.end(); it != it_end; ++it) + for (std::list<Anope::string>::const_iterator it = this->commands.begin(), it_end = this->commands.end(); it != it_end; ++it) { if (Anope::Match(cmdstr, *it)) return true; @@ -29,9 +29,9 @@ bool OperType::HasCommand(const ci::string &cmdstr) const return false; } -bool OperType::HasPriv(const ci::string &privstr) const +bool OperType::HasPriv(const Anope::string &privstr) const { - for (std::list<ci::string>::const_iterator it = this->privs.begin(), it_end = this->privs.end(); it != it_end; ++it) + for (std::list<Anope::string>::const_iterator it = this->privs.begin(), it_end = this->privs.end(); it != it_end; ++it) { if (Anope::Match(privstr, *it)) return true; @@ -47,17 +47,17 @@ bool OperType::HasPriv(const ci::string &privstr) const return false; } -void OperType::AddCommand(const ci::string &cmdstr) +void OperType::AddCommand(const Anope::string &cmdstr) { this->commands.push_back(cmdstr); } -void OperType::AddPriv(const ci::string &privstr) +void OperType::AddPriv(const Anope::string &privstr) { this->privs.push_back(privstr); } -const ci::string &OperType::GetName() const +const Anope::string &OperType::GetName() const { return this->name; } diff --git a/src/process.cpp b/src/process.cpp index 07f1ff451..6ea72dcb6 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -27,48 +27,40 @@ IgnoreData *ignore; * @param nick Nick or (nick!)user@host to add to the ignorelist. * @param delta Seconds untill new entry is set to expire. 0 for permanent. */ -void add_ignore(const char *nick, time_t delta) +void add_ignore(const Anope::string &nick, time_t delta) { IgnoreData *ign; - char tmp[BUFSIZE]; - char *mask, *user, *host; + Anope::string tmp, mask; + size_t user, host; User *u; time_t now; - if (!nick) + if (nick.empty()) return; now = time(NULL); /* If it s an existing user, we ignore the hostmask. */ if ((u = finduser(nick))) - { - snprintf(tmp, sizeof(tmp), "*!*@%s", u->host); - mask = sstrdup(tmp); - } + mask = "*!*@" + u->host; /* Determine whether we get a nick or a mask. */ - else if ((host = const_cast<char *>(strchr(nick, '@')))) + else if ((host = nick.find('@')) != Anope::string::npos) { /* Check whether we have a nick too.. */ - if ((user = const_cast<char *>(strchr(nick, '!')))) + if ((user = nick.find('!')) != Anope::string::npos) { /* this should never happen */ if (user > host) return; - mask = sstrdup(nick); + mask = nick; } else - { /* We have user@host. Add nick wildcard. */ - snprintf(tmp, sizeof(tmp), "*!%s", nick); - mask = sstrdup(tmp); - } + mask = "*!" + nick; } /* We only got a nick.. */ - else { - snprintf(tmp, sizeof(tmp), "%s!*@*", nick); - mask = sstrdup(tmp); - } + else + mask = nick + "!*@*"; /* Check if we already got an identical entry. */ for (ign = ignore; ign; ign = ign->next) - if (!stricmp(ign->mask, mask)) + if (mask.equals_ci(ign->mask)) break; /* Found one.. */ if (ign) @@ -102,14 +94,14 @@ void add_ignore(const char *nick, time_t delta) * @param nick Nick or (nick!)user@host to look for on the ignorelist. * @return Pointer to the ignore record, NULL if none was found. */ -IgnoreData *get_ignore(const char *nick) +IgnoreData *get_ignore(const Anope::string &nick) { IgnoreData *ign; - char tmp[BUFSIZE]; - char *user, *host; + Anope::string tmp; + size_t user, host; time_t now; User *u; - if (!nick) + if (nick.empty()) return NULL; /* User has disabled the IGNORE system */ if (!allow_ignore) @@ -129,24 +121,24 @@ IgnoreData *get_ignore(const char *nick) else { /* We didn't get a user.. generate a valid mask. */ - if ((host = const_cast<char *>(strchr(nick, '@')))) + if ((host = nick.find('@')) != Anope::string::npos) { - if ((user = const_cast<char *>(strchr(nick, '!')))) + if ((user = nick.find('!')) != Anope::string::npos) { /* this should never happen */ if (user > host) return NULL; - snprintf(tmp, sizeof(tmp), "%s", nick); + tmp = nick; } else /* We have user@host. Add nick wildcard. */ - snprintf(tmp, sizeof(tmp), "*!%s", nick); + tmp = "*!" + nick; } /* We only got a nick.. */ else - snprintf(tmp, sizeof(tmp), "%s!*@*", nick); + tmp = nick + "!*@*"; for (ign = ignore; ign; ign = ign->next) - if (Anope::Match(tmp, ign->mask, false)) + if (Anope::Match(tmp, ign->mask)) break; } /* Check whether the entry has timed out */ @@ -159,7 +151,6 @@ IgnoreData *get_ignore(const char *nick) ignore = ign->next; if (ign->next) ign->next->prev = ign->prev; - delete [] ign->mask; delete ign; ign = NULL; } @@ -175,37 +166,37 @@ IgnoreData *get_ignore(const char *nick) * @param nick Nick or (nick!)user@host to delete from the ignorelist. * @return Returns 1 on success, 0 if no entry is found. */ -int delete_ignore(const char *nick) +int delete_ignore(const Anope::string &nick) { IgnoreData *ign; - char tmp[BUFSIZE]; - char *user, *host; + Anope::string tmp; + size_t user, host; User *u; - if (!nick) + if (nick.empty()) return 0; /* If it s an existing user, we ignore the hostmask. */ if ((u = finduser(nick))) - snprintf(tmp, sizeof(tmp), "*!*@%s", u->host); + tmp = "*!*@" + u->host; /* Determine whether we get a nick or a mask. */ - else if ((host = const_cast<char *>(strchr(nick, '@')))) + else if ((host = nick.find('@')) != Anope::string::npos) { /* Check whether we have a nick too.. */ - if ((user = const_cast<char *>(strchr(nick, '!')))) + if ((user = nick.find('!')) != Anope::string::npos) { /* this should never happen */ if (user > host) return 0; - snprintf(tmp, sizeof(tmp), "%s", nick); + tmp = nick; } else /* We have user@host. Add nick wildcard. */ - snprintf(tmp, sizeof(tmp), "*!%s", nick); + tmp = "*!" + nick; } /* We only got a nick.. */ else - snprintf(tmp, sizeof(tmp), "%s!*@*", nick); + tmp = nick + "!*@*"; for (ign = ignore; ign; ign = ign->next) - if (!stricmp(ign->mask, tmp)) + if (tmp.equals_ci(ign->mask)) break; /* No matching ignore found. */ if (!ign) @@ -218,7 +209,6 @@ int delete_ignore(const char *nick) ignore = ign->next; if (ign->next) ign->next->prev = ign->prev; - delete [] ign->mask; delete ign; ign = NULL; return 1; @@ -240,7 +230,6 @@ int clear_ignores() { next = ign->next; Alog(LOG_DEBUG) << "Deleting ignore entry " << ign->mask; - delete [] ign->mask; delete ign; ++i; } @@ -299,7 +288,7 @@ int split_buf(char *buf, const char ***argv, int colon_special) /* process: Main processing routine. Takes the string in inbuf (global * variable) and does something appropriate with it. */ -void process(const std::string &buffer) +void process(const Anope::string &buffer) { int retVal = 0; char source[64] = ""; diff --git a/src/protocol.cpp b/src/protocol.cpp index 13ff84a24..7bb21407b 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -1,6 +1,6 @@ #include "services.h" -void IRCDProto::SendMessageInternal(BotInfo *bi, const char *dest, const char *buf) +void IRCDProto::SendMessageInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &buf) { if (Config.NSDefFlags.HasFlag(NI_MSG)) SendPrivmsgInternal(bi, dest, buf); @@ -8,50 +8,49 @@ void IRCDProto::SendMessageInternal(BotInfo *bi, const char *dest, const char *b SendNoticeInternal(bi, dest, buf); } -void IRCDProto::SendNoticeInternal(BotInfo *bi, const char *dest, const char *msg) +void IRCDProto::SendNoticeInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &msg) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :%s", dest, msg); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :%s", dest.c_str(), msg.c_str()); } -void IRCDProto::SendPrivmsgInternal(BotInfo *bi, const char *dest, const char *buf) +void IRCDProto::SendPrivmsgInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &buf) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s :%s", dest, buf); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s :%s", dest.c_str(), buf.c_str()); } -void IRCDProto::SendQuitInternal(BotInfo *bi, const char *buf) +void IRCDProto::SendQuitInternal(BotInfo *bi, const Anope::string &buf) { - if (buf) - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "QUIT :%s", buf); + if (!buf.empty()) + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "QUIT :%s", buf.c_str()); else send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "QUIT"); } -void IRCDProto::SendPartInternal(BotInfo *bi, Channel *chan, const char *buf) +void IRCDProto::SendPartInternal(BotInfo *bi, Channel *chan, const Anope::string &buf) { - if (buf) - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PART %s :%s", chan->name.c_str(), buf); + if (!buf.empty()) + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PART %s :%s", chan->name.c_str(), buf.c_str()); else send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PART %s", chan->name.c_str()); } -void IRCDProto::SendGlobopsInternal(BotInfo *source, const char *buf) +void IRCDProto::SendGlobopsInternal(BotInfo *source, const Anope::string &buf) { if (source) - send_cmd(ircd->ts6 ? source->GetUID() : source->nick, "GLOBOPS :%s", buf); + send_cmd(ircd->ts6 ? source->GetUID() : source->nick, "GLOBOPS :%s", buf.c_str()); else - send_cmd(Config.ServerName, "GLOBOPS :%s", buf); + send_cmd(Config.ServerName, "GLOBOPS :%s", buf.c_str()); } -void IRCDProto::SendCTCPInternal(BotInfo *bi, const char *dest, const char *buf) +void IRCDProto::SendCTCPInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &buf) { - char *s = normalizeBuffer(buf); - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :\1%s\1", dest, s); - delete [] s; + Anope::string s = normalizeBuffer(buf); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :\1%s\1", dest.c_str(), s.c_str()); } -void IRCDProto::SendNumericInternal(const char *source, int numeric, const char *dest, const char *buf) +void IRCDProto::SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf) { - send_cmd(source, "%03d %s %s", numeric, dest, buf); + send_cmd(source, "%03d %s %s", numeric, dest.c_str(), buf.c_str()); } void IRCDProto::SendSVSKill(BotInfo *source, User *user, const char *fmt, ...) @@ -110,7 +109,7 @@ void IRCDProto::SendNoticeChanops(BotInfo *bi, Channel *dest, const char *fmt, . SendNoticeChanopsInternal(bi, dest, buf); } -void IRCDProto::SendMessage(BotInfo *bi, const char *dest, const char *fmt, ...) +void IRCDProto::SendMessage(BotInfo *bi, const Anope::string &dest, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -120,7 +119,7 @@ void IRCDProto::SendMessage(BotInfo *bi, const char *dest, const char *fmt, ...) SendMessageInternal(bi, dest, buf); } -void IRCDProto::SendNotice(BotInfo *bi, const char *dest, const char *fmt, ...) +void IRCDProto::SendNotice(BotInfo *bi, const Anope::string &dest, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -130,18 +129,18 @@ void IRCDProto::SendNotice(BotInfo *bi, const char *dest, const char *fmt, ...) SendNoticeInternal(bi, dest, buf); } -void IRCDProto::SendAction(BotInfo *bi, const char *dest, const char *fmt, ...) +void IRCDProto::SendAction(BotInfo *bi, const Anope::string &dest, const char *fmt, ...) { va_list args; - char buf[BUFSIZE] = "", actionbuf[BUFSIZE] = ""; + char buf[BUFSIZE] = ""; va_start(args, fmt); vsnprintf(buf, BUFSIZE - 1, fmt, args); va_end(args); - snprintf(actionbuf, BUFSIZE - 1, "%cACTION %s%c", 1, buf, 1); + Anope::string actionbuf = Anope::string("\1ACTION ") + buf + '\1'; SendPrivmsgInternal(bi, dest, actionbuf); } -void IRCDProto::SendPrivmsg(BotInfo *bi, const char *dest, const char *fmt, ...) +void IRCDProto::SendPrivmsg(BotInfo *bi, const Anope::string &dest, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -151,17 +150,17 @@ void IRCDProto::SendPrivmsg(BotInfo *bi, const char *dest, const char *fmt, ...) SendPrivmsgInternal(bi, dest, buf); } -void IRCDProto::SendGlobalNotice(BotInfo *bi, Server *dest, const char *msg) +void IRCDProto::SendGlobalNotice(BotInfo *bi, Server *dest, const Anope::string &msg) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg.c_str()); } -void IRCDProto::SendGlobalPrivmsg(BotInfo *bi, Server *dest, const char *msg) +void IRCDProto::SendGlobalPrivmsg(BotInfo *bi, Server *dest, const Anope::string &msg) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg.c_str()); } -void IRCDProto::SendQuit(const char *nick, const char *) +void IRCDProto::SendQuit(const Anope::string &nick, const Anope::string &) { send_cmd(nick, "QUIT"); } @@ -176,12 +175,12 @@ void IRCDProto::SendQuit(BotInfo *bi, const char *fmt, ...) SendQuitInternal(bi, buf); } -void IRCDProto::SendPing(const char *servname, const char *who) +void IRCDProto::SendPing(const Anope::string &servname, const Anope::string &who) { - if (!servname) - send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PING %s", who); + if (servname.empty()) + send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PING %s", who.c_str()); else - send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PING %s %s", servname, who); + send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PING %s %s", servname.c_str(), who.c_str()); } /** @@ -190,17 +189,17 @@ void IRCDProto::SendPing(const char *servname, const char *who) * @param servname Daemon or client that is responding to the PING. * @param who Origin of the PING and destination of the PONG message. **/ -void IRCDProto::SendPong(const char *servname, const char *who) +void IRCDProto::SendPong(const Anope::string &servname, const Anope::string &who) { - if (!servname) - send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PONG %s", who); - else - send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PONG %s %s", servname, who); + if (servname.empty()) + send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PONG %s", who.c_str()); + else + send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PONG %s %s", servname.c_str(), who.c_str()); } -void IRCDProto::SendInvite(BotInfo *bi, const char *chan, const char *nick) +void IRCDProto::SendInvite(BotInfo *bi, const Anope::string &chan, const Anope::string &nick) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "INVITE %s %s", nick, chan); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "INVITE %s %s", nick.c_str(), chan.c_str()); } void IRCDProto::SendPart(BotInfo *bi, Channel *chan, const char *fmt, ...) @@ -214,7 +213,8 @@ void IRCDProto::SendPart(BotInfo *bi, Channel *chan, const char *fmt, ...) va_end(args); SendPartInternal(bi, chan, buf); } - else SendPartInternal(bi, chan, NULL); + else + SendPartInternal(bi, chan, ""); } void IRCDProto::SendGlobops(BotInfo *source, const char *fmt, ...) @@ -227,21 +227,22 @@ void IRCDProto::SendGlobops(BotInfo *source, const char *fmt, ...) SendGlobopsInternal(source, buf); } -void IRCDProto::SendSquit(const char *servname, const char *message) +void IRCDProto::SendSquit(const Anope::string &servname, const Anope::string &message) { - send_cmd(NULL, "SQUIT %s :%s", servname, message); + send_cmd("", "SQUIT %s :%s", servname.c_str(), message.c_str()); } -void IRCDProto::SendChangeBotNick(BotInfo *bi, const char *newnick) +void IRCDProto::SendChangeBotNick(BotInfo *bi, const Anope::string &newnick) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NICK %s %ld", newnick, static_cast<long>(time(NULL))); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NICK %s %ld", newnick.c_str(), static_cast<long>(time(NULL))); } -void IRCDProto::SendForceNickChange(User *u, const char *newnick, time_t when) + +void IRCDProto::SendForceNickChange(User *u, const Anope::string &newnick, time_t when) { - send_cmd(NULL, "SVSNICK %s %s :%ld", u->nick.c_str(), newnick, static_cast<long>(when)); + send_cmd("", "SVSNICK %s %s :%ld", u->nick.c_str(), newnick.c_str(), static_cast<long>(when)); } -void IRCDProto::SendCTCP(BotInfo *bi, const char *dest, const char *fmt, ...) +void IRCDProto::SendCTCP(BotInfo *bi, const Anope::string &dest, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -251,7 +252,7 @@ void IRCDProto::SendCTCP(BotInfo *bi, const char *dest, const char *fmt, ...) SendCTCPInternal(bi, dest, buf); } -void IRCDProto::SendNumeric(const char *source, int numeric, const char *dest, const char *fmt, ...) +void IRCDProto::SendNumeric(const Anope::string &source, int numeric, const Anope::string &dest, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -261,10 +262,10 @@ void IRCDProto::SendNumeric(const char *source, int numeric, const char *dest, c SendNumericInternal(source, numeric, dest, buf); } -int IRCDProto::IsChannelValid(const char *chan) +bool IRCDProto::IsChannelValid(const Anope::string &chan) { - if (*chan != '#') - return 0; + if (chan[0] != '#') + return false; - return 1; + return true; } diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 4670bc109..d596b6bb6 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -16,16 +16,14 @@ /** Default constructor * @param chname The channel name */ -ChannelInfo::ChannelInfo(const std::string &chname) +ChannelInfo::ChannelInfo(const Anope::string &chname) { if (chname.empty()) throw CoreException("Empty channel passed to ChannelInfo constructor"); founder = successor = NULL; - desc = last_topic = forbidby = forbidreason = NULL; last_topic_time = 0; levels = NULL; - entry_message = NULL; c = NULL; capsmin = capspercent = 0; floodlines = floodsecs = 0; @@ -59,7 +57,7 @@ ChannelInfo::ChannelInfo(const std::string &chname) reset_levels(this); - RegisteredChannelList[this->name.c_str()] = this; + RegisteredChannelList[this->name] = this; } /** Default destructor, cleans up the channel complete and removes it from the internal list @@ -79,19 +77,8 @@ ChannelInfo::~ChannelInfo() this->c->ci = NULL; } - RegisteredChannelList.erase(this->name.c_str()); + RegisteredChannelList.erase(this->name); - if (this->desc) - delete [] this->desc; - if (this->entry_message) - delete [] this->entry_message; - - if (this->last_topic) - delete [] this->last_topic; - if (this->forbidby) - delete [] this->forbidby; - if (this->forbidreason) - delete [] this->forbidreason; this->ClearAccess(); this->ClearAkick(); this->ClearBadWords(); @@ -101,11 +88,7 @@ ChannelInfo::~ChannelInfo() if (!this->memos.memos.empty()) { for (i = 0, end = this->memos.memos.size(); i < end; ++i) - { - if (this->memos.memos[i]->text) - delete [] this->memos.memos[i]->text; delete this->memos.memos[i]; - } this->memos.memos.clear(); } @@ -126,7 +109,7 @@ ChannelInfo::~ChannelInfo() * Creates a new access list entry and inserts it into the access list. */ -void ChannelInfo::AddAccess(NickCore *nc, int16 level, const std::string &creator, int32 last_seen) +void ChannelInfo::AddAccess(NickCore *nc, int16 level, const Anope::string &creator, int32 last_seen) { ChanAccess *new_access = new ChanAccess(); new_access->nc = nc; @@ -164,7 +147,7 @@ ChanAccess *ChannelInfo::GetAccess(unsigned index) * Retrieves an entry from the access list that matches the given NickCore, optionally also matching a certain level. */ -ChanAccess *ChannelInfo::GetAccess(NickCore *nc, int16 level) +ChanAccess *ChannelInfo::GetAccess(const NickCore *nc, int16 level) { if (access.empty()) return NULL; @@ -184,7 +167,6 @@ const unsigned ChannelInfo::GetAccessCount() const return access.empty() ? 0 : access.size(); } - /** Erase an entry from the channel access list * * @param index The index in the access list vector @@ -217,7 +199,7 @@ void ChannelInfo::ClearAccess() * @param lu The time the akick was last used, defaults to never * @return The AutoKick structure */ -AutoKick *ChannelInfo::AddAkick(const std::string &user, NickCore *akicknc, const std::string &reason, time_t t, time_t lu) +AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t, time_t lu) { if (!akicknc) return NULL; @@ -243,7 +225,7 @@ AutoKick *ChannelInfo::AddAkick(const std::string &user, NickCore *akicknc, cons * @param lu The time the akick was last used, defaults to never * @return The AutoKick structure */ -AutoKick *ChannelInfo::AddAkick(const std::string &user, const std::string &mask, const std::string &reason, time_t t, time_t lu) +AutoKick *ChannelInfo::AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t, time_t lu) { AutoKick *autokick = new AutoKick(); autokick->mask = mask; @@ -302,7 +284,7 @@ void ChannelInfo::ClearAkick() * @param type The type (SINGLE START END) * @return The badword */ -BadWord *ChannelInfo::AddBadWord(const std::string &word, BadWordType type) +BadWord *ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type) { BadWord *bw = new BadWord; bw->word = word; @@ -360,11 +342,11 @@ void ChannelInfo::ClearBadWords() */ void ChannelInfo::LoadMLock() { - std::vector<std::string> modenames; + std::vector<Anope::string> modenames; if (this->GetExtRegular("db_mlock_modes_on", modenames)) { - for (std::vector<std::string>::iterator it = modenames.begin(), it_end = modenames.end(); it != it_end; ++it) + for (std::vector<Anope::string>::iterator it = modenames.begin(), it_end = modenames.end(); it != it_end; ++it) { for (std::list<Mode *>::iterator mit = ModeManager::Modes.begin(), mit_end = ModeManager::Modes.end(); mit != mit_end; ++mit) { @@ -372,7 +354,7 @@ void ChannelInfo::LoadMLock() { ChannelMode *cm = dynamic_cast<ChannelMode *>(*mit); - if (cm->NameAsString == *it) + if (cm->NameAsString.equals_ci(*it)) this->SetMLock(cm->Name, true); } } @@ -383,7 +365,7 @@ void ChannelInfo::LoadMLock() if (this->GetExtRegular("db_mlock_modes_off", modenames)) { - for (std::vector<std::string>::iterator it = modenames.begin(), it_end = modenames.end(); it != it_end; ++it) + for (std::vector<Anope::string>::iterator it = modenames.begin(), it_end = modenames.end(); it != it_end; ++it) { for (std::list<Mode *>::iterator mit = ModeManager::Modes.begin(), mit_end = ModeManager::Modes.end(); mit != mit_end; ++mit) { @@ -391,7 +373,7 @@ void ChannelInfo::LoadMLock() { ChannelMode *cm = dynamic_cast<ChannelMode *>(*mit); - if (cm->NameAsString == *it) + if (cm->NameAsString.equals_ci(*it)) this->SetMLock(cm->Name, false); } } @@ -400,11 +382,11 @@ void ChannelInfo::LoadMLock() this->Shrink("db_mlock_modes_off"); } - std::vector<std::pair<std::string, std::string> > params; + std::vector<std::pair<Anope::string, Anope::string> > params; if (this->GetExtRegular("db_mlp", params)) { - for (std::vector<std::pair<std::string, std::string> >::iterator it = params.begin(), it_end = params.end(); it != it_end; ++it) + for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = params.begin(), it_end = params.end(); it != it_end; ++it) { for (std::list<Mode *>::iterator mit = ModeManager::Modes.begin(), mit_end = ModeManager::Modes.end(); mit != mit_end; ++mit) { @@ -412,7 +394,7 @@ void ChannelInfo::LoadMLock() { ChannelMode *cm = dynamic_cast<ChannelMode *>(*mit); - if (cm->NameAsString == it->first) + if (cm->NameAsString.equals_ci(it->first)) this->SetMLock(cm->Name, true, it->second); } } @@ -441,7 +423,7 @@ const bool ChannelInfo::HasMLock(ChannelModeName Name, bool status) * @param param The param to use for this mode, if required * @return true on success, false on failure (module blocking) */ -bool ChannelInfo::SetMLock(ChannelModeName Name, bool status, const std::string param) +bool ChannelInfo::SetMLock(ChannelModeName Name, bool status, const Anope::string ¶m) { if (!status && !param.empty()) throw CoreException("Was told to mlock a mode negatively with a param?"); @@ -455,7 +437,7 @@ bool ChannelInfo::SetMLock(ChannelModeName Name, bool status, const std::string mlock_on.UnsetFlag(Name); mlock_off.UnsetFlag(Name); - std::map<ChannelModeName, std::string>::iterator it = Params.find(Name); + std::map<ChannelModeName, Anope::string>::iterator it = Params.find(Name); if (it != Params.end()) Params.erase(it); @@ -484,7 +466,7 @@ bool ChannelInfo::RemoveMLock(ChannelModeName Name) mlock_on.UnsetFlag(Name); mlock_off.UnsetFlag(Name); - std::map<ChannelModeName, std::string>::iterator it = Params.find(Name); + std::map<ChannelModeName, Anope::string>::iterator it = Params.find(Name); if (it != Params.end()) Params.erase(it); @@ -516,9 +498,9 @@ const size_t ChannelInfo::GetMLockCount(bool status) const * @param Target a string to put the param into * @return true on success */ -const bool ChannelInfo::GetParam(ChannelModeName Name, std::string &Target) +const bool ChannelInfo::GetParam(ChannelModeName Name, Anope::string &Target) { - std::map<ChannelModeName, std::string>::iterator it = Params.find(Name); + std::map<ChannelModeName, Anope::string>::iterator it = Params.find(Name); Target.clear(); @@ -536,7 +518,7 @@ const bool ChannelInfo::GetParam(ChannelModeName Name, std::string &Target) */ const bool ChannelInfo::HasParam(ChannelModeName Name) { - std::map<ChannelModeName, std::string>::iterator it = Params.find(Name); + std::map<ChannelModeName, Anope::string>::iterator it = Params.find(Name); if (it != Params.end()) return true; @@ -559,9 +541,9 @@ bool ChannelInfo::CheckKick(User *user) { AutoKick *autokick; bool set_modes = false, do_kick = false; - NickCore *nc; - char mask[BUFSIZE]; - const char *reason; + const NickCore *nc; + Anope::string mask; + Anope::string reason; if (!user || !this->c) return false; @@ -582,8 +564,8 @@ bool ChannelInfo::CheckKick(User *user) if (!is_oper(user) && (this->HasFlag(CI_SUSPENDED) || this->HasFlag(CI_FORBIDDEN))) { - get_idealban(this, user, mask, sizeof(mask)); - reason = this->forbidreason ? this->forbidreason : getstring(user, CHAN_MAY_NOT_BE_USED); + get_idealban(this, user, mask); + reason = !this->forbidreason.empty() ? this->forbidreason : getstring(user, CHAN_MAY_NOT_BE_USED); set_modes = true; do_kick = true; } @@ -602,15 +584,15 @@ bool ChannelInfo::CheckKick(User *user) { autokick = this->GetAkick(j); - if ((autokick->HasFlag(AK_ISNICK) && autokick->nc == nc) || (!autokick->HasFlag(AK_ISNICK) && match_usermask(autokick->mask.c_str(), user))) + if ((autokick->HasFlag(AK_ISNICK) && autokick->nc == nc) || (!autokick->HasFlag(AK_ISNICK) && match_usermask(autokick->mask, user))) { Alog(LOG_DEBUG_2) << user->nick << " matched akick " << (autokick->HasFlag(AK_ISNICK) ? autokick->nc->display : autokick->mask); autokick->last_used = time(NULL); if (autokick->HasFlag(AK_ISNICK)) - get_idealban(this, user, mask, sizeof(mask)); + get_idealban(this, user, mask); else - strlcpy(mask, autokick->mask.c_str(), sizeof(mask)); - reason = !autokick->reason.empty() ? autokick->reason.c_str() : Config.CSAutokickReason; + mask = autokick->mask; + reason = !autokick->reason.empty() ? autokick->reason : Config.CSAutokickReason; do_kick = true; break; } @@ -619,7 +601,7 @@ bool ChannelInfo::CheckKick(User *user) if (!do_kick && check_access(user, this, CA_NOJOIN)) { - get_idealban(this, user, mask, sizeof(mask)); + get_idealban(this, user, mask); reason = getstring(user, CHAN_NOT_ALLOWED_TO_JOIN); do_kick = true; } @@ -653,7 +635,7 @@ bool ChannelInfo::CheckKick(User *user) } this->c->SetMode(NULL, CMODE_BAN, mask); - this->c->Kick(NULL, user, "%s", reason); + this->c->Kick(NULL, user, "%s", reason.c_str()); return true; } diff --git a/src/send.cpp b/src/send.cpp index 430c7f919..f04e937c2 100644 --- a/src/send.cpp +++ b/src/send.cpp @@ -21,42 +21,7 @@ * @param ... any number of parameters * @return void */ -void send_cmd(const char *source, const char *fmt, ...) -{ - va_list args; - static char buf[BUFSIZE]; - - va_start(args, fmt); - - vsnprintf(buf, BUFSIZE - 1, fmt, args); - - if (!UplinkSock) - { - if (source) - Alog(LOG_DEBUG) << "Attemtped to send \"" << source << " " << buf << "\" with UplinkSock NULL"; - else - Alog(LOG_DEBUG) << "Attemtped to send \"" << buf << "\" with UplinkSock NULL"; - return; - } - - if (source) - { - UplinkSock->Write(":%s %s", source, buf); - Alog(LOG_DEBUG) << "Sent: :" << source << " " << buf; - } - else - { - UplinkSock->Write("%s", buf); - Alog(LOG_DEBUG) << "Sent: "<< buf; - } - - va_end(args); -} - -/* - * Copypasta version that accepts std::string source. - */ -void send_cmd(const std::string &source, const char *fmt, ...) +void send_cmd(const Anope::string &source, const char *fmt, ...) { va_list args; static char buf[BUFSIZE]; @@ -70,7 +35,7 @@ void send_cmd(const std::string &source, const char *fmt, ...) if (!source.empty()) Alog(LOG_DEBUG) << "Attemtped to send \"" << source << " " << buf << "\" with UplinkSock NULL"; else - Alog(LOG_DEBUG) << "Attemtped to send " << buf << "\" with UplinkSock NULL"; + Alog(LOG_DEBUG) << "Attemtped to send \"" << buf << "\" with UplinkSock NULL"; return; } @@ -82,7 +47,7 @@ void send_cmd(const std::string &source, const char *fmt, ...) else { UplinkSock->Write("%s", buf); - Alog(LOG_DEBUG) << "Sent: " << buf; + Alog(LOG_DEBUG) << "Sent: "<< buf; } va_end(args); @@ -98,7 +63,7 @@ void send_cmd(const std::string &source, const char *fmt, ...) * @param ... any number of parameters * @return void */ -void notice_server(char *source, Server * s, const char *fmt, ...) +void notice_server(const Anope::string &source, Server *s, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -119,32 +84,6 @@ void notice_server(char *source, Server * s, const char *fmt, ...) /*************************************************************************/ /** - * Send a NULL-terminated array of text as NOTICEs. - * @param source Orgin of the Message - * @param dest Destination of the Notice - * @param text Array of text to send - * @return void - */ -void notice_list(char *source, char *dest, char **text) -{ - User *u = finduser(dest); - while (*text) - { - /* Have to kludge around an ircII bug here: if a notice includes - * no text, it is ignored, so we replace blank lines by lines - * with a single space. - */ - if (**text) - u->SendMessage(source, "%s", *text); - else - u->SendMessage(source, " "); - ++text; - } -} - -/*************************************************************************/ - -/** * Send a message in the user's selected language to the user using NOTICE. * @param source Orgin of the Message * @param u User Struct @@ -152,7 +91,7 @@ void notice_list(char *source, char *dest, char **text) * @param ... any number of parameters * @return void */ -void notice_lang(const std::string &source, User * dest, int message, ...) +void notice_lang(const Anope::string &source, User *dest, int message, ...) { va_list args; char buf[4096]; /* because messages can be really big */ @@ -193,7 +132,7 @@ void notice_lang(const std::string &source, User * dest, int message, ...) * @param ... any number of parameters * @return void */ -void notice_help(const char *source, User * dest, int message, ...) +void notice_help(const Anope::string &source, User * dest, int message, ...) { va_list args; char buf[4096], buf2[4096], outbuf[BUFSIZE]; @@ -220,7 +159,7 @@ void notice_help(const char *source, User * dest, int message, ...) if (*s) *s++ = 0; strscpy(outbuf, t, sizeof(outbuf)); - strnrepl(outbuf, sizeof(outbuf), "\1\1", source); + strnrepl(outbuf, sizeof(outbuf), "\1\1", source.c_str()); dest->SendMessage(source, "%s", *outbuf ? outbuf : " "); } diff --git a/src/servers.cpp b/src/servers.cpp index 69562e9c2..251e594ea 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -12,7 +12,7 @@ #include "services.h" #include "modules.h" -char *TS6SID = NULL; +Anope::string TS6SID; /* Anope */ Server *Me = NULL; @@ -56,7 +56,7 @@ Flags<CapabType, CAPAB_END> Capab; * @param description Server rdescription * @param sid Server sid/numeric */ -Server::Server(Server *uplink, const std::string &name, unsigned int hops, const std::string &description, const std::string &sid) : Name(name), Hops(hops), Description(description), SID(sid), UplinkServer(uplink) +Server::Server(Server *uplink, const Anope::string &name, unsigned int hops, const Anope::string &description, const Anope::string &sid) : Name(name), Hops(hops), Description(description), SID(sid), UplinkServer(uplink) { Links = NULL; @@ -103,9 +103,7 @@ Server::~Server() if (na && !na->HasFlag(NS_FORBIDDEN) && (!na->nc->HasFlag(NI_SUSPENDED)) && (u->IsRecognized() || u->IsIdentified())) { na->last_seen = t; - if (na->last_quit) - delete [] na->last_quit; - na->last_quit = (!QReason.empty() ? sstrdup(QReason.c_str()) : NULL); + na->last_quit = QReason; } delete u; @@ -116,15 +114,11 @@ Server::~Server() } if (UplinkServer) - { UplinkServer->DelLink(this); - } if (Links) - { for (std::list<Server *>::iterator it = Links->begin(), it_end = Links->end(); it != it_end; ++it) delete *it; - } delete Links; } @@ -132,7 +126,7 @@ Server::~Server() /** Delete this server with a reason * @param reason The reason */ -void Server::Delete(const std::string &reason) +void Server::Delete(const Anope::string &reason) { QReason = reason; delete this; @@ -141,7 +135,7 @@ void Server::Delete(const std::string &reason) /** Get the name for this server * @return The name */ -const std::string &Server::GetName() const +const Anope::string &Server::GetName() const { return Name; } @@ -157,7 +151,7 @@ unsigned int Server::GetHops() const /** Set the server description * @param desc The new description */ -void Server::SetDescription(const std::string &desc) +void Server::SetDescription(const Anope::string &desc) { Description = desc; } @@ -165,7 +159,7 @@ void Server::SetDescription(const std::string &desc) /** Get the server description * @return The server description */ -const std::string &Server::GetDescription() const +const Anope::string &Server::GetDescription() const { return Description; } @@ -173,7 +167,7 @@ const std::string &Server::GetDescription() const /** Get the server numeric/SID * @return The numeric/SID */ -const std::string &Server::GetSID() const +const Anope::string &Server::GetSID() const { return SID; } @@ -204,7 +198,7 @@ void Server::AddLink(Server *s) */ if (this == Me && !UplinkServer) UplinkServer = s; - + if (!Links) Links = new std::list<Server *>(); @@ -286,8 +280,8 @@ bool Server::IsSynced() const */ bool Server::IsULined() const { - for (int j = 0; j < Config.NumUlines; ++j) - if (!stricmp(Config.Ulines[j], GetName().c_str())) + for (std::list<Anope::string>::const_iterator it = Config.Ulines.begin(), it_end = Config.Ulines.end(); it != it_end; ++it) + if (it->equals_ci(GetName())) return true; return false; } @@ -297,13 +291,13 @@ bool Server::IsULined() const * @param s The server list to search for this server on, defaults to our Uplink * @return The server */ -Server *Server::Find(const std::string &name, Server *s) +Server *Server::Find(const Anope::string &name, Server *s) { Alog(LOG_DEBUG) << "Server::Find called for " << name; if (!s) s = Me; - if (s->GetName() == name || s->GetSID() == name) + if (s->GetName().equals_cs(name) || s->GetSID().equals_cs(name)) return s; if (s->GetLinks()) @@ -312,7 +306,7 @@ Server *Server::Find(const std::string &name, Server *s) { Server *serv = *it; - if (serv->GetName() == name || serv->GetSID() == name) + if (serv->GetName().equals_cs(name) || serv->GetSID().equals_cs(name)) return serv; Alog(LOG_DEBUG) << "Server::Find checking " << serv->GetName() << " server tree for " << name; Server *server = Server::Find(name, serv); @@ -335,7 +329,7 @@ Server *Server::Find(const std::string &name, Server *s) * @param numeric Server Numberic/SUID * @return void */ -void do_server(const std::string &source, const std::string &servername, unsigned int hops, const std::string &descript, const std::string &numeric) +void do_server(const Anope::string &source, const Anope::string &servername, unsigned int hops, const Anope::string &descript, const Anope::string &numeric) { if (source.empty()) Alog(LOG_DEBUG) << "Server " << servername << " introduced"; @@ -358,8 +352,8 @@ void do_server(const std::string &source, const std::string &servername, unsigne Server *newserver = new Server(s, servername, hops, descript, numeric); /* Announce services being online. */ - if (Config.GlobalOnCycle && Config.GlobalOnCycleUP) - notice_server(Config.s_GlobalNoticer, newserver, "%s", Config.GlobalOnCycleUP); + if (Config.GlobalOnCycle && !Config.GlobalOnCycleUP.empty()) + notice_server(Config.s_GlobalNoticer, newserver, "%s", Config.GlobalOnCycleUP.c_str()); /* Let modules know about the connection */ FOREACH_MOD(I_OnNewServer, OnNewServer(newserver)); @@ -374,9 +368,8 @@ void do_server(const std::string &source, const std::string &servername, unsigne * @param av Agruments as part of the SQUIT * @return void */ -void do_squit(const char *source, int ac, const char **av) +void do_squit(const Anope::string &source, int ac, const char **av) { - char buf[BUFSIZE]; Server *s = Server::Find(av[0]); if (!s) @@ -387,22 +380,23 @@ void do_squit(const char *source, int ac, const char **av) FOREACH_MOD(I_OnServerQuit, OnServerQuit(s)); + Anope::string buf; /* If this is a juped server, send a nice global to inform the online * opers that we received it. */ if (s->HasFlag(SERVER_JUPED)) { - snprintf(buf, BUFSIZE, "Received SQUIT for juped server %s", s->GetName().c_str()); - ircdproto->SendGlobops(OperServ, buf); + buf = "Received SQUIT for juped server " + s->GetName(); + ircdproto->SendGlobops(OperServ, "%s", buf.c_str()); } - snprintf(buf, sizeof(buf), "%s %s", s->GetName().c_str(), s->GetUplink()->GetName().c_str()); + buf = s->GetName() + " " + s->GetUplink()->GetName(); if (s->GetUplink() == Me->GetUplink() && Capab.HasFlag(CAPAB_UNCONNECT)) { Alog(LOG_DEBUG) << "Sending UNCONNECT SQUIT for " << s->GetName(); /* need to fix */ - ircdproto->SendSquit(s->GetName().c_str(), buf); + ircdproto->SendSquit(s->GetName(), buf); } s->Delete(buf); @@ -420,11 +414,11 @@ void CapabParse(int ac, const char **av) { for (unsigned j = 0; !Capab_Info[j].Token.empty(); ++j) { - if (av[i] == Capab_Info[j].Token) + if (Capab_Info[j].Token.equals_ci(av[i])) { Capab.SetFlag(Capab_Info[j].Flag); - if (Capab_Info[j].Token == "NICKIP" && !ircd->nickip) + if (Capab_Info[j].Token.equals_ci("NICKIP") && !ircd->nickip) ircd->nickip = 1; break; } @@ -452,7 +446,7 @@ static char ts6_new_uid[10]; static void ts6_uid_increment(unsigned int slot) { - if (slot != strlen(TS6SID)) + if (slot != TS6SID.length()) { if (ts6_new_uid[slot] == 'Z') ts6_new_uid[slot] = '0'; @@ -487,7 +481,7 @@ const char *ts6_uid_retrieve() if (!ts6_uid_initted) { - snprintf(ts6_new_uid, 10, "%sAAAAAA", TS6SID); + snprintf(ts6_new_uid, 10, "%sAAAAAA", TS6SID.c_str()); ts6_uid_initted = true; } @@ -554,7 +548,7 @@ const char *ts6_sid_retrieve() if (!ts6_sid_initted) { // Initialize ts6_new_sid with the services server SID - snprintf(ts6_new_sid, 4, "%s", TS6SID); + snprintf(ts6_new_sid, 4, "%s", TS6SID.c_str()); ts6_sid_initted = true; } diff --git a/src/sessions.cpp b/src/sessions.cpp index 9c8ec7163..9a1bc7a76 100644 --- a/src/sessions.cpp +++ b/src/sessions.cpp @@ -51,8 +51,7 @@ session_map SessionList; -Exception *exceptions = NULL; -int16 nexceptions = 0; +std::vector<Exception *> exceptions; /*************************************************************************/ /****************************** Statistics *******************************/ @@ -66,7 +65,7 @@ void get_session_stats(long *nrec, long *memuse) { Session *session = it->second; - mem += strlen(session->host) + 1; + mem += session->host.length() + 1; } *memuse = mem; @@ -76,15 +75,19 @@ void get_session_stats(long *nrec, long *memuse) void get_exception_stats(long *nrec, long *memuse) { long mem; - int i; - mem = sizeof(Exception) * nexceptions; - for (i = 0; i < nexceptions; ++i) + mem = sizeof(Exception) * exceptions.size(); + for (std::vector<Exception *>::const_iterator it = exceptions.begin(), it_end = exceptions.end(); it != it_end; ++it) { - mem += strlen(exceptions[i].mask) + 1; - mem += strlen(exceptions[i].reason) + 1; + Exception *e = *it; + if (!e->mask.empty()) + mem += e->mask.length() + 1; + if (!e->reason.empty()) + mem += e->reason.length() + 1; + if (!e->who.empty()) + mem += e->who.length() + 1; } - *nrec = nexceptions; + *nrec = exceptions.size(); *memuse = mem; } @@ -92,7 +95,7 @@ void get_exception_stats(long *nrec, long *memuse) /********************* Internal Session Functions ************************/ /*************************************************************************/ -Session *findsession(const std::string &host) +Session *findsession(const Anope::string &host) { session_map::const_iterator it = SessionList.find(host); @@ -106,7 +109,7 @@ Session *findsession(const std::string &host) * Returns 1 if the host was added or 0 if the user was killed. */ -int add_session(const char *nick, const char *host, char *hostip) +int add_session(const Anope::string &nick, const Anope::string &host, const Anope::string &hostip) { Session *session; Exception *exception; @@ -120,12 +123,12 @@ int add_session(const char *nick, const char *host, char *hostip) sessionlimit = exception ? exception->limit : Config.DefSessionLimit; - if (sessionlimit != 0 && session->count >= sessionlimit) + if (sessionlimit && session->count >= sessionlimit) { - if (Config.SessionLimitExceeded) - ircdproto->SendMessage(OperServ, nick, Config.SessionLimitExceeded, host); - if (Config.SessionLimitDetailsLoc) - ircdproto->SendMessage(OperServ, nick, "%s", Config.SessionLimitDetailsLoc); + if (!Config.SessionLimitExceeded.empty()) + ircdproto->SendMessage(OperServ, nick, Config.SessionLimitExceeded.c_str(), host.c_str()); + if (!Config.SessionLimitDetailsLoc.empty()) + ircdproto->SendMessage(OperServ, nick, "%s", Config.SessionLimitDetailsLoc.c_str()); /* Previously on IRCds that send a QUIT (InspIRCD) when a user is killed, the session for a host was * decremented in do_quit, which caused problems and fixed here @@ -140,12 +143,11 @@ int add_session(const char *nick, const char *host, char *hostip) ++session->hits; if (Config.MaxSessionKill && session->hits >= Config.MaxSessionKill) { - char akillmask[BUFSIZE]; - snprintf(akillmask, sizeof(akillmask), "*@%s", host); - XLine *x = new XLine(ci::string("*@") + host, Config.s_OperServ, time(NULL) + Config.SessionAutoKillExpiry, "Session limit exceeded"); + Anope::string akillmask = "*@" + host; + XLine *x = new XLine(akillmask, Config.s_OperServ, time(NULL) + Config.SessionAutoKillExpiry, "Session limit exceeded"); if (x) x->By = Config.s_OperServ; - ircdproto->SendGlobops(OperServ, "Added a temporary AKILL for \2%s\2 due to excessive connections", akillmask); + ircdproto->SendGlobops(OperServ, "Added a temporary AKILL for \2%s\2 due to excessive connections", akillmask.c_str()); } return 0; } @@ -157,7 +159,7 @@ int add_session(const char *nick, const char *host, char *hostip) } session = new Session; - session->host = sstrdup(host); + session->host = host; session->count = 1; session->hits = 0; @@ -166,7 +168,7 @@ int add_session(const char *nick, const char *host, char *hostip) return 1; } -void del_session(const char *host) +void del_session(const Anope::string &host) { if (!Config.LimitSessions) { @@ -174,7 +176,7 @@ void del_session(const char *host) return; } - if (!host || !*host) + if (host.empty()) { Alog(LOG_DEBUG) << "del_session called with NULL values"; return; @@ -188,7 +190,7 @@ void del_session(const char *host) { if (debug) { - ircdproto->SendGlobops(OperServ, "WARNING: Tried to delete non-existant session: \2%s", host); + ircdproto->SendGlobops(OperServ, "WARNING: Tried to delete non-existant session: \2%s", host.c_str()); Alog(LOG_DEBUG) << "session: Tried to delete non-existant session: " << host; } return; @@ -204,7 +206,6 @@ void del_session(const char *host) Alog(LOG_DEBUG_2) << "del_session(): free session structure"; - delete [] session->host; delete session; Alog(LOG_DEBUG_2) << "del_session() done"; @@ -216,46 +217,45 @@ void del_session(const char *host) void expire_exceptions() { - int i; time_t now = time(NULL); - for (i = 0; i < nexceptions; ++i) + for (std::vector<Exception *>::iterator it = exceptions.begin(), it_end = exceptions.end(); it != it_end; ) { - if (!exceptions[i].expires || exceptions[i].expires > now) + Exception *e = *it; + std::vector<Exception *>::iterator curr_it = it++; + + if (!e->expires || e->expires > now) continue; if (Config.WallExceptionExpire) - ircdproto->SendGlobops(OperServ, "Session limit exception for %s has expired.", exceptions[i].mask); - delete [] exceptions[i].mask; - delete [] exceptions[i].reason; - delete [] exceptions[i].who; - --nexceptions; - memmove(exceptions + i, exceptions + i + 1, sizeof(Exception) * (nexceptions - i)); - exceptions = static_cast<Exception *>(srealloc(exceptions, sizeof(Exception) * nexceptions)); - --i; + ircdproto->SendGlobops(OperServ, "Session limit exception for %s has expired.", e->mask.c_str()); + delete e; + exceptions.erase(curr_it); } } /* Find the first exception this host matches and return it. */ -Exception *find_host_exception(const char *host) +Exception *find_host_exception(const Anope::string &host) { - int i; - - for (i = 0; i < nexceptions; ++i) - if ((Anope::Match(host, exceptions[i].mask, false))) - return &exceptions[i]; + for (std::vector<Exception *>::const_iterator it = exceptions.begin(), it_end = exceptions.end(); it != it_end; ++it) + { + Exception *e = *it; + if (Anope::Match(host, e->mask)) + return e; + } return NULL; } /* Same as find_host_exception() except * this tries to find the exception by IP also. */ -Exception *find_hostip_exception(const char *host, const char *hostip) +Exception *find_hostip_exception(const Anope::string &host, const Anope::string &hostip) { - int i; - - for (i = 0; i < nexceptions; ++i) - if (Anope::Match(host, exceptions[i].mask, false) || ((ircd->nickip && hostip) && Anope::Match(hostip, exceptions[i].mask, false))) - return &exceptions[i]; + for (std::vector<Exception *>::const_iterator it = exceptions.begin(), it_end = exceptions.end(); it != it_end; ++it) + { + Exception *e = *it; + if (Anope::Match(host, e->mask) || (ircd->nickip && !hostip.empty() && Anope::Match(hostip, e->mask))) + return e; + } return NULL; } @@ -264,52 +264,47 @@ Exception *find_hostip_exception(const char *host, const char *hostip) /************************ Exception Manipulation *************************/ /*************************************************************************/ -int exception_add(User *u, const char *mask, const int limit, const char *reason, const char *who, const time_t expires) +int exception_add(User *u, const Anope::string &mask, int limit, const Anope::string &reason, const Anope::string &who, time_t expires) { - int i; - /* Check if an exception already exists for this mask */ - for (i = 0; i < nexceptions; ++i) + for (std::vector<Exception *>::iterator it = exceptions.begin(), it_end = exceptions.end(); it != it_end; ++it) { - if (!stricmp(mask, exceptions[i].mask)) + Exception *e = *it; + if (e->mask.equals_ci(mask)) { - if (exceptions[i].limit != limit) + if (e->limit != limit) { - exceptions[i].limit = limit; + e->limit = limit; if (u) - notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_CHANGED, mask, exceptions[i].limit); + notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_CHANGED, mask.c_str(), e->limit); return -2; } else { if (u) - notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_EXISTS, mask); + notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_EXISTS, mask.c_str()); return -1; } } } - nexceptions++; - exceptions = static_cast<Exception *>(srealloc(exceptions, sizeof(Exception) * nexceptions)); - - exceptions[nexceptions - 1].mask = sstrdup(mask); - exceptions[nexceptions - 1].limit = limit; - exceptions[nexceptions - 1].reason = sstrdup(reason); - exceptions[nexceptions - 1].time = time(NULL); - exceptions[nexceptions - 1].who = sstrdup(who); - exceptions[nexceptions - 1].expires = expires; - exceptions[nexceptions - 1].num = nexceptions - 1; + Exception *exception = new Exception(); + exception->mask = mask; + exception->limit = limit; + exception->reason = reason; + exception->time = time(NULL); + exception->who = who; + exception->expires = expires; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnExceptionAdd, OnExceptionAdd(u, &exceptions[nexceptions - 1])); + FOREACH_RESULT(I_OnExceptionAdd, OnExceptionAdd(u, exception)); if (MOD_RESULT == EVENT_STOP) { - delete [] exceptions[nexceptions - 1].mask; - delete [] exceptions[nexceptions - 1].reason; - --nexceptions; - exceptions = static_cast<Exception *>(srealloc(exceptions, sizeof(Exception) * nexceptions)); + delete exception; return -3; } + exceptions.push_back(exception); + return 1; } diff --git a/src/sockets.cpp b/src/sockets.cpp index 418b1b334..d72b2847d 100644 --- a/src/sockets.cpp +++ b/src/sockets.cpp @@ -24,9 +24,9 @@ Socket::Socket(int nsock, bool nIPv6) Type = SOCKTYPE_CLIENT; IPv6 = nIPv6; if (nsock == 0) - sock = socket(IPv6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0); + Sock = socket(IPv6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0); else - sock = nsock; + Sock = nsock; SocketEngine->AddSocket(this); } @@ -35,7 +35,7 @@ Socket::Socket(int nsock, bool nIPv6) Socket::~Socket() { SocketEngine->DelSocket(this); - CloseSocket(sock); + CloseSocket(Sock); } /** Really recieve something from the buffer @@ -52,7 +52,7 @@ const int Socket::RecvInternal(char *buf, size_t sz) const * @param buf What to write * @return Number of bytes written */ -const int Socket::SendInternal(const std::string &buf) const +const int Socket::SendInternal(const Anope::string &buf) const { return send(GetSock(), buf.c_str(), buf.length(), 0); } @@ -62,7 +62,7 @@ const int Socket::SendInternal(const std::string &buf) const */ int Socket::GetSock() const { - return sock; + return Sock; } /** Mark a socket as blockig @@ -122,8 +122,7 @@ size_t Socket::WriteBufferLen() const */ bool Socket::ProcessRead() { - char tbuffer[NET_BUFSIZE]; - memset(&tbuffer, '\0', sizeof(tbuffer)); + char tbuffer[NET_BUFSIZE] = ""; RecvLen = RecvInternal(tbuffer, sizeof(tbuffer) - 1); if (RecvLen <= 0) @@ -132,7 +131,7 @@ bool Socket::ProcessRead() std::string sbuffer = extrabuf; sbuffer.append(tbuffer); extrabuf.clear(); - size_t lastnewline = sbuffer.find_last_of('\n'); + size_t lastnewline = sbuffer.rfind('\n'); if (lastnewline == std::string::npos) { extrabuf = sbuffer; @@ -147,10 +146,12 @@ bool Socket::ProcessRead() sepstream stream(sbuffer, '\n'); - std::string tbuf; + Anope::string tbuf; while (stream.GetToken(tbuf)) { - TrimBuf(tbuf); + std::string tmp_tbuf = tbuf.str(); + TrimBuf(tmp_tbuf); + tbuf = tmp_tbuf; if (!tbuf.empty()) if (!Read(tbuf)) @@ -190,7 +191,7 @@ void Socket::ProcessError() * @param buf The line * @return true to continue reading, false to drop the socket */ -bool Socket::Read(const std::string &buf) +bool Socket::Read(const Anope::string &buf) { return false; } @@ -202,8 +203,7 @@ void Socket::Write(const char *message, ...) { va_list vi; char tbuffer[BUFSIZE]; - std::string sbuf; - + if (!message) return; @@ -211,16 +211,16 @@ void Socket::Write(const char *message, ...) vsnprintf(tbuffer, sizeof(tbuffer), message, vi); va_end(vi); - sbuf = tbuffer; + Anope::string sbuf = tbuffer; Write(sbuf); } /** Write to the socket * @param message The message */ -void Socket::Write(const std::string &message) +void Socket::Write(const Anope::string &message) { - WriteBuffer.append(message + "\r\n"); + WriteBuffer.append(message.str() + "\r\n"); SocketEngine->MarkWriteable(this); } @@ -230,11 +230,11 @@ void Socket::Write(const std::string &message) * @param nsock The socket * @param nIPv6 IPv6 */ -ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std::string &nBindHost, bool nIPv6) : Socket(0, nIPv6), TargetHost(nTargetHost), Port(nPort), BindHost(nBindHost) +ClientSocket::ClientSocket(const Anope::string &nTargetHost, int nPort, const Anope::string &nBindHost, bool nIPv6) : Socket(0, nIPv6), TargetHost(nTargetHost), Port(nPort), BindHost(nBindHost) { - if (!IPv6 && (TargetHost.find(':') != std::string::npos || BindHost.find(':') != std::string::npos)) + if (!IPv6 && (TargetHost.find(':') != Anope::string::npos || BindHost.find(':') != Anope::string::npos)) IPv6 = true; - + addrinfo hints; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = 0; @@ -247,7 +247,7 @@ ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std: sockaddr_in bindaddr; sockaddr_in6 bindaddr6; - if (getaddrinfo(BindHost.c_str(), NULL, &hints, &bindar) == 0) + if (!getaddrinfo(BindHost.c_str(), NULL, &hints, &bindar)) { if (IPv6) memcpy(&bindaddr6, bindar->ai_addr, bindar->ai_addrlen); @@ -263,26 +263,26 @@ ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std: bindaddr6.sin6_family = AF_INET6; if (inet_pton(AF_INET6, BindHost.c_str(), &bindaddr6.sin6_addr) < 1) - throw SocketException("Invalid bind host: " + std::string(strerror(errno))); + throw SocketException(Anope::string("Invalid bind host: ") + strerror(errno)); } else { bindaddr.sin_family = AF_INET; if (inet_pton(AF_INET, BindHost.c_str(), &bindaddr.sin_addr) < 1) - throw SocketException("Invalid bind host: " + std::string(strerror(errno))); + throw SocketException(Anope::string("Invalid bind host: ") + strerror(errno)); } } if (IPv6) { - if (bind(sock, reinterpret_cast<sockaddr *>(&bindaddr6), sizeof(bindaddr6)) == -1) - throw SocketException("Unable to bind to address: " + std::string(strerror(errno))); + if (bind(Sock, reinterpret_cast<sockaddr *>(&bindaddr6), sizeof(bindaddr6)) == -1) + throw SocketException(Anope::string("Unable to bind to address: ") + strerror(errno)); } else { - if (bind(sock, reinterpret_cast<sockaddr *>(&bindaddr), sizeof(bindaddr)) == -1) - throw SocketException("Unable to bind to address: " + std::string(strerror(errno))); + if (bind(Sock, reinterpret_cast<sockaddr *>(&bindaddr), sizeof(bindaddr)) == -1) + throw SocketException(Anope::string("Unable to bind to address: ") + strerror(errno)); } } @@ -290,7 +290,7 @@ ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std: sockaddr_in6 addr6; sockaddr_in addr; - if (getaddrinfo(TargetHost.c_str(), NULL, &hints, &conar) == 0) + if (!getaddrinfo(TargetHost.c_str(), NULL, &hints, &conar)) { if (IPv6) memcpy(&addr6, conar->ai_addr, conar->ai_addrlen); @@ -304,12 +304,12 @@ ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std: if (IPv6) { if (inet_pton(AF_INET6, TargetHost.c_str(), &addr6.sin6_addr) < 1) - throw SocketException("Invalid server host: " + std::string(strerror(errno))); + throw SocketException(Anope::string("Invalid server host: ") + strerror(errno)); } else { if (inet_pton(AF_INET, TargetHost.c_str(), &addr.sin_addr) < 1) - throw SocketException("Invalid server host: " + std::string(strerror(errno))); + throw SocketException(Anope::string("Invalid server host: ") + strerror(errno)); } } @@ -318,20 +318,16 @@ ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std: addr6.sin6_family = AF_INET6; addr6.sin6_port = htons(nPort); - if (connect(sock, reinterpret_cast<sockaddr *>(&addr6), sizeof(addr6)) == -1) - { - throw SocketException("Error connecting to server: " + std::string(strerror(errno))); - } + if (connect(Sock, reinterpret_cast<sockaddr *>(&addr6), sizeof(addr6)) == -1) + throw SocketException(Anope::string("Error connecting to server: ") + strerror(errno)); } else { addr.sin_family = AF_INET; addr.sin_port = htons(nPort); - if (connect(sock, reinterpret_cast<sockaddr *>(&addr), sizeof(addr)) == -1) - { - throw SocketException("Error connecting to server: " + std::string(strerror(errno))); - } + if (connect(Sock, reinterpret_cast<sockaddr *>(&addr), sizeof(addr)) == -1) + throw SocketException(Anope::string("Error connecting to server: ") + strerror(errno)); } this->SetNonBlocking(); @@ -347,7 +343,7 @@ ClientSocket::~ClientSocket() * @param buf The line * @return true to continue reading, false to drop the socket */ -bool ClientSocket::Read(const std::string &buf) +bool ClientSocket::Read(const Anope::string &buf) { return true; } @@ -356,7 +352,7 @@ bool ClientSocket::Read(const std::string &buf) * @param bind The IP to bind to * @param port The port to listen on */ -ListenSocket::ListenSocket(const std::string &bindip, int port) : Socket(0, (bindip.find(':') != std::string::npos ? true : false)) +ListenSocket::ListenSocket(const Anope::string &bindip, int port) : Socket(0, (bindip.find(':') != Anope::string::npos ? true : false)) { Type = SOCKTYPE_LISTEN; BindIP = bindip; @@ -364,16 +360,14 @@ ListenSocket::ListenSocket(const std::string &bindip, int port) : Socket(0, (bin sockaddr_in sock_addr; sockaddr_in6 sock_addr6; - + if (IPv6) { sock_addr6.sin6_family = AF_INET6; sock_addr6.sin6_port = htons(port); - + if (inet_pton(AF_INET6, bindip.c_str(), &sock_addr6.sin6_addr) < 1) - { - throw SocketException("Invalid bind host: " + std::string(strerror(errno))); - } + throw SocketException(Anope::string("Invalid bind host: ") + strerror(errno)); } else { @@ -381,30 +375,22 @@ ListenSocket::ListenSocket(const std::string &bindip, int port) : Socket(0, (bin sock_addr.sin_port = htons(port); if (inet_pton(AF_INET, bindip.c_str(), &sock_addr.sin_addr) < 1) - { - throw SocketException("Invalid bind host: " + std::string(strerror(errno))); - } + throw SocketException(Anope::string("Invalid bind host: ") + strerror(errno)); } if (IPv6) { - if (bind(sock, reinterpret_cast<sockaddr *>(&sock_addr6), sizeof(sock_addr6)) == -1) - { - throw SocketException("Unable to bind to address: " + std::string(strerror(errno))); - } + if (bind(Sock, reinterpret_cast<sockaddr *>(&sock_addr6), sizeof(sock_addr6)) == -1) + throw SocketException(Anope::string("Unable to bind to address: ") + strerror(errno)); } else { - if (bind(sock, reinterpret_cast<sockaddr *>(&sock_addr), sizeof(sock_addr)) == -1) - { - throw SocketException("Unable to bind to address: " + std::string(strerror(errno))); - } + if (bind(Sock, reinterpret_cast<sockaddr *>(&sock_addr), sizeof(sock_addr)) == -1) + throw SocketException(Anope::string("Unable to bind to address: ") + strerror(errno)); } - if (listen(sock, 5) == -1) - { - throw SocketException("Unable to listen: " + std::string(strerror(errno))); - } + if (listen(Sock, 5) == -1) + throw SocketException(Anope::string("Unable to listen: ") + strerror(errno)); this->SetNonBlocking(); } @@ -419,16 +405,14 @@ ListenSocket::~ListenSocket() */ bool ListenSocket::ProcessRead() { - int newsock = accept(sock, NULL, NULL); + int newsock = accept(Sock, NULL, NULL); #ifndef _WIN32 # define INVALID_SOCKET 0 #endif if (newsock > 0 && newsock != INVALID_SOCKET) - { return this->OnAccept(new Socket(newsock, IPv6)); - } return true; } @@ -445,9 +429,9 @@ bool ListenSocket::OnAccept(Socket *s) /** Get the bind IP for this socket * @return the bind ip */ -const std::string &ListenSocket::GetBindIP() const +const Anope::string &ListenSocket::GetBindIP() const { - return BindIP; + return BindIP; } /** Get the port this socket is bound to @@ -457,4 +441,3 @@ const int ListenSocket::GetPort() const { return Port; } - diff --git a/src/threadengines/threadengine_pthread.cpp b/src/threadengines/threadengine_pthread.cpp index a85af583e..f63cc066e 100644 --- a/src/threadengines/threadengine_pthread.cpp +++ b/src/threadengines/threadengine_pthread.cpp @@ -47,7 +47,7 @@ void ThreadEngine::Start(Thread *thread) if (pthread_create(&thread->Handle, &threadengine_attr, entry_point, thread)) { delete thread; - throw CoreException("Unable to create thread: " + std::string(strerror(errno))); + throw CoreException(Anope::string("Unable to create thread: ") + strerror(errno)); } } diff --git a/src/threadengines/threadengine_win32.cpp b/src/threadengines/threadengine_win32.cpp index 54db9529a..a07a75cce 100644 --- a/src/threadengines/threadengine_win32.cpp +++ b/src/threadengines/threadengine_win32.cpp @@ -43,7 +43,7 @@ void ThreadEngine::Start(Thread *thread) if (!thread->Handle) { delete thread; - throw CoreException("Unable to create thread: " + std::string(dlerror())); + throw CoreException(Anope::string("Unable to create thread: ") + dlerror()); } } diff --git a/src/timers.cpp b/src/timers.cpp index e4a2ef04b..df3f2d228 100644 --- a/src/timers.cpp +++ b/src/timers.cpp @@ -99,7 +99,7 @@ void TimerManager::DelTimer(Timer *T) */ void TimerManager::TickTimers(time_t ctime) { - while (Timers.size() && (ctime > Timers.front()->GetTimer())) + while (Timers.size() && ctime > Timers.front()->GetTimer()) { Timer *t = Timers.front(); @@ -119,5 +119,5 @@ void TimerManager::TickTimers(time_t ctime) */ bool TimerManager::TimerComparison(Timer *one, Timer *two) { - return (one->GetTimer() < two->GetTimer()); + return one->GetTimer() < two->GetTimer(); } diff --git a/src/tools/db-convert.h b/src/tools/db-convert.h index cf265c92f..b2e067f87 100644 --- a/src/tools/db-convert.h +++ b/src/tools/db-convert.h @@ -704,8 +704,6 @@ int delcore(NickCore *nc) nclists[HASH(nc->display)] = nc->next; delete [] nc->display; - if (nc->pass) - delete [] nc->pass; if (nc->email) delete [] nc->email; if (nc->greet) diff --git a/src/users.cpp b/src/users.cpp index 887929c76..6ccaf9bf0 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -26,15 +26,14 @@ time_t maxusertime; /*************************************************************************/ /*************************************************************************/ -User::User(const std::string &snick, const std::string &suid) +User::User(const Anope::string &snick, const Anope::string &suid) { if (snick.empty()) - throw "what the craq, empty nick passed to constructor"; + throw CoreException("what the craq, empty nick passed to constructor"); // XXX: we should also duplicate-check here. /* we used to do this by calloc, no more. */ - host = hostip = vhost = realname = NULL; server = NULL; nc = NULL; invalid_pw_count = timestamp = my_signon = invalid_pw_time = lastmemosend = lastnickreg = lastmail = 0; @@ -43,7 +42,7 @@ User::User(const std::string &snick, const std::string &suid) this->nick = snick; this->uid = suid; - UserListByNick[snick.c_str()] = this; + UserListByNick[snick] = this; if (!suid.empty()) UserListByUID[suid] = this; @@ -62,19 +61,19 @@ User::User(const std::string &snick, const std::string &suid) this->isSuperAdmin = 0; /* always set SuperAdmin to 0 for new users */ } -void User::SetNewNick(const std::string &newnick) +void User::SetNewNick(const Anope::string &newnick) { /* Sanity check to make sure we don't segfault */ if (newnick.empty()) - throw "User::SetNewNick() got a bad argument"; + throw CoreException("User::SetNewNick() got a bad argument"); Alog(LOG_DEBUG) << this->nick << " changed nick to " << newnick; - UserListByNick.erase(this->nick.c_str()); + UserListByNick.erase(this->nick); this->nick = newnick; - UserListByNick[this->nick.c_str()] = this; + UserListByNick[this->nick] = this; OnAccess = false; NickAlias *na = findnick(this->nick); @@ -82,14 +81,12 @@ void User::SetNewNick(const std::string &newnick) OnAccess = is_on_access(this, na->nc); } -void User::SetDisplayedHost(const std::string &shost) +void User::SetDisplayedHost(const Anope::string &shost) { if (shost.empty()) - throw "empty host? in MY services? it seems it's more likely than I thought."; + throw CoreException("empty host? in MY services? it seems it's more likely than I thought."); - if (this->vhost) - delete [] this->vhost; - this->vhost = sstrdup(shost.c_str()); + this->vhost = shost; Alog(LOG_DEBUG) << this->nick << " changed vhost to " << shost; @@ -99,9 +96,9 @@ void User::SetDisplayedHost(const std::string &shost) /** Get the displayed vhost of a user record. * @return The displayed vhost of the user, where ircd-supported, or the user's real host. */ -const std::string User::GetDisplayedHost() const +const Anope::string User::GetDisplayedHost() const { - if (ircd->vhost && this->vhost) + if (ircd->vhost && !this->vhost.empty()) return this->vhost; else if (this->HasMode(UMODE_CLOAK) && !this->GetCloakedHost().empty()) return this->GetCloakedHost(); @@ -112,7 +109,7 @@ const std::string User::GetDisplayedHost() const /** Update the cloaked host of a user * @param host The cloaked host */ -void User::SetCloakedHost(const std::string &newhost) +void User::SetCloakedHost(const Anope::string &newhost) { if (newhost.empty()) throw "empty host in User::SetCloakedHost"; @@ -127,17 +124,17 @@ void User::SetCloakedHost(const std::string &newhost) /** Get the cloaked host of a user * @return The cloaked host */ -const std::string &User::GetCloakedHost() const +const Anope::string &User::GetCloakedHost() const { return chost; } -const std::string &User::GetUID() const +const Anope::string &User::GetUID() const { return this->uid; } -void User::SetVIdent(const std::string &sident) +void User::SetVIdent(const Anope::string &sident) { this->vident = sident; @@ -146,7 +143,7 @@ void User::SetVIdent(const std::string &sident) this->UpdateHost(); } -const std::string &User::GetVIdent() const +const Anope::string &User::GetVIdent() const { if (this->HasMode(UMODE_CLOAK)) return this->vident; @@ -156,7 +153,7 @@ const std::string &User::GetVIdent() const return this->ident; } -void User::SetIdent(const std::string &sident) +void User::SetIdent(const Anope::string &sident) { this->ident = sident; @@ -165,34 +162,28 @@ void User::SetIdent(const std::string &sident) this->UpdateHost(); } -const std::string &User::GetIdent() const +const Anope::string &User::GetIdent() const { return this->ident; } -const std::string User::GetMask() +const Anope::string User::GetMask() { std::stringstream buf; buf << this->nick << "!" << this->ident << "@" << this->host; return buf.str(); } -void User::SetRealname(const std::string &srealname) +void User::SetRealname(const Anope::string &srealname) { if (srealname.empty()) - throw "realname empty in SetRealname"; + throw CoreException("realname empty in SetRealname"); - if (this->realname) - delete [] this->realname; - this->realname = sstrdup(srealname.c_str()); + this->realname = srealname; NickAlias *na = findnick(this->nick); if (na && (this->IsIdentified(true) || this->IsRecognized(true))) - { - if (na->last_realname) - delete [] na->last_realname; - na->last_realname = sstrdup(srealname.c_str()); - } + na->last_realname = srealname; Alog(LOG_DEBUG) << this->nick << " changed realname to " << srealname; } @@ -205,11 +196,9 @@ User::~User() if (Config.LogUsers) { - const char *srealname = normalizeBuffer(this->realname); + Anope::string srealname = normalizeBuffer(this->realname); Alog() << "LOGUSERS: " << this->GetMask() << (ircd->vhost ? " => " : " ") << (ircd->vhost ? this->GetDisplayedHost() : "") << " (" << srealname << ") left the network (" << this->server->GetName() << ")."; - - delete [] srealname; } FOREACH_MOD(I_OnUserLogoff, OnUserLogoff(this)); @@ -221,11 +210,11 @@ User::~User() while (!this->chans.empty()) this->chans.front()->chan->DeleteUser(this); - + if (Config.LimitSessions && !this->server->IsULined()) del_session(this->host); - UserListByNick.erase(this->nick.c_str()); + UserListByNick.erase(this->nick); if (!this->uid.empty()) UserListByUID.erase(this->uid); @@ -233,20 +222,10 @@ User::~User() if (na) na->OnCancel(this); - delete [] this->host; - - if (this->vhost) - delete [] this->vhost; - - if (this->realname) - delete [] this->realname; - if (this->hostip) - delete [] this->hostip; - Alog(LOG_DEBUG_2) << "User::~User() done"; } -void User::SendMessage(const std::string &source, const char *fmt, ...) +void User::SendMessage(const Anope::string &source, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -256,13 +235,13 @@ void User::SendMessage(const std::string &source, const char *fmt, ...) va_start(args, fmt); vsnprintf(buf, BUFSIZE - 1, fmt, args); - this->SendMessage(source, std::string(buf)); + this->SendMessage(source, Anope::string(buf)); va_end(args); } } -void User::SendMessage(const std::string &source, const std::string &msg) +void User::SendMessage(const Anope::string &source, const Anope::string &msg) { /* Send privmsg instead of notice if: * - UsePrivmsg is enabled @@ -270,9 +249,9 @@ void User::SendMessage(const std::string &source, const std::string &msg) * - The user is registered and has set /ns set msg on */ if (Config.UsePrivmsg && ((!this->nc && Config.NSDefFlags.HasFlag(NI_MSG)) || (this->nc && this->nc->HasFlag(NI_MSG)))) - ircdproto->SendPrivmsg(findbot(source), this->nick.c_str(), "%s", msg.c_str()); + ircdproto->SendPrivmsg(findbot(source), this->nick, "%s", msg.c_str()); else - ircdproto->SendNotice(findbot(source), this->nick.c_str(), "%s", msg.c_str()); + ircdproto->SendNotice(findbot(source), this->nick, "%s", msg.c_str()); } /** Collides a nick. @@ -338,17 +317,15 @@ void User::Collide(NickAlias *na) if (ircd->svsnick) { - std::string guestnick; + Anope::string guestnick; do { - char randbuf[17]; - snprintf(randbuf, sizeof(randbuf), "%d", getrandom16()); - guestnick = std::string(Config.NSGuestNickPrefix) + std::string(randbuf); + guestnick = Config.NSGuestNickPrefix + stringify(getrandom16()); } while (finduser(guestnick)); notice_lang(Config.s_NickServ, this, FORCENICKCHANGE_CHANGING, guestnick.c_str()); - ircdproto->SendForceNickChange(this, guestnick.c_str(), time(NULL)); + ircdproto->SendForceNickChange(this, guestnick, time(NULL)); } else kill_user(Config.s_NickServ, this->nick, "Services nickname-enforcer kill"); @@ -358,7 +335,7 @@ void User::Collide(NickAlias *na) * their svid matches the one stored in their nickcore * @param svid Services id */ -void User::CheckAuthenticationToken(const char *svid) +void User::CheckAuthenticationToken(const Anope::string &svid) { NickAlias *na; @@ -367,12 +344,9 @@ void User::CheckAuthenticationToken(const char *svid) char *c; if (na->nc && na->nc->GetExtArray("authenticationtoken", c)) { - if (svid && c && !strcmp(svid, c)) - { + if (!svid.empty() && c && svid.equals_cs(c)) /* Users authentication token matches so they should become identified */ this->Login(na->nc); - return; - } } } @@ -382,9 +356,9 @@ void User::CheckAuthenticationToken(const char *svid) /** Auto identify the user to the given accountname. * @param account Display nick of account */ -void User::AutoID(const std::string &account) +void User::AutoID(const Anope::string &account) { - NickCore *core = findcore(account.c_str()); + NickCore *core = findcore(account); if (core) { @@ -393,9 +367,7 @@ void User::AutoID(const std::string &account) NickAlias *na = findnick(this->nick); if (na && na->nc == core) { - if (na->last_realname) - delete [] na->last_realname; - na->last_realname = sstrdup(this->realname); + na->last_realname = this->realname; na->last_seen = time(NULL); this->SetMode(NickServ, UMODE_REGISTERED); this->UpdateHost(); @@ -433,7 +405,7 @@ void User::Logout() /** Get the account the user is logged in using * @reurn The account or NULL */ -NickCore *User::Account() const +NickCore *User::Account() { return nc; } @@ -442,7 +414,7 @@ NickCore *User::Account() const * @param CheckNick True to check if the user is identified to the nickname they are on too * @return true or false */ -const bool User::IsIdentified(bool CheckNick) const +bool User::IsIdentified(bool CheckNick) const { if (CheckNick && this->nc) { @@ -461,7 +433,7 @@ const bool User::IsIdentified(bool CheckNick) const * @param CheckSecure Only returns true if the user has secure off * @return true or false */ -const bool User::IsRecognized(bool CheckSecure) const +bool User::IsRecognized(bool CheckSecure) const { if (CheckSecure && OnAccess) { @@ -478,7 +450,7 @@ const bool User::IsRecognized(bool CheckSecure) const */ void User::UpdateHost() { - if (!this->host) + if (this->host.empty()) return; NickAlias *na = findnick(this->nick); @@ -488,11 +460,8 @@ void User::UpdateHost() if (na && (this->IsIdentified(true) || this->IsRecognized(true))) { - if (na->last_usermask) - delete [] na->last_usermask; - - std::string last_usermask = this->GetIdent() + "@" + this->GetDisplayedHost(); - na->last_usermask = sstrdup(last_usermask.c_str()); + Anope::string last_usermask = this->GetIdent() + "@" + this->GetDisplayedHost(); + na->last_usermask = last_usermask; } } @@ -500,7 +469,7 @@ void User::UpdateHost() * @param Name Mode name * @return true or false */ -const bool User::HasMode(UserModeName Name) const +bool User::HasMode(UserModeName Name) const { return modes.HasFlag(Name); } @@ -509,7 +478,7 @@ const bool User::HasMode(UserModeName Name) const * @param um The user mode * @param Param The param, if there is one */ -void User::SetModeInternal(UserMode *um, const std::string &Param) +void User::SetModeInternal(UserMode *um, const Anope::string &Param) { if (!um) return; @@ -530,7 +499,7 @@ void User::RemoveModeInternal(UserMode *um) return; modes.UnsetFlag(um->Name); - std::map<UserModeName, std::string>::iterator it = Params.find(um->Name); + std::map<UserModeName, Anope::string>::iterator it = Params.find(um->Name); if (it != Params.end()) Params.erase(it); @@ -542,7 +511,7 @@ void User::RemoveModeInternal(UserMode *um) * @param um The user mode * @param Param Optional param for the mode */ -void User::SetMode(BotInfo *bi, UserMode *um, const std::string &Param) +void User::SetMode(BotInfo *bi, UserMode *um, const Anope::string &Param) { if (!um || HasMode(um->Name)) return; @@ -556,7 +525,7 @@ void User::SetMode(BotInfo *bi, UserMode *um, const std::string &Param) * @param Name The mode name * @param param Optional param for the mode */ -void User::SetMode(BotInfo *bi, UserModeName Name, const std::string &Param) +void User::SetMode(BotInfo *bi, UserModeName Name, const Anope::string &Param) { SetMode(bi, ModeManager::FindUserModeByName(Name), Param); } @@ -566,7 +535,7 @@ void User::SetMode(BotInfo *bi, UserModeName Name, const std::string &Param) * @param ModeChar The mode char * @param param Optional param for the mode */ -void User::SetMode(BotInfo *bi, char ModeChar, const std::string &Param) +void User::SetMode(BotInfo *bi, char ModeChar, const Anope::string &Param) { SetMode(bi, ModeManager::FindUserModeByChar(ModeChar), Param); } @@ -610,7 +579,7 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...) { char buf[BUFSIZE] = ""; va_list args; - std::string modebuf, sbuf; + Anope::string modebuf, sbuf; int add = -1; va_start(args, umodes); vsnprintf(buf, BUFSIZE - 1, umodes, args); @@ -618,7 +587,7 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...) spacesepstream sep(buf); sep.GetToken(modebuf); - for (unsigned i = 0, end = modebuf.size(); i < end; ++i) + for (unsigned i = 0, end = modebuf.length(); i < end; ++i) { UserMode *um; @@ -687,15 +656,15 @@ void get_user_stats(long *nusers, long *memuse) count++; mem += sizeof(*user); - if (user->host) - mem += strlen(user->host) + 1; + if (!user->host.empty()) + mem += user->host.length() + 1; if (ircd->vhost) { - if (user->vhost) - mem += strlen(user->vhost) + 1; + if (!user->vhost.empty()) + mem += user->vhost.length() + 1; } - if (user->realname) - mem += strlen(user->realname) + 1; + if (!user->realname.empty()) + mem += user->realname.length() + 1; mem += user->server->GetName().length() + 1; mem += (sizeof(ChannelContainer) * user->chans.size()); } @@ -703,21 +672,11 @@ void get_user_stats(long *nusers, long *memuse) *memuse = mem; } -User *finduser(const char *nick) -{ - return finduser(ci::string(nick)); -} - -User *finduser(const std::string &nick) -{ - return finduser(ci::string(nick.c_str())); -} - -User *finduser(const ci::string &nick) +User *finduser(const Anope::string &nick) { if (isdigit(nick[0]) && ircd->ts6) { - user_uid_map::const_iterator it = UserListByUID.find(nick.c_str()); + user_uid_map::const_iterator it = UserListByUID.find(nick); if (it != UserListByUID.end()) return it->second; @@ -735,22 +694,23 @@ User *finduser(const ci::string &nick) /* Handle a server NICK command. */ -User *do_nick(const char *source, const char *nick, const char *username, const char *host, const char *server, const char *realname, time_t ts, uint32 ip, const char *vhost, const char *uid) +User *do_nick(const Anope::string &source, const Anope::string &nick, const Anope::string &username, const Anope::string &host, const Anope::string &server, const Anope::string &realname, time_t ts, uint32 ip, const Anope::string &vhost, const Anope::string &uid) { User *user = NULL; + Anope::string vhost2 = vhost; - if (!*source) + if (source.empty()) { char ipbuf[16]; struct in_addr addr; if (ircd->nickvhost) { - if (vhost) + if (!vhost2.empty()) { - if (!strcmp(vhost, "*")) + if (vhost2.equals_cs("*")) { - vhost = NULL; + vhost2.clear(); Alog(LOG_DEBUG) << "new user with no vhost in NICK command: " << nick; } } @@ -772,42 +732,39 @@ User *do_nick(const char *source, const char *nick, const char *username, const /** * Ugly swap routine for Flop's bug :) XXX **/ - if (realname) + Anope::string logrealname = realname; + if (!logrealname.empty()) { - char *tmp = const_cast<char *>(strchr(realname, '%')); - while (tmp) - { - *tmp = '-'; - tmp = const_cast<char *>(strchr(realname, '%')); - } + size_t tmp; + while ((tmp = logrealname.find('%')) != Anope::string::npos) + logrealname[tmp] = '-'; } - const char *logrealname = normalizeBuffer(realname); + logrealname = normalizeBuffer(logrealname); /** * End of ugly swap **/ - Alog() << "LOGUSERS: " << nick << " (" << username << "@" << host << (ircd->nickvhost && vhost ? " => " : "") << (ircd->nickvhost && vhost ? vhost : "") << ") (" << logrealname << ") " + Alog() << "LOGUSERS: " << nick << " (" << username << "@" << host << (ircd->nickvhost && !vhost2.empty() ? " => " : "") << (ircd->nickvhost && !vhost2.empty() ? vhost2 : "") << ") (" << logrealname << ") " << (ircd->nickip ? "[" : "") << (ircd->nickip ? ipbuf : "") << (ircd->nickip ? "]" : "") << " connected to the network (" << serv->GetName() << ")."; - delete [] logrealname; } /* Allocate User structure and fill it in. */ - user = new User(nick, uid ? uid : ""); + user = new User(nick, !uid.empty() ? uid : ""); user->SetIdent(username); - user->host = sstrdup(host); + user->host = host; user->server = serv; - user->realname = sstrdup(realname); + user->realname = realname; user->timestamp = ts; user->my_signon = time(NULL); - if (vhost) - user->SetCloakedHost(vhost); + if (!vhost2.empty()) + user->SetCloakedHost(vhost2); user->SetVIdent(username); /* We now store the user's ip in the user_ struct, * because we will use it in serveral places -- DrStein */ if (ircd->nickip) - user->hostip = sstrdup(ipbuf); + user->hostip = ipbuf; else - user->hostip = NULL; + user->hostip = ""; EventReturn MOD_RESULT; FOREACH_RESULT(I_OnPreUserConnect, OnPreUserConnect(user)); @@ -840,16 +797,14 @@ User *do_nick(const char *source, const char *nick, const char *username, const if (Config.LogUsers) { - const char *logrealname = normalizeBuffer(user->realname); - Alog() << "LOGUSERS: " << user->nick << " (" << user->GetIdent() << "@" << user->host << (ircd->vhost ? " => " : "") << (ircd->vhost ? user->GetDisplayedHost() : "") << ") (" - << logrealname << ") " << "changed nick to " << nick << " (" << user->server->GetName() << ")."; - if (logrealname) - delete [] logrealname; + Anope::string logrealname = normalizeBuffer(user->realname); + Alog() << "LOGUSERS: " << user->nick << " (" << user->GetIdent() << "@" << user->host << (ircd->vhost ? " => " : "") << (ircd->vhost ? user->GetDisplayedHost() : "") << ") (" << logrealname << ") changed nick to " + << nick << " (" << user->server->GetName() << ")."; } user->timestamp = ts; - if (!stricmp(nick, user->nick.c_str())) + if (user->nick.equals_ci(nick)) /* No need to redo things */ user->SetNewNick(nick); else @@ -861,7 +816,7 @@ User *do_nick(const char *source, const char *nick, const char *username, const if (old_na && (old_na->nc == user->Account() || user->IsRecognized())) old_na->last_seen = time(NULL); - std::string oldnick = user->nick; + Anope::string oldnick = user->nick; user->SetNewNick(nick); FOREACH_MOD(I_OnUserNickChange, OnUserNickChange(user, oldnick)); @@ -903,7 +858,7 @@ User *do_nick(const char *source, const char *nick, const char *username, const * av[1] = modes */ -void do_umode(const char *source, int ac, const char **av) +void do_umode(const Anope::string &source, int ac, const char **av) { User *user; @@ -923,7 +878,7 @@ void do_umode(const char *source, int ac, const char **av) * av[0] = reason */ -void do_quit(const char *source, int ac, const char **av) +void do_quit(const Anope::string &source, int ac, const char **av) { User *user; NickAlias *na; @@ -938,9 +893,7 @@ void do_quit(const char *source, int ac, const char **av) if ((na = findnick(user->nick)) && !na->HasFlag(NS_FORBIDDEN) && !na->nc->HasFlag(NI_SUSPENDED) && (user->IsRecognized() || user->IsIdentified(true))) { na->last_seen = time(NULL); - if (na->last_quit) - delete [] na->last_quit; - na->last_quit = *av[0] ? sstrdup(av[0]) : NULL; + na->last_quit = *av[0] ? av[0] : ""; } FOREACH_MOD(I_OnUserQuit, OnUserQuit(user, *av[0] ? av[0] : "")); delete user; @@ -953,7 +906,7 @@ void do_quit(const char *source, int ac, const char **av) * av[1] = reason */ -void do_kill(const std::string &nick, const std::string &msg) +void do_kill(const Anope::string &nick, const Anope::string &msg) { User *user; NickAlias *na; @@ -968,9 +921,7 @@ void do_kill(const std::string &nick, const std::string &msg) if ((na = findnick(user->nick)) && !na->HasFlag(NS_FORBIDDEN) && !na->nc->HasFlag(NI_SUSPENDED) && (user->IsRecognized() || user->IsIdentified(true))) { na->last_seen = time(NULL); - if (na->last_quit) - delete [] na->last_quit; - na->last_quit = !msg.empty() ? sstrdup(msg.c_str()) : NULL; + na->last_quit = msg; } delete user; } @@ -980,7 +931,7 @@ void do_kill(const std::string &nick, const std::string &msg) /* Is the given nick an oper? */ -int is_oper(User * user) +int is_oper(User *user) { if (user && user->HasMode(UMODE_OPER)) return 1; @@ -992,7 +943,7 @@ int is_oper(User * user) /*************************************************************************/ /* Is the given user ban-excepted? */ -int is_excepted(ChannelInfo * ci, User * user) +int is_excepted(ChannelInfo *ci, User *user) { if (!ci->c || !ModeManager::FindChannelModeByName(CMODE_EXCEPT)) return 0; @@ -1006,7 +957,7 @@ int is_excepted(ChannelInfo * ci, User * user) /*************************************************************************/ /* Is the given MASK ban-excepted? */ -int is_excepted_mask(ChannelInfo * ci, const char *mask) +int is_excepted_mask(ChannelInfo *ci, const Anope::string &mask) { if (!ci->c || !ModeManager::FindChannelModeByName(CMODE_EXCEPT)) return 0; @@ -1023,40 +974,34 @@ int is_excepted_mask(ChannelInfo * ci, const char *mask) * just user@host)? */ -int match_usermask(const char *mask, User * user) +int match_usermask(const Anope::string &mask, User *user) { - char *mask2; - char *nick, *username, *host; int result; - if (!mask || !*mask) + if (mask.empty()) return 0; - mask2 = sstrdup(mask); - - if (strchr(mask2, '!')) + Anope::string mask2 = mask, nick, username, host; + size_t ex = mask2.find('!'); + if (ex != Anope::string::npos) { - nick = strtok(mask2, "!"); - username = strtok(NULL, "@"); + nick = mask2.substr(0, ex); + mask2 = mask2.substr(ex + 1); } - else + size_t at = mask2.find('@'); + if (at != Anope::string::npos) { - nick = NULL; - username = strtok(mask2, "@"); + username = mask2.substr(0, at); + host = mask2.substr(at + 1); } - host = strtok(NULL, ""); - if (!username || !host) - { - delete [] mask2; + if (username.empty() || host.empty()) return 0; - } - if (nick) - result = Anope::Match(user->nick, nick, false) && Anope::Match(user->GetIdent().c_str(), username, false) && (Anope::Match(user->host, host, false) || Anope::Match(user->GetDisplayedHost().c_str(), host, false)); + if (!nick.empty()) + result = Anope::Match(user->nick, nick) && Anope::Match(user->GetIdent(), username) && (Anope::Match(user->host, host) || Anope::Match(user->GetDisplayedHost(), host)); else - result = Anope::Match(user->GetIdent().c_str(), username, false) && (Anope::Match(user->host, host, false) || Anope::Match(user->GetDisplayedHost().c_str(), host, false)); + result = Anope::Match(user->GetIdent(), username) && (Anope::Match(user->host, host) || Anope::Match(user->GetDisplayedHost(), host)); - delete [] mask2; return result; } @@ -1067,49 +1012,37 @@ int match_usermask(const char *mask, User * user) * 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. The returned character string is malloc'd and should be free'd - * when done with. + * it. */ -char *create_mask(User *u) +Anope::string create_mask(User *u) { - char *mask, *s, *end; - std::string mident = u->GetIdent(); - std::string mhost = u->GetDisplayedHost(); - int ulen = mident.length(); + Anope::string mask; + Anope::string mident = u->GetIdent(); + Anope::string mhost = u->GetDisplayedHost(); /* Get us a buffer the size of the username plus hostname. The result * will never be longer than this (and will often be shorter), thus we * can use strcpy() and sprintf() safely. */ - end = mask = new char[ulen + mhost.length() + 3]; if (mident[0] == '~') - end += sprintf(end, "*%s@", mident.c_str()); + mask = "*" + mident + "@"; else - end += sprintf(end, "%s@", mident.c_str()); + mask = mident + "@"; - // XXX: someone needs to rewrite this godawful kitten murdering pile of crap. - if (strspn(mhost.c_str(), "0123456789.") == mhost.length() - && (s = strchr(const_cast<char *>(mhost.c_str()), '.')) // XXX - Potentially unsafe cast - && (s = strchr(s + 1, '.')) && (s = strchr(s + 1, '.')) && (!strchr(s + 1, '.'))) + size_t dot; + /* To make sure this is an IP, make sure the host contains only numbers and dots, and check to make sure it only contains 3 dots */ + if (mhost.find_first_not_of("0123456789.") == Anope::string::npos && (dot = mhost.find('.')) != Anope::string::npos && (dot = mhost.find('.', dot + 1)) != Anope::string::npos && (dot = mhost.find('.', dot + 1)) != Anope::string::npos && mhost.find('.', dot + 1) == Anope::string::npos) { /* IP addr */ - s = sstrdup(mhost.c_str()); - *strrchr(s, '.') = 0; - - sprintf(end, "%s.*", s); - delete [] s; + dot = mhost.find('.'); + mask += mhost.substr(0, dot) + ".*"; } else { - if ((s = strchr(const_cast<char *>(mhost.c_str()), '.')) && strchr(s + 1, '.')) - { - s = sstrdup(strchr(mhost.c_str(), '.') - 1); - *s = '*'; - strcpy(end, s); - delete [] s; - } + if ((dot = mhost.find('.')) != Anope::string::npos && mhost.find('.', dot + 1) != Anope::string::npos) + mask += "*" + mhost.substr(dot); else - strcpy(end, mhost.c_str()); + mask += mhost; } return mask; } @@ -1183,11 +1116,8 @@ void UserSetInternalModes(User *user, int ac, const char **av) break; case UMODE_CLOAK: case UMODE_VHOST: - if (!add && user->vhost) - { - delete [] user->vhost; - user->vhost = NULL; - } + if (!add && !user->vhost.empty()) + user->vhost.clear(); user->UpdateHost(); default: break; diff --git a/src/wildcard.cpp b/src/wildcard.cpp index 42f0812f7..1716068d1 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -2,9 +2,9 @@ static bool match_internal(const unsigned char *str, const unsigned char *mask, bool case_sensitive) { - unsigned char *cp = NULL, *mp = NULL; - unsigned char *string = const_cast<unsigned char *>(str); // XXX: unsafe cast - unsigned char *wild = const_cast<unsigned char *>(mask); // XXX: unsafe cast + const unsigned char *cp = NULL, *mp = NULL; + const unsigned char *string = str; + const unsigned char *wild = mask; while (*string && *wild != '*') { @@ -19,8 +19,8 @@ static bool match_internal(const unsigned char *str, const unsigned char *mask, return false; } - wild++; - string++; + ++wild; + ++string; } while (*string) @@ -71,7 +71,7 @@ static bool match_internal(const unsigned char *str, const unsigned char *mask, return !*wild; } -bool Anope::Match(const std::string &str, const std::string &mask, bool case_sensitive) +bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case_sensitive) { return match_internal(reinterpret_cast<const unsigned char *>(str.c_str()), reinterpret_cast<const unsigned char *>(mask.c_str()), case_sensitive); } diff --git a/src/win32/windows.cpp b/src/win32/windows.cpp index 6568e860e..9ea3dad09 100644 --- a/src/win32/windows.cpp +++ b/src/win32/windows.cpp @@ -47,7 +47,7 @@ int inet_pton(int af, const char *src, void *dst) return -1; } - if (!WSAStringToAddress((LPSTR) src, af, NULL, reinterpret_cast<LPSOCKADDR>(&sa), &address_length)) + if (!WSAStringToAddress(static_cast<LPSTR>(const_cast<char *>(src)), af, NULL, reinterpret_cast<LPSOCKADDR>(&sa), &address_length)) { switch (af) { |