/*
- 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.
[self setBody:[_request content]];
/* transfer cookies */
- if ([[_request cookies] count] > 0)
+ if ([[_request cookies] isNotEmpty])
[self warnWithFormat:@"cannot transfer cookies to NGHttpRequest yet !"];
/* transfer headers !!! */
cookieValue = [(NGHttpCookie *)_cookie value];
if ([cookieValue isKindOfClass:[NSArray class]]) {
- if ([cookieValue count] == 0)
+ if (![cookieValue isNotEmpty])
cookieValue = @"";
else if ([cookieValue count] == 1)
cookieValue = [[cookieValue objectAtIndex:0] stringValue];
char *uribuf;
const char *p = uribuf;
NGHashMap *map;
-
+
if ((s = [self uri]) == nil)
return formContent;
if ([s rangeOfString:@"?"].length == 0)
return formContent;
-
+
urilen = [s cStringLength];
p = uribuf = malloc(urilen + 4);
[s getCString:uribuf]; // UNICODE?
p++; // skip the '?'
map = NGDecodeUrlFormParameters((unsigned char *)p, strlen((char *)p));
if (uribuf != NULL) free(uribuf); uribuf = NULL; p = NULL;
-
+
if (map == nil)
return formContent;
if (formContent == nil)
tmp = formContent;
formContent = [[NGMutableHashMap alloc] initWithHashMap:tmp];
- [tmp release];
+ [tmp release]; tmp = nil;
keys = [map keyEnumerator];
- while ((key = [keys nextObject])) {
+ while ((key = [keys nextObject]) != nil) {
NSEnumerator *values;
id value;
values = [map objectEnumeratorForKey:key];
- while ((value = [values nextObject]))
+ while ((value = [values nextObject]) != nil)
[formContent addObject:value forKey:key];
}
}
tmp = formContent;
formContent = [[NGMutableHashMap alloc] initWithDictionary:tmp];
[tmp release];
-
+
keys = [map keyEnumerator];
- while ((key = [keys nextObject])) {
+ while ((key = [keys nextObject]) != nil) {
NSEnumerator *values;
id value;
values = [map objectEnumeratorForKey:key];
- while ((value = [values nextObject]))
+ while ((value = [values nextObject]) != nil)
[formContent addObject:value forKey:key];
}
}
- (NGHashMap *)formParameters {
id formContent;
- if (multipartFormData == nil) {
- multipartFormData = [NGMimeType mimeType:@"multipart/form-data"];
- multipartFormData = [multipartFormData retain];
- }
+ if (multipartFormData == nil)
+ multipartFormData = [[NGMimeType mimeType:@"multipart/form-data"] retain];
if ([[self methodName] isEqualToString:@"POST"]) {
NGMimeType *contentType = [self contentType];
/*
- 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.
return NO;
if (i >= 15) {
- NSLog(@"WARNING: truncated request method "
- @"(may not longer than 15 chars): %s",
- buf);
+ [self warnWithFormat:@"truncated request method "
+ @"(may not longer than 15 chars): %s", buf];
}
self->methodName = [[NSString alloc] initWithCString:buf length:i];
c = _readByte(self); /* read LF */
if ((c != 10) && (c != -1)) {
- NSLog(@"WARNING(%s): missed LF after CR (got %i)\n",
- __PRETTY_FUNCTION__, c);
+ [self warnWithFormat:@"%s: missed LF after CR (got %i)\n",
+ __PRETTY_FUNCTION__, c];
}
}
return NO;
if (i >= 15) {
- NSLog(@"WARNING: truncated request method "
+ [self warnWithFormat:@"truncated request method "
@"(may not longer than 15 chars): %s",
- buf);
+ buf];
}
self->methodName = [[NSString alloc] initWithCString:buf length:i];
{ /* process path */
NSMutableData *data = nil;
- data = [[NSMutableData allocWithZone:[self zone]] initWithCapacity:256];
+ data = [[NSMutableData allocWithZone:NULL] initWithCapacity:256];
do {
NGAddChar(data, c);
c = _readByte(self);
return NO;
}
- self->uri = [[NSString allocWithZone:[self zone]]
+ self->uri = [[NSString allocWithZone:NULL]
initWithCString:[data bytes] length:[data length]];
RELEASE(data); data = nil;
}
c = _readByte(self); // read LF
if (c != 10)
- NSLog(@"WARNING: expected LF after CR in request line, got %i", c);
+ [self warnWithFormat:@"expected LF after CR in request line, got %i", c];
self->version = @"HTTP/0.9";
}
}
if (i >= 15) {
- NSLog(@"WARNING: truncated protocol version "
- @"(may not be longer than 15 chars): %s", buf);
+ [self warnWithFormat:@"truncated protocol version "
+ @"(may not be longer than 15 chars): %s", buf];
}
- self->version = [[NSString allocWithZone:[self zone]]
- initWithCString:buf length:i];
+ self->version =
+ [[NSString allocWithZone:NULL] initWithCString:buf length:i];
/* and now read all remaining chars (spaces and CRLF..) */
while ((c != 10) && (c != -1))
return NO;
if (i >= 15) {
- NSLog(@"WARNING: truncated response version "
+ [self warnWithFormat:@"truncated response version "
@"(may not longer than 15 chars): %s",
- buf);
+ buf];
}
self->version = [[NSString alloc] initWithCString:buf length:i];
return NO;
if (i >= 5) {
- NSLog(@"WARNING: truncated response status "
- @"(may not longer than 3 chars): %s",
- buf);
+ [self warnWithFormat:@"truncated response status "
+ @"(may not longer than 3 chars): %s",
+ buf];
}
self->status = atoi(buf);
c = _readByte(self); // read LF
if (c != 10)
- NSLog(@"WARNING: expected LF after CR in request line, got %i", c);
+ [self warnWithFormat:@"expected LF after CR in request line, got %i", c];
}
else { // HTTP reason text next
// to be done ..
id clenValues;
if (_part == nil) {
- NSLog(@"WARNING(%s:%i): got no part !", __PRETTY_FUNCTION__, __LINE__);
+ [self warnWithFormat:@"%s:%i: got no part!", __PRETTY_FUNCTION__,__LINE__];
return;
}
else {
/* parse until EOF */
#if 0
- NSLog(@"WARNING(%s): parsing until EOF, "
+ [self warnWithFormat:@"%s: parsing until EOF, "
@"missed content-length header in part %@..",
- __PRETTY_FUNCTION__, _part);
+ __PRETTY_FUNCTION__, _part];
#endif
doParse = YES;
}
rq = (NGHttpRequest *)_part;
#if DEBUG
if (![rq isKindOfClass:[NGHttpRequest class]]) {
- NSLog(@"ERROR(%s:%i): got invalid part for request parsing !",
- __PRETTY_FUNCTION__, __LINE__);
+ [self errorWithFormat:@"%s:%i: got invalid part for request parsing !",
+ __PRETTY_FUNCTION__, __LINE__];
}
#endif
case NGHttpMethod_UNLOCK:
/* never parse body of the requests above */
if ([rq contentLength] > 0) {
- [self logWithFormat:
- @"WARNING: expected no content with this method !"];
+ [self warnWithFormat:
+ @"expected no content with this method !"];
}
doParse = NO;
break;
{
NGHttpRequest *request = nil;
- request = [[NGHttpRequest allocWithZone:[self zone]]
+ request = [[NGHttpRequest allocWithZone:NULL]
initWithMethod:_method
uri:_uri
header:_header
{
NGHttpResponse *response = nil;
- response = [[NGHttpResponse allocWithZone:[self zone]]
+ response = [[NGHttpResponse allocWithZone:NULL]
initWithStatus:_code
reason:_text
header:_header
/*
- 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.
char *uri;
NSString *serverUrl;
+ // TBD: do not use cString ...
uriLen = [self->_uri cStringLength];
- uriBuf = uri = malloc(uriLen + 1);
+ uriBuf = uri = malloc(uriLen + 4 /* some extra safety ;-) */);
[self->_uri getCString:uriBuf]; uriBuf[uriLen] = '\0';
/* determine adaptor prefix */
- if ((serverUrl = [self headerForKey:@"x-webobjects-adaptor-prefix"]))
- self->adaptorPrefix = [serverUrl copyWithZone:[self zone]];
+ if ((serverUrl = [self headerForKey:@"x-webobjects-adaptor-prefix"]) != nil)
+ self->adaptorPrefix = [serverUrl copyWithZone:NULL];
if (self->adaptorPrefix == nil)
self->adaptorPrefix = @"";
-
- /* new parse */
- if (uri) {
+
+ /* new parse */
+
+ if (uri != nil) {
const char *start = NULL;
/* skip adaptor prefix */
/* parsing done (found '\0') */
done:
; // required for MacOSX-S
- if (uriBuf) free(uriBuf);
+ if (uriBuf != nil) free(uriBuf);
}
}