xmlrpc_processor.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "xmlrpc_processor.h"
00024 #include <webview/page_reply.h>
00025 #include <webview/error_reply.h>
00026 #include <utils/logging/logger.h>
00027
00028 #include <xmlrpc-c/registry.hpp>
00029 #include <cstring>
00030
00031 using namespace fawkes;
00032
00033
00034 #define MAX_REQUEST_LENGTH (1024*512)
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 XmlRpcRequestProcessor::XmlRpcRequestProcessor(fawkes::Logger *logger)
00046 : WebRequestProcessor( true)
00047 {
00048 __logger = logger;
00049 __xmlrpc_registry = new xmlrpc_c::registry();
00050 }
00051
00052
00053
00054 XmlRpcRequestProcessor::~XmlRpcRequestProcessor()
00055 {
00056 delete __xmlrpc_registry;
00057 }
00058
00059
00060
00061
00062 xmlrpc_c::registry *
00063 XmlRpcRequestProcessor::registry()
00064 {
00065 return __xmlrpc_registry;
00066 }
00067
00068
00069 WebReply *
00070 XmlRpcRequestProcessor::process_request(const char *url,
00071 const char *method,
00072 const char *version,
00073 const char *upload_data,
00074 size_t *upload_data_size,
00075 void **session_data)
00076 {
00077 if ( *session_data == NULL ) {
00078 std::string *c = new std::string(upload_data);
00079 *upload_data_size = 0;
00080 *session_data = c;
00081 return NULL;
00082 } else {
00083 if (*upload_data_size > 0) {
00084 std::string *c = (std::string *)*session_data;
00085 if ( (c->length() + *upload_data_size) > MAX_REQUEST_LENGTH ) {
00086 delete c;
00087 *session_data = NULL;
00088 return new WebErrorPageReply(WebErrorPageReply::HTTP_REQUEST_ENTITY_TOO_LARGE);
00089 }
00090
00091 *c += upload_data;
00092 *upload_data_size = 0;
00093 return NULL;
00094 }
00095 }
00096
00097 std::string *call = (std::string *)*session_data;
00098 *session_data = NULL;
00099
00100 if (strcmp(method, "POST") != 0) {
00101 return new WebErrorPageReply(WebErrorPageReply::HTTP_METHOD_NOT_ALLOWED);
00102 } else {
00103 std::string response = "";
00104 __xmlrpc_registry->processCall(*call, &response);
00105
00106
00107 delete call;
00108 return new StaticWebReply(WebReply::HTTP_OK, response);
00109 }
00110 }