Qore YamlRpcHandler Module Reference  1.2
 All Classes Namespaces Functions Variables Pages
YamlRpcHandler.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* YamlRpcHandler.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 yaml module
28 
29 // need mime definitions
30 
31 // need Util module
32 
33 // need HttpServerUtil module at a minimum in this module
34 
35 // do not use $ signs in declarations
36 
37 
99 namespace YamlRpcHandler {
102 
104 class YamlRpcHandler : public AbstractHttpRequestHandler {
105 
106 public:
108  const Version = "1.0";
109 
111  const InternalMethods = (
112  ("function": "help",
113  "help" : "shows a list of YAML-RPC methods registered with this handler",
114  "text" : "help",
115  "logopt" : 2
116  ),
117  ("function": "listMethods",
118  "help" : "lists YAML-RPC method names registered with this handler",
119  "text" : "system.listMethods",
120  "logopt" : 2
121  ),
122  ("function": "system_describe",
123  "help" : "returns a service description object, like the one specified by the JSON-RPC 1.1 spec (even though we use YAML instead of JSON)",
124  "text" : "system.describe",
125  "logopt" : 2
126  ),
127  );
128 
130  private :
131  list methods = ();
132  hash mi;
133  int loglevel;
134 
135  // if True then verbose exception info will be logged
136  bool debug;
137 
138  // prefix to add to derived methods with GET requests if no "." characters are in the path
139  *string get_prefix;
140 
141  // a closure/call reference to get the log message and/or process arguments in incoming requests
142  *code getLogMessage;
143 
144  // a closure/call reference for logging (when set this is used instead of the HTTP server's logfunc for logging)
145  *code clog;
146 
147 public:
149 
151 
165  constructor(HttpServer::AbstractAuthenticator v_auth, list v_methods, *code v_get_log_msg, bool v_dbg = False, *string v_get_prefix, *code v_log) ;
166 
167 
169 
176  addMethod(string name, code func, string text, string help, auto logopt, auto cmark);
177 
178 
180  setDebug(bool dbg = True);
181 
182 
184  bool getDebug();
185 
186 
188  static string makeResponse(auto response, int flags = YAML::None);
189 
191  static string makeErrorResponse(int code, string mess, auto err, int flags = YAML::None);
192 
194  // method called by HttpServer to handle a request
195  // don't reimplement this method; fix/enhance it in the module
196  final hash handleRequest(hash cx, hash hdr, *data body);
197 
198 
199  // don't reimplement this method; fix/enhance it in the module
200 
201 private:
202  final addMethodInternal(hash h);
203 public:
204 
205 
206 
207 private:
208  hash help();
209 public:
210 
211 
212 
213 private:
214  hash system_describe();
215 public:
216 
217 
218 
219 private:
220  list listMethods();
221 public:
222 
223 
224 
225 private:
226  log(hash cx, string str);
227 public:
228 
229 
230  // don't reimplement this method; fix/enhance it in the module
231 
232 private:
233  final hash callMethod(hash cx, auto params);
234 public:
235 
237  };
238 };
setDebug(bool dbg=True)
turns on or off debugging; when debugging is enabled more verbose error messages are reported ...
static string makeErrorResponse(int code, string mess, auto err, int flags=YAML::None)
serializes an error reponse in YAML-RPC format given the arguments
bool getDebug()
returns the current status of the debug flag
constructor(HttpServer::AbstractAuthenticator v_auth, list v_methods, *code v_get_log_msg, bool v_dbg=False, *string v_get_prefix, *code v_log)
creates the handler with the given method list
static string makeResponse(auto response, int flags=YAML::None)
serializes a reponse in YAML-RPC format given the arguments
addMethod(string name, code func, string text, string help, auto logopt, auto cmark)
adds a method to the handler dynamically
const InternalMethods
internal methods of the handler (introspection)
Definition: YamlRpcHandler.qm.dox.h:111
YamlRpcHandler class definition; to be registered as a handler in the HttpServer class.
Definition: YamlRpcHandler.qm.dox.h:104
const Version
implementation of the handler
Definition: YamlRpcHandler.qm.dox.h:108