-const char filters_rcs[] = "$Id: filters.c,v 1.117 2009/04/17 11:35:28 fabiankeil Exp $";
+const char filters_rcs[] = "$Id: filters.c,v 1.118 2009/04/17 11:37:03 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/filters.c,v $
*
* Revisions :
* $Log: filters.c,v $
+ * Revision 1.118 2009/04/17 11:37:03 fabiankeil
+ * Allow IPv6 addresses in forward-override{}.
+ *
* Revision 1.117 2009/04/17 11:35:28 fabiankeil
* Fix compiler warning.
*
if (NULL != socks_proxy)
{
/* Parse the SOCKS proxy host[:port] */
- char *p = socks_proxy;
- fwd->gateway_host = strdup(socks_proxy);
-
- if ((*fwd->gateway_host == '[')
- && (NULL != (p = strchr(fwd->gateway_host, ']'))))
- {
- *p++ = '\0';
- memmove(fwd->gateway_host, fwd->gateway_host + 1,
- (size_t)(p - fwd->gateway_host));
- if (*p == ':')
- {
- fwd->gateway_port = (int)strtol(++p, NULL, 0);
- }
- }
- else if (NULL != (p = strchr(fwd->gateway_host, ':')))
- {
- *p++ = '\0';
- fwd->gateway_port = (int)strtol(p, NULL, 0);
- }
-
- if (fwd->gateway_port <= 0)
- {
- fwd->gateway_port = 1080;
- }
+ fwd->gateway_port = 1080;
+ parse_forwarder_address(socks_proxy,
+ &fwd->gateway_host, &fwd->gateway_port);
http_parent = vec[2];
}
/* Parse http forwarding settings */
if (strcmp(http_parent, ".") != 0)
{
- char *p = http_parent;
- fwd->forward_host = strdup(http_parent);
-
- if ((*fwd->forward_host == '[')
- && (NULL != (p = strchr(fwd->forward_host, ']'))))
- {
- *p++ = '\0';
- memmove(fwd->forward_host, fwd->forward_host + 1,
- (size_t)(p - fwd->forward_host));
- if (*p == ':')
- {
- fwd->forward_port = (int)strtol(++p, NULL, 0);
- }
- }
- else if (NULL != (p = strchr(fwd->forward_host, ':')))
- {
- *p++ = '\0';
- fwd->forward_port = (int)strtol(p, NULL, 0);
- }
-
- if (fwd->forward_port <= 0)
- {
- fwd->forward_port = 8000;
- }
+ fwd->forward_port = 8000;
+ parse_forwarder_address(http_parent,
+ &fwd->forward_host, &fwd->forward_port);
}
assert (NULL != fwd);
-const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.94 2009/04/17 11:27:49 fabiankeil Exp $";
+const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.95 2009/04/17 11:34:34 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
*
* Revisions :
* $Log: loadcfg.c,v $
+ * Revision 1.95 2009/04/17 11:34:34 fabiankeil
+ * Style cosmetics for the IPv6 code.
+ *
* Revision 1.94 2009/04/17 11:27:49 fabiankeil
* Petr Pisar's privoxy-3.0.12-ipv6-3.diff.
*
if (strcmp(p, ".") != 0)
{
- cur_fwd->forward_host = strdup(p);
-
- if ((*cur_fwd->forward_host == '[')
- && (NULL != (p = strchr(cur_fwd->forward_host, ']'))))
- {
- *p++ = '\0';
- memmove(cur_fwd->forward_host, cur_fwd->forward_host + 1,
- (size_t)(p - cur_fwd->forward_host));
- if (*p == ':')
- {
- cur_fwd->forward_port = atoi(++p);
- }
- }
- else if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
- {
- *p++ = '\0';
- cur_fwd->forward_port = atoi(p);
- }
-
- if (cur_fwd->forward_port <= 0)
- {
- cur_fwd->forward_port = 8000;
- }
+ cur_fwd->forward_port = 8000;
+ parse_forwarder_address(p, &cur_fwd->forward_host,
+ &cur_fwd->forward_port);
}
/* Add to list. */
/* Parse the SOCKS proxy host[:port] */
p = vec[1];
+ /* XXX: This check looks like a bug. */
if (strcmp(p, ".") != 0)
{
- cur_fwd->gateway_host = strdup(p);
-
- if ((*cur_fwd->gateway_host == '[')
- && (NULL != (p = strchr(cur_fwd->gateway_host, ']'))))
- {
- *p++ = '\0';
- memmove(cur_fwd->gateway_host, cur_fwd->gateway_host + 1,
- (size_t)(p - cur_fwd->gateway_host));
- if (*p == ':')
- {
- cur_fwd->gateway_port = atoi(++p);
- }
- }
- else if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
- {
- *p++ = '\0';
- cur_fwd->gateway_port = atoi(p);
- }
-
- if (cur_fwd->gateway_port <= 0)
- {
- cur_fwd->gateway_port = 1080;
- }
+ cur_fwd->gateway_port = 1080;
+ parse_forwarder_address(p, &cur_fwd->gateway_host,
+ &cur_fwd->gateway_port);
}
/* Parse the parent HTTP proxy host[:port] */
if (strcmp(p, ".") != 0)
{
- cur_fwd->forward_host = strdup(p);
-
- if ((*cur_fwd->forward_host == '[')
- && (NULL != (p = strchr(cur_fwd->forward_host, ']'))))
- {
- *p++ = '\0';
- memmove(cur_fwd->forward_host, cur_fwd->forward_host + 1,
- (size_t)(p - cur_fwd->forward_host));
- if (*p == ':')
- {
- cur_fwd->forward_port = atoi(++p);
- }
- }
- else if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
- {
- *p++ = '\0';
- cur_fwd->forward_port = atoi(p);
- }
-
- if (cur_fwd->forward_port <= 0)
- {
- cur_fwd->forward_port = 8000;
- }
+ cur_fwd->forward_port = 8000;
+ parse_forwarder_address(p, &cur_fwd->forward_host,
+ &cur_fwd->forward_port);
}
/* Add to list. */
/* Parse the SOCKS proxy host[:port] */
p = vec[1];
- cur_fwd->gateway_host = strdup(p);
-
- if ((*cur_fwd->gateway_host == '[')
- && (NULL != (p = strchr(cur_fwd->gateway_host, ']'))))
- {
- *p++ = '\0';
- memmove(cur_fwd->gateway_host, cur_fwd->gateway_host + 1,
- (size_t)(p - cur_fwd->gateway_host));
- if (*p == ':')
- {
- cur_fwd->gateway_port = atoi(++p);
- }
- }
- else if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
- {
- *p++ = '\0';
- cur_fwd->gateway_port = atoi(p);
- }
-
- if (cur_fwd->gateway_port <= 0)
- {
- cur_fwd->gateway_port = 1080;
- }
+ cur_fwd->gateway_port = 1080;
+ parse_forwarder_address(p, &cur_fwd->gateway_host,
+ &cur_fwd->gateway_port);
/* Parse the parent HTTP proxy host[:port] */
p = vec[2];
if (strcmp(p, ".") != 0)
{
- cur_fwd->forward_host = strdup(p);
-
- if (*cur_fwd->forward_host == '[' &&
- NULL != (p = strchr(cur_fwd->forward_host, ']')))
- {
- *p++ = '\0';
- memmove(cur_fwd->forward_host, cur_fwd->forward_host + 1,
- (size_t) (p - cur_fwd->forward_host));
- if (*p == ':')
- {
- cur_fwd->forward_port = atoi(++p);
- }
- }
- else if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
- {
- *p++ = '\0';
- cur_fwd->forward_port = atoi(p);
- }
-
- if (cur_fwd->forward_port <= 0)
- {
- cur_fwd->forward_port = 8000;
- }
+ cur_fwd->forward_port = 8000;
+ parse_forwarder_address(p, &cur_fwd->forward_host,
+ &cur_fwd->forward_port);
}
/* Add to list. */
-const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.48 2009/04/17 11:27:49 fabiankeil Exp $";
+const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.49 2009/04/17 11:34:35 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/urlmatch.c,v $
*
* Revisions :
* $Log: urlmatch.c,v $
+ * Revision 1.49 2009/04/17 11:34:35 fabiankeil
+ * Style cosmetics for the IPv6 code.
+ *
* Revision 1.48 2009/04/17 11:27:49 fabiankeil
* Petr Pisar's privoxy-3.0.12-ipv6-3.diff.
*
}
+/*********************************************************************
+ *
+ * Function : parse_forwarder_address
+ *
+ * Description : Parse out the host and port from a forwarder address.
+ *
+ * Parameters :
+ * 1 : address = The forwarder address to parse.
+ * 2 : hostname = Used to return the hostname. NULL on error.
+ * 3 : port = Used to return the port. Untouched if no port
+ * is specified.
+ *
+ * Returns : JB_ERR_OK on success
+ * JB_ERR_MEMORY on out of memory
+ * JB_ERR_PARSE on malformed address.
+ *
+ *********************************************************************/
+jb_err parse_forwarder_address(char *address, char **hostname, int *port)
+{
+ char *p = address;
+
+ if ((*address == '[') && (NULL == strchr(address, ']')))
+ {
+ /* XXX: Should do some more validity checks here. */
+ return JB_ERR_PARSE;
+ }
+
+ *hostname = strdup(address);
+ if (NULL == *hostname)
+ {
+ return JB_ERR_MEMORY;
+ }
+
+ if ((**hostname == '[') && (NULL != (p = strchr(*hostname, ']'))))
+ {
+ *p++ = '\0';
+ memmove(*hostname, (*hostname + 1), (size_t)(p - *hostname));
+ if (*p == ':')
+ {
+ *port = (int)strtol(++p, NULL, 0);
+ }
+ }
+ else if (NULL != (p = strchr(*hostname, ':')))
+ {
+ *p++ = '\0';
+ *port = (int)strtol(p, NULL, 0);
+ }
+
+ return JB_ERR_OK;
+
+}
+
+
/*
Local Variables:
tab-width: 3
#ifndef URLMATCH_H_INCLUDED
#define URLMATCH_H_INCLUDED
-#define URLMATCH_H_VERSION "$Id: urlmatch.h,v 1.12 2008/05/04 16:18:32 fabiankeil Exp $"
+#define URLMATCH_H_VERSION "$Id: urlmatch.h,v 1.13 2009/03/02 19:18:11 fabiankeil Exp $"
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/urlmatch.h,v $
*
* Revisions :
* $Log: urlmatch.h,v $
+ * Revision 1.13 2009/03/02 19:18:11 fabiankeil
+ * Streamline parse_http_request()'s prototype. As
+ * cparser pointed out it doesn't actually use csp.
+ *
* Revision 1.12 2008/05/04 16:18:32 fabiankeil
* Provide parse_http_url() with a third parameter to specify
* whether or not URLs without protocol are acceptable.
extern jb_err create_url_spec(struct url_spec *url, char *buf);
extern void free_url_spec(struct url_spec *url);
extern int match_portlist(const char *portlist, int port);
+extern jb_err parse_forwarder_address(char *address, char **hostname, int *port);
/* Revision control strings from this header and associated .c file */