Changeset 3543 for pjproject


Ignore:
Timestamp:
Apr 26, 2011 3:07:24 AM (13 years ago)
Author:
ming
Message:

Fixed #1246: Use CFHost for pj_getaddrinfo() on iOS

  • Replace the fix for ticket #1104 with this fix
  • Modify pjturn-client/client_main's shutdown() function which conflicts with an existing function

Re-run configure-iphone to use this fix automatically.

Location:
pjproject/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/compat/os_auto.h.in

    r3423 r3543  
    176176#    if TARGET_OS_IPHONE 
    177177#       include "Availability.h" 
     178        /* Use CFHost API for pj_getaddrinfo() (see ticket #1246) */ 
     179#       define PJ_GETADDRINFO_USE_CFHOST 1 
    178180#       ifdef __IPHONE_4_0 
    179             /* Append ".local" suffix to the system's hostname? (see ticket #1104) */ 
    180 #           define PJ_GETHOSTNAME_APPEND_LOCAL_SUFFIX           1 
    181181            /* Is multitasking support available?  (see ticket #1107) */ 
    182182#           define PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT        1 
  • pjproject/trunk/pjlib/src/pj/addr_resolv_sock.c

    r3234 r3543  
    2525#include <pj/compat/socket.h> 
    2626 
     27#if defined(PJ_GETADDRINFO_USE_CFHOST) && PJ_GETADDRINFO_USE_CFHOST!=0 
     28#   include <CoreFoundation/CFString.h> 
     29#   include <CFNetwork/CFHost.h> 
     30#endif 
    2731 
    2832PJ_DEF(pj_status_t) pj_gethostbyname(const pj_str_t *hostname, pj_hostent *phe) 
     
    6367#if defined(PJ_SOCK_HAS_GETADDRINFO) && PJ_SOCK_HAS_GETADDRINFO!=0 
    6468    char nodecopy[PJ_MAX_HOSTNAME]; 
    65     struct addrinfo hint, *res, *orig_res; 
    6669    pj_bool_t has_addr = PJ_FALSE; 
    6770    unsigned i; 
     71#if defined(PJ_GETADDRINFO_USE_CFHOST) && PJ_GETADDRINFO_USE_CFHOST!=0 
     72    CFStringRef hostname; 
     73    CFHostRef hostRef; 
     74    pj_status_t status = PJ_SUCCESS; 
     75#else 
    6876    int rc; 
     77    struct addrinfo hint, *res, *orig_res; 
     78#endif 
    6979 
    7080    PJ_ASSERT_RETURN(nodename && count && *count && ai, PJ_EINVAL); 
     
    106116    nodecopy[nodename->slen] = '\0'; 
    107117 
     118#if defined(PJ_GETADDRINFO_USE_CFHOST) && PJ_GETADDRINFO_USE_CFHOST!=0 
     119    hostname =  CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, nodecopy, 
     120                                                kCFStringEncodingASCII, 
     121                                                kCFAllocatorNull); 
     122    hostRef = CFHostCreateWithName(kCFAllocatorDefault, hostname); 
     123    if (CFHostStartInfoResolution(hostRef, kCFHostAddresses, nil)) { 
     124        CFArrayRef addrRef = CFHostGetAddressing(hostRef, nil); 
     125        i = 0; 
     126        if (addrRef != nil) { 
     127            CFIndex idx, naddr; 
     128             
     129            naddr = CFArrayGetCount(addrRef); 
     130            for (idx = 0; idx < naddr && i < *count; idx++) { 
     131                struct sockaddr *addr; 
     132                 
     133                addr = (struct sockaddr *) 
     134                       CFDataGetBytePtr(CFArrayGetValueAtIndex(addrRef, idx)); 
     135                /* This should not happen. */ 
     136                pj_assert(addr); 
     137                 
     138                /* Ignore unwanted address families */ 
     139                if (af!=PJ_AF_UNSPEC && addr->sa_family != af) 
     140                    continue; 
     141 
     142                /* Store canonical name */ 
     143                pj_ansi_strcpy(ai[i].ai_canonname, nodecopy); 
     144                 
     145                /* Store address */ 
     146                PJ_ASSERT_ON_FAIL(sizeof(*addr) <= sizeof(pj_sockaddr), 
     147                                  continue); 
     148                pj_memcpy(&ai[i].ai_addr, addr, sizeof(*addr)); 
     149                PJ_SOCKADDR_RESET_LEN(&ai[i].ai_addr); 
     150                 
     151                i++; 
     152            } 
     153        } 
     154         
     155        *count = i; 
     156    } else { 
     157        status = PJ_ERESOLVE; 
     158    } 
     159     
     160    CFRelease(hostRef); 
     161    CFRelease(hostname); 
     162     
     163    return status; 
     164#else 
    108165    /* Call getaddrinfo() */ 
    109166    pj_bzero(&hint, sizeof(hint)); 
     
    146203    /* Done */ 
    147204    return PJ_SUCCESS; 
     205#endif 
    148206 
    149207#else   /* PJ_SOCK_HAS_GETADDRINFO */ 
  • pjproject/trunk/pjlib/src/pj/sock_bsd.c

    r3492 r3543  
    457457        } else { 
    458458            hostname.slen = strlen(buf); 
    459 #if defined(PJ_GETHOSTNAME_APPEND_LOCAL_SUFFIX) && \ 
    460     PJ_GETHOSTNAME_APPEND_LOCAL_SUFFIX!=0 
    461             { 
    462                 const pj_str_t suffix = {".local", 6}; 
    463  
    464                 if (hostname.slen < suffix.slen || 
    465                     pj_ansi_strnicmp(hostname.ptr + hostname.slen - 
    466                                      suffix.slen, suffix.ptr, suffix.slen)) 
    467                 { 
    468                     if (hostname.slen + suffix.slen + 1 < sizeof(buf)) 
    469                         pj_strcat(&hostname, &suffix); 
    470                     else 
    471                         hostname.slen = 0; 
    472                     hostname.ptr[hostname.slen] = '\0'; 
    473                 } 
    474             } 
    475 #endif 
    476459        } 
    477460    } 
  • pjproject/trunk/pjnath/src/pjturn-client/client_main.c

    r2589 r3543  
    186186 
    187187 
    188 static int shutdown() 
     188static int client_shutdown() 
    189189{ 
    190190    unsigned i; 
     
    626626 
    627627on_return: 
    628     shutdown(); 
     628    client_shutdown(); 
    629629    return status ? 1 : 0; 
    630630} 
Note: See TracChangeset for help on using the changeset viewer.