~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

« back to all changes in this revision

Viewing changes to pgadmin/utils/pgconfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2011-06-07 23:03:54 UTC
  • mfrom: (1.3.1 upstream) (13 sid)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110607230354-3td4j9y71u4ahcvj
Tags: 1.14.0~beta1-1
* New upstream development release, adding Build-Depends on
  postgresql-server-dev-all >= 117~.
* Add Build-Depends on quilt, (un)patch to debian/rules and patch for fixing
  the include for kwlist.h in pgadmin/db/keywords.c.
* Add pg_config --includedir-server output to CPPFLAGS.
* Remove unrecognized configure options: --with-wx-config,
  --with-pgsql-include, --enable-gtk2, --enable-unicode.
* Clean up manually the files that are left behind after the broken
  distclean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//////////////////////////////////////////////////////////////////////////
2
2
//
3
3
// pgAdmin III - PostgreSQL Tools
4
 
// 
5
 
// Copyright (C) 2002 - 2010, The pgAdmin Development Team
 
4
//
 
5
// Copyright (C) 2002 - 2011, The pgAdmin Development Team
6
6
// This software is released under the PostgreSQL Licence
7
7
//
8
8
// pgconfig.cpp - backend configuration classes
24
24
 
25
25
int FindToken(const wxString &str, const wxChar **list)
26
26
{
27
 
    int index;
28
 
    for (index = 0 ; list[index] ; index++)
29
 
    {
30
 
        if (list[index] == str)
31
 
            return index;
 
27
        int index;
 
28
        for (index = 0 ; list[index] ; index++)
 
29
        {
 
30
                if (list[index] == str)
 
31
                        return index;
32
32
 
33
 
    }
34
 
    return -1;
 
33
        }
 
34
        return -1;
35
35
}
36
36
 
37
37
 
38
 
const wxChar *pgConfigTypeStrings[]=
 
38
const wxChar *pgConfigTypeStrings[] =
39
39
{
40
 
    wxT("bool"),
41
 
    wxT("integer"),
42
 
    wxT("real"),
43
 
    wxT("string"),
44
 
    0
 
40
        wxT("bool"),
 
41
        wxT("integer"),
 
42
        wxT("real"),
 
43
        wxT("string"),
 
44
        0
45
45
};
46
46
 
47
 
    
 
47
 
48
48
void pgSettingItem::SetType(const wxString &str)
49
49
{
50
 
    int index=FindToken(str, pgConfigTypeStrings);
51
 
    if (index < 0)
52
 
        type = PGC_STRING;
53
 
    else
54
 
        type = (pgConfigType)index;
 
50
        int index = FindToken(str, pgConfigTypeStrings);
 
51
        if (index < 0)
 
52
                type = PGC_STRING;
 
53
        else
 
54
                type = (pgConfigType)index;
55
55
}
56
56
 
57
57
 
58
 
const wxChar *pgConfigContextStrings[]=
 
58
const wxChar *pgConfigContextStrings[] =
59
59
{
60
 
    wxT("internal"),
61
 
    wxT("postmaster"),
62
 
    wxT("sighup"),
63
 
    wxT("backend"),
64
 
    wxT("superuser"),
65
 
    wxT("userlimit"),
66
 
    wxT("user"),
67
 
    0
 
60
        wxT("internal"),
 
61
        wxT("postmaster"),
 
62
        wxT("sighup"),
 
63
        wxT("backend"),
 
64
        wxT("superuser"),
 
65
        wxT("userlimit"),
 
66
        wxT("user"),
 
67
        0
68
68
};
69
69
 
70
70
 
71
71
void pgSettingItem::SetContext(const wxString &str)
72
72
{
73
 
    int index = FindToken(str, pgConfigContextStrings);
74
 
    if (index < 0)
75
 
        context = PGC_INTERNAL;
76
 
    else
77
 
        context = (pgConfigContext)index;
 
73
        int index = FindToken(str, pgConfigContextStrings);
 
74
        if (index < 0)
 
75
                context = PGC_INTERNAL;
 
76
        else
 
77
                context = (pgConfigContext)index;
78
78
}
79
79
 
80
80
 
81
 
const wxChar *pgConfigSourceStrings[]=
 
81
const wxChar *pgConfigSourceStrings[] =
82
82
{
83
 
    wxT("default"),
84
 
    wxT("environment variable"),
85
 
    wxT("configuration file"),
86
 
    wxT("command line"),
87
 
    wxT("unprivileged"),
88
 
    wxT("database"),
89
 
    wxT("user"),
90
 
    wxT("client"),
91
 
    wxT("override"),
92
 
    wxT("interactive"),
93
 
    wxT("test"),
94
 
    wxT("session"),
95
 
    0
 
83
        wxT("default"),
 
84
        wxT("environment variable"),
 
85
        wxT("configuration file"),
 
86
        wxT("command line"),
 
87
        wxT("unprivileged"),
 
88
        wxT("database"),
 
89
        wxT("user"),
 
90
        wxT("client"),
 
91
        wxT("override"),
 
92
        wxT("interactive"),
 
93
        wxT("test"),
 
94
        wxT("session"),
 
95
        0
96
96
};
97
97
 
98
 
    
 
98
 
99
99
void pgSettingItem::SetSource(const wxString &str)
100
100
{
101
 
    int index = FindToken(str, pgConfigSourceStrings);
102
 
    if (index < 0)
103
 
        source = PGC_UNKNOWNSOURCE;
104
 
    else
105
 
        source = (pgConfigSource)index;
 
101
        int index = FindToken(str, pgConfigSourceStrings);
 
102
        if (index < 0)
 
103
                source = PGC_UNKNOWNSOURCE;
 
104
        else
 
105
                source = (pgConfigSource)index;
106
106
}
107
107
 
108
108
 
109
109
wxString pgSettingItem::GetActiveValue()
110
110
{
111
 
    if (newLine)
112
 
    {
113
 
        if (!newLine->isComment)
114
 
            return newLine->value;
115
 
    }
116
 
    else if (orgLine)
117
 
    {
118
 
        if (!orgLine->isComment)
119
 
            return orgLine->value;
120
 
    }
121
 
    return value;
 
111
        if (newLine)
 
112
        {
 
113
                if (!newLine->isComment)
 
114
                        return newLine->value;
 
115
        }
 
116
        else if (orgLine)
 
117
        {
 
118
                if (!orgLine->isComment)
 
119
                        return orgLine->value;
 
120
        }
 
121
        return value;
122
122
}
123
123
 
124
124
 
125
125
pgConfigLine::pgConfigLine(pgConfigLine *line)
126
126
{
127
 
    item=line->item;
128
 
    value=line->value;
129
 
    comment=line->comment;
130
 
    isComment = line->isComment;
 
127
        item = line->item;
 
128
        value = line->value;
 
129
        comment = line->comment;
 
130
        isComment = line->isComment;
131
131
}
132
132
 
133
133
 
134
134
bool pgConfigLine::Differs(pgConfigLine *line)
135
135
{
136
 
    return value != line->value || comment != line->comment || isComment != line->isComment;
 
136
        return value != line->value || comment != line->comment || isComment != line->isComment;
137
137
}
138
138
 
139
139
 
140
140
wxString pgConfigLine::GetNewText()
141
141
{
142
 
    wxString quote;
143
 
    wxString newLine;
144
 
    if (item->type == pgSettingItem::PGC_STRING)
145
 
    {
146
 
        if (value.Find('\'') >= 0)
147
 
            quote = wxT("\"");
148
 
        else
149
 
            quote = wxT("'");
150
 
    }
151
 
    if (isComment)
152
 
        newLine = wxT("# ");
153
 
 
154
 
    newLine += item->name + wxT(" = ")
155
 
            + quote + value + quote;
156
 
 
157
 
    if (!comment.IsEmpty())
158
 
    {
159
 
        if (item->orgLine && item->orgLine->commentIndent.Find('#') >= 0)
160
 
            newLine += item->orgLine->commentIndent;
161
 
        else
162
 
            newLine += DEFAULT_COMMENT_INDEX;
163
 
        newLine += comment;
164
 
    }
165
 
    return newLine;
 
142
        wxString quote;
 
143
        wxString newLine;
 
144
        if (item->type == pgSettingItem::PGC_STRING)
 
145
        {
 
146
                if (value.Find('\'') >= 0)
 
147
                        quote = wxT("\"");
 
148
                else
 
149
                        quote = wxT("'");
 
150
        }
 
151
        if (isComment)
 
152
                newLine = wxT("# ");
 
153
 
 
154
        newLine += item->name + wxT(" = ")
 
155
                   + quote + value + quote;
 
156
 
 
157
        if (!comment.IsEmpty())
 
158
        {
 
159
                if (item->orgLine && item->orgLine->commentIndent.Find('#') >= 0)
 
160
                        newLine += item->orgLine->commentIndent;
 
161
                else
 
162
                        newLine += DEFAULT_COMMENT_INDEX;
 
163
                newLine += comment;
 
164
        }
 
165
        return newLine;
166
166
}
167
167
 
168
168
 
169
169
pgConfigOrgLine::pgConfigOrgLine(pgConfigLine *line) : pgConfigLine(line)
170
170
{
171
 
    text = line->GetNewText();
172
 
    if (isComment)
173
 
        commentIndent = DEFAULT_COMMENT_INDEX;
 
171
        text = line->GetNewText();
 
172
        if (isComment)
 
173
                commentIndent = DEFAULT_COMMENT_INDEX;
174
174
}
175
175
 
176
176
 
177
177
wxString pgConfigOrgLine::GetNewText()
178
178
{
179
 
    if (!item || !item->newLine)
180
 
        return text;
181
 
    return item->newLine->GetNewText();
 
179
        if (!item || !item->newLine)
 
180
                return text;
 
181
        return item->newLine->GetNewText();
182
182
}
183
183
 
184
184
 
188
188
pgSettingFileReader::pgSettingFileReader(bool localized)
189
189
{
190
190
 
191
 
    wxUtfFile file;
192
 
 
193
 
    wxString path=i18nPath + wxT("/") + settings->GetCanonicalLanguageName() +wxT("/pg_settings.csv");
194
 
    if (localized && wxFile::Exists(path))
195
 
        file.Open(path);
196
 
    else
197
 
        file.Open(i18nPath+wxT("/pg_settings.csv"));
198
 
 
199
 
    if (file.IsOpened())
200
 
    {
201
 
        file.Read(buffer);
202
 
        file.Close();
203
 
    }
204
 
 
205
 
    if (!buffer.IsEmpty())
206
 
    {
207
 
        buffer = wxTextBuffer::Translate(buffer, wxTextFileType_Unix);
208
 
 
209
 
        columnNames = buffer.BeforeFirst('\n');
210
 
        bp = (wxChar*)buffer.c_str() + columnNames.Length()+1;
211
 
    }
 
191
        wxUtfFile file;
 
192
 
 
193
        wxString path = i18nPath + wxT("/") + settings->GetCanonicalLanguageName() + wxT("/pg_settings.csv");
 
194
        if (localized && wxFile::Exists(path))
 
195
                file.Open(path);
 
196
        else
 
197
                file.Open(i18nPath + wxT("/pg_settings.csv"));
 
198
 
 
199
        if (file.IsOpened())
 
200
        {
 
201
                file.Read(buffer);
 
202
                file.Close();
 
203
        }
 
204
 
 
205
        if (!buffer.IsEmpty())
 
206
        {
 
207
                buffer = wxTextBuffer::Translate(buffer, wxTextFileType_Unix);
 
208
 
 
209
                columnNames = buffer.BeforeFirst('\n');
 
210
                bp = const_cast<wxChar *>((const wxChar *)buffer + columnNames.Length() + 1);
 
211
        }
212
212
}
213
213
 
214
214
 
219
219
 
220
220
pgSettingItem *pgSettingFileReader::GetNextItem()
221
221
{
222
 
    if (!bp || !*bp || *bp == '\n')
223
 
        return 0;
224
 
 
225
 
    pgSettingItem *item=new pgSettingItem;
226
 
    wxStringTokenizer tk(columnNames, wxT(";"));
227
 
    wxString column=tk.GetNextToken();
228
 
 
229
 
    wxChar *c = bp;
230
 
    while (*c)
231
 
    {
232
 
        wxString value;
233
 
 
234
 
        if (*c++ != '"')
235
 
        {
236
 
            // invalid syntax
237
 
            return 0;
238
 
        }
239
 
        while (*c && *c != '\n')
240
 
        {
241
 
            if (*c == '"')
242
 
            {
243
 
                if (c[1] == '"')
244
 
                    c++;
245
 
                else
246
 
                    break;
247
 
            }
248
 
            value.Append(*c++);
249
 
        }
250
 
        if (*c++ != '"')
251
 
        {
252
 
            // format error
253
 
            return 0;
254
 
        }
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);
271
 
 
272
 
        column = tk.GetNextToken();
273
 
        if (*c == '\n')
274
 
        {
275
 
            bp = c +1;
276
 
            break;
277
 
        }
278
 
        else if (!*c)
279
 
        {
280
 
            bp=0;
281
 
            break;
282
 
        }
283
 
        else if (*c == ';')
284
 
            c++;
285
 
        else
286
 
        {
287
 
            // invalid syntax
288
 
            return 0;
289
 
        }
290
 
    }
291
 
 
292
 
    return item;
 
222
        if (!bp || !*bp || *bp == '\n')
 
223
                return 0;
 
224
 
 
225
        pgSettingItem *item = new pgSettingItem;
 
226
        wxStringTokenizer tk(columnNames, wxT(";"));
 
227
        wxString column = tk.GetNextToken();
 
228
 
 
229
        wxChar *c = bp;
 
230
        while (*c)
 
231
        {
 
232
                wxString value;
 
233
 
 
234
                if (*c++ != '"')
 
235
                {
 
236
                        // invalid syntax
 
237
                        return 0;
 
238
                }
 
239
                while (*c && *c != '\n')
 
240
                {
 
241
                        if (*c == '"')
 
242
                        {
 
243
                                if (c[1] == '"')
 
244
                                        c++;
 
245
                                else
 
246
                                        break;
 
247
                        }
 
248
                        value.Append(*c++);
 
249
                }
 
250
                if (*c++ != '"')
 
251
                {
 
252
                        // format error
 
253
                        return 0;
 
254
                }
 
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);
 
271
 
 
272
                column = tk.GetNextToken();
 
273
                if (*c == '\n')
 
274
                {
 
275
                        bp = c + 1;
 
276
                        break;
 
277
                }
 
278
                else if (!*c)
 
279
                {
 
280
                        bp = 0;
 
281
                        break;
 
282
                }
 
283
                else if (*c == ';')
 
284
                        c++;
 
285
                else
 
286
                {
 
287
                        // invalid syntax
 
288
                        return 0;
 
289
                }
 
290
        }
 
291
 
 
292
        return item;
293
293
}
294
294
 
295
295
 
296
296
pgSettingDbReader::pgSettingDbReader(pgConn *conn)
297
297
{
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"));
299
299
}
300
300
 
301
301
 
302
302
pgSettingDbReader::~pgSettingDbReader()
303
303
{
304
 
    if (set)
305
 
        delete set;
 
304
        if (set)
 
305
                delete set;
306
306
}
307
307
 
308
308
pgSettingItem *pgSettingDbReader::GetNextItem()
309
309
{
310
 
    if (set->Eof())
311
 
        return 0;
312
 
    
313
 
    pgSettingItem *item=new pgSettingItem;
314
 
 
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"));
325
 
 
326
 
    set->MoveNext();
327
 
 
328
 
    return item;
 
310
        if (set->Eof())
 
311
                return 0;
 
312
 
 
313
        pgSettingItem *item = new pgSettingItem;
 
314
 
 
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"));
 
325
 
 
326
        set->MoveNext();
 
327
 
 
328
        return item;
329
329
}
330
330
 
331
331
 
334
334
// must match enum pgHbaConnectType!!!
335
335
const wxChar *pgHbaConnectTypeStrings[] =
336
336
{
337
 
    wxT("local"),
338
 
    wxT("host"),
339
 
    wxT("hostssl"),
340
 
    wxT("hostnossl"),
341
 
    0
 
337
        wxT("local"),
 
338
        wxT("host"),
 
339
        wxT("hostssl"),
 
340
        wxT("hostnossl"),
 
341
        0
342
342
};
343
343
 
344
344
 
345
345
// must match enum pgHbaMethod!!!
346
346
const wxChar *pgHbaMethodStrings[] =
347
347
{
348
 
    wxT("trust"),
349
 
    wxT("reject"),
350
 
    wxT("md5"),
351
 
    wxT("crypt"),
352
 
    wxT("password"),
353
 
    wxT("krb4"),
354
 
    wxT("krb5"),
355
 
    wxT("ident"),
356
 
    wxT("pam"),
357
 
    wxT("ldap"),
358
 
    wxT("gss"),
359
 
    wxT("sspi"),
360
 
    0
 
348
        wxT("trust"),
 
349
        wxT("reject"),
 
350
        wxT("md5"),
 
351
        wxT("crypt"),
 
352
        wxT("password"),
 
353
        wxT("krb4"),
 
354
        wxT("krb5"),
 
355
        wxT("ident"),
 
356
        wxT("pam"),
 
357
        wxT("ldap"),
 
358
        wxT("gss"),
 
359
        wxT("sspi"),
 
360
        0
361
361
};
362
362
 
363
363
 
364
 
bool IsSpaceChar(wxChar c, const wxChar *spaceChars=wxT("\t "))
365
 
{
366
 
    return wxStrchr(spaceChars, c) != NULL;
367
 
}
368
 
 
369
 
 
370
 
void SkipSpace(const wxChar* &ptr, const wxChar *spaceChars=wxT("\t "))
371
 
{
372
 
    while (*ptr && IsSpaceChar(*ptr))
373
 
        ptr++;
374
 
}
375
 
 
376
 
 
377
 
void SkipNonspace(const wxChar* &ptr, const wxChar *spaceChars=wxT("\t "))
378
 
{
379
 
    while (*ptr && !IsSpaceChar(*ptr))
380
 
        ptr++;
 
364
bool IsSpaceChar(wxChar c, const wxChar *spaceChars = wxT("\t "))
 
365
{
 
366
        return wxStrchr(spaceChars, c) != NULL;
 
367
}
 
368
 
 
369
 
 
370
void SkipSpace(const wxChar* &ptr, const wxChar *spaceChars = wxT("\t "))
 
371
{
 
372
        while (*ptr && IsSpaceChar(*ptr))
 
373
                ptr++;
 
374
}
 
375
 
 
376
 
 
377
void SkipNonspace(const wxChar* &ptr, const wxChar *spaceChars = wxT("\t "))
 
378
{
 
379
        while (*ptr && !IsSpaceChar(*ptr))
 
380
                ptr++;
381
381
}
382
382
 
383
383
 
384
384
pgHbaConfigLine::pgHbaConfigLine(const wxString &line)
385
385
{
386
 
    item=-1;
387
 
    connectType = PGC_INVALIDCONF;
388
 
    method = PGC_INVALIDMETHOD;
389
 
    Init(line);
 
386
        item = -1;
 
387
        connectType = PGC_INVALIDCONF;
 
388
        method = PGC_INVALIDMETHOD;
 
389
        Init(line);
390
390
}
391
391
 
392
392
 
393
393
void pgHbaConfigLine::Init(const wxString &line)
394
394
{
395
 
    connectType = PGC_INVALIDCONF;
396
 
    changed = false;
397
 
 
398
 
    if (line.IsEmpty())
399
 
        return;
400
 
 
401
 
    text = line;
402
 
 
403
 
    const wxChar *p0=line.c_str();
404
 
 
405
 
    if (*p0 == '#')
406
 
    {
407
 
        isComment = true;
408
 
        p0++;
409
 
        SkipSpace(p0);
410
 
    }
411
 
    else
412
 
        isComment = false;
413
 
 
414
 
 
415
 
    const wxChar *p1=p0;
416
 
    SkipNonspace(p1);
417
 
 
418
 
    wxString str=line.Mid(p0-line.c_str(), p1-p0);
419
 
    
420
 
    int i=FindToken(str, pgHbaConnectTypeStrings);
421
 
 
422
 
    if (i >= 0)
423
 
        connectType = (pgHbaConnectType)i;
424
 
    else
425
 
    {
426
 
        connectType = PGC_INVALIDCONF;
427
 
        isComment = true;
428
 
        return;
429
 
    }
430
 
 
431
 
    SkipSpace(p1);
432
 
 
433
 
    const wxChar *p2=p1;
434
 
    bool quoted=false;
435
 
 
436
 
    while (*p2)
437
 
    {
438
 
        if (!quoted && IsSpaceChar(*p2))
439
 
            break;
440
 
        if (*p2 == '"')
441
 
            quoted ^= quoted;
442
 
        p2++;
443
 
    }
444
 
 
445
 
    database = line.Mid(p1-line.c_str(), p2-p1);
446
 
 
447
 
    SkipSpace(p2);
448
 
 
449
 
    const wxChar *p3=p2;
450
 
 
451
 
    quoted=false;
452
 
    while (*p3)
453
 
    {
454
 
        if (!quoted && IsSpaceChar(*p3))
455
 
            break;
456
 
        if (*p3 == '"')
457
 
            quoted ^= quoted;
458
 
        p3++;
459
 
    }
460
 
 
461
 
    user = line.Mid(p2-line.c_str(), p3-p2);
462
 
 
463
 
    SkipSpace(p3);
464
 
 
465
 
    const wxChar *p4=p3;
466
 
 
467
 
    if (connectType == PGC_LOCAL)
468
 
    {
469
 
        // no ip address
470
 
    }
471
 
    else
472
 
    {
473
 
        bool hasCidr=false;
474
 
        while (*p4 && !IsSpaceChar(*p4))
475
 
        {
476
 
            if (*p4 == '/')
477
 
                hasCidr=true;
478
 
            p4++;
479
 
        }
480
 
        if (!hasCidr)
481
 
        {
482
 
            SkipSpace(p4);
483
 
            SkipNonspace(p4);
484
 
        }
485
 
 
486
 
        ipaddress = line.Mid(p3-line.c_str(), p4-p3);
487
 
        SkipSpace(p4);
488
 
    }
489
 
 
490
 
    const wxChar *p5=p4;
491
 
    SkipNonspace(p5);
492
 
 
493
 
    str=line.Mid(p4-line.c_str(), p5-p4);
494
 
 
495
 
    i = FindToken(str, pgHbaMethodStrings);
496
 
 
497
 
    if (i >= 0)
498
 
        method = (pgHbaMethod)i;
499
 
    else
500
 
    {
501
 
        connectType = PGC_INVALIDCONF;
502
 
        isComment = true;
503
 
        return;
504
 
    }
505
 
    SkipSpace(p5);
506
 
    option = p5;
 
395
        connectType = PGC_INVALIDCONF;
 
396
        changed = false;
 
397
 
 
398
        if (line.IsEmpty())
 
399
                return;
 
400
 
 
401
        text = line;
 
402
 
 
403
        const wxChar *p0 = line.c_str();
 
404
 
 
405
        if (*p0 == '#')
 
406
        {
 
407
                isComment = true;
 
408
                p0++;
 
409
                SkipSpace(p0);
 
410
        }
 
411
        else
 
412
                isComment = false;
 
413
 
 
414
 
 
415
        const wxChar *p1 = p0;
 
416
        SkipNonspace(p1);
 
417
 
 
418
        wxString str = line.Mid(p0 - line.c_str(), p1 - p0);
 
419
 
 
420
        int i = FindToken(str, pgHbaConnectTypeStrings);
 
421
 
 
422
        if (i >= 0)
 
423
                connectType = (pgHbaConnectType)i;
 
424
        else
 
425
        {
 
426
                connectType = PGC_INVALIDCONF;
 
427
                isComment = true;
 
428
                return;
 
429
        }
 
430
 
 
431
        SkipSpace(p1);
 
432
 
 
433
        const wxChar *p2 = p1;
 
434
        bool quoted = false;
 
435
 
 
436
        while (*p2)
 
437
        {
 
438
                if (!quoted && IsSpaceChar(*p2))
 
439
                        break;
 
440
                if (*p2 == '"')
 
441
                        quoted = !quoted;
 
442
                p2++;
 
443
        }
 
444
 
 
445
        database = line.Mid(p1 - line.c_str(), p2 - p1);
 
446
 
 
447
        SkipSpace(p2);
 
448
 
 
449
        const wxChar *p3 = p2;
 
450
 
 
451
        quoted = false;
 
452
        while (*p3)
 
453
        {
 
454
                if (!quoted && IsSpaceChar(*p3))
 
455
                        break;
 
456
                if (*p3 == '"')
 
457
                        quoted = !quoted;
 
458
                p3++;
 
459
        }
 
460
 
 
461
        user = line.Mid(p2 - line.c_str(), p3 - p2);
 
462
 
 
463
        SkipSpace(p3);
 
464
 
 
465
        const wxChar *p4 = p3;
 
466
 
 
467
        if (connectType == PGC_LOCAL)
 
468
        {
 
469
                // no ip address
 
470
        }
 
471
        else
 
472
        {
 
473
                bool hasCidr = false;
 
474
                while (*p4 && !IsSpaceChar(*p4))
 
475
                {
 
476
                        if (*p4 == '/')
 
477
                                hasCidr = true;
 
478
                        p4++;
 
479
                }
 
480
                if (!hasCidr)
 
481
                {
 
482
                        SkipSpace(p4);
 
483
                        SkipNonspace(p4);
 
484
                }
 
485
 
 
486
                ipaddress = line.Mid(p3 - line.c_str(), p4 - p3);
 
487
                SkipSpace(p4);
 
488
        }
 
489
 
 
490
        const wxChar *p5 = p4;
 
491
        SkipNonspace(p5);
 
492
 
 
493
        str = line.Mid(p4 - line.c_str(), p5 - p4);
 
494
 
 
495
        i = FindToken(str, pgHbaMethodStrings);
 
496
 
 
497
        if (i >= 0)
 
498
                method = (pgHbaMethod)i;
 
499
        else
 
500
        {
 
501
                connectType = PGC_INVALIDCONF;
 
502
                isComment = true;
 
503
                return;
 
504
        }
 
505
        SkipSpace(p5);
 
506
        option = p5;
507
507
}
508
508
 
509
509
 
510
510
const wxChar *pgHbaConfigLine::GetConnectType()
511
511
{
512
 
    if (connectType >= 0 && connectType < PGC_INVALIDCONF)
513
 
        return pgHbaConnectTypeStrings[connectType];
514
 
    return 0;
 
512
        if (connectType >= 0 && connectType < PGC_INVALIDCONF)
 
513
                return pgHbaConnectTypeStrings[connectType];
 
514
        return 0;
515
515
}
516
516
 
517
517
 
518
518
const wxChar *pgHbaConfigLine::GetMethod()
519
519
{
520
 
    if (method >= 0 && method < PGC_INVALIDMETHOD)
521
 
        return pgHbaMethodStrings[method];
522
 
    return 0;
 
520
        if (method >= 0 && method < PGC_INVALIDMETHOD)
 
521
                return pgHbaMethodStrings[method];
 
522
        return 0;
523
523
}
524
524
 
525
525
 
526
526
wxString pgHbaConfigLine::GetText()
527
527
{
528
 
    if (!changed)
529
 
        return text;
530
 
 
531
 
    wxString str;
532
 
    wxString tabspace=wxT("\t ");
533
 
    if (isComment)
534
 
        str = wxT("# ");
535
 
 
536
 
    str += GetConnectType() 
537
 
        +  tabspace + database
538
 
        +  tabspace + user;
539
 
 
540
 
    if (connectType != PGC_LOCAL)
541
 
        str += tabspace + ipaddress;
542
 
 
543
 
    str += tabspace + GetMethod();
544
 
 
545
 
    if (method >= PGC_IDENT && !option.IsEmpty())
546
 
        str += tabspace + option;
547
 
 
548
 
    return str;
 
528
        if (!changed)
 
529
                return text;
 
530
 
 
531
        wxString str;
 
532
        wxString tabspace = wxT("\t ");
 
533
        if (isComment)
 
534
                str = wxT("# ");
 
535
 
 
536
        str += GetConnectType()
 
537
               +  tabspace + database
 
538
               +  tabspace + user;
 
539
 
 
540
        if (connectType != PGC_LOCAL)
 
541
                str += tabspace + ipaddress;
 
542
 
 
543
        str += tabspace + GetMethod();
 
544
 
 
545
        if (method >= PGC_IDENT && !option.IsEmpty())
 
546
                str += tabspace + option;
 
547
 
 
548
        return str;
549
549
}
550
550
 
551
551
 
552
552
////////////////////////////////////////////////
553
553
pgPassConfigLine::pgPassConfigLine(const wxString &line)
554
554
{
555
 
    item=-1;
556
 
    Init(line);
 
555
        item = -1;
 
556
        Init(line);
557
557
}
558
558
 
559
559
void pgPassConfigLine::Init(const wxString &line)
560
560
{
561
561
        text = line;
562
562
 
563
 
    if (line.IsEmpty())
564
 
        return;
 
563
        if (line.IsEmpty())
 
564
                return;
565
565
 
566
566
        isComment = line.StartsWith(wxT("#"));
567
567
 
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())
580
580
 
581
581
wxString pgPassConfigLine::GetText()
582
582
{
583
 
        return (isComment?wxT("#"):wxT("")) +
584
 
                   hostname + wxT(":") + 
585
 
                   port + wxT(":") +
586
 
                   database + wxT(":") +
587
 
                   username + wxT(":") +
588
 
                   password;
 
583
        return (isComment ? wxT("#") : wxT("")) +
 
584
               hostname + wxT(":") +
 
585
               port + wxT(":") +
 
586
               database + wxT(":") +
 
587
               username + wxT(":") +
 
588
               password;
589
589
}