Merge branch 'master' of git://gitorious.org/radicale/radicale

Conflicts:
	radicale/__init__.py
This commit is contained in:
Corentin Le Bail
2011-04-10 09:35:01 +02:00
7 changed files with 95 additions and 48 deletions

View File

@ -88,10 +88,26 @@ class HTTPServer(server.HTTPServer):
# Maybe a Pylint bug, ``__init__`` calls ``server.HTTPServer.__init__``
# pylint: disable=W0231
def __init__(self, address, handler):
def __init__(self, address, handler, bind_and_activate=True):
"""Create server."""
log.log(10, "Create HTTP server.")
server.HTTPServer.__init__(self, address, handler)
ipv6 = ":" in address[0]
if ipv6:
self.address_family = socket.AF_INET6
# Do not bind and activate, as we might change socketopts
server.HTTPServer.__init__(self, address, handler, False)
if ipv6:
# Only allow IPv6 connections to the IPv6 socket
self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
if bind_and_activate:
self.server_bind()
self.server_activate()
self.acl = acl.load()
# pylint: enable=W0231
@ -100,7 +116,7 @@ class HTTPSServer(HTTPServer):
"""HTTPS server."""
PROTOCOL = "https"
def __init__(self, address, handler):
def __init__(self, address, handler, bind_and_activate=True):
"""Create server by wrapping HTTP socket in an SSL socket."""
log.log(10, "Create server by wrapping HTTP socket in an SSL socket.")
# Fails with Python 2.5, import if needed
@ -108,15 +124,17 @@ class HTTPSServer(HTTPServer):
import ssl
# pylint: enable=F0401
HTTPServer.__init__(self, address, handler)
HTTPServer.__init__(self, address, handler, False)
self.socket = ssl.wrap_socket(
socket.socket(self.address_family, self.socket_type),
self.socket,
server_side=True,
certfile=config.get("server", "certificate"),
keyfile=config.get("server", "key"),
ssl_version=ssl.PROTOCOL_SSLv23)
self.server_bind()
self.server_activate()
if bind_and_activate:
self.server_bind()
self.server_activate()
class CalendarHTTPHandler(server.BaseHTTPRequestHandler):

View File

@ -39,8 +39,7 @@ except ImportError:
# Default configuration
INITIAL_CONFIG = {
"server": {
"host": "",
"port": "5232",
"hosts": "0.0.0.0:5232",
"daemon": "False",
"ssl": "False",
"certificate": "/etc/apache2/ssl/server.crt",