From 699fe7efcdbf9c68024e2d2de4463126faf89a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 8 Dec 2023 02:55:43 +0000 Subject: [PATCH] Moved proxysql_find_charset_* functions out of MySQL_Thread.cpp --- include/MySQL_Variables.h | 3 -- include/proxysql_find_charset.h | 7 ++++ lib/Makefile | 3 +- lib/MySQL_Protocol.cpp | 3 +- lib/MySQL_Session.cpp | 5 +-- lib/MySQL_Thread.cpp | 65 -------------------------------- lib/MySQL_Variables.cpp | 1 + lib/ProxySQL_Admin.cpp | 2 +- lib/mysql_connection.cpp | 3 +- lib/proxysql_find_charset.cpp | 67 +++++++++++++++++++++++++++++++++ 10 files changed, 81 insertions(+), 78 deletions(-) create mode 100644 include/proxysql_find_charset.h create mode 100644 lib/proxysql_find_charset.cpp diff --git a/include/MySQL_Variables.h b/include/MySQL_Variables.h index 95381bf2da..678d594a06 100644 --- a/include/MySQL_Variables.h +++ b/include/MySQL_Variables.h @@ -10,9 +10,6 @@ class MySQL_Session; -extern const MARIADB_CHARSET_INFO * proxysql_find_charset_nr(unsigned int nr); -extern MARIADB_CHARSET_INFO * proxysql_find_charset_name(const char *name); -extern MARIADB_CHARSET_INFO * proxysql_find_charset_collate(const char *collatename); extern void print_backtrace(void); typedef bool (*verify_var)(MySQL_Session* session, int idx, uint32_t client_hash, uint32_t server_hash); diff --git a/include/proxysql_find_charset.h b/include/proxysql_find_charset.h new file mode 100644 index 0000000000..11ae949d48 --- /dev/null +++ b/include/proxysql_find_charset.h @@ -0,0 +1,7 @@ +#include "mysql.h" +#include "mariadb_com.h" + +MARIADB_CHARSET_INFO * proxysql_find_charset_name(const char * const name); +MARIADB_CHARSET_INFO * proxysql_find_charset_collate_names(const char *csname, const char *collatename); +const MARIADB_CHARSET_INFO * proxysql_find_charset_nr(unsigned int nr); +MARIADB_CHARSET_INFO * proxysql_find_charset_collate(const char *collatename); diff --git a/lib/Makefile b/lib/Makefile index 73fb64ed14..ee6b75fd2a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -144,7 +144,8 @@ MYCXXFLAGS=-std=c++11 $(MYCFLAGS) $(PSQLCH) $(ENABLE_EPOLL) default: libproxysql.a .PHONY: default -_OBJ_CXX = ProxySQL_GloVars.oo network.oo debug.oo configfile.oo Query_Cache.oo SpookyV2.oo MySQL_Authentication.oo gen_utils.oo sqlite3db.oo mysql_connection.oo MySQL_HostGroups_Manager.oo mysql_data_stream.oo MySQL_Thread.oo MySQL_Session.oo MySQL_Protocol.oo mysql_backend.oo Query_Processor.oo ProxySQL_Admin.oo ProxySQL_Config.oo ProxySQL_Restapi.oo MySQL_Monitor.oo MySQL_Logger.oo thread.oo MySQL_PreparedStatement.oo ProxySQL_Cluster.oo ClickHouse_Authentication.oo ClickHouse_Server.oo ProxySQL_Statistics.oo Chart_bundle_js.oo ProxySQL_HTTP_Server.oo ProxySQL_RESTAPI_Server.oo font-awesome.min.css.oo main-bundle.min.css.oo set_parser.oo MySQL_Variables.oo c_tokenizer.oo proxysql_utils.oo proxysql_coredump.oo proxysql_sslkeylog.oo +_OBJ_CXX = ProxySQL_GloVars.oo network.oo debug.oo configfile.oo Query_Cache.oo SpookyV2.oo MySQL_Authentication.oo gen_utils.oo sqlite3db.oo mysql_connection.oo MySQL_HostGroups_Manager.oo mysql_data_stream.oo MySQL_Thread.oo MySQL_Session.oo MySQL_Protocol.oo mysql_backend.oo Query_Processor.oo ProxySQL_Admin.oo ProxySQL_Config.oo ProxySQL_Restapi.oo MySQL_Monitor.oo MySQL_Logger.oo thread.oo MySQL_PreparedStatement.oo ProxySQL_Cluster.oo ClickHouse_Authentication.oo ClickHouse_Server.oo ProxySQL_Statistics.oo Chart_bundle_js.oo ProxySQL_HTTP_Server.oo ProxySQL_RESTAPI_Server.oo font-awesome.min.css.oo main-bundle.min.css.oo set_parser.oo MySQL_Variables.oo c_tokenizer.oo proxysql_utils.oo proxysql_coredump.oo proxysql_sslkeylog.oo \ + proxysql_find_charset.oo OBJ_CXX = $(patsubst %,$(ODIR)/%,$(_OBJ_CXX)) HEADERS = ../include/*.h ../include/*.hpp diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index ddcbc84228..c2d4828e21 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -32,8 +32,7 @@ extern ClickHouse_Authentication *GloClickHouseAuth; #define CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA 0x00200000 #endif -extern const MARIADB_CHARSET_INFO * proxysql_find_charset_nr(unsigned int nr); -MARIADB_CHARSET_INFO * proxysql_find_charset_name(const char *name); +#include "proxysql_find_charset.h" #ifdef DEBUG static void __dump_pkt(const char *func, unsigned char *_ptr, unsigned int len) { diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 4dab93185e..29fa32b2e6 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -119,10 +119,7 @@ static const std::set mysql_variables_strings = { "wsrep_osu_method", }; -extern MARIADB_CHARSET_INFO * proxysql_find_charset_name(const char * const name); -extern MARIADB_CHARSET_INFO * proxysql_find_charset_collate_names(const char *csname, const char *collatename); -extern const MARIADB_CHARSET_INFO * proxysql_find_charset_nr(unsigned int nr); -extern MARIADB_CHARSET_INFO * proxysql_find_charset_collate(const char *collatename); +#include "proxysql_find_charset.h" extern MySQL_Authentication *GloMyAuth; extern MySQL_LDAP_Authentication *GloMyLdapAuth; diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 18efd1f6a5..4124329551 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -105,71 +105,6 @@ mythr_g_st_vars_t MySQL_Thread_status_variables_gauge_array[] { extern mysql_variable_st mysql_tracked_variables[]; -const MARIADB_CHARSET_INFO * proxysql_find_charset_nr(unsigned int nr) { - const MARIADB_CHARSET_INFO * c = mariadb_compiled_charsets; - do { - if (c->nr == nr) { - return c; - } - ++c; - } while (c[0].nr != 0); - return NULL; -} - -MARIADB_CHARSET_INFO * proxysql_find_charset_name(const char *name_) { - MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets; - const char *name; - if (strcasecmp(name_,(const char *)"utf8mb3")==0) { - name = (const char *)"utf8"; - } else { - name = name_; - } - do { - if (!strcasecmp(c->csname, name)) { - return c; - } - ++c; - } while (c[0].nr != 0); - return NULL; -} - -MARIADB_CHARSET_INFO * proxysql_find_charset_collate_names(const char *csname_, const char *collatename_) { - MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets; - char buf[64]; - const char *csname; - const char *collatename; - if (strcasecmp(csname_,(const char *)"utf8mb3")==0) { - csname = (const char *)"utf8"; - } else { - csname = csname_; - } - if (strncasecmp(collatename_,(const char *)"utf8mb3", 7)==0) { - memcpy(buf,(const char *)"utf8",4); - strcpy(buf+4,collatename_+7); - collatename = buf; - } else { - collatename = collatename_; - } - do { - if (!strcasecmp(c->csname, csname) && !strcasecmp(c->name, collatename)) { - return c; - } - ++c; - } while (c[0].nr != 0); - return NULL; -} - -MARIADB_CHARSET_INFO * proxysql_find_charset_collate(const char *collatename) { - MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets; - do { - if (!strcasecmp(c->name, collatename)) { - return c; - } - ++c; - } while (c[0].nr != 0); - return NULL; -} - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ diff --git a/lib/MySQL_Variables.cpp b/lib/MySQL_Variables.cpp index c1ed5685a7..6f5c1f0481 100644 --- a/lib/MySQL_Variables.cpp +++ b/lib/MySQL_Variables.cpp @@ -17,6 +17,7 @@ static inline char is_digit(char c) { return 0; } +#include "proxysql_find_charset.h" verify_var MySQL_Variables::verifiers[SQL_NAME_LAST_HIGH_WM]; update_var MySQL_Variables::updaters[SQL_NAME_LAST_HIGH_WM]; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index aef000b653..cc751096b4 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -102,7 +102,7 @@ extern char *ssl_ca_fp; int admin___web_verbosity = 0; char * proxysql_version = NULL; -MARIADB_CHARSET_INFO * proxysql_find_charset_name(const char *name); +#include "proxysql_find_charset.h" static const vector mysql_servers_tablenames = { diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index c5cb83a8c1..4400d7ec9b 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -107,8 +107,7 @@ void ma_free_root(MA_MEM_ROOT *root, myf MyFlags) extern char * binary_sha1; -extern const MARIADB_CHARSET_INFO * proxysql_find_charset_nr(unsigned int nr); -MARIADB_CHARSET_INFO * proxysql_find_charset_name(const char *name); +#include "proxysql_find_charset.h" void Variable::fill_server_internal_session(json &j, int conn_num, int idx) { if (idx == SQL_CHARACTER_SET_RESULTS || idx == SQL_CHARACTER_SET_CLIENT || idx == SQL_CHARACTER_SET_DATABASE) { diff --git a/lib/proxysql_find_charset.cpp b/lib/proxysql_find_charset.cpp new file mode 100644 index 0000000000..c4d9c8cb0a --- /dev/null +++ b/lib/proxysql_find_charset.cpp @@ -0,0 +1,67 @@ +#include "proxysql_find_charset.h" +#include + +const MARIADB_CHARSET_INFO * proxysql_find_charset_nr(unsigned int nr) { + const MARIADB_CHARSET_INFO * c = mariadb_compiled_charsets; + do { + if (c->nr == nr) { + return c; + } + ++c; + } while (c[0].nr != 0); + return NULL; +} + +MARIADB_CHARSET_INFO * proxysql_find_charset_name(const char *name_) { + MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets; + const char *name; + if (strcasecmp(name_,(const char *)"utf8mb3")==0) { + name = (const char *)"utf8"; + } else { + name = name_; + } + do { + if (!strcasecmp(c->csname, name)) { + return c; + } + ++c; + } while (c[0].nr != 0); + return NULL; +} + +MARIADB_CHARSET_INFO * proxysql_find_charset_collate_names(const char *csname_, const char *collatename_) { + MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets; + char buf[64]; + const char *csname; + const char *collatename; + if (strcasecmp(csname_,(const char *)"utf8mb3")==0) { + csname = (const char *)"utf8"; + } else { + csname = csname_; + } + if (strncasecmp(collatename_,(const char *)"utf8mb3", 7)==0) { + memcpy(buf,(const char *)"utf8",4); + strcpy(buf+4,collatename_+7); + collatename = buf; + } else { + collatename = collatename_; + } + do { + if (!strcasecmp(c->csname, csname) && !strcasecmp(c->name, collatename)) { + return c; + } + ++c; + } while (c[0].nr != 0); + return NULL; +} + +MARIADB_CHARSET_INFO * proxysql_find_charset_collate(const char *collatename) { + MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets; + do { + if (!strcasecmp(c->name, collatename)) { + return c; + } + ++c; + } while (c[0].nr != 0); + return NULL; +}