Changeset 881


Ignore:
Timestamp:
Jan 13, 2007 11:22:40 PM (17 years ago)
Author:
bennylp
Message:

More work on ticket #50: binding of PJSUA-API account to specific transport, and minor fixes in PJSIP core implementation. Tested okay.

Location:
pjproject/trunk/pjsip
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsip/sip_transport.h

    r879 r881  
    918918 * @param tpmgr     The transport manager. 
    919919 * @param pool      Pool to allocate memory for the IP address. 
    920  * @param h         Destination address to contact. 
     920 * @param type      Destination address to contact. 
     921 * @param sel       Optional pointer to prefered transport, if any. 
    921922 * @param ip_addr   Pointer to receive the IP address. 
    922923 * @param port      Pointer to receive the port number. 
     
    927928                                                  pj_pool_t *pool, 
    928929                                                  pjsip_transport_type_e type, 
     930                                                  const pjsip_tpselector *sel, 
    929931                                                  pj_str_t *ip_addr, 
    930932                                                  int *port); 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r875 r881  
    13421342    pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES]; 
    13431343 
     1344    /** 
     1345     * Optionally bind this account to specific transport. This normally is 
     1346     * not a good idea, as account should be able to send requests using 
     1347     * any available transports according to the destination. But some 
     1348     * application may want to have explicit control over the transport to 
     1349     * use, so in that case it can set this field. 
     1350     * 
     1351     * Default: -1 (PJSUA_INVALID_ID) 
     1352     * 
     1353     * @see pjsua_acc_set_transport() 
     1354     */ 
     1355    pjsua_transport_id  transport_id; 
     1356 
    13441357} pjsua_acc_config; 
    13451358 
     
    13551368 
    13561369    cfg->reg_timeout = PJSUA_REG_INTERVAL; 
     1370    cfg->transport_id = PJSUA_INVALID_ID; 
    13571371} 
    13581372 
     
    16551669                                                   pjsip_rx_data *rdata ); 
    16561670                                                            
     1671 
     1672/** 
     1673 * Lock/bind this account to a specific transport/listener. Normally 
     1674 * application shouldn't need to do this, as transports will be selected 
     1675 * automatically by the stack according to the destination. 
     1676 * 
     1677 * When account is locked/bound to a specific transport, all outgoing 
     1678 * requests from this account will use the specified transport (this 
     1679 * includes SIP registration, dialog (call and event subscription), and 
     1680 * out-of-dialog requests such as MESSAGE). 
     1681 * 
     1682 * Note that transport_id may be specified in pjsua_acc_config too. 
     1683 * 
     1684 * @param acc_id        The account ID. 
     1685 * @param tp_id         The transport ID. 
     1686 * 
     1687 * @return              PJ_SUCCESS on success. 
     1688 */ 
     1689PJ_DECL(pj_status_t) pjsua_acc_set_transport(pjsua_acc_id acc_id, 
     1690                                             pjsua_transport_id tp_id); 
    16571691 
    16581692 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h

    r811 r881  
    107107 *Transport. 
    108108 */ 
    109 typedef struct transport_data 
     109typedef struct pjsua_transport_data 
    110110{ 
    111111    int                      index; 
     
    119119    } data; 
    120120 
    121 } transport_data; 
     121} pjsua_transport_data; 
    122122 
    123123 
     
    180180    pjsip_endpoint      *endpt;     /**< Global endpoint.               */ 
    181181    pjsip_module         mod;       /**< pjsua's PJSIP module.          */ 
    182     transport_data      tpdata[8]; /**< Array of transports.           */ 
     182    pjsua_transport_data tpdata[8]; /**< Array of transports.           */ 
    183183 
    184184    /* Threading: */ 
     
    380380 
    381381 
     382/* 
     383 * Internal function to init transport selector from transport id. 
     384 */ 
     385void pjsua_init_tpselector(pjsua_transport_id tp_id, 
     386                           pjsip_tpselector *sel); 
     387 
     388 
     389 
    382390PJ_END_DECL 
    383391 
  • pjproject/trunk/pjsip/src/pjsip/sip_dialog.c

    r879 r881  
    102102        dlg->mutex_ = NULL; 
    103103    } 
     104    if (dlg->tp_sel.type != PJSIP_TPSELECTOR_NONE) { 
     105        pjsip_tpselector_dec_ref(&dlg->tp_sel); 
     106        pj_bzero(&dlg->tp_sel, sizeof(pjsip_tpselector)); 
     107    } 
    104108    pjsip_endpt_release_pool(dlg->endpt, dlg->pool); 
    105109} 
  • pjproject/trunk/pjsip/src/pjsip/sip_errno.c

    r871 r881  
    6868    PJ_BUILD_ERR( PJSIP_ERXOVERFLOW,    "Rx buffer overflow"), 
    6969    PJ_BUILD_ERR( PJSIP_EBUFDESTROYED,  "Buffer destroyed"), 
     70    PJ_BUILD_ERR( PJSIP_ETPNOTSUITABLE, "Unsuitable transport selected"), 
    7071 
    7172    /* Transaction errors */ 
  • pjproject/trunk/pjsip/src/pjsip/sip_transport.c

    r879 r881  
    941941                                                 pj_pool_t *pool, 
    942942                                                 pjsip_transport_type_e type, 
     943                                                 const pjsip_tpselector *sel, 
    943944                                                 pj_str_t *ip_addr, 
    944945                                                 int *port) 
     
    955956    flag = pjsip_transport_get_flag_from_type(type); 
    956957 
    957     if ((flag & PJSIP_TRANSPORT_DATAGRAM) != 0) { 
     958    if (sel && sel->type == PJSIP_TPSELECTOR_TRANSPORT && 
     959        sel->u.transport) 
     960    { 
     961        pj_strdup(pool, ip_addr, &sel->u.transport->local_name.host); 
     962        *port = sel->u.transport->local_name.port; 
     963        status = PJ_SUCCESS; 
     964 
     965    } else if (sel && sel->type == PJSIP_TPSELECTOR_LISTENER && 
     966               sel->u.listener) 
     967    { 
     968        pj_strdup(pool, ip_addr, &sel->u.listener->addr_name.host); 
     969        *port = sel->u.listener->addr_name.port; 
     970        status = PJ_SUCCESS; 
     971 
     972    } else if ((flag & PJSIP_TRANSPORT_DATAGRAM) != 0) { 
    958973         
    959974        pj_sockaddr_in remote; 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c

    r799 r881  
    226226        return status; 
    227227 
    228  
    229228    /* Mark account as valid */ 
    230229    pjsua_var.acc[acc_id].valid = PJ_TRUE; 
     
    259258 
    260259    /* Must have a transport */ 
    261     PJ_TODO(associate_acc_with_transport); 
    262260    PJ_ASSERT_RETURN(pjsua_var.tpdata[0].data.ptr != NULL, PJ_EINVALIDOP); 
    263261 
     
    321319{ 
    322320    pjsua_acc_config cfg; 
    323     struct transport_data *t = &pjsua_var.tpdata[tid]; 
     321    pjsua_transport_data *t = &pjsua_var.tpdata[tid]; 
    324322    char uri[PJSIP_MAX_URL_SIZE]; 
    325323 
     
    383381    } 
    384382 
    385     PJ_TODO(may_need_to_scan_calls); 
     383    /* Leave the calls intact, as I don't think calls need to 
     384     * access account once it's created 
     385     */ 
     386 
    386387 
    387388    PJSUA_UNLOCK(); 
     
    492493    pj_status_t status; 
    493494 
     495    PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL); 
    494496    acc = &pjsua_var.acc[acc_id]; 
    495497 
     
    539541    } 
    540542 
     543    /* If account is locked to specific transport, then set transport to 
     544     * the client registration. 
     545     */ 
     546    if (pjsua_var.acc[acc_id].cfg.transport_id != PJSUA_INVALID_ID) { 
     547        pjsip_tpselector tp_sel; 
     548 
     549        pjsua_init_tpselector(pjsua_var.acc[acc_id].cfg.transport_id, &tp_sel); 
     550        pjsip_regc_set_transport(acc->regc, &tp_sel); 
     551    } 
     552 
     553 
    541554    /* Set credentials 
    542555     */ 
     
    641654 
    642655    PJ_ASSERT_RETURN(info != NULL, PJ_EINVAL); 
     656    PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL); 
    643657     
    644658    pj_bzero(info, sizeof(pjsua_acc_info)); 
     
    855869        pjsua_acc *acc = &pjsua_var.acc[acc_id]; 
    856870 
    857         if (pj_stricmp(&acc->user_part, &sip_uri->user)==0 && 
     871        if (acc->valid && pj_stricmp(&acc->user_part, &sip_uri->user)==0 && 
    858872            pj_stricmp(&acc->srv_domain, &sip_uri->host)==0)  
    859873        { 
     
    869883        pjsua_acc *acc = &pjsua_var.acc[acc_id]; 
    870884 
    871         if (pj_stricmp(&acc->srv_domain, &sip_uri->host)==0) { 
     885        if (acc->valid && pj_stricmp(&acc->srv_domain, &sip_uri->host)==0) { 
    872886            /* Match ! */ 
    873887            PJSUA_UNLOCK(); 
     
    876890    } 
    877891 
    878     /* No matching account, try match user part only. */ 
     892    /* No matching account, try match user part (and transport type) only. */ 
    879893    for (i=0; i < pjsua_var.acc_cnt; ++i) { 
    880894        unsigned acc_id = pjsua_var.acc_ids[i]; 
    881895        pjsua_acc *acc = &pjsua_var.acc[acc_id]; 
    882896 
    883         if (pj_stricmp(&acc->user_part, &sip_uri->user)==0) { 
     897        if (acc->valid && pj_stricmp(&acc->user_part, &sip_uri->user)==0) { 
     898 
     899            if (acc->cfg.transport_id != PJSUA_INVALID_ID) { 
     900                pjsip_transport_type_e type; 
     901                type = pjsip_transport_get_type_from_name(&sip_uri->transport_param); 
     902                if (type == PJSIP_TRANSPORT_UNSPECIFIED) 
     903                    type = PJSIP_TRANSPORT_UDP; 
     904 
     905                if (pjsua_var.tpdata[acc->cfg.transport_id].type != type) 
     906                    continue; 
     907            } 
     908 
    884909            /* Match ! */ 
    885910            PJSUA_UNLOCK(); 
     
    904929    pjsip_transport_type_e tp_type = PJSIP_TRANSPORT_UNSPECIFIED; 
    905930    pj_str_t local_addr; 
     931    pjsip_tpselector tp_sel; 
    906932    unsigned flag; 
    907933    int secure; 
    908934    int local_port; 
    909935     
     936    PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL); 
    910937    acc = &pjsua_var.acc[acc_id]; 
    911938 
     
    946973    secure = (flag & PJSIP_TRANSPORT_SECURE) != 0; 
    947974 
     975    /* Init transport selector. */ 
     976    pjsua_init_tpselector(pjsua_var.acc[acc_id].cfg.transport_id, &tp_sel); 
     977 
    948978    /* Get local address suitable to send request from */ 
    949979    status = pjsip_tpmgr_find_local_addr(pjsip_endpt_get_tpmgr(pjsua_var.endpt), 
    950                                          pool, tp_type, &local_addr, &local_port); 
     980                                         pool, tp_type, &tp_sel,  
     981                                         &local_addr, &local_port); 
    951982    if (status != PJ_SUCCESS) 
    952983        return status; 
     
    9911022    pjsip_transport_type_e tp_type = PJSIP_TRANSPORT_UNSPECIFIED; 
    9921023    pj_str_t local_addr; 
     1024    pjsip_tpselector tp_sel; 
    9931025    unsigned flag; 
    9941026    int secure; 
    9951027    int local_port; 
    9961028     
     1029    PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL); 
    9971030    acc = &pjsua_var.acc[acc_id]; 
    9981031 
     
    10391072    secure = (flag & PJSIP_TRANSPORT_SECURE) != 0; 
    10401073 
     1074    /* Init transport selector. */ 
     1075    pjsua_init_tpselector(pjsua_var.acc[acc_id].cfg.transport_id, &tp_sel); 
     1076 
    10411077    /* Get local address suitable to send request from */ 
    10421078    status = pjsip_tpmgr_find_local_addr(pjsip_endpt_get_tpmgr(pjsua_var.endpt), 
    1043                                          pool, tp_type, &local_addr, &local_port); 
     1079                                         pool, tp_type, &tp_sel, 
     1080                                         &local_addr, &local_port); 
    10441081    if (status != PJ_SUCCESS) 
    10451082        return status; 
     
    10651102 
    10661103 
    1067  
     1104PJ_DEF(pj_status_t) pjsua_acc_set_transport( pjsua_acc_id acc_id, 
     1105                                             pjsua_transport_id tp_id) 
     1106{ 
     1107    pjsua_acc *acc; 
     1108 
     1109    PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL); 
     1110    acc = &pjsua_var.acc[acc_id]; 
     1111 
     1112    PJ_ASSERT_RETURN(tp_id >= 0 && tp_id < PJ_ARRAY_SIZE(pjsua_var.tpdata), 
     1113                     PJ_EINVAL); 
     1114     
     1115    acc->cfg.transport_id = tp_id; 
     1116 
     1117    return PJ_SUCCESS; 
     1118} 
     1119 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r875 r881  
    331331    call->user_data = user_data; 
    332332 
     333    /* If account is locked to specific transport, then lock dialog 
     334     * to this transport too. 
     335     */ 
     336    if (acc->cfg.transport_id != PJSUA_INVALID_ID) { 
     337        pjsip_tpselector tp_sel; 
     338 
     339        pjsua_init_tpselector(acc->cfg.transport_id, &tp_sel); 
     340        pjsip_dlg_set_transport(dlg, &tp_sel); 
     341    } 
     342 
    333343    /* Set dialog Route-Set: */ 
    334344    if (!pj_list_empty(&acc->route_set)) 
     
    620630    inv->mod_data[pjsua_var.mod.id] = call; 
    621631 
     632    /* If account is locked to specific transport, then lock dialog 
     633     * to this transport too. 
     634     */ 
     635    if (pjsua_var.acc[acc_id].cfg.transport_id != PJSUA_INVALID_ID) { 
     636        pjsip_tpselector tp_sel; 
     637 
     638        pjsua_init_tpselector(pjsua_var.acc[acc_id].cfg.transport_id, &tp_sel); 
     639        pjsip_dlg_set_transport(dlg, &tp_sel); 
     640    } 
    622641 
    623642    /* Must answer with some response to initial INVITE. 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r861 r881  
    11901190                                              pjsua_transport_info *info) 
    11911191{ 
    1192     struct transport_data *t = &pjsua_var.tpdata[id]; 
     1192    pjsua_transport_data *t = &pjsua_var.tpdata[id]; 
    11931193    pj_status_t status; 
    11941194 
     
    14171417 
    14181418/* 
     1419 * Internal function to init transport selector from transport id. 
     1420 */ 
     1421void pjsua_init_tpselector(pjsua_transport_id tp_id, 
     1422                           pjsip_tpselector *sel) 
     1423{ 
     1424    pjsua_transport_data *tpdata; 
     1425    unsigned flag; 
     1426 
     1427    pj_bzero(sel, sizeof(*sel)); 
     1428    if (tp_id == PJSUA_INVALID_ID) 
     1429        return; 
     1430 
     1431    pj_assert(tp_id >= 0 && tp_id < PJ_ARRAY_SIZE(pjsua_var.tpdata)); 
     1432    tpdata = &pjsua_var.tpdata[tp_id]; 
     1433 
     1434    flag = pjsip_transport_get_flag_from_type(tpdata->type); 
     1435 
     1436    if (flag & PJSIP_TRANSPORT_DATAGRAM) { 
     1437        sel->type = PJSIP_TPSELECTOR_TRANSPORT; 
     1438        sel->u.transport = tpdata->data.tp; 
     1439    } else { 
     1440        sel->type = PJSIP_TPSELECTOR_LISTENER; 
     1441        sel->u.listener = tpdata->data.factory; 
     1442    } 
     1443} 
     1444 
     1445 
     1446/* 
    14191447 * Verify that valid SIP url is given. 
    14201448 */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_im.c

    r688 r881  
    434434    } 
    435435 
     436    /* If account is locked to specific transport, then set transport to 
     437     * the request. 
     438     */ 
     439    if (pjsua_var.acc[acc_id].cfg.transport_id != PJSUA_INVALID_ID) { 
     440        pjsip_tpselector tp_sel; 
     441 
     442        pjsua_init_tpselector(pjsua_var.acc[acc_id].cfg.transport_id, &tp_sel); 
     443        pjsip_tx_data_set_transport(tdata, &tp_sel); 
     444    } 
     445 
    436446    /* Add accept header. */ 
    437447    pjsip_msg_add_hdr( tdata->msg,  
     
    521531 
    522532 
     533    /* If account is locked to specific transport, then set transport to 
     534     * the request. 
     535     */ 
     536    if (pjsua_var.acc[acc_id].cfg.transport_id != PJSUA_INVALID_ID) { 
     537        pjsip_tpselector tp_sel; 
     538 
     539        pjsua_init_tpselector(pjsua_var.acc[acc_id].cfg.transport_id, &tp_sel); 
     540        pjsip_tx_data_set_transport(tdata, &tp_sel); 
     541    } 
     542 
    523543    /* Add accept header. */ 
    524544    pjsip_msg_add_hdr( tdata->msg,  
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c

    r734 r881  
    502502    } 
    503503 
     504    /* If account is locked to specific transport, then lock dialog 
     505     * to this transport too. 
     506     */ 
     507    if (acc->cfg.transport_id != PJSUA_INVALID_ID) { 
     508        pjsip_tpselector tp_sel; 
     509 
     510        pjsua_init_tpselector(acc->cfg.transport_id, &tp_sel); 
     511        pjsip_dlg_set_transport(dlg, &tp_sel); 
     512    } 
     513 
    504514    /* Attach our data to the subscription: */ 
    505515    uapres = pj_pool_alloc(dlg->pool, sizeof(pjsua_srv_pres)); 
     
    989999    } 
    9901000 
     1001    /* If account is locked to specific transport, then lock dialog 
     1002     * to this transport too. 
     1003     */ 
     1004    if (acc->cfg.transport_id != PJSUA_INVALID_ID) { 
     1005        pjsip_tpselector tp_sel; 
     1006 
     1007        pjsua_init_tpselector(acc->cfg.transport_id, &tp_sel); 
     1008        pjsip_dlg_set_transport(dlg, &tp_sel); 
     1009    } 
     1010 
    9911011    /* Set route-set */ 
    9921012    if (!pj_list_empty(&acc->route_set)) { 
Note: See TracChangeset for help on using the changeset viewer.