diff --git a/Pusher/NWAppDelegate.m b/Pusher/NWAppDelegate.m index 81e22c7..2798953 100644 --- a/Pusher/NWAppDelegate.m +++ b/Pusher/NWAppDelegate.m @@ -46,12 +46,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification - (void)applicationWillTerminate:(NSNotification *)notification { NWLog(@"Application will terminate"); - [pusher disconnect]; pusher = nil; + [pusher disconnect]; pusher = nil; } - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)application { - return YES; + return YES; } diff --git a/Pusher/NWPushFeedback.m b/Pusher/NWPushFeedback.m index 3806717..f59dfc6 100644 --- a/Pusher/NWPushFeedback.m +++ b/Pusher/NWPushFeedback.m @@ -50,7 +50,7 @@ - (BOOL)connectWithIdentity:(SecIdentityRef)identity sandbox:(BOOL)sandbox - (void)disconnect { - [connection disconnect]; connection = nil; + [connection disconnect]; connection = nil; } diff --git a/Pusher/NWPusher.m b/Pusher/NWPusher.m index 9a0fe1e..962d6ef 100644 --- a/Pusher/NWPusher.m +++ b/Pusher/NWPusher.m @@ -51,7 +51,7 @@ - (BOOL)connectWithIdentityRef:(SecIdentityRef)identity sandbox:(BOOL)sandbox - (void)disconnect { - [connection disconnect]; connection = nil; + [connection disconnect]; connection = nil; } @@ -117,13 +117,13 @@ - (BOOL)pushPayloadData:(NSData *)payload tokenData:(NSData *)token enhance:(BOO NWLogWarn(@"Payload cannot be more than %i bytes (UTF8)", (int)NWPayloadMaxSize); return NO; } - - char buffer[sizeof(uint8_t) + sizeof(uint32_t) * 2 + sizeof(uint16_t) + NWDeviceTokenSize + sizeof(uint16_t) + NWPayloadMaxSize]; - char *p = buffer; - uint8_t command = enhance ? 1 : 0; - memcpy(p, &command, sizeof(uint8_t)); - p += sizeof(uint8_t); + char buffer[sizeof(uint8_t) + sizeof(uint32_t) * 2 + sizeof(uint16_t) + NWDeviceTokenSize + sizeof(uint16_t) + NWPayloadMaxSize]; + char *p = buffer; + + uint8_t command = enhance ? 1 : 0; + memcpy(p, &command, sizeof(uint8_t)); + p += sizeof(uint8_t); if (enhance) { uint32_t ID = htonl(identifier); @@ -135,20 +135,20 @@ - (BOOL)pushPayloadData:(NSData *)payload tokenData:(NSData *)token enhance:(BOO p += sizeof(uint32_t); } - uint16_t tokenLength = htons(token.length); - memcpy(p, &tokenLength, sizeof(uint16_t)); - p += sizeof(uint16_t); + uint16_t tokenLength = htons(token.length); + memcpy(p, &tokenLength, sizeof(uint16_t)); + p += sizeof(uint16_t); + + memcpy(p, token.bytes, token.length); + p += token.length; - memcpy(p, token.bytes, token.length); - p += token.length; + uint16_t payloadLength = htons(payload.length); + memcpy(p, &payloadLength, sizeof(uint16_t)); + p += sizeof(uint16_t); - uint16_t payloadLength = htons(payload.length); - memcpy(p, &payloadLength, sizeof(uint16_t)); - p += sizeof(uint16_t); + memcpy(p, payload.bytes, payload.length); + p += payload.length; - memcpy(p, payload.bytes, payload.length); - p += payload.length; - NSData *data = [NSData dataWithBytes:buffer length:p - buffer]; BOOL result = [connection write:data length:NULL]; diff --git a/Pusher/NWSSLConnection.m b/Pusher/NWSSLConnection.m index 6ed54c5..1b384fc 100644 --- a/Pusher/NWSSLConnection.m +++ b/Pusher/NWSSLConnection.m @@ -12,7 +12,7 @@ @implementation NWSSLConnection { otSocket connection; - SSLContextRef context; + SSLContextRef context; } @synthesize host, port, identity; @@ -37,48 +37,48 @@ - (void)dealloc - (BOOL)connect { - PeerSpec spec; - OSStatus status = MakeServerConnection(host.UTF8String, (int)port, &connection, &spec); + PeerSpec spec; + OSStatus status = MakeServerConnection(host.UTF8String, (int)port, &connection, &spec); if (status != noErr) { NWLogWarn(@"Unable to create connection to server (%i)", status); return NO; } - status = SSLNewContext(false, &context); + status = SSLNewContext(false, &context); if (status != noErr) { NWLogWarn(@"Unable create SSL context (%i)", status); return NO; } - - status = SSLSetIOFuncs(context, SocketRead, SocketWrite); + + status = SSLSetIOFuncs(context, SocketRead, SocketWrite); if (status != noErr) { NWLogWarn(@"Unable to set socket callbacks (%i)", status); return NO; } - - status = SSLSetConnection(context, connection); + + status = SSLSetConnection(context, connection); if (status != noErr) { NWLogWarn(@"Unable to set SSL connection (%i)", status); return NO; } - - status = SSLSetPeerDomainName(context, host.UTF8String, strlen(host.UTF8String)); + + status = SSLSetPeerDomainName(context, host.UTF8String, strlen(host.UTF8String)); if (status != noErr) { NWLogWarn(@"Unable to set peer domain (%i)", status); return NO; } - CFArrayRef certificates = CFArrayCreate(NULL, (const void **)&identity, 1, NULL); - status = SSLSetCertificate(context, certificates); + CFArrayRef certificates = CFArrayCreate(NULL, (const void **)&identity, 1, NULL); + status = SSLSetCertificate(context, certificates); CFRelease(certificates); if (status != noErr) { NWLogWarn(@"Unable to assign certificate (%i)", status); return NO; } - - do { - status = SSLHandshake(context); - } while(status == errSSLWouldBlock); + + do { + status = SSLHandshake(context); + } while(status == errSSLWouldBlock); if (status != noErr) { switch (status) { case ioErr: NWLogWarn(@"Unable to perform SSL handshake, no connection"); break; @@ -120,7 +120,7 @@ - (BOOL)write:(NSData *)data length:(NSUInteger *)length { size_t processed = 0; const void *bytes = data.bytes; - OSStatus status = errSSLWouldBlock; + OSStatus status = errSSLWouldBlock; for (NSUInteger i = 0; i < 4 && status == errSSLWouldBlock; i++) { status = SSLWrite(context, bytes, data.length, &processed); } @@ -140,9 +140,9 @@ - (BOOL)write:(NSData *)data length:(NSUInteger *)length - (void)disconnect { - SSLClose(context); - close((int)connection); connection = NULL; - SSLDisposeContext(context); context = NULL; + SSLClose(context); + close((int)connection); connection = NULL; + SSLDisposeContext(context); context = NULL; } @end diff --git a/Pusher/NWSecTools.m b/Pusher/NWSecTools.m index 28a81d2..507caee 100644 --- a/Pusher/NWSecTools.m +++ b/Pusher/NWSecTools.m @@ -34,7 +34,7 @@ + (BOOL)identityWithCertificateData:(NSData *)certificate identity:(SecIdentityR + (BOOL)identityWithCertificateRef:(SecCertificateRef)certificate identity:(SecIdentityRef *)identity { - OSStatus status = SecIdentityCreateWithCertificate(NULL, certificate, identity); + OSStatus status = SecIdentityCreateWithCertificate(NULL, certificate, identity); if (status != noErr) { switch (status) { case errSecItemNotFound: NWLogWarn(@"Unable to create identitiy, private key missing"); break;