Skip to content

Commit 09851dd

Browse files
committed
Modernize ObjC
1 parent 23f77b5 commit 09851dd

33 files changed

+850
-911
lines changed

GCDWebDAVServer/GCDWebDAVServer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#import "GCDWebServer.h"
2929

30+
NS_ASSUME_NONNULL_BEGIN
31+
3032
@class GCDWebDAVServer;
3133

3234
/**
@@ -86,7 +88,7 @@
8688
/**
8789
* Sets the delegate for the server.
8890
*/
89-
@property(nonatomic, assign) id<GCDWebDAVServerDelegate> delegate;
91+
@property(nonatomic, weak, nullable) id<GCDWebDAVServerDelegate> delegate;
9092

9193
/**
9294
* Sets which files are allowed to be operated on depending on their extension.
@@ -154,3 +156,5 @@
154156
- (BOOL)shouldCreateDirectoryAtPath:(NSString*)path;
155157

156158
@end
159+
160+
NS_ASSUME_NONNULL_END

GCDWebDAVServer/GCDWebDAVServer.m

Lines changed: 113 additions & 107 deletions
Large diffs are not rendered by default.

GCDWebServer.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,6 @@
12371237
"-Wno-cstring-format-directive",
12381238
"-Wno-reserved-id-macro",
12391239
"-Wno-cast-qual",
1240-
"-Wno-nullable-to-nonnull-conversion",
12411240
"-Wno-partial-availability",
12421241
);
12431242
};

GCDWebServer/Core/GCDWebServer.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#import "GCDWebServerRequest.h"
3131
#import "GCDWebServerResponse.h"
3232

33+
NS_ASSUME_NONNULL_BEGIN
34+
3335
/**
3436
* The GCDWebServerMatchBlock is called for every handler added to the
3537
* GCDWebServer whenever a new HTTP request has started (i.e. HTTP headers have
@@ -40,7 +42,7 @@
4042
* GCDWebServerRequest instance created with the same basic info.
4143
* Otherwise, it simply returns nil.
4244
*/
43-
typedef GCDWebServerRequest* (^GCDWebServerMatchBlock)(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery);
45+
typedef GCDWebServerRequest* _Nullable (^GCDWebServerMatchBlock)(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery);
4446

4547
/**
4648
* The GCDWebServerProcessBlock is called after the HTTP request has been fully
@@ -52,7 +54,7 @@ typedef GCDWebServerRequest* (^GCDWebServerMatchBlock)(NSString* requestMethod,
5254
* recommended to return a GCDWebServerErrorResponse on error so more useful
5355
* information can be returned to the client.
5456
*/
55-
typedef GCDWebServerResponse* (^GCDWebServerProcessBlock)(__kindof GCDWebServerRequest* request);
57+
typedef GCDWebServerResponse* _Nullable (^GCDWebServerProcessBlock)(__kindof GCDWebServerRequest* request);
5658

5759
/**
5860
* The GCDWebServerAsynchronousProcessBlock works like the GCDWebServerProcessBlock
@@ -64,7 +66,7 @@ typedef GCDWebServerResponse* (^GCDWebServerProcessBlock)(__kindof GCDWebServerR
6466
* It's however recommended to return a GCDWebServerErrorResponse on error so more
6567
* useful information can be returned to the client.
6668
*/
67-
typedef void (^GCDWebServerCompletionBlock)(GCDWebServerResponse* response);
69+
typedef void (^GCDWebServerCompletionBlock)(GCDWebServerResponse* _Nullable response);
6870
typedef void (^GCDWebServerAsyncProcessBlock)(__kindof GCDWebServerRequest* request, GCDWebServerCompletionBlock completionBlock);
6971

7072
/**
@@ -295,7 +297,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
295297
/**
296298
* Sets the delegate for the server.
297299
*/
298-
@property(nonatomic, assign) id<GCDWebServerDelegate> delegate;
300+
@property(nonatomic, weak, nullable) id<GCDWebServerDelegate> delegate;
299301

300302
/**
301303
* Returns YES if the server is currently running.
@@ -315,15 +317,15 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
315317
* @warning This property is only valid if the server is running and Bonjour
316318
* registration has successfully completed, which can take up to a few seconds.
317319
*/
318-
@property(nonatomic, readonly) NSString* bonjourName;
320+
@property(nonatomic, readonly, nullable) NSString* bonjourName;
319321

320322
/**
321323
* Returns the Bonjour service type used by the server.
322324
*
323325
* @warning This property is only valid if the server is running and Bonjour
324326
* registration has successfully completed, which can take up to a few seconds.
325327
*/
326-
@property(nonatomic, readonly) NSString* bonjourType;
328+
@property(nonatomic, readonly, nullable) NSString* bonjourType;
327329

328330
/**
329331
* This method is the designated initializer for the class.
@@ -363,7 +365,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
363365
*
364366
* Returns NO if the server failed to start and sets "error" argument if not NULL.
365367
*/
366-
- (BOOL)startWithOptions:(NSDictionary*)options error:(NSError**)error;
368+
- (BOOL)startWithOptions:(nullable NSDictionary*)options error:(NSError** _Nullable)error;
367369

368370
/**
369371
* Stops the server and prevents it to accepts new HTTP requests.
@@ -383,7 +385,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
383385
*
384386
* @warning This property is only valid if the server is running.
385387
*/
386-
@property(nonatomic, readonly) NSURL* serverURL;
388+
@property(nonatomic, readonly, nullable) NSURL* serverURL;
387389

388390
/**
389391
* Returns the server's Bonjour URL.
@@ -393,15 +395,15 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
393395
* Also be aware this property will not automatically update if the Bonjour hostname
394396
* has been dynamically changed after the server started running (this should be rare).
395397
*/
396-
@property(nonatomic, readonly) NSURL* bonjourServerURL;
398+
@property(nonatomic, readonly, nullable) NSURL* bonjourServerURL;
397399

398400
/**
399401
* Returns the server's public URL.
400402
*
401403
* @warning This property is only valid if the server is running and NAT port
402404
* mapping is active.
403405
*/
404-
@property(nonatomic, readonly) NSURL* publicServerURL;
406+
@property(nonatomic, readonly, nullable) NSURL* publicServerURL;
405407

406408
/**
407409
* Starts the server on port 8080 (OS X & iOS Simulator) or port 80 (iOS)
@@ -418,7 +420,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
418420
*
419421
* Returns NO if the server failed to start.
420422
*/
421-
- (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name;
423+
- (BOOL)startWithPort:(NSUInteger)port bonjourName:(nullable NSString*)name;
422424

423425
#if !TARGET_OS_IPHONE
424426

@@ -431,7 +433,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
431433
*
432434
* @warning This method must be used from the main thread only.
433435
*/
434-
- (BOOL)runWithPort:(NSUInteger)port bonjourName:(NSString*)name;
436+
- (BOOL)runWithPort:(NSUInteger)port bonjourName:(nullable NSString*)name;
435437

436438
/**
437439
* Runs the server synchronously using -startWithOptions: until a SIGTERM or
@@ -442,7 +444,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
442444
*
443445
* @warning This method must be used from the main thread only.
444446
*/
445-
- (BOOL)runWithOptions:(NSDictionary*)options error:(NSError**)error;
447+
- (BOOL)runWithOptions:(nullable NSDictionary*)options error:(NSError** _Nullable)error;
446448

447449
#endif
448450

@@ -498,7 +500,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
498500
* Adds a handler to the server to respond to incoming "GET" HTTP requests
499501
* with a specific case-insensitive path with in-memory data.
500502
*/
501-
- (void)addGETHandlerForPath:(NSString*)path staticData:(NSData*)staticData contentType:(NSString*)contentType cacheAge:(NSUInteger)cacheAge;
503+
- (void)addGETHandlerForPath:(NSString*)path staticData:(NSData*)staticData contentType:(nullable NSString*)contentType cacheAge:(NSUInteger)cacheAge;
502504

503505
/**
504506
* Adds a handler to the server to respond to incoming "GET" HTTP requests
@@ -515,7 +517,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
515517
* The "indexFilename" argument allows to specify an "index" file name to use
516518
* when the request path corresponds to a directory.
517519
*/
518-
- (void)addGETHandlerForBasePath:(NSString*)basePath directoryPath:(NSString*)directoryPath indexFilename:(NSString*)indexFilename cacheAge:(NSUInteger)cacheAge allowRangeRequests:(BOOL)allowRangeRequests;
520+
- (void)addGETHandlerForBasePath:(NSString*)basePath directoryPath:(NSString*)directoryPath indexFilename:(nullable NSString*)indexFilename cacheAge:(NSUInteger)cacheAge allowRangeRequests:(BOOL)allowRangeRequests;
519521

520522
@end
521523

@@ -612,8 +614,10 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
612614
*
613615
* Returns the number of failed tests or -1 if server failed to start.
614616
*/
615-
- (NSInteger)runTestsWithOptions:(NSDictionary*)options inDirectory:(NSString*)path;
617+
- (NSInteger)runTestsWithOptions:(nullable NSDictionary*)options inDirectory:(NSString*)path;
616618

617619
@end
618620

619621
#endif
622+
623+
NS_ASSUME_NONNULL_END

GCDWebServer/Core/GCDWebServer.m

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,9 @@ static void _ExecuteMainThreadRunLoopSources() {
132132

133133
#endif
134134

135-
@interface GCDWebServerHandler () {
136-
@private
137-
GCDWebServerMatchBlock _matchBlock;
138-
GCDWebServerAsyncProcessBlock _asyncProcessBlock;
139-
}
140-
@end
141-
142135
@implementation GCDWebServerHandler
143136

144-
@synthesize matchBlock = _matchBlock, asyncProcessBlock = _asyncProcessBlock;
145-
146-
- (id)initWithMatchBlock:(GCDWebServerMatchBlock)matchBlock asyncProcessBlock:(GCDWebServerAsyncProcessBlock)processBlock {
137+
- (instancetype)initWithMatchBlock:(GCDWebServerMatchBlock _Nonnull)matchBlock asyncProcessBlock:(GCDWebServerAsyncProcessBlock _Nonnull)processBlock {
147138
if ((self = [super init])) {
148139
_matchBlock = [matchBlock copy];
149140
_asyncProcessBlock = [processBlock copy];
@@ -153,9 +144,7 @@ - (id)initWithMatchBlock:(GCDWebServerMatchBlock)matchBlock asyncProcessBlock:(G
153144

154145
@end
155146

156-
@interface GCDWebServer () {
157-
@private
158-
id<GCDWebServerDelegate> __unsafe_unretained _delegate;
147+
@implementation GCDWebServer {
159148
dispatch_queue_t _syncQueue;
160149
dispatch_group_t _sourceGroup;
161150
NSMutableArray* _handlers;
@@ -164,15 +153,10 @@ @interface GCDWebServer () {
164153
CFRunLoopTimerRef _disconnectTimer; // Accessed on main thread only
165154

166155
NSDictionary* _options;
167-
NSString* _serverName;
168-
NSString* _authenticationRealm;
169156
NSMutableDictionary* _authenticationBasicAccounts;
170157
NSMutableDictionary* _authenticationDigestAccounts;
171158
Class _connectionClass;
172-
BOOL _mapHEADToGET;
173159
CFTimeInterval _disconnectDelay;
174-
dispatch_queue_priority_t _dispatchQueuePriority;
175-
NSUInteger _port;
176160
dispatch_source_t _source4;
177161
dispatch_source_t _source6;
178162
CFNetServiceRef _registrationService;
@@ -191,13 +175,6 @@ @interface GCDWebServer () {
191175
BOOL _recording;
192176
#endif
193177
}
194-
@end
195-
196-
@implementation GCDWebServer
197-
198-
@synthesize delegate = _delegate, handlers = _handlers, port = _port, serverName = _serverName, authenticationRealm = _authenticationRealm,
199-
authenticationBasicAccounts = _authenticationBasicAccounts, authenticationDigestAccounts = _authenticationDigestAccounts,
200-
shouldAutomaticallyMapHEADToGET = _mapHEADToGET, dispatchQueuePriority = _dispatchQueuePriority;
201178

202179
+ (void)initialize {
203180
GCDWebServerInitializeFunctions();
@@ -600,7 +577,7 @@ - (BOOL)_start:(NSError**)error {
600577
}];
601578
}
602579
_connectionClass = _GetOption(_options, GCDWebServerOption_ConnectionClass, [GCDWebServerConnection class]);
603-
_mapHEADToGET = [_GetOption(_options, GCDWebServerOption_AutomaticallyMapHEADToGET, @YES) boolValue];
580+
_shouldAutomaticallyMapHEADToGET = [_GetOption(_options, GCDWebServerOption_AutomaticallyMapHEADToGET, @YES) boolValue];
604581
_disconnectDelay = [_GetOption(_options, GCDWebServerOption_ConnectedStateCoalescingInterval, @1.0) doubleValue];
605582
_dispatchQueuePriority = [_GetOption(_options, GCDWebServerOption_DispatchQueuePriority, @(DISPATCH_QUEUE_PRIORITY_DEFAULT)) longValue];
606583

@@ -1294,9 +1271,9 @@ - (NSInteger)runTestsWithOptions:(NSDictionary*)options inDirectory:(NSString*)p
12941271
success = NO;
12951272
#if !TARGET_OS_IPHONE
12961273
#if DEBUG
1297-
if (GCDWebServerIsTextContentType([expectedHeaders objectForKey:@"Content-Type"])) {
1298-
NSString* expectedPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]];
1299-
NSString* actualPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]];
1274+
if (GCDWebServerIsTextContentType((NSString*)[expectedHeaders objectForKey:@"Content-Type"])) {
1275+
NSString* expectedPath = [NSTemporaryDirectory() stringByAppendingPathComponent:(NSString*)[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]];
1276+
NSString* actualPath = [NSTemporaryDirectory() stringByAppendingPathComponent:(NSString*)[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]];
13001277
if ([expectedBody writeToFile:expectedPath atomically:YES] && [actualBody writeToFile:actualPath atomically:YES]) {
13011278
NSTask* task = [[NSTask alloc] init];
13021279
[task setLaunchPath:@"/usr/bin/opendiff"];

GCDWebServer/Core/GCDWebServerConnection.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#import "GCDWebServer.h"
2929

30+
NS_ASSUME_NONNULL_BEGIN
31+
3032
@class GCDWebServerHandler;
3133

3234
/**
@@ -139,7 +141,7 @@
139141
* The default implementation checks for HTTP authentication if applicable
140142
* and returns a barebone 401 status code response if authentication failed.
141143
*/
142-
- (GCDWebServerResponse*)preflightRequest:(GCDWebServerRequest*)request;
144+
- (nullable GCDWebServerResponse*)preflightRequest:(GCDWebServerRequest*)request;
143145

144146
/**
145147
* Assuming a valid HTTP request was received and -preflightRequest: returned nil,
@@ -169,11 +171,13 @@
169171
* @warning If the request was invalid (e.g. the HTTP headers were malformed),
170172
* the "request" argument will be nil.
171173
*/
172-
- (void)abortRequest:(GCDWebServerRequest*)request withStatusCode:(NSInteger)statusCode;
174+
- (void)abortRequest:(nullable GCDWebServerRequest*)request withStatusCode:(NSInteger)statusCode;
173175

174176
/**
175177
* Called when the connection is closed.
176178
*/
177179
- (void)close;
178180

179181
@end
182+
183+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)