+2007-05-31 Helge Hess <helge.hess@opengroupware.org>
+
+ * v4.7.11
+
+ * NGHttp+WO.m, WOSimpleHTTPParser.m: process the 'charset' parameter
+ of the request content type to extract the content encoding of the
+ request
+
+ * WOMessage.m: print a warning if -contentAsString got called but the
+ content could not be converted using the charset assigned to the
+ WORequest
+
+ * WORequest.m: minor code cleanups, use isNotEmpty
+
2007-05-28 Helge Hess <helge.hess@opengroupware.org>
* DAVPropMap.plist: added HTTPMail junkemail property (v4.7.10)
NSAutoreleasePool *pool;
WORequest *request;
NSDictionary *woHeaders;
-
- pool = [[NSAutoreleasePool alloc] init];
+ pool = [[NSAutoreleasePool alloc] init];
+
+ /* Note: headers are added below ... */
woHeaders = nil;
request = [[WORequest alloc]
[request _setHttpRequest:self];
+ /* process charset */
+ // DUP: WOSimpleHTTPParser
+ {
+ NSStringEncoding enc = 0;
+ NGMimeType *rqContentType = [self contentType];
+ NSString *charset = [rqContentType valueOfParameter:@"charset"];
+
+ if ([charset isNotEmpty]) {
+ enc = [NSString stringEncodingForEncodingNamed:charset];
+ }
+ else if (rqContentType != nil) {
+ /* process default charsets for content types */
+ NSString *majorType = [rqContentType type];
+
+ if ([majorType isEqualToString:@"text"]) {
+ NSString *subType = [rqContentType subType];
+
+ if ([subType isEqualToString:@"calendar"]) {
+ /* RFC2445, section 4.1.4 */
+ enc = NSUTF8StringEncoding;
+ }
+ }
+ else if ([majorType isEqualToString:@"application"]) {
+ NSString *subType = [rqContentType subType];
+
+ if ([subType isEqualToString:@"xml"]) {
+ // TBD: we should look at the actual content! (<?xml declaration
+ // and BOM
+ enc = NSUTF8StringEncoding;
+ }
+ }
+ }
+
+ if (enc != 0)
+ [request setContentEncoding:enc];
+ }
+
/* process cookies */
{
NSEnumerator *cs;
WOCookie *cookie;
cs = [[self woCookies] objectEnumerator];
- while ((cookie = [cs nextObject]))
+ while ((cookie = [cs nextObject]) != nil)
[request addCookie:cookie];
}
NSArrayClass = [NSArray class];
keys = [self headerFieldNames];
- while ((key = [keys nextObject])) {
+ while ((key = [keys nextObject]) != nil) {
NSEnumerator *values;
id value;
values = [self valuesOfHeaderFieldWithName:key];
- while ((value = [values nextObject])) {
+ while ((value = [values nextObject]) != nil) {
if ([value isKindOfClass:NSArrayClass]) {
NSEnumerator *ev2;
ev2 = [value objectEnumerator];
- while ((value = [ev2 nextObject])) {
+ while ((value = [ev2 nextObject]) != nil) {
value = [value stringValue];
[request appendHeader:value forKey:key];
}
# version file
-SUBMINOR_VERSION:=10
+SUBMINOR_VERSION:=11
+# v4.7.11 requires libNGExtensions v4.7.194
# v4.5.234 requires libDOM v4.5.21
# v4.5.214 requires libNGExtensions v4.5.179
# v4.5.122 requires libNGExtensions v4.5.153
if ((c = [self content]) == nil)
return nil;
-
+
s = [[NSString alloc] initWithData:c encoding:[self contentEncoding]];
+ if (s == nil) {
+ [self warnWithFormat:
+ @"could not convert request content (len=%d) to encoding %i (%@)",
+ [c length], [self contentEncoding],
+ [NSString localizedNameOfStringEncoding:[self contentEncoding]]];
+ }
return [s autorelease];
}
- (BOOL)doesStreamContent {
/* apply defaults on some globals ... */
apath = [ud stringForKey:@"WORequestValueSessionID"];
- if ([apath length] > 0)
+ if ([apath isNotEmpty])
WORequestValueSessionID = [apath copy];
apath = [ud stringForKey:@"WORequestValueInstance"];
- if ([apath length] > 0)
+ if ([apath isNotEmpty])
WORequestValueInstance = [apath copy];
apath = [ud stringForKey:@"WONoSelectionString"];
- if ([apath length] > 0)
+ if ([apath isNotEmpty])
WONoSelectionString = [apath copy];
/* load language mappings */
/* new parse */
- if (uri != nil) {
+ if (uri != NULL) {
const char *start = NULL;
/* skip adaptor prefix */
/* parsing done (found '\0') */
done:
; // required for MacOSX-S
- if (uriBuf != nil) free(uriBuf);
+ if (uriBuf != NULL) free(uriBuf);
}
}
content:(NSData *)_body
userInfo:(NSDictionary *)_userInfo
{
- if ((self = [super init])) {
+ if ((self = [super init]) != nil) {
self->_uri = [__uri copy];
self->method = [_method copy];
[self _parseURI];
/*
- Copyright (C) 2000-2005 SKYRIX Software AG
+ Copyright (C) 2000-2007 SKYRIX Software AG
+ Copyright (C) 2007 Helge Hess
This file is part of SOPE.
#include "WOSimpleHTTPParser.h"
#include <NGObjWeb/WOResponse.h>
#include <NGObjWeb/WORequest.h>
+#include <NGMime/NGMimeType.h>
#include "common.h"
#include <string.h>
/* parsing */
+- (void)_fixupContentEncodingOfMessageBasedOnContentType:(WOMessage *)_msg {
+ // DUP: NGHttp+WO.m
+ NSStringEncoding enc = 0;
+ NSString *ctype;
+ NGMimeType *rqContentType;
+ NSString *charset;
+
+ if (![(ctype = [_msg headerForKey:@"content-type"]) isNotEmpty])
+ /* an HTTP message w/o a content type? */
+ return;
+
+ if ((rqContentType = [NGMimeType mimeType:ctype]) == nil) {
+ [self warnWithFormat:@"could not parse MIME type: '%@'", ctype];
+ return;
+ }
+
+ charset = [rqContentType valueOfParameter:@"charset"];
+
+ if ([charset isNotEmpty]) {
+ enc = [NSString stringEncodingForEncodingNamed:charset];
+ }
+ else if (rqContentType != nil) {
+ /* process default charsets for content types */
+ NSString *majorType = [rqContentType type];
+
+ if ([majorType isEqualToString:@"text"]) {
+ NSString *subType = [rqContentType subType];
+
+ if ([subType isEqualToString:@"calendar"]) {
+ /* RFC2445, section 4.1.4 */
+ enc = NSUTF8StringEncoding;
+ }
+ }
+ else if ([majorType isEqualToString:@"application"]) {
+ NSString *subType = [rqContentType subType];
+
+ if ([subType isEqualToString:@"xml"]) {
+ // TBD: we should look at the actual content! (<?xml declaration
+ // and BOM
+ enc = NSUTF8StringEncoding;
+ }
+ }
+ }
+
+ if (enc != 0)
+ [_msg setContentEncoding:enc];
+}
+
- (WORequest *)parseRequest {
NSException *e = nil;
WORequest *r = nil;
/* process header */
- if ((e = [self parseHeader])) {
+ if ((e = [self parseHeader]) != nil) {
ASSIGN(self->lastException, e);
return nil;
}
/* check for expectations */
- if ((expect = [self->headers objectForKey:@"expect"])) {
+ if ((expect = [self->headers objectForKey:@"expect"]) != nil) {
if ([expect rangeOfString:@"100-continue"
options:NSCaseInsensitiveSearch].length > 0) {
if (![self processContinueExpectation])
headers:self->headers
content:self->content
userInfo:nil];
+ [self _fixupContentEncodingOfMessageBasedOnContentType:r];
[self reset];
if (heavyDebugOn)
[r setHTTPVersion:self->httpVersion];
[r setHeaders:self->headers];
[r setContent:self->content];
+ [self _fixupContentEncodingOfMessageBasedOnContentType:r];
[self reset];