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 #include <webview/page_reply.h>
25 #include <webview/error_reply.h>
26 #include <logging/logger.h>
27 
28 #include <xmlrpc-c/registry.hpp>
29 #include <cstring>
30 
31 using namespace fawkes;
32 
33 // accept up to 512KB as request
34 #define MAX_REQUEST_LENGTH (1024*512)
35 
36 /** @class XmlRpcRequestProcessor "xmlrpc_processor.h"
37  * XML-RPC web request processor.
38  * Process web requests and pass them to the XML-RPC processor.
39  * @author Tim Niemueller
40  */
41 
42 /** Constructor.
43  * @param logger logger to report problems
44  */
46 {
47  __logger = logger;
48  __xmlrpc_registry = new xmlrpc_c::registry();
49 }
50 
51 
52 /** Destructor. */
54 {
55  delete __xmlrpc_registry;
56 }
57 
58 /** Get XML-RPC registry.
59  * @return XML-RPC registry
60  */
61 xmlrpc_c::registry *
63 {
64  return __xmlrpc_registry;
65 }
66 
67 
68 WebReply *
70 {
71  if (request->method() != WebRequest::METHOD_POST) {
73  } else {
74  std::string response = "";
75  __xmlrpc_registry->processCall(request->raw_post_data(), &response);
76  //__logger->log_debug("XmlRpcRequestProcessor", "Call: %s reponse: %s",
77  // request->raw_post_data().c_str(), response.c_str());
78  return new StaticWebReply(WebReply::HTTP_OK, response);
79  }
80 }
XmlRpcRequestProcessor(fawkes::Logger *logger)
Constructor.
const std::string & raw_post_data() const
Get raw post data.
Definition: request.h:230
Fawkes library namespace.
Method method() const
Get HTTP transfer method.
Definition: request.h:77
virtual fawkes::WebReply * process_request(const fawkes::WebRequest *request)
Process a request.
Web request meta data carrier.
Definition: request.h:42
Basic web reply.
Definition: reply.h:36
xmlrpc_c::registry * registry()
Get XML-RPC registry.
Static error page reply.
Definition: error_reply.h:33
Static web reply.
Definition: reply.h:133
virtual ~XmlRpcRequestProcessor()
Destructor.
Interface for logging.
Definition: logger.h:34