Skip to content

Commit 3e2feb1

Browse files
Merge pull request #52 from WilliamDenniss/loopback-warnings
Fixed compiler warnings in OIDLoopbackHTTPServer.
2 parents 68db005 + 597a889 commit 3e2feb1

File tree

4 files changed

+38
-29
lines changed

4 files changed

+38
-29
lines changed

AppAuth.podspec

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ tasks like performing an action with fresh tokens.
3131

3232
s.source = { :git => "https://github.com/openid/AppAuth-iOS.git", :tag => s.version }
3333

34+
s.pod_target_xcconfig = {
35+
# Treat warnings as errors.
36+
'GCC_TREAT_WARNINGS_AS_ERRORS' => 'YES',
37+
}
38+
3439
s.source_files = "Source/*.{h,m}"
3540
s.requires_arc = true
3641

Example-Mac/Source/AppAuthExampleViewController.m

+8-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ - (void)viewDidLoad {
8383

8484
NSAssert(![kClientID isEqualToString:@"YOUR_CLIENT.apps.googleusercontent.com"],
8585
@"Update kClientID with your own client ID. "
86-
"Instructions: https://github.com/openid/AppAuth-iOS/blob/master/Example-Mac/README.md");
86+
"Instructions: "
87+
"https://github.com/openid/AppAuth-iOS/blob/master/Example-Mac/README.md");
8788

8889
#endif // !defined(NS_BLOCK_ASSERTIONS)
8990

@@ -173,11 +174,13 @@ - (IBAction)authWithAutoCodeExchange:(nullable id)sender {
173174

174175
NSAssert(![kClientID isEqualToString:@"YOUR_CLIENT.apps.googleusercontent.com"],
175176
@"Update kClientID with your own client ID. "
176-
"Instructions: https://github.com/openid/AppAuth-iOS/blob/master/Example-Mac/README.md");
177+
"Instructions: "
178+
"https://github.com/openid/AppAuth-iOS/blob/master/Example-Mac/README.md");
177179

178180
NSAssert(![kRedirectURI isEqualToString:@"com.googleusercontent.apps.YOUR_CLIENT:/oauthredirect"],
179181
@"Update kRedirectURI with your own redirect URI. "
180-
"Instructions: https://github.com/openid/AppAuth-iOS/blob/master/Example-Mac/README.md");
182+
"Instructions: "
183+
"https://github.com/openid/AppAuth-iOS/blob/master/Example-Mac/README.md");
181184

182185
// verifies that the custom URI scheme has been updated in the Info.plist
183186
NSArray __unused* urlTypes =
@@ -252,7 +255,8 @@ - (IBAction)authWithAutoCodeExchangeHTTP:(nullable id)sender {
252255

253256
NSAssert(![kClientSecret isEqualToString:@"YOUR_CLIENT_SECRET"],
254257
@"Update kClientSecret with your own client ID secret. "
255-
"Instructions: https://github.com/openid/AppAuth-iOS/blob/master/Example-Mac/README.md");
258+
"Instructions: "
259+
"https://github.com/openid/AppAuth-iOS/blob/master/Example-Mac/README.md");
256260

257261
#endif // !defined(NS_BLOCK_ASSERTIONS)
258262

Source/macOS/LoopbackHTTPServer/OIDLoopbackHTTPServer.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#import <Foundation/Foundation.h>
2424
#import <CoreServices/CoreServices.h>
2525

26-
@class HTTPConnection, HTTPServerRequest;
26+
@class HTTPConnection, HTTPServerRequest, TCPServer;
2727

2828
extern NSString * const TCPServerErrorDomain;
2929

@@ -33,9 +33,18 @@ typedef enum {
3333
kTCPServerNoSocketsAvailable = 3,
3434
} TCPServerErrorCode;
3535

36+
@protocol TCPServerDelegate <NSObject>
37+
38+
- (void)TCPServer:(TCPServer *)server
39+
didReceiveConnectionFromAddress:(NSData *)addr
40+
inputStream:(NSInputStream *)istr
41+
outputStream:(NSOutputStream *)ostr;
42+
43+
@end
44+
3645
@interface TCPServer : NSObject {
3746
@private
38-
__weak id delegate;
47+
__weak id<TCPServerDelegate> delegate;
3948
NSString *domain;
4049
NSString *name;
4150
NSString *type;
@@ -70,15 +79,6 @@ typedef enum {
7079

7180
@end
7281

73-
@interface TCPServer (TCPServerDelegateMethods)
74-
// if the delegate implements this method, it is called when a new
75-
// connection comes in; a subclass may, of course, change that behavior
76-
- (void)TCPServer:(TCPServer *)server
77-
didReceiveConnectionFromAddress:(NSData *)addr
78-
inputStream:(NSInputStream *)istr
79-
outputStream:(NSOutputStream *)ostr;
80-
@end
81-
8282
@interface HTTPServer : TCPServer {
8383
@private
8484
Class connClass;
@@ -107,7 +107,7 @@ typedef enum {
107107

108108

109109
// This class represents each incoming client connection.
110-
@interface HTTPConnection : NSObject {
110+
@interface HTTPConnection : NSObject <NSStreamDelegate> {
111111
@private
112112
__weak id delegate;
113113
NSData *peerAddress;

Source/macOS/LoopbackHTTPServer/OIDLoopbackHTTPServer.m

+13-13
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ - (HTTPServer *)server {
109109
}
110110

111111
- (HTTPServerRequest *)nextRequest {
112-
unsigned idx, cnt = requests ? [requests count] : 0;
112+
NSUInteger idx, cnt = requests ? [requests count] : 0;
113113
for (idx = 0; idx < cnt; idx++) {
114114
id obj = [requests objectAtIndex:idx];
115115
if ([obj response] == nil) {
@@ -157,7 +157,7 @@ - (BOOL)processIncomingBytes {
157157

158158
unsigned contentLength = contentLengthValue ? [contentLengthValue intValue] : 0;
159159
NSData *body = (__bridge_transfer NSData *)CFHTTPMessageCopyBody(working);
160-
unsigned bodyLength = [body length];
160+
NSUInteger bodyLength = [body length];
161161
if (contentLength <= bodyLength) {
162162
NSData *newBody = [NSData dataWithBytes:[body bytes] length:contentLength];
163163
[ibuffer setLength:0];
@@ -199,9 +199,9 @@ - (void)processOutgoingBytes {
199199
return;
200200
}
201201

202-
unsigned olen = [obuffer length];
202+
NSUInteger olen = [obuffer length];
203203
if (0 < olen) {
204-
int writ = [ostream write:[obuffer bytes] maxLength:olen];
204+
NSInteger writ = [ostream write:[obuffer bytes] maxLength:olen];
205205
// buffer any unwritten bytes for later writing
206206
if (writ < olen) {
207207
memmove([obuffer mutableBytes], [obuffer mutableBytes] + writ, olen - writ);
@@ -211,7 +211,7 @@ - (void)processOutgoingBytes {
211211
[obuffer setLength:0];
212212
}
213213

214-
unsigned cnt = requests ? [requests count] : 0;
214+
NSUInteger cnt = requests ? [requests count] : 0;
215215
HTTPServerRequest *req = (0 < cnt) ? [requests objectAtIndex:0] : nil;
216216

217217
CFHTTPMessageRef cfresp = req ? [req response] : NULL;
@@ -224,9 +224,9 @@ - (void)processOutgoingBytes {
224224
if (!firstResponseDone) {
225225
firstResponseDone = YES;
226226
NSData *serialized = (__bridge_transfer NSData *)CFHTTPMessageCopySerializedMessage(cfresp);
227-
unsigned olen = [serialized length];
227+
NSUInteger olen = [serialized length];
228228
if (0 < olen) {
229-
int writ = [ostream write:[serialized bytes] maxLength:olen];
229+
NSInteger writ = [ostream write:[serialized bytes] maxLength:olen];
230230
if (writ < olen) {
231231
// buffer any unwritten bytes for later writing
232232
[obuffer setLength:(olen - writ)];
@@ -243,7 +243,7 @@ - (void)processOutgoingBytes {
243243
}
244244
// read some bytes from the stream into our local buffer
245245
[obuffer setLength:16 * 1024];
246-
int read = [respStream read:[obuffer mutableBytes] maxLength:[obuffer length]];
246+
NSInteger read = [respStream read:[obuffer mutableBytes] maxLength:[obuffer length]];
247247
[obuffer setLength:read];
248248
}
249249

@@ -264,7 +264,7 @@ - (void)processOutgoingBytes {
264264

265265
olen = [obuffer length];
266266
if (0 < olen) {
267-
int writ = [ostream write:[obuffer bytes] maxLength:olen];
267+
NSInteger writ = [ostream write:[obuffer bytes] maxLength:olen];
268268
// buffer any unwritten bytes for later writing
269269
if (writ < olen) {
270270
memmove([obuffer mutableBytes], [obuffer mutableBytes] + writ, olen - writ);
@@ -278,9 +278,9 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)streamEvent {
278278
case NSStreamEventHasBytesAvailable:;
279279
uint8_t buf[16 * 1024];
280280
uint8_t *buffer = NULL;
281-
unsigned int len = 0;
281+
NSUInteger len = 0;
282282
if (![istream getBuffer:&buffer length:&len]) {
283-
int amount = [istream read:buf maxLength:sizeof(buf)];
283+
NSInteger amount = [istream read:buf maxLength:sizeof(buf)];
284284
buffer = buf;
285285
len = amount;
286286
}
@@ -344,7 +344,7 @@ - (void)performDefaultRequestHandling:(HTTPServerRequest *)mess {
344344
}
345345

346346
CFHTTPMessageRef response = CFHTTPMessageCreateResponse(kCFAllocatorDefault, 200, NULL, kCFHTTPVersion1_1); // OK
347-
CFHTTPMessageSetHeaderFieldValue(response, (CFStringRef)@"Content-Length", (__bridge CFStringRef)[NSString stringWithFormat:@"%d", [data length]]);
347+
CFHTTPMessageSetHeaderFieldValue(response, (CFStringRef)@"Content-Length", (__bridge CFStringRef)[NSString stringWithFormat:@"%lu", (unsigned long) [data length]]);
348348
if ([method isEqual:@"GET"]) {
349349
CFHTTPMessageSetBody(response, (__bridge CFDataRef)data);
350350
}
@@ -473,7 +473,7 @@ - (void)setPort:(uint16_t)value {
473473

474474
- (void)handleNewConnectionFromAddress:(NSData *)addr inputStream:(NSInputStream *)istr outputStream:(NSOutputStream *)ostr {
475475
// if the delegate implements the delegate method, call it
476-
if (delegate && [delegate respondsToSelector:@selector(TCPServer:didReceiveConnectionFrom:inputStream:outputStream:)]) {
476+
if (delegate && [(NSObject*)delegate respondsToSelector:@selector(TCPServer:didReceiveConnectionFromAddress:inputStream:outputStream:)]) {
477477
[delegate TCPServer:self didReceiveConnectionFromAddress:addr inputStream:istr outputStream:ostr];
478478
}
479479
}

0 commit comments

Comments
 (0)