diff --git a/src/Common/Parser.cpp b/src/Common/Parser.cpp index 012a3306..9c073f2c 100644 --- a/src/Common/Parser.cpp +++ b/src/Common/Parser.cpp @@ -20,30 +20,6 @@ using namespace toolkit; namespace mediakit { -string findrSubString(const char *buf, const char *start, const char end, size_t buf_size) { - if (buf_size <= 0) { - buf_size = strlen(buf); - } - auto msg_start = buf; - auto msg_end = buf + buf_size; - size_t len = 0; - if (start != NULL) { - len = strlen(start); - msg_start = strstr(buf, start); - } - if (msg_start == NULL) { - return ""; - } - msg_start += len; - if (end != NULL) { - msg_end = strrchr(msg_start, end); - if (msg_end == NULL) { - return ""; - } - } - return string(msg_start, msg_end); -} - string findSubString(const char *buf, const char *start, const char *end, size_t buf_size) { if (buf_size <= 0) { buf_size = strlen(buf); diff --git a/src/Common/Parser.h b/src/Common/Parser.h index 5c10cae7..3741f4bc 100644 --- a/src/Common/Parser.h +++ b/src/Common/Parser.h @@ -18,7 +18,6 @@ namespace mediakit { // 从字符串中提取子字符串 -std::string findrSubString(const char *buf, const char *start, const char end, size_t buf_size = 0); std::string findSubString(const char *buf, const char *start, const char *end, size_t buf_size = 0); // 把url解析为主机地址和端口号,兼容ipv4/ipv6/dns void splitUrl(const std::string &url, std::string &host, uint16_t &port); diff --git a/src/Rtmp/RtmpPusher.cpp b/src/Rtmp/RtmpPusher.cpp index ee7d560b..1569d30b 100644 --- a/src/Rtmp/RtmpPusher.cpp +++ b/src/Rtmp/RtmpPusher.cpp @@ -62,32 +62,21 @@ void RtmpPusher::onPublishResult_l(const SockException &ex, bool handshake_done) shutdown(SockException(Err_shutdown,"teardown")); } } -#ifdef _MSC_VER -//not #if defined(_WIN32) || defined(_WIN64) because we have strncasecmp in mingw -#define strncasecmp _strnicmp -#define strcasecmp _stricmp -#endif -void RtmpPusher::publish(const string &url) { + +void RtmpPusher::publish(const string &url) { teardown(); - string head ; - // rtmps rt_url head should be rtmps - const char *rtmp_head = "rtmp://"; - const char *rtmps_head = "rtmps://"; - if(0 == strncasecmp(url.c_str(), rtmp_head, strlen(rtmp_head))) - { - head = rtmp_head; - } - if(0 == strncasecmp(url.c_str(), rtmps_head, strlen(rtmps_head))) - { - head = rtmps_head; - } - - string host_url = findSubString(url.data(), "://", "/"); - _app = findrSubString(url.data(), (host_url + "/").data(), '/'); + auto schema = findSubString(url.data(), nullptr, "://"); + auto host_url = findSubString(url.data(), "://", "/"); + _app = findSubString(url.data(), (host_url + "/").data(), "/"); _stream_id = findSubString(url.data(), (host_url + "/" + _app + "/").data(), NULL); - _tc_url = head + host_url + "/" + _app; - - if (!_app.size() || !_stream_id.size() || !head.size()) { + auto app_second = findSubString(_stream_id.data(), nullptr, "/"); + if (!app_second.empty() && app_second.find('?') == std::string::npos) { + // _stream_id存在多级;不包含'?', 说明分割符'/'不是url参数的一部分 + _app += "/" + app_second; + _stream_id.erase(0, app_second.size()); + } + _tc_url = schema + "://" + host_url + "/" + _app; + if (_app.empty() || _stream_id.empty()) { onPublishResult_l(SockException(Err_other, "rtmp url非法"), false); return; }