From: Amos Jeffries Date: Mon, 9 Nov 2009 11:25:11 +0000 (+1300) Subject: Polish rfc1738 library code. Add cppunit tests. X-Git-Tag: SQUID_3_2_0_1~594 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1fa9b1a75e167be8035e2408e17d49a37dcbe1d4;p=thirdparty%2Fsquid.git Polish rfc1738 library code. Add cppunit tests. * Adds API header file for this library. * Reveals the do_escape API and creates meaningful flags for its API. * Adds documentation. * Convert original unit tests by Robert Collins to cppunit code * Add new tests based on work for Samba by Andrew Bartlett --- diff --git a/helpers/basic_auth/LDAP/basic_ldap_auth.cc b/helpers/basic_auth/LDAP/basic_ldap_auth.cc index eaee9ce809..02b626c71c 100644 --- a/helpers/basic_auth/LDAP/basic_ldap_auth.cc +++ b/helpers/basic_auth/LDAP/basic_ldap_auth.cc @@ -84,6 +84,7 @@ #define LDAP_DEPRECATED 1 +#include "rfc1738.h" #include "util.h" #include diff --git a/helpers/basic_auth/MSNT/msntauth.c b/helpers/basic_auth/MSNT/msntauth.c index a877089fe7..ab9f04dc72 100644 --- a/helpers/basic_auth/MSNT/msntauth.c +++ b/helpers/basic_auth/MSNT/msntauth.c @@ -31,6 +31,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include "rfc1738.h" #include "util.h" #include diff --git a/helpers/basic_auth/NCSA/basic_ncsa_auth.cc b/helpers/basic_auth/NCSA/basic_ncsa_auth.cc index a7f3de977a..2f49f45ec7 100644 --- a/helpers/basic_auth/NCSA/basic_ncsa_auth.cc +++ b/helpers/basic_auth/NCSA/basic_ncsa_auth.cc @@ -18,6 +18,7 @@ */ #include "config.h" +#include "rfc1738.h" #if HAVE_STDIO_H #include diff --git a/helpers/basic_auth/PAM/pam_auth.c b/helpers/basic_auth/PAM/pam_auth.c index 90174b8942..a80ac1d513 100644 --- a/helpers/basic_auth/PAM/pam_auth.c +++ b/helpers/basic_auth/PAM/pam_auth.c @@ -63,6 +63,7 @@ * Compile this program with: gcc -o pam_auth pam_auth.c -lpam -ldl */ +#include "rfc1738.h" #include "util.h" #include diff --git a/helpers/basic_auth/SASL/sasl_auth.c b/helpers/basic_auth/SASL/sasl_auth.c index f1ff3c4e39..6efa30dfea 100644 --- a/helpers/basic_auth/SASL/sasl_auth.c +++ b/helpers/basic_auth/SASL/sasl_auth.c @@ -31,6 +31,7 @@ #include #include +#include "rfc1738.h" #include "util.h" #ifdef HAVE_SASL_SASL_H diff --git a/helpers/basic_auth/YP/yp_auth.c b/helpers/basic_auth/YP/yp_auth.c index 4f6d23634f..379adabe04 100644 --- a/helpers/basic_auth/YP/yp_auth.c +++ b/helpers/basic_auth/YP/yp_auth.c @@ -4,6 +4,8 @@ */ #include "config.h" +#include "rfc1738.h" + #if HAVE_STDIO_H #include #endif diff --git a/helpers/basic_auth/getpwnam/basic_getpwnam_auth.cc b/helpers/basic_auth/getpwnam/basic_getpwnam_auth.cc index b119ebf67e..a75b8b4f07 100644 --- a/helpers/basic_auth/getpwnam/basic_getpwnam_auth.cc +++ b/helpers/basic_auth/getpwnam/basic_getpwnam_auth.cc @@ -25,6 +25,7 @@ */ #include "config.h" +#include "rfc1738.h" #if HAVE_STDIO_H #include diff --git a/helpers/external_acl/ip_user/main.c b/helpers/external_acl/ip_user/main.c index 5b03b56595..f9537572ef 100644 --- a/helpers/external_acl/ip_user/main.c +++ b/helpers/external_acl/ip_user/main.c @@ -19,6 +19,7 @@ * */ +#include "rfc1738.h" #include "util.h" #include diff --git a/helpers/external_acl/ldap_group/squid_ldap_group.c b/helpers/external_acl/ldap_group/squid_ldap_group.c index afdb8d491a..a89c3f43aa 100644 --- a/helpers/external_acl/ldap_group/squid_ldap_group.c +++ b/helpers/external_acl/ldap_group/squid_ldap_group.c @@ -35,6 +35,7 @@ #define LDAP_DEPRECATED 1 +#include "rfc1738.h" #include "util.h" #include diff --git a/helpers/external_acl/unix_group/check_group.c b/helpers/external_acl/unix_group/check_group.c index eb277ad4e0..f7d1c4bd36 100644 --- a/helpers/external_acl/unix_group/check_group.c +++ b/helpers/external_acl/unix_group/check_group.c @@ -52,6 +52,7 @@ * */ +#include "rfc1738.h" #include "util.h" #include diff --git a/include/rfc1738.h b/include/rfc1738.h new file mode 100644 index 0000000000..b3538ecad0 --- /dev/null +++ b/include/rfc1738.h @@ -0,0 +1,45 @@ +#ifndef _SQUID_INCLUDE_RFC1738_H +#define _SQUID_INCLUDE_RFC1738_H + +/* for SQUIDCEXTERN */ +#include "config.h" + + +/* Encoder rfc1738_do_escape flag values. */ +#define RFC1738_ESCAPE_UNSAFE 0 +#define RFC1738_ESCAPE_RESERVED 1 +#define RFC1738_ESCAPE_UNESCAPED -1 + + +/** + * \group rfc1738 RFC 1738 URL-escaping library + * + * Public API is formed of a triplet of encode functions mapping to the rfc1738_do_encode() engine. + * + * ASCII characters are split into three groups: + * \item SAFE Characters which are safe to occur in any URL. For example A,B,C + * \item UNSAFE Characters which are completely usafe to occur in any URL. For example; backspace, tab, space, newline + * \item RESERVED Characters which are reserved for special meaning and may only occur in certain parts of a URL. + * + * Returns a static buffer containing the RFC 1738 compliant, escaped version of the given url. + * + * \param flags RFC1738_ESCAPE_UNSAFE Only encode unsafe characters. Ignore reserved. + * \param flags RFC1738_ESCAPE_RESERVED Encode all unsafe and reserved characters. + * \param flags RFC1738_ESCAPE_UNESCAPED Encode all unsafe characters which have not already been encoded. + */ +SQUIDCEXTERN char *rfc1738_do_escape(const char *url, int flags); + +/* Old API functions */ +#define rfc1738_escape(x) rfc1738_do_escape(x, RFC1738_ESCAPE_UNSAFE) +#define rfc1738_escape_part(x) rfc1738_do_escape(x, RFC1738_ESCAPE_RESERVED) +#define rfc1738_escape_unescaped(x) rfc1738_do_escape(x, RFC1738_ESCAPE_UNESCAPED) + + +/** + * Unescape a URL string according to RFC 1738 specification. + * String is unescaped in-place + */ +SQUIDCEXTERN void rfc1738_unescape(char *url); + + +#endif /* _SQUID_INCLUDE_RFC1738_H */ diff --git a/include/util.h b/include/util.h index 28f56d29bf..0bf570b4c2 100644 --- a/include/util.h +++ b/include/util.h @@ -90,12 +90,6 @@ SQUIDCEXTERN void xxfree(const void *); #include "SquidNew.h" #endif -/* rfc1738.c */ -SQUIDCEXTERN char *rfc1738_escape(const char *); -SQUIDCEXTERN char *rfc1738_escape_unescaped(const char *); -SQUIDCEXTERN char *rfc1738_escape_part(const char *); -SQUIDCEXTERN void rfc1738_unescape(char *); - /* charset.c */ SQUIDCEXTERN char *latin1_to_utf8(char *out, size_t size, const char *in); diff --git a/lib/Makefile.am b/lib/Makefile.am index 02bee1739a..444b10dd35 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -99,6 +99,8 @@ tests_testAll_SOURCES= \ tests/testArray.cc \ tests/testRFC1035.h \ tests/testRFC1035.cc \ + tests/testRFC1738.h \ + tests/testRFC1738.cc \ tests/testMain.cc \ $(XPROF_STATS_SOURCE) \ $(WIN32SRC) \ diff --git a/lib/rfc1738.c b/lib/rfc1738.c index bba0a5d6a7..a0edaf7576 100644 --- a/lib/rfc1738.c +++ b/lib/rfc1738.c @@ -33,6 +33,8 @@ */ #include "config.h" +#include "rfc1738.h" +#include "util.h" #if HAVE_STDIO_H #include @@ -41,8 +43,6 @@ #include #endif -#include "util.h" - /* * RFC 1738 defines that these characters should be escaped, as well * any non-US-ASCII character or anything between 0x00 - 0x1F. @@ -82,8 +82,8 @@ static char rfc1738_reserved_chars[] = { * rfc1738_escape - Returns a static buffer contains the RFC 1738 * compliant, escaped version of the given url. */ -static char * -rfc1738_do_escape(const char *url, int encode_reserved) +char * +rfc1738_do_escape(const char *url, int flags) { static char *buf; static size_t bufsize = 0; @@ -94,7 +94,7 @@ rfc1738_do_escape(const char *url, int encode_reserved) if (buf == NULL || strlen(url) * 3 > bufsize) { xfree(buf); bufsize = strlen(url) * 3 + 1; - buf = xcalloc(bufsize, 1); + buf = (char*)xcalloc(bufsize, 1); } for (p = url, q = buf; *p != '\0' && q < (buf + bufsize - 1); p++, q++) { do_escape = 0; @@ -107,10 +107,10 @@ rfc1738_do_escape(const char *url, int encode_reserved) } } /* Handle % separately */ - if (encode_reserved >= 0 && *p == '%') + if (flags != RFC1738_ESCAPE_UNESCAPED && *p == '%') do_escape = 1; /* RFC 1738 defines these chars as reserved */ - for (i = 0; i < sizeof(rfc1738_reserved_chars) && encode_reserved > 0; i++) { + for (i = 0; i < sizeof(rfc1738_reserved_chars) && flags == RFC1738_ESCAPE_RESERVED; i++) { if (*p == rfc1738_reserved_chars[i]) { do_escape = 1; break; @@ -143,6 +143,7 @@ rfc1738_do_escape(const char *url, int encode_reserved) return (buf); } +#if 0 /* legacy API */ /* * rfc1738_escape - Returns a static buffer that contains the RFC * 1738 compliant, escaped version of the given url. @@ -172,6 +173,7 @@ rfc1738_escape_part(const char *url) { return rfc1738_do_escape(url, 1); } +#endif /* 0 */ /* * rfc1738_unescape() - Converts escaped characters (%xy numbers) in diff --git a/lib/tests/testRFC1738.cc b/lib/tests/testRFC1738.cc new file mode 100644 index 0000000000..5ee0d5e28c --- /dev/null +++ b/lib/tests/testRFC1738.cc @@ -0,0 +1,155 @@ +#include "config.h" + +#if HAVE_ASSERT_H +#include +#endif + +#include "testRFC1738.h" + +/* Being a C library code it is best bodily included and tested with C++ type-safe techniques. */ +#include "lib/rfc1738.c" + +CPPUNIT_TEST_SUITE_REGISTRATION( testRFC1738 ); + +/* Regular Format de-coding tests */ +void testRFC1738::testUrlDecode() +{ + char *unescaped_str; + + /* regular URL-path */ + unescaped_str = xstrdup("%2Fdata%2Fsource%2Fpath"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "/data/source/path",18)==0); + xfree(unescaped_str); + + /* path in full URL */ + unescaped_str = xstrdup("http://foo.invalid%2Fdata%2Fsource%2Fpath"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "http://foo.invalid/data/source/path",36)==0); + xfree(unescaped_str); + +// TODO query string... + + /* Newline %0A encoded */ + unescaped_str = xstrdup("w%0Ard"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "w\nrd",5)==0); + xfree(unescaped_str); + + /* Handle Un-encoded % */ + unescaped_str = xstrdup("w%rd"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "w%rd",5)==0); + xfree(unescaped_str); + + /* Handle encoded % */ + unescaped_str = xstrdup("w%%rd"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "w%%rd",6)==0); + xfree(unescaped_str); + + /* Handle mixed-encoded % */ + unescaped_str = xstrdup("w%%%rd"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "w%%rd",6)==0); + xfree(unescaped_str); + + /* A corrupt string */ + unescaped_str = xstrdup("Bad String %1"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "Bad String %1",14)==0); + xfree(unescaped_str); + + + /* A partly corrupt string */ + unescaped_str = xstrdup("Bad String %1A%3"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "Bad String \032%3",15)==0); + xfree(unescaped_str); + + /* A non corrupt string */ + unescaped_str = xstrdup("Good String %1A"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "Good String \032",14)==0); + xfree(unescaped_str); +} + +/** + * Public API is formed of a triplet of encode functions mapping to the rfc1738_do_encode() engine. + * + * Flags: + * rfc1738_escape == 0 + * rfc1738_escape_unescaped == -1 + * rfc1738_escape_part == 1 + */ +void testRFC1738::testUrlEncode() +{ + char *result; + +#define RFC1738_ESCAPE_UNSAFE 0 +#define RFC1738_ESCAPE_RESERVED 1 +#define RFC1738_ESCAPE_UNESCAPED -1 + + /* TEST: Escaping only unsafe characters */ + + /* regular URL (no encoding needed) */ + result = rfc1738_do_escape("http://foo.invalid/data/source/path", RFC1738_ESCAPE_UNSAFE); + CPPUNIT_ASSERT(memcmp(result, "http://foo.invalid/data/source/path",36)==0); + + /* long string of unsafe # characters */ + result = rfc1738_do_escape("################ ################ ################ ################ ################ ################ ################ ################", RFC1738_ESCAPE_UNSAFE); + CPPUNIT_ASSERT(memcmp(result, "%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23",406)==0); + + + /* TEST: escaping only reserved characters */ + + /* regular URL (full encoding requested) */ + result = rfc1738_do_escape("http://foo.invalid/data/source/path", RFC1738_ESCAPE_RESERVED); + CPPUNIT_ASSERT(memcmp(result, "http%3A%2F%2Ffoo.invalid%2Fdata%2Fsource%2Fpath",48)==0); + + /* regular path (encoding wanted for ALL special chars) */ + result = rfc1738_do_escape("/data/source/path", RFC1738_ESCAPE_RESERVED); + CPPUNIT_ASSERT(memcmp(result, "%2Fdata%2Fsource%2Fpath",24)==0); + + + /* TEST: safety-escaping a string already partially escaped */ + + /* escaping of dangerous characters in a partially escaped string */ + result = rfc1738_do_escape("http://foo.invalid/data%2Fsource[]", RFC1738_ESCAPE_UNESCAPED); + CPPUNIT_ASSERT(memcmp(result, "http://foo.invalid/data%2Fsource%5B%5D",39)==0); + + /* escaping of hexadecimal 0xFF characters in a partially escaped string */ + result = rfc1738_do_escape("http://foo.invalid/data%2Fsource\xFF\xFF", RFC1738_ESCAPE_UNESCAPED); + CPPUNIT_ASSERT(memcmp(result, "http://foo.invalid/data%2Fsource%FF%FF",39)==0); + +} + +/** SECURITY BUG TESTS: avoid null truncation attacks by skipping %00 bytes */ +void testRFC1738::PercentZeroNullDecoding() +{ + char *unescaped_str; + + /* Attack with %00 encoded NULL */ + unescaped_str = xstrdup("w%00rd"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "w%00rd",7)==0); + xfree(unescaped_str); + + /* Attack with %0 encoded NULL */ + unescaped_str = xstrdup("w%0rd"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "w%0rd",6)==0); + xfree(unescaped_str); + + /* Handle '0' bytes embeded in encoded % */ + unescaped_str = xstrdup("w%%00%rd"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "w%00%rd",8)==0); + xfree(unescaped_str); + + /* Handle NULL bytes with encoded % */ + unescaped_str = xstrdup("w%%%00%rd"); + rfc1738_unescape(unescaped_str); + CPPUNIT_ASSERT(memcmp(unescaped_str, "w%%00%rd",9)==0); + xfree(unescaped_str); +} diff --git a/lib/tests/testRFC1738.h b/lib/tests/testRFC1738.h new file mode 100644 index 0000000000..624f72025e --- /dev/null +++ b/lib/tests/testRFC1738.h @@ -0,0 +1,28 @@ +#ifndef SQUID_LIB_TEST_RFC1738_H +#define SQUID_LIB_TEST_RFC1738_H + +#include + +/** + * Test the URL coder RFC 1738 Engine + */ +class testRFC1738 : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE( testRFC1738 ); +// CPPUNIT_TEST( testUrlDecode ); +// CPPUNIT_TEST( testUrlEncode ); + + CPPUNIT_TEST( PercentZeroNullDecoding ); + CPPUNIT_TEST_SUITE_END(); + +public: + +protected: + void testUrlDecode(); + void testUrlEncode(); + + // bugs. + void PercentZeroNullDecoding(); +}; + +#endif /* SQUID_LIB_TEST_RFC1738_H */ diff --git a/src/access_log.cc b/src/access_log.cc index a69fa2984b..d08280e75a 100644 --- a/src/access_log.cc +++ b/src/access_log.cc @@ -49,6 +49,7 @@ #include "HttpReply.h" #include "HttpRequest.h" #include "MemBuf.h" +#include "rfc1738.h" #include "SquidTime.h" static void accessLogSquid(AccessLogEntry * al, Logfile * logfile); diff --git a/src/acl/Url.cc b/src/acl/Url.cc index bd26c08113..a7366b6a55 100644 --- a/src/acl/Url.cc +++ b/src/acl/Url.cc @@ -38,7 +38,7 @@ #include "acl/Url.h" #include "acl/Checklist.h" #include "acl/RegexData.h" - +#include "rfc1738.h" int ACLUrlStrategy::match (ACLData * &data, ACLFilledChecklist *checklist) diff --git a/src/acl/UrlPath.cc b/src/acl/UrlPath.cc index c36d170c86..cd1a8bae52 100644 --- a/src/acl/UrlPath.cc +++ b/src/acl/UrlPath.cc @@ -39,7 +39,7 @@ #include "acl/Checklist.h" #include "acl/RegexData.h" #include "HttpRequest.h" - +#include "rfc1738.h" int ACLUrlPathStrategy::match (ACLData * &data, ACLFilledChecklist *checklist) diff --git a/src/auth/basic/auth_basic.cc b/src/auth/basic/auth_basic.cc index 9aa07bb53a..aae8d6a2b6 100644 --- a/src/auth/basic/auth_basic.cc +++ b/src/auth/basic/auth_basic.cc @@ -44,6 +44,7 @@ #include "Store.h" #include "HttpReply.h" #include "basicScheme.h" +#include "rfc1738.h" #include "wordlist.h" #include "SquidTime.h" diff --git a/src/cache_cf.cc b/src/cache_cf.cc index daec10505c..b943ba14cb 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -46,6 +46,7 @@ #include "acl/Gadgets.h" #include "StoreFileSystem.h" #include "Parsing.h" +#include "rfc1738.h" #include "MemBuf.h" #include "wordlist.h" #include "ident/Config.h" diff --git a/src/client_side.cc b/src/client_side.cc index d1fa9d50a5..f0de89502d 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -105,6 +105,7 @@ #include "SquidTime.h" #include "ChunkedCodingParser.h" #include "eui/Config.h" +#include "rfc1738.h" #if LINGERING_CLOSE #define comm_close comm_lingering_close diff --git a/src/errorpage.cc b/src/errorpage.cc index 1754494647..5a70d686e0 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -43,6 +43,7 @@ #include "MemObject.h" #include "fde.h" #include "MemBuf.h" +#include "rfc1738.h" #include "URLScheme.h" #include "wordlist.h" diff --git a/src/external_acl.cc b/src/external_acl.cc index 3c4f737084..90ff036841 100644 --- a/src/external_acl.cc +++ b/src/external_acl.cc @@ -60,6 +60,7 @@ #include "auth/Gadgets.h" #include "helper.h" #include "MemBuf.h" +#include "rfc1738.h" #include "URLScheme.h" #include "wordlist.h" diff --git a/src/ftp.cc b/src/ftp.cc index 5cc847a158..c8a48e4ca9 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -54,6 +54,7 @@ #include "SquidTime.h" #include "URLScheme.h" #include "SquidString.h" +#include "rfc1738.h" /** \defgroup ServerProtocolFTPInternal Server-Side FTP Internals diff --git a/src/gopher.cc b/src/gopher.cc index 532151917a..4003b70543 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -45,6 +45,7 @@ #endif #include "MemBuf.h" #include "forward.h" +#include "rfc1738.h" #include "SquidTime.h" /** diff --git a/src/http.cc b/src/http.cc index c45c6a1566..749a070424 100644 --- a/src/http.cc +++ b/src/http.cc @@ -56,6 +56,7 @@ #include "MemBuf.h" #include "MemObject.h" #include "protos.h" +#include "rfc1738.h" #include "SquidTime.h" #include "Store.h" #include "TextException.h" diff --git a/src/icp_v2.cc b/src/icp_v2.cc index 32b2e72f33..cbfed7a359 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -48,6 +48,7 @@ #include "SwapDir.h" #include "icmp/net_db.h" #include "ip/IpAddress.h" +#include "rfc1738.h" /// \ingroup ServerProtocolICPInternal2 static void icpLogIcp(const IpAddress &, log_type, int, const char *, int); diff --git a/src/ipc.cc b/src/ipc.cc index e886e95710..9e7968d80a 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -34,6 +34,7 @@ #include "comm.h" #include "fde.h" #include "ip/IpAddress.h" +#include "rfc1738.h" static const char *hello_string = "hi there\n"; #define HELLO_BUF_SZ 32 diff --git a/src/redirect.cc b/src/redirect.cc index 93fe7d43c8..04bbe8a08a 100644 --- a/src/redirect.cc +++ b/src/redirect.cc @@ -43,6 +43,7 @@ #include "HttpRequest.h" #include "client_side.h" #include "helper.h" +#include "rfc1738.h" typedef struct { void *data; diff --git a/src/url.cc b/src/url.cc index 8e105266bc..d9ac26f6d7 100644 --- a/src/url.cc +++ b/src/url.cc @@ -36,6 +36,7 @@ #include "URL.h" #include "HttpRequest.h" #include "URLScheme.h" +#include "rfc1738.h" static HttpRequest *urnParse(const HttpRequestMethod& method, char *urn); static const char valid_hostname_chars_u[] = diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 469bf7d22a..513aea4c4f 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -17,7 +17,7 @@ LDADD = \ $(top_builddir)/src/globals.o \ $(top_builddir)/src/time.o -EXTRA_PROGRAMS = mem_node_test membanger splay tcp-banger2 rfc1738 +EXTRA_PROGRAMS = mem_node_test membanger splay tcp-banger2 EXTRA_DIST = testheaders.sh @@ -35,7 +35,6 @@ TESTS += debug \ syntheticoperators \ VirtualDeleteOperator \ StackTest \ - rfc1738 \ refcount\ splay\ MemPoolTest\ @@ -50,7 +49,6 @@ check_PROGRAMS += debug \ mem_node_test\ mem_hdr_test \ refcount\ - rfc1738\ splay \ StackTest \ syntheticoperators \ @@ -77,8 +75,6 @@ StackTest_SOURCES = StackTest.cc $(DEBUG_SOURCE) syntheticoperators_SOURCES = syntheticoperators.cc $(DEBUG_SOURCE) VirtualDeleteOperator_SOURCES = VirtualDeleteOperator.cc $(DEBUG_SOURCE) -rfc1738_SOURCES = rfc1738.cc - ## membanger won't link today. Bitrot.. ##CC = gcc ##CFLAGS = -g -Wall -I../include -I../src diff --git a/test-suite/rfc1738.cc b/test-suite/rfc1738.cc deleted file mode 100644 index 1c4218c0b1..0000000000 --- a/test-suite/rfc1738.cc +++ /dev/null @@ -1,79 +0,0 @@ - -/* - * $Id$ - * - * DEBUG: section xx RFC 1738 string [un]escaping - * AUTHOR: Robert Collins - * - * SQUID Web Proxy Cache http://www.squid-cache.org/ - * ---------------------------------------------------------- - * - * Squid is the result of efforts by numerous individuals from - * the Internet community; see the CONTRIBUTORS file for full - * details. Many organizations have provided support for Squid's - * development; see the SPONSORS file for full details. Squid is - * Copyrighted (C) 2001 by the Regents of the University of - * California; see the COPYRIGHT file for full details. Squid - * incorporates software developed and/or copyrighted by other - * sources; see the CREDITS file for full details. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. - * - * Copyright (c) 2003 Robert Collins - */ - -#include "squid.h" -#include "util.h" -/* testing: -SQUIDCEXTERN char *rfc1738_escape(const char *); -SQUIDCEXTERN char *rfc1738_escape_unescaped(const char *); -SQUIDCEXTERN char *rfc1738_escape_part(const char *); -SQUIDCEXTERN void rfc1738_unescape(char *); -*/ - -/* A corrupt string */ -#define BADSTRING "An Escaped %1" -/* A partly corrupt string */ -#define CASE1 "An escaped %1A%3" -#define RESULT1 "An escaped \032%3" -/* A non corrupt string */ -#define GOODSTRING "An Escaped %1A" -#define GOODUSTRING "An Escaped \032" - -void -testAString(char const *aString, char const *aResult) -{ - char *escapedString; - escapedString = xstrdup (aString); - rfc1738_unescape(escapedString); - if (strcmp(escapedString, aResult)) - exit (1); - safe_free (escapedString); -} - -void -testUnescaping() -{ - testAString(BADSTRING,BADSTRING); - testAString(GOODSTRING, GOODUSTRING); - testAString(CASE1, RESULT1); -} - -int -main (int argc, char **argv) -{ - testUnescaping(); - return 0; -} diff --git a/tools/cachemgr.cc b/tools/cachemgr.cc index e71920c991..25800b8cf7 100644 --- a/tools/cachemgr.cc +++ b/tools/cachemgr.cc @@ -31,6 +31,7 @@ */ #include "config.h" +#include "rfc1738.h" #if HAVE_UNISTD_H #include