25
25
int FindToken(const wxString &str, const wxChar **list)
28
for (index = 0 ; list[index] ; index++)
30
if (list[index] == str)
28
for (index = 0 ; list[index] ; index++)
30
if (list[index] == str)
38
const wxChar *pgConfigTypeStrings[]=
38
const wxChar *pgConfigTypeStrings[] =
48
48
void pgSettingItem::SetType(const wxString &str)
50
int index=FindToken(str, pgConfigTypeStrings);
54
type = (pgConfigType)index;
50
int index = FindToken(str, pgConfigTypeStrings);
54
type = (pgConfigType)index;
58
const wxChar *pgConfigContextStrings[]=
58
const wxChar *pgConfigContextStrings[] =
71
71
void pgSettingItem::SetContext(const wxString &str)
73
int index = FindToken(str, pgConfigContextStrings);
75
context = PGC_INTERNAL;
77
context = (pgConfigContext)index;
73
int index = FindToken(str, pgConfigContextStrings);
75
context = PGC_INTERNAL;
77
context = (pgConfigContext)index;
81
const wxChar *pgConfigSourceStrings[]=
81
const wxChar *pgConfigSourceStrings[] =
84
wxT("environment variable"),
85
wxT("configuration file"),
84
wxT("environment variable"),
85
wxT("configuration file"),
99
99
void pgSettingItem::SetSource(const wxString &str)
101
int index = FindToken(str, pgConfigSourceStrings);
103
source = PGC_UNKNOWNSOURCE;
105
source = (pgConfigSource)index;
101
int index = FindToken(str, pgConfigSourceStrings);
103
source = PGC_UNKNOWNSOURCE;
105
source = (pgConfigSource)index;
109
109
wxString pgSettingItem::GetActiveValue()
113
if (!newLine->isComment)
114
return newLine->value;
118
if (!orgLine->isComment)
119
return orgLine->value;
113
if (!newLine->isComment)
114
return newLine->value;
118
if (!orgLine->isComment)
119
return orgLine->value;
125
125
pgConfigLine::pgConfigLine(pgConfigLine *line)
129
comment=line->comment;
130
isComment = line->isComment;
129
comment = line->comment;
130
isComment = line->isComment;
134
134
bool pgConfigLine::Differs(pgConfigLine *line)
136
return value != line->value || comment != line->comment || isComment != line->isComment;
136
return value != line->value || comment != line->comment || isComment != line->isComment;
140
140
wxString pgConfigLine::GetNewText()
144
if (item->type == pgSettingItem::PGC_STRING)
146
if (value.Find('\'') >= 0)
154
newLine += item->name + wxT(" = ")
155
+ quote + value + quote;
157
if (!comment.IsEmpty())
159
if (item->orgLine && item->orgLine->commentIndent.Find('#') >= 0)
160
newLine += item->orgLine->commentIndent;
162
newLine += DEFAULT_COMMENT_INDEX;
144
if (item->type == pgSettingItem::PGC_STRING)
146
if (value.Find('\'') >= 0)
154
newLine += item->name + wxT(" = ")
155
+ quote + value + quote;
157
if (!comment.IsEmpty())
159
if (item->orgLine && item->orgLine->commentIndent.Find('#') >= 0)
160
newLine += item->orgLine->commentIndent;
162
newLine += DEFAULT_COMMENT_INDEX;
169
169
pgConfigOrgLine::pgConfigOrgLine(pgConfigLine *line) : pgConfigLine(line)
171
text = line->GetNewText();
173
commentIndent = DEFAULT_COMMENT_INDEX;
171
text = line->GetNewText();
173
commentIndent = DEFAULT_COMMENT_INDEX;
177
177
wxString pgConfigOrgLine::GetNewText()
179
if (!item || !item->newLine)
181
return item->newLine->GetNewText();
179
if (!item || !item->newLine)
181
return item->newLine->GetNewText();
220
220
pgSettingItem *pgSettingFileReader::GetNextItem()
222
if (!bp || !*bp || *bp == '\n')
225
pgSettingItem *item=new pgSettingItem;
226
wxStringTokenizer tk(columnNames, wxT(";"));
227
wxString column=tk.GetNextToken();
239
while (*c && *c != '\n')
255
if (column == wxT("name") || column == wxT("\"name\""))
256
item->name = value.Lower();
257
else if (column == wxT("category") || column == wxT("\"category\""))
258
item->category = value;
259
else if (column == wxT("short_desc") || column == wxT("\"short_desc\""))
260
item->short_desc = value;
261
else if (column == wxT("extra_desc") || column == wxT("\"extra_desc\""))
262
item->extra_desc = value;
263
else if (column == wxT("min_val") || column == wxT("\"min_val\""))
264
item->min_val = value;
265
else if (column == wxT("max_val") || column == wxT("\"max_val\""))
266
item->max_val = value;
267
else if (column == wxT("context") || column == wxT("\"context\""))
268
item->SetContext(value);
269
else if (column == wxT("vartype") || column == wxT("\"vartype\""))
270
item->SetType(value);
272
column = tk.GetNextToken();
222
if (!bp || !*bp || *bp == '\n')
225
pgSettingItem *item = new pgSettingItem;
226
wxStringTokenizer tk(columnNames, wxT(";"));
227
wxString column = tk.GetNextToken();
239
while (*c && *c != '\n')
255
if (column == wxT("name") || column == wxT("\"name\""))
256
item->name = value.Lower();
257
else if (column == wxT("category") || column == wxT("\"category\""))
258
item->category = value;
259
else if (column == wxT("short_desc") || column == wxT("\"short_desc\""))
260
item->short_desc = value;
261
else if (column == wxT("extra_desc") || column == wxT("\"extra_desc\""))
262
item->extra_desc = value;
263
else if (column == wxT("min_val") || column == wxT("\"min_val\""))
264
item->min_val = value;
265
else if (column == wxT("max_val") || column == wxT("\"max_val\""))
266
item->max_val = value;
267
else if (column == wxT("context") || column == wxT("\"context\""))
268
item->SetContext(value);
269
else if (column == wxT("vartype") || column == wxT("\"vartype\""))
270
item->SetType(value);
272
column = tk.GetNextToken();
296
296
pgSettingDbReader::pgSettingDbReader(pgConn *conn)
298
set=conn->ExecuteSet(wxT("SELECT name, setting, source, category, short_desc, extra_desc, context, vartype, min_val, max_val FROM pg_settings ORDER BY name"));
298
set = conn->ExecuteSet(wxT("SELECT name, setting, source, category, short_desc, extra_desc, context, vartype, min_val, max_val FROM pg_settings ORDER BY name"));
302
302
pgSettingDbReader::~pgSettingDbReader()
308
308
pgSettingItem *pgSettingDbReader::GetNextItem()
313
pgSettingItem *item=new pgSettingItem;
315
item->name = set->GetVal(wxT("name")).Lower();
316
item->category = set->GetVal(wxT("category"));
317
item->short_desc = set->GetVal(wxT("short_desc"));
318
item->extra_desc = set->GetVal(wxT("extra_desc"));
319
item->min_val = set->GetVal(wxT("min_val"));
320
item->max_val = set->GetVal(wxT("max_val"));
321
item->SetContext(set->GetVal(wxT("context")));
322
item->SetType(set->GetVal(wxT("vartype")));
323
item->SetSource(set->GetVal(wxT("source")));
324
item->value = set->GetVal(wxT("setting"));
313
pgSettingItem *item = new pgSettingItem;
315
item->name = set->GetVal(wxT("name")).Lower();
316
item->category = set->GetVal(wxT("category"));
317
item->short_desc = set->GetVal(wxT("short_desc"));
318
item->extra_desc = set->GetVal(wxT("extra_desc"));
319
item->min_val = set->GetVal(wxT("min_val"));
320
item->max_val = set->GetVal(wxT("max_val"));
321
item->SetContext(set->GetVal(wxT("context")));
322
item->SetType(set->GetVal(wxT("vartype")));
323
item->SetSource(set->GetVal(wxT("source")));
324
item->value = set->GetVal(wxT("setting"));
334
334
// must match enum pgHbaConnectType!!!
335
335
const wxChar *pgHbaConnectTypeStrings[] =
345
345
// must match enum pgHbaMethod!!!
346
346
const wxChar *pgHbaMethodStrings[] =
364
bool IsSpaceChar(wxChar c, const wxChar *spaceChars=wxT("\t "))
366
return wxStrchr(spaceChars, c) != NULL;
370
void SkipSpace(const wxChar* &ptr, const wxChar *spaceChars=wxT("\t "))
372
while (*ptr && IsSpaceChar(*ptr))
377
void SkipNonspace(const wxChar* &ptr, const wxChar *spaceChars=wxT("\t "))
379
while (*ptr && !IsSpaceChar(*ptr))
364
bool IsSpaceChar(wxChar c, const wxChar *spaceChars = wxT("\t "))
366
return wxStrchr(spaceChars, c) != NULL;
370
void SkipSpace(const wxChar* &ptr, const wxChar *spaceChars = wxT("\t "))
372
while (*ptr && IsSpaceChar(*ptr))
377
void SkipNonspace(const wxChar* &ptr, const wxChar *spaceChars = wxT("\t "))
379
while (*ptr && !IsSpaceChar(*ptr))
384
384
pgHbaConfigLine::pgHbaConfigLine(const wxString &line)
387
connectType = PGC_INVALIDCONF;
388
method = PGC_INVALIDMETHOD;
387
connectType = PGC_INVALIDCONF;
388
method = PGC_INVALIDMETHOD;
393
393
void pgHbaConfigLine::Init(const wxString &line)
395
connectType = PGC_INVALIDCONF;
403
const wxChar *p0=line.c_str();
418
wxString str=line.Mid(p0-line.c_str(), p1-p0);
420
int i=FindToken(str, pgHbaConnectTypeStrings);
423
connectType = (pgHbaConnectType)i;
426
connectType = PGC_INVALIDCONF;
438
if (!quoted && IsSpaceChar(*p2))
445
database = line.Mid(p1-line.c_str(), p2-p1);
454
if (!quoted && IsSpaceChar(*p3))
461
user = line.Mid(p2-line.c_str(), p3-p2);
467
if (connectType == PGC_LOCAL)
474
while (*p4 && !IsSpaceChar(*p4))
486
ipaddress = line.Mid(p3-line.c_str(), p4-p3);
493
str=line.Mid(p4-line.c_str(), p5-p4);
495
i = FindToken(str, pgHbaMethodStrings);
498
method = (pgHbaMethod)i;
501
connectType = PGC_INVALIDCONF;
395
connectType = PGC_INVALIDCONF;
403
const wxChar *p0 = line.c_str();
415
const wxChar *p1 = p0;
418
wxString str = line.Mid(p0 - line.c_str(), p1 - p0);
420
int i = FindToken(str, pgHbaConnectTypeStrings);
423
connectType = (pgHbaConnectType)i;
426
connectType = PGC_INVALIDCONF;
433
const wxChar *p2 = p1;
438
if (!quoted && IsSpaceChar(*p2))
445
database = line.Mid(p1 - line.c_str(), p2 - p1);
449
const wxChar *p3 = p2;
454
if (!quoted && IsSpaceChar(*p3))
461
user = line.Mid(p2 - line.c_str(), p3 - p2);
465
const wxChar *p4 = p3;
467
if (connectType == PGC_LOCAL)
473
bool hasCidr = false;
474
while (*p4 && !IsSpaceChar(*p4))
486
ipaddress = line.Mid(p3 - line.c_str(), p4 - p3);
490
const wxChar *p5 = p4;
493
str = line.Mid(p4 - line.c_str(), p5 - p4);
495
i = FindToken(str, pgHbaMethodStrings);
498
method = (pgHbaMethod)i;
501
connectType = PGC_INVALIDCONF;
510
510
const wxChar *pgHbaConfigLine::GetConnectType()
512
if (connectType >= 0 && connectType < PGC_INVALIDCONF)
513
return pgHbaConnectTypeStrings[connectType];
512
if (connectType >= 0 && connectType < PGC_INVALIDCONF)
513
return pgHbaConnectTypeStrings[connectType];
518
518
const wxChar *pgHbaConfigLine::GetMethod()
520
if (method >= 0 && method < PGC_INVALIDMETHOD)
521
return pgHbaMethodStrings[method];
520
if (method >= 0 && method < PGC_INVALIDMETHOD)
521
return pgHbaMethodStrings[method];
526
526
wxString pgHbaConfigLine::GetText()
532
wxString tabspace=wxT("\t ");
536
str += GetConnectType()
537
+ tabspace + database
540
if (connectType != PGC_LOCAL)
541
str += tabspace + ipaddress;
543
str += tabspace + GetMethod();
545
if (method >= PGC_IDENT && !option.IsEmpty())
546
str += tabspace + option;
532
wxString tabspace = wxT("\t ");
536
str += GetConnectType()
537
+ tabspace + database
540
if (connectType != PGC_LOCAL)
541
str += tabspace + ipaddress;
543
str += tabspace + GetMethod();
545
if (method >= PGC_IDENT && !option.IsEmpty())
546
str += tabspace + option;
552
552
////////////////////////////////////////////////
553
553
pgPassConfigLine::pgPassConfigLine(const wxString &line)
559
559
void pgPassConfigLine::Init(const wxString &line)
566
566
isComment = line.StartsWith(wxT("#"));
568
wxStringTokenizer tok(isComment?line.Mid(1):line, wxT(":"));
568
wxStringTokenizer tok(isComment ? line.Mid(1) : line, wxT(":"));
569
569
if (tok.HasMoreTokens())
570
570
hostname = tok.GetNextToken();
571
571
if (tok.HasMoreTokens())