diff options
author | Adam <Adam@anope.org> | 2010-07-15 22:55:02 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-07-15 22:55:02 -0400 |
commit | a22f8d3b2de88b9bb6f80f0c2780846ae23ab389 (patch) | |
tree | a2fdf570868896a787df8a1169951b0028e68d6b /modules/extra/mysql/db_mysql.h | |
parent | 43b1e43afb85639485e36d24da351dc0f121be6e (diff) |
Moved some files and diretories around, made cmake skip files it knows it can't compile because of missing dependices.
Diffstat (limited to 'modules/extra/mysql/db_mysql.h')
-rw-r--r-- | modules/extra/mysql/db_mysql.h | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/modules/extra/mysql/db_mysql.h b/modules/extra/mysql/db_mysql.h new file mode 100644 index 000000000..32a2469c9 --- /dev/null +++ b/modules/extra/mysql/db_mysql.h @@ -0,0 +1,211 @@ +#ifndef DB_MYSQL_H +#define DB_MYSQL_H + +#include "module.h" + +struct NickAliasFlagInfo +{ + std::string Name; + NickNameFlag Flag; +}; + +NickAliasFlagInfo NickAliasFlags[] = { + {"FORBIDDEN", NS_FORBIDDEN}, + {"NOEXPIRE", NS_NO_EXPIRE}, + {"", static_cast<NickNameFlag>(-1)} +}; + +struct NickCoreFlagInfo +{ + std::string Name; + NickCoreFlag Flag; +}; + +NickCoreFlagInfo NickCoreFlags[] = { + {"KILLPROTECT", NI_KILLPROTECT}, + {"SECURE", NI_SECURE}, + {"MSG", NI_MSG}, + {"MEMO_HARDMAX", NI_MEMO_HARDMAX}, + {"MEMO_SIGNON", NI_MEMO_SIGNON}, + {"MEMO_RECEIVE", NI_MEMO_RECEIVE}, + {"PRIVATE", NI_PRIVATE}, + {"HIDE_EMAIL", NI_HIDE_EMAIL}, + {"HIDE_MASK", NI_HIDE_MASK}, + {"HIDE_QUIT", NI_HIDE_QUIT}, + {"KILL_QUICK", NI_KILL_QUICK}, + {"KILL_IMMED", NI_KILL_IMMED}, + {"MEMO_MAIL", NI_MEMO_MAIL}, + {"HIDE_STATUS", NI_HIDE_STATUS}, + {"SUSPENDED", NI_SUSPENDED}, + {"AUTOOP", NI_AUTOOP}, + {"FORBIDDEN", NI_FORBIDDEN}, + {"", static_cast<NickCoreFlag>(-1)} +}; + +struct BotFlagInfo +{ + std::string Name; + BotServFlag Flag; +}; + +BotFlagInfo BotFlags[] = { + {"DONTKICKOPS", BS_DONTKICKOPS}, + {"DONTKICKVOICES", BS_DONTKICKVOICES}, + {"FANTASY", BS_FANTASY}, + {"SYMBIOSIS", BS_SYMBIOSIS}, + {"GREET", BS_GREET}, + {"NOBOT", BS_NOBOT}, + {"KICK_BOLDS", BS_KICK_BOLDS}, + {"KICK_COLORS", BS_KICK_COLORS}, + {"KICK_REVERSES", BS_KICK_REVERSES}, + {"KICK_UNDERLINES", BS_KICK_UNDERLINES}, + {"KICK_BADWORDS", BS_KICK_BADWORDS}, + {"KICK_CAPS", BS_KICK_CAPS}, + {"KICK_FLOOD", BS_KICK_FLOOD}, + {"KICK_REPEAT", BS_KICK_REPEAT}, + {"", static_cast<BotServFlag>(-1)} +}; + +struct ChannelFlagInfo +{ + std::string Name; + ChannelInfoFlag Flag; +}; + +ChannelFlagInfo ChannelFlags[] = { + {"KEEPTOPIC", CI_KEEPTOPIC}, + {"SECUREOPS", CI_SECUREOPS}, + {"PRIVATE", CI_PRIVATE}, + {"TOPICLOCK", CI_TOPICLOCK}, + {"RESTRICTED", CI_RESTRICTED}, + {"PEACE", CI_PEACE}, + {"SECURE", CI_SECURE}, + {"FORBIDDEN", CI_FORBIDDEN}, + {"NO_EXPIRE", CI_NO_EXPIRE}, + {"MEMO_HARDMAX", CI_MEMO_HARDMAX}, + {"OPNOTICE", CI_OPNOTICE}, + {"SECUREFOUNDER", CI_SECUREFOUNDER}, + {"SIGNKICK", CI_SIGNKICK}, + {"SIGNKICK_LEVEL", CI_SIGNKICK_LEVEL}, + {"XOP", CI_XOP}, + {"SUSPENDED", CI_SUSPENDED}, + {"PERSIST", CI_PERSIST}, + {"", static_cast<ChannelInfoFlag>(-1)} +}; + +struct BotServFlagInfo +{ + std::string Name; + BotFlag Flag; +}; + +BotServFlagInfo BotServFlags[] = { + {"PRIVATE", BI_PRIVATE}, + {"", static_cast<BotFlag>(-1)} +}; + +struct MemoFlagInfo +{ + std::string Name; + MemoFlag Flag; +}; + +MemoFlagInfo MemoFlags[] = { + {"UNREAD", MF_UNREAD}, + {"RECEIPT", MF_RECEIPT}, + {"NOTIFYS", MF_NOTIFYS}, + {"", static_cast<MemoFlag>(-1)} +}; + +#define MYSQLPP_MYSQL_HEADERS_BURIED +#include <mysql++/mysql++.h> + +inline std::string SQLAssign(const mysqlpp::String &s) { return s.c_str(); } + +class DBMySQL; +static DBMySQL *me; + +bool ExecuteQuery(mysqlpp::Query &query) +{ + Alog(LOG_DEBUG) << "MySQL: " << query.str(); + + if (!query.execute()) + { + Alog() << "MySQL: error executing query: " << query.error(); + return false; + } + + return true; +} + +mysqlpp::StoreQueryResult StoreQuery(mysqlpp::Query &query) +{ + Alog(LOG_DEBUG) << "MySQL: " << query.str(); + + mysqlpp::StoreQueryResult result = query.store(); + if (!result) + Alog() << "MySQL: error executing query: " << query.error(); + return result; +} + +class DBMySQL : public Module +{ + private: + bool LoadConfig() + { + ConfigReader config; + + Database = config.ReadValue("mysql", "database", "anope", 0); + Server = config.ReadValue("mysql", "server", "127.0.0.1", 0); + SQLUser = config.ReadValue("mysql", "username", "anope", 0); + Password = config.ReadValue("mysql", "password", "", 0); + Port = config.ReadInteger("mysql", "port", "3306", 0, true); + Delay = config.ReadInteger("mysql", "updatedelay", "60", 0, true); + + return !Password.empty(); + } + + public: + mysqlpp::Connection *Con; + mysqlpp::NoExceptions *Ne; + + std::string Database; + std::string Server; + std::string SQLUser; + std::string Password; + unsigned int Port; + unsigned int Delay; + + DBMySQL(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + me = this; + + this->SetAuthor("Anope"); + this->SetType(DATABASE); + + if (!LoadConfig()) + throw ModuleException("Couldn't load config"); + + Con = new mysqlpp::Connection(false); + Ne = new mysqlpp::NoExceptions(Con); + if (!Con->connect(Database.c_str(), Server.c_str(), SQLUser.c_str(), Password.c_str(), Port)) + { + std::string Error = "MySQL: Error connecting to SQL server: "; + Error += Con->error(); + delete Con; + throw ModuleException(Error.c_str()); + } + + mysqlpp::Query query(Con); + query << "SET NAMES 'utf8'"; + ExecuteQuery(query); + } + + virtual ~DBMySQL() + { + delete Ne; + delete Con; + } +}; + +#endif // DB_MYSQL_H |