Add hostname directive. Closes PR#1918189.
authorFabian Keil <fk@fabiankeil.de>
Wed, 26 Mar 2008 18:07:18 +0000 (18:07 +0000)
committerFabian Keil <fk@fabiankeil.de>
Wed, 26 Mar 2008 18:07:18 +0000 (18:07 +0000)
cgi.c
doc/source/p-config.sgml
jbsockets.c
loadcfg.c
project.h

diff --git a/cgi.c b/cgi.c
index 4f46bca..9171737 100644 (file)
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-const char cgi_rcs[] = "$Id: cgi.c,v 1.102 2008/02/23 16:33:43 fabiankeil Exp $";
+const char cgi_rcs[] = "$Id: cgi.c,v 1.103 2008/03/21 11:13:57 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/cgi.c,v $
@@ -38,6 +38,11 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.102 2008/02/23 16:33:43 fabiankeil Exp $"
  *
  * Revisions   :
  *    $Log: cgi.c,v $
+ *    Revision 1.103  2008/03/21 11:13:57  fabiankeil
+ *    Only gather host information if it's actually needed.
+ *    Also move the code out of accept_connection() so it's less likely
+ *    to delay other incoming connections if the host is misconfigured.
+ *
  *    Revision 1.102  2008/02/23 16:33:43  fabiankeil
  *    Let forward_url() use the standard parameter ordering
  *    and mark its second parameter immutable.
@@ -2577,7 +2582,15 @@ struct map *default_exports(const struct client_state *csp, const char *caller)
       return NULL;
    }
 
-   get_host_information(csp->cfd, &ip_address, &hostname);
+   if (csp->config->hostname)
+   {
+      get_host_information(csp->cfd, &ip_address, NULL);
+      hostname = strdup(csp->config->hostname);
+   }
+   else
+   {
+      get_host_information(csp->cfd, &ip_address, &hostname);
+   }
 
    err = map(exports, "version", 1, html_encode(VERSION), 0);
    if (!err) err = map(exports, "my-ip-address", 1, html_encode(ip_address ? ip_address : "unknown"), 0);
index 2a90843..0d96945 100644 (file)
@@ -3,7 +3,7 @@
 
  Purpose     :  Used with other docs and files only.
 
- $Id: p-config.sgml,v 2.27 2008/01/17 01:49:51 hal9 Exp $
+ $Id: p-config.sgml,v 2.28 2008/02/03 19:15:54 fabiankeil Exp $
 
  Copyright (C) 2001-2008 Privoxy Developers http://www.privoxy.org/
  See LICENSE.
@@ -95,7 +95,7 @@
  Sample Configuration File for Privoxy v&p-version;
 </title>
 <para>
- $Id: p-config.sgml,v 2.27 2008/01/17 01:49:51 hal9 Exp $
+ $Id: p-config.sgml,v 2.28 2008/02/03 19:15:54 fabiankeil Exp $
 </para>
 <para>
 Copyright (C) 2001-2008 Privoxy Developers http://www.privoxy.org/
@@ -1166,6 +1166,62 @@ actionsfile
 <![%config-file;[<literallayout>@@#single-threaded</literallayout>]]>
 </sect3>
 
+<!--   ~~~~~       New section      ~~~~~     -->
+<sect3 renderas="sect4" id="hostname"><title>hostname</title>
+
+<variablelist>
+ <varlistentry>
+  <term>Specifies:</term>
+  <listitem>
+   <para>
+    The hostname shown on the CGI pages.
+   </para>
+  </listitem>
+ </varlistentry>
+ <varlistentry>
+  <term>Type of value:</term>
+  <listitem>
+   <para>Text</para>
+  </listitem>
+ </varlistentry>
+ <varlistentry>
+  <term>Default value:</term>
+  <listitem>
+   <para><emphasis>Unset</emphasis></para>
+  </listitem>
+ </varlistentry>
+ <varlistentry>
+  <term>Effect if unset:</term>
+  <listitem>
+   <para>
+    The hostname provided by the operating system is used.
+   </para>
+  </listitem>
+ </varlistentry>
+ <varlistentry>
+  <term>Notes:</term>
+  <listitem>
+   <para>
+    On some misconfigured systems resolving the hostname fails or
+    takes too much time and slows Privoxy down. Setting a fixed hostname
+    works around the problem.
+   </para>
+   <para>
+    In other circumstances it might be desirable to show a hostname
+    other than the one returned by the operating system. For example
+    if the system has several different hostnames and you don't want
+    to use the first one.
+   </para>
+   <para>
+    Note that Privoxy does not validate the specified hostname value.
+   </para>
+  </listitem>
+ </varlistentry>
+</variablelist>
+
+<![%config-file;[<literallayout>@@#hostname hostname.example.org</literallayout>]]>
+</sect3>
+
 </sect2>
 
 <!--  ~  End section  ~  -->
index 74a3e43..2949c31 100644 (file)
@@ -1,4 +1,4 @@
-const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.45 2007/09/30 16:59:22 fabiankeil Exp $";
+const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.46 2008/03/21 11:13:57 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jbsockets.c,v $
@@ -35,6 +35,11 @@ const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.45 2007/09/30 16:59:22 fabian
  *
  * Revisions   :
  *    $Log: jbsockets.c,v $
+ *    Revision 1.46  2008/03/21 11:13:57  fabiankeil
+ *    Only gather host information if it's actually needed.
+ *    Also move the code out of accept_connection() so it's less likely
+ *    to delay other incoming connections if the host is misconfigured.
+ *
  *    Revision 1.45  2007/09/30 16:59:22  fabiankeil
  *    Set the maximum listen() backlog to 128. Apparently SOMAXCONN is
  *    neither high enough, nor a hard limit on mingw32. Again for BR#1795281.
@@ -724,7 +729,8 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd)
  *          2  :  ip_address = Pointer to return the pointer to
  *                             the ip address string.
  *          3  :  hostname =   Pointer to return the pointer to
- *                             the hostname.
+ *                             the hostname or NULL if the caller
+ *                             isn't interested in it.
  *
  * Returns     :  void.
  *
@@ -750,12 +756,24 @@ void get_host_information(jb_socket afd, char **ip_address, char **hostname)
 #endif /* def HAVE_GETHOSTBYADDR_R_(8|7|5)_ARGS */
    s_length = sizeof(server);
 
-   *hostname = NULL;
+   if (NULL != hostname)
+   {
+      *hostname = NULL;
+   }
    *ip_address = NULL;
 
    if (!getsockname(afd, (struct sockaddr *) &server, &s_length))
    {
       *ip_address = strdup(inet_ntoa(server.sin_addr));
+
+      if (NULL == hostname)
+      {
+         /*
+          * We're done here, the caller isn't
+          * interested in knowing the hostname.
+          */
+         return;
+      }
 #if defined(HAVE_GETHOSTBYADDR_R_8_ARGS)
       gethostbyaddr_r((const char *)&server.sin_addr,
                       sizeof(server.sin_addr), AF_INET,
index 43e272e..311a431 100644 (file)
--- a/loadcfg.c
+++ b/loadcfg.c
@@ -1,4 +1,4 @@
-const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.72 2008/02/03 13:46:15 fabiankeil Exp $";
+const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.73 2008/02/16 16:54:51 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
@@ -8,7 +8,7 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.72 2008/02/03 13:46:15 fabiankeil
  *                routine to load the configuration and the global
  *                variables it writes to.
  *
- * Copyright   :  Written by and Copyright (C) 2001-2007 the SourceForge
+ * Copyright   :  Written by and Copyright (C) 2001-2008 the SourceForge
  *                Privoxy team. http://www.privoxy.org/
  *
  *                Based on the Internet Junkbuster originally written
@@ -35,6 +35,9 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.72 2008/02/03 13:46:15 fabiankeil
  *
  * Revisions   :
  *    $Log: loadcfg.c,v $
+ *    Revision 1.73  2008/02/16 16:54:51  fabiankeil
+ *    Fix typo.
+ *
  *    Revision 1.72  2008/02/03 13:46:15  fabiankeil
  *    Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
  *
@@ -540,6 +543,7 @@ static struct file_list *current_configfile = NULL;
 #define hash_forward_socks4a             2639958518ul /* "forward-socks4a" */
 #define hash_forward_socks5              3963965522ul /* "forward-socks5" */
 #define hash_forwarded_connect_retries    101465292ul /* "forwarded-connect-retries" */
+#define hash_hostname                      10308071ul /* "hostname" */
 #define hash_jarfile                        2046641ul /* "jarfile" */
 #define hash_listen_address              1255650842ul /* "listen-address" */
 #define hash_logdir                          422889ul /* "logdir" */
@@ -621,6 +625,7 @@ static void unload_configfile (void * data)
    freez(config->confdir);
    freez(config->logdir);
    freez(config->templdir);
+   freez(config->hostname);
 
    freez(config->haddr);
    freez(config->logfile);
@@ -1297,6 +1302,18 @@ struct configuration_spec * load_config(void)
             config->forwarded_connect_retries = atoi(arg);
             continue;
 
+/* *************************************************************************
+ * hostname hostname-to-show-on-cgi-pages
+ * *************************************************************************/
+         case hash_hostname :
+            freez(config->hostname);
+            config->hostname = strdup(arg);
+            if (NULL == config->hostname)
+            {
+               log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
+            }
+            continue;
+
 /* *************************************************************************
  * jarfile jar-file-name
  * In logdir by default
index 05fa8e6..412f9f8 100644 (file)
--- a/project.h
+++ b/project.h
@@ -1,7 +1,7 @@
 #ifndef PROJECT_H_INCLUDED
 #define PROJECT_H_INCLUDED
 /** Version string. */
-#define PROJECT_H_VERSION "$Id: project.h,v 1.105 2008/03/21 11:16:27 fabiankeil Exp $"
+#define PROJECT_H_VERSION "$Id: project.h,v 1.106 2008/03/24 11:21:03 fabiankeil Exp $"
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/project.h,v $
  *
  * Revisions   :
  *    $Log: project.h,v $
+ *    Revision 1.106  2008/03/24 11:21:03  fabiankeil
+ *    Share the action settings for multiple patterns in the same
+ *    section so we waste less memory for gigantic block lists
+ *    (and load them slightly faster). Reported by Franz Schwartau.
+ *
  *    Revision 1.105  2008/03/21 11:16:27  fabiankeil
  *    Garbage-collect csp->my_ip_addr_str and csp->my_hostname.
  *
@@ -1663,6 +1668,9 @@ struct configuration_spec
    /** The short names of the pcre filter files. */
    const char *re_filterfile_short[MAX_AF_FILES];
 
+   /** The hostname to show on CGI pages, or NULL to use the real one. */
+   const char *hostname;
+
 #ifdef FEATURE_COOKIE_JAR
 
    /** The file name of the cookie jar file */