svn log -v -r376544 http://svn.apache.org/repos/asf ------------------------------------------------------------------------ r376544 | jgallacher | 2006-02-09 23:43:55 -0500 (Thu, 09 Feb 2006) | 18 lines Changed paths: M /httpd/mod_python/trunk/src/connobject.c M /httpd/mod_python/trunk/src/filterobject.c M /httpd/mod_python/trunk/test/httpdconf.py M /httpd/mod_python/trunk/test/test.py Added support for Apache 2.2. Ref MODPYTHON-78 Changed connobject makesockaddr to directly access the address port rather than using apr_sockaddr_port_get, which was deprecated and removea d in apr 1.x. Removed APR_STATUS_IS_SUCCESS which is deprecated. Code which used this macro will now just compare any return condition with APR_SUCCESS. Added support to unit test to detect apache version. Modified unit tests to accomodate changes to mod_auth in apache 2.2. Mod_auth has been split into multiple modules. The mod_python unit test will now use mod_auth_basic when apache 2.2 is detected. An explicit value for KeepAliveTimeout is now set in the unit test when apache 2.2 is detected. ------------------------------------------------------------------------ Index: test/httpdconf.py =================================================================== --- test/httpdconf.py (revision 376543) +++ test/httpdconf.py (revision 376544) @@ -37,8 +37,11 @@ class Container: def __init__(self, *args): - self.args = args + self.args = list(args) self.indent = 0 + + def append(self, value): + self.args.append(value) def __str__(self): @@ -80,6 +83,16 @@ 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,6 +125,10 @@ 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) Index: test/test.py =================================================================== --- test/test.py (revision 376543) +++ test/test.py (revision 376544) @@ -220,6 +220,32 @@ 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,14 +315,26 @@ Listen(PORT), PythonOption('PythonOptionTest sample_value'), DocumentRoot(DOCUMENT_ROOT), - LoadModule("python_module %s" % quoteIfSpace(MOD_PYTHON_SO)), - IfModule("!mod_auth.c", + 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.write("\n# --APPENDED-- \n\n"+append) f.close() def startHttpd(self,extra=''): @@ -595,7 +633,12 @@ def test_req_requires_conf(self): - c = VirtualHost("*", + 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, @@ -603,8 +646,23 @@ 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, + SetHandler("mod_python"), + AuthName("blah"), + AuthType("basic"), + Require("valid-user"), + PythonAuthenHandler("tests::req_requires"), + PythonDebug("On"))) + return str(c) def test_req_requires(self): Index: src/filterobject.c =================================================================== --- src/filterobject.c (revision 376543) +++ src/filterobject.c (revision 376544) @@ -178,7 +178,7 @@ APR_BLOCK_READ, self->readbytes); Py_END_ALLOW_THREADS; - if (!APR_STATUS_IS_EAGAIN(self->rc) && !APR_STATUS_IS_SUCCESS(self->rc)) { + if (!APR_STATUS_IS_EAGAIN(self->rc) && !(self->rc == APR_SUCCESS)) { PyErr_SetObject(PyExc_IOError, PyString_FromString("Input filter read error")); return NULL; Index: src/connobject.c =================================================================== --- src/connobject.c (revision 376543) +++ src/connobject.c (revision 376544) @@ -79,7 +79,7 @@ rc = ap_get_brigade(c->input_filters, bb, mode, APR_BLOCK_READ, bufsize); Py_END_ALLOW_THREADS; - if (! APR_STATUS_IS_SUCCESS(rc)) { + if (rc != APR_SUCCESS) { PyErr_SetObject(PyExc_IOError, PyString_FromString("Connection read error")); return NULL; @@ -319,14 +319,14 @@ { 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; - 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"); - } + port = addr->port; + ret = Py_BuildValue("Oi", addrobj, port ); Py_DECREF(addrobj); } return ret;