Ignore:
Timestamp:
Dec 28, 2016 3:40:07 AM (7 years ago)
Author:
nanang
Message:

Re #1900: More merged from trunk (r5512 mistakenly contains merged changes in third-party dir only).

Location:
pjproject/branches/projects/uwp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/uwp

  • pjproject/branches/projects/uwp/pjsip/src/pjsua-lib/pjsua_acc.c

    r5188 r5513  
    8888    pj_strdup_with_null(pool, &dst->reg_uri, &src->reg_uri); 
    8989    pj_strdup_with_null(pool, &dst->force_contact, &src->force_contact); 
     90    pj_strdup_with_null(pool, &dst->reg_contact_params, 
     91                        &src->reg_contact_params); 
    9092    pj_strdup_with_null(pool, &dst->contact_params, &src->contact_params); 
    9193    pj_strdup_with_null(pool, &dst->contact_uri_params, 
     
    381383    pj_array_insert(pjsua_var.acc_ids, sizeof(pjsua_var.acc_ids[0]), 
    382384                    pjsua_var.acc_cnt, i, &acc_id); 
     385 
     386    if (acc_cfg->transport_id != PJSUA_INVALID_ID) 
     387        acc->tp_type = pjsua_var.tpdata[acc_cfg->transport_id].type; 
    383388 
    384389    return PJ_SUCCESS; 
     
    513518    char transport_param[32]; 
    514519    char uri[PJSIP_MAX_URL_SIZE]; 
     520    pjsua_acc_id acc_id; 
     521    pj_status_t status; 
    515522 
    516523    /* ID must be valid */ 
     
    555562    cfg.id = pj_str(uri); 
    556563     
    557     return pjsua_acc_add(&cfg, is_default, p_acc_id); 
     564    status = pjsua_acc_add(&cfg, is_default, &acc_id); 
     565    if (status == PJ_SUCCESS) { 
     566        pjsua_var.acc[acc_id].tp_type = t->type; 
     567        if (p_acc_id) 
     568            *p_acc_id = acc_id; 
     569    } 
     570 
     571    return status; 
    558572} 
    559573 
     
    981995        update_reg = PJ_TRUE; 
    982996        unreg_first = PJ_TRUE; 
     997    } 
     998 
     999    /* Register contact params */ 
     1000    if (pj_strcmp(&acc->cfg.reg_contact_params, &cfg->reg_contact_params)) { 
     1001        pj_strdup_with_null(acc->pool, &acc->cfg.reg_contact_params, 
     1002                            &cfg->reg_contact_params); 
     1003        update_reg = PJ_TRUE; 
    9831004    } 
    9841005 
     
    14661487 
    14671488done: 
    1468     if (!need_outbound) { 
    1469         /* Outbound is not needed/wanted for the account. acc->reg_contact 
    1470          * is set to the same as acc->contact. 
    1471          */ 
    1472         acc->reg_contact = acc->contact; 
    1473         acc->rfc5626_status = OUTBOUND_NA; 
    1474     } else { 
    1475         /* Need to use outbound, append the contact with +sip.instance and 
    1476          * reg-id parameters. 
    1477          */ 
     1489    { 
    14781490        pj_ssize_t len; 
    14791491        pj_str_t reg_contact; 
    14801492 
    14811493        acc->rfc5626_status = OUTBOUND_WANTED; 
    1482         len = acc->contact.slen + acc->rfc5626_instprm.slen + 
    1483               acc->rfc5626_regprm.slen; 
    1484         reg_contact.ptr = (char*) pj_pool_alloc(acc->pool, len); 
    1485  
    1486         pj_strcpy(&reg_contact, &acc->contact); 
    1487         pj_strcat(&reg_contact, &acc->rfc5626_regprm); 
    1488         pj_strcat(&reg_contact, &acc->rfc5626_instprm); 
    1489  
    1490         acc->reg_contact = reg_contact; 
    1491  
    1492         PJ_LOG(4,(THIS_FILE, 
    1493                   "Contact for acc %d updated for SIP outbound: %.*s", 
    1494                   acc->index, 
    1495                   (int)acc->reg_contact.slen, 
    1496                   acc->reg_contact.ptr)); 
     1494        len = acc->contact.slen + acc->cfg.reg_contact_params.slen + 
     1495              (need_outbound? 
     1496               (acc->rfc5626_instprm.slen + acc->rfc5626_regprm.slen): 0); 
     1497        if (len > acc->contact.slen) { 
     1498            reg_contact.ptr = (char*) pj_pool_alloc(acc->pool, len); 
     1499 
     1500            pj_strcpy(&reg_contact, &acc->contact); 
     1501         
     1502            if (need_outbound) { 
     1503                acc->rfc5626_status = OUTBOUND_WANTED; 
     1504 
     1505                /* Need to use outbound, append the contact with 
     1506                 * +sip.instance and reg-id parameters. 
     1507                 */ 
     1508                pj_strcat(&reg_contact, &acc->rfc5626_regprm); 
     1509                pj_strcat(&reg_contact, &acc->rfc5626_instprm); 
     1510            } else { 
     1511                acc->rfc5626_status = OUTBOUND_NA; 
     1512            } 
     1513 
     1514            pj_strcat(&reg_contact, &acc->cfg.reg_contact_params); 
     1515             
     1516            acc->reg_contact = reg_contact; 
     1517 
     1518            PJ_LOG(4,(THIS_FILE, 
     1519                      "Contact for acc %d updated: %.*s", 
     1520                      acc->index, 
     1521                      (int)acc->reg_contact.slen, 
     1522                      acc->reg_contact.ptr)); 
     1523 
     1524        } else { 
     1525             /* Outbound is not needed/wanted for the account and there's 
     1526              * no custom registration Contact params. acc->reg_contact 
     1527              * is set to the same as acc->contact. 
     1528              */ 
     1529             acc->reg_contact = acc->contact; 
     1530             acc->rfc5626_status = OUTBOUND_NA; 
     1531        } 
    14971532    } 
    14981533} 
     
    15331568    pjsip_via_hdr *via; 
    15341569    pj_sockaddr contact_addr; 
    1535     pj_sockaddr recv_addr; 
     1570    pj_sockaddr recv_addr = {{0}}; 
    15361571    pj_status_t status; 
    15371572    pj_bool_t matched; 
     
    16461681                                   &recv_addr); 
    16471682    if (status == PJ_SUCCESS) { 
    1648         /* Compare the addresses as sockaddr according to the ticket above */ 
    1649         matched = (uri->port == rport && 
     1683        /* Compare the addresses as sockaddr according to the ticket above, 
     1684         * but only if they have the same family (ipv4 vs ipv4, or 
     1685         * ipv6 vs ipv6) 
     1686         */ 
     1687        matched = (contact_addr.addr.sa_family != recv_addr.addr.sa_family) || 
     1688                  (uri->port == rport && 
    16501689                   pj_sockaddr_cmp(&contact_addr, &recv_addr)==0); 
    16511690    } else { 
     
    19411980    /* Send raw packet */ 
    19421981    status = pjsip_tpmgr_send_raw(pjsip_endpt_get_tpmgr(pjsua_var.endpt), 
    1943                                   PJSIP_TRANSPORT_UDP, &tp_sel, 
     1982                                  acc->ka_transport->key.type, &tp_sel, 
    19441983                                  NULL, acc->cfg.ka_data.ptr,  
    19451984                                  acc->cfg.ka_data.slen,  
     
    20082047        if (/*pjsua_var.stun_srv.ipv4.sin_family == 0 ||*/ 
    20092048            acc->cfg.ka_interval == 0 || 
    2010             param->rdata->tp_info.transport->key.type != PJSIP_TRANSPORT_UDP) 
     2049            (param->rdata->tp_info.transport->key.type &   
     2050             ~PJSIP_TRANSPORT_IPV6)!= PJSIP_TRANSPORT_UDP) 
    20112051        { 
    20122052            /* Keep alive is not necessary */ 
     
    22882328        reg_info.cbparam = param; 
    22892329        reg_info.regc = param->regc; 
    2290         reg_info.renew = (rinfo.interval != 0); 
     2330        reg_info.renew = !param->is_unreg; 
    22912331        (*pjsua_var.ua_cfg.cb.on_reg_state2)(acc->index, &reg_info); 
    22922332    } 
     
    24762516} 
    24772517 
     2518pj_bool_t pjsua_sip_acc_is_using_ipv6(pjsua_acc_id acc_id) 
     2519{ 
     2520    pjsua_acc *acc = &pjsua_var.acc[acc_id]; 
     2521 
     2522    return (acc->tp_type & PJSIP_TRANSPORT_IPV6) == PJSIP_TRANSPORT_IPV6; 
     2523} 
     2524 
    24782525pj_bool_t pjsua_sip_acc_is_using_stun(pjsua_acc_id acc_id) 
    24792526{ 
     
    24812528 
    24822529    return acc->cfg.sip_stun_use != PJSUA_STUN_USE_DISABLED && 
    2483             pjsua_var.ua_cfg.stun_srv_cnt != 0; 
     2530           pjsua_var.ua_cfg.stun_srv_cnt != 0; 
     2531} 
     2532 
     2533pj_bool_t pjsua_media_acc_is_using_stun(pjsua_acc_id acc_id) 
     2534{ 
     2535    pjsua_acc *acc = &pjsua_var.acc[acc_id]; 
     2536 
     2537    return acc->cfg.media_stun_use != PJSUA_STUN_USE_DISABLED && 
     2538           pjsua_var.ua_cfg.stun_srv_cnt != 0; 
    24842539} 
    24852540 
     
    29072962 
    29082963        if (acc->valid && pj_stricmp(&acc->user_part, &sip_uri->user)==0) { 
    2909  
    2910             if (acc->cfg.transport_id != PJSUA_INVALID_ID) { 
    2911                 pjsip_transport_type_e type; 
    2912                 type = pjsip_transport_get_type_from_name(&sip_uri->transport_param); 
    2913                 if (type == PJSIP_TRANSPORT_UNSPECIFIED) 
    2914                     type = PJSIP_TRANSPORT_UDP; 
    2915  
    2916                 if (pjsua_var.tpdata[acc->cfg.transport_id].type != type) 
    2917                     continue; 
     2964            if (acc->tp_type != PJSIP_TRANSPORT_UNSPECIFIED && 
     2965                acc->tp_type != rdata->tp_info.transport->key.type) 
     2966            { 
     2967                continue; 
    29182968            } 
    29192969 
     
    30193069    pj_in6_addr dummy6; 
    30203070 
    3021     /* First check with inet_aton() */ 
    3022     if (pj_inet_aton(host, &dummy) > 0) 
     3071    /* First check if this is an IPv4 address */ 
     3072    if (pj_inet_pton(pj_AF_INET(), host, &dummy) == PJ_SUCCESS) 
    30233073        return 4; 
    30243074 
     
    30883138        return PJSIP_EUNSUPTRANSPORT; 
    30893139 
    3090     /* If destination URI specifies IPv6, then set transport type 
    3091      * to use IPv6 as well. 
     3140    /* If destination URI specifies IPv6 or account is configured to use IPv6, 
     3141     * then set transport type to use IPv6 as well. 
    30923142     */ 
    3093     if (pj_strchr(&sip_uri->host, ':')) 
    3094         tp_type = (pjsip_transport_type_e)(((int)tp_type) + PJSIP_TRANSPORT_IPV6); 
     3143    if (pj_strchr(&sip_uri->host, ':') || pjsua_sip_acc_is_using_ipv6(acc_id)) 
     3144        tp_type = (pjsip_transport_type_e)(((int)tp_type) | 
     3145                  PJSIP_TRANSPORT_IPV6); 
    30953146 
    30963147    flag = pjsip_transport_get_flag_from_type(tp_type); 
     
    31533204        if (status == PJ_SUCCESS) { 
    31543205            unsigned cnt=1; 
    3155             int af; 
    3156  
    3157             af = (dinfo.type & PJSIP_TRANSPORT_IPV6)? PJ_AF_INET6 : PJ_AF_INET; 
     3206            int af = pj_AF_UNSPEC(); 
     3207 
     3208            if (pjsua_sip_acc_is_using_ipv6(acc_id) || 
     3209                (dinfo.type & PJSIP_TRANSPORT_IPV6)) 
     3210            { 
     3211                af = pj_AF_INET6(); 
     3212            } 
    31583213            status = pj_getaddrinfo(af, &dinfo.addr.host, &cnt, &ai); 
     3214            if (cnt == 0) { 
     3215                status = PJ_ENOTSUP; 
     3216            } else if ((dinfo.type & PJSIP_TRANSPORT_IPV6)==0 && 
     3217                        ai.ai_addr.addr.sa_family == pj_AF_INET6()) 
     3218            { 
     3219                /* Destination is a hostname and account is not bound to IPv6, 
     3220                 * but hostname resolution reveals that it has IPv6 address, 
     3221                 * so let's use IPv6 transport type. 
     3222                 */ 
     3223                dinfo.type |= PJSIP_TRANSPORT_IPV6; 
     3224                tp_type |= PJSIP_TRANSPORT_IPV6; 
     3225            } 
    31593226        } 
    31603227 
     
    34023469        return PJSIP_EUNSUPTRANSPORT; 
    34033470 
    3404     /* If destination URI specifies IPv6, then set transport type 
    3405      * to use IPv6 as well. 
     3471    /* If destination URI specifies IPv6 or account is configured to use IPv6 
     3472     * or the transport being used to receive data is an IPv6 transport, 
     3473     * then set transport type to use IPv6 as well. 
    34063474     */ 
    3407     if (pj_strchr(&sip_uri->host, ':')) 
    3408         tp_type = (pjsip_transport_type_e)(((int)tp_type) + PJSIP_TRANSPORT_IPV6); 
     3475    if (pj_strchr(&sip_uri->host, ':') || 
     3476        pjsua_sip_acc_is_using_ipv6(acc_id) || 
     3477        (rdata->tp_info.transport->key.type & PJSIP_TRANSPORT_IPV6)) 
     3478    { 
     3479        tp_type = (pjsip_transport_type_e) 
     3480                  (((int)tp_type) | PJSIP_TRANSPORT_IPV6); 
     3481    } 
    34093482 
    34103483    flag = pjsip_transport_get_flag_from_type(tp_type); 
     
    34903563     
    34913564    acc->cfg.transport_id = tp_id; 
     3565    acc->tp_type = pjsua_var.tpdata[tp_id].type; 
    34923566 
    34933567    return PJ_SUCCESS; 
Note: See TracChangeset for help on using the changeset viewer.