Skip to content

Commit

Permalink
Updating WebServerIPhone project
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiehanson committed Jun 17, 2012
1 parent b21761e commit 49a2003
Show file tree
Hide file tree
Showing 10 changed files with 1,339 additions and 632 deletions.
97 changes: 90 additions & 7 deletions Xcode/WebServerIPhone/Vendor/CocoaAsyncSocket/GCDAsyncSocket.h
Expand Up @@ -3,25 +3,77 @@
//
// This class is in the public domain.
// Originally created by Robbie Hanson in Q3 2010.
// Updated and maintained by Deusty LLC and the Mac development community.
// Updated and maintained by Deusty LLC and the Apple development community.
//
// http://code.google.com/p/cocoaasyncsocket/
// https://github.com/robbiehanson/CocoaAsyncSocket
//

#import <Foundation/Foundation.h>
#import <Security/Security.h>
#import <Security/SecureTransport.h>
#import <dispatch/dispatch.h>

@class GCDAsyncReadPacket;
@class GCDAsyncWritePacket;
@class GCDAsyncSocketPreBuffer;

#if TARGET_OS_IPHONE

// Compiling for iOS

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000 // iOS 5.0 supported

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 50000 // iOS 5.0 supported and required

#define IS_SECURE_TRANSPORT_AVAILABLE YES
#define SECURE_TRANSPORT_MAYBE_AVAILABLE 1
#define SECURE_TRANSPORT_MAYBE_UNAVAILABLE 0

#else // iOS 5.0 supported but not required

#ifndef NSFoundationVersionNumber_iPhoneOS_5_0
#define NSFoundationVersionNumber_iPhoneOS_5_0 881.00
#endif

#define IS_SECURE_TRANSPORT_AVAILABLE (NSFoundationVersionNumber >= NSFoundationVersionNumber_iPhoneOS_5_0)
#define SECURE_TRANSPORT_MAYBE_AVAILABLE 1
#define SECURE_TRANSPORT_MAYBE_UNAVAILABLE 1

#endif

#else // iOS 5.0 not supported

#define IS_SECURE_TRANSPORT_AVAILABLE NO
#define SECURE_TRANSPORT_MAYBE_AVAILABLE 0
#define SECURE_TRANSPORT_MAYBE_UNAVAILABLE 1

#endif

#else

// Compiling for Mac OS X

#define IS_SECURE_TRANSPORT_AVAILABLE YES
#define SECURE_TRANSPORT_MAYBE_AVAILABLE 1
#define SECURE_TRANSPORT_MAYBE_UNAVAILABLE 0

#endif

extern NSString *const GCDAsyncSocketException;
extern NSString *const GCDAsyncSocketErrorDomain;

#if !TARGET_OS_IPHONE
extern NSString *const GCDAsyncSocketQueueName;
extern NSString *const GCDAsyncSocketThreadName;

#if SECURE_TRANSPORT_MAYBE_AVAILABLE
extern NSString *const GCDAsyncSocketSSLCipherSuites;
#if TARGET_OS_IPHONE
extern NSString *const GCDAsyncSocketSSLProtocolVersionMin;
extern NSString *const GCDAsyncSocketSSLProtocolVersionMax;
#else
extern NSString *const GCDAsyncSocketSSLDiffieHellmanParameters;
#endif
#endif

enum GCDAsyncSocketError
{
Expand All @@ -46,7 +98,11 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
uint32_t flags;
uint16_t config;

#if __has_feature(objc_arc_weak)
__weak id delegate;
#else
__unsafe_unretained id delegate;
#endif
dispatch_queue_t delegateQueue;

int socket4FD;
Expand All @@ -73,16 +129,18 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;

unsigned long socketFDBytesAvailable;

NSMutableData *partialReadBuffer;
GCDAsyncSocketPreBuffer *preBuffer;

#if TARGET_OS_IPHONE
CFStreamClientContext streamContext;
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
#else
#endif
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
SSLContextRef sslContext;
NSMutableData *sslReadBuffer;
GCDAsyncSocketPreBuffer *sslPreBuffer;
size_t sslWriteCachedLength;
OSStatus sslErrCode;
#endif

id userData;
Expand Down Expand Up @@ -646,6 +704,12 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
maxLength:(NSUInteger)length
tag:(long)tag;

/**
* Returns progress of the current read, from 0.0 to 1.0, or NaN if no current read (use isnan() to check).
* The parameters "tag", "done" and "total" will be filled in if they aren't NULL.
**/
- (float)progressOfReadReturningTag:(long *)tagPtr bytesDone:(NSUInteger *)donePtr total:(NSUInteger *)totalPtr;

#pragma mark Writing

/**
Expand All @@ -667,6 +731,12 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
**/
- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag;

/**
* Returns progress of the current write, from 0.0 to 1.0, or NaN if no current write (use isnan() to check).
* The parameters "tag", "done" and "total" will be filled in if they aren't NULL.
**/
- (float)progressOfWriteReturningTag:(long *)tagPtr bytesDone:(NSUInteger *)donePtr total:(NSUInteger *)totalPtr;

#pragma mark Security

/**
Expand All @@ -678,7 +748,8 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
* Any reads or writes scheduled after this method is called will occur over the secured connection.
*
* The possible keys and values for the TLS settings are well documented.
* Some possible keys are:
* Standard keys are:
*
* - kCFStreamSSLLevel
* - kCFStreamSSLAllowsExpiredCertificates
* - kCFStreamSSLAllowsExpiredRoots
Expand All @@ -688,6 +759,18 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
* - kCFStreamSSLCertificates
* - kCFStreamSSLIsServer
*
* If SecureTransport is available on iOS:
*
* - GCDAsyncSocketSSLCipherSuites
* - GCDAsyncSocketSSLProtocolVersionMin
* - GCDAsyncSocketSSLProtocolVersionMax
*
* If SecureTransport is available on Mac OS X:
*
* - GCDAsyncSocketSSLCipherSuites
* - GCDAsyncSocketSSLDiffieHellmanParameters;
*
*
* Please refer to Apple's documentation for associated values, as well as other possible keys.
*
* If you pass in nil or an empty dictionary, the default settings will be used.
Expand Down

0 comments on commit 49a2003

Please sign in to comment.