Qore JsonRpcHandler Module Reference  1.3
JsonRpcHandler.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* JsonRpcHandler.qm Copyright (C) 2012 - 2018 Qore Technologies, s.r.o.
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // minimum qore version
26 
27 // requires the binary json module
28 
29 // need mime definitions
30 
31 // need Util functions
32 
33 // need HttpServerUtil definitions
34 
35 // don't use "$" for vars, members, and method calls, assume local var scope
36 
37 
95 namespace JsonRpcHandler {
98 
100 class JsonRpcHandler : public AbstractHttpRequestHandler {
101 
102 public:
104  const Version = "1.3";
105 
107  const InternalMethods = (
108  {
109  "function": "help",
110  "help": "shows a list of JSON-RPC methods registered with this handler",
111  "text": "help",
112  "logopt": 2
113  },
114  {
115  "function": "listMethods",
116  "help": "lists JSON-RPC method names registered with this handler",
117  "text": "system.listMethods",
118  "logopt": 2
119  },
120  {
121  "function": "systemDescribe",
122  "help": "returns the service description object as per the JSON-RPC 1.1 spec",
123  "text": "system.describe",
124  "logopt": 2
125  },
126  );
127 
129  const JRE_ParseError = -32700;
130 
132  const JRE_InvalidRequest = -32600;
133 
135  const JRE_MethodNotFound = -32601;
136 
138  const JRE_InvalidParams = -32602;
139 
141  const JRE_InternalError = -32603;
142 
144 private:
145  list methods = ();
146  hash mi;
147  int loglevel;
148 
149  // if True then verbose exception info will be logged
150  bool debug;
151 
152  // prefix to add to derived methods with GET requests if no "." characters are in the path
153  *string get_prefix;
154 
155  // a closure/call reference to get the log message and/or process arguments in incoming requests
156  *code getLogMessage;
157 
158  // a closure/call reference for logging (when set this is used instead of the HTTP server's logfunc for logging)
159  *code log_code;
160 
161 public:
163 
165 
180  constructor(HttpServer::AbstractAuthenticator n_auth, list<auto> n_methods, *code n_getLogMessage, bool n_dbg = False, *string n_get_prefix, *code n_log) ;
181 
182 
184 
191  addMethod(string name, code func, string text, string help, auto logopt, auto cmark);
192 
193 
195  setDebug(bool dbg = True);
196 
197 
199  bool getDebug();
200 
201 
203  // don't reimplement this method; fix/enhance it in the module
204 protected:
205  final addMethodInternal(hash<auto> h);
206 public:
207 
208 
209 protected:
210  hash<auto> help();
211 public:
212 
213 
214 protected:
215  hash systemDescribe();
216 public:
217 
218 
219 protected:
220  softlist<string> listMethods();
221 public:
222 
223 
224 protected:
225  log(hash<auto> cx, string str);
226 public:
227 
228 
229  // don't reimplement this method; fix/enhance it in the module
230 protected:
231  final hash callMethod(hash<auto> cx, auto params);
232 public:
233 
234 
235  // method called by HttpServer to handle a request
236  // don't reimplement this method; fix/enhance it in the module
237  final hash<auto> handleRequest(hash<auto> cx, hash<auto> hdr, *data body);
238 
239 
240 protected:
241  hash<auto> processBatchMessage(hash<auto> cx, list<auto> l);
242 public:
243 
244  };
245 };
JsonRpcHandler::JsonRpcHandler::getDebug
bool getDebug()
returns the current status of the debug flag
JsonRpcHandler::JsonRpcHandler::addMethod
addMethod(string name, code func, string text, string help, auto logopt, auto cmark)
adds a method to the handler dynamically
JsonRpcHandler::JsonRpcHandler::setDebug
setDebug(bool dbg=True)
turns on or off debugging; when debugging is enabled more verbose error messages are reported
JsonRpcHandler::JsonRpcHandler::addMethodInternal
final addMethodInternal(hash< auto > h)
@conf nodoc
JsonRpcHandler
the JsonRpcHandler namespace holds all public definitions in the JsonRpcHandler module
Definition: JsonRpcHandler.qm.dox.h:96
JsonRpcHandler::JsonRpcHandler::constructor
constructor(HttpServer::AbstractAuthenticator n_auth, list< auto > n_methods, *code n_getLogMessage, bool n_dbg=False, *string n_get_prefix, *code n_log)
creates the handler with the given method list