From 9ff2c42d45ab9ae935fac216ee945337e1e4e4ca Mon Sep 17 00:00:00 2001 From: helge Date: Fri, 19 Aug 2005 13:38:10 +0000 Subject: [PATCH] added a hack for bug #1435 git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1052 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 11 +++ sope-appserver/NGObjWeb/SoObjects/SoObject.m | 91 +++++++++++++------ sope-appserver/NGObjWeb/Version | 2 +- .../NGObjWeb/WebDAV/SoObjectDataSource.m | 4 +- .../NGObjWeb/WebDAV/SoObjectResultEntry.m | 2 +- .../WebDAV/SoObjectWebDAVDispatcher.m | 26 +----- 6 files changed, 84 insertions(+), 52 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 64c06de6..8c40f1a1 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,14 @@ +2005-08-19 Helge Hess + + * v4.5.188 + + * WebDAV/SoObjectWebDAVDispatcher.m: reuse root-url construction method in SoObject.m + + * WebDAV/SoObjectDataSource.m, WebDAV/SoObjectResultEntry.m: removed two aborts + + * SoObjects/SoObject.m: added a hack to deal with buggy Debian apachessl (#1435), + moved root-url construction method to a function + 2005-08-16 Helge Hess * v4.5.187 diff --git a/sope-appserver/NGObjWeb/SoObjects/SoObject.m b/sope-appserver/NGObjWeb/SoObjects/SoObject.m index 0bdd569d..04ad8eae 100644 --- a/sope-appserver/NGObjWeb/SoObjects/SoObject.m +++ b/sope-appserver/NGObjWeb/SoObjects/SoObject.m @@ -41,10 +41,12 @@ static void _initialize(void) { if (debugLookup == -1) { debugLookup = [[NSUserDefaults standardUserDefaults] boolForKey:@"SoDebugKeyLookup"] ? 1 : 0; + NSLog(@"Note(SoObject): SoDebugKeyLookup is enabled!"); } if (debugBaseURL == -1) { debugBaseURL = [[NSUserDefaults standardUserDefaults] boolForKey:@"SoDebugBaseURL"] ? 1 : 0; + NSLog(@"Note(SoObject): SoDebugBaseURL is enabled!"); } } @@ -257,14 +259,15 @@ static void _initialize(void) { baseURL = [baseURL stringByAppendingString:name]; if (debugBaseURL) { - [self logWithFormat:@"baseURL(%@,%@): %@", - [self nameInContainer], [[self container] baseURL], baseURL]; + [self logWithFormat:@"baseURL: name=%@ (container=%@)\n container: %@\n own: %@", + [self nameInContainer], NSStringFromClass([[self container] class]), + [[self container] baseURL], baseURL]; } } else { baseURL = [self rootURLInContext:_ctx]; if (debugBaseURL) { - [self logWithFormat:@"ROOT baseURL(no container, name=%@): %@", + [self logWithFormat:@"ROOT baseURL(no container, name=%@):\n own: %@", [self nameInContainer], baseURL]; } } @@ -280,7 +283,15 @@ static void _initialize(void) { return baseURL; } -- (NSString *)rootURLInContext:(id)_ctx { + +NSString *SoObjectRootURLInContext(WOContext *_ctx, id self /* logger */, BOOL withAppPart) { + /* + Note: Evolution doesn't correctly transfer the "Host:" header, it + misses the port argument :-( + + Note: this is called by SoObjectWebDAVDispatcher.m. + */ + // TODO: this should be a WOContext method? NSMutableString *ms; BOOL isHTTPS = NO; // TODO: what about https?? NSString *rootURL; @@ -289,17 +300,9 @@ static void _initialize(void) { int port; _initialize(); - if ((rootURL = [_ctx rootURL]) != nil) { - if (debugBaseURL) { - [self logWithFormat:@" using root-url from context: %@", - rootURL]; - } - return rootURL; - } - // TODO: this is somewhat weird, why don't we use WOContext for URL gen.? - rq = [(WOContext *)_ctx request]; + rq = [_ctx request]; port = [[rq headerForKey:@"x-webobjects-server-port"] intValue]; /* TODO: how to handle Evolution bug which sends invalid port ? */ @@ -316,38 +319,52 @@ static void _initialize(void) { ms = [[NSMutableString alloc] initWithCapacity:128]; - if ((tmp = [rq headerForKey:@"host"])) { + if ((tmp = [rq headerForKey:@"host"]) != nil) { /* check whether we have a host header with port */ if ([tmp rangeOfString:@":"].length == 0) tmp = nil; } - - if (tmp) { + if (tmp != nil) { /* we have a host header with port */ isHTTPS = [[rq headerForKey:@"x-webobjects-server-url"] hasPrefix:@"https"]; [ms appendString:isHTTPS ? @"https://" : @"http://"]; [ms appendString:tmp]; } - else if ((tmp = [rq headerForKey:@"x-webobjects-server-url"])) { + else if ((tmp = [rq headerForKey:@"x-webobjects-server-url"]) != nil) { /* sometimes the URL is just wrong! (suggests port 80) */ - if ([tmp hasSuffix:@":0"] && [tmp length] > 2) // TODO: bad bad bad + if ([tmp hasSuffix:@":0"] && [tmp length] > 2) { // TODO: bad bad bad + [self logWithFormat:@"WARNING(%s): got incorrect URL from Apache: '%@'", + __PRETTY_FUNCTION__, tmp]; tmp = [tmp substringToIndex:([tmp length] - 2)]; + } + else if ([tmp hasSuffix:@":443"] && [tmp hasPrefix:@"http://"]) { + /* see OGo bug #1435, Debian Apache hack */ + [self logWithFormat:@"WARNING(%s): got 'http' protocol but 443 port, " + @"assuming Debian/Apache bug (OGo #1435): '%@'", + __PRETTY_FUNCTION__, tmp]; + tmp = [tmp substringWithRange:NSMakeRange(4, [tmp length] - 4 - 4)]; + tmp = [@"https" stringByAppendingString:tmp]; + } [ms appendString:tmp]; } else { + // TODO: isHTTPS always no in this case? [ms appendString:isHTTPS ? @"https://" : @"http://"]; [ms appendString:[rq headerForKey:@"x-webobjects-server-name"]]; if ((isHTTPS ? (port != 443) : (port != 80)) && port != 0) [ms appendFormat:@":%i", port]; } - if (![ms hasSuffix:@"/"]) [ms appendString:@"/"]; - /* appname, two cases: */ - /* a) direct access, eg /MyFolder */ - /* b) access via app, eg /MyApp/so/MyFolder */ - [ms appendString:[rq applicationName]]; - if (![ms hasSuffix:@"/"]) [ms appendString:@"/"]; + if (withAppPart) { + if (![ms hasSuffix:@"/"]) [ms appendString:@"/"]; + + /* appname, two cases: */ + /* a) direct access, eg /MyFolder */ + /* b) access via app, eg /MyApp/so/MyFolder */ + [ms appendString:[rq applicationName]]; + if (![ms hasSuffix:@"/"]) [ms appendString:@"/"]; + } /* done */ rootURL = [[ms copy] autorelease]; @@ -356,10 +373,30 @@ static void _initialize(void) { [self logWithFormat:@" constructed root-url: %@", rootURL]; /* some hack for the request handler? */ - rh = [rq requestHandlerKey]; - if ([[[_ctx application] registeredRequestHandlerKeys] containsObject:rh]) - rootURL = [rootURL stringByAppendingFormat:@"%@/", rh]; + if (withAppPart) { + rh = [rq requestHandlerKey]; + if ([[[_ctx application] registeredRequestHandlerKeys] containsObject:rh]) + rootURL = [rootURL stringByAppendingFormat:@"%@/", rh]; + } + + return rootURL; +} + +- (NSString *)rootURLInContext:(id)_ctx { + NSString *rootURL; + + /* check cache */ + if ((rootURL = [_ctx rootURL]) != nil) { + if (debugBaseURL) { + [self logWithFormat:@" using root-url from context: %@", + rootURL]; + } + return rootURL; + } + + rootURL = SoObjectRootURLInContext(_ctx, self, YES); + /* remember in cache */ if (debugBaseURL) { [self logWithFormat:@" setting root-url in context: %@", rootURL]; diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index a31359c9..a154504c 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=187 +SUBMINOR_VERSION:=188 # v4.5.122 requires libNGExtensions v4.5.153 # v4.5.91 requires libNGExtensions v4.5.134 diff --git a/sope-appserver/NGObjWeb/WebDAV/SoObjectDataSource.m b/sope-appserver/NGObjWeb/WebDAV/SoObjectDataSource.m index f32f9d13..6824f766 100644 --- a/sope-appserver/NGObjWeb/WebDAV/SoObjectDataSource.m +++ b/sope-appserver/NGObjWeb/WebDAV/SoObjectDataSource.m @@ -111,6 +111,8 @@ static BOOL debugOn = NO; entityURL = [_fs entityName]; if (![entityURL hasSuffix:@"/"]) entityURL = [entityURL stringByAppendingString:@"/"]; + if (debugOn) + [self logWithFormat:@"using base-url: %@", entityURL]; doEscape = YES; @@ -208,7 +210,7 @@ static BOOL debugOn = NO; ![childHref hasPrefix:@"http://"]) { [self logWithFormat:@"BROKEN CHILD URL: %@ (entity=%@,key=%@)", childHref, [_fs entityName], childKey]; - abort(); + //abort(); } } diff --git a/sope-appserver/NGObjWeb/WebDAV/SoObjectResultEntry.m b/sope-appserver/NGObjWeb/WebDAV/SoObjectResultEntry.m index 055923df..a5057a4d 100644 --- a/sope-appserver/NGObjWeb/WebDAV/SoObjectResultEntry.m +++ b/sope-appserver/NGObjWeb/WebDAV/SoObjectResultEntry.m @@ -33,7 +33,7 @@ static BOOL debugOn = NO; if ([_href hasPrefix:@"http:/"] && ![_href hasPrefix:@"http://"]) { [self logWithFormat:@"BROKEN URL: %@", _href]; [self release]; - abort(); + //abort(); return nil; } } diff --git a/sope-appserver/NGObjWeb/WebDAV/SoObjectWebDAVDispatcher.m b/sope-appserver/NGObjWeb/WebDAV/SoObjectWebDAVDispatcher.m index c32ec8f1..733cb29f 100644 --- a/sope-appserver/NGObjWeb/WebDAV/SoObjectWebDAVDispatcher.m +++ b/sope-appserver/NGObjWeb/WebDAV/SoObjectWebDAVDispatcher.m @@ -107,29 +107,11 @@ static NSTimeZone *gmt = nil; } - (NSString *)baseURLForContext:(WOContext *)_ctx { - /* - Note: Evolution doesn't correctly transfer the "Host:" header, it - misses the port argument :-( - */ - NSString *baseURL; - WORequest *rq; - NSString *hostport; - id tmp; - - rq = [_ctx request]; - - if ((tmp = [rq headerForKey:@"x-webobjects-server-name"])) { - hostport = tmp; - if ((tmp = [rq headerForKey:@"x-webobjects-server-port"])) - hostport = [NSString stringWithFormat:@"%@:%@", hostport, tmp]; - } - else if ((tmp = [rq headerForKey:@"host"])) - hostport = tmp; - else - hostport = [[NSHost currentHost] name]; + extern NSString *SoObjectRootURLInContext(WOContext *_ctx, id logobj, BOOL withAppPart); + NSString *rootURL; - baseURL = [NSString stringWithFormat:@"http://%@%@", hostport, [rq uri]]; - return baseURL; + rootURL = SoObjectRootURLInContext(_ctx, self, NO); + return [rootURL stringByAppendingString:[[_ctx request] uri]]; } - (id)primaryCallWebDAVMethod:(NSString *)_name inContext:(WOContext *)_ctx { -- 2.39.5