mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 00:09:26 +02:00
* Correct params checking in case of array
This commit is contained in:
parent
6e5c5f599e
commit
cb0ed2b6f0
@ -74,8 +74,14 @@ Type
|
|||||||
private
|
private
|
||||||
FClassName: String;
|
FClassName: String;
|
||||||
FMethod: String;
|
FMethod: String;
|
||||||
|
FParamDefinitions: TJSONParamDefs;
|
||||||
|
FParams: TJSONData;
|
||||||
FTID: String;
|
FTID: String;
|
||||||
|
procedure SetParams(AValue: TJSONData);
|
||||||
|
protected
|
||||||
|
Property ParamDefinitions : TJSONParamDefs Read FParamDefinitions Write FParamDefinitions;
|
||||||
Public
|
Public
|
||||||
|
Property Params : TJSONData Read FParams Write SetParams;
|
||||||
// Action used to call handler.
|
// Action used to call handler.
|
||||||
Property ClassName : String Read FClassName Write FClassName;
|
Property ClassName : String Read FClassName Write FClassName;
|
||||||
// Method used to call handler.
|
// Method used to call handler.
|
||||||
@ -356,7 +362,7 @@ Type
|
|||||||
TCustomJSONRPCHandlerManager = Class(TComponent)
|
TCustomJSONRPCHandlerManager = Class(TComponent)
|
||||||
Private
|
Private
|
||||||
FRegistering: Boolean;
|
FRegistering: Boolean;
|
||||||
FHandlerCount : Integer;
|
FHandlerCount : Int64;
|
||||||
Protected
|
Protected
|
||||||
procedure Initialize; virtual;
|
procedure Initialize; virtual;
|
||||||
procedure DoClear; virtual;
|
procedure DoClear; virtual;
|
||||||
@ -532,6 +538,14 @@ begin
|
|||||||
raise EJSONRPC.CreateFmt(SErrParams, [Format(Fmt, Args)]);
|
raise EJSONRPC.CreateFmt(SErrParams, [Format(Fmt, Args)]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TJSONRPCCallContext }
|
||||||
|
|
||||||
|
procedure TJSONRPCCallContext.SetParams(AValue: TJSONData);
|
||||||
|
begin
|
||||||
|
if FParams=AValue then Exit;
|
||||||
|
FParams:=AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TAPIDescriptionCreator }
|
{ TAPIDescriptionCreator }
|
||||||
|
|
||||||
function TAPIDescriptionCreator.GetOwner: TPersistent;
|
function TAPIDescriptionCreator.GetOwner: TPersistent;
|
||||||
@ -798,20 +812,24 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomJSONRPCHandler.DoCheckParamArray(const ParamArray: TJSONArray);
|
procedure TCustomJSONRPCHandler.DoCheckParamArray(const ParamArray: TJSONArray);
|
||||||
|
|
||||||
var
|
var
|
||||||
element: TJSONEnum;
|
I : Integer;
|
||||||
|
Param: TJSONData;
|
||||||
|
Def : TJSONParamDef;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
for element in ParamArray do
|
for I:=0 to ParamDefs.Count-1 do
|
||||||
begin
|
|
||||||
// check object parameters if objects given
|
|
||||||
if (element.Value.JSONType=jtObject) then
|
|
||||||
begin
|
begin
|
||||||
DoCheckParamDefsOnObject(element.Value as TJSONObject);
|
Def:=ParamDefs[i];
|
||||||
end else
|
if I>=ParamArray.Count then
|
||||||
// not an object
|
if ParamDefs[i].Required then
|
||||||
if (jroObjectParams in Options) then
|
JSONRPCParamError(SErrParamsRequiredParamNotFound,[def.Name]);
|
||||||
JSONRPCParamError(SErrParamsOnlyObjectsInArray,[JSONTypeName(element.Value.JSONType),element.KeyNum]);
|
Param:=ParamArray[i];
|
||||||
end;
|
// 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;
|
end;
|
||||||
|
|
||||||
function TCustomJSONRPCHandler.DoExecute(Const Params: TJSONData;AContext : TJSONRPCCallContext): TJSONData;
|
function TCustomJSONRPCHandler.DoExecute(Const Params: TJSONData;AContext : TJSONRPCCallContext): TJSONData;
|
||||||
@ -1809,7 +1827,7 @@ begin
|
|||||||
N:=aContainer.Name;
|
N:=aContainer.Name;
|
||||||
if N='' then
|
if N='' then
|
||||||
N:=aContainer.ClassName;
|
N:=aContainer.ClassName;
|
||||||
N:=N+IntToStr(InterlockedIncrement(FHandlerCount));
|
N:=N+IntToStr(InterlockedIncrement64(FHandlerCount));
|
||||||
aContainer.Name:=N;
|
aContainer.Name:=N;
|
||||||
O.InsertComponent(aContainer);
|
O.InsertComponent(aContainer);
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user