winlin

private the srs_vhost_resolve

@@ -41,6 +41,46 @@ using namespace std; @@ -41,6 +41,46 @@ using namespace std;
41 #include <srs_rtmp_stack.hpp> 41 #include <srs_rtmp_stack.hpp>
42 #include <srs_protocol_io.hpp> 42 #include <srs_protocol_io.hpp>
43 43
  44 +/**
  45 + * resolve the vhost in query string
  46 + * @pram vhost, update the vhost if query contains the vhost.
  47 + * @param app, may contains the vhost in query string format:
  48 + * app?vhost=request_vhost
  49 + * app...vhost...request_vhost
  50 + * @param param, the query, for example, ?vhost=xxx
  51 + */
  52 +void srs_vhost_resolve(string& vhost, string& app, string& param)
  53 +{
  54 + // get original param
  55 + size_t pos = 0;
  56 + if ((pos = app.find("?")) != std::string::npos) {
  57 + param = app.substr(pos);
  58 + }
  59 +
  60 + // filter tcUrl
  61 + app = srs_string_replace(app, ",", "?");
  62 + app = srs_string_replace(app, "...", "?");
  63 + app = srs_string_replace(app, "&&", "?");
  64 + app = srs_string_replace(app, "=", "?");
  65 +
  66 + if ((pos = app.find("?")) != std::string::npos) {
  67 + std::string query = app.substr(pos + 1);
  68 + app = app.substr(0, pos);
  69 +
  70 + if ((pos = query.find("vhost?")) != std::string::npos) {
  71 + query = query.substr(pos + 6);
  72 + if (!query.empty()) {
  73 + vhost = query;
  74 + }
  75 + if ((pos = vhost.find("?")) != std::string::npos) {
  76 + vhost = vhost.substr(0, pos);
  77 + }
  78 + }
  79 + }
  80 +
  81 + /* others */
  82 +}
  83 +
44 void srs_discovery_tc_url( 84 void srs_discovery_tc_url(
45 string tcUrl, 85 string tcUrl,
46 string& schema, string& host, string& vhost, 86 string& schema, string& host, string& vhost,
@@ -77,38 +117,6 @@ void srs_discovery_tc_url( @@ -77,38 +117,6 @@ void srs_discovery_tc_url(
77 srs_vhost_resolve(vhost, app, param); 117 srs_vhost_resolve(vhost, app, param);
78 } 118 }
79 119
80 -void srs_vhost_resolve(string& vhost, string& app, string& param)  
81 -{  
82 - // get original param  
83 - size_t pos = 0;  
84 - if ((pos = app.find("?")) != std::string::npos) {  
85 - param = app.substr(pos);  
86 - }  
87 -  
88 - // filter tcUrl  
89 - app = srs_string_replace(app, ",", "?");  
90 - app = srs_string_replace(app, "...", "?");  
91 - app = srs_string_replace(app, "&&", "?");  
92 - app = srs_string_replace(app, "=", "?");  
93 -  
94 - if ((pos = app.find("?")) != std::string::npos) {  
95 - std::string query = app.substr(pos + 1);  
96 - app = app.substr(0, pos);  
97 -  
98 - if ((pos = query.find("vhost?")) != std::string::npos) {  
99 - query = query.substr(pos + 6);  
100 - if (!query.empty()) {  
101 - vhost = query;  
102 - }  
103 - if ((pos = vhost.find("?")) != std::string::npos) {  
104 - vhost = vhost.substr(0, pos);  
105 - }  
106 - }  
107 - }  
108 -  
109 - /* others */  
110 -}  
111 -  
112 void srs_random_generate(char* bytes, int size) 120 void srs_random_generate(char* bytes, int size)
113 { 121 {
114 static bool _random_initialized = false; 122 static bool _random_initialized = false;
@@ -63,18 +63,6 @@ extern void srs_discovery_tc_url( @@ -63,18 +63,6 @@ extern void srs_discovery_tc_url(
63 ); 63 );
64 64
65 /** 65 /**
66 -* resolve the vhost in query string  
67 -* @pram vhost, update the vhost if query contains the vhost.  
68 -* @param app, may contains the vhost in query string format:  
69 -* app?vhost=request_vhost  
70 -* app...vhost...request_vhost  
71 -* @param param, the query, for example, ?vhost=xxx  
72 -*/  
73 -extern void srs_vhost_resolve(  
74 - std::string& vhost, std::string& app, std::string& param  
75 -);  
76 -  
77 -/**  
78 * generate ramdom data for handshake. 66 * generate ramdom data for handshake.
79 */ 67 */
80 extern void srs_random_generate(char* bytes, int size); 68 extern void srs_random_generate(char* bytes, int size);
@@ -424,39 +424,6 @@ VOID TEST(ProtocolHandshakeTest, BytesEqual) @@ -424,39 +424,6 @@ VOID TEST(ProtocolHandshakeTest, BytesEqual)
424 } 424 }
425 425
426 /** 426 /**
427 -* resolve vhost from tcUrl.  
428 -*/  
429 -VOID TEST(ProtocolUtilityTest, VhostResolve)  
430 -{  
431 - std::string vhost = "vhost";  
432 - std::string app = "app";  
433 - std::string param;  
434 - srs_vhost_resolve(vhost, app, param);  
435 - EXPECT_STREQ("vhost", vhost.c_str());  
436 - EXPECT_STREQ("app", app.c_str());  
437 -  
438 - app = "app?vhost=changed";  
439 - srs_vhost_resolve(vhost, app, param);  
440 - EXPECT_STREQ("changed", vhost.c_str());  
441 - EXPECT_STREQ("app", app.c_str());  
442 -  
443 - app = "app?vhost=changed1&&query=true";  
444 - srs_vhost_resolve(vhost, app, param);  
445 - EXPECT_STREQ("changed1", vhost.c_str());  
446 - EXPECT_STREQ("app", app.c_str());  
447 -  
448 - app = "app?other=true&&vhost=changed2&&query=true";  
449 - srs_vhost_resolve(vhost, app, param);  
450 - EXPECT_STREQ("changed2", vhost.c_str());  
451 - EXPECT_STREQ("app", app.c_str());  
452 -  
453 - app = "app...other...true...vhost...changed3...query...true";  
454 - srs_vhost_resolve(vhost, app, param);  
455 - EXPECT_STREQ("changed3", vhost.c_str());  
456 - EXPECT_STREQ("app", app.c_str());  
457 -}  
458 -  
459 -/**  
460 * discovery tcUrl to schema/vhost/host/port/app 427 * discovery tcUrl to schema/vhost/host/port/app
461 */ 428 */
462 VOID TEST(ProtocolUtilityTest, DiscoveryTcUrl) 429 VOID TEST(ProtocolUtilityTest, DiscoveryTcUrl)