From 81f3deda2a5b077adb145e75755891017f734266 Mon Sep 17 00:00:00 2001 From: kfxiaoxia Date: Sat, 22 May 2021 18:51:16 +0800 Subject: [PATCH] fix: apns server address --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 + SmartPush/Library/ioSock.c | 651 ++++++++++-------- SmartPush/Library/ioSock.h | 134 ++-- SmartPush/PushViewController.m | 14 +- 4 files changed, 424 insertions(+), 383 deletions(-) create mode 100644 SmartPush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/SmartPush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SmartPush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/SmartPush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/SmartPush/Library/ioSock.c b/SmartPush/Library/ioSock.c index 5ca781d..5e9ae78 100755 --- a/SmartPush/Library/ioSock.c +++ b/SmartPush/Library/ioSock.c @@ -1,50 +1,29 @@ /* - File: ioSock.h - - Contains: SecureTransport sample I/O module, X sockets version - - Copyright: Copyright 2002 Apple Computer, Inc. All rights reserved. - - Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. - ("Apple") in consideration of your agreement to the following terms, and your - use, installation, modification or redistribution of this Apple software - constitutes acceptance of these terms. If you do not agree with these terms, - please do not use, install, modify or redistribute this Apple software. - - In consideration of your agreement to abide by the following terms, and subject - to these terms, Apple grants you a personal, non-exclusive license, under Apples - copyrights in this original Apple software (the "Apple Software"), to use, - reproduce, modify and redistribute the Apple Software, with or without - modifications, in source and/or binary forms; provided that if you redistribute - the Apple Software in its entirety and without modifications, you must retain - this notice and the following text and disclaimers in all such redistributions of - the Apple Software. Neither the name, trademarks, service marks or logos of - Apple Computer, Inc. may be used to endorse or promote products derived from the - Apple Software without specific prior written permission from Apple. Except as - expressly stated in this notice, no other rights or licenses, express or implied, - are granted by Apple herein, including but not limited to any patent rights that - may be infringed by your derivative works or by other works in which the Apple - Software may be incorporated. - - The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO - WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED - WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN - COMBINATION WITH YOUR PRODUCTS. - - IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION - OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT - (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN - ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Change History (most recent first): - 11/4/02 1.0d1 - -*/ + * Copyright (c) 2006-2008,2010-2012 Apple Inc. All Rights Reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * ioSock.c - socket-based I/O routines for use with Secure Transport + */ #include "ioSock.h" #include @@ -58,88 +37,88 @@ #include #include -#include +#include #include #include /* debugging for this module */ -#define SSL_OT_DEBUG 1 +#define SSL_OT_DEBUG 1 /* log errors to stdout */ -#define SSL_OT_ERRLOG 1 +#define SSL_OT_ERRLOG 1 /* trace all low-level network I/O */ -#define SSL_OT_IO_TRACE 0 +#define SSL_OT_IO_TRACE 0 /* if SSL_OT_IO_TRACE, only log non-zero length transfers */ -#define SSL_OT_IO_TRACE_NZ 1 +#define SSL_OT_IO_TRACE_NZ 1 /* pause after each I/O (only meaningful if SSL_OT_IO_TRACE == 1) */ -#define SSL_OT_IO_PAUSE 0 +#define SSL_OT_IO_PAUSE 0 /* print a stream of dots while I/O pending */ -#define SSL_OT_DOT 1 +#define SSL_OT_DOT 1 /* dump some bytes of each I/O (only meaningful if SSL_OT_IO_TRACE == 1) */ -#define SSL_OT_IO_DUMP 0 -#define SSL_OT_IO_DUMP_SIZE 256 +#define SSL_OT_IO_DUMP 0 +#define SSL_OT_IO_DUMP_SIZE 256 + +/* indicate errSSLWouldBlock with a '.' */ +#define SSL_DISPL_WOULD_BLOCK 0 /* general, not-too-verbose debugging */ -#if SSL_OT_DEBUG -#define dprintf(s) printf s -#else +#if SSL_OT_DEBUG +#define dprintf(s) printf s +#else #define dprintf(s) #endif /* errors --> stdout */ -#if SSL_OT_ERRLOG -#define eprintf(s) printf s -#else +#if SSL_OT_ERRLOG +#define eprintf(s) printf s +#else #define eprintf(s) #endif -/* enable nonblocking I/O - maybe should be an arg to MakeServerConnection() */ -#define NON_BLOCKING 0 - /* trace completion of every r/w */ -#if SSL_OT_IO_TRACE +#if SSL_OT_IO_TRACE static void tprintf( - const char *str, - UInt32 req, - UInt32 act, - const UInt8 *buf) + const char *str, + UInt32 req, + UInt32 act, + const UInt8 *buf) { - #if SSL_OT_IO_TRACE_NZ - if(act == 0) { - return; - } - #endif - printf("%s(%d): moved (%d) bytes\n", str, req, act); - #if SSL_OT_IO_DUMP - { - int i; - - for(i=0; i= (SSL_OT_IO_DUMP_SIZE - 1)) { - break; - } - } - printf("\n"); - } - #endif - #if SSL_OT_IO_PAUSE - { - char instr[20]; - printf("CR to continue: "); - gets(instr); - } - #endif + #if SSL_OT_IO_TRACE_NZ + if(act == 0) { + return; + } + #endif + printf("%s(%u): moved (%u) bytes\n", str, (unsigned)req, (unsigned)act); + #if SSL_OT_IO_DUMP + { + unsigned i; + + for(i=0; i= (SSL_OT_IO_DUMP_SIZE - 1)) { + break; + } + } + printf("\n"); + } + #endif + #if SSL_OT_IO_PAUSE + { + char instr[20]; + printf("CR to continue: "); + gets(instr); + } + #endif } -#else +#else #define tprintf(str, req, act, buf) -#endif /* SSL_OT_IO_TRACE */ +#endif /* SSL_OT_IO_TRACE */ /* * If SSL_OT_DOT, output a '.' every so often while waiting for @@ -147,19 +126,19 @@ static void tprintf( * UI. */ -#if SSL_OT_DOT +#if SSL_OT_DOT static time_t lastTime = (time_t)0; -#define TIME_INTERVAL 3 +#define TIME_INTERVAL 3 static void outputDot() { - time_t thisTime = time(0); - - if((thisTime - lastTime) >= TIME_INTERVAL) { - printf("."); fflush(stdout); - lastTime = thisTime; - } + time_t thisTime = time(0); + + if((thisTime - lastTime) >= TIME_INTERVAL) { + printf("."); fflush(stdout); + lastTime = thisTime; + } } #else #define outputDot() @@ -169,35 +148,48 @@ static void outputDot() /* * One-time only init. */ -void initSslOt() +void initSslOt(void) { } /* - * Connect to server. + * Connect to server. */ +#define GETHOST_RETRIES 3 + OSStatus MakeServerConnection( - const char *hostName, - int port, - otSocket *socketNo, // RETURNED - PeerSpec *peer) // RETURNED + const char *hostName, + int port, + int nonBlocking, // 0 or 1 + otSocket *socketNo, // RETURNED + PeerSpec *peer) // RETURNED { struct sockaddr_in addr; - struct hostent *ent; + struct hostent *ent; struct in_addr host; - int sock = 0; - - *socketNo = NULL; + int sock = 0; + + *socketNo = 0; if (hostName[0] >= '0' && hostName[0] <= '9') { host.s_addr = inet_addr(hostName); } - else - { ent = gethostbyname(hostName); - if (!ent) - { printf("gethostbyname failed\n"); - return ioErr; + else { + unsigned dex; + /* seeing a lot of soft failures here that I really don't want to track down */ + for(dex=0; dexh_addr, sizeof(struct in_addr)); } @@ -208,66 +200,98 @@ OSStatus MakeServerConnection( addr.sin_family = AF_INET; if (connect(sock, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) != 0) { printf("connect returned error\n"); - return ioErr; + return errSecIO; } - #if NON_BLOCKING - /* OK to do this after connect? */ - { - int rtn = fcntl(sock, F_SETFL, O_NONBLOCK); - if(rtn == -1) { - perror("fctnl(O_NONBLOCK)"); - return ioErr; - } - } - #endif /* NON_BLOCKING*/ - + if(nonBlocking) { + /* OK to do this after connect? */ + int rtn = fcntl(sock, F_SETFL, O_NONBLOCK); + if(rtn == -1) { + perror("fctnl(O_NONBLOCK)"); + return errSecIO; + } + } + peer->ipAddr = addr.sin_addr.s_addr; peer->port = htons((u_short)port); - *socketNo = (otSocket)sock; - return noErr; + *socketNo = (otSocket)sock; + return errSecSuccess; } /* * Set up an otSocket to listen for client connections. Call once, then - * use multiple AcceptClientConnection calls. + * use multiple AcceptClientConnection calls. */ OSStatus ListenForClients( - int port, - otSocket *socketNo) // RETURNED -{ - struct sockaddr_in addr; + int port, + int nonBlocking, // 0 or 1 + otSocket *socketNo) // RETURNED +{ + struct sockaddr_in addr; struct hostent *ent; int len; - int sock; - + int sock; + sock = socket(AF_INET, SOCK_STREAM, 0); - if(sock < 1) { - perror("socket"); - return ioErr; - } - + if(sock < 1) { + perror("socket"); + return errSecIO; + } + + int reuse = 1; + int err = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)); + if (err != 0) { + perror("setsockopt"); + return err; + } + ent = gethostbyname("localhost"); if (!ent) { - perror("gethostbyname"); - return ioErr; + perror("gethostbyname"); + return errSecIO; } memcpy(&addr.sin_addr, ent->h_addr, sizeof(struct in_addr)); - + addr.sin_port = htons((u_short)port); addr.sin_addr.s_addr = INADDR_ANY; addr.sin_family = AF_INET; len = sizeof(struct sockaddr_in); if (bind(sock, (struct sockaddr *) &addr, len)) { - perror("bind"); - return ioErr; + int theErr = errno; + perror("bind"); + if(theErr == EADDRINUSE) { + return errSecOpWr; + } + else { + return errSecIO; + } } - if (listen(sock, 1)) { - perror("listen"); - return ioErr; + if(nonBlocking) { + int rtn = fcntl(sock, F_SETFL, O_NONBLOCK); + if(rtn == -1) { + perror("fctnl(O_NONBLOCK)"); + return errSecIO; + } + } + + for(;;) { + int rtn = listen(sock, 1); + switch(rtn) { + case 0: + *socketNo = (otSocket)sock; + rtn = errSecSuccess; + break; + case EWOULDBLOCK: + continue; + default: + perror("listen"); + rtn = errSecIO; + break; + } + return rtn; } - *socketNo = (otSocket)sock; - return noErr; + /* NOT REACHED */ + return 0; } /* @@ -276,178 +300,203 @@ OSStatus ListenForClients( /* * Currently we always get back a different peer port number on successive - * connections, no matter what the client is doing. To test for resumable + * connections, no matter what the client is doing. To test for resumable * session support, force peer port = 0. */ -#define FORCE_ACCEPT_PEER_PORT_ZERO 1 +#define FORCE_ACCEPT_PEER_PORT_ZERO 1 OSStatus AcceptClientConnection( - otSocket listenSock, // obtained from ListenForClients - otSocket *acceptSock, // RETURNED - PeerSpec *peer) // RETURNED -{ - struct sockaddr_in addr; - int sock; - socklen_t len; - + otSocket listenSock, // obtained from ListenForClients + otSocket *acceptSock, // RETURNED + PeerSpec *peer) // RETURNED +{ + struct sockaddr_in addr; + int sock; + socklen_t len; + len = sizeof(struct sockaddr_in); - sock = accept((int)listenSock, (struct sockaddr *) &addr, &len); - if (sock < 0) { - perror("accept"); - return ioErr; - } - *acceptSock = (otSocket)sock; + do { + sock = accept((int)listenSock, (struct sockaddr *) &addr, &len); + if (sock < 0) { + if(errno == EAGAIN) { + /* nonblocking, no connection yet */ + continue; + } + else { + perror("accept"); + return errSecIO; + } + } + else { + break; + } + } while(1); + *acceptSock = (otSocket)sock; peer->ipAddr = addr.sin_addr.s_addr; - #if FORCE_ACCEPT_PEER_PORT_ZERO - peer->port = 0; - #else + #if FORCE_ACCEPT_PEER_PORT_ZERO + peer->port = 0; + #else peer->port = ntohs(addr.sin_port); - #endif - return noErr; + #endif + return errSecSuccess; } /* * Shut down a connection. */ void endpointShutdown( - otSocket socket) + otSocket sock) { - close((int)socket); + close((int)sock); } - + /* * R/W. Called out from SSL. */ OSStatus SocketRead( - SSLConnectionRef connection, - void *data, /* owned by - * caller, data - * RETURNED */ - size_t *dataLength) /* IN/OUT */ + SSLConnectionRef connection, + void *data, /* owned by + * caller, data + * RETURNED */ + size_t *dataLength) /* IN/OUT */ { - UInt32 bytesToGo = *dataLength; - UInt32 initLen = bytesToGo; - UInt8 *currData = (UInt8 *)data; - int sock = (int)connection; - OSStatus rtn = noErr; - UInt32 bytesRead; - int rrtn; - - *dataLength = 0; - - for(;;) { - bytesRead = 0; - rrtn = read(sock, currData, bytesToGo); - if (rrtn <= 0) { - /* this is guesswork... */ - int theErr = errno; - dprintf(("SocketRead: read(%d) error %d\n", (int)bytesToGo, theErr)); - #if !NON_BLOCKING - if((rrtn == 0) && (theErr == 0)) { - /* try fix for iSync */ - rtn = errSSLClosedGraceful; - //rtn = errSSLClosedAbort; - } - else /* do the switch */ - #endif - switch(theErr) { - case ENOENT: - /* connection closed */ - rtn = errSSLClosedGraceful; - break; - case ECONNRESET: - rtn = errSSLClosedAbort; - break; - #if NON_BLOCKING - case EAGAIN: - #else - case 0: /* ??? */ - #endif - rtn = errSSLWouldBlock; - break; - default: - dprintf(("SocketRead: read(%d) error %d\n", - (int)bytesToGo, theErr)); - rtn = ioErr; - break; - } - break; - } - else { - bytesRead = rrtn; - } - bytesToGo -= bytesRead; - currData += bytesRead; - - if(bytesToGo == 0) { - /* filled buffer with incoming data, done */ - break; - } - } - *dataLength = initLen - bytesToGo; - tprintf("SocketRead", initLen, *dataLength, (UInt8 *)data); - - #if SSL_OT_DOT || (SSL_OT_DEBUG && !SSL_OT_IO_TRACE) - if((rtn == 0) && (*dataLength == 0)) { - /* keep UI alive */ - outputDot(); - } - #endif - return rtn; + UInt32 bytesToGo = *dataLength; + UInt32 initLen = bytesToGo; + UInt8 *currData = (UInt8 *)data; + int sock = (int)((long)connection); + OSStatus rtn = errSecSuccess; + UInt32 bytesRead; + ssize_t rrtn; + + *dataLength = 0; + + for(;;) { + bytesRead = 0; + /* paranoid check, ensure errno is getting written */ + errno = -555; + rrtn = recv(sock, currData, bytesToGo, 0); + if (rrtn <= 0) { + if(rrtn == 0) { + /* closed, EOF */ + rtn = errSSLClosedGraceful; + break; + } + int theErr = errno; + switch(theErr) { + case ENOENT: + /* + * Undocumented but I definitely see this. + * Non-blocking sockets only. Definitely retriable + * just like an EAGAIN. + */ + dprintf(("SocketRead RETRYING on ENOENT, rrtn %d\n", + (int)rrtn)); + /* normal... */ + //rtn = errSSLWouldBlock; + /* ...for temp testing.... */ + rtn = errSecIO; + break; + case ECONNRESET: + /* explicit peer abort */ + rtn = errSSLClosedAbort; + break; + case EAGAIN: + /* nonblocking, no data */ + rtn = errSSLWouldBlock; + break; + default: + dprintf(("SocketRead: read(%u) error %d, rrtn %d\n", + (unsigned)bytesToGo, theErr, (int)rrtn)); + rtn = errSecIO; + break; + } + /* in any case, we're done with this call if rrtn <= 0 */ + break; + } + bytesRead = rrtn; + bytesToGo -= bytesRead; + currData += bytesRead; + + if(bytesToGo == 0) { + /* filled buffer with incoming data, done */ + break; + } + } + *dataLength = initLen - bytesToGo; + tprintf("SocketRead", initLen, *dataLength, (UInt8 *)data); + + #if SSL_OT_DOT || (SSL_OT_DEBUG && !SSL_OT_IO_TRACE) + if((rtn == 0) && (*dataLength == 0)) { + /* keep UI alive */ + outputDot(); + } + #endif + #if SSL_DISPL_WOULD_BLOCK + if(rtn == errSSLWouldBlock) { + printf("."); fflush(stdout); + } + #endif + return rtn; } int oneAtATime = 0; OSStatus SocketWrite( - SSLConnectionRef connection, - const void *data, - size_t *dataLength) /* IN/OUT */ + SSLConnectionRef connection, + const void *data, + size_t *dataLength) /* IN/OUT */ { - UInt32 bytesSent = 0; - int sock = (int)connection; - int length; - UInt32 dataLen = *dataLength; - const UInt8 *dataPtr = (UInt8 *)data; - OSStatus ortn; - - if(oneAtATime && (*dataLength > 1)) { - UInt32 i; - UInt32 outLen; - size_t thisMove; - - outLen = 0; - for(i=0; i 1)) { + size_t i; + size_t outLen; + size_t thisMove; + + outLen = 0; + for(i=0; i 0) && - ( (bytesSent += length) < dataLen) ); - - if(length <= 0) { - if(errno == EAGAIN) { - ortn = errSSLWouldBlock; - } - else { - ortn = ioErr; - } - } - else { - ortn = noErr; - } - tprintf("SocketWrite", dataLen, bytesSent, dataPtr); - *dataLength = bytesSent; - return ortn; + length = write(sock, + (char*)dataPtr + bytesSent, + dataLen - bytesSent); + } while ((length > 0) && + ( (bytesSent += length) < dataLen) ); + + if(length <= 0) { + int theErr = errno; + switch(theErr) { + case EAGAIN: + ortn = errSSLWouldBlock; break; + case EPIPE: + ortn = errSSLClosedAbort; break; + default: + dprintf(("SocketWrite: write(%u) error %d\n", + (unsigned)(dataLen - bytesSent), theErr)); + ortn = errSecIO; + break; + } + } + else { + ortn = errSecSuccess; + } + tprintf("SocketWrite", dataLen, bytesSent, dataPtr); + *dataLength = bytesSent; + return ortn; } diff --git a/SmartPush/Library/ioSock.h b/SmartPush/Library/ioSock.h index e48e075..8b418f8 100755 --- a/SmartPush/Library/ioSock.h +++ b/SmartPush/Library/ioSock.h @@ -1,71 +1,47 @@ /* - File: ioSock.h - - Contains: socket-based I/O routines for SecureTransport tests - - Copyright: Copyright 2002 Apple Computer, Inc. All rights reserved. - - Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. - ("Apple") in consideration of your agreement to the following terms, and your - use, installation, modification or redistribution of this Apple software - constitutes acceptance of these terms. If you do not agree with these terms, - please do not use, install, modify or redistribute this Apple software. - - In consideration of your agreement to abide by the following terms, and subject - to these terms, Apple grants you a personal, non-exclusive license, under Apples - copyrights in this original Apple software (the "Apple Software"), to use, - reproduce, modify and redistribute the Apple Software, with or without - modifications, in source and/or binary forms; provided that if you redistribute - the Apple Software in its entirety and without modifications, you must retain - this notice and the following text and disclaimers in all such redistributions of - the Apple Software. Neither the name, trademarks, service marks or logos of - Apple Computer, Inc. may be used to endorse or promote products derived from the - Apple Software without specific prior written permission from Apple. Except as - expressly stated in this notice, no other rights or licenses, express or implied, - are granted by Apple herein, including but not limited to any patent rights that - may be infringed by your derivative works or by other works in which the Apple - Software may be incorporated. - - The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO - WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED - WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN - COMBINATION WITH YOUR PRODUCTS. - - IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION - OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT - (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN - ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Change History (most recent first): - 11/4/02 1.0d1 - -*/ + * Copyright (c) 2006-2008,2010-2012 Apple Inc. All Rights Reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * ioSock.h - socket-based I/O routines for use with Secure Transport + */ -#ifndef _IO_SOCK_H_ +#ifndef _IO_SOCK_H_ #define _IO_SOCK_H_ -//#include -#include - #include #include -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif /* * Opaque reference to an Open Transport connection. */ -typedef void *otSocket; +typedef int otSocket; /* - * info about a peer returned from MakeServerConnection() and + * info about a peer returned from MakeServerConnection() and * AcceptClientConnection(). */ typedef struct @@ -76,57 +52,59 @@ typedef struct /* * Ont-time only init. */ -void initSslOt(); +void initSslOt(void); /* - * Connect to server. + * Connect to server. */ extern OSStatus MakeServerConnection( - const char *hostName, - int port, - otSocket *socketNo, // RETURNED - PeerSpec *peer); // RETURNED + const char *hostName, + int port, + int nonBlocking, // 0 or 1 + otSocket *socketNo, // RETURNED + PeerSpec *peer); // RETURNED /* * Set up an otSocket to listen for client connections. Call once, then - * use multiple AcceptClientConnection calls. + * use multiple AcceptClientConnection calls. */ OSStatus ListenForClients( - int port, - otSocket *socketNo); // RETURNED + int port, + int nonBlocking, // 0 or 1 + otSocket *socketNo); // RETURNED /* * Accept a client connection. Call endpointShutdown() for each successful; - * return from this function. + * return from this function. */ OSStatus AcceptClientConnection( - otSocket listenSock, // obtained from ListenForClients - otSocket *acceptSock, // RETURNED - PeerSpec *peer); // RETURNED + otSocket listenSock, // obtained from ListenForClients + otSocket *acceptSock, // RETURNED + PeerSpec *peer); // RETURNED /* * Shut down a connection. */ void endpointShutdown( - otSocket socket); - + otSocket socket); + /* * R/W. Called out from SSL. */ OSStatus SocketRead( - SSLConnectionRef connection, - void *data, /* owned by - * caller, data - * RETURNED */ - size_t *dataLength); /* IN/OUT */ - + SSLConnectionRef connection, + void *data, /* owned by + * caller, data + * RETURNED */ + size_t *dataLength); /* IN/OUT */ + OSStatus SocketWrite( - SSLConnectionRef connection, - const void *data, - size_t *dataLength); /* IN/OUT */ + SSLConnectionRef connection, + const void *data, + size_t *dataLength); /* IN/OUT */ -#ifdef __cplusplus +#ifdef __cplusplus } #endif -#endif /* _IO_SOCK_H_ */ +#endif /* _IO_SOCK_H_ */ diff --git a/SmartPush/PushViewController.m b/SmartPush/PushViewController.m index b2d183a..2f1cb5f 100644 --- a/SmartPush/PushViewController.m +++ b/SmartPush/PushViewController.m @@ -6,8 +6,8 @@ // Copyright (c) 2015年 www.skyfox.org. All rights reserved. // -#define Push_Developer "gateway.sandbox.push.apple.com" -#define Push_Production "gateway.push.apple.com" +#define Push_Developer "api.sandbox.push.apple.com" +#define Push_Production "api.push.apple.com" #define KEY_CERNAME @"KEY_CERNAME" @@ -198,14 +198,20 @@ - (IBAction)connect:(id)sender { PeerSpec peer; //测试开发环境 + +// const char *hostName, +// int port, +// int nonBlocking, // 0 or 1 +// otSocket *socketNo, // RETURNED +// PeerSpec *peer); if (self.devSelect == self.mode.selectedCell) { - _connectResult = MakeServerConnection(Push_Developer, 2195, &socket, &peer); + _connectResult = MakeServerConnection(Push_Developer, 2197, 0, &socket, &peer); // NSLog(@"MakeServerConnection(): %d", result); } //生产正式环境 if (self.productSelect == self.mode.selectedCell) { - _connectResult = MakeServerConnection(Push_Production, 2195, &socket, &peer); + _connectResult = MakeServerConnection(Push_Production, 2197, 0, &socket, &peer); // NSLog(@"MakeServerConnection(): %d", result); } switch (_connectResult) {