11 Commits
1.2 ... 1.2.2

Author SHA1 Message Date
Pierre-Olivier Latour
36658278f8 Fixed more build warnings 2014-01-29 09:14:23 -08:00
Pierre-Olivier Latour
0f2f22a1b0 Updated for arm64 2014-01-29 08:38:25 -08:00
Pierre-Olivier Latour
628cf6833c Make sure @bonjourName is not an empty string 2014-01-23 14:26:31 -08:00
Pierre-Olivier Latour
9392ddadb6 Added bonjourName property 2014-01-23 14:17:44 -08:00
Pierre-Olivier Latour
5dee044caa Check for main thread only during first +initialize call 2014-01-23 11:44:43 -08:00
Pierre-Olivier Latour
7c8205caa0 Don't use dispatch_release() under ARC in OS X 10.8 or iOS 6.0 and later 2014-01-23 11:33:33 -08:00
Pierre-Olivier Latour
965e111280 Don't use deprecated dispatch_get_current_queue() 2014-01-23 11:20:43 -08:00
Pierre-Olivier Latour
8a69050cca Merge pull request #14 from chrisdevereux/master
Log to stderr, not stdout
2014-01-13 10:03:33 -08:00
Chris Devereux
a15a49240a Log to stderr, not stdout 2014-01-13 12:58:54 +00:00
Pierre-Olivier Latour
404b46537e Merge pull request #13 from djmadcat/master
Add podspec for version 1.2
2014-01-12 17:06:46 -08:00
Alexey Aleshkov
811e18e2fa Add podspec for version 1.2 2014-01-13 01:44:54 +04:00
9 changed files with 51 additions and 12 deletions

View File

@@ -41,6 +41,7 @@ typedef GCDWebServerResponse* (^GCDWebServerProcessBlock)(GCDWebServerRequest* r
}
@property(nonatomic, readonly, getter=isRunning) BOOL running;
@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)removeAllHandlers;

View File

@@ -145,6 +145,11 @@ static void _SignalHandler(int signal) {
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 {
DCHECK(_source == NULL);
GCDWebServerHandler* handler = [[GCDWebServerHandler alloc] initWithMatchBlock:matchBlock processBlock:handlerBlock];
@@ -166,7 +171,7 @@ static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* er
if (error->error) {
LOG_ERROR(@"Bonjour error %i (domain %i)", error->error, (int)error->domain);
} 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));
}
}
}
@@ -239,7 +244,7 @@ static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* er
}
if (name) {
_service = CFNetServiceCreate(kCFAllocatorDefault, CFSTR("local."), CFSTR("_http._tcp"), (ARC_BRIDGE CFStringRef)name, _port);
_service = CFNetServiceCreate(kCFAllocatorDefault, CFSTR("local."), CFSTR("_http._tcp"), (ARC_BRIDGE CFStringRef)name, (SInt32)_port);
if (_service) {
CFNetServiceClientContext context = {0, (ARC_BRIDGE void*)self, NULL, NULL, NULL};
CFNetServiceSetClient(_service, _NetServiceClientCallBack, &context);
@@ -282,7 +287,7 @@ static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* er
}
dispatch_source_cancel(_source); // This will close the socket
dispatch_release(_source);
ARC_DISPATCH_RELEASE(_source);
_source = NULL;
LOG_VERBOSE(@"%@ stopped", [self class]);
@@ -309,7 +314,7 @@ static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* er
- (BOOL)runWithPort:(NSUInteger)port {
BOOL success = NO;
_run = YES;
void* handler = signal(SIGINT, _SignalHandler);
void (*handler)(int) = signal(SIGINT, _SignalHandler);
if (handler != SIG_ERR) {
if ([self startWithPort:port bonjourName:@""]) {
while (_run) {

View File

@@ -193,7 +193,7 @@ static dispatch_queue_t _formatterQueue = NULL;
#if !__has_feature(objc_arc)
[data retain];
#endif
dispatch_data_t buffer = dispatch_data_create(data.bytes, data.length, dispatch_get_current_queue(), ^{
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
@@ -201,7 +201,7 @@ static dispatch_queue_t _formatterQueue = NULL;
#endif
});
[self _writeBuffer:buffer withCompletionBlock:block];
dispatch_release(buffer);
ARC_DISPATCH_RELEASE(buffer);
}
- (void)_writeHeadersWithCompletionBlock:(WriteHeadersCompletionBlock)block {
@@ -226,7 +226,7 @@ static dispatch_queue_t _formatterQueue = NULL;
}
}];
dispatch_release(wrapper);
ARC_DISPATCH_RELEASE(wrapper);
} else if (result < 0) {
LOG_ERROR(@"Failed reading response body on socket %i (error %i)", _socket, (int)result);
block(NO);
@@ -244,7 +244,6 @@ static dispatch_queue_t _formatterQueue = NULL;
@synthesize server=_server, address=_address, totalBytesRead=_bytesRead, totalBytesWritten=_bytesWritten;
+ (void)initialize {
DCHECK([NSThread isMainThread]); // NSDateFormatter should be initialized on main thread
if (_separatorData == nil) {
_separatorData = [[NSData alloc] initWithBytes:"\r\n\r\n" length:4];
DCHECK(_separatorData);
@@ -260,6 +259,7 @@ static dispatch_queue_t _formatterQueue = NULL;
DCHECK(_continueData);
}
if (_dateFormatter == nil) {
DCHECK([NSThread isMainThread]); // NSDateFormatter should be initialized on main thread
_dateFormatter = [[NSDateFormatter alloc] init];
_dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
_dateFormatter.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'";

View File

@@ -25,6 +25,9 @@
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__)
@@ -32,6 +35,11 @@
#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]
@@ -39,6 +47,7 @@
#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"
@@ -62,7 +71,7 @@ static inline void __LogMessage(long level, NSString* format, ...) {
va_start(arguments, format);
NSString* message = [[NSString alloc] initWithFormat:format arguments:arguments];
va_end(arguments);
printf("[%s] %s\n", levelNames[level], [message UTF8String]);
fprintf(stderr, "[%s] %s\n", levelNames[level], [message UTF8String]);
ARC_RELEASE(message);
}
}

View File

@@ -429,7 +429,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
const void* dataBytes = _parserData.bytes;
NSUInteger dataLength = range.location - 2;
if (_tmpPath) {
int result = write(_tmpFile, dataBytes, dataLength);
ssize_t result = write(_tmpFile, dataBytes, dataLength);
if (result == dataLength) {
if (close(_tmpFile) == 0) {
_tmpFile = 0;
@@ -467,7 +467,7 @@ static NSStringEncoding _StringEncodingFromCharset(NSString* charset) {
NSUInteger margin = 2 * _boundary.length;
if (_tmpPath && (_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) {
[_parserData replaceBytesInRange:NSMakeRange(0, length) withBytes:NULL length:0];
} else {

View File

@@ -243,7 +243,7 @@
type = kGCDWebServerDefaultMimeType;
}
if ((self = [super initWithContentType:type contentLength:info.st_size])) {
if ((self = [super initWithContentType:type contentLength:(NSUInteger)info.st_size])) {
_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
NSData* data = [[path lastPathComponent] dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:YES];

18
GCDWebServer.podspec Normal file
View 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

View File

@@ -291,6 +291,7 @@
1DEB928608733DD80010E9CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = GCDWebServer;
SDKROOT = macosx;
@@ -300,6 +301,7 @@
1DEB928708733DD80010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = GCDWebServer;
SDKROOT = macosx;
@@ -328,6 +330,7 @@
E22112761690B4DF0048D2B2 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = iOS/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
@@ -341,6 +344,7 @@
E22112771690B4DF0048D2B2 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = iOS/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;

View File

@@ -29,6 +29,8 @@
@implementation AppDelegate
@synthesize window=_window;
#if !__has_feature(objc_arc)
- (void)dealloc {