util/StorageService.h \
util/TemplateEngine.h \
util/Threads.h \
+ util/URLEncoder.h \
util/XMLConstants.h \
util/XMLHelper.h \
util/XMLObjectChildrenList.h
util/ReplayCache.cpp \
util/StorageService.cpp \
util/TemplateEngine.cpp \
+ util/URLEncoder.cpp \
util/XMLConstants.cpp \
util/XMLHelper.cpp \
validation/ValidatorSuite.cpp \
#include "util/ReplayCache.h"
#include "util/StorageService.h"
#include "util/TemplateEngine.h"
+#include "util/URLEncoder.h"
#include "util/XMLConstants.h"
#include "validation/ValidatorSuite.h"
m_templateEngine = templateEngine;
}
+void XMLToolingConfig::setURLEncoder(URLEncoder* urlEncoder)
+{
+ delete m_urlEncoder;
+ m_urlEncoder = urlEncoder;
+}
+
bool XMLToolingInternalConfig::init()
{
#ifdef _DEBUG
registerKeyInfoClasses();
registerEncryptionClasses();
registerSOAPClasses();
+
+ m_urlEncoder = new URLEncoder();
REGISTER_XMLTOOLING_EXCEPTION_FACTORY(XMLParserException,xmltooling);
REGISTER_XMLTOOLING_EXCEPTION_FACTORY(XMLObjectException,xmltooling);
delete m_templateEngine;
m_templateEngine = NULL;
+ delete m_urlEncoder;
+ m_urlEncoder = NULL;
+
for (vector<void*>::reverse_iterator i=m_libhandles.rbegin(); i!=m_libhandles.rend(); i++) {
#if defined(WIN32)
FARPROC fn=GetProcAddress(static_cast<HMODULE>(*i),"xmltooling_extension_term");
class XMLTOOL_API SOAPTransport;
class XMLTOOL_API StorageService;
class XMLTOOL_API TemplateEngine;
+ class XMLTOOL_API URLEncoder;
/**
* Singleton object that manages library startup/shutdown.configuration.
{
MAKE_NONCOPYABLE(XMLToolingConfig);
protected:
- XMLToolingConfig() : m_replayCache(NULL), m_templateEngine(NULL), clock_skew_secs(180) {}
+ XMLToolingConfig() : m_replayCache(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
/** Global ReplayCache instance. */
ReplayCache* m_replayCache;
/** Global TemplateEngine instance. */
TemplateEngine* m_templateEngine;
+
+ /** Global URLEncoder instance for use by URL-related functions. */
+ URLEncoder* m_urlEncoder;
+
public:
virtual ~XMLToolingConfig() {}
}
/**
+ * Sets the global URLEncoder instance.
+ * This method must be externally synchronized with any code that uses the object.
+ * Any previously set object is destroyed.
+ *
+ * @param urlEncoder new URLEncoder instance to store
+ */
+ void setURLEncoder(URLEncoder* urlEncoder);
+
+ /**
+ * Returns the global URLEncoder instance.
+ *
+ * @return global URLEncoder or NULL
+ */
+ const URLEncoder* getURLEncoder() const {
+ return m_urlEncoder;
+ }
+
+ /**
* Sets the global TemplateEngine instance.
* This method must be externally synchronized with any code that uses the object.
* Any previously set object is destroyed.
#include "internal.h"
#include "exceptions.h"
#include "XMLToolingConfig.h"
+#include "util/URLEncoder.h"
#include "util/XMLConstants.h"
#include "util/XMLHelper.h"
const char* msg=getMessage();
if (msg)
xml=xml + "<message>" + msg + "</message>";
- for (map<string,string>::const_iterator i=m_params.begin(); i!=m_params.end(); i++) {
+ for (map<string,string>::const_iterator i=m_params.begin(); i!=m_params.end(); i++)
xml=xml + "<param name=\"" + i->first + "\">" + i->second + "</param>";
- }
xml+="</exception>";
return xml;
}
+string XMLToolingException::toQueryString() const
+{
+ const URLEncoder* enc = XMLToolingConfig::getConfig().getURLEncoder();
+ string q("type=");
+ q = q + enc->encode(getClassName()) + "&message=" + enc->encode(what());
+ for (map<string,string>::const_iterator i=m_params.begin(); i!=m_params.end(); i++)
+ q = q + '&' + i->first + '=' + enc->encode(i->second.c_str());
+ return q;
+}
+
XMLToolingException* XMLToolingException::fromStream(std::istream& in)
{
static const XMLCh exception[] = { chLatin_e, chLatin_x, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chLatin_i, chLatin_o, chLatin_n, chNull };
*/
std::string toString() const;
+ /**
+ * Returns a set of query string name/value pairs, URL-encoded, representing the
+ * exception's type, message, and parameters.
+ *
+ * @return the query string representation
+ */
+ std::string toQueryString() const;
+
private:
std::string m_msg;
mutable std::string m_processedmsg;
--- /dev/null
+/*
+ * Copyright 2001-2007 Internet2
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * URLEncoder.cpp
+ *
+ * Interface to a URL-encoding mechanism along with a
+ * default implementation.
+ */
+
+#include "internal.h"
+#include "util/URLEncoder.h"
+
+using namespace xmltooling;
+using namespace std;
+
+static char x2c(char *what)
+{
+ register char digit;
+
+ digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
+ digit *= 16;
+ digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
+ return(digit);
+}
+
+void URLEncoder::decode(char* s) const
+{
+ register int x,y;
+
+ for(x=0,y=0;s[y];++x,++y)
+ {
+ if((s[x] = s[y]) == '%')
+ {
+ s[x] = x2c(&s[y+1]);
+ y+=2;
+ }
+ else if (s[x] == '+')
+ {
+ s[x] = ' ';
+ }
+ }
+ s[x] = '\0';
+}
+
+static inline char hexchar(unsigned short s)
+{
+ return (s<=9) ? ('0' + s) : ('A' + s - 10);
+}
+
+string URLEncoder::encode(const char* s) const
+{
+ string ret;
+ for (; *s; s++) {
+ if (isBad(*s)) {
+ ret+='%';
+ ret+=hexchar((unsigned char)*s >> 4);
+ ret+=hexchar((unsigned char)*s & 0x0F);
+ }
+ else
+ ret+=*s;
+ }
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright 2001-2007 Internet2
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file xmltooling/util/URLEncoder.h
+ *
+ * Interface to a URL-encoding mechanism along with a
+ * default implementation.
+ */
+
+#ifndef __xmltool_urlenc_h__
+#define __xmltool_urlenc_h__
+
+#include <xmltooling/base.h>
+
+namespace xmltooling {
+ /**
+ * Interface to a URL-encoding mechanism along with a default implementation.
+ *
+ * Since URL-encoding is not canonical, it's important that the same
+ * encoder is used during some library operations and the calling code.
+ * Applications can supply an alternative implementation to the library
+ * if required.
+ */
+ class XMLTOOL_API URLEncoder {
+ MAKE_NONCOPYABLE(URLEncoder);
+ public:
+ URLEncoder() {}
+ virtual ~URLEncoder() {}
+
+ /**
+ * Produce a URL-safe but equivalent version of the input string.
+ *
+ * @param s input string to encode
+ * @return a string object containing the result of encoding the input
+ */
+ virtual std::string encode(const char* s) const;
+
+ /**
+ * Perform an in-place decoding operation on the input string.
+ * The resulting string will be NULL-terminated.
+ *
+ * @param s input string to decode in a writable buffer
+ */
+ virtual void decode(char* s) const;
+
+ protected:
+ /**
+ * Returns true iff the input character requires encoding.
+ *
+ * @param ch the character to check
+ * @return true iff the character should be encoded
+ */
+ virtual bool isBad(char ch) const {
+ static char badchars[]="=&/?:\"\\+<>#%{}|^~[]`;@";
+ return (strchr(badchars,ch) || ch<=0x20 || ch>=0x7F);
+ }
+ };
+};
+
+#endif /* __xmltool_urlenc_h__ */
>\r
</File>\r
<File\r
+ RelativePath=".\util\URLEncoder.cpp"\r
+ >\r
+ </File>\r
+ <File\r
RelativePath=".\util\Win32Threads.cpp"\r
>\r
</File>\r
>\r
</File>\r
<File\r
+ RelativePath=".\util\URLEncoder.h"\r
+ >\r
+ </File>\r
+ <File\r
RelativePath=".\util\XMLConstants.h"\r
>\r
</File>\r