19 using namespace XmlRpc;
23 #ifdef USE_WINDOWS_DEBUG
24 #define WIN32_LEAN_AND_MEAN
38 void log(
int level,
const char* msg) {
39 #ifdef USE_WINDOWS_DEBUG
40 if (level <= _verbosity) { OutputDebugString(msg); OutputDebugString(
"\n"); }
42 if (level <= _verbosity) std::cout << msg << std::endl;
57 #ifdef USE_WINDOWS_DEBUG
58 OutputDebugString(msg); OutputDebugString(
"\n");
60 std::cerr << msg << std::endl;
83 vsnprintf(buf,
sizeof(buf)-1,fmt,va);
84 buf[
sizeof(buf)-1] = 0;
95 vsnprintf(buf,
sizeof(buf)-1,fmt,va);
96 buf[
sizeof(buf)-1] = 0;
105 if (*offset >=
int(xml.length()))
return std::string();
106 size_t istart = xml.find(tag, *offset);
107 if (istart == std::string::npos)
return std::string();
108 istart += strlen(tag);
109 std::string etag =
"</";
111 size_t iend = xml.find(etag, istart);
112 if (iend == std::string::npos)
return std::string();
114 *offset = int(iend + etag.length());
115 return xml.substr(istart, iend-istart);
123 if (*offset >=
int(xml.length()))
return false;
124 size_t istart = xml.find(tag, *offset);
125 if (istart == std::string::npos)
128 *offset = int(istart + strlen(tag));
138 if (*offset >=
int(xml.length()))
return false;
139 const char* cp = xml.c_str() + *offset;
141 while (*cp && isspace(*cp)) {
146 int len = int(strlen(tag));
147 if (*cp && (strncmp(cp, tag, len) == 0)) {
160 if (*offset >=
int(xml.length()))
return std::string();
162 const char* cp = xml.c_str() + size_t(*offset);
163 const char* startcp = cp;
164 while (*cp && isspace(*cp))
168 if (*cp !=
'<')
return std::string();
171 const char* start = cp++;
172 while (*cp !=
'>' && *cp != 0 && ! isspace(*cp))
175 std::string s(start, cp-start+1);
179 while (*cp !=
'>' && *cp != 0)
182 s[s.length()-1] = *cp;
185 *offset += int(cp - startcp + 1);
192 static const char AMP =
'&';
193 static const char rawEntity[] = {
'<',
'>',
'&',
'\'',
'\"', 0 };
194 static const char*
xmlEntity[] = {
"lt;",
"gt;",
"amp;",
"apos;",
"quot;", 0 };
203 std::string::size_type iAmp = encoded.find(
AMP);
204 if (iAmp == std::string::npos)
207 std::string decoded(encoded, 0, iAmp);
208 std::string::size_type iSize = encoded.size();
209 decoded.reserve(iSize);
211 const char* ens = encoded.c_str();
212 while (iAmp != iSize) {
213 if (encoded[iAmp] ==
AMP && iAmp+1 < iSize) {
215 for (iEntity=0;
xmlEntity[iEntity] != 0; ++iEntity)
224 decoded += encoded[iAmp++];
227 decoded += encoded[iAmp++];
240 std::string::size_type iRep = raw.find_first_of(
rawEntity);
241 if (iRep == std::string::npos)
244 std::string encoded(raw, 0, iRep);
245 std::string::size_type iSize = raw.size();
247 while (iRep != iSize) {
249 for (iEntity=0;
rawEntity[iEntity] != 0; ++iEntity)
257 encoded += raw[iRep];