Go to the documentation of this file.
21 "<?xml version=\"1.0\"?>\r\n"
22 "<methodCall><methodName>";
36 return "NO_CONNECTION";
40 return "WRITE_REQUEST";
44 return "READ_RESPONSE";
53 : _connectionState(NO_CONNECTION),
63 XmlRpcUtil::log(1,
"XmlRpcClient new client: host %s, port %d.", host, port);
127 double msTime = -1.0;
138 if (
_header.find(
"HTTP/1.1 200 OK", 0, 15) != 0) {
142 XmlRpcUtil::log(1,
"XmlRpcClient::execute: method %s completed.", method);
210 XmlRpcUtil::error(
"Error in XmlRpcClient::handleEvent: could not connect to server (%s).",
300 if (params.
valid()) {
304 for (
int i=0; i<params.
size(); ++i) {
306 body += params[i].
toXml();
313 body += params.
toXml();
322 XmlRpcUtil::log(4,
"XmlRpcClient::generateRequest: header is %d bytes, content-length is %d.",
323 header.length(), body.length());
327 if (
_request.length() >
size_t(INT_MAX)) {
328 XmlRpcUtil::error(
"XmlRpcClient::generateRequest: request length (%u) exceeds maximum allowed size (%u).",
341 "POST " +
_uri +
" HTTP/1.1\r\n"
348 std::snprintf(buff,40,
":%d\r\n",
_port);
351 header +=
"Content-Type: text/xml\r\nContent-length: ";
353 std::snprintf(buff,40,
"%zu\r\n\r\n", length);
408 "header (%s) on fd %d.",
418 char *hp = (
char*)
_header.c_str();
419 char *ep = hp +
_header.length();
423 for (
char *cp = hp; (bp == 0) && (cp < ep); ++cp) {
424 if ((ep - cp > 16) && (strncasecmp(cp,
"Content-length: ", 16) == 0))
426 else if ((ep - cp > 4) && (strncmp(cp,
"\r\n\r\n", 4) == 0))
428 else if ((ep - cp > 2) && (strncmp(cp,
"\n\n", 2) == 0))
436 XmlRpcUtil::error(
"Error in XmlRpcClient::readHeader: EOF while reading header");
446 XmlRpcUtil::error(
"Error XmlRpcClient::readHeader: No Content-length specified");
453 long int clength = 0;
454 clength = strtol(lp,
nullptr, 10);
455 if ((clength <= 0) || (clength > INT_MAX)) {
456 XmlRpcUtil::error(
"Error in XmlRpcClient::readHeader: Invalid Content-length specified.");
488 if (
_response.length() >
size_t(INT_MAX)) {
489 XmlRpcUtil::error(
"XmlRpcClient::readResponse: response length (%u) exceeds the maximum allowed size (%u).",
498 XmlRpcUtil::error(
"Error in XmlRpcClient::readResponse: EOF while reading response");
525 XmlRpcUtil::error(
"Error in XmlRpcClient::parseResponse: Invalid response - no methodResponse. Response:\n%s",
_response.c_str());
540 XmlRpcUtil::error(
"Error in XmlRpcClient::parseResponse: Invalid response - no param or fault tag. Response:\n%s",
_response.c_str());
546 return result.
valid();
int size() const
Return the size for string, base64, array, and struct values.
std::string toXml() const
Encode the Value in xml.
static const char * connectionStateStr(ClientConnectionState state)
@ WritableEvent
connected/data can be written without blocking
static int socket()
Creates a stream (TCP) socket. Returns -1 on failure.
virtual ~XmlRpcClient()
Destructor.
virtual std::string generateHeader(size_t length) const
bool fromXml(std::string const &valueXml, int *offset)
Decode xml. Destroys any existing value.
void setfd(int fd)
Specify the file descriptor to monitor.
bool executeNonBlock(const char *method, XmlRpcValue const ¶ms)
static void log(int level, const char *fmt,...)
Dump messages somewhere.
static const char PARAM_TAG[]
virtual unsigned handleEvent(unsigned eventType)
void setKeepOpen(bool b=true)
Specify whether the file descriptor should be kept open if it is no longer monitored.
bool execute(const char *method, XmlRpcValue const ¶ms, XmlRpcValue &result)
static const char METHODRESPONSE_TAG[]
virtual bool writeRequest()
bool executeCheckDone(XmlRpcValue &result)
ClearFlagOnExit(bool &flag)
void exit()
Exit from work routine.
@ ReadableEvent
data available to read
virtual void close()
Close the owned fd. If deleteOnClose was specified at construction, the object is deleted.
void clear()
Erase the current value.
void addSource(XmlRpcSource *source, unsigned eventMask)
virtual bool parseResponse(XmlRpcValue &result)
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 setNonBlocking(int socket)
Sets a stream (TCP) socket to perform non-blocking IO. Returns false on failure.
static const char FAULT_TAG[]
virtual bool generateRequest(const char *method, XmlRpcValue const ¶ms)
virtual bool readResponse()
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)
static void error(const char *fmt,...)
Dump error messages somewhere.
virtual bool setupConnection()
static const char REQUEST_END[]
void removeSource(XmlRpcSource *source)
int getfd() const
Return the file descriptor being monitored.
const Type & getType() const
Return the type of the value stored.
static const char REQUEST_BEGIN[]
bool getKeepOpen() const
Return whether the file descriptor should be kept open if it is no longer monitored.
static const char PARAMS_TAG[]
bool valid() const
Return true if the value has been set to something.
static bool nbWrite(int socket, const std::string &s, int *bytesSoFar)
Write text to the specified socket. Returns false on error.
virtual bool readHeader()
static std::string getErrorMsg()
Returns message corresponding to last error.
static bool nbRead(int socket, std::string &s, bool *eof)
Read text from the specified socket. Returns false on error.
static const char PARAM_ETAG[]
static const char REQUEST_END_METHODNAME[]
ClientConnectionState _connectionState
const XMLRPCPP_DECL char XMLRPC_VERSION[]
Version identifier.
static const char PARAMS_ETAG[]
@ Exception
out-of-band data has arrived
virtual void close()
Close the connection.
RPC method arguments and results are represented by Values.
static bool connect(int socket, const std::string &host, int port)
Connect a socket to a server (from a client)
XmlRpcClient(const char *host, int port, const char *uri=0)
xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas
, Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:32