diff --git a/src/sip/sipvoiplink.cpp b/src/sip/sipvoiplink.cpp index 2168b09607fe288f490b013a00e31092e3b690cd..5f375f98d53d4a3168872619af47a1db7b73ca09 100644 --- a/src/sip/sipvoiplink.cpp +++ b/src/sip/sipvoiplink.cpp @@ -1060,22 +1060,20 @@ handleMediaControl(SIPCall& call, pjsip_msg_body* body) if (body->len and pj_stricmp(&body->content_type.type, &STR_APPLICATION) == 0 and pj_stricmp(&body->content_type.subtype, &STR_MEDIA_CONTROL_XML) == 0) { - pj_str_t control_st; + auto body_msg = std::string_view((char*)body->data, (size_t)body->len); /* Apply and answer the INFO request */ - pj_strset(&control_st, (char*) body->data, body->len); - static constexpr pj_str_t PICT_FAST_UPDATE = CONST_PJ_STR("picture_fast_update"); - static constexpr pj_str_t DEVICE_ORIENTATION = CONST_PJ_STR("device_orientation"); - static constexpr pj_str_t RECORDING_STATE = CONST_PJ_STR("recording_state"); + static constexpr auto PICT_FAST_UPDATE = "picture_fast_update"sv; + static constexpr auto DEVICE_ORIENTATION = "device_orientation"sv; + static constexpr auto RECORDING_STATE = "recording_state"sv; - if (pj_strstr(&control_st, &PICT_FAST_UPDATE)) { + if (body_msg.find(PICT_FAST_UPDATE) != std::string_view::npos) { call.sendKeyframe(); return true; - } else if (pj_strstr(&control_st, &DEVICE_ORIENTATION)) { + } else if (body_msg.find(DEVICE_ORIENTATION) != std::string_view::npos) { static const std::regex ORIENTATION_REGEX("device_orientation=([-+]?[0-9]+)"); - std::string body_msg(control_st.ptr, control_st.slen); - std::smatch matched_pattern; + std::svmatch matched_pattern; std::regex_search(body_msg, matched_pattern, ORIENTATION_REGEX); if (matched_pattern.ready() && !matched_pattern.empty() && matched_pattern[1].matched) { @@ -1094,10 +1092,9 @@ handleMediaControl(SIPCall& call, pjsip_msg_body* body) } return true; } - } else if (pj_strstr(&control_st, &RECORDING_STATE)) { + } else if (body_msg.find(RECORDING_STATE) != std::string_view::npos) { static const std::regex REC_REGEX("recording_state=([0-1])"); - std::string body_msg(control_st.ptr, control_st.slen); - std::smatch matched_pattern; + std::svmatch matched_pattern; std::regex_search(body_msg, matched_pattern, REC_REGEX); if (matched_pattern.ready() && !matched_pattern.empty() && matched_pattern[1].matched) { diff --git a/src/string_utils.h b/src/string_utils.h index 58a13bb7bf9d6ffc9afe9380fb1de7ede10fdd8f..8f0bb07d8738d1e5d77b5b2f334ef8b9479c4f03 100644 --- a/src/string_utils.h +++ b/src/string_utils.h @@ -68,6 +68,14 @@ regex_match(string_view sv, { return regex_match(sv.begin(), sv.end(), e, flags); } +inline bool +regex_search(string_view sv, + svmatch& m, + const regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default) +{ + return regex_search(sv.begin(), sv.end(), m, e, flags); +} } // namespace std namespace jami {