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-09-15 12:15:18 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
631e76cd32b49c01b4910e2703166b89221ceccc
631e76cd
1 parent
95979674
for #319, support update and delete the disabled vhost
显示空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
99 行增加
和
10 行删除
trunk/src/app/srs_app_config.cpp
trunk/src/app/srs_app_config.hpp
trunk/src/app/srs_app_http_api.cpp
trunk/src/app/srs_app_config.cpp
查看文件 @
631e76c
...
...
@@ -228,6 +228,14 @@ SrsConfDirective* SrsConfDirective::set_arg0(string a0)
return
this
;
}
void
SrsConfDirective
::
remove
(
SrsConfDirective
*
v
)
{
std
::
vector
<
SrsConfDirective
*>::
iterator
it
;
if
((
it
=
::
find
(
directives
.
begin
(),
directives
.
end
(),
v
))
!=
directives
.
end
())
{
directives
.
erase
(
it
);
}
}
bool
SrsConfDirective
::
is_vhost
()
{
return
name
==
"vhost"
;
...
...
@@ -2472,6 +2480,40 @@ int SrsConfig::raw_create_vhost(string vhost, bool& applied)
return
ret
;
}
int
SrsConfig
::
raw_update_vhost
(
string
vhost
,
string
name
,
bool
&
applied
)
{
int
ret
=
ERROR_SUCCESS
;
applied
=
false
;
// the vhost must be disabled, so we donot need to reload.
SrsConfDirective
*
conf
=
root
->
get_or_create
(
"vhost"
,
vhost
);
conf
->
set_arg0
(
name
);
applied
=
true
;
return
ret
;
}
int
SrsConfig
::
raw_delete_vhost
(
string
vhost
,
bool
&
applied
)
{
int
ret
=
ERROR_SUCCESS
;
applied
=
false
;
// the vhost must be disabled, so we donot need to reload.
SrsConfDirective
*
conf
=
root
->
get
(
"vhost"
,
vhost
);
srs_assert
(
conf
);
// remove the directive.
root
->
remove
(
conf
);
srs_freep
(
conf
);
applied
=
true
;
return
ret
;
}
int
SrsConfig
::
do_reload_listen
()
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/app/srs_app_config.hpp
查看文件 @
631e76c
...
...
@@ -131,6 +131,10 @@ public:
virtual
SrsConfDirective
*
get_or_create
(
std
::
string
n
);
virtual
SrsConfDirective
*
get_or_create
(
std
::
string
n
,
std
::
string
a0
);
virtual
SrsConfDirective
*
set_arg0
(
std
::
string
a0
);
/**
* remove the v from sub directives, user must free the v.
*/
virtual
void
remove
(
SrsConfDirective
*
v
);
// help utilities
public:
/**
...
...
@@ -378,6 +382,14 @@ public:
* raw create the new vhost.
*/
virtual
int
raw_create_vhost
(
std
::
string
vhost
,
bool
&
applied
);
/**
* raw update the disabled vhost name.
*/
virtual
int
raw_update_vhost
(
std
::
string
vhost
,
std
::
string
name
,
bool
&
applied
);
/**
* raw delete the disabled vhost.
*/
virtual
int
raw_delete_vhost
(
std
::
string
vhost
,
bool
&
applied
);
private
:
virtual
int
do_reload_listen
();
virtual
int
do_reload_pid
();
...
...
trunk/src/app/srs_app_http_api.cpp
查看文件 @
631e76c
...
...
@@ -985,6 +985,7 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
// @scope the scope to update for config.
// @value the updated value for scope.
// @param the extra param for scope.
// @data the extra data for scope.
// possible updates:
// @scope @value value-description
// listen 1935,1936 the port list.
...
...
@@ -998,8 +999,9 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
// utc_time false whether enable utc time.
// pithy_print_ms 10000 the pithy print interval in ms.
// vhost specified updates:
// @scope @value @param description
// vhost ossrs.net create create vhost ossrs.net
// @scope @value @param @data description
// vhost ossrs.net create - create vhost ossrs.net
// vhost ossrs.net update new.ossrs.net the new name to update vhost
if
(
rpc
==
"update"
)
{
if
(
!
allow_update
)
{
ret
=
ERROR_SYSTEM_CONFIG_RAW_DISABLED
;
...
...
@@ -1009,7 +1011,6 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
std
::
string
scope
=
r
->
query_get
(
"scope"
);
std
::
string
value
=
r
->
query_get
(
"value"
);
std
::
string
param
=
r
->
query_get
(
"param"
);
if
(
scope
.
empty
())
{
ret
=
ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED
;
srs_error
(
"raw api query invalid empty scope. ret=%d"
,
ret
);
...
...
@@ -1024,13 +1025,9 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
srs_error
(
"raw api query invalid scope=%s. ret=%d"
,
scope
.
c_str
(),
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
if
(
scope
==
"vhost"
&&
param
!=
"create"
)
{
ret
=
ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED
;
srs_error
(
"raw api query invalid scope=%s, param=%s. ret=%d"
,
scope
.
c_str
(),
param
.
c_str
(),
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
bool
applied
=
false
;
string
extra
=
""
;
if
(
scope
==
"listen"
)
{
vector
<
string
>
eps
=
srs_string_split
(
value
,
","
);
...
...
@@ -1156,6 +1153,15 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
return
srs_api_response_code
(
w
,
r
,
ret
);
}
}
else
if
(
scope
==
"vhost"
)
{
std
::
string
param
=
r
->
query_get
(
"param"
);
std
::
string
data
=
r
->
query_get
(
"data"
);
if
(
param
!=
"create"
&&
param
!=
"update"
&&
param
!=
"delete"
)
{
ret
=
ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED
;
srs_error
(
"raw api query invalid scope=%s, param=%s. ret=%d"
,
scope
.
c_str
(),
param
.
c_str
(),
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
extra
+=
" "
+
param
;
if
(
param
==
"create"
)
{
// when create, the vhost must not exists.
if
(
param
.
empty
()
||
_srs_config
->
get_vhost
(
value
,
false
))
{
...
...
@@ -1168,15 +1174,44 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
srs_error
(
"raw api update vhost=%s, param=%s failed. ret=%d"
,
value
.
c_str
(),
param
.
c_str
(),
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
}
else
if
(
param
==
"update"
)
{
extra
+=
" to "
+
data
;
// when update, the vhost must exists and disabled.
SrsConfDirective
*
vhost
=
_srs_config
->
get_vhost
(
value
,
false
);
if
(
data
.
empty
()
||
data
==
value
||
param
.
empty
()
||
!
vhost
||
_srs_config
->
get_vhost_enabled
(
vhost
))
{
ret
=
ERROR_SYSTEM_CONFIG_RAW_PARAMS
;
srs_error
(
"raw api update check vhost=%s, param=%s, data=%s failed. ret=%d"
,
value
.
c_str
(),
param
.
c_str
(),
data
.
c_str
(),
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
if
((
ret
=
_srs_config
->
raw_update_vhost
(
value
,
data
,
applied
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"raw api update vhost=%s, param=%s, data=%s failed. ret=%d"
,
value
.
c_str
(),
param
.
c_str
(),
data
.
c_str
(),
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
}
else
if
(
param
==
"delete"
)
{
// when delete, the vhost must exists and disabled.
SrsConfDirective
*
vhost
=
_srs_config
->
get_vhost
(
value
,
false
);
if
(
param
.
empty
()
||
!
vhost
||
_srs_config
->
get_vhost_enabled
(
vhost
))
{
ret
=
ERROR_SYSTEM_CONFIG_RAW_PARAMS
;
srs_error
(
"raw api update check vhost=%s, param=%s failed. ret=%d"
,
value
.
c_str
(),
param
.
c_str
(),
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
if
((
ret
=
_srs_config
->
raw_delete_vhost
(
value
,
applied
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"raw api update vhost=%s, param=%s failed. ret=%d"
,
value
.
c_str
(),
param
.
c_str
(),
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
}
}
// whether the config applied.
if
(
applied
)
{
server
->
on_signal
(
SRS_SIGNAL_PERSISTENCE_CONFIG
);
srs_trace
(
"raw api update %s=%s
ok."
,
scope
.
c_str
(),
value
.
c_str
());
srs_trace
(
"raw api update %s=%s
%s ok."
,
scope
.
c_str
(),
value
.
c_str
(),
extra
.
c_str
());
}
else
{
srs_warn
(
"raw api update not applied %s=%s
."
,
scope
.
c_str
(),
value
.
c_str
());
srs_warn
(
"raw api update not applied %s=%s
%s."
,
scope
.
c_str
(),
value
.
c_str
(),
extra
.
c_str
());
}
return
srs_api_response
(
w
,
r
,
obj
->
to_json
());
...
...
请
注册
或
登录
后发表评论