From cb0ed2b6f0f06783a77b505b08a49e817eddd56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Van=20Canneyt?= Date: Sun, 5 Feb 2023 11:35:11 +0100 Subject: [PATCH] * Correct params checking in case of array --- packages/fcl-web/src/jsonrpc/fpjsonrpc.pp | 44 ++++++++++++++++------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/packages/fcl-web/src/jsonrpc/fpjsonrpc.pp b/packages/fcl-web/src/jsonrpc/fpjsonrpc.pp index c41af262f6..c112bd9155 100644 --- a/packages/fcl-web/src/jsonrpc/fpjsonrpc.pp +++ b/packages/fcl-web/src/jsonrpc/fpjsonrpc.pp @@ -74,8 +74,14 @@ Type private FClassName: String; FMethod: String; + FParamDefinitions: TJSONParamDefs; + FParams: TJSONData; FTID: String; + procedure SetParams(AValue: TJSONData); + protected + Property ParamDefinitions : TJSONParamDefs Read FParamDefinitions Write FParamDefinitions; Public + Property Params : TJSONData Read FParams Write SetParams; // Action used to call handler. Property ClassName : String Read FClassName Write FClassName; // Method used to call handler. @@ -356,7 +362,7 @@ Type TCustomJSONRPCHandlerManager = Class(TComponent) Private FRegistering: Boolean; - FHandlerCount : Integer; + FHandlerCount : Int64; Protected procedure Initialize; virtual; procedure DoClear; virtual; @@ -532,6 +538,14 @@ begin raise EJSONRPC.CreateFmt(SErrParams, [Format(Fmt, Args)]); end; +{ TJSONRPCCallContext } + +procedure TJSONRPCCallContext.SetParams(AValue: TJSONData); +begin + if FParams=AValue then Exit; + FParams:=AValue; +end; + { TAPIDescriptionCreator } function TAPIDescriptionCreator.GetOwner: TPersistent; @@ -798,20 +812,24 @@ begin end; procedure TCustomJSONRPCHandler.DoCheckParamArray(const ParamArray: TJSONArray); + var - element: TJSONEnum; + I : Integer; + Param: TJSONData; + Def : TJSONParamDef; + begin - for element in ParamArray do - begin - // check object parameters if objects given - if (element.Value.JSONType=jtObject) then + for I:=0 to ParamDefs.Count-1 do begin - DoCheckParamDefsOnObject(element.Value as TJSONObject); - end else - // not an object - if (jroObjectParams in Options) then - JSONRPCParamError(SErrParamsOnlyObjectsInArray,[JSONTypeName(element.Value.JSONType),element.KeyNum]); - end; + Def:=ParamDefs[i]; + if I>=ParamArray.Count then + if ParamDefs[i].Required then + JSONRPCParamError(SErrParamsRequiredParamNotFound,[def.Name]); + Param:=ParamArray[i]; + // jtUnkown accepts all data types + if (def.DataType<>jtUnknown) and not (Param.JSONType=def.DataType) then + JSONRPCParamError(SErrParamsDataTypeMismatch,[def.Name,JSONTypeName(def.DataType),JSONTypeName(Param.JSONType)]); + end; end; function TCustomJSONRPCHandler.DoExecute(Const Params: TJSONData;AContext : TJSONRPCCallContext): TJSONData; @@ -1809,7 +1827,7 @@ begin N:=aContainer.Name; if N='' then N:=aContainer.ClassName; - N:=N+IntToStr(InterlockedIncrement(FHandlerCount)); + N:=N+IntToStr(InterlockedIncrement64(FHandlerCount)); aContainer.Name:=N; O.InsertComponent(aContainer); end;