- Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathIntlParametersBlock.cpp
367 lines (314 loc) · 7.13 KB
/
IntlParametersBlock.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*
* PROGRAM: Firebird interface.
* MODULE: IntlParametersBlock.cpp
* DESCRIPTION: Convert strings in parameters block to/from UTF8.
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights
* and limitations under the License.
*
* The Original Code was created by Alex Peshkov
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2012 Alex Peshkov <peshkoff at mail.ru>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*
*
*/
#include"firebird.h"
#include"../common/IntlParametersBlock.h"
#include"firebird/impl/consts_pub.h"
#include"../common/isc_f_proto.h"
#include"../common/classes/ClumpletWriter.h"
#include"../common/UtilSvc.h"
#include"../common/StatusHolder.h"
usingnamespaceFirebird;
namespace
{
voidstrToUtf8(string& s)
{
ISC_systemToUtf8(s);
}
voidstrFromUtf8(string& s)
{
ISC_unescape(s);
ISC_utf8ToSystem(s);
}
voidprocessCommandLine(IntlParametersBlock::ProcessString* processString, string& par)
{
bool flagIn = false;
string current, result;
for (constchar* s = par.begin(); s < par.end(); ++s)
{
if (s[0] == SVC_TRMNTR)
{
if (!flagIn)
{
flagIn = true;
}
elseif (s[1] == SVC_TRMNTR)
{
current += SVC_TRMNTR;
++s;
}
else
{
flagIn = false;
processString(current);
UtilSvc::addStringWithSvcTrmntr(current, result);
current = "";
}
}
elseif (s[0] != '' || flagIn || current.hasData())
{
current += s[0];
}
}
if (current.hasData())
{
processString(current);
UtilSvc::addStringWithSvcTrmntr(current, result);
}
result.rtrim();
par = result;
}
}
namespaceFirebird
{
voidIntlParametersBlock::toUtf8(ClumpletWriter& pb)
{
UCHAR utf8Tag = getUtf8Tag();
if (utf8Tag)
{
pb.insertTag(utf8Tag);
}
processParametersBlock(strToUtf8, pb);
}
voidIntlParametersBlock::fromUtf8(ClumpletWriter& pb)
{
UCHAR utf8Tag = getUtf8Tag();
if (utf8Tag)
{
pb.deleteWithTag(utf8Tag);
}
processParametersBlock(strFromUtf8, pb);
}
voidIntlParametersBlock::processParametersBlock(ProcessString* processString, ClumpletWriter& pb)
{
constchar* tagName = NULL;
try
{
for (pb.rewind(); !pb.isEof(); )
{
UCHAR tag = pb.getClumpTag();
string s;
tagName = NULL;
switch (checkTag(tag, &tagName))
{
case TAG_SKIP:
pb.moveNext();
break;
case TAG_STRING:
pb.getString(s);
processString(s);
pb.deleteClumplet();
pb.insertString(tag, s);
break;
case TAG_COMMAND_LINE:
pb.getString(s);
processCommandLine(processString, s);
pb.deleteClumplet();
pb.insertString(tag, s);
break;
}
}
}
catch (const Firebird::status_exception& st)
{
LocalStatus ls;
CheckStatusWrapper l(&ls);
st.stuffException(&l);
if ((l.getState() & IStatus::STATE_ERRORS) && (l.getErrors()[1] == isc_bad_conn_str) && tagName)
{
Arg::Gds newErrors(isc_intl_char);
newErrors << tagName;
const ISC_STATUS* errors = l.getErrors();
newErrors << Arg::StatusVector(errors + 2); // skip isc_bad_conn_str
l.setErrors(newErrors.value());
status_exception::raise(&l);
}
// other case leave exception as is
throw;
}
}
#defineFB_IPB_TAG(t) case t: if (!*tagName) *tagName = #t
IntlParametersBlock::TagType IntlDpb::checkTag(UCHAR tag, constchar** tagName)
{
switch (tag)
{
FB_IPB_TAG(isc_dpb_user_name);
FB_IPB_TAG(isc_dpb_password);
FB_IPB_TAG(isc_dpb_sql_role_name);
FB_IPB_TAG(isc_dpb_trusted_auth);
FB_IPB_TAG(isc_dpb_trusted_role);
FB_IPB_TAG(isc_dpb_working_directory);
FB_IPB_TAG(isc_dpb_set_db_charset);
FB_IPB_TAG(isc_dpb_process_name);
FB_IPB_TAG(isc_dpb_host_name);
FB_IPB_TAG(isc_dpb_os_user);
return TAG_STRING;
}
return TAG_SKIP;
}
IntlParametersBlock::TagType IntlSpb::checkTag(UCHAR tag, constchar** tagName)
{
switch (tag)
{
FB_IPB_TAG(isc_spb_user_name);
FB_IPB_TAG(isc_spb_password);
FB_IPB_TAG(isc_spb_sql_role_name);
FB_IPB_TAG(isc_spb_trusted_auth);
FB_IPB_TAG(isc_spb_trusted_role);
FB_IPB_TAG(isc_spb_process_name);
FB_IPB_TAG(isc_spb_expected_db);
return TAG_STRING;
FB_IPB_TAG(isc_spb_command_line);
return TAG_COMMAND_LINE;
}
return TAG_SKIP;
}
IntlParametersBlock::TagType IntlSpbStart::checkTag(UCHAR tag, constchar** tagName)
{
switch (tag)
{
FB_IPB_TAG(isc_spb_dbname);
return TAG_STRING;
}
switch (mode)
{
case0:
switch (tag)
{
case isc_action_svc_backup:
case isc_action_svc_restore:
case isc_action_svc_properties:
case isc_action_svc_repair:
case isc_action_svc_add_user:
case isc_action_svc_delete_user:
case isc_action_svc_modify_user:
case isc_action_svc_display_user:
case isc_action_svc_display_user_adm:
case isc_action_svc_nbak:
case isc_action_svc_nrest:
case isc_action_svc_trace_start:
case isc_action_svc_db_stats:
case isc_action_svc_validate:
case isc_action_svc_set_mapping:
case isc_action_svc_drop_mapping:
mode = tag;
break;
}
break;
case isc_action_svc_backup:
case isc_action_svc_restore:
switch (tag)
{
FB_IPB_TAG(isc_spb_bkp_file);
FB_IPB_TAG(isc_spb_bkp_skip_data);
return TAG_STRING;
}
break;
case isc_action_svc_repair:
switch (tag)
{
FB_IPB_TAG(isc_spb_tra_db_path);
return TAG_STRING;
}
break;
case isc_action_svc_add_user:
case isc_action_svc_delete_user:
case isc_action_svc_modify_user:
case isc_action_svc_display_user:
case isc_action_svc_display_user_adm:
switch (tag)
{
FB_IPB_TAG(isc_spb_sql_role_name);
FB_IPB_TAG(isc_spb_sec_username);
FB_IPB_TAG(isc_spb_sec_password);
FB_IPB_TAG(isc_spb_sec_groupname);
FB_IPB_TAG(isc_spb_sec_firstname);
FB_IPB_TAG(isc_spb_sec_middlename);
FB_IPB_TAG(isc_spb_sec_lastname);
return TAG_STRING;
}
break;
case isc_action_svc_nbak:
case isc_action_svc_nrest:
switch (tag)
{
FB_IPB_TAG(isc_spb_nbk_file);
return TAG_STRING;
}
break;
case isc_action_svc_trace_start:
switch (tag)
{
FB_IPB_TAG(isc_spb_trc_name);
FB_IPB_TAG(isc_spb_trc_cfg);
return TAG_STRING;
}
break;
case isc_action_svc_db_stats:
switch (tag)
{
FB_IPB_TAG(isc_spb_sts_table);
return TAG_STRING;
FB_IPB_TAG(isc_spb_command_line);
return TAG_COMMAND_LINE;
}
break;
case isc_action_svc_validate:
switch (tag)
{
FB_IPB_TAG(isc_spb_val_tab_incl);
FB_IPB_TAG(isc_spb_val_tab_excl);
FB_IPB_TAG(isc_spb_val_idx_incl);
FB_IPB_TAG(isc_spb_val_idx_excl);
return TAG_STRING;
}
break;
case isc_action_svc_set_mapping:
case isc_action_svc_drop_mapping:
switch (tag)
{
FB_IPB_TAG(isc_spb_sql_role_name);
return TAG_STRING;
}
break;
}
return TAG_SKIP;
}
#undef FB_IPB_TAG
UCHAR IntlDpb::getUtf8Tag()
{
return isc_dpb_utf8_filename;
}
UCHAR IntlSpb::getUtf8Tag()
{
return isc_spb_utf8_filename;
}
UCHAR IntlSpbStart::getUtf8Tag()
{
return0;
}
}