From d8594f74aea62784f8125b833e1d1f0f8c3a73e9 Mon Sep 17 00:00:00 2001 From: Tom Meier Date: Fri, 24 Jul 2015 16:18:10 +0200 Subject: [PATCH 1/4] Update to 2.x Cocoalumberjack usage --- CocoaHTTPServer.podspec.json | 4 ++-- Core/HTTPLogging.h | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CocoaHTTPServer.podspec.json b/CocoaHTTPServer.podspec.json index 6f09ea06..d22f4f93 100644 --- a/CocoaHTTPServer.podspec.json +++ b/CocoaHTTPServer.podspec.json @@ -38,7 +38,7 @@ ], "CocoaLumberjack": [ - + ">= 2.0.0" ] } -} \ No newline at end of file +} diff --git a/Core/HTTPLogging.h b/Core/HTTPLogging.h index 2e4bbcd0..200cfc8a 100644 --- a/Core/HTTPLogging.h +++ b/Core/HTTPLogging.h @@ -1,52 +1,52 @@ /** * In order to provide fast and flexible logging, this project uses Cocoa Lumberjack. - * + * * The Google Code page has a wealth of documentation if you have any questions. * https://github.com/robbiehanson/CocoaLumberjack - * + * * Here's what you need to know concerning how logging is setup for CocoaHTTPServer: - * + * * There are 4 log levels: * - Error * - Warning * - Info * - Verbose - * + * * In addition to this, there is a Trace flag that can be enabled. * When tracing is enabled, it spits out the methods that are being called. - * + * * Please note that tracing is separate from the log levels. * For example, one could set the log level to warning, and enable tracing. - * + * * All logging is asynchronous, except errors. * To use logging within your own custom files, follow the steps below. - * + * * Step 1: * Import this header in your implementation file: - * + * * #import "HTTPLogging.h" - * + * * Step 2: * Define your logging level in your implementation file: - * + * * // Log levels: off, error, warn, info, verbose * static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE; - * + * * If you wish to enable tracing, you could do something like this: - * + * * // Debug levels: off, error, warn, info, verbose * static const int httpLogLevel = HTTP_LOG_LEVEL_INFO | HTTP_LOG_FLAG_TRACE; - * + * * Step 3: * Replace your NSLog statements with HTTPLog statements according to the severity of the message. - * + * * NSLog(@"Fatal error, no dohickey found!"); -> HTTPLogError(@"Fatal error, no dohickey found!"); - * + * * HTTPLog works exactly the same as NSLog. * This means you can pass it multiple variables just like NSLog. **/ -#import "DDLog.h" +#import // Define logging context for every log message coming from the HTTP server. // The logging context can be extracted from the DDLogMessage from within the logging framework, @@ -69,7 +69,7 @@ // Setup fine grained logging. // The first 4 bits are being used by the standard log levels (0 - 3) -// +// // We're going to add tracing, but NOT as a log level. // Tracing can be turned on and off independently of log level. From 4ecb6ec23f2872536675f83f351a0b8ea3b17a58 Mon Sep 17 00:00:00 2001 From: Tom Meier Date: Fri, 24 Jul 2015 16:18:19 +0200 Subject: [PATCH 2/4] Preliminary update of samples --- .../DynamicServer/DynamicServerAppDelegate.m | 23 +++++++++---------- Samples/PasswdHTTPServer/AppDelegate.m | 18 +++++++-------- Samples/PostHTTPServer/AppDelegate.m | 20 ++++++++-------- Samples/SecureHTTPServer/AppDelegate.m | 20 ++++++++-------- .../SecureWebSocketServerAppDelegate.m | 21 ++++++++--------- .../SimpleFileUploadServer/AppDelegate.m | 18 +++++++-------- Samples/SimpleHTTPServer/AppDelegate.m | 16 ++++++------- .../SimpleWebSocketServerAppDelegate.m | 20 ++++++++-------- Samples/WebDAVServer/AppDelegate.m | 12 +++++----- .../Classes/iPhoneHTTPServerAppDelegate.m | 23 +++++++++---------- 10 files changed, 94 insertions(+), 97 deletions(-) diff --git a/Samples/DynamicServer/DynamicServerAppDelegate.m b/Samples/DynamicServer/DynamicServerAppDelegate.m index 52efc16e..6e984778 100644 --- a/Samples/DynamicServer/DynamicServerAppDelegate.m +++ b/Samples/DynamicServer/DynamicServerAppDelegate.m @@ -1,12 +1,11 @@ +#import #import "DynamicServerAppDelegate.h" #import "HTTPServer.h" #import "MyHTTPConnection.h" -#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const int ddLogLevel = LOG_LEVEL_VERBOSE; - +static const DDLogLevel ddLogLevel = DDLogLevelVerbose; @implementation DynamicServerAppDelegate @@ -17,33 +16,33 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Initalize our http server httpServer = [[HTTPServer alloc] init]; - + // Tell server to use our custom MyHTTPConnection class. [httpServer setConnectionClass:[MyHTTPConnection class]]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // Serve files from our embedded Web folder NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Web"]; DDLogVerbose(@"Setting document root: %@", webPath); - + [httpServer setDocumentRoot:webPath]; - + // Start the server (and check for problems) - + NSError *error; BOOL success = [httpServer start:&error]; - + if(!success) { DDLogError(@"Error starting HTTP Server: %@", error); diff --git a/Samples/PasswdHTTPServer/AppDelegate.m b/Samples/PasswdHTTPServer/AppDelegate.m index 9e963812..c3541c5a 100644 --- a/Samples/PasswdHTTPServer/AppDelegate.m +++ b/Samples/PasswdHTTPServer/AppDelegate.m @@ -1,11 +1,11 @@ +#import #import "AppDelegate.h" #import "HTTPServer.h" #import "MyHTTPConnection.h" -#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const int ddLogLevel = LOG_LEVEL_VERBOSE; +static const DDLogLevel ddLogLevel = DDLogLevelVerbose; @implementation AppDelegate @@ -15,29 +15,29 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Initalize our http server httpServer = [[HTTPServer alloc] init]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // We're going to extend the base HTTPConnection class with our MyHTTPConnection class. // This allows us to do custom password protection on our sensitive directories. [httpServer setConnectionClass:[MyHTTPConnection class]]; - + // Serve files from the standard Sites folder NSString *docRoot = [@"~/Sites" stringByExpandingTildeInPath]; DDLogInfo(@"Setting document root: %@", docRoot); - + [httpServer setDocumentRoot:docRoot]; - + NSError *error = nil; if (![httpServer start:&error]) { diff --git a/Samples/PostHTTPServer/AppDelegate.m b/Samples/PostHTTPServer/AppDelegate.m index 0c332916..96a52cfc 100644 --- a/Samples/PostHTTPServer/AppDelegate.m +++ b/Samples/PostHTTPServer/AppDelegate.m @@ -1,11 +1,11 @@ +#import #import "AppDelegate.h" #import "HTTPServer.h" #import "MyHTTPConnection.h" -#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const int ddLogLevel = LOG_LEVEL_VERBOSE; +static const DDLogLevel ddLogLevel = DDLogLevelVerbose; @implementation AppDelegate @@ -15,30 +15,30 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Initalize our http server httpServer = [[HTTPServer alloc] init]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // We're going to extend the base HTTPConnection class with our MyHTTPConnection class. // This allows us to do all kinds of customizations. [httpServer setConnectionClass:[MyHTTPConnection class]]; - + // Serve files from our embedded Web folder NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Web"]; DDLogInfo(@"Setting document root: %@", webPath); - + [httpServer setDocumentRoot:webPath]; - - + + NSError *error = nil; if(![httpServer start:&error]) { diff --git a/Samples/SecureHTTPServer/AppDelegate.m b/Samples/SecureHTTPServer/AppDelegate.m index 8efca1b3..ff6db823 100644 --- a/Samples/SecureHTTPServer/AppDelegate.m +++ b/Samples/SecureHTTPServer/AppDelegate.m @@ -1,11 +1,11 @@ +#import #import "AppDelegate.h" #import "HTTPServer.h" #import "MyHTTPConnection.h" -#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const int ddLogLevel = LOG_LEVEL_VERBOSE; +static const DDLogLevel ddLogLevel = DDLogLevelVerbose; @implementation AppDelegate @@ -15,32 +15,32 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Initalize our http server httpServer = [[HTTPServer alloc] init]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. // [httpServer setType:@"_http._tcp."]; - + // Note: Clicking the bonjour service in Safari won't work because Safari will use http and not https. // Just change the url to https for proper access. - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // We're going to extend the base HTTPConnection class with our MyHTTPConnection class. // This allows us to customize the server for things such as SSL and password-protection. [httpServer setConnectionClass:[MyHTTPConnection class]]; - + // Serve files from the standard Sites folder NSString *docRoot = [@"~/Sites" stringByExpandingTildeInPath]; DDLogInfo(@"Setting document root: %@", docRoot); - + [httpServer setDocumentRoot:docRoot]; - + NSError *error = nil; if(![httpServer start:&error]) { diff --git a/Samples/SecureWebSocketServer/SecureWebSocketServer/SecureWebSocketServerAppDelegate.m b/Samples/SecureWebSocketServer/SecureWebSocketServer/SecureWebSocketServerAppDelegate.m index b58c3f6a..9d41a92f 100644 --- a/Samples/SecureWebSocketServer/SecureWebSocketServer/SecureWebSocketServerAppDelegate.m +++ b/Samples/SecureWebSocketServer/SecureWebSocketServer/SecureWebSocketServerAppDelegate.m @@ -1,12 +1,11 @@ +#import #import "SecureWebSocketServerAppDelegate.h" #import "HTTPServer.h" #import "MyHTTPConnection.h" -#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const int ddLogLevel = LOG_LEVEL_VERBOSE; - +static const DDLogLevel ddLogLevel = DDLogLevelVerbose; @implementation SecureWebSocketServerAppDelegate @@ -17,30 +16,30 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Create server using our custom MyHTTPServer class httpServer = [[HTTPServer alloc] init]; - + // Tell server to use our custom MyHTTPConnection class. [httpServer setConnectionClass:[MyHTTPConnection class]]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // Serve files from our embedded Web folder NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Web"]; DDLogInfo(@"Setting document root: %@", webPath); - + [httpServer setDocumentRoot:webPath]; - + // Start the server (and check for problems) - + NSError *error; if(![httpServer start:&error]) { diff --git a/Samples/SimpleFileUploadServer/SimpleFileUploadServer/AppDelegate.m b/Samples/SimpleFileUploadServer/SimpleFileUploadServer/AppDelegate.m index e7488186..d73ed050 100644 --- a/Samples/SimpleFileUploadServer/SimpleFileUploadServer/AppDelegate.m +++ b/Samples/SimpleFileUploadServer/SimpleFileUploadServer/AppDelegate.m @@ -1,10 +1,10 @@ +#import #import "AppDelegate.h" #import "HTTPServer.h" -#import "DDLog.h" #import "DDTTYLogger.h" #import "MyHTTPConnection.h" // Log levels: off, error, warn, info, verbose -static const int ddLogLevel = LOG_LEVEL_VERBOSE; +static const DDLogLevel ddLogLevel = DDLogLevelVerbose; @implementation AppDelegate @@ -14,27 +14,27 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Initalize our http server httpServer = [[HTTPServer alloc] init]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // Serve files from the standard Sites folder NSString *docRoot = [[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"web"] stringByDeletingLastPathComponent]; DDLogInfo(@"Setting document root: %@", docRoot); - + [httpServer setDocumentRoot:docRoot]; - + [httpServer setConnectionClass:[MyHTTPConnection class]]; - + NSError *error = nil; if(![httpServer start:&error]) { diff --git a/Samples/SimpleHTTPServer/AppDelegate.m b/Samples/SimpleHTTPServer/AppDelegate.m index 06c2fa39..4b469c9a 100644 --- a/Samples/SimpleHTTPServer/AppDelegate.m +++ b/Samples/SimpleHTTPServer/AppDelegate.m @@ -1,10 +1,10 @@ +#import #import "AppDelegate.h" #import "HTTPServer.h" -#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const int ddLogLevel = LOG_LEVEL_VERBOSE; +static const DDLogLevel ddLogLevel = DDLogLevelVerbose; @implementation AppDelegate @@ -14,25 +14,25 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Initalize our http server httpServer = [[HTTPServer alloc] init]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // Serve files from the standard Sites folder NSString *docRoot = [@"~/Sites" stringByExpandingTildeInPath]; DDLogInfo(@"Setting document root: %@", docRoot); - + [httpServer setDocumentRoot:docRoot]; - + NSError *error = nil; if(![httpServer start:&error]) { diff --git a/Samples/SimpleWebSocketServer/SimpleWebSocketServerAppDelegate.m b/Samples/SimpleWebSocketServer/SimpleWebSocketServerAppDelegate.m index 9a032138..09f892ad 100644 --- a/Samples/SimpleWebSocketServer/SimpleWebSocketServerAppDelegate.m +++ b/Samples/SimpleWebSocketServer/SimpleWebSocketServerAppDelegate.m @@ -1,11 +1,11 @@ +#import #import "SimpleWebSocketServerAppDelegate.h" #import "HTTPServer.h" #import "MyHTTPConnection.h" -#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const int ddLogLevel = LOG_LEVEL_VERBOSE; +static const DDLogLevel ddLogLevel = DDLogLevelVerbose; @implementation SimpleWebSocketServerAppDelegate @@ -17,30 +17,30 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Create server using our custom MyHTTPServer class httpServer = [[HTTPServer alloc] init]; - + // Tell server to use our custom MyHTTPConnection class. [httpServer setConnectionClass:[MyHTTPConnection class]]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // Serve files from our embedded Web folder NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Web"]; DDLogInfo(@"Setting document root: %@", webPath); - + [httpServer setDocumentRoot:webPath]; - + // Start the server (and check for problems) - + NSError *error; if(![httpServer start:&error]) { diff --git a/Samples/WebDAVServer/AppDelegate.m b/Samples/WebDAVServer/AppDelegate.m index 99739b8c..47005e47 100644 --- a/Samples/WebDAVServer/AppDelegate.m +++ b/Samples/WebDAVServer/AppDelegate.m @@ -1,28 +1,28 @@ +#import #import "AppDelegate.h" -#import "DDLog.h" #import "DDTTYLogger.h" #import "HTTPServer.h" #import "DAVConnection.h" -static const int ddLogLevel = LOG_LEVEL_VERBOSE; +static const DDLogLevel ddLogLevel = DDLogLevelVerbose; @implementation AppDelegate - (void) applicationDidFinishLaunching:(NSNotification*)notification { // Configure logging system [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Create DAV server _httpServer = [[HTTPServer alloc] init]; [_httpServer setConnectionClass:[DAVConnection class]]; [_httpServer setPort:8080]; - + // Enable Bonjour [_httpServer setType:@"_http._tcp."]; - + // Set document root [_httpServer setDocumentRoot:[@"~/Sites" stringByExpandingTildeInPath]]; - + // Start DAV server NSError* error = nil; if (![_httpServer start:&error]) { diff --git a/Samples/iPhoneHTTPServer/Classes/iPhoneHTTPServerAppDelegate.m b/Samples/iPhoneHTTPServer/Classes/iPhoneHTTPServerAppDelegate.m index 221d1c05..cece41f2 100644 --- a/Samples/iPhoneHTTPServer/Classes/iPhoneHTTPServerAppDelegate.m +++ b/Samples/iPhoneHTTPServer/Classes/iPhoneHTTPServerAppDelegate.m @@ -1,12 +1,11 @@ +#import #import "iPhoneHTTPServerAppDelegate.h" #import "iPhoneHTTPServerViewController.h" #import "HTTPServer.h" -#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const int ddLogLevel = LOG_LEVEL_VERBOSE; - +static const DDLogLevel ddLogLevel = DDLogLevelVerbose; @implementation iPhoneHTTPServerAppDelegate @@ -16,7 +15,7 @@ @implementation iPhoneHTTPServerAppDelegate - (void)startServer { // Start the server (and check for problems) - + NSError *error; if([httpServer start:&error]) { @@ -33,31 +32,31 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Create server using our custom MyHTTPServer class httpServer = [[HTTPServer alloc] init]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // Serve files from our embedded Web folder NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Web"]; DDLogInfo(@"Setting document root: %@", webPath); - + [httpServer setDocumentRoot:webPath]; [self startServer]; - + // Add the view controller's view to the window and display. [window addSubview:viewController.view]; [window makeKeyAndVisible]; - + return YES; } @@ -71,7 +70,7 @@ - (void)applicationDidEnterBackground:(UIApplication *)application // There is no public(allowed in AppStore) method for iOS to run continiously in the background for our purposes (serving HTTP). // So, we stop the server when the app is paused (if a users exits from the app or locks a device) and // restart the server when the app is resumed (based on this document: http://developer.apple.com/library/ios/#technotes/tn2277/_index.html ) - + [httpServer stop]; } From 4731696776ecd5b1d05a91ca6a59051d00dbbac4 Mon Sep 17 00:00:00 2001 From: Tom Meier Date: Fri, 24 Jul 2015 16:36:10 +0200 Subject: [PATCH 3/4] Add in missing macros --- Core/HTTPLogging.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Core/HTTPLogging.h b/Core/HTTPLogging.h index 200cfc8a..649eab87 100644 --- a/Core/HTTPLogging.h +++ b/Core/HTTPLogging.h @@ -48,6 +48,18 @@ #import +#ifndef LOG_OBJC_MAYBE + // TODO: Remove these... and just use lib directly? + #define LOG_MAYBE(async, lvl, flg, ctx, fnct, frmt, ...) \ + do { if(lvl & flg) LOG_MACRO(async, lvl, flg, ctx, nil, fnct, frmt, ##__VA_ARGS__); } while(0) + +#define LOG_OBJC_MAYBE(async, lvl, flg, ctx, frmt, ...) \ + LOG_MAYBE(async, lvl, flg, ctx, sel_getName(_cmd), frmt, ##__VA_ARGS__) + +#define LOG_C_MAYBE(async, lvl, flg, ctx, frmt, ...) \ + LOG_MAYBE(async, lvl, flg, ctx, __FUNCTION__, frmt, ##__VA_ARGS__) +#endif + // Define logging context for every log message coming from the HTTP server. // The logging context can be extracted from the DDLogMessage from within the logging framework, // which gives loggers, formatters, and filters the ability to optionally process them differently. From ab27facf739fe2618c6630af393e15c7bb2a4326 Mon Sep 17 00:00:00 2001 From: Tom Meier Date: Fri, 24 Jul 2015 16:43:59 +0200 Subject: [PATCH 4/4] Revert "Preliminary update of samples" This reverts commit 4ecb6ec23f2872536675f83f351a0b8ea3b17a58. --- .../DynamicServer/DynamicServerAppDelegate.m | 23 ++++++++++--------- Samples/PasswdHTTPServer/AppDelegate.m | 18 +++++++-------- Samples/PostHTTPServer/AppDelegate.m | 20 ++++++++-------- Samples/SecureHTTPServer/AppDelegate.m | 20 ++++++++-------- .../SecureWebSocketServerAppDelegate.m | 21 +++++++++-------- .../SimpleFileUploadServer/AppDelegate.m | 18 +++++++-------- Samples/SimpleHTTPServer/AppDelegate.m | 16 ++++++------- .../SimpleWebSocketServerAppDelegate.m | 20 ++++++++-------- Samples/WebDAVServer/AppDelegate.m | 12 +++++----- .../Classes/iPhoneHTTPServerAppDelegate.m | 23 ++++++++++--------- 10 files changed, 97 insertions(+), 94 deletions(-) diff --git a/Samples/DynamicServer/DynamicServerAppDelegate.m b/Samples/DynamicServer/DynamicServerAppDelegate.m index 6e984778..52efc16e 100644 --- a/Samples/DynamicServer/DynamicServerAppDelegate.m +++ b/Samples/DynamicServer/DynamicServerAppDelegate.m @@ -1,11 +1,12 @@ -#import #import "DynamicServerAppDelegate.h" #import "HTTPServer.h" #import "MyHTTPConnection.h" +#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const DDLogLevel ddLogLevel = DDLogLevelVerbose; +static const int ddLogLevel = LOG_LEVEL_VERBOSE; + @implementation DynamicServerAppDelegate @@ -16,33 +17,33 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Initalize our http server httpServer = [[HTTPServer alloc] init]; - + // Tell server to use our custom MyHTTPConnection class. [httpServer setConnectionClass:[MyHTTPConnection class]]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // Serve files from our embedded Web folder NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Web"]; DDLogVerbose(@"Setting document root: %@", webPath); - + [httpServer setDocumentRoot:webPath]; - + // Start the server (and check for problems) - + NSError *error; BOOL success = [httpServer start:&error]; - + if(!success) { DDLogError(@"Error starting HTTP Server: %@", error); diff --git a/Samples/PasswdHTTPServer/AppDelegate.m b/Samples/PasswdHTTPServer/AppDelegate.m index c3541c5a..9e963812 100644 --- a/Samples/PasswdHTTPServer/AppDelegate.m +++ b/Samples/PasswdHTTPServer/AppDelegate.m @@ -1,11 +1,11 @@ -#import #import "AppDelegate.h" #import "HTTPServer.h" #import "MyHTTPConnection.h" +#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const DDLogLevel ddLogLevel = DDLogLevelVerbose; +static const int ddLogLevel = LOG_LEVEL_VERBOSE; @implementation AppDelegate @@ -15,29 +15,29 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Initalize our http server httpServer = [[HTTPServer alloc] init]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // We're going to extend the base HTTPConnection class with our MyHTTPConnection class. // This allows us to do custom password protection on our sensitive directories. [httpServer setConnectionClass:[MyHTTPConnection class]]; - + // Serve files from the standard Sites folder NSString *docRoot = [@"~/Sites" stringByExpandingTildeInPath]; DDLogInfo(@"Setting document root: %@", docRoot); - + [httpServer setDocumentRoot:docRoot]; - + NSError *error = nil; if (![httpServer start:&error]) { diff --git a/Samples/PostHTTPServer/AppDelegate.m b/Samples/PostHTTPServer/AppDelegate.m index 96a52cfc..0c332916 100644 --- a/Samples/PostHTTPServer/AppDelegate.m +++ b/Samples/PostHTTPServer/AppDelegate.m @@ -1,11 +1,11 @@ -#import #import "AppDelegate.h" #import "HTTPServer.h" #import "MyHTTPConnection.h" +#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const DDLogLevel ddLogLevel = DDLogLevelVerbose; +static const int ddLogLevel = LOG_LEVEL_VERBOSE; @implementation AppDelegate @@ -15,30 +15,30 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Initalize our http server httpServer = [[HTTPServer alloc] init]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // We're going to extend the base HTTPConnection class with our MyHTTPConnection class. // This allows us to do all kinds of customizations. [httpServer setConnectionClass:[MyHTTPConnection class]]; - + // Serve files from our embedded Web folder NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Web"]; DDLogInfo(@"Setting document root: %@", webPath); - + [httpServer setDocumentRoot:webPath]; - - + + NSError *error = nil; if(![httpServer start:&error]) { diff --git a/Samples/SecureHTTPServer/AppDelegate.m b/Samples/SecureHTTPServer/AppDelegate.m index ff6db823..8efca1b3 100644 --- a/Samples/SecureHTTPServer/AppDelegate.m +++ b/Samples/SecureHTTPServer/AppDelegate.m @@ -1,11 +1,11 @@ -#import #import "AppDelegate.h" #import "HTTPServer.h" #import "MyHTTPConnection.h" +#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const DDLogLevel ddLogLevel = DDLogLevelVerbose; +static const int ddLogLevel = LOG_LEVEL_VERBOSE; @implementation AppDelegate @@ -15,32 +15,32 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Initalize our http server httpServer = [[HTTPServer alloc] init]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. // [httpServer setType:@"_http._tcp."]; - + // Note: Clicking the bonjour service in Safari won't work because Safari will use http and not https. // Just change the url to https for proper access. - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // We're going to extend the base HTTPConnection class with our MyHTTPConnection class. // This allows us to customize the server for things such as SSL and password-protection. [httpServer setConnectionClass:[MyHTTPConnection class]]; - + // Serve files from the standard Sites folder NSString *docRoot = [@"~/Sites" stringByExpandingTildeInPath]; DDLogInfo(@"Setting document root: %@", docRoot); - + [httpServer setDocumentRoot:docRoot]; - + NSError *error = nil; if(![httpServer start:&error]) { diff --git a/Samples/SecureWebSocketServer/SecureWebSocketServer/SecureWebSocketServerAppDelegate.m b/Samples/SecureWebSocketServer/SecureWebSocketServer/SecureWebSocketServerAppDelegate.m index 9d41a92f..b58c3f6a 100644 --- a/Samples/SecureWebSocketServer/SecureWebSocketServer/SecureWebSocketServerAppDelegate.m +++ b/Samples/SecureWebSocketServer/SecureWebSocketServer/SecureWebSocketServerAppDelegate.m @@ -1,11 +1,12 @@ -#import #import "SecureWebSocketServerAppDelegate.h" #import "HTTPServer.h" #import "MyHTTPConnection.h" +#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const DDLogLevel ddLogLevel = DDLogLevelVerbose; +static const int ddLogLevel = LOG_LEVEL_VERBOSE; + @implementation SecureWebSocketServerAppDelegate @@ -16,30 +17,30 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Create server using our custom MyHTTPServer class httpServer = [[HTTPServer alloc] init]; - + // Tell server to use our custom MyHTTPConnection class. [httpServer setConnectionClass:[MyHTTPConnection class]]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // Serve files from our embedded Web folder NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Web"]; DDLogInfo(@"Setting document root: %@", webPath); - + [httpServer setDocumentRoot:webPath]; - + // Start the server (and check for problems) - + NSError *error; if(![httpServer start:&error]) { diff --git a/Samples/SimpleFileUploadServer/SimpleFileUploadServer/AppDelegate.m b/Samples/SimpleFileUploadServer/SimpleFileUploadServer/AppDelegate.m index d73ed050..e7488186 100644 --- a/Samples/SimpleFileUploadServer/SimpleFileUploadServer/AppDelegate.m +++ b/Samples/SimpleFileUploadServer/SimpleFileUploadServer/AppDelegate.m @@ -1,10 +1,10 @@ -#import #import "AppDelegate.h" #import "HTTPServer.h" +#import "DDLog.h" #import "DDTTYLogger.h" #import "MyHTTPConnection.h" // Log levels: off, error, warn, info, verbose -static const DDLogLevel ddLogLevel = DDLogLevelVerbose; +static const int ddLogLevel = LOG_LEVEL_VERBOSE; @implementation AppDelegate @@ -14,27 +14,27 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Initalize our http server httpServer = [[HTTPServer alloc] init]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // Serve files from the standard Sites folder NSString *docRoot = [[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"web"] stringByDeletingLastPathComponent]; DDLogInfo(@"Setting document root: %@", docRoot); - + [httpServer setDocumentRoot:docRoot]; - + [httpServer setConnectionClass:[MyHTTPConnection class]]; - + NSError *error = nil; if(![httpServer start:&error]) { diff --git a/Samples/SimpleHTTPServer/AppDelegate.m b/Samples/SimpleHTTPServer/AppDelegate.m index 4b469c9a..06c2fa39 100644 --- a/Samples/SimpleHTTPServer/AppDelegate.m +++ b/Samples/SimpleHTTPServer/AppDelegate.m @@ -1,10 +1,10 @@ -#import #import "AppDelegate.h" #import "HTTPServer.h" +#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const DDLogLevel ddLogLevel = DDLogLevelVerbose; +static const int ddLogLevel = LOG_LEVEL_VERBOSE; @implementation AppDelegate @@ -14,25 +14,25 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Initalize our http server httpServer = [[HTTPServer alloc] init]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // Serve files from the standard Sites folder NSString *docRoot = [@"~/Sites" stringByExpandingTildeInPath]; DDLogInfo(@"Setting document root: %@", docRoot); - + [httpServer setDocumentRoot:docRoot]; - + NSError *error = nil; if(![httpServer start:&error]) { diff --git a/Samples/SimpleWebSocketServer/SimpleWebSocketServerAppDelegate.m b/Samples/SimpleWebSocketServer/SimpleWebSocketServerAppDelegate.m index 09f892ad..9a032138 100644 --- a/Samples/SimpleWebSocketServer/SimpleWebSocketServerAppDelegate.m +++ b/Samples/SimpleWebSocketServer/SimpleWebSocketServerAppDelegate.m @@ -1,11 +1,11 @@ -#import #import "SimpleWebSocketServerAppDelegate.h" #import "HTTPServer.h" #import "MyHTTPConnection.h" +#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const DDLogLevel ddLogLevel = DDLogLevelVerbose; +static const int ddLogLevel = LOG_LEVEL_VERBOSE; @implementation SimpleWebSocketServerAppDelegate @@ -17,30 +17,30 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Create server using our custom MyHTTPServer class httpServer = [[HTTPServer alloc] init]; - + // Tell server to use our custom MyHTTPConnection class. [httpServer setConnectionClass:[MyHTTPConnection class]]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // Serve files from our embedded Web folder NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Web"]; DDLogInfo(@"Setting document root: %@", webPath); - + [httpServer setDocumentRoot:webPath]; - + // Start the server (and check for problems) - + NSError *error; if(![httpServer start:&error]) { diff --git a/Samples/WebDAVServer/AppDelegate.m b/Samples/WebDAVServer/AppDelegate.m index 47005e47..99739b8c 100644 --- a/Samples/WebDAVServer/AppDelegate.m +++ b/Samples/WebDAVServer/AppDelegate.m @@ -1,28 +1,28 @@ -#import #import "AppDelegate.h" +#import "DDLog.h" #import "DDTTYLogger.h" #import "HTTPServer.h" #import "DAVConnection.h" -static const DDLogLevel ddLogLevel = DDLogLevelVerbose; +static const int ddLogLevel = LOG_LEVEL_VERBOSE; @implementation AppDelegate - (void) applicationDidFinishLaunching:(NSNotification*)notification { // Configure logging system [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Create DAV server _httpServer = [[HTTPServer alloc] init]; [_httpServer setConnectionClass:[DAVConnection class]]; [_httpServer setPort:8080]; - + // Enable Bonjour [_httpServer setType:@"_http._tcp."]; - + // Set document root [_httpServer setDocumentRoot:[@"~/Sites" stringByExpandingTildeInPath]]; - + // Start DAV server NSError* error = nil; if (![_httpServer start:&error]) { diff --git a/Samples/iPhoneHTTPServer/Classes/iPhoneHTTPServerAppDelegate.m b/Samples/iPhoneHTTPServer/Classes/iPhoneHTTPServerAppDelegate.m index cece41f2..221d1c05 100644 --- a/Samples/iPhoneHTTPServer/Classes/iPhoneHTTPServerAppDelegate.m +++ b/Samples/iPhoneHTTPServer/Classes/iPhoneHTTPServerAppDelegate.m @@ -1,11 +1,12 @@ -#import #import "iPhoneHTTPServerAppDelegate.h" #import "iPhoneHTTPServerViewController.h" #import "HTTPServer.h" +#import "DDLog.h" #import "DDTTYLogger.h" // Log levels: off, error, warn, info, verbose -static const DDLogLevel ddLogLevel = DDLogLevelVerbose; +static const int ddLogLevel = LOG_LEVEL_VERBOSE; + @implementation iPhoneHTTPServerAppDelegate @@ -15,7 +16,7 @@ @implementation iPhoneHTTPServerAppDelegate - (void)startServer { // Start the server (and check for problems) - + NSError *error; if([httpServer start:&error]) { @@ -32,31 +33,31 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // Configure our logging framework. // To keep things simple and fast, we're just going to log to the Xcode console. [DDLog addLogger:[DDTTYLogger sharedInstance]]; - + // Create server using our custom MyHTTPServer class httpServer = [[HTTPServer alloc] init]; - + // Tell the server to broadcast its presence via Bonjour. // This allows browsers such as Safari to automatically discover our service. [httpServer setType:@"_http._tcp."]; - + // Normally there's no need to run our server on any specific port. // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. // However, for easy testing you may want force a certain port so you can just hit the refresh button. // [httpServer setPort:12345]; - + // Serve files from our embedded Web folder NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Web"]; DDLogInfo(@"Setting document root: %@", webPath); - + [httpServer setDocumentRoot:webPath]; [self startServer]; - + // Add the view controller's view to the window and display. [window addSubview:viewController.view]; [window makeKeyAndVisible]; - + return YES; } @@ -70,7 +71,7 @@ - (void)applicationDidEnterBackground:(UIApplication *)application // There is no public(allowed in AppStore) method for iOS to run continiously in the background for our purposes (serving HTTP). // So, we stop the server when the app is paused (if a users exits from the app or locks a device) and // restart the server when the app is resumed (based on this document: http://developer.apple.com/library/ios/#technotes/tn2277/_index.html ) - + [httpServer stop]; }