summaryrefslogtreecommitdiff
path: root/include/anope.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/anope.h')
-rw-r--r--include/anope.h199
1 files changed, 152 insertions, 47 deletions
diff --git a/include/anope.h b/include/anope.h
index 18367a623..0b22584ef 100644
--- a/include/anope.h
+++ b/include/anope.h
@@ -1,16 +1,23 @@
/*
+ * Anope IRC Services
*
- * (C) 2003-2017 Anope Team
- * Contact us at team@anope.org
+ * Copyright (C) 2012-2017 Anope Team <team@anope.org>
*
- * Please read COPYING and README for further details.
+ * This file is part of Anope. Anope is free software; you can
+ * redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software
+ * Foundation, version 2.
*
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
-#ifndef ANOPE_H
-#define ANOPE_H
+#pragma once
#include <signal.h>
@@ -140,6 +147,9 @@ namespace Anope
*/
inline void push_back(char c) { return this->_string.push_back(c); }
+ inline string& insert(const_iterator p, char c) { this->_string.insert(p, c); return *this; }
+ inline string& insert(size_t pos, const string& str) { this->_string.insert(pos, str._string); return *this; }
+
inline string& append(const string &s) { this->_string.append(s.str()); return *this; }
inline string& append(const char *s, size_t n) { this->_string.append(s, n); return *this; }
@@ -308,36 +318,45 @@ namespace Anope
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; }
+ struct hash
+ {
+ size_t operator()(const string &s) const;
+ };
+
+ struct compare
+ {
+ bool operator()(const string &s1, const string &s2) const;
+ };
+
struct hash_ci
{
- inline size_t operator()(const string &s) const
- {
- return TR1NS::hash<std::string>()(s.lower().str());
- }
+ size_t operator()(const string &s) const;
};
- struct hash_cs
+ struct compare_ci
{
- inline size_t operator()(const string &s) const
- {
- return TR1NS::hash<std::string>()(s.str());
- }
+ bool operator()(const string &s1, const string &s2) const;
};
- struct compare
+ struct hash_locale
{
- inline bool operator()(const string &s1, const string &s2) const
- {
- return s1.equals_ci(s2);
- }
+ size_t operator()(const string &s) const;
+ };
+
+ struct compare_locale
+ {
+ bool operator()(const string &s1, const string &s2) const;
};
- template<typename T> class map : public std::map<string, T, ci::less> { };
- template<typename T> class multimap : public std::multimap<string, T, ci::less> { };
- template<typename T> class hash_map : public TR1NS::unordered_map<string, T, hash_ci, compare> { };
+ extern Anope::string transform(const Anope::string &);
+
+ template<typename T> using map = std::map<string, T, ci::less>;
+ template<typename T> using multimap = std::multimap<string, T, ci::less>;
+ template<typename T> using hash_map = std::unordered_map<string, T, hash_ci, compare_ci>;
+ template<typename T> using locale_hash_map = std::unordered_map<string, T, hash_locale, compare_locale>;
#ifndef REPRODUCIBLE_BUILD
- static const char *const compiled = __TIME__ " " __DATE__;
+ static const char *const COMPILED = __DATE__ " " __TIME__;
#endif
/** The time Anope started.
@@ -366,7 +385,7 @@ namespace Anope
*/
extern CoreExport bool ReadOnly, NoFork, NoThird, NoExpire, ProtocolDebug;
- /** The root of the services installation. Usually ~/services
+ /** The root of the services installation. Usually ~/anope
*/
extern CoreExport Anope::string ServicesDir;
@@ -390,7 +409,8 @@ namespace Anope
*/
extern CoreExport string Version();
extern CoreExport string VersionShort();
- extern CoreExport string VersionBuildString();
+ extern CoreExport string VersionBuildTime();
+ extern CoreExport string VersionFlags();
extern CoreExport int VersionMajor();
extern CoreExport int VersionMinor();
extern CoreExport int VersionPatch();
@@ -418,10 +438,6 @@ namespace Anope
*/
extern void Init(int ac, char **av);
- /** Calls the save database event
- */
- extern CoreExport void SaveDatabases();
-
/** Check whether two strings match.
* @param str The string to check against the pattern (e.g. foobar)
* @param mask The pattern to check (e.g. foo*bar)
@@ -443,13 +459,13 @@ namespace Anope
*/
extern CoreExport void Unhex(const string &src, string &dest);
extern CoreExport void Unhex(const string &src, char *dest, size_t sz);
-
+
/** Base 64 encode a string
* @param src The string to encode
* @param target Where the encoded string is placed
*/
extern CoreExport void B64Encode(const string &src, string &target);
-
+
/** Base 64 decode a string
* @param src The base64 encoded string
* @param target The plain text result
@@ -462,14 +478,6 @@ namespace Anope
*/
extern CoreExport void Encrypt(const Anope::string &src, Anope::string &dest);
- /** Decrypts what is in 'src' to 'dest'.
- * @param src The source string to decrypt
- * @param dest The destination where the decrypted string is placed
- * @return true if decryption was successful. This is usually not the case
- * as most encryption methods we use are one way.
- */
- extern CoreExport bool Decrypt(const Anope::string &src, Anope::string &dest);
-
/** Returns a sequence of data formatted as the format argument specifies.
** After the format parameter, the function expects at least as many
** additional arguments as specified in format.
@@ -504,21 +512,21 @@ namespace Anope
* @param nc The account to use language settings for to translate this string, if applicable
* @return A human readable string, eg "1 minute"
*/
- extern CoreExport Anope::string Duration(time_t seconds, const NickCore *nc = NULL);
+ extern CoreExport Anope::string Duration(time_t seconds, NickServ::Account *nc = NULL);
/** Generates a human readable string of type "expires in ..."
* @param expires time in seconds
* @param nc The account to use language settings for to translate this string, if applicable
* @return A human readable string, eg "expires in 5 days"
*/
- extern CoreExport Anope::string Expires(time_t seconds, const NickCore *nc = NULL);
+ extern CoreExport Anope::string Expires(time_t seconds, NickServ::Account *nc = NULL);
/** Converts a time in seconds (epoch) to a human readable format.
* @param t The time
* @param nc The account to use language settings for to translate this string, if applicable
* @param short_output If true, the output is just a date (eg, "Apr 12 20:18:22 2009 MSD"), else it includes the date and how long ago/from now that date is, (eg "Apr 12 20:18:22 2009 MSD (1313 days, 9 hours, 32 minutes ago)"
*/
- extern CoreExport Anope::string strftime(time_t t, const NickCore *nc = NULL, bool short_output = false);
+ extern CoreExport Anope::string strftime(time_t t, NickServ::Account *nc = NULL, bool short_output = false);
/** Normalize buffer, stripping control characters and colors
* @param A string to be parsed for control and color codes
@@ -530,6 +538,7 @@ namespace Anope
* @param Raw message from the uplink
*/
extern void Process(const Anope::string &);
+ extern void ProcessCommand(MessageSource &source, const Anope::string &command, const std::vector<Anope::string> &params);
/** Does a blocking dns query and returns the first IP.
* @param host host to look up
@@ -542,6 +551,8 @@ namespace Anope
* @param len The length of the string returned
*/
extern CoreExport Anope::string Random(size_t len);
+
+ extern Logger Logger;
}
/** sepstream allows for splitting token separated lists.
@@ -633,7 +644,7 @@ class spacesepstream : public sepstream
public:
/** Initialize with space seperator
*/
- spacesepstream(const Anope::string &source) : sepstream(source, ' ') { }
+ spacesepstream(const Anope::string &source, bool allowempty = false) : sepstream(source, ' ', allowempty) { }
};
/** This class can be used on its own to represent an exception, or derived to represent a module-specific exception.
@@ -706,9 +717,26 @@ class ConvertException : public CoreException
virtual ~ConvertException() throw() { }
};
+template<typename T>
+typename std::enable_if<std::is_enum<T>::value, std::ostream &>::type
+operator<<(std::ostream &os, T t)
+{
+ // XXX
+ return os;
+}
+
+template<typename T>
+typename std::enable_if<std::is_enum<T>::value, std::istream &>::type
+operator>>(std::istream &is, T& t)
+{
+ // XXX
+ return is;
+}
+
/** Convert something to a string
*/
-template<typename T> inline Anope::string stringify(const T &x)
+template<typename T>
+inline Anope::string stringify(const T &x)
{
std::ostringstream stream;
@@ -718,6 +746,12 @@ template<typename T> inline Anope::string stringify(const T &x)
return stream.str();
}
+template<>
+inline Anope::string stringify(const Anope::string &str)
+{
+ return str;
+}
+
template<typename T> inline void convert(const Anope::string &s, T &x, Anope::string &leftover, bool failIfLeftoverChars = true)
{
leftover.clear();
@@ -778,4 +812,75 @@ template<typename T, typename O> inline T anope_dynamic_static_cast(O ptr)
}
#endif
-#endif // ANOPE_H
+struct kwarg
+{
+ Anope::string name, value;
+
+ template<typename T>
+ kwarg& operator=(const T& rhs)
+ {
+ value = stringify(rhs);
+ return *this;
+ }
+};
+
+inline kwarg operator"" _kw(const char *literal, size_t n)
+{
+ return { literal };
+}
+
+class FormatInfo
+{
+ Anope::string format;
+ std::vector<kwarg> parameters;
+ unsigned int pos = 0;
+
+ public:
+ FormatInfo(const Anope::string &fmt, size_t size) : format(fmt), parameters(size) { }
+
+ template<typename T>
+ void Add(const T& arg)
+ {
+ kwarg k = kwarg{ stringify(pos), stringify(arg) };
+ Add(k);
+ }
+
+ void AddArgs() { }
+
+ template<typename Arg, typename... Args>
+ void AddArgs(Arg &&arg, Args&&... args)
+ {
+ Add(arg);
+ AddArgs(std::forward<Args>(args)...);
+ }
+
+ const kwarg *GetKwarg(const Anope::string &name) const;
+
+ void Format();
+
+ const Anope::string &GetFormat() const;
+};
+
+template<>
+inline void FormatInfo::Add(const kwarg &arg)
+{
+ unsigned int p = pos++;
+
+ if (p >= parameters.size())
+ parameters.resize(p + 1);
+
+ parameters[p] = arg;
+}
+
+namespace Anope
+{
+ template<typename... Args>
+ inline Anope::string Format(const Anope::string &format, Args&&... args)
+ {
+ FormatInfo fi(format, sizeof...(Args));
+ fi.AddArgs(std::forward<Args>(args)...);
+ fi.Format();
+ return fi.GetFormat();
+ }
+}
+