正在显示
6 个修改的文件
包含
57 行增加
和
12 行删除
| @@ -106,29 +106,25 @@ int srs_api_response_json_code(ISrsHttpResponseWriter* w, int code) | @@ -106,29 +106,25 @@ int srs_api_response_json_code(ISrsHttpResponseWriter* w, int code) | ||
| 106 | 106 | ||
| 107 | int srs_api_response(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string json) | 107 | int srs_api_response(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string json) |
| 108 | { | 108 | { |
| 109 | - string callback = r->query_get("callback"); | ||
| 110 | - bool jsonp = !callback.empty(); | ||
| 111 | - | ||
| 112 | // no jsonp, directly response. | 109 | // no jsonp, directly response. |
| 113 | - if (!jsonp) { | 110 | + if (!r->is_jsonp()) { |
| 114 | return srs_api_response_json(w, json); | 111 | return srs_api_response_json(w, json); |
| 115 | } | 112 | } |
| 116 | 113 | ||
| 117 | // jsonp, get function name from query("callback") | 114 | // jsonp, get function name from query("callback") |
| 115 | + string callback = r->query_get("callback"); | ||
| 118 | return srs_api_response_jsonp(w, callback, json); | 116 | return srs_api_response_jsonp(w, callback, json); |
| 119 | } | 117 | } |
| 120 | 118 | ||
| 121 | int srs_api_response_code(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, int code) | 119 | int srs_api_response_code(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, int code) |
| 122 | { | 120 | { |
| 123 | - string callback = r->query_get("callback"); | ||
| 124 | - bool jsonp = !callback.empty(); | ||
| 125 | - | ||
| 126 | // no jsonp, directly response. | 121 | // no jsonp, directly response. |
| 127 | - if (!jsonp) { | 122 | + if (!r->is_jsonp()) { |
| 128 | return srs_api_response_json_code(w, code); | 123 | return srs_api_response_json_code(w, code); |
| 129 | } | 124 | } |
| 130 | 125 | ||
| 131 | // jsonp, get function name from query("callback") | 126 | // jsonp, get function name from query("callback") |
| 127 | + string callback = r->query_get("callback"); | ||
| 132 | return srs_api_response_jsonp_code(w, callback, code); | 128 | return srs_api_response_jsonp_code(w, callback, code); |
| 133 | } | 129 | } |
| 134 | 130 |
| @@ -494,6 +494,7 @@ SrsHttpMessage::SrsHttpMessage(SrsStSocket* io, SrsConnection* c) : ISrsHttpMess | @@ -494,6 +494,7 @@ SrsHttpMessage::SrsHttpMessage(SrsStSocket* io, SrsConnection* c) : ISrsHttpMess | ||
| 494 | _uri = new SrsHttpUri(); | 494 | _uri = new SrsHttpUri(); |
| 495 | _body = new SrsHttpResponseReader(this, io); | 495 | _body = new SrsHttpResponseReader(this, io); |
| 496 | _http_ts_send_buffer = new char[SRS_HTTP_TS_SEND_BUFFER_SIZE]; | 496 | _http_ts_send_buffer = new char[SRS_HTTP_TS_SEND_BUFFER_SIZE]; |
| 497 | + jsonp = false; | ||
| 497 | } | 498 | } |
| 498 | 499 | ||
| 499 | SrsHttpMessage::~SrsHttpMessage() | 500 | SrsHttpMessage::~SrsHttpMessage() |
| @@ -570,6 +571,14 @@ int SrsHttpMessage::update(string url, http_parser* header, SrsFastBuffer* body, | @@ -570,6 +571,14 @@ int SrsHttpMessage::update(string url, http_parser* header, SrsFastBuffer* body, | ||
| 570 | _ext = ""; | 571 | _ext = ""; |
| 571 | } | 572 | } |
| 572 | 573 | ||
| 574 | + // parse jsonp request message. | ||
| 575 | + if (!query_get("callback").empty()) { | ||
| 576 | + jsonp = true; | ||
| 577 | + } | ||
| 578 | + if (jsonp) { | ||
| 579 | + jsonp_method = query_get("method"); | ||
| 580 | + } | ||
| 581 | + | ||
| 573 | return ret; | 582 | return ret; |
| 574 | } | 583 | } |
| 575 | 584 | ||
| @@ -580,6 +589,18 @@ SrsConnection* SrsHttpMessage::connection() | @@ -580,6 +589,18 @@ SrsConnection* SrsHttpMessage::connection() | ||
| 580 | 589 | ||
| 581 | u_int8_t SrsHttpMessage::method() | 590 | u_int8_t SrsHttpMessage::method() |
| 582 | { | 591 | { |
| 592 | + if (jsonp && !jsonp_method.empty()) { | ||
| 593 | + if (jsonp_method == "GET") { | ||
| 594 | + return SRS_CONSTS_HTTP_GET; | ||
| 595 | + } else if (jsonp_method == "PUT") { | ||
| 596 | + return SRS_CONSTS_HTTP_PUT; | ||
| 597 | + } else if (jsonp_method == "POST") { | ||
| 598 | + return SRS_CONSTS_HTTP_POST; | ||
| 599 | + } else if (jsonp_method == "DELETE") { | ||
| 600 | + return SRS_CONSTS_HTTP_DELETE; | ||
| 601 | + } | ||
| 602 | + } | ||
| 603 | + | ||
| 583 | return (u_int8_t)_header.method; | 604 | return (u_int8_t)_header.method; |
| 584 | } | 605 | } |
| 585 | 606 | ||
| @@ -590,6 +611,10 @@ u_int16_t SrsHttpMessage::status_code() | @@ -590,6 +611,10 @@ u_int16_t SrsHttpMessage::status_code() | ||
| 590 | 611 | ||
| 591 | string SrsHttpMessage::method_str() | 612 | string SrsHttpMessage::method_str() |
| 592 | { | 613 | { |
| 614 | + if (jsonp && !jsonp_method.empty()) { | ||
| 615 | + return jsonp_method; | ||
| 616 | + } | ||
| 617 | + | ||
| 593 | if (is_http_get()) { | 618 | if (is_http_get()) { |
| 594 | return "GET"; | 619 | return "GET"; |
| 595 | } | 620 | } |
| @@ -611,22 +636,22 @@ string SrsHttpMessage::method_str() | @@ -611,22 +636,22 @@ string SrsHttpMessage::method_str() | ||
| 611 | 636 | ||
| 612 | bool SrsHttpMessage::is_http_get() | 637 | bool SrsHttpMessage::is_http_get() |
| 613 | { | 638 | { |
| 614 | - return _header.method == SRS_CONSTS_HTTP_GET; | 639 | + return method() == SRS_CONSTS_HTTP_GET; |
| 615 | } | 640 | } |
| 616 | 641 | ||
| 617 | bool SrsHttpMessage::is_http_put() | 642 | bool SrsHttpMessage::is_http_put() |
| 618 | { | 643 | { |
| 619 | - return _header.method == SRS_CONSTS_HTTP_PUT; | 644 | + return method() == SRS_CONSTS_HTTP_PUT; |
| 620 | } | 645 | } |
| 621 | 646 | ||
| 622 | bool SrsHttpMessage::is_http_post() | 647 | bool SrsHttpMessage::is_http_post() |
| 623 | { | 648 | { |
| 624 | - return _header.method == SRS_CONSTS_HTTP_POST; | 649 | + return method() == SRS_CONSTS_HTTP_POST; |
| 625 | } | 650 | } |
| 626 | 651 | ||
| 627 | bool SrsHttpMessage::is_http_delete() | 652 | bool SrsHttpMessage::is_http_delete() |
| 628 | { | 653 | { |
| 629 | - return _header.method == SRS_CONSTS_HTTP_DELETE; | 654 | + return method() == SRS_CONSTS_HTTP_DELETE; |
| 630 | } | 655 | } |
| 631 | 656 | ||
| 632 | bool SrsHttpMessage::is_http_options() | 657 | bool SrsHttpMessage::is_http_options() |
| @@ -803,6 +828,11 @@ SrsRequest* SrsHttpMessage::to_request(string vhost) | @@ -803,6 +828,11 @@ SrsRequest* SrsHttpMessage::to_request(string vhost) | ||
| 803 | return req; | 828 | return req; |
| 804 | } | 829 | } |
| 805 | 830 | ||
| 831 | +bool SrsHttpMessage::is_jsonp() | ||
| 832 | +{ | ||
| 833 | + return jsonp; | ||
| 834 | +} | ||
| 835 | + | ||
| 806 | SrsHttpParser::SrsHttpParser() | 836 | SrsHttpParser::SrsHttpParser() |
| 807 | { | 837 | { |
| 808 | buffer = new SrsFastBuffer(); | 838 | buffer = new SrsFastBuffer(); |
| @@ -203,6 +203,10 @@ private: | @@ -203,6 +203,10 @@ private: | ||
| 203 | std::map<std::string, std::string> _query; | 203 | std::map<std::string, std::string> _query; |
| 204 | // the transport connection, can be NULL. | 204 | // the transport connection, can be NULL. |
| 205 | SrsConnection* conn; | 205 | SrsConnection* conn; |
| 206 | + // whether request is jsonp. | ||
| 207 | + bool jsonp; | ||
| 208 | + // the method in QueryString will override the HTTP method. | ||
| 209 | + std::string jsonp_method; | ||
| 206 | public: | 210 | public: |
| 207 | SrsHttpMessage(SrsStSocket* io, SrsConnection* c); | 211 | SrsHttpMessage(SrsStSocket* io, SrsConnection* c); |
| 208 | virtual ~SrsHttpMessage(); | 212 | virtual ~SrsHttpMessage(); |
| @@ -285,6 +289,8 @@ public: | @@ -285,6 +289,8 @@ public: | ||
| 285 | * @remark user must free the return request. | 289 | * @remark user must free the return request. |
| 286 | */ | 290 | */ |
| 287 | virtual SrsRequest* to_request(std::string vhost); | 291 | virtual SrsRequest* to_request(std::string vhost); |
| 292 | +public: | ||
| 293 | + virtual bool is_jsonp(); | ||
| 288 | }; | 294 | }; |
| 289 | 295 | ||
| 290 | /** | 296 | /** |
trunk/src/app/srs_app_statistic.cpp
100755 → 100644
| @@ -49,6 +49,7 @@ SrsStatisticVhost::SrsStatisticVhost() | @@ -49,6 +49,7 @@ SrsStatisticVhost::SrsStatisticVhost() | ||
| 49 | kbps->set_io(NULL, NULL); | 49 | kbps->set_io(NULL, NULL); |
| 50 | 50 | ||
| 51 | nb_clients = 0; | 51 | nb_clients = 0; |
| 52 | + nb_streams = 0; | ||
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | SrsStatisticVhost::~SrsStatisticVhost() | 55 | SrsStatisticVhost::~SrsStatisticVhost() |
| @@ -69,6 +70,7 @@ int SrsStatisticVhost::dumps(stringstream& ss) | @@ -69,6 +70,7 @@ int SrsStatisticVhost::dumps(stringstream& ss) | ||
| 69 | << SRS_JFIELD_STR("name", vhost) << SRS_JFIELD_CONT | 70 | << SRS_JFIELD_STR("name", vhost) << SRS_JFIELD_CONT |
| 70 | << SRS_JFIELD_BOOL("enabled", enabled) << SRS_JFIELD_CONT | 71 | << SRS_JFIELD_BOOL("enabled", enabled) << SRS_JFIELD_CONT |
| 71 | << SRS_JFIELD_ORG("clients", nb_clients) << SRS_JFIELD_CONT | 72 | << SRS_JFIELD_ORG("clients", nb_clients) << SRS_JFIELD_CONT |
| 73 | + << SRS_JFIELD_ORG("streams", nb_streams) << SRS_JFIELD_CONT | ||
| 72 | << SRS_JFIELD_ORG("send_bytes", kbps->get_send_bytes()) << SRS_JFIELD_CONT | 74 | << SRS_JFIELD_ORG("send_bytes", kbps->get_send_bytes()) << SRS_JFIELD_CONT |
| 73 | << SRS_JFIELD_ORG("recv_bytes", kbps->get_recv_bytes()) << SRS_JFIELD_CONT | 75 | << SRS_JFIELD_ORG("recv_bytes", kbps->get_recv_bytes()) << SRS_JFIELD_CONT |
| 74 | << SRS_JFIELD_OBJ("kbps") | 76 | << SRS_JFIELD_OBJ("kbps") |
| @@ -169,6 +171,8 @@ void SrsStatisticStream::publish(int cid) | @@ -169,6 +171,8 @@ void SrsStatisticStream::publish(int cid) | ||
| 169 | { | 171 | { |
| 170 | connection_cid = cid; | 172 | connection_cid = cid; |
| 171 | active = true; | 173 | active = true; |
| 174 | + | ||
| 175 | + vhost->nb_streams++; | ||
| 172 | } | 176 | } |
| 173 | 177 | ||
| 174 | void SrsStatisticStream::close() | 178 | void SrsStatisticStream::close() |
| @@ -176,6 +180,8 @@ void SrsStatisticStream::close() | @@ -176,6 +180,8 @@ void SrsStatisticStream::close() | ||
| 176 | has_video = false; | 180 | has_video = false; |
| 177 | has_audio = false; | 181 | has_audio = false; |
| 178 | active = false; | 182 | active = false; |
| 183 | + | ||
| 184 | + vhost->nb_streams--; | ||
| 179 | } | 185 | } |
| 180 | 186 | ||
| 181 | SrsStatisticClient::SrsStatisticClient() | 187 | SrsStatisticClient::SrsStatisticClient() |
trunk/src/app/srs_app_statistic.hpp
100755 → 100644
| @@ -527,6 +527,12 @@ public: | @@ -527,6 +527,12 @@ public: | ||
| 527 | virtual int request_header_count() = 0; | 527 | virtual int request_header_count() = 0; |
| 528 | virtual std::string request_header_key_at(int index) = 0; | 528 | virtual std::string request_header_key_at(int index) = 0; |
| 529 | virtual std::string request_header_value_at(int index) = 0; | 529 | virtual std::string request_header_value_at(int index) = 0; |
| 530 | +public: | ||
| 531 | + /** | ||
| 532 | + * whether the current request is JSONP, | ||
| 533 | + * which has a "callback=xxx" in QueryString. | ||
| 534 | + */ | ||
| 535 | + virtual bool is_jsonp() = 0; | ||
| 530 | }; | 536 | }; |
| 531 | 537 | ||
| 532 | #endif | 538 | #endif |
-
请 注册 或 登录 后发表评论