Skip to content

Commit 5477d7f

Browse files
author
ronierys2@hotmail.com
committed
Correções
- Ajuste para sempre passar pelo ReadRawHeaders. - Ajuste para encontrar o evento na lista de eventos, para assim determinar se passa ou não no validador de permissão - Correção no sistema da Leitura de Parametros Path e Query.
1 parent 28754dc commit 5477d7f

2 files changed

Lines changed: 114 additions & 62 deletions

File tree

CORE/Source/Basic/uRESTDWServerMethodClass.pas

Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
unit uRESTDWServerMethodClass;
1+
unit uRESTDWServerMethodClass;
22

33
{$I ..\Includes\uRESTDW.inc}
44

@@ -149,43 +149,64 @@ implementation
149149
vTempValue,
150150
vTempParamsURI,
151151
vTempURL,
152+
vParamChar,
152153
ParamsURI : String;
153154
vParamMethods : TRESTDWParamsMethods;
154155
Procedure ParseParams;
155156
Var
156157
lst : TStringList;
157158
pAux1,
158159
cAux1 : Integer;
160+
ctempURI,
161+
sAux,
159162
sAux1,
160163
sAux2 : string;
161164
JSONParam : TRESTDWJSONParam;
162165
Begin
163166
lst := TStringList.Create;
164167
Try
165-
pAux1 := Pos('?', ParamsURI);
168+
ctempURI := ParamsURI;
169+
pAux1 := Pos('?', ctempURI);
166170
// params com /
167-
sAux1 := Copy(ParamsURI, 1, pAux1 - 1);
171+
If vIsQuery Then
172+
Begin
173+
If Pos('/', ctempURI) > 0 Then
174+
Begin
175+
sAux2 := Copy(ctempURI, pAux1 + 1, Pos('/', ctempURI) -2);
176+
Delete(ctempURI, pAux1, Pos('/', ctempURI));
177+
End
178+
Else
179+
Begin
180+
sAux2 := Copy(ctempURI, pAux1 + 1, Length(ctempURI));
181+
Delete(ctempURI, pAux1, Length(ctempURI));
182+
End;
183+
End
184+
Else
185+
sAux2 := '';
168186
// params com &
169-
sAux2 := Copy(ParamsURI, pAux1 + 1, Length(ParamsURI));
187+
If ctempURI <> '' Then
188+
sAux1 := Copy(ctempURI, InitStrPos, Length(ctempURI))
189+
Else
190+
sAux1 := '';
191+
While (sAux2 <> '') Do
192+
Begin
193+
pAux1 := Pos('&', sAux2);
194+
If pAux1 = 0 then
195+
pAux1 := Length(sAux2) + 1;
196+
sAux := Copy(sAux2, InitStrPos, pAux1 - 1);
197+
If Pos('dwmark:', sAux) = 0 then
198+
lst.Add(sAux);
199+
Delete(sAux2, InitStrPos, pAux1);
200+
End;
170201
cAux1 := 0;
171202
While (sAux1 <> '') Do
172203
Begin
173204
pAux1 := Pos('/', sAux1);
174205
If pAux1 = 0 Then
175206
pAux1 := Length(sAux1) + 1;
176-
lst.Add(IntToStr(cAux1) + '=' + Copy(sAux1, 1, pAux1 - 1));
177-
cAux1 := cAux1 + 1;
178-
Delete(sAux1, 1, pAux1);
179-
End;
180-
While (sAux2 <> '') Do
181-
Begin
182-
pAux1 := Pos('&', sAux2);
183-
If pAux1 = 0 then
184-
pAux1 := Length(sAux2) + 1;
185-
sAux1 := Copy(sAux2, 1, pAux1 - 1);
186-
If Pos('dwmark:', sAux1) = 0 then
187-
lst.Add(sAux1);
188-
Delete(sAux2, 1, pAux1);
207+
lst.Add(IntToStr(cAux1) + '=' + Copy(sAux1, InitStrPos, pAux1 - 1));
208+
Inc(cAux1);
209+
Delete(sAux1, InitStrPos, pAux1);
189210
End;
190211
While lst.Count > 0 Do
191212
Begin
@@ -198,15 +219,14 @@ implementation
198219
JSONParam.SetValue(lst.ValueFromIndex[0]);
199220
Params.Add(JSONParam);
200221
End
201-
Else If JSONParam.IsNull Then
222+
Else
202223
JSONParam.SetValue(lst.ValueFromIndex[0]);
203224
lst.Delete(0);
204225
End;
205226
Finally
206227
FreeAndNil(lst);
207228
End;
208229
End;
209-
210230
Procedure CopyParams(SourceParams : TRESTDWParamsMethods);
211231
Var
212232
isrc : Integer;
@@ -225,7 +245,6 @@ implementation
225245
End;
226246
End;
227247
End;
228-
229248
Procedure ParseURL;
230249
Begin
231250
vPosQuery := Pos('?', URL);
@@ -250,7 +269,6 @@ implementation
250269
If URL = '' Then
251270
URL := '/';
252271
End;
253-
254272
Begin
255273
Result := False;
256274
If Length(URL) = 0 Then
@@ -263,8 +281,16 @@ implementation
263281
Begin
264282
For A := 0 To TRESTDWServerEvents(Components[I]).Events.Count -1 Do
265283
Begin
284+
If Pos('?', vTempValue) > 0 Then
285+
vParamChar := '?'
286+
Else
287+
vParamChar := '/';
288+
If vParamChar = '/' Then
289+
If Length(vTempValue) > 0 Then
290+
If vTempValue[Length(vTempValue) - FinalStrPos] <> vParamChar Then
291+
vTempValue := vTempValue + vParamChar;
266292
vTempRoute := TRESTDWServerEvents(Components[I]).Events[A].BaseURL +
267-
TRESTDWServerEvents(Components[I]).Events[A].EventName;
293+
TRESTDWServerEvents(Components[I]).Events[A].EventName + vParamChar;
268294
If ((vTempValue = '/') or (vTempValue = '')) Then
269295
Begin
270296
If TRESTDWServerEvents(Components[I]).DefaultEvent <> '' Then
@@ -274,55 +300,55 @@ implementation
274300
vTempValue := '/' + vTempValue;
275301
End;
276302
End;
277-
If SameText(vTempRoute, vTempValue) Then
303+
If SameText(vTempRoute, Copy(vTempValue, InitStrPos, Length(vTempRoute))) Then
278304
Begin
279305
Result := True;
280306
vTempURL := vTempRoute;
281-
vTempParamsURI := '';
307+
Delete(vTempValue, InitStrPos, Length(vTempRoute));
308+
vTempParamsURI := vTempValue;
282309
vParamMethods := TRESTDWServerEvents(Components[I]).Events[A].Params;
283310
BuildCORS(TRESTDWServerEvents(Components[I]).Events[A].Routes, CORS_CustomHeaders);
284311
Break;
285-
End
286-
Else If SameText(vTempRoute + '/', Copy(vTempValue + '/', InitStrPos, Length(vTempRoute + '/') - FinalStrPos)) Then
287-
Begin
288-
Result := True;
289-
vTempURL := vTempRoute;
290-
vTempParamsURI := Copy(vTempValue, Length(vTempRoute) + 2, Length(vTempValue));
291-
vParamMethods := TRESTDWServerEvents(Components[I]).Events[A].Params;
292-
BuildCORS(TRESTDWServerEvents(Components[I]).Events[A].Routes, CORS_CustomHeaders);
293312
End;
294313
End;
295314
End
296315
Else If (Components[i] Is TRESTDWServerContext) Then
297316
Begin
298317
For A := 0 To TRESTDWServerContext(Components[I]).ContextList.Count - 1 Do
299318
Begin
319+
If Pos('?', vTempValue) > 0 Then
320+
vParamChar := '?'
321+
Else
322+
vParamChar := '/';
323+
If vParamChar = '/' Then
324+
If Length(vTempValue) > 0 Then
325+
If vTempValue[Length(vTempValue) - FinalStrPos] <> vParamChar Then
326+
vTempValue := vTempValue + vParamChar;
300327
vTempRoute := TRESTDWServerContext(Components[I]).ContextList[A].BaseURL +
301-
TRESTDWServerContext(Components[I]).ContextList[A].ContextName;
302-
If SameText(vTempRoute, vTempValue) Then
328+
TRESTDWServerContext(Components[I]).ContextList[A].ContextName + vParamChar;
329+
If SameText(vTempRoute, Copy(vTempValue, InitStrPos, Length(vTempRoute))) Then
303330
Begin
304331
Result := True;
305332
vTempURL := vTempRoute;
306-
vTempParamsURI := '';
333+
Delete(vTempValue, InitStrPos, Length(vTempRoute));
334+
vTempParamsURI := vTempValue;
307335
vParamMethods := TRESTDWServerContext(Components[I]).ContextList[A].Params;
308336
BuildCORS(TRESTDWServerContext(Components[I]).ContextList[A].Routes, CORS_CustomHeaders);
309337
Break;
310-
End
311-
Else If SameText(vTempRoute+'/', Copy(vTempValue+'/', 1, Length(vTempRoute+'/'))) Then
312-
Begin
313-
Result := True;
314-
vTempURL := vTempRoute;
315-
vTempParamsURI := Copy(vTempValue, Length(vTempRoute) + 2, Length(vTempValue));
316-
vParamMethods := TRESTDWServerContext(Components[I]).ContextList[A].Params;
317-
BuildCORS(TRESTDWServerContext(Components[I]).ContextList[A].Routes, CORS_CustomHeaders);
318338
End;
319339
End;
320340
End;
321341
If Result Then
322342
Begin
323343
CopyParams(vParamMethods);
324344
URL := vTempURL;
325-
ParamsURI := '?' + ParamsURI;
345+
If Not vIsQuery Then
346+
ParamsURI := vParamChar + ParamsURI
347+
Else
348+
ParamsURI := '?' + ParamsURI;
349+
If vTempParamsURI <> '' Then
350+
If vTempParamsURI[Length(vTempParamsURI) - FinalStrPos] = '/' Then
351+
Delete(vTempParamsURI, Length(vTempParamsURI) - FinalStrPos, 1);
326352
ParamsURI := vTempParamsURI + ParamsURI;
327353
ParseParams;
328354
Break;

CORE/Source/Plugins/DMDados/uRESTDWDatamodule.pas

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,36 +124,56 @@ implementation
124124
lst : TStringList;
125125
pAux1,
126126
cAux1 : Integer;
127+
ctempURI,
128+
sAux,
127129
sAux1,
128130
sAux2 : string;
129131
JSONParam : TRESTDWJSONParam;
130132
Begin
131133
lst := TStringList.Create;
132134
Try
133-
pAux1 := Pos('?', ParamsURI);
135+
ctempURI := ParamsURI;
136+
pAux1 := Pos('?', ctempURI);
134137
// params com /
135-
sAux1 := Copy(ParamsURI, 1, pAux1 - 1);
138+
If vIsQuery Then
139+
Begin
140+
If Pos('/', ctempURI) > 0 Then
141+
Begin
142+
sAux2 := Copy(ctempURI, pAux1 + 1, Pos('/', ctempURI) -2);
143+
Delete(ctempURI, pAux1, Pos('/', ctempURI));
144+
End
145+
Else
146+
Begin
147+
sAux2 := Copy(ctempURI, pAux1 + 1, Length(ctempURI));
148+
Delete(ctempURI, pAux1, Length(ctempURI));
149+
End;
150+
End
151+
Else
152+
sAux2 := '';
136153
// params com &
137-
sAux2 := Copy(ParamsURI, pAux1 + 1, Length(ParamsURI));
154+
If ctempURI <> '' Then
155+
sAux1 := Copy(ctempURI, InitStrPos, Length(ctempURI))
156+
Else
157+
sAux1 := '';
158+
While (sAux2 <> '') Do
159+
Begin
160+
pAux1 := Pos('&', sAux2);
161+
If pAux1 = 0 then
162+
pAux1 := Length(sAux2) + 1;
163+
sAux := Copy(sAux2, InitStrPos, pAux1 - 1);
164+
If Pos('dwmark:', sAux) = 0 then
165+
lst.Add(sAux);
166+
Delete(sAux2, InitStrPos, pAux1);
167+
End;
138168
cAux1 := 0;
139169
While (sAux1 <> '') Do
140170
Begin
141171
pAux1 := Pos('/', sAux1);
142172
If pAux1 = 0 Then
143173
pAux1 := Length(sAux1) + 1;
144-
lst.Add(IntToStr(cAux1) + '=' + Copy(sAux1, 1, pAux1 - 1));
145-
cAux1 := cAux1 + 1;
146-
Delete(sAux1, 1, pAux1);
147-
End;
148-
While (sAux2 <> '') Do
149-
Begin
150-
pAux1 := Pos('&', sAux2);
151-
If pAux1 = 0 then
152-
pAux1 := Length(sAux2) + 1;
153-
sAux1 := Copy(sAux2, 1, pAux1 - 1);
154-
If Pos('dwmark:', sAux1) = 0 then
155-
lst.Add(sAux1);
156-
Delete(sAux2, 1, pAux1);
174+
lst.Add(IntToStr(cAux1) + '=' + Copy(sAux1, InitStrPos, pAux1 - 1));
175+
Inc(cAux1);
176+
Delete(sAux1, InitStrPos, pAux1);
157177
End;
158178
While lst.Count > 0 Do
159179
Begin
@@ -166,7 +186,7 @@ implementation
166186
JSONParam.SetValue(lst.ValueFromIndex[0]);
167187
Params.Add(JSONParam);
168188
End
169-
Else If JSONParam.IsNull Then
189+
Else
170190
JSONParam.SetValue(lst.ValueFromIndex[0]);
171191
lst.Delete(0);
172192
End;
@@ -289,7 +309,13 @@ implementation
289309
Begin
290310
CopyParams(vParamMethods);
291311
URL := vTempURL;
292-
ParamsURI := vParamChar + ParamsURI;
312+
If Not vIsQuery Then
313+
ParamsURI := vParamChar + ParamsURI
314+
Else
315+
ParamsURI := '?' + ParamsURI;
316+
If vTempParamsURI <> '' Then
317+
If vTempParamsURI[Length(vTempParamsURI) - FinalStrPos] = '/' Then
318+
Delete(vTempParamsURI, Length(vTempParamsURI) - FinalStrPos, 1);
293319
ParamsURI := vTempParamsURI + ParamsURI;
294320
ParseParams;
295321
Break;

0 commit comments

Comments
 (0)