From 3e8a845903f9cfb887a9ac11131708a61a877f2d Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Mon, 26 Jul 2010 12:33:34 +0300 Subject: [PATCH] Http services: ensure the order in the MultiHandler If we happen to register the '/' service, and then try to register the '/webdav/' one, the latter must be inserted before the more generic path. bzr revid: p_christ@hol.gr-20100726093334-3w7hyaukhzw9xpup --- bin/service/http_server.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/bin/service/http_server.py b/bin/service/http_server.py index bab38b06609..a61877b20e6 100644 --- a/bin/service/http_server.py +++ b/bin/service/http_server.py @@ -148,6 +148,29 @@ class BaseHttpDaemon(threading.Thread, netsvc.Server): raise return True + def append_svc(self, service): + if not isinstance(service, HTTPDir): + raise Exception("Wrong class for http service") + + pos = len(self.server.vdirs) + lastpos = pos + while pos > 0: + pos -= 1 + if self.server.vdirs[pos].matches(service.path): + lastpos = pos + # we won't break here, but search all way to the top, to + # ensure there is no lesser entry that will shadow the one + # we are inserting. + self.server.vdirs.insert(lastpos, service) + + def list_services(self): + ret = [] + for svc in self.server.vdirs: + ret.append( ( svc.path, str(svc.handler)) ) + + return ret + + class HttpDaemon(BaseHttpDaemon): def __init__(self, interface, port): super(HttpDaemon, self).__init__(interface, port, @@ -190,19 +213,26 @@ def reg_http_service(hts, secure_only = False): hts must be an HTTPDir """ global httpd, httpsd - if not isinstance(hts, HTTPDir): - raise Exception("Wrong class for http service") if httpd and not secure_only: - httpd.server.vdirs.append(hts) + httpd.append_svc(hts) if httpsd: - httpsd.server.vdirs.append(hts) + httpsd.append_svc(hts) if (not httpd) and (not httpsd): netsvc.Logger().notifyChannel('httpd',netsvc.LOG_WARNING,"No httpd available to register service %s" % hts.path) return +def list_http_services(protocol=None): + global httpd, httpsd + if httpd and (protocol == 'http' or protocol == None): + return httpd.list_services() + elif httpsd and (protocol == 'https' or protocol == None): + return httpsd.list_services() + else: + raise Exception("Incorrect protocol or no http services") + import SimpleXMLRPCServer class XMLRPCRequestHandler(netsvc.OpenERPDispatcher,FixSendError,SimpleXMLRPCServer.SimpleXMLRPCRequestHandler): rpc_paths = []