[Cppcms-users] json_rpc and json questions
Brought to you by:
artyom-beilis
From: Daniel V. <chi...@gm...> - 2011-05-18 20:57:20
|
Hello, Question 1. I am implementing a json rpc server (cppcms::rpc::json_rpc_server) with privileges. One possible solution is for each rpc method do the following: void my_rpc_server::get_sensible_data() { if ( check_privileges() ) { // method implementation //... } else { return_error("not authorized"); } }; The problem is that I think this solution is not good because I would like to decouple the privilege system of the rpc methods definitions. Another theoretical solution would be extend virtual main method to add desired pre actions: class my_rcp : public cppcms::rpc::json_rpc_server { virtual void main(std::string); }; void main(std::string //unused) { json_rpc_request req = parse_json_rpc_request(context()); // Ideally this method should be protected and implemented in json_rpc_server. // Added pre actions if ( check_privileges(req.method_name) ) { dispatch_request(req); // Ideally this method should be protected and implemented in json_rpc_server. } else { return_error("not authorised"); } } AFAIK that is not posible with current json_rpc_server implementation. What is the best approach to add pre actions (ie: check privileges) to rpc method invocation?. Question 2. I can't implement a json rpc method with a json::value argument, for example the following example not compile: void my_rpc_server::my_method(cppcms::json::value v) { } One posible workaround is define a json::value to json::value trait: namespace cppcms { namespace json { template<> struct traits<value> { static value get(value const &v) { return v; } static void set(value &v,value const &in) { v = in; } }; }} // end cppcms::json But I guest it is not optimal because nedless copy overhead. Thank you. |