2 * Copyright 2001-2006 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 * @file saml/binding/URLEncoder.h
\r
20 * Interface to a URL-encoding mechanism along with a
\r
21 * default implementation.
\r
24 #ifndef __saml_urlenc_h__
\r
25 #define __saml_urlenc_h__
\r
27 #include <saml/base.h>
\r
29 namespace opensaml {
\r
31 * Interface to a URL-encoding mechanism along with a default implementation.
\r
33 * Since URL-encoding is not canonical, it's important that the same
\r
34 * encoder is used during some library operations and the calling code.
\r
35 * Applications can supply an alternative implementation to the library
\r
38 class SAML_API URLEncoder {
\r
39 MAKE_NONCOPYABLE(URLEncoder);
\r
42 virtual ~URLEncoder() {}
\r
45 * Produce a URL-safe but equivalent version of the input string.
\r
47 * @param s input string to encode
\r
48 * @return a string object containing the result of encoding the input
\r
50 virtual std::string encode(const char* s) const;
\r
53 * Perform an in-place decoding operation on the input string.
\r
54 * The resulting string will be NULL-terminated.
\r
56 * @param s input string to decode in a writable buffer
\r
58 virtual void decode(char* s) const;
\r
62 * Returns true iff the input character requires encoding.
\r
64 * @param ch the character to check
\r
65 * @return true iff the character should be encoded
\r
67 virtual bool isBad(char ch) const {
\r
68 static char badchars[]="=&/?:\"\\+<>#%{}|^~[]`;@";
\r
69 return (strchr(badchars,ch) || ch<=0x20 || ch>=0x7F);
\r
74 #endif /* __saml_urlenc_h__ */
\r