Skip to content

Commit b970933

Browse files
committed
fix: Ajuste de identação
fix: Ajuste de versionamento fix: Correções de charset entre Lazarus e Delphi fix: Correções de typecast devido a mudança de charset fix: Correções na criptografia pra adequar ao novo charset fix: Correção de comunicação entre Delphi e Lazarus fix: Prevenção de erros diversos fix: Ajuste de detecção de separador para evitar laço sem necessidade fix: Correção de charset no cliente no Delphi unificando código de tratamento entre Delphi e Lazarus fix: Prevenção de erros através de uma constante EmptyStr para versões que não a possuem fix: Mudança no RALDBConnection para usar verbo POST ao invés do GET para enviar SQL no Body evitando problemas com body no GET fix: Otimização de case agrupando tipos comuns fix: Correção nas criptografias para produzirem o mesmo resultado tanto no Delphi quanto no Lazarus feat: Adição de decrypt e encrypt para stream na RALHashes
1 parent 67766ee commit b970933

25 files changed

Lines changed: 424 additions & 251 deletions

src/base/RALClient.pas

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ TRALClient = class(TRALComponent)
128128
/// event called when client thread finishes
129129
procedure OnThreadResponse(Sender: TObject; AResponse: TRALResponse; AException: StringRAL);
130130

131-
function CreateClient : TRALClientHTTP;
131+
function CreateClient: TRALClientHTTP;
132132
/// Copy all properties of current TRALClientBase object
133133
procedure CopyProperties(ADest: TRALClient); virtual;
134134

@@ -148,31 +148,31 @@ TRALClient = class(TRALComponent)
148148
function Clone(AOwner: TComponent = nil): TRALClient; virtual;
149149

150150
/// Defines method on the client: Delete.
151-
procedure Delete(ARoute : StringRAL; var AResponse : TRALResponse); overload;
152-
procedure Delete(ARoute : StringRAL; AOnResponse: TRALThreadClientResponse = nil;
151+
procedure Delete(ARoute: StringRAL; var AResponse : TRALResponse); overload;
152+
procedure Delete(ARoute: StringRAL; AOnResponse: TRALThreadClientResponse = nil;
153153
AExecBehavior : TRALExecBehavior = ebMultiThread); overload;
154154

155155
/// Defines method on the client: Get.
156-
procedure Get(ARoute : StringRAL; var AResponse : TRALResponse); overload;
157-
procedure Get(ARoute : StringRAL; AOnResponse: TRALThreadClientResponse = nil;
156+
procedure Get(ARoute: StringRAL; var AResponse : TRALResponse); overload;
157+
procedure Get(ARoute: StringRAL; AOnResponse: TRALThreadClientResponse = nil;
158158
AExecBehavior : TRALExecBehavior = ebMultiThread); overload;
159159

160160
/// Defines method on the client: Patch.
161-
procedure Patch(ARoute : StringRAL; var AResponse : TRALResponse); overload;
162-
procedure Patch(ARoute : StringRAL; AOnResponse: TRALThreadClientResponse = nil;
161+
procedure Patch(ARoute: StringRAL; var AResponse : TRALResponse); overload;
162+
procedure Patch(ARoute: StringRAL; AOnResponse: TRALThreadClientResponse = nil;
163163
AExecBehavior : TRALExecBehavior = ebMultiThread); overload;
164164

165165
/// Defines method on the client: Post.
166-
procedure Post(ARoute : StringRAL; var AResponse : TRALResponse); overload;
167-
procedure Post(ARoute : StringRAL; AOnResponse: TRALThreadClientResponse = nil;
166+
procedure Post(ARoute: StringRAL; var AResponse : TRALResponse); overload;
167+
procedure Post(ARoute: StringRAL; AOnResponse: TRALThreadClientResponse = nil;
168168
AExecBehavior : TRALExecBehavior = ebMultiThread); overload;
169169

170170
/// Defines method on the client: Put.
171-
procedure Put(ARoute : StringRAL; var AResponse : TRALResponse); overload;
172-
procedure Put(ARoute : StringRAL; AOnResponse: TRALThreadClientResponse = nil;
173-
AExecBehavior : TRALExecBehavior = ebMultiThread); overload;
171+
procedure Put(ARoute: StringRAL; var AResponse : TRALResponse); overload;
172+
procedure Put(ARoute: StringRAL; AOnResponse: TRALThreadClientResponse = nil;
173+
AExecBehavior: TRALExecBehavior = ebMultiThread); overload;
174174

175-
property Request : TRALRequest read FRequest;
175+
property Request: TRALRequest read FRequest;
176176
published
177177
property Authentication: TRALAuthClient read FAuthentication write SetAuthentication;
178178
property BaseURL: TStrings read FBaseURL write SetBaseURL;
@@ -304,7 +304,7 @@ procedure TRALClient.ExecuteThread(ARoute: StringRAL; AMethod: TRALMethod;
304304
function TRALClient.ExecuteSingle(ARoute: StringRAL; AMethod: TRALMethod): TRALResponse;
305305
var
306306
vClient: TRALClientHTTP;
307-
vRequest : TRALRequest;
307+
vRequest: TRALRequest;
308308
begin
309309
Result := TRALClientResponse.Create(Self);
310310
vRequest := TRALClientRequest.Create(Self);

src/base/RALConsts.pas

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface
1313

1414
const
1515
// Versionamento
16-
RALVERSION = '0.11.0-18 alpha';
16+
RALVERSION = '0.12.0-1 alpha';
1717
RALVERSION_MAJOR = 0;
1818
RALVERSION_MINOR = 11;
1919
RALVERSION_PATCH = 0;
@@ -28,6 +28,11 @@ interface
2828
RALPACKAGESITE = 'https://github.com/OpenSourceCommunityBrasil/PascalRAL';
2929
RALPACKAGELICENSE = 'OpenSource';
3030
RALPACKAGELICENSEVERSION = 'OpenSource - v' + RALVERSION;
31+
ENGINESYNOPSE = 'mORMot2';
32+
ENGINEINDY = 'Indy';
33+
ENGINESAGUI = 'Sagui';
34+
ENGINENETHTTP = 'netHttp';
35+
ENGINEFPHTTP = 'fpHttp';
3136

3237
// html pages
3338
RALDefaultPage = '<!DOCTYPE html>'

src/base/RALDBTypes.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ TRALDBInfoTable = class
157157

158158
TRALDBInfoTables = class
159159
private
160-
FTables : TList;
160+
FTables: TList;
161161
protected
162162
function GetAsJSON: StringRAL;
163163
function GetAsJSONObj: TRALJSONArray;

src/base/RALParams.pas

Lines changed: 114 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface
66

77
uses
88
Classes, SysUtils, TypInfo,
9+
RALHashes,
910
RALTypes, RALMIMETypes, RALMultipartCoder, RALTools, RALUrlCoder,
1011
RALCripto, RALCriptoAES, RALStream, RALCompress, RALConsts;
1112

@@ -20,6 +21,7 @@ TRALParam = class
2021
private
2122
FContent: TStream;
2223
FContentType: StringRAL;
24+
FContentDisposition: StringRAL;
2325
FContentDispositionInline: Boolean;
2426
FFileName: StringRAL;
2527
FKind: TRALParamKind;
@@ -221,7 +223,7 @@ implementation
221223

222224
procedure TRALParam.Clone(ASource: TRALParam);
223225
begin
224-
ASource.ContentDisposition := Self.ContentDisposition;
226+
ASource.ContentDispositionInline := Self.ContentDispositionInline;
225227
ASource.ContentType := Self.ContentType;
226228
ASource.FileName := Self.FileName;
227229
ASource.Kind := Self.Kind;
@@ -318,7 +320,9 @@ function TRALParam.GetContentDisposition: StringRAL;
318320
if (FFileName <> '') and (not FContentDispositionInline) then
319321
Result := Format('attachment; name="%s"; filename="%s"', [FParamName, FFileName])
320322
else
321-
Result := Format('inline; name="%s"', [FParamName]);
323+
// Result := Format('inline; name="%s"', [FParamName]);
324+
// pode cagar o módulo web
325+
Result := 'inline';
322326
end;
323327

324328
function TRALParam.GetContentSize: Int64RAL;
@@ -443,7 +447,7 @@ procedure TRALParam.SetContentDisposition(AValue: StringRAL);
443447
vQuoted := False;
444448
for vInt := 1 to vLen do
445449
begin
446-
vChr := Char(AStr[vInt]);
450+
vChr := CharRAL(AStr[vInt]);
447451
if (vChr = '"') then
448452
begin
449453
vQuoted := not vQuoted;
@@ -531,13 +535,13 @@ function TRALParams.AddFile(const AParamName, AFileName: StringRAL): TRALParam;
531535
Result.OpenFile(AFileName);
532536
Result.Kind := rpkBODY;
533537

534-
vMime := TRALMIMEType.Create;
538+
vMime := TRALMIMEType.GetInstance;
535539
try
536540
Result.ContentType := vMime.GetMIMEType(AFileName);
537541
if Result.ContentType = '' then
538542
Result.ContentType := rctAPPLICATIONOCTETSTREAM;
539543
finally
540-
FreeAndNil(vMime);
544+
// FreeAndNil(vMime);
541545
end;
542546
end;
543547
end;
@@ -635,9 +639,12 @@ procedure TRALParams.AppendParamsListText(ASource: StringRAL; AKind: TRALParamKi
635639
vLine: StringRAL;
636640
vIs13: Boolean;
637641
begin
638-
{$IFNDEF FPC}
639-
ASource := UTF8ToString(ASource);
642+
{$IFDEF FPC}
643+
ASource := UTF8Decode(ASource);
644+
{$ELSE}
645+
ASource := UTF8ToString(ASource);
640646
{$ENDIF}
647+
641648
if (ASource <> '') and (ANameSeparator = '') then
642649
ANameSeparator := FindNameSeparator(ASource);
643650

@@ -1157,16 +1164,26 @@ function TRALParams.NextParamStr: StringRAL;
11571164
function TRALParams.FindNameSeparator(const ASource: StringRAL): StringRAL;
11581165
var
11591166
vPos, vMin: IntegerRAL;
1167+
Engine: StringRAL;
11601168
begin
1161-
vMin := Length(ASource);
1162-
vPos := Pos('=', ASource);
1163-
if (vPos > 0) and (vPos <= vMin) then
1169+
Engine := Self.GetParam('RALEngine').AsString;
1170+
if SameText(Engine, ENGINESYNOPSE) then
1171+
Result := ': '
1172+
else if SameText(Engine, ENGINEINDY) or SameText(Engine, ENGINEFPHTTP)
1173+
or SameText(Engine, ENGINESAGUI) or SameText(Engine, ENGINENETHTTP) then
11641174
Result := '='
11651175
else
11661176
begin
1167-
vPos := Pos(StringRAL(': '), ASource);
1177+
vMin := Length(ASource);
1178+
vPos := Pos('=', ASource);
11681179
if (vPos > 0) and (vPos <= vMin) then
1169-
Result := ': ';
1180+
Result := '='
1181+
else
1182+
begin
1183+
vPos := Pos(StringRAL(': '), ASource);
1184+
if (vPos > 0) and (vPos <= vMin) then
1185+
Result := ': ';
1186+
end;
11701187
end;
11711188
end;
11721189

@@ -1254,34 +1271,35 @@ function TRALParams.Compress(AStream: TStream): TStream;
12541271
end;
12551272

12561273
function TRALParams.Encrypt(AStream: TStream): TStream;
1257-
var
1258-
vCript: TRALCripto;
1259-
begin
1260-
Result := nil;
1261-
case FCriptoOptions.CriptType of
1262-
crAES128:
1263-
begin
1264-
vCript := TRALCriptoAES.Create;
1265-
TRALCriptoAES(vCript).AESType := tAES128;
1266-
end;
1267-
crAES192:
1268-
begin
1269-
vCript := TRALCriptoAES.Create;
1270-
TRALCriptoAES(vCript).AESType := tAES192;
1271-
end;
1272-
crAES256:
1273-
begin
1274-
vCript := TRALCriptoAES.Create;
1275-
TRALCriptoAES(vCript).AESType := tAES256;
1276-
end;
1277-
end;
1278-
1279-
try
1280-
vCript.Key := FCriptoOptions.Key;
1281-
Result := vCript.EncryptAsStream(AStream);
1282-
finally
1283-
FreeAndNil(vCript);
1284-
end;
1274+
//var
1275+
// vCript: TRALCripto;
1276+
begin
1277+
Result := TRALHashes.Encrypt(AStream, FCriptoOptions.Key, FCriptoOptions.CriptType);
1278+
// Result := nil;
1279+
// case FCriptoOptions.CriptType of
1280+
// crAES128:
1281+
// begin
1282+
// vCript := TRALCriptoAES.Create;
1283+
// TRALCriptoAES(vCript).AESType := tAES128;
1284+
// end;
1285+
// crAES192:
1286+
// begin
1287+
// vCript := TRALCriptoAES.Create;
1288+
// TRALCriptoAES(vCript).AESType := tAES192;
1289+
// end;
1290+
// crAES256:
1291+
// begin
1292+
// vCript := TRALCriptoAES.Create;
1293+
// TRALCriptoAES(vCript).AESType := tAES256;
1294+
// end;
1295+
// end;
1296+
//
1297+
// try
1298+
// vCript.Key := FCriptoOptions.Key;
1299+
// Result := vCript.EncryptAsStream(AStream);
1300+
// finally
1301+
// FreeAndNil(vCript);
1302+
// end;
12851303
end;
12861304

12871305
function TRALParams.Decompress(AStream: TStream): TStream;
@@ -1327,65 +1345,65 @@ function TRALParams.Decompress(const ASource: StringRAL): StringRAL;
13271345
end;
13281346

13291347
function TRALParams.Decrypt(AStream: TStream): TStream;
1330-
var
1331-
vCript: TRALCripto;
1332-
begin
1333-
Result := nil;
1334-
case FCriptoOptions.CriptType of
1335-
crAES128:
1336-
begin
1337-
vCript := TRALCriptoAES.Create;
1338-
TRALCriptoAES(vCript).AESType := tAES128;
1339-
end;
1340-
crAES192:
1341-
begin
1342-
vCript := TRALCriptoAES.Create;
1343-
TRALCriptoAES(vCript).AESType := tAES192;
1344-
end;
1345-
crAES256:
1346-
begin
1347-
vCript := TRALCriptoAES.Create;
1348-
TRALCriptoAES(vCript).AESType := tAES256;
1349-
end;
1350-
end;
1351-
1352-
try
1353-
vCript.Key := FCriptoOptions.Key;
1354-
Result := vCript.DecryptAsStream(AStream);
1355-
finally
1356-
FreeAndNil(vCript);
1357-
end;
1348+
//var
1349+
// vCript: TRALCripto;
1350+
begin
1351+
Result := TRALHashes.Decrypt(AStream, FCriptoOptions.Key, FCriptoOptions.CriptType);
1352+
// case FCriptoOptions.CriptType of
1353+
// crAES128:
1354+
// begin
1355+
// vCript := TRALCriptoAES.Create;
1356+
// TRALCriptoAES(vCript).AESType := tAES128;
1357+
// end;
1358+
// crAES192:
1359+
// begin
1360+
// vCript := TRALCriptoAES.Create;
1361+
// TRALCriptoAES(vCript).AESType := tAES192;
1362+
// end;
1363+
// crAES256:
1364+
// begin
1365+
// vCript := TRALCriptoAES.Create;
1366+
// TRALCriptoAES(vCript).AESType := tAES256;
1367+
// end;
1368+
// end;
1369+
//
1370+
// try
1371+
// vCript.Key := FCriptoOptions.Key;
1372+
// Result := vCript.DecryptAsStream(AStream);
1373+
// finally
1374+
// FreeAndNil(vCript);
1375+
// end;
13581376
end;
13591377

13601378
function TRALParams.Decrypt(const ASource: StringRAL): StringRAL;
1361-
var
1362-
vCript: TRALCripto;
1363-
begin
1364-
Result := '';
1365-
case FCriptoOptions.CriptType of
1366-
crAES128:
1367-
begin
1368-
vCript := TRALCriptoAES.Create;
1369-
TRALCriptoAES(vCript).AESType := tAES128;
1370-
end;
1371-
crAES192:
1372-
begin
1373-
vCript := TRALCriptoAES.Create;
1374-
TRALCriptoAES(vCript).AESType := tAES192;
1375-
end;
1376-
crAES256:
1377-
begin
1378-
vCript := TRALCriptoAES.Create;
1379-
TRALCriptoAES(vCript).AESType := tAES256;
1380-
end;
1381-
end;
1382-
1383-
try
1384-
vCript.Key := FCriptoOptions.Key;
1385-
Result := vCript.Decrypt(ASource);
1386-
finally
1387-
FreeAndNil(vCript);
1388-
end;
1379+
//var
1380+
// vCript: TRALCripto;
1381+
begin
1382+
Result := TRALHashes.Decrypt(ASource, FCriptoOptions.Key, FCriptoOptions.CriptType);
1383+
// case FCriptoOptions.CriptType of
1384+
// crAES128:
1385+
// begin
1386+
// vCript := TRALCriptoAES.Create;
1387+
// TRALCriptoAES(vCript).AESType := tAES128;
1388+
// end;
1389+
// crAES192:
1390+
// begin
1391+
// vCript := TRALCriptoAES.Create;
1392+
// TRALCriptoAES(vCript).AESType := tAES192;
1393+
// end;
1394+
// crAES256:
1395+
// begin
1396+
// vCript := TRALCriptoAES.Create;
1397+
// TRALCriptoAES(vCript).AESType := tAES256;
1398+
// end;
1399+
// end;
1400+
//
1401+
// try
1402+
// vCript.Key := FCriptoOptions.Key;
1403+
// Result := vCript.Decrypt(ASource);
1404+
// finally
1405+
// FreeAndNil(vCript);
1406+
// end;
13891407
end;
13901408

13911409
procedure TRALParams.DelParam(const AName: StringRAL; AKind: TRALParamKind);

0 commit comments

Comments
 (0)