#include "internal.h"
#include "HTTPResponse.h"
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/bind.hpp>
+
using namespace xmltooling;
+using namespace boost;
using namespace std;
GenericResponse::GenericResponse()
void HTTPResponse::sanitizeURL(const char* url)
{
+ // predicate for checking scheme below
+ static bool (*fn)(const string&, const string&, const std::locale&) = iequals;
+
const char* ch;
for (ch=url; *ch; ++ch) {
if (iscntrl((unsigned char)(*ch))) // convert to unsigned to allow full range from 00-FF
if (!ch)
throw IOException("URL is malformed.");
string s(url, ch - url);
- for (vector<string>::const_iterator i = m_allowedSchemes.begin(); i != m_allowedSchemes.end(); ++i) {
-#ifdef HAVE_STRCASECMP
- if (!strcasecmp(s.c_str(), i->c_str()))
-#else
- if (!stricmp(s.c_str(), i->c_str()))
-#endif
- return;
- }
+ vector<string>::const_iterator i =
+ find_if(m_allowedSchemes.begin(), m_allowedSchemes.end(), boost::bind(fn, boost::cref(s), _1, boost::cref(std::locale())));
+ if (i != m_allowedSchemes.end())
+ return;
throw IOException("URL contains invalid scheme ($1).", params(1, s.c_str()));
}