1#ifndef _XMLRPCSERVERCONNECTION_H_ 2#define _XMLRPCSERVERCONNECTION_H_ 3// 4// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley 5// 6#if defined(_MSC_VER) 7# pragma warning(disable:4786) // identifier was truncated in debug info 8#endif 9 10#ifndef MAKEDEPEND 11# include <string> 12#endif 13 14#include "XmlRpcValue.h" 15#include "XmlRpcSource.h" 16 17namespace XmlRpc { 18 19 20 // The server waits for client connections and provides methods 21 class XmlRpcServer; 22 class XmlRpcServerMethod; 23 24 //! A class to handle XML RPC requests from a particular client 25 class XmlRpcServerConnection : public XmlRpcSource { 26 public: 27 // Static data 28 static const char METHODNAME_TAG[]; 29 static const char PARAMS_TAG[]; 30 static const char PARAMS_ETAG[]; 31 static const char PARAM_TAG[]; 32 static const char PARAM_ETAG[]; 33 34 static const std::string SYSTEM_MULTICALL; 35 static const std::string METHODNAME; 36 static const std::string PARAMS; 37 38 static const std::string FAULTCODE; 39 static const std::string FAULTSTRING; 40 41 //! Constructor 42 XmlRpcServerConnection(int fd, XmlRpcServer* server, bool deleteOnClose = false); 43 //! Destructor 44 virtual ~XmlRpcServerConnection(); 45 46 // XmlRpcSource interface implementation 47 //! Handle IO on the client connection socket. 48 //! @param eventType Type of IO event that occurred. @see XmlRpcDispatch::EventType. 49 virtual unsigned handleEvent(unsigned eventType); 50 51 protected: 52 53 bool readHeader(); 54 bool readRequest(); 55 bool writeResponse(); 56 57 // Parses the request, runs the method, generates the response xml. 58 virtual void executeRequest(); 59 60 // Parse the methodName and parameters from the request. 61 std::string parseRequest(XmlRpcValue& params); 62 63 // Execute a named method with the specified params. 64 bool executeMethod(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result); 65 66 // Execute multiple calls and return the results in an array. 67 bool executeMulticall(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result); 68 69 // Construct a response from the result XML. 70 void generateResponse(std::string const& resultXml); 71 void generateFaultResponse(std::string const& msg, int errorCode = -1); 72 std::string generateHeader(std::string const& body); 73 74 75 // The XmlRpc server that accepted this connection 76 XmlRpcServer* _server; 77 78 // Possible IO states for the connection 79 enum ServerConnectionState { READ_HEADER, READ_REQUEST, WRITE_RESPONSE }; 80 ServerConnectionState _connectionState; 81 82 // Request headers 83 std::string _header; 84 85 // Number of bytes expected in the request body (parsed from header) 86 int _contentLength; 87 88 // Request body 89 std::string _request; 90 91 // Response 92 std::string _response; 93 94 // Number of bytes of the response written so far 95 int _bytesWritten; 96 97 // Whether to keep the current client connection open for further requests 98 bool _keepAlive; 99 }; 100} // namespace XmlRpc 101 102#endif // _XMLRPCSERVERCONNECTION_H_ 103