summaryrefslogtreecommitdiff
path: root/ndb
diff options
context:
space:
mode:
authorunknown <tomas@poseidon.ndb.mysql.com>2004-10-18 09:37:48 +0000
committerunknown <tomas@poseidon.ndb.mysql.com>2004-10-18 09:37:48 +0000
commite7e86d20f96b21af4f90315884439a75b3c0709c (patch)
tree1540582cf82e50a008007d59d8de0b2d4c6c56d1 /ndb
parent221d51ebb1b178061904e68cc2ff40a11da835d1 (diff)
downloadmariadb-git-e7e86d20f96b21af4f90315884439a75b3c0709c.tar.gz
remove possibility of connectstring error like "hostname=..."
+ some fixed string length cleanup + fixed a better error printout
Diffstat (limited to 'ndb')
-rw-r--r--ndb/include/mgmcommon/LocalConfig.hpp4
-rw-r--r--ndb/src/common/mgmcommon/LocalConfig.cpp47
2 files changed, 27 insertions, 24 deletions
diff --git a/ndb/include/mgmcommon/LocalConfig.hpp b/ndb/include/mgmcommon/LocalConfig.hpp
index c741b35f482..9ceeffdba36 100644
--- a/ndb/include/mgmcommon/LocalConfig.hpp
+++ b/ndb/include/mgmcommon/LocalConfig.hpp
@@ -53,14 +53,14 @@ struct LocalConfig {
void printUsage() const;
void setError(int lineNumber, const char * _msg);
- bool readConnectString(const char *);
+ bool readConnectString(const char *, const char *info);
bool readFile(const char * file, bool &fopenError);
bool parseLine(char * line, int lineNumber);
bool parseNodeId(const char *buf);
bool parseHostName(const char *buf);
bool parseFileName(const char *buf);
- bool parseString(const char *buf, char *line);
+ bool parseString(const char *buf, BaseString &err);
};
#endif // LocalConfig_H
diff --git a/ndb/src/common/mgmcommon/LocalConfig.cpp b/ndb/src/common/mgmcommon/LocalConfig.cpp
index cc66f357236..4a558d8421a 100644
--- a/ndb/src/common/mgmcommon/LocalConfig.cpp
+++ b/ndb/src/common/mgmcommon/LocalConfig.cpp
@@ -40,7 +40,7 @@ LocalConfig::init(const char *connectString,
//1. Check connectString
if(connectString != 0 && connectString[0] != 0){
- if(readConnectString(connectString)){
+ if(readConnectString(connectString, "connect string")){
return true;
}
return false;
@@ -59,7 +59,7 @@ LocalConfig::init(const char *connectString,
char buf[255];
if(NdbEnv_GetEnv("NDB_CONNECTSTRING", buf, sizeof(buf)) &&
strlen(buf) != 0){
- if(readConnectString(buf)){
+ if(readConnectString(buf, "NDB_CONNECTSTRING")){
return true;
}
return false;
@@ -91,7 +91,7 @@ LocalConfig::init(const char *connectString,
{
char buf[256];
snprintf(buf, sizeof(buf), "host=localhost:%s", NDB_BASE_PORT);
- if(readConnectString(buf))
+ if(readConnectString(buf, "default connect string"))
return true;
}
@@ -109,8 +109,10 @@ void LocalConfig::setError(int lineNumber, const char * _msg) {
}
void LocalConfig::printError() const {
- ndbout << "Local configuration error"<< endl
- << "Line: "<< error_line << ", " << error_msg << endl << endl;
+ ndbout << "Configuration error" << endl;
+ if (error_line)
+ ndbout << "Line: "<< error_line << ", ";
+ ndbout << error_msg << endl << endl;
}
void LocalConfig::printUsage() const {
@@ -140,7 +142,7 @@ const char *nodeIdTokens[] = {
const char *hostNameTokens[] = {
"host://%[^:]:%i",
"host=%[^:]:%i",
- "%[^:]:%i",
+ "%[^:^=^ ]:%i",
"%s %i",
0
};
@@ -192,7 +194,7 @@ LocalConfig::parseFileName(const char * buf){
}
bool
-LocalConfig::parseString(const char * connectString, char *line){
+LocalConfig::parseString(const char * connectString, BaseString &err){
char * for_strtok;
char * copy = strdup(connectString);
NdbAutoPtr<char> tmp_aptr(copy);
@@ -212,15 +214,12 @@ LocalConfig::parseString(const char * connectString, char *line){
if (found_other = parseFileName(tok))
continue;
- if (line)
- snprintf(line, 150, "Unexpected entry: \"%s\"", tok);
+ err.assfmt("Unexpected entry: \"%s\"", tok);
return false;
}
if (!found_other) {
- if (line)
- snprintf(line, 150, "Missing host/file name extry in \"%s\"",
- connectString);
+ err.appfmt("Missing host/file name extry in \"%s\"", connectString);
return false;
}
@@ -235,7 +234,8 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError)
FILE * file = fopen(filename, "r");
if(file == 0){
- snprintf(line, 150, "Unable to open local config file: %s", filename);
+ snprintf(line, sizeof(line),
+ "Unable to open local config file: %s", filename);
setError(0, line);
fopenError = true;
return false;
@@ -243,7 +243,7 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError)
BaseString theString;
- while(fgets(line, 1024, file)){
+ while(fgets(line, sizeof(line), file)){
BaseString tmp(line);
tmp.trim(" \t\n\r");
if(tmp.length() > 0 && tmp.c_str()[0] != '#'){
@@ -251,7 +251,7 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError)
break;
}
}
- while (fgets(line, 1024, file)) {
+ while (fgets(line, sizeof(line), file)) {
BaseString tmp(line);
tmp.trim(" \t\n\r");
if(tmp.length() > 0 && tmp.c_str()[0] != '#'){
@@ -260,11 +260,12 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError)
}
}
- bool return_value = parseString(theString.c_str(), line);
+ BaseString err;
+ bool return_value = parseString(theString.c_str(), err);
if (!return_value) {
BaseString tmp;
- tmp.assfmt("Reading %s: %s", filename, line);
+ tmp.assfmt("Reading %s: %s", filename, err.c_str());
setError(0, tmp.c_str());
}
@@ -273,12 +274,14 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError)
}
bool
-LocalConfig::readConnectString(const char * connectString){
- char line[150], line2[150];
- bool return_value = parseString(connectString, line);
+LocalConfig::readConnectString(const char * connectString,
+ const char * info){
+ BaseString err;
+ bool return_value = parseString(connectString, err);
if (!return_value) {
- snprintf(line2, 150, "Reading NDB_CONNECTSTRING \"%s\": %s", connectString, line);
- setError(0,line2);
+ BaseString err2;
+ err2.assfmt("Reading %d \"%s\": %s", info, connectString, err.c_str());
+ setError(0,err2.c_str());
}
return return_value;
}