Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2015-03-06 11:51:20 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
964e4be9d4e0bebd6f6f772a45b4e39c86204313
964e4be9
1 parent
3982ec1d
refine http request post. 2.0.132.
隐藏空白字符变更
内嵌
并排对比
正在显示
6 个修改的文件
包含
85 行增加
和
256 行删除
trunk/src/app/srs_app_heartbeat.cpp
trunk/src/app/srs_app_http.cpp
trunk/src/app/srs_app_http_client.cpp
trunk/src/app/srs_app_http_client.hpp
trunk/src/app/srs_app_http_hooks.cpp
trunk/src/app/srs_app_http_hooks.hpp
trunk/src/app/srs_app_heartbeat.cpp
查看文件 @
964e4be
...
...
@@ -35,6 +35,7 @@ using namespace std;
#include <srs_app_json.hpp>
#include <srs_app_http.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>
SrsHttpHeartbeat
::
SrsHttpHeartbeat
()
{
...
...
@@ -73,17 +74,22 @@ void SrsHttpHeartbeat::heartbeat()
srs_api_dump_summaries
(
ss
);
}
ss
<<
__SRS_JOBJECT_END
;
std
::
string
data
=
ss
.
str
();
std
::
string
res
;
int
status_code
;
std
::
string
data
=
ss
.
str
();
SrsHttpClient
http
;
if
((
ret
=
http
.
post
(
&
uri
,
data
,
status_code
,
res
))
!=
ERROR_SUCCESS
)
{
SrsHttpMessage
*
msg
=
NULL
;
if
((
ret
=
http
.
post
(
&
uri
,
data
,
&
msg
))
!=
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
);
return
;
}
SrsAutoFree
(
SrsHttpMessage
,
msg
);
std
::
string
res
;
if
((
ret
=
msg
->
body_read_all
(
res
))
!=
ERROR_SUCCESS
)
{
return
;
}
srs_info
(
"http hook hartbeart success. "
"url=%s, request=%s, status_code=%d, response=%s, ret=%d"
,
...
...
trunk/src/app/srs_app_http.cpp
查看文件 @
964e4be
...
...
@@ -1181,22 +1181,8 @@ int SrsHttpMessage::body_read_all(string& body)
{
int
ret
=
ERROR_SUCCESS
;
// chunked, always read with
if
(
chunked
)
{
return
_body
->
read
(
body
);
}
int
content_length
=
(
int
)(
int64_t
)
_header
.
content_length
;
// ignore if not set, should be zero length body.
if
(
content_length
<=
0
)
{
srs_info
(
"unspecified content-length with body empty."
);
return
ret
;
}
// when content length specified, read specified length.
int
expect
=
content_length
+
(
int
)
body
.
length
();
while
((
int
)
body
.
length
()
<
expect
)
{
// whatever, read util EOF.
while
(
!
_body
->
eof
())
{
if
((
ret
=
_body
->
read
(
body
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
trunk/src/app/srs_app_http_client.cpp
查看文件 @
964e4be
...
...
@@ -54,9 +54,9 @@ SrsHttpClient::~SrsHttpClient()
srs_freep
(
parser
);
}
int
SrsHttpClient
::
post
(
SrsHttpUri
*
uri
,
string
req
,
int
&
status_code
,
string
&
res
)
int
SrsHttpClient
::
post
(
SrsHttpUri
*
uri
,
string
req
,
SrsHttpMessage
**
ppmsg
)
{
res
=
""
;
*
ppmsg
=
NULL
;
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -103,16 +103,7 @@ int SrsHttpClient::post(SrsHttpUri* uri, string req, int& status_code, string& r
}
srs_assert
(
msg
);
// always free it in this scope.
SrsAutoFree
(
SrsHttpMessage
,
msg
);
status_code
=
(
int
)
msg
->
status_code
();
// get response body.
if
((
ret
=
msg
->
body_read_all
(
res
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
*
ppmsg
=
msg
;
srs_info
(
"parse http post response success."
);
return
ret
;
...
...
trunk/src/app/srs_app_http_client.hpp
查看文件 @
964e4be
...
...
@@ -57,10 +57,9 @@ public:
/**
* to post data to the uri.
* @param req the data post to uri. empty string to ignore.
* @param status_code the output status code response by server.
* @param res output the response data from server.
* @param ppmsg output the http message to read the response.
*/
virtual
int
post
(
SrsHttpUri
*
uri
,
std
::
string
req
,
int
&
status_code
,
std
::
string
&
res
);
virtual
int
post
(
SrsHttpUri
*
uri
,
std
::
string
req
,
SrsHttpMessage
**
ppmsg
);
/**
* to get data from the uri.
* @param req the data post to uri. empty string to ignore.
...
...
trunk/src/app/srs_app_http_hooks.cpp
查看文件 @
964e4be
...
...
@@ -35,6 +35,7 @@ using namespace std;
#include <srs_app_json.hpp>
#include <srs_app_dvr.hpp>
#include <srs_app_http_client.hpp>
#include <srs_core_autofree.hpp>
#define SRS_HTTP_RESPONSE_OK __SRS_XSTR(ERROR_SUCCESS)
...
...
@@ -53,13 +54,6 @@ int SrsHttpHooks::on_connect(string url, int client_id, string ip, SrsRequest* r
{
int
ret
=
ERROR_SUCCESS
;
SrsHttpUri
uri
;
if
((
ret
=
uri
.
initialize
(
url
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"http uri parse on_connect url failed. "
"client_id=%d, url=%s, ret=%d"
,
client_id
,
url
.
c_str
(),
ret
);
return
ret
;
}
std
::
stringstream
ss
;
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_STR
(
"action"
,
"on_connect"
)
<<
__SRS_JFIELD_CONT
...
...
@@ -70,31 +64,14 @@ int SrsHttpHooks::on_connect(string url, int client_id, string ip, SrsRequest* r
<<
__SRS_JFIELD_STR
(
"tcUrl"
,
req
->
tcUrl
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"pageUrl"
,
req
->
pageUrl
)
<<
__SRS_JOBJECT_END
;
std
::
string
data
=
ss
.
str
();
std
::
string
res
;
int
status_code
;
SrsHttpClient
http
;
if
((
ret
=
http
.
post
(
&
uri
,
data
,
status_code
,
res
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
do_post
(
url
,
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. "
"client_id=%d, res=%s, ret=%d"
,
client_id
,
res
.
c_str
(),
ret
);
"client_id=%d, url=%s, request=%s, response=%s, code=%d, ret=%d"
,
client_id
,
url
.
c_str
(),
data
.
c_str
(),
res
.
c_str
(),
status_code
,
ret
);
return
ret
;
}
...
...
@@ -109,13 +86,6 @@ void SrsHttpHooks::on_close(string url, int client_id, string ip, SrsRequest* re
{
int
ret
=
ERROR_SUCCESS
;
SrsHttpUri
uri
;
if
((
ret
=
uri
.
initialize
(
url
))
!=
ERROR_SUCCESS
)
{
srs_warn
(
"http uri parse on_close url failed, ignored. "
"client_id=%d, url=%s, ret=%d"
,
client_id
,
url
.
c_str
(),
ret
);
return
;
}
std
::
stringstream
ss
;
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_STR
(
"action"
,
"on_close"
)
<<
__SRS_JFIELD_CONT
...
...
@@ -124,31 +94,14 @@ void SrsHttpHooks::on_close(string url, int client_id, string ip, SrsRequest* re
<<
__SRS_JFIELD_STR
(
"vhost"
,
req
->
vhost
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"app"
,
req
->
app
)
<<
__SRS_JOBJECT_END
;
std
::
string
data
=
ss
.
str
();
std
::
string
res
;
int
status_code
;
SrsHttpClient
http
;
if
((
ret
=
http
.
post
(
&
uri
,
data
,
status_code
,
res
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
do_post
(
url
,
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. "
"client_id=%d, res=%s, ret=%d"
,
client_id
,
res
.
c_str
(),
ret
);
"client_id=%d, url=%s, request=%s, response=%s, code=%d, ret=%d"
,
client_id
,
url
.
c_str
(),
data
.
c_str
(),
res
.
c_str
(),
status_code
,
ret
);
return
;
}
...
...
@@ -163,13 +116,6 @@ int SrsHttpHooks::on_publish(string url, int client_id, string ip, SrsRequest* r
{
int
ret
=
ERROR_SUCCESS
;
SrsHttpUri
uri
;
if
((
ret
=
uri
.
initialize
(
url
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"http uri parse on_publish url failed. "
"client_id=%d, url=%s, ret=%d"
,
client_id
,
url
.
c_str
(),
ret
);
return
ret
;
}
std
::
stringstream
ss
;
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_STR
(
"action"
,
"on_publish"
)
<<
__SRS_JFIELD_CONT
...
...
@@ -179,31 +125,14 @@ int SrsHttpHooks::on_publish(string url, int client_id, string ip, SrsRequest* r
<<
__SRS_JFIELD_STR
(
"app"
,
req
->
app
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"stream"
,
req
->
stream
)
<<
__SRS_JOBJECT_END
;
std
::
string
data
=
ss
.
str
();
std
::
string
res
;
int
status_code
;
SrsHttpClient
http
;
if
((
ret
=
http
.
post
(
&
uri
,
data
,
status_code
,
res
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
do_post
(
url
,
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. "
"client_id=%d, res=%s, ret=%d"
,
client_id
,
res
.
c_str
(),
ret
);
"client_id=%d, url=%s, request=%s, response=%s, code=%d, ret=%d"
,
client_id
,
url
.
c_str
(),
data
.
c_str
(),
res
.
c_str
(),
status_code
,
ret
);
return
ret
;
}
...
...
@@ -218,13 +147,6 @@ void SrsHttpHooks::on_unpublish(string url, int client_id, string ip, SrsRequest
{
int
ret
=
ERROR_SUCCESS
;
SrsHttpUri
uri
;
if
((
ret
=
uri
.
initialize
(
url
))
!=
ERROR_SUCCESS
)
{
srs_warn
(
"http uri parse on_unpublish url failed, ignored. "
"client_id=%d, url=%s, ret=%d"
,
client_id
,
url
.
c_str
(),
ret
);
return
;
}
std
::
stringstream
ss
;
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_STR
(
"action"
,
"on_unpublish"
)
<<
__SRS_JFIELD_CONT
...
...
@@ -234,31 +156,14 @@ void SrsHttpHooks::on_unpublish(string url, int client_id, string ip, SrsRequest
<<
__SRS_JFIELD_STR
(
"app"
,
req
->
app
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"stream"
,
req
->
stream
)
<<
__SRS_JOBJECT_END
;
std
::
string
data
=
ss
.
str
();
std
::
string
res
;
int
status_code
;
SrsHttpClient
http
;
if
((
ret
=
http
.
post
(
&
uri
,
data
,
status_code
,
res
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
do_post
(
url
,
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. "
"client_id=%d, res=%s, ret=%d"
,
client_id
,
res
.
c_str
(),
ret
);
"client_id=%d, url=%s, request=%s, response=%s, code=%d, ret=%d"
,
client_id
,
url
.
c_str
(),
data
.
c_str
(),
res
.
c_str
(),
status_code
,
ret
);
return
;
}
...
...
@@ -273,13 +178,6 @@ int SrsHttpHooks::on_play(string url, int client_id, string ip, SrsRequest* req)
{
int
ret
=
ERROR_SUCCESS
;
SrsHttpUri
uri
;
if
((
ret
=
uri
.
initialize
(
url
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"http uri parse on_play url failed. "
"client_id=%d, url=%s, ret=%d"
,
client_id
,
url
.
c_str
(),
ret
);
return
ret
;
}
std
::
stringstream
ss
;
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_STR
(
"action"
,
"on_play"
)
<<
__SRS_JFIELD_CONT
...
...
@@ -289,31 +187,14 @@ int SrsHttpHooks::on_play(string url, int client_id, string ip, SrsRequest* req)
<<
__SRS_JFIELD_STR
(
"app"
,
req
->
app
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"stream"
,
req
->
stream
)
<<
__SRS_JOBJECT_END
;
std
::
string
data
=
ss
.
str
();
std
::
string
res
;
int
status_code
;
SrsHttpClient
http
;
if
((
ret
=
http
.
post
(
&
uri
,
data
,
status_code
,
res
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
do_post
(
url
,
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. "
"client_id=%d, res=%s, ret=%d"
,
client_id
,
res
.
c_str
(),
ret
);
"client_id=%d, url=%s, request=%s, response=%s, code=%d, ret=%d"
,
client_id
,
url
.
c_str
(),
data
.
c_str
(),
res
.
c_str
(),
status_code
,
ret
);
return
ret
;
}
...
...
@@ -328,13 +209,6 @@ void SrsHttpHooks::on_stop(string url, int client_id, string ip, SrsRequest* req
{
int
ret
=
ERROR_SUCCESS
;
SrsHttpUri
uri
;
if
((
ret
=
uri
.
initialize
(
url
))
!=
ERROR_SUCCESS
)
{
srs_warn
(
"http uri parse on_stop url failed, ignored. "
"client_id=%d, url=%s, ret=%d"
,
client_id
,
url
.
c_str
(),
ret
);
return
;
}
std
::
stringstream
ss
;
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_STR
(
"action"
,
"on_stop"
)
<<
__SRS_JFIELD_CONT
...
...
@@ -344,31 +218,14 @@ void SrsHttpHooks::on_stop(string url, int client_id, string ip, SrsRequest* req
<<
__SRS_JFIELD_STR
(
"app"
,
req
->
app
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"stream"
,
req
->
stream
)
<<
__SRS_JOBJECT_END
;
std
::
string
data
=
ss
.
str
();
std
::
string
res
;
int
status_code
;
SrsHttpClient
http
;
if
((
ret
=
http
.
post
(
&
uri
,
data
,
status_code
,
res
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
do_post
(
url
,
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. "
"client_id=%d, res=%s, ret=%d"
,
client_id
,
res
.
c_str
(),
ret
);
"client_id=%d, url=%s, request=%s, response=%s, code=%d, ret=%d"
,
client_id
,
url
.
c_str
(),
data
.
c_str
(),
res
.
c_str
(),
status_code
,
ret
);
return
;
}
...
...
@@ -383,13 +240,6 @@ int SrsHttpHooks::on_dvr(string url, int client_id, string ip, SrsRequest* req,
{
int
ret
=
ERROR_SUCCESS
;
SrsHttpUri
uri
;
if
((
ret
=
uri
.
initialize
(
url
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"http uri parse on_dvr url failed, ignored. "
"client_id=%d, url=%s, ret=%d"
,
client_id
,
url
.
c_str
(),
ret
);
return
ret
;
}
std
::
stringstream
ss
;
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_STR
(
"action"
,
"on_dvr"
)
<<
__SRS_JFIELD_CONT
...
...
@@ -401,31 +251,14 @@ int SrsHttpHooks::on_dvr(string url, int client_id, string ip, SrsRequest* req,
<<
__SRS_JFIELD_STR
(
"cwd"
,
cwd
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"file"
,
file
)
<<
__SRS_JOBJECT_END
;
std
::
string
data
=
ss
.
str
();
std
::
string
res
;
int
status_code
;
SrsHttpClient
http
;
if
((
ret
=
http
.
post
(
&
uri
,
data
,
status_code
,
res
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
do_post
(
url
,
data
,
status_code
,
res
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"http post on_dvr 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
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_dvr 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_warn
(
"http hook on_dvr validate failed, ignored. "
"client_id=%d, res=%s, ret=%d"
,
client_id
,
res
.
c_str
(),
ret
);
"client_id=%d, url=%s, request=%s, response=%s, code=%d, ret=%d"
,
client_id
,
url
.
c_str
(),
data
.
c_str
(),
res
.
c_str
(),
status_code
,
ret
);
return
ret
;
}
...
...
@@ -440,13 +273,6 @@ int SrsHttpHooks::on_dvr_reap_segment(string url, int client_id, SrsRequest* req
{
int
ret
=
ERROR_SUCCESS
;
SrsHttpUri
uri
;
if
((
ret
=
uri
.
initialize
(
url
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"http uri parse on_dvr_reap_segment url failed, ignored. "
"client_id=%d, url=%s, ret=%d"
,
client_id
,
url
.
c_str
(),
ret
);
return
ret
;
}
std
::
stringstream
ss
;
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_STR
(
"action"
,
"on_dvr_reap_segment"
)
<<
__SRS_JFIELD_CONT
...
...
@@ -457,38 +283,57 @@ int SrsHttpHooks::on_dvr_reap_segment(string url, int client_id, SrsRequest* req
<<
__SRS_JFIELD_STR
(
"cwd"
,
cwd
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"file"
,
file
)
<<
__SRS_JOBJECT_END
;
std
::
string
data
=
ss
.
str
();
std
::
string
res
;
int
status_code
;
SrsHttpClient
http
;
if
((
ret
=
http
.
post
(
&
uri
,
data
,
status_code
,
res
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
do_post
(
url
,
data
,
status_code
,
res
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"http post on_dvr_reap_segment 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
);
"client_id=%d, url=%s, request=%s, response=%s, code=%d, ret=%d"
,
client_id
,
url
.
c_str
(),
data
.
c_str
(),
res
.
c_str
(),
status_code
,
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_dvr_reap_segment status failed. "
"client_id=%d, code=%d, ret=%d"
,
client_id
,
status_code
,
ret
);
srs_trace
(
"http hook on_dvr_reap_segment success. "
"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
;
}
int
SrsHttpHooks
::
do_post
(
std
::
string
url
,
std
::
string
req
,
int
&
code
,
string
&
res
)
{
int
ret
=
ERROR_SUCCESS
;
SrsHttpUri
uri
;
if
((
ret
=
uri
.
initialize
(
url
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"http: post failed. url=%s, ret=%d"
,
url
.
c_str
(),
ret
);
return
ret
;
}
if
(
res
.
empty
()
||
res
!=
SRS_HTTP_RESPONSE_OK
)
{
ret
=
ERROR_HTTP_DATA_INVLIAD
;
srs_warn
(
"http hook on_dvr_reap_segment validate failed, ignored. "
"client_id=%d, res=%s, ret=%d"
,
client_id
,
res
.
c_str
(),
ret
);
SrsHttpClient
http
;
SrsHttpMessage
*
msg
=
NULL
;
if
((
ret
=
http
.
post
(
&
uri
,
req
,
&
msg
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
SrsAutoFree
(
SrsHttpMessage
,
msg
);
srs_trace
(
"http hook on_dvr_reap_segment success. "
"client_id=%d, url=%s, request=%s, response=%s, ret=%d"
,
client_id
,
url
.
c_str
(),
data
.
c_str
(),
res
.
c_str
(),
ret
);
code
=
msg
->
status_code
();
if
((
ret
=
msg
->
body_read_all
(
res
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
// ensure the http status is ok.
// https://github.com/winlinvip/simple-rtmp-server/issues/158
if
(
code
!=
SRS_CONSTS_HTTP_OK
)
{
return
ERROR_HTTP_STATUS_INVLIAD
;
}
// TODO: FIXME: parse json.
if
(
res
.
empty
()
||
res
!=
SRS_HTTP_RESPONSE_OK
)
{
return
ERROR_HTTP_DATA_INVLIAD
;
}
return
ret
;
}
...
...
trunk/src/app/srs_app_http_hooks.hpp
查看文件 @
964e4be
...
...
@@ -113,6 +113,8 @@ public:
* @param file the file path, can be relative or absolute path.
*/
static
int
on_dvr_reap_segment
(
std
::
string
url
,
int
client_id
,
SrsRequest
*
req
,
std
::
string
cwd
,
std
::
string
file
);
private
:
static
int
do_post
(
std
::
string
url
,
std
::
string
req
,
int
&
code
,
std
::
string
&
res
);
};
#endif
...
...
请
注册
或
登录
后发表评论