RTC Forums

Subscription => Support => Topic started by: Max Terentiev on June 26, 2017, 11:58:17 AM



Title: json-rpc 2.0 request paramteres order
Post by: Max Terentiev on June 26, 2017, 11:58:17 AM
Hi, Danijel !

I have problems with json-rpc 2.0 requests generated by PHP function "json_encode".

This function generate json object like this (looks like parameters in alphabetical order):

{"jsonrpc":"2.0","id":1,"method":"engineGetStatus","params":[]}

While your implementation expect this:

{"jsonrpc":"2.0","method":"engineGetStatus","params":[],"id":1}

I think request parameters order should be not important. So, this variants should be also valid:

{"id":1, "jsonrpc":"2.0","method":"engineGetStatus","params":[]}
{"method":"engineGetStatus","params":[],"id":1,"jsonrpc":"2.0"}
etc

As a quick fix a modify TRtcValueObject.json_checkFunctionType to:

Code:
if ( json_checkTag(RTC_QMETHOD,s,at2) or
                     json_checkTag(RTC_QPARAMS,s,at2) or
                     json_checkTag(RTC_QID,s,at2) )then // added this line
                  Result:=rtc_Function;   

But it's not a final solution. It's only handle requests where "id" is second paramter.

Hope you can fix it in next version.

Thank you !


Title: Re: json-rpc 2.0 request paramteres order
Post by: Max Terentiev on June 26, 2017, 01:02:54 PM
And one addition: if your parser does not recognize request as json-rpc request (rtc_Function) they should send back some error like "invalid json-rpc request".
Instead they send back just nothing.


Title: Re: json-rpc 2.0 request paramteres order
Post by: D.Tkalcec (RTC) on June 26, 2017, 02:46:15 PM
Thanks. I'll add your proposed fix for PHP in the next RTC SDK update. Let me know if you bump into any other problems.

Best Regards,
Danijel Tkalcec


Title: Re: json-rpc 2.0 request paramteres order
Post by: D.Tkalcec (RTC) on June 28, 2017, 11:25:07 AM
I've released RTC SDK v8.15 now to fix the "JSON-RPC 2.0" parser, so it will recognize remote function calls received from PHP using "json_encode", where "id" is the 2nd element in a JSON record (directly following "jsonrpc":"2.0").

Best Regards,
Danijel Tkalcec


Title: Re: json-rpc 2.0 request paramteres order
Post by: D.Tkalcec (RTC) on June 28, 2017, 05:35:38 PM
I've now also released RTC SDK v8.16, which extends the "JSON-RPC 2.0" parser to also recognize and parse remote function calls and exception objects where "jsonrpc" is NOT the 1st element in the root JSON record. In other words, all of these JSON objects should now be recognized and correctly parsed as "JSON-RPC 2.0" remote function calls:

{"jsonrpc":"2.0", "method":"engineGetStatus", "params":[], "id":1}
{"jsonrpc":"2.0", "id":1, "method":"engineGetStatus", "params":[]}
{"id":1, "jsonrpc":"2.0", "method":"engineGetStatus", "params":[]}
{"id":1, "method":"engineGetStatus", "params":[], "jsonrpc":"2.0"}
{"method":"engineGetStatus", "params":[], "id":1, "jsonrpc":"2.0"}
{"method":"engineGetStatus", "params":[], "jsonrpc":"2.0", "id":1}

Best Regards,
Danijel Tkalcec


Title: Re: json-rpc 2.0 request paramteres order
Post by: Max Terentiev on July 03, 2017, 01:01:43 PM
Thank you very much !