The maximum length of host names is provided by POSIX-compliant
compilers. MAXHOSTNAMELEN is a standard definition relative to those
values so we do not need the magic numbers. The actual RC2181 texts
describe the same limits defined by POSIX IEEE Std 1003.1.
There are some slightly-broken systems which use an older POSIX standard
with much smaller values. But I feel we should obey those system limits
and not pass their kernels larger chunks of data.
This makes use of the standard values instead of our magic numbers.
Votes?
Amos
=== modified file 'compat/Makefile.am'
--- compat/Makefile.am 2009-11-12 01:12:50 +0000
+++ compat/Makefile.am 2009-11-15 03:50:16 +0000
@@ -18,6 +18,7 @@
debug.h \
fdsetsize.h \
osdetect.h \
+ posix.h \
stdvarargs.h \
valgrind.h \
\
=== modified file 'compat/compat.h'
--- compat/compat.h 2009-11-10 14:44:34 +0000
+++ compat/compat.h 2009-11-15 03:49:44 +0000
@@ -79,6 +79,9 @@
/* component-specific portabilities */
/*****************************************************/
+/* some POSIX contants need help. */
+#include "compat/posix.h"
+
/* helper debugging requires some hacks to be clean */
#include "compat/debug.h"
=== added file 'compat/posix.h'
--- compat/posix.h 1970-01-01 00:00:00 +0000
+++ compat/posix.h 2009-11-15 04:13:32 +0000
@@ -0,0 +1,52 @@
+#ifndef SQUID_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef SQUID_COMPAT_POSIX_H
+#define SQUID_COMPAT_POSIX_H
+
+/*
+ * IEEE Std 1003.1:
+ *
+ * "The <limits.h> header shall define various symbolic names."
+ */
+#if HAVE_LIMITS_H
+#include <limits.h>
+#endif
+
+/*
+ * MAXHOSTNAMELEN must be POSIX compliant AND include a terminating NULL.
+ *
+ * \par RFC 2181 section 11:
+ * A full domain name is limited to 255 octets (including the separators).
+ *
+ * \par RFC 1123 section 2.1:
+ * Host software MUST handle host names of up to 63 characters and
+ * SHOULD handle host names of up to 255 characters.
+ *
+ * \par
+ * Also Ref: RFC 1035 Section 3.1 (RFC1035_MAXHOSTNAMESZ)
+ */
+#if !defined(MAXHOSTNAMELEN)
+#define MAXHOSTNAMELEN (_POSIX_HOST_NAME_MAX+1)
+#endif
+
+/*
+ * MAXPATHLEN must be POSIX compliant AND include a terminating NULL
+ */
+#if !defined(MAXPATHLEN)
+#define MAXPATHLEN (_POSIX_PATH_MAX+1)
+#endif
+
+
+/* Legacy bits to remove still... */
+
+// TODO: remove SQUID_MAXPATHLEN macro in favor of MAXPATHLEN
+#define SQUID_MAXPATHLEN MAXPATHLEN
+// TODO: remove RFC2181_HOSTNAMELEN in favor of MAXHOSTNAMELEN
+#define RFC2181_MAXHOSTNAMELEN MAXHOSTNAMELEN
+// TODO: remove SQUIDHOSTNAMELEN in favor of MAXHOSTNAMELEN
+#define SQUIDHOSTNAMELEN RFC2181_MAXHOSTNAMELEN
+
+
+#endif /* SQUID_COMPAT_POSIX_H */
=== removed file 'include/rfc2181.h'
--- include/rfc2181.h 2008-09-29 09:56:06 +0000
+++ include/rfc2181.h 1970-01-01 00:00:00 +0000
@@ -1,27 +0,0 @@
-/*
- * $Id$
- */
-#ifndef _SQUID_INCLUDE_RFC1123_H
-#define _SQUID_INCLUDE_RFC1123_H
-
-/**
- \par RFC 2181 section 11:
- * A full domain name is limited to 255 octets (including the separators).
- *
- \par RFC 1123 section 2.1:
- * Host software MUST handle host names of up to 63 characters and
- * SHOULD handle host names of up to 255 characters.
- *
- *\par
- * Also Ref: RFC 1035 Section 3.1 (RFC1035_MAXHOSTNAMESZ)
- *
- \par
- * Squid accepts up to 255 character Hostname and Fully-Qualified Domain Names.
- * Squid still NULL-terminates its FQDN and hotsname strings.
- */
-#define RFC2181_MAXHOSTNAMELEN 256
-
-/// Back-port macro for old squid code still using SQUIDHOSTNAMELEN without RFC reference.
-#define SQUIDHOSTNAMELEN RFC2181_MAXHOSTNAMELEN
-
-#endif /* _SQUID_INCLUDE_RFC1123_H */
=== modified file 'include/rfc1035.h'
--- include/rfc1035.h 2009-01-21 03:47:47 +0000
+++ include/rfc1035.h 2009-11-15 04:32:47 +0000
@@ -45,17 +45,15 @@
#include <arpa/inet.h>
#endif
-#include "rfc2181.h"
-
/**
\par RFC 1035 Section 3.1:
* To simplify implementations, the total length of a domain name (i.e.,
* label octets and label length octets) is restricted to 255 octets or
* less.
*\par
- * Clarified by RFC 2181 Section 11. (RFC2181_MAXHOSTNAMELEN)
+ * Clarified by RFC 2181 Section 11. (MAXHOSTNAMELEN)
*/
-#define RFC1035_MAXHOSTNAMESZ RFC2181_MAXHOSTNAMELEN
+#define RFC1035_MAXHOSTNAMESZ MAXHOSTNAMELEN
typedef struct _rfc1035_rr rfc1035_rr;
=== modified file 'lib/getfullhostname.c'
--- lib/getfullhostname.c 2009-01-21 03:47:47 +0000
+++ lib/getfullhostname.c 2009-11-15 04:31:29 +0000
@@ -75,9 +75,6 @@
#include <netdb.h>
#endif
-/* for RFC 2181 constants */
-#include "rfc2181.h"
-
/* for xstrncpy() - may need breakign out of there. */
#include "util.h"
=== modified file 'src/HierarchyLogEntry.h'
--- src/HierarchyLogEntry.h 2009-08-23 09:30:49 +0000
+++ src/HierarchyLogEntry.h 2009-11-15 04:38:04 +0000
@@ -36,7 +36,6 @@
#include "hier_code.h"
#include "lookup_t.h"
-#include "rfc2181.h"
#include "PingData.h"
/* for http_status */
=== modified file 'src/globals.h'
--- src/globals.h 2009-08-23 09:30:49 +0000
+++ src/globals.h 2009-11-15 04:35:19 +0000
@@ -36,8 +36,6 @@
#include <stdio.h>
#endif
-#include "rfc2181.h"
-
/* for ERROR_BUF_SZ, BUFSIZ, MAXHTTPPORTS */
#include "defines.h"
=== modified file 'src/squid.h'
--- src/squid.h 2009-02-18 00:18:43 +0000
+++ src/squid.h 2009-11-15 04:34:35 +0000
@@ -139,9 +139,6 @@
#if HAVE_GETOPT_H
#include <getopt.h>
#endif
-#if HAVE_LIMITS_H
-#include <limits.h>
-#endif
#ifdef _SQUID_WIN32_
#include <io.h>
#endif
@@ -201,15 +198,6 @@
#include <math.h>
#endif
-#if 0 // moved to include/rfc2181.h - RFC defined constants
-#define SQUIDHOSTNAMELEN 256
-#endif
-
-#define SQUID_MAXPATHLEN 256
-#ifndef MAXPATHLEN
-#define MAXPATHLEN SQUID_MAXPATHLEN
-#endif
-
#if !HAVE_STRUCT_RUSAGE
/*
* If we don't have getrusage() then we create a fake structure