From 1f6cc6db8ae47c6d5d201cb08c2608929a019e2c Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Thu, 3 May 2018 15:53:17 +0300 Subject: [PATCH] MXS-1840 Compile all routers as C++ Minimal changes, only what is needed in order to make it compile. --- avro/maxavro.h | 7 +- server/modules/routing/CMakeLists.txt | 2 +- .../modules/routing/avrorouter/CMakeLists.txt | 2 +- .../routing/avrorouter/{avro.c => avro.cc} | 22 +- .../{avro_client.c => avro_client.cc} | 8 +- .../avrorouter/{avro_file.c => avro_file.cc} | 27 +- .../{avro_index.c => avro_index.cc} | 18 +- .../avrorouter/{avro_rbr.c => avro_rbr.cc} | 6 +- .../{avro_schema.c => avro_schema.cc} | 54 ++-- .../modules/routing/avrorouter/avrorouter.h | 8 +- .../routing/avrorouter/test/CMakeLists.txt | 4 +- ..._alter_parsing.c => test_alter_parsing.cc} | 2 +- .../routing/binlogrouter/CMakeLists.txt | 4 +- .../{binlog_common.c => binlog_common.cc} | 4 +- .../routing/binlogrouter/{blr.c => blr.cc} | 25 +- server/modules/routing/binlogrouter/blr.h | 76 ++--- .../{blr_cache.c => blr_cache.cc} | 0 .../binlogrouter/{blr_file.c => blr_file.cc} | 50 +-- .../{blr_master.c => blr_master.cc} | 32 +- .../{blr_slave.c => blr_slave.cc} | 143 ++++----- .../{maxbinlogcheck.c => maxbinlogcheck.cc} | 2 +- .../routing/binlogrouter/test/CMakeLists.txt | 2 +- .../test/{testbinlog.c => testbinlog.cc} | 3 +- server/modules/routing/cat/cat.cc | 6 +- server/modules/routing/cli/CMakeLists.txt | 2 +- server/modules/routing/cli/{cli.c => cli.cc} | 6 +- .../modules/routing/debugcli/CMakeLists.txt | 2 +- .../debugcli/{debugcli.c => debugcli.cc} | 6 +- .../debugcli/{debugcmd.c => debugcmd.cc} | 292 ++++++++++-------- server/modules/routing/maxinfo/CMakeLists.txt | 2 +- .../routing/maxinfo/{maxinfo.c => maxinfo.cc} | 10 +- server/modules/routing/maxinfo/maxinfo.h | 3 +- .../{maxinfo_error.c => maxinfo_error.cc} | 4 +- .../{maxinfo_exec.c => maxinfo_exec.cc} | 44 +-- .../{maxinfo_parse.c => maxinfo_parse.cc} | 2 +- .../routing/readconnroute/CMakeLists.txt | 2 +- .../{readconnroute.c => readconnroute.cc} | 9 +- .../routing/readwritesplit/readwritesplit.cc | 6 +- .../schemarouter/schemarouterinstance.cc | 6 +- 39 files changed, 476 insertions(+), 427 deletions(-) rename server/modules/routing/avrorouter/{avro.c => avro.cc} (98%) rename server/modules/routing/avrorouter/{avro_client.c => avro_client.cc} (99%) rename server/modules/routing/avrorouter/{avro_file.c => avro_file.cc} (96%) rename server/modules/routing/avrorouter/{avro_index.c => avro_index.cc} (92%) rename server/modules/routing/avrorouter/{avro_rbr.c => avro_rbr.cc} (98%) rename server/modules/routing/avrorouter/{avro_schema.c => avro_schema.cc} (94%) rename server/modules/routing/avrorouter/test/{test_alter_parsing.c => test_alter_parsing.cc} (99%) rename server/modules/routing/binlogrouter/{binlog_common.c => binlog_common.cc} (98%) rename server/modules/routing/binlogrouter/{blr.c => blr.cc} (99%) rename server/modules/routing/binlogrouter/{blr_cache.c => blr_cache.cc} (100%) rename server/modules/routing/binlogrouter/{blr_file.c => blr_file.cc} (98%) rename server/modules/routing/binlogrouter/{blr_master.c => blr_master.cc} (99%) rename server/modules/routing/binlogrouter/{blr_slave.c => blr_slave.cc} (99%) rename server/modules/routing/binlogrouter/{maxbinlogcheck.c => maxbinlogcheck.cc} (99%) rename server/modules/routing/binlogrouter/test/{testbinlog.c => testbinlog.cc} (99%) rename server/modules/routing/cli/{cli.c => cli.cc} (97%) rename server/modules/routing/debugcli/{debugcli.c => debugcli.cc} (97%) rename server/modules/routing/debugcli/{debugcmd.c => debugcmd.cc} (88%) rename server/modules/routing/maxinfo/{maxinfo.c => maxinfo.cc} (98%) rename server/modules/routing/maxinfo/{maxinfo_error.c => maxinfo_error.cc} (96%) rename server/modules/routing/maxinfo/{maxinfo_exec.c => maxinfo_exec.cc} (96%) rename server/modules/routing/maxinfo/{maxinfo_parse.c => maxinfo_parse.cc} (99%) rename server/modules/routing/readconnroute/{readconnroute.c => readconnroute.cc} (99%) diff --git a/avro/maxavro.h b/avro/maxavro.h index f4b103354..5f64537a5 100644 --- a/avro/maxavro.h +++ b/avro/maxavro.h @@ -1,5 +1,4 @@ -#ifndef _MAXAVRO_H -#define _MAXAVRO_H +#pragma once /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -20,6 +19,8 @@ #include #include +MXS_BEGIN_DECLS + /** File magic and sync marker sizes block sizes */ #define AVRO_MAGIC_SIZE 4 #define SYNC_MARKER_SIZE 16 @@ -154,4 +155,4 @@ GWBUF* maxavro_file_binary_header(MAXAVRO_FILE *file); enum maxavro_error maxavro_get_error(MAXAVRO_FILE *file); const char* maxavro_get_error_string(MAXAVRO_FILE *file); -#endif +MXS_END_DECLS diff --git a/server/modules/routing/CMakeLists.txt b/server/modules/routing/CMakeLists.txt index 54f6fa959..709829aa9 100644 --- a/server/modules/routing/CMakeLists.txt +++ b/server/modules/routing/CMakeLists.txt @@ -5,6 +5,7 @@ if(BUILD_BINLOG) add_subdirectory(binlogrouter) endif() +add_subdirectory(cat) add_subdirectory(cli) add_subdirectory(debugcli) add_subdirectory(hintrouter) @@ -12,6 +13,5 @@ add_subdirectory(maxinfo) add_subdirectory(readconnroute) add_subdirectory(readwritesplit) add_subdirectory(schemarouter) -add_subdirectory(cat) diff --git a/server/modules/routing/avrorouter/CMakeLists.txt b/server/modules/routing/avrorouter/CMakeLists.txt index 6ef88d671..74a999f4c 100644 --- a/server/modules/routing/avrorouter/CMakeLists.txt +++ b/server/modules/routing/avrorouter/CMakeLists.txt @@ -1,7 +1,7 @@ if(AVRO_FOUND AND JANSSON_FOUND) include_directories(${AVRO_INCLUDE_DIR}) include_directories(${JANSSON_INCLUDE_DIR}) - add_library(avrorouter SHARED avro.c ../binlogrouter/binlog_common.c avro_client.c avro_schema.c avro_rbr.c avro_file.c avro_index.c) + add_library(avrorouter SHARED avro.cc ../binlogrouter/binlog_common.cc avro_client.cc avro_schema.cc avro_rbr.cc avro_file.cc avro_index.cc) set_target_properties(avrorouter PROPERTIES VERSION "1.0.0") set_target_properties(avrorouter PROPERTIES LINK_FLAGS -Wl,-z,defs) target_link_libraries(avrorouter maxscale-common ${JANSSON_LIBRARIES} ${AVRO_LIBRARIES} maxavro lzma) diff --git a/server/modules/routing/avrorouter/avro.c b/server/modules/routing/avrorouter/avro.cc similarity index 98% rename from server/modules/routing/avrorouter/avro.c rename to server/modules/routing/avrorouter/avro.cc index 1b78b90f3..7465825a1 100644 --- a/server/modules/routing/avrorouter/avro.c +++ b/server/modules/routing/avrorouter/avro.cc @@ -195,7 +195,7 @@ static bool avro_handle_purge(const MODULECMD_ARG *args, json_t** output) * * @return The module object */ -MXS_MODULE* MXS_CREATE_MODULE() +extern "C" MXS_MODULE* MXS_CREATE_MODULE() { spinlock_init(&instlock); instances = NULL; @@ -297,7 +297,7 @@ bool create_tables(sqlite3* handle) NULL, NULL, &errmsg); if (rc != SQLITE_OK) { - MXS_ERROR("Failed to create GTID index table '"GTID_TABLE_NAME"': %s", + MXS_ERROR("Failed to create GTID index table '" GTID_TABLE_NAME "': %s", sqlite3_errmsg(handle)); sqlite3_free(errmsg); return false; @@ -310,7 +310,7 @@ bool create_tables(sqlite3* handle) NULL, NULL, &errmsg); if (rc != SQLITE_OK) { - MXS_ERROR("Failed to create used tables table '"USED_TABLES_TABLE_NAME"': %s", + MXS_ERROR("Failed to create used tables table '" USED_TABLES_TABLE_NAME "': %s", sqlite3_errmsg(handle)); sqlite3_free(errmsg); return false; @@ -321,17 +321,17 @@ bool create_tables(sqlite3* handle) NULL, NULL, &errmsg); if (rc != SQLITE_OK) { - MXS_ERROR("Failed to create indexing progress table '"INDEX_TABLE_NAME"': %s", + MXS_ERROR("Failed to create indexing progress table '" INDEX_TABLE_NAME "': %s", sqlite3_errmsg(handle)); sqlite3_free(errmsg); return false; } - rc = sqlite3_exec(handle, "ATTACH DATABASE ':memory:' AS "MEMORY_DATABASE_NAME, + rc = sqlite3_exec(handle, "ATTACH DATABASE ':memory:' AS " MEMORY_DATABASE_NAME, NULL, NULL, &errmsg); if (rc != SQLITE_OK) { - MXS_ERROR("Failed to attach in-memory database '"MEMORY_DATABASE_NAME"': %s", + MXS_ERROR("Failed to attach in-memory database '" MEMORY_DATABASE_NAME "': %s", sqlite3_errmsg(handle)); sqlite3_free(errmsg); return false; @@ -344,8 +344,8 @@ bool create_tables(sqlite3* handle) NULL, NULL, &errmsg); if (rc != SQLITE_OK) { - MXS_ERROR("Failed to create in-memory used tables table '"MEMORY_DATABASE_NAME - "."MEMORY_TABLE_NAME"': %s", + MXS_ERROR("Failed to create in-memory used tables table '" MEMORY_DATABASE_NAME + "." MEMORY_TABLE_NAME "': %s", sqlite3_errmsg(handle)); sqlite3_free(errmsg); return false; @@ -479,7 +479,7 @@ createInstance(SERVICE *service, char **options) AVRO_INSTANCE *inst; int i; - if ((inst = MXS_CALLOC(1, sizeof(AVRO_INSTANCE))) == NULL) + if ((inst = static_cast(MXS_CALLOC(1, sizeof(AVRO_INSTANCE)))) == NULL) { return NULL; } @@ -506,7 +506,7 @@ createInstance(SERVICE *service, char **options) inst->fileroot = MXS_STRDUP_A(config_get_string(params, "filestem")); inst->row_target = config_get_integer(params, "group_rows"); inst->trx_target = config_get_integer(params, "group_trx"); - inst->codec = config_get_enum(params, "codec", codec_values); + inst->codec = static_cast(config_get_enum(params, "codec", codec_values)); int first_file = config_get_integer(params, "start_index"); inst->block_size = config_get_size(params, "block_size"); @@ -798,7 +798,7 @@ newSession(MXS_ROUTER *instance, MXS_SESSION *session) CHK_CLIENT_RSES(client); - return (void *) client; + return reinterpret_cast(client); } /** diff --git a/server/modules/routing/avrorouter/avro_client.c b/server/modules/routing/avrorouter/avro_client.cc similarity index 99% rename from server/modules/routing/avrorouter/avro_client.c rename to server/modules/routing/avrorouter/avro_client.cc index bc454477d..ebbfa947e 100644 --- a/server/modules/routing/avrorouter/avro_client.c +++ b/server/modules/routing/avrorouter/avro_client.cc @@ -156,7 +156,7 @@ avro_client_do_registration(AVRO_INSTANCE *router, AVRO_CLIENT *client, GWBUF *d *sep_ptr = '\0'; } - if (strlen(uuid) < uuid_len) + if (strlen(uuid) < static_cast(uuid_len)) { data_len -= (uuid_len - strlen(uuid)); } @@ -288,7 +288,7 @@ int gtid_query_cb_plain(void* data, int ncolumns, char** values, char** names) void add_used_tables(sqlite3 *handle, json_t* obj, gtid_pos_t* gtid) { char sql[AVRO_SQL_BUFFER_SIZE]; - snprintf(sql, sizeof(sql), "SELECT table_name FROM "USED_TABLES_TABLE_NAME + snprintf(sql, sizeof(sql), "SELECT table_name FROM " USED_TABLES_TABLE_NAME " WHERE domain = %lu AND server_id = %lu AND sequence = %lu", gtid->domain, gtid->server_id, gtid->seq); @@ -320,7 +320,7 @@ void avro_get_used_tables(AVRO_INSTANCE *router, DCB* dcb) { sqlite3 *handle = router->sqlite_handle; char sql[AVRO_SQL_BUFFER_SIZE]; - snprintf(sql, sizeof(sql), "SELECT table_name FROM "USED_TABLES_TABLE_NAME + snprintf(sql, sizeof(sql), "SELECT table_name FROM " USED_TABLES_TABLE_NAME " WHERE domain = %lu AND server_id = %lu AND sequence = %lu", router->gtid.domain, router->gtid.server_id, router->gtid.seq); @@ -366,7 +366,7 @@ int timestamp_query_cb(void* data, int ncolumns, char** values, char** names) void add_timestamp(sqlite3 *handle, json_t* obj, gtid_pos_t* gtid) { char sql[AVRO_SQL_BUFFER_SIZE]; - snprintf(sql, sizeof(sql), "SELECT DISTINCT binlog_timestamp FROM "USED_TABLES_TABLE_NAME + snprintf(sql, sizeof(sql), "SELECT DISTINCT binlog_timestamp FROM " USED_TABLES_TABLE_NAME " WHERE domain = %lu AND server_id = %lu AND sequence = %lu", gtid->domain, gtid->server_id, gtid->seq); diff --git a/server/modules/routing/avrorouter/avro_file.c b/server/modules/routing/avrorouter/avro_file.cc similarity index 96% rename from server/modules/routing/avrorouter/avro_file.c rename to server/modules/routing/avrorouter/avro_file.cc index d37da88ce..fcd2196d4 100644 --- a/server/modules/routing/avrorouter/avro_file.c +++ b/server/modules/routing/avrorouter/avro_file.cc @@ -103,7 +103,7 @@ void avro_close_binlog(int fd) AVRO_TABLE* avro_table_alloc(const char* filepath, const char* json_schema, const char *codec, size_t block_size) { - AVRO_TABLE *table = MXS_CALLOC(1, sizeof(AVRO_TABLE)); + AVRO_TABLE *table = static_cast(MXS_CALLOC(1, sizeof(AVRO_TABLE))); if (table) { if (avro_schema_from_json_length(json_schema, strlen(json_schema), @@ -163,7 +163,7 @@ bool avro_save_conversion_state(AVRO_INSTANCE *router) FILE *config_file; char filename[PATH_MAX + 1]; - snprintf(filename, sizeof(filename), "%s/"AVRO_PROGRESS_FILE".tmp", router->avrodir); + snprintf(filename, sizeof(filename), "%s/" AVRO_PROGRESS_FILE ".tmp", router->avrodir); /* open file for writing */ config_file = fopen(filename, "wb"); @@ -184,7 +184,7 @@ bool avro_save_conversion_state(AVRO_INSTANCE *router) /* rename tmp file to right filename */ char newname[PATH_MAX + 1]; - snprintf(newname, sizeof(newname), "%s/"AVRO_PROGRESS_FILE, router->avrodir); + snprintf(newname, sizeof(newname), "%s/" AVRO_PROGRESS_FILE, router->avrodir); int rc = rename(filename, newname); if (rc == -1) @@ -266,7 +266,7 @@ bool avro_load_conversion_state(AVRO_INSTANCE *router) char filename[PATH_MAX + 1]; bool rval = false; - snprintf(filename, sizeof(filename), "%s/"AVRO_PROGRESS_FILE, router->avrodir); + snprintf(filename, sizeof(filename), "%s/" AVRO_PROGRESS_FILE, router->avrodir); /** No stored state, this is the first time the router is started */ if (access(filename, F_OK) == -1) @@ -340,7 +340,7 @@ static avro_binlog_end_t rotate_to_next_file_if_exists(AVRO_INSTANCE* router, ui char next_binlog[BINLOG_FNAMELEN + 1]; if (snprintf(next_binlog, sizeof(next_binlog), BINLOG_NAMEFMT, router->fileroot, - blr_file_get_next_binlogname(router->binlog_name)) >= sizeof(next_binlog)) + blr_file_get_next_binlogname(router->binlog_name)) >= (int)sizeof(next_binlog)) { MXS_ERROR("Next binlog name did not fit into the allocated buffer " "but was truncated, aborting: %s", next_binlog); @@ -416,7 +416,7 @@ static GWBUF* read_event_data(AVRO_INSTANCE *router, REP_HEADER* hdr, uint64_t p /** NULL-terminate for QUERY_EVENT processing */ data[hdr->event_size - BINLOG_EVENT_HDR_LEN] = '\0'; - if (n != hdr->event_size - BINLOG_EVENT_HDR_LEN) + if (n != static_cast(hdr->event_size - BINLOG_EVENT_HDR_LEN)) { if (n == -1) { @@ -824,7 +824,8 @@ void avro_load_metadata_from_schemas(AVRO_INSTANCE *router) if (versionend == suffix) { snprintf(table_ident, sizeof(table_ident), "%s.%s", db, table); - TABLE_CREATE *old = hashtable_fetch(router->created_tables, table_ident); + TABLE_CREATE *old = + static_cast(hashtable_fetch(router->created_tables, table_ident)); if (old == NULL || version > old->version) { @@ -860,7 +861,7 @@ void avro_flush_all_tables(AVRO_INSTANCE *router, enum avrorouter_file_op flush) char *key; while ((key = (char*)hashtable_next(iter))) { - AVRO_TABLE *table = hashtable_fetch(router->open_tables, key); + AVRO_TABLE *table = static_cast(hashtable_fetch(router->open_tables, key)); if (table) { @@ -974,18 +975,18 @@ bool save_and_replace_table_create(AVRO_INSTANCE *router, TABLE_CREATE *created) snprintf(table_ident, sizeof(table_ident), "%s.%s", created->database, created->table); spinlock_acquire(&router->lock); // Is this necessary? - TABLE_CREATE *old = hashtable_fetch(router->created_tables, table_ident); + TABLE_CREATE *old = static_cast(hashtable_fetch(router->created_tables, table_ident)); if (old) { HASHITERATOR *iter = hashtable_iterator(router->table_maps); char *key; - while ((key = hashtable_next(iter))) + while ((key = static_cast(hashtable_next(iter)))) { if (strcmp(key, table_ident) == 0) { - TABLE_MAP* map = hashtable_fetch(router->table_maps, key); + TABLE_MAP* map = static_cast(hashtable_fetch(router->table_maps, key)); router->active_maps[map->id % MAX_MAPPED_TABLES] = NULL; hashtable_delete(router->table_maps, key); } @@ -1066,7 +1067,7 @@ void handle_query_event(AVRO_INSTANCE *router, REP_HEADER *hdr, int *pending_tra db[dblen] = 0; size_t sqlsz = len, tmpsz = len; - char *tmp = MXS_MALLOC(len + 1); + char *tmp = static_cast(MXS_MALLOC(len + 1)); MXS_ABORT_IF_NULL(tmp); remove_mysql_comments((const char**)&sql, &sqlsz, &tmp, &tmpsz); sql = tmp; @@ -1126,7 +1127,7 @@ void handle_query_event(AVRO_INSTANCE *router, REP_HEADER *hdr, int *pending_tra } else if (is_alter_table_statement(router, sql, len)) { - TABLE_CREATE *created = hashtable_fetch(router->created_tables, ident); + TABLE_CREATE *created = static_cast(hashtable_fetch(router->created_tables, ident)); if (created) { diff --git a/server/modules/routing/avrorouter/avro_index.c b/server/modules/routing/avrorouter/avro_index.cc similarity index 92% rename from server/modules/routing/avrorouter/avro_index.c rename to server/modules/routing/avrorouter/avro_index.cc index 4de727e3d..06d0e726d 100644 --- a/server/modules/routing/avrorouter/avro_index.c +++ b/server/modules/routing/avrorouter/avro_index.cc @@ -76,7 +76,7 @@ void avro_index_file(AVRO_INSTANCE *router, const char* filename) if (file) { - char *name = strrchr(filename, '/'); + const char *name = strrchr(filename, '/'); ss_dassert(name); if (name) @@ -86,7 +86,7 @@ void avro_index_file(AVRO_INSTANCE *router, const char* filename) long pos = -1; name++; - snprintf(sql, sizeof(sql), "SELECT position FROM "INDEX_TABLE_NAME + snprintf(sql, sizeof(sql), "SELECT position FROM " INDEX_TABLE_NAME " WHERE filename=\"%s\";", name); if (sqlite3_exec(router->sqlite_handle, sql, index_query_cb, &pos, &errmsg) != SQLITE_OK) @@ -155,7 +155,7 @@ void avro_index_file(AVRO_INSTANCE *router, const char* filename) } sqlite3_free(errmsg); - snprintf(sql, sizeof(sql), "INSERT OR REPLACE INTO "INDEX_TABLE_NAME + snprintf(sql, sizeof(sql), "INSERT OR REPLACE INTO " INDEX_TABLE_NAME " values (%lu, \"%s\");", file->block_start_pos, name); if (sqlite3_exec(router->sqlite_handle, sql, NULL, NULL, &errmsg) != SQLITE_OK) @@ -194,7 +194,7 @@ void avro_update_index(AVRO_INSTANCE* router) if (glob(path, 0, NULL, &files) != GLOB_NOMATCH) { - for (int i = 0; i < files.gl_pathc; i++) + for (size_t i = 0; i < files.gl_pathc; i++) { avro_index_file(router, files.gl_pathv[i]); } @@ -204,7 +204,7 @@ void avro_update_index(AVRO_INSTANCE* router) } /** The SQL for the in-memory used_tables table */ -static const char *insert_sql = "INSERT OR IGNORE INTO "MEMORY_TABLE_NAME +static const char *insert_sql = "INSERT OR IGNORE INTO " MEMORY_TABLE_NAME "(domain, server_id, sequence, binlog_timestamp, table_name)" " VALUES (%lu, %lu, %lu, %u, \"%s\")"; @@ -217,7 +217,7 @@ static const char *insert_sql = "INSERT OR IGNORE INTO "MEMORY_TABLE_NAME * @param router Avro router instance * @param table Table to add */ -void add_used_table(AVRO_INSTANCE* router, char* table) +void add_used_table(AVRO_INSTANCE* router, const char* table) { char sql[AVRO_SQL_BUFFER_SIZE], *errmsg; snprintf(sql, sizeof(sql), insert_sql, router->gtid.domain, router->gtid.server_id, @@ -244,14 +244,14 @@ void update_used_tables(AVRO_INSTANCE* router) { char *errmsg; - if (sqlite3_exec(router->sqlite_handle, "INSERT INTO "USED_TABLES_TABLE_NAME - " SELECT * FROM "MEMORY_TABLE_NAME, NULL, NULL, &errmsg) != SQLITE_OK) + if (sqlite3_exec(router->sqlite_handle, "INSERT INTO " USED_TABLES_TABLE_NAME + " SELECT * FROM " MEMORY_TABLE_NAME, NULL, NULL, &errmsg) != SQLITE_OK) { MXS_ERROR("Failed to transfer used table data from memory to disk: %s", errmsg); } sqlite3_free(errmsg); - if (sqlite3_exec(router->sqlite_handle, "DELETE FROM "MEMORY_TABLE_NAME, + if (sqlite3_exec(router->sqlite_handle, "DELETE FROM " MEMORY_TABLE_NAME, NULL, NULL, &errmsg) != SQLITE_OK) { MXS_ERROR("Failed to transfer used table data from memory to disk: %s", errmsg); diff --git a/server/modules/routing/avrorouter/avro_rbr.c b/server/modules/routing/avrorouter/avro_rbr.cc similarity index 98% rename from server/modules/routing/avrorouter/avro_rbr.c rename to server/modules/routing/avrorouter/avro_rbr.cc index 38d57ed07..7cc8ba90e 100644 --- a/server/modules/routing/avrorouter/avro_rbr.c +++ b/server/modules/routing/avrorouter/avro_rbr.cc @@ -100,12 +100,12 @@ bool handle_table_map_event(AVRO_INSTANCE *router, REP_HEADER *hdr, uint8_t *ptr int ev_len = router->event_type_hdr_lens[hdr->event_type]; read_table_info(ptr, ev_len, &id, table_ident, sizeof(table_ident)); - TABLE_CREATE* create = hashtable_fetch(router->created_tables, table_ident); + TABLE_CREATE* create = static_cast(hashtable_fetch(router->created_tables, table_ident)); if (create) { ss_dassert(create->columns > 0); - TABLE_MAP *old = hashtable_fetch(router->table_maps, table_ident); + TABLE_MAP *old = static_cast(hashtable_fetch(router->table_maps, table_ident)); TABLE_MAP *map = table_map_alloc(ptr, ev_len, create); MXS_ABORT_IF_NULL(map); // Fatal error at this point @@ -292,7 +292,7 @@ bool handle_row_event(AVRO_INSTANCE *router, REP_HEADER *hdr, uint8_t *ptr) { char table_ident[MYSQL_TABLE_MAXLEN + MYSQL_DATABASE_MAXLEN + 2]; snprintf(table_ident, sizeof(table_ident), "%s.%s", map->database, map->table); - AVRO_TABLE* table = hashtable_fetch(router->open_tables, table_ident); + AVRO_TABLE* table = static_cast(hashtable_fetch(router->open_tables, table_ident)); TABLE_CREATE* create = map->table_create; ss_dassert(hashtable_fetch(router->created_tables, table_ident) == create); diff --git a/server/modules/routing/avrorouter/avro_schema.c b/server/modules/routing/avrorouter/avro_schema.cc similarity index 94% rename from server/modules/routing/avrorouter/avro_schema.c rename to server/modules/routing/avrorouter/avro_schema.cc index c6a29279b..49b3b54e2 100644 --- a/server/modules/routing/avrorouter/avro_schema.c +++ b/server/modules/routing/avrorouter/avro_schema.cc @@ -642,9 +642,9 @@ int count_columns(const char* ptr) static int process_column_definition(const char *nameptr, char*** dest, char*** dest_types, int** dest_lens) { int n = count_columns(nameptr); - *dest = MXS_MALLOC(sizeof(char*) * n); - *dest_types = MXS_MALLOC(sizeof(char*) * n); - *dest_lens = MXS_MALLOC(sizeof(int) * n); + *dest = static_cast(MXS_MALLOC(sizeof(char*) * n)); + *dest_types = static_cast(MXS_MALLOC(sizeof(char*) * n)); + *dest_lens = static_cast(MXS_MALLOC(sizeof(int) * n)); char **names = *dest; char **types = *dest_types; @@ -727,7 +727,7 @@ int resolve_table_version(const char* db, const char* table) * * @return New CREATE_TABLE object or NULL if an error occurred */ -TABLE_CREATE* table_create_alloc(const char* ident, const char* sql, int len) +TABLE_CREATE* table_create_alloc(char* ident, const char* sql, int len) { /** Extract the table definition so we can get the column names from it */ int stmt_len = 0; @@ -753,7 +753,7 @@ TABLE_CREATE* table_create_alloc(const char* ident, const char* sql, int len) TABLE_CREATE *rval = NULL; if (n_columns > 0) { - if ((rval = MXS_MALLOC(sizeof(TABLE_CREATE)))) + if ((rval = static_cast(MXS_MALLOC(sizeof(TABLE_CREATE))))) { rval->version = resolve_table_version(database, table); rval->was_used = false; @@ -990,15 +990,15 @@ TABLE_CREATE* table_create_copy(AVRO_INSTANCE *router, const char* sql, size_t l strcat(table_ident, source); - TABLE_CREATE *old = hashtable_fetch(router->created_tables, table_ident); + TABLE_CREATE *old = static_cast(hashtable_fetch(router->created_tables, table_ident)); if (old) { int n = old->columns; - char** names = MXS_MALLOC(sizeof(char*) * n); - char** types = MXS_MALLOC(sizeof(char*) * n); - int* lengths = MXS_MALLOC(sizeof(int) * n); - rval = MXS_MALLOC(sizeof(TABLE_CREATE)); + char** names = static_cast(MXS_MALLOC(sizeof(char*) * n)); + char** types = static_cast(MXS_MALLOC(sizeof(char*) * n)); + int* lengths = static_cast(MXS_MALLOC(sizeof(int) * n)); + rval = static_cast(MXS_MALLOC(sizeof(TABLE_CREATE))); MXS_ABORT_IF_FALSE(names && types && lengths && rval); @@ -1402,7 +1402,7 @@ int get_column_index(TABLE_CREATE *create, const char *tok, int len) fix_reserved_word(safe_tok); - for (int x = 0; x < create->columns; x++) + for (size_t x = 0; x < create->columns; x++) { if (strcasecmp(create->column_names[x], safe_tok) == 0) { @@ -1496,9 +1496,15 @@ bool table_create_alter(TABLE_CREATE *create, const char *sql, const char *end) if (is_new) { - create->column_names = MXS_REALLOC(create->column_names, sizeof(char*) * (create->columns + 1)); - create->column_types = MXS_REALLOC(create->column_types, sizeof(char*) * (create->columns + 1)); - create->column_lengths = MXS_REALLOC(create->column_lengths, sizeof(int) * (create->columns + 1)); + create->column_names = + static_cast(MXS_REALLOC(create->column_names, + sizeof(char*) * (create->columns + 1))); + create->column_types = + static_cast(MXS_REALLOC(create->column_types, + sizeof(char*) * (create->columns + 1))); + create->column_lengths = + static_cast(MXS_REALLOC(create->column_lengths, + sizeof(int) * (create->columns + 1))); char field_type[200] = ""; // Enough to hold all types int field_length = extract_type_length(tok + len, field_type); @@ -1526,9 +1532,15 @@ bool table_create_alter(TABLE_CREATE *create, const char *sql, const char *end) create->column_lengths[i] = create->column_lengths[i + 1]; } - create->column_names = MXS_REALLOC(create->column_names, sizeof(char*) * (create->columns - 1)); - create->column_types = MXS_REALLOC(create->column_types, sizeof(char*) * (create->columns - 1)); - create->column_lengths = MXS_REALLOC(create->column_lengths, sizeof(int) * (create->columns - 1)); + create->column_names = + static_cast(MXS_REALLOC(create->column_names, + sizeof(char*) * (create->columns - 1))); + create->column_types = + static_cast(MXS_REALLOC(create->column_types, + sizeof(char*) * (create->columns - 1))); + create->column_lengths = + static_cast(MXS_REALLOC(create->column_lengths, + sizeof(int) * (create->columns - 1))); create->columns--; updates++; } @@ -1657,7 +1669,7 @@ TABLE_MAP *table_map_alloc(uint8_t *ptr, uint8_t hdr_len, TABLE_CREATE* create) uint8_t* metadata = (uint8_t*)mxs_lestr_consume(&ptr, &metadata_size); uint8_t *nullmap = ptr; size_t nullmap_size = (column_count + 7) / 8; - TABLE_MAP *map = MXS_MALLOC(sizeof(TABLE_MAP)); + TABLE_MAP *map = static_cast(MXS_MALLOC(sizeof(TABLE_MAP))); if (map) { @@ -1665,11 +1677,11 @@ TABLE_MAP *table_map_alloc(uint8_t *ptr, uint8_t hdr_len, TABLE_CREATE* create) map->version = create->version; map->flags = flags; map->columns = column_count; - map->column_types = MXS_MALLOC(column_count); + map->column_types = static_cast(MXS_MALLOC(column_count)); /** Allocate at least one byte for the metadata */ - map->column_metadata = MXS_CALLOC(1, metadata_size + 1); + map->column_metadata = static_cast(MXS_CALLOC(1, metadata_size + 1)); map->column_metadata_size = metadata_size; - map->null_bitmap = MXS_MALLOC(nullmap_size); + map->null_bitmap = static_cast(MXS_MALLOC(nullmap_size)); map->database = MXS_STRDUP(schema_name); map->table = MXS_STRDUP(table_name); map->table_create = create; diff --git a/server/modules/routing/avrorouter/avrorouter.h b/server/modules/routing/avrorouter/avrorouter.h index 67029e1c5..9daa1c7ff 100644 --- a/server/modules/routing/avrorouter/avrorouter.h +++ b/server/modules/routing/avrorouter/avrorouter.h @@ -73,8 +73,8 @@ MXS_BEGIN_DECLS #define AVRO_MAX_FILENAME_LEN 255 #endif -static char *avro_client_states[] = { "Unregistered", "Registered", "Processing", "Errored" }; -static char *avro_client_client_mode[] = { "Catch-up", "Busy", "Wait_for_data" }; +static const char *avro_client_states[] = { "Unregistered", "Registered", "Processing", "Errored" }; +static const char *avro_client_client_mode[] = { "Catch-up", "Busy", "Wait_for_data" }; static const char *avro_domain = "domain"; static const char *avro_server_id = "server_id"; @@ -82,7 +82,7 @@ static const char *avro_sequence = "sequence"; static const char *avro_event_number = "event_number"; static const char *avro_event_type = "event_type"; static const char *avro_timestamp = "timestamp"; -static char *avro_client_ouput[] = { "Undefined", "JSON", "Avro" }; +static const char *avro_client_ouput[] = { "Undefined", "JSON", "Avro" }; static inline bool is_reserved_word(const char* word) { @@ -310,7 +310,7 @@ extern void read_table_info(uint8_t *ptr, uint8_t post_header_len, uint64_t *tab char* dest, size_t len); extern TABLE_MAP *table_map_alloc(uint8_t *ptr, uint8_t hdr_len, TABLE_CREATE* create); extern void table_map_free(TABLE_MAP *map); -extern TABLE_CREATE* table_create_alloc(const char* ident, const char* sql, int len); +extern TABLE_CREATE* table_create_alloc(char* ident, const char* sql, int len); extern TABLE_CREATE* table_create_copy(AVRO_INSTANCE *router, const char* sql, size_t len, const char* db); extern void table_create_free(TABLE_CREATE* value); extern bool table_create_save(TABLE_CREATE *create, const char *filename); diff --git a/server/modules/routing/avrorouter/test/CMakeLists.txt b/server/modules/routing/avrorouter/test/CMakeLists.txt index 016461f38..1a2bfb627 100644 --- a/server/modules/routing/avrorouter/test/CMakeLists.txt +++ b/server/modules/routing/avrorouter/test/CMakeLists.txt @@ -1,3 +1,3 @@ -add_executable(test_alter_parsing test_alter_parsing.c) +add_executable(test_alter_parsing test_alter_parsing.cc) target_link_libraries(test_alter_parsing maxscale-common ${JANSSON_LIBRARIES} ${AVRO_LIBRARIES} maxavro sqlite3 lzma) -add_test(test_alter_parsing test_alter_parsing) \ No newline at end of file +add_test(test_alter_parsing test_alter_parsing) diff --git a/server/modules/routing/avrorouter/test/test_alter_parsing.c b/server/modules/routing/avrorouter/test/test_alter_parsing.cc similarity index 99% rename from server/modules/routing/avrorouter/test/test_alter_parsing.c rename to server/modules/routing/avrorouter/test/test_alter_parsing.cc index c622d6e75..1af4d9d73 100644 --- a/server/modules/routing/avrorouter/test/test_alter_parsing.c +++ b/server/modules/routing/avrorouter/test/test_alter_parsing.cc @@ -1,4 +1,4 @@ -#include "../avro_schema.c" +#include "../avro_schema.cc" static struct { diff --git a/server/modules/routing/binlogrouter/CMakeLists.txt b/server/modules/routing/binlogrouter/CMakeLists.txt index a847e9792..8dd4c516c 100644 --- a/server/modules/routing/binlogrouter/CMakeLists.txt +++ b/server/modules/routing/binlogrouter/CMakeLists.txt @@ -1,10 +1,10 @@ -add_library(binlogrouter SHARED blr.c blr_master.c blr_cache.c blr_slave.c blr_file.c) +add_library(binlogrouter SHARED blr.cc blr_master.cc blr_cache.cc blr_slave.cc blr_file.cc) set_target_properties(binlogrouter PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_LIBDIR} VERSION "2.0.0") set_target_properties(binlogrouter PROPERTIES LINK_FLAGS -Wl,-z,defs) target_link_libraries(binlogrouter maxscale-common ${PCRE_LINK_FLAGS} uuid) install_module(binlogrouter core) -add_executable(maxbinlogcheck maxbinlogcheck.c blr_file.c blr_cache.c blr_master.c blr_slave.c blr.c) +add_executable(maxbinlogcheck maxbinlogcheck.cc blr_file.cc blr_cache.cc blr_master.cc blr_slave.cc blr.cc) target_link_libraries(maxbinlogcheck maxscale-common ${PCRE_LINK_FLAGS} uuid) install_executable(maxbinlogcheck core) diff --git a/server/modules/routing/binlogrouter/binlog_common.c b/server/modules/routing/binlogrouter/binlog_common.cc similarity index 98% rename from server/modules/routing/binlogrouter/binlog_common.c rename to server/modules/routing/binlogrouter/binlog_common.cc index ccc2c4340..e41769a43 100644 --- a/server/modules/routing/binlogrouter/binlog_common.c +++ b/server/modules/routing/binlogrouter/binlog_common.cc @@ -43,7 +43,7 @@ */ int blr_file_get_next_binlogname(const char *binlog_name) { - char *sptr; + const char *sptr; int filenum; if ((sptr = strrchr(binlog_name, '.')) == NULL) @@ -72,7 +72,7 @@ bool binlog_next_file_exists(const char* binlogdir, const char* binlog) if (filenum) { - char *sptr = strrchr(binlog, '.'); + const char *sptr = strrchr(binlog, '.'); if (sptr) { diff --git a/server/modules/routing/binlogrouter/blr.c b/server/modules/routing/binlogrouter/blr.cc similarity index 99% rename from server/modules/routing/binlogrouter/blr.c rename to server/modules/routing/binlogrouter/blr.cc index 7abce8c96..66ea72ed1 100644 --- a/server/modules/routing/binlogrouter/blr.c +++ b/server/modules/routing/binlogrouter/blr.cc @@ -135,7 +135,7 @@ static const MXS_ENUM_VALUE binlog_storage_values[] = * * @return The module object */ -MXS_MODULE* MXS_CREATE_MODULE() +extern "C" MXS_MODULE* MXS_CREATE_MODULE() { MXS_NOTICE("Initialise binlog router module."); spinlock_init(&instlock); @@ -810,7 +810,8 @@ createInstance(SERVICE *service, char **options) } /* Allocate SSL struct for backend connection */ - if ((ssl_cfg = MXS_CALLOC(1, sizeof(SSL_LISTENER))) == NULL) + if ((ssl_cfg = + static_cast(MXS_CALLOC(1, sizeof(SSL_LISTENER)))) == NULL) { MXS_ERROR("%s: Error allocating memory for SSL struct in createInstance", inst->service->name); @@ -1236,7 +1237,7 @@ newSession(MXS_ROUTER *instance, MXS_SESSION *session) CHK_CLIENT_RSES(slave); - return (void *)slave; + return reinterpret_cast(slave); } /** @@ -1417,7 +1418,7 @@ routeQuery(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session, GWBUF *queu return blr_slave_request(router, slave, queue); } -static char *event_names[] = +static const char *event_names[] = { "Invalid", "Start Event V3", "Query Event", "Stop Event", "Rotate Event", "Integer Session Variable", "Load Event", "Slave Event", "Create File Event", @@ -1433,7 +1434,7 @@ static char *event_names[] = }; /* New MariaDB event numbers starts from 0xa0 */ -static char *event_names_mariadb10[] = +static const char *event_names_mariadb10[] = { "Annotate Rows Event", /* New MariaDB 10.x event numbers */ @@ -1641,7 +1642,7 @@ diagnostics(MXS_ROUTER *router, DCB *dcb) } else { - char *ptr = NULL; + const char *ptr = NULL; if (router_inst->lastEventReceived <= MAX_EVENT_TYPE) { ptr = event_names[router_inst->lastEventReceived]; @@ -2061,7 +2062,7 @@ static json_t* diagnostics_json(const MXS_ROUTER *router) } else { - char *ptr = NULL; + const char *ptr = NULL; if (router_inst->lastEventReceived <= MAX_EVENT_TYPE) { ptr = event_names[router_inst->lastEventReceived]; @@ -2623,7 +2624,7 @@ blr_send_custom_error(DCB *dcb, int packet_number, int affected_rows, const char *msg, - char *statemsg, + const char *statemsg, unsigned int errcode) { uint8_t *outbuf = NULL; @@ -2967,10 +2968,10 @@ static int blr_check_binlog(ROUTER_INSTANCE *router) * @param router The router instance * @return The event description or NULL */ -char * +const char * blr_last_event_description(ROUTER_INSTANCE *router) { - char *event_desc = NULL; + const char *event_desc = NULL; if (!router->mariadb10_compat) { @@ -3006,10 +3007,10 @@ blr_last_event_description(ROUTER_INSTANCE *router) * @param event The current event * @return The event description or NULL */ -char * +const char * blr_get_event_description(ROUTER_INSTANCE *router, uint8_t event) { - char *event_desc = NULL; + const char *event_desc = NULL; if (!router->mariadb10_compat) { diff --git a/server/modules/routing/binlogrouter/blr.h b/server/modules/routing/binlogrouter/blr.h index 4d9722434..6f1e45a19 100644 --- a/server/modules/routing/binlogrouter/blr.h +++ b/server/modules/routing/binlogrouter/blr.h @@ -473,6 +473,23 @@ typedef enum blr_thread_role r == BLR_THREAD_ROLE_MASTER_NOTRX ? "master (no trx)" : \ r == BLR_THREAD_ROLE_MASTER_TRX ? "master (trx)" : "slave" +/** + * Binlog encryption context of slave binlog file + */ + +typedef struct slave_encryption_ctx +{ + uint8_t binlog_crypto_scheme; /**< Encryption scheme */ + uint32_t binlog_key_version; /**< Encryption key version */ + uint8_t nonce[AES_BLOCK_SIZE]; /**< nonce (random bytes) of current binlog. + * These bytes + the binlog event current pos + * form the encrryption IV for the event */ + char *log_file; /**< The log file the client has requested */ + uint32_t first_enc_event_pos; /**< The position of first encrypted event + * It's the first event afte Start_encryption_event + * which is after FDE */ +} SLAVE_ENCRYPTION_CTX; + /** * The client session structure used within this router. This represents * the slaves that are replicating binlogs from MaxScale. @@ -525,7 +542,7 @@ typedef struct router_slave /*< Which binlog file */ uint32_t lsi_binlog_pos; /*< What position */ - void *encryption_ctx; + SLAVE_ENCRYPTION_CTX *encryption_ctx; /*< Encryption context */ bool gtid_strict_mode; /*< MariaDB 10 Slave sets gtid_strict_mode */ @@ -631,6 +648,20 @@ typedef struct pending_transaction */ } PENDING_TRANSACTION; +/** + * Binlog encryption context of binlog file + */ + +typedef struct binlog_encryption_ctx +{ + uint8_t binlog_crypto_scheme; /**< Encryption scheme */ + uint32_t binlog_key_version; /**< Encryption key version */ + uint8_t nonce[AES_BLOCK_SIZE]; /**< nonce (random bytes) of current binlog. + * These bytes + the binlog event current pos + * form the encrryption IV for the event */ + char *binlog_file; /**< Current binlog file being encrypted */ +} BINLOG_ENCRYPTION_CTX; + /** * The per instance data for the router. */ @@ -718,7 +749,7 @@ typedef struct router_instance bool request_semi_sync; /*< Request Semi-Sync replication to master */ int master_semi_sync; /*< Semi-Sync replication status of master server */ BINLOG_ENCRYPTION_SETUP encryption; /*< Binlog encryption setup */ - void *encryption_ctx; /*< Encryption context */ + BINLOG_ENCRYPTION_CTX *encryption_ctx; /*< Encryption context */ char last_mariadb_gtid[GTID_MAX_LEN + 1]; /*< Last seen MariaDB 10 GTID */ bool mariadb10_gtid; /*< Save received MariaDB GTIDs into repo. @@ -735,37 +766,6 @@ typedef struct router_instance struct router_instance *next; } ROUTER_INSTANCE; -/** - * Binlog encryption context of slave binlog file - */ - -typedef struct slave_encryption_ctx -{ - uint8_t binlog_crypto_scheme; /**< Encryption scheme */ - uint32_t binlog_key_version; /**< Encryption key version */ - uint8_t nonce[AES_BLOCK_SIZE]; /**< nonce (random bytes) of current binlog. - * These bytes + the binlog event current pos - * form the encrryption IV for the event */ - char *log_file; /**< The log file the client has requested */ - uint32_t first_enc_event_pos; /**< The position of first encrypted event - * It's the first event afte Start_encryption_event - * which is after FDE */ -} SLAVE_ENCRYPTION_CTX; - -/** - * Binlog encryption context of binlog file - */ - -typedef struct binlog_encryption_ctx -{ - uint8_t binlog_crypto_scheme; /**< Encryption scheme */ - uint32_t binlog_key_version; /**< Encryption key version */ - uint8_t nonce[AES_BLOCK_SIZE]; /**< nonce (random bytes) of current binlog. - * These bytes + the binlog event current pos - * form the encrryption IV for the event */ - char *binlog_file; /**< Current binlog file being encrypted */ -} BINLOG_ENCRYPTION_CTX; - /** * Holds information about: * truncating a corrupted file @@ -848,7 +848,7 @@ typedef struct binlog_pos_fix #define BLRM_MAXSTATE 0x0023 -static char *blrm_states[] = +static const char *blrm_states[] = { "Unconfigured", "Unconnected", @@ -896,7 +896,7 @@ static char *blrm_states[] = #define BLRS_MAXSTATE 0x0004 -static char *blrs_states[] = +static const char *blrs_states[] = { "Created", "Unregistered", @@ -987,7 +987,7 @@ extern int blr_send_custom_error(DCB *, int, int, const char *, - char *, + const char *, unsigned int); extern int blr_file_next_exists(ROUTER_INSTANCE *, ROUTER_SLAVE *, @@ -996,10 +996,10 @@ uint32_t extract_field(uint8_t *src, int bits); void blr_cache_read_master_data(ROUTER_INSTANCE *router); int blr_read_events_all_events(ROUTER_INSTANCE *, BINLOG_FILE_FIX *, int); int blr_save_dbusers(const ROUTER_INSTANCE *router); -char *blr_get_event_description(ROUTER_INSTANCE *router, uint8_t event); +const char *blr_get_event_description(ROUTER_INSTANCE *router, uint8_t event); void blr_file_append(ROUTER_INSTANCE *router, char *file); void blr_cache_response(ROUTER_INSTANCE *router, char *response, GWBUF *buf); -char * blr_last_event_description(ROUTER_INSTANCE *router); +const char *blr_last_event_description(ROUTER_INSTANCE *router); void blr_free_ssl_data(ROUTER_INSTANCE *inst); extern bool blr_send_event(blr_thread_role_t role, diff --git a/server/modules/routing/binlogrouter/blr_cache.c b/server/modules/routing/binlogrouter/blr_cache.cc similarity index 100% rename from server/modules/routing/binlogrouter/blr_cache.c rename to server/modules/routing/binlogrouter/blr_cache.cc diff --git a/server/modules/routing/binlogrouter/blr_file.c b/server/modules/routing/binlogrouter/blr_file.cc similarity index 98% rename from server/modules/routing/binlogrouter/blr_file.c rename to server/modules/routing/binlogrouter/blr_file.cc index 41625cd22..981df7504 100644 --- a/server/modules/routing/binlogrouter/blr_file.c +++ b/server/modules/routing/binlogrouter/blr_file.cc @@ -130,7 +130,7 @@ static const char blr_encryption_algorithm_list_names[] = "aes_cbc"; #endif static int blr_file_create(ROUTER_INSTANCE *router, char *file); -static void blr_log_header(int priority, char *msg, uint8_t *ptr); +static void blr_log_header(int priority, const char *msg, uint8_t *ptr); void blr_cache_read_master_data(ROUTER_INSTANCE *router); int blr_file_get_next_binlogname(ROUTER_INSTANCE *router); int blr_file_new_binlog(ROUTER_INSTANCE *router, char *file); @@ -737,7 +737,7 @@ blr_write_binlog_record(ROUTER_INSTANCE *router, } /* Check write operation result*/ - if (n != size) + if (n != static_cast(size)) { MXS_ERROR("%s: Failed to write binlog record at %lu of %s, %s. " "Truncating to previous record.", @@ -1275,7 +1275,7 @@ blr_read_binlog(ROUTER_INSTANCE *router, &data[BINLOG_EVENT_HDR_LEN], hdr->event_size - BINLOG_EVENT_HDR_LEN, pos + BINLOG_EVENT_HDR_LEN)) - != hdr->event_size - BINLOG_EVENT_HDR_LEN) // Read the balance + != static_cast(hdr->event_size - BINLOG_EVENT_HDR_LEN)) // Read the balance { if (n == 0) { @@ -1447,7 +1447,7 @@ blr_close_binlog(ROUTER_INSTANCE *router, BLFILE *file) * @param ptr The event header raw data */ static void -blr_log_header(int priority, char *msg, uint8_t *ptr) +blr_log_header(int priority, const char *msg, uint8_t *ptr) { char buf[400], *bufp; int i; @@ -1551,7 +1551,7 @@ blr_cache_response(ROUTER_INSTANCE *router, char *response, GWBUF *buf) * @return A pointer to a GWBUF structure */ GWBUF * -blr_cache_read_response(ROUTER_INSTANCE *router, char *response) +blr_cache_read_response(ROUTER_INSTANCE *router, const char *response) { static const char CACHE[] = "/cache"; size_t len = strlen(router->binlogdir) + @@ -2127,10 +2127,11 @@ blr_read_events_all_events(ROUTER_INSTANCE *router, memcpy(data, hdbuf, BINLOG_EVENT_HDR_LEN);// Copy the header in /* Read event data */ - if ((n = pread(router->binlog_fd, - &data[BINLOG_EVENT_HDR_LEN], - hdr.event_size - BINLOG_EVENT_HDR_LEN, - pos + BINLOG_EVENT_HDR_LEN)) != hdr.event_size - BINLOG_EVENT_HDR_LEN) + n = pread(router->binlog_fd, + &data[BINLOG_EVENT_HDR_LEN], + hdr.event_size - BINLOG_EVENT_HDR_LEN, + pos + BINLOG_EVENT_HDR_LEN); + if (n != static_cast(hdr.event_size - BINLOG_EVENT_HDR_LEN)) { if (n == -1) { @@ -2359,7 +2360,7 @@ blr_read_events_all_events(ROUTER_INSTANCE *router, if ((debug & BLR_REPORT_REP_HEADER)) { - char *event_desc = blr_get_event_description(router, hdr.event_type); + const char *event_desc = blr_get_event_description(router, hdr.event_type); MXS_DEBUG("%8s==== Event Header ====\n%39sEvent Pos %lu\n%39sEvent time %lu\n%39s" "Event size %lu\n%39sEvent Type %u (%s)\n%39s" "Server Id %lu\n%39sNextPos %lu\n%39sFlags %u", @@ -2392,7 +2393,9 @@ blr_read_events_all_events(ROUTER_INSTANCE *router, { char nonce_hex[AES_BLOCK_SIZE * 2 + 1] = ""; START_ENCRYPTION_EVENT ste_event = {}; - BINLOG_ENCRYPTION_CTX *new_encryption_ctx = MXS_CALLOC(1, sizeof(BINLOG_ENCRYPTION_CTX)); + void *mem = MXS_CALLOC(1, sizeof(BINLOG_ENCRYPTION_CTX)); + BINLOG_ENCRYPTION_CTX *new_encryption_ctx = + static_cast(mem); if (new_encryption_ctx == NULL) { @@ -2516,7 +2519,7 @@ blr_read_events_all_events(ROUTER_INSTANCE *router, action->pos > 4 && (pos == action->pos || replace_trx_events)) { - char *event_desc = blr_get_event_description(router, hdr.event_type); + const char *event_desc = blr_get_event_description(router, hdr.event_type); if (action->replace_trx && !replace_trx_events) { @@ -2742,7 +2745,7 @@ blr_read_events_all_events(ROUTER_INSTANCE *router, BINLOG_EVENT_HDR_LEN - (4 + 4 + 1 + 2 + 2 + var_block_len + 1 + db_name_len); - statement_sql = MXS_CALLOC(1, statement_len + 1); + statement_sql = static_cast(MXS_CALLOC(1, statement_len + 1)); if (statement_sql) { memcpy(statement_sql, @@ -3114,7 +3117,7 @@ blr_file_new_binlog(ROUTER_INSTANCE *router, char *file) int blr_file_write_master_config(ROUTER_INSTANCE *router, char *error) { - char *section = "binlog_configuration"; + const char *section = "binlog_configuration"; FILE *config_file; int rc; static const char MASTER_INI[] = "master.ini"; @@ -3233,7 +3236,7 @@ blr_print_binlog_details(ROUTER_INSTANCE *router, { char buf_t[40]; struct tm tm_t; - char *event_desc; + const char *event_desc; /* First Event */ localtime_r(&first_event.event_time, &tm_t); @@ -3291,7 +3294,7 @@ blr_create_ignorable_event(uint32_t event_size, } // Allocate space for event: size might contain the 4 crc32 - new_event = MXS_CALLOC(1, event_size); + new_event = static_cast(MXS_CALLOC(1, event_size)); if (new_event == NULL) { return NULL; @@ -3343,7 +3346,7 @@ blr_write_special_event(ROUTER_INSTANCE *router, { int n; uint8_t *new_event; - char *new_event_desc; + const char *new_event_desc; switch (type) { @@ -3417,7 +3420,7 @@ blr_write_special_event(ROUTER_INSTANCE *router, if ((n = pwrite(router->binlog_fd, new_event, event_size, - router->last_written)) != event_size) + router->last_written)) != static_cast(event_size)) { MXS_ERROR("%s: Failed to write %s special binlog record at %lu of %s, %s. " "Truncating to previous record.", @@ -3476,7 +3479,8 @@ blr_create_start_encryption_event(ROUTER_INSTANCE *router, { uint8_t *new_event; uint8_t event_size = sizeof(START_ENCRYPTION_EVENT); - BINLOG_ENCRYPTION_CTX *new_encryption_ctx = MXS_CALLOC(1, sizeof(BINLOG_ENCRYPTION_CTX)); + BINLOG_ENCRYPTION_CTX *new_encryption_ctx = + static_cast(MXS_CALLOC(1, sizeof(BINLOG_ENCRYPTION_CTX))); if (new_encryption_ctx == NULL) { @@ -3489,7 +3493,7 @@ blr_create_start_encryption_event(ROUTER_INSTANCE *router, event_size += BINLOG_EVENT_CRC_SIZE; } - new_event = MXS_CALLOC(1, event_size); + new_event = static_cast(MXS_CALLOC(1, event_size)); if (new_event == NULL) { return NULL; @@ -3891,7 +3895,7 @@ static int blr_aes_create_tail_for_cbc(uint8_t *output, * * Note: this also works for decryption */ - for (int i = 0; i < in_size; i++) + for (uint32_t i = 0; i < in_size; i++) { output[i] = input[i] ^ mask[i]; } @@ -4253,7 +4257,7 @@ bool blr_fetch_mariadb_gtid(ROUTER_SLAVE *slave, unsigned int blr_file_get_next_seqno(const char *filename) { - char *sptr; + const char *sptr; int filenum; if ((sptr = strrchr(filename, '.')) == NULL) @@ -4486,7 +4490,7 @@ bool blr_compare_binlogs(const ROUTER_INSTANCE *router, { // domain_id, server_id and strcmp() return ((router->mariadb10_gtid_domain == info->domain_id) && - (router->orig_masterid == info->server_id) && + (router->orig_masterid == static_cast(info->server_id)) && strcmp(r_file, s_file) == 0); } } diff --git a/server/modules/routing/binlogrouter/blr_master.c b/server/modules/routing/binlogrouter/blr_master.cc similarity index 99% rename from server/modules/routing/binlogrouter/blr_master.c rename to server/modules/routing/binlogrouter/blr_master.cc index 82196a7a5..eaf520c82 100644 --- a/server/modules/routing/binlogrouter/blr_master.c +++ b/server/modules/routing/binlogrouter/blr_master.cc @@ -58,12 +58,13 @@ static GWBUF *blr_make_binlog_dump(ROUTER_INSTANCE *router); void encode_value(unsigned char *data, unsigned int value, int len); void blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt); static int blr_rotate_event(ROUTER_INSTANCE *router, uint8_t *pkt, REP_HEADER *hdr); -static void *CreateMySQLAuthData(char *username, char *password, char *database); +static void *CreateMySQLAuthData(const char *username, + const char *password, + const char *database); void blr_extract_header(uint8_t *pkt, REP_HEADER *hdr); -static void blr_log_packet(int priority, char *msg, uint8_t *ptr, int len); +static void blr_log_packet(int priority, const char *msg, uint8_t *ptr, int len); void blr_master_close(ROUTER_INSTANCE *); char *blr_extract_column(GWBUF *buf, int col); -void poll_fake_write_event(DCB *dcb); static bool blr_check_last_master_event(void *inst); extern int blr_check_heartbeat(ROUTER_INSTANCE *router); static void blr_log_identity(ROUTER_INSTANCE *router); @@ -354,7 +355,7 @@ static void worker_cb_close_master(int worker_id, void* data) // This is itended to be called only in the main worker. ss_dassert(worker_id == 0); - blr_master_close(data); + blr_master_close(static_cast(data)); } /** @@ -629,7 +630,7 @@ blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf) { MXS_FREE(router->m_errmsg); } - router->m_errmsg = msg_err ? msg_err : "(memory failure)"; + router->m_errmsg = msg_err ? msg_err : MXS_STRDUP("(memory failure)"); router->active_logs = 0; if (router->reconnect_pending) @@ -927,7 +928,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt) if (len < BINLOG_EVENT_HDR_LEN && router->master_event_state != BLR_EVENT_ONGOING) { - char *event_msg = "unknown"; + const char *event_msg = "unknown"; /* Packet is too small to be a binlog event */ if (ptr[4] == 0xfe) /* EOF Packet */ @@ -1242,7 +1243,8 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt) statement_len = len - (MYSQL_HEADER_LEN + 1 + BINLOG_EVENT_HDR_LEN + 4 + 4 + 1 + 2 + 2 \ + var_block_len + 1 + db_name_len); - statement_sql = MXS_CALLOC(1, statement_len + 1); + statement_sql = + static_cast(MXS_CALLOC(1, statement_len + 1)); MXS_ABORT_IF_NULL(statement_sql); memcpy(statement_sql, (char *)ptr + MYSQL_HEADER_LEN + 1 + BINLOG_EVENT_HDR_LEN + 4 + 4 + 1 + 2 + 2 \ @@ -1694,7 +1696,7 @@ blr_rotate_event(ROUTER_INSTANCE *router, uint8_t *ptr, REP_HEADER *hdr) * This doesn't really belong here and should be moved at some stage. */ static void * -CreateMySQLAuthData(char *username, char *password, char *database) +CreateMySQLAuthData(const char *username, const char *password, const char *database) { MYSQL_session *auth_info; @@ -1718,7 +1720,8 @@ CreateMySQLAuthData(char *username, char *password, char *database) return NULL; } - if ((auth_info = MXS_CALLOC(1, sizeof(MYSQL_session))) == NULL) + if ((auth_info = + static_cast(MXS_CALLOC(1, sizeof(MYSQL_session)))) == NULL) { return NULL; } @@ -1747,7 +1750,7 @@ typedef enum * @param len Length of message packet */ static void -blr_log_packet(int priority, char *msg, uint8_t *ptr, int len) +blr_log_packet(int priority, const char *msg, uint8_t *ptr, int len) { char buf[400] = ""; char *bufp; @@ -1851,7 +1854,7 @@ blr_extract_column(GWBUF *buf, int col) ptr += collen; } collen = *ptr++; - if ((rval = MXS_MALLOC(collen + 1)) == NULL) + if ((rval = static_cast(MXS_MALLOC(collen + 1))) == NULL) { return NULL; } @@ -1976,7 +1979,7 @@ int blr_check_heartbeat(ROUTER_INSTANCE *router) { time_t t_now = time(0); - char *event_desc = NULL; + const char *event_desc = NULL; if (router->master_state != BLRM_BINLOGDUMP) { @@ -1988,7 +1991,8 @@ blr_check_heartbeat(ROUTER_INSTANCE *router) if (router->master_state == BLRM_BINLOGDUMP && router->lastEventReceived > 0) { - if ((t_now - router->stats.lastReply) > (router->heartbeat + BLR_NET_LATENCY_WAIT_TIME)) + if (static_cast(t_now - router->stats.lastReply) > + (router->heartbeat + BLR_NET_LATENCY_WAIT_TIME)) { MXS_ERROR("No event received from master [%s]:%d in heartbeat period (%lu seconds), " "last event (%s %d) received %lu seconds ago. Assuming connection is dead " @@ -2097,7 +2101,7 @@ blr_write_data_into_binlog(ROUTER_INSTANCE *router, uint32_t data_len, uint8_t * int n; if ((n = pwrite(router->binlog_fd, buf, data_len, - router->last_written)) != data_len) + router->last_written)) != static_cast(data_len)) { MXS_ERROR("%s: Failed to write binlog record at %lu of %s, %s. " "Truncating to previous record.", diff --git a/server/modules/routing/binlogrouter/blr_slave.c b/server/modules/routing/binlogrouter/blr_slave.cc similarity index 99% rename from server/modules/routing/binlogrouter/blr_slave.c rename to server/modules/routing/binlogrouter/blr_slave.cc index 7cc5c2126..0845df761 100644 --- a/server/modules/routing/binlogrouter/blr_slave.c +++ b/server/modules/routing/binlogrouter/blr_slave.cc @@ -69,27 +69,27 @@ #include "blr.h" +#include +#include #include #include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include #include #include -#include -#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /** * This struct is used by sqlite3_exec callback routine @@ -118,7 +118,6 @@ typedef enum SLAVE_EOF_ERROR } slave_eof_action_t; -extern void poll_fake_write_event(DCB *dcb); static char* get_next_token(char *str, const char* delim, char **saveptr); extern int load_mysql_users(SERV_LISTENER *listener); extern void blr_master_close(ROUTER_INSTANCE* router); @@ -137,7 +136,7 @@ static int blr_slave_replay(ROUTER_INSTANCE *router, GWBUF *master); static void blr_slave_send_error(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, - char *msg); + const char *msg); static int blr_slave_send_timestamp(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave); static int blr_slave_register(ROUTER_INSTANCE *router, @@ -199,9 +198,9 @@ static int blr_stop_slave(ROUTER_INSTANCE* router, static int blr_start_slave(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave); static void blr_slave_send_error_packet(ROUTER_SLAVE *slave, - char *msg, + const char *msg, unsigned int err_num, - char *status); + const char *status); static int blr_handle_change_master(ROUTER_INSTANCE* router, char *command, char *error); @@ -237,17 +236,17 @@ static int blr_handle_change_master_token(char *input, static void blr_master_free_parsed_options(CHANGE_MASTER_OPTIONS *options); static int blr_slave_send_var_value(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, - char *variable, - char *value, + const char *variable, + const char *value, int column_type); static int blr_slave_send_variable(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, - char *variable, - char *value, + const char *variable, + const char *value, int column_type); static int blr_slave_send_columndef_with_info_schema(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, - char *name, + const char *name, int type, int len, uint8_t seqno); @@ -262,20 +261,20 @@ static int blr_slave_handle_variables(ROUTER_INSTANCE *router, char *stmt); static int blr_slave_send_warning_message(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave, - char *message); + const char *message); static int blr_slave_show_warnings(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave); static int blr_slave_send_status_variable(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, - char *variable, - char *value, + const char *variable, + const char *value, int column_type); static int blr_slave_handle_status_variables(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, char *stmt); static int blr_slave_send_columndef_with_status_schema(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, - char *name, + const char *name, int type, int len, uint8_t seqno); @@ -610,11 +609,10 @@ static int blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) { char *qtext, *query_text; - char *sep = " ,="; + const char *sep = " ,="; char *word, *brkb; int query_len; char *ptr; - extern char *strcasestr(); bool unexpected = true; qtext = (char*)GWBUF_DATA(queue); @@ -816,7 +814,7 @@ blr_slave_replay(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *master) * @param msg The error message to send */ static void -blr_slave_send_error(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, char *msg) +blr_slave_send_error(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, const char *msg) { GWBUF *pkt; unsigned char *data; @@ -2480,8 +2478,9 @@ blr_slave_catchup(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, bool large) { /* read it, set slave & file context */ uint8_t *record_ptr = GWBUF_DATA(record); + void *mem = MXS_CALLOC(1, sizeof(SLAVE_ENCRYPTION_CTX)); SLAVE_ENCRYPTION_CTX *encryption_ctx; - encryption_ctx = MXS_CALLOC(1, sizeof(SLAVE_ENCRYPTION_CTX)); + encryption_ctx = static_cast(mem); MXS_ABORT_IF_NULL(encryption_ctx); record_ptr += BINLOG_EVENT_HDR_LEN; @@ -3209,7 +3208,7 @@ blr_slave_fake_rotate(ROUTER_INSTANCE *router, BLFILE** filep, const char *new_file) { - char *sptr; + const char *sptr; int filenum; GWBUF *r_event; MARIADB_GTID_INFO *f_tree = router->storage_type == BLR_BINLOG_STORAGE_TREE ? @@ -4139,15 +4138,15 @@ blr_start_slave(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave) */ static void blr_slave_send_error_packet(ROUTER_SLAVE *slave, - char *msg, + const char *msg, unsigned int err_num, - char *status) + const char *status) { GWBUF *pkt; unsigned char *data; int len; unsigned int mysql_errno = 0; - char *mysql_state; + const char *mysql_state; if ((pkt = gwbuf_alloc(strlen(msg) + 13)) == NULL) { @@ -5060,7 +5059,7 @@ blr_parse_change_master_command(char *input, char *error_string, CHANGE_MASTER_OPTIONS *config) { - char *sep = ","; + const char *sep = ","; char *word, *brkb; if ((word = get_next_token(input, sep, &brkb)) == NULL) @@ -5111,7 +5110,7 @@ blr_handle_change_master_token(char *input, CHANGE_MASTER_OPTIONS *config) { /* space+TAB+= */ - char *sep = " \t="; + const char *sep = " \t="; char *word, *brkb; char *value = NULL; char **option_field = NULL; @@ -5172,7 +5171,7 @@ blr_get_parsed_command_value(char *input) strcpy(value, input); /* space+TAB+= */ - char *sep = " \t="; + const char *sep = " \t="; char *word; if ((word = get_next_token(NULL, sep, &input)) != NULL) @@ -5330,8 +5329,8 @@ blr_master_free_parsed_options(CHANGE_MASTER_OPTIONS *options) static int blr_slave_send_var_value(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, - char *variable, - char *value, + const char *variable, + const char *value, int column_type) { GWBUF *pkt; @@ -5384,8 +5383,8 @@ blr_slave_send_var_value(ROUTER_INSTANCE *router, static int blr_slave_send_variable(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, - char *variable, - char *value, + const char *variable, + const char *value, int column_type) { GWBUF *pkt; @@ -5475,7 +5474,7 @@ blr_slave_send_variable(ROUTER_INSTANCE *router, static int blr_slave_send_columndef_with_info_schema(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, - char *name, + const char *name, int type, int len, uint8_t seqno) @@ -5616,7 +5615,7 @@ blr_slave_handle_variables(ROUTER_INSTANCE *router, char *brkb; char *word; /* SPACE,TAB,= */ - char *sep = " ,="; + const char *sep = " ,="; if ((word = strtok_r(stmt, sep, &brkb)) == NULL) { @@ -5696,7 +5695,7 @@ blr_slave_handle_variables(ROUTER_INSTANCE *router, static int blr_slave_send_warning_message(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave, - char *message) + const char *message) { GWBUF *pkt; uint8_t *ptr; @@ -5764,7 +5763,7 @@ blr_slave_show_warnings(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave) /* check whether a warning message is available */ if (slave->warning_msg) { - char *level = "Warning"; + const char *level = "Warning"; char *msg_ptr; char err_code[16 + 1] = ""; msg_ptr = strchr(slave->warning_msg, ':'); @@ -5855,7 +5854,7 @@ blr_slave_handle_status_variables(ROUTER_INSTANCE *router, char *brkb = NULL; char *word = NULL; /* SPACE,TAB,= */ - char *sep = " ,="; + const char *sep = " ,="; if ((word = strtok_r(stmt, sep, &brkb)) == NULL) { @@ -5913,8 +5912,8 @@ blr_slave_handle_status_variables(ROUTER_INSTANCE *router, static int blr_slave_send_status_variable(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, - char *variable, - char *value, + const char *variable, + const char *value, int column_type) { GWBUF *pkt; @@ -6009,7 +6008,7 @@ blr_slave_send_status_variable(ROUTER_INSTANCE *router, static int blr_slave_send_columndef_with_status_schema(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, - char *name, + const char *name, int type, int len, uint8_t seqno) @@ -6022,7 +6021,7 @@ blr_slave_send_columndef_with_status_schema(ROUTER_INSTANCE *router, int column_name_len = strlen(name); int orig_column_name_len = strlen("VARIABLE_NAME"); int packet_data_len = 0; - char *ptr_name_start = name; + const char *ptr_name_start = name; if (strcasecmp(ptr_name_start, "value") == 0) { @@ -6308,7 +6307,8 @@ blr_set_master_ssl(ROUTER_INSTANCE *router, else { /* Allocate SSL struct for backend connection */ - if ((server_ssl = MXS_CALLOC(1, sizeof(SSL_LISTENER))) == NULL) + server_ssl = static_cast(MXS_CALLOC(1, sizeof(SSL_LISTENER))); + if (server_ssl == NULL) { router->ssl_enabled = false; @@ -6481,8 +6481,9 @@ blr_slave_read_ste(ROUTER_INSTANCE *router, if (hdr.event_type == MARIADB10_START_ENCRYPTION_EVENT) { uint8_t *record_ptr = GWBUF_DATA(record); - SLAVE_ENCRYPTION_CTX *new_encryption_ctx; - new_encryption_ctx = MXS_CALLOC(1, sizeof(SLAVE_ENCRYPTION_CTX)); + void *mem = MXS_CALLOC(1, sizeof(SLAVE_ENCRYPTION_CTX)); + SLAVE_ENCRYPTION_CTX *new_encryption_ctx = + static_cast(mem); if (!new_encryption_ctx) { @@ -6545,7 +6546,7 @@ static bool blr_handle_simple_select_stmt(ROUTER_INSTANCE *router, { char *word; char *brkb; - char *sep = " \t,="; + const char *sep = " \t,="; if ((word = strtok_r(select_stmt, sep, &brkb)) == NULL) { @@ -7456,7 +7457,7 @@ static bool blr_handle_show_stmt(ROUTER_INSTANCE *router, { char *word; char *brkb; - char *sep = " \t,="; + const char *sep = " \t,="; if ((word = strtok_r(show_stmt, sep, &brkb)) == NULL) { MXS_ERROR("%s: Incomplete show query.", router->service->name); @@ -7475,8 +7476,9 @@ static bool blr_handle_show_stmt(ROUTER_INSTANCE *router, } else { - char *errmsg = "SHOW [FULL] BINARY LOGS needs the" - " 'mariadb10_slave_gtid' option to be set."; + const char *errmsg = + "SHOW [FULL] BINARY LOGS needs the" + " 'mariadb10_slave_gtid' option to be set."; MXS_ERROR("%s: %s", errmsg, router->service->name); @@ -7678,7 +7680,7 @@ static bool blr_handle_set_stmt(ROUTER_INSTANCE *router, { char *word; char *brkb; - char *sep = " \t,="; + const char *sep = " \t,="; if ((word = strtok_r(set_stmt, sep, &brkb)) == NULL) { @@ -7976,7 +7978,7 @@ static bool blr_handle_admin_stmt(ROUTER_INSTANCE *router, { char *word; char *brkb; - char *sep = " \t,="; + const char *sep = " \t,="; if (admin_opts == NULL || !admin_opts[0]) { @@ -8004,8 +8006,9 @@ static bool blr_handle_admin_stmt(ROUTER_INSTANCE *router, } else { - char *errmsg = "PURGE BINARY LOGS needs the " - "'mariadb10_slave_gtid' option to be set."; + const char *errmsg = + "PURGE BINARY LOGS needs the " + "'mariadb10_slave_gtid' option to be set."; MXS_ERROR("%s: %s", errmsg, router->service->name); @@ -9194,9 +9197,10 @@ static void blr_log_config_changes(ROUTER_INSTANCE *router, } /* Prepare GTID msg */ - char *gtid_msg = change_master->use_mariadb10_gtid ? - ", MASTER_USE_GTID=Slave_pos" : - ""; + const char *gtid_msg = + change_master->use_mariadb10_gtid ? + ", MASTER_USE_GTID=Slave_pos" : + ""; /* Log previous state and new changes */ MXS_NOTICE("%s: 'CHANGE MASTER TO executed'. Previous state " @@ -9244,10 +9248,10 @@ static bool blr_check_connecting_slave(const ROUTER_INSTANCE *router, enum blr_slave_check check) { int rv = true; - char *err_msg = NULL; - char *err_status = "HY000"; + const char *err_msg = NULL; + const char *err_status = "HY000"; int err_code = BINLOG_FATAL_ERROR_READING; - char *msg_detail = ""; + const char *msg_detail = ""; switch (check) { @@ -9657,7 +9661,8 @@ static bool blr_apply_changes(ROUTER_INSTANCE *router, } else { - if (master_log_pos != NULL && pos != router->current_pos) + if (master_log_pos != NULL && + pos != static_cast(router->current_pos)) { snprintf(error, BINLOG_ERROR_MSG_LEN, "Can not set MASTER_LOG_POS to %s: " diff --git a/server/modules/routing/binlogrouter/maxbinlogcheck.c b/server/modules/routing/binlogrouter/maxbinlogcheck.cc similarity index 99% rename from server/modules/routing/binlogrouter/maxbinlogcheck.c rename to server/modules/routing/binlogrouter/maxbinlogcheck.cc index ad02d5a93..03a0ac1c0 100644 --- a/server/modules/routing/binlogrouter/maxbinlogcheck.c +++ b/server/modules/routing/binlogrouter/maxbinlogcheck.cc @@ -72,7 +72,7 @@ static struct option long_options[] = {0, 0, 0, 0} }; #endif -char *binlog_check_version = "2.2.1"; +const char *binlog_check_version = "2.2.1"; int maxscale_uptime() diff --git a/server/modules/routing/binlogrouter/test/CMakeLists.txt b/server/modules/routing/binlogrouter/test/CMakeLists.txt index d600418eb..86b248a5f 100644 --- a/server/modules/routing/binlogrouter/test/CMakeLists.txt +++ b/server/modules/routing/binlogrouter/test/CMakeLists.txt @@ -1,5 +1,5 @@ if(BUILD_TESTS) - add_executable(testbinlogrouter testbinlog.c ../blr.c ../blr_slave.c ../blr_master.c ../blr_file.c ../blr_cache.c) + add_executable(testbinlogrouter testbinlog.cc ../blr.cc ../blr_slave.cc ../blr_master.cc ../blr_file.cc ../blr_cache.cc) target_link_libraries(testbinlogrouter maxscale-common ${PCRE_LINK_FLAGS} uuid) add_test(NAME TestBinlogRouter COMMAND ./testbinlogrouter WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) endif() diff --git a/server/modules/routing/binlogrouter/test/testbinlog.c b/server/modules/routing/binlogrouter/test/testbinlog.cc similarity index 99% rename from server/modules/routing/binlogrouter/test/testbinlog.c rename to server/modules/routing/binlogrouter/test/testbinlog.cc index a784e573a..62b6db533 100644 --- a/server/modules/routing/binlogrouter/test/testbinlog.c +++ b/server/modules/routing/binlogrouter/test/testbinlog.cc @@ -132,7 +132,8 @@ int main(int argc, char **argv) serviceAddBackend(service, server); } - if ((inst = MXS_CALLOC(1, sizeof(ROUTER_INSTANCE))) == NULL) + inst = static_cast(MXS_CALLOC(1, sizeof(ROUTER_INSTANCE))); + if (inst == NULL) { mxs_log_flush_sync(); mxs_log_finish(); diff --git a/server/modules/routing/cat/cat.cc b/server/modules/routing/cat/cat.cc index 5fd1b708e..b39b0eae4 100644 --- a/server/modules/routing/cat/cat.cc +++ b/server/modules/routing/cat/cat.cc @@ -62,8 +62,6 @@ uint64_t Cat::getCapabilities() return caps; } -MXS_BEGIN_DECLS - /** * The module entry point routine. It is this routine that * must populate the structure that is referred to as the @@ -72,7 +70,7 @@ MXS_BEGIN_DECLS * * @return The module object */ -MXS_MODULE* MXS_CREATE_MODULE() +extern "C" MXS_MODULE* MXS_CREATE_MODULE() { static MXS_MODULE info = { @@ -94,5 +92,3 @@ MXS_MODULE* MXS_CREATE_MODULE() return &info; } - -MXS_END_DECLS diff --git a/server/modules/routing/cli/CMakeLists.txt b/server/modules/routing/cli/CMakeLists.txt index aff15d29a..aeda66272 100644 --- a/server/modules/routing/cli/CMakeLists.txt +++ b/server/modules/routing/cli/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(cli SHARED cli.c ../debugcli/debugcmd.c) +add_library(cli SHARED cli.cc ../debugcli/debugcmd.cc) target_link_libraries(cli maxscale-common) set_target_properties(cli PROPERTIES VERSION "1.0.0") install_module(cli core) diff --git a/server/modules/routing/cli/cli.c b/server/modules/routing/cli/cli.cc similarity index 97% rename from server/modules/routing/cli/cli.c rename to server/modules/routing/cli/cli.cc index 2d9fdddb9..2940e0f82 100644 --- a/server/modules/routing/cli/cli.c +++ b/server/modules/routing/cli/cli.cc @@ -65,7 +65,7 @@ static CLI_INSTANCE *instances; * * @return The module object */ -MXS_MODULE* MXS_CREATE_MODULE() +extern "C" MXS_MODULE* MXS_CREATE_MODULE() { MXS_NOTICE("Initialise CLI router module"); spinlock_init(&instlock); @@ -122,7 +122,7 @@ createInstance(SERVICE *service, char **options) CLI_INSTANCE *inst; int i; - if ((inst = MXS_MALLOC(sizeof(CLI_INSTANCE))) == NULL) + if ((inst = static_cast(MXS_MALLOC(sizeof(CLI_INSTANCE)))) == NULL) { return NULL; } @@ -180,7 +180,7 @@ newSession(MXS_ROUTER *instance, MXS_SESSION *session) session->state = SESSION_STATE_READY; - return (void *)client; + return reinterpret_cast(client); } /** diff --git a/server/modules/routing/debugcli/CMakeLists.txt b/server/modules/routing/debugcli/CMakeLists.txt index f32ea459a..5266d79ee 100644 --- a/server/modules/routing/debugcli/CMakeLists.txt +++ b/server/modules/routing/debugcli/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(debugcli SHARED debugcli.c debugcmd.c) +add_library(debugcli SHARED debugcli.cc debugcmd.cc) target_link_libraries(debugcli maxscale-common) set_target_properties(debugcli PROPERTIES VERSION "1.1.1") install_module(debugcli core) diff --git a/server/modules/routing/debugcli/debugcli.c b/server/modules/routing/debugcli/debugcli.cc similarity index 97% rename from server/modules/routing/debugcli/debugcli.c rename to server/modules/routing/debugcli/debugcli.cc index c7f717b5b..4118e8c68 100644 --- a/server/modules/routing/debugcli/debugcli.c +++ b/server/modules/routing/debugcli/debugcli.cc @@ -64,7 +64,7 @@ static CLI_INSTANCE *instances; * * @return The module object */ -MXS_MODULE* MXS_CREATE_MODULE() +extern "C" MXS_MODULE* MXS_CREATE_MODULE() { MXS_NOTICE("Initialise debug CLI router module."); spinlock_init(&instlock); @@ -121,7 +121,7 @@ createInstance(SERVICE *service, char **options) CLI_INSTANCE *inst; int i; - if ((inst = MXS_MALLOC(sizeof(CLI_INSTANCE))) == NULL) + if ((inst = static_cast(MXS_MALLOC(sizeof(CLI_INSTANCE)))) == NULL) { return NULL; } @@ -174,7 +174,7 @@ newSession(MXS_ROUTER *instance, MXS_SESSION *session) dcb_printf(session->client_dcb, "Welcome to the MariaDB Corporation MaxScale Debug Interface.\n"); dcb_printf(session->client_dcb, "Type help for a list of available commands.\n\n"); - return (void *)client; + return reinterpret_cast(client); } /** diff --git a/server/modules/routing/debugcli/debugcmd.c b/server/modules/routing/debugcli/debugcmd.cc similarity index 88% rename from server/modules/routing/debugcli/debugcmd.c rename to server/modules/routing/debugcli/debugcmd.cc index 3c8daff4a..f5715fc57 100644 --- a/server/modules/routing/debugcli/debugcmd.c +++ b/server/modules/routing/debugcli/debugcmd.cc @@ -84,15 +84,45 @@ * * These are the options that may be passed to a command */ +typedef void (*FN )(DCB*); +typedef void (*FN1 )(DCB*, unsigned long); +typedef void (*FN2 )(DCB*, unsigned long, unsigned long); +typedef void (*FN3 )(DCB*, unsigned long, unsigned long, unsigned long); +typedef void (*FN4 )(DCB*, unsigned long, unsigned long, unsigned long, unsigned long); +typedef void (*FN5 )(DCB*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); +typedef void (*FN6 )(DCB*, + unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long); +typedef void (*FN7 )(DCB*, + unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long, unsigned long); +typedef void (*FN8 )(DCB*, + unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long, unsigned long, unsigned long); +typedef void (*FN9 )(DCB*, + unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long, unsigned long, unsigned long, unsigned long); +typedef void (*FN10)(DCB*, + unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); +typedef void (*FN11)(DCB*, + unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long); +typedef void (*FN12)(DCB*, + unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long, unsigned long); + struct subcommand { - char *arg1; - int argc_min; - int argc_max; - void (*fn)(); - char *help; - char *devhelp; - int arg_types[MAXARGS]; + const char *arg1; + int argc_min; + int argc_max; + void (*fn)(DCB*); + const char *help; + const char *devhelp; + int arg_types[MAXARGS]; }; #define EMPTY_OPTION @@ -112,26 +142,26 @@ struct subcommand showoptions[] = { #if defined(BUFFER_TRACE) { - "buffers", 0, dprintAllBuffers, + "buffers", 0, (FN)dprintAllBuffers, "Show all buffers with backtrace", "Show all buffers with backtrace", {0} }, #endif { - "dcbs", 0, 0, dprintAllDCBs, + "dcbs", 0, 0, (FN)dprintAllDCBs, "Show all DCBs", "Usage: show dcbs", {0} }, { - "dbusers", 1, 1, service_print_users, + "dbusers", 1, 1, (FN)service_print_users, "[deprecated] Show user statistics", "See `show authenticators`", {ARG_TYPE_SERVICE} }, { - "authenticators", 1, 1, service_print_users, + "authenticators", 1, 1, (FN)service_print_users, "Show authenticator diagnostics for a service", "Usage: show authenticators SERVICE\n" "\n" @@ -142,19 +172,19 @@ struct subcommand showoptions[] = {ARG_TYPE_SERVICE} }, { - "epoll", 0, 0, dprintPollStats, + "epoll", 0, 0, (FN)dprintPollStats, "Show the polling system statistics", "Usage: show epoll", {0} }, { - "eventstats", 0, 0, dShowEventStats, + "eventstats", 0, 0, (FN)dShowEventStats, "Show event queue statistics", "Usage: show eventstats", {0} }, { - "filter", 1, 1, dprintFilter, + "filter", 1, 1, (FN)dprintFilter, "Show filter details", "Usage: show filter FILTER\n" "\n" @@ -165,25 +195,25 @@ struct subcommand showoptions[] = {ARG_TYPE_FILTER} }, { - "filters", 0, 0, dprintAllFilters, + "filters", 0, 0, (FN)dprintAllFilters, "Show all filters", "Usage: show filters", {0} }, { - "log_throttling", 0, 0, show_log_throttling, + "log_throttling", 0, 0, (FN)show_log_throttling, "Show the current log throttling setting (count, window (ms), suppression (ms))", "Usage: show log_throttling", {0} }, { - "modules", 0, 0, dprintAllModules, + "modules", 0, 0, (FN)dprintAllModules, "Show all currently loaded modules", "Usage: show modules", {0} }, { - "monitor", 1, 1, monitorShow, + "monitor", 1, 1, (FN)monitorShow, "Show monitor details", "Usage: show monitor MONITOR\n" "\n" @@ -194,13 +224,13 @@ struct subcommand showoptions[] = {ARG_TYPE_MONITOR} }, { - "monitors", 0, 0, monitorShowAll, + "monitors", 0, 0, (FN)monitorShowAll, "Show all monitors", "Usage: show monitors", {0} }, { - "persistent", 1, 1, dprintPersistentDCBs, + "persistent", 1, 1, (FN)dprintPersistentDCBs, "Show the persistent connection pool of a server", "Usage: show persistent SERVER\n" "\n" @@ -211,7 +241,7 @@ struct subcommand showoptions[] = {ARG_TYPE_SERVER} }, { - "server", 1, 1, dprintServer, + "server", 1, 1, (FN)dprintServer, "Show server details", "Usage: show server SERVER\n" "\n" @@ -222,25 +252,25 @@ struct subcommand showoptions[] = {ARG_TYPE_SERVER} }, { - "servers", 0, 0, dprintAllServers, + "servers", 0, 0, (FN)dprintAllServers, "Show all servers", "Usage: show servers", {0} }, { - "serversjson", 0, 0, dprintAllServersJson, + "serversjson", 0, 0, (FN)dprintAllServersJson, "Show all servers in JSON", "Usage: show serversjson", {0} }, { - "services", 0, 0, dprintAllServices, + "services", 0, 0, (FN)dprintAllServices, "Show all configured services in MaxScale", "Usage: show services", {0} }, { - "service", 1, 1, dprintService, + "service", 1, 1, (FN)dprintService, "Show a single service in MaxScale", "Usage: show service SERVICE\n" "\n" @@ -251,7 +281,7 @@ struct subcommand showoptions[] = {ARG_TYPE_SERVICE} }, { - "session", 1, 1, dprintSession, + "session", 1, 1, (FN)dprintSession, "Show session details", "Usage: show session SESSION\n" "\n" @@ -262,31 +292,31 @@ struct subcommand showoptions[] = {ARG_TYPE_SESSION} }, { - "sessions", 0, 0, dprintAllSessions, + "sessions", 0, 0, (FN)dprintAllSessions, "Show all active sessions in MaxScale", "Usage: show sessions", {0} }, { - "tasks", 0, 0, hkshow_tasks, + "tasks", 0, 0, (FN)hkshow_tasks, "Show all active housekeeper tasks in MaxScale", "Usage: show tasks", {0} }, { - "threads", 0, 0, dShowThreads, + "threads", 0, 0, (FN)dShowThreads, "Show the status of the worker threads in MaxScale", "Usage: show threads", {0} }, { - "users", 0, 0, telnetdShowUsers, + "users", 0, 0, (FN)telnetdShowUsers, "Show enabled Linux accounts", "Usage: show users", {0} }, { - "version", 0, 0, showVersion, + "version", 0, 0, (FN)showVersion, "Show the MaxScale version number", "Usage: show version", {0} @@ -336,67 +366,67 @@ void dListCommands(DCB *dcb, const char *domain, const char *ident) struct subcommand listoptions[] = { { - "clients", 0, 0, dListClients, + "clients", 0, 0, (FN)dListClients, "List all the client connections to MaxScale", "Usage: list clients", {0} }, { - "dcbs", 0, 0, dListDCBs, + "dcbs", 0, 0, (FN)dListDCBs, "List all active connections within MaxScale", "Usage: list dcbs", {0} }, { - "filters", 0, 0, dListFilters, + "filters", 0, 0, (FN)dListFilters, "List all filters", "Usage: list filters", {0} }, { - "listeners", 0, 0, dListListeners, + "listeners", 0, 0, (FN)dListListeners, "List all listeners", "Usage: list listeners", {0} }, { - "modules", 0, 0, dprintAllModules, + "modules", 0, 0, (FN)dprintAllModules, "List all currently loaded modules", "Usage: list modules", {0} }, { - "monitors", 0, 0, monitorList, + "monitors", 0, 0, (FN)monitorList, "List all monitors", "Usage: list monitors", {0} }, { - "services", 0, 0, dListServices, + "services", 0, 0, (FN)dListServices, "List all services", "Usage: list services", {0} }, { - "servers", 0, 0, dListServers, + "servers", 0, 0, (FN)dListServers, "List all servers", "Usage: list servers", {0} }, { - "sessions", 0, 0, dListSessions, + "sessions", 0, 0, (FN)dListSessions, "List all the active sessions within MaxScale", "Usage: list sessions", {0} }, { - "threads", 0, 0, dShowThreads, + "threads", 0, 0, (FN)dShowThreads, "List the status of the polling threads in MaxScale", "Usage: list threads", {0} }, { - "commands", 0, 2, dListCommands, + "commands", 0, 2, (FN)dListCommands, "List registered commands", "Usage: list commands [MODULE] [COMMAND]\n" "\n" @@ -439,7 +469,7 @@ struct subcommand shutdownoptions[] = { "maxscale", 0, 0, - shutdown_server, + (FN)shutdown_server, "Initiate a controlled shutdown of MaxScale", "Usage: shutdown maxscale", {0} @@ -447,7 +477,7 @@ struct subcommand shutdownoptions[] = { "monitor", 1, 1, - shutdown_monitor, + (FN)shutdown_monitor, "Stop a monitor", "Usage: shutdown monitor MONITOR\n" "\n" @@ -460,7 +490,7 @@ struct subcommand shutdownoptions[] = { "service", 1, 1, - shutdown_service, + (FN)shutdown_service, "Stop a service", "Usage: shutdown service SERVICE\n" "\n" @@ -473,7 +503,7 @@ struct subcommand shutdownoptions[] = { "listener", 2, 2, - shutdown_listener, + (FN)shutdown_listener, "Stop a listener", "Usage: shutdown listener SERVICE LISTENER\n" "\n" @@ -507,7 +537,7 @@ struct subcommand syncoptions[] = { "logs", 0, 0, - sync_logs, + (FN)sync_logs, "Flush log files to disk", "Usage: flush logs", {0} @@ -539,7 +569,7 @@ restart_listener(DCB *dcb, SERVICE *service, const char *name) struct subcommand restartoptions[] = { { - "monitor", 1, 1, restart_monitor, + "monitor", 1, 1, (FN)restart_monitor, "Restart a monitor", "Usage: restart monitor NAME\n" "\n" @@ -550,7 +580,7 @@ struct subcommand restartoptions[] = {ARG_TYPE_MONITOR} }, { - "service", 1, 1, restart_service, + "service", 1, 1, (FN)restart_service, "Restart a service", "Usage: restart service NAME\n" "\n" @@ -561,7 +591,7 @@ struct subcommand restartoptions[] = {ARG_TYPE_SERVICE} }, { - "listener", 2, 2, restart_listener, + "listener", 2, 2, (FN)restart_listener, "Restart a listener", "Usage: restart listener NAME\n" "\n" @@ -584,7 +614,7 @@ static void set_log_throttling(DCB *dcb, int count, int window_ms, int suppress_ struct subcommand setoptions[] = { { - "server", 2, 2, set_server, + "server", 2, 2, (FN)set_server, "Set the status of a server", "Usage: set server NAME STATUS\n" "\n" @@ -596,19 +626,19 @@ struct subcommand setoptions[] = {ARG_TYPE_SERVER, ARG_TYPE_OBJECT_NAME} }, { - "pollsleep", 1, 1, set_pollsleep, + "pollsleep", 1, 1, (FN)set_pollsleep, "Set poll sleep period", "Deprecated in 2.3", {ARG_TYPE_NUMERIC} }, { - "nbpolls", 1, 1, set_nbpoll, + "nbpolls", 1, 1, (FN)set_nbpoll, "Set non-blocking polls", "Deprecated in 2.3", {ARG_TYPE_NUMERIC} }, { - "log_throttling", 3, 3, set_log_throttling, + "log_throttling", 3, 3, (FN)set_log_throttling, "Set the log throttling configuration", "Usage: set log_throttling COUNT WINDOW SUPPRESS\n" "\n" @@ -630,7 +660,7 @@ static void clear_server(DCB *dcb, SERVER *server, char *bit); struct subcommand clearoptions[] = { { - "server", 2, 2, clear_server, + "server", 2, 2, (FN)clear_server, "Clear server status", "Usage: clear server NAME STATUS\n" "\n" @@ -653,13 +683,13 @@ static void reload_config(DCB *dcb); struct subcommand reloadoptions[] = { { - "config", 0, 0, reload_config, + "config", 0, 0, (FN)reload_config, "[Deprecated] Reload the configuration", "Usage: reload config", {0} }, { - "dbusers", 1, 1, reload_dbusers, + "dbusers", 1, 1, (FN)reload_dbusers, "Reload the database users for a service", "Usage: reload dbusers SERVICE\n" "\n" @@ -694,7 +724,7 @@ struct subcommand enableoptions[] = { "log-priority", 1, 1, - enable_log_priority, + (FN)enable_log_priority, "Enable a logging priority", "Usage: enable log-priority PRIORITY\n" "\n" @@ -707,7 +737,7 @@ struct subcommand enableoptions[] = { "sessionlog-priority", 2, 2, - enable_sess_log_priority, + (FN)enable_sess_log_priority, "[Deprecated] Enable a logging priority for a session", "This command is deprecated", {ARG_TYPE_OBJECT_NAME, ARG_TYPE_OBJECT_NAME} @@ -715,7 +745,7 @@ struct subcommand enableoptions[] = { "root", 1, 1, - enable_service_root, + (FN)enable_service_root, "Enable root user access to a service", "Usage: enable root SERVICE\n" "\n" @@ -728,7 +758,7 @@ struct subcommand enableoptions[] = { "syslog", 0, 0, - enable_syslog, + (FN)enable_syslog, "Enable syslog logging", "Usage: enable syslog", {0} @@ -736,7 +766,7 @@ struct subcommand enableoptions[] = { "maxlog", 0, 0, - enable_maxlog, + (FN)enable_maxlog, "Enable MaxScale logging", "Usage: enable maxlog", {0} @@ -744,7 +774,7 @@ struct subcommand enableoptions[] = { "account", 1, 1, - enable_admin_account, + (FN)enable_admin_account, "Activate a Linux user account for administrative MaxAdmin use", "Usage: enable account USER\n" "\n" @@ -757,7 +787,7 @@ struct subcommand enableoptions[] = { "readonly-account", 1, 1, - enable_account, + (FN)enable_account, "Activate a Linux user account for read-only MaxAdmin use", "Usage: enable account USER\n" "\n" @@ -782,7 +812,7 @@ struct subcommand disableoptions[] = { "log-priority", 1, 1, - disable_log_priority, + (FN)disable_log_priority, "Disable a logging priority", "Usage: disable log-priority PRIORITY\n" "\n" @@ -795,7 +825,7 @@ struct subcommand disableoptions[] = { "sessionlog-priority", 2, 2, - disable_sess_log_priority, + (FN)disable_sess_log_priority, "[Deprecated] Disable a logging priority for a particular session", "This command is deprecated", {ARG_TYPE_OBJECT_NAME, ARG_TYPE_OBJECT_NAME} @@ -803,7 +833,7 @@ struct subcommand disableoptions[] = { "root", 1, 1, - disable_service_root, + (FN)disable_service_root, "Disable root access", "Usage: disable root SERVICE\n" "\n" @@ -816,7 +846,7 @@ struct subcommand disableoptions[] = { "syslog", 0, 0, - disable_syslog, + (FN)disable_syslog, "Disable syslog logging", "Usage: disable syslog", {0} @@ -824,7 +854,7 @@ struct subcommand disableoptions[] = { "maxlog", 0, 0, - disable_maxlog, + (FN)disable_maxlog, "Disable MaxScale logging", "Usage: disable maxlog", {0} @@ -832,7 +862,7 @@ struct subcommand disableoptions[] = { "account", 1, 1, - disable_account, + (FN)disable_account, "Disable Linux user", "Usage: disable account USER\n" "\n" @@ -884,7 +914,7 @@ void ping_workers(DCB* dcb) struct subcommand pingoptions[] = { { - "workers", 0, 0, ping_workers, + "workers", 0, 0, (FN)ping_workers, "Ping Workers", "Ping Workers", {ARG_TYPE_NONE} @@ -898,7 +928,7 @@ struct subcommand pingoptions[] = struct subcommand addoptions[] = { { - "user", 2, 2, inet_add_admin_user, + "user", 2, 2, (FN)inet_add_admin_user, "Add an administrative account for using maxadmin over the network", "Usage: add user USER PASSWORD\n" "\n" @@ -910,7 +940,7 @@ struct subcommand addoptions[] = {ARG_TYPE_OBJECT_NAME, ARG_TYPE_STRING} }, { - "readonly-user", 2, 2, inet_add_user, + "readonly-user", 2, 2, (FN)inet_add_user, "Add a read-only account for using maxadmin over the network", "Usage: add user USER PASSWORD\n" "\n" @@ -922,7 +952,7 @@ struct subcommand addoptions[] = {ARG_TYPE_OBJECT_NAME, ARG_TYPE_STRING} }, { - "server", 2, 12, cmd_AddServer, + "server", 2, 12, (FN)cmd_AddServer, "Add a new server to a service", "Usage: add server SERVER TARGET...\n" "\n" @@ -973,7 +1003,7 @@ struct subcommand removeoptions[] = { "user", 1, 1, - telnetdRemoveUser, + (FN)telnetdRemoveUser, "Remove account for using maxadmin over the network", "Usage: remove user USER\n" "\n" @@ -984,7 +1014,7 @@ struct subcommand removeoptions[] = {ARG_TYPE_STRING} }, { - "server", 2, 12, cmd_RemoveServer, + "server", 2, 12, (FN)cmd_RemoveServer, "Remove a server from a service or a monitor", "Usage: remove server SERVER TARGET...\n" "\n" @@ -1080,7 +1110,7 @@ struct subcommand flushoptions[] = { "log", 1, 1, - flushlog, + (FN)flushlog, "Flush the content of a log file and reopen it", "Usage: flush log", {ARG_TYPE_STRING} @@ -1088,7 +1118,7 @@ struct subcommand flushoptions[] = { "logs", 0, 0, - flushlogs, + (FN)flushlogs, "Flush the content of a log file and reopen it", "Usage: flush logs", {0} @@ -1172,7 +1202,7 @@ static void createMonitor(DCB *dcb, const char *name, const char *module) struct subcommand createoptions[] = { { - "server", 2, 6, createServer, + "server", 2, 6, (FN)createServer, "Create a new server", "Usage: create server NAME HOST [PORT] [PROTOCOL] [AUTHENTICATOR] [OPTIONS]\n" "\n" @@ -1193,7 +1223,7 @@ struct subcommand createoptions[] = } }, { - "listener", 2, 12, createListener, + "listener", 2, 12, (FN)createListener, "Create a new listener for a service", "Usage: create listener SERVICE NAME [HOST] [PORT] [PROTOCOL] [AUTHENTICATOR] [OPTIONS]\n" " [SSL_KEY] [SSL_CERT] [SSL_CA] [SSL_VERSION] [SSL_VERIFY_DEPTH]\n" @@ -1225,7 +1255,7 @@ struct subcommand createoptions[] = } }, { - "monitor", 2, 2, createMonitor, + "monitor", 2, 2, (FN)createMonitor, "Create a new monitor", "Usage: create monitor NAME MODULE\n" "\n" @@ -1292,7 +1322,7 @@ static void destroyMonitor(DCB *dcb, MXS_MONITOR *monitor) struct subcommand destroyoptions[] = { { - "server", 1, 1, destroyServer, + "server", 1, 1, (FN)destroyServer, "Destroy a server", "Usage: destroy server NAME\n" "\n" @@ -1303,7 +1333,7 @@ struct subcommand destroyoptions[] = {ARG_TYPE_SERVER} }, { - "listener", 2, 2, destroyListener, + "listener", 2, 2, (FN)destroyListener, "Destroy a listener", "Usage: destroy listener SERVICE NAME\n" "\n" @@ -1316,7 +1346,7 @@ struct subcommand destroyoptions[] = {ARG_TYPE_SERVICE, ARG_TYPE_OBJECT_NAME} }, { - "monitor", 1, 1, destroyMonitor, + "monitor", 1, 1, (FN)destroyMonitor, "Destroy a monitor", "Usage: destroy monitor NAME\n" "\n" @@ -1510,7 +1540,7 @@ static void alterMaxScale(DCB *dcb, char *v1, char *v2, char *v3, struct subcommand alteroptions[] = { { - "server", 2, 12, alterServer, + "server", 2, 12, (FN)alterServer, "Alter server parameters", "Usage: alter server NAME KEY=VALUE ...\n" "\n" @@ -1544,7 +1574,7 @@ struct subcommand alteroptions[] = } }, { - "monitor", 2, 12, alterMonitor, + "monitor", 2, 12, (FN)alterMonitor, "Alter monitor parameters", "Usage: alter monitor NAME KEY=VALUE ...\n" "\n" @@ -1574,7 +1604,7 @@ struct subcommand alteroptions[] = } }, { - "service", 2, 12, alterService, + "service", 2, 12, (FN)alterService, "Alter service parameters", "Usage: alter service NAME KEY=VALUE ...\n" "\n" @@ -1605,7 +1635,7 @@ struct subcommand alteroptions[] = } }, { - "maxscale", 1, 11, alterMaxScale, + "maxscale", 1, 11, (FN)alterMaxScale, "Alter maxscale parameters", "Usage: alter maxscale KEY=VALUE ...\n" "\n" @@ -1694,7 +1724,7 @@ static void callModuleCommand(DCB *dcb, char *domain, char *id, char *v3, struct subcommand calloptions[] = { { - "command", 2, 12, callModuleCommand, + "command", 2, 12, (FN)callModuleCommand, "Call module command", "Usage: call command MODULE COMMAND ARGS...\n" "\n" @@ -1722,7 +1752,7 @@ struct subcommand calloptions[] = */ static struct { - char *cmd; + const char *cmd; struct subcommand *options; } cmds[] = { @@ -1825,7 +1855,7 @@ static void free_arg(int arg_type, void *value) switch (arg_type) { case ARG_TYPE_SESSION: - session_put_ref(value); + session_put_ref(static_cast(value)); break; default: @@ -2067,58 +2097,58 @@ execute_cmd(CLI_SESSION *cli) cmds[i].options[j].fn(dcb); break; case 1: - cmds[i].options[j].fn(dcb, arg_list[0]); + ((FN1)cmds[i].options[j].fn)(dcb, arg_list[0]); break; case 2: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1]); + ((FN2)cmds[i].options[j].fn)(dcb, arg_list[0], arg_list[1]); break; case 3: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2]); + ((FN3)cmds[i].options[j].fn)(dcb, arg_list[0], arg_list[1], arg_list[2]); break; case 4: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3]); + ((FN4)cmds[i].options[j].fn)(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3]); break; case 5: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4]); - break; + ((FN5)cmds[i].options[j].fn)(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4]); + break; case 6: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5]); - break; + ((FN6)cmds[i].options[j].fn)(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5]); + break; case 7: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5], - arg_list[6]); + ((FN7)cmds[i].options[j].fn)(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5], + arg_list[6]); break; case 8: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5], - arg_list[6], arg_list[7]); + ((FN8)cmds[i].options[j].fn)(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5], + arg_list[6], arg_list[7]); break; case 9: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5], - arg_list[6], arg_list[7], arg_list[8]); + ((FN9)cmds[i].options[j].fn)(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5], + arg_list[6], arg_list[7], arg_list[8]); break; case 10: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5], - arg_list[6], arg_list[7], arg_list[8], - arg_list[9]); + ((FN10)cmds[i].options[j].fn)(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5], + arg_list[6], arg_list[7], arg_list[8], + arg_list[9]); break; case 11: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5], - arg_list[6], arg_list[7], arg_list[8], - arg_list[9], arg_list[10]); + ((FN11)cmds[i].options[j].fn)(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5], + arg_list[6], arg_list[7], arg_list[8], + arg_list[9], arg_list[10]); break; case 12: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5], - arg_list[6], arg_list[7], arg_list[8], - arg_list[9], arg_list[10], arg_list[11]); + ((FN12)cmds[i].options[j].fn)(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5], + arg_list[6], arg_list[7], arg_list[8], + arg_list[9], arg_list[10], arg_list[11]); break; default: dcb_printf(dcb, "Error: Maximum argument count is %d.\n", MAXARGS); @@ -2453,11 +2483,13 @@ static int string_to_priority(const char* name) const size_t N_LOG_PRIORITY_ENTRIES = sizeof(LOG_PRIORITY_ENTRIES) / sizeof(LOG_PRIORITY_ENTRIES[0]); struct log_priority_entry key = { name, -1 }; - struct log_priority_entry* result = bsearch(&key, - LOG_PRIORITY_ENTRIES, - N_LOG_PRIORITY_ENTRIES, - sizeof(struct log_priority_entry), - compare_log_priority_entries); + void* value = bsearch(&key, + LOG_PRIORITY_ENTRIES, + N_LOG_PRIORITY_ENTRIES, + sizeof(struct log_priority_entry), + compare_log_priority_entries); + + struct log_priority_entry* result = static_cast(value); return result ? result->priority : -1; } @@ -2561,7 +2593,9 @@ set_log_throttling(DCB *dcb, int count, int window_ms, int suppress_ms) { if ((count >= 0) || (window_ms >= 0) || (suppress_ms >= 0)) { - MXS_LOG_THROTTLING t = { count, window_ms, suppress_ms }; + MXS_LOG_THROTTLING t = { static_cast(count), + static_cast(window_ms), + static_cast(suppress_ms) }; mxs_log_set_throttling(&t); } diff --git a/server/modules/routing/maxinfo/CMakeLists.txt b/server/modules/routing/maxinfo/CMakeLists.txt index f4bd0b294..246b4ae2a 100644 --- a/server/modules/routing/maxinfo/CMakeLists.txt +++ b/server/modules/routing/maxinfo/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(maxinfo SHARED maxinfo.c maxinfo_parse.c maxinfo_error.c maxinfo_exec.c) +add_library(maxinfo SHARED maxinfo.cc maxinfo_parse.cc maxinfo_error.cc maxinfo_exec.cc) set_target_properties(maxinfo PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_LIBDIR} VERSION "1.0.0") target_link_libraries(maxinfo maxscale-common) install_module(maxinfo core) diff --git a/server/modules/routing/maxinfo/maxinfo.c b/server/modules/routing/maxinfo/maxinfo.cc similarity index 98% rename from server/modules/routing/maxinfo/maxinfo.c rename to server/modules/routing/maxinfo/maxinfo.cc index 4792ab6dd..6f6913e2f 100644 --- a/server/modules/routing/maxinfo/maxinfo.c +++ b/server/modules/routing/maxinfo/maxinfo.cc @@ -92,7 +92,7 @@ static INFO_INSTANCE *instances; * * @return The module object */ -MXS_MODULE* MXS_CREATE_MODULE() +extern "C" MXS_MODULE* MXS_CREATE_MODULE() { MXS_NOTICE("Initialise MaxInfo router module."); spinlock_init(&instlock); @@ -149,7 +149,7 @@ createInstance(SERVICE *service, char **options) INFO_INSTANCE *inst; int i; - if ((inst = MXS_MALLOC(sizeof(INFO_INSTANCE))) == NULL) + if ((inst = static_cast(MXS_MALLOC(sizeof(INFO_INSTANCE)))) == NULL) { return NULL; } @@ -207,7 +207,7 @@ newSession(MXS_ROUTER *instance, MXS_SESSION *session) session->state = SESSION_STATE_READY; - return (void *)client; + return reinterpret_cast(client); } /** @@ -329,7 +329,7 @@ execute(MXS_ROUTER *rinstance, MXS_ROUTER_SESSION *router_session, GWBUF *queue) } data = (uint8_t *)GWBUF_DATA(queue); length = data[0] + (data[1] << 8) + (data[2] << 16); - if (length + 4 > GWBUF_LENGTH(queue)) + if (length + 4 > static_cast(GWBUF_LENGTH(queue))) { // Incomplete packet, must be buffered session->queue = queue; @@ -684,7 +684,7 @@ typedef RESULTSET *(*RESULTSETFUNC)(); */ static struct uri_table { - char *uri; + const char *uri; RESULTSETFUNC func; } supported_uri[] = { diff --git a/server/modules/routing/maxinfo/maxinfo.h b/server/modules/routing/maxinfo/maxinfo.h index 973091af8..1ca9659aa 100644 --- a/server/modules/routing/maxinfo/maxinfo.h +++ b/server/modules/routing/maxinfo/maxinfo.h @@ -135,9 +135,8 @@ typedef enum extern MAXINFO_TREE *maxinfo_parse(char *, PARSE_ERROR *); extern void maxinfo_free_tree(MAXINFO_TREE *); extern void maxinfo_execute(DCB *, MAXINFO_TREE *); -extern void maxinfo_send_error(DCB *, int, char *); +extern void maxinfo_send_error(DCB *, int, const char *); extern void maxinfo_send_parse_error(DCB *, char *, PARSE_ERROR); -extern void maxinfo_send_error(DCB *, int, char *); extern RESULTSET *maxinfo_variables(); extern RESULTSET *maxinfo_status(); diff --git a/server/modules/routing/maxinfo/maxinfo_error.c b/server/modules/routing/maxinfo/maxinfo_error.cc similarity index 96% rename from server/modules/routing/maxinfo/maxinfo_error.c rename to server/modules/routing/maxinfo/maxinfo_error.cc index 4ebfaa748..7fb5d5d60 100644 --- a/server/modules/routing/maxinfo/maxinfo_error.c +++ b/server/modules/routing/maxinfo/maxinfo_error.cc @@ -51,7 +51,7 @@ void maxinfo_send_parse_error(DCB *dcb, char *sql, PARSE_ERROR err) { - char *desc = ""; + const char *desc = ""; char *msg; int len; @@ -86,7 +86,7 @@ maxinfo_send_parse_error(DCB *dcb, char *sql, PARSE_ERROR err) * @param msg The slave server instance */ void -maxinfo_send_error(DCB *dcb, int errcode, char *msg) +maxinfo_send_error(DCB *dcb, int errcode, const char *msg) { GWBUF *pkt; unsigned char *data; diff --git a/server/modules/routing/maxinfo/maxinfo_exec.c b/server/modules/routing/maxinfo/maxinfo_exec.cc similarity index 96% rename from server/modules/routing/maxinfo/maxinfo_exec.c rename to server/modules/routing/maxinfo/maxinfo_exec.cc index ae7003448..af675045b 100644 --- a/server/modules/routing/maxinfo/maxinfo_exec.c +++ b/server/modules/routing/maxinfo/maxinfo_exec.cc @@ -55,7 +55,7 @@ static void exec_show(DCB *dcb, MAXINFO_TREE *tree); static void exec_select(DCB *dcb, MAXINFO_TREE *tree); static void exec_show_variables(DCB *dcb, MAXINFO_TREE *filter); static void exec_show_status(DCB *dcb, MAXINFO_TREE *filter); -static int maxinfo_pattern_match(char *pattern, char *str); +static int maxinfo_pattern_match(const char *pattern, const char *str); static void exec_flush(DCB *dcb, MAXINFO_TREE *tree); static void exec_set(DCB *dcb, MAXINFO_TREE *tree); static void exec_clear(DCB *dcb, MAXINFO_TREE *tree); @@ -272,7 +272,7 @@ exec_show_eventTimes(DCB *dcb, MAXINFO_TREE *tree) */ static struct { - char *name; + const char *name; void (*func)(DCB *, MAXINFO_TREE *); } show_commands[] = { @@ -334,7 +334,7 @@ void exec_flush_logs(DCB *dcb, MAXINFO_TREE *tree) */ static struct { - char *name; + const char *name; void (*func)(DCB *, MAXINFO_TREE *); } flush_commands[] = { @@ -421,7 +421,7 @@ void exec_set_server(DCB *dcb, MAXINFO_TREE *tree) */ static struct { - char *name; + const char *name; void (*func)(DCB *, MAXINFO_TREE *); } set_commands[] = { @@ -502,7 +502,7 @@ void exec_clear_server(DCB *dcb, MAXINFO_TREE *tree) */ static struct { - char *name; + const char *name; void (*func)(DCB *, MAXINFO_TREE *); } clear_commands[] = { @@ -621,7 +621,7 @@ void exec_shutdown_service(DCB *dcb, MAXINFO_TREE *tree) */ static struct { - char *name; + const char *name; void (*func)(DCB *, MAXINFO_TREE *); } shutdown_commands[] = { @@ -731,7 +731,7 @@ void exec_restart_service(DCB *dcb, MAXINFO_TREE *tree) */ static struct { - char *name; + const char *name; void (*func)(DCB *, MAXINFO_TREE *); } restart_commands[] = { @@ -777,10 +777,10 @@ exec_restart(DCB *dcb, MAXINFO_TREE *tree) static char * getVersion() { - return MAXSCALE_VERSION; + return const_cast(MAXSCALE_VERSION); } -static char *versionComment = "MariaDB MaxScale"; +static const char *versionComment = "MariaDB MaxScale"; /** * Return the current MaxScale version * @@ -789,7 +789,7 @@ static char *versionComment = "MariaDB MaxScale"; static char * getVersionComment() { - return versionComment; + return const_cast(versionComment); } /** @@ -813,7 +813,7 @@ typedef void *(*STATSFUNC)(); */ static struct { - char *name; + const char *name; int type; STATSFUNC func; } variables[] = @@ -833,7 +833,7 @@ static struct typedef struct { int index; - char *like; + const char *like; } VARCONTEXT; /** * Callback function to populate rows of the show variable @@ -894,7 +894,7 @@ exec_show_variables(DCB *dcb, MAXINFO_TREE *filter) RESULTSET *result; VARCONTEXT *context; - if ((context = MXS_MALLOC(sizeof(VARCONTEXT))) == NULL) + if ((context = static_cast(MXS_MALLOC(sizeof(VARCONTEXT)))) == NULL) { return; } @@ -931,7 +931,7 @@ maxinfo_variables() { RESULTSET *result; VARCONTEXT *context; - if ((context = MXS_MALLOC(sizeof(VARCONTEXT))) == NULL) + if ((context = static_cast(MXS_MALLOC(sizeof(VARCONTEXT)))) == NULL) { return NULL; } @@ -1079,9 +1079,9 @@ maxinfo_max_event_exec_time() */ static struct { - char *name; - int type; - STATSFUNC func; + const char *name; + int type; + STATSFUNC func; } status[] = { { "Uptime", VT_INT, (STATSFUNC)maxscale_uptime }, @@ -1166,7 +1166,7 @@ exec_show_status(DCB *dcb, MAXINFO_TREE *filter) RESULTSET *result; VARCONTEXT *context; - if ((context = MXS_MALLOC(sizeof(VARCONTEXT))) == NULL) + if ((context = static_cast(MXS_MALLOC(sizeof(VARCONTEXT)))) == NULL) { return; } @@ -1203,7 +1203,7 @@ maxinfo_status() { RESULTSET *result; VARCONTEXT *context; - if ((context = MXS_MALLOC(sizeof(VARCONTEXT))) == NULL) + if ((context = static_cast(MXS_MALLOC(sizeof(VARCONTEXT)))) == NULL) { return NULL; } @@ -1242,10 +1242,10 @@ exec_select(DCB *dcb, MAXINFO_TREE *tree) * @return Zero on match */ static int -maxinfo_pattern_match(char *pattern, char *str) +maxinfo_pattern_match(const char *pattern, const char *str) { int anchor = 0, len, trailing; - char *fixed; + const char *fixed; if (*pattern != '%') { @@ -1275,7 +1275,7 @@ maxinfo_pattern_match(char *pattern, char *str) } else { - char *portion = MXS_MALLOC(len + 1); + char *portion = static_cast(MXS_MALLOC(len + 1)); MXS_ABORT_IF_NULL(portion); int rval; strncpy(portion, fixed, len - trailing); diff --git a/server/modules/routing/maxinfo/maxinfo_parse.c b/server/modules/routing/maxinfo/maxinfo_parse.cc similarity index 99% rename from server/modules/routing/maxinfo/maxinfo_parse.c rename to server/modules/routing/maxinfo/maxinfo_parse.cc index 1f00c6871..572e9e69e 100644 --- a/server/modules/routing/maxinfo/maxinfo_parse.c +++ b/server/modules/routing/maxinfo/maxinfo_parse.cc @@ -305,7 +305,7 @@ maxinfo_free_tree(MAXINFO_TREE *tree) */ static struct { - char *text; + const char *text; int token; } keywords[] = { diff --git a/server/modules/routing/readconnroute/CMakeLists.txt b/server/modules/routing/readconnroute/CMakeLists.txt index c8463d622..f60039745 100644 --- a/server/modules/routing/readconnroute/CMakeLists.txt +++ b/server/modules/routing/readconnroute/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(readconnroute SHARED readconnroute.c) +add_library(readconnroute SHARED readconnroute.cc) target_link_libraries(readconnroute maxscale-common) set_target_properties(readconnroute PROPERTIES VERSION "1.1.0") install_module(readconnroute core) diff --git a/server/modules/routing/readconnroute/readconnroute.c b/server/modules/routing/readconnroute/readconnroute.cc similarity index 99% rename from server/modules/routing/readconnroute/readconnroute.c rename to server/modules/routing/readconnroute/readconnroute.cc index 47b2b2dc0..d953c851a 100644 --- a/server/modules/routing/readconnroute/readconnroute.c +++ b/server/modules/routing/readconnroute/readconnroute.cc @@ -112,7 +112,7 @@ static SERVER_REF *get_root_master(SERVER_REF *servers); * * @return The module object */ -MXS_MODULE* MXS_CREATE_MODULE() +extern "C" MXS_MODULE* MXS_CREATE_MODULE() { MXS_NOTICE("Initialise readconnroute router module."); @@ -176,7 +176,7 @@ createInstance(SERVICE *service, char **options) SERVER_REF *sref; int i, n; - if ((inst = MXS_CALLOC(1, sizeof(ROUTER_INSTANCE))) == NULL) + if ((inst = static_cast(MXS_CALLOC(1, sizeof(ROUTER_INSTANCE)))) == NULL) { return NULL; } @@ -433,7 +433,7 @@ newSession(MXS_ROUTER *instance, MXS_SESSION *session) MXS_INFO("New session for server %s. Connections : %d", candidate->server->name, candidate->connections); - return (void *) client_rses; + return reinterpret_cast(client_rses); } /** @@ -613,6 +613,7 @@ routeQuery(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session, GWBUF *queu } bool valid; + char* trc = NULL; if (rses_is_closed || backend_dcb == NULL || (valid = !connection_is_valid(inst, router_cli_ses))) @@ -623,8 +624,6 @@ routeQuery(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session, GWBUF *queu } - char* trc = NULL; - switch (mysql_command) { case MXS_COM_CHANGE_USER: diff --git a/server/modules/routing/readwritesplit/readwritesplit.cc b/server/modules/routing/readwritesplit/readwritesplit.cc index 39dd216ce..03c6fba52 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.cc +++ b/server/modules/routing/readwritesplit/readwritesplit.cc @@ -419,14 +419,12 @@ uint64_t RWSplit::getCapabilities() RCAP_TYPE_PACKET_OUTPUT | RCAP_TYPE_SESSION_STATE_TRACKING; } -MXS_BEGIN_DECLS - /** * The module entry point routine. It is this routine that must return * the structure that is referred to as the "module object". This is a * structure with the set of external entry points for this module. */ -MXS_MODULE *MXS_CREATE_MODULE() +extern "C" MXS_MODULE *MXS_CREATE_MODULE() { static MXS_MODULE info = { @@ -485,5 +483,3 @@ MXS_MODULE *MXS_CREATE_MODULE() MXS_NOTICE("Initializing statement-based read/write split router module."); return &info; } - -MXS_END_DECLS diff --git a/server/modules/routing/schemarouter/schemarouterinstance.cc b/server/modules/routing/schemarouter/schemarouterinstance.cc index 4c563effb..83d21f82f 100644 --- a/server/modules/routing/schemarouter/schemarouterinstance.cc +++ b/server/modules/routing/schemarouter/schemarouterinstance.cc @@ -369,8 +369,6 @@ uint64_t SchemaRouter::getCapabilities() } -MXS_BEGIN_DECLS - /** * The module entry point routine. It is this routine that * must populate the structure that is referred to as the @@ -379,7 +377,7 @@ MXS_BEGIN_DECLS * * @return The module object */ -MXS_MODULE* MXS_CREATE_MODULE() +extern "C" MXS_MODULE* MXS_CREATE_MODULE() { static MXS_MODULE info = { @@ -409,5 +407,3 @@ MXS_MODULE* MXS_CREATE_MODULE() return &info; } - -MXS_END_DECLS