19 "<?xml version=\"1.0\"?>\r\n" 20 "<methodCall><methodName>";
34 XmlRpcUtil::log(1,
"XmlRpcClient new client: host %s, port %d.", host, port);
103 double msTime = -1.0;
109 XmlRpcUtil::log(1,
"XmlRpcClient::execute: method %s completed.", method);
169 XmlRpcUtil::error(
"Error in XmlRpcClient::handleEvent: could not connect to server (%s).",
258 if (params.
valid()) {
262 for (
int i=0; i<params.
size(); ++i) {
264 body += params[i].
toXml();
271 body += params.
toXml();
280 XmlRpcUtil::log(4,
"XmlRpcClient::generateRequest: header is %d bytes, content-length is %d.",
281 header.length(), body.length());
285 if (_request.length() > size_t(__INT_MAX__)) {
286 XmlRpcUtil::error(
"XmlRpcClient::generateRequest: request length (%u) exceeds maximum allowed size (%u).",
287 _request.length(), __INT_MAX__);
299 "POST " +
_uri +
" HTTP/1.1\r\n" 302 header +=
"\r\nHost: ";
307 sprintf_s(buff,40,
":%d\r\n",
_port);
309 sprintf(buff,
":%d\r\n",
_port);
313 header +=
"Content-Type: text/xml\r\nContent-length: ";
316 sprintf_s(buff,40,
"%d\r\n\r\n", (
int)body.size());
318 sprintf(buff,
"%d\r\n\r\n", (
int)body.size());
321 return header + buff;
366 XmlRpcUtil::error(
"Error in XmlRpcClient::readHeader: error while reading header (%s) on fd %d.",
373 char *hp = (
char*)
_header.c_str();
374 char *ep = hp +
_header.length();
378 for (
char *cp = hp; (bp == 0) && (cp < ep); ++cp) {
379 if ((ep - cp > 16) && (strncasecmp(cp,
"Content-length: ", 16) == 0))
381 else if ((ep - cp > 4) && (strncmp(cp,
"\r\n\r\n", 4) == 0))
383 else if ((ep - cp > 2) && (strncmp(cp,
"\n\n", 2) == 0))
391 XmlRpcUtil::error(
"Error in XmlRpcClient::readHeader: EOF while reading header");
400 XmlRpcUtil::error(
"Error XmlRpcClient::readHeader: No Content-length specified");
405 long int clength = 0;
406 clength = strtol(lp, NULL, 10);
407 if ((clength <= 0) || (clength > __INT_MAX__)) {
408 XmlRpcUtil::error(
"Error in XmlRpcClient::readHeader: Invalid Content-length specified.");
433 if (
_response.length() > size_t(__INT_MAX__)) {
434 XmlRpcUtil::error(
"XmlRpcClient::readResponse: response length (%u) exceeds the maximum allowed size (%u).",
443 XmlRpcUtil::error(
"Error in XmlRpcClient::readResponse: EOF while reading response");
467 XmlRpcUtil::error(
"Error in XmlRpcClient::parseResponse: Invalid response - no methodResponse. Response:\n%s",
_response.c_str());
484 XmlRpcUtil::error(
"Error in XmlRpcClient::parseResponse: Invalid response - no param or fault tag. Response:\n%s",
_response.c_str());
493 if (
_header.rfind(
"HTTP/1.0", 0) == 0) {
499 return result.
valid();
static const char REQUEST_BEGIN[]
virtual bool generateRequest(const char *method, XmlRpcValue const ¶ms)
bool getKeepOpen() const
Return whether the file descriptor should be kept open if it is no longer monitored.
virtual bool parseResponse(XmlRpcValue &result)
RPC method arguments and results are represented by Values.
const char XMLRPC_VERSION[]
Version identifier.
connected/data can be written without blocking
static const char PARAMS_TAG[]
int size() const
Return the size for string, base64, array, and struct values.
virtual bool readHeader()
bool valid() const
Return true if the value has been set to something.
void removeSource(XmlRpcSource *source)
static const char REQUEST_END[]
void setKeepOpen(bool b=true)
Specify whether the file descriptor should be kept open if it is no longer monitored.
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.
static bool nbRead(int socket, std::string &s, bool *eof)
Read text from the specified socket. Returns false on error.
static bool connect(int socket, std::string &host, int port)
Connect a socket to a server (from a client)
Type const & getType() const
Return the type of the value stored.
void clear()
Erase the current value.
static std::string getErrorMsg()
Returns message corresponding to last error.
virtual void close()
Close the connection.
static const char PARAM_ETAG[]
static const char REQUEST_END_METHODNAME[]
int getfd() const
Return the file descriptor being monitored.
ClientConnectionState _connectionState
virtual void close()
Close the owned fd. If deleteOnClose was specified at construction, the object is deleted...
void setfd(int fd)
Specify the file descriptor to monitor.
std::string toXml() const
Encode the Value in xml.
static const char PARAMS_ETAG[]
XmlRpcClient(const char *host, int port, const char *uri=0)
virtual ~XmlRpcClient()
Destructor.
static const char PARAM_TAG[]
bool fromXml(std::string const &valueXml, int *offset)
Decode xml. Destroys any existing value.
static int socket()
Creates a stream (TCP) socket. Returns -1 on failure.
virtual std::string generateHeader(std::string const &body)
virtual unsigned handleEvent(unsigned eventType)
static bool nbWrite(int socket, std::string &s, int *bytesSoFar)
Write text to the specified socket. Returns false on error.
static const char METHODRESPONSE_TAG[]
bool execute(const char *method, XmlRpcValue const ¶ms, XmlRpcValue &result)
void addSource(XmlRpcSource *source, unsigned eventMask)
bool executeNonBlock(const char *method, XmlRpcValue const ¶ms)
void exit()
Exit from work routine.
static bool setNonBlocking(int socket)
Sets a stream (TCP) socket to perform non-blocking IO. Returns false on failure.
virtual bool setupConnection()
virtual bool readResponse()
bool executeCheckDone(XmlRpcValue &result)
virtual bool writeRequest()
static void log(int level, const char *fmt,...)
Dump messages somewhere.
ClearFlagOnExit(bool &flag)
static const char FAULT_TAG[]
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)