Commit 426b4b2e authored by unknown's avatar unknown

Merge tulin@bk-internal.mysql.com:/home/bk/mysql-4.1

into poseidon.ndb.mysql.com:/home/tomas/mysql-4.1
parents 458754fb f0d53aeb
......@@ -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
......
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment