OverSim
XmlRpcServer.h
Go to the documentation of this file.
1 
2 #ifndef _XMLRPCSERVER_H_
3 #define _XMLRPCSERVER_H_
4 //
5 // XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
6 //
7 
13 #if defined(_MSC_VER)
14 # pragma warning(disable:4786) // identifier was truncated in debug info
15 #endif
16 
17 #ifndef MAKEDEPEND
18 # include <map>
19 # include <string>
20 #include <cstdio>
21 #endif
22 
23 #include "XmlRpcDispatch.h"
24 #include "XmlRpcSource.h"
25 
26 namespace XmlRpc {
27 
28 
29  // An abstract class supporting XML RPC methods
30  class XmlRpcServerMethod;
31 
32  // Class representing connections to specific clients
33  class XmlRpcServerConnection;
34 
35  // Class representing argument and result values
36  class XmlRpcValue;
37 
38 
40  class XmlRpcServer : public XmlRpcSource {
41  public:
43  XmlRpcServer();
45  virtual ~XmlRpcServer();
46 
48  void enableIntrospection(bool enabled=true);
49 
51  void addMethod(XmlRpcServerMethod* method);
52 
54  void removeMethod(XmlRpcServerMethod* method);
55 
57  void removeMethod(const std::string& methodName);
58 
60  XmlRpcServerMethod* findMethod(const std::string& name) const;
61 
66  bool bindAndListen(int port, int backlog = 5);
67 
69  int getPort(void) const;
70 
72  void work(double msTime);
73 
75  void exit();
76 
78  void shutdown();
79 
81  void listMethods(XmlRpcValue& result);
82 
83 
86  virtual std::string executeRequest(std::string const& request);
87 
88 
89  // XmlRpcSource interface implementation
90 
92  virtual unsigned handleEvent(unsigned eventType);
93 
96 
97  protected:
98 
99  // Static data
100  static const char METHODNAME_TAG[];
101  static const char PARAMS_TAG[];
102  static const char PARAMS_ETAG[];
103  static const char PARAM_TAG[];
104  static const char PARAM_ETAG[];
105 
106  static const std::string SYSTEM_MULTICALL;
107  static const std::string METHODNAME;
108  static const std::string PARAMS;
109 
110  static const std::string FAULTCODE;
111  static const std::string FAULTSTRING;
112 
113 
115  virtual void acceptConnection();
116 
119  virtual XmlRpcServerConnection* createConnection(int socket);
120 
122  virtual void dispatchConnection(XmlRpcServerConnection* sc);
123 
124 
127  std::string parseRequest(std::string const& request, XmlRpcValue& params);
128 
130  bool executeMethod(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result);
131 
134  bool executeMulticall(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result);
135 
137  std::string generateResponse(std::string const& resultXml);
138 
140  std::string generateFaultResponse(std::string const& msg, int errorCode = -1);
141 
143  std::string generateHeader(std::string const& body);
144 
145 
146 
149 
152 
154  typedef std::map< std::string, XmlRpcServerMethod* > MethodMap;
155 
158 
161 
164 
165  };
166 } // namespace XmlRpc
167 
168 #endif //_XMLRPCSERVER_H_