PJSIP iOS 错误
Posted
技术标签:
【中文标题】PJSIP iOS 错误【英文标题】:PJSIP iOS Error 【发布时间】:2017-05-30 10:36:05 【问题描述】:我正在我的一个项目中实现 pjsip,这是我第一次从事 VOIP。实际上,我的问题是我无法弄清楚在我的应用程序中使用 PJSIP 代码的步骤。我已经编译了 pjsip 并集成到我的应用程序中。但是在我使用 pjsip 方法添加帐户后,我的服务器开发人员说 我需要在下一次尝试中发送身份验证,我无法弄清楚我该怎么做。请找到我的代码并从中回复。
pj_status_t status;
pjsua_acc_id acc_id;
// Create pjsua first
status = pjsua_create();
if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", status);
// Init pjsua
// Init the config structure
pjsua_config cfg;
pjsua_config_default (&cfg);
cfg.cb.on_incoming_call = &on_incoming_call;
cfg.cb.on_call_media_state = &on_call_media_state;
cfg.cb.on_call_state = &on_call_state;
// Init the logging config structure
pjsua_logging_config log_cfg;
pjsua_logging_config_default(&log_cfg);
log_cfg.console_level = 4;
log_cfg.level = 5;
// Init the pjsua
status = pjsua_init(&cfg, &log_cfg, NULL);
if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", status);
// Add UDP transport.
// Init transport config structure
pjsua_transport_config cfg;
pjsua_transport_config_default(&cfg);
cfg.port = 5060;
// Add TCP transport.
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
// Add TCP transport.
// Init transport config structure
pjsua_transport_config cfg;
pjsua_transport_config_default(&cfg);
cfg.port = 5080;
// Add TCP transport.
status = pjsua_transport_create(PJSIP_TRANSPORT_TCP, &cfg, NULL);
if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
// Initialization is done, now start pjsua
status = pjsua_start();
if (status != PJ_SUCCESS) error_exit("Error starting pjsua", status);
// Register the account on local sip server
pjsua_acc_config cfg;
// cfg.reg_uri = pj_str(regUri);
cfg.cred_count = 1;
cfg.cred_info[0].realm = pj_str("*");
cfg.cred_info[0].scheme = pj_str("digest");
cfg.cred_info[0].username = pj_str(sipUser);
cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
cfg.cred_info[0].data = pj_str(password);
cfg.ice_cfg_use=PJSUA_ICE_CONFIG_USE_DEFAULT;
pjsua_acc_config_default(&cfg);
char sipId[MAX_SIP_ID_LENGTH];
sprintf(sipId, "sip:%s@%s", sipUser, sipDomain);
cfg.id = pj_str(sipId);
char regUri[MAX_SIP_REG_URI_LENGTH];
sprintf(regUri, "sip:%s", primary);
cfg.reg_uri = pj_str(regUri);
pjsip_endpoint* endpoint = pjsua_get_pjsip_endpt();
pj_dns_resolver* resolver;
struct pj_str_t servers[] = pj_str(primary) ;
pjsip_endpt_create_resolver(endpoint, &resolver);
pj_dns_resolver_set_ns(resolver, 1, servers, NULL);
status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id);
if (status != PJ_SUCCESS) error_exit("Error adding account", status);
然后它返回错误,请在下面找到
17:02:30.936 pjsua_acc.c ....IP address change detected for account 0 (xxx.xxx.x.34:5060 --> xxx.xxx.xx.3:5060). Updating registration (using method 4)
17:02:30.942 sip_auth_clien ...Unable to set auth for tdta0x101176c00: can not find credential for d0c20d13-e5b4-4649-821e-9ab8ec94b141/Digest
17:02:30.942 pjsua_acc.c ....SIP registration error: No suitable credential (PJSIP_ENOCREDENTIAL) [status=171101]
17:02:31.312 pjsua_core.c .RX 737 bytes Response msg 401/REGISTER/cseq=45424 (rdata0x101171428) from UDP xx.xxx.xx.111:5060:
SIP/2.0 401 Unauthorized
status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id);的完整响应;
17:02:23.460 os_core_unix.c !pjlib 2.2.1 for POSIX initialized
17:02:23.463 sip_endpoint.c .Creating endpoint instance...
17:02:23.465 pjlib .select() I/O Queue created (0x101156a28)
17:02:23.466 sip_endpoint.c .Module "mod-msg-print" registered
17:02:23.466 sip_transport. .Transport manager created.
17:02:23.466 pjsua_core.c .PJSUA state changed: NULL --> CREATED
17:02:23.466 sip_endpoint.c .Module "mod-pjsua-log" registered
17:02:23.466 sip_endpoint.c .Module "mod-tsx-layer" registered
17:02:23.466 sip_endpoint.c .Module "mod-stateful-util" registered
17:02:23.466 sip_endpoint.c .Module "mod-ua" registered
17:02:23.467 sip_endpoint.c .Module "mod-100rel" registered
17:02:23.467 sip_endpoint.c .Module "mod-pjsua" registered
17:02:23.467 sip_endpoint.c .Module "mod-invite" registered
17:02:23.524 coreaudio_dev. .. dev_id 0: iPhone IO device (in=1, out=1) 8000Hz
17:02:23.524 coreaudio_dev. ..core audio initialized
17:02:23.524 pjlib ..select() I/O Queue created (0x10116d428)
17:02:23.549 sip_endpoint.c .Module "mod-evsub" registered
17:02:23.549 sip_endpoint.c .Module "mod-presence" registered
17:02:23.549 sip_endpoint.c .Module "mod-mwi" registered
17:02:23.549 sip_endpoint.c .Module "mod-refer" registered
17:02:23.549 sip_endpoint.c .Module "mod-pjsua-pres" registered
17:02:23.549 sip_endpoint.c .Module "mod-pjsua-im" registered
17:02:23.549 sip_endpoint.c .Module "mod-pjsua-options" registered
17:02:23.549 pjsua_core.c .1 SIP worker threads created
17:02:23.550 pjsua_core.c .pjsua version 2.2.1 for ios-10.3.1/arm-iPhone7,1/iOS-SDK-7.1 initialized
17:02:23.550 pjsua_core.c .PJSUA state changed: CREATED --> INIT
17:02:23.551 pjsua_core.c SIP UDP socket reachable at xxx.xxx.x.xx:5060
17:02:23.551 udp0x1008a5690 SIP UDP transport started, published address is xxx.xxx.x.xx:5060
17:02:23.552 tcplis:5080 SIP TCP listener ready for incoming connections at xxx.xxx.x.xx:5080
17:02:23.552 pjsua_core.c PJSUA state changed: INIT --> STARTING
17:02:23.552 sip_endpoint.c .Module "mod-unsolicited-mwi" registered
17:02:23.552 pjsua_core.c .PJSUA state changed: STARTING --> RUNNING
2017-05-30 17:02:23.553998+0530 MangoVoice[580:58635] Warning: Libinfo call to mDNSResponder on main thread
17:02:23.555 pjsua_acc.c Adding account: id=sip:Xb3253592824b8a8ded0@d0c20d13-e5b4-4649-821e-9ab8ec94b141
17:02:23.556 pjsua_acc.c .Account sip:Xb3253592824b8a8ded0@d0c20d13-e5b4-4649-821e-9ab8ec94b141 added with id 0
17:02:23.556 pjsua_acc.c .Acc 0: setting registration..
17:02:23.559 pjsua_core.c ...TX 586 bytes Request msg REGISTER/cseq=45424 (tdta0x101176c00) to UDP xxx.xxx.xx.111:5060:
REGISTER sip:xxx.xxx.com SIP/2.0
Via: SIP/2.0/UDP xxx.xxx.x.xx:5060;rport;branch=z9hG4bKPjzsVCERQi7e0oTiyjeP1VcxrybJOBV3eT
Max-Forwards: 70
From: <sip:Xb3253592824b8a8ded0@d0c20d13-e5b4-4649-821e-9ab8ec94b141>;tag=ePz39uBlCOl2fQc7ZCKUxzF69RuasBjW
To: <sip:Xb3253592824b8a8ded0@d0c20d13-e5b4-4649-821e-9ab8ec94b141>
Call-ID: WGh6WZa6sUjf8d2w.XfD-U4fx9kndxPE
CSeq: 45424 REGISTER
Contact: <sip:Xb3253592824b8a8ded0@xxx.xxx.x.xx:5060;ob>
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0
--end msg--
17:02:23.559 pjsua_acc.c ..Acc 0: Registration sent
17:02:30.930 pjsua_core.c .TX 586 bytes Request msg REGISTER/cseq=45424 (tdta0x101176c00) to UDP xxx.xxx.xx.111:5060:
REGISTER sip:xxx.xxx.com SIP/2.0
Via: SIP/2.0/UDP xxx.xxx.x.xx:5060;rport;branch=z9hG4bKPjzsVCERQi7e0oTiyjeP1VcxrybJOBV3eT
Max-Forwards: 70
From: <sip:Xb3253592824b8a8ded0@d0c20d13-e5b4-4649-821e-9ab8ec94b141>;tag=ePz39uBlCOl2fQc7ZCKUxzF69RuasBjW
To: <sip:Xb3253592824b8a8ded0@d0c20d13-e5b4-4649-821e-9ab8ec94b141>
Call-ID: WGh6WZa6sUjf8d2w.XfD-U4fx9kndxPE
CSeq: 45424 REGISTER
Contact: <sip:Xb3253592824b8a8ded0@xxx.xxx.x.xx:5060;ob>
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0
--end msg--
17:02:30.935 pjsua_core.c .RX 737 bytes Response msg 401/REGISTER/cseq=45424 (rdata0x101171428) from UDP xxx.xxx.xx.111:5060:
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP xxx.xxx.x.xx:5060;rport=5060;branch=z9hG4bKPjzsVCERQi7e0oTiyjeP1VcxrybJOBV3eT;received=112.196.29.3
From: <sip:Xb3253592824b8a8ded0@d0c20d13-e5b4-4649-821e-9ab8ec94b141>;tag=ePz39uBlCOl2fQc7ZCKUxzF69RuasBjW
To: <sip:Xb3253592824b8a8ded0@d0c20d13-e5b4-4649-821e-9ab8ec94b141>;tag=Fp60emvSDBrgN
Call-ID: WGh6WZa6sUjf8d2w.XfD-U4fx9kndxPE
CSeq: 45424 REGISTER
User-Agent: MangoVoice
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
WWW-Authenticate: Digest realm="d0c20d13-e5b4-4649-821e-9ab8ec94b141", nonce="28a8625e-d168-4462-97f8-1a244a5b0243", algorithm=MD5, qop="auth"
Content-Length: 0
--end msg--
17:02:30.936 pjsua_acc.c ....IP address change detected for account 0 (xxx.xxx.x.xx:5060 --> 112.196.29.3:5060). Updating registration (using method 4)
17:02:30.942 sip_auth_clien ...Unable to set auth for tdta0x101176c00: can not find credential for d0c20d13-e5b4-4649-821e-9ab8ec94b141/Digest
17:02:30.942 pjsua_acc.c ....SIP registration error: No suitable credential (PJSIP_ENOCREDENTIAL) [status=171101]
17:02:31.312 pjsua_core.c .RX 737 bytes Response msg 401/REGISTER/cseq=45424 (rdata0x101171428) from UDP xxx.xxx.xx.111:5060:
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP xxx.xxx.x.xx:5060;rport=5060;branch=z9hG4bKPjzsVCERQi7e0oTiyjeP1VcxrybJOBV3eT;received=112.196.29.3
From: <sip:Xb3253592824b8a8ded0@d0c20d13-e5b4-4649-821e-9ab8ec94b141>;tag=ePz39uBlCOl2fQc7ZCKUxzF69RuasBjW
To: <sip:Xb3253592824b8a8ded0@d0c20d13-e5b4-4649-821e-9ab8ec94b141>;tag=Fp60emvSDBrgN
Call-ID: WGh6WZa6sUjf8d2w.XfD-U4fx9kndxPE
CSeq: 45424 REGISTER
User-Agent: MangoVoice
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
WWW-Authenticate: Digest realm="d0c20d13-e5b4-4649-821e-9ab8ec94b141", nonce="28a8625e-d168-4462-97f8-1a244a5b0243", algorithm=MD5, qop="auth"
Content-Length: 0
--end msg--
【问题讨论】:
你有什么运气吗? 如果你没有解决这个问题,你能告诉我们status
对于这条线status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
的值是多少?
【参考方案1】:
在 cfg 中设置任何设置之前,请尝试使用 pjsua_acc_config_default(&cfg)。当您告诉它使用摘要方案时,您正在使用默认更改 cfg 它不会发送身份验证信息以回复 401 响应
【讨论】:
以上是关于PJSIP iOS 错误的主要内容,如果未能解决你的问题,请参考以下文章
如何在 ios 中使用带有域的 pjsip 添加对 IPv6 的支持?