diff --git a/README.md b/README.md index fa74d56d5..d6b653a89 100755 --- a/README.md +++ b/README.md @@ -501,6 +501,7 @@ Supported operating systems and hardware: * 2013-10-17, Created.
## History +* v2.0, 2014-01-02, fix [#158](https://github.com/winlinvip/simple-rtmp-server/issues/158), http-callback check http status code ok(200). 2.0.84 * v2.0, 2015-01-02, hotfix [#216](https://github.com/winlinvip/simple-rtmp-server/issues/216), http-callback post in application/json content-type. 2.0.83 * v2.0, 2014-01-02, fix [#263](https://github.com/winlinvip/simple-rtmp-server/issues/263), srs-librtmp flv read tag should init size. 2.0.82 * v2.0, 2015-01-01, hotfix [#270](https://github.com/winlinvip/simple-rtmp-server/issues/270), memory leak for http client post. 2.0.81 diff --git a/trunk/research/api-server/server.py b/trunk/research/api-server/server.py index ff4c062db..6b6d6a858 100755 --- a/trunk/research/api-server/server.py +++ b/trunk/research/api-server/server.py @@ -87,6 +87,7 @@ class RESTClients(object): "action": "on_connect", "client_id": 1985, "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", + "tcUrl": "rtmp://video.test.com/live?key=d2fa801d08e3f90ed1e1670e6e52651a", "pageUrl": "http://www.test.com/live.html" } on_close: @@ -118,6 +119,7 @@ class RESTClients(object): action = json_req["action"] if action == "on_connect": + raise cherrypy.HTTPError(401) code = self.__on_connect(json_req) elif action == "on_close": code = self.__on_close(json_req) diff --git a/trunk/src/app/srs_app_heartbeat.cpp b/trunk/src/app/srs_app_heartbeat.cpp index a7cdc5ff0..a8828c1d8 100644 --- a/trunk/src/app/srs_app_heartbeat.cpp +++ b/trunk/src/app/srs_app_heartbeat.cpp @@ -75,9 +75,10 @@ void SrsHttpHeartbeat::heartbeat() ss << __SRS_JOBJECT_END; std::string data = ss.str(); std::string res; + int status_code; SrsHttpClient http; - if ((ret = http.post(&uri, data, res)) != ERROR_SUCCESS) { + if ((ret = http.post(&uri, data, status_code, res)) != ERROR_SUCCESS) { srs_info("http post hartbeart uri failed. " "url=%s, request=%s, response=%s, ret=%d", url.c_str(), data.c_str(), res.c_str(), ret); @@ -85,8 +86,8 @@ void SrsHttpHeartbeat::heartbeat() } srs_info("http hook hartbeart success. " - "url=%s, request=%s, response=%s, ret=%d", - url.c_str(), data.c_str(), res.c_str(), ret); + "url=%s, request=%s, status_code=%d, response=%s, ret=%d", + url.c_str(), data.c_str(), status_code, res.c_str(), ret); return; } diff --git a/trunk/src/app/srs_app_http.cpp b/trunk/src/app/srs_app_http.cpp index 499b9cee8..c6d542ba0 100644 --- a/trunk/src/app/srs_app_http.cpp +++ b/trunk/src/app/srs_app_http.cpp @@ -593,6 +593,11 @@ u_int8_t SrsHttpMessage::method() return (u_int8_t)_header.method; } +u_int16_t SrsHttpMessage::status_code() +{ + return (u_int16_t)_header.status_code; +} + string SrsHttpMessage::method_str() { if (is_http_get()) { diff --git a/trunk/src/app/srs_app_http.hpp b/trunk/src/app/srs_app_http.hpp index 77fd120af..7ea2ec7b1 100644 --- a/trunk/src/app/srs_app_http.hpp +++ b/trunk/src/app/srs_app_http.hpp @@ -249,6 +249,7 @@ public: public: virtual bool is_complete(); virtual u_int8_t method(); + virtual u_int16_t status_code(); virtual std::string method_str(); virtual bool is_http_get(); virtual bool is_http_put(); diff --git a/trunk/src/app/srs_app_http_client.cpp b/trunk/src/app/srs_app_http_client.cpp index 71e2e6b3a..d3d57ac30 100644 --- a/trunk/src/app/srs_app_http_client.cpp +++ b/trunk/src/app/srs_app_http_client.cpp @@ -52,7 +52,7 @@ SrsHttpClient::~SrsHttpClient() srs_freep(parser); } -int SrsHttpClient::post(SrsHttpUri* uri, string req, string& res) +int SrsHttpClient::post(SrsHttpUri* uri, string req, int& status_code, string& res) { res = ""; @@ -105,6 +105,8 @@ int SrsHttpClient::post(SrsHttpUri* uri, string req, string& res) srs_assert(msg); srs_assert(msg->is_complete()); + status_code = (int)msg->status_code(); + // get response body. if (msg->body_size() > 0) { res = msg->body(); diff --git a/trunk/src/app/srs_app_http_client.hpp b/trunk/src/app/srs_app_http_client.hpp index 245c79490..1ffef3bc9 100644 --- a/trunk/src/app/srs_app_http_client.hpp +++ b/trunk/src/app/srs_app_http_client.hpp @@ -54,9 +54,10 @@ public: /** * to post data to the uri. * @param req the data post to uri. - * @param res the response data from server. + * @param status_code the output status code response by server. + * @param res output the response data from server. */ - virtual int post(SrsHttpUri* uri, std::string req, std::string& res); + virtual int post(SrsHttpUri* uri, std::string req, int& status_code, std::string& res); private: virtual void disconnect(); virtual int connect(SrsHttpUri* uri); diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index 6fc7d0f75..5d792c6a7 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -36,7 +36,7 @@ using namespace std; #include #include -#define SRS_HTTP_RESPONSE_OK "0" +#define SRS_HTTP_RESPONSE_OK __SRS_XSTR(ERROR_SUCCESS) #define SRS_HTTP_HEADER_BUFFER 1024 #define SRS_HTTP_BODY_BUFFER 32 * 1024 @@ -72,15 +72,25 @@ int SrsHttpHooks::on_connect(string url, int client_id, string ip, SrsRequest* r << __SRS_JOBJECT_END; std::string data = ss.str(); std::string res; + int status_code; SrsHttpClient http; - if ((ret = http.post(&uri, data, res)) != ERROR_SUCCESS) { + if ((ret = http.post(&uri, data, status_code, res)) != ERROR_SUCCESS) { srs_error("http post on_connect uri failed. " "client_id=%d, url=%s, request=%s, response=%s, ret=%d", client_id, url.c_str(), data.c_str(), res.c_str(), ret); return ret; } + // ensure the http status is ok. + // https://github.com/winlinvip/simple-rtmp-server/issues/158 + if (status_code != SRS_CONSTS_HTTP_OK) { + ret = ERROR_HTTP_STATUS_INVLIAD; + srs_error("http hook on_connect status failed. " + "client_id=%d, code=%d, ret=%d", client_id, status_code, ret); + return ret; + } + if (res.empty() || res != SRS_HTTP_RESPONSE_OK) { ret = ERROR_HTTP_DATA_INVLIAD; srs_error("http hook on_connect validate failed. " @@ -117,15 +127,25 @@ void SrsHttpHooks::on_close(string url, int client_id, string ip, SrsRequest* re << __SRS_JOBJECT_END; std::string data = ss.str(); std::string res; + int status_code; SrsHttpClient http; - if ((ret = http.post(&uri, data, res)) != ERROR_SUCCESS) { + if ((ret = http.post(&uri, data, status_code, res)) != ERROR_SUCCESS) { srs_warn("http post on_close uri failed, ignored. " "client_id=%d, url=%s, request=%s, response=%s, ret=%d", client_id, url.c_str(), data.c_str(), res.c_str(), ret); return; } + // ensure the http status is ok. + // https://github.com/winlinvip/simple-rtmp-server/issues/158 + if (status_code != SRS_CONSTS_HTTP_OK) { + ret = ERROR_HTTP_STATUS_INVLIAD; + srs_error("http hook on_close status failed. " + "client_id=%d, code=%d, ret=%d", client_id, status_code, ret); + return; + } + if (res.empty() || res != SRS_HTTP_RESPONSE_OK) { ret = ERROR_HTTP_DATA_INVLIAD; srs_warn("http hook on_close validate failed, ignored. " @@ -163,15 +183,25 @@ int SrsHttpHooks::on_publish(string url, int client_id, string ip, SrsRequest* r << __SRS_JOBJECT_END; std::string data = ss.str(); std::string res; + int status_code; SrsHttpClient http; - if ((ret = http.post(&uri, data, res)) != ERROR_SUCCESS) { + if ((ret = http.post(&uri, data, status_code, res)) != ERROR_SUCCESS) { srs_error("http post on_publish uri failed. " "client_id=%d, url=%s, request=%s, response=%s, ret=%d", client_id, url.c_str(), data.c_str(), res.c_str(), ret); return ret; } + // ensure the http status is ok. + // https://github.com/winlinvip/simple-rtmp-server/issues/158 + if (status_code != SRS_CONSTS_HTTP_OK) { + ret = ERROR_HTTP_STATUS_INVLIAD; + srs_error("http hook on_publish status failed. " + "client_id=%d, code=%d, ret=%d", client_id, status_code, ret); + return ret; + } + if (res.empty() || res != SRS_HTTP_RESPONSE_OK) { ret = ERROR_HTTP_DATA_INVLIAD; srs_error("http hook on_publish validate failed. " @@ -209,15 +239,25 @@ void SrsHttpHooks::on_unpublish(string url, int client_id, string ip, SrsRequest << __SRS_JOBJECT_END; std::string data = ss.str(); std::string res; + int status_code; SrsHttpClient http; - if ((ret = http.post(&uri, data, res)) != ERROR_SUCCESS) { + if ((ret = http.post(&uri, data, status_code, res)) != ERROR_SUCCESS) { srs_warn("http post on_unpublish uri failed, ignored. " "client_id=%d, url=%s, request=%s, response=%s, ret=%d", client_id, url.c_str(), data.c_str(), res.c_str(), ret); return; } + // ensure the http status is ok. + // https://github.com/winlinvip/simple-rtmp-server/issues/158 + if (status_code != SRS_CONSTS_HTTP_OK) { + ret = ERROR_HTTP_STATUS_INVLIAD; + srs_error("http hook on_unpublish status failed. " + "client_id=%d, code=%d, ret=%d", client_id, status_code, ret); + return; + } + if (res.empty() || res != SRS_HTTP_RESPONSE_OK) { ret = ERROR_HTTP_DATA_INVLIAD; srs_warn("http hook on_unpublish validate failed, ignored. " @@ -255,15 +295,25 @@ int SrsHttpHooks::on_play(string url, int client_id, string ip, SrsRequest* req) << __SRS_JOBJECT_END; std::string data = ss.str(); std::string res; + int status_code; SrsHttpClient http; - if ((ret = http.post(&uri, data, res)) != ERROR_SUCCESS) { + if ((ret = http.post(&uri, data, status_code, res)) != ERROR_SUCCESS) { srs_error("http post on_play uri failed. " "client_id=%d, url=%s, request=%s, response=%s, ret=%d", client_id, url.c_str(), data.c_str(), res.c_str(), ret); return ret; } + // ensure the http status is ok. + // https://github.com/winlinvip/simple-rtmp-server/issues/158 + if (status_code != SRS_CONSTS_HTTP_OK) { + ret = ERROR_HTTP_STATUS_INVLIAD; + srs_error("http hook on_play status failed. " + "client_id=%d, code=%d, ret=%d", client_id, status_code, ret); + return ret; + } + if (res.empty() || res != SRS_HTTP_RESPONSE_OK) { ret = ERROR_HTTP_DATA_INVLIAD; srs_error("http hook on_play validate failed. " @@ -301,15 +351,25 @@ void SrsHttpHooks::on_stop(string url, int client_id, string ip, SrsRequest* req << __SRS_JOBJECT_END; std::string data = ss.str(); std::string res; + int status_code; SrsHttpClient http; - if ((ret = http.post(&uri, data, res)) != ERROR_SUCCESS) { + if ((ret = http.post(&uri, data, status_code, res)) != ERROR_SUCCESS) { srs_warn("http post on_stop uri failed, ignored. " "client_id=%d, url=%s, request=%s, response=%s, ret=%d", client_id, url.c_str(), data.c_str(), res.c_str(), ret); return; } + // ensure the http status is ok. + // https://github.com/winlinvip/simple-rtmp-server/issues/158 + if (status_code != SRS_CONSTS_HTTP_OK) { + ret = ERROR_HTTP_STATUS_INVLIAD; + srs_error("http hook on_stop status failed. " + "client_id=%d, code=%d, ret=%d", client_id, status_code, ret); + return; + } + if (res.empty() || res != SRS_HTTP_RESPONSE_OK) { ret = ERROR_HTTP_DATA_INVLIAD; srs_warn("http hook on_stop validate failed, ignored. " diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 7c0b04be9..e55faf24e 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 83 +#define VERSION_REVISION 84 // server info. #define RTMP_SIG_SRS_KEY "SRS" #define RTMP_SIG_SRS_ROLE "origin/edge server" diff --git a/trunk/src/kernel/srs_kernel_error.hpp b/trunk/src/kernel/srs_kernel_error.hpp index 7d3bb3a16..7bbfeb525 100644 --- a/trunk/src/kernel/srs_kernel_error.hpp +++ b/trunk/src/kernel/srs_kernel_error.hpp @@ -196,6 +196,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define ERROR_AAC_REQUIRED_ADTS 3046 #define ERROR_AAC_ADTS_HEADER 3047 #define ERROR_AAC_DATA_INVALID 3048 +#define ERROR_HTTP_STATUS_INVLIAD 3049 /** * whether the error code is an system control error.