Qore YamlRpcHandler Module Reference  1.4
YamlRpcHandler.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* YamlRpcHandler.qm Copyright (C) 2012 - 2019 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 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 
100 namespace YamlRpcHandler {
103 
105 class YamlRpcHandler : public AbstractHttpRequestHandler {
106 
107 public:
109  const Version = "1.0";
110 
112  const InternalMethods = (
113  {
114  "function": "help",
115  "help" : "shows a list of YAML-RPC methods registered with this handler",
116  "text" : "help",
117  "logopt" : 2,
118  },
119  {
120  "function": "listMethods",
121  "help" : "lists YAML-RPC method names registered with this handler",
122  "text" : "system.listMethods",
123  "logopt" : 2,
124  },
125  {
126  "function": "system_describe",
127  "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)",
128  "text" : "system.describe",
129  "logopt" : 2,
130  },
131  );
132 
134 protected:
135  list methods = ();
136  hash mi;
137  int loglevel;
138 
139  // if True then verbose exception info will be logged
140  bool debug;
141 
142  // prefix to add to derived methods with GET requests if no "." characters are in the path
143  *string get_prefix;
144 
145  // a closure/call reference to get the log message and/or process arguments in incoming requests
146  *code getLogMessage;
147 
148  // a closure/call reference for logging (when set this is used instead of the HTTP server's logfunc for logging)
149  *code clog;
150 
151 public:
153 
155 
169  constructor(HttpServer::AbstractAuthenticator v_auth, list v_methods, *code v_get_log_msg, bool v_dbg = False, *string v_get_prefix, *code v_log) ;
170 
171 
173 
180  addMethod(string name, code func, string text, string help, auto logopt, auto cmark);
181 
182 
184  setDebug(bool dbg = True);
185 
186 
188  bool getDebug();
189 
190 
192  static string makeResponse(auto response, int flags = YAML::None);
193 
195  static string makeErrorResponse(int code, string mess, auto err, int flags = YAML::None);
196 
198  // method called by HttpServer to handle a request
199  // don't reimplement this method; fix/enhance it in the module
200  final hash handleRequest(hash cx, hash hdr, *data body);
201 
202 
203  // don't reimplement this method; fix/enhance it in the module
204 protected:
205  final addMethodInternal(hash h);
206 public:
207 
208 
209 protected:
210  hash help();
211 public:
212 
213 
214 protected:
215  hash system_describe();
216 public:
217 
218 
219 protected:
220  softlist<string> listMethods();
221 public:
222 
223 
224 protected:
225  log(hash cx, string str);
226 public:
227 
228 
229  // don't reimplement this method; fix/enhance it in the module
230 protected:
231  final hash callMethod(hash cx, auto params);
232 public:
233 
235  };
236 };
YamlRpcHandler::YamlRpcHandler::makeErrorResponse
static string makeErrorResponse(int code, string mess, auto err, int flags=YAML::None)
serializes an error reponse in YAML-RPC format given the arguments
YamlRpcHandler::YamlRpcHandler::makeResponse
static string makeResponse(auto response, int flags=YAML::None)
serializes a reponse in YAML-RPC format given the arguments
YamlRpcHandler::YamlRpcHandler::getDebug
bool getDebug()
returns the current status of the debug flag
YamlRpcHandler::YamlRpcHandler::constructor
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
YamlRpcHandler::YamlRpcHandler::setDebug
setDebug(bool dbg=True)
turns on or off debugging; when debugging is enabled more verbose error messages are reported
YamlRpcHandler
the YamlRpcHandler namespace holds all public definitions in the YamlRpcHandler module
Definition: YamlRpcHandler.qm.dox.h:101
YamlRpcHandler::YamlRpcHandler::addMethod
addMethod(string name, code func, string text, string help, auto logopt, auto cmark)
adds a method to the handler dynamically