00001 #ifndef _XMLRPCSERVERCONNECTION_H_ 00002 #define _XMLRPCSERVERCONNECTION_H_ 00003 // 00004 // XmlRpc++ Copyright (c) 2002-2003 by Chris Morley 00005 // 00006 #if defined(_MSC_VER) 00007 # pragma warning(disable:4786) // identifier was truncated in debug info 00008 #endif 00009 00010 #ifndef MAKEDEPEND 00011 # include <string> 00012 #endif 00013 00014 #include "XmlRpcValue.h" 00015 #include "XmlRpcSource.h" 00016 00017 namespace XmlRpc { 00018 00019 00020 // The server waits for client connections and provides methods 00021 class XmlRpcServer; 00022 class XmlRpcServerMethod; 00023 00025 class XmlRpcServerConnection : public XmlRpcSource { 00026 public: 00027 // Static data 00028 static const char METHODNAME_TAG[]; 00029 static const char PARAMS_TAG[]; 00030 static const char PARAMS_ETAG[]; 00031 static const char PARAM_TAG[]; 00032 static const char PARAM_ETAG[]; 00033 00034 static const std::string SYSTEM_MULTICALL; 00035 static const std::string METHODNAME; 00036 static const std::string PARAMS; 00037 00038 static const std::string FAULTCODE; 00039 static const std::string FAULTSTRING; 00040 00042 XmlRpcServerConnection(int fd, XmlRpcServer* server, bool deleteOnClose = false); 00044 virtual ~XmlRpcServerConnection(); 00045 00046 // XmlRpcSource interface implementation 00049 virtual unsigned handleEvent(unsigned eventType); 00050 00051 protected: 00052 00053 bool readHeader(); 00054 bool readRequest(); 00055 bool writeResponse(); 00056 00057 // Parses the request, runs the method, generates the response xml. 00058 virtual void executeRequest(); 00059 00060 // Parse the methodName and parameters from the request. 00061 std::string parseRequest(XmlRpcValue& params); 00062 00063 // Execute a named method with the specified params. 00064 bool executeMethod(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result); 00065 00066 // Execute multiple calls and return the results in an array. 00067 bool executeMulticall(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result); 00068 00069 // Construct a response from the result XML. 00070 void generateResponse(std::string const& resultXml); 00071 void generateFaultResponse(std::string const& msg, int errorCode = -1); 00072 std::string generateHeader(std::string const& body); 00073 00074 00075 // The XmlRpc server that accepted this connection 00076 XmlRpcServer* _server; 00077 00078 // Possible IO states for the connection 00079 enum ServerConnectionState { READ_HEADER, READ_REQUEST, WRITE_RESPONSE }; 00080 ServerConnectionState _connectionState; 00081 00082 // Request headers 00083 std::string _header; 00084 00085 // Number of bytes expected in the request body (parsed from header) 00086 int _contentLength; 00087 00088 // Request body 00089 std::string _request; 00090 00091 // Response 00092 std::string _response; 00093 00094 // Number of bytes of the response written so far 00095 int _bytesWritten; 00096 00097 // Whether to keep the current client connection open for further requests 00098 bool _keepAlive; 00099 }; 00100 } // namespace XmlRpc 00101 00102 #endif // _XMLRPCSERVERCONNECTION_H_