Qore YamlRpcHandler Module Reference  1.2
YamlRpcHandler.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* YamlRpcHandler.qm Copyright (C) 2012 - 2015 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 
38 /* Version History
39  * 2014-03-05 v1.2: David Nichols <david@qore.org>: minor error logging updates, updated minimum qore version to 0.8.7 for get_ex_pos()
40  * 2013-09-24 v1.1: David Nichols <david@qore.org>: added optional log closure to constructor
41  * 2012-05-24 v1.0: David Nichols <david@qore.org>: updated to a user module
42 */
43 
85 namespace YamlRpcHandler {
88 
90 class YamlRpcHandler : public AbstractHttpRequestHandler {
91 
92 public:
94  const Version = "1.0";
95 
97  const InternalMethods = (
98  ("function": "help",
99  "help" : "shows a list of YAML-RPC methods registered with this handler",
100  "text" : "help",
101  "logopt" : 2
102  ),
103  ("function": "listMethods",
104  "help" : "lists YAML-RPC method names registered with this handler",
105  "text" : "system.listMethods",
106  "logopt" : 2
107  ),
108  ("function": "system_describe",
109  "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)",
110  "text" : "system.describe",
111  "logopt" : 2
112  ),
113  );
114 
116  private :
117  list methods = ();
118  hash mi;
119  int loglevel;
120 
121  // if True then verbose exception info will be logged
122  bool debug;
123 
124  // prefix to add to derived methods with GET requests if no "." characters are in the path
125  __7_ string get_prefix;
126 
127  // a closure/call reference to get the log message and/or process arguments in incoming requests
128  __7_ code getLogMessage;
129 
130  // a closure/call reference for logging (when set this is used instead of the HTTP server's logfunc for logging)
131  __7_ code clog;
132 
133 public:
135 
137 
151  constructor(HttpServer::AbstractAuthenticator v_auth, list v_methods, __7_ code v_get_log_msg, bool v_dbg = False, __7_ string v_get_prefix, __7_ code v_log);
152 
153 
155 
162  addMethod(string name, code func, string text, string help, any logopt, any cmark);
163 
164 
166  setDebug(bool dbg = True);
167 
168 
170  bool getDebug();
171 
172 
174  static string makeResponse(any response, int flags = YAML::None);
175 
177  static string makeErrorResponse(int code, string mess, any err, int flags = YAML::None);
178 
180  // method called by HttpServer to handle a request
181  // don't reimplement this method; fix/enhance it in the module
182  final hash handleRequest(hash cx, hash hdr, __7_ data body);
183 
184 
185  // don't reimplement this method; fix/enhance it in the module
186  final private addMethodInternal(hash h);
187 
188 
189  private hash help();
190 
191 
192  private hash system_describe();
193 
194 
195  private list listMethods();
196 
197 
198  private log(hash cx, string str);
199 
200 
201  // don't reimplement this method; fix/enhance it in the module
202  final private hash callMethod(hash cx, any params);
203 
205  };
206 };
the YamlRpcHandler namespace holds all public definitions in the YamlRpcHandler module ...
Definition: YamlRpcHandler.qm.dox.h:86