Changeset 881 for pjproject/trunk
- Timestamp:
- Jan 13, 2007 11:22:40 PM (18 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsip/sip_transport.h
r879 r881 918 918 * @param tpmgr The transport manager. 919 919 * @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. 921 922 * @param ip_addr Pointer to receive the IP address. 922 923 * @param port Pointer to receive the port number. … … 927 928 pj_pool_t *pool, 928 929 pjsip_transport_type_e type, 930 const pjsip_tpselector *sel, 929 931 pj_str_t *ip_addr, 930 932 int *port); -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r875 r881 1342 1342 pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES]; 1343 1343 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 1344 1357 } pjsua_acc_config; 1345 1358 … … 1355 1368 1356 1369 cfg->reg_timeout = PJSUA_REG_INTERVAL; 1370 cfg->transport_id = PJSUA_INVALID_ID; 1357 1371 } 1358 1372 … … 1655 1669 pjsip_rx_data *rdata ); 1656 1670 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 */ 1689 PJ_DECL(pj_status_t) pjsua_acc_set_transport(pjsua_acc_id acc_id, 1690 pjsua_transport_id tp_id); 1657 1691 1658 1692 -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
r811 r881 107 107 *Transport. 108 108 */ 109 typedef struct transport_data109 typedef struct pjsua_transport_data 110 110 { 111 111 int index; … … 119 119 } data; 120 120 121 } transport_data;121 } pjsua_transport_data; 122 122 123 123 … … 180 180 pjsip_endpoint *endpt; /**< Global endpoint. */ 181 181 pjsip_module mod; /**< pjsua's PJSIP module. */ 182 transport_datatpdata[8]; /**< Array of transports. */182 pjsua_transport_data tpdata[8]; /**< Array of transports. */ 183 183 184 184 /* Threading: */ … … 380 380 381 381 382 /* 383 * Internal function to init transport selector from transport id. 384 */ 385 void pjsua_init_tpselector(pjsua_transport_id tp_id, 386 pjsip_tpselector *sel); 387 388 389 382 390 PJ_END_DECL 383 391 -
pjproject/trunk/pjsip/src/pjsip/sip_dialog.c
r879 r881 102 102 dlg->mutex_ = NULL; 103 103 } 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 } 104 108 pjsip_endpt_release_pool(dlg->endpt, dlg->pool); 105 109 } -
pjproject/trunk/pjsip/src/pjsip/sip_errno.c
r871 r881 68 68 PJ_BUILD_ERR( PJSIP_ERXOVERFLOW, "Rx buffer overflow"), 69 69 PJ_BUILD_ERR( PJSIP_EBUFDESTROYED, "Buffer destroyed"), 70 PJ_BUILD_ERR( PJSIP_ETPNOTSUITABLE, "Unsuitable transport selected"), 70 71 71 72 /* Transaction errors */ -
pjproject/trunk/pjsip/src/pjsip/sip_transport.c
r879 r881 941 941 pj_pool_t *pool, 942 942 pjsip_transport_type_e type, 943 const pjsip_tpselector *sel, 943 944 pj_str_t *ip_addr, 944 945 int *port) … … 955 956 flag = pjsip_transport_get_flag_from_type(type); 956 957 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) { 958 973 959 974 pj_sockaddr_in remote; -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
r799 r881 226 226 return status; 227 227 228 229 228 /* Mark account as valid */ 230 229 pjsua_var.acc[acc_id].valid = PJ_TRUE; … … 259 258 260 259 /* Must have a transport */ 261 PJ_TODO(associate_acc_with_transport);262 260 PJ_ASSERT_RETURN(pjsua_var.tpdata[0].data.ptr != NULL, PJ_EINVALIDOP); 263 261 … … 321 319 { 322 320 pjsua_acc_config cfg; 323 structtransport_data *t = &pjsua_var.tpdata[tid];321 pjsua_transport_data *t = &pjsua_var.tpdata[tid]; 324 322 char uri[PJSIP_MAX_URL_SIZE]; 325 323 … … 383 381 } 384 382 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 386 387 387 388 PJSUA_UNLOCK(); … … 492 493 pj_status_t status; 493 494 495 PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL); 494 496 acc = &pjsua_var.acc[acc_id]; 495 497 … … 539 541 } 540 542 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 541 554 /* Set credentials 542 555 */ … … 641 654 642 655 PJ_ASSERT_RETURN(info != NULL, PJ_EINVAL); 656 PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL); 643 657 644 658 pj_bzero(info, sizeof(pjsua_acc_info)); … … 855 869 pjsua_acc *acc = &pjsua_var.acc[acc_id]; 856 870 857 if ( pj_stricmp(&acc->user_part, &sip_uri->user)==0 &&871 if (acc->valid && pj_stricmp(&acc->user_part, &sip_uri->user)==0 && 858 872 pj_stricmp(&acc->srv_domain, &sip_uri->host)==0) 859 873 { … … 869 883 pjsua_acc *acc = &pjsua_var.acc[acc_id]; 870 884 871 if ( pj_stricmp(&acc->srv_domain, &sip_uri->host)==0) {885 if (acc->valid && pj_stricmp(&acc->srv_domain, &sip_uri->host)==0) { 872 886 /* Match ! */ 873 887 PJSUA_UNLOCK(); … … 876 890 } 877 891 878 /* No matching account, try match user part only. */892 /* No matching account, try match user part (and transport type) only. */ 879 893 for (i=0; i < pjsua_var.acc_cnt; ++i) { 880 894 unsigned acc_id = pjsua_var.acc_ids[i]; 881 895 pjsua_acc *acc = &pjsua_var.acc[acc_id]; 882 896 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 884 909 /* Match ! */ 885 910 PJSUA_UNLOCK(); … … 904 929 pjsip_transport_type_e tp_type = PJSIP_TRANSPORT_UNSPECIFIED; 905 930 pj_str_t local_addr; 931 pjsip_tpselector tp_sel; 906 932 unsigned flag; 907 933 int secure; 908 934 int local_port; 909 935 936 PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL); 910 937 acc = &pjsua_var.acc[acc_id]; 911 938 … … 946 973 secure = (flag & PJSIP_TRANSPORT_SECURE) != 0; 947 974 975 /* Init transport selector. */ 976 pjsua_init_tpselector(pjsua_var.acc[acc_id].cfg.transport_id, &tp_sel); 977 948 978 /* Get local address suitable to send request from */ 949 979 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); 951 982 if (status != PJ_SUCCESS) 952 983 return status; … … 991 1022 pjsip_transport_type_e tp_type = PJSIP_TRANSPORT_UNSPECIFIED; 992 1023 pj_str_t local_addr; 1024 pjsip_tpselector tp_sel; 993 1025 unsigned flag; 994 1026 int secure; 995 1027 int local_port; 996 1028 1029 PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL); 997 1030 acc = &pjsua_var.acc[acc_id]; 998 1031 … … 1039 1072 secure = (flag & PJSIP_TRANSPORT_SECURE) != 0; 1040 1073 1074 /* Init transport selector. */ 1075 pjsua_init_tpselector(pjsua_var.acc[acc_id].cfg.transport_id, &tp_sel); 1076 1041 1077 /* Get local address suitable to send request from */ 1042 1078 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); 1044 1081 if (status != PJ_SUCCESS) 1045 1082 return status; … … 1065 1102 1066 1103 1067 1104 PJ_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 331 331 call->user_data = user_data; 332 332 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 333 343 /* Set dialog Route-Set: */ 334 344 if (!pj_list_empty(&acc->route_set)) … … 620 630 inv->mod_data[pjsua_var.mod.id] = call; 621 631 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 } 622 641 623 642 /* Must answer with some response to initial INVITE. -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r861 r881 1190 1190 pjsua_transport_info *info) 1191 1191 { 1192 structtransport_data *t = &pjsua_var.tpdata[id];1192 pjsua_transport_data *t = &pjsua_var.tpdata[id]; 1193 1193 pj_status_t status; 1194 1194 … … 1417 1417 1418 1418 /* 1419 * Internal function to init transport selector from transport id. 1420 */ 1421 void 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 /* 1419 1447 * Verify that valid SIP url is given. 1420 1448 */ -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_im.c
r688 r881 434 434 } 435 435 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 436 446 /* Add accept header. */ 437 447 pjsip_msg_add_hdr( tdata->msg, … … 521 531 522 532 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 523 543 /* Add accept header. */ 524 544 pjsip_msg_add_hdr( tdata->msg, -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c
r734 r881 502 502 } 503 503 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 504 514 /* Attach our data to the subscription: */ 505 515 uapres = pj_pool_alloc(dlg->pool, sizeof(pjsua_srv_pres)); … … 989 999 } 990 1000 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 991 1011 /* Set route-set */ 992 1012 if (!pj_list_empty(&acc->route_set)) {
Note: See TracChangeset
for help on using the changeset viewer.