From 1702abe77e81ad0d8a7478d63e6d5c7a479f4a47 Mon Sep 17 00:00:00 2001 From: helge Date: Thu, 31 Aug 2006 21:16:48 +0000 Subject: [PATCH] code cleanups git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1357 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 5 ++ sope-appserver/NGObjWeb/SoObjects/SoObject.m | 20 ++++--- sope-appserver/NGObjWeb/Version | 2 +- .../WebDAV/SoObjectWebDAVDispatcher.m | 55 ++++++++++--------- .../NGObjWeb/WebDAV/SoWebDAVRenderer.m | 2 +- 5 files changed, 47 insertions(+), 37 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 77426bb2..0ab37e2c 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,8 @@ +2006-08-31 Helge Hess + + * WebDAV/SoObjectWebDAVDispatcher.m: code cleanups, use -isNotEmpty + (v4.5.246) + 2006-08-31 Wolfgang Sourdeau * DynamicElements/WOCheckBoxList.m: embed 'suffix' label binding in diff --git a/sope-appserver/NGObjWeb/SoObjects/SoObject.m b/sope-appserver/NGObjWeb/SoObjects/SoObject.m index c9ca1aa7..6d759388 100644 --- a/sope-appserver/NGObjWeb/SoObjects/SoObject.m +++ b/sope-appserver/NGObjWeb/SoObjects/SoObject.m @@ -285,11 +285,16 @@ static void _initialize(void) { return baseURL; } -NSString *SoObjectRootURLInContext(WOContext *_ctx, id self /* logger */, BOOL withAppPart) { +NSString *SoObjectRootURLInContext + (WOContext *_ctx, id self /* logger */, BOOL withAppPart) +{ + // TODO: it would be best if we would return relative URLs here, but + // _some_ places (like the ZideStore subscription page) actually + // need absolute URLs. /* 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? @@ -306,16 +311,15 @@ NSString *SoObjectRootURLInContext(WOContext *_ctx, id self /* logger */, BOOL w rq = [_ctx request]; port = [[rq headerForKey:@"x-webobjects-server-port"] intValue]; - /* TODO: how to handle Evolution bug which sends invalid port ? */ + /* this is actually a bug in Apache */ if (port == 0) { static BOOL didWarn = NO; if (!didWarn) { - [self warnWithFormat:@"(%s:%i): got an empty port, probably buggy " - @"SOAP host header!", + [self warnWithFormat:@"(%s:%i): got an empty port from Apache!", __PRETTY_FUNCTION__, __LINE__]; didWarn = YES; } - port = 23000; + port = 80; } ms = [[NSMutableString alloc] initWithCapacity:128]; @@ -334,13 +338,13 @@ NSString *SoObjectRootURLInContext(WOContext *_ctx, id self /* logger */, BOOL w 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 logWithFormat:@"WARNING(%s): got incorrect URL from Apache: '%@'", + [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 logWithFormat:@"WARNING(%s): got 'http' protocol but 443 port, " + [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)]; diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index ce37dc3a..1eb93813 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=245 +SUBMINOR_VERSION:=246 # v4.5.234 requires libDOM v4.5.21 # v4.5.214 requires libNGExtensions v4.5.179 diff --git a/sope-appserver/NGObjWeb/WebDAV/SoObjectWebDAVDispatcher.m b/sope-appserver/NGObjWeb/WebDAV/SoObjectWebDAVDispatcher.m index 6568d9da..aa3f3103 100644 --- a/sope-appserver/NGObjWeb/WebDAV/SoObjectWebDAVDispatcher.m +++ b/sope-appserver/NGObjWeb/WebDAV/SoObjectWebDAVDispatcher.m @@ -113,7 +113,8 @@ static NSTimeZone *gmt = nil; } - (NSString *)baseURLForContext:(WOContext *)_ctx { - extern NSString *SoObjectRootURLInContext(WOContext *_ctx, id logobj, BOOL withAppPart); + extern NSString *SoObjectRootURLInContext + (WOContext *_ctx, id logobj, BOOL withAppPart); NSString *rootURL; rootURL = SoObjectRootURLInContext(_ctx, self, NO); @@ -203,7 +204,7 @@ static NSTimeZone *gmt = nil; sm = [_ctx soSecurityManager]; e = [sm validatePermission: - ([pathInfo length] > 0) + [pathInfo isNotEmpty] ? SoPerm_AddDocumentsImagesAndFiles : SoPerm_ChangeImagesAndFiles onObject:self->object @@ -215,7 +216,7 @@ static NSTimeZone *gmt = nil; /* perform */ - if ([pathInfo length] > 0) { + if ([pathInfo isNotEmpty]) { /* check whether all the parent collections are available */ // TODO: we might also want to check for a 'create' permission if ([pathInfo rangeOfString:@"/"].length > 0) { @@ -304,7 +305,7 @@ static NSTimeZone *gmt = nil; NSString *pathInfo; pathInfo = [_ctx pathInfo]; - if ([pathInfo length] == 0) { + if (![pathInfo isNotEmpty]) { /* MKCOL target already exists ... */ WOResponse *r; @@ -436,9 +437,9 @@ static NSTimeZone *gmt = nil; depth = [rq headerForKey:@"depth"]; uri = [rq uri]; - if ([depth length] == 0) depth = @"infinity"; + if (![depth isNotEmpty]) depth = @"infinity"; - if ([[rq content] length] > 0) { + if ([[rq content] isNotEmpty]) { [self lockParser:davsax]; { [xmlParser parseFromSource:[rq content]]; @@ -455,7 +456,7 @@ static NSTimeZone *gmt = nil; "A client may choose not to submit a request body. An empty PROPFIND request body MUST be treated as a request for the names and values of all properties." - TODO: means, an empty request is to be treated as allprop? + TODO: means, an empty request is to be handled as ? */ propNames = nil; findAll = YES; @@ -482,9 +483,9 @@ static NSTimeZone *gmt = nil; if ([s hasSuffix:@"/"]) s = [s substringToIndex:([s length] - 1)]; if ([s hasPrefix:@"_"]) s = [s substringFromIndex:1]; - ids = ([s length] == 0) - ? (NSArray *)[NSArray array] - : [s componentsSeparatedByString:@"_"]; + ids = [s isNotEmpty] + ? [s componentsSeparatedByString:@"_"] + : (NSArray *)[NSArray array]; // TODO: should use -stringByUnescapingURL on IDs (not required for ints) @@ -577,7 +578,7 @@ static NSTimeZone *gmt = nil; /* check permissions */ sm = [_ctx soSecurityManager]; - e = [sm validatePermission:([pathInfo length] > 0) + e = [sm validatePermission:[pathInfo isNotEmpty] ? SoPerm_AddDocumentsImagesAndFiles : SoPerm_ChangeImagesAndFiles onObject:self->object @@ -586,7 +587,7 @@ static NSTimeZone *gmt = nil; /* check for conflicts */ - if ([pathInfo length] > 0) { + if ([pathInfo isNotEmpty]) { /* check whether all the parent collections are available */ if ([pathInfo rangeOfString:@"/"].length > 0) { return [self httpException:409 /* Conflict */ @@ -598,7 +599,7 @@ static NSTimeZone *gmt = nil; /* check whether the object supports patching */ - if ([pathInfo length] > 0) { + if ([pathInfo isNotEmpty]) { if (![self->object respondsToSelector: @selector(davCreateObject:properties:inContext:)]) { [self debugWithFormat:@"cannot create new object via DAV on %@", @@ -636,9 +637,9 @@ static NSTimeZone *gmt = nil; reason:@"got no properties in PROPPATCH !"]; } - if ([pathInfo length] > 0) { + if ([pathInfo isNotEmpty]) { /* a create object cannot delete props ... */ - if ([delProps count] > 0) { + if ([delProps isNotEmpty]) { if (![self allowDeletePropertiesOnNewObjectInContext:_ctx]) { [self logWithFormat:@"shall delete props in new object '%@': %@", pathInfo, delProps]; @@ -840,7 +841,7 @@ static NSTimeZone *gmt = nil; /* TODO: check proper permission prior attempting a move */ absDestURL = [[_ctx request] headerForKey:@"destination"]; - if ([absDestURL length] == 0) { + if (![absDestURL isNotEmpty]) { return [self httpException:400 /* Bad Request */ reason: @"the destination WebDAV header was missing " @@ -972,7 +973,7 @@ static NSTimeZone *gmt = nil; return error; } - return ([newName length] > 0) + return [newName isNotEmpty] ? [NSNumber numberWithBool:201 /* Created */] : [NSNumber numberWithBool:204 /* No Content */]; } @@ -1007,7 +1008,7 @@ static NSTimeZone *gmt = nil; return error; } - return ([newName length] > 0) + return [newName isNotEmpty] ? [NSNumber numberWithBool:201 /* Created */] : [NSNumber numberWithBool:204 /* No Content */]; } @@ -1040,6 +1041,7 @@ static NSTimeZone *gmt = nil; return [_ctx response]; } + // TODO: whats that? VERY bad, maybe use -baseURLForContext:? baseURL = [NSString stringWithFormat:@"http://%@%@", [[_ctx request] headerForKey:@"host"], [[_ctx request] uri]]; @@ -1125,7 +1127,7 @@ static NSTimeZone *gmt = nil; } subscriptionID = [rq headerForKey:@"subscription-id"]; - if ([subscriptionID length] == 0) { + if (![subscriptionID isNotEmpty]) { return [self httpException:400 /* Bad Request */ reason:@"did not find subscription-id header in POLL"]; } @@ -1160,7 +1162,7 @@ static NSTimeZone *gmt = nil; /* first check, whether it's an existing subscription to be renewed */ - if ([subscriptionID length] > 0) { + if ([subscriptionID isNotEmpty]) { NSString *newId; if ((newId = [sm renewSubscription:subscriptionID onURL:url]) == nil) { @@ -1215,7 +1217,7 @@ static NSTimeZone *gmt = nil; } subscriptionID = [rq headerForKey:@"subscription-id"]; - if ([subscriptionID length] == 0) { + if (![subscriptionID isNotEmpty]) { return [self httpException:400 /* Bad Request */ reason:@"missing subscription id !"]; } @@ -1224,10 +1226,9 @@ static NSTimeZone *gmt = nil; [r setStatus:200]; return r; } - else { - return [self httpException:400 /* Bad Request */ - reason:@"unsubscribe failed (invalid or old id ?)"]; - } + + return [self httpException:400 /* Bad Request */ + reason:@"unsubscribe failed (invalid or old id ?)"]; } /* Exchange bulk methods */ @@ -1335,7 +1336,7 @@ static NSTimeZone *gmt = nil; rq = [_ctx request]; depth = [rq headerForKey:@"depth"]; - if ([depth length] == 0) depth = @"infinity"; + if (![depth isNotEmpty]) depth = @"infinity"; [self lockParser:davsax]; { @@ -1349,7 +1350,7 @@ static NSTimeZone *gmt = nil; propNames = [propNames autorelease]; targets = [targets autorelease]; - if ([targets count] == 0) + if (![targets isNotEmpty]) return [NSArray array]; /* check query all properties */ diff --git a/sope-appserver/NGObjWeb/WebDAV/SoWebDAVRenderer.m b/sope-appserver/NGObjWeb/WebDAV/SoWebDAVRenderer.m index 7c739aa1..b50ff5cc 100644 --- a/sope-appserver/NGObjWeb/WebDAV/SoWebDAVRenderer.m +++ b/sope-appserver/NGObjWeb/WebDAV/SoWebDAVRenderer.m @@ -208,7 +208,7 @@ static BOOL formatOutput = NO; [_object appendToResponse:r inContext:_ctx]; data = [r content]; - if ([[r headerForKey:@"content-type"] length] == 0) { + if (![[r headerForKey:@"content-type"] isNotEmpty]) { [r setHeader:[self mimeTypeForData:data inContext:_ctx] forKey:@"content-type"]; } -- 2.39.5