-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.119 2009/04/17 11:38:28 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/filters.c,v $
*
* Revisions :
* $Log: filters.c,v $
+ * Revision 1.119 2009/04/17 11:38:28 fabiankeil
+ * Add and use parse_forwarder_address() to reduce code duplication.
+ *
+ * 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.
*
#include <string.h>
#include <assert.h>
-#ifdef HAVE_GETADDRINFO
+#ifdef HAVE_RFC2553
#include <netdb.h>
#include <sys/socket.h>
-#endif /* def HAVE_GETADDRINFO */
+#endif /* def HAVE_RFC2553 */
#ifndef _WIN32
#ifndef __OS2__
static jb_err prepare_for_filtering(struct client_state *csp);
#ifdef FEATURE_ACL
-#ifdef HAVE_GETADDRINFO
+#ifdef HAVE_RFC2553
/*********************************************************************
*
* Function : sockaddr_storage_to_ip
return 1;
}
-#endif /* def HAVE_GETADDRINFO */
+#endif /* def HAVE_RFC2553 */
/*********************************************************************
while (acl != NULL)
{
if (
-#ifdef HAVE_GETADDRINFO
+#ifdef HAVE_RFC2553
match_sockaddr(&acl->src->addr, &acl->src->mask, &csp->tcp_addr)
#else
(csp->ip_addr_long & acl->src->mask) == acl->src->addr
}
}
else if (
-#ifdef HAVE_GETADDRINFO
+#ifdef HAVE_RFC2553
/*
* XXX: An undefined acl->dst is full of zeros and should be
* considered a wildcard address. sockaddr_storage_to_ip()
int acl_addr(const char *aspec, struct access_control_addr *aca)
{
int i, masklength;
-#ifdef HAVE_GETADDRINFO
+#ifdef HAVE_RFC2553
struct addrinfo hints, *result;
uint8_t *mask_data;
in_port_t *mask_port;
unsigned int addr_len;
#else
long port;
-#endif /* def HAVE_GETADDRINFO */
+#endif /* def HAVE_RFC2553 */
char *p;
char *acl_spec = NULL;
-#ifdef HAVE_GETADDRINFO
+#ifdef HAVE_RFC2553
/* XXX: Depend on ai_family */
masklength = 128;
#else
}
if ((masklength < 0) ||
-#ifdef HAVE_GETADDRINFO
+#ifdef HAVE_RFC2553
(masklength > 128)
#else
(masklength > 32)
p = strchr(acl_spec, ':');
}
-#ifdef HAVE_GETADDRINFO
+#ifdef HAVE_RFC2553
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
/* XXX: This will be logged as parse error. */
return(-1);
}
-#endif /* def HAVE_GETADDRINFO */
+#endif /* def HAVE_RFC2553 */
/* build the netmask */
-#ifdef HAVE_GETADDRINFO
+#ifdef HAVE_RFC2553
/* Clip masklength according to current family. */
if ((aca->addr.ss_family == AF_INET) && (masklength > 32))
{
* (i.e. save on the network portion of the address).
*/
aca->addr = aca->addr & aca->mask;
-#endif /* def HAVE_GETADDRINFO */
+#endif /* def HAVE_RFC2553 */
return(0);
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);