IPAddressChange: iphone_ip_change_pjsip_1_12.patch

File iphone_ip_change_pjsip_1_12.patch, 27.5 KB (added by bennylp, 8 years ago)

Patch to handle IP change on iPhone, including connection monitor

  • pjsip-apps/src/pjsua/pjsua_app.c

     
    126126 
    127127} app_config; 
    128128 
     129static int the_acc_id; 
     130static pjsip_transport *the_transport; 
    129131 
    130132//static pjsua_acc_id   current_acc; 
    131133#define current_acc     pjsua_acc_get_default() 
     
    175177} 
    176178#endif 
    177179 
     180void ip_change() 
     181{ 
     182    pj_status_t status; 
     183     
     184    PJ_LOG(3,(THIS_FILE, "xxx: IP change..")); 
     185 
     186    if (the_transport) { 
     187        status = pjsip_transport_shutdown(the_transport); 
     188        if (status != PJ_SUCCESS) 
     189            PJ_PERROR(1,(THIS_FILE, status, 
     190                         "xxx: pjsip_transport_shutdown() error")); 
     191         
     192        pjsip_transport_dec_ref(the_transport); 
     193        the_transport = NULL; 
     194    } 
     195 
     196    status = pjsua_acc_set_registration(the_acc_id, PJ_FALSE); 
     197    if (status != PJ_SUCCESS) 
     198        PJ_PERROR(1,(THIS_FILE, status, 
     199                     "xxx: pjsua_acc_set_registration(0) error")); 
     200     
     201    PJ_LOG(3,(THIS_FILE, "xxx: IP change done, " 
     202                         "press \"rr\" to reregister.."));     
     203} 
     204 
    178205/* Show usage */ 
    179206static void usage(void) 
    180207{ 
     
    27512778/* 
    27522779 * Handler registration status has changed. 
    27532780 */ 
    2754 static void on_reg_state(pjsua_acc_id acc_id) 
     2781static void on_reg_state2(pjsua_acc_id acc_id, pjsua_reg_info *info) 
    27552782{ 
     2783    struct pjsip_regc_cbparam *rp = info->cbparam; 
     2784 
    27562785    PJ_UNUSED_ARG(acc_id); 
    27572786 
    27582787    // Log already written. 
     2788    if (rp->code/100 == 2 && rp->expiration > 0 && rp->contact_cnt > 0) { 
     2789        /* Registration success */ 
     2790        if (the_transport) { 
     2791            PJ_LOG(3,(THIS_FILE, "xxx: Releasing transport..")); 
     2792            pjsip_transport_dec_ref(the_transport); 
     2793            the_transport = NULL; 
     2794        } 
     2795        /* Save transport instance so that we can close it later when 
     2796         * new IP address is detected. 
     2797         */ 
     2798        PJ_LOG(3,(THIS_FILE, "xxx: Saving transport..")); 
     2799        the_transport = rp->rdata->tp_info.transport; 
     2800        pjsip_transport_add_ref(the_transport); 
     2801    } else { 
     2802        if (the_transport) { 
     2803            PJ_LOG(3,(THIS_FILE, "xxx: Releasing transport..")); 
     2804            pjsip_transport_dec_ref(the_transport); 
     2805            the_transport = NULL; 
     2806        } 
     2807    } 
    27592808} 
    27602809 
    27612810 
     
    44984547            } 
    44994548            break; 
    45004549 
     4550        case 'P': 
     4551            ip_change(); 
     4552            break; 
     4553 
    45014554        default: 
    45024555            if (menuin[0] != '\n' && menuin[0] != '\r') { 
    45034556                printf("Invalid input %s", menuin); 
     
    46394692    app_config.cfg.cb.on_call_tsx_state = &on_call_tsx_state; 
    46404693    app_config.cfg.cb.on_dtmf_digit = &call_on_dtmf_callback; 
    46414694    app_config.cfg.cb.on_call_redirected = &call_on_redirected; 
    4642     app_config.cfg.cb.on_reg_state = &on_reg_state; 
     4695    app_config.cfg.cb.on_reg_state2 = &on_reg_state2; 
    46434696    app_config.cfg.cb.on_incoming_subscribe = &on_incoming_subscribe; 
    46444697    app_config.cfg.cb.on_buddy_state = &on_buddy_state; 
    46454698    app_config.cfg.cb.on_buddy_evsub_state = &on_buddy_evsub_state; 
     
    49294982 
    49304983    /* Add accounts */ 
    49314984    for (i=0; i<app_config.acc_cnt; ++i) { 
    4932         status = pjsua_acc_add(&app_config.acc_cfg[i], PJ_TRUE, NULL); 
     4985        pjsua_acc_id acc_id; 
     4986        status = pjsua_acc_add(&app_config.acc_cfg[i], PJ_TRUE, &acc_id); 
    49334987        if (status != PJ_SUCCESS) 
    49344988            goto on_error; 
    49354989        pjsua_acc_set_online_status(current_acc, PJ_TRUE); 
     4990 
     4991        if (!the_acc_id) { 
     4992            the_acc_id = acc_id; 
     4993        } 
    49364994    } 
    49374995 
    49384996    /* Add buddies */ 
  • pjsip-apps/src/ipjsua/Classes/ipjsuaAppDelegate.m

     
    1616 * along with this program; if not, write to the Free Software 
    1717 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
    1818 */ 
     19#import "Reachability.h" 
    1920#import <pjlib.h> 
    2021#import <pjsua.h> 
    2122#import "ipjsuaAppDelegate.h" 
     
    5253pj_thread_desc           a_thread_desc; 
    5354pj_thread_t             *a_thread; 
    5455pjsua_call_id            ccall_id; 
     56Reachability            *internetReach; 
    5557 
    5658pj_status_t app_init(int argc, char *argv[]); 
    5759pj_status_t app_main(void); 
    5860pj_status_t app_destroy(void); 
    5961void keepAliveFunction(int timeout); 
     62void ip_change(); 
    6063 
    6164void showMsg(const char *format, ...) 
    6265{ 
     
    204207    [self.mainView.textView scrollRangeToVisible:NSMakeRange([self.mainView.textView.text length] - 1, 1)]; 
    205208} 
    206209 
     210- (void) updateWithReachability: (Reachability *)curReach 
     211{ 
     212    NetworkStatus netStatus = [curReach currentReachabilityStatus]; 
     213    BOOL connectionRequired= [curReach connectionRequired]; 
     214 
     215    switch (netStatus) { 
     216        case NotReachable: 
     217            PJ_LOG(3,("", "Access Not Available..")); 
     218            connectionRequired= NO;   
     219            break; 
     220        case ReachableViaWiFi: 
     221            PJ_LOG(3,("", "Reachable WiFi..")); 
     222            break; 
     223        case ReachableViaWWAN: 
     224            PJ_LOG(3,("", "Reachable WWAN..")); 
     225            break; 
     226    } 
     227 
     228    if (connectionRequired) { 
     229        PJ_LOG(3,("", "Connection Required")); 
     230    } 
     231} 
     232 
     233/* Called by Reachability whenever status changes. */ 
     234- (void)reachabilityChanged: (NSNotification *)note 
     235{ 
     236    Reachability* curReach = [note object]; 
     237 
     238    NSParameterAssert([curReach isKindOfClass: [Reachability class]]); 
     239    PJ_LOG(3,("", "reachability changed..")); 
     240    [self updateWithReachability: curReach]; 
     241     
     242    if ([curReach currentReachabilityStatus] != NotReachable && 
     243        ![curReach connectionRequired]) 
     244         ip_change(); 
     245} 
     246 
    207247- (void)applicationDidFinishLaunching:(UIApplication *)application { 
     248    /* Observe the kNetworkReachabilityChangedNotification. When that 
     249     * notification is posted, the method "reachabilityChanged" will be called.  
     250     */ 
     251    [[NSNotificationCenter defaultCenter] addObserver: self 
     252        selector: @selector(reachabilityChanged:) 
     253        name: kReachabilityChangedNotification object: nil]; 
     254         
     255    internetReach = [[Reachability reachabilityForInternetConnection] retain]; 
     256    [internetReach startNotifier]; 
     257    [self updateWithReachability: internetReach]; 
     258 
    208259    /* If there is no config file in the document dir, copy the default config file into the directory */  
    209260    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    210261    NSString *cfgPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"/config.cfg"]; 
  • pjsip-apps/src/ipjsua/Classes/Reachability.h

     
     1/* 
     2  
     3 File: Reachability.h 
     4 Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs. 
     5  
     6 Version: 2.2 
     7  
     8 Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple Inc. 
     9 ("Apple") in consideration of your agreement to the following terms, and your 
     10 use, installation, modification or redistribution of this Apple software 
     11 constitutes acceptance of these terms.  If you do not agree with these terms, 
     12 please do not use, install, modify or redistribute this Apple software. 
     13  
     14 In consideration of your agreement to abide by the following terms, and subject 
     15 to these terms, Apple grants you a personal, non-exclusive license, under 
     16 Apple's copyrights in this original Apple software (the "Apple Software"), to 
     17 use, reproduce, modify and redistribute the Apple Software, with or without 
     18 modifications, in source and/or binary forms; provided that if you redistribute 
     19 the Apple Software in its entirety and without modifications, you must retain 
     20 this notice and the following text and disclaimers in all such redistributions 
     21 of the Apple Software. 
     22 Neither the name, trademarks, service marks or logos of Apple Inc. may be used 
     23 to endorse or promote products derived from the Apple Software without specific 
     24 prior written permission from Apple.  Except as expressly stated in this notice, 
     25 no other rights or licenses, express or implied, are granted by Apple herein, 
     26 including but not limited to any patent rights that may be infringed by your 
     27 derivative works or by other works in which the Apple Software may be 
     28 incorporated. 
     29  
     30 The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO 
     31 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED 
     32 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
     33 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN 
     34 COMBINATION WITH YOUR PRODUCTS. 
     35  
     36 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR 
     37 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
     38 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
     39 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR 
     40 DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF 
     41 CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF 
     42 APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     43  
     44 Copyright (C) 2010 Apple Inc. All Rights Reserved. 
     45  
     46*/ 
     47 
     48 
     49#import <Foundation/Foundation.h> 
     50#import <SystemConfiguration/SystemConfiguration.h> 
     51 
     52typedef enum { 
     53        NotReachable = 0, 
     54        ReachableViaWiFi, 
     55        ReachableViaWWAN 
     56} NetworkStatus; 
     57#define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification" 
     58 
     59@interface Reachability: NSObject 
     60{ 
     61        BOOL localWiFiRef; 
     62        SCNetworkReachabilityRef reachabilityRef; 
     63} 
     64 
     65//reachabilityWithHostName- Use to check the reachability of a particular host name.  
     66+ (Reachability*) reachabilityWithHostName: (NSString*) hostName; 
     67 
     68//reachabilityWithAddress- Use to check the reachability of a particular IP address.  
     69+ (Reachability*) reachabilityWithAddress: (const struct sockaddr_in*) hostAddress; 
     70 
     71//reachabilityForInternetConnection- checks whether the default route is available.   
     72//  Should be used by applications that do not connect to a particular host 
     73+ (Reachability*) reachabilityForInternetConnection; 
     74 
     75//reachabilityForLocalWiFi- checks whether a local wifi connection is available. 
     76+ (Reachability*) reachabilityForLocalWiFi; 
     77 
     78//Start listening for reachability notifications on the current run loop 
     79- (BOOL) startNotifier; 
     80- (void) stopNotifier; 
     81 
     82- (NetworkStatus) currentReachabilityStatus; 
     83//WWAN may be available, but not active until a connection has been established. 
     84//WiFi may require a connection for VPN on Demand. 
     85- (BOOL) connectionRequired; 
     86@end 
     87 
     88 
  • pjsip-apps/src/ipjsua/Classes/Reachability.m

    Property changes on: pjsip-apps/src/ipjsua/Classes/Reachability.h
    ___________________________________________________________________
    Added: svn:keywords
       + id
    Added: svn:eol-style
       + native
    
     
     1/* 
     2  
     3 File: Reachability.m 
     4 Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs. 
     5  
     6 Version: 2.2 
     7  
     8 Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple Inc. 
     9 ("Apple") in consideration of your agreement to the following terms, and your 
     10 use, installation, modification or redistribution of this Apple software 
     11 constitutes acceptance of these terms.  If you do not agree with these terms, 
     12 please do not use, install, modify or redistribute this Apple software. 
     13  
     14 In consideration of your agreement to abide by the following terms, and subject 
     15 to these terms, Apple grants you a personal, non-exclusive license, under 
     16 Apple's copyrights in this original Apple software (the "Apple Software"), to 
     17 use, reproduce, modify and redistribute the Apple Software, with or without 
     18 modifications, in source and/or binary forms; provided that if you redistribute 
     19 the Apple Software in its entirety and without modifications, you must retain 
     20 this notice and the following text and disclaimers in all such redistributions 
     21 of the Apple Software. 
     22 Neither the name, trademarks, service marks or logos of Apple Inc. may be used 
     23 to endorse or promote products derived from the Apple Software without specific 
     24 prior written permission from Apple.  Except as expressly stated in this notice, 
     25 no other rights or licenses, express or implied, are granted by Apple herein, 
     26 including but not limited to any patent rights that may be infringed by your 
     27 derivative works or by other works in which the Apple Software may be 
     28 incorporated. 
     29  
     30 The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO 
     31 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED 
     32 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
     33 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN 
     34 COMBINATION WITH YOUR PRODUCTS. 
     35  
     36 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR 
     37 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
     38 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
     39 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR 
     40 DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF 
     41 CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF 
     42 APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     43  
     44 Copyright (C) 2010 Apple Inc. All Rights Reserved. 
     45  
     46*/ 
     47 
     48#import <sys/socket.h> 
     49#import <netinet/in.h> 
     50#import <netinet6/in6.h> 
     51#import <arpa/inet.h> 
     52#import <ifaddrs.h> 
     53#import <netdb.h> 
     54 
     55#import <CoreFoundation/CoreFoundation.h> 
     56 
     57#import "Reachability.h" 
     58 
     59#define kShouldPrintReachabilityFlags 1 
     60 
     61static void PrintReachabilityFlags(SCNetworkReachabilityFlags    flags, const char* comment) 
     62{ 
     63#if kShouldPrintReachabilityFlags 
     64         
     65    NSLog(@"Reachability Flag Status: %c%c %c%c%c%c%c%c%c %s\n", 
     66                        (flags & kSCNetworkReachabilityFlagsIsWWAN)                               ? 'W' : '-', 
     67                        (flags & kSCNetworkReachabilityFlagsReachable)            ? 'R' : '-', 
     68                         
     69                        (flags & kSCNetworkReachabilityFlagsTransientConnection)  ? 't' : '-', 
     70                        (flags & kSCNetworkReachabilityFlagsConnectionRequired)   ? 'c' : '-', 
     71                        (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic)  ? 'C' : '-', 
     72                        (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-', 
     73                        (flags & kSCNetworkReachabilityFlagsConnectionOnDemand)   ? 'D' : '-', 
     74                        (flags & kSCNetworkReachabilityFlagsIsLocalAddress)       ? 'l' : '-', 
     75                        (flags & kSCNetworkReachabilityFlagsIsDirect)             ? 'd' : '-', 
     76                        comment 
     77                        ); 
     78#endif 
     79} 
     80 
     81 
     82@implementation Reachability 
     83static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) 
     84{ 
     85        #pragma unused (target, flags) 
     86        NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback"); 
     87        NSCAssert([(NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback"); 
     88 
     89        //We're on the main RunLoop, so an NSAutoreleasePool is not necessary, but is added defensively 
     90        // in case someon uses the Reachablity object in a different thread. 
     91        NSAutoreleasePool* myPool = [[NSAutoreleasePool alloc] init]; 
     92         
     93        Reachability* noteObject = (Reachability*) info; 
     94        // Post a notification to notify the client that the network reachability changed. 
     95        [[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject]; 
     96         
     97        [myPool release]; 
     98} 
     99 
     100- (BOOL) startNotifier 
     101{ 
     102        BOOL retVal = NO; 
     103        SCNetworkReachabilityContext    context = {0, self, NULL, NULL, NULL}; 
     104        if(SCNetworkReachabilitySetCallback(reachabilityRef, ReachabilityCallback, &context)) 
     105        { 
     106                if(SCNetworkReachabilityScheduleWithRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) 
     107                { 
     108                        retVal = YES; 
     109                } 
     110        } 
     111        return retVal; 
     112} 
     113 
     114- (void) stopNotifier 
     115{ 
     116        if(reachabilityRef!= NULL) 
     117        { 
     118                SCNetworkReachabilityUnscheduleFromRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 
     119        } 
     120} 
     121 
     122- (void) dealloc 
     123{ 
     124        [self stopNotifier]; 
     125        if(reachabilityRef!= NULL) 
     126        { 
     127                CFRelease(reachabilityRef); 
     128        } 
     129        [super dealloc]; 
     130} 
     131 
     132+ (Reachability*) reachabilityWithHostName: (NSString*) hostName; 
     133{ 
     134        Reachability* retVal = NULL; 
     135        SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]); 
     136        if(reachability!= NULL) 
     137        { 
     138                retVal= [[[self alloc] init] autorelease]; 
     139                if(retVal!= NULL) 
     140                { 
     141                        retVal->reachabilityRef = reachability; 
     142                        retVal->localWiFiRef = NO; 
     143                } 
     144        } 
     145        return retVal; 
     146} 
     147 
     148+ (Reachability*) reachabilityWithAddress: (const struct sockaddr_in*) hostAddress; 
     149{ 
     150        SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress); 
     151        Reachability* retVal = NULL; 
     152        if(reachability!= NULL) 
     153        { 
     154                retVal= [[[self alloc] init] autorelease]; 
     155                if(retVal!= NULL) 
     156                { 
     157                        retVal->reachabilityRef = reachability; 
     158                        retVal->localWiFiRef = NO; 
     159                } 
     160        } 
     161        return retVal; 
     162} 
     163 
     164+ (Reachability*) reachabilityForInternetConnection; 
     165{ 
     166        struct sockaddr_in zeroAddress; 
     167        bzero(&zeroAddress, sizeof(zeroAddress)); 
     168        zeroAddress.sin_len = sizeof(zeroAddress); 
     169        zeroAddress.sin_family = AF_INET; 
     170        return [self reachabilityWithAddress: &zeroAddress]; 
     171} 
     172 
     173+ (Reachability*) reachabilityForLocalWiFi; 
     174{ 
     175        struct sockaddr_in localWifiAddress; 
     176        bzero(&localWifiAddress, sizeof(localWifiAddress)); 
     177        localWifiAddress.sin_len = sizeof(localWifiAddress); 
     178        localWifiAddress.sin_family = AF_INET; 
     179        // IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0 
     180        localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM); 
     181        Reachability* retVal = [self reachabilityWithAddress: &localWifiAddress]; 
     182        if(retVal!= NULL) 
     183        { 
     184                retVal->localWiFiRef = YES; 
     185        } 
     186        return retVal; 
     187} 
     188 
     189#pragma mark Network Flag Handling 
     190 
     191- (NetworkStatus) localWiFiStatusForFlags: (SCNetworkReachabilityFlags) flags 
     192{ 
     193        PrintReachabilityFlags(flags, "localWiFiStatusForFlags"); 
     194 
     195        BOOL retVal = NotReachable; 
     196        if((flags & kSCNetworkReachabilityFlagsReachable) && (flags & kSCNetworkReachabilityFlagsIsDirect)) 
     197        { 
     198                retVal = ReachableViaWiFi;       
     199        } 
     200        return retVal; 
     201} 
     202 
     203- (NetworkStatus) networkStatusForFlags: (SCNetworkReachabilityFlags) flags 
     204{ 
     205        PrintReachabilityFlags(flags, "networkStatusForFlags"); 
     206        if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) 
     207        { 
     208                // if target host is not reachable 
     209                return NotReachable; 
     210        } 
     211 
     212        BOOL retVal = NotReachable; 
     213         
     214        if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0) 
     215        { 
     216                // if target host is reachable and no connection is required 
     217                //  then we'll assume (for now) that your on Wi-Fi 
     218                retVal = ReachableViaWiFi; 
     219        } 
     220         
     221         
     222        if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || 
     223                (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0)) 
     224        { 
     225                        // ... and the connection is on-demand (or on-traffic) if the 
     226                        //     calling application is using the CFSocketStream or higher APIs 
     227 
     228                        if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0) 
     229                        { 
     230                                // ... and no [user] intervention is needed 
     231                                retVal = ReachableViaWiFi; 
     232                        } 
     233                } 
     234         
     235        if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) 
     236        { 
     237                // ... but WWAN connections are OK if the calling application 
     238                //     is using the CFNetwork (CFSocketStream?) APIs. 
     239                retVal = ReachableViaWWAN; 
     240        } 
     241        return retVal; 
     242} 
     243 
     244- (BOOL) connectionRequired; 
     245{ 
     246        NSAssert(reachabilityRef != NULL, @"connectionRequired called with NULL reachabilityRef"); 
     247        SCNetworkReachabilityFlags flags; 
     248        if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) 
     249        { 
     250                return (flags & kSCNetworkReachabilityFlagsConnectionRequired); 
     251        } 
     252        return NO; 
     253} 
     254 
     255- (NetworkStatus) currentReachabilityStatus 
     256{ 
     257        NSAssert(reachabilityRef != NULL, @"currentNetworkStatus called with NULL reachabilityRef"); 
     258        NetworkStatus retVal = NotReachable; 
     259        SCNetworkReachabilityFlags flags; 
     260        if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) 
     261        { 
     262                if(localWiFiRef) 
     263                { 
     264                        retVal = [self localWiFiStatusForFlags: flags]; 
     265                } 
     266                else 
     267                { 
     268                        retVal = [self networkStatusForFlags: flags]; 
     269                } 
     270        } 
     271        return retVal; 
     272} 
     273@end 
  • pjsip-apps/src/ipjsua/ipjsua.xcodeproj/project.pbxproj

    Property changes on: pjsip-apps/src/ipjsua/Classes/Reachability.m
    ___________________________________________________________________
    Added: svn:keywords
       + id
    Added: svn:eol-style
       + native
    
     
    1818                3A0D789F121E324E009D5030 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A0D789E121E324E009D5030 /* CFNetwork.framework */; }; 
    1919                3A0D7ECD123DD46C009D5030 /* MainWindow-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3A0D7ECC123DD46C009D5030 /* MainWindow-iPad.xib */; }; 
    2020                3A0D7F20123F2254009D5030 /* SecondView-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3A0D7F1F123F2254009D5030 /* SecondView-iPad.xib */; }; 
     21                3AD13BEE13F54D8F00F1536A /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AD13BED13F54D8F00F1536A /* Reachability.m */; }; 
     22                3AD13C0913F8B0AE00F1536A /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AD13C0813F8B0AE00F1536A /* SystemConfiguration.framework */; }; 
    2123                3AE9099D11587BB900FAEAA5 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AE9099C11587BB900FAEAA5 /* AudioToolbox.framework */; }; 
    2224                3AE90A2D1158B52500FAEAA5 /* pjsua_app.c in Sources */ = {isa = PBXBuildFile; fileRef = 3AE90A2C1158B52500FAEAA5 /* pjsua_app.c */; }; 
    2325                3AE90A6A1158C6B400FAEAA5 /* libgsmcodec-arm-apple-darwin9.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AE90A691158C6B400FAEAA5 /* libgsmcodec-arm-apple-darwin9.a */; }; 
     
    5961                3A0D789E121E324E009D5030 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; 
    6062                3A0D7ECC123DD46C009D5030 /* MainWindow-iPad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MainWindow-iPad.xib"; path = "Resources-iPad/MainWindow-iPad.xib"; sourceTree = "<group>"; }; 
    6163                3A0D7F1F123F2254009D5030 /* SecondView-iPad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "SecondView-iPad.xib"; path = "Resources-iPad/SecondView-iPad.xib"; sourceTree = "<group>"; }; 
     64                3AD13BEC13F54D8F00F1536A /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = "<group>"; }; 
     65                3AD13BED13F54D8F00F1536A /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = "<group>"; }; 
     66                3AD13C0813F8B0AE00F1536A /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; 
    6267                3AE9099C11587BB900FAEAA5 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 
    6368                3AE90A2C1158B52500FAEAA5 /* pjsua_app.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pjsua_app.c; path = ../pjsua/pjsua_app.c; sourceTree = SOURCE_ROOT; }; 
    6469                3AE90A691158C6B400FAEAA5 /* libgsmcodec-arm-apple-darwin9.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libgsmcodec-arm-apple-darwin9.a"; path = "../../../third_party/lib/libgsmcodec-arm-apple-darwin9.a"; sourceTree = SOURCE_ROOT; }; 
     
    116121                                3AE90EBB115F7BCE00FAEAA5 /* libspeex-arm-apple-darwin9.a in Frameworks */, 
    117122                                3AE90EBC115F7BCE00FAEAA5 /* libsrtp-arm-apple-darwin9.a in Frameworks */, 
    118123                                3A0D789F121E324E009D5030 /* CFNetwork.framework in Frameworks */, 
     124                                3AD13C0913F8B0AE00F1536A /* SystemConfiguration.framework in Frameworks */, 
    119125                        ); 
    120126                        runOnlyForDeploymentPostprocessing = 0; 
    121127                }; 
     
    125131                080E96DDFE201D6D7F000001 /* Classes */ = { 
    126132                        isa = PBXGroup; 
    127133                        children = ( 
     134                                3AD13BEC13F54D8F00F1536A /* Reachability.h */, 
     135                                3AD13BED13F54D8F00F1536A /* Reachability.m */, 
    128136                                3AE90DAB115BB1CF00FAEAA5 /* ConfigViewController.h */, 
    129137                                3AE90DAC115BB1CF00FAEAA5 /* ConfigViewController.m */, 
    130138                                28216C950DB411BC00E5133A /* FirstViewController.h */, 
     
    184192                29B97323FDCFA39411CA2CEA /* Frameworks */ = { 
    185193                        isa = PBXGroup; 
    186194                        children = ( 
     195                                3AD13C0813F8B0AE00F1536A /* SystemConfiguration.framework */, 
    187196                                1DF5F4DF0D08C38300B7A737 /* UIKit.framework */, 
    188197                                1D30AB110D05D00D00671497 /* Foundation.framework */, 
    189198                                288765070DF74369002DB57D /* CoreGraphics.framework */, 
     
    257266                        }; 
    258267                        buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ipjsua" */; 
    259268                        compatibilityVersion = "Xcode 3.1"; 
     269                        developmentRegion = English; 
    260270                        hasScannedForEncodings = 1; 
     271                        knownRegions = ( 
     272                                en, 
     273                        ); 
    261274                        mainGroup = 29B97314FDCFA39411CA2CEA /* ipjsua */; 
    262275                        projectDirPath = ""; 
    263276                        projectRoot = ""; 
     
    293306                                3AE90A2D1158B52500FAEAA5 /* pjsua_app.c in Sources */, 
    294307                                3AE90C51115A35BB00FAEAA5 /* TabBarController.m in Sources */, 
    295308                                3AE90DAD115BB1CF00FAEAA5 /* ConfigViewController.m in Sources */, 
     309                                3AD13BEE13F54D8F00F1536A /* Reachability.m in Sources */, 
    296310                        ); 
    297311                        runOnlyForDeploymentPostprocessing = 0; 
    298312                }; 
     
    303317                        isa = XCBuildConfiguration; 
    304318                        buildSettings = { 
    305319                                ALWAYS_SEARCH_USER_PATHS = NO; 
    306                                 ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 
     320                                ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)"; 
    307321                                COPY_PHASE_STRIP = NO; 
    308322                                GCC_DYNAMIC_NO_PIC = NO; 
    309323                                GCC_OPTIMIZATION_LEVEL = 0; 
     
    321335                                        "\"$(SRCROOT)/../../../pjsip/lib\"", 
    322336                                ); 
    323337                                PRODUCT_NAME = ipjsua; 
    324                                 SDKROOT = iphoneos3.2; 
     338                                SDKROOT = iphoneos; 
    325339                                TARGETED_DEVICE_FAMILY = "1,2"; 
    326340                        }; 
    327341                        name = Debug; 
     
    330344                        isa = XCBuildConfiguration; 
    331345                        buildSettings = { 
    332346                                ALWAYS_SEARCH_USER_PATHS = NO; 
    333                                 ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 
     347                                ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)"; 
    334348                                COPY_PHASE_STRIP = YES; 
    335349                                GCC_PRECOMPILE_PREFIX_HEADER = YES; 
    336350                                GCC_PREFIX_HEADER = ipjsua_Prefix.pch; 
     
    346360                                        "\"$(SRCROOT)/../../../pjsip/lib\"", 
    347361                                ); 
    348362                                PRODUCT_NAME = ipjsua; 
    349                                 SDKROOT = iphoneos3.2; 
     363                                SDKROOT = iphoneos; 
    350364                                TARGETED_DEVICE_FAMILY = "1,2"; 
    351365                        }; 
    352366                        name = Release; 
     
    354368                C01FCF4F08A954540054247B /* Debug */ = { 
    355369                        isa = XCBuildConfiguration; 
    356370                        buildSettings = { 
    357                                 ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 
     371                                ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)"; 
    358372                                "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 
    359373                                GCC_C_LANGUAGE_STANDARD = c99; 
    360374                                GCC_PREPROCESSOR_DEFINITIONS = USE_GUI; 
     
    377391                                ); 
    378392                                OTHER_CFLAGS = ""; 
    379393                                PREBINDING = NO; 
    380                                 SDKROOT = iphoneos3.2; 
     394                                SDKROOT = iphoneos; 
    381395                        }; 
    382396                        name = Debug; 
    383397                }; 
    384398                C01FCF5008A954540054247B /* Release */ = { 
    385399                        isa = XCBuildConfiguration; 
    386400                        buildSettings = { 
    387                                 ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 
     401                                ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)"; 
    388402                                "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 
    389403                                GCC_C_LANGUAGE_STANDARD = c99; 
    390404                                GCC_PREPROCESSOR_DEFINITIONS = USE_GUI; 
     
    407421                                ); 
    408422                                OTHER_CFLAGS = ""; 
    409423                                PREBINDING = NO; 
    410                                 SDKROOT = iphoneos3.2; 
     424                                SDKROOT = iphoneos; 
    411425                        }; 
    412426                        name = Release; 
    413427                };