This commit is contained in:
Ivan
2022-04-05 11:42:28 +03:00
commit 6dc0eb0fcf
5565 changed files with 1200500 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
// this file modified by Morgan Quigley on 22 April 2008 to add
// a std::exception-derived class
#ifndef _XMLRPC_H_
#define _XMLRPC_H_
//
// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
//
#if defined(_MSC_VER)
# pragma warning(disable:4786) // identifier was truncated in debug info
#endif
#ifndef MAKEDEPEND
# include <string>
#endif
#include "xmlrpcpp/XmlRpcClient.h"
#include "xmlrpcpp/XmlRpcException.h"
#include "xmlrpcpp/XmlRpcServer.h"
#include "xmlrpcpp/XmlRpcServerMethod.h"
#include "xmlrpcpp/XmlRpcValue.h"
#include "xmlrpcpp/XmlRpcUtil.h"
#include <stdexcept>
namespace XmlRpc {
//! An interface allowing custom handling of error message reporting.
class XmlRpcErrorHandler {
public:
virtual ~XmlRpcErrorHandler() { }
//! Returns a pointer to the currently installed error handling object.
static XmlRpcErrorHandler* getErrorHandler()
{ return _errorHandler; }
//! Specifies the error handler.
static void setErrorHandler(XmlRpcErrorHandler* eh)
{ _errorHandler = eh; }
//! Report an error. Custom error handlers should define this method.
virtual void error(const char* msg) = 0;
protected:
static XmlRpcErrorHandler* _errorHandler;
};
//! An interface allowing custom handling of informational message reporting.
class XmlRpcLogHandler {
public:
virtual ~XmlRpcLogHandler() { }
//! Returns a pointer to the currently installed message reporting object.
static XmlRpcLogHandler* getLogHandler()
{ return _logHandler; }
//! Specifies the message handler.
static void setLogHandler(XmlRpcLogHandler* lh)
{ _logHandler = lh; }
//! Returns the level of verbosity of informational messages. 0 is no output, 5 is very verbose.
static int getVerbosity()
{ return _verbosity; }
//! Specify the level of verbosity of informational messages. 0 is no output, 5 is very verbose.
static void setVerbosity(int v)
{ _verbosity = v; }
//! Output a message. Custom error handlers should define this method.
virtual void log(int level, const char* msg) = 0;
protected:
static XmlRpcLogHandler* _logHandler;
static int _verbosity;
};
//! Returns log message verbosity. This is short for XmlRpcLogHandler::getVerbosity()
int getVerbosity();
//! Sets log message verbosity. This is short for XmlRpcLogHandler::setVerbosity(level)
void setVerbosity(int level);
//! Version identifier
extern const char XMLRPC_VERSION[];
} // namespace XmlRpc
#endif // _XMLRPC_H_

View File

@@ -0,0 +1,133 @@
#ifndef _XMLRPCCLIENT_H_
#define _XMLRPCCLIENT_H_
//
// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
//
#if defined(_MSC_VER)
# pragma warning(disable:4786) // identifier was truncated in debug info
#endif
#ifndef MAKEDEPEND
# include <string>
#endif
#include "xmlrpcpp/XmlRpcDispatch.h"
#include "xmlrpcpp/XmlRpcSource.h"
#include "xmlrpcpp/XmlRpcDecl.h"
namespace XmlRpc {
// Arguments and results are represented by XmlRpcValues
class XmlRpcValue;
//! A class to send XML RPC requests to a server and return the results.
class XMLRPCPP_DECL XmlRpcClient : public XmlRpcSource {
public:
// Static data
static const char REQUEST_BEGIN[];
static const char REQUEST_END_METHODNAME[];
static const char PARAMS_TAG[];
static const char PARAMS_ETAG[];
static const char PARAM_TAG[];
static const char PARAM_ETAG[];
static const char REQUEST_END[];
// Result tags
static const char METHODRESPONSE_TAG[];
static const char FAULT_TAG[];
//! Construct a client to connect to the server at the specified host:port address
//! @param host The name of the remote machine hosting the server
//! @param port The port on the remote machine where the server is listening
//! @param uri An optional string to be sent as the URI in the HTTP GET header
XmlRpcClient(const char* host, int port, const char* uri=0);
//! Destructor
virtual ~XmlRpcClient();
//! Execute the named procedure on the remote server.
//! @param method The name of the remote procedure to execute
//! @param params An array of the arguments for the method
//! @param result The result value to be returned to the client
//! @return true if the request was sent and a result received
//! (although the result might be a fault).
//!
//! Currently this is a synchronous (blocking) implementation (execute
//! does not return until it receives a response or an error). Use isFault()
//! to determine whether the result is a fault response.
bool execute(const char* method, XmlRpcValue const& params, XmlRpcValue& result);
bool executeNonBlock(const char* method, XmlRpcValue const& params);
bool executeCheckDone(XmlRpcValue& result);
//! Returns true if the result of the last execute() was a fault response.
bool isFault() const { return _isFault; }
// XmlRpcSource interface implementation
//! Close the connection
virtual void close();
//! Handle server responses. Called by the event dispatcher during execute.
//! @param eventType The type of event that occurred.
//! @see XmlRpcDispatch::EventType
virtual unsigned handleEvent(unsigned eventType);
protected:
// Execution processing helpers
virtual bool doConnect();
virtual bool setupConnection();
virtual bool generateRequest(const char* method, XmlRpcValue const& params);
virtual std::string generateHeader(std::string const& body);
virtual bool writeRequest();
virtual bool readHeader();
virtual bool readResponse();
virtual bool parseResponse(XmlRpcValue& result);
// Possible IO states for the connection
enum ClientConnectionState { NO_CONNECTION, CONNECTING, WRITE_REQUEST, READ_HEADER, READ_RESPONSE, IDLE };
ClientConnectionState _connectionState;
// Server location
std::string _host;
std::string _uri;
int _port;
public:
const std::string &getHost() { return _host; }
const std::string &getUri() { return _uri; }
int getPort() const { return _port; }
// The xml-encoded request, http header of response, and response xml
std::string _request;
std::string _header;
std::string _response;
// Number of times the client has attempted to send the request
int _sendAttempts;
// Number of bytes of the request that have been written to the socket so far
int _bytesWritten;
// True if we are currently executing a request. If you want to multithread,
// each thread should have its own client.
bool _executing;
// True if the server closed the connection
bool _eof;
// True if a fault response was returned by the server
bool _isFault;
// Number of bytes expected in the response body (parsed from response header)
int _contentLength;
// Event dispatcher
XmlRpcDispatch _disp;
}; // class XmlRpcClient
} // namespace XmlRpc
#endif // _XMLRPCCLIENT_H_

View File

@@ -0,0 +1,55 @@
/*********************************************************************
*
* Software License Agreement (BSD License)
*
* Copyright (c) 2009, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Willow Garage nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*********************************************************************/
/*
* Cross platform macros.
*
*/
#ifndef XMLRPCPP_DECL_H_INCLUDED
#define XMLRPCPP_DECL_H_INCLUDED
#include <ros/macros.h>
#ifdef ROS_BUILD_SHARED_LIBS // ros is being built around shared libraries
#ifdef xmlrpcpp_EXPORTS // we are building a shared lib/dll
#define XMLRPCPP_DECL ROS_HELPER_EXPORT
#else // we are using shared lib/dll
#define XMLRPCPP_DECL ROS_HELPER_IMPORT
#endif
#else // ros is being built around static libraries
#define XMLRPCPP_DECL
#endif
#endif /* XMLRPCPP_DECL_H_INCLUDED */

View File

@@ -0,0 +1,89 @@
#ifndef _XMLRPCDISPATCH_H_
#define _XMLRPCDISPATCH_H_
//
// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
//
#if defined(_MSC_VER)
# pragma warning(disable:4786) // identifier was truncated in debug info
#endif
#include "xmlrpcpp/XmlRpcDecl.h"
#ifndef MAKEDEPEND
# include <list>
#endif
namespace XmlRpc {
// An RPC source represents a file descriptor to monitor
class XmlRpcSource;
//! An object which monitors file descriptors for events and performs
//! callbacks when interesting events happen.
class XMLRPCPP_DECL XmlRpcDispatch {
public:
//! Constructor
XmlRpcDispatch();
~XmlRpcDispatch();
//! Values indicating the type of events a source is interested in
enum EventType {
ReadableEvent = 1, //!< data available to read
WritableEvent = 2, //!< connected/data can be written without blocking
Exception = 4 //!< uh oh
};
//! Monitor this source for the event types specified by the event mask
//! and call its event handler when any of the events occur.
//! @param source The source to monitor
//! @param eventMask Which event types to watch for. \see EventType
void addSource(XmlRpcSource* source, unsigned eventMask);
//! Stop monitoring this source.
//! @param source The source to stop monitoring
void removeSource(XmlRpcSource* source);
//! Modify the types of events to watch for on this source
void setSourceEvents(XmlRpcSource* source, unsigned eventMask);
//! Watch current set of sources and process events for the specified
//! duration (in ms, -1 implies wait forever, or until exit is called)
void work(double msTime);
//! Exit from work routine
void exit();
//! Clear all sources from the monitored sources list. Sources are closed.
void clear();
// helper returning current steady/monotonic time
double getTime();
// A source to monitor and what to monitor it for
struct MonitoredSource {
MonitoredSource(XmlRpcSource* src, unsigned mask) : _src(src), _mask(mask) {}
XmlRpcSource* getSource() const { return _src; }
unsigned& getMask() { return _mask; }
XmlRpcSource* _src;
unsigned _mask;
};
// A list of sources to monitor
typedef std::list< MonitoredSource > SourceList;
// Sources being monitored
SourceList _sources;
protected:
// When work should stop (-1 implies wait forever, or until exit is called)
double _endTime;
bool _doClear;
bool _inWork;
};
} // namespace XmlRpc
#endif // _XMLRPCDISPATCH_H_

View File

@@ -0,0 +1,44 @@
#ifndef _XMLRPCEXCEPTION_H_
#define _XMLRPCEXCEPTION_H_
//
// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
//
#if defined(_MSC_VER)
# pragma warning(disable:4786) // identifier was truncated in debug info
#endif
#ifndef MAKEDEPEND
# include <string>
#endif
#include "xmlrpcpp/XmlRpcDecl.h"
namespace XmlRpc {
//! A class representing an error.
//! If server methods throw this exception, a fault response is returned
//! to the client.
class XMLRPCPP_DECL XmlRpcException {
public:
//! Constructor
//! @param message A descriptive error message
//! @param code An integer error code
XmlRpcException(const std::string& message, int code=-1) :
_message(message), _code(code) {}
//! Return the error message.
const std::string& getMessage() const { return _message; }
//! Return the error code.
int getCode() const { return _code; }
private:
std::string _message;
int _code;
};
}
#endif // _XMLRPCEXCEPTION_H_

View File

@@ -0,0 +1,114 @@
// this file modified by Morgan Quigley on 22 Apr 2008.
// added features: server can be opened on port 0 and you can read back
// what port the OS gave you
#ifndef _XMLRPCSERVER_H_
#define _XMLRPCSERVER_H_
//
// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
//
#if defined(_MSC_VER)
# pragma warning(disable:4786) // identifier was truncated in debug info
#endif
#ifndef MAKEDEPEND
# include <map>
# include <string>
#endif
#include "xmlrpcpp/XmlRpcDispatch.h"
#include "xmlrpcpp/XmlRpcSource.h"
#include "xmlrpcpp/XmlRpcDecl.h"
namespace XmlRpc {
// An abstract class supporting XML RPC methods
class XmlRpcServerMethod;
// Class representing connections to specific clients
class XmlRpcServerConnection;
// Class representing argument and result values
class XmlRpcValue;
//! A class to handle XML RPC requests
class XMLRPCPP_DECL XmlRpcServer : public XmlRpcSource {
public:
//! Create a server object.
XmlRpcServer();
//! Destructor.
virtual ~XmlRpcServer();
//! Specify whether introspection is enabled or not. Default is not enabled.
void enableIntrospection(bool enabled=true);
//! Add a command to the RPC server
void addMethod(XmlRpcServerMethod* method);
//! Remove a command from the RPC server
void removeMethod(XmlRpcServerMethod* method);
//! Remove a command from the RPC server by name
void removeMethod(const std::string& methodName);
//! Look up a method by name
XmlRpcServerMethod* findMethod(const std::string& name) const;
//! Create a socket, bind to the specified port, and
//! set it in listen mode to make it available for clients.
bool bindAndListen(int port, int backlog = 5);
//! Process client requests for the specified time
void work(double msTime);
//! Temporarily stop processing client requests and exit the work() method.
void exit();
//! Close all connections with clients and the socket file descriptor
void shutdown();
//! Introspection support
void listMethods(XmlRpcValue& result);
// XmlRpcSource interface implementation
//! Handle client connection requests
virtual unsigned handleEvent(unsigned eventType);
//! Remove a connection from the dispatcher
virtual void removeConnection(XmlRpcServerConnection*);
inline int get_port() { return _port; }
XmlRpcDispatch *get_dispatch() { return &_disp; }
protected:
//! Accept a client connection request
virtual void acceptConnection();
//! Create a new connection object for processing requests from a specific client.
virtual XmlRpcServerConnection* createConnection(int socket);
// Whether the introspection API is supported by this server
bool _introspectionEnabled;
// Event dispatcher
XmlRpcDispatch _disp;
// Collection of methods. This could be a set keyed on method name if we wanted...
typedef std::map< std::string, XmlRpcServerMethod* > MethodMap;
MethodMap _methods;
// system methods
XmlRpcServerMethod* _listMethods;
XmlRpcServerMethod* _methodHelp;
int _port;
};
} // namespace XmlRpc
#endif //_XMLRPCSERVER_H_

View File

@@ -0,0 +1,103 @@
#ifndef _XMLRPCSERVERCONNECTION_H_
#define _XMLRPCSERVERCONNECTION_H_
//
// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
//
#if defined(_MSC_VER)
# pragma warning(disable:4786) // identifier was truncated in debug info
#endif
#ifndef MAKEDEPEND
# include <string>
#endif
#include "xmlrpcpp/XmlRpcValue.h"
#include "xmlrpcpp/XmlRpcSource.h"
#include "xmlrpcpp/XmlRpcDecl.h"
namespace XmlRpc {
// The server waits for client connections and provides methods
class XmlRpcServer;
class XmlRpcServerMethod;
//! A class to handle XML RPC requests from a particular client
class XMLRPCPP_DECL XmlRpcServerConnection : public XmlRpcSource {
public:
// Static data
static const char METHODNAME_TAG[];
static const char PARAMS_TAG[];
static const char PARAMS_ETAG[];
static const char PARAM_TAG[];
static const char PARAM_ETAG[];
static const std::string SYSTEM_MULTICALL;
static const std::string METHODNAME;
static const std::string PARAMS;
static const std::string FAULTCODE;
static const std::string FAULTSTRING;
//! Constructor
XmlRpcServerConnection(int fd, XmlRpcServer* server, bool deleteOnClose = false);
//! Destructor
virtual ~XmlRpcServerConnection();
// XmlRpcSource interface implementation
//! Handle IO on the client connection socket.
//! @param eventType Type of IO event that occurred. @see XmlRpcDispatch::EventType.
virtual unsigned handleEvent(unsigned eventType);
protected:
bool readHeader();
bool readRequest();
bool writeResponse();
// Parses the request, runs the method, generates the response xml.
virtual void executeRequest();
// Parse the methodName and parameters from the request.
std::string parseRequest(XmlRpcValue& params);
// Execute a named method with the specified params.
bool executeMethod(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result);
// Execute multiple calls and return the results in an array.
bool executeMulticall(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result);
// Construct a response from the result XML.
void generateResponse(std::string const& resultXml);
void generateFaultResponse(std::string const& msg, int errorCode = -1);
std::string generateHeader(std::string const& body);
// The XmlRpc server that accepted this connection
XmlRpcServer* _server;
// Possible IO states for the connection
enum ServerConnectionState { READ_HEADER, READ_REQUEST, WRITE_RESPONSE };
ServerConnectionState _connectionState;
// Request headers
std::string _header;
// Number of bytes expected in the request body (parsed from header)
int _contentLength;
// Request body
std::string _request;
// Response
std::string _response;
// Number of bytes of the response written so far
int _bytesWritten;
// Whether to keep the current client connection open for further requests
bool _keepAlive;
};
} // namespace XmlRpc
#endif // _XMLRPCSERVERCONNECTION_H_

View File

@@ -0,0 +1,49 @@
#ifndef _XMLRPCSERVERMETHOD_H_
#define _XMLRPCSERVERMETHOD_H_
//
// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
//
#if defined(_MSC_VER)
# pragma warning(disable:4786) // identifier was truncated in debug info
#endif
#include "xmlrpcpp/XmlRpcDecl.h"
#ifndef MAKEDEPEND
# include <string>
#endif
namespace XmlRpc {
// Representation of a parameter or result value
class XmlRpcValue;
// The XmlRpcServer processes client requests to call RPCs
class XmlRpcServer;
//! Abstract class representing a single RPC method
class XMLRPCPP_DECL XmlRpcServerMethod {
public:
//! Constructor
XmlRpcServerMethod(std::string const& name, XmlRpcServer* server = 0);
//! Destructor
virtual ~XmlRpcServerMethod();
//! Returns the name of the method
std::string& name() { return _name; }
//! Execute the method. Subclasses must provide a definition for this method.
virtual void execute(XmlRpcValue& params, XmlRpcValue& result) = 0;
//! Returns a help string for the method.
//! Subclasses should define this method if introspection is being used.
virtual std::string help() { return std::string(); }
protected:
std::string _name;
XmlRpcServer* _server;
};
} // namespace XmlRpc
#endif // _XMLRPCSERVERMETHOD_H_

View File

@@ -0,0 +1,80 @@
// this file modified by Morgan Quigley on 22 Apr 2008.
// added features: server can be opened on port 0 and you can read back
// what port the OS gave you
#ifndef _XMLRPCSOCKET_H_
#define _XMLRPCSOCKET_H_
//
// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
//
#if defined(_MSC_VER)
# pragma warning(disable:4786) // identifier was truncated in debug info
#endif
#ifndef MAKEDEPEND
# include <string>
#endif
#include "xmlrpcpp/XmlRpcDecl.h"
namespace XmlRpc {
//! A platform-independent socket API.
class XMLRPCPP_DECL XmlRpcSocket {
public:
static bool s_use_ipv6_;
//! Creates a stream (TCP) socket. Returns -1 on failure.
static int socket();
//! Closes a socket.
static void close(int socket);
//! Sets a stream (TCP) socket to perform non-blocking IO. Returns false on failure.
static bool setNonBlocking(int socket);
//! Read text from the specified socket. Returns false on error.
static bool nbRead(int socket, std::string& s, bool *eof);
//! Write text to the specified socket. Returns false on error.
static bool nbWrite(int socket, std::string& s, int *bytesSoFar);
// The next four methods are appropriate for servers.
//! Allow the port the specified socket is bound to to be re-bound immediately so
//! server re-starts are not delayed. Returns false on failure.
static bool setReuseAddr(int socket);
//! Bind to a specified port
static bool bind(int socket, int port);
static int get_port(int socket);
//! Set socket in listen mode
static bool listen(int socket, int backlog);
//! Accept a client connection request
static int accept(int socket);
//! Connect a socket to a server (from a client)
static bool connect(int socket, std::string& host, int port);
//! Returns last errno
static int getError();
//! Returns message corresponding to last error
static std::string getErrorMsg();
//! Returns message corresponding to error
static std::string getErrorMsg(int error);
};
} // namespace XmlRpc
#endif

View File

@@ -0,0 +1,57 @@
#ifndef _XMLRPCSOURCE_H_
#define _XMLRPCSOURCE_H_
//
// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
//
#if defined(_MSC_VER)
# pragma warning(disable:4786) // identifier was truncated in debug info
#endif
#include "xmlrpcpp/XmlRpcDecl.h"
namespace XmlRpc {
//! An RPC source represents a file descriptor to monitor
class XMLRPCPP_DECL XmlRpcSource {
public:
//! Constructor
//! @param fd The socket file descriptor to monitor.
//! @param deleteOnClose If true, the object deletes itself when close is called.
XmlRpcSource(int fd = -1, bool deleteOnClose = false);
//! Destructor
virtual ~XmlRpcSource();
//! Return the file descriptor being monitored.
int getfd() const { return _fd; }
//! Specify the file descriptor to monitor.
void setfd(int fd) { _fd = fd; }
//! Return whether the file descriptor should be kept open if it is no longer monitored.
bool getKeepOpen() const { return _keepOpen; }
//! Specify whether the file descriptor should be kept open if it is no longer monitored.
void setKeepOpen(bool b=true) { _keepOpen = b; }
//! Close the owned fd. If deleteOnClose was specified at construction, the object is deleted.
virtual void close();
//! Return true to continue monitoring this source
virtual unsigned handleEvent(unsigned eventType) = 0;
private:
// Socket. This should really be a SOCKET (an alias for unsigned int*) on windows...
int _fd;
// In the server, a new source (XmlRpcServerConnection) is created
// for each connected client. When each connection is closed, the
// corresponding source object is deleted.
bool _deleteOnClose;
// In the client, keep connections open if you intend to make multiple calls.
bool _keepOpen;
};
} // namespace XmlRpc
#endif //_XMLRPCSOURCE_H_

View File

@@ -0,0 +1,63 @@
#ifndef _XMLRPCUTIL_H_
#define _XMLRPCUTIL_H_
//
// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
//
#if defined(_MSC_VER)
# pragma warning(disable:4786) // identifier was truncated in debug info
#endif
#ifndef MAKEDEPEND
# include <string>
#endif
#include "xmlrpcpp/XmlRpcDecl.h"
#if defined(_MSC_VER)
# define snprintf _snprintf_s
# define vsnprintf _vsnprintf_s
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
#elif defined(__BORLANDC__)
# define strcasecmp stricmp
# define strncasecmp strnicmp
#endif
namespace XmlRpc {
//! Utilities for XML parsing, encoding, and decoding and message handlers.
class XMLRPCPP_DECL XmlRpcUtil {
public:
// hokey xml parsing
//! Returns contents between <tag> and </tag>, updates offset to char after </tag>
static std::string parseTag(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 findTag(const char* tag, std::string const& xml, int* offset);
//! Returns the next tag and updates offset to the char after the tag, or empty string
//! if the next non-whitespace character is not '<'
static std::string getNextTag(std::string const& xml, int* offset);
//! Returns true if the tag is found at the specified offset (modulo any whitespace)
//! and updates offset to the char after the tag
static bool nextTagIs(const char* tag, std::string const& xml, int* offset);
//! Convert raw text to encoded xml.
static std::string xmlEncode(const std::string& raw);
//! Convert encoded xml to raw text
static std::string xmlDecode(const std::string& encoded);
//! Dump messages somewhere
static void log(int level, const char* fmt, ...);
//! Dump error messages somewhere
static void error(const char* fmt, ...);
};
} // namespace XmlRpc
#endif // _XMLRPCUTIL_H_

View File

@@ -0,0 +1,195 @@
#ifndef _XMLRPCVALUE_H_
#define _XMLRPCVALUE_H_
//
// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
//
#if defined(_MSC_VER)
# pragma warning(disable:4786) // identifier was truncated in debug info
#endif
#include "xmlrpcpp/XmlRpcDecl.h"
#ifndef MAKEDEPEND
# include <map>
# include <string>
# include <vector>
# include <time.h>
#endif
namespace XmlRpc {
//! RPC method arguments and results are represented by Values
// should probably refcount them...
class XMLRPCPP_DECL XmlRpcValue {
public:
enum Type {
TypeInvalid,
TypeBoolean,
TypeInt,
TypeDouble,
TypeString,
TypeDateTime,
TypeBase64,
TypeArray,
TypeStruct
};
// Non-primitive types
typedef std::vector<char> BinaryData;
typedef std::vector<XmlRpcValue> ValueArray;
typedef std::map<std::string, XmlRpcValue> ValueStruct;
typedef ValueStruct::iterator iterator;
//! Constructors
XmlRpcValue() : _type(TypeInvalid) { _value.asBinary = 0; }
XmlRpcValue(bool value) : _type(TypeBoolean) { _value.asBool = value; }
XmlRpcValue(int value) : _type(TypeInt) { _value.asInt = value; }
XmlRpcValue(double value) : _type(TypeDouble) { _value.asDouble = value; }
XmlRpcValue(std::string const& value) : _type(TypeString)
{ _value.asString = new std::string(value); }
XmlRpcValue(const char* value) : _type(TypeString)
{ _value.asString = new std::string(value); }
XmlRpcValue(struct tm* value) : _type(TypeDateTime)
{ _value.asTime = new struct tm(*value); }
XmlRpcValue(void* value, int nBytes) : _type(TypeBase64)
{
_value.asBinary = new BinaryData((char*)value, ((char*)value)+nBytes);
}
//! Construct from xml, beginning at *offset chars into the string, updates offset
XmlRpcValue(std::string const& xml, int* offset) : _type(TypeInvalid)
{ if ( ! fromXml(xml,offset)) _type = TypeInvalid; }
//! Copy
XmlRpcValue(XmlRpcValue const& rhs) : _type(TypeInvalid) { *this = rhs; }
//! Destructor (make virtual if you want to subclass)
/*virtual*/ ~XmlRpcValue() { invalidate(); }
//! Erase the current value
void clear() { invalidate(); }
// Operators
XmlRpcValue& operator=(XmlRpcValue const& rhs);
XmlRpcValue& operator=(int const& rhs) { return operator=(XmlRpcValue(rhs)); }
XmlRpcValue& operator=(double const& rhs) { return operator=(XmlRpcValue(rhs)); }
XmlRpcValue& operator=(const char* rhs) { return operator=(XmlRpcValue(std::string(rhs))); }
bool operator==(XmlRpcValue const& other) const;
bool operator!=(XmlRpcValue const& other) const;
operator bool&() { assertTypeOrInvalid(TypeBoolean); return _value.asBool; }
operator int&() { assertTypeOrInvalid(TypeInt); return _value.asInt; }
operator double&() { assertTypeOrInvalid(TypeDouble); return _value.asDouble; }
operator std::string&() { assertTypeOrInvalid(TypeString); return *_value.asString; }
operator BinaryData&() { assertTypeOrInvalid(TypeBase64); return *_value.asBinary; }
operator struct tm&() { assertTypeOrInvalid(TypeDateTime); return *_value.asTime; }
XmlRpcValue const& operator[](int i) const { assertArray(i+1); return _value.asArray->at(i); }
XmlRpcValue& operator[](int i) { assertArray(i+1); return _value.asArray->at(i); }
XmlRpcValue& operator[](std::string const& k) { assertStruct(); return (*_value.asStruct)[k]; }
XmlRpcValue& operator[](const char* k) { assertStruct(); std::string s(k); return (*_value.asStruct)[s]; }
iterator begin() {assertStruct(); return (*_value.asStruct).begin(); }
iterator end() {assertStruct(); return (*_value.asStruct).end(); }
// Accessors
//! Return true if the value has been set to something.
bool valid() const { return _type != TypeInvalid; }
//! Return the type of the value stored. \see Type.
Type const &getType() const { return _type; }
//! Return the size for string, base64, array, and struct values.
int size() const;
//! Specify the size for array values. Array values will grow beyond this size if needed.
void setSize(int size) { assertArray(size); }
//! Check for the existence of a struct member by name.
bool hasMember(const std::string& name) const;
//! Decode xml. Destroys any existing value.
bool fromXml(std::string const& valueXml, int* offset);
//! Encode the Value in xml
std::string toXml() const;
//! Write the value (no xml encoding)
std::ostream& write(std::ostream& os) const;
// Formatting
//! Return the format used to write double values.
static std::string const& getDoubleFormat() { return _doubleFormat; }
//! Specify the format used to write double values.
static void setDoubleFormat(const char* f) { _doubleFormat = f; }
protected:
// Clean up
void invalidate();
// Type checking
void assertTypeOrInvalid(Type t);
void assertArray(int size) const;
void assertArray(int size);
void assertStruct();
// XML decoding
bool boolFromXml(std::string const& valueXml, int* offset);
bool intFromXml(std::string const& valueXml, int* offset);
bool doubleFromXml(std::string const& valueXml, int* offset);
bool stringFromXml(std::string const& valueXml, int* offset);
bool timeFromXml(std::string const& valueXml, int* offset);
bool binaryFromXml(std::string const& valueXml, int* offset);
bool arrayFromXml(std::string const& valueXml, int* offset);
bool structFromXml(std::string const& valueXml, int* offset);
// XML encoding
std::string boolToXml() const;
std::string intToXml() const;
std::string doubleToXml() const;
std::string stringToXml() const;
std::string timeToXml() const;
std::string binaryToXml() const;
std::string arrayToXml() const;
std::string structToXml() const;
// Format strings
static std::string _doubleFormat;
// Type tag and values
Type _type;
// At some point I will split off Arrays and Structs into
// separate ref-counted objects for more efficient copying.
union {
bool asBool;
int asInt;
double asDouble;
struct tm* asTime;
std::string* asString;
BinaryData* asBinary;
ValueArray* asArray;
ValueStruct* asStruct;
} _value;
};
} // namespace XmlRpc
std::ostream& operator<<(std::ostream& os, const XmlRpc::XmlRpcValue& v);
#endif // _XMLRPCVALUE_H_

View File

@@ -0,0 +1,380 @@
// base64.hpp
// Autor Konstantin Pilipchuk
// mailto:lostd@ukr.net
//
//
#if !defined(__BASE64_H_INCLUDED__)
#define __BASE64_H_INCLUDED__ 1
#ifndef MAKEDEPEND
# include <iterator>
#endif
#include <ios>
static
int _base64Chars[]= {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9',
'+','/' };
#define _0000_0011 0x03
#define _1111_1100 0xFC
#define _1111_0000 0xF0
#define _0011_0000 0x30
#define _0011_1100 0x3C
#define _0000_1111 0x0F
#define _1100_0000 0xC0
#define _0011_1111 0x3F
#define _EQUAL_CHAR (-1)
#define _UNKNOWN_CHAR (-2)
#define _IOS_FAILBIT std::ios_base::failbit
#define _IOS_EOFBIT std::ios_base::eofbit
#define _IOS_BADBIT std::ios_base::badbit
#define _IOS_GOODBIT std::ios_base::goodbit
// TEMPLATE CLASS base64_put
template<class _E = char, class _Tr = std::char_traits<_E> >
class base64
{
public:
typedef unsigned char byte_t;
typedef _E char_type;
typedef _Tr traits_type;
// base64 requires max line length <= 72 characters
// you can fill end of line
// it may be crlf, crlfsp, noline or other class like it
struct crlf
{
template<class _OI>
_OI operator()(_OI _To) const{
*_To = _Tr::to_char_type('\r'); ++_To;
*_To = _Tr::to_char_type('\n'); ++_To;
return (_To);
}
};
struct crlfsp
{
template<class _OI>
_OI operator()(_OI _To) const{
*_To = _Tr::to_char_type('\r'); ++_To;
*_To = _Tr::to_char_type('\n'); ++_To;
*_To = _Tr::to_char_type(' '); ++_To;
return (_To);
}
};
struct noline
{
template<class _OI>
_OI operator()(_OI _To) const{
return (_To);
}
};
struct three2four
{
void zero()
{
_data[0] = 0;
_data[1] = 0;
_data[2] = 0;
}
byte_t get_0() const
{
return _data[0];
}
byte_t get_1() const
{
return _data[1];
}
byte_t get_2() const
{
return _data[2];
}
void set_0(byte_t _ch)
{
_data[0] = _ch;
}
void set_1(byte_t _ch)
{
_data[1] = _ch;
}
void set_2(byte_t _ch)
{
_data[2] = _ch;
}
// 0000 0000 1111 1111 2222 2222
// xxxx xxxx xxxx xxxx xxxx xxxx
// 0000 0011 1111 2222 2233 3333
int b64_0() const {return (_data[0] & _1111_1100) >> 2;}
int b64_1() const {return ((_data[0] & _0000_0011) << 4) + ((_data[1] & _1111_0000)>>4);}
int b64_2() const {return ((_data[1] & _0000_1111) << 2) + ((_data[2] & _1100_0000)>>6);}
int b64_3() const {return (_data[2] & _0011_1111);}
void b64_0(int _ch) {_data[0] = ((_ch & _0011_1111) << 2) | (_0000_0011 & _data[0]);}
void b64_1(int _ch) {
_data[0] = ((_ch & _0011_0000) >> 4) | (_1111_1100 & _data[0]);
_data[1] = ((_ch & _0000_1111) << 4) | (_0000_1111 & _data[1]); }
void b64_2(int _ch) {
_data[1] = ((_ch & _0011_1100) >> 2) | (_1111_0000 & _data[1]);
_data[2] = ((_ch & _0000_0011) << 6) | (_0011_1111 & _data[2]); }
void b64_3(int _ch){
_data[2] = (_ch & _0011_1111) | (_1100_0000 & _data[2]);}
private:
byte_t _data[3];
};
template<class _II, class _OI, class _State, class _Endline>
_II put(_II _First, _II _Last, _OI _To, _State&, _Endline) const
{
three2four _3to4;
int line_octets = 0;
while(_First != _Last)
{
_3to4.zero();
_3to4.set_0(*_First);
_First++;
if(_First == _Last)
{
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_0()]); ++_To;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_1()]); ++_To;
*_To = _Tr::to_char_type('='); ++_To;
*_To = _Tr::to_char_type('='); ++_To;
goto __end;
}
_3to4.set_1(*_First);
_First++;
if(_First == _Last)
{
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_0()]); ++_To;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_1()]); ++_To;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_2()]); ++_To;
*_To = _Tr::to_char_type('='); ++_To;
goto __end;
}
_3to4.set_2(*_First);
_First++;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_0()]); ++_To;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_1()]); ++_To;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_2()]); ++_To;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_3()]); ++_To;
if(line_octets == 17)
{
//_To = _Endl(_To);
*_To = '\n'; ++_To;
line_octets = 0;
}
else
++line_octets;
}
__end: ;
return (_First);
}
template<class _II, class _OI, class _State>
_II get(_II _First, _II _Last, _OI _To, _State& _St) const
{
three2four _3to4;
int _Char;
while(_First != _Last)
{
// Take octet
_3to4.zero();
// -- 0 --
// Search next valid char...
while((_Char = _getCharType(*_First)) < 0 && _Char == _UNKNOWN_CHAR)
{
if(++_First == _Last)
{
_St |= _IOS_FAILBIT|_IOS_EOFBIT; return _First; // unexpected EOF
}
}
if(_Char == _EQUAL_CHAR){
// Error! First character in octet can't be '='
_St |= _IOS_FAILBIT;
return _First;
}
else
_3to4.b64_0(_Char);
// -- 1 --
// Search next valid char...
while(++_First != _Last)
if((_Char = _getCharType(*_First)) != _UNKNOWN_CHAR)
break;
if(_First == _Last) {
_St |= _IOS_FAILBIT|_IOS_EOFBIT; // unexpected EOF
return _First;
}
if(_Char == _EQUAL_CHAR){
// Error! Second character in octet can't be '='
_St |= _IOS_FAILBIT;
return _First;
}
else
_3to4.b64_1(_Char);
// -- 2 --
// Search next valid char...
while(++_First != _Last)
if((_Char = _getCharType(*_First)) != _UNKNOWN_CHAR)
break;
if(_First == _Last) {
// Error! Unexpected EOF. Must be '=' or base64 character
_St |= _IOS_FAILBIT|_IOS_EOFBIT;
return _First;
}
if(_Char == _EQUAL_CHAR){
// OK!
_3to4.b64_2(0);
_3to4.b64_3(0);
// chek for EOF
if(++_First == _Last)
{
// Error! Unexpected EOF. Must be '='. Ignore it.
//_St |= _IOS_BADBIT|_IOS_EOFBIT;
_St |= _IOS_EOFBIT;
}
else
if(_getCharType(*_First) != _EQUAL_CHAR)
{
// Error! Must be '='. Ignore it.
//_St |= _IOS_BADBIT;
}
else
++_First; // Skip '='
// write 1 byte to output
*_To = (byte_t) _3to4.get_0();
return _First;
}
else
_3to4.b64_2(_Char);
// -- 3 --
// Search next valid char...
while(++_First != _Last)
if((_Char = _getCharType(*_First)) != _UNKNOWN_CHAR)
break;
if(_First == _Last) {
// Unexpected EOF. It's error. But ignore it.
//_St |= _IOS_FAILBIT|_IOS_EOFBIT;
_St |= _IOS_EOFBIT;
return _First;
}
if(_Char == _EQUAL_CHAR)
{
// OK!
_3to4.b64_3(0);
// write to output 2 bytes
*_To = (byte_t) _3to4.get_0();
*_To = (byte_t) _3to4.get_1();
++_First; // set position to next character
return _First;
}
else
_3to4.b64_3(_Char);
// write to output 3 bytes
*_To = (byte_t) _3to4.get_0();
*_To = (byte_t) _3to4.get_1();
*_To = (byte_t) _3to4.get_2();
++_First;
} // while(_First != _Last)
return (_First);
}
protected:
int _getCharType(int _Ch) const
{
if(_base64Chars[62] == _Ch)
return 62;
if(_base64Chars[63] == _Ch)
return 63;
if((_base64Chars[0] <= _Ch) && (_base64Chars[25] >= _Ch))
return _Ch - _base64Chars[0];
if((_base64Chars[26] <= _Ch) && (_base64Chars[51] >= _Ch))
return _Ch - _base64Chars[26] + 26;
if((_base64Chars[52] <= _Ch) && (_base64Chars[61] >= _Ch))
return _Ch - _base64Chars[52] + 52;
if(_Ch == _Tr::to_int_type('='))
return _EQUAL_CHAR;
return _UNKNOWN_CHAR;
}
};
#endif