Qore JsonRpcHandler Module Reference  1.1
 All Classes Namespaces Functions Variables Pages
JsonRpcHandler.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* JsonRpcHandler.qm Copyright 2012 - 2013 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 HttpServer definitions
32 
33 
34 /* Version History
35  * 2012-06-01 v1.0: David Nichols <david@qore.org>: updated to a user module
36  * 2013-09-24 v1.1: David Nichols <david@qore.org>: added optional log closure to constructor
37 */
38 
78 namespace JsonRpcHandler {
81 
83 class JsonRpcHandler : public AbstractHttpRequestHandler {
84 
85 public:
87  const Version = "1.0";
88 
90  const InternalMethods = (
91  ("function": "help",
92  "help": "shows a list of JSON-RPC methods registered with this handler",
93  "text": "help",
94  "logopt": 2
95  ),
96  ("function": "listMethods",
97  "help": "lists JSON-RPC method names registered with this handler",
98  "text": "system.listMethods",
99  "logopt": 2
100  ),
101  ("function": "system_describe",
102  "help": "returns the service description object as per the JSON-RPC 1.1 spec",
103  "text": "system.describe",
104  "logopt": 2
105  ));
106 
108  private :
109  list methods = ();
110  hash mi;
111  int loglevel;
112 
113  // if True then verbose exception info will be logged
114  bool debug;
115 
116  // prefix to add to derived methods with GET requests if no "." characters are in the path
117  *string get_prefix;
118 
119  // a closure/call reference to get the log message and/or process arguments in incoming requests
120  *code getLogMessage;
121 
122  // a closure/call reference for logging (when set this is used instead of the HTTP server's logfunc for logging)
123  *code log;
124 
125 public:
127 
129 
146  constructor(AbstractAuthenticator auth, list methods, *code getLogMessage, bool dbg = False, *string get_prefix, *code log);
147 
148 
150 
157  addMethod(string name, code func, string text, string help, any logopt, any cmark);
158 
159 
161  setDebug(bool dbg = True);
162 
163 
165  bool getDebug();
166 
167 
169  // don't reimplement this method; fix/enhance it in the module
170 
171 private:
172  final addMethodInternal(hash h);
173 public:
174 
175 
176 
177 private:
178  hash help();
179 public:
180 
181 
182 
183 private:
184  hash system_describe();
185 public:
186 
187 
188 
189 private:
190  list listMethods();
191 public:
192 
193 
194 
195 private:
196  log(hash cx, string str);
197 public:
198 
199 
200  // don't reimplement this method; fix/enhance it in the module
201 
202 private:
203  final hash callMethod(hash cx, any params);
204 public:
205 
206 
207  // method called by HttpServer to handle a request
208  // don't reimplement this method; fix/enhance it in the module
209  final hash handleRequest(hash cx, hash hdr, *data body);
210 
211  };
212 };
213 
bool getDebug()
returns the current status of the debug flag
const Version
implementation of the handler
Definition: JsonRpcHandler.qm.dox.h:87
setDebug(bool dbg=True)
turns on or off debugging; when debugging is enabled more verbose error messages are reported ...
JsonRpcHandler class definition; to be registered as a handler in the HttpServer class.
Definition: JsonRpcHandler.qm.dox.h:83
const InternalMethods
internal methods of the handler (introspection)
Definition: JsonRpcHandler.qm.dox.h:90
final addMethodInternal(hash h)
nodoc
constructor(AbstractAuthenticator auth, list methods, *code getLogMessage, bool dbg=False, *string get_prefix, *code log)
creates the handler with the given method list
addMethod(string name, code func, string text, string help, any logopt, any cmark)
adds a method to the handler dynamically