Fawkes API Fawkes Development Version
xmlrpc_processor.cpp
1
2/***************************************************************************
3 * xmlrpc_processor.cpp - XML-RPC processor
4 *
5 * Created: Sun Aug 30 19:39:31 2009
6 * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL file in the doc directory.
21 */
22
23#include "xmlrpc_processor.h"
24
25#include <logging/logger.h>
26#include <webview/error_reply.h>
27#include <webview/page_reply.h>
28#include <webview/request.h>
29
30#include <cstring>
31#include <xmlrpc-c/registry.hpp>
32
33using namespace fawkes;
34
35// accept up to 512KB as request
36#define MAX_REQUEST_LENGTH (1024 * 512)
37
38/** @class XmlRpcRequestProcessor "xmlrpc_processor.h"
39 * XML-RPC web request processor.
40 * Process web requests and pass them to the XML-RPC processor.
41 * @author Tim Niemueller
42 */
43
44/** Constructor.
45 * @param logger logger to report problems
46 */
48{
49 logger_ = logger;
50 xmlrpc_registry_.reset(new xmlrpc_c::registry);
51}
52
53/** Destructor. */
55{
56 xmlrpc_registry_.reset();
57}
58
59/** Get XML-RPC registry.
60 * @return XML-RPC registry
61 */
62std::shared_ptr<xmlrpc_c::registry>
64{
65 return xmlrpc_registry_;
66}
67
68/** Process request.
69 * @param request incoming request
70 * @return web reply
71 */
74{
75 if (request->method() != WebRequest::METHOD_POST) {
76 return new WebErrorPageReply(WebErrorPageReply::HTTP_METHOD_NOT_ALLOWED);
77 } else {
78 std::string response;
79 xmlrpc_registry_->processCall(request->body(), &response);
80 //logger_->log_debug("XmlRpcRequestProcessor", "Call: %s reponse: %s",
81 // request->raw_post_data().c_str(), response.c_str());
82 return new StaticWebReply(WebReply::HTTP_OK, response);
83 }
84}
fawkes::WebReply * process_request(const fawkes::WebRequest *request)
Process request.
~XmlRpcRequestProcessor()
Destructor.
XmlRpcRequestProcessor(fawkes::Logger *logger)
Constructor.
std::shared_ptr< xmlrpc_c::registry > registry()
Get XML-RPC registry.
Interface for logging.
Definition: logger.h:42
Static web reply.
Definition: reply.h:136
Static error page reply.
Definition: error_reply.h:31
Basic web reply.
Definition: reply.h:34
Web request meta data carrier.
Definition: request.h:42
Method method() const
Get HTTP transfer method.
Definition: request.h:84
const std::string & body() const
Get body of request.
Definition: request.h:325
Fawkes library namespace.