winlin

refine config, warning when feature disabled.

  1 +# http-hooks or http-callbacks config for srs.
  2 +# @see full.conf for detail config.
  3 +
  4 +listen 1935;
  5 +srs_log_tank file;
  6 +srs_log_file ./objs/srs.log;
  7 +vhost __defaultVhost__ {
  8 + http_hooks {
  9 + enabled on;
  10 + on_connect http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;
  11 + on_close http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;
  12 + on_publish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;
  13 + on_unpublish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;
  14 + on_play http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;
  15 + on_stop http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;
  16 + on_dvr_hss_reap_flv http://127.0.0.1:8085/api/v1/dvrs http://localhost:8085/api/v1/dvrs;
  17 + }
  18 +}
@@ -44,6 +44,8 @@ using namespace std; @@ -44,6 +44,8 @@ using namespace std;
44 #include <srs_app_source.hpp> 44 #include <srs_app_source.hpp>
45 #include <srs_kernel_file.hpp> 45 #include <srs_kernel_file.hpp>
46 46
  47 +using namespace _srs_internal;
  48 +
47 #define SRS_WIKI_URL_LOG "https://github.com/winlinvip/simple-rtmp-server/wiki/SrsLog" 49 #define SRS_WIKI_URL_LOG "https://github.com/winlinvip/simple-rtmp-server/wiki/SrsLog"
48 50
49 #define FILE_OFFSET(fd) lseek(fd, 0, SEEK_CUR) 51 #define FILE_OFFSET(fd) lseek(fd, 0, SEEK_CUR)
@@ -145,13 +147,13 @@ bool SrsConfDirective::is_vhost() @@ -145,13 +147,13 @@ bool SrsConfDirective::is_vhost()
145 return name == "vhost"; 147 return name == "vhost";
146 } 148 }
147 149
148 -int SrsConfDirective::parse(_srs_internal::SrsConfigBuffer* buffer) 150 +int SrsConfDirective::parse(SrsConfigBuffer* buffer)
149 { 151 {
150 return parse_conf(buffer, parse_file); 152 return parse_conf(buffer, parse_file);
151 } 153 }
152 154
153 // see: ngx_conf_parse 155 // see: ngx_conf_parse
154 -int SrsConfDirective::parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDirectiveType type) 156 +int SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveType type)
155 { 157 {
156 int ret = ERROR_SUCCESS; 158 int ret = ERROR_SUCCESS;
157 159
@@ -213,7 +215,7 @@ int SrsConfDirective::parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDire @@ -213,7 +215,7 @@ int SrsConfDirective::parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDire
213 } 215 }
214 216
215 // see: ngx_conf_read_token 217 // see: ngx_conf_read_token
216 -int SrsConfDirective::read_token(_srs_internal::SrsConfigBuffer* buffer, vector<string>& args, int& line_start) 218 +int SrsConfDirective::read_token(SrsConfigBuffer* buffer, vector<string>& args, int& line_start)
217 { 219 {
218 int ret = ERROR_SUCCESS; 220 int ret = ERROR_SUCCESS;
219 221
@@ -1166,7 +1168,7 @@ int SrsConfig::parse_file(const char* filename) @@ -1166,7 +1168,7 @@ int SrsConfig::parse_file(const char* filename)
1166 return ERROR_SYSTEM_CONFIG_INVALID; 1168 return ERROR_SYSTEM_CONFIG_INVALID;
1167 } 1169 }
1168 1170
1169 - _srs_internal::SrsConfigBuffer buffer; 1171 + SrsConfigBuffer buffer;
1170 1172
1171 if ((ret = buffer.fullfill(config_file.c_str())) != ERROR_SUCCESS) { 1173 if ((ret = buffer.fullfill(config_file.c_str())) != ERROR_SUCCESS) {
1172 return ret; 1174 return ret;
@@ -1175,13 +1177,9 @@ int SrsConfig::parse_file(const char* filename) @@ -1175,13 +1177,9 @@ int SrsConfig::parse_file(const char* filename)
1175 return parse_buffer(&buffer); 1177 return parse_buffer(&buffer);
1176 } 1178 }
1177 1179
1178 -int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer) 1180 +int SrsConfig::check_config()
1179 { 1181 {
1180 int ret = ERROR_SUCCESS; 1182 int ret = ERROR_SUCCESS;
1181 -  
1182 - if ((ret = root->parse(buffer)) != ERROR_SUCCESS) {  
1183 - return ret;  
1184 - }  
1185 1183
1186 // check empty 1184 // check empty
1187 if (root->directives.size() == 0) { 1185 if (root->directives.size() == 0) {
@@ -1230,9 +1228,67 @@ int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer) @@ -1230,9 +1228,67 @@ int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer)
1230 srs_trace("write log to console"); 1228 srs_trace("write log to console");
1231 } 1229 }
1232 1230
  1231 + // check features
  1232 +#ifndef SRS_AUTO_HTTP_SERVER
  1233 + if (get_http_stream_enabled()) {
  1234 + srs_warn("http_stream is disabled by configure");
  1235 + }
  1236 +#endif
  1237 +#ifndef SRS_AUTO_HTTP_API
  1238 + if (get_http_api_enabled()) {
  1239 + srs_warn("http_api is disabled by configure");
  1240 + }
  1241 +#endif
  1242 + vector<SrsConfDirective*> vhosts = get_vhosts();
  1243 + for (int i = 0; i < (int)vhosts.size(); i++) {
  1244 + SrsConfDirective* vhost = vhosts[i];
  1245 +#ifndef SRS_AUTO_DVR
  1246 + if (get_dvr_enabled(vhost->arg0())) {
  1247 + srs_warn("dvr of vhost %s is disabled by configure", vhost->arg0().c_str());
  1248 + }
  1249 +#endif
  1250 +#ifndef SRS_AUTO_HLS
  1251 + if (get_hls_enabled(vhost->arg0())) {
  1252 + srs_warn("hls of vhost %s is disabled by configure", vhost->arg0().c_str());
  1253 + }
  1254 +#endif
  1255 +#ifndef SRS_AUTO_HTTP_CALLBACK
  1256 + if (get_vhost_http_hooks_enabled(vhost->arg0())) {
  1257 + srs_warn("http_hooks of vhost %s is disabled by configure", vhost->arg0().c_str());
  1258 + }
  1259 +#endif
  1260 +#ifndef SRS_AUTO_TRANSCODE
  1261 + if (get_transcode_enabled(get_transcode(vhost->arg0(), ""))) {
  1262 + srs_warn("transcode of vhost %s is disabled by configure", vhost->arg0().c_str());
  1263 + }
  1264 +#endif
  1265 +#ifndef SRS_AUTO_INGEST
  1266 + vector<SrsConfDirective*> ingesters = get_ingesters(vhost->arg0());
  1267 + for (int j = 0; j < (int)ingesters.size(); j++) {
  1268 + SrsConfDirective* ingest = ingesters[j];
  1269 + if (get_ingest_enabled(ingest)) {
  1270 + srs_warn("ingest %s of vhost %s is disabled by configure",
  1271 + ingest->arg0().c_str(), vhost->arg0().c_str()
  1272 + );
  1273 + }
  1274 + }
  1275 +#endif
  1276 + }
  1277 +
1233 return ret; 1278 return ret;
1234 } 1279 }
1235 1280
  1281 +int SrsConfig::parse_buffer(SrsConfigBuffer* buffer)
  1282 +{
  1283 + int ret = ERROR_SUCCESS;
  1284 +
  1285 + if ((ret = root->parse(buffer)) != ERROR_SUCCESS) {
  1286 + return ret;
  1287 + }
  1288 +
  1289 + return check_config();
  1290 +}
  1291 +
1236 string SrsConfig::cwd() 1292 string SrsConfig::cwd()
1237 { 1293 {
1238 return _cwd; 1294 return _cwd;
@@ -338,6 +338,11 @@ protected: @@ -338,6 +338,11 @@ protected:
338 * @remark, protected for the utest to override with mock. 338 * @remark, protected for the utest to override with mock.
339 */ 339 */
340 virtual int parse_buffer(_srs_internal::SrsConfigBuffer* buffer); 340 virtual int parse_buffer(_srs_internal::SrsConfigBuffer* buffer);
  341 +private:
  342 + /**
  343 + * check the parsed config.
  344 + */
  345 + virtual int check_config();
341 // global env 346 // global env
342 public: 347 public:
343 /** 348 /**