From 0af89e55d24f50b3dd08717358d97a79ee3d1b04 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 10 May 2024 13:54:05 +0100 Subject: Add SRV record support to the mysql module. --- src/modules/extra/m_mysql.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/modules/extra/m_mysql.cpp') diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index e840bd851..a8c13a4fd 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -334,8 +334,23 @@ public: const std::string user = config->getString("user"); const std::string pass = config->getString("pass"); const std::string dbname = config->getString("name"); - unsigned int port = config->getNum("port", 3306, 1, 65535); - if (!mysql_real_connect(connection, host.c_str(), user.c_str(), pass.c_str(), dbname.c_str(), port, nullptr, CLIENT_IGNORE_SIGPIPE)) + + MYSQL* result; +#if defined LIBMYSQL_VERSION_ID && LIBMYSQL_VERSION_ID > 80000 + if (config->getBool("srv")) + { + result = mysql_real_connect_dns_srv(connection, host.c_str(), user.c_str(), + pass.c_str(), dbname.c_str(), CLIENT_IGNORE_SIGPIPE); + } + else +#endif + { + auto port = config->getNum("port", 3306, 1, 65535); + result = mysql_real_connect(connection, host.c_str(), user.c_str(), pass.c_str(), + dbname.c_str(), port, nullptr, CLIENT_IGNORE_SIGPIPE); + } + + if (!result) { ServerInstance->Logs.Critical(MODNAME, "Unable to connect to the {} MySQL server: {}", GetId(), mysql_error(connection)); -- cgit v1.3.1-10-gc9f91