Changeset 1561
- Timestamp:
- Nov 8, 2007 9:24:30 AM (17 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r1543 r1561 118 118 puts (""); 119 119 puts ("SIP Account options:"); 120 puts (" --use-ims Enable 3GPP/IMS related settings on this account"); 120 121 puts (" --registrar=url Set the URL of registrar server"); 121 122 puts (" --id=url Set the URL of local ID (used in From header)"); … … 129 130 puts (" --publish Send presence PUBLISH for this account"); 130 131 puts (" --use-100rel Require reliable provisional response (100rel)"); 131 puts (" --service-route Enable Service-Route processing");132 132 puts (" --next-cred Add another credentials"); 133 133 puts (""); … … 373 373 OPT_LOCAL_PORT, OPT_IP_ADDR, OPT_PROXY, OPT_OUTBOUND_PROXY, 374 374 OPT_REGISTRAR, OPT_REG_TIMEOUT, OPT_PUBLISH, OPT_ID, OPT_CONTACT, 375 OPT_100REL, OPT_ SERVICE_ROUTE, OPT_REALM, OPT_USERNAME, OPT_PASSWORD,375 OPT_100REL, OPT_USE_IMS, OPT_REALM, OPT_USERNAME, OPT_PASSWORD, 376 376 OPT_NAMESERVER, OPT_STUN_DOMAIN, OPT_STUN_SRV, 377 377 OPT_ADD_BUDDY, OPT_OFFER_X_MS_MSG, OPT_NO_PRESENCE, … … 410 410 { "publish", 0, 0, OPT_PUBLISH}, 411 411 { "use-100rel", 0, 0, OPT_100REL}, 412 { " service-route", 0, 0, OPT_SERVICE_ROUTE},412 { "use-ims", 0, 0, OPT_USE_IMS}, 413 413 { "id", 1, 0, OPT_ID}, 414 414 { "contact", 1, 0, OPT_CONTACT}, … … 637 637 break; 638 638 639 case OPT_ SERVICE_ROUTE: /* Service-Route processing*/640 cur_acc-> enable_service_route= PJ_TRUE;639 case OPT_USE_IMS: /* Activate IMS settings */ 640 cur_acc->auth_pref.initial_auth = PJ_TRUE; 641 641 break; 642 642 … … 668 668 case OPT_USERNAME: /* Default authentication user */ 669 669 cur_acc->cred_info[cur_acc->cred_count].username = pj_str(pj_optarg); 670 cur_acc->cred_info[cur_acc->cred_count].scheme = pj_str(" digest");670 cur_acc->cred_info[cur_acc->cred_count].scheme = pj_str("Digest"); 671 671 break; 672 672 … … 993 993 994 994 for (i=0; i<cfg->acc_cnt; ++i) { 995 if (cfg->acc_cfg[i].cred_info[cfg->acc_cfg[i].cred_count].username.slen) 995 pjsua_acc_config *acfg = &cfg->acc_cfg[i]; 996 997 if (acfg->cred_info[acfg->cred_count].username.slen) 996 998 { 997 cfg->acc_cfg[i].cred_count++; 999 acfg->cred_count++; 1000 } 1001 1002 /* When IMS mode is enabled for the account, verify that settings 1003 * are okay. 1004 */ 1005 /* For now we check if IMS mode is activated by looking if 1006 * initial_auth is set. 1007 */ 1008 if (acfg->auth_pref.initial_auth && acfg->cred_count) { 1009 /* Realm must point to the real domain */ 1010 if (*acfg->cred_info[0].realm.ptr=='*') { 1011 PJ_LOG(1,(THIS_FILE, 1012 "Error: cannot use '*' as realm with IMS")); 1013 return PJ_EINVAL; 1014 } 1015 1016 /* Username for authentication must be in a@b format */ 1017 if (strchr(acfg->cred_info[0].username.ptr, '@')==0) { 1018 PJ_LOG(1,(THIS_FILE, 1019 "Error: Username for authentication must " 1020 "be in user@domain format with IMS")); 1021 return PJ_EINVAL; 1022 } 998 1023 } 999 1024 } … … 2686 2711 acc_cfg.reg_uri = pj_str(registrar); 2687 2712 acc_cfg.cred_count = 1; 2688 acc_cfg.cred_info[0].scheme = pj_str(" digest");2713 acc_cfg.cred_info[0].scheme = pj_str("Digest"); 2689 2714 acc_cfg.cred_info[0].realm = pj_str(realm); 2690 2715 acc_cfg.cred_info[0].username = pj_str(uname); -
pjproject/trunk/pjsip/include/pjsip-ua/sip_regc.h
r974 r1561 190 190 191 191 /** 192 * Set authentication preference. 193 * 194 * @param regc The registration structure. 195 * @param pref Authentication preference. 196 * 197 * @return PJ_SUCCESS on success. 198 */ 199 PJ_DECL(pj_status_t) pjsip_regc_set_prefs( pjsip_regc *regc, 200 const pjsip_auth_clt_pref *pref); 201 202 /** 192 203 * Set route set to be used for outgoing requests. 193 204 * -
pjproject/trunk/pjsip/include/pjsip/sip_auth.h
r1500 r1561 184 184 185 185 /** 186 * This structure describes client authentication session preference. 187 * The preference can be set by calling #pjsip_auth_clt_set_prefs(). 188 */ 189 typedef struct pjsip_auth_clt_pref 190 { 191 /** 192 * If this flag is set, the authentication client framework will 193 * send an empty Authorization header in each initial request. 194 * Default is no. 195 */ 196 pj_bool_t initial_auth; 197 198 /** 199 * Specify the algorithm to use when empty Authorization header 200 * is to be sent for each initial request (see above) 201 */ 202 pj_str_t algorithm; 203 204 } pjsip_auth_clt_pref; 205 206 207 /** 186 208 * This structure describes client authentication sessions. It keeps 187 209 * all the information needed to authorize the client against all downstream … … 192 214 pj_pool_t *pool; /**< Pool to use. */ 193 215 pjsip_endpoint *endpt; /**< Endpoint where this belongs. */ 216 pjsip_auth_clt_pref pref; /**< Preference/options. */ 194 217 unsigned cred_cnt; /**< Number of credentials. */ 195 218 pjsip_cred_info *cred_info; /**< Array of credential information*/ … … 288 311 const pjsip_cred_info *c); 289 312 313 314 /** 315 * Set the preference for the client authentication session. 316 * 317 * @param sess The client authentication session. 318 * @param p Preference. 319 * 320 * @return PJ_SUCCESS on success. 321 */ 322 PJ_DECL(pj_status_t) pjsip_auth_clt_set_prefs(pjsip_auth_clt_sess *sess, 323 const pjsip_auth_clt_pref *p); 324 325 326 /** 327 * Get the preference for the client authentication session. 328 * 329 * @param sess The client authentication session. 330 * @param p Pointer to receive the preference. 331 * 332 * @return PJ_SUCCESS on success. 333 */ 334 PJ_DECL(pj_status_t) pjsip_auth_clt_get_prefs(pjsip_auth_clt_sess *sess, 335 pjsip_auth_clt_pref *p); 290 336 291 337 /** -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r1541 r1561 1841 1841 * If this flag is set, the presence information of this account will 1842 1842 * be PUBLISH-ed to the server where the account belongs. 1843 * 1844 * Default: PJ_FALSE 1843 1845 */ 1844 1846 pj_bool_t publish_enabled; 1847 1848 /** 1849 * Authentication preference. 1850 */ 1851 pjsip_auth_clt_pref auth_pref; 1845 1852 1846 1853 /** … … 1890 1897 */ 1891 1898 pj_str_t proxy[PJSUA_ACC_MAX_PROXIES]; 1892 1893 /**1894 * Enable Service-Route processing for this account.1895 */1896 pj_bool_t enable_service_route;1897 1899 1898 1900 /** -
pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
r1554 r1561 1564 1564 /* Include SDP when it's available for 2xx and 18x (but not 180) response. 1565 1565 * Subsequent response will include this SDP. 1566 * 1567 * Note note: 1568 * - When offer/answer has been completed in reliable 183, we MUST NOT 1569 * send SDP in 2xx response. So if we don't have SDP to send, clear 1570 * the SDP in the message body ONLY if 100rel is active in this 1571 * session. 1566 1572 */ 1567 1573 if (sdp) { 1568 1574 tdata->msg->body = create_sdp_body(tdata->pool, sdp); 1575 } else { 1576 if (inv->options & PJSIP_INV_REQUIRE_100REL) { 1577 tdata->msg->body = NULL; 1578 } 1569 1579 } 1570 1580 … … 2227 2237 pj_status_t status = -1; 2228 2238 2239 /* Handle 401/407 challenge. */ 2240 if (tsx->state == PJSIP_TSX_STATE_COMPLETED && 2241 (tsx->status_code == 401 || tsx->status_code == 407)) { 2242 2243 pjsip_tx_data *tdata; 2244 2245 status = pjsip_auth_clt_reinit_req( &inv->dlg->auth_sess, 2246 e->body.tsx_state.src.rdata, 2247 tsx->last_tx, 2248 &tdata); 2249 2250 if (status != PJ_SUCCESS) { 2251 2252 /* Does not have proper credentials. 2253 * End the session anyway. 2254 */ 2255 inv_set_cause(inv, PJSIP_SC_OK, NULL); 2256 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 2257 2258 } else { 2259 /* Re-send BYE. */ 2260 status = pjsip_inv_send_msg(inv, tdata); 2261 } 2262 2229 2263 /* Process 2xx response */ 2230 if (tsx->state == PJSIP_TSX_STATE_COMPLETED &&2264 } else if (tsx->state == PJSIP_TSX_STATE_COMPLETED && 2231 2265 tsx->status_code/100 == 2 && 2232 2266 e->body.tsx_state.src.rdata->msg_info.msg->body) -
pjproject/trunk/pjsip/src/pjsip-ua/sip_reg.c
r1547 r1561 308 308 } 309 309 310 PJ_DEF(pj_status_t) pjsip_regc_set_prefs( pjsip_regc *regc, 311 const pjsip_auth_clt_pref *pref) 312 { 313 PJ_ASSERT_RETURN(regc && pref, PJ_EINVAL); 314 return pjsip_auth_clt_set_prefs(®c->auth_sess, pref); 315 } 316 310 317 PJ_DEF(pj_status_t) pjsip_regc_set_route_set( pjsip_regc *regc, 311 318 const pjsip_route_hdr *route_set) -
pjproject/trunk/pjsip/src/pjsip/sip_auth_client.c
r1539 r1561 533 533 534 534 535 /* 536 * Set the preference for the client authentication session. 537 */ 538 PJ_DEF(pj_status_t) pjsip_auth_clt_set_prefs(pjsip_auth_clt_sess *sess, 539 const pjsip_auth_clt_pref *p) 540 { 541 PJ_ASSERT_RETURN(sess && p, PJ_EINVAL); 542 543 pj_memcpy(&sess->pref, p, sizeof(*p)); 544 pj_strdup(sess->pool, &sess->pref.algorithm, &p->algorithm); 545 //if (sess->pref.algorithm.slen == 0) 546 // sess->pref.algorithm = pj_str("md5"); 547 548 return PJ_SUCCESS; 549 } 550 551 552 /* 553 * Get the preference for the client authentication session. 554 */ 555 PJ_DEF(pj_status_t) pjsip_auth_clt_get_prefs(pjsip_auth_clt_sess *sess, 556 pjsip_auth_clt_pref *p) 557 { 558 PJ_ASSERT_RETURN(sess && p, PJ_EINVAL); 559 560 pj_memcpy(p, &sess->pref, sizeof(pjsip_auth_clt_pref)); 561 return PJ_SUCCESS; 562 } 563 564 535 565 /* 536 566 * Create Authorization/Proxy-Authorization response header based on the challege … … 699 729 700 730 731 /* Find credential in list of (Proxy-)Authorization headers */ 732 static pjsip_authorization_hdr* get_header_for_realm(const pjsip_hdr *hdr_list, 733 const pj_str_t *realm) 734 { 735 pjsip_authorization_hdr *h; 736 737 h = (pjsip_authorization_hdr*)hdr_list->next; 738 while (h != (pjsip_authorization_hdr*)hdr_list) { 739 if (pj_stricmp(&h->credential.digest.realm, realm)==0) 740 return h; 741 h = h->next; 742 } 743 744 return NULL; 745 } 746 701 747 702 748 /* Initialize outgoing request. */ … … 706 752 const pjsip_method *method; 707 753 pjsip_cached_auth *auth; 754 pjsip_hdr added; 708 755 709 756 PJ_ASSERT_RETURN(sess && tdata, PJ_EINVAL); … … 711 758 PJ_ASSERT_RETURN(tdata->msg->type==PJSIP_REQUEST_MSG, 712 759 PJSIP_ENOTREQUESTMSG); 760 761 /* Init list */ 762 pj_list_init(&added); 713 763 714 764 /* Get the method. */ … … 729 779 pjsip_authorization_hdr *hauth; 730 780 hauth = pjsip_hdr_shallow_clone(tdata->pool, entry->hdr); 731 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth); 781 //pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth); 782 pj_list_push_back(&added, hauth); 732 783 break; 733 784 } … … 777 828 return status; 778 829 779 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth); 830 //pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth); 831 pj_list_push_back(&added, hauth); 780 832 } 781 833 # endif /* PJSIP_AUTH_QOP_SUPPORT && PJSIP_AUTH_AUTO_SEND_NEXT */ 782 834 783 835 auth = auth->next; 836 } 837 838 if (sess->pref.initial_auth == PJ_FALSE) { 839 pjsip_hdr *h; 840 841 /* Don't want to send initial empty Authorization header, so 842 * just send whatever available in the list (maybe empty). 843 */ 844 845 h = added.next; 846 while (h != &added) { 847 pjsip_hdr *next = h->next; 848 pjsip_msg_add_hdr(tdata->msg, h); 849 h = next; 850 } 851 } else { 852 /* For each realm, add either the cached authorization header 853 * or add an empty authorization header. 854 */ 855 unsigned i; 856 char *uri_str; 857 int len; 858 859 uri_str = pj_pool_alloc(tdata->pool, PJSIP_MAX_URL_SIZE); 860 len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, tdata->msg->line.req.uri, 861 uri_str, PJSIP_MAX_URL_SIZE); 862 if (len < 1 || len >= PJSIP_MAX_URL_SIZE) 863 return PJSIP_EURITOOLONG; 864 865 for (i=0; i<sess->cred_cnt; ++i) { 866 pjsip_cred_info *c = &sess->cred_info[i]; 867 pjsip_authorization_hdr *h; 868 869 h = get_header_for_realm(&added, &c->realm); 870 if (h) { 871 pj_list_erase(h); 872 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)h); 873 } else { 874 enum { HDRLEN = 256 }; 875 const pj_str_t hname = pj_str("Authorization"); 876 pj_str_t hval; 877 pjsip_generic_string_hdr *hs; 878 char *hdr; 879 880 hdr = pj_pool_alloc(tdata->pool, HDRLEN); 881 len = pj_ansi_snprintf( 882 hdr, HDRLEN, 883 "%.*s username=\"%.*s\", realm=\"%.*s\"," 884 " nonce=\"\", uri=\"%s\",%s%.*s%s response=\"\"", 885 (int)c->scheme.slen, c->scheme.ptr, 886 (int)c->username.slen, c->username.ptr, 887 (int)c->realm.slen, c->realm.ptr, 888 uri_str, 889 (sess->pref.algorithm.slen ? " algorithm=" : ""), 890 (int)sess->pref.algorithm.slen, sess->pref.algorithm.ptr, 891 (sess->pref.algorithm.slen ? "," : "")); 892 893 PJ_ASSERT_RETURN(len>0 && len<HDRLEN, PJ_ETOOBIG); 894 895 hval.ptr = hdr; 896 hval.slen = len; 897 hs = pjsip_generic_string_hdr_create(tdata->pool, &hname, 898 &hval); 899 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hs); 900 } 901 } 784 902 } 785 903 -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
r1542 r1561 545 545 unsigned i, uri_cnt = 0, rcnt; 546 546 547 /* Skip processing is enable_service_route is not set */548 if (!acc->cfg.enable_service_route)549 return;550 551 547 /* Find and parse Service-Route headers */ 552 548 for (;;) { … … 916 912 pjsip_regc_set_credentials( acc->regc, acc->cred_cnt, acc->cred); 917 913 } 914 915 /* Set authentication preference */ 916 pjsip_regc_set_prefs(acc->regc, &acc->cfg.auth_pref); 918 917 919 918 /* Set route-set -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
r1553 r1561 384 384 } 385 385 386 /* Set authentication preference */ 387 pjsip_auth_clt_set_prefs(&dlg->auth_sess, &acc->cfg.auth_pref); 386 388 387 389 /* Create initial INVITE: */ … … 666 668 pjsua_var.acc[acc_id].cred); 667 669 } 670 671 /* Set preference */ 672 pjsip_auth_clt_set_prefs(&dlg->auth_sess, 673 &pjsua_var.acc[acc_id].cfg.auth_pref); 668 674 669 675 /* Create invite session: */ -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_im.c
r1367 r1561 322 322 pjsua_var.acc[im_data->acc_id].cred); 323 323 324 pjsip_auth_clt_set_prefs(&auth, 325 &pjsua_var.acc[im_data->acc_id].cfg.auth_pref); 326 324 327 status = pjsip_auth_clt_reinit_req(&auth, rdata, tsx->last_tx, 325 328 &tdata); … … 418 421 pjsua_var.acc[im_data->acc_id].cred); 419 422 423 pjsip_auth_clt_set_prefs(&auth, 424 &pjsua_var.acc[im_data->acc_id].cfg.auth_pref); 425 420 426 status = pjsip_auth_clt_reinit_req(&auth, rdata, tsx->last_tx, 421 427 &tdata); -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c
r1556 r1561 572 572 } 573 573 574 /* Set credentials . */574 /* Set credentials and preference. */ 575 575 pjsip_auth_clt_set_credentials(&dlg->auth_sess, acc->cred_cnt, acc->cred); 576 pjsip_auth_clt_set_prefs(&dlg->auth_sess, &acc->cfg.auth_pref); 576 577 577 578 /* Init callback: */ … … 1174 1175 } 1175 1176 1177 /* Set authentication preference */ 1178 pjsip_auth_clt_set_prefs(&buddy->dlg->auth_sess, &acc->cfg.auth_pref); 1179 1176 1180 pjsip_evsub_set_mod_data(buddy->sub, pjsua_var.mod.id, buddy); 1177 1181
Note: See TracChangeset
for help on using the changeset viewer.