正在显示
9 个修改的文件
包含
203 行增加
和
45 行删除
| @@ -516,7 +516,8 @@ if [ $SRS_LIBRTMP = YES ]; then | @@ -516,7 +516,8 @@ if [ $SRS_LIBRTMP = YES ]; then | ||
| 516 | fi | 516 | fi |
| 517 | # | 517 | # |
| 518 | # utest, the unit-test cases of srs, base on gtest1.6 | 518 | # utest, the unit-test cases of srs, base on gtest1.6 |
| 519 | -MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_handshake" "srs_utest_buffer") | 519 | +MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_handshake" |
| 520 | + "srs_utest_buffer" "srs_utest_protocol") | ||
| 520 | ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot}) | 521 | ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot}) |
| 521 | ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile}) | 522 | ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile}) |
| 522 | MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP") | 523 | MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP") |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR "0" | 32 | #define VERSION_MAJOR "0" |
| 33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
| 34 | -#define VERSION_REVISION "139" | 34 | +#define VERSION_REVISION "140" |
| 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
| 36 | // server info. | 36 | // server info. |
| 37 | #define RTMP_SIG_SRS_KEY "SRS" | 37 | #define RTMP_SIG_SRS_KEY "SRS" |
| @@ -124,41 +124,6 @@ void SrsRequest::update_auth(SrsRequest* req) | @@ -124,41 +124,6 @@ void SrsRequest::update_auth(SrsRequest* req) | ||
| 124 | srs_info("update req of soruce for auth ok"); | 124 | srs_info("update req of soruce for auth ok"); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | -int SrsRequest::discovery_app() | ||
| 128 | -{ | ||
| 129 | - int ret = ERROR_SUCCESS; | ||
| 130 | - | ||
| 131 | - size_t pos = std::string::npos; | ||
| 132 | - std::string url = tcUrl; | ||
| 133 | - | ||
| 134 | - if ((pos = url.find("://")) != std::string::npos) { | ||
| 135 | - schema = url.substr(0, pos); | ||
| 136 | - url = url.substr(schema.length() + 3); | ||
| 137 | - srs_verbose("discovery schema=%s", schema.c_str()); | ||
| 138 | - } | ||
| 139 | - | ||
| 140 | - if ((pos = url.find("/")) != std::string::npos) { | ||
| 141 | - host = url.substr(0, pos); | ||
| 142 | - url = url.substr(host.length() + 1); | ||
| 143 | - srs_verbose("discovery host=%s", host.c_str()); | ||
| 144 | - } | ||
| 145 | - | ||
| 146 | - port = RTMP_DEFAULT_PORT; | ||
| 147 | - if ((pos = host.find(":")) != std::string::npos) { | ||
| 148 | - port = host.substr(pos + 1); | ||
| 149 | - host = host.substr(0, pos); | ||
| 150 | - srs_verbose("discovery host=%s, port=%s", host.c_str(), port.c_str()); | ||
| 151 | - } | ||
| 152 | - | ||
| 153 | - app = url; | ||
| 154 | - vhost = host; | ||
| 155 | - srs_vhost_resolve(vhost, app); | ||
| 156 | - | ||
| 157 | - strip(); | ||
| 158 | - | ||
| 159 | - return ret; | ||
| 160 | -} | ||
| 161 | - | ||
| 162 | string SrsRequest::get_stream_url() | 127 | string SrsRequest::get_stream_url() |
| 163 | { | 128 | { |
| 164 | std::string url = ""; | 129 | std::string url = ""; |
| @@ -867,7 +832,10 @@ int SrsRtmpServer::connect_app(SrsRequest* req) | @@ -867,7 +832,10 @@ int SrsRtmpServer::connect_app(SrsRequest* req) | ||
| 867 | 832 | ||
| 868 | srs_info("get connect app message params success."); | 833 | srs_info("get connect app message params success."); |
| 869 | 834 | ||
| 870 | - return req->discovery_app(); | 835 | + srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->port); |
| 836 | + req->strip(); | ||
| 837 | + | ||
| 838 | + return ret; | ||
| 871 | } | 839 | } |
| 872 | 840 | ||
| 873 | int SrsRtmpServer::set_window_ack_size(int ack_size) | 841 | int SrsRtmpServer::set_window_ack_size(int ack_size) |
| @@ -98,9 +98,8 @@ public: | @@ -98,9 +98,8 @@ public: | ||
| 98 | virtual void update_auth(SrsRequest* req); | 98 | virtual void update_auth(SrsRequest* req); |
| 99 | 99 | ||
| 100 | /** | 100 | /** |
| 101 | - * disconvery vhost/app from tcUrl. | 101 | + * get the stream identify, vhost/app/stream. |
| 102 | */ | 102 | */ |
| 103 | - virtual int discovery_app(); | ||
| 104 | virtual std::string get_stream_url(); | 103 | virtual std::string get_stream_url(); |
| 105 | 104 | ||
| 106 | // strip url, user must strip when update the url. | 105 | // strip url, user must strip when update the url. |
| @@ -29,9 +29,43 @@ using namespace std; | @@ -29,9 +29,43 @@ using namespace std; | ||
| 29 | #include <srs_kernel_log.hpp> | 29 | #include <srs_kernel_log.hpp> |
| 30 | #include <srs_kernel_utility.hpp> | 30 | #include <srs_kernel_utility.hpp> |
| 31 | 31 | ||
| 32 | +void srs_discovery_tc_url( | ||
| 33 | + string tcUrl, | ||
| 34 | + string& schema, string& host, string& vhost, | ||
| 35 | + string& app, string& port | ||
| 36 | +) { | ||
| 37 | + size_t pos = std::string::npos; | ||
| 38 | + std::string url = tcUrl; | ||
| 39 | + | ||
| 40 | + if ((pos = url.find("://")) != std::string::npos) { | ||
| 41 | + schema = url.substr(0, pos); | ||
| 42 | + url = url.substr(schema.length() + 3); | ||
| 43 | + srs_info("discovery schema=%s", schema.c_str()); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + if ((pos = url.find("/")) != std::string::npos) { | ||
| 47 | + host = url.substr(0, pos); | ||
| 48 | + url = url.substr(host.length() + 1); | ||
| 49 | + srs_info("discovery host=%s", host.c_str()); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + port = RTMP_DEFAULT_PORT; | ||
| 53 | + if ((pos = host.find(":")) != std::string::npos) { | ||
| 54 | + port = host.substr(pos + 1); | ||
| 55 | + host = host.substr(0, pos); | ||
| 56 | + srs_info("discovery host=%s, port=%s", host.c_str(), port.c_str()); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + app = url; | ||
| 60 | + vhost = host; | ||
| 61 | + srs_vhost_resolve(vhost, app); | ||
| 62 | +} | ||
| 63 | + | ||
| 32 | void srs_vhost_resolve(string& vhost, string& app) | 64 | void srs_vhost_resolve(string& vhost, string& app) |
| 33 | { | 65 | { |
| 34 | app = srs_string_replace(app, "...", "?"); | 66 | app = srs_string_replace(app, "...", "?"); |
| 67 | + app = srs_string_replace(app, "&&", "?"); | ||
| 68 | + app = srs_string_replace(app, "=", "?"); | ||
| 35 | 69 | ||
| 36 | size_t pos = 0; | 70 | size_t pos = 0; |
| 37 | if ((pos = app.find("?")) == std::string::npos) { | 71 | if ((pos = app.find("?")) == std::string::npos) { |
| @@ -41,15 +75,14 @@ void srs_vhost_resolve(string& vhost, string& app) | @@ -41,15 +75,14 @@ void srs_vhost_resolve(string& vhost, string& app) | ||
| 41 | std::string query = app.substr(pos + 1); | 75 | std::string query = app.substr(pos + 1); |
| 42 | app = app.substr(0, pos); | 76 | app = app.substr(0, pos); |
| 43 | 77 | ||
| 44 | - if ((pos = query.find("vhost?")) != std::string::npos | ||
| 45 | - || (pos = query.find("vhost=")) != std::string::npos | ||
| 46 | - || (pos = query.find("Vhost?")) != std::string::npos | ||
| 47 | - || (pos = query.find("Vhost=")) != std::string::npos | ||
| 48 | - ) { | 78 | + if ((pos = query.find("vhost?")) != std::string::npos) { |
| 49 | query = query.substr(pos + 6); | 79 | query = query.substr(pos + 6); |
| 50 | if (!query.empty()) { | 80 | if (!query.empty()) { |
| 51 | vhost = query; | 81 | vhost = query; |
| 52 | } | 82 | } |
| 83 | + if ((pos = vhost.find("?")) != std::string::npos) { | ||
| 84 | + vhost = vhost.substr(0, pos); | ||
| 85 | + } | ||
| 53 | } | 86 | } |
| 54 | } | 87 | } |
| 55 | 88 |
| @@ -39,6 +39,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -39,6 +39,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 39 | // the default chunk size for system. | 39 | // the default chunk size for system. |
| 40 | #define SRS_CONF_DEFAULT_CHUNK_SIZE 60000 | 40 | #define SRS_CONF_DEFAULT_CHUNK_SIZE 60000 |
| 41 | 41 | ||
| 42 | +// parse the tcUrl, output the schema, host, vhost, app and port. | ||
| 43 | +extern void srs_discovery_tc_url( | ||
| 44 | + std::string tcUrl, | ||
| 45 | + std::string& schema, std::string& host, std::string& vhost, | ||
| 46 | + std::string& app, std::string& port | ||
| 47 | +); | ||
| 48 | + | ||
| 42 | // resolve the vhost in query string | 49 | // resolve the vhost in query string |
| 43 | // @param app, may contains the vhost in query string format: | 50 | // @param app, may contains the vhost in query string format: |
| 44 | // app?vhost=request_vhost | 51 | // app?vhost=request_vhost |
| @@ -116,6 +116,8 @@ file | @@ -116,6 +116,8 @@ file | ||
| 116 | ..\utest\srs_utest_buffer.cpp, | 116 | ..\utest\srs_utest_buffer.cpp, |
| 117 | ..\utest\srs_utest_handshake.hpp, | 117 | ..\utest\srs_utest_handshake.hpp, |
| 118 | ..\utest\srs_utest_handshake.cpp, | 118 | ..\utest\srs_utest_handshake.cpp, |
| 119 | + ..\utest\srs_utest_protocol.hpp, | ||
| 120 | + ..\utest\srs_utest_protocol.cpp, | ||
| 119 | research readonly separator, | 121 | research readonly separator, |
| 120 | ..\..\research\librtmp\srs_detect_rtmp.c, | 122 | ..\..\research\librtmp\srs_detect_rtmp.c, |
| 121 | ..\..\research\librtmp\srs_flv_injecter.c, | 123 | ..\..\research\librtmp\srs_flv_injecter.c, |
trunk/src/utest/srs_utest_protocol.cpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2014 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | +#include <srs_utest_protocol.hpp> | ||
| 24 | + | ||
| 25 | +using namespace std; | ||
| 26 | + | ||
| 27 | +#include <srs_kernel_error.hpp> | ||
| 28 | +#include <srs_kernel_utility.hpp> | ||
| 29 | + | ||
| 30 | +VOID TEST(ProtocolUtilityTest, VhostResolve) | ||
| 31 | +{ | ||
| 32 | + std::string vhost = "vhost"; | ||
| 33 | + std::string app = "app"; | ||
| 34 | + srs_vhost_resolve(vhost, app); | ||
| 35 | + EXPECT_STREQ("vhost", vhost.c_str()); | ||
| 36 | + EXPECT_STREQ("app", app.c_str()); | ||
| 37 | + | ||
| 38 | + app = "app?vhost=changed"; | ||
| 39 | + srs_vhost_resolve(vhost, app); | ||
| 40 | + EXPECT_STREQ("changed", vhost.c_str()); | ||
| 41 | + EXPECT_STREQ("app", app.c_str()); | ||
| 42 | + | ||
| 43 | + app = "app?vhost=changed1&&query=true"; | ||
| 44 | + srs_vhost_resolve(vhost, app); | ||
| 45 | + EXPECT_STREQ("changed1", vhost.c_str()); | ||
| 46 | + EXPECT_STREQ("app", app.c_str()); | ||
| 47 | + | ||
| 48 | + app = "app?other=true&&vhost=changed2&&query=true"; | ||
| 49 | + srs_vhost_resolve(vhost, app); | ||
| 50 | + EXPECT_STREQ("changed2", vhost.c_str()); | ||
| 51 | + EXPECT_STREQ("app", app.c_str()); | ||
| 52 | + | ||
| 53 | + app = "app...other...true...vhost...changed3...query...true"; | ||
| 54 | + srs_vhost_resolve(vhost, app); | ||
| 55 | + EXPECT_STREQ("changed3", vhost.c_str()); | ||
| 56 | + EXPECT_STREQ("app", app.c_str()); | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +VOID TEST(ProtocolUtilityTest, DiscoveryTcUrl) | ||
| 60 | +{ | ||
| 61 | + std::string tcUrl; | ||
| 62 | + std::string schema; std::string host; std::string vhost; | ||
| 63 | + std::string app; std::string port; | ||
| 64 | + | ||
| 65 | + tcUrl = "rtmp://127.0.0.1:1935/live"; | ||
| 66 | + srs_discovery_tc_url(tcUrl, schema, host, vhost, app, port); | ||
| 67 | + EXPECT_STREQ("rtmp", schema.c_str()); | ||
| 68 | + EXPECT_STREQ("127.0.0.1", host.c_str()); | ||
| 69 | + EXPECT_STREQ("127.0.0.1", vhost.c_str()); | ||
| 70 | + EXPECT_STREQ("live", app.c_str()); | ||
| 71 | + EXPECT_STREQ("1935", port.c_str()); | ||
| 72 | + | ||
| 73 | + tcUrl = "rtmp://127.0.0.1:19351/live"; | ||
| 74 | + srs_discovery_tc_url(tcUrl, schema, host, vhost, app, port); | ||
| 75 | + EXPECT_STREQ("rtmp", schema.c_str()); | ||
| 76 | + EXPECT_STREQ("127.0.0.1", host.c_str()); | ||
| 77 | + EXPECT_STREQ("127.0.0.1", vhost.c_str()); | ||
| 78 | + EXPECT_STREQ("live", app.c_str()); | ||
| 79 | + EXPECT_STREQ("19351", port.c_str()); | ||
| 80 | + | ||
| 81 | + tcUrl = "rtmp://127.0.0.1:19351/live?vhost=demo"; | ||
| 82 | + srs_discovery_tc_url(tcUrl, schema, host, vhost, app, port); | ||
| 83 | + EXPECT_STREQ("rtmp", schema.c_str()); | ||
| 84 | + EXPECT_STREQ("127.0.0.1", host.c_str()); | ||
| 85 | + EXPECT_STREQ("demo", vhost.c_str()); | ||
| 86 | + EXPECT_STREQ("live", app.c_str()); | ||
| 87 | + EXPECT_STREQ("19351", port.c_str()); | ||
| 88 | + | ||
| 89 | + tcUrl = "rtmp://127.0.0.1:19351/live/show?vhost=demo"; | ||
| 90 | + srs_discovery_tc_url(tcUrl, schema, host, vhost, app, port); | ||
| 91 | + EXPECT_STREQ("rtmp", schema.c_str()); | ||
| 92 | + EXPECT_STREQ("127.0.0.1", host.c_str()); | ||
| 93 | + EXPECT_STREQ("demo", vhost.c_str()); | ||
| 94 | + EXPECT_STREQ("live/show", app.c_str()); | ||
| 95 | + EXPECT_STREQ("19351", port.c_str()); | ||
| 96 | +} | ||
| 97 | + | ||
| 98 | +VOID TEST(ProtocolUtilityTest, GenerateTcUrl) | ||
| 99 | +{ | ||
| 100 | + string ip; string vhost; string app; string port; string tcUrl; | ||
| 101 | + | ||
| 102 | + ip = "127.0.0.1"; vhost = "__defaultVhost__"; app = "live"; port = "1935"; | ||
| 103 | + tcUrl = srs_generate_tc_url(ip, vhost, app, port); | ||
| 104 | + EXPECT_STREQ("rtmp://127.0.0.1/live", tcUrl.c_str()); | ||
| 105 | + | ||
| 106 | + ip = "127.0.0.1"; vhost = "demo"; app = "live"; port = "1935"; | ||
| 107 | + tcUrl = srs_generate_tc_url(ip, vhost, app, port); | ||
| 108 | + EXPECT_STREQ("rtmp://demo/live", tcUrl.c_str()); | ||
| 109 | + | ||
| 110 | + ip = "127.0.0.1"; vhost = "demo"; app = "live"; port = "19351"; | ||
| 111 | + tcUrl = srs_generate_tc_url(ip, vhost, app, port); | ||
| 112 | + EXPECT_STREQ("rtmp://demo:19351/live", tcUrl.c_str()); | ||
| 113 | +} |
trunk/src/utest/srs_utest_protocol.hpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2014 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#ifndef SRS_UTEST_PROTOCOL_HPP | ||
| 25 | +#define SRS_UTEST_PROTOCOL_HPP | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | +#include <srs_utest_protocol.hpp> | ||
| 29 | +*/ | ||
| 30 | +#include <srs_utest.hpp> | ||
| 31 | + | ||
| 32 | +#include <string> | ||
| 33 | +#include <srs_protocol_utility.hpp> | ||
| 34 | + | ||
| 35 | +#endif |
-
请 注册 或 登录 后发表评论