Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-6211] Added iOS "secured" and "startTLS" to TCP Sockets #725

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions iphone/Classes/TiNetworkSocketTCPProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef enum {
KrollCallback* accepted;
KrollCallback* closed;
KrollCallback* error;
KrollCallback* secured;
}
// Properties:
// -- Stored on TiProxy dynprops --
Expand All @@ -65,9 +66,11 @@ typedef enum {
@property (nonatomic, readwrite, retain) KrollCallback* accepted;
@property (nonatomic, readwrite, retain) KrollCallback* closed;
@property (nonatomic, readwrite, retain) KrollCallback* error;
@property (nonatomic, readwrite, retain) KrollCallback* secured;

// Public API
-(void)connect:(id)_void;
-(void)startTLS:(id)_void;
-(void)listen:(id)arg; // arg[0]: int maxAcceptQueueSize : queue size
-(void)accept:(id)arg; // arg[0]: Object params : callbacks for created socket
-(void)close:(id)_void;
Expand Down
18 changes: 17 additions & 1 deletion iphone/Classes/TiNetworkSocketTCPProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ -(void)socketRunLoop;
@end

@implementation TiNetworkSocketTCPProxy
@synthesize host, connected, accepted, closed, error;
@synthesize host, connected, accepted, closed, error, secured;

#pragma mark Internals

Expand Down Expand Up @@ -66,6 +66,7 @@ -(void)_destroy
RELEASE_TO_NIL(accepted);
RELEASE_TO_NIL(closed);
RELEASE_TO_NIL(error);
RELEASE_TO_NIL(secured);

// Release the conditions... so long as each condition has been retained, this is safe.
RELEASE_TO_NIL(listening);
Expand Down Expand Up @@ -292,6 +293,14 @@ -(void)connect:(id)_void
[self performSelectorInBackground:@selector(startConnectingSocket) withObject:nil];
}

-(void)startTLS:(id)_void
{
NSMutableDictionary* args = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO],(NSString *)kCFStreamSSLValidatesCertificateChain,
nil];
[socket performSelector:@selector(startTLS:) onThread:socketThread withObject:args waitUntilDone:NO];
}

-(void)listen:(id)arg
{
if (!(internalState & SOCKET_INITIALIZED)) {
Expand Down Expand Up @@ -385,6 +394,7 @@ -(void)funcname:(type*)val \

TYPESAFE_SETTER(setConnected, connected, KrollCallback)
TYPESAFE_SETTER(setAccepted, accepted, KrollCallback)
TYPESAFE_SETTER(setSecured, secured, KrollCallback)
TYPESAFE_SETTER(setClosed, closed, KrollCallback)
TYPESAFE_SETTER(setError, error, KrollCallback)

Expand Down Expand Up @@ -627,6 +637,12 @@ -(void)onSocketReadyInRunLoop:(AsyncSocket *)sock
[tempConditionRef release];
}

- (void)onSocketDidSecure:(AsyncSocket *)_socket
{
NSDictionary* event = [NSDictionary dictionaryWithObjectsAndKeys:self,@"socket", nil];
[self _fireEventToListener:@"secured" withObject:event listener:secured thisObject:self];
}

-(void)onSocketDidDisconnect:(AsyncSocket *)sock
{
// Triggered when we error out, so don't fire in that situation
Expand Down