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!");
}
}
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];
}
}
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;
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 ? */
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];
[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];