XmlRpc::XmlRpcUtil Class Reference

Utilities for XML parsing, encoding, and decoding and message handlers. More...

#include <XmlRpcUtil.h>

List of all members.

Static Public Member Functions

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>.
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 std::string getNextTag (std::string const &xml, int *offset)
static bool nextTagIs (const char *tag, std::string const &xml, int *offset)
static std::string xmlEncode (const std::string &raw)
 Convert raw text to encoded xml.
static std::string xmlDecode (const std::string &encoded)
 Convert encoded xml to raw text.
static void log (int level, const char *fmt,...)
 Dump messages somewhere.
static void error (const char *fmt,...)
 Dump error messages somewhere.


Detailed Description

Utilities for XML parsing, encoding, and decoding and message handlers.

Definition at line 27 of file XmlRpcUtil.h.


Member Function Documentation

void XmlRpcUtil::error ( const char *  fmt,
  ... 
) [static]

Dump error messages somewhere.

Definition at line 85 of file XmlRpcUtil.cpp.

References XmlRpc::XmlRpcErrorHandler::error(), and XmlRpc::XmlRpcErrorHandler::getErrorHandler().

Referenced by XmlRpc::XmlRpcClient::parseResponse(), XmlRpc::XmlRpcServerConnection::readHeader(), XmlRpc::XmlRpcClient::readHeader(), and XmlRpc::XmlRpcServerConnection::writeResponse().

00086 {
00087   va_list va;
00088   va_start(va, fmt);
00089   char buf[1024];
00090   vsnprintf(buf,sizeof(buf)-1,fmt,va);
00091   buf[sizeof(buf)-1] = 0;
00092   XmlRpcErrorHandler::getErrorHandler()->error(buf);
00093 }

bool XmlRpcUtil::findTag ( const char *  tag,
std::string const &  xml,
int *  offset 
) [static]

Returns true if the tag is found and updates offset to the char after the tag.

Definition at line 116 of file XmlRpcUtil.cpp.

References RealDBUtil::npos.

Referenced by XmlRpc::XmlRpcValue::fromXml(), XmlRpc::XmlRpcServerConnection::parseRequest(), and XmlRpc::XmlRpcClient::parseResponse().

00117 {
00118   if (*offset >= int(xml.length())) return false;
00119   size_t istart = xml.find(tag, *offset);
00120   if (istart == std::string::npos)
00121     return false;
00122 
00123   *offset = int(istart + strlen(tag));
00124   return true;
00125 }

std::string XmlRpcUtil::getNextTag ( std::string const &  xml,
int *  offset 
) [static]

Returns the next tag and updates offset to the char after the tag, or empty string if the next non-whitespace character is not '<'

Definition at line 152 of file XmlRpcUtil.cpp.

References boss::pos, s, and deljobs::string.

Referenced by XmlRpc::XmlRpcValue::fromXml().

00153 {
00154   if (*offset >= int(xml.length())) return std::string();
00155 
00156   size_t pos = *offset;
00157   const char* cp = xml.c_str() + pos;
00158   while (*cp && isspace(*cp)) {
00159     ++cp;
00160     ++pos;
00161   }
00162 
00163   if (*cp != '<') return std::string();
00164 
00165   std::string s;
00166   do {
00167     s += *cp;
00168     ++pos;
00169   } while (*cp++ != '>' && *cp != 0);
00170 
00171   *offset = int(pos);
00172   return s;
00173 }

void XmlRpcUtil::log ( int  level,
const char *  fmt,
  ... 
) [static]

Dump messages somewhere.

Definition at line 71 of file XmlRpcUtil.cpp.

References XmlRpc::XmlRpcLogHandler::getLogHandler(), XmlRpc::XmlRpcLogHandler::getVerbosity(), and XmlRpc::XmlRpcLogHandler::log().

Referenced by XmlRpc::XmlRpcServer::acceptConnection(), XmlRpc::XmlRpcServer::bindAndListen(), XmlRpc::XmlRpcSource::close(), XmlRpc::XmlRpcSocket::close(), XmlRpc::XmlRpcClient::close(), XmlRpc::XmlRpcClient::doConnect(), XmlRpc::XmlRpcClient::execute(), XmlRpc::XmlRpcServerConnection::executeRequest(), XmlRpc::XmlRpcClient::generateRequest(), XmlRpc::XmlRpcServerConnection::generateResponse(), XmlRpc::XmlRpcSocket::nbRead(), XmlRpc::XmlRpcSocket::nbWrite(), XmlRpc::XmlRpcServerConnection::readHeader(), XmlRpc::XmlRpcClient::readHeader(), XmlRpc::XmlRpcServerConnection::readRequest(), XmlRpc::XmlRpcClient::readResponse(), XmlRpc::XmlRpcServer::work(), XmlRpc::XmlRpcClient::writeRequest(), XmlRpc::XmlRpcServerConnection::writeResponse(), XmlRpc::XmlRpcClient::XmlRpcClient(), XmlRpc::XmlRpcServerConnection::XmlRpcServerConnection(), and XmlRpc::XmlRpcServerConnection::~XmlRpcServerConnection().

00072 {
00073   if (level <= XmlRpcLogHandler::getVerbosity())
00074   {
00075     va_list va;
00076     char buf[1024];
00077     va_start( va, fmt);
00078     vsnprintf(buf,sizeof(buf)-1,fmt,va);
00079     buf[sizeof(buf)-1] = 0;
00080     XmlRpcLogHandler::getLogHandler()->log(level, buf);
00081   }
00082 }

bool XmlRpcUtil::nextTagIs ( const char *  tag,
std::string const &  xml,
int *  offset 
) [static]

Returns true if the tag is found at the specified offset (modulo any whitespace) and updates offset to the char after the tag

Definition at line 131 of file XmlRpcUtil.cpp.

Referenced by XmlRpc::XmlRpcValue::arrayFromXml(), XmlRpc::XmlRpcValue::fromXml(), XmlRpc::XmlRpcServerConnection::parseRequest(), XmlRpc::XmlRpcClient::parseResponse(), and XmlRpc::XmlRpcValue::structFromXml().

00132 {
00133   if (*offset >= int(xml.length())) return false;
00134   const char* cp = xml.c_str() + *offset;
00135   int nc = 0;
00136   while (*cp && isspace(*cp)) {
00137     ++cp;
00138     ++nc;
00139   }
00140 
00141   int len = int(strlen(tag));
00142   if  (*cp && (strncmp(cp, tag, len) == 0)) {
00143     *offset += nc + len;
00144     return true;
00145   }
00146   return false;
00147 }

std::string XmlRpcUtil::parseTag ( const char *  tag,
std::string const &  xml,
int *  offset 
) [static]

Returns contents between <tag> and </tag>, updates offset to char after </tag>.

Definition at line 98 of file XmlRpcUtil.cpp.

References RealDBUtil::npos, and deljobs::string.

Referenced by XmlRpc::XmlRpcServerConnection::parseRequest(), and XmlRpc::XmlRpcValue::structFromXml().

00099 {
00100   if (*offset >= int(xml.length())) return std::string();
00101   size_t istart = xml.find(tag, *offset);
00102   if (istart == std::string::npos) return std::string();
00103   istart += strlen(tag);
00104   std::string etag = "</";
00105   etag += tag + 1;
00106   size_t iend = xml.find(etag, istart);
00107   if (iend == std::string::npos) return std::string();
00108 
00109   *offset = int(iend + etag.length());
00110   return xml.substr(istart, iend-istart);
00111 }

std::string XmlRpcUtil::xmlDecode ( const std::string encoded  )  [static]

Convert encoded xml to raw text.

Definition at line 187 of file XmlRpcUtil.cpp.

References AMP, RealDBUtil::npos, rawEntity, deljobs::string, xmlEntity, and xmlEntLen.

Referenced by XmlRpc::XmlRpcValue::stringFromXml().

00188 {
00189   std::string::size_type iAmp = encoded.find(AMP);
00190   if (iAmp == std::string::npos)
00191     return encoded;
00192 
00193   std::string decoded(encoded, 0, iAmp);
00194   std::string::size_type iSize = encoded.size();
00195   decoded.reserve(iSize);
00196 
00197   const char* ens = encoded.c_str();
00198   while (iAmp != iSize) {
00199     if (encoded[iAmp] == AMP && iAmp+1 < iSize) {
00200       int iEntity;
00201       for (iEntity=0; xmlEntity[iEntity] != 0; ++iEntity)
00202         //if (encoded.compare(iAmp+1, xmlEntLen[iEntity], xmlEntity[iEntity]) == 0)
00203         if (strncmp(ens+iAmp+1, xmlEntity[iEntity], xmlEntLen[iEntity]) == 0)
00204         {
00205           decoded += rawEntity[iEntity];
00206           iAmp += xmlEntLen[iEntity]+1;
00207           break;
00208         }
00209       if (xmlEntity[iEntity] == 0)    // unrecognized sequence
00210         decoded += encoded[iAmp++];
00211 
00212     } else {
00213       decoded += encoded[iAmp++];
00214     }
00215   }
00216     
00217   return decoded;
00218 }

std::string XmlRpcUtil::xmlEncode ( const std::string raw  )  [static]

Convert raw text to encoded xml.

Definition at line 224 of file XmlRpcUtil.cpp.

References AMP, RealDBUtil::npos, rawEntity, deljobs::string, and xmlEntity.

Referenced by XmlRpc::XmlRpcValue::stringToXml(), and XmlRpc::XmlRpcValue::structToXml().

00225 {
00226   std::string::size_type iRep = raw.find_first_of(rawEntity);
00227   if (iRep == std::string::npos)
00228     return raw;
00229 
00230   std::string encoded(raw, 0, iRep);
00231   std::string::size_type iSize = raw.size();
00232 
00233   while (iRep != iSize) {
00234     int iEntity;
00235     for (iEntity=0; rawEntity[iEntity] != 0; ++iEntity)
00236       if (raw[iRep] == rawEntity[iEntity])
00237       {
00238         encoded += AMP;
00239         encoded += xmlEntity[iEntity];
00240         break;
00241       }
00242     if (rawEntity[iEntity] == 0)
00243       encoded += raw[iRep];
00244     ++iRep;
00245   }
00246   return encoded;
00247 }


Generated on Tue Nov 29 23:36:39 2016 for BOSS_7.0.2 by  doxygen 1.4.7