14e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius#ifndef _XMLRPCUTIL_H_ 24e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius#define _XMLRPCUTIL_H_ 34e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius// 44e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley 54e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius// 64e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius#if defined(_MSC_VER) 74e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius# pragma warning(disable:4786) // identifier was truncated in debug info 84e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius#endif 94e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 104e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius#ifndef MAKEDEPEND 114e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius# include <string> 124e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius#endif 134e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 144e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius#if defined(_MSC_VER) 154e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius# define snprintf _snprintf 164e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius# define vsnprintf _vsnprintf 174e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius# define strcasecmp _stricmp 184e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius# define strncasecmp _strnicmp 194e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius#elif defined(__BORLANDC__) 204e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius# define strcasecmp stricmp 214e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius# define strncasecmp strnicmp 224e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius#endif 234e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 244e2ea8184cc1f9609f1f1251394316629a108a78Roshan Piusnamespace XmlRpc { 254e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 264e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius //! Utilities for XML parsing, encoding, and decoding and message handlers. 274e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius class XmlRpcUtil { 284e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius public: 294e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius // hokey xml parsing 304e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius //! Returns contents between <tag> and </tag>, updates offset to char after </tag> 314e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius static std::string parseTag(const char* tag, std::string const& xml, int* offset); 324e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 334e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius //! Returns true if the tag is found and updates offset to the char after the tag 344e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius static bool findTag(const char* tag, std::string const& xml, int* offset); 354e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 364e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius //! Returns the next tag and updates offset to the char after the tag, or empty string 374e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius //! if the next non-whitespace character is not '<' 384e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius static std::string getNextTag(std::string const& xml, int* offset); 394e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 404e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius //! Returns true if the tag is found at the specified offset (modulo any whitespace) 414e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius //! and updates offset to the char after the tag 424e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius static bool nextTagIs(const char* tag, std::string const& xml, int* offset); 434e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 444e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 454e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius //! Convert raw text to encoded xml. 464e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius static std::string xmlEncode(const std::string& raw); 474e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 484e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius //! Convert encoded xml to raw text 494e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius static std::string xmlDecode(const std::string& encoded); 504e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 514e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 524e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius //! Dump messages somewhere 534e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius static void log(int level, const char* fmt, ...); 544e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 554e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius //! Dump error messages somewhere 564e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius static void error(const char* fmt, ...); 574e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 584e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius }; 594e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius} // namespace XmlRpc 604e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius 614e2ea8184cc1f9609f1f1251394316629a108a78Roshan Pius#endif // _XMLRPCUTIL_H_ 62