[prev in list] [next in list] [prev in thread] [next in thread] 

List:       privoxy-commits
Subject:    [privoxy-commits] current filters.c, 1.118, 1.119 loadcfg.c, 1.95,
From:       noreply () sourceforge ! net
Date:       2009-04-17 11:38:30
Message-ID: E1LumOs-0001Jg-BM () 23jxhf1 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Update of /cvsroot/ijbswa/current
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv5056

Modified Files:
	filters.c loadcfg.c urlmatch.c urlmatch.h 
Log Message:
Add and use parse_forwarder_address() to reduce code duplication.


Index: filters.c
===================================================================
RCS file: /cvsroot/ijbswa/current/filters.c,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- filters.c	17 Apr 2009 11:37:03 -0000	1.118
+++ filters.c	17 Apr 2009 11:38:28 -0000	1.119
@@ -40,6 +40,9 @@
  *
  * Revisions   :
  *    $Log$
+ *    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{}.
  *
@@ -2808,30 +2811,9 @@
       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];
       }
@@ -2847,30 +2829,9 @@
    /* 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);

Index: loadcfg.c
===================================================================
RCS file: /cvsroot/ijbswa/current/loadcfg.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- loadcfg.c	17 Apr 2009 11:34:34 -0000	1.95
+++ loadcfg.c	17 Apr 2009 11:38:28 -0000	1.96
@@ -35,6 +35,9 @@
  *
  * Revisions   :
  *    $Log$
+ *    Revision 1.96  2009/04/17 11:38:28  fabiankeil
+ *    Add and use parse_forwarder_address() to reduce code duplication.
+ *
  *    Revision 1.95  2009/04/17 11:34:34  fabiankeil
  *    Style cosmetics for the IPv6 code.
  *
@@ -1202,29 +1205,9 @@
 
             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. */
@@ -1275,31 +1258,12 @@
             /* 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] */
@@ -1307,29 +1271,9 @@
 
             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. */
@@ -1388,58 +1332,18 @@
             /* 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. */

Index: urlmatch.c
===================================================================
RCS file: /cvsroot/ijbswa/current/urlmatch.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- urlmatch.c	17 Apr 2009 11:34:35 -0000	1.49
+++ urlmatch.c	17 Apr 2009 11:38:28 -0000	1.50
@@ -33,6 +33,9 @@
  *
  * Revisions   :
  *    $Log$
+ *    Revision 1.50  2009/04/17 11:38:28  fabiankeil
+ *    Add and use parse_forwarder_address() to reduce code duplication.
+ *
  *    Revision 1.49  2009/04/17 11:34:35  fabiankeil
  *    Style cosmetics for the IPv6 code.
  *
@@ -1509,6 +1512,59 @@
 }
 
 
+/*********************************************************************
+ *
+ * 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

Index: urlmatch.h
===================================================================
RCS file: /cvsroot/ijbswa/current/urlmatch.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- urlmatch.h	2 Mar 2009 19:18:11 -0000	1.13
+++ urlmatch.h	17 Apr 2009 11:38:28 -0000	1.14
@@ -35,6 +35,9 @@
  *
  * Revisions   :
  *    $Log$
+ *    Revision 1.14  2009/04/17 11:38:28  fabiankeil
+ *    Add and use parse_forwarder_address() to reduce code duplication.
+ *
  *    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.
@@ -117,6 +120,7 @@
 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 */


------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
ijbswa-commits mailing list
ijbswa-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ijbswa-commits
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic