正在显示
3 个修改的文件
包含
31 行增加
和
27 行删除
| @@ -58,6 +58,7 @@ using namespace std; | @@ -58,6 +58,7 @@ using namespace std; | ||
| 58 | #include <srs_protocol_json.hpp> | 58 | #include <srs_protocol_json.hpp> |
| 59 | #include <srs_app_http_hooks.hpp> | 59 | #include <srs_app_http_hooks.hpp> |
| 60 | #include <srs_protocol_amf0.hpp> | 60 | #include <srs_protocol_amf0.hpp> |
| 61 | +#include <srs_app_utility.hpp> | ||
| 61 | 62 | ||
| 62 | #endif | 63 | #endif |
| 63 | 64 | ||
| @@ -541,11 +542,10 @@ int SrsHttpMessage::update(string url, bool allow_jsonp, http_parser* header, Sr | @@ -541,11 +542,10 @@ int SrsHttpMessage::update(string url, bool allow_jsonp, http_parser* header, Sr | ||
| 541 | // parse uri from url. | 542 | // parse uri from url. |
| 542 | std::string host = get_request_header("Host"); | 543 | std::string host = get_request_header("Host"); |
| 543 | 544 | ||
| 544 | - // donot parse the empty host for uri, | ||
| 545 | - // for example, the response contains no host, | ||
| 546 | - // ignore it is ok. | 545 | + // use server public ip when no host specified. |
| 546 | + // to make telnet happy. | ||
| 547 | if (host.empty()) { | 547 | if (host.empty()) { |
| 548 | - return ret; | 548 | + host= srs_get_public_internet_address(); |
| 549 | } | 549 | } |
| 550 | 550 | ||
| 551 | // parse uri to schema/server:port/path?query | 551 | // parse uri to schema/server:port/path?query |
| @@ -554,32 +554,12 @@ int SrsHttpMessage::update(string url, bool allow_jsonp, http_parser* header, Sr | @@ -554,32 +554,12 @@ int SrsHttpMessage::update(string url, bool allow_jsonp, http_parser* header, Sr | ||
| 554 | return ret; | 554 | return ret; |
| 555 | } | 555 | } |
| 556 | 556 | ||
| 557 | - // must format as key=value&...&keyN=valueN | ||
| 558 | - std::string q = _uri->get_query(); | ||
| 559 | - size_t pos = string::npos; | ||
| 560 | - while (!q.empty()) { | ||
| 561 | - std::string k = q; | ||
| 562 | - if ((pos = q.find("=")) != string::npos) { | ||
| 563 | - k = q.substr(0, pos); | ||
| 564 | - q = q.substr(pos + 1); | ||
| 565 | - } else { | ||
| 566 | - q = ""; | ||
| 567 | - } | ||
| 568 | - | ||
| 569 | - std::string v = q; | ||
| 570 | - if ((pos = q.find("&")) != string::npos) { | ||
| 571 | - v = q.substr(0, pos); | ||
| 572 | - q = q.substr(pos + 1); | ||
| 573 | - } else { | ||
| 574 | - q = ""; | ||
| 575 | - } | ||
| 576 | - | ||
| 577 | - _query[k] = v; | ||
| 578 | - } | ||
| 579 | - | ||
| 580 | // parse ext. | 557 | // parse ext. |
| 581 | _ext = srs_path_filext(_uri->get_path()); | 558 | _ext = srs_path_filext(_uri->get_path()); |
| 582 | 559 | ||
| 560 | + // parse query string. | ||
| 561 | + srs_parse_query_string(_uri->get_query(), _query); | ||
| 562 | + | ||
| 583 | // parse jsonp request message. | 563 | // parse jsonp request message. |
| 584 | if (allow_jsonp) { | 564 | if (allow_jsonp) { |
| 585 | if (!query_get("callback").empty()) { | 565 | if (!query_get("callback").empty()) { |
| @@ -654,6 +654,9 @@ extern void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps); | @@ -654,6 +654,9 @@ extern void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps); | ||
| 654 | // get local ip, fill to @param ips | 654 | // get local ip, fill to @param ips |
| 655 | extern std::vector<std::string>& srs_get_local_ipv4_ips(); | 655 | extern std::vector<std::string>& srs_get_local_ipv4_ips(); |
| 656 | 656 | ||
| 657 | +// get local public ip, empty string if no public internet address found. | ||
| 658 | +extern std::string srs_get_public_internet_address(); | ||
| 659 | + | ||
| 657 | // get local or peer ip. | 660 | // get local or peer ip. |
| 658 | // where local ip is the server ip which client connected. | 661 | // where local ip is the server ip which client connected. |
| 659 | extern std::string srs_get_local_ip(int fd); | 662 | extern std::string srs_get_local_ip(int fd); |
| @@ -117,6 +117,27 @@ void srs_discovery_tc_url( | @@ -117,6 +117,27 @@ void srs_discovery_tc_url( | ||
| 117 | srs_vhost_resolve(vhost, app, param); | 117 | srs_vhost_resolve(vhost, app, param); |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | +void srs_parse_query_string(string q, map<string,string>& query) | ||
| 121 | +{ | ||
| 122 | + // query string flags. | ||
| 123 | + static vector<string> flags; | ||
| 124 | + if (flags.empty()) { | ||
| 125 | + flags.push_back("="); | ||
| 126 | + flags.push_back(","); | ||
| 127 | + flags.push_back("&&"); | ||
| 128 | + flags.push_back("&"); | ||
| 129 | + flags.push_back(";"); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + vector<string> kvs = srs_string_split(q, flags); | ||
| 133 | + for (int i = 0; i < (int)kvs.size(); i+=2) { | ||
| 134 | + string k = kvs.at(i); | ||
| 135 | + string v = (i < (int)kvs.size() - 1)? kvs.at(i+1):""; | ||
| 136 | + | ||
| 137 | + query[k] = v; | ||
| 138 | + } | ||
| 139 | +} | ||
| 140 | + | ||
| 120 | void srs_random_generate(char* bytes, int size) | 141 | void srs_random_generate(char* bytes, int size) |
| 121 | { | 142 | { |
| 122 | static bool _random_initialized = false; | 143 | static bool _random_initialized = false; |
-
请 注册 或 登录 后发表评论