Fix fixing of std::string object names

Comparing two fixed std::strings would have equal C strings but comparing
with operator== they would be different. This was a result of the string
modification done by fix_object_name.

Converted the internal header into a C++ header, added std::string
overload and fixed use of the function.
This commit is contained in:
Markus Mäkelä 2018-07-29 10:59:58 +03:00
parent afde1fa072
commit 3be975ba5d
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
11 changed files with 25 additions and 20 deletions

View File

@ -50,7 +50,7 @@
#include <maxscale/utils.hh>
#include <maxscale/version.h>
#include "internal/config.h"
#include "internal/config.hh"
#include "internal/event.hh"
#include "internal/filter.hh"
#include "internal/modules.h"
@ -550,6 +550,14 @@ void fix_object_name(char *name)
replace_whitespace(name);
}
void fix_object_name(std::string& name)
{
char buf[name.size() + 1];
strcpy(buf, name.c_str());
fix_object_name(buf);
name.assign(buf);
}
static bool is_empty_string(const char* str)
{
for (const char* p = str; *p; p++)
@ -3206,9 +3214,9 @@ int configure_new_service(CONFIG_CONTEXT *obj)
Service *service = static_cast<Service*>(obj->element);
ss_dassert(service);
for (auto&& a: mxs::strtok(config_get_string(obj->parameters, CN_SERVERS), ","))
for (auto&& a : mxs::strtok(config_get_string(obj->parameters, CN_SERVERS), ","))
{
fix_object_name(&a[0]);
fix_object_name(a);
if (SERVER* s = server_find_by_unique_name(a.c_str()))
{
@ -3246,9 +3254,9 @@ int create_new_monitor(CONFIG_CONTEXT *obj, std::set<std::string>& monitored_ser
bool err = false;
// TODO: Use server list parameter type for this
for (auto&& s: mxs::strtok(config_get_string(obj->parameters, CN_SERVERS), ","))
for (auto&& s : mxs::strtok(config_get_string(obj->parameters, CN_SERVERS), ","))
{
fix_object_name(&s[0]);
fix_object_name(s);
SERVER* server = server_find_by_unique_name(s.c_str());
if (!server)

View File

@ -34,7 +34,7 @@
#include <maxscale/users.h>
#include <maxscale/router.h>
#include "internal/config.h"
#include "internal/config.hh"
#include "internal/monitor.h"
#include "internal/modules.h"
#include "internal/filter.hh"

View File

@ -37,7 +37,7 @@
#include <maxscale/json_api.h>
#include <algorithm>
#include "internal/config.h"
#include "internal/config.hh"
#include "internal/modules.h"
#include "internal/service.hh"

View File

@ -56,7 +56,7 @@
#include <maxscale/random_jkiss.h>
#include "internal/admin.hh"
#include "internal/config.h"
#include "internal/config.hh"
#include "internal/maxscale.h"
#include "internal/modules.h"
#include "internal/monitor.h"

View File

@ -21,8 +21,6 @@
#include <maxscale/ssl.h>
#include <maxscale/jansson.h>
MXS_BEGIN_DECLS
#define DEFAULT_NBPOLLS 3 /**< Default number of non block polls before we block */
#define DEFAULT_POLLSLEEP 1000 /**< Default poll wait time (milliseconds) */
#define DEFAULT_NTHREADS 1 /**< Default number of polling threads */
@ -182,6 +180,7 @@ void config_add_module_params_json(const MXS_MODULE* mod,
* @param name Object name to fix
*/
void fix_object_name(char *name);
void fix_object_name(std::string& name);
/**
* @brief Serialize global options
@ -200,5 +199,3 @@ bool config_global_serialize();
bool export_config_file(const char* filename);
bool is_normal_server_parameter(const char *param);
MXS_END_DECLS

View File

@ -41,7 +41,7 @@
#include <maxscale/query_classifier.h>
#include "internal/modules.h"
#include "internal/config.h"
#include "internal/config.hh"
namespace
{

View File

@ -41,7 +41,7 @@
#include <maxscale/json_api.h>
#include <mysqld_error.h>
#include "internal/config.h"
#include "internal/config.hh"
#include "internal/externcmd.h"
#include "internal/monitor.h"
#include "internal/modules.h"
@ -144,7 +144,7 @@ MXS_MONITOR* monitor_create(const char *name, const char *module, MXS_CONFIG_PAR
for (auto&& s: mxs::strtok(config_get_string(params, CN_SERVERS), ","))
{
fix_object_name(&s[0]);
fix_object_name(s);
monitor_add_server(mon, server_find_by_unique_name(s.c_str()));
}

View File

@ -44,7 +44,7 @@
#include "internal/monitor.h"
#include "internal/poll.h"
#include "internal/routingworker.hh"
#include "internal/config.h"
#include "internal/config.hh"
#include "internal/service.hh"

View File

@ -55,7 +55,7 @@
#include <maxscale/json_api.h>
#include <maxscale/routingworker.h>
#include "internal/config.h"
#include "internal/config.hh"
#include "internal/filter.hh"
#include "internal/modules.h"
#include "internal/service.hh"
@ -1243,7 +1243,7 @@ bool service_set_filters(Service* service, const char* filters)
for (auto&& f: mxs::strtok(filters, "|"))
{
fix_object_name(&f[0]);
fix_object_name(f);
if (FilterDef* def = filter_find(f.c_str()))
{

View File

@ -42,7 +42,7 @@
#include <maxscale/alloc.h>
#include <maxscale/utils.hh>
#include "../../../../core/internal/modules.h"
#include "../../../../core/internal/config.h"
#include "../../../../core/internal/config.hh"
#include <maxscale/protocol/mysql.h>
#include <ini.h>

View File

@ -56,7 +56,7 @@
#include <debugcli.h>
#include "../../../core/internal/config.h"
#include "../../../core/internal/config.hh"
#include "../../../core/internal/config_runtime.h"
#include "../../../core/internal/maxscale.h"
#include "../../../core/internal/modules.h"