diff --git a/src/ice_transport.cpp b/src/ice_transport.cpp index 293c7891cf4531b856c245267899281ff348553c..5c8cfed1c122d398bd8a66a01c4941008be19ed0 100644 --- a/src/ice_transport.cpp +++ b/src/ice_transport.cpp @@ -185,11 +185,9 @@ IceTransport::onComplete(pj_ice_strans* ice_st, pj_ice_strans_op op, const bool done = status == PJ_SUCCESS; RING_DBG("ICE %s with %s", opname, done?"success":"error"); - if (!done) { - char errmsg[PJ_ERR_MSG_SIZE]; - pj_strerror(status, errmsg, sizeof(errmsg)); - RING_ERR("ICE %s failed: %s", opname, errmsg); - } + if (!done) + RING_ERR("ICE %s failed: %s", opname, + sip_utils::sip_strerror(status).c_str()); { std::lock_guard<std::mutex> lk(iceMutex_); @@ -254,8 +252,7 @@ IceTransport::setInitiatorSession() if (isInitialized()) { auto status = pj_ice_strans_change_role(icest_.get(), PJ_ICE_SESS_ROLE_CONTROLLING); if (status != PJ_SUCCESS) { - RING_ERR("ICE role change failed"); - sip_utils::sip_strerror(status); + RING_ERR("ICE role change failed: %s", sip_utils::sip_strerror(status).c_str()); return false; } return true; @@ -271,8 +268,7 @@ IceTransport::setSlaveSession() if (isInitialized()) { auto status = pj_ice_strans_change_role(icest_.get(), PJ_ICE_SESS_ROLE_CONTROLLED); if (status != PJ_SUCCESS) { - RING_ERR("ICE role change failed"); - sip_utils::sip_strerror(status); + RING_ERR("ICE role change failed: %s", sip_utils::sip_strerror(status).c_str()); return false; } return true; @@ -311,8 +307,7 @@ IceTransport::start(const Attribute& rem_attrs, rem_candidates.size(), rem_candidates.data()); if (status != PJ_SUCCESS) { - RING_ERR("ICE start failed"); - sip_utils::sip_strerror(status); + RING_ERR("ICE start failed: %s", sip_utils::sip_strerror(status).c_str()); return false; } return true; @@ -381,8 +376,7 @@ IceTransport::stop() auto status = pj_ice_strans_stop_ice(icest_.get()); if (status != PJ_SUCCESS) { - RING_ERR("ICE start failed"); - sip_utils::sip_strerror(status); + RING_ERR("ICE start failed: %s", sip_utils::sip_strerror(status).c_str()); return false; } @@ -523,12 +517,12 @@ IceTransport::addCandidate(int comp_id, const IpAddr& localAddr, NULL); if (ret != PJ_SUCCESS) { - RING_ERR("fail to add candidate for comp_id=%d : %s : %s", comp_id + RING_ERR("failed to add candidate for comp_id=%d : %s : %s", comp_id , localAddr.toString().c_str() , publicAddr.toString().c_str()); - sip_utils::sip_strerror(ret); + sip_utils::sip_printerror(ret); } else { - RING_DBG("success to add candidate for comp_id=%d : %s : %s", comp_id + RING_DBG("succeed to add candidate for comp_id=%d : %s : %s", comp_id , localAddr.toString().c_str() , publicAddr.toString().c_str()); } @@ -708,8 +702,7 @@ IceTransport::send(int comp_id, const unsigned char* buf, size_t len) } auto status = pj_ice_strans_sendto(icest_.get(), comp_id+1, buf, len, remote.pjPtr(), remote.getLength()); if (status != PJ_SUCCESS) { - sip_utils::sip_strerror(status); - RING_ERR("send failed"); + RING_ERR("ice send failed: %s", sip_utils::sip_strerror(status).c_str()); return -1; } return len; @@ -846,11 +839,8 @@ handleIOEvents(pj_ice_strans_cfg& cfg, unsigned max_msec) // error if (n_events < 0) { const auto err = pj_get_os_error(); - char err_msg[128]; - pj_strerror(err, err_msg, sizeof(err_msg)); - err_msg[sizeof(err_msg)-1] = '\0'; // Kept as debug as some errors are "normal" in regular context - RING_DBG("IceIOQueue: error %d - %s", err, err_msg); + RING_DBG("IceIOQueue: error %d - %s", err, sip_utils::sip_strerror(err).c_str()); std::this_thread::sleep_for(std::chrono::milliseconds(PJ_TIME_VAL_MSEC(timeout))); return; } diff --git a/src/ip_utils.cpp b/src/ip_utils.cpp index fd83d40778c5659480a14b43a5e15bbec4f317e2..66435d20d312c48f7cb54e74f497b17765c8258a 100644 --- a/src/ip_utils.cpp +++ b/src/ip_utils.cpp @@ -65,8 +65,8 @@ ip_utils::getAddrList(const std::string &name, pj_uint16_t family) pj_cstr(&pjname, name.c_str()); auto status = pj_getaddrinfo(family, &pjname, &addr_num, res); if (status != PJ_SUCCESS) { - RING_ERR("Error resolving %s :", name.c_str()); - sip_utils::sip_strerror(status); + RING_ERR("Error resolving %s : %s", name.c_str(), + sip_utils::sip_strerror(status).c_str()); return ipList; } diff --git a/src/sip/sip_utils.cpp b/src/sip/sip_utils.cpp index 6b1510c7e7b650e2c8bed984c179b84858638354..b85bf161a621d1de2337d66b73d3a4c7c76198d4 100644 --- a/src/sip/sip_utils.cpp +++ b/src/sip/sip_utils.cpp @@ -204,13 +204,20 @@ addContactHeader(const pj_str_t *contact_str, pjsip_tx_data *tdata) pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*) contact); } - void -sip_strerror(pj_status_t code) +sip_printerror(pj_status_t code) { char err_msg[PJ_ERR_MSG_SIZE]; pj_strerror(code, err_msg, sizeof err_msg); RING_ERR("%d: %s", code, err_msg); } +std::string +sip_strerror(pj_status_t code) +{ + char err_msg[PJ_ERR_MSG_SIZE]; + pj_strerror(code, err_msg, sizeof err_msg); + return std::string{err_msg}; +} + }} // namespace ring::sip_utils diff --git a/src/sip/sip_utils.h b/src/sip/sip_utils.h index e64fbba8889f5266a3d0691ffce4650175c87d1e..d9333a76cc610bf2e4f2f5b34a71da7177084bb4 100644 --- a/src/sip/sip_utils.h +++ b/src/sip/sip_utils.h @@ -79,7 +79,8 @@ std::string getHostFromUri(const std::string& sipUri); void addContactHeader(const pj_str_t *contactStr, pjsip_tx_data *tdata); -void sip_strerror(pj_status_t code); +void sip_printerror(pj_status_t code); +std::string sip_strerror(pj_status_t code); }} // namespace ring::sip_utils diff --git a/src/sip/sipaccount.cpp b/src/sip/sipaccount.cpp index cb7a2b175691c5b6c025adae9f628aa112e219e6..b9ae351f77358040db8f0da8516fc460ad870297 100644 --- a/src/sip/sipaccount.cpp +++ b/src/sip/sipaccount.cpp @@ -270,12 +270,9 @@ SIPAccount::onTransportStateChanged(pjsip_transport_state state, const pjsip_tra RING_DBG("Transport state changed to %s for account %s !", SipTransport::stateToStr(state), accountID_.c_str()); if (!SipTransport::isAlive(transport_, state)) { if (info) { - char err_msg[128]; - err_msg[0] = '\0'; - pj_str_t descr = pj_strerror(info->status, err_msg, sizeof(err_msg)); transportStatus_ = info->status; - transportError_ = std::string(descr.ptr, descr.slen); - RING_ERR("Transport disconnected: %.*s", descr.slen, descr.ptr); + transportError_ = sip_utils::sip_strerror(info->status); + RING_ERR("Transport disconnected: %s", transportError_.c_str()); } else { // This is already the generic error used by pjsip. @@ -993,7 +990,7 @@ SIPAccount::sendRegister() //RING_DBG("pjsip_regc_init from:%s, srv:%s, contact:%s", from.c_str(), srvUri.c_str(), std::string(pj_strbuf(&pjContact), pj_strlen(&pjContact)).c_str()); if ((status = pjsip_regc_init(regc, &pjSrv, &pjFrom, &pjFrom, 1, &pjContact, getRegistrationExpire())) != PJ_SUCCESS) { - sip_utils::sip_strerror(status); + sip_utils::sip_printerror(status); throw VoipLinkException("Unable to initialize account registration structure"); } @@ -1032,7 +1029,7 @@ SIPAccount::sendRegister() // pjsip_regc_send increment the transport ref count by one, if ((status = pjsip_regc_send(regc, tdata)) != PJ_SUCCESS) { - sip_utils::sip_strerror(status); + sip_utils::sip_printerror(status); throw VoipLinkException("Unable to send account registration request"); } @@ -1147,7 +1144,7 @@ SIPAccount::sendUnregister() pj_status_t status; if ((status = pjsip_regc_send(regc, tdata)) != PJ_SUCCESS) { - sip_utils::sip_strerror(status); + sip_utils::sip_printerror(status); throw VoipLinkException("Unable to send request to unregister sip account"); } @@ -2153,10 +2150,7 @@ SIPAccount::sendTextMessage(const std::string& to, const std::string& msg) pj_status_t status = pjsip_endpt_create_request(link_->getEndpoint(), &msg_method, &pjTo, &pjFrom, &pjTo, NULL, NULL, -1, NULL, &tdata); if (status != PJ_SUCCESS) { - char err_msg[128]; - err_msg[0] = '\0'; - pj_str_t descr = pj_strerror(status, err_msg, sizeof(err_msg)); - RING_ERR("Unable to create request: %.*s", descr.slen, descr.ptr); + RING_ERR("Unable to create request: %s", sip_utils::sip_strerror(status).c_str()); return; } @@ -2181,10 +2175,7 @@ SIPAccount::sendTextMessage(const std::string& to, const std::string& msg) status = pjsip_endpt_send_request(link_->getEndpoint(), tdata, -1, nullptr, nullptr); if (status != PJ_SUCCESS) { - char err_msg[128]; - err_msg[0] = '\0'; - pj_str_t descr = pj_strerror(status, err_msg, sizeof(err_msg)); - RING_ERR("Unable to send request: %.*s", descr.slen, descr.ptr); + RING_ERR("Unable to send request: %s", sip_utils::sip_strerror(status).c_str()); return; } } diff --git a/src/sip/sipcall.cpp b/src/sip/sipcall.cpp index 9f9ec612c5e39af11f554e8818182ef7e697d100..64fdb92bdc6abe159aeebca79c7967dd1ced599a 100644 --- a/src/sip/sipcall.cpp +++ b/src/sip/sipcall.cpp @@ -670,7 +670,7 @@ SIPCall::peerHungup() inv->mod_data[getSIPVoIPLink()->getModId()] = NULL; } else { inv.reset(); - sip_utils::sip_strerror(ret); + sip_utils::sip_printerror(ret); } } diff --git a/src/sip/siptransport.cpp b/src/sip/siptransport.cpp index 91be97a9cf183fc93818ebe9b69189f9e32ebe87..726bdb174b7cf1cde6209d9cbaa40c4afe108229 100644 --- a/src/sip/siptransport.cpp +++ b/src/sip/siptransport.cpp @@ -352,7 +352,7 @@ SipTransportBroker::createUdpTransport(const SipTransportDescr& d) RING_ERR("UDP IPv%s Transport did not start on %s", listeningAddress.isIpv4() ? "4" : "6", listeningAddress.toString(true).c_str()); - sip_utils::sip_strerror(status); + sip_utils::sip_printerror(status); return nullptr; } @@ -388,8 +388,7 @@ SipTransportBroker::getTlsListener(const SipTransportDescr& d, const pjsip_tls_s pjsip_tpfactory *listener = nullptr; const pj_status_t status = pjsip_tls_transport_start2(endpt_, settings, listeningAddress.pjPtr(), nullptr, 1, &listener); if (status != PJ_SUCCESS) { - RING_ERR("TLS listener did not start"); - sip_utils::sip_strerror(status); + RING_ERR("TLS listener did not start: %s", sip_utils::sip_strerror(status).c_str()); return nullptr; } return std::make_shared<TlsListener>(listener); @@ -423,8 +422,7 @@ SipTransportBroker::getTlsTransport(const std::shared_ptr<TlsListener>& l, const &transport); if (!transport || status != PJ_SUCCESS) { - RING_ERR("Could not get new TLS transport"); - sip_utils::sip_strerror(status); + RING_ERR("Could not get new TLS transport: %s", sip_utils::sip_strerror(status).c_str()); return nullptr; } auto ret = std::make_shared<SipTransport>(transport, l); diff --git a/src/sip/sipvoiplink.cpp b/src/sip/sipvoiplink.cpp index 5890328e3e54b1ee612ec1f7c7ddeaccab52143b..327f22454d5fe88a2c74a6f0c3138a98b52091e1 100644 --- a/src/sip/sipvoiplink.cpp +++ b/src/sip/sipvoiplink.cpp @@ -528,10 +528,8 @@ SIPVoIPLink::SIPVoIPLink() auto status = pjsip_tpmgr_set_state_cb(pjsip_endpt_get_tpmgr(endpt_), tp_state_callback); - if (status != PJ_SUCCESS) { - RING_ERR("Can't set transport callback"); - sip_utils::sip_strerror(status); - } + if (status != PJ_SUCCESS) + RING_ERR("Can't set transport callback: %s", sip_utils::sip_strerror(status).c_str()); if (!ip_utils::getLocalAddr()) throw VoipLinkException("UserAgent: Unable to determine network capabilities"); @@ -699,7 +697,7 @@ SIPVoIPLink::handleEvents() static const pj_time_val timeout = {0, 0}; // polling auto ret = pjsip_endpt_handle_events(endpt_, &timeout); if (ret != PJ_SUCCESS) - sip_utils::sip_strerror(ret); + sip_utils::sip_printerror(ret); #ifdef RING_VIDEO dequeKeyframeRequests();