CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
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)
 
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

◆ error()

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

Dump error messages somewhere.

Definition at line 85 of file XmlRpcUtil.cpp.

86{
87 va_list va;
88 va_start(va, fmt);
89 char buf[1024];
90 vsnprintf(buf,sizeof(buf)-1,fmt,va);
91 buf[sizeof(buf)-1] = 0;
93}
static XmlRpcErrorHandler * getErrorHandler()
Returns a pointer to the currently installed error handling object.
Definition: XmlRpc.h:42
virtual void error(const char *msg)=0
Report an error. Custom error handlers should define this method.

Referenced by XmlRpc::XmlRpcServer::acceptConnection(), XmlRpc::XmlRpcServer::bindAndListen(), XmlRpc::XmlRpcClient::doConnect(), XmlRpc::XmlRpcClient::handleEvent(), XmlRpc::XmlRpcClient::parseResponse(), XmlRpc::XmlRpcClient::readHeader(), XmlRpc::XmlRpcServerConnection::readHeader(), XmlRpc::XmlRpcServerConnection::readRequest(), XmlRpc::XmlRpcClient::readResponse(), XmlRpc::XmlRpcDispatch::work(), XmlRpc::XmlRpcClient::writeRequest(), and XmlRpc::XmlRpcServerConnection::writeResponse().

◆ findTag()

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.

117{
118 if (*offset >= int(xml.length())) return false;
119 size_t istart = xml.find(tag, *offset);
120 if (istart == std::string::npos)
121 return false;
122
123 *offset = int(istart + strlen(tag));
124 return true;
125}

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

◆ getNextTag()

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.

153{
154 if (*offset >= int(xml.length())) return std::string();
155
156 size_t pos = *offset;
157 const char* cp = xml.c_str() + pos;
158 while (*cp && isspace(*cp)) {
159 ++cp;
160 ++pos;
161 }
162
163 if (*cp != '<') return std::string();
164
165 std::string s;
166 do {
167 s += *cp;
168 ++pos;
169 } while (*cp++ != '>' && *cp != 0);
170
171 *offset = int(pos);
172 return s;
173}
XmlRpcServer s
Definition: HelloServer.cpp:11

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

◆ log()

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

Dump messages somewhere.

Definition at line 71 of file XmlRpcUtil.cpp.

72{
73 if (level <= XmlRpcLogHandler::getVerbosity())
74 {
75 va_list va;
76 char buf[1024];
77 va_start( va, fmt);
78 vsnprintf(buf,sizeof(buf)-1,fmt,va);
79 buf[sizeof(buf)-1] = 0;
81 }
82}
static XmlRpcLogHandler * getLogHandler()
Returns a pointer to the currently installed message reporting object.
Definition: XmlRpc.h:60
virtual void log(int level, const char *msg)=0
Output a message. Custom error handlers should define this method.
static int getVerbosity()
Returns the level of verbosity of informational messages. 0 is no output, 5 is very verbose.
Definition: XmlRpc.h:68

Referenced by XmlRpc::XmlRpcServer::acceptConnection(), XmlRpc::XmlRpcServer::bindAndListen(), XmlRpc::XmlRpcClient::close(), XmlRpc::XmlRpcSource::close(), XmlRpc::XmlRpcSocket::close(), XmlRpc::XmlRpcClient::doConnect(), XmlRpc::XmlRpcClient::execute(), XmlRpc::XmlRpcServerConnection::executeRequest(), XmlRpc::XmlRpcClient::generateRequest(), XmlRpc::XmlRpcServerConnection::generateResponse(), XmlRpc::XmlRpcSocket::nbRead(), XmlRpc::XmlRpcSocket::nbWrite(), parseRequest(), XmlRpc::XmlRpcClient::readHeader(), XmlRpc::XmlRpcServerConnection::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().

◆ nextTagIs()

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.

132{
133 if (*offset >= int(xml.length())) return false;
134 const char* cp = xml.c_str() + *offset;
135 int nc = 0;
136 while (*cp && isspace(*cp)) {
137 ++cp;
138 ++nc;
139 }
140
141 int len = int(strlen(tag));
142 if (*cp && (strncmp(cp, tag, len) == 0)) {
143 *offset += nc + len;
144 return true;
145 }
146 return false;
147}

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

◆ parseTag()

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.

99{
100 if (*offset >= int(xml.length())) return std::string();
101 size_t istart = xml.find(tag, *offset);
102 if (istart == std::string::npos) return std::string();
103 istart += strlen(tag);
104 std::string etag = "</";
105 etag += tag + 1;
106 size_t iend = xml.find(etag, istart);
107 if (iend == std::string::npos) return std::string();
108
109 *offset = int(iend + etag.length());
110 return xml.substr(istart, iend-istart);
111}

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

◆ xmlDecode()

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

Convert encoded xml to raw text.

Definition at line 187 of file XmlRpcUtil.cpp.

188{
189 std::string::size_type iAmp = encoded.find(AMP);
190 if (iAmp == std::string::npos)
191 return encoded;
192
193 std::string decoded(encoded, 0, iAmp);
194 std::string::size_type iSize = encoded.size();
195 decoded.reserve(iSize);
196
197 const char* ens = encoded.c_str();
198 while (iAmp != iSize) {
199 if (encoded[iAmp] == AMP && iAmp+1 < iSize) {
200 int iEntity;
201 for (iEntity=0; xmlEntity[iEntity] != 0; ++iEntity)
202 //if (encoded.compare(iAmp+1, xmlEntLen[iEntity], xmlEntity[iEntity]) == 0)
203 if (strncmp(ens+iAmp+1, xmlEntity[iEntity], xmlEntLen[iEntity]) == 0)
204 {
205 decoded += rawEntity[iEntity];
206 iAmp += xmlEntLen[iEntity]+1;
207 break;
208 }
209 if (xmlEntity[iEntity] == 0) // unrecognized sequence
210 decoded += encoded[iAmp++];
211
212 } else {
213 decoded += encoded[iAmp++];
214 }
215 }
216
217 return decoded;
218}

Referenced by main(), and XmlRpc::XmlRpcValue::stringFromXml().

◆ xmlEncode()

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

Convert raw text to encoded xml.

Definition at line 224 of file XmlRpcUtil.cpp.

225{
226 std::string::size_type iRep = raw.find_first_of(rawEntity);
227 if (iRep == std::string::npos)
228 return raw;
229
230 std::string encoded(raw, 0, iRep);
231 std::string::size_type iSize = raw.size();
232
233 while (iRep != iSize) {
234 int iEntity;
235 for (iEntity=0; rawEntity[iEntity] != 0; ++iEntity)
236 if (raw[iRep] == rawEntity[iEntity])
237 {
238 encoded += AMP;
239 encoded += xmlEntity[iEntity];
240 break;
241 }
242 if (rawEntity[iEntity] == 0)
243 encoded += raw[iRep];
244 ++iRep;
245 }
246 return encoded;
247}

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


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