Benno Rice wrote:
Address Alex and Amos' comments.
<snip>
/*
+ * Test if a URL is relative.
+ *
+ * RFC 2396, Section 5 (Page 17) implies that in a relative URL, a '/' will
+ * appear before a ':'.
+ */
+bool
+urlIsRelative(const char *url)
+{
+ const char *p;
+
+ if (url == NULL) {
+ return (false);
+ }
+ if (*url == '\0') {
+ return (false);
+ }
Those can deflate down to:
if(url == NULL || *url == '\0')
return false;
+
+ for (p = url; *p != '\0' && *p != ':' && *p != '/'; p++);
+
+ if (*p == ':') {
+ return (false);
+ }
+ return (true);
+}
+
+/*
+ * Convert a relative URL to an absolute URL using the context of a given
+ * request.
+ *
+ * It is assumed that you have already ensured that the URL is relative.
+ *
+ * If NULL is returned it is an indication that the method in use in the
+ * request does not distinguish between relative and absolute and you should
+ * use the url unchanged.
+ *
+ * If non-NULL is returned, it is up to the caller to free the resulting
+ * memory using safe_free().
+ */
+char *
+urlMakeAbsolute(const HttpRequest * req, const char *relUrl)
+{
+
+ if (req->method.id() == METHOD_CONNECT) {
+ return (NULL);
+ }
+
+ char *urlbuf = (char *)xmalloc(MAX_URL * sizeof(char));
FYI, in pedantic C++ this is:
char *urlbuf = static_cast<char*>( xmalloc(MAX_URL * sizeof(char)) );
to show that its a cast we need and not to be 'cleaned' away.
No requirement to use it though.
bb:approve
since style fixes are only style.
Amos
--
Please use Squid 2.7.STABLE4 or 3.0.STABLE8