diff --git a/include/Base_Session.h b/include/Base_Session.h index 09cd1a866..8d286e843 100644 --- a/include/Base_Session.h +++ b/include/Base_Session.h @@ -2,12 +2,7 @@ #define CLASS_BASE_SESSION_H #include "proxysql.h" -/* -#include "MySQL_Variables.h" -#include "../deps/json/json.hpp" -using json = nlohmann::json; -*/ class MySQL_Session; class PgSQL_Session; diff --git a/include/Client_Session.h b/include/Client_Session.h index 6b3fc0bbb..9f5315e20 100644 --- a/include/Client_Session.h +++ b/include/Client_Session.h @@ -8,8 +8,13 @@ #include "cpp.h" #include "MySQL_Variables.h" -#include "../deps/json/json.hpp" -using json = nlohmann::json; +//#include "../deps/json/json.hpp" +//using json = nlohmann::json; + +#ifndef PROXYJSON +#define PROXYJSON +namespace nlohmann { class json; } +#endif // PROXYJSON class MySQL_Session; class PgSQL_Session; diff --git a/include/MySQL_Data_Stream.h b/include/MySQL_Data_Stream.h index 38a2d9436..fb388900a 100644 --- a/include/MySQL_Data_Stream.h +++ b/include/MySQL_Data_Stream.h @@ -6,6 +6,11 @@ #include "MySQL_Protocol.h" +#ifndef PROXYJSON +#define PROXYJSON +namespace nlohmann { class json; } +#endif // PROXYJSON + #ifndef uchar typedef unsigned char uchar; #endif @@ -274,6 +279,6 @@ class MySQL_Data_Stream void reset_connection(); - void get_client_myds_info_json(json&); + void get_client_myds_info_json(nlohmann::json&); }; #endif /* __CLASS_MYSQL_DATA_STREAM_H */ diff --git a/include/MySQL_HostGroups_Manager.h b/include/MySQL_HostGroups_Manager.h index 2bf87e333..81724ef87 100644 --- a/include/MySQL_HostGroups_Manager.h +++ b/include/MySQL_HostGroups_Manager.h @@ -23,8 +23,10 @@ #define SPOOKYV2 #endif -#include "../deps/json/json.hpp" -using json = nlohmann::json; +#ifndef PROXYJSON +#define PROXYJSON +namespace nlohmann { class json; } +#endif // PROXYJSON #ifdef DEBUG /* */ @@ -300,7 +302,7 @@ class MyHGC { // MySQL Host Group Container bool connection_warming; bool configured; // this variable controls if attributes are configured or not. If not configured, they do not apply bool initialized; // this variable controls if attributes were ever configured or not. Used by reset_attributes() - json ignore_session_variables_json; // the JSON format of ignore_session_variables + nlohmann::json * ignore_session_variables_json = NULL; // the JSON format of ignore_session_variables } attributes; struct { int64_t weight; @@ -1204,47 +1206,5 @@ private: uint64_t get_mysql_servers_v2_checksum(SQLite3_result* incoming_mysql_servers_v2 = nullptr); }; -/** - * @brief Helper function used to try to extract a value from the JSON field 'servers_defaults'. - * - * @param j JSON object constructed from 'servers_defaults' field. - * @param hid Hostgroup for which the 'servers_defaults' is defined in 'mysql_hostgroup_attributes'. Used for - * error logging. - * @param key The key for the value to be extracted. - * @param val_check A validation function, checks if the value is within a expected range. - * - * @return The value extracted from the supplied JSON. In case of error '-1', and error cause is logged. - */ -template ::value, bool>::type = true> -T j_get_srv_default_int_val( - const json& j, uint32_t hid, const string& key, const function& val_check -) { - if (j.find(key) != j.end()) { - const json::value_t val_type = j[key].type(); - const char* type_name = j[key].type_name(); - - if (val_type == json::value_t::number_integer || val_type == json::value_t::number_unsigned) { - T val = j[key].get(); - - if (val_check(val)) { - return val; - } else { - proxy_error( - "Invalid value %ld supplied for 'mysql_hostgroup_attributes.servers_defaults.%s' for hostgroup %d." - " Value NOT UPDATED.\n", - static_cast(val), key.c_str(), hid - ); - } - } else { - proxy_error( - "Invalid type '%s'(%hhu) supplied for 'mysql_hostgroup_attributes.servers_defaults.%s' for hostgroup %d." - " Value NOT UPDATED.\n", - type_name, static_cast(val_type), key.c_str(), hid - ); - } - } - - return static_cast(-1); -} #endif /* __CLASS_MYSQL_HOSTGROUPS_MANAGER_H */ diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index b6778c96f..ebc12605e 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -15,8 +15,10 @@ #include "cpp.h" #include "MySQL_Variables.h" -#include "../deps/json/json.hpp" -using json = nlohmann::json; +#ifndef PROXYJSON +#define PROXYJSON +namespace nlohmann { class json; } +#endif // PROXYJSON extern class MySQL_Variables mysql_variables; @@ -428,7 +430,7 @@ class MySQL_Session * params. */ void finishQuery(MySQL_Data_Stream *myds, MySQL_Connection *myconn, bool); - void generate_proxysql_internal_session_json(json &); + void generate_proxysql_internal_session_json(nlohmann::json &); bool known_query_for_locked_on_hostgroup(uint64_t); void unable_to_parse_set_statement(bool *); bool has_any_backend(); diff --git a/include/PgSQL_Connection.h b/include/PgSQL_Connection.h index bab7641c2..a2f2a7a43 100644 --- a/include/PgSQL_Connection.h +++ b/include/PgSQL_Connection.h @@ -4,8 +4,11 @@ #include "proxysql.h" #include "cpp.h" -#include "../deps/json/json.hpp" -using json = nlohmann::json; +#ifndef PROXYJSON +#define PROXYJSON +namespace nlohmann { class json; } +#endif // PROXYJSON + class PgSQL_SrvC; @@ -252,8 +255,8 @@ public: class PgSQL_Variable { public: char *value = (char*)""; - void fill_server_internal_session(json &j, int conn_num, int idx); - void fill_client_internal_session(json &j, int idx); + void fill_server_internal_session(nlohmann::json &j, int conn_num, int idx); + void fill_client_internal_session(nlohmann::json &j, int idx); }; enum pgsql_charset_action { diff --git a/include/PgSQL_HostGroups_Manager.h b/include/PgSQL_HostGroups_Manager.h index 7f8477c7a..fedad984c 100644 --- a/include/PgSQL_HostGroups_Manager.h +++ b/include/PgSQL_HostGroups_Manager.h @@ -23,8 +23,10 @@ #define SPOOKYV2 #endif -#include "../deps/json/json.hpp" -using json = nlohmann::json; +#ifndef PROXYJSON +#define PROXYJSON +namespace nlohmann { class json; } +#endif // PROXYJSON #ifdef DEBUG /* */ @@ -287,7 +289,7 @@ class PgSQL_HGC { // MySQL Host Group Container bool connection_warming; bool configured; // this variable controls if attributes are configured or not. If not configured, they do not apply bool initialized; // this variable controls if attributes were ever configured or not. Used by reset_attributes() - json ignore_session_variables_json; // the JSON format of ignore_session_variables + nlohmann::json * ignore_session_variables_json = NULL; // the JSON format of ignore_session_variables } attributes; struct { int64_t weight; @@ -1117,47 +1119,5 @@ private: uint64_t get_pgsql_servers_v2_checksum(SQLite3_result* incoming_pgsql_servers_v2 = nullptr); }; -/** - * @brief Helper function used to try to extract a value from the JSON field 'servers_defaults'. - * - * @param j JSON object constructed from 'servers_defaults' field. - * @param hid Hostgroup for which the 'servers_defaults' is defined in 'pgsql_hostgroup_attributes'. Used for - * error logging. - * @param key The key for the value to be extracted. - * @param val_check A validation function, checks if the value is within a expected range. - * - * @return The value extracted from the supplied JSON. In case of error '-1', and error cause is logged. - */ -template ::value, bool>::type = true> -T PgSQL_j_get_srv_default_int_val( - const json& j, uint32_t hid, const string& key, const function& val_check -) { - if (j.find(key) != j.end()) { - const json::value_t val_type = j[key].type(); - const char* type_name = j[key].type_name(); - - if (val_type == json::value_t::number_integer || val_type == json::value_t::number_unsigned) { - T val = j[key].get(); - - if (val_check(val)) { - return val; - } else { - proxy_error( - "Invalid value %ld supplied for 'pgsql_hostgroup_attributes.servers_defaults.%s' for hostgroup %d." - " Value NOT UPDATED.\n", - static_cast(val), key.c_str(), hid - ); - } - } else { - proxy_error( - "Invalid type '%s'(%hhu) supplied for 'pgsql_hostgroup_attributes.servers_defaults.%s' for hostgroup %d." - " Value NOT UPDATED.\n", - type_name, static_cast(val_type), key.c_str(), hid - ); - } - } - - return static_cast(-1); -} #endif /* __CLASS_POSTGRESQL_HOSTGROUPS_MANAGER_H */ diff --git a/include/PgSQL_Session.h b/include/PgSQL_Session.h index 3a8f7a2a0..96c9db021 100644 --- a/include/PgSQL_Session.h +++ b/include/PgSQL_Session.h @@ -10,8 +10,13 @@ #include "cpp.h" #include "PgSQL_Variables.h" -#include "../deps/json/json.hpp" -using json = nlohmann::json; +//#include "../deps/json/json.hpp" +//using json = nlohmann::json; + +#ifndef PROXYJSON +#define PROXYJSON +namespace nlohmann { class json; } +#endif // PROXYJSON extern class PgSQL_Variables pgsql_variables; @@ -399,7 +404,7 @@ public: * params. */ void finishQuery(PgSQL_Data_Stream* myds, PgSQL_Connection* myconn, bool); - void generate_proxysql_internal_session_json(json&); + void generate_proxysql_internal_session_json(nlohmann::json&); bool known_query_for_locked_on_hostgroup(uint64_t); void unable_to_parse_set_statement(bool*); bool has_any_backend(); diff --git a/include/mysql_connection.h b/include/mysql_connection.h index f88e41eb3..167632ff9 100644 --- a/include/mysql_connection.h +++ b/include/mysql_connection.h @@ -4,8 +4,13 @@ #include "proxysql.h" #include "cpp.h" -#include "../deps/json/json.hpp" -using json = nlohmann::json; +//#include "../deps/json/json.hpp" +//using json = nlohmann::json; + +#ifndef PROXYJSON +#define PROXYJSON +namespace nlohmann { class json; } +#endif // PROXYJSON //#define STATUS_MYSQL_CONNECTION_TRANSACTION 0x00000001 // DEPRECATED #define STATUS_MYSQL_CONNECTION_COMPRESSION 0x00000002 @@ -26,8 +31,8 @@ class MySQLServers_SslParams; class Variable { public: char *value = (char*)""; - void fill_server_internal_session(json &j, int idx); - void fill_client_internal_session(json &j, int idx); + void fill_server_internal_session(nlohmann::json &j, int idx); + void fill_client_internal_session(nlohmann::json &j, int idx); }; enum charset_action { @@ -264,7 +269,7 @@ class MySQL_Connection { unsigned long get_mysql_thread_id() { return mysql ? mysql->thread_id : 0; } static void set_ssl_params(MYSQL *mysql, MySQLServers_SslParams *ssl_params); - void get_mysql_info_json(json&); - void get_backend_conn_info_json(json&); + void get_mysql_info_json(nlohmann::json&); + void get_backend_conn_info_json(nlohmann::json&); }; #endif /* __CLASS_MYSQL_CONNECTION_H */ diff --git a/include/query_processor.h b/include/query_processor.h index 968c32491..2032b4b00 100644 --- a/include/query_processor.h +++ b/include/query_processor.h @@ -10,8 +10,12 @@ #define DIGEST_STATS_FAST_MINSIZE 100000 #define DIGEST_STATS_FAST_THREADS 4 -#include "../deps/json/json.hpp" +//#include "../deps/json/json.hpp" +#ifndef PROXYJSON +#define PROXYJSON +namespace nlohmann { class json; } +#endif // PROXYJSON #include "khash.h" KHASH_MAP_INIT_STR(khStrInt, int) @@ -204,20 +208,7 @@ class Query_Processor_Output { free(comment); } } - void get_info_json(nlohmann::json& j) { - j["create_new_connection"] = create_new_conn; - j["reconnect"] = reconnect; - j["sticky_conn"] = sticky_conn; - j["cache_timeout"] = cache_timeout; - j["cache_ttl"] = cache_ttl; - j["delay"] = delay; - j["destination_hostgroup"] = destination_hostgroup; - j["firewall_whitelist_mode"] = firewall_whitelist_mode; - j["multiplex"] = multiplex; - j["timeout"] = timeout; - j["retries"] = retries; - j["max_lag_ms"] = max_lag_ms; - } + void get_info_json(nlohmann::json& j); }; static char *commands_counters_desc[MYSQL_COM_QUERY___NONE]; diff --git a/lib/MyHGC.cpp b/lib/MyHGC.cpp index 9a2a8a062..36160349a 100644 --- a/lib/MyHGC.cpp +++ b/lib/MyHGC.cpp @@ -41,7 +41,10 @@ void MyHGC::reset_attributes() { attributes.comment = NULL; free(attributes.ignore_session_variables_text); attributes.ignore_session_variables_text = NULL; - attributes.ignore_session_variables_json = json(); + if (attributes.ignore_session_variables_json) { + delete attributes.ignore_session_variables_json; + attributes.ignore_session_variables_json = NULL; + } } MyHGC::~MyHGC() { diff --git a/lib/MySQL_Authentication.cpp b/lib/MySQL_Authentication.cpp index e619182f2..f6b1129fe 100644 --- a/lib/MySQL_Authentication.cpp +++ b/lib/MySQL_Authentication.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +//using json = nlohmann::json; +#define PROXYJSON + //#include "btree_map.h" #include "proxysql.h" #include "cpp.h" @@ -10,6 +14,7 @@ #define SPOOKYV2 #endif + MySQL_Authentication::MySQL_Authentication() { #ifdef DEBUG if (glovars.has_debug==false) { diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 678d4a2fb..e0cda1bb2 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include "MySQL_HostGroups_Manager.h" #include "proxysql.h" #include "cpp.h" @@ -82,6 +86,50 @@ static int wait_for_mysql(MYSQL *mysql, int status) { } } +/** + * @brief Helper function used to try to extract a value from the JSON field 'servers_defaults'. + * + * @param j JSON object constructed from 'servers_defaults' field. + * @param hid Hostgroup for which the 'servers_defaults' is defined in 'mysql_hostgroup_attributes'. Used for + * error logging. + * @param key The key for the value to be extracted. + * @param val_check A validation function, checks if the value is within a expected range. + * + * @return The value extracted from the supplied JSON. In case of error '-1', and error cause is logged. + */ +template ::value, bool>::type = true> +T j_get_srv_default_int_val( + const json& j, uint32_t hid, const string& key, const function& val_check +) { + if (j.find(key) != j.end()) { + const json::value_t val_type = j[key].type(); + const char* type_name = j[key].type_name(); + + if (val_type == json::value_t::number_integer || val_type == json::value_t::number_unsigned) { + T val = j[key].get(); + + if (val_check(val)) { + return val; + } else { + proxy_error( + "Invalid value %ld supplied for 'mysql_hostgroup_attributes.servers_defaults.%s' for hostgroup %d." + " Value NOT UPDATED.\n", + static_cast(val), key.c_str(), hid + ); + } + } else { + proxy_error( + "Invalid type '%s'(%hhu) supplied for 'mysql_hostgroup_attributes.servers_defaults.%s' for hostgroup %d." + " Value NOT UPDATED.\n", + type_name, static_cast(val_type), key.c_str(), hid + ); + } + } + + return static_cast(-1); +} + + //static void * HGCU_thread_run() { static void * HGCU_thread_run() { PtrArray *conn_array=new PtrArray(); @@ -6369,14 +6417,16 @@ void MySQL_HostGroups_Manager::generate_mysql_hostgroup_attributes_table() { if (myhgc->attributes.ignore_session_variables_text == NULL) { myhgc->attributes.ignore_session_variables_text = strdup(ignore_session_variables); if (strlen(ignore_session_variables) != 0) { // only if there is a valid JSON - myhgc->attributes.ignore_session_variables_json = json::parse(ignore_session_variables); + if (myhgc->attributes.ignore_session_variables_json != nullptr) { delete myhgc->attributes.ignore_session_variables_json; } + myhgc->attributes.ignore_session_variables_json = new json(json::parse(ignore_session_variables)); } } else { if (strcmp(myhgc->attributes.ignore_session_variables_text, ignore_session_variables) != 0) { free(myhgc->attributes.ignore_session_variables_text); myhgc->attributes.ignore_session_variables_text = strdup(ignore_session_variables); if (strlen(ignore_session_variables) != 0) { // only if there is a valid JSON - myhgc->attributes.ignore_session_variables_json = json::parse(ignore_session_variables); + if (myhgc->attributes.ignore_session_variables_json != nullptr) { delete myhgc->attributes.ignore_session_variables_json; } + myhgc->attributes.ignore_session_variables_json = new json(json::parse(ignore_session_variables)); } // TODO: assign the variables } diff --git a/lib/MySQL_Logger.cpp b/lib/MySQL_Logger.cpp index 6dd183846..e070f478b 100644 --- a/lib/MySQL_Logger.cpp +++ b/lib/MySQL_Logger.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include #include "proxysql.h" #include "cpp.h" @@ -10,9 +14,6 @@ #include #include -#include "../deps/json/json.hpp" -using json = nlohmann::json; - #ifdef DEBUG #define DEB "_DEBUG" #else diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index a943f10a9..530c40a0b 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -7,6 +7,11 @@ 0.2.0902 * original implementation */ + +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include #include #include diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index cba71c6a8..6d5aa4663 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include #include "proxysql.h" #include "cpp.h" diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 3a0159f49..86a08298a 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include "MySQL_HostGroups_Manager.h" #include "MySQL_Thread.h" #include "proxysql.h" diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 88fe791b6..a19069f6d 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + //#define __CLASS_STANDARD_MYSQL_THREAD_H #include diff --git a/lib/PgSQL_Authentication.cpp b/lib/PgSQL_Authentication.cpp index ccc56071a..60a9b25ad 100644 --- a/lib/PgSQL_Authentication.cpp +++ b/lib/PgSQL_Authentication.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + //#include "btree_map.h" #include "proxysql.h" #include "cpp.h" diff --git a/lib/PgSQL_Connection.cpp b/lib/PgSQL_Connection.cpp index 7b5acf392..7a898b4bb 100644 --- a/lib/PgSQL_Connection.cpp +++ b/lib/PgSQL_Connection.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include "PgSQL_HostGroups_Manager.h" #include "proxysql.h" #include "cpp.h" diff --git a/lib/PgSQL_HostGroups_Manager.cpp b/lib/PgSQL_HostGroups_Manager.cpp index e7418c86d..29e89b144 100644 --- a/lib/PgSQL_HostGroups_Manager.cpp +++ b/lib/PgSQL_HostGroups_Manager.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include "PgSQL_HostGroups_Manager.h" #include "proxysql.h" #include "cpp.h" @@ -122,6 +126,49 @@ static int wait_for_pgsql(MYSQL *mysql, int status) { } } +/** + * @brief Helper function used to try to extract a value from the JSON field 'servers_defaults'. + * + * @param j JSON object constructed from 'servers_defaults' field. + * @param hid Hostgroup for which the 'servers_defaults' is defined in 'pgsql_hostgroup_attributes'. Used for + * error logging. + * @param key The key for the value to be extracted. + * @param val_check A validation function, checks if the value is within a expected range. + * + * @return The value extracted from the supplied JSON. In case of error '-1', and error cause is logged. + */ +template ::value, bool>::type = true> +T PgSQL_j_get_srv_default_int_val( + const json& j, uint32_t hid, const string& key, const function& val_check +) { + if (j.find(key) != j.end()) { + const json::value_t val_type = j[key].type(); + const char* type_name = j[key].type_name(); + + if (val_type == json::value_t::number_integer || val_type == json::value_t::number_unsigned) { + T val = j[key].get(); + + if (val_check(val)) { + return val; + } else { + proxy_error( + "Invalid value %ld supplied for 'pgsql_hostgroup_attributes.servers_defaults.%s' for hostgroup %d." + " Value NOT UPDATED.\n", + static_cast(val), key.c_str(), hid + ); + } + } else { + proxy_error( + "Invalid type '%s'(%hhu) supplied for 'pgsql_hostgroup_attributes.servers_defaults.%s' for hostgroup %d." + " Value NOT UPDATED.\n", + type_name, static_cast(val_type), key.c_str(), hid + ); + } + } + + return static_cast(-1); +} + #if 0 static void reader_cb(struct ev_loop *loop, struct ev_io *w, int revents) { pthread_mutex_lock(&ev_loop_mutex); @@ -921,7 +968,10 @@ void PgSQL_HGC::reset_attributes() { attributes.comment = NULL; free(attributes.ignore_session_variables_text); attributes.ignore_session_variables_text = NULL; - attributes.ignore_session_variables_json = json(); + if (attributes.ignore_session_variables_json) { + delete attributes.ignore_session_variables_json; + attributes.ignore_session_variables_json = NULL; + } } PgSQL_HGC::~PgSQL_HGC() { @@ -7303,14 +7353,16 @@ void PgSQL_HostGroups_Manager::generate_pgsql_hostgroup_attributes_table() { if (myhgc->attributes.ignore_session_variables_text == NULL) { myhgc->attributes.ignore_session_variables_text = strdup(ignore_session_variables); if (strlen(ignore_session_variables) != 0) { // only if there is a valid JSON - myhgc->attributes.ignore_session_variables_json = json::parse(ignore_session_variables); + if (myhgc->attributes.ignore_session_variables_json != nullptr) { delete myhgc->attributes.ignore_session_variables_json; } + myhgc->attributes.ignore_session_variables_json = new json(json::parse(ignore_session_variables)); } } else { if (strcmp(myhgc->attributes.ignore_session_variables_text, ignore_session_variables) != 0) { free(myhgc->attributes.ignore_session_variables_text); myhgc->attributes.ignore_session_variables_text = strdup(ignore_session_variables); if (strlen(ignore_session_variables) != 0) { // only if there is a valid JSON - myhgc->attributes.ignore_session_variables_json = json::parse(ignore_session_variables); + if (myhgc->attributes.ignore_session_variables_json != nullptr) { delete myhgc->attributes.ignore_session_variables_json; } + myhgc->attributes.ignore_session_variables_json = new json(json::parse(ignore_session_variables)); } // TODO: assign the variables } diff --git a/lib/PgSQL_Logger.cpp b/lib/PgSQL_Logger.cpp index 56169cc0b..06a319d15 100644 --- a/lib/PgSQL_Logger.cpp +++ b/lib/PgSQL_Logger.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include #include "proxysql.h" #include "cpp.h" @@ -10,8 +14,6 @@ #include #include -#include "../deps/json/json.hpp" -using json = nlohmann::json; #ifdef DEBUG #define DEB "_DEBUG" diff --git a/lib/PgSQL_Session.cpp b/lib/PgSQL_Session.cpp index b98dc228c..42e69825b 100644 --- a/lib/PgSQL_Session.cpp +++ b/lib/PgSQL_Session.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include "PgSQL_HostGroups_Manager.h" #include "PgSQL_Thread.h" #include "proxysql.h" diff --git a/lib/PgSQL_Thread.cpp b/lib/PgSQL_Thread.cpp index d663a6667..9daaaba4c 100644 --- a/lib/PgSQL_Thread.cpp +++ b/lib/PgSQL_Thread.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + //#define __CLASS_STANDARD_MYSQL_THREAD_H #include diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index c431e4829..88ca44213 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include // std::cout #include // std::stringstream #include @@ -120,6 +124,10 @@ char * proxysql_version = NULL; #include "proxysql_find_charset.h" +template ::value, bool>::type = true> +T j_get_srv_default_int_val( +const json& j, uint32_t hid, const string& key, const function& val_check); + static const vector mysql_servers_tablenames = { "mysql_servers", diff --git a/lib/ProxySQL_RESTAPI_Server.cpp b/lib/ProxySQL_RESTAPI_Server.cpp index 795112b9c..f1f6c71e1 100644 --- a/lib/ProxySQL_RESTAPI_Server.cpp +++ b/lib/ProxySQL_RESTAPI_Server.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include "proxysql.h" #include "cpp.h" #include "httpserver.hpp" @@ -17,7 +21,7 @@ extern ProxySQL_Admin *GloAdmin; using namespace httpserver; -using nlohmann::json; +//using nlohmann::json; class sync_resource : public http_resource { private: diff --git a/lib/Query_Processor.cpp b/lib/Query_Processor.cpp index 55f88a491..5ab1a1542 100644 --- a/lib/Query_Processor.cpp +++ b/lib/Query_Processor.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include // std::cout #include // std::sort #include // std::vector @@ -3403,6 +3407,21 @@ bool Query_Processor::pgsql_whitelisted_sqli_fingerprint(char* _s) { return ret; } +void Query_Processor_Output::get_info_json(json& j) { + j["create_new_connection"] = create_new_conn; + j["reconnect"] = reconnect; + j["sticky_conn"] = sticky_conn; + j["cache_timeout"] = cache_timeout; + j["cache_ttl"] = cache_ttl; + j["delay"] = delay; + j["destination_hostgroup"] = destination_hostgroup; + j["firewall_whitelist_mode"] = firewall_whitelist_mode; + j["multiplex"] = multiplex; + j["timeout"] = timeout; + j["retries"] = retries; + j["max_lag_ms"] = max_lag_ms; +} + template Query_Processor_Output* Query_Processor::process_mysql_query(Client_Session, void*, unsigned int, Query_Info_T); diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index 103230a60..1c5845285 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include "MySQL_HostGroups_Manager.h" #include "proxysql.h" #include "cpp.h" diff --git a/lib/mysql_data_stream.cpp b/lib/mysql_data_stream.cpp index c1f37efc0..6f13577db 100644 --- a/lib/mysql_data_stream.cpp +++ b/lib/mysql_data_stream.cpp @@ -1,3 +1,7 @@ +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include "proxysql.h" #include "cpp.h" #include diff --git a/src/main.cpp b/src/main.cpp index 66e758926..a7228055f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,9 @@ #define MAIN_PROXY_SQLITE3 + +#include "../deps/json/json.hpp" +using json = nlohmann::json; +#define PROXYJSON + #include #include #include "btree_map.h"