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-08-29 18:40:18 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7ef3ff90c030eab604a8d91027c9ffc6014383c3
7ef3ff90
1 parent
a79e1959
refine the config structure, compatible with SRS1/2
显示空白字符变更
内嵌
并排对比
正在显示
6 个修改的文件
包含
400 行增加
和
201 行删除
trunk/conf/compatible.conf
trunk/conf/full.conf
trunk/conf/full.one.vhost.conf
trunk/src/app/srs_app_config.cpp
trunk/src/app/srs_app_config.hpp
trunk/src/app/srs_app_rtmp_conn.cpp
trunk/conf/compatible.conf
0 → 100644
查看文件 @
7ef3ff9
listen
1935
;
pid
./
objs
/
srs
.
pid
;
srs_log_tank
console
;
srs_log_level
trace
;
max_connections
1000
;
daemon
off
;
http_api
{
enabled
on
;
listen
1985
;
crossdomain
on
;
raw_api
{
enabled
on
;
allow_reload
on
;
allow_query
on
;
}
}
# for SRS1.
http_stream
{
enabled
on
;
listen
8080
;
dir
./
objs
/
nginx
/
html
;
}
vhost
__
defaultVhost__
{
# for SRS2.
refer
github
.
com
github
.
io
;
refer_publish
github
.
com
github
.
io
;
refer_play
github
.
com
github
.
io
;
# for SRS1.
http
{
enabled
on
;
mount
[
vhost
]/
hls
;
dir
./
objs
/
nginx
/
html
/
hls
;
}
}
...
...
trunk/conf/full.conf
查看文件 @
7ef3ff9
...
...
@@ -230,6 +230,81 @@ stream_caster {
vhost
__
defaultVhost__
{
}
# the vhost for antisuck.
vhost
refer
.
anti_suck
.
com
{
# refer hotlink-denial.
refer
{
# whether enable the refer hotlink-denial.
# default: off.
enabled
on
;
# the common refer for play and publish.
# if the page url of client not in the refer, access denied.
# if not specified this field, allow all.
# default: not specified.
all
github
.
com
github
.
io
;
# refer for publish clients specified.
# the common refer is not overrided by this.
# if not specified this field, allow all.
# default: not specified.
publish
github
.
com
github
.
io
;
# refer for play clients specified.
# the common refer is not overrided by this.
# if not specified this field, allow all.
# default: not specified.
play
github
.
com
github
.
io
;
}
}
# vhost for bandwidth check
# generally, the bandcheck vhost must be: bandcheck.srs.com,
# or need to modify the vhost of client.
vhost
bandcheck
.
srs
.
com
{
enabled
on
;
chunk_size
65000
;
# bandwidth check config.
bandcheck
{
# whether support bandwidth check,
# default: off.
enabled
on
;
# the key for server to valid,
# if invalid key, server disconnect and abort the bandwidth check.
key
"35c9b402c12a7246868752e2878f7e0e"
;
# the interval in seconds for bandwidth check,
# server donot allow new test request.
# default: 30
interval
30
;
# the max available check bandwidth in kbps.
# to avoid attack of bandwidth check.
# default: 1000
limit_kbps
4000
;
}
}
# the security to allow or deny clients.
vhost
security
.
srs
.
com
{
# security for host to allow or deny clients.
...
...
@@ -952,25 +1027,6 @@ vhost stream.control.com {
publish_normal_timeout
7000
;
}
# the vhost for antisuck.
vhost
refer
.
anti_suck
.
com
{
# the common refer for play and publish.
# if the page url of client not in the refer, access denied.
# if not specified this field, allow all.
# default: not specified.
refer
github
.
com
github
.
io
;
# refer for publish clients specified.
# the common refer is not overrided by this.
# if not specified this field, allow all.
# default: not specified.
refer_publish
github
.
com
github
.
io
;
# refer for play clients specified.
# the common refer is not overrided by this.
# if not specified this field, allow all.
# default: not specified.
refer_play
github
.
com
github
.
io
;
}
# the vhost which forward publish streams.
vhost
same
.
vhost
.
forward
.
srs
.
com
{
# forward all publish stream to the specified server.
...
...
@@ -1003,31 +1059,6 @@ vhost exec.srs.com {
}
}
# vhost for bandwidth check
# generally, the bandcheck vhost must be: bandcheck.srs.com,
# or need to modify the vhost of client.
vhost
bandcheck
.
srs
.
com
{
enabled
on
;
chunk_size
65000
;
# bandwidth check config.
bandcheck
{
# whether support bandwidth check,
# default: off.
enabled
on
;
# the key for server to valid,
# if invalid key, server disconnect and abort the bandwidth check.
key
"35c9b402c12a7246868752e2878f7e0e"
;
# the interval in seconds for bandwidth check,
# server donot allow new test request.
# default: 30
interval
30
;
# the max available check bandwidth in kbps.
# to avoid attack of bandwidth check.
# default: 1000
limit_kbps
4000
;
}
}
# set the chunk size of vhost.
vhost
chunksize
.
srs
.
com
{
# the default chunk size is 128, max is 65536,
...
...
trunk/conf/full.one.vhost.conf
查看文件 @
7ef3ff9
...
...
@@ -43,26 +43,6 @@ stream_caster {
rtp_port_min
57200
;
rtp_port_max
57300
;
}
stream_caster
{
enabled
off
;
caster
mpegts_over_udp
;
output
rtmp
://
127
.
0
.
0
.
1
/
live
/
livestream
;
listen
8935
;
}
stream_caster
{
enabled
off
;
caster
rtsp
;
output
rtmp
://
127
.
0
.
0
.
1
/[
app
]/[
stream
];
listen
554
;
rtp_port_min
57200
;
rtp_port_max
57300
;
}
stream_caster
{
enabled
off
;
caster
flv
;
output
rtmp
://
127
.
0
.
0
.
1
/[
app
]/[
stream
];
listen
8936
;
}
vhost
__
defaultVhost__
{
}
vhost
vhost
.
srs
.
com
{
...
...
@@ -98,9 +78,12 @@ vhost vhost.srs.com {
publish_1stpkt_timeout
20000
;
publish_normal_timeout
7000
;
refer
github
.
com
github
.
io
;
refer_publish
github
.
com
github
.
io
;
refer_play
github
.
com
github
.
io
;
refer
{
enabled
off
;
all
github
.
com
github
.
io
;
publish
github
.
com
github
.
io
;
play
github
.
com
github
.
io
;
}
bandcheck
{
enabled
off
;
...
...
trunk/src/app/srs_app_config.cpp
查看文件 @
7ef3ff9
...
...
@@ -105,15 +105,10 @@ using namespace _srs_internal;
// the interval in seconds for bandwidth check
#define SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS 1000
#define SRS_CONF_DEFAULT_HTTP_MOUNT "[vhost]/"
#define SRS_CONF_DEFAULT_HTTP_REMUX_MOUNT "[vhost]/[app]/[stream].flv"
#define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH
#define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 0
#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT "8080"
#define SRS_CONF_DEFAULT_HTTP_API_PORT "1985"
#define SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN true
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED false
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INTERVAL 9.9
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_URL "http://"SRS_CONSTS_LOCALHOST":8085/api/v1/servers"
...
...
@@ -228,6 +223,37 @@ SrsConfDirective* SrsConfDirective::get(string _name, string _arg0)
return
NULL
;
}
SrsConfDirective
*
SrsConfDirective
::
get_or_create
(
string
n
)
{
SrsConfDirective
*
conf
=
get
(
n
);
if
(
!
conf
)
{
conf
=
new
SrsConfDirective
();
conf
->
name
=
n
;
directives
.
push_back
(
conf
);
}
return
conf
;
}
SrsConfDirective
*
SrsConfDirective
::
get_or_create
(
string
n
,
string
a0
)
{
SrsConfDirective
*
conf
=
get_or_create
(
n
);
if
(
conf
->
arg0
()
==
a0
)
{
return
conf
;
}
// update a0.
if
(
!
conf
->
args
.
empty
())
{
conf
->
args
.
erase
(
conf
->
args
.
begin
());
}
conf
->
args
.
insert
(
conf
->
args
.
begin
(),
a0
);
return
conf
;
}
bool
SrsConfDirective
::
is_vhost
()
{
return
name
==
"vhost"
;
...
...
@@ -645,6 +671,12 @@ int SrsConfig::reload()
}
srs_info
(
"config reloader parse file success."
);
// transform config to compatible with previous style of config.
if
((
ret
=
srs_config_transform_vhost
(
conf
.
root
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"transform config failed. ret=%d"
,
ret
);
return
ret
;
}
if
((
ret
=
conf
.
check_config
())
!=
ERROR_SUCCESS
)
{
srs_error
(
"ignore config reloader check config failed. ret=%d"
,
ret
);
ret
=
ERROR_SUCCESS
;
...
...
@@ -958,20 +990,7 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
srs_trace
(
"vhost %s reload min_latency success."
,
vhost
.
c_str
());
}
// http, only one per vhost.
if
(
!
srs_directive_equals
(
new_vhost
->
get
(
"http"
),
old_vhost
->
get
(
"http"
)))
{
for
(
it
=
subscribes
.
begin
();
it
!=
subscribes
.
end
();
++
it
)
{
ISrsReloadHandler
*
subscribe
=
*
it
;
if
((
ret
=
subscribe
->
on_reload_vhost_http_updated
())
!=
ERROR_SUCCESS
)
{
srs_error
(
"vhost %s notify subscribes http failed. ret=%d"
,
vhost
.
c_str
(),
ret
);
return
ret
;
}
}
srs_trace
(
"vhost %s reload http success."
,
vhost
.
c_str
());
}
// http_static, only one per vhost.
// @remark, http_static introduced as alias of http.
if
(
!
srs_directive_equals
(
new_vhost
->
get
(
"http_static"
),
old_vhost
->
get
(
"http_static"
)))
{
for
(
it
=
subscribes
.
begin
();
it
!=
subscribes
.
end
();
++
it
)
{
ISrsReloadHandler
*
subscribe
=
*
it
;
...
...
@@ -1239,17 +1258,8 @@ int SrsConfig::reload_http_stream(SrsConfDirective* old_root)
// ENABLED => DISABLED
// ENABLED => ENABLED (modified)
SrsConfDirective
*
new_http_stream
=
root
->
get
(
"http_stream"
);
// http_stream rename to http_server in SRS2.
if
(
!
new_http_stream
)
{
new_http_stream
=
root
->
get
(
"http_server"
);
}
SrsConfDirective
*
old_http_stream
=
old_root
->
get
(
"http_stream"
);
// http_stream rename to http_server in SRS2.
if
(
!
old_http_stream
)
{
old_http_stream
=
root
->
get
(
"http_server"
);
}
SrsConfDirective
*
new_http_stream
=
root
->
get
(
"http_server"
);
SrsConfDirective
*
old_http_stream
=
old_root
->
get
(
"http_server"
);
// DISABLED => ENABLED
if
(
!
get_http_stream_enabled
(
old_http_stream
)
&&
get_http_stream_enabled
(
new_http_stream
))
{
...
...
@@ -1524,6 +1534,12 @@ int SrsConfig::parse_options(int argc, char** argv)
ret
=
parse_file
(
config_file
.
c_str
());
// transform config to compatible with previous style of config.
if
((
ret
=
srs_config_transform_vhost
(
root
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"transform config failed. ret=%d"
,
ret
);
return
ret
;
}
if
(
test_conf
)
{
// the parse_file never check the config,
// we check it when user requires check config file.
...
...
@@ -1735,7 +1751,7 @@ int SrsConfig::global_to_json(SrsAmf0Object* obj)
sobj
->
set
(
"forward"
,
SrsAmf0Any
::
boolean
(
get_forward
(
dir
->
name
)));
sobj
->
set
(
"security"
,
SrsAmf0Any
::
boolean
(
get_security_enabled
(
dir
->
name
)));
sobj
->
set
(
"refer"
,
SrsAmf0Any
::
boolean
(
get_refer
(
dir
->
name
)
||
get_refer_play
(
dir
->
name
)
||
get_refer_publish
(
dir
->
name
)));
sobj
->
set
(
"refer"
,
SrsAmf0Any
::
boolean
(
get_refer
_enabled
(
dir
->
name
)));
sobj
->
set
(
"mr"
,
SrsAmf0Any
::
boolean
(
get_mr_enabled
(
dir
->
name
)));
sobj
->
set
(
"min_latency"
,
SrsAmf0Any
::
boolean
(
get_realtime_enabled
(
dir
->
name
)));
...
...
@@ -1905,13 +1921,22 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
// refer
if
((
dir
=
vhost
->
get
(
"refer"
))
!=
NULL
)
{
obj
->
set
(
"refer"
,
dir
->
dumps_args
());
SrsAmf0Object
*
refer
=
SrsAmf0Any
::
object
();
obj
->
set
(
"refer"
,
refer
);
for
(
int
i
=
0
;
i
<
(
int
)
dir
->
directives
.
size
();
i
++
)
{
SrsConfDirective
*
sdir
=
dir
->
directives
.
at
(
i
);
if
(
sdir
->
name
==
"enabled"
)
{
refer
->
set
(
"enabled"
,
sdir
->
dumps_arg0_to_boolean
());
}
else
if
(
sdir
->
name
==
"all"
)
{
refer
->
set
(
"all"
,
sdir
->
dumps_args
());
}
else
if
(
sdir
->
name
==
"publish"
)
{
refer
->
set
(
"publish"
,
sdir
->
dumps_args
());
}
else
if
(
sdir
->
name
==
"play"
)
{
refer
->
set
(
"play"
,
sdir
->
dumps_args
());
}
if
((
dir
=
vhost
->
get
(
"refer_publish"
))
!=
NULL
)
{
obj
->
set
(
"refer_publish"
,
dir
->
dumps_args
());
}
if
((
dir
=
vhost
->
get
(
"refer_play"
))
!=
NULL
)
{
obj
->
set
(
"refer_play"
,
dir
->
dumps_args
());
}
// bandcheck
...
...
@@ -2495,7 +2520,7 @@ int SrsConfig::check_config()
&&
n
!=
"srs_log_tank"
&&
n
!=
"srs_log_level"
&&
n
!=
"srs_log_file"
&&
n
!=
"max_connections"
&&
n
!=
"daemon"
&&
n
!=
"heartbeat"
&&
n
!=
"http_api"
&&
n
!=
"stats"
&&
n
!=
"vhost"
&&
n
!=
"pithy_print_ms"
&&
n
!=
"http_s
tream"
&&
n
!=
"http_s
erver"
&&
n
!=
"stream_caster"
&&
n
!=
"http_server"
&&
n
!=
"stream_caster"
&&
n
!=
"utc_time"
)
{
ret
=
ERROR_SYSTEM_CONFIG_INVALID
;
...
...
@@ -2504,7 +2529,7 @@ int SrsConfig::check_config()
}
}
if
(
true
)
{
SrsConfDirective
*
conf
=
get_http_api
(
);
SrsConfDirective
*
conf
=
root
->
get
(
"http_api"
);
for
(
int
i
=
0
;
conf
&&
i
<
(
int
)
conf
->
directives
.
size
();
i
++
)
{
SrsConfDirective
*
obj
=
conf
->
at
(
i
);
string
n
=
obj
->
name
;
...
...
@@ -2527,7 +2552,7 @@ int SrsConfig::check_config()
}
}
if
(
true
)
{
SrsConfDirective
*
conf
=
get_http_stream
(
);
SrsConfDirective
*
conf
=
root
->
get
(
"http_server"
);
for
(
int
i
=
0
;
conf
&&
i
<
(
int
)
conf
->
directives
.
size
();
i
++
)
{
string
n
=
conf
->
at
(
i
)
->
name
;
if
(
n
!=
"enabled"
&&
n
!=
"listen"
&&
n
!=
"dir"
)
{
...
...
@@ -2751,8 +2776,7 @@ int SrsConfig::check_config()
&&
n
!=
"mode"
&&
n
!=
"origin"
&&
n
!=
"token_traverse"
&&
n
!=
"vhost"
&&
n
!=
"dvr"
&&
n
!=
"ingest"
&&
n
!=
"hls"
&&
n
!=
"http_hooks"
&&
n
!=
"gop_cache"
&&
n
!=
"queue_length"
&&
n
!=
"refer"
&&
n
!=
"refer_publish"
&&
n
!=
"refer_play"
&&
n
!=
"forward"
&&
n
!=
"transcode"
&&
n
!=
"bandcheck"
&&
n
!=
"refer"
&&
n
!=
"forward"
&&
n
!=
"transcode"
&&
n
!=
"bandcheck"
&&
n
!=
"time_jitter"
&&
n
!=
"mix_correct"
&&
n
!=
"atc"
&&
n
!=
"atc_auto"
&&
n
!=
"debug_srs_upnode"
...
...
@@ -2760,8 +2784,7 @@ int SrsConfig::check_config()
&&
n
!=
"tcp_nodelay"
&&
n
!=
"send_min_interval"
&&
n
!=
"reduce_sequence_header"
&&
n
!=
"publish_1stpkt_timeout"
&&
n
!=
"publish_normal_timeout"
&&
n
!=
"security"
&&
n
!=
"http_remux"
&&
n
!=
"http"
&&
n
!=
"http_static"
&&
n
!=
"hds"
&&
n
!=
"exec"
&&
n
!=
"http_static"
&&
n
!=
"hds"
&&
n
!=
"exec"
)
{
ret
=
ERROR_SYSTEM_CONFIG_INVALID
;
srs_error
(
"unsupported vhost directive %s, ret=%d"
,
n
.
c_str
(),
ret
);
...
...
@@ -2779,6 +2802,15 @@ int SrsConfig::check_config()
return
ret
;
}
}
}
else
if
(
n
==
"refer"
)
{
for
(
int
j
=
0
;
j
<
(
int
)
conf
->
directives
.
size
();
j
++
)
{
string
m
=
conf
->
at
(
j
)
->
name
.
c_str
();
if
(
m
!=
"enabled"
&&
m
!=
"all"
&&
m
!=
"publish"
&&
m
!=
"play"
)
{
ret
=
ERROR_SYSTEM_CONFIG_INVALID
;
srs_error
(
"unsupported vhost refer directive %s, ret=%d"
,
m
.
c_str
(),
ret
);
return
ret
;
}
}
}
else
if
(
n
==
"exec"
)
{
for
(
int
j
=
0
;
j
<
(
int
)
conf
->
directives
.
size
();
j
++
)
{
string
m
=
conf
->
at
(
j
)
->
name
.
c_str
();
...
...
@@ -2806,7 +2838,7 @@ int SrsConfig::check_config()
return
ret
;
}
}
}
else
if
(
n
==
"http
"
||
n
==
"http
_static"
)
{
}
else
if
(
n
==
"http_static"
)
{
for
(
int
j
=
0
;
j
<
(
int
)
conf
->
directives
.
size
();
j
++
)
{
string
m
=
conf
->
at
(
j
)
->
name
.
c_str
();
if
(
m
!=
"enabled"
&&
m
!=
"mount"
&&
m
!=
"dir"
)
{
...
...
@@ -3372,37 +3404,77 @@ double SrsConfig::get_queue_length(string vhost)
return
::
atoi
(
conf
->
arg0
().
c_str
());
}
bool
SrsConfig
::
get_refer_enabled
(
string
vhost
)
{
static
bool
DEFAULT
=
false
;
SrsConfDirective
*
conf
=
get_vhost
(
vhost
);
if
(
!
conf
)
{
return
DEFAULT
;
}
conf
=
conf
->
get
(
"refer"
);
if
(
!
conf
)
{
return
DEFAULT
;
}
conf
=
conf
->
get
(
"enabled"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
DEFAULT
;
}
return
SRS_CONF_PERFER_FALSE
(
conf
->
arg0
());
}
SrsConfDirective
*
SrsConfig
::
get_refer
(
string
vhost
)
{
static
SrsConfDirective
*
DEFAULT
=
NULL
;
SrsConfDirective
*
conf
=
get_vhost
(
vhost
);
if
(
!
conf
)
{
return
DEFAULT
;
}
conf
=
conf
->
get
(
"refer"
);
if
(
!
conf
)
{
return
NULL
;
return
DEFAULT
;
}
return
conf
->
get
(
"
refer
"
);
return
conf
->
get
(
"
all
"
);
}
SrsConfDirective
*
SrsConfig
::
get_refer_play
(
string
vhost
)
{
static
SrsConfDirective
*
DEFAULT
=
NULL
;
SrsConfDirective
*
conf
=
get_vhost
(
vhost
);
if
(
!
conf
)
{
return
DEFAULT
;
}
conf
=
conf
->
get
(
"refer"
);
if
(
!
conf
)
{
return
NULL
;
return
DEFAULT
;
}
return
conf
->
get
(
"
refer_
play"
);
return
conf
->
get
(
"play"
);
}
SrsConfDirective
*
SrsConfig
::
get_refer_publish
(
string
vhost
)
{
static
SrsConfDirective
*
DEFAULT
=
NULL
;
SrsConfDirective
*
conf
=
get_vhost
(
vhost
);
if
(
!
conf
)
{
return
DEFAULT
;
}
conf
=
conf
->
get
(
"refer"
);
if
(
!
conf
)
{
return
NULL
;
return
DEFAULT
;
}
return
conf
->
get
(
"
refer_
publish"
);
return
conf
->
get
(
"publish"
);
}
int
SrsConfig
::
get_chunk_size
(
string
vhost
)
...
...
@@ -5046,24 +5118,21 @@ int SrsConfig::get_dvr_time_jitter(string vhost)
bool
SrsConfig
::
get_http_api_enabled
()
{
SrsConfDirective
*
conf
=
get_http_api
(
);
SrsConfDirective
*
conf
=
root
->
get
(
"http_api"
);
return
get_http_api_enabled
(
conf
);
}
SrsConfDirective
*
SrsConfig
::
get_http_api
()
{
return
root
->
get
(
"http_api"
);
}
bool
SrsConfig
::
get_http_api_enabled
(
SrsConfDirective
*
conf
)
{
static
bool
DEFAULT
=
false
;
if
(
!
conf
)
{
return
false
;
return
DEFAULT
;
}
conf
=
conf
->
get
(
"enabled"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
false
;
return
DEFAULT
;
}
return
SRS_CONF_PERFER_FALSE
(
conf
->
arg0
());
...
...
@@ -5071,15 +5140,17 @@ bool SrsConfig::get_http_api_enabled(SrsConfDirective* conf)
string
SrsConfig
::
get_http_api_listen
()
{
SrsConfDirective
*
conf
=
get_http_api
();
static
string
DEFAULT
=
"1985"
;
SrsConfDirective
*
conf
=
root
->
get
(
"http_api"
);
if
(
!
conf
)
{
return
SRS_CONF_DEFAULT_HTTP_API_POR
T
;
return
DEFAUL
T
;
}
conf
=
conf
->
get
(
"listen"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
SRS_CONF_DEFAULT_HTTP_API_POR
T
;
return
DEFAUL
T
;
}
return
conf
->
arg0
();
...
...
@@ -5087,15 +5158,17 @@ string SrsConfig::get_http_api_listen()
bool
SrsConfig
::
get_http_api_crossdomain
()
{
SrsConfDirective
*
conf
=
get_http_api
();
static
bool
DEFAULT
=
true
;
SrsConfDirective
*
conf
=
root
->
get
(
"http_api"
);
if
(
!
conf
)
{
return
SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN
;
return
DEFAULT
;
}
conf
=
conf
->
get
(
"crossdomain"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN
;
return
DEFAULT
;
}
return
SRS_CONF_PERFER_TRUE
(
conf
->
arg0
());
...
...
@@ -5105,7 +5178,7 @@ bool SrsConfig::get_raw_api()
{
static
bool
DEFAULT
=
false
;
SrsConfDirective
*
conf
=
get_http_api
(
);
SrsConfDirective
*
conf
=
root
->
get
(
"http_api"
);
if
(
!
conf
)
{
return
DEFAULT
;
}
...
...
@@ -5127,7 +5200,7 @@ bool SrsConfig::get_raw_api_allow_reload()
{
static
bool
DEFAULT
=
false
;
SrsConfDirective
*
conf
=
get_http_api
(
);
SrsConfDirective
*
conf
=
root
->
get
(
"http_api"
);
if
(
!
conf
)
{
return
DEFAULT
;
}
...
...
@@ -5149,7 +5222,7 @@ bool SrsConfig::get_raw_api_allow_query()
{
static
bool
DEFAULT
=
false
;
SrsConfDirective
*
conf
=
get_http_api
(
);
SrsConfDirective
*
conf
=
root
->
get
(
"http_api"
);
if
(
!
conf
)
{
return
DEFAULT
;
}
...
...
@@ -5169,30 +5242,21 @@ bool SrsConfig::get_raw_api_allow_query()
bool
SrsConfig
::
get_http_stream_enabled
()
{
SrsConfDirective
*
conf
=
get_http_stream
(
);
SrsConfDirective
*
conf
=
root
->
get
(
"http_server"
);
return
get_http_stream_enabled
(
conf
);
}
SrsConfDirective
*
SrsConfig
::
get_http_stream
()
{
SrsConfDirective
*
conf
=
root
->
get
(
"http_stream"
);
// http_stream renamed to http_server in SRS2.
if
(
!
conf
)
{
conf
=
root
->
get
(
"http_server"
);
}
return
conf
;
}
bool
SrsConfig
::
get_http_stream_enabled
(
SrsConfDirective
*
conf
)
{
static
bool
DEFAULT
=
false
;
if
(
!
conf
)
{
return
false
;
return
DEFAULT
;
}
conf
=
conf
->
get
(
"enabled"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
false
;
return
DEFAULT
;
}
return
SRS_CONF_PERFER_FALSE
(
conf
->
arg0
());
...
...
@@ -5200,15 +5264,17 @@ bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf)
string
SrsConfig
::
get_http_stream_listen
()
{
SrsConfDirective
*
conf
=
get_http_stream
();
static
string
DEFAULT
=
"8080"
;
SrsConfDirective
*
conf
=
root
->
get
(
"http_server"
);
if
(
!
conf
)
{
return
SRS_CONF_DEFAULT_HTTP_STREAM_POR
T
;
return
DEFAUL
T
;
}
conf
=
conf
->
get
(
"listen"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
SRS_CONF_DEFAULT_HTTP_STREAM_POR
T
;
return
DEFAUL
T
;
}
return
conf
->
arg0
();
...
...
@@ -5216,18 +5282,16 @@ string SrsConfig::get_http_stream_listen()
string
SrsConfig
::
get_http_stream_dir
()
{
SrsConfDirective
*
conf
=
get_http_stream
();
if
(
!
conf
)
{
return
SRS_CONF_DEFAULT_HTTP_DIR
;
}
static
string
DEFAULT
=
"./objs/nginx/html"
;
conf
=
conf
->
get
(
"di
r"
);
SrsConfDirective
*
conf
=
root
->
get
(
"http_serve
r"
);
if
(
!
conf
)
{
return
SRS_CONF_DEFAULT_HTTP_DIR
;
return
DEFAULT
;
}
if
(
conf
->
arg0
().
empty
())
{
return
SRS_CONF_DEFAULT_HTTP_DIR
;
conf
=
conf
->
get
(
"dir"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
DEFAULT
;
}
return
conf
->
arg0
();
...
...
@@ -5235,23 +5299,21 @@ string SrsConfig::get_http_stream_dir()
bool
SrsConfig
::
get_vhost_http_enabled
(
string
vhost
)
{
SrsConfDirective
*
vconf
=
get_vhost
(
vhost
);
if
(
!
vconf
)
{
return
false
;
}
static
bool
DEFAULT
=
false
;
SrsConfDirective
*
conf
=
vconf
->
get
(
"http"
);
SrsConfDirective
*
conf
=
get_vhost
(
vhost
);
if
(
!
conf
)
{
conf
=
vconf
->
get
(
"http_static"
)
;
return
DEFAULT
;
}
conf
=
conf
->
get
(
"http_static"
);
if
(
!
conf
)
{
return
false
;
return
DEFAULT
;
}
conf
=
conf
->
get
(
"enabled"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
false
;
return
DEFAULT
;
}
return
SRS_CONF_PERFER_FALSE
(
conf
->
arg0
());
...
...
@@ -5259,22 +5321,21 @@ bool SrsConfig::get_vhost_http_enabled(string vhost)
string
SrsConfig
::
get_vhost_http_mount
(
string
vhost
)
{
SrsConfDirective
*
vconf
=
get_vhost
(
vhost
);
if
(
!
vconf
)
{
return
SRS_CONF_DEFAULT_HTTP_MOUNT
;
}
static
string
DEFAULT
=
"[vhost]/"
;
SrsConfDirective
*
conf
=
vconf
->
get
(
"http"
);
if
(
!
conf
)
{
conf
=
vconf
->
get
(
"http_static"
);
SrsConfDirective
*
conf
=
get_vhost
(
vhost
);
if
(
!
conf
)
{
return
SRS_CONF_DEFAULT_HTTP_MOUN
T
;
return
DEFAUL
T
;
}
conf
=
conf
->
get
(
"http_static"
);
if
(
!
conf
)
{
return
DEFAULT
;
}
conf
=
conf
->
get
(
"mount"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
SRS_CONF_DEFAULT_HTTP_MOUN
T
;
return
DEFAUL
T
;
}
return
conf
->
arg0
();
...
...
@@ -5282,22 +5343,21 @@ string SrsConfig::get_vhost_http_mount(string vhost)
string
SrsConfig
::
get_vhost_http_dir
(
string
vhost
)
{
SrsConfDirective
*
vconf
=
get_vhost
(
vhost
);
if
(
!
vconf
)
{
return
SRS_CONF_DEFAULT_HTTP_DIR
;
}
static
string
DEFAULT
=
"./objs/nginx/html"
;
SrsConfDirective
*
conf
=
vconf
->
get
(
"http"
);
if
(
!
conf
)
{
conf
=
vconf
->
get
(
"http_static"
);
SrsConfDirective
*
conf
=
get_vhost
(
vhost
);
if
(
!
conf
)
{
return
SRS_CONF_DEFAULT_HTTP_DIR
;
return
DEFAULT
;
}
conf
=
conf
->
get
(
"http_static"
);
if
(
!
conf
)
{
return
DEFAULT
;
}
conf
=
conf
->
get
(
"dir"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
SRS_CONF_DEFAULT_HTTP_DIR
;
return
DEFAULT
;
}
return
conf
->
arg0
();
...
...
@@ -5650,3 +5710,73 @@ bool srs_stream_caster_is_flv(string caster)
{
return
caster
==
SRS_CONF_DEFAULT_STREAM_CASTER_FLV
;
}
int
srs_config_transform_vhost
(
SrsConfDirective
*
root
)
{
int
ret
=
ERROR_SUCCESS
;
for
(
int
i
=
0
;
i
<
root
->
directives
.
size
();
i
++
)
{
SrsConfDirective
*
dir
=
root
->
directives
.
at
(
i
);
// SRS2.0, rename global http_stream to http_server.
// SRS1:
// http_stream {}
// SRS2+:
// http_server {}
if
(
dir
->
name
==
"http_stream"
)
{
dir
->
name
=
"http_server"
;
continue
;
}
if
(
!
dir
->
is_vhost
())
{
continue
;
}
std
::
vector
<
SrsConfDirective
*>::
iterator
it
;
for
(
it
=
dir
->
directives
.
begin
();
it
!=
dir
->
directives
.
end
();)
{
SrsConfDirective
*
conf
=
*
it
;
// SRS2.0, rename vhost http to http_static
// SRS1:
// vhost { http {} }
// SRS2+:
// vhost { http_static {} }
if
(
conf
->
name
==
"http"
)
{
conf
->
name
=
"http_static"
;
++
it
;
continue
;
}
// SRS3.0, change the refer style
// SRS1/2:
// vhost { refer; refer_play; refer_publish; }
// SRS3+:
// vhost { refer { enabled; all; play; publish; } }
if
((
conf
->
name
==
"refer"
&&
conf
->
directives
.
empty
())
||
conf
->
name
==
"refer_play"
||
conf
->
name
==
"refer_publish"
)
{
// remove the old one first, for name duplicated.
it
=
dir
->
directives
.
erase
(
it
);
SrsConfDirective
*
refer
=
dir
->
get_or_create
(
"refer"
);
refer
->
get_or_create
(
"enabled"
,
"on"
);
if
(
conf
->
name
==
"refer"
)
{
SrsConfDirective
*
all
=
refer
->
get_or_create
(
"all"
);
all
->
args
=
conf
->
args
;
}
else
if
(
conf
->
name
==
"play"
)
{
SrsConfDirective
*
play
=
refer
->
get_or_create
(
"play"
);
play
->
args
=
conf
->
args
;
}
else
if
(
conf
->
name
==
"publish"
)
{
SrsConfDirective
*
publish
=
refer
->
get_or_create
(
"publish"
);
publish
->
args
=
conf
->
args
;
}
// remove the old directive.
srs_freep
(
conf
);
continue
;
}
++
it
;
}
}
return
ret
;
}
...
...
trunk/src/app/srs_app_config.hpp
查看文件 @
7ef3ff9
...
...
@@ -126,6 +126,10 @@ public:
* get the directive by name and its arg0, return the first match.
*/
virtual
SrsConfDirective
*
get
(
std
::
string
_name
,
std
::
string
_arg0
);
// raw
public:
virtual
SrsConfDirective
*
get_or_create
(
std
::
string
n
);
virtual
SrsConfDirective
*
get_or_create
(
std
::
string
n
,
std
::
string
a0
);
// help utilities
public:
/**
...
...
@@ -293,6 +297,7 @@ private:
/**
* reload the http_stream section of config.
*/
// TODO: FIXME: rename to http_server.
virtual
int
reload_http_stream
(
SrsConfDirective
*
old_root
);
/**
* reload the transcode section of vhost of config.
...
...
@@ -518,21 +523,23 @@ public:
*/
virtual
double
get_queue_length
(
std
::
string
vhost
);
/**
* get the refer antisuck directive.
* each args of directive is a refer config.
* when the client refer(pageUrl) not match the refer config,
* SRS will reject the connection.
* @remark, default NULL.
* whether the refer hotlink-denial enabled.
*/
virtual
bool
get_refer_enabled
(
std
::
string
vhost
);
/**
* get the refer hotlink-denial for all type.
* @return the refer, NULL for not configed.
*/
// TODO: FIXME: rename to get_refer_all
virtual
SrsConfDirective
*
get_refer
(
std
::
string
vhost
);
/**
* get the play refer, refer for play clients.
* @remark, default NULL.
* get the refer hotlink-denial for play.
* @return the refer, NULL for not configed.
*/
virtual
SrsConfDirective
*
get_refer_play
(
std
::
string
vhost
);
/**
* get the publish refer, refer for publish clients.
* @remark, default NULL.
* get the refer hotlink-denial for publish.
* @return the refer, NULL for not configed.
*/
virtual
SrsConfDirective
*
get_refer_publish
(
std
::
string
vhost
);
/**
...
...
@@ -1048,10 +1055,6 @@ public:
// http api section
private:
/**
* get the http api directive.
*/
virtual
SrsConfDirective
*
get_http_api
();
/**
* whether http api enabled
*/
virtual
bool
get_http_api_enabled
(
SrsConfDirective
*
conf
);
...
...
@@ -1083,10 +1086,6 @@ public:
// http stream section
private:
/**
* get the http stream directive.
*/
virtual
SrsConfDirective
*
get_http_stream
();
/**
* whether http stream enabled.
*/
virtual
bool
get_http_stream_enabled
(
SrsConfDirective
*
conf
);
...
...
@@ -1094,6 +1093,7 @@ public:
/**
* whether http stream enabled.
*/
// TODO: FIXME: rename to http_static.
virtual
bool
get_http_stream_enabled
();
/**
* get the http stream listen port.
...
...
@@ -1238,6 +1238,20 @@ extern bool srs_stream_caster_is_udp(std::string caster);
extern
bool
srs_stream_caster_is_rtsp
(
std
::
string
caster
);
extern
bool
srs_stream_caster_is_flv
(
std
::
string
caster
);
/**
* parse loaded vhost directives to compatible mode.
* for exmaple, SRS1/2 use the follow refer style:
* refer a.domain.com b.domain.com;
* while SRS3 use the following:
* refer {
* enabled on;
* all a.domain.com b.domain.com;
* }
* so we must transform the vhost directive anytime load the config.
* @param root the root directive to transform, in and out parameter.
*/
extern
int
srs_config_transform_vhost
(
SrsConfDirective
*
root
);
// global config
extern
SrsConfig
*
_srs_config
;
...
...
trunk/src/app/srs_app_rtmp_conn.cpp
查看文件 @
7ef3ff9
...
...
@@ -579,11 +579,13 @@ int SrsRtmpConn::check_vhost()
req
->
vhost
=
vhost
->
arg0
();
}
if
(
_srs_config
->
get_refer_enabled
(
req
->
vhost
))
{
if
((
ret
=
refer
->
check
(
req
->
pageUrl
,
_srs_config
->
get_refer
(
req
->
vhost
)))
!=
ERROR_SUCCESS
)
{
srs_error
(
"check refer failed. ret=%d"
,
ret
);
return
ret
;
}
srs_verbose
(
"check refer success."
);
}
if
((
ret
=
http_hooks_on_connect
())
!=
ERROR_SUCCESS
)
{
return
ret
;
...
...
@@ -637,11 +639,13 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe
srs_assert
(
consumer
!=
NULL
);
if
(
_srs_config
->
get_refer_enabled
(
req
->
vhost
))
{
if
((
ret
=
refer
->
check
(
req
->
pageUrl
,
_srs_config
->
get_refer_play
(
req
->
vhost
)))
!=
ERROR_SUCCESS
)
{
srs_error
(
"check play_refer failed. ret=%d"
,
ret
);
return
ret
;
}
srs_verbose
(
"check play_refer success."
);
}
// initialize other components
SrsPithyPrint
*
pprint
=
SrsPithyPrint
::
create_rtmp_play
();
...
...
@@ -811,11 +815,13 @@ int SrsRtmpConn::publishing(SrsSource* source)
{
int
ret
=
ERROR_SUCCESS
;
if
(
_srs_config
->
get_refer_enabled
(
req
->
vhost
))
{
if
((
ret
=
refer
->
check
(
req
->
pageUrl
,
_srs_config
->
get_refer_publish
(
req
->
vhost
)))
!=
ERROR_SUCCESS
)
{
srs_error
(
"check publish_refer failed. ret=%d"
,
ret
);
return
ret
;
}
srs_verbose
(
"check publish_refer success."
);
}
if
((
ret
=
http_hooks_on_publish
())
!=
ERROR_SUCCESS
)
{
srs_error
(
"http hook on_publish failed. ret=%d"
,
ret
);
...
...
请
注册
或
登录
后发表评论