Skip to content

Commit

Permalink
Merge pull request #52 from WilliamDenniss/loopback-warnings
Browse files Browse the repository at this point in the history
Fixed compiler warnings in OIDLoopbackHTTPServer.
  • Loading branch information
WilliamDenniss authored Nov 2, 2016
2 parents 68db005 + 597a889 commit 3e2feb1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
5 changes: 5 additions & 0 deletions AppAuth.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ tasks like performing an action with fresh tokens.

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

s.pod_target_xcconfig = {
# Treat warnings as errors.
'GCC_TREAT_WARNINGS_AS_ERRORS' => 'YES',
}

s.source_files = "Source/*.{h,m}"
s.requires_arc = true

Expand Down
12 changes: 8 additions & 4 deletions Example-Mac/Source/AppAuthExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ - (void)viewDidLoad {

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

#endif // !defined(NS_BLOCK_ASSERTIONS)

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

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

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

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

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

#endif // !defined(NS_BLOCK_ASSERTIONS)

Expand Down
24 changes: 12 additions & 12 deletions Source/macOS/LoopbackHTTPServer/OIDLoopbackHTTPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#import <Foundation/Foundation.h>
#import <CoreServices/CoreServices.h>

@class HTTPConnection, HTTPServerRequest;
@class HTTPConnection, HTTPServerRequest, TCPServer;

extern NSString * const TCPServerErrorDomain;

Expand All @@ -33,9 +33,18 @@ typedef enum {
kTCPServerNoSocketsAvailable = 3,
} TCPServerErrorCode;

@protocol TCPServerDelegate <NSObject>

- (void)TCPServer:(TCPServer *)server
didReceiveConnectionFromAddress:(NSData *)addr
inputStream:(NSInputStream *)istr
outputStream:(NSOutputStream *)ostr;

@end

@interface TCPServer : NSObject {
@private
__weak id delegate;
__weak id<TCPServerDelegate> delegate;
NSString *domain;
NSString *name;
NSString *type;
Expand Down Expand Up @@ -70,15 +79,6 @@ typedef enum {

@end

@interface TCPServer (TCPServerDelegateMethods)
// if the delegate implements this method, it is called when a new
// connection comes in; a subclass may, of course, change that behavior
- (void)TCPServer:(TCPServer *)server
didReceiveConnectionFromAddress:(NSData *)addr
inputStream:(NSInputStream *)istr
outputStream:(NSOutputStream *)ostr;
@end

@interface HTTPServer : TCPServer {
@private
Class connClass;
Expand Down Expand Up @@ -107,7 +107,7 @@ typedef enum {


// This class represents each incoming client connection.
@interface HTTPConnection : NSObject {
@interface HTTPConnection : NSObject <NSStreamDelegate> {
@private
__weak id delegate;
NSData *peerAddress;
Expand Down
26 changes: 13 additions & 13 deletions Source/macOS/LoopbackHTTPServer/OIDLoopbackHTTPServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ - (HTTPServer *)server {
}

- (HTTPServerRequest *)nextRequest {
unsigned idx, cnt = requests ? [requests count] : 0;
NSUInteger idx, cnt = requests ? [requests count] : 0;
for (idx = 0; idx < cnt; idx++) {
id obj = [requests objectAtIndex:idx];
if ([obj response] == nil) {
Expand Down Expand Up @@ -157,7 +157,7 @@ - (BOOL)processIncomingBytes {

unsigned contentLength = contentLengthValue ? [contentLengthValue intValue] : 0;
NSData *body = (__bridge_transfer NSData *)CFHTTPMessageCopyBody(working);
unsigned bodyLength = [body length];
NSUInteger bodyLength = [body length];
if (contentLength <= bodyLength) {
NSData *newBody = [NSData dataWithBytes:[body bytes] length:contentLength];
[ibuffer setLength:0];
Expand Down Expand Up @@ -199,9 +199,9 @@ - (void)processOutgoingBytes {
return;
}

unsigned olen = [obuffer length];
NSUInteger olen = [obuffer length];
if (0 < olen) {
int writ = [ostream write:[obuffer bytes] maxLength:olen];
NSInteger writ = [ostream write:[obuffer bytes] maxLength:olen];
// buffer any unwritten bytes for later writing
if (writ < olen) {
memmove([obuffer mutableBytes], [obuffer mutableBytes] + writ, olen - writ);
Expand All @@ -211,7 +211,7 @@ - (void)processOutgoingBytes {
[obuffer setLength:0];
}

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

CFHTTPMessageRef cfresp = req ? [req response] : NULL;
Expand All @@ -224,9 +224,9 @@ - (void)processOutgoingBytes {
if (!firstResponseDone) {
firstResponseDone = YES;
NSData *serialized = (__bridge_transfer NSData *)CFHTTPMessageCopySerializedMessage(cfresp);
unsigned olen = [serialized length];
NSUInteger olen = [serialized length];
if (0 < olen) {
int writ = [ostream write:[serialized bytes] maxLength:olen];
NSInteger writ = [ostream write:[serialized bytes] maxLength:olen];
if (writ < olen) {
// buffer any unwritten bytes for later writing
[obuffer setLength:(olen - writ)];
Expand All @@ -243,7 +243,7 @@ - (void)processOutgoingBytes {
}
// read some bytes from the stream into our local buffer
[obuffer setLength:16 * 1024];
int read = [respStream read:[obuffer mutableBytes] maxLength:[obuffer length]];
NSInteger read = [respStream read:[obuffer mutableBytes] maxLength:[obuffer length]];
[obuffer setLength:read];
}

Expand All @@ -264,7 +264,7 @@ - (void)processOutgoingBytes {

olen = [obuffer length];
if (0 < olen) {
int writ = [ostream write:[obuffer bytes] maxLength:olen];
NSInteger writ = [ostream write:[obuffer bytes] maxLength:olen];
// buffer any unwritten bytes for later writing
if (writ < olen) {
memmove([obuffer mutableBytes], [obuffer mutableBytes] + writ, olen - writ);
Expand All @@ -278,9 +278,9 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)streamEvent {
case NSStreamEventHasBytesAvailable:;
uint8_t buf[16 * 1024];
uint8_t *buffer = NULL;
unsigned int len = 0;
NSUInteger len = 0;
if (![istream getBuffer:&buffer length:&len]) {
int amount = [istream read:buf maxLength:sizeof(buf)];
NSInteger amount = [istream read:buf maxLength:sizeof(buf)];
buffer = buf;
len = amount;
}
Expand Down Expand Up @@ -344,7 +344,7 @@ - (void)performDefaultRequestHandling:(HTTPServerRequest *)mess {
}

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

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

0 comments on commit 3e2feb1

Please sign in to comment.