Changeset 3366 for pjproject/trunk
- Timestamp:
- Nov 16, 2010 3:07:46 AM (14 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r3339 r3366 2334 2334 2335 2335 /** 2336 * Control the use of SIP outbound feature. SIP outbound is described in 2337 * RFC 5626 to enable proxies or registrar to send inbound requests back 2338 * to UA using the same connection initiated by the UA for its 2339 * registration. This feature is highly useful in NAT-ed deployemtns, 2340 * hence it is enabled by default. 2341 * 2342 * Note: currently SIP outbound can only be used with TCP and TLS 2343 * transports. If UDP is used for the registration, the SIP outbound 2344 * feature will be silently ignored for the account. 2345 * 2346 * Default: PJ_TRUE 2347 */ 2348 unsigned use_rfc5626; 2349 2350 /** 2351 * Specify SIP outbound (RFC 5626) instance ID to be used by this 2352 * application. If empty, an instance ID will be generated based on 2353 * the hostname of this agent. If application specifies this parameter, the 2354 * value will look like "<urn:uuid:00000000-0000-1000-8000-AABBCCDDEEFF>" 2355 * without the doublequote. 2356 * 2357 * Default: empty 2358 */ 2359 pj_str_t rfc5626_instance_id; 2360 2361 /** 2362 * Specify SIP outbound (RFC 5626) registration ID. The default value 2363 * is empty, which would cause the library to automatically generate 2364 * a suitable value. 2365 * 2366 * Default: empty 2367 */ 2368 pj_str_t rfc5626_reg_id; 2369 2370 /** 2336 2371 * Set the interval for periodic keep-alive transmission for this account. 2337 2372 * If this value is zero, keep-alive will be disabled for this account. -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
r3349 r3366 115 115 }; 116 116 117 118 117 /** 119 118 * Account … … 129 128 pj_str_t user_part; /**< User part of local URI. */ 130 129 pj_str_t contact; /**< Our Contact header. */ 130 pj_str_t reg_contact; /**< Contact header for REGISTER. 131 It may be different than acc 132 contact if outbound is used */ 131 133 132 134 pj_str_t srv_domain; /**< Host part of reg server. */ … … 152 154 pj_uint32_t global_route_crc; /** CRC of global route setting. */ 153 155 pj_uint32_t local_route_crc; /** CRC of account route setting.*/ 156 157 unsigned rfc5626_status;/**< SIP outbound status: 158 0: not used 159 1: requested 160 2: acknowledged by servers */ 161 pj_str_t rfc5626_instprm;/**< SIP outbound instance param. */ 162 pj_str_t rfc5626_regprm;/**< SIP outbound reg param. */ 154 163 155 164 unsigned cred_cnt; /**< Number of credentials. */ -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
r3326 r3366 24 24 #define THIS_FILE "pjsua_acc.c" 25 25 26 enum 27 { 28 OUTBOUND_NONE, 29 OUTBOUND_WANTED, 30 OUTBOUND_ACTIVE 31 }; 32 26 33 27 34 static void schedule_reregistration(pjsua_acc *acc); … … 80 87 pj_strdup_with_null(pool, &dst->force_contact, &src->force_contact); 81 88 pj_strdup_with_null(pool, &dst->pidf_tuple_id, &src->pidf_tuple_id); 89 pj_strdup_with_null(pool, &dst->rfc5626_instance_id, &src->rfc5626_instance_id); 90 pj_strdup_with_null(pool, &dst->rfc5626_reg_id, &src->rfc5626_reg_id); 82 91 83 92 dst->proxy_cnt = src->proxy_cnt; … … 269 278 if (status != PJ_SUCCESS) 270 279 return status; 280 281 /* If SIP outbound is enabled, generate instance and reg ID if they are 282 * not specified 283 */ 284 if (acc_cfg->use_rfc5626) { 285 if (acc_cfg->rfc5626_instance_id.slen==0) { 286 const pj_str_t *hostname; 287 pj_uint32_t hval, pos; 288 char instprm[] = ";+sip.instance=\"<urn:uuid:00000000-0000-0000-0000-0000CCDDEEFF>\""; 289 290 hostname = pj_gethostname(); 291 pos = pj_ansi_strlen(instprm) - 10; 292 hval = pj_hash_calc(0, hostname->ptr, hostname->slen); 293 pj_val_to_hex_digit( ((char*)&hval)[0], instprm+pos+0); 294 pj_val_to_hex_digit( ((char*)&hval)[1], instprm+pos+2); 295 pj_val_to_hex_digit( ((char*)&hval)[2], instprm+pos+4); 296 pj_val_to_hex_digit( ((char*)&hval)[3], instprm+pos+6); 297 298 pj_strdup2(acc->pool, &acc->rfc5626_instprm, instprm); 299 } else { 300 const char *prmname = ";+sip.instance=\""; 301 unsigned len; 302 303 len = pj_ansi_strlen(prmname) + acc_cfg->rfc5626_instance_id.slen + 1; 304 acc->rfc5626_instprm.ptr = (char*)pj_pool_alloc(acc->pool, len+1); 305 pj_ansi_snprintf(acc->rfc5626_instprm.ptr, len+1, 306 "%s%.*s\"", 307 prmname, 308 (int)acc_cfg->rfc5626_instance_id.slen, 309 acc_cfg->rfc5626_instance_id.ptr); 310 acc->rfc5626_instprm.slen = len; 311 } 312 313 if (acc_cfg->rfc5626_reg_id.slen==0) { 314 acc->rfc5626_regprm = pj_str(";reg-id=1"); 315 } else { 316 const char *prmname = ";reg-id="; 317 unsigned len; 318 319 len = pj_ansi_strlen(prmname) + acc_cfg->rfc5626_reg_id.slen; 320 acc->rfc5626_regprm.ptr = (char*)pj_pool_alloc(acc->pool, len+1); 321 pj_ansi_snprintf(acc->rfc5626_regprm.ptr, len+1, 322 "%s%.*s\"", 323 prmname, 324 (int)acc_cfg->rfc5626_reg_id.slen, 325 acc_cfg->rfc5626_reg_id.ptr); 326 acc->rfc5626_regprm.slen = len; 327 } 328 } 271 329 272 330 /* Mark account as valid */ … … 900 958 } 901 959 960 /* SIP outbound setting */ 961 if (acc->cfg.use_rfc5626 != cfg->use_rfc5626 || 962 pj_strcmp(&acc->cfg.rfc5626_instance_id, &cfg->rfc5626_instance_id) || 963 pj_strcmp(&acc->cfg.rfc5626_reg_id, &cfg->rfc5626_reg_id)) 964 { 965 update_reg = PJ_TRUE; 966 } 967 902 968 /* Update registration */ 903 969 if (update_reg) { … … 954 1020 pjsua_pres_update_acc(acc_id, PJ_TRUE); 955 1021 return PJ_SUCCESS; 1022 } 1023 1024 /* Create reg_contact, mainly for SIP outbound */ 1025 static void update_regc_contact(pjsua_acc *acc) 1026 { 1027 pjsua_acc_config *acc_cfg = &acc->cfg; 1028 pj_bool_t need_outbound = PJ_FALSE; 1029 const pj_str_t tcp_param = pj_str(";transport=tcp"); 1030 const pj_str_t tls_param = pj_str(";transport=tls"); 1031 1032 if (!acc_cfg->use_rfc5626) 1033 goto done; 1034 1035 if (pj_stristr(&acc->contact, &tcp_param)==NULL && 1036 pj_stristr(&acc->contact, &tls_param)==NULL) 1037 { 1038 /* Currently we can only do SIP outbound for TCP 1039 * and TLS. 1040 */ 1041 goto done; 1042 } 1043 1044 /* looks like we can use outbound */ 1045 need_outbound = PJ_TRUE; 1046 1047 done: 1048 if (!need_outbound) { 1049 /* Outbound is not needed/wanted for the account. acc->reg_contact 1050 * is set to the same as acc->contact. 1051 */ 1052 acc->reg_contact = acc->contact; 1053 acc->rfc5626_status = OUTBOUND_NONE; 1054 } else { 1055 /* Need to use outbound, append the contact with +sip.instance and 1056 * reg-id parameters. 1057 */ 1058 unsigned len; 1059 pj_str_t reg_contact; 1060 1061 acc->rfc5626_status = OUTBOUND_WANTED; 1062 len = acc->contact.slen + acc->rfc5626_instprm.slen + 1063 acc->rfc5626_regprm.slen; 1064 reg_contact.ptr = (char*) pj_pool_alloc(acc->pool, reg_contact.slen); 1065 1066 pj_strcpy(®_contact, &acc->contact); 1067 pj_strcat(®_contact, &acc->rfc5626_regprm); 1068 pj_strcat(®_contact, &acc->rfc5626_instprm); 1069 1070 acc->reg_contact = reg_contact; 1071 1072 PJ_LOG(4,(THIS_FILE, 1073 "Contact for acc %d updated for SIP outbound: %.*s", 1074 acc->index, 1075 (int)acc->reg_contact.slen, 1076 acc->reg_contact.ptr)); 1077 } 956 1078 } 957 1079 … … 999 1121 if (acc->cfg.allow_contact_rewrite == PJ_FALSE) 1000 1122 return PJ_FALSE; 1123 1124 /* If SIP outbound is active, no need to update */ 1125 if (acc->rfc5626_status == OUTBOUND_ACTIVE) { 1126 PJ_LOG(4,(THIS_FILE, "Acc %d has SIP outbound active, no need to " 1127 "update registration Contact", acc->index)); 1128 return PJ_FALSE; 1129 } 1001 1130 1002 1131 #if 0 … … 1143 1272 */ 1144 1273 { 1274 const char *ob = ";ob"; 1145 1275 char *tmp; 1146 1276 const char *beginquote, *endquote; … … 1157 1287 tmp = (char*) pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE); 1158 1288 len = pj_ansi_snprintf(tmp, PJSIP_MAX_URL_SIZE, 1159 "<sip:%.*s%s%s%.*s%s:%d;transport=%s%.*s >%.*s",1289 "<sip:%.*s%s%s%.*s%s:%d;transport=%s%.*s%s>%.*s", 1160 1290 (int)acc->user_part.slen, 1161 1291 acc->user_part.ptr, … … 1169 1299 (int)acc->cfg.contact_uri_params.slen, 1170 1300 acc->cfg.contact_uri_params.ptr, 1301 ob, 1171 1302 (int)acc->cfg.contact_params.slen, 1172 1303 acc->cfg.contact_params.ptr); … … 1178 1309 pj_strdup2_with_null(acc->pool, &acc->contact, tmp); 1179 1310 1311 update_regc_contact(acc); 1312 1180 1313 /* Always update, by http://trac.pjsip.org/repos/ticket/864. */ 1181 1314 pj_strdup_with_null(tp->pool, &tp->local_name.host, via_addr); … … 1185 1318 1186 1319 if (acc->cfg.contact_rewrite_method == 2 && acc->regc != NULL) { 1187 pjsip_regc_update_contact(acc->regc, 1, &acc-> contact);1320 pjsip_regc_update_contact(acc->regc, 1, &acc->reg_contact); 1188 1321 } 1189 1322 … … 1419 1552 1420 1553 1554 /* Update the status of SIP outbound registration request */ 1555 static void update_rfc5626_status(pjsua_acc *acc, pjsip_rx_data *rdata) 1556 { 1557 pjsip_require_hdr *hreq; 1558 const pj_str_t STR_OUTBOUND = {"outbound", 8}; 1559 unsigned i; 1560 1561 if (acc->rfc5626_status == OUTBOUND_NONE) { 1562 goto on_return; 1563 } 1564 1565 hreq = rdata->msg_info.require; 1566 if (!hreq) { 1567 acc->rfc5626_status = OUTBOUND_NONE; 1568 goto on_return; 1569 } 1570 1571 for (i=0; i<hreq->count; ++i) { 1572 if (pj_stricmp(&hreq->values[i], &STR_OUTBOUND)==0) { 1573 acc->rfc5626_status = OUTBOUND_ACTIVE; 1574 goto on_return; 1575 } 1576 } 1577 1578 /* Server does not support outbound */ 1579 acc->rfc5626_status = OUTBOUND_NONE; 1580 1581 on_return: 1582 PJ_LOG(4,(THIS_FILE, "SIP outbound status for acc %d is %s", 1583 acc->index, (acc->rfc5626_status==OUTBOUND_ACTIVE? 1584 "active": "not active"))); 1585 } 1586 1421 1587 /* 1422 1588 * This callback is called by pjsip_regc when outgoing register … … 1474 1640 pjsua_var.acc[acc->index].cfg.id.ptr)); 1475 1641 } else { 1642 /* Check and update SIP outbound status first, since the result 1643 * will determine if we should update re-registration 1644 */ 1645 update_rfc5626_status(acc, param->rdata); 1646 1476 1647 /* Check NAT bound address */ 1477 1648 if (acc_check_nat_addr(acc, param)) { 1478 /* Update address, don't notify application yet */1479 1649 PJSUA_UNLOCK(); 1480 1650 return; … … 1596 1766 1597 1767 pj_strdup_with_null(acc->pool, &acc->contact, &tmp_contact); 1768 update_regc_contact(acc); 1598 1769 } 1599 1770 … … 1602 1773 &acc->cfg.id, 1603 1774 &acc->cfg.id, 1604 1, &acc-> contact,1775 1, &acc->reg_contact, 1605 1776 acc->cfg.reg_timeout); 1606 1777 if (status != PJ_SUCCESS) { … … 1683 1854 &pjsua_var.ua_cfg.user_agent); 1684 1855 pj_list_push_back(&hdr_list, (pjsip_hdr*)h); 1856 1857 pjsip_regc_add_headers(acc->regc, &hdr_list); 1858 } 1859 1860 /* If SIP outbound is used, add "Supported: outbound, path header" */ 1861 if (acc->rfc5626_status == OUTBOUND_WANTED) { 1862 pjsip_hdr hdr_list; 1863 pjsip_supported_hdr *hsup; 1864 1865 pj_list_init(&hdr_list); 1866 hsup = pjsip_supported_hdr_create(pool); 1867 pj_list_push_back(&hdr_list, hsup); 1868 1869 hsup->count = 2; 1870 hsup->values[0] = pj_str("outbound"); 1871 hsup->values[1] = pj_str("path"); 1685 1872 1686 1873 pjsip_regc_add_headers(acc->regc, &hdr_list); … … 2147 2334 const char *beginquote, *endquote; 2148 2335 char transport_param[32]; 2336 const char *ob = ";ob"; 2149 2337 2150 2338 … … 2232 2420 contact->ptr = (char*)pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE); 2233 2421 contact->slen = pj_ansi_snprintf(contact->ptr, PJSIP_MAX_URL_SIZE, 2234 "%.*s%s<%s:%.*s%s%s%.*s%s:%d%s%.*s >%.*s",2422 "%.*s%s<%s:%.*s%s%s%.*s%s:%d%s%.*s%s>%.*s", 2235 2423 (int)acc->display.slen, 2236 2424 acc->display.ptr, … … 2248 2436 (int)acc->cfg.contact_uri_params.slen, 2249 2437 acc->cfg.contact_uri_params.ptr, 2438 ob, 2250 2439 (int)acc->cfg.contact_params.slen, 2251 2440 acc->cfg.contact_params.ptr); -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r3330 r3366 184 184 cfg->reg_retry_interval = PJSUA_REG_RETRY_INTERVAL; 185 185 cfg->contact_rewrite_method = PJSUA_CONTACT_REWRITE_METHOD; 186 cfg->use_rfc5626 = PJ_TRUE; 186 187 cfg->reg_use_proxy = PJSUA_REG_USE_OUTBOUND_PROXY | 187 188 PJSUA_REG_USE_ACC_PROXY;
Note: See TracChangeset
for help on using the changeset viewer.