TCP/TCPEndpoint.m
author morrowa
Fri Jul 03 17:50:28 2009 -0700 (2009-07-03)
changeset 58 6577813acf12
parent 26 cb9cdf247239
permissions -rw-r--r--
Fixed bug which caused PyBLIP to stop sending responses while the connection was closing.
     1 //
     2 //  BLIPEndpoint.m
     3 //  MYNetwork
     4 //
     5 //  Created by Jens Alfke on 5/14/08.
     6 //  Copyright 2008 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import "TCPEndpoint.h"
    10 #import "Test.h"
    11 #import "CollectionUtils.h"
    12 #import "ExceptionUtils.h"
    13 #import <Security/Security.h>
    14 
    15 
    16 NSString* const kTCPPropertySSLClientSideAuthentication = @"kTCPPropertySSLClientSideAuthentication";
    17 
    18 
    19 @implementation TCPEndpoint
    20 
    21 
    22 - (void) dealloc
    23 {
    24     [_sslProperties release];
    25     [super dealloc];
    26 }
    27 
    28 
    29 - (NSMutableDictionary*) SSLProperties {return _sslProperties;}
    30 
    31 - (void) setSSLProperties: (NSMutableDictionary*)props
    32 {
    33     if( props != _sslProperties ) {
    34         [_sslProperties release];
    35         _sslProperties = [props mutableCopy];
    36     }
    37 }
    38 
    39 - (void) setSSLProperty: (id)value forKey: (NSString*)key
    40 {
    41     if( value ) {
    42         if( ! _sslProperties )
    43             _sslProperties = [[NSMutableDictionary alloc] init];
    44         [_sslProperties setObject: value forKey: key];
    45     } else
    46         [_sslProperties removeObjectForKey: key];
    47 }
    48 
    49 - (NSString*) securityLevel                 {return [_sslProperties objectForKey: (id)kCFStreamSSLLevel];}
    50 - (void) setSecurityLevel: (NSString*)level {[self setSSLProperty: level forKey: (id)kCFStreamSSLLevel];}
    51 
    52 - (void) setPeerToPeerIdentity: (SecIdentityRef)identity {
    53     Assert(identity);
    54     self.SSLProperties = $mdict(
    55              {(id)kCFStreamSSLLevel, NSStreamSocketSecurityLevelTLSv1},
    56              {kTCPPropertySSLCertificates, $array((id)identity)},
    57              {kTCPPropertySSLAllowsAnyRoot, $true},
    58              {kTCPPropertySSLPeerName, [NSNull null]},
    59              {kTCPPropertySSLClientSideAuthentication, $object(kTCPAlwaysAuthenticate)});
    60 }
    61 
    62 - (void) tellDelegate: (SEL)selector withObject: (id)param
    63 {
    64     if( [_delegate respondsToSelector: selector] ) {
    65         @try{
    66             [_delegate performSelector: selector withObject: self withObject: param];
    67         }catchAndReport(@"%@ delegate",self.class);
    68     }
    69 }
    70 
    71 
    72 @end
    73 
    74 
    75 /*
    76  Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
    77  
    78  Redistribution and use in source and binary forms, with or without modification, are permitted
    79  provided that the following conditions are met:
    80  
    81  * Redistributions of source code must retain the above copyright notice, this list of conditions
    82  and the following disclaimer.
    83  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
    84  and the following disclaimer in the documentation and/or other materials provided with the
    85  distribution.
    86  
    87  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
    88  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    89  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
    90  BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    91  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    92   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    93  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
    94  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    95  */