XmlRpc::XmlRpcUtil Class Reference

#include <XmlRpcUtil.h>

List of all members.


Detailed Description

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

Definition at line 33 of file XmlRpcUtil.h.


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)
 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 bool nextTagIs (const char *tag, 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 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.

Member Function Documentation

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 103 of file XmlRpcUtil.cc.

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

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

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 121 of file XmlRpcUtil.cc.

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

00122 {
00123   if (*offset >= int(xml.length())) return false;
00124   size_t istart = xml.find(tag, *offset);
00125   if (istart == std::string::npos)
00126     return false;
00127 
00128   *offset = int(istart + strlen(tag));
00129   return true;
00130 }

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 158 of file XmlRpcUtil.cc.

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

00159 {
00160   if (*offset >= int(xml.length())) return std::string();
00161 
00162   const char* cp = xml.c_str() + size_t(*offset);
00163   const char* startcp = cp;
00164   while (*cp && isspace(*cp))
00165     ++cp;
00166 
00167 
00168   if (*cp != '<') return std::string();
00169 
00170   // Tag includes the non-blank characters after <
00171   const char* start = cp++;
00172   while (*cp != '>' && *cp != 0 && ! isspace(*cp))
00173     ++cp;
00174 
00175   std::string s(start, cp-start+1);
00176 
00177   if (*cp != '>')   // Skip parameters and values
00178   {
00179     while (*cp != '>' && *cp != 0)
00180       ++cp;
00181 
00182     s[s.length()-1] = *cp;
00183   }
00184 
00185   *offset += int(cp - startcp + 1);
00186   return s;
00187 }

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 136 of file XmlRpcUtil.cc.

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

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

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

Convert raw text to encoded xml.

Definition at line 238 of file XmlRpcUtil.cc.

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

00239 {
00240   std::string::size_type iRep = raw.find_first_of(rawEntity);
00241   if (iRep == std::string::npos)
00242     return raw;
00243 
00244   std::string encoded(raw, 0, iRep);
00245   std::string::size_type iSize = raw.size();
00246 
00247   while (iRep != iSize) {
00248     int iEntity;
00249     for (iEntity=0; rawEntity[iEntity] != 0; ++iEntity)
00250       if (raw[iRep] == rawEntity[iEntity])
00251       {
00252         encoded += AMP;
00253         encoded += xmlEntity[iEntity];
00254         break;
00255       }
00256     if (rawEntity[iEntity] == 0)
00257       encoded += raw[iRep];
00258     ++iRep;
00259   }
00260   return encoded;
00261 }

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

Convert encoded xml to raw text.

Definition at line 201 of file XmlRpcUtil.cc.

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

00202 {
00203   std::string::size_type iAmp = encoded.find(AMP);
00204   if (iAmp == std::string::npos)
00205     return encoded;
00206 
00207   std::string decoded(encoded, 0, iAmp);
00208   std::string::size_type iSize = encoded.size();
00209   decoded.reserve(iSize);
00210 
00211   const char* ens = encoded.c_str();
00212   while (iAmp != iSize) {
00213     if (encoded[iAmp] == AMP && iAmp+1 < iSize) {
00214       int iEntity;
00215       for (iEntity=0; xmlEntity[iEntity] != 0; ++iEntity)
00216         //if (encoded.compare(iAmp+1, xmlEntLen[iEntity], xmlEntity[iEntity]) == 0)
00217         if (strncmp(ens+iAmp+1, xmlEntity[iEntity], xmlEntLen[iEntity]) == 0)
00218         {
00219           decoded += rawEntity[iEntity];
00220           iAmp += xmlEntLen[iEntity]+1;
00221           break;
00222         }
00223       if (xmlEntity[iEntity] == 0)    // unrecognized sequence
00224         decoded += encoded[iAmp++];
00225 
00226     } else {
00227       decoded += encoded[iAmp++];
00228     }
00229   }
00230     
00231   return decoded;
00232 }

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

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


The documentation for this class was generated from the following files:

Generated on Wed Mar 25 16:32:55 2009 for OverSim by  doxygen 1.5.5