正在显示
6 个修改的文件
包含
421 行增加
和
222 行删除
trunk/conf/compatible.conf
0 → 100644
| 1 | +listen 1935; | ||
| 2 | +pid ./objs/srs.pid; | ||
| 3 | +srs_log_tank console; | ||
| 4 | +srs_log_level trace; | ||
| 5 | +max_connections 1000; | ||
| 6 | +daemon off; | ||
| 7 | +http_api { | ||
| 8 | + enabled on; | ||
| 9 | + listen 1985; | ||
| 10 | + crossdomain on; | ||
| 11 | + raw_api { | ||
| 12 | + enabled on; | ||
| 13 | + allow_reload on; | ||
| 14 | + allow_query on; | ||
| 15 | + } | ||
| 16 | +} | ||
| 17 | +# for SRS1. | ||
| 18 | +http_stream { | ||
| 19 | + enabled on; | ||
| 20 | + listen 8080; | ||
| 21 | + dir ./objs/nginx/html; | ||
| 22 | +} | ||
| 23 | +vhost __defaultVhost__ { | ||
| 24 | + # for SRS2. | ||
| 25 | + refer github.com github.io; | ||
| 26 | + refer_publish github.com github.io; | ||
| 27 | + refer_play github.com github.io; | ||
| 28 | + | ||
| 29 | + # for SRS1. | ||
| 30 | + http { | ||
| 31 | + enabled on; | ||
| 32 | + mount [vhost]/hls; | ||
| 33 | + dir ./objs/nginx/html/hls; | ||
| 34 | + } | ||
| 35 | +} |
| @@ -230,6 +230,81 @@ stream_caster { | @@ -230,6 +230,81 @@ stream_caster { | ||
| 230 | vhost __defaultVhost__ { | 230 | vhost __defaultVhost__ { |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | +# the vhost for antisuck. | ||
| 234 | +vhost refer.anti_suck.com { | ||
| 235 | + # refer hotlink-denial. | ||
| 236 | + refer { | ||
| 237 | + # whether enable the refer hotlink-denial. | ||
| 238 | + # default: off. | ||
| 239 | + enabled on; | ||
| 240 | + # the common refer for play and publish. | ||
| 241 | + # if the page url of client not in the refer, access denied. | ||
| 242 | + # if not specified this field, allow all. | ||
| 243 | + # default: not specified. | ||
| 244 | + all github.com github.io; | ||
| 245 | + # refer for publish clients specified. | ||
| 246 | + # the common refer is not overrided by this. | ||
| 247 | + # if not specified this field, allow all. | ||
| 248 | + # default: not specified. | ||
| 249 | + publish github.com github.io; | ||
| 250 | + # refer for play clients specified. | ||
| 251 | + # the common refer is not overrided by this. | ||
| 252 | + # if not specified this field, allow all. | ||
| 253 | + # default: not specified. | ||
| 254 | + play github.com github.io; | ||
| 255 | + } | ||
| 256 | +} | ||
| 257 | + | ||
| 258 | +# vhost for bandwidth check | ||
| 259 | +# generally, the bandcheck vhost must be: bandcheck.srs.com, | ||
| 260 | +# or need to modify the vhost of client. | ||
| 261 | +vhost bandcheck.srs.com { | ||
| 262 | + enabled on; | ||
| 263 | + chunk_size 65000; | ||
| 264 | + # bandwidth check config. | ||
| 265 | + bandcheck { | ||
| 266 | + # whether support bandwidth check, | ||
| 267 | + # default: off. | ||
| 268 | + enabled on; | ||
| 269 | + # the key for server to valid, | ||
| 270 | + # if invalid key, server disconnect and abort the bandwidth check. | ||
| 271 | + key "35c9b402c12a7246868752e2878f7e0e"; | ||
| 272 | + # the interval in seconds for bandwidth check, | ||
| 273 | + # server donot allow new test request. | ||
| 274 | + # default: 30 | ||
| 275 | + interval 30; | ||
| 276 | + # the max available check bandwidth in kbps. | ||
| 277 | + # to avoid attack of bandwidth check. | ||
| 278 | + # default: 1000 | ||
| 279 | + limit_kbps 4000; | ||
| 280 | + } | ||
| 281 | +} | ||
| 282 | + | ||
| 283 | + | ||
| 284 | + | ||
| 285 | + | ||
| 286 | + | ||
| 287 | + | ||
| 288 | + | ||
| 289 | + | ||
| 290 | + | ||
| 291 | + | ||
| 292 | + | ||
| 293 | + | ||
| 294 | + | ||
| 295 | + | ||
| 296 | + | ||
| 297 | + | ||
| 298 | + | ||
| 299 | + | ||
| 300 | + | ||
| 301 | + | ||
| 302 | + | ||
| 303 | + | ||
| 304 | + | ||
| 305 | + | ||
| 306 | + | ||
| 307 | + | ||
| 233 | # the security to allow or deny clients. | 308 | # the security to allow or deny clients. |
| 234 | vhost security.srs.com { | 309 | vhost security.srs.com { |
| 235 | # security for host to allow or deny clients. | 310 | # security for host to allow or deny clients. |
| @@ -952,25 +1027,6 @@ vhost stream.control.com { | @@ -952,25 +1027,6 @@ vhost stream.control.com { | ||
| 952 | publish_normal_timeout 7000; | 1027 | publish_normal_timeout 7000; |
| 953 | } | 1028 | } |
| 954 | 1029 | ||
| 955 | -# the vhost for antisuck. | ||
| 956 | -vhost refer.anti_suck.com { | ||
| 957 | - # the common refer for play and publish. | ||
| 958 | - # if the page url of client not in the refer, access denied. | ||
| 959 | - # if not specified this field, allow all. | ||
| 960 | - # default: not specified. | ||
| 961 | - refer github.com github.io; | ||
| 962 | - # refer for publish clients specified. | ||
| 963 | - # the common refer is not overrided by this. | ||
| 964 | - # if not specified this field, allow all. | ||
| 965 | - # default: not specified. | ||
| 966 | - refer_publish github.com github.io; | ||
| 967 | - # refer for play clients specified. | ||
| 968 | - # the common refer is not overrided by this. | ||
| 969 | - # if not specified this field, allow all. | ||
| 970 | - # default: not specified. | ||
| 971 | - refer_play github.com github.io; | ||
| 972 | -} | ||
| 973 | - | ||
| 974 | # the vhost which forward publish streams. | 1030 | # the vhost which forward publish streams. |
| 975 | vhost same.vhost.forward.srs.com { | 1031 | vhost same.vhost.forward.srs.com { |
| 976 | # forward all publish stream to the specified server. | 1032 | # forward all publish stream to the specified server. |
| @@ -1003,31 +1059,6 @@ vhost exec.srs.com { | @@ -1003,31 +1059,6 @@ vhost exec.srs.com { | ||
| 1003 | } | 1059 | } |
| 1004 | } | 1060 | } |
| 1005 | 1061 | ||
| 1006 | -# vhost for bandwidth check | ||
| 1007 | -# generally, the bandcheck vhost must be: bandcheck.srs.com, | ||
| 1008 | -# or need to modify the vhost of client. | ||
| 1009 | -vhost bandcheck.srs.com { | ||
| 1010 | - enabled on; | ||
| 1011 | - chunk_size 65000; | ||
| 1012 | - # bandwidth check config. | ||
| 1013 | - bandcheck { | ||
| 1014 | - # whether support bandwidth check, | ||
| 1015 | - # default: off. | ||
| 1016 | - enabled on; | ||
| 1017 | - # the key for server to valid, | ||
| 1018 | - # if invalid key, server disconnect and abort the bandwidth check. | ||
| 1019 | - key "35c9b402c12a7246868752e2878f7e0e"; | ||
| 1020 | - # the interval in seconds for bandwidth check, | ||
| 1021 | - # server donot allow new test request. | ||
| 1022 | - # default: 30 | ||
| 1023 | - interval 30; | ||
| 1024 | - # the max available check bandwidth in kbps. | ||
| 1025 | - # to avoid attack of bandwidth check. | ||
| 1026 | - # default: 1000 | ||
| 1027 | - limit_kbps 4000; | ||
| 1028 | - } | ||
| 1029 | -} | ||
| 1030 | - | ||
| 1031 | # set the chunk size of vhost. | 1062 | # set the chunk size of vhost. |
| 1032 | vhost chunksize.srs.com { | 1063 | vhost chunksize.srs.com { |
| 1033 | # the default chunk size is 128, max is 65536, | 1064 | # the default chunk size is 128, max is 65536, |
| @@ -43,26 +43,6 @@ stream_caster { | @@ -43,26 +43,6 @@ stream_caster { | ||
| 43 | rtp_port_min 57200; | 43 | rtp_port_min 57200; |
| 44 | rtp_port_max 57300; | 44 | rtp_port_max 57300; |
| 45 | } | 45 | } |
| 46 | -stream_caster { | ||
| 47 | - enabled off; | ||
| 48 | - caster mpegts_over_udp; | ||
| 49 | - output rtmp://127.0.0.1/live/livestream; | ||
| 50 | - listen 8935; | ||
| 51 | -} | ||
| 52 | -stream_caster { | ||
| 53 | - enabled off; | ||
| 54 | - caster rtsp; | ||
| 55 | - output rtmp://127.0.0.1/[app]/[stream]; | ||
| 56 | - listen 554; | ||
| 57 | - rtp_port_min 57200; | ||
| 58 | - rtp_port_max 57300; | ||
| 59 | -} | ||
| 60 | -stream_caster { | ||
| 61 | - enabled off; | ||
| 62 | - caster flv; | ||
| 63 | - output rtmp://127.0.0.1/[app]/[stream]; | ||
| 64 | - listen 8936; | ||
| 65 | -} | ||
| 66 | vhost __defaultVhost__ { | 46 | vhost __defaultVhost__ { |
| 67 | } | 47 | } |
| 68 | vhost vhost.srs.com { | 48 | vhost vhost.srs.com { |
| @@ -98,9 +78,12 @@ vhost vhost.srs.com { | @@ -98,9 +78,12 @@ vhost vhost.srs.com { | ||
| 98 | publish_1stpkt_timeout 20000; | 78 | publish_1stpkt_timeout 20000; |
| 99 | publish_normal_timeout 7000; | 79 | publish_normal_timeout 7000; |
| 100 | 80 | ||
| 101 | - refer github.com github.io; | ||
| 102 | - refer_publish github.com github.io; | ||
| 103 | - refer_play github.com github.io; | 81 | + refer { |
| 82 | + enabled off; | ||
| 83 | + all github.com github.io; | ||
| 84 | + publish github.com github.io; | ||
| 85 | + play github.com github.io; | ||
| 86 | + } | ||
| 104 | 87 | ||
| 105 | bandcheck { | 88 | bandcheck { |
| 106 | enabled off; | 89 | enabled off; |
| @@ -105,15 +105,10 @@ using namespace _srs_internal; | @@ -105,15 +105,10 @@ using namespace _srs_internal; | ||
| 105 | // the interval in seconds for bandwidth check | 105 | // the interval in seconds for bandwidth check |
| 106 | #define SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS 1000 | 106 | #define SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS 1000 |
| 107 | 107 | ||
| 108 | -#define SRS_CONF_DEFAULT_HTTP_MOUNT "[vhost]/" | ||
| 109 | #define SRS_CONF_DEFAULT_HTTP_REMUX_MOUNT "[vhost]/[app]/[stream].flv" | 108 | #define SRS_CONF_DEFAULT_HTTP_REMUX_MOUNT "[vhost]/[app]/[stream].flv" |
| 110 | #define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH | 109 | #define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH |
| 111 | #define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 0 | 110 | #define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 0 |
| 112 | 111 | ||
| 113 | -#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT "8080" | ||
| 114 | -#define SRS_CONF_DEFAULT_HTTP_API_PORT "1985" | ||
| 115 | -#define SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN true | ||
| 116 | - | ||
| 117 | #define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED false | 112 | #define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED false |
| 118 | #define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INTERVAL 9.9 | 113 | #define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INTERVAL 9.9 |
| 119 | #define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_URL "http://"SRS_CONSTS_LOCALHOST":8085/api/v1/servers" | 114 | #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) | @@ -228,6 +223,37 @@ SrsConfDirective* SrsConfDirective::get(string _name, string _arg0) | ||
| 228 | return NULL; | 223 | return NULL; |
| 229 | } | 224 | } |
| 230 | 225 | ||
| 226 | +SrsConfDirective* SrsConfDirective::get_or_create(string n) | ||
| 227 | +{ | ||
| 228 | + SrsConfDirective* conf = get(n); | ||
| 229 | + | ||
| 230 | + if (!conf) { | ||
| 231 | + conf = new SrsConfDirective(); | ||
| 232 | + conf->name = n; | ||
| 233 | + directives.push_back(conf); | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + return conf; | ||
| 237 | +} | ||
| 238 | + | ||
| 239 | +SrsConfDirective* SrsConfDirective::get_or_create(string n, string a0) | ||
| 240 | +{ | ||
| 241 | + SrsConfDirective* conf = get_or_create(n); | ||
| 242 | + | ||
| 243 | + if (conf->arg0() == a0) { | ||
| 244 | + return conf; | ||
| 245 | + } | ||
| 246 | + | ||
| 247 | + // update a0. | ||
| 248 | + if (!conf->args.empty()) { | ||
| 249 | + conf->args.erase(conf->args.begin()); | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + conf->args.insert(conf->args.begin(), a0); | ||
| 253 | + | ||
| 254 | + return conf; | ||
| 255 | +} | ||
| 256 | + | ||
| 231 | bool SrsConfDirective::is_vhost() | 257 | bool SrsConfDirective::is_vhost() |
| 232 | { | 258 | { |
| 233 | return name == "vhost"; | 259 | return name == "vhost"; |
| @@ -644,6 +670,12 @@ int SrsConfig::reload() | @@ -644,6 +670,12 @@ int SrsConfig::reload() | ||
| 644 | return ret; | 670 | return ret; |
| 645 | } | 671 | } |
| 646 | srs_info("config reloader parse file success."); | 672 | srs_info("config reloader parse file success."); |
| 673 | + | ||
| 674 | + // transform config to compatible with previous style of config. | ||
| 675 | + if ((ret = srs_config_transform_vhost(conf.root)) != ERROR_SUCCESS) { | ||
| 676 | + srs_error("transform config failed. ret=%d", ret); | ||
| 677 | + return ret; | ||
| 678 | + } | ||
| 647 | 679 | ||
| 648 | if ((ret = conf.check_config()) != ERROR_SUCCESS) { | 680 | if ((ret = conf.check_config()) != ERROR_SUCCESS) { |
| 649 | srs_error("ignore config reloader check config failed. ret=%d", ret); | 681 | srs_error("ignore config reloader check config failed. ret=%d", ret); |
| @@ -958,20 +990,7 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) | @@ -958,20 +990,7 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) | ||
| 958 | srs_trace("vhost %s reload min_latency success.", vhost.c_str()); | 990 | srs_trace("vhost %s reload min_latency success.", vhost.c_str()); |
| 959 | } | 991 | } |
| 960 | 992 | ||
| 961 | - // http, only one per vhost. | ||
| 962 | - if (!srs_directive_equals(new_vhost->get("http"), old_vhost->get("http"))) { | ||
| 963 | - for (it = subscribes.begin(); it != subscribes.end(); ++it) { | ||
| 964 | - ISrsReloadHandler* subscribe = *it; | ||
| 965 | - if ((ret = subscribe->on_reload_vhost_http_updated()) != ERROR_SUCCESS) { | ||
| 966 | - srs_error("vhost %s notify subscribes http failed. ret=%d", vhost.c_str(), ret); | ||
| 967 | - return ret; | ||
| 968 | - } | ||
| 969 | - } | ||
| 970 | - srs_trace("vhost %s reload http success.", vhost.c_str()); | ||
| 971 | - } | ||
| 972 | - | ||
| 973 | // http_static, only one per vhost. | 993 | // http_static, only one per vhost. |
| 974 | - // @remark, http_static introduced as alias of http. | ||
| 975 | if (!srs_directive_equals(new_vhost->get("http_static"), old_vhost->get("http_static"))) { | 994 | if (!srs_directive_equals(new_vhost->get("http_static"), old_vhost->get("http_static"))) { |
| 976 | for (it = subscribes.begin(); it != subscribes.end(); ++it) { | 995 | for (it = subscribes.begin(); it != subscribes.end(); ++it) { |
| 977 | ISrsReloadHandler* subscribe = *it; | 996 | ISrsReloadHandler* subscribe = *it; |
| @@ -1239,17 +1258,8 @@ int SrsConfig::reload_http_stream(SrsConfDirective* old_root) | @@ -1239,17 +1258,8 @@ int SrsConfig::reload_http_stream(SrsConfDirective* old_root) | ||
| 1239 | // ENABLED => DISABLED | 1258 | // ENABLED => DISABLED |
| 1240 | // ENABLED => ENABLED (modified) | 1259 | // ENABLED => ENABLED (modified) |
| 1241 | 1260 | ||
| 1242 | - SrsConfDirective* new_http_stream = root->get("http_stream"); | ||
| 1243 | - // http_stream rename to http_server in SRS2. | ||
| 1244 | - if (!new_http_stream) { | ||
| 1245 | - new_http_stream = root->get("http_server"); | ||
| 1246 | - } | ||
| 1247 | - | ||
| 1248 | - SrsConfDirective* old_http_stream = old_root->get("http_stream"); | ||
| 1249 | - // http_stream rename to http_server in SRS2. | ||
| 1250 | - if (!old_http_stream) { | ||
| 1251 | - old_http_stream = root->get("http_server"); | ||
| 1252 | - } | 1261 | + SrsConfDirective* new_http_stream = root->get("http_server"); |
| 1262 | + SrsConfDirective* old_http_stream = old_root->get("http_server"); | ||
| 1253 | 1263 | ||
| 1254 | // DISABLED => ENABLED | 1264 | // DISABLED => ENABLED |
| 1255 | if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) { | 1265 | 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) | @@ -1524,6 +1534,12 @@ int SrsConfig::parse_options(int argc, char** argv) | ||
| 1524 | 1534 | ||
| 1525 | ret = parse_file(config_file.c_str()); | 1535 | ret = parse_file(config_file.c_str()); |
| 1526 | 1536 | ||
| 1537 | + // transform config to compatible with previous style of config. | ||
| 1538 | + if ((ret = srs_config_transform_vhost(root)) != ERROR_SUCCESS) { | ||
| 1539 | + srs_error("transform config failed. ret=%d", ret); | ||
| 1540 | + return ret; | ||
| 1541 | + } | ||
| 1542 | + | ||
| 1527 | if (test_conf) { | 1543 | if (test_conf) { |
| 1528 | // the parse_file never check the config, | 1544 | // the parse_file never check the config, |
| 1529 | // we check it when user requires check config file. | 1545 | // we check it when user requires check config file. |
| @@ -1735,7 +1751,7 @@ int SrsConfig::global_to_json(SrsAmf0Object* obj) | @@ -1735,7 +1751,7 @@ int SrsConfig::global_to_json(SrsAmf0Object* obj) | ||
| 1735 | sobj->set("forward", SrsAmf0Any::boolean(get_forward(dir->name))); | 1751 | sobj->set("forward", SrsAmf0Any::boolean(get_forward(dir->name))); |
| 1736 | 1752 | ||
| 1737 | sobj->set("security", SrsAmf0Any::boolean(get_security_enabled(dir->name))); | 1753 | sobj->set("security", SrsAmf0Any::boolean(get_security_enabled(dir->name))); |
| 1738 | - sobj->set("refer", SrsAmf0Any::boolean(get_refer(dir->name) || get_refer_play(dir->name) || get_refer_publish(dir->name))); | 1754 | + sobj->set("refer", SrsAmf0Any::boolean(get_refer_enabled(dir->name))); |
| 1739 | 1755 | ||
| 1740 | sobj->set("mr", SrsAmf0Any::boolean(get_mr_enabled(dir->name))); | 1756 | sobj->set("mr", SrsAmf0Any::boolean(get_mr_enabled(dir->name))); |
| 1741 | sobj->set("min_latency", SrsAmf0Any::boolean(get_realtime_enabled(dir->name))); | 1757 | sobj->set("min_latency", SrsAmf0Any::boolean(get_realtime_enabled(dir->name))); |
| @@ -1905,13 +1921,22 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) | @@ -1905,13 +1921,22 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) | ||
| 1905 | 1921 | ||
| 1906 | // refer | 1922 | // refer |
| 1907 | if ((dir = vhost->get("refer")) != NULL) { | 1923 | if ((dir = vhost->get("refer")) != NULL) { |
| 1908 | - obj->set("refer", dir->dumps_args()); | ||
| 1909 | - } | ||
| 1910 | - if ((dir = vhost->get("refer_publish")) != NULL) { | ||
| 1911 | - obj->set("refer_publish", dir->dumps_args()); | ||
| 1912 | - } | ||
| 1913 | - if ((dir = vhost->get("refer_play")) != NULL) { | ||
| 1914 | - obj->set("refer_play", dir->dumps_args()); | 1924 | + SrsAmf0Object* refer = SrsAmf0Any::object(); |
| 1925 | + obj->set("refer", refer); | ||
| 1926 | + | ||
| 1927 | + for (int i = 0; i < (int)dir->directives.size(); i++) { | ||
| 1928 | + SrsConfDirective* sdir = dir->directives.at(i); | ||
| 1929 | + | ||
| 1930 | + if (sdir->name == "enabled") { | ||
| 1931 | + refer->set("enabled", sdir->dumps_arg0_to_boolean()); | ||
| 1932 | + } else if (sdir->name == "all") { | ||
| 1933 | + refer->set("all", sdir->dumps_args()); | ||
| 1934 | + } else if (sdir->name == "publish") { | ||
| 1935 | + refer->set("publish", sdir->dumps_args()); | ||
| 1936 | + } else if (sdir->name == "play") { | ||
| 1937 | + refer->set("play", sdir->dumps_args()); | ||
| 1938 | + } | ||
| 1939 | + } | ||
| 1915 | } | 1940 | } |
| 1916 | 1941 | ||
| 1917 | // bandcheck | 1942 | // bandcheck |
| @@ -2495,7 +2520,7 @@ int SrsConfig::check_config() | @@ -2495,7 +2520,7 @@ int SrsConfig::check_config() | ||
| 2495 | && n != "srs_log_tank" && n != "srs_log_level" && n != "srs_log_file" | 2520 | && n != "srs_log_tank" && n != "srs_log_level" && n != "srs_log_file" |
| 2496 | && n != "max_connections" && n != "daemon" && n != "heartbeat" | 2521 | && n != "max_connections" && n != "daemon" && n != "heartbeat" |
| 2497 | && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms" | 2522 | && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms" |
| 2498 | - && n != "http_stream" && n != "http_server" && n != "stream_caster" | 2523 | + && n != "http_server" && n != "stream_caster" |
| 2499 | && n != "utc_time" | 2524 | && n != "utc_time" |
| 2500 | ) { | 2525 | ) { |
| 2501 | ret = ERROR_SYSTEM_CONFIG_INVALID; | 2526 | ret = ERROR_SYSTEM_CONFIG_INVALID; |
| @@ -2504,7 +2529,7 @@ int SrsConfig::check_config() | @@ -2504,7 +2529,7 @@ int SrsConfig::check_config() | ||
| 2504 | } | 2529 | } |
| 2505 | } | 2530 | } |
| 2506 | if (true) { | 2531 | if (true) { |
| 2507 | - SrsConfDirective* conf = get_http_api(); | 2532 | + SrsConfDirective* conf = root->get("http_api"); |
| 2508 | for (int i = 0; conf && i < (int)conf->directives.size(); i++) { | 2533 | for (int i = 0; conf && i < (int)conf->directives.size(); i++) { |
| 2509 | SrsConfDirective* obj = conf->at(i); | 2534 | SrsConfDirective* obj = conf->at(i); |
| 2510 | string n = obj->name; | 2535 | string n = obj->name; |
| @@ -2527,7 +2552,7 @@ int SrsConfig::check_config() | @@ -2527,7 +2552,7 @@ int SrsConfig::check_config() | ||
| 2527 | } | 2552 | } |
| 2528 | } | 2553 | } |
| 2529 | if (true) { | 2554 | if (true) { |
| 2530 | - SrsConfDirective* conf = get_http_stream(); | 2555 | + SrsConfDirective* conf = root->get("http_server"); |
| 2531 | for (int i = 0; conf && i < (int)conf->directives.size(); i++) { | 2556 | for (int i = 0; conf && i < (int)conf->directives.size(); i++) { |
| 2532 | string n = conf->at(i)->name; | 2557 | string n = conf->at(i)->name; |
| 2533 | if (n != "enabled" && n != "listen" && n != "dir") { | 2558 | if (n != "enabled" && n != "listen" && n != "dir") { |
| @@ -2751,8 +2776,7 @@ int SrsConfig::check_config() | @@ -2751,8 +2776,7 @@ int SrsConfig::check_config() | ||
| 2751 | && n != "mode" && n != "origin" && n != "token_traverse" && n != "vhost" | 2776 | && n != "mode" && n != "origin" && n != "token_traverse" && n != "vhost" |
| 2752 | && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks" | 2777 | && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks" |
| 2753 | && n != "gop_cache" && n != "queue_length" | 2778 | && n != "gop_cache" && n != "queue_length" |
| 2754 | - && n != "refer" && n != "refer_publish" && n != "refer_play" | ||
| 2755 | - && n != "forward" && n != "transcode" && n != "bandcheck" | 2779 | + && n != "refer" && n != "forward" && n != "transcode" && n != "bandcheck" |
| 2756 | && n != "time_jitter" && n != "mix_correct" | 2780 | && n != "time_jitter" && n != "mix_correct" |
| 2757 | && n != "atc" && n != "atc_auto" | 2781 | && n != "atc" && n != "atc_auto" |
| 2758 | && n != "debug_srs_upnode" | 2782 | && n != "debug_srs_upnode" |
| @@ -2760,8 +2784,7 @@ int SrsConfig::check_config() | @@ -2760,8 +2784,7 @@ int SrsConfig::check_config() | ||
| 2760 | && n != "tcp_nodelay" && n != "send_min_interval" && n != "reduce_sequence_header" | 2784 | && n != "tcp_nodelay" && n != "send_min_interval" && n != "reduce_sequence_header" |
| 2761 | && n != "publish_1stpkt_timeout" && n != "publish_normal_timeout" | 2785 | && n != "publish_1stpkt_timeout" && n != "publish_normal_timeout" |
| 2762 | && n != "security" && n != "http_remux" | 2786 | && n != "security" && n != "http_remux" |
| 2763 | - && n != "http" && n != "http_static" | ||
| 2764 | - && n != "hds" && n != "exec" | 2787 | + && n != "http_static" && n != "hds" && n != "exec" |
| 2765 | ) { | 2788 | ) { |
| 2766 | ret = ERROR_SYSTEM_CONFIG_INVALID; | 2789 | ret = ERROR_SYSTEM_CONFIG_INVALID; |
| 2767 | srs_error("unsupported vhost directive %s, ret=%d", n.c_str(), ret); | 2790 | srs_error("unsupported vhost directive %s, ret=%d", n.c_str(), ret); |
| @@ -2779,6 +2802,15 @@ int SrsConfig::check_config() | @@ -2779,6 +2802,15 @@ int SrsConfig::check_config() | ||
| 2779 | return ret; | 2802 | return ret; |
| 2780 | } | 2803 | } |
| 2781 | } | 2804 | } |
| 2805 | + } else if (n == "refer") { | ||
| 2806 | + for (int j = 0; j < (int)conf->directives.size(); j++) { | ||
| 2807 | + string m = conf->at(j)->name.c_str(); | ||
| 2808 | + if (m != "enabled" && m != "all" && m != "publish" && m != "play") { | ||
| 2809 | + ret = ERROR_SYSTEM_CONFIG_INVALID; | ||
| 2810 | + srs_error("unsupported vhost refer directive %s, ret=%d", m.c_str(), ret); | ||
| 2811 | + return ret; | ||
| 2812 | + } | ||
| 2813 | + } | ||
| 2782 | } else if (n == "exec") { | 2814 | } else if (n == "exec") { |
| 2783 | for (int j = 0; j < (int)conf->directives.size(); j++) { | 2815 | for (int j = 0; j < (int)conf->directives.size(); j++) { |
| 2784 | string m = conf->at(j)->name.c_str(); | 2816 | string m = conf->at(j)->name.c_str(); |
| @@ -2806,7 +2838,7 @@ int SrsConfig::check_config() | @@ -2806,7 +2838,7 @@ int SrsConfig::check_config() | ||
| 2806 | return ret; | 2838 | return ret; |
| 2807 | } | 2839 | } |
| 2808 | } | 2840 | } |
| 2809 | - } else if (n == "http" || n == "http_static") { | 2841 | + } else if (n == "http_static") { |
| 2810 | for (int j = 0; j < (int)conf->directives.size(); j++) { | 2842 | for (int j = 0; j < (int)conf->directives.size(); j++) { |
| 2811 | string m = conf->at(j)->name.c_str(); | 2843 | string m = conf->at(j)->name.c_str(); |
| 2812 | if (m != "enabled" && m != "mount" && m != "dir") { | 2844 | if (m != "enabled" && m != "mount" && m != "dir") { |
| @@ -3372,37 +3404,77 @@ double SrsConfig::get_queue_length(string vhost) | @@ -3372,37 +3404,77 @@ double SrsConfig::get_queue_length(string vhost) | ||
| 3372 | return ::atoi(conf->arg0().c_str()); | 3404 | return ::atoi(conf->arg0().c_str()); |
| 3373 | } | 3405 | } |
| 3374 | 3406 | ||
| 3375 | -SrsConfDirective* SrsConfig::get_refer(string vhost) | 3407 | +bool SrsConfig::get_refer_enabled(string vhost) |
| 3376 | { | 3408 | { |
| 3409 | + static bool DEFAULT = false; | ||
| 3410 | + | ||
| 3377 | SrsConfDirective* conf = get_vhost(vhost); | 3411 | SrsConfDirective* conf = get_vhost(vhost); |
| 3412 | + if (!conf) { | ||
| 3413 | + return DEFAULT; | ||
| 3414 | + } | ||
| 3415 | + | ||
| 3416 | + conf = conf->get("refer"); | ||
| 3417 | + if (!conf) { | ||
| 3418 | + return DEFAULT; | ||
| 3419 | + } | ||
| 3420 | + | ||
| 3421 | + conf = conf->get("enabled"); | ||
| 3422 | + if (!conf || conf->arg0().empty()) { | ||
| 3423 | + return DEFAULT; | ||
| 3424 | + } | ||
| 3425 | + | ||
| 3426 | + return SRS_CONF_PERFER_FALSE(conf->arg0()); | ||
| 3427 | +} | ||
| 3378 | 3428 | ||
| 3429 | +SrsConfDirective* SrsConfig::get_refer(string vhost) | ||
| 3430 | +{ | ||
| 3431 | + static SrsConfDirective* DEFAULT = NULL; | ||
| 3432 | + | ||
| 3433 | + SrsConfDirective* conf = get_vhost(vhost); | ||
| 3379 | if (!conf) { | 3434 | if (!conf) { |
| 3380 | - return NULL; | 3435 | + return DEFAULT; |
| 3381 | } | 3436 | } |
| 3382 | 3437 | ||
| 3383 | - return conf->get("refer"); | 3438 | + conf = conf->get("refer"); |
| 3439 | + if (!conf) { | ||
| 3440 | + return DEFAULT; | ||
| 3441 | + } | ||
| 3442 | + | ||
| 3443 | + return conf->get("all"); | ||
| 3384 | } | 3444 | } |
| 3385 | 3445 | ||
| 3386 | SrsConfDirective* SrsConfig::get_refer_play(string vhost) | 3446 | SrsConfDirective* SrsConfig::get_refer_play(string vhost) |
| 3387 | { | 3447 | { |
| 3448 | + static SrsConfDirective* DEFAULT = NULL; | ||
| 3449 | + | ||
| 3388 | SrsConfDirective* conf = get_vhost(vhost); | 3450 | SrsConfDirective* conf = get_vhost(vhost); |
| 3389 | - | ||
| 3390 | if (!conf) { | 3451 | if (!conf) { |
| 3391 | - return NULL; | 3452 | + return DEFAULT; |
| 3453 | + } | ||
| 3454 | + | ||
| 3455 | + conf = conf->get("refer"); | ||
| 3456 | + if (!conf) { | ||
| 3457 | + return DEFAULT; | ||
| 3392 | } | 3458 | } |
| 3393 | 3459 | ||
| 3394 | - return conf->get("refer_play"); | 3460 | + return conf->get("play"); |
| 3395 | } | 3461 | } |
| 3396 | 3462 | ||
| 3397 | SrsConfDirective* SrsConfig::get_refer_publish(string vhost) | 3463 | SrsConfDirective* SrsConfig::get_refer_publish(string vhost) |
| 3398 | { | 3464 | { |
| 3465 | + static SrsConfDirective* DEFAULT = NULL; | ||
| 3466 | + | ||
| 3399 | SrsConfDirective* conf = get_vhost(vhost); | 3467 | SrsConfDirective* conf = get_vhost(vhost); |
| 3400 | - | ||
| 3401 | if (!conf) { | 3468 | if (!conf) { |
| 3402 | - return NULL; | 3469 | + return DEFAULT; |
| 3470 | + } | ||
| 3471 | + | ||
| 3472 | + conf = conf->get("refer"); | ||
| 3473 | + if (!conf) { | ||
| 3474 | + return DEFAULT; | ||
| 3403 | } | 3475 | } |
| 3404 | 3476 | ||
| 3405 | - return conf->get("refer_publish"); | 3477 | + return conf->get("publish"); |
| 3406 | } | 3478 | } |
| 3407 | 3479 | ||
| 3408 | int SrsConfig::get_chunk_size(string vhost) | 3480 | int SrsConfig::get_chunk_size(string vhost) |
| @@ -5046,24 +5118,21 @@ int SrsConfig::get_dvr_time_jitter(string vhost) | @@ -5046,24 +5118,21 @@ int SrsConfig::get_dvr_time_jitter(string vhost) | ||
| 5046 | 5118 | ||
| 5047 | bool SrsConfig::get_http_api_enabled() | 5119 | bool SrsConfig::get_http_api_enabled() |
| 5048 | { | 5120 | { |
| 5049 | - SrsConfDirective* conf = get_http_api(); | 5121 | + SrsConfDirective* conf = root->get("http_api"); |
| 5050 | return get_http_api_enabled(conf); | 5122 | return get_http_api_enabled(conf); |
| 5051 | } | 5123 | } |
| 5052 | 5124 | ||
| 5053 | -SrsConfDirective* SrsConfig::get_http_api() | ||
| 5054 | -{ | ||
| 5055 | - return root->get("http_api"); | ||
| 5056 | -} | ||
| 5057 | - | ||
| 5058 | bool SrsConfig::get_http_api_enabled(SrsConfDirective* conf) | 5125 | bool SrsConfig::get_http_api_enabled(SrsConfDirective* conf) |
| 5059 | { | 5126 | { |
| 5127 | + static bool DEFAULT = false; | ||
| 5128 | + | ||
| 5060 | if (!conf) { | 5129 | if (!conf) { |
| 5061 | - return false; | 5130 | + return DEFAULT; |
| 5062 | } | 5131 | } |
| 5063 | 5132 | ||
| 5064 | conf = conf->get("enabled"); | 5133 | conf = conf->get("enabled"); |
| 5065 | if (!conf || conf->arg0().empty()) { | 5134 | if (!conf || conf->arg0().empty()) { |
| 5066 | - return false; | 5135 | + return DEFAULT; |
| 5067 | } | 5136 | } |
| 5068 | 5137 | ||
| 5069 | return SRS_CONF_PERFER_FALSE(conf->arg0()); | 5138 | return SRS_CONF_PERFER_FALSE(conf->arg0()); |
| @@ -5071,15 +5140,17 @@ bool SrsConfig::get_http_api_enabled(SrsConfDirective* conf) | @@ -5071,15 +5140,17 @@ bool SrsConfig::get_http_api_enabled(SrsConfDirective* conf) | ||
| 5071 | 5140 | ||
| 5072 | string SrsConfig::get_http_api_listen() | 5141 | string SrsConfig::get_http_api_listen() |
| 5073 | { | 5142 | { |
| 5074 | - SrsConfDirective* conf = get_http_api(); | 5143 | + static string DEFAULT = "1985"; |
| 5144 | + | ||
| 5145 | + SrsConfDirective* conf = root->get("http_api"); | ||
| 5075 | 5146 | ||
| 5076 | if (!conf) { | 5147 | if (!conf) { |
| 5077 | - return SRS_CONF_DEFAULT_HTTP_API_PORT; | 5148 | + return DEFAULT; |
| 5078 | } | 5149 | } |
| 5079 | 5150 | ||
| 5080 | conf = conf->get("listen"); | 5151 | conf = conf->get("listen"); |
| 5081 | if (!conf || conf->arg0().empty()) { | 5152 | if (!conf || conf->arg0().empty()) { |
| 5082 | - return SRS_CONF_DEFAULT_HTTP_API_PORT; | 5153 | + return DEFAULT; |
| 5083 | } | 5154 | } |
| 5084 | 5155 | ||
| 5085 | return conf->arg0(); | 5156 | return conf->arg0(); |
| @@ -5087,15 +5158,17 @@ string SrsConfig::get_http_api_listen() | @@ -5087,15 +5158,17 @@ string SrsConfig::get_http_api_listen() | ||
| 5087 | 5158 | ||
| 5088 | bool SrsConfig::get_http_api_crossdomain() | 5159 | bool SrsConfig::get_http_api_crossdomain() |
| 5089 | { | 5160 | { |
| 5090 | - SrsConfDirective* conf = get_http_api(); | 5161 | + static bool DEFAULT = true; |
| 5162 | + | ||
| 5163 | + SrsConfDirective* conf = root->get("http_api"); | ||
| 5091 | 5164 | ||
| 5092 | if (!conf) { | 5165 | if (!conf) { |
| 5093 | - return SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN; | 5166 | + return DEFAULT; |
| 5094 | } | 5167 | } |
| 5095 | 5168 | ||
| 5096 | conf = conf->get("crossdomain"); | 5169 | conf = conf->get("crossdomain"); |
| 5097 | if (!conf || conf->arg0().empty()) { | 5170 | if (!conf || conf->arg0().empty()) { |
| 5098 | - return SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN; | 5171 | + return DEFAULT; |
| 5099 | } | 5172 | } |
| 5100 | 5173 | ||
| 5101 | return SRS_CONF_PERFER_TRUE(conf->arg0()); | 5174 | return SRS_CONF_PERFER_TRUE(conf->arg0()); |
| @@ -5105,7 +5178,7 @@ bool SrsConfig::get_raw_api() | @@ -5105,7 +5178,7 @@ bool SrsConfig::get_raw_api() | ||
| 5105 | { | 5178 | { |
| 5106 | static bool DEFAULT = false; | 5179 | static bool DEFAULT = false; |
| 5107 | 5180 | ||
| 5108 | - SrsConfDirective* conf = get_http_api(); | 5181 | + SrsConfDirective* conf = root->get("http_api"); |
| 5109 | if (!conf) { | 5182 | if (!conf) { |
| 5110 | return DEFAULT; | 5183 | return DEFAULT; |
| 5111 | } | 5184 | } |
| @@ -5127,7 +5200,7 @@ bool SrsConfig::get_raw_api_allow_reload() | @@ -5127,7 +5200,7 @@ bool SrsConfig::get_raw_api_allow_reload() | ||
| 5127 | { | 5200 | { |
| 5128 | static bool DEFAULT = false; | 5201 | static bool DEFAULT = false; |
| 5129 | 5202 | ||
| 5130 | - SrsConfDirective* conf = get_http_api(); | 5203 | + SrsConfDirective* conf = root->get("http_api"); |
| 5131 | if (!conf) { | 5204 | if (!conf) { |
| 5132 | return DEFAULT; | 5205 | return DEFAULT; |
| 5133 | } | 5206 | } |
| @@ -5149,7 +5222,7 @@ bool SrsConfig::get_raw_api_allow_query() | @@ -5149,7 +5222,7 @@ bool SrsConfig::get_raw_api_allow_query() | ||
| 5149 | { | 5222 | { |
| 5150 | static bool DEFAULT = false; | 5223 | static bool DEFAULT = false; |
| 5151 | 5224 | ||
| 5152 | - SrsConfDirective* conf = get_http_api(); | 5225 | + SrsConfDirective* conf = root->get("http_api"); |
| 5153 | if (!conf) { | 5226 | if (!conf) { |
| 5154 | return DEFAULT; | 5227 | return DEFAULT; |
| 5155 | } | 5228 | } |
| @@ -5169,30 +5242,21 @@ bool SrsConfig::get_raw_api_allow_query() | @@ -5169,30 +5242,21 @@ bool SrsConfig::get_raw_api_allow_query() | ||
| 5169 | 5242 | ||
| 5170 | bool SrsConfig::get_http_stream_enabled() | 5243 | bool SrsConfig::get_http_stream_enabled() |
| 5171 | { | 5244 | { |
| 5172 | - SrsConfDirective* conf = get_http_stream(); | 5245 | + SrsConfDirective* conf = root->get("http_server"); |
| 5173 | return get_http_stream_enabled(conf); | 5246 | return get_http_stream_enabled(conf); |
| 5174 | } | 5247 | } |
| 5175 | 5248 | ||
| 5176 | -SrsConfDirective* SrsConfig::get_http_stream() | ||
| 5177 | -{ | ||
| 5178 | - SrsConfDirective* conf = root->get("http_stream"); | ||
| 5179 | - // http_stream renamed to http_server in SRS2. | ||
| 5180 | - if (!conf) { | ||
| 5181 | - conf = root->get("http_server"); | ||
| 5182 | - } | ||
| 5183 | - | ||
| 5184 | - return conf; | ||
| 5185 | -} | ||
| 5186 | - | ||
| 5187 | bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf) | 5249 | bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf) |
| 5188 | { | 5250 | { |
| 5251 | + static bool DEFAULT = false; | ||
| 5252 | + | ||
| 5189 | if (!conf) { | 5253 | if (!conf) { |
| 5190 | - return false; | 5254 | + return DEFAULT; |
| 5191 | } | 5255 | } |
| 5192 | 5256 | ||
| 5193 | conf = conf->get("enabled"); | 5257 | conf = conf->get("enabled"); |
| 5194 | if (!conf || conf->arg0().empty()) { | 5258 | if (!conf || conf->arg0().empty()) { |
| 5195 | - return false; | 5259 | + return DEFAULT; |
| 5196 | } | 5260 | } |
| 5197 | 5261 | ||
| 5198 | return SRS_CONF_PERFER_FALSE(conf->arg0()); | 5262 | return SRS_CONF_PERFER_FALSE(conf->arg0()); |
| @@ -5200,15 +5264,17 @@ bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf) | @@ -5200,15 +5264,17 @@ bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf) | ||
| 5200 | 5264 | ||
| 5201 | string SrsConfig::get_http_stream_listen() | 5265 | string SrsConfig::get_http_stream_listen() |
| 5202 | { | 5266 | { |
| 5203 | - SrsConfDirective* conf = get_http_stream(); | 5267 | + static string DEFAULT = "8080"; |
| 5268 | + | ||
| 5269 | + SrsConfDirective* conf = root->get("http_server"); | ||
| 5204 | 5270 | ||
| 5205 | if (!conf) { | 5271 | if (!conf) { |
| 5206 | - return SRS_CONF_DEFAULT_HTTP_STREAM_PORT; | 5272 | + return DEFAULT; |
| 5207 | } | 5273 | } |
| 5208 | 5274 | ||
| 5209 | conf = conf->get("listen"); | 5275 | conf = conf->get("listen"); |
| 5210 | if (!conf || conf->arg0().empty()) { | 5276 | if (!conf || conf->arg0().empty()) { |
| 5211 | - return SRS_CONF_DEFAULT_HTTP_STREAM_PORT; | 5277 | + return DEFAULT; |
| 5212 | } | 5278 | } |
| 5213 | 5279 | ||
| 5214 | return conf->arg0(); | 5280 | return conf->arg0(); |
| @@ -5216,18 +5282,16 @@ string SrsConfig::get_http_stream_listen() | @@ -5216,18 +5282,16 @@ string SrsConfig::get_http_stream_listen() | ||
| 5216 | 5282 | ||
| 5217 | string SrsConfig::get_http_stream_dir() | 5283 | string SrsConfig::get_http_stream_dir() |
| 5218 | { | 5284 | { |
| 5219 | - SrsConfDirective* conf = get_http_stream(); | ||
| 5220 | - if (!conf) { | ||
| 5221 | - return SRS_CONF_DEFAULT_HTTP_DIR; | ||
| 5222 | - } | 5285 | + static string DEFAULT = "./objs/nginx/html"; |
| 5223 | 5286 | ||
| 5224 | - conf = conf->get("dir"); | 5287 | + SrsConfDirective* conf = root->get("http_server"); |
| 5225 | if (!conf) { | 5288 | if (!conf) { |
| 5226 | - return SRS_CONF_DEFAULT_HTTP_DIR; | 5289 | + return DEFAULT; |
| 5227 | } | 5290 | } |
| 5228 | 5291 | ||
| 5229 | - if (conf->arg0().empty()) { | ||
| 5230 | - return SRS_CONF_DEFAULT_HTTP_DIR; | 5292 | + conf = conf->get("dir"); |
| 5293 | + if (!conf || conf->arg0().empty()) { | ||
| 5294 | + return DEFAULT; | ||
| 5231 | } | 5295 | } |
| 5232 | 5296 | ||
| 5233 | return conf->arg0(); | 5297 | return conf->arg0(); |
| @@ -5235,23 +5299,21 @@ string SrsConfig::get_http_stream_dir() | @@ -5235,23 +5299,21 @@ string SrsConfig::get_http_stream_dir() | ||
| 5235 | 5299 | ||
| 5236 | bool SrsConfig::get_vhost_http_enabled(string vhost) | 5300 | bool SrsConfig::get_vhost_http_enabled(string vhost) |
| 5237 | { | 5301 | { |
| 5238 | - SrsConfDirective* vconf = get_vhost(vhost); | ||
| 5239 | - if (!vconf) { | ||
| 5240 | - return false; | ||
| 5241 | - } | 5302 | + static bool DEFAULT = false; |
| 5242 | 5303 | ||
| 5243 | - SrsConfDirective* conf = vconf->get("http"); | 5304 | + SrsConfDirective* conf = get_vhost(vhost); |
| 5244 | if (!conf) { | 5305 | if (!conf) { |
| 5245 | - conf = vconf->get("http_static"); | 5306 | + return DEFAULT; |
| 5246 | } | 5307 | } |
| 5247 | 5308 | ||
| 5309 | + conf = conf->get("http_static"); | ||
| 5248 | if (!conf) { | 5310 | if (!conf) { |
| 5249 | - return false; | 5311 | + return DEFAULT; |
| 5250 | } | 5312 | } |
| 5251 | 5313 | ||
| 5252 | conf = conf->get("enabled"); | 5314 | conf = conf->get("enabled"); |
| 5253 | if (!conf || conf->arg0().empty()) { | 5315 | if (!conf || conf->arg0().empty()) { |
| 5254 | - return false; | 5316 | + return DEFAULT; |
| 5255 | } | 5317 | } |
| 5256 | 5318 | ||
| 5257 | return SRS_CONF_PERFER_FALSE(conf->arg0()); | 5319 | return SRS_CONF_PERFER_FALSE(conf->arg0()); |
| @@ -5259,22 +5321,21 @@ bool SrsConfig::get_vhost_http_enabled(string vhost) | @@ -5259,22 +5321,21 @@ bool SrsConfig::get_vhost_http_enabled(string vhost) | ||
| 5259 | 5321 | ||
| 5260 | string SrsConfig::get_vhost_http_mount(string vhost) | 5322 | string SrsConfig::get_vhost_http_mount(string vhost) |
| 5261 | { | 5323 | { |
| 5262 | - SrsConfDirective* vconf = get_vhost(vhost); | ||
| 5263 | - if (!vconf) { | ||
| 5264 | - return SRS_CONF_DEFAULT_HTTP_MOUNT; | 5324 | + static string DEFAULT = "[vhost]/"; |
| 5325 | + | ||
| 5326 | + SrsConfDirective* conf = get_vhost(vhost); | ||
| 5327 | + if (!conf) { | ||
| 5328 | + return DEFAULT; | ||
| 5265 | } | 5329 | } |
| 5266 | 5330 | ||
| 5267 | - SrsConfDirective* conf = vconf->get("http"); | 5331 | + conf = conf->get("http_static"); |
| 5268 | if (!conf) { | 5332 | if (!conf) { |
| 5269 | - conf = vconf->get("http_static"); | ||
| 5270 | - if (!conf) { | ||
| 5271 | - return SRS_CONF_DEFAULT_HTTP_MOUNT; | ||
| 5272 | - } | 5333 | + return DEFAULT; |
| 5273 | } | 5334 | } |
| 5274 | 5335 | ||
| 5275 | conf = conf->get("mount"); | 5336 | conf = conf->get("mount"); |
| 5276 | if (!conf || conf->arg0().empty()) { | 5337 | if (!conf || conf->arg0().empty()) { |
| 5277 | - return SRS_CONF_DEFAULT_HTTP_MOUNT; | 5338 | + return DEFAULT; |
| 5278 | } | 5339 | } |
| 5279 | 5340 | ||
| 5280 | return conf->arg0(); | 5341 | return conf->arg0(); |
| @@ -5282,22 +5343,21 @@ string SrsConfig::get_vhost_http_mount(string vhost) | @@ -5282,22 +5343,21 @@ string SrsConfig::get_vhost_http_mount(string vhost) | ||
| 5282 | 5343 | ||
| 5283 | string SrsConfig::get_vhost_http_dir(string vhost) | 5344 | string SrsConfig::get_vhost_http_dir(string vhost) |
| 5284 | { | 5345 | { |
| 5285 | - SrsConfDirective* vconf = get_vhost(vhost); | ||
| 5286 | - if (!vconf) { | ||
| 5287 | - return SRS_CONF_DEFAULT_HTTP_DIR; | 5346 | + static string DEFAULT = "./objs/nginx/html"; |
| 5347 | + | ||
| 5348 | + SrsConfDirective* conf = get_vhost(vhost); | ||
| 5349 | + if (!conf) { | ||
| 5350 | + return DEFAULT; | ||
| 5288 | } | 5351 | } |
| 5289 | 5352 | ||
| 5290 | - SrsConfDirective* conf = vconf->get("http"); | 5353 | + conf = conf->get("http_static"); |
| 5291 | if (!conf) { | 5354 | if (!conf) { |
| 5292 | - conf = vconf->get("http_static"); | ||
| 5293 | - if (!conf) { | ||
| 5294 | - return SRS_CONF_DEFAULT_HTTP_DIR; | ||
| 5295 | - } | 5355 | + return DEFAULT; |
| 5296 | } | 5356 | } |
| 5297 | 5357 | ||
| 5298 | conf = conf->get("dir"); | 5358 | conf = conf->get("dir"); |
| 5299 | if (!conf || conf->arg0().empty()) { | 5359 | if (!conf || conf->arg0().empty()) { |
| 5300 | - return SRS_CONF_DEFAULT_HTTP_DIR; | 5360 | + return DEFAULT; |
| 5301 | } | 5361 | } |
| 5302 | 5362 | ||
| 5303 | return conf->arg0(); | 5363 | return conf->arg0(); |
| @@ -5650,3 +5710,73 @@ bool srs_stream_caster_is_flv(string caster) | @@ -5650,3 +5710,73 @@ bool srs_stream_caster_is_flv(string caster) | ||
| 5650 | { | 5710 | { |
| 5651 | return caster == SRS_CONF_DEFAULT_STREAM_CASTER_FLV; | 5711 | return caster == SRS_CONF_DEFAULT_STREAM_CASTER_FLV; |
| 5652 | } | 5712 | } |
| 5713 | + | ||
| 5714 | +int srs_config_transform_vhost(SrsConfDirective* root) | ||
| 5715 | +{ | ||
| 5716 | + int ret = ERROR_SUCCESS; | ||
| 5717 | + | ||
| 5718 | + for (int i = 0; i < root->directives.size(); i++) { | ||
| 5719 | + SrsConfDirective* dir = root->directives.at(i); | ||
| 5720 | + | ||
| 5721 | + // SRS2.0, rename global http_stream to http_server. | ||
| 5722 | + // SRS1: | ||
| 5723 | + // http_stream {} | ||
| 5724 | + // SRS2+: | ||
| 5725 | + // http_server {} | ||
| 5726 | + if (dir->name == "http_stream") { | ||
| 5727 | + dir->name = "http_server"; | ||
| 5728 | + continue; | ||
| 5729 | + } | ||
| 5730 | + | ||
| 5731 | + if (!dir->is_vhost()) { | ||
| 5732 | + continue; | ||
| 5733 | + } | ||
| 5734 | + | ||
| 5735 | + std::vector<SrsConfDirective*>::iterator it; | ||
| 5736 | + for (it = dir->directives.begin(); it != dir->directives.end();) { | ||
| 5737 | + SrsConfDirective* conf = *it; | ||
| 5738 | + | ||
| 5739 | + // SRS2.0, rename vhost http to http_static | ||
| 5740 | + // SRS1: | ||
| 5741 | + // vhost { http {} } | ||
| 5742 | + // SRS2+: | ||
| 5743 | + // vhost { http_static {} } | ||
| 5744 | + if (conf->name == "http") { | ||
| 5745 | + conf->name = "http_static"; | ||
| 5746 | + ++it; | ||
| 5747 | + continue; | ||
| 5748 | + } | ||
| 5749 | + | ||
| 5750 | + // SRS3.0, change the refer style | ||
| 5751 | + // SRS1/2: | ||
| 5752 | + // vhost { refer; refer_play; refer_publish; } | ||
| 5753 | + // SRS3+: | ||
| 5754 | + // vhost { refer { enabled; all; play; publish; } } | ||
| 5755 | + if ((conf->name == "refer" && conf->directives.empty()) || conf->name == "refer_play" || conf->name == "refer_publish") { | ||
| 5756 | + // remove the old one first, for name duplicated. | ||
| 5757 | + it = dir->directives.erase(it); | ||
| 5758 | + | ||
| 5759 | + SrsConfDirective* refer = dir->get_or_create("refer"); | ||
| 5760 | + refer->get_or_create("enabled", "on"); | ||
| 5761 | + if (conf->name == "refer") { | ||
| 5762 | + SrsConfDirective* all = refer->get_or_create("all"); | ||
| 5763 | + all->args = conf->args; | ||
| 5764 | + } else if (conf->name == "play") { | ||
| 5765 | + SrsConfDirective* play = refer->get_or_create("play"); | ||
| 5766 | + play->args = conf->args; | ||
| 5767 | + } else if (conf->name == "publish") { | ||
| 5768 | + SrsConfDirective* publish = refer->get_or_create("publish"); | ||
| 5769 | + publish->args = conf->args; | ||
| 5770 | + } | ||
| 5771 | + | ||
| 5772 | + // remove the old directive. | ||
| 5773 | + srs_freep(conf); | ||
| 5774 | + continue; | ||
| 5775 | + } | ||
| 5776 | + | ||
| 5777 | + ++it; | ||
| 5778 | + } | ||
| 5779 | + } | ||
| 5780 | + | ||
| 5781 | + return ret; | ||
| 5782 | +} |
| @@ -126,6 +126,10 @@ public: | @@ -126,6 +126,10 @@ public: | ||
| 126 | * get the directive by name and its arg0, return the first match. | 126 | * get the directive by name and its arg0, return the first match. |
| 127 | */ | 127 | */ |
| 128 | virtual SrsConfDirective* get(std::string _name, std::string _arg0); | 128 | virtual SrsConfDirective* get(std::string _name, std::string _arg0); |
| 129 | +// raw | ||
| 130 | +public: | ||
| 131 | + virtual SrsConfDirective* get_or_create(std::string n); | ||
| 132 | + virtual SrsConfDirective* get_or_create(std::string n, std::string a0); | ||
| 129 | // help utilities | 133 | // help utilities |
| 130 | public: | 134 | public: |
| 131 | /** | 135 | /** |
| @@ -293,6 +297,7 @@ private: | @@ -293,6 +297,7 @@ private: | ||
| 293 | /** | 297 | /** |
| 294 | * reload the http_stream section of config. | 298 | * reload the http_stream section of config. |
| 295 | */ | 299 | */ |
| 300 | + // TODO: FIXME: rename to http_server. | ||
| 296 | virtual int reload_http_stream(SrsConfDirective* old_root); | 301 | virtual int reload_http_stream(SrsConfDirective* old_root); |
| 297 | /** | 302 | /** |
| 298 | * reload the transcode section of vhost of config. | 303 | * reload the transcode section of vhost of config. |
| @@ -518,22 +523,24 @@ public: | @@ -518,22 +523,24 @@ public: | ||
| 518 | */ | 523 | */ |
| 519 | virtual double get_queue_length(std::string vhost); | 524 | virtual double get_queue_length(std::string vhost); |
| 520 | /** | 525 | /** |
| 521 | - * get the refer antisuck directive. | ||
| 522 | - * each args of directive is a refer config. | ||
| 523 | - * when the client refer(pageUrl) not match the refer config, | ||
| 524 | - * SRS will reject the connection. | ||
| 525 | - * @remark, default NULL. | ||
| 526 | - */ | 526 | + * whether the refer hotlink-denial enabled. |
| 527 | + */ | ||
| 528 | + virtual bool get_refer_enabled(std::string vhost); | ||
| 529 | + /** | ||
| 530 | + * get the refer hotlink-denial for all type. | ||
| 531 | + * @return the refer, NULL for not configed. | ||
| 532 | + */ | ||
| 533 | + // TODO: FIXME: rename to get_refer_all | ||
| 527 | virtual SrsConfDirective* get_refer(std::string vhost); | 534 | virtual SrsConfDirective* get_refer(std::string vhost); |
| 528 | /** | 535 | /** |
| 529 | - * get the play refer, refer for play clients. | ||
| 530 | - * @remark, default NULL. | ||
| 531 | - */ | 536 | + * get the refer hotlink-denial for play. |
| 537 | + * @return the refer, NULL for not configed. | ||
| 538 | + */ | ||
| 532 | virtual SrsConfDirective* get_refer_play(std::string vhost); | 539 | virtual SrsConfDirective* get_refer_play(std::string vhost); |
| 533 | /** | 540 | /** |
| 534 | - * get the publish refer, refer for publish clients. | ||
| 535 | - * @remark, default NULL. | ||
| 536 | - */ | 541 | + * get the refer hotlink-denial for publish. |
| 542 | + * @return the refer, NULL for not configed. | ||
| 543 | + */ | ||
| 537 | virtual SrsConfDirective* get_refer_publish(std::string vhost); | 544 | virtual SrsConfDirective* get_refer_publish(std::string vhost); |
| 538 | /** | 545 | /** |
| 539 | * get the chunk size of vhost. | 546 | * get the chunk size of vhost. |
| @@ -1048,10 +1055,6 @@ public: | @@ -1048,10 +1055,6 @@ public: | ||
| 1048 | // http api section | 1055 | // http api section |
| 1049 | private: | 1056 | private: |
| 1050 | /** | 1057 | /** |
| 1051 | - * get the http api directive. | ||
| 1052 | - */ | ||
| 1053 | - virtual SrsConfDirective* get_http_api(); | ||
| 1054 | - /** | ||
| 1055 | * whether http api enabled | 1058 | * whether http api enabled |
| 1056 | */ | 1059 | */ |
| 1057 | virtual bool get_http_api_enabled(SrsConfDirective* conf); | 1060 | virtual bool get_http_api_enabled(SrsConfDirective* conf); |
| @@ -1083,10 +1086,6 @@ public: | @@ -1083,10 +1086,6 @@ public: | ||
| 1083 | // http stream section | 1086 | // http stream section |
| 1084 | private: | 1087 | private: |
| 1085 | /** | 1088 | /** |
| 1086 | - * get the http stream directive. | ||
| 1087 | - */ | ||
| 1088 | - virtual SrsConfDirective* get_http_stream(); | ||
| 1089 | - /** | ||
| 1090 | * whether http stream enabled. | 1089 | * whether http stream enabled. |
| 1091 | */ | 1090 | */ |
| 1092 | virtual bool get_http_stream_enabled(SrsConfDirective* conf); | 1091 | virtual bool get_http_stream_enabled(SrsConfDirective* conf); |
| @@ -1094,6 +1093,7 @@ public: | @@ -1094,6 +1093,7 @@ public: | ||
| 1094 | /** | 1093 | /** |
| 1095 | * whether http stream enabled. | 1094 | * whether http stream enabled. |
| 1096 | */ | 1095 | */ |
| 1096 | + // TODO: FIXME: rename to http_static. | ||
| 1097 | virtual bool get_http_stream_enabled(); | 1097 | virtual bool get_http_stream_enabled(); |
| 1098 | /** | 1098 | /** |
| 1099 | * get the http stream listen port. | 1099 | * get the http stream listen port. |
| @@ -1238,6 +1238,20 @@ extern bool srs_stream_caster_is_udp(std::string caster); | @@ -1238,6 +1238,20 @@ extern bool srs_stream_caster_is_udp(std::string caster); | ||
| 1238 | extern bool srs_stream_caster_is_rtsp(std::string caster); | 1238 | extern bool srs_stream_caster_is_rtsp(std::string caster); |
| 1239 | extern bool srs_stream_caster_is_flv(std::string caster); | 1239 | extern bool srs_stream_caster_is_flv(std::string caster); |
| 1240 | 1240 | ||
| 1241 | +/** | ||
| 1242 | + * parse loaded vhost directives to compatible mode. | ||
| 1243 | + * for exmaple, SRS1/2 use the follow refer style: | ||
| 1244 | + * refer a.domain.com b.domain.com; | ||
| 1245 | + * while SRS3 use the following: | ||
| 1246 | + * refer { | ||
| 1247 | + * enabled on; | ||
| 1248 | + * all a.domain.com b.domain.com; | ||
| 1249 | + * } | ||
| 1250 | + * so we must transform the vhost directive anytime load the config. | ||
| 1251 | + * @param root the root directive to transform, in and out parameter. | ||
| 1252 | + */ | ||
| 1253 | +extern int srs_config_transform_vhost(SrsConfDirective* root); | ||
| 1254 | + | ||
| 1241 | // global config | 1255 | // global config |
| 1242 | extern SrsConfig* _srs_config; | 1256 | extern SrsConfig* _srs_config; |
| 1243 | 1257 |
| @@ -579,11 +579,13 @@ int SrsRtmpConn::check_vhost() | @@ -579,11 +579,13 @@ int SrsRtmpConn::check_vhost() | ||
| 579 | req->vhost = vhost->arg0(); | 579 | req->vhost = vhost->arg0(); |
| 580 | } | 580 | } |
| 581 | 581 | ||
| 582 | - if ((ret = refer->check(req->pageUrl, _srs_config->get_refer(req->vhost))) != ERROR_SUCCESS) { | ||
| 583 | - srs_error("check refer failed. ret=%d", ret); | ||
| 584 | - return ret; | 582 | + if (_srs_config->get_refer_enabled(req->vhost)) { |
| 583 | + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer(req->vhost))) != ERROR_SUCCESS) { | ||
| 584 | + srs_error("check refer failed. ret=%d", ret); | ||
| 585 | + return ret; | ||
| 586 | + } | ||
| 587 | + srs_verbose("check refer success."); | ||
| 585 | } | 588 | } |
| 586 | - srs_verbose("check refer success."); | ||
| 587 | 589 | ||
| 588 | if ((ret = http_hooks_on_connect()) != ERROR_SUCCESS) { | 590 | if ((ret = http_hooks_on_connect()) != ERROR_SUCCESS) { |
| 589 | return ret; | 591 | return ret; |
| @@ -637,11 +639,13 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe | @@ -637,11 +639,13 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe | ||
| 637 | 639 | ||
| 638 | srs_assert(consumer != NULL); | 640 | srs_assert(consumer != NULL); |
| 639 | 641 | ||
| 640 | - if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != ERROR_SUCCESS) { | ||
| 641 | - srs_error("check play_refer failed. ret=%d", ret); | ||
| 642 | - return ret; | 642 | + if (_srs_config->get_refer_enabled(req->vhost)) { |
| 643 | + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != ERROR_SUCCESS) { | ||
| 644 | + srs_error("check play_refer failed. ret=%d", ret); | ||
| 645 | + return ret; | ||
| 646 | + } | ||
| 647 | + srs_verbose("check play_refer success."); | ||
| 643 | } | 648 | } |
| 644 | - srs_verbose("check play_refer success."); | ||
| 645 | 649 | ||
| 646 | // initialize other components | 650 | // initialize other components |
| 647 | SrsPithyPrint* pprint = SrsPithyPrint::create_rtmp_play(); | 651 | SrsPithyPrint* pprint = SrsPithyPrint::create_rtmp_play(); |
| @@ -810,12 +814,14 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe | @@ -810,12 +814,14 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe | ||
| 810 | int SrsRtmpConn::publishing(SrsSource* source) | 814 | int SrsRtmpConn::publishing(SrsSource* source) |
| 811 | { | 815 | { |
| 812 | int ret = ERROR_SUCCESS; | 816 | int ret = ERROR_SUCCESS; |
| 813 | - | ||
| 814 | - if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) { | ||
| 815 | - srs_error("check publish_refer failed. ret=%d", ret); | ||
| 816 | - return ret; | 817 | + |
| 818 | + if (_srs_config->get_refer_enabled(req->vhost)) { | ||
| 819 | + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) { | ||
| 820 | + srs_error("check publish_refer failed. ret=%d", ret); | ||
| 821 | + return ret; | ||
| 822 | + } | ||
| 823 | + srs_verbose("check publish_refer success."); | ||
| 817 | } | 824 | } |
| 818 | - srs_verbose("check publish_refer success."); | ||
| 819 | 825 | ||
| 820 | if ((ret = http_hooks_on_publish()) != ERROR_SUCCESS) { | 826 | if ((ret = http_hooks_on_publish()) != ERROR_SUCCESS) { |
| 821 | srs_error("http hook on_publish failed. ret=%d", ret); | 827 | srs_error("http hook on_publish failed. ret=%d", ret); |
-
请 注册 或 登录 后发表评论