17#ifdef USE_WINDOWS_DEBUG
18# define WIN32_LEAN_AND_MEAN
31 void log(
int level,
const char* msg ) {
32#ifdef USE_WINDOWS_DEBUG
35 OutputDebugString( msg );
36 OutputDebugString(
"\n" );
39 if ( level <=
_verbosity ) std::cout << msg << std::endl;
51 void error(
const char* msg ) {
52#ifdef USE_WINDOWS_DEBUG
53 OutputDebugString( msg );
54 OutputDebugString(
"\n" );
56 std::cerr << msg << std::endl;
74 vsnprintf( buf,
sizeof( buf ) - 1, fmt, va );
75 buf[
sizeof( buf ) - 1] = 0;
84 vsnprintf( buf,
sizeof( buf ) - 1, fmt, va );
85 buf[
sizeof( buf ) - 1] = 0;
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 =
"</";
97 size_t iend = xml.find( etag, istart );
98 if ( iend == std::string::npos )
return std::string();
100 *offset = int( iend + etag.length() );
101 return xml.substr( istart, iend - istart );
106 if ( *offset >=
int( xml.length() ) )
return false;
107 size_t istart = xml.find( tag, *offset );
108 if ( istart == std::string::npos )
return false;
110 *offset = int( istart + strlen( tag ) );
117 if ( *offset >=
int( xml.length() ) )
return false;
118 const char* cp = xml.c_str() + *offset;
120 while ( *cp && isspace( *cp ) )
126 int len = int( strlen( tag ) );
127 if ( *cp && ( strncmp( cp, tag, len ) == 0 ) )
138 if ( *offset >=
int( xml.length() ) )
return std::string();
140 size_t pos = *offset;
141 const char* cp = xml.c_str() + pos;
142 while ( *cp && isspace( *cp ) )
148 if ( *cp !=
'<' )
return std::string();
154 }
while ( *cp++ !=
'>' && *cp != 0 );
156 *offset = int( pos );
161static const char AMP =
'&';
162static const char rawEntity[] = {
'<',
'>',
'&',
'\'',
'\"', 0 };
163static const char* xmlEntity[] = {
"lt;",
"gt;",
"amp;",
"apos;",
"quot;", 0 };
164static const int xmlEntLen[] = { 3, 3, 4, 5, 5 };
169 std::string::size_type iAmp = encoded.find( AMP );
170 if ( iAmp == std::string::npos )
return encoded;
172 std::string decoded( encoded, 0, iAmp );
173 std::string::size_type iSize = encoded.size();
174 decoded.reserve( iSize );
176 const char* ens = encoded.c_str();
177 while ( iAmp != iSize )
179 if ( encoded[iAmp] == AMP && iAmp + 1 < iSize )
182 for ( iEntity = 0; xmlEntity[iEntity] != 0; ++iEntity )
184 if ( strncmp( ens + iAmp + 1, xmlEntity[iEntity], xmlEntLen[iEntity] ) == 0 )
186 decoded += rawEntity[iEntity];
187 iAmp += xmlEntLen[iEntity] + 1;
190 if ( xmlEntity[iEntity] == 0 )
191 decoded += encoded[iAmp++];
193 else { decoded += encoded[iAmp++]; }
202 std::string::size_type iRep = raw.find_first_of( rawEntity );
203 if ( iRep == std::string::npos )
return raw;
205 std::string encoded( raw, 0, iRep );
206 std::string::size_type iSize = raw.size();
208 while ( iRep != iSize )
211 for ( iEntity = 0; rawEntity[iEntity] != 0; ++iEntity )
212 if ( raw[iRep] == rawEntity[iEntity] )
215 encoded += xmlEntity[iEntity];
218 if ( rawEntity[iEntity] == 0 ) encoded += raw[iRep];
An interface allowing custom handling of error message reporting.
static XmlRpcErrorHandler * getErrorHandler()
Returns a pointer to the currently installed error handling object.
virtual void error(const char *msg)=0
Report an error. Custom error handlers should define this method.
static XmlRpcErrorHandler * _errorHandler
An interface allowing custom handling of informational message reporting.
static XmlRpcLogHandler * getLogHandler()
Returns a pointer to the currently installed message reporting object.
virtual void log(int level, const char *msg)=0
Output a message. Custom error handlers should define this method.
static int getVerbosity()
static void setVerbosity(int v)
static XmlRpcLogHandler * _logHandler
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)
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 void error(const char *fmt,...)
Dump error messages somewhere.
static std::string xmlEncode(const std::string &raw)
Convert raw text to encoded xml.
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 void log(int level, const char *fmt,...)
Dump messages somewhere.
static std::string getNextTag(std::string const &xml, int *offset)
static std::string xmlDecode(const std::string &encoded)
Convert encoded xml to raw text.
int getVerbosity()
Returns log message verbosity. This is short for XmlRpcLogHandler::getVerbosity().
const char XMLRPC_VERSION[]
Version identifier.
void setVerbosity(int level)
Sets log message verbosity. This is short for XmlRpcLogHandler::setVerbosity(level).