OverSim
XmlRpc::XmlRpcUtil Class Reference

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

#include <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.

Detailed Description

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

Definition at line 33 of file XmlRpcUtil.h.

Member Function Documentation

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

Dump error messages somewhere.

Definition at line 90 of file XmlRpcUtil.cc.

Referenced by XmlRpc::XmlRpcServerConnection::readHeader(), XmlRpcInterface::readHeader(), XmlRpcInterface::readRequest(), and XmlRpcInterface::writeResponse().

{
va_list va;
va_start(va, fmt);
char buf[1024];
vsnprintf(buf,sizeof(buf)-1,fmt,va);
buf[sizeof(buf)-1] = 0;
}
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().

{
if (*offset >= int(xml.length())) return false;
size_t istart = xml.find(tag, *offset);
if (istart == std::string::npos)
return false;
*offset = int(istart + strlen(tag));
return true;
}
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().

{
if (*offset >= int(xml.length())) return std::string();
const char* cp = xml.c_str() + size_t(*offset);
const char* startcp = cp;
while (*cp && isspace(*cp))
++cp;
if (*cp != '<') return std::string();
// Tag includes the non-blank characters after <
const char* start = cp++;
while (*cp != '>' && *cp != 0 && ! isspace(*cp))
++cp;
std::string s(start, cp-start+1);
if (*cp != '>') // Skip parameters and values
{
while (*cp != '>' && *cp != 0)
++cp;
s[s.length()-1] = *cp;
}
*offset += int(cp - startcp + 1);
return s;
}
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().

{
if (*offset >= int(xml.length())) return false;
const char* cp = xml.c_str() + *offset;
int nc = 0;
while (*cp && isspace(*cp)) {
++cp;
++nc;
}
int len = int(strlen(tag));
if (*cp && (strncmp(cp, tag, len) == 0)) {
*offset += nc + len;
return true;
}
return false;
}
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().

{
if (*offset >= int(xml.length())) return std::string();
size_t istart = xml.find(tag, *offset);
if (istart == std::string::npos) return std::string();
istart += strlen(tag);
std::string etag = "</";
etag += tag + 1;
size_t iend = xml.find(etag, istart);
if (iend == std::string::npos) return std::string();
*offset = int(iend + etag.length());
return xml.substr(istart, iend-istart);
}
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().

{
std::string::size_type iAmp = encoded.find(AMP);
if (iAmp == std::string::npos)
return encoded;
std::string decoded(encoded, 0, iAmp);
std::string::size_type iSize = encoded.size();
decoded.reserve(iSize);
const char* ens = encoded.c_str();
while (iAmp != iSize) {
if (encoded[iAmp] == AMP && iAmp+1 < iSize) {
int iEntity;
for (iEntity=0; xmlEntity[iEntity] != 0; ++iEntity)
//if (encoded.compare(iAmp+1, xmlEntLen[iEntity], xmlEntity[iEntity]) == 0)
if (strncmp(ens+iAmp+1, xmlEntity[iEntity], xmlEntLen[iEntity]) == 0)
{
decoded += rawEntity[iEntity];
iAmp += xmlEntLen[iEntity]+1;
break;
}
if (xmlEntity[iEntity] == 0) // unrecognized sequence
decoded += encoded[iAmp++];
} else {
decoded += encoded[iAmp++];
}
}
return decoded;
}
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().

{
std::string::size_type iRep = raw.find_first_of(rawEntity);
if (iRep == std::string::npos)
return raw;
std::string encoded(raw, 0, iRep);
std::string::size_type iSize = raw.size();
while (iRep != iSize) {
int iEntity;
for (iEntity=0; rawEntity[iEntity] != 0; ++iEntity)
if (raw[iRep] == rawEntity[iEntity])
{
encoded += AMP;
encoded += xmlEntity[iEntity];
break;
}
if (rawEntity[iEntity] == 0)
encoded += raw[iRep];
++iRep;
}
return encoded;
}

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