From 0d0287d0131dd4a25fa3de71e674f4849def8a37 Mon Sep 17 00:00:00 2001 From: helge Date: Thu, 8 Feb 2007 18:39:39 +0000 Subject: [PATCH] added a WebDAV property, added relative URLs to WebDAV git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1411 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 8 ++ sope-appserver/NGObjWeb/DAVPropMap.plist | 1 + sope-appserver/NGObjWeb/SoObjects/SoObject.m | 101 ++++++++++-------- sope-appserver/NGObjWeb/Version | 2 +- .../NGObjWeb/WebDAV/SoWebDAVRenderer.m | 11 +- 5 files changed, 76 insertions(+), 47 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 56719c1a..786b3c71 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,5 +1,13 @@ 2007-02-08 Helge Hess + * v4.5.266 + + * SoObject.m, SoWebDAVRenderer.m: made the URL generation honour the + WOUseRelativeURLs default (which is on by default, so all generated + WebDAV URLs now do not include the hostname) + + * DAVPropMap.plist: mapped calendar-color WebDAV property + * WebDAV/SoWebDAVRenderer.m: added support for XML properties which contain values (v4.5.265) diff --git a/sope-appserver/NGObjWeb/DAVPropMap.plist b/sope-appserver/NGObjWeb/DAVPropMap.plist index 541f8b16..1f6b3622 100644 --- a/sope-appserver/NGObjWeb/DAVPropMap.plist +++ b/sope-appserver/NGObjWeb/DAVPropMap.plist @@ -128,4 +128,5 @@ davDropboxHomeURL; "{http://apple.com/ns/calendarserver/}notifications-URL" = davNotificationsURL; + "{com.apple.ical:}calendarcolor" = davCalendarColor; } diff --git a/sope-appserver/NGObjWeb/SoObjects/SoObject.m b/sope-appserver/NGObjWeb/SoObjects/SoObject.m index 6d759388..a01d0681 100644 --- a/sope-appserver/NGObjWeb/SoObjects/SoObject.m +++ b/sope-appserver/NGObjWeb/SoObjects/SoObject.m @@ -38,6 +38,7 @@ static int debugLookup = -1; static int debugBaseURL = -1; +static int useRelativeURLs = -1; static void _initialize(void) { if (debugLookup == -1) { debugLookup = [[NSUserDefaults standardUserDefaults] @@ -49,6 +50,11 @@ static void _initialize(void) { boolForKey:@"SoDebugBaseURL"] ? 1 : 0; NSLog(@"Note(SoObject): SoDebugBaseURL is enabled!"); } + if (useRelativeURLs == -1) { + useRelativeURLs = [[NSUserDefaults standardUserDefaults] + boolForKey:@"WOUseRelativeURLs"] ?1:0; + NSLog(@"Note(SoObject): relative base URLs are enabled."); + } } /* classes */ @@ -260,8 +266,10 @@ static void _initialize(void) { baseURL = [baseURL stringByAppendingString:name]; if (debugBaseURL) { - [self logWithFormat:@"baseURL: name=%@ (container=%@)\n container: %@\n own: %@", - [self nameInContainer], NSStringFromClass([[self container] class]), + [self logWithFormat: + @"baseURL: name=%@ (container=%@)\n container: %@\n own: %@", + [self nameInContainer], + NSStringFromClass([[self container] class]), [[self container] baseURL], baseURL]; } } @@ -308,57 +316,59 @@ NSString *SoObjectRootURLInContext // TODO: this is somewhat weird, why don't we use WOContext for URL gen.? - rq = [_ctx request]; - port = [[rq headerForKey:@"x-webobjects-server-port"] intValue]; + rq = [_ctx request]; + ms = [[NSMutableString alloc] initWithCapacity:128]; + + if (!useRelativeURLs) { + port = [[rq headerForKey:@"x-webobjects-server-port"] intValue]; - /* this is actually a bug in Apache */ - if (port == 0) { - static BOOL didWarn = NO; - if (!didWarn) { - [self warnWithFormat:@"(%s:%i): got an empty port from Apache!", + /* this is actually a bug in Apache */ + if (port == 0) { + static BOOL didWarn = NO; + if (!didWarn) { + [self warnWithFormat:@"(%s:%i): got an empty port from Apache!", __PRETTY_FUNCTION__, __LINE__]; - didWarn = YES; + didWarn = YES; + } + port = 80; } - port = 80; - } - - ms = [[NSMutableString alloc] initWithCapacity:128]; - if ((tmp = [rq headerForKey:@"host"]) != nil) { - /* check whether we have a host header with port */ - if ([tmp rangeOfString:@":"].length == 0) - tmp = nil; - } - 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"]) != nil) { - /* sometimes the URL is just wrong! (suggests port 80) */ - if ([tmp hasSuffix:@":0"] && [tmp length] > 2) { // TODO: bad bad bad - [self warnWithFormat:@"%s: got incorrect URL from Apache: '%@'", - __PRETTY_FUNCTION__, tmp]; - tmp = [tmp substringToIndex:([tmp length] - 2)]; + if ((tmp = [rq headerForKey:@"host"]) != nil) { + /* check whether we have a host header with port */ + if ([tmp rangeOfString:@":"].length == 0) + tmp = nil; + } + 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 hasSuffix:@":443"] && [tmp hasPrefix:@"http://"]) { - /* see OGo bug #1435, Debian Apache hack */ - [self warnWithFormat:@"%s: got 'http' protocol but 443 port, " + 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 + [self warnWithFormat:@"%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 warnWithFormat:@"%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]; + tmp = [tmp substringWithRange:NSMakeRange(4, [tmp length] - 4 - 4)]; + tmp = [@"https" stringByAppendingString:tmp]; + } + [ms appendString:tmp]; } - [ms appendString:tmp]; - } - else { - // TODO: isHTTPS always no in this case? - [ms appendString:isHTTPS ? @"https://" : @"http://"]; + 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]; + [ms appendString:[rq headerForKey:@"x-webobjects-server-name"]]; + if ((isHTTPS ? (port != 443) : (port != 80)) && port != 0) + [ms appendFormat:@":%i", port]; + } } if (withAppPart) { @@ -399,7 +409,8 @@ NSString *SoObjectRootURLInContext return rootURL; } - rootURL = SoObjectRootURLInContext(_ctx, self, YES); + rootURL = SoObjectRootURLInContext + (_ctx, self /* logger */, YES /* withAppPart */); /* remember in cache */ if (debugBaseURL) { diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index b613fe43..2a92e8b6 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,7 +1,7 @@ # version file ifneq ($(GNUSTEP_HOST_VENDOR),apple) # linker overflow -SUBMINOR_VERSION:=265 +SUBMINOR_VERSION:=266 else SUBMINOR_VERSION:=255 endif diff --git a/sope-appserver/NGObjWeb/WebDAV/SoWebDAVRenderer.m b/sope-appserver/NGObjWeb/WebDAV/SoWebDAVRenderer.m index 6f61841e..94a801a4 100644 --- a/sope-appserver/NGObjWeb/WebDAV/SoWebDAVRenderer.m +++ b/sope-appserver/NGObjWeb/WebDAV/SoWebDAVRenderer.m @@ -60,6 +60,7 @@ static NSDictionary *predefinedNamespacePrefixes = nil; static NSTimeZone *gmt = nil; static BOOL debugOn = NO; static BOOL formatOutput = NO; +static BOOL useRelativeURLs = YES; + (void)initialize { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; @@ -73,7 +74,8 @@ static BOOL formatOutput = NO; predefinedNamespacePrefixes = [[ud objectForKey:@"SoPreferredNamespacePrefixes"] copy]; } - formatOutput = [ud boolForKey:@"SoWebDAVFormatOutput"]; + formatOutput = [ud boolForKey:@"SoWebDAVFormatOutput"]; + useRelativeURLs = [ud boolForKey:@"WOUseRelativeURLs"]; if ((debugOn = [ud boolForKey:@"SoRendererDebugEnabled"])) NSLog(@"enabled debugging in SoWebDAVRenderer (SoRendererDebugEnabled)"); @@ -545,6 +547,13 @@ static BOOL formatOutput = NO; } else if (![href isAbsoluteURL]) { // maybe only check for http[s]:// ? // TODO: use "real" URL processing + if ([href hasPrefix:@"/"]) { + if (useRelativeURLs) + return href; + + [self warnWithFormat:@"href path is absolute:\n base: %@\n href: %@", + baseURL, href]; + } href = [baseURL stringByAppendingPathComponent:href]; } return href; -- 2.39.5