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