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 
94 namespace JsonRpcHandler {
97 
99 class JsonRpcHandler : public AbstractHttpRequestHandler {
100 
101 public:
102  public :
104  const Version = "1.3";
105 
107  const InternalMethods = (
108  ("function": "help",
109  "help": "shows a list of JSON-RPC methods registered with this handler",
110  "text": "help",
111  "logopt": 2
112  ),
113  ("function": "listMethods",
114  "help": "lists JSON-RPC method names registered with this handler",
115  "text": "system.listMethods",
116  "logopt": 2
117  ),
118  ("function": "systemDescribe",
119  "help": "returns the service description object as per the JSON-RPC 1.1 spec",
120  "text": "system.describe",
121  "logopt": 2
122  ));
123 
125  const JRE_ParseError = -32700;
126 
128  const JRE_InvalidRequest = -32600;
129 
131  const JRE_MethodNotFound = -32601;
132 
134  const JRE_InvalidParams = -32602;
135 
137  const JRE_InternalError = -32603;
138 
139 public:
140 
142  private:internal {
143  list methods = ();
144  hash mi;
145  int loglevel;
146 
147  // if True then verbose exception info will be logged
148  bool debug;
149 
150  // prefix to add to derived methods with GET requests if no "." characters are in the path
151  *string get_prefix;
152 
153  // a closure/call reference to get the log message and/or process arguments in incoming requests
154  *code getLogMessage;
155 
156  // a closure/call reference for logging (when set this is used instead of the HTTP server's logfunc for logging)
157  *code log_code;
158  }
160 
162 
177  constructor(HttpServer::AbstractAuthenticator n_auth, list n_methods, *code n_getLogMessage, bool n_dbg = False, *string n_get_prefix, *code n_log) ;
178 
179 
181 
188  addMethod(string name, code func, string text, string help, auto logopt, auto cmark);
189 
190 
192  setDebug(bool dbg = True);
193 
194 
196  bool getDebug();
197 
198 
200  // don't reimplement this method; fix/enhance it in the module
201 
202 private:
203  final addMethodInternal(hash h);
204 public:
205 
206 
207 
208 private:
209  hash help();
210 public:
211 
212 
213 
214 private:
215  hash systemDescribe();
216 public:
217 
218 
219 
220 private:
221  list listMethods();
222 public:
223 
224 
225 
226 private:
227  log(hash cx, string str);
228 public:
229 
230 
231  // don't reimplement this method; fix/enhance it in the module
232 
233 private:
234  final hash callMethod(hash cx, auto params);
235 public:
236 
237 
238  // method called by HttpServer to handle a request
239  // don't reimplement this method; fix/enhance it in the module
240  final hash handleRequest(hash cx, hash hdr, *data body);
241 
242 
243 
244 private:
245  hash processBatchMessage(hash cx, list l);
246 public:
247 
248  };
249 };
the JsonRpcHandler namespace holds all public definitions in the JsonRpcHandler module ...
Definition: JsonRpcHandler.qm.dox.h:95