Qore JsonRpcHandler Module Reference  1.1
JsonRpcHandler.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* JsonRpcHandler.qm Copyright (C) 2012 - 2016 David Nichols
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 
91 namespace JsonRpcHandler {
94 
96 class JsonRpcHandler : public AbstractHttpRequestHandler {
97 
98 public:
100  const Version = "1.0";
101 
103  const InternalMethods = (
104  ("function": "help",
105  "help": "shows a list of JSON-RPC methods registered with this handler",
106  "text": "help",
107  "logopt": 2
108  ),
109  ("function": "listMethods",
110  "help": "lists JSON-RPC method names registered with this handler",
111  "text": "system.listMethods",
112  "logopt": 2
113  ),
114  ("function": "system_describe",
115  "help": "returns the service description object as per the JSON-RPC 1.1 spec",
116  "text": "system.describe",
117  "logopt": 2
118  ));
119 
121  private :
122  list methods = ();
123  hash mi;
124  int loglevel;
125 
126  // if True then verbose exception info will be logged
127  bool debug;
128 
129  // prefix to add to derived methods with GET requests if no "." characters are in the path
130  *string get_prefix;
131 
132  // a closure/call reference to get the log message and/or process arguments in incoming requests
133  *code getLogMessage;
134 
135  // a closure/call reference for logging (when set this is used instead of the HTTP server's logfunc for logging)
136  *code log;
137 
138 public:
140 
142 
157  constructor(HttpServer::AbstractAuthenticator n_auth, list n_methods, *code n_getLogMessage, bool n_dbg = False, *string n_get_prefix, *code n_log);
158 
159 
161 
168  addMethod(string name, code func, string text, string help, any logopt, any cmark);
169 
170 
172  setDebug(bool dbg = True);
173 
174 
176  bool getDebug();
177 
178 
180  // don't reimplement this method; fix/enhance it in the module
181  final private addMethodInternal(hash h);
182 
183 
184  private hash help();
185 
186 
187  private hash system_describe();
188 
189 
190  private list listMethods();
191 
192 
193  private log(hash cx, string str);
194 
195 
196  // don't reimplement this method; fix/enhance it in the module
197  final private hash callMethod(hash cx, any params);
198 
199 
200  // method called by HttpServer to handle a request
201  // don't reimplement this method; fix/enhance it in the module
202  final hash handleRequest(hash cx, hash hdr, *data body);
203 
204  };
205 };
the JsonRpcHandler namespace holds all public definitions in the JsonRpcHandler module ...
Definition: JsonRpcHandler.qm.dox.h:92