86 char *hp = (
char*)
_header.c_str();
87 char *ep = hp +
_header.length();
92 for (
char *cp = hp; (bp == 0) && (cp < ep); ++cp) {
93 if ((ep - cp > 16) && (strncasecmp(cp,
"Content-length: ", 16) == 0))
95 else if ((ep - cp > 12) && (strncasecmp(cp,
"Connection: ", 12) == 0))
97 else if ((ep - cp > 4) && (strncmp(cp,
"\r\n\r\n", 4) == 0))
99 else if ((ep - cp > 2) && (strncmp(cp,
"\n\n", 2) == 0))
109 XmlRpcUtil::error(
"XmlRpcServerConnection::readHeader: EOF while reading header");
118 XmlRpcUtil::error(
"XmlRpcServerConnection::readHeader: No Content-length specified");
135 if (
_header.find(
"HTTP/1.0") != std::string::npos) {
136 if (kp == 0 || strncasecmp(kp,
"keep-alive", 10) != 0)
139 if (kp != 0 && strncasecmp(kp,
"close", 5) == 0)
164 XmlRpcUtil::error(
"XmlRpcServerConnection::readRequest: EOF while reading request");
217 XmlRpcUtil::log(2,
"XmlRpcServerConnection::executeRequest: server calling method '%s'",
229 XmlRpcUtil::log(2,
"XmlRpcServerConnection::executeRequest: fault %s.",
264 if ( ! method)
return false;
266 method->
execute(params, result);
269 if ( ! result.
valid())
270 result = std::string();
286 int nc = params[0].
size();
289 for (
int i=0; i<nc; ++i) {
292 ! params[0][i].hasMember(
PARAMS)) {
295 ": Invalid argument (expected a struct with members methodName and params)";
299 const std::string& methodName = params[0][i][
METHODNAME];
305 if ( !
executeMethod(methodName, methodParams, resultValue[0]) &&
309 result[i][
FAULTSTRING] = methodName +
": unknown method name";
312 result[i] = resultValue;
328 const char RESPONSE_1[] =
329 "<?xml version=\"1.0\"?>\r\n" 330 "<methodResponse><params><param>\r\n\t";
331 const char RESPONSE_2[] =
332 "\r\n</param></params></methodResponse>\r\n";
334 std::string body = RESPONSE_1 + resultXml + RESPONSE_2;
346 "HTTP/1.1 200 OK\r\n" 350 "Content-Type: text/xml\r\n" 355 sprintf_s(buffLen,40,
"%d\r\n\r\n", (
int)body.size());
357 sprintf(buffLen,
"%d\r\n\r\n", (
int)body.size());
360 return header + buffLen;
367 const char RESPONSE_1[] =
368 "<?xml version=\"1.0\"?>\r\n" 369 "<methodResponse><fault>\r\n\t";
370 const char RESPONSE_2[] =
371 "\r\n</fault></methodResponse>\r\n";
376 std::string body = RESPONSE_1 + faultStruct.
toXml() + RESPONSE_2;
const std::string & getMessage() const
Return the error message.
virtual void execute(XmlRpcValue ¶ms, XmlRpcValue &result)=0
Execute the method. Subclasses must provide a definition for this method.
virtual void executeRequest()
RPC method arguments and results are represented by Values.
const char XMLRPC_VERSION[]
Version identifier.
connected/data can be written without blocking
ServerConnectionState _connectionState
static const std::string PARAMS
static const std::string SYSTEM_MULTICALL
int size() const
Return the size for string, base64, array, and struct values.
static std::string parseTag(const char *tag, std::string const &xml, int *offset)
Returns contents between <tag> and </tag>, updates offset to char after </tag>
XmlRpcServerMethod * findMethod(const std::string &name) const
Look up a method by name.
bool valid() const
Return true if the value has been set to something.
static const char PARAM_TAG[]
static void error(const char *fmt,...)
Dump error messages somewhere.
static bool findTag(const char *tag, std::string const &xml, int *offset)
Returns true if the tag is found and updates offset to the char after the tag.
int getCode() const
Return the error code.
static bool nbRead(int socket, std::string &s, bool *eof)
Read text from the specified socket. Returns false on error.
std::string generateHeader(std::string const &body)
static const char PARAMS_TAG[]
bool executeMulticall(const std::string &methodName, XmlRpcValue ¶ms, XmlRpcValue &result)
Type const & getType() const
Return the type of the value stored.
bool executeMethod(const std::string &methodName, XmlRpcValue ¶ms, XmlRpcValue &result)
static std::string getErrorMsg()
Returns message corresponding to last error.
static bool nbWrite(int socket, const std::string &s, int *bytesSoFar)
Write text to the specified socket. Returns false on error.
int getfd() const
Return the file descriptor being monitored.
virtual ~XmlRpcServerConnection()
Destructor.
static const char METHODNAME_TAG[]
Abstract class representing a single RPC method.
static const std::string FAULTCODE
std::string toXml() const
Encode the Value in xml.
virtual void removeConnection(XmlRpcServerConnection *)
Remove a connection from the dispatcher.
void setSize(int size)
Specify the size for array values. Array values will grow beyond this size if needed.
static const std::string FAULTSTRING
An RPC source represents a file descriptor to monitor.
static const char PARAM_ETAG[]
A class to handle XML RPC requests.
static const std::string METHODNAME
static const char PARAMS_ETAG[]
void generateFaultResponse(std::string const &msg, int errorCode=-1)
void generateResponse(std::string const &resultXml)
virtual unsigned handleEvent(unsigned eventType)
XmlRpcServerConnection(int fd, XmlRpcServer *server, bool deleteOnClose=false)
Constructor.
std::string parseRequest(XmlRpcValue ¶ms)
static void log(int level, const char *fmt,...)
Dump messages somewhere.
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)