BOSS 8.0.0
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 80 of file XmlRpcUtil.cpp.

80 {
81 va_list va;
82 va_start( va, fmt );
83 char buf[1024];
84 vsnprintf( buf, sizeof( buf ) - 1, fmt, va );
85 buf[sizeof( buf ) - 1] = 0;
87}
static XmlRpcErrorHandler * getErrorHandler()
Returns a pointer to the currently installed error handling object.
Definition XmlRpc.h:41
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 105 of file XmlRpcUtil.cpp.

105 {
106 if ( *offset >= int( xml.length() ) ) return false;
107 size_t istart = xml.find( tag, *offset );
108 if ( istart == std::string::npos ) return false;
109
110 *offset = int( istart + strlen( tag ) );
111 return true;
112}

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 137 of file XmlRpcUtil.cpp.

137 {
138 if ( *offset >= int( xml.length() ) ) return std::string();
139
140 size_t pos = *offset;
141 const char* cp = xml.c_str() + pos;
142 while ( *cp && isspace( *cp ) )
143 {
144 ++cp;
145 ++pos;
146 }
147
148 if ( *cp != '<' ) return std::string();
149
150 std::string s;
151 do {
152 s += *cp;
153 ++pos;
154 } while ( *cp++ != '>' && *cp != 0 );
155
156 *offset = int( pos );
157 return s;
158}
XmlRpcServer s

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

◆ log()

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

Dump messages somewhere.

Definition at line 68 of file XmlRpcUtil.cpp.

68 {
69 if ( level <= XmlRpcLogHandler::getVerbosity() )
70 {
71 va_list va;
72 char buf[1024];
73 va_start( va, fmt );
74 vsnprintf( buf, sizeof( buf ) - 1, fmt, va );
75 buf[sizeof( buf ) - 1] = 0;
76 XmlRpcLogHandler::getLogHandler()->log( level, buf );
77 }
78}
static XmlRpcLogHandler * getLogHandler()
Returns a pointer to the currently installed message reporting object.
Definition XmlRpc.h:57
virtual void log(int level, const char *msg)=0
Output a message. Custom error handlers should define this method.
static int getVerbosity()
Definition XmlRpc.h:64

Referenced by XmlRpc::XmlRpcServer::acceptConnection(), XmlRpc::XmlRpcServer::bindAndListen(), XmlRpc::XmlRpcClient::close(), XmlRpc::XmlRpcSocket::close(), XmlRpc::XmlRpcSource::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 116 of file XmlRpcUtil.cpp.

116 {
117 if ( *offset >= int( xml.length() ) ) return false;
118 const char* cp = xml.c_str() + *offset;
119 int nc = 0;
120 while ( *cp && isspace( *cp ) )
121 {
122 ++cp;
123 ++nc;
124 }
125
126 int len = int( strlen( tag ) );
127 if ( *cp && ( strncmp( cp, tag, len ) == 0 ) )
128 {
129 *offset += nc + len;
130 return true;
131 }
132 return false;
133}

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 90 of file XmlRpcUtil.cpp.

90 {
91 if ( *offset >= int( xml.length() ) ) return std::string();
92 size_t istart = xml.find( tag, *offset );
93 if ( istart == std::string::npos ) return std::string();
94 istart += strlen( tag );
95 std::string etag = "</";
96 etag += tag + 1;
97 size_t iend = xml.find( etag, istart );
98 if ( iend == std::string::npos ) return std::string();
99
100 *offset = int( iend + etag.length() );
101 return xml.substr( istart, iend - istart );
102}

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 168 of file XmlRpcUtil.cpp.

168 {
169 std::string::size_type iAmp = encoded.find( AMP );
170 if ( iAmp == std::string::npos ) return encoded;
171
172 std::string decoded( encoded, 0, iAmp );
173 std::string::size_type iSize = encoded.size();
174 decoded.reserve( iSize );
175
176 const char* ens = encoded.c_str();
177 while ( iAmp != iSize )
178 {
179 if ( encoded[iAmp] == AMP && iAmp + 1 < iSize )
180 {
181 int iEntity;
182 for ( iEntity = 0; xmlEntity[iEntity] != 0; ++iEntity )
183 // if (encoded.compare(iAmp+1, xmlEntLen[iEntity], xmlEntity[iEntity]) == 0)
184 if ( strncmp( ens + iAmp + 1, xmlEntity[iEntity], xmlEntLen[iEntity] ) == 0 )
185 {
186 decoded += rawEntity[iEntity];
187 iAmp += xmlEntLen[iEntity] + 1;
188 break;
189 }
190 if ( xmlEntity[iEntity] == 0 ) // unrecognized sequence
191 decoded += encoded[iAmp++];
192 }
193 else { decoded += encoded[iAmp++]; }
194 }
195
196 return decoded;
197}

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 201 of file XmlRpcUtil.cpp.

201 {
202 std::string::size_type iRep = raw.find_first_of( rawEntity );
203 if ( iRep == std::string::npos ) return raw;
204
205 std::string encoded( raw, 0, iRep );
206 std::string::size_type iSize = raw.size();
207
208 while ( iRep != iSize )
209 {
210 int iEntity;
211 for ( iEntity = 0; rawEntity[iEntity] != 0; ++iEntity )
212 if ( raw[iRep] == rawEntity[iEntity] )
213 {
214 encoded += AMP;
215 encoded += xmlEntity[iEntity];
216 break;
217 }
218 if ( rawEntity[iEntity] == 0 ) encoded += raw[iRep];
219 ++iRep;
220 }
221 return encoded;
222}

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


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