From af47bb13a5f3f4401c4dad05c4aa1d4086238bb5 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Tue, 28 Feb 2006 12:01:39 +0000
Subject: [PATCH] * Apache updated to 2.2.0. * mod_python updated to 3.2.8,
 with a patch to get it to work with   Apache 2.2.x.

svn path=/nixpkgs/trunk/; revision=4927
---
 pkgs/servers/http/apache-httpd/builder.sh     |  10 +-
 pkgs/servers/http/apache-httpd/default.nix    |  10 +-
 .../apache-modules/mod_python/default.nix     |   8 +-
 .../mod_python/jg-20060204-1.patch            | 265 ++++++++++++++++++
 pkgs/system/all-packages-generic.nix          |   2 +-
 5 files changed, 283 insertions(+), 12 deletions(-)
 create mode 100644 pkgs/servers/http/apache-modules/mod_python/jg-20060204-1.patch

diff --git a/pkgs/servers/http/apache-httpd/builder.sh b/pkgs/servers/http/apache-httpd/builder.sh
index 35d33db9c1d2..3a5ccd846eec 100644
--- a/pkgs/servers/http/apache-httpd/builder.sh
+++ b/pkgs/servers/http/apache-httpd/builder.sh
@@ -1,8 +1,14 @@
 buildInputs="$openssl $db4 $expat $perl"
 source $stdenv/setup
 
-configureFlags="--with-expat=$expat --enable-mods-shared=all --without-gdbm \
- --enable-threads --with-devrandom=/dev/urandom"
+configureFlags="\
+ --with-expat=$expat \
+ --with-z=$zlib \
+ --enable-mods-shared=all \
+ --enable-authn-alias \
+ --without-gdbm \
+ --enable-threads \
+ --with-devrandom=/dev/urandom"
 
 if test $db4Support; then
     configureFlags="--with-berkeley-db=$db4 $configureFlags"
diff --git a/pkgs/servers/http/apache-httpd/default.nix b/pkgs/servers/http/apache-httpd/default.nix
index 617c1f1262b9..f9fc3c7562bf 100644
--- a/pkgs/servers/http/apache-httpd/default.nix
+++ b/pkgs/servers/http/apache-httpd/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, openssl, db4, expat, perl
+{ stdenv, fetchurl, openssl, db4, expat, perl, zlib
 , sslSupport, db4Support
 }:
 
@@ -7,17 +7,17 @@ assert db4Support -> db4 != null;
 assert expat != null && perl != null;
 
 stdenv.mkDerivation {
-  name = "apache-httpd-2.0.55";
+  name = "apache-httpd-2.2.0";
 
   builder = ./builder.sh;
   src = fetchurl {
-    url = http://nix.cs.uu.nl/dist/tarballs/httpd-2.0.55.tar.bz2;
-    md5 = "f1b5b65c8661db9ffe38b5a4a865a0e2";
+    url = http://archive.apache.org/dist/httpd/httpd-2.2.0.tar.bz2;
+    md5 = "402b90a2e47205f94b3b1d91e1a8c459";
   };
 
   inherit sslSupport db4Support;
 
-  inherit perl expat;
+  inherit perl expat zlib;
   openssl = if sslSupport then openssl else null;
   db4 = if db4Support then db4 else null;
 }
diff --git a/pkgs/servers/http/apache-modules/mod_python/default.nix b/pkgs/servers/http/apache-modules/mod_python/default.nix
index b185afd77fde..09a5135dd97b 100644
--- a/pkgs/servers/http/apache-modules/mod_python/default.nix
+++ b/pkgs/servers/http/apache-modules/mod_python/default.nix
@@ -1,16 +1,16 @@
 {stdenv, fetchurl, apacheHttpd, python}:
 
 stdenv.mkDerivation {
-  name = "mod_python-3.1.4";
+  name = "mod_python-3.2.8";
 
   builder = ./builder.sh;
 
   src = fetchurl {
-    url = http://nix.cs.uu.nl/dist/tarballs/mod_python-3.1.4.tgz;
-    md5 = "607175958137b06bcda91110414c82a1";
+    url = http://apache.nedmirror.nl/httpd/modpython/mod_python-3.2.8.tgz;
+    md5 = "d03452979a6a334f73cc2b95b39db331";
   };
 
-  patches = [./install.patch];
+  patches = [./install.patch ./jg-20060204-1.patch];
 
   inherit apacheHttpd;
   buildInputs = [apacheHttpd python];
diff --git a/pkgs/servers/http/apache-modules/mod_python/jg-20060204-1.patch b/pkgs/servers/http/apache-modules/mod_python/jg-20060204-1.patch
new file mode 100644
index 000000000000..cf3c65e9407a
--- /dev/null
+++ b/pkgs/servers/http/apache-modules/mod_python/jg-20060204-1.patch
@@ -0,0 +1,265 @@
+diff -rc mod_python-3.2.8-orig/src/connobject.c mod_python-3.2.8/src/connobject.c
+*** mod_python-3.2.8-orig/src/connobject.c	2006-02-02 22:30:55.000000000 +0100
+--- mod_python-3.2.8/src/connobject.c	2006-02-28 11:18:01.000000000 +0100
+***************
+*** 319,332 ****
+  {
+      PyObject *addrobj = makeipaddr(addr);
+      PyObject *ret = NULL;
+      if (addrobj) {
+          apr_port_t port;
+!         if(apr_sockaddr_port_get(&port, addr)==APR_SUCCESS) {
+!             ret = Py_BuildValue("Oi", addrobj, port );
+!         }
+!         else {
+!             PyErr_SetString(PyExc_SystemError,"apr_sockaddr_port_get failure");
+!         }
+          Py_DECREF(addrobj);
+      }
+      return ret;
+--- 319,332 ----
+  {
+      PyObject *addrobj = makeipaddr(addr);
+      PyObject *ret = NULL;
++ 
++     /* apr_sockaddr_port_get was deprecated and removed in apr 1.x
++      * Access the port directly instead
++      */
+      if (addrobj) {
+          apr_port_t port;
+!         port = addr->port; 
+!         ret = Py_BuildValue("Oi", addrobj, port );
+          Py_DECREF(addrobj);
+      }
+      return ret;
+diff -rc mod_python-3.2.8-orig/src/include/mod_python.h.in mod_python-3.2.8/src/include/mod_python.h.in
+*** mod_python-3.2.8-orig/src/include/mod_python.h.in	2005-09-19 19:51:03.000000000 +0200
+--- mod_python-3.2.8/src/include/mod_python.h.in	2006-02-28 11:18:01.000000000 +0100
+***************
+*** 179,184 ****
+--- 179,219 ----
+  
+  #endif /* !Mp_MOD_PYTHON_H */
+  
++ #ifndef APR_STATUS_IS_SUCCESS
++ /* APR_STATUS_IS_SUCCESS is defined in apr_errno.h for apr versions < 1.x.
++  * It was dropped in the current apr version 1.x, which causes a problem
++  * for mod_python connobject.c and filterobject.c in Apache 2.2.
++  * Occurrences of APR_STATUS_IS_SUCCESS in mod_python should be replaced
++  * with something like:
++  *   if (s != APR_SUCCESS) 
++  *     //error handling code
++  *
++  * Their is some uncertainty if the APR_OS_START_SYSERR part of
++  * the test is significant in Win32 (it likely is not), but to be safe 
++  * APR_STATUS_IS_SUCCESS is reproduced here for use with Apache 2.2.
++  * The APR_STATUS_IS_SUCCESS should be considered as deprecated.
++  */
++ 
++ #if defined(OS2) && !defined(DOXYGEN)
++ #define APR_STATUS_IS_SUCCESS(s)           ((s) == APR_SUCCESS \
++                 || (s) == APR_OS_START_SYSERR + NO_ERROR)
++ 
++ #elif defined(WIN32) && !defined(DOXYGEN) /* !defined(OS2) */
++ #define APR_STATUS_IS_SUCCESS(s)           ((s) == APR_SUCCESS \
++                 || (s) == APR_OS_START_SYSERR + ERROR_SUCCESS)
++ 
++ #elif defined(NETWARE) && !defined(DOXYGEN) /* !defined(OS2) && !defined(WIN32) */
++ #define APR_STATUS_IS_SUCCESS(s)           ((s) == APR_SUCCESS)
++ 
++ #else /* !defined(NETWARE) && !defined(OS2) && !defined(WIN32) */
++ 
++ /** no error */
++ #define APR_STATUS_IS_SUCCESS(s)        ((s) == APR_SUCCESS)
++ #endif
++ 
++ #endif /* !APR_STATUS_IS_SUCCESS */
++ 
++ 
+  /*
+  # makes emacs go into C mode
+  ### Local Variables:
+diff -rc mod_python-3.2.8-orig/test/httpdconf.py mod_python-3.2.8/test/httpdconf.py
+*** mod_python-3.2.8-orig/test/httpdconf.py	2005-09-13 22:35:57.000000000 +0200
+--- mod_python-3.2.8/test/httpdconf.py	2006-02-28 11:18:01.000000000 +0100
+***************
+*** 37,44 ****
+  class Container:
+      
+      def __init__(self, *args):
+!         self.args = args
+          self.indent = 0
+  
+      def __str__(self):
+  
+--- 37,47 ----
+  class Container:
+      
+      def __init__(self, *args):
+!         self.args = list(args)
+          self.indent = 0
++     
++     def append(self, value):
++         self.args.append(value)
+  
+      def __str__(self):
+  
+***************
+*** 80,85 ****
+--- 83,98 ----
+      def __init__(self, val):
+          Directive.__init__(self, self.__class__.__name__, val)
+  
++ class AuthBasicAuthoritative(Directive):
++     # New in Apache 2.2
++     def __init__(self, val):
++         Directive.__init__(self, self.__class__.__name__, val)
++ 
++ class AuthBasicProvider(Directive):
++     # New in Apache 2.2
++     def __init__(self, val):
++         Directive.__init__(self, self.__class__.__name__, val)
++ 
+  class AuthType(Directive):
+      def __init__(self, val):
+          Directive.__init__(self, self.__class__.__name__, val)
+***************
+*** 112,117 ****
+--- 125,134 ----
+      def __init__(self, dir, *args):
+          ContainerTag.__init__(self, self.__class__.__name__, dir, args)
+  
++ class KeepAliveTimeout(Directive):
++     def __init__(self, val):
++         Directive.__init__(self, self.__class__.__name__, val)
++ 
+  class Listen(Directive):
+      def __init__(self, val):
+          Directive.__init__(self, self.__class__.__name__, val)
+diff -rc mod_python-3.2.8-orig/test/test.py mod_python-3.2.8/test/test.py
+*** mod_python-3.2.8-orig/test/test.py	2006-02-19 20:51:17.000000000 +0100
+--- mod_python-3.2.8/test/test.py	2006-02-28 11:18:01.000000000 +0100
+***************
+*** 220,225 ****
+--- 220,251 ----
+          s = '"%s"' % s
+      return s
+  
++ def get_apache_version():
++ 
++     print "Checking Apache version...."
++     httpd = quoteIfSpace(HTTPD)
++     cmd = '%s -v' % (httpd)
++     (stdin,stdout) = os.popen2(cmd)
++ 
++     version_str = None
++     for line in stdout:
++         if line.startswith('Server version'):
++              version_str = line.strip()
++              break
++ 
++     if version_str:
++         version_str = version_str.split('/')[1]
++         major,minor,patch = version_str.split('.',3)
++         version = '%s.%s' % (major,minor)
++     else:
++         
++         print "Can't determine Apache version. Assuming 2.0"
++         version = '2.0'
++     print version
++     return version
++ 
++ APACHE_VERSION = get_apache_version()
++ 
+  class HttpdCtrl:
+      # a mixin providing ways to control httpd
+  
+***************
+*** 289,302 ****
+              Listen(PORT),
+              PythonOption('PythonOptionTest sample_value'),
+              DocumentRoot(DOCUMENT_ROOT),
+!             LoadModule("python_module %s" % quoteIfSpace(MOD_PYTHON_SO)),
+!             IfModule("!mod_auth.c",
+                       LoadModule("auth_module %s" %
+                                  quoteIfSpace(os.path.join(modpath, "mod_auth.so")))))
+  
+          f = open(CONFIG, "w")
+          f.write(str(s))
+-         f.write("\n# --APPENDED-- \n\n"+append)
+          f.close()
+  
+      def startHttpd(self,extra=''):
+--- 315,340 ----
+              Listen(PORT),
+              PythonOption('PythonOptionTest sample_value'),
+              DocumentRoot(DOCUMENT_ROOT),
+!             LoadModule("python_module %s" % quoteIfSpace(MOD_PYTHON_SO)))
+! 
+!         if APACHE_VERSION == '2.2':
+!             # mod_auth has been split into mod_auth_basic and some other modules
+!             s.append(IfModule("!mod_auth_basic.c",
+!                      LoadModule("auth_basic_module %s" %
+!                                 quoteIfSpace(os.path.join(modpath, "mod_auth_basic.so")))))
+! 
+!             # Default KeepAliveTimeout is 5 for apache 2.2, but 15 in apache 2.0
+!             # Explicitly set the value so it's the same as 2.0
+!             s.append(KeepAliveTimeout("15"))
+!         else:
+!             s.append(IfModule("!mod_auth.c",
+                       LoadModule("auth_module %s" %
+                                  quoteIfSpace(os.path.join(modpath, "mod_auth.so")))))
+  
++         s.append("\n# --APPENDED-- \n\n"+append)
++ 
+          f = open(CONFIG, "w")
+          f.write(str(s))
+          f.close()
+  
+      def startHttpd(self,extra=''):
+***************
+*** 595,601 ****
+  
+      def test_req_requires_conf(self):
+  
+!         c = VirtualHost("*",
+                          ServerName("test_req_requires"),
+                          DocumentRoot(DOCUMENT_ROOT),
+                          Directory(DOCUMENT_ROOT,
+--- 633,658 ----
+  
+      def test_req_requires_conf(self):
+  
+!         if APACHE_VERSION == '2.2':
+!             # Apache 2.2 needs AuthBasicAuthoritative Off 
+!             # This is necessary when combining mod_auth_basic with third-party
+!             # modules that are not configured with the AuthBasicProvider  
+!             # directive. 
+!             c = VirtualHost("*",
+!                         ServerName("test_req_requires"),
+!                         DocumentRoot(DOCUMENT_ROOT),
+!                         Directory(DOCUMENT_ROOT,
+!                                   SetHandler("mod_python"),
+!                                   AuthName("blah"),
+!                                   AuthType("basic"),
+!                                   Require("valid-user"),
+!                                   AuthBasicAuthoritative("Off"),
+!                                   PythonAuthenHandler("tests::req_requires"),
+!                                   PythonDebug("On")))
+! 
+!         else:
+!             # This configuration is suitable for Apache 2.0
+!             c = VirtualHost("*",
+                          ServerName("test_req_requires"),
+                          DocumentRoot(DOCUMENT_ROOT),
+                          Directory(DOCUMENT_ROOT,
+***************
+*** 605,610 ****
+--- 662,668 ----
+                                    Require("valid-user"),
+                                    PythonAuthenHandler("tests::req_requires"),
+                                    PythonDebug("On")))
++ 
+          return str(c)
+  
+      def test_req_requires(self):
diff --git a/pkgs/system/all-packages-generic.nix b/pkgs/system/all-packages-generic.nix
index 4a4f368e17b7..d314dee781f4 100644
--- a/pkgs/system/all-packages-generic.nix
+++ b/pkgs/system/all-packages-generic.nix
@@ -1526,7 +1526,7 @@ rec {
   ### SERVERS
 
   apacheHttpd = (import ../servers/http/apache-httpd) {
-    inherit fetchurl stdenv perl openssl db4 expat;
+    inherit fetchurl stdenv perl openssl db4 expat zlib;
     sslSupport = true;
     db4Support = true;
   };