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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
|
{
This file is part of the Free Pascal run time library.
Copyright (c) 2019 by the Free Pascal development team
SQLDB REST Dispatcher .ini file load/save support.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit sqldbrestini;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, sqldbrestio, sqldbrestauth, sqldbrestbridge, sqldbrestschema, inifiles;
Type
TConnectionIniOption = (scoClearOnRead, // Clear values first
scoSkipPassword, // Do not save/load password
scoSkipMaskPassword, // do not mask the password
scoUserNameAsMask, // use the username as mask for password
scoSkipParams // Do not read/write params.
);
TConnectionIniOptions = Set of TConnectionIniOption;
TSQLDBRestConnectionHelper = class helper for TSQLDBRestConnection
Private
Procedure ClearValues;
Public
Procedure LoadFromIni(Const aIni: TCustomIniFile; aOptions : TConnectionIniOptions = []); overload;
Procedure LoadFromIni(Const aIni: TCustomIniFile; ASection : String; aOptions : TConnectionIniOptions); overload;
Procedure LoadFromFile(Const aFileName : String; aOptions : TConnectionIniOptions = []); overload;
Procedure LoadFromFile(Const aFileName : String; Const ASection : String; aOptions : TConnectionIniOptions); overload;
Procedure SaveToFile(Const aFileName : String; aOptions : TConnectionIniOptions = []);overload;
Procedure SaveToFile(Const aFileName : String; Const ASection : String; aOptions : TConnectionIniOptions = []);overload;
Procedure SaveToIni(Const aIni: TCustomIniFile; aOptions : TConnectionIniOptions = []); overload;
Procedure SaveToIni(Const aIni: TCustomIniFile; ASection : String; aOptions : TConnectionIniOptions); overload;
end;
TDispatcherIniOption = (dioSkipReadConnections, // Do not Read connection definitions
dioSkipExposeConnections, // Do not Expose connections defined in .ini file
dioSkipReadSchemas, // Do not Read schema definitions
dioDisableSchemas, // Do not enable schemas
dioSkipWriteConnections, // Do not write connection definitions
dioSkipWriteSchemas, // Do not Read schema definitions
dioSkipBasicAuth, // Do not read/write basic auth data.
dioSkipStringConfig // Do not read strings config
);
TDispatcherIniOptions = set of TDispatcherIniOption;
{ TSQLDBRestDispatcherHelper }
TSQLDBRestDispatcherHelper = class helper for TSQLDBRestDispatcher
private
Public
procedure ReadSchemas(const aIni: TCustomIniFile; ASection: String; aOptions: TDispatcherIniOptions);
procedure ReadConnections(const aIni: TCustomIniFile; ASection: String);
procedure WriteConnections(const aIni: TCustomIniFile; ASection: String; aOptions : TConnectionIniOptions);
procedure WriteSchemas(const aIni: TCustomIniFile; ASection: String; SchemaFileDir : String);
Procedure LoadFromIni(Const aIni: TCustomIniFile; aOptions : TDispatcherIniOptions = []); overload;
Procedure LoadFromIni(Const aIni: TCustomIniFile; ASection : String; aOptions : TDispatcherIniOptions); overload;
Procedure LoadFromFile(Const aFileName : String; aOptions : TDispatcherIniOptions = []); overload;
Procedure LoadFromFile(Const aFileName : String; Const ASection : String; aOptions : TDispatcherIniOptions); overload;
Procedure SaveToFile(Const aFileName : String; aOptions : TDispatcherIniOptions = []);overload;
Procedure SaveToFile(Const aFileName : String; Const ASection : String; aOptions : TDispatcherIniOptions = []);overload;
Procedure SaveToIni(Const aIni: TCustomIniFile; aOptions : TDispatcherIniOptions = []); overload;
Procedure SaveToIni(Const aIni: TCustomIniFile; ASection : String; aOptions : TDispatcherIniOptions); overload;
end;
{ TRestStringsConfigHelper }
TRestStringsConfigHelper = class helper for TRestStringsConfig
Public
Procedure LoadFromIni(Const aIni: TCustomIniFile); overload;
Procedure LoadFromIni(Const aIni: TCustomIniFile; ASection : String); overload;
Procedure LoadFromFile(Const aFileName : String); overload;
Procedure LoadFromFile(Const aFileName : String; Const ASection : String); overload;
Procedure SaveToFile(Const aFileName : String);overload;
Procedure SaveToFile(Const aFileName : String; Const ASection : String);overload;
Procedure SaveToIni(Const aIni: TCustomIniFile); overload;
Procedure SaveToIni(Const aIni: TCustomIniFile; ASection : String); overload;
end;
Function StrToOutputOptions(S : String) : TRestOutputOptions;
Function StrToDispatcherOptions(S : String) : TRestDispatcherOptions;
Function StrToConnectionIniOptions(S : String) : TConnectionIniOptions;
Function OutputOptionsToStr(Options : TRestOutputOptions): String;
Function DispatcherOptionsToStr(Options: TRestDispatcherOptions) : String;
Function ConnectionIniOptionsToStr(Options: TConnectionIniOptions): String;
Var
TrivialEncryptKey : String = 'SQLDB';
DefaultConnectionSection : String = 'Connection';
DefaultDispatcherSection : String = 'Dispatcher';
DefaultStringsConfigSection : String = 'Dispatcher_strings';
implementation
uses typinfo,strutils, sqldbrestauthini;
Const
KeyHost = 'Host';
KeyDatabaseName = 'DatabaseName';
KeyUserName = 'UserName';
KeyPassword = 'Password';
KeyPort = 'Port';
keyParams = 'Params';
KeyCharset = 'Charset';
KeyRole = 'Role';
KeyType = 'Type';
KeyConnections = 'Connections';
KeySchemas = 'Schemas';
keyDispatcherOptions = 'DispatcherOptions';
keyOutputOptions = 'OutputOptions';
KeyBasePath = 'BasePath';
KeyDefaultConnection = 'DefaultConnection';
KeyEnforceLimit = 'EnforceLimit';
KeyCORSAllowedOrigins = 'CORSAllowedOrigins';
KeyLoadOptions = 'LoadOptions';
KeyMinFieldOptions = 'MinFieldOptions';
KeyFileName = 'File';
KeyEnabled = 'Enabled';
KeyBasicAuth = 'BasicAuth';
Function StrToOutputOptions(S : String) : TRestOutputOptions;
var
i : integer;
begin
I:=StringToSet(PTypeInfo(TypeInfo(TRestOutputOptions)),S);
Result:=TRestOutputOptions(I);
end;
Function StrToDispatcherOptions(S : String) : TRestDispatcherOptions;
var
i : integer;
begin
I:=StringToSet(PTypeInfo(TypeInfo(TRestDispatcherOptions)),S);
Result:=TRestDispatcherOptions(I);
end;
Function StrToConnectionIniOptions(S : String) : TConnectionIniOptions;
var
i : integer;
begin
I:=StringToSet(PTypeInfo(TypeInfo(TConnectionIniOptions)),S);
Result:=TConnectionIniOptions(I);
end;
Function StrToRestFieldOptions(S : String) : TRestFieldOptions;
var
i : integer;
begin
I:=StringToSet(PTypeInfo(TypeInfo(TRestFieldOptions)),S);
Result:=TRestFieldOptions(I);
end;
Function OutputOptionsToStr(Options : TRestOutputOptions): String;
begin
Result:=SetToString(PTypeInfo(TypeInfo(TRestOutputOptions)),Integer(Options),False);
end;
Function DispatcherOptionsToStr(Options : TRestDispatcherOptions) : String;
begin
Result:=SetToString(PTypeInfo(TypeInfo(TRestDispatcherOptions)),Integer(Options),false);
end;
Function ConnectionIniOptionsToStr(Options : TConnectionIniOptions): String;
begin
Result:=SetToString(PTypeInfo(TypeInfo(TConnectionIniOptions)),Integer(Options),false);
end;
{ TRestStringsConfigHelper }
procedure TRestStringsConfigHelper.LoadFromIni(const aIni: TCustomIniFile);
begin
LoadFromIni(aIni,DefaultStringsConfigSection);
end;
procedure TRestStringsConfigHelper.LoadFromIni(const aIni: TCustomIniFile; ASection: String);
Var
T : TRestStringProperty;
N : String;
S : UTF8String;
begin
For T in TRestStringProperty do
begin
Str(T,N);
Delete(N,1,2);
S:=aIni.ReadString(aSection, N, GetRestString(T));
SetRestString(T,S);
end;
end;
procedure TRestStringsConfigHelper.LoadFromFile(const aFileName: String);
begin
LoadFromFile(aFileName,DefaultStringsConfigSection);
end;
procedure TRestStringsConfigHelper.LoadFromFile(const aFileName: String; const ASection: String);
Var
Ini : TCustomIniFile;
begin
Ini:=TMeminiFile.Create(aFileName);
try
LoadFromIni(Ini,aSection);
finally
Ini.Free;
end;
end;
procedure TRestStringsConfigHelper.SaveToFile(const aFileName: String);
begin
SaveToFile(aFileName,DefaultStringsConfigSection);
end;
procedure TRestStringsConfigHelper.SaveToFile(const aFileName: String; const ASection: String);
Var
Ini : TCustomIniFile;
begin
Ini:=TMeminiFile.Create(aFileName);
try
SaveToIni(Ini,aSection);
Ini.UpdateFile;
finally
Ini.Free;
end;
end;
procedure TRestStringsConfigHelper.SaveToIni(const aIni: TCustomIniFile);
begin
SaveToini(aIni,DefaultStringsConfigSection);
end;
procedure TRestStringsConfigHelper.SaveToIni(const aIni: TCustomIniFile; ASection: String);
Var
T : TRestStringProperty;
N : String;
begin
For T in TRestStringProperty do
begin
Str(T,N);
Delete(N,1,2);
aIni.WriteString(aSection, N, GetRestString(T));
end;
end;
{ TSQLDBRestDispatcherHelper }
procedure TSQLDBRestDispatcherHelper.LoadFromIni(const aIni: TCustomIniFile; aOptions: TDispatcherIniOptions);
begin
LoadFromIni(aIni,DefaultDispatcherSection,aOptions);
end;
procedure TSQLDBRestDispatcherHelper.ReadConnections(const aIni: TCustomIniFile; ASection: String);
Var
S,L : String;
I : Integer;
C : TSQLDBRestConnection;
CIO : TConnectionIniOptions;
begin
// Read connections
L:=aIni.ReadString(aSection,KeyConnections,'');
For I:=1 to WordCount(L,[',']) do
begin
S:=ExtractWord(I,L,[',']);
C:=Connections.AddConnection('','','','','');
C.Name:=S;
CIO:=StrToConnectionIniOptions(aIni.ReadString(S,KeyLoadOptions,''));
C.LoadFromIni(aIni,S,CIO);
end;
end;
procedure TSQLDBRestDispatcherHelper.WriteConnections(const aIni: TCustomIniFile; ASection: String; aOptions: TConnectionIniOptions);
Var
S,L : String;
I : Integer;
begin
L:='';
for I:=0 to Connections.Count-1 do
begin
if (L<>'') then
L:=L+',';
L:=L+Connections[i].Name;
end;
aIni.WriteString(aSection,KeyConnections,L);
for I:=0 to Connections.Count-1 do
begin
S:=Connections[i].Name;
L:=ConnectionIniOptionsToStr(aOptions);
Connections[i].SaveToIni(aIni,S,aOptions);
aIni.WriteString(S,KeyLoadOptions,L);
end;
end;
procedure TSQLDBRestDispatcherHelper.WriteSchemas(const aIni: TCustomIniFile; ASection: String; SchemaFileDir : String);
Var
S,L,FN : String;
I : Integer;
Sch : TSQLDBRestSchema;
begin
// Read Schemas
L:='';
for I:=0 to Schemas.Count-1 do
if Assigned(Schemas[i].Schema) then
begin
if (L<>'') then
L:=L+',';
L:=L+Schemas[i].Schema.Name;
end;
aIni.WriteString(aSection,KeySchemas,L);
for I:=0 to Schemas.Count-1 do
if Assigned(Schemas[i].Schema) then
begin
S:=Schemas[i].Schema.Name;
Sch:=Schemas[i].Schema;
if (SchemaFileDir<>'') then
FN:=IncludeTrailingPathDelimiter(SchemaFileDir)+S+'.json'
else
FN:='';
aIni.WriteString(S,KeyFileName,FN);
aIni.WriteBool(S,KeyEnabled,Schemas[i].Enabled);
if (FN<>'') then
Sch.SaveToFile(FN);
end;
end;
procedure TSQLDBRestDispatcherHelper.ReadSchemas(const aIni: TCustomIniFile; ASection: String; aOptions: TDispatcherIniOptions);
Var
S,L,FN : String;
I : Integer;
Sch : TSQLDBRestSchema;
SRef : TSQLDBRestSchemaRef;
begin
// Read Schemas
L:=aIni.ReadString(aSection,KeySchemas,'');
For I:=1 to WordCount(L,[',']) do
begin
S:=ExtractWord(I,L,[',']);
Sch:=TSQLDBRestSchema.Create(Self);
Sch.Name:=S;
SRef:=Schemas.AddSchema(Sch);
SRef.Enabled:=aIni.ReadBool(S,KeyEnabled,True);
if (dioDisableSchemas in aOptions) then
SRef.Enabled:=False;
FN:=aIni.ReadString(S,KeyFileName,'');
if (FN<>'') then
Sch.LoadFromFile(FN);
end;
end;
procedure TSQLDBRestDispatcherHelper.LoadFromIni(const aIni: TCustomIniFile; ASection: String; aOptions: TDispatcherIniOptions);
Var
I : Integer;
FO : TRestFieldOptions;
BAN : String;
BA : TRestBasicAuthenticator;
BAO : TBasicAuthIniOptions;
begin
DispatchOptions:=StrToDispatcherOptions(aIni.ReadString(aSection,keyDispatcherOptions,''));
OutputOptions:=StrToOutputOptions(aIni.ReadString(aSection,keyOutputOptions,''));
BasePath:=aIni.ReadString(aSection,KeyBasePath,'');
DefaultConnection:=aIni.ReadString(aSection,KeyDefaultConnection,'');
EnforceLimit:=aIni.ReadInteger(aSection,KeyEnforceLimit,0);
CORSAllowedOrigins:=aIni.ReadString(aSection,KeyCORSAllowedOrigins,'');
if Not (dioSkipReadConnections in aOptions) then
ReadConnections(aIni,aSection);
if Not (dioSkipReadSchemas in aOptions) then
ReadSchemas(aIni,aSection,aOptions);
// Expose connections
if not (dioSkipExposeConnections in aOptions) then
for I:=0 to Connections.Count-1 do
if Connections[i].Enabled then
begin
FO:=StrToRestFieldOptions(aIni.ReadString(Connections[i].Name,KeyMinFieldOptions,''));
ExposeConnection(Connections[i],Nil,FO);
end;
if not (dioSkipBasicAuth in aOptions) then
begin
BAN:=aIni.ReadString(aSection,KeyBasicAuth,'');
if BAN<>'' then
begin
BAO:=StrToBasicAuthIniOptions(aIni.ReadString(BAN,keyLoadOptions,''));
BA:=TRestBasicAuthenticator.Create(Self);
BA.Name:=BAN;
BA.LoadFromIni(aIni,BAN,BAO);
Self.Authenticator:=BA;
end;
end;
if not (dioSkipStringConfig in aOptions) then
Strings.LoadFromIni(aIni,aSection+'_strings');
end;
procedure TSQLDBRestDispatcherHelper.LoadFromFile(const aFileName: String; aOptions: TDispatcherIniOptions);
begin
Loadfromfile(aFileName,DefaultDispatcherSection,aOptions);
end;
procedure TSQLDBRestDispatcherHelper.LoadFromFile(const aFileName: String; const ASection: String; aOptions: TDispatcherIniOptions);
Var
Ini : TCustomIniFile;
begin
Ini:=TMeminiFile.Create(aFileName);
try
LoadFromIni(Ini,aSection,aOptions);
finally
Ini.Free;
end;
end;
procedure TSQLDBRestDispatcherHelper.SaveToFile(const aFileName: String; aOptions: TDispatcherIniOptions);
begin
SaveTofile(aFileName,DefaultDispatcherSection,aOptions);
end;
procedure TSQLDBRestDispatcherHelper.SaveToFile(const aFileName: String; const ASection: String; aOptions: TDispatcherIniOptions);
Var
Ini : TCustomIniFile;
begin
Ini:=TMeminiFile.Create(aFileName);
try
SaveToIni(Ini,aSection,aOptions);
Ini.UpdateFile;
finally
Ini.Free;
end;
end;
procedure TSQLDBRestDispatcherHelper.SaveToIni(const aIni: TCustomIniFile; aOptions: TDispatcherIniOptions);
begin
SaveToIni(aIni,DefaultDispatcherSection,aOptions);
end;
procedure TSQLDBRestDispatcherHelper.SaveToIni(const aIni: TCustomIniFile; ASection: String; aOptions: TDispatcherIniOptions);
Var
BAN : String;
begin
aIni.WriteString(aSection,keyDispatcherOptions,DispatcherOptionsToStr(DispatchOptions));
aIni.WriteString(aSection,keyOutputOptions,OutputOptionsToStr(OutputOptions));
aIni.WriteString(aSection,KeyBasePath,BasePath);
aIni.WriteString(aSection,KeyDefaultConnection,DefaultConnection);
aIni.WriteInteger(aSection,KeyEnforceLimit,EnforceLimit);
aIni.WriteString(aSection,KeyCORSAllowedOrigins,CORSAllowedOrigins);
if Not (dioSkipWriteConnections in aOptions) then
WriteConnections(aIni,aSection,[]);
if Not (dioSkipWriteSchemas in aOptions) then
WriteSchemas(aIni,aSection,ExtractFilePath(ExpandFileName(aIni.FileName)));
if not (dioSkipBasicAuth in aOptions) then
if Assigned(Authenticator) and (Authenticator is TRestBasicAuthenticator) then
begin
BAN:=Authenticator.Name;
if BAN='' then
BAN:=Self.Name+'_basicauth';
TRestBasicAuthenticator(Authenticator).SaveToIni(aIni,BAN,[]);
aIni.WriteString(aSection,KeyBasicAuth,BAN);
end;
if not (dioSkipStringConfig in aOptions) then
Strings.SaveToIni(aIni,aSection+'_strings');
end;
{ TSQLDBRestConnectionHelper }
procedure TSQLDBRestConnectionHelper.ClearValues;
begin
HostName:='';
DatabaseName:='';
UserName:='';
Password:='';
CharSet:='';
Params.Clear;
Port:=0;
end;
Const
ForbiddenParamKeys : Array[1..8] of unicodestring
= (keyHost,KeyDatabaseName,KeyUserName,KeyPassword,KeyPort,keyParams,keyCharSet,keyRole);
ParamSeps = [',',';',' '];
procedure TSQLDBRestConnectionHelper.LoadFromIni(const aIni: TCustomIniFile; ASection: String; aOptions: TConnectionIniOptions);
Var
M,N,P : String;
I : integer;
begin
With aIni do
begin
if (scoClearOnRead in aOptions) then
ClearValues;
ConnectionType:=ReadString(ASection,KeyType,ConnectionType);
HostName:=ReadString(ASection,KeyHost,HostName);
DatabaseName:=ReadString(ASection,KeyDatabaseName,DatabaseName);
UserName:=ReadString(ASection,KeyUserName,UserName);
CharSet:=ReadString(ASection,KeyCharSet,CharSet);
Role:=ReadString(ASection,KeyRole,Role);
Port:=ReadInteger(ASection,KeyPort,Port);
Enabled:=ReadBool(ASection,KeyEnabled,True);
// optional parts
if not (scoSkipPassword in aOptions) then
begin
if scoSkipMaskPassword in aOptions then
P:=ReadString(ASection,KeyPassword,Password)
else
begin
P:=ReadString(ASection,KeyPassword,'');
if (P<>'') then
begin
if scoUserNameAsMask in aOptions then
M:=UserName
else
M:=TrivialEncryptKey;
P:=XorDecode(M,P);
end;
end;
Password:=P;
end;
if not (scoSkipParams in aOptions) then
begin
M:=ReadString(ASection,keyParams,'');
For I:=1 to WordCount(M,ParamSeps) do
begin
N:=ExtractWord(I,M,ParamSeps);
if IndexStr(Utf8Decode(N),ForbiddenParamKeys)=-1 then
begin
P:=ReadString(ASection,N,'');
Params.Values[N]:=P;
end;
end;
end;
end;
end;
procedure TSQLDBRestConnectionHelper.LoadFromIni(const aIni: TCustomIniFile; aOptions: TConnectionIniOptions);
begin
LoadFromIni(aIni,DefaultConnectionSection,aOptions);
end;
procedure TSQLDBRestConnectionHelper.LoadFromFile(const aFileName: String; aOptions: TConnectionIniOptions);
begin
Loadfromfile(aFileName,DefaultConnectionSection,aOptions);
end;
procedure TSQLDBRestConnectionHelper.LoadFromFile(const aFileName: String; const ASection: String; aOptions: TConnectionIniOptions);
Var
Ini : TCustomIniFile;
begin
Ini:=TMeminiFile.Create(aFileName);
try
LoadFromIni(Ini,aSection,aOptions);
finally
Ini.Free;
end;
end;
procedure TSQLDBRestConnectionHelper.SaveToFile(const aFileName: String; aOptions: TConnectionIniOptions);
begin
SaveToFile(aFileName,DefaultConnectionSection,aOptions);
end;
procedure TSQLDBRestConnectionHelper.SaveToFile(const aFileName: String; const ASection: String; aOptions: TConnectionIniOptions);
Var
Ini : TCustomIniFile;
begin
Ini:=TMeminiFile.Create(aFileName);
try
SaveToini(Ini,aSection,aOptions);
Ini.UpdateFile;
finally
Ini.Free;
end;
end;
procedure TSQLDBRestConnectionHelper.SaveToIni(const aIni: TCustomIniFile; aOptions: TConnectionIniOptions);
begin
SaveToIni(aIni,DefaultConnectionSection,aOptions);
end;
procedure TSQLDBRestConnectionHelper.SaveToIni(const aIni: TCustomIniFile; ASection: String; aOptions: TConnectionIniOptions);
Var
M,N,P : String;
I : integer;
begin
With aIni do
begin
WriteString(ASection,KeyHost,HostName);
WriteString(ASection,KeyDatabaseName,DatabaseName);
WriteString(ASection,KeyUserName,UserName);
WriteString(ASection,KeyCharSet,CharSet);
WriteString(ASection,KeyType,ConnectionType);
WriteString(ASection,KeyRole,Role);
WriteInteger(ASection,KeyPort,Port);
WriteBool(ASection,KeyEnabled,Enabled);
if not (scoSkipPassword in aOptions) then
begin
P:=Password;
if Not (scoSkipMaskPassword in aOptions) then
begin
if scoUserNameAsMask in aOptions then
M:=UserName
else
M:=TrivialEncryptKey;
P:=XorEncode(M,P);
end;
WriteString(ASection,KeyPassword,P);
end;
if not (scoSkipParams in aOptions) then
begin
M:='';
for I:=0 to Params.Count-1 do
begin
Params.GetNameValue(I,N,P);
if (N<>'') and (IndexStr(Utf8Decode(N),ForbiddenParamKeys)=-1) then
begin
WriteString(ASection,N,P);
if (M<>'') then
M:=M+',';
M:=M+N;
end;
end;
WriteString(ASection,KeyParams,M);
end;
end;
end;
end.
|