mirror of
https://github.com/swisspol/GCDWebServer.git
synced 2026-02-11 00:00:07 +08:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36658278f8 | ||
|
|
0f2f22a1b0 | ||
|
|
628cf6833c | ||
|
|
9392ddadb6 | ||
|
|
5dee044caa | ||
|
|
7c8205caa0 | ||
|
|
965e111280 | ||
|
|
8a69050cca | ||
|
|
a15a49240a | ||
|
|
404b46537e | ||
|
|
811e18e2fa | ||
|
|
78480e004a | ||
|
|
2e587919ca | ||
|
|
544e236144 | ||
|
|
1a1ee2869e | ||
|
|
e665d0a778 | ||
|
|
43cc98ad47 | ||
|
|
1d08a8fcc3 | ||
|
|
2cddc8c939 | ||
|
|
1344ad9e04 | ||
|
|
3eb27a4d7b | ||
|
|
a557080a07 | ||
|
|
20507e9e85 | ||
|
|
bcd9654330 | ||
|
|
e00f4e1cdf | ||
|
|
2bfcbbc929 | ||
|
|
6ede203f54 | ||
|
|
9e042c9cb6 |
17
.gitignore
vendored
17
.gitignore
vendored
@@ -1,18 +1,3 @@
|
|||||||
# Xcode
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
build/
|
|
||||||
*.pbxuser
|
|
||||||
!default.pbxuser
|
|
||||||
*.mode1v3
|
|
||||||
!default.mode1v3
|
|
||||||
*.mode2v3
|
|
||||||
!default.mode2v3
|
|
||||||
*.perspectivev3
|
|
||||||
!default.perspectivev3
|
|
||||||
*.xcworkspace
|
|
||||||
!default.xcworkspace
|
|
||||||
xcuserdata
|
xcuserdata
|
||||||
profile
|
project.xcworkspace
|
||||||
*.moved-aside
|
|
||||||
DerivedData
|
|
||||||
.idea/
|
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2012-2013, Pierre-Olivier Latour
|
Copyright (c) 2012-2013, Pierre-Olivier Latour
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
* Redistributions of source code must retain the above copyright
|
* Redistributions of source code must retain the above copyright
|
||||||
notice, this list of conditions and the following disclaimer.
|
notice, this list of conditions and the following disclaimer.
|
||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "GCDWebServerRequest.h"
|
#import "GCDWebServerRequest.h"
|
||||||
#import "GCDWebServerResponse.h"
|
#import "GCDWebServerResponse.h"
|
||||||
@@ -36,17 +36,17 @@ typedef GCDWebServerResponse* (^GCDWebServerProcessBlock)(GCDWebServerRequest* r
|
|||||||
NSMutableArray* _handlers;
|
NSMutableArray* _handlers;
|
||||||
|
|
||||||
NSUInteger _port;
|
NSUInteger _port;
|
||||||
NSRunLoop* _runLoop;
|
dispatch_source_t _source;
|
||||||
CFSocketRef _socket;
|
|
||||||
CFNetServiceRef _service;
|
CFNetServiceRef _service;
|
||||||
}
|
}
|
||||||
@property(nonatomic, readonly, getter=isRunning) BOOL running;
|
@property(nonatomic, readonly, getter=isRunning) BOOL running;
|
||||||
@property(nonatomic, readonly) NSUInteger port;
|
@property(nonatomic, readonly) NSUInteger port;
|
||||||
|
@property(nonatomic, readonly) NSString* bonjourName; // Only non-nil if Bonjour registration is active
|
||||||
- (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock;
|
- (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock;
|
||||||
- (void)removeAllHandlers;
|
- (void)removeAllHandlers;
|
||||||
|
|
||||||
- (BOOL)start; // Default is main runloop, 8080 port and computer name
|
- (BOOL)start; // Default is 8080 port and computer name
|
||||||
- (BOOL)startWithRunloop:(NSRunLoop*)runloop port:(NSUInteger)port bonjourName:(NSString*)name; // Pass nil name to disable Bonjour or empty string to use computer name
|
- (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name; // Pass nil name to disable Bonjour or empty string to use computer name
|
||||||
- (void)stop;
|
- (void)stop;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
@@ -34,6 +34,8 @@
|
|||||||
|
|
||||||
#import "GCDWebServerPrivate.h"
|
#import "GCDWebServerPrivate.h"
|
||||||
|
|
||||||
|
#define kMaxPendingConnections 16
|
||||||
|
|
||||||
static BOOL _run;
|
static BOOL _run;
|
||||||
|
|
||||||
NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension) {
|
NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension) {
|
||||||
@@ -48,9 +50,9 @@ NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension) {
|
|||||||
if (extension.length) {
|
if (extension.length) {
|
||||||
mimeType = [_overrides objectForKey:extension];
|
mimeType = [_overrides objectForKey:extension];
|
||||||
if (mimeType == nil) {
|
if (mimeType == nil) {
|
||||||
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)extension, NULL);
|
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (ARC_BRIDGE CFStringRef)extension, NULL);
|
||||||
if (uti) {
|
if (uti) {
|
||||||
mimeType = [(id)UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType) autorelease];
|
mimeType = ARC_BRIDGE_RELEASE(UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType));
|
||||||
CFRelease(uti);
|
CFRelease(uti);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,8 +61,8 @@ NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NSString* GCDWebServerUnescapeURLString(NSString* string) {
|
NSString* GCDWebServerUnescapeURLString(NSString* string) {
|
||||||
return [(id)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)string, CFSTR(""),
|
return ARC_BRIDGE_RELEASE(CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)string, CFSTR(""),
|
||||||
kCFStringEncodingUTF8) autorelease];
|
kCFStringEncodingUTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form) {
|
NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form) {
|
||||||
@@ -88,7 +90,7 @@ NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form) {
|
|||||||
}
|
}
|
||||||
[scanner setScanLocation:([scanner scanLocation] + 1)];
|
[scanner setScanLocation:([scanner scanLocation] + 1)];
|
||||||
}
|
}
|
||||||
[scanner release];
|
ARC_RELEASE(scanner);
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,17 +105,17 @@ static void _SignalHandler(int signal) {
|
|||||||
|
|
||||||
- (id)initWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock {
|
- (id)initWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock {
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
_matchBlock = Block_copy(matchBlock);
|
_matchBlock = [matchBlock copy];
|
||||||
_processBlock = Block_copy(processBlock);
|
_processBlock = [processBlock copy];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
Block_release(_matchBlock);
|
ARC_RELEASE(_matchBlock);
|
||||||
Block_release(_processBlock);
|
ARC_RELEASE(_processBlock);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -134,29 +136,34 @@ static void _SignalHandler(int signal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
if (_runLoop) {
|
if (_source) {
|
||||||
[self stop];
|
[self stop];
|
||||||
}
|
}
|
||||||
|
|
||||||
[_handlers release];
|
ARC_RELEASE(_handlers);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString*)bonjourName {
|
||||||
|
CFStringRef name = _service ? CFNetServiceGetName(_service) : NULL;
|
||||||
|
return name && CFStringGetLength(name) ? ARC_BRIDGE_RELEASE(CFStringCreateCopy(kCFAllocatorDefault, name)) : nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)handlerBlock {
|
- (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)handlerBlock {
|
||||||
DCHECK(_runLoop == nil);
|
DCHECK(_source == NULL);
|
||||||
GCDWebServerHandler* handler = [[GCDWebServerHandler alloc] initWithMatchBlock:matchBlock processBlock:handlerBlock];
|
GCDWebServerHandler* handler = [[GCDWebServerHandler alloc] initWithMatchBlock:matchBlock processBlock:handlerBlock];
|
||||||
[_handlers insertObject:handler atIndex:0];
|
[_handlers insertObject:handler atIndex:0];
|
||||||
[handler release];
|
ARC_RELEASE(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeAllHandlers {
|
- (void)removeAllHandlers {
|
||||||
DCHECK(_runLoop == nil);
|
DCHECK(_source == NULL);
|
||||||
[_handlers removeAllObjects];
|
[_handlers removeAllObjects];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)start {
|
- (BOOL)start {
|
||||||
return [self startWithRunloop:[NSRunLoop mainRunLoop] port:8080 bonjourName:@""];
|
return [self startWithPort:8080 bonjourName:@""];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* error, void* info) {
|
static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* error, void* info) {
|
||||||
@@ -164,35 +171,18 @@ static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* er
|
|||||||
if (error->error) {
|
if (error->error) {
|
||||||
LOG_ERROR(@"Bonjour error %i (domain %i)", error->error, (int)error->domain);
|
LOG_ERROR(@"Bonjour error %i (domain %i)", error->error, (int)error->domain);
|
||||||
} else {
|
} else {
|
||||||
LOG_VERBOSE(@"Registered Bonjour service \"%@\" with type '%@' on port %i", CFNetServiceGetName(service), CFNetServiceGetType(service), CFNetServiceGetPortNumber(service));
|
LOG_VERBOSE(@"Registered Bonjour service \"%@\" in domain \"%@\" with type '%@' on port %i", CFNetServiceGetName(service), CFNetServiceGetDomain(service), CFNetServiceGetType(service), CFNetServiceGetPortNumber(service));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _SocketCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void* data, void* info) {
|
- (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name {
|
||||||
if (type == kCFSocketAcceptCallBack) {
|
DCHECK(_source == NULL);
|
||||||
CFSocketNativeHandle handle = *(CFSocketNativeHandle*)data;
|
int listeningSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
int set = 1;
|
if (listeningSocket > 0) {
|
||||||
setsockopt(handle, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)); // Make sure this socket cannot generate SIG_PIPE
|
|
||||||
@autoreleasepool {
|
|
||||||
Class class = [[(GCDWebServer*)info class] connectionClass];
|
|
||||||
GCDWebServerConnection* connection = [[class alloc] initWithServer:(GCDWebServer*)info address:(NSData*)address socket:handle];
|
|
||||||
[connection release]; // Connection will automatically retain itself while opened
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
DNOT_REACHED();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)startWithRunloop:(NSRunLoop*)runloop port:(NSUInteger)port bonjourName:(NSString*)name {
|
|
||||||
DCHECK(runloop);
|
|
||||||
DCHECK(port);
|
|
||||||
DCHECK(_runLoop == nil);
|
|
||||||
CFSocketContext context = {0, self, NULL, NULL, NULL};
|
|
||||||
_socket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, IPPROTO_TCP, kCFSocketAcceptCallBack, _SocketCallBack, &context);
|
|
||||||
if (_socket) {
|
|
||||||
int yes = 1;
|
int yes = 1;
|
||||||
setsockopt(CFSocketGetNative(_socket), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
|
setsockopt(listeningSocket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
|
||||||
|
setsockopt(listeningSocket, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes));
|
||||||
|
|
||||||
struct sockaddr_in addr4;
|
struct sockaddr_in addr4;
|
||||||
bzero(&addr4, sizeof(addr4));
|
bzero(&addr4, sizeof(addr4));
|
||||||
@@ -200,58 +190,108 @@ static void _SocketCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDat
|
|||||||
addr4.sin_family = AF_INET;
|
addr4.sin_family = AF_INET;
|
||||||
addr4.sin_port = htons(port);
|
addr4.sin_port = htons(port);
|
||||||
addr4.sin_addr.s_addr = htonl(INADDR_ANY);
|
addr4.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
if (CFSocketSetAddress(_socket, (CFDataRef)[NSData dataWithBytes:&addr4 length:sizeof(addr4)]) == kCFSocketSuccess) {
|
if (bind(listeningSocket, (void*)&addr4, sizeof(addr4)) == 0) {
|
||||||
CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(kCFAllocatorDefault, _socket, 0);
|
if (listen(listeningSocket, kMaxPendingConnections) == 0) {
|
||||||
CFRunLoopAddSource([runloop getCFRunLoop], source, kCFRunLoopCommonModes);
|
_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, listeningSocket, 0, kGCDWebServerGCDQueue);
|
||||||
CFRelease(source);
|
dispatch_source_set_cancel_handler(_source, ^{
|
||||||
|
|
||||||
if (name) {
|
@autoreleasepool {
|
||||||
_service = CFNetServiceCreate(kCFAllocatorDefault, CFSTR("local."), CFSTR("_http._tcp"), (CFStringRef)name, port);
|
int result = close(listeningSocket);
|
||||||
if (_service) {
|
if (result != 0) {
|
||||||
CFNetServiceClientContext context = {0, self, NULL, NULL, NULL};
|
LOG_ERROR(@"Failed closing socket (%i): %s", errno, strerror(errno));
|
||||||
CFNetServiceSetClient(_service, _NetServiceClientCallBack, &context);
|
} else {
|
||||||
CFNetServiceScheduleWithRunLoop(_service, [runloop getCFRunLoop], kCFRunLoopCommonModes);
|
LOG_DEBUG(@"Closed listening socket");
|
||||||
CFStreamError error = {0};
|
}
|
||||||
CFNetServiceRegisterWithOptions(_service, 0, &error);
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
dispatch_source_set_event_handler(_source, ^{
|
||||||
|
|
||||||
|
@autoreleasepool {
|
||||||
|
struct sockaddr addr;
|
||||||
|
socklen_t addrlen = sizeof(addr);
|
||||||
|
int socket = accept(listeningSocket, &addr, &addrlen);
|
||||||
|
if (socket > 0) {
|
||||||
|
int yes = 1;
|
||||||
|
setsockopt(socket, SOL_SOCKET, SO_NOSIGPIPE, &yes, sizeof(yes)); // Make sure this socket cannot generate SIG_PIPE
|
||||||
|
|
||||||
|
NSData* data = [NSData dataWithBytes:&addr length:addrlen];
|
||||||
|
Class connectionClass = [[self class] connectionClass];
|
||||||
|
GCDWebServerConnection* connection = [[connectionClass alloc] initWithServer:self address:data socket:socket]; // Connection will automatically retain itself while opened
|
||||||
|
#if __has_feature(objc_arc)
|
||||||
|
[connection self]; // Prevent compiler from complaining about unused variable / useless statement
|
||||||
|
#else
|
||||||
|
[connection release];
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
LOG_ERROR(@"Failed accepting socket (%i): %s", errno, strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
if (port == 0) { // Determine the actual port we are listening on
|
||||||
|
struct sockaddr addr;
|
||||||
|
socklen_t addrlen = sizeof(addr);
|
||||||
|
if (getsockname(listeningSocket, &addr, &addrlen) == 0) {
|
||||||
|
struct sockaddr_in* sockaddr = (struct sockaddr_in*)&addr;
|
||||||
|
_port = ntohs(sockaddr->sin_port);
|
||||||
|
} else {
|
||||||
|
LOG_ERROR(@"Failed retrieving socket address (%i): %s", errno, strerror(errno));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(@"Failed creating CFNetService");
|
_port = port;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_port = port;
|
if (name) {
|
||||||
_runLoop = [runloop retain];
|
_service = CFNetServiceCreate(kCFAllocatorDefault, CFSTR("local."), CFSTR("_http._tcp"), (ARC_BRIDGE CFStringRef)name, (SInt32)_port);
|
||||||
LOG_VERBOSE(@"%@ started on port %i", [self class], (int)port);
|
if (_service) {
|
||||||
|
CFNetServiceClientContext context = {0, (ARC_BRIDGE void*)self, NULL, NULL, NULL};
|
||||||
|
CFNetServiceSetClient(_service, _NetServiceClientCallBack, &context);
|
||||||
|
CFNetServiceScheduleWithRunLoop(_service, CFRunLoopGetMain(), kCFRunLoopCommonModes);
|
||||||
|
CFStreamError error = {0};
|
||||||
|
CFNetServiceRegisterWithOptions(_service, 0, &error);
|
||||||
|
} else {
|
||||||
|
LOG_ERROR(@"Failed creating CFNetService");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch_resume(_source);
|
||||||
|
LOG_VERBOSE(@"%@ started on port %i", [self class], (int)_port);
|
||||||
|
} else {
|
||||||
|
LOG_ERROR(@"Failed listening on socket (%i): %s", errno, strerror(errno));
|
||||||
|
close(listeningSocket);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(@"Failed binding socket");
|
LOG_ERROR(@"Failed binding socket (%i): %s", errno, strerror(errno));
|
||||||
CFRelease(_socket);
|
close(listeningSocket);
|
||||||
_socket = NULL;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(@"Failed creating CFSocket");
|
LOG_ERROR(@"Failed creating socket (%i): %s", errno, strerror(errno));
|
||||||
}
|
}
|
||||||
return (_runLoop != nil ? YES : NO);
|
return (_source ? YES : NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isRunning {
|
- (BOOL)isRunning {
|
||||||
return (_runLoop != nil ? YES : NO);
|
return (_source ? YES : NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)stop {
|
- (void)stop {
|
||||||
DCHECK(_runLoop != nil);
|
DCHECK(_source != NULL);
|
||||||
if (_socket) {
|
if (_source) {
|
||||||
if (_service) {
|
if (_service) {
|
||||||
CFNetServiceUnscheduleFromRunLoop(_service, [_runLoop getCFRunLoop], kCFRunLoopCommonModes);
|
CFNetServiceUnscheduleFromRunLoop(_service, CFRunLoopGetMain(), kCFRunLoopCommonModes);
|
||||||
CFNetServiceSetClient(_service, NULL, NULL);
|
CFNetServiceSetClient(_service, NULL, NULL);
|
||||||
CFRelease(_service);
|
CFRelease(_service);
|
||||||
|
_service = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFSocketInvalidate(_socket);
|
dispatch_source_cancel(_source); // This will close the socket
|
||||||
CFRelease(_socket);
|
ARC_DISPATCH_RELEASE(_source);
|
||||||
_socket = NULL;
|
_source = NULL;
|
||||||
|
|
||||||
LOG_VERBOSE(@"%@ stopped", [self class]);
|
LOG_VERBOSE(@"%@ stopped", [self class]);
|
||||||
}
|
}
|
||||||
[_runLoop release];
|
|
||||||
_runLoop = nil;
|
|
||||||
_port = 0;
|
_port = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,11 +314,11 @@ static void _SocketCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDat
|
|||||||
- (BOOL)runWithPort:(NSUInteger)port {
|
- (BOOL)runWithPort:(NSUInteger)port {
|
||||||
BOOL success = NO;
|
BOOL success = NO;
|
||||||
_run = YES;
|
_run = YES;
|
||||||
void* handler = signal(SIGINT, _SignalHandler);
|
void (*handler)(int) = signal(SIGINT, _SignalHandler);
|
||||||
if (handler != SIG_ERR) {
|
if (handler != SIG_ERR) {
|
||||||
if ([self startWithRunloop:[NSRunLoop currentRunLoop] port:port bonjourName:@""]) {
|
if ([self startWithPort:port bonjourName:@""]) {
|
||||||
while (_run) {
|
while (_run) {
|
||||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
|
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0, true);
|
||||||
}
|
}
|
||||||
[self stop];
|
[self stop];
|
||||||
success = YES;
|
success = YES;
|
||||||
@@ -295,7 +335,7 @@ static void _SocketCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDat
|
|||||||
- (void)addDefaultHandlerForMethod:(NSString*)method requestClass:(Class)class processBlock:(GCDWebServerProcessBlock)block {
|
- (void)addDefaultHandlerForMethod:(NSString*)method requestClass:(Class)class processBlock:(GCDWebServerProcessBlock)block {
|
||||||
[self addHandlerWithMatchBlock:^GCDWebServerRequest *(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
|
[self addHandlerWithMatchBlock:^GCDWebServerRequest *(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
|
||||||
|
|
||||||
return [[[class alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery] autorelease];
|
return ARC_AUTORELEASE([[class alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery]);
|
||||||
|
|
||||||
} processBlock:block];
|
} processBlock:block];
|
||||||
}
|
}
|
||||||
@@ -332,6 +372,11 @@ static void _SocketCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDat
|
|||||||
|
|
||||||
- (void)addHandlerForBasePath:(NSString*)basePath localPath:(NSString*)localPath indexFilename:(NSString*)indexFilename cacheAge:(NSUInteger)cacheAge {
|
- (void)addHandlerForBasePath:(NSString*)basePath localPath:(NSString*)localPath indexFilename:(NSString*)indexFilename cacheAge:(NSUInteger)cacheAge {
|
||||||
if ([basePath hasPrefix:@"/"] && [basePath hasSuffix:@"/"]) {
|
if ([basePath hasPrefix:@"/"] && [basePath hasSuffix:@"/"]) {
|
||||||
|
#if __has_feature(objc_arc)
|
||||||
|
__unsafe_unretained GCDWebServer* server = self;
|
||||||
|
#else
|
||||||
|
GCDWebServer* server = self;
|
||||||
|
#endif
|
||||||
[self addHandlerWithMatchBlock:^GCDWebServerRequest *(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
|
[self addHandlerWithMatchBlock:^GCDWebServerRequest *(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
|
||||||
|
|
||||||
if (![requestMethod isEqualToString:@"GET"]) {
|
if (![requestMethod isEqualToString:@"GET"]) {
|
||||||
@@ -340,7 +385,7 @@ static void _SocketCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDat
|
|||||||
if (![urlPath hasPrefix:basePath]) {
|
if (![urlPath hasPrefix:basePath]) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
return [[[GCDWebServerRequest alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery] autorelease];
|
return ARC_AUTORELEASE([[GCDWebServerRequest alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery]);
|
||||||
|
|
||||||
} processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
|
} processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
|
||||||
|
|
||||||
@@ -352,12 +397,12 @@ static void _SocketCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDat
|
|||||||
if (indexFilename) {
|
if (indexFilename) {
|
||||||
NSString* indexPath = [filePath stringByAppendingPathComponent:indexFilename];
|
NSString* indexPath = [filePath stringByAppendingPathComponent:indexFilename];
|
||||||
if ([[NSFileManager defaultManager] fileExistsAtPath:indexPath isDirectory:&isDirectory] && !isDirectory) {
|
if ([[NSFileManager defaultManager] fileExistsAtPath:indexPath isDirectory:&isDirectory] && !isDirectory) {
|
||||||
return [self _responseWithContentsOfFile:indexPath];
|
return [server _responseWithContentsOfFile:indexPath];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response = [self _responseWithContentsOfDirectory:filePath];
|
response = [server _responseWithContentsOfDirectory:filePath];
|
||||||
} else {
|
} else {
|
||||||
response = [self _responseWithContentsOfFile:filePath];
|
response = [server _responseWithContentsOfFile:filePath];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (response) {
|
if (response) {
|
||||||
@@ -383,7 +428,7 @@ static void _SocketCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDat
|
|||||||
if ([urlPath caseInsensitiveCompare:path] != NSOrderedSame) {
|
if ([urlPath caseInsensitiveCompare:path] != NSOrderedSame) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
return [[[class alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery] autorelease];
|
return ARC_AUTORELEASE([[class alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery]);
|
||||||
|
|
||||||
} processBlock:block];
|
} processBlock:block];
|
||||||
} else {
|
} else {
|
||||||
@@ -402,7 +447,7 @@ static void _SocketCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDat
|
|||||||
if ([expression firstMatchInString:urlPath options:0 range:NSMakeRange(0, urlPath.length)] == nil) {
|
if ([expression firstMatchInString:urlPath options:0 range:NSMakeRange(0, urlPath.length)] == nil) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
return [[[class alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery] autorelease];
|
return ARC_AUTORELEASE([[class alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery]);
|
||||||
|
|
||||||
} processBlock:block];
|
} processBlock:block];
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2012-2013, Pierre-Olivier Latour
|
Copyright (c) 2012-2013, Pierre-Olivier Latour
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
* Redistributions of source code must retain the above copyright
|
* Redistributions of source code must retain the above copyright
|
||||||
notice, this list of conditions and the following disclaimer.
|
notice, this list of conditions and the following disclaimer.
|
||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "GCDWebServer.h"
|
#import "GCDWebServer.h"
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#import "GCDWebServerPrivate.h"
|
#import "GCDWebServerPrivate.h"
|
||||||
|
|
||||||
#define kReadWriteQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
|
|
||||||
#define kHeadersReadBuffer 1024
|
#define kHeadersReadBuffer 1024
|
||||||
#define kBodyWriteBufferSize (32 * 1024)
|
#define kBodyWriteBufferSize (32 * 1024)
|
||||||
|
|
||||||
@@ -49,7 +48,7 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
@implementation GCDWebServerConnection (Read)
|
@implementation GCDWebServerConnection (Read)
|
||||||
|
|
||||||
- (void)_readBufferWithLength:(NSUInteger)length completionBlock:(ReadBufferCompletionBlock)block {
|
- (void)_readBufferWithLength:(NSUInteger)length completionBlock:(ReadBufferCompletionBlock)block {
|
||||||
dispatch_read(_socket, length, kReadWriteQueue, ^(dispatch_data_t buffer, int error) {
|
dispatch_read(_socket, length, kGCDWebServerGCDQueue, ^(dispatch_data_t buffer, int error) {
|
||||||
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
@@ -85,7 +84,7 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
block(data);
|
block(data);
|
||||||
[data release];
|
ARC_RELEASE(data);
|
||||||
} else {
|
} else {
|
||||||
block(nil);
|
block(nil);
|
||||||
}
|
}
|
||||||
@@ -95,17 +94,22 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
|
|
||||||
- (void)_readHeadersWithCompletionBlock:(ReadHeadersCompletionBlock)block {
|
- (void)_readHeadersWithCompletionBlock:(ReadHeadersCompletionBlock)block {
|
||||||
DCHECK(_requestMessage);
|
DCHECK(_requestMessage);
|
||||||
NSMutableData* data = [NSMutableData dataWithCapacity:kHeadersReadBuffer];
|
|
||||||
[self _readBufferWithLength:SIZE_T_MAX completionBlock:^(dispatch_data_t buffer) {
|
[self _readBufferWithLength:SIZE_T_MAX completionBlock:^(dispatch_data_t buffer) {
|
||||||
|
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
|
NSMutableData* data = [NSMutableData dataWithCapacity:kHeadersReadBuffer];
|
||||||
dispatch_data_apply(buffer, ^bool(dispatch_data_t region, size_t offset, const void* buffer, size_t size) {
|
dispatch_data_apply(buffer, ^bool(dispatch_data_t region, size_t offset, const void* buffer, size_t size) {
|
||||||
[data appendBytes:buffer length:size];
|
[data appendBytes:buffer length:size];
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
NSRange range = [data rangeOfData:_separatorData options:0 range:NSMakeRange(0, data.length)];
|
NSRange range = [data rangeOfData:_separatorData options:0 range:NSMakeRange(0, data.length)];
|
||||||
if (range.location == NSNotFound) {
|
if (range.location == NSNotFound) {
|
||||||
[self _readHeadersWithCompletionBlock:block];
|
if (CFHTTPMessageAppendBytes(_requestMessage, data.bytes, data.length)) {
|
||||||
|
[self _readHeadersWithCompletionBlock:block];
|
||||||
|
} else {
|
||||||
|
LOG_ERROR(@"Failed appending request headers data from socket %i", _socket);
|
||||||
|
block(nil);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
NSUInteger length = range.location + range.length;
|
NSUInteger length = range.location + range.length;
|
||||||
if (CFHTTPMessageAppendBytes(_requestMessage, data.bytes, length)) {
|
if (CFHTTPMessageAppendBytes(_requestMessage, data.bytes, length)) {
|
||||||
@@ -168,7 +172,7 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
|
|
||||||
- (void)_writeBuffer:(dispatch_data_t)buffer withCompletionBlock:(WriteBufferCompletionBlock)block {
|
- (void)_writeBuffer:(dispatch_data_t)buffer withCompletionBlock:(WriteBufferCompletionBlock)block {
|
||||||
size_t size = dispatch_data_get_size(buffer);
|
size_t size = dispatch_data_get_size(buffer);
|
||||||
dispatch_write(_socket, buffer, kReadWriteQueue, ^(dispatch_data_t data, int error) {
|
dispatch_write(_socket, buffer, kGCDWebServerGCDQueue, ^(dispatch_data_t data, int error) {
|
||||||
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
@@ -186,18 +190,24 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)_writeData:(NSData*)data withCompletionBlock:(WriteDataCompletionBlock)block {
|
- (void)_writeData:(NSData*)data withCompletionBlock:(WriteDataCompletionBlock)block {
|
||||||
|
#if !__has_feature(objc_arc)
|
||||||
[data retain];
|
[data retain];
|
||||||
dispatch_data_t buffer = dispatch_data_create(data.bytes, data.length, dispatch_get_current_queue(), ^{
|
#endif
|
||||||
|
dispatch_data_t buffer = dispatch_data_create(data.bytes, data.length, dispatch_get_main_queue(), ^{
|
||||||
|
#if __has_feature(objc_arc)
|
||||||
|
[data self]; // Keeps ARC from releasing data too early
|
||||||
|
#else
|
||||||
[data release];
|
[data release];
|
||||||
|
#endif
|
||||||
});
|
});
|
||||||
[self _writeBuffer:buffer withCompletionBlock:block];
|
[self _writeBuffer:buffer withCompletionBlock:block];
|
||||||
dispatch_release(buffer);
|
ARC_DISPATCH_RELEASE(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_writeHeadersWithCompletionBlock:(WriteHeadersCompletionBlock)block {
|
- (void)_writeHeadersWithCompletionBlock:(WriteHeadersCompletionBlock)block {
|
||||||
DCHECK(_responseMessage);
|
DCHECK(_responseMessage);
|
||||||
CFDataRef message = CFHTTPMessageCopySerializedMessage(_responseMessage);
|
CFDataRef message = CFHTTPMessageCopySerializedMessage(_responseMessage);
|
||||||
[self _writeData:(NSData*)message withCompletionBlock:block];
|
[self _writeData:(ARC_BRIDGE NSData*)message withCompletionBlock:block];
|
||||||
CFRelease(message);
|
CFRelease(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +226,7 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
}
|
}
|
||||||
|
|
||||||
}];
|
}];
|
||||||
dispatch_release(wrapper);
|
ARC_DISPATCH_RELEASE(wrapper);
|
||||||
} else if (result < 0) {
|
} else if (result < 0) {
|
||||||
LOG_ERROR(@"Failed reading response body on socket %i (error %i)", _socket, (int)result);
|
LOG_ERROR(@"Failed reading response body on socket %i (error %i)", _socket, (int)result);
|
||||||
block(NO);
|
block(NO);
|
||||||
@@ -234,22 +244,26 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
@synthesize server=_server, address=_address, totalBytesRead=_bytesRead, totalBytesWritten=_bytesWritten;
|
@synthesize server=_server, address=_address, totalBytesRead=_bytesRead, totalBytesWritten=_bytesWritten;
|
||||||
|
|
||||||
+ (void)initialize {
|
+ (void)initialize {
|
||||||
DCHECK([NSThread isMainThread]); // NSDateFormatter should be initialized on main thread
|
|
||||||
if (_separatorData == nil) {
|
if (_separatorData == nil) {
|
||||||
_separatorData = [[NSData alloc] initWithBytes:"\r\n\r\n" length:4];
|
_separatorData = [[NSData alloc] initWithBytes:"\r\n\r\n" length:4];
|
||||||
DCHECK(_separatorData);
|
DCHECK(_separatorData);
|
||||||
}
|
}
|
||||||
if (_continueData == nil) {
|
if (_continueData == nil) {
|
||||||
CFHTTPMessageRef message = CFHTTPMessageCreateResponse(kCFAllocatorDefault, 100, NULL, kCFHTTPVersion1_1);
|
CFHTTPMessageRef message = CFHTTPMessageCreateResponse(kCFAllocatorDefault, 100, NULL, kCFHTTPVersion1_1);
|
||||||
|
#if __has_feature(objc_arc)
|
||||||
|
_continueData = CFBridgingRelease(CFHTTPMessageCopySerializedMessage(message));
|
||||||
|
#else
|
||||||
_continueData = (NSData*)CFHTTPMessageCopySerializedMessage(message);
|
_continueData = (NSData*)CFHTTPMessageCopySerializedMessage(message);
|
||||||
|
#endif
|
||||||
CFRelease(message);
|
CFRelease(message);
|
||||||
DCHECK(_continueData);
|
DCHECK(_continueData);
|
||||||
}
|
}
|
||||||
if (_dateFormatter == nil) {
|
if (_dateFormatter == nil) {
|
||||||
|
DCHECK([NSThread isMainThread]); // NSDateFormatter should be initialized on main thread
|
||||||
_dateFormatter = [[NSDateFormatter alloc] init];
|
_dateFormatter = [[NSDateFormatter alloc] init];
|
||||||
_dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
|
_dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
|
||||||
_dateFormatter.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'";
|
_dateFormatter.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'";
|
||||||
_dateFormatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
|
_dateFormatter.locale = ARC_AUTORELEASE([[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]);
|
||||||
DCHECK(_dateFormatter);
|
DCHECK(_dateFormatter);
|
||||||
}
|
}
|
||||||
if (_formatterQueue == NULL) {
|
if (_formatterQueue == NULL) {
|
||||||
@@ -261,10 +275,10 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
- (void)_initializeResponseHeadersWithStatusCode:(NSInteger)statusCode {
|
- (void)_initializeResponseHeadersWithStatusCode:(NSInteger)statusCode {
|
||||||
_responseMessage = CFHTTPMessageCreateResponse(kCFAllocatorDefault, statusCode, NULL, kCFHTTPVersion1_1);
|
_responseMessage = CFHTTPMessageCreateResponse(kCFAllocatorDefault, statusCode, NULL, kCFHTTPVersion1_1);
|
||||||
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Connection"), CFSTR("Close"));
|
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Connection"), CFSTR("Close"));
|
||||||
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Server"), (CFStringRef)[[_server class] serverName]);
|
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Server"), (ARC_BRIDGE CFStringRef)[[_server class] serverName]);
|
||||||
dispatch_sync(_formatterQueue, ^{
|
dispatch_sync(_formatterQueue, ^{
|
||||||
NSString* date = [_dateFormatter stringFromDate:[NSDate date]];
|
NSString* date = [_dateFormatter stringFromDate:[NSDate date]];
|
||||||
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Date"), (CFStringRef)date);
|
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Date"), (ARC_BRIDGE CFStringRef)date);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,23 +298,23 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
|
|
||||||
GCDWebServerResponse* response = [self processRequest:_request withBlock:_handler.processBlock];
|
GCDWebServerResponse* response = [self processRequest:_request withBlock:_handler.processBlock];
|
||||||
if (![response hasBody] || [response open]) {
|
if (![response hasBody] || [response open]) {
|
||||||
_response = [response retain];
|
_response = ARC_RETAIN(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_response) {
|
if (_response) {
|
||||||
[self _initializeResponseHeadersWithStatusCode:_response.statusCode];
|
[self _initializeResponseHeadersWithStatusCode:_response.statusCode];
|
||||||
NSUInteger maxAge = _response.cacheControlMaxAge;
|
NSUInteger maxAge = _response.cacheControlMaxAge;
|
||||||
if (maxAge > 0) {
|
if (maxAge > 0) {
|
||||||
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Cache-Control"), (CFStringRef)[NSString stringWithFormat:@"max-age=%i, public", (int)maxAge]);
|
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Cache-Control"), (ARC_BRIDGE CFStringRef)[NSString stringWithFormat:@"max-age=%i, public", (int)maxAge]);
|
||||||
} else {
|
} else {
|
||||||
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Cache-Control"), CFSTR("no-cache"));
|
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Cache-Control"), CFSTR("no-cache"));
|
||||||
}
|
}
|
||||||
[_response.additionalHeaders enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL* stop) {
|
[_response.additionalHeaders enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL* stop) {
|
||||||
CFHTTPMessageSetHeaderFieldValue(_responseMessage, (CFStringRef)key, (CFStringRef)obj);
|
CFHTTPMessageSetHeaderFieldValue(_responseMessage, (ARC_BRIDGE CFStringRef)key, (ARC_BRIDGE CFStringRef)obj);
|
||||||
}];
|
}];
|
||||||
if ([_response hasBody]) {
|
if ([_response hasBody]) {
|
||||||
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Content-Type"), (CFStringRef)_response.contentType);
|
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Content-Type"), (ARC_BRIDGE CFStringRef)_response.contentType);
|
||||||
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Content-Length"), (CFStringRef)[NSString stringWithFormat:@"%i", (int)_response.contentLength]);
|
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Content-Length"), (ARC_BRIDGE CFStringRef)[NSString stringWithFormat:@"%i", (int)_response.contentLength]);
|
||||||
}
|
}
|
||||||
[self _writeHeadersWithCompletionBlock:^(BOOL success) {
|
[self _writeHeadersWithCompletionBlock:^(BOOL success) {
|
||||||
|
|
||||||
@@ -369,22 +383,22 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
[self _readHeadersWithCompletionBlock:^(NSData* extraData) {
|
[self _readHeadersWithCompletionBlock:^(NSData* extraData) {
|
||||||
|
|
||||||
if (extraData) {
|
if (extraData) {
|
||||||
NSString* requestMethod = [[(id)CFHTTPMessageCopyRequestMethod(_requestMessage) autorelease] uppercaseString];
|
NSString* requestMethod = [ARC_BRIDGE_RELEASE(CFHTTPMessageCopyRequestMethod(_requestMessage)) uppercaseString];
|
||||||
DCHECK(requestMethod);
|
DCHECK(requestMethod);
|
||||||
NSURL* requestURL = [(id)CFHTTPMessageCopyRequestURL(_requestMessage) autorelease];
|
NSURL* requestURL = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyRequestURL(_requestMessage));
|
||||||
DCHECK(requestURL);
|
DCHECK(requestURL);
|
||||||
NSString* requestPath = GCDWebServerUnescapeURLString([(id)CFURLCopyPath((CFURLRef)requestURL) autorelease]); // Don't use -[NSURL path] which strips the ending slash
|
NSString* requestPath = GCDWebServerUnescapeURLString(ARC_BRIDGE_RELEASE(CFURLCopyPath((CFURLRef)requestURL))); // Don't use -[NSURL path] which strips the ending slash
|
||||||
DCHECK(requestPath);
|
DCHECK(requestPath);
|
||||||
NSDictionary* requestQuery = nil;
|
NSDictionary* requestQuery = nil;
|
||||||
NSString* queryString = [(id)CFURLCopyQueryString((CFURLRef)requestURL, NULL) autorelease]; // Don't use -[NSURL query] to make sure query is not unescaped;
|
NSString* queryString = ARC_BRIDGE_RELEASE(CFURLCopyQueryString((CFURLRef)requestURL, NULL)); // Don't use -[NSURL query] to make sure query is not unescaped;
|
||||||
if (queryString.length) {
|
if (queryString.length) {
|
||||||
requestQuery = GCDWebServerParseURLEncodedForm(queryString);
|
requestQuery = GCDWebServerParseURLEncodedForm(queryString);
|
||||||
DCHECK(requestQuery);
|
DCHECK(requestQuery);
|
||||||
}
|
}
|
||||||
NSDictionary* requestHeaders = [(id)CFHTTPMessageCopyAllHeaderFields(_requestMessage) autorelease];
|
NSDictionary* requestHeaders = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyAllHeaderFields(_requestMessage));
|
||||||
DCHECK(requestHeaders);
|
DCHECK(requestHeaders);
|
||||||
for (_handler in _server.handlers) {
|
for (_handler in _server.handlers) {
|
||||||
_request = [_handler.matchBlock(requestMethod, requestURL, requestHeaders, requestPath, requestQuery) retain];
|
_request = ARC_RETAIN(_handler.matchBlock(requestMethod, requestURL, requestHeaders, requestPath, requestQuery));
|
||||||
if (_request) {
|
if (_request) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -392,7 +406,7 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
if (_request) {
|
if (_request) {
|
||||||
if (_request.hasBody) {
|
if (_request.hasBody) {
|
||||||
if (extraData.length <= _request.contentLength) {
|
if (extraData.length <= _request.contentLength) {
|
||||||
NSString* expectHeader = [(id)CFHTTPMessageCopyHeaderFieldValue(_requestMessage, CFSTR("Expect")) autorelease];
|
NSString* expectHeader = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyHeaderFieldValue(_requestMessage, CFSTR("Expect")));
|
||||||
if (expectHeader) {
|
if (expectHeader) {
|
||||||
if ([expectHeader caseInsensitiveCompare:@"100-continue"] == NSOrderedSame) {
|
if ([expectHeader caseInsensitiveCompare:@"100-continue"] == NSOrderedSame) {
|
||||||
[self _writeData:_continueData withCompletionBlock:^(BOOL success) {
|
[self _writeData:_continueData withCompletionBlock:^(BOOL success) {
|
||||||
@@ -428,8 +442,8 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
|
|
||||||
- (id)initWithServer:(GCDWebServer*)server address:(NSData*)address socket:(CFSocketNativeHandle)socket {
|
- (id)initWithServer:(GCDWebServer*)server address:(NSData*)address socket:(CFSocketNativeHandle)socket {
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
_server = [server retain];
|
_server = ARC_RETAIN(server);
|
||||||
_address = [address retain];
|
_address = ARC_RETAIN(address);
|
||||||
_socket = socket;
|
_socket = socket;
|
||||||
|
|
||||||
[self open];
|
[self open];
|
||||||
@@ -440,20 +454,20 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[self close];
|
[self close];
|
||||||
|
|
||||||
[_server release];
|
ARC_RELEASE(_server);
|
||||||
[_address release];
|
ARC_RELEASE(_address);
|
||||||
|
|
||||||
if (_requestMessage) {
|
if (_requestMessage) {
|
||||||
CFRelease(_requestMessage);
|
CFRelease(_requestMessage);
|
||||||
}
|
}
|
||||||
[_request release];
|
ARC_RELEASE(_request);
|
||||||
|
|
||||||
if (_responseMessage) {
|
if (_responseMessage) {
|
||||||
CFRelease(_responseMessage);
|
CFRelease(_responseMessage);
|
||||||
}
|
}
|
||||||
[_response release];
|
ARC_RELEASE(_response);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -478,7 +492,10 @@ static dispatch_queue_t _formatterQueue = NULL;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)close {
|
- (void)close {
|
||||||
close(_socket);
|
int result = close(_socket);
|
||||||
|
if (result != 0) {
|
||||||
|
LOG_ERROR(@"Failed closing socket %i for connection (%i): %s", _socket, errno, strerror(errno));
|
||||||
|
}
|
||||||
LOG_DEBUG(@"Did close connection on socket %i", _socket);
|
LOG_DEBUG(@"Did close connection on socket %i", _socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,54 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2012-2013, Pierre-Olivier Latour
|
Copyright (c) 2012-2013, Pierre-Olivier Latour
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
* Redistributions of source code must retain the above copyright
|
* Redistributions of source code must retain the above copyright
|
||||||
notice, this list of conditions and the following disclaimer.
|
notice, this list of conditions and the following disclaimer.
|
||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#import <TargetConditionals.h>
|
||||||
|
#import <AvailabilityMacros.h>
|
||||||
|
|
||||||
|
#if __has_feature(objc_arc)
|
||||||
|
#define ARC_BRIDGE __bridge
|
||||||
|
#define ARC_BRIDGE_RELEASE(__OBJECT__) CFBridgingRelease(__OBJECT__)
|
||||||
|
#define ARC_RETAIN(__OBJECT__) __OBJECT__
|
||||||
|
#define ARC_RELEASE(__OBJECT__)
|
||||||
|
#define ARC_AUTORELEASE(__OBJECT__) __OBJECT__
|
||||||
|
#define ARC_DEALLOC(__OBJECT__)
|
||||||
|
#if (TARGET_OS_IPHONE && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_6_0)) || (!TARGET_OS_IPHONE && (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_8))
|
||||||
|
#define ARC_DISPATCH_RELEASE(__OBJECT__)
|
||||||
|
#else
|
||||||
|
#define ARC_DISPATCH_RELEASE(__OBJECT__) dispatch_release(__OBJECT__)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define ARC_BRIDGE
|
||||||
|
#define ARC_BRIDGE_RELEASE(__OBJECT__) [(id)__OBJECT__ autorelease]
|
||||||
|
#define ARC_RETAIN(__OBJECT__) [__OBJECT__ retain]
|
||||||
|
#define ARC_RELEASE(__OBJECT__) [__OBJECT__ release]
|
||||||
|
#define ARC_AUTORELEASE(__OBJECT__) [__OBJECT__ autorelease]
|
||||||
|
#define ARC_DEALLOC(__OBJECT__) [__OBJECT__ dealloc]
|
||||||
|
#define ARC_DISPATCH_RELEASE(__OBJECT__) dispatch_release(__OBJECT__)
|
||||||
|
#endif
|
||||||
|
|
||||||
#import "GCDWebServerConnection.h"
|
#import "GCDWebServerConnection.h"
|
||||||
|
|
||||||
@@ -46,8 +71,8 @@ static inline void __LogMessage(long level, NSString* format, ...) {
|
|||||||
va_start(arguments, format);
|
va_start(arguments, format);
|
||||||
NSString* message = [[NSString alloc] initWithFormat:format arguments:arguments];
|
NSString* message = [[NSString alloc] initWithFormat:format arguments:arguments];
|
||||||
va_end(arguments);
|
va_end(arguments);
|
||||||
printf("[%s] %s\n", levelNames[level], [message UTF8String]);
|
fprintf(stderr, "[%s] %s\n", levelNames[level], [message UTF8String]);
|
||||||
[message release];
|
ARC_RELEASE(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +104,7 @@ static inline void __LogMessage(long level, NSString* format, ...) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define kGCDWebServerDefaultMimeType @"application/octet-stream"
|
#define kGCDWebServerDefaultMimeType @"application/octet-stream"
|
||||||
|
#define kGCDWebServerGCDQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
@@ -54,7 +54,7 @@ static NSString* _ExtractHeaderParameter(NSString* header, NSString* attribute)
|
|||||||
[scanner scanUpToCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:&value];
|
[scanner scanUpToCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:&value];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[scanner release];
|
ARC_RELEASE(scanner);
|
||||||
}
|
}
|
||||||
return value;
|
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 {
|
- (id)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers path:(NSString*)path query:(NSDictionary*)query {
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
_method = [method copy];
|
_method = [method copy];
|
||||||
_url = [url retain];
|
_url = ARC_RETAIN(url);
|
||||||
_headers = [headers retain];
|
_headers = ARC_RETAIN(headers);
|
||||||
_path = [path copy];
|
_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];
|
NSInteger length = [[_headers objectForKey:@"Content-Length"] integerValue];
|
||||||
if (length < 0) {
|
if (length < 0) {
|
||||||
DNOT_REACHED();
|
DNOT_REACHED();
|
||||||
[self release];
|
ARC_RELEASE(self);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
_length = length;
|
_length = length;
|
||||||
@@ -97,14 +97,14 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[_method release];
|
ARC_RELEASE(_method);
|
||||||
[_url release];
|
ARC_RELEASE(_url);
|
||||||
[_headers release];
|
ARC_RELEASE(_headers);
|
||||||
[_path release];
|
ARC_RELEASE(_path);
|
||||||
[_query release];
|
ARC_RELEASE(_query);
|
||||||
[_type release];
|
ARC_RELEASE(_type);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)hasBody {
|
- (BOOL)hasBody {
|
||||||
@@ -138,9 +138,9 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
DCHECK(_data != nil);
|
DCHECK(_data != nil);
|
||||||
[_data release];
|
ARC_RELEASE(_data);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)open {
|
- (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 {
|
- (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])) {
|
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;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -176,9 +176,9 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
DCHECK(_file < 0);
|
DCHECK(_file < 0);
|
||||||
unlink([_filePath fileSystemRepresentation]);
|
unlink([_filePath fileSystemRepresentation]);
|
||||||
[_filePath release];
|
ARC_RELEASE(_filePath);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)open {
|
- (BOOL)open {
|
||||||
@@ -210,9 +210,9 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[_arguments release];
|
ARC_RELEASE(_arguments);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)close {
|
- (BOOL)close {
|
||||||
@@ -222,8 +222,8 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
|
|
||||||
NSString* charset = _ExtractHeaderParameter(self.contentType, @"charset");
|
NSString* charset = _ExtractHeaderParameter(self.contentType, @"charset");
|
||||||
NSString* string = [[NSString alloc] initWithData:self.data encoding:_StringEncodingFromCharset(charset)];
|
NSString* string = [[NSString alloc] initWithData:self.data encoding:_StringEncodingFromCharset(charset)];
|
||||||
_arguments = [GCDWebServerParseURLEncodedForm(string) retain];
|
_arguments = ARC_RETAIN(GCDWebServerParseURLEncodedForm(string));
|
||||||
[string release];
|
ARC_RELEASE(string);
|
||||||
|
|
||||||
return (_arguments ? YES : NO);
|
return (_arguments ? YES : NO);
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
_contentType = [contentType copy];
|
_contentType = [contentType copy];
|
||||||
NSArray* components = [_contentType componentsSeparatedByString:@";"];
|
NSArray* components = [_contentType componentsSeparatedByString:@";"];
|
||||||
if (components.count) {
|
if (components.count) {
|
||||||
_mimeType = [[[components objectAtIndex:0] lowercaseString] retain];
|
_mimeType = ARC_RETAIN([[components objectAtIndex:0] lowercaseString]);
|
||||||
}
|
}
|
||||||
if (_mimeType == nil) {
|
if (_mimeType == nil) {
|
||||||
_mimeType = @"text/plain";
|
_mimeType = @"text/plain";
|
||||||
@@ -249,10 +249,10 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[_contentType release];
|
ARC_RELEASE(_contentType);
|
||||||
[_mimeType release];
|
ARC_RELEASE(_mimeType);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -263,7 +263,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
|
|
||||||
- (id)initWithContentType:(NSString*)contentType data:(NSData*)data {
|
- (id)initWithContentType:(NSString*)contentType data:(NSData*)data {
|
||||||
if ((self = [super initWithContentType:contentType])) {
|
if ((self = [super initWithContentType:contentType])) {
|
||||||
_data = [data retain];
|
_data = ARC_RETAIN(data);
|
||||||
|
|
||||||
if ([self.mimeType hasPrefix:@"text/"]) {
|
if ([self.mimeType hasPrefix:@"text/"]) {
|
||||||
NSString* charset = _ExtractHeaderParameter(self.contentType, @"charset");
|
NSString* charset = _ExtractHeaderParameter(self.contentType, @"charset");
|
||||||
@@ -274,10 +274,10 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[_data release];
|
ARC_RELEASE(_data);
|
||||||
[_string release];
|
ARC_RELEASE(_string);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*)description {
|
- (NSString*)description {
|
||||||
@@ -301,10 +301,10 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
unlink([_temporaryPath fileSystemRepresentation]);
|
unlink([_temporaryPath fileSystemRepresentation]);
|
||||||
|
|
||||||
[_fileName release];
|
ARC_RELEASE(_fileName);
|
||||||
[_temporaryPath release];
|
ARC_RELEASE(_temporaryPath);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*)description {
|
- (NSString*)description {
|
||||||
@@ -340,11 +340,12 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
if ((self = [super initWithMethod:method url:url headers:headers path:path query:query])) {
|
if ((self = [super initWithMethod:method url:url headers:headers path:path query:query])) {
|
||||||
NSString* boundary = _ExtractHeaderParameter(self.contentType, @"boundary");
|
NSString* boundary = _ExtractHeaderParameter(self.contentType, @"boundary");
|
||||||
if (boundary) {
|
if (boundary) {
|
||||||
_boundary = [[[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSASCIIStringEncoding] retain];
|
NSData* data = [[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSASCIIStringEncoding];
|
||||||
|
_boundary = ARC_RETAIN(data);
|
||||||
}
|
}
|
||||||
if (_boundary == nil) {
|
if (_boundary == nil) {
|
||||||
DNOT_REACHED();
|
DNOT_REACHED();
|
||||||
[self release];
|
ARC_RELEASE(self);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,13 +370,13 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
NSRange range = [_parserData rangeOfData:_newlinesData options:0 range:NSMakeRange(0, _parserData.length)];
|
NSRange range = [_parserData rangeOfData:_newlinesData options:0 range:NSMakeRange(0, _parserData.length)];
|
||||||
if (range.location != NSNotFound) {
|
if (range.location != NSNotFound) {
|
||||||
|
|
||||||
[_controlName release];
|
ARC_RELEASE(_controlName);
|
||||||
_controlName = nil;
|
_controlName = nil;
|
||||||
[_fileName release];
|
ARC_RELEASE(_fileName);
|
||||||
_fileName = nil;
|
_fileName = nil;
|
||||||
[_contentType release];
|
ARC_RELEASE(_contentType);
|
||||||
_contentType = nil;
|
_contentType = nil;
|
||||||
[_tmpPath release];
|
ARC_RELEASE(_tmpPath);
|
||||||
_tmpPath = nil;
|
_tmpPath = nil;
|
||||||
CFHTTPMessageRef message = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, true);
|
CFHTTPMessageRef message = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, true);
|
||||||
const char* temp = "GET / HTTP/1.0\r\n";
|
const char* temp = "GET / HTTP/1.0\r\n";
|
||||||
@@ -384,7 +385,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
if (CFHTTPMessageIsHeaderComplete(message)) {
|
if (CFHTTPMessageIsHeaderComplete(message)) {
|
||||||
NSString* controlName = nil;
|
NSString* controlName = nil;
|
||||||
NSString* fileName = nil;
|
NSString* fileName = nil;
|
||||||
NSDictionary* headers = [(id)CFHTTPMessageCopyAllHeaderFields(message) autorelease];
|
NSDictionary* headers = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyAllHeaderFields(message));
|
||||||
NSString* contentDisposition = [headers objectForKey:@"Content-Disposition"];
|
NSString* contentDisposition = [headers objectForKey:@"Content-Disposition"];
|
||||||
if ([[contentDisposition lowercaseString] hasPrefix:@"form-data;"]) {
|
if ([[contentDisposition lowercaseString] hasPrefix:@"form-data;"]) {
|
||||||
controlName = _ExtractHeaderParameter(contentDisposition, @"name");
|
controlName = _ExtractHeaderParameter(contentDisposition, @"name");
|
||||||
@@ -392,7 +393,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
}
|
}
|
||||||
_controlName = [controlName copy];
|
_controlName = [controlName copy];
|
||||||
_fileName = [fileName copy];
|
_fileName = [fileName copy];
|
||||||
_contentType = [[headers objectForKey:@"Content-Type"] retain];
|
_contentType = ARC_RETAIN([headers objectForKey:@"Content-Type"]);
|
||||||
}
|
}
|
||||||
CFRelease(message);
|
CFRelease(message);
|
||||||
if (_controlName) {
|
if (_controlName) {
|
||||||
@@ -428,13 +429,13 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
const void* dataBytes = _parserData.bytes;
|
const void* dataBytes = _parserData.bytes;
|
||||||
NSUInteger dataLength = range.location - 2;
|
NSUInteger dataLength = range.location - 2;
|
||||||
if (_tmpPath) {
|
if (_tmpPath) {
|
||||||
int result = write(_tmpFile, dataBytes, dataLength);
|
ssize_t result = write(_tmpFile, dataBytes, dataLength);
|
||||||
if (result == dataLength) {
|
if (result == dataLength) {
|
||||||
if (close(_tmpFile) == 0) {
|
if (close(_tmpFile) == 0) {
|
||||||
_tmpFile = 0;
|
_tmpFile = 0;
|
||||||
GCDWebServerMultiPartFile* file = [[GCDWebServerMultiPartFile alloc] initWithContentType:_contentType fileName:_fileName temporaryPath:_tmpPath];
|
GCDWebServerMultiPartFile* file = [[GCDWebServerMultiPartFile alloc] initWithContentType:_contentType fileName:_fileName temporaryPath:_tmpPath];
|
||||||
[_files setObject:file forKey:_controlName];
|
[_files setObject:file forKey:_controlName];
|
||||||
[file release];
|
ARC_RELEASE(file);
|
||||||
} else {
|
} else {
|
||||||
DNOT_REACHED();
|
DNOT_REACHED();
|
||||||
success = NO;
|
success = NO;
|
||||||
@@ -443,14 +444,14 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
DNOT_REACHED();
|
DNOT_REACHED();
|
||||||
success = NO;
|
success = NO;
|
||||||
}
|
}
|
||||||
[_tmpPath release];
|
ARC_RELEASE(_tmpPath);
|
||||||
_tmpPath = nil;
|
_tmpPath = nil;
|
||||||
} else {
|
} else {
|
||||||
NSData* data = [[NSData alloc] initWithBytesNoCopy:(void*)dataBytes length:dataLength freeWhenDone:NO];
|
NSData* data = [[NSData alloc] initWithBytesNoCopy:(void*)dataBytes length:dataLength freeWhenDone:NO];
|
||||||
GCDWebServerMultiPartArgument* argument = [[GCDWebServerMultiPartArgument alloc] initWithContentType:_contentType data:data];
|
GCDWebServerMultiPartArgument* argument = [[GCDWebServerMultiPartArgument alloc] initWithContentType:_contentType data:data];
|
||||||
[_arguments setObject:argument forKey:_controlName];
|
[_arguments setObject:argument forKey:_controlName];
|
||||||
[argument release];
|
ARC_RELEASE(argument);
|
||||||
[data release];
|
ARC_RELEASE(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,7 +467,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
NSUInteger margin = 2 * _boundary.length;
|
NSUInteger margin = 2 * _boundary.length;
|
||||||
if (_tmpPath && (_parserData.length > margin)) {
|
if (_tmpPath && (_parserData.length > margin)) {
|
||||||
NSUInteger length = _parserData.length - margin;
|
NSUInteger length = _parserData.length - margin;
|
||||||
int result = write(_tmpFile, _parserData.bytes, length);
|
ssize_t result = write(_tmpFile, _parserData.bytes, length);
|
||||||
if (result == length) {
|
if (result == length) {
|
||||||
[_parserData replaceBytesInRange:NSMakeRange(0, length) withBytes:NULL length:0];
|
[_parserData replaceBytesInRange:NSMakeRange(0, length) withBytes:NULL length:0];
|
||||||
} else {
|
} else {
|
||||||
@@ -487,26 +488,31 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
|
|||||||
|
|
||||||
- (BOOL)close {
|
- (BOOL)close {
|
||||||
DCHECK(_parserData != nil);
|
DCHECK(_parserData != nil);
|
||||||
[_parserData release];
|
ARC_RELEASE(_parserData);
|
||||||
_parserData = nil;
|
_parserData = nil;
|
||||||
[_controlName release];
|
ARC_RELEASE(_controlName);
|
||||||
[_fileName release];
|
_controlName = nil;
|
||||||
[_contentType release];
|
ARC_RELEASE(_fileName);
|
||||||
|
_fileName = nil;
|
||||||
|
ARC_RELEASE(_contentType);
|
||||||
|
_contentType = nil;
|
||||||
if (_tmpFile > 0) {
|
if (_tmpFile > 0) {
|
||||||
close(_tmpFile);
|
close(_tmpFile);
|
||||||
unlink([_tmpPath fileSystemRepresentation]);
|
unlink([_tmpPath fileSystemRepresentation]);
|
||||||
|
_tmpFile = 0;
|
||||||
}
|
}
|
||||||
[_tmpPath release];
|
ARC_RELEASE(_tmpPath);
|
||||||
|
_tmpPath = nil;
|
||||||
return (_parserState == kParserState_End ? YES : NO);
|
return (_parserState == kParserState_End ? YES : NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
DCHECK(_parserData == nil);
|
DCHECK(_parserData == nil);
|
||||||
[_arguments release];
|
ARC_RELEASE(_arguments);
|
||||||
[_files release];
|
ARC_RELEASE(_files);
|
||||||
[_boundary release];
|
ARC_RELEASE(_boundary);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
@@ -33,8 +33,8 @@
|
|||||||
|
|
||||||
@synthesize contentType=_type, contentLength=_length, statusCode=_status, cacheControlMaxAge=_maxAge, additionalHeaders=_headers;
|
@synthesize contentType=_type, contentLength=_length, statusCode=_status, cacheControlMaxAge=_maxAge, additionalHeaders=_headers;
|
||||||
|
|
||||||
+(GCDWebServerResponse*) response {
|
+ (GCDWebServerResponse*)response {
|
||||||
return [[[[self class] alloc] init] autorelease];
|
return ARC_AUTORELEASE([[[self class] alloc] init]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init {
|
- (id)init {
|
||||||
@@ -57,10 +57,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[_type release];
|
ARC_RELEASE(_type);
|
||||||
[_headers release];
|
ARC_RELEASE(_headers);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setValue:(NSString*)value forAdditionalHeader:(NSString*)header {
|
- (void)setValue:(NSString*)value forAdditionalHeader:(NSString*)header {
|
||||||
@@ -95,11 +95,11 @@
|
|||||||
@implementation GCDWebServerResponse (Extensions)
|
@implementation GCDWebServerResponse (Extensions)
|
||||||
|
|
||||||
+ (GCDWebServerResponse*)responseWithStatusCode:(NSInteger)statusCode {
|
+ (GCDWebServerResponse*)responseWithStatusCode:(NSInteger)statusCode {
|
||||||
return [[[self alloc] initWithStatusCode:statusCode] autorelease];
|
return ARC_AUTORELEASE([[self alloc] initWithStatusCode:statusCode]);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (GCDWebServerResponse*)responseWithRedirect:(NSURL*)location permanent:(BOOL)permanent {
|
+ (GCDWebServerResponse*)responseWithRedirect:(NSURL*)location permanent:(BOOL)permanent {
|
||||||
return [[[self alloc] initWithRedirect:location permanent:permanent] autorelease];
|
return ARC_AUTORELEASE([[self alloc] initWithRedirect:location permanent:permanent]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithStatusCode:(NSInteger)statusCode {
|
- (id)initWithStatusCode:(NSInteger)statusCode {
|
||||||
@@ -122,18 +122,18 @@
|
|||||||
@implementation GCDWebServerDataResponse
|
@implementation GCDWebServerDataResponse
|
||||||
|
|
||||||
+ (GCDWebServerDataResponse*)responseWithData:(NSData*)data contentType:(NSString*)type {
|
+ (GCDWebServerDataResponse*)responseWithData:(NSData*)data contentType:(NSString*)type {
|
||||||
return [[[[self class] alloc] initWithData:data contentType:type] autorelease];
|
return ARC_AUTORELEASE([[[self class] alloc] initWithData:data contentType:type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithData:(NSData*)data contentType:(NSString*)type {
|
- (id)initWithData:(NSData*)data contentType:(NSString*)type {
|
||||||
if (data == nil) {
|
if (data == nil) {
|
||||||
DNOT_REACHED();
|
DNOT_REACHED();
|
||||||
[self release];
|
ARC_RELEASE(self);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((self = [super initWithContentType:type contentLength:data.length])) {
|
if ((self = [super initWithContentType:type contentLength:data.length])) {
|
||||||
_data = [data retain];
|
_data = ARC_RETAIN(data);
|
||||||
_offset = -1;
|
_offset = -1;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@@ -141,9 +141,9 @@
|
|||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
DCHECK(_offset < 0);
|
DCHECK(_offset < 0);
|
||||||
[_data release];
|
ARC_RELEASE(_data);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)open {
|
- (BOOL)open {
|
||||||
@@ -174,22 +174,22 @@
|
|||||||
@implementation GCDWebServerDataResponse (Extensions)
|
@implementation GCDWebServerDataResponse (Extensions)
|
||||||
|
|
||||||
+ (GCDWebServerDataResponse*)responseWithText:(NSString*)text {
|
+ (GCDWebServerDataResponse*)responseWithText:(NSString*)text {
|
||||||
return [[[self alloc] initWithText:text] autorelease];
|
return ARC_AUTORELEASE([[self alloc] initWithText:text]);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (GCDWebServerDataResponse*)responseWithHTML:(NSString*)html {
|
+ (GCDWebServerDataResponse*)responseWithHTML:(NSString*)html {
|
||||||
return [[[self alloc] initWithHTML:html] autorelease];
|
return ARC_AUTORELEASE([[self alloc] initWithHTML:html]);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (GCDWebServerDataResponse*)responseWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables {
|
+ (GCDWebServerDataResponse*)responseWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables {
|
||||||
return [[[self alloc] initWithHTMLTemplate:path variables:variables] autorelease];
|
return ARC_AUTORELEASE([[self alloc] initWithHTMLTemplate:path variables:variables]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithText:(NSString*)text {
|
- (id)initWithText:(NSString*)text {
|
||||||
NSData* data = [text dataUsingEncoding:NSUTF8StringEncoding];
|
NSData* data = [text dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
if (data == nil) {
|
if (data == nil) {
|
||||||
DNOT_REACHED();
|
DNOT_REACHED();
|
||||||
[self release];
|
ARC_RELEASE(self);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
return [self initWithData:data contentType:@"text/plain; charset=utf-8"];
|
return [self initWithData:data contentType:@"text/plain; charset=utf-8"];
|
||||||
@@ -199,7 +199,7 @@
|
|||||||
NSData* data = [html dataUsingEncoding:NSUTF8StringEncoding];
|
NSData* data = [html dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
if (data == nil) {
|
if (data == nil) {
|
||||||
DNOT_REACHED();
|
DNOT_REACHED();
|
||||||
[self release];
|
ARC_RELEASE(self);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
return [self initWithData:data contentType:@"text/html; charset=utf-8"];
|
return [self initWithData:data contentType:@"text/html; charset=utf-8"];
|
||||||
@@ -211,7 +211,7 @@
|
|||||||
[html replaceOccurrencesOfString:[NSString stringWithFormat:@"%%%@%%", key] withString:value options:0 range:NSMakeRange(0, html.length)];
|
[html replaceOccurrencesOfString:[NSString stringWithFormat:@"%%%@%%", key] withString:value options:0 range:NSMakeRange(0, html.length)];
|
||||||
}];
|
}];
|
||||||
id response = [self initWithHTML:html];
|
id response = [self initWithHTML:html];
|
||||||
[html release];
|
ARC_RELEASE(html);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,11 +220,11 @@
|
|||||||
@implementation GCDWebServerFileResponse
|
@implementation GCDWebServerFileResponse
|
||||||
|
|
||||||
+ (GCDWebServerFileResponse*)responseWithFile:(NSString*)path {
|
+ (GCDWebServerFileResponse*)responseWithFile:(NSString*)path {
|
||||||
return [[[[self class] alloc] initWithFile:path] autorelease];
|
return ARC_AUTORELEASE([[[self class] alloc] initWithFile:path]);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (GCDWebServerFileResponse*)responseWithFile:(NSString*)path isAttachment:(BOOL)attachment {
|
+ (GCDWebServerFileResponse*)responseWithFile:(NSString*)path isAttachment:(BOOL)attachment {
|
||||||
return [[[[self class] alloc] initWithFile:path isAttachment:attachment] autorelease];
|
return ARC_AUTORELEASE([[[self class] alloc] initWithFile:path isAttachment:attachment]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithFile:(NSString*)path {
|
- (id)initWithFile:(NSString*)path {
|
||||||
@@ -235,7 +235,7 @@
|
|||||||
struct stat info;
|
struct stat info;
|
||||||
if (lstat([path fileSystemRepresentation], &info) || !(info.st_mode & S_IFREG)) {
|
if (lstat([path fileSystemRepresentation], &info) || !(info.st_mode & S_IFREG)) {
|
||||||
DNOT_REACHED();
|
DNOT_REACHED();
|
||||||
[self release];
|
ARC_RELEASE(self);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
NSString* type = GCDWebServerGetMimeTypeForExtension([path pathExtension]);
|
NSString* type = GCDWebServerGetMimeTypeForExtension([path pathExtension]);
|
||||||
@@ -243,14 +243,14 @@
|
|||||||
type = kGCDWebServerDefaultMimeType;
|
type = kGCDWebServerDefaultMimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((self = [super initWithContentType:type contentLength:info.st_size])) {
|
if ((self = [super initWithContentType:type contentLength:(NSUInteger)info.st_size])) {
|
||||||
_path = [path copy];
|
_path = [path copy];
|
||||||
if (attachment) { // TODO: Use http://tools.ietf.org/html/rfc5987 to encode file names with special characters instead of using lossy conversion to ISO 8859-1
|
if (attachment) { // TODO: Use http://tools.ietf.org/html/rfc5987 to encode file names with special characters instead of using lossy conversion to ISO 8859-1
|
||||||
NSData* data = [[path lastPathComponent] dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:YES];
|
NSData* data = [[path lastPathComponent] dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:YES];
|
||||||
NSString* fileName = data ? [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding] : nil;
|
NSString* fileName = data ? [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding] : nil;
|
||||||
if (fileName) {
|
if (fileName) {
|
||||||
[self setValue:[NSString stringWithFormat:@"attachment; filename=\"%@\"", fileName] forAdditionalHeader:@"Content-Disposition"];
|
[self setValue:[NSString stringWithFormat:@"attachment; filename=\"%@\"", fileName] forAdditionalHeader:@"Content-Disposition"];
|
||||||
[fileName release];
|
ARC_RELEASE(fileName);
|
||||||
} else {
|
} else {
|
||||||
DNOT_REACHED();
|
DNOT_REACHED();
|
||||||
}
|
}
|
||||||
@@ -261,9 +261,9 @@
|
|||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
DCHECK(_file <= 0);
|
DCHECK(_file <= 0);
|
||||||
[_path release];
|
ARC_RELEASE(_path);
|
||||||
|
|
||||||
[super dealloc];
|
ARC_DEALLOC(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)open {
|
- (BOOL)open {
|
||||||
|
|||||||
18
GCDWebServer.podspec
Normal file
18
GCDWebServer.podspec
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
Pod::Spec.new do |s|
|
||||||
|
s.name = 'GCDWebServer'
|
||||||
|
s.version = '1.2'
|
||||||
|
s.author = { 'Pierre-Olivier Latour' => 'info@pol-online.net' }
|
||||||
|
s.license = { :type => 'BSD', :file => 'LICENSE' }
|
||||||
|
s.homepage = 'https://github.com/swisspol/GCDWebServer'
|
||||||
|
s.summary = 'Lightweight GCD based HTTP server for Mac OS X & iOS apps'
|
||||||
|
s.source = { :git => 'https://github.com/swisspol/GCDWebServer.git', :tag => s.version.to_s }
|
||||||
|
|
||||||
|
s.requires_arc = true
|
||||||
|
|
||||||
|
s.source_files = 'CGDWebServer/*.{h,m}'
|
||||||
|
|
||||||
|
s.ios.deployment_target = '5.0'
|
||||||
|
s.osx.deployment_target = '10.7'
|
||||||
|
|
||||||
|
s.ios.framework = 'MobileCoreServices'
|
||||||
|
end
|
||||||
@@ -6,6 +6,21 @@
|
|||||||
objectVersion = 46;
|
objectVersion = 46;
|
||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
|
/* Begin PBXAggregateTarget section */
|
||||||
|
E274F876187E77D8009E0582 /* Build All */ = {
|
||||||
|
isa = PBXAggregateTarget;
|
||||||
|
buildConfigurationList = E274F879187E77D8009E0582 /* Build configuration list for PBXAggregateTarget "Build All" */;
|
||||||
|
buildPhases = (
|
||||||
|
);
|
||||||
|
dependencies = (
|
||||||
|
E274F87D187E77E5009E0582 /* PBXTargetDependency */,
|
||||||
|
E274F87B187E77E3009E0582 /* PBXTargetDependency */,
|
||||||
|
);
|
||||||
|
name = "Build All";
|
||||||
|
productName = "Build All";
|
||||||
|
};
|
||||||
|
/* End PBXAggregateTarget section */
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
E208D149167B76B700500836 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E208D148167B76B700500836 /* CFNetwork.framework */; };
|
E208D149167B76B700500836 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E208D148167B76B700500836 /* CFNetwork.framework */; };
|
||||||
E208D1B3167BB17E00500836 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E208D1B2167BB17E00500836 /* CoreServices.framework */; };
|
E208D1B3167BB17E00500836 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E208D1B2167BB17E00500836 /* CoreServices.framework */; };
|
||||||
@@ -25,6 +40,23 @@
|
|||||||
E221129D1690B7BA0048D2B2 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E221129C1690B7BA0048D2B2 /* MobileCoreServices.framework */; };
|
E221129D1690B7BA0048D2B2 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E221129C1690B7BA0048D2B2 /* MobileCoreServices.framework */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
|
/* Begin PBXContainerItemProxy section */
|
||||||
|
E274F87A187E77E3009E0582 /* PBXContainerItemProxy */ = {
|
||||||
|
isa = PBXContainerItemProxy;
|
||||||
|
containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */;
|
||||||
|
proxyType = 1;
|
||||||
|
remoteGlobalIDString = 8DD76FA90486AB0100D96B5E;
|
||||||
|
remoteInfo = "GCDWebServer (Mac)";
|
||||||
|
};
|
||||||
|
E274F87C187E77E5009E0582 /* PBXContainerItemProxy */ = {
|
||||||
|
isa = PBXContainerItemProxy;
|
||||||
|
containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */;
|
||||||
|
proxyType = 1;
|
||||||
|
remoteGlobalIDString = E22112591690B4DE0048D2B2;
|
||||||
|
remoteInfo = "GCDWebServer (iOS)";
|
||||||
|
};
|
||||||
|
/* End PBXContainerItemProxy section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
8DD76FB20486AB0100D96B5E /* GCDWebServer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = GCDWebServer; sourceTree = BUILT_PRODUCTS_DIR; };
|
8DD76FB20486AB0100D96B5E /* GCDWebServer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = GCDWebServer; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
E208D148167B76B700500836 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
|
E208D148167B76B700500836 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
|
||||||
@@ -189,6 +221,9 @@
|
|||||||
/* Begin PBXProject section */
|
/* Begin PBXProject section */
|
||||||
08FB7793FE84155DC02AAC07 /* Project object */ = {
|
08FB7793FE84155DC02AAC07 /* Project object */ = {
|
||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
|
attributes = {
|
||||||
|
LastUpgradeCheck = 0500;
|
||||||
|
};
|
||||||
buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "GCDWebServer" */;
|
buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "GCDWebServer" */;
|
||||||
compatibilityVersion = "Xcode 3.2";
|
compatibilityVersion = "Xcode 3.2";
|
||||||
developmentRegion = English;
|
developmentRegion = English;
|
||||||
@@ -204,6 +239,7 @@
|
|||||||
projectDirPath = "";
|
projectDirPath = "";
|
||||||
projectRoot = "";
|
projectRoot = "";
|
||||||
targets = (
|
targets = (
|
||||||
|
E274F876187E77D8009E0582 /* Build All */,
|
||||||
8DD76FA90486AB0100D96B5E /* GCDWebServer (Mac) */,
|
8DD76FA90486AB0100D96B5E /* GCDWebServer (Mac) */,
|
||||||
E22112591690B4DE0048D2B2 /* GCDWebServer (iOS) */,
|
E22112591690B4DE0048D2B2 /* GCDWebServer (iOS) */,
|
||||||
);
|
);
|
||||||
@@ -238,11 +274,24 @@
|
|||||||
};
|
};
|
||||||
/* End PBXSourcesBuildPhase section */
|
/* End PBXSourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXTargetDependency section */
|
||||||
|
E274F87B187E77E3009E0582 /* PBXTargetDependency */ = {
|
||||||
|
isa = PBXTargetDependency;
|
||||||
|
target = 8DD76FA90486AB0100D96B5E /* GCDWebServer (Mac) */;
|
||||||
|
targetProxy = E274F87A187E77E3009E0582 /* PBXContainerItemProxy */;
|
||||||
|
};
|
||||||
|
E274F87D187E77E5009E0582 /* PBXTargetDependency */ = {
|
||||||
|
isa = PBXTargetDependency;
|
||||||
|
target = E22112591690B4DE0048D2B2 /* GCDWebServer (iOS) */;
|
||||||
|
targetProxy = E274F87C187E77E5009E0582 /* PBXContainerItemProxy */;
|
||||||
|
};
|
||||||
|
/* End PBXTargetDependency section */
|
||||||
|
|
||||||
/* Begin XCBuildConfiguration section */
|
/* Begin XCBuildConfiguration section */
|
||||||
1DEB928608733DD80010E9CD /* Debug */ = {
|
1DEB928608733DD80010E9CD /* Debug */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
|
ARCHS = "$(ARCHS_STANDARD)";
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.7;
|
MACOSX_DEPLOYMENT_TARGET = 10.7;
|
||||||
PRODUCT_NAME = GCDWebServer;
|
PRODUCT_NAME = GCDWebServer;
|
||||||
SDKROOT = macosx;
|
SDKROOT = macosx;
|
||||||
@@ -252,7 +301,7 @@
|
|||||||
1DEB928708733DD80010E9CD /* Release */ = {
|
1DEB928708733DD80010E9CD /* Release */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
|
ARCHS = "$(ARCHS_STANDARD)";
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.7;
|
MACOSX_DEPLOYMENT_TARGET = 10.7;
|
||||||
PRODUCT_NAME = GCDWebServer;
|
PRODUCT_NAME = GCDWebServer;
|
||||||
SDKROOT = macosx;
|
SDKROOT = macosx;
|
||||||
@@ -262,6 +311,7 @@
|
|||||||
1DEB928A08733DD80010E9CD /* Debug */ = {
|
1DEB928A08733DD80010E9CD /* Debug */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
GCC_OPTIMIZATION_LEVEL = 0;
|
GCC_OPTIMIZATION_LEVEL = 0;
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
WARNING_CFLAGS = "-Wall";
|
WARNING_CFLAGS = "-Wall";
|
||||||
@@ -271,10 +321,8 @@
|
|||||||
1DEB928B08733DD80010E9CD /* Release */ = {
|
1DEB928B08733DD80010E9CD /* Release */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
NDEBUG,
|
GCC_PREPROCESSOR_DEFINITIONS = NDEBUG;
|
||||||
NS_BLOCK_ASSERTIONS,
|
|
||||||
);
|
|
||||||
WARNING_CFLAGS = "-Wall";
|
WARNING_CFLAGS = "-Wall";
|
||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
@@ -282,6 +330,7 @@
|
|||||||
E22112761690B4DF0048D2B2 /* Debug */ = {
|
E22112761690B4DF0048D2B2 /* Debug */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
|
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
|
||||||
CODE_SIGN_IDENTITY = "iPhone Developer";
|
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||||
INFOPLIST_FILE = iOS/Info.plist;
|
INFOPLIST_FILE = iOS/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
|
||||||
@@ -295,6 +344,7 @@
|
|||||||
E22112771690B4DF0048D2B2 /* Release */ = {
|
E22112771690B4DF0048D2B2 /* Release */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
|
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
|
||||||
CODE_SIGN_IDENTITY = "iPhone Developer";
|
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||||
INFOPLIST_FILE = iOS/Info.plist;
|
INFOPLIST_FILE = iOS/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
|
||||||
@@ -305,6 +355,20 @@
|
|||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
};
|
};
|
||||||
|
E274F877187E77D8009E0582 /* Debug */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
};
|
||||||
|
name = Debug;
|
||||||
|
};
|
||||||
|
E274F878187E77D8009E0582 /* Release */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
};
|
||||||
|
name = Release;
|
||||||
|
};
|
||||||
/* End XCBuildConfiguration section */
|
/* End XCBuildConfiguration section */
|
||||||
|
|
||||||
/* Begin XCConfigurationList section */
|
/* Begin XCConfigurationList section */
|
||||||
@@ -333,6 +397,16 @@
|
|||||||
E22112771690B4DF0048D2B2 /* Release */,
|
E22112771690B4DF0048D2B2 /* Release */,
|
||||||
);
|
);
|
||||||
defaultConfigurationIsVisible = 0;
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
|
};
|
||||||
|
E274F879187E77D8009E0582 /* Build configuration list for PBXAggregateTarget "Build All" */ = {
|
||||||
|
isa = XCConfigurationList;
|
||||||
|
buildConfigurations = (
|
||||||
|
E274F877187E77D8009E0582 /* Debug */,
|
||||||
|
E274F878187E77D8009E0582 /* Release */,
|
||||||
|
);
|
||||||
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
};
|
};
|
||||||
/* End XCConfigurationList section */
|
/* End XCConfigurationList section */
|
||||||
};
|
};
|
||||||
|
|||||||
8
LICENSE
8
LICENSE
@@ -8,14 +8,14 @@ modification, are permitted provided that the following conditions are met:
|
|||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
|||||||
10
Mac/main.m
10
Mac/main.m
@@ -9,14 +9,14 @@
|
|||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
@@ -81,7 +81,9 @@ int main(int argc, const char* argv[]) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
success = [webServer runWithPort:8080];
|
success = [webServer runWithPort:8080];
|
||||||
|
#if !__has_feature(objc_arc)
|
||||||
[webServer release];
|
[webServer release];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return success ? 0 : -1;
|
return success ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -7,7 +7,7 @@ GCDWebServer is a lightweight GCD based HTTP 1.1 server designed to be embedded
|
|||||||
* Support for streaming large HTTP bodies for requests and responses to minimize memory usage
|
* Support for streaming large HTTP bodies for requests and responses to minimize memory usage
|
||||||
* Built-in parser for web forms submitted using "application/x-www-form-urlencoded" or "multipart/form-data" encodings (including file uploads)
|
* Built-in parser for web forms submitted using "application/x-www-form-urlencoded" or "multipart/form-data" encodings (including file uploads)
|
||||||
* Minimal number of source files and no dependencies on third-party source code
|
* Minimal number of source files and no dependencies on third-party source code
|
||||||
* Available under a friendly [New BSD License](GCDWebServer/blob/master/LICENSE)
|
* Available under a friendly [New BSD License](LICENSE)
|
||||||
|
|
||||||
What's not available out of the box but can be implemented on top of the API:
|
What's not available out of the box but can be implemented on top of the API:
|
||||||
* Authentication like Basic Authentication
|
* Authentication like Basic Authentication
|
||||||
@@ -83,7 +83,7 @@ You start by creating an instance of the 'GCDWebServer' class. Note that you can
|
|||||||
|
|
||||||
Then you add one or more "handlers" to the server: each handler gets a chance to handle an incoming web request and provide a response. Handlers are called in a LIFO queue, so the latest added handler overrides any previously added ones.
|
Then you add one or more "handlers" to the server: each handler gets a chance to handle an incoming web request and provide a response. Handlers are called in a LIFO queue, so the latest added handler overrides any previously added ones.
|
||||||
|
|
||||||
Finally you start the server on a given port. Note that even if built on GCD, GCDWebServer still requires a runloop to be around (by default the main thread runloop is used). This is because there is no CGD API at this point to handle listening sockets, so it must be done using CFSocket which requires a runloop. However, the runloop is only used to accept the connection: immediately afterwards, the connection handling is dispatched to GCD queues.
|
Finally you start the server on a given port.
|
||||||
|
|
||||||
Understanding GCDWebServer Architecture
|
Understanding GCDWebServer Architecture
|
||||||
=======================================
|
=======================================
|
||||||
@@ -91,8 +91,8 @@ Understanding GCDWebServer Architecture
|
|||||||
GCDWebServer is made of only 4 core classes:
|
GCDWebServer is made of only 4 core classes:
|
||||||
* 'GCDWebServer' manages the socket that listens for new HTTP connections and the list of handlers used by the server.
|
* 'GCDWebServer' manages the socket that listens for new HTTP connections and the list of handlers used by the server.
|
||||||
* 'GCDWebServerConnection' is instantiated by 'GCDWebServer' to handle each new HTTP connection. Each instance stays alive until the connection is closed. You cannot use this class directly, but it is exposed so you can subclass it to override some hooks.
|
* 'GCDWebServerConnection' is instantiated by 'GCDWebServer' to handle each new HTTP connection. Each instance stays alive until the connection is closed. You cannot use this class directly, but it is exposed so you can subclass it to override some hooks.
|
||||||
* 'GCDWebServerRequest' is created by the 'GCDWebServerConnection' instance after HTTP headers have been received. It wraps the request and handles the HTTP body if any. GCDWebServer comes with several subclasses of 'GCDWebServerRequest' to handle common cases like storing the body in memory or stream it to a file on disk. See [GCDWebServerRequest.h](GCDWebServer/blob/master/CGDWebServer/GCDWebServerRequest.h) for the full list.
|
* 'GCDWebServerRequest' is created by the 'GCDWebServerConnection' instance after HTTP headers have been received. It wraps the request and handles the HTTP body if any. GCDWebServer comes with several subclasses of 'GCDWebServerRequest' to handle common cases like storing the body in memory or stream it to a file on disk. See [GCDWebServerRequest.h](CGDWebServer/GCDWebServerRequest.h) for the full list.
|
||||||
* 'GCDWebServerResponse' is created by the request handler and wraps the response HTTP headers and optional body. GCDWebServer provides several subclasses of 'GCDWebServerResponse' to handle common cases like HTML text in memory or streaming a file from disk. See [GCDWebServerResponse.h](GCDWebServer/blob/master/CGDWebServer/GCDWebServerResponse.h) for the full list.
|
* 'GCDWebServerResponse' is created by the request handler and wraps the response HTTP headers and optional body. GCDWebServer provides several subclasses of 'GCDWebServerResponse' to handle common cases like HTML text in memory or streaming a file from disk. See [GCDWebServerResponse.h](CGDWebServer/GCDWebServerResponse.h) for the full list.
|
||||||
|
|
||||||
Implementing Handlers
|
Implementing Handlers
|
||||||
=====================
|
=====================
|
||||||
@@ -203,4 +203,4 @@ Final Example: File Downloads and Uploads From iOS App
|
|||||||
|
|
||||||
GCDWebServer was originally written for the [ComicFlow](http://itunes.apple.com/us/app/comicflow/id409290355?mt=8) comic reader app for iPad. It uses it to provide a web server for people to upload and download comic files directly over WiFi to and from the app.
|
GCDWebServer was originally written for the [ComicFlow](http://itunes.apple.com/us/app/comicflow/id409290355?mt=8) comic reader app for iPad. It uses it to provide a web server for people to upload and download comic files directly over WiFi to and from the app.
|
||||||
|
|
||||||
ComicFlow is [entirely open-source](https://code.google.com/p/comicflow/) and you can see how it uses GCDWebServer in the [WebServer.m](http://code.google.com/p/comicflow/source/browse/Classes/WebServer.m) file.
|
ComicFlow is [entirely open-source](https://github.com/swisspol/ComicFlow) and you can see how it uses GCDWebServer in the [WebServer.m](https://github.com/swisspol/ComicFlow/blob/master/Classes/WebServer.m) file.
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
@@ -29,12 +29,18 @@
|
|||||||
|
|
||||||
@implementation AppDelegate
|
@implementation AppDelegate
|
||||||
|
|
||||||
|
@synthesize window=_window;
|
||||||
|
|
||||||
|
#if !__has_feature(objc_arc)
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[_window release];
|
[_window release];
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
|
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
|
||||||
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||||
_window.backgroundColor = [UIColor whiteColor];
|
_window.backgroundColor = [UIColor whiteColor];
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
* Redistributions in binary form must reproduce the above copyright
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
* Neither the name of the <organization> nor the
|
* The name of Pierre-Olivier Latour may not be used to endorse
|
||||||
names of its contributors may be used to endorse or promote products
|
or promote products derived from this software without specific
|
||||||
derived from this software without specific prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
|||||||
Reference in New Issue
Block a user