Ignore:
Timestamp:
Jul 18, 2006 12:33:02 AM (18 years ago)
Author:
bennylp
Message:

More intelligent PJSUA-LIB in selecting the appropriate address for Contact header

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_transport.c

    r600 r611  
    8282}; 
    8383 
     84/* Key for looking up hash table */ 
     85struct transport_key 
     86{ 
     87    pjsip_transport_type_e  type; 
     88    pj_sockaddr             addr; 
     89}; 
     90 
    8491/***************************************************************************** 
    8592 * 
     
    818825} 
    819826 
     827 
     828 
     829/* 
     830 * Find out the appropriate local address info (IP address and port) to 
     831 * advertise in Contact header based on the remote address to be  
     832 * contacted. The local address info would be the address name of the 
     833 * transport or listener which will be used to send the request. 
     834 * 
     835 * In this implementation, it will only select the transport based on 
     836 * the transport type in the request. 
     837 */ 
     838PJ_DEF(pj_status_t) pjsip_tpmgr_find_local_addr( pjsip_tpmgr *tpmgr, 
     839                                                 pj_pool_t *pool, 
     840                                                 pjsip_transport_type_e type, 
     841                                                 pj_str_t *ip_addr, 
     842                                                 int *port) 
     843{ 
     844    pj_status_t status = PJSIP_EUNSUPTRANSPORT; 
     845    unsigned flag; 
     846 
     847    /* Sanity checks */ 
     848    PJ_ASSERT_RETURN(tpmgr && pool && ip_addr && port, PJ_EINVAL); 
     849 
     850    ip_addr->slen = 0; 
     851    *port = 0; 
     852 
     853    flag = pjsip_transport_get_flag_from_type(type); 
     854 
     855    if ((flag & PJSIP_TRANSPORT_DATAGRAM) != 0) { 
     856         
     857        pj_sockaddr_in remote; 
     858        pjsip_transport *tp; 
     859 
     860        pj_sockaddr_in_init(&remote, NULL, 0); 
     861        status = pjsip_tpmgr_acquire_transport(tpmgr, type, &remote, 
     862                                               sizeof(remote), &tp); 
     863 
     864        if (status == PJ_SUCCESS) { 
     865            pj_strdup(pool, ip_addr, &tp->local_name.host); 
     866            *port = tp->local_name.port; 
     867            status = PJ_SUCCESS; 
     868 
     869            pjsip_transport_dec_ref(tp); 
     870        } 
     871 
     872    } else { 
     873        /* For connection oriented transport, enum the factories */ 
     874        pjsip_tpfactory *f; 
     875 
     876        pj_lock_acquire(tpmgr->lock); 
     877 
     878        f = tpmgr->factory_list.next; 
     879        while (f != &tpmgr->factory_list) { 
     880            if (f->type == type) 
     881                break; 
     882            f = f->next; 
     883        } 
     884 
     885        if (f != &tpmgr->factory_list) { 
     886            pj_strdup(pool, ip_addr, &f->addr_name.host); 
     887            *port = f->addr_name.port; 
     888            status = PJ_SUCCESS; 
     889        } 
     890        pj_lock_release(tpmgr->lock); 
     891    } 
     892 
     893    return PJ_SUCCESS; 
     894} 
     895 
     896 
    820897/* 
    821898 * pjsip_tpmgr_destroy() 
     
    10621139                                                  pjsip_transport **tp) 
    10631140{ 
    1064     struct transport_key 
    1065     { 
    1066         pjsip_transport_type_e  type; 
    1067         pj_sockaddr             addr; 
    1068     } key; 
     1141    struct transport_key key; 
    10691142    int key_len; 
    10701143    pjsip_transport *transport; 
Note: See TracChangeset for help on using the changeset viewer.