Quantcast

json_put bug?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

json_put bug?

rickerdo
While mucking around with MH's JSON interface I noticed something odd. The json_put function in json_server.pl blindly takes the body of the request and passes it to an object's method. This means something like: curl -X PUT -d '{"set":"on"}' http://banshee:8080/json/objects/Garage/set is passed through to: "my $response = $object->$method($body);" which in turn becomes Garage->set(set => on). Obviously this fails.

However, sending: curl -X PUT -d '{"on"}' http://banshee:8080/json/objects/Garage/set crashes MH because the body is not properly JSON formatted.

Is this a bug, or am I incorrectly using a JSON PUT? Also, shouldn't this be a POST, not a PUT? Maybe even just a GET?

My goal is to submit a GET to control the state of an object and receive a JSON formatted response containing the new state. Am I taking the wrong approach?

Thanks!

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: json_put bug?

Eloy Paris
Hi Rick,

On Sat, Nov 05, 2016 at 12:04:32PM -0500, Rick Reed wrote:

[...]

> However, sending: curl -X PUT -d '{"on"}'
> http://banshee:8080/json/objects/Garage/set crashes MH because the body is
> not properly JSON formatted.
>
> Is this a bug, or am I incorrectly using a JSON PUT? Also, shouldn't this
> be a POST, not a PUT? Maybe even just a GET?

Without delving too deep into the problem, if it makes MH crash then
it is a bug. Input should always be checked, and bad input should be
discarded to prevent damage (like a crash) down the road.

Cheers,

Eloy Paris.-


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: json_put bug?

H Plato
In reply to this post by rickerdo
I haven’t used json_put, so I can’t really answer the question.

however, perl doesn’t fail json handling very well. If you look at the json_get, I’ve wrapped the decode_json's in eval loops, so if the decode fails, a warning is printed to the print_log, and MH doesn’t crash.

It would probably make sense to wrap this;

                my $response = $object->$method($body);

in an eval loop as well.

That said, the $object->can( $path[2] ); should catch if an object can do the $path[2] method.

IA7 doesn’t use json_put, but rather http://server/SET;none?select_item=ITEM&select_state=STATE

It doesn’t return any output though. IA7 gets around this by using a long poll, and then the object is set to the new state once MH processes it.


On Nov 5, 2016, at 11:04 AM, Rick Reed <[hidden email]> wrote:

While mucking around with MH's JSON interface I noticed something odd. The json_put function in json_server.pl blindly takes the body of the request and passes it to an object's method. This means something like: curl -X PUT -d '{"set":"on"}' http://banshee:8080/json/objects/Garage/set is passed through to: "my $response = $object->$method($body);" which in turn becomes Garage->set(set => on). Obviously this fails.

However, sending: curl -X PUT -d '{"on"}' http://banshee:8080/json/objects/Garage/set crashes MH because the body is not properly JSON formatted.

Is this a bug, or am I incorrectly using a JSON PUT? Also, shouldn't this be a POST, not a PUT? Maybe even just a GET?

My goal is to submit a GET to control the state of an object and receive a JSON formatted response containing the new state. Am I taking the wrong approach?

Thanks!
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Loading...