00001 #ifndef _XMLRPCSERVERCONNECTION_H_
00002 #define _XMLRPCSERVERCONNECTION_H_
00003
00004
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
00021 class XmlRpcServer;
00022 class XmlRpcServerMethod;
00023
00025 class XmlRpcServerConnection : public XmlRpcSource {
00026 public:
00027
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
00049
00050
00051 protected:
00052
00053 bool readHeader();
00054 bool readRequest();
00055 bool writeResponse();
00056
00057
00058 virtual void executeRequest();
00059
00060
00061 std::string parseRequest(XmlRpcValue& params);
00062
00063
00064 bool executeMethod(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result);
00065
00066
00067 bool executeMulticall(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result);
00068
00069
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
00076 XmlRpcServer* _server;
00077
00078
00079 enum ServerConnectionState { READ_HEADER, READ_REQUEST, WRITE_RESPONSE };
00080 ServerConnectionState _connectionState;
00081
00082
00083 std::string _header;
00084
00085
00086 int _contentLength;
00087
00088
00089 std::string _request;
00090
00091
00092 std::string _response;
00093
00094
00095 int _bytesWritten;
00096
00097
00098 bool _keepAlive;
00099 };
00100 }
00101
00102 #endif // _XMLRPCSERVERCONNECTION_H_