mirror of
https://github.com/swisspol/GCDWebServer.git
synced 2026-04-24 00:00:04 +08:00
Added ARC support
This commit is contained in:
@@ -54,7 +54,7 @@ static NSString* _ExtractHeaderParameter(NSString* header, NSString* attribute)
|
||||
[scanner scanUpToCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:&value];
|
||||
}
|
||||
}
|
||||
[scanner release];
|
||||
ARC_RELEASE(scanner);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -75,16 +75,16 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
- (id)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers path:(NSString*)path query:(NSDictionary*)query {
|
||||
if ((self = [super init])) {
|
||||
_method = [method copy];
|
||||
_url = [url retain];
|
||||
_headers = [headers retain];
|
||||
_url = ARC_RETAIN(url);
|
||||
_headers = ARC_RETAIN(headers);
|
||||
_path = [path copy];
|
||||
_query = [query retain];
|
||||
_query = ARC_RETAIN(query);
|
||||
|
||||
_type = [[_headers objectForKey:@"Content-Type"] retain];
|
||||
_type = ARC_RETAIN([_headers objectForKey:@"Content-Type"]);
|
||||
NSInteger length = [[_headers objectForKey:@"Content-Length"] integerValue];
|
||||
if (length < 0) {
|
||||
DNOT_REACHED();
|
||||
[self release];
|
||||
ARC_RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
_length = length;
|
||||
@@ -97,14 +97,14 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_method release];
|
||||
[_url release];
|
||||
[_headers release];
|
||||
[_path release];
|
||||
[_query release];
|
||||
[_type release];
|
||||
ARC_RELEASE(_method);
|
||||
ARC_RELEASE(_url);
|
||||
ARC_RELEASE(_headers);
|
||||
ARC_RELEASE(_path);
|
||||
ARC_RELEASE(_query);
|
||||
ARC_RELEASE(_type);
|
||||
|
||||
[super dealloc];
|
||||
ARC_DEALLOC(super);
|
||||
}
|
||||
|
||||
- (BOOL)hasBody {
|
||||
@@ -138,9 +138,9 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
|
||||
- (void)dealloc {
|
||||
DCHECK(_data != nil);
|
||||
[_data release];
|
||||
ARC_RELEASE(_data);
|
||||
|
||||
[super dealloc];
|
||||
ARC_DEALLOC(super);
|
||||
}
|
||||
|
||||
- (BOOL)open {
|
||||
@@ -168,7 +168,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
|
||||
- (id)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers path:(NSString*)path query:(NSDictionary*)query {
|
||||
if ((self = [super initWithMethod:method url:url headers:headers path:path query:query])) {
|
||||
_filePath = [[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]] retain];
|
||||
_filePath = ARC_RETAIN([NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -176,9 +176,9 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
- (void)dealloc {
|
||||
DCHECK(_file < 0);
|
||||
unlink([_filePath fileSystemRepresentation]);
|
||||
[_filePath release];
|
||||
ARC_RELEASE(_filePath);
|
||||
|
||||
[super dealloc];
|
||||
ARC_DEALLOC(super);
|
||||
}
|
||||
|
||||
- (BOOL)open {
|
||||
@@ -210,9 +210,9 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_arguments release];
|
||||
ARC_RELEASE(_arguments);
|
||||
|
||||
[super dealloc];
|
||||
ARC_DEALLOC(super);
|
||||
}
|
||||
|
||||
- (BOOL)close {
|
||||
@@ -222,8 +222,8 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
|
||||
NSString* charset = _ExtractHeaderParameter(self.contentType, @"charset");
|
||||
NSString* string = [[NSString alloc] initWithData:self.data encoding:_StringEncodingFromCharset(charset)];
|
||||
_arguments = [GCDWebServerParseURLEncodedForm(string) retain];
|
||||
[string release];
|
||||
_arguments = ARC_RETAIN(GCDWebServerParseURLEncodedForm(string));
|
||||
ARC_RELEASE(string);
|
||||
|
||||
return (_arguments ? YES : NO);
|
||||
}
|
||||
@@ -239,7 +239,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
_contentType = [contentType copy];
|
||||
NSArray* components = [_contentType componentsSeparatedByString:@";"];
|
||||
if (components.count) {
|
||||
_mimeType = [[[components objectAtIndex:0] lowercaseString] retain];
|
||||
_mimeType = ARC_RETAIN([[components objectAtIndex:0] lowercaseString]);
|
||||
}
|
||||
if (_mimeType == nil) {
|
||||
_mimeType = @"text/plain";
|
||||
@@ -249,10 +249,10 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_contentType release];
|
||||
[_mimeType release];
|
||||
ARC_RELEASE(_contentType);
|
||||
ARC_RELEASE(_mimeType);
|
||||
|
||||
[super dealloc];
|
||||
ARC_DEALLOC(super);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -263,7 +263,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
|
||||
- (id)initWithContentType:(NSString*)contentType data:(NSData*)data {
|
||||
if ((self = [super initWithContentType:contentType])) {
|
||||
_data = [data retain];
|
||||
_data = ARC_RETAIN(data);
|
||||
|
||||
if ([self.mimeType hasPrefix:@"text/"]) {
|
||||
NSString* charset = _ExtractHeaderParameter(self.contentType, @"charset");
|
||||
@@ -274,10 +274,10 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_data release];
|
||||
[_string release];
|
||||
ARC_RELEASE(_data);
|
||||
ARC_RELEASE(_string);
|
||||
|
||||
[super dealloc];
|
||||
ARC_DEALLOC(super);
|
||||
}
|
||||
|
||||
- (NSString*)description {
|
||||
@@ -301,10 +301,10 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
- (void)dealloc {
|
||||
unlink([_temporaryPath fileSystemRepresentation]);
|
||||
|
||||
[_fileName release];
|
||||
[_temporaryPath release];
|
||||
ARC_RELEASE(_fileName);
|
||||
ARC_RELEASE(_temporaryPath);
|
||||
|
||||
[super dealloc];
|
||||
ARC_DEALLOC(super);
|
||||
}
|
||||
|
||||
- (NSString*)description {
|
||||
@@ -340,11 +340,12 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
if ((self = [super initWithMethod:method url:url headers:headers path:path query:query])) {
|
||||
NSString* boundary = _ExtractHeaderParameter(self.contentType, @"boundary");
|
||||
if (boundary) {
|
||||
_boundary = [[[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSASCIIStringEncoding] retain];
|
||||
NSData* data = [[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSASCIIStringEncoding];
|
||||
_boundary = ARC_RETAIN(data);
|
||||
}
|
||||
if (_boundary == nil) {
|
||||
DNOT_REACHED();
|
||||
[self release];
|
||||
ARC_RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -369,13 +370,13 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
NSRange range = [_parserData rangeOfData:_newlinesData options:0 range:NSMakeRange(0, _parserData.length)];
|
||||
if (range.location != NSNotFound) {
|
||||
|
||||
[_controlName release];
|
||||
ARC_RELEASE(_controlName);
|
||||
_controlName = nil;
|
||||
[_fileName release];
|
||||
ARC_RELEASE(_fileName);
|
||||
_fileName = nil;
|
||||
[_contentType release];
|
||||
ARC_RELEASE(_contentType);
|
||||
_contentType = nil;
|
||||
[_tmpPath release];
|
||||
ARC_RELEASE(_tmpPath);
|
||||
_tmpPath = nil;
|
||||
CFHTTPMessageRef message = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, true);
|
||||
const char* temp = "GET / HTTP/1.0\r\n";
|
||||
@@ -384,7 +385,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
if (CFHTTPMessageIsHeaderComplete(message)) {
|
||||
NSString* controlName = nil;
|
||||
NSString* fileName = nil;
|
||||
NSDictionary* headers = [(id)CFHTTPMessageCopyAllHeaderFields(message) autorelease];
|
||||
NSDictionary* headers = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyAllHeaderFields(message));
|
||||
NSString* contentDisposition = [headers objectForKey:@"Content-Disposition"];
|
||||
if ([[contentDisposition lowercaseString] hasPrefix:@"form-data;"]) {
|
||||
controlName = _ExtractHeaderParameter(contentDisposition, @"name");
|
||||
@@ -392,7 +393,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
}
|
||||
_controlName = [controlName copy];
|
||||
_fileName = [fileName copy];
|
||||
_contentType = [[headers objectForKey:@"Content-Type"] retain];
|
||||
_contentType = ARC_RETAIN([headers objectForKey:@"Content-Type"]);
|
||||
}
|
||||
CFRelease(message);
|
||||
if (_controlName) {
|
||||
@@ -434,7 +435,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
_tmpFile = 0;
|
||||
GCDWebServerMultiPartFile* file = [[GCDWebServerMultiPartFile alloc] initWithContentType:_contentType fileName:_fileName temporaryPath:_tmpPath];
|
||||
[_files setObject:file forKey:_controlName];
|
||||
[file release];
|
||||
ARC_RELEASE(file);
|
||||
} else {
|
||||
DNOT_REACHED();
|
||||
success = NO;
|
||||
@@ -443,14 +444,14 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
DNOT_REACHED();
|
||||
success = NO;
|
||||
}
|
||||
[_tmpPath release];
|
||||
ARC_RELEASE(_tmpPath);
|
||||
_tmpPath = nil;
|
||||
} else {
|
||||
NSData* data = [[NSData alloc] initWithBytesNoCopy:(void*)dataBytes length:dataLength freeWhenDone:NO];
|
||||
GCDWebServerMultiPartArgument* argument = [[GCDWebServerMultiPartArgument alloc] initWithContentType:_contentType data:data];
|
||||
[_arguments setObject:argument forKey:_controlName];
|
||||
[argument release];
|
||||
[data release];
|
||||
ARC_RELEASE(argument);
|
||||
ARC_RELEASE(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -487,26 +488,31 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
||||
|
||||
- (BOOL)close {
|
||||
DCHECK(_parserData != nil);
|
||||
[_parserData release];
|
||||
ARC_RELEASE(_parserData);
|
||||
_parserData = nil;
|
||||
[_controlName release];
|
||||
[_fileName release];
|
||||
[_contentType release];
|
||||
ARC_RELEASE(_controlName);
|
||||
_controlName = nil;
|
||||
ARC_RELEASE(_fileName);
|
||||
_fileName = nil;
|
||||
ARC_RELEASE(_contentType);
|
||||
_contentType = nil;
|
||||
if (_tmpFile > 0) {
|
||||
close(_tmpFile);
|
||||
unlink([_tmpPath fileSystemRepresentation]);
|
||||
_tmpFile = 0;
|
||||
}
|
||||
[_tmpPath release];
|
||||
ARC_RELEASE(_tmpPath);
|
||||
_tmpPath = nil;
|
||||
return (_parserState == kParserState_End ? YES : NO);
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
DCHECK(_parserData == nil);
|
||||
[_arguments release];
|
||||
[_files release];
|
||||
[_boundary release];
|
||||
ARC_RELEASE(_arguments);
|
||||
ARC_RELEASE(_files);
|
||||
ARC_RELEASE(_boundary);
|
||||
|
||||
[super dealloc];
|
||||
ARC_DEALLOC(super);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user