1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

fix #158: http-callback check http status code ok(200). 2.0.84

This commit is contained in:
winlin 2015-01-02 10:21:04 +08:00
parent 8df0f724d6
commit 9d34820c80
10 changed files with 88 additions and 14 deletions

View file

@ -501,6 +501,7 @@ Supported operating systems and hardware:
* 2013-10-17, Created.<br/>
## 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

View file

@ -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)

View file

@ -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;
}

View file

@ -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()) {

View file

@ -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();

View file

@ -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();

View file

@ -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);

View file

@ -36,7 +36,7 @@ using namespace std;
#include <srs_app_dvr.hpp>
#include <srs_app_http_client.hpp>
#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. "

View file

@ -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"

View file

@ -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.