winlin

refine config, check all config item name.

@@ -1181,14 +1181,18 @@ int SrsConfig::check_config() @@ -1181,14 +1181,18 @@ int SrsConfig::check_config()
1181 { 1181 {
1182 int ret = ERROR_SUCCESS; 1182 int ret = ERROR_SUCCESS;
1183 1183
  1184 + ////////////////////////////////////////////////////////////////////////
1184 // check empty 1185 // check empty
  1186 + ////////////////////////////////////////////////////////////////////////
1185 if (root->directives.size() == 0) { 1187 if (root->directives.size() == 0) {
1186 ret = ERROR_SYSTEM_CONFIG_INVALID; 1188 ret = ERROR_SYSTEM_CONFIG_INVALID;
1187 srs_error("conf is empty, ret=%d", ret); 1189 srs_error("conf is empty, ret=%d", ret);
1188 return ret; 1190 return ret;
1189 } 1191 }
1190 1192
  1193 + ////////////////////////////////////////////////////////////////////////
1191 // check root directives. 1194 // check root directives.
  1195 + ////////////////////////////////////////////////////////////////////////
1192 for (int i = 0; i < (int)root->directives.size(); i++) { 1196 for (int i = 0; i < (int)root->directives.size(); i++) {
1193 SrsConfDirective* conf = root->at(i); 1197 SrsConfDirective* conf = root->at(i);
1194 std::string n = conf->name; 1198 std::string n = conf->name;
@@ -1203,32 +1207,228 @@ int SrsConfig::check_config() @@ -1203,32 +1207,228 @@ int SrsConfig::check_config()
1203 return ret; 1207 return ret;
1204 } 1208 }
1205 } 1209 }
  1210 + if (true) {
  1211 + SrsConfDirective* conf = get_http_api();
  1212 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1213 + string n = conf->at(i)->name;
  1214 + if (n != "enabled" && n != "listen") {
  1215 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1216 + srs_error("unsupported http_api directive %s, ret=%d", n.c_str(), ret);
  1217 + return ret;
  1218 + }
  1219 + }
  1220 + }
  1221 + if (true) {
  1222 + SrsConfDirective* conf = get_http_stream();
  1223 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1224 + string n = conf->at(i)->name;
  1225 + if (n != "enabled" && n != "listen" && n != "dir") {
  1226 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1227 + srs_error("unsupported http_stream directive %s, ret=%d", n.c_str(), ret);
  1228 + return ret;
  1229 + }
  1230 + }
  1231 + }
  1232 + if (true) {
  1233 + SrsConfDirective* conf = get_heartbeart();
  1234 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1235 + string n = conf->at(i)->name;
  1236 + if (n != "enabled" && n != "interval" && n != "url"
  1237 + && n != "device_id" && n != "device_index" && n != "summaries"
  1238 + ) {
  1239 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1240 + srs_error("unsupported heartbeat directive %s, ret=%d", n.c_str(), ret);
  1241 + return ret;
  1242 + }
  1243 + }
  1244 + }
  1245 + if (true) {
  1246 + SrsConfDirective* conf = get_pithy_print();
  1247 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1248 + string n = conf->at(i)->name;
  1249 + if (n != "publish" && n != "play" && n != "forwarder"
  1250 + && n != "encoder" && n != "ingester" && n != "hls" && n != "edge"
  1251 + ) {
  1252 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1253 + srs_error("unsupported pithy_print directive %s, ret=%d", n.c_str(), ret);
  1254 + return ret;
  1255 + }
  1256 + }
  1257 + }
  1258 + if (true) {
  1259 + vector<SrsConfDirective*> vhosts = get_vhosts();
  1260 + for (int i = 0; i < (int)vhosts.size(); i++) {
  1261 + SrsConfDirective* conf = vhosts[i];
  1262 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1263 + SrsConfDirective* conf0 = conf->at(i);
  1264 + string n = conf0->name;
  1265 + if (n != "enabled" && n != "chunk_size"
  1266 + && n != "mode" && n != "origin" && n != "token_traverse"
  1267 + && n != "dvr" && n != "ingest" && n != "http" && n != "hls" && n != "http_hooks"
  1268 + && n != "gop_cache" && n != "queue_length"
  1269 + && n != "refer" && n != "refer_publish" && n != "refer_play"
  1270 + && n != "forward" && n != "transcode" && n != "bandcheck"
  1271 + && n != "time_jitter"
  1272 + && n != "atc" && n != "atc_auto"
  1273 + ) {
  1274 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1275 + srs_error("unsupported vhost directive %s, ret=%d", n.c_str(), ret);
  1276 + return ret;
  1277 + }
  1278 + // for each sub directives of vhost.
  1279 + if (n == "dvr") {
  1280 + for (int j = 0; j < (int)conf0->directives.size(); j++) {
  1281 + string m = conf0->at(j)->name.c_str();
  1282 + if (m != "enabled" && m != "dvr_path" && m != "dvr_plan"
  1283 + && m != "dvr_duration" && m != "time_jitter"
  1284 + ) {
  1285 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1286 + srs_error("unsupported vhost dvr directive %s, ret=%d", m.c_str(), ret);
  1287 + return ret;
  1288 + }
  1289 + }
  1290 + } else if (n == "ingest") {
  1291 + for (int j = 0; j < (int)conf0->directives.size(); j++) {
  1292 + string m = conf0->at(j)->name.c_str();
  1293 + if (m != "enabled" && m != "input" && m != "ffmpeg"
  1294 + && m != "engine"
  1295 + ) {
  1296 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1297 + srs_error("unsupported vhost ingest directive %s, ret=%d", m.c_str(), ret);
  1298 + return ret;
  1299 + }
  1300 + }
  1301 + } else if (n == "http") {
  1302 + for (int j = 0; j < (int)conf0->directives.size(); j++) {
  1303 + string m = conf0->at(j)->name.c_str();
  1304 + if (m != "enabled" && m != "mount" && m != "dir") {
  1305 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1306 + srs_error("unsupported vhost http directive %s, ret=%d", m.c_str(), ret);
  1307 + return ret;
  1308 + }
  1309 + }
  1310 + } else if (n == "hls") {
  1311 + for (int j = 0; j < (int)conf0->directives.size(); j++) {
  1312 + string m = conf0->at(j)->name.c_str();
  1313 + if (m != "enabled" && m != "hls_path" && m != "hls_fragment" && m != "hls_window") {
  1314 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1315 + srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret);
  1316 + return ret;
  1317 + }
  1318 + }
  1319 + } else if (n == "http_hooks") {
  1320 + for (int j = 0; j < (int)conf0->directives.size(); j++) {
  1321 + string m = conf0->at(j)->name.c_str();
  1322 + if (m != "enabled" && m != "on_connect" && m != "on_close" && m != "on_publish"
  1323 + && m != "on_unpublish" && m != "on_play" && m != "on_stop" && m != "on_dvr_hss_reap_flv"
  1324 + ) {
  1325 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1326 + srs_error("unsupported vhost http_hooks directive %s, ret=%d", m.c_str(), ret);
  1327 + return ret;
  1328 + }
  1329 + }
  1330 + } else if (n == "forward") {
  1331 + // TODO: FIXME: implements it.
  1332 + /*for (int j = 0; j < (int)conf0->directives.size(); j++) {
  1333 + string m = conf0->at(j)->name.c_str();
  1334 + if (m != "enabled" && m != "vhost" && m != "refer") {
  1335 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1336 + srs_error("unsupported vhost forward directive %s, ret=%d", m.c_str(), ret);
  1337 + return ret;
  1338 + }
  1339 + }*/
  1340 + } else if (n == "transcode") {
  1341 + for (int j = 0; j < (int)conf0->directives.size(); j++) {
  1342 + SrsConfDirective* conf1 = conf0->at(j);
  1343 + string m = conf1->name.c_str();
  1344 + if (m != "enabled" && m != "ffmpeg" && m != "engine") {
  1345 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1346 + srs_error("unsupported vhost transcode directive %s, ret=%d", m.c_str(), ret);
  1347 + return ret;
  1348 + }
  1349 + if (m == "engine") {
  1350 + for (int k = 0; k < (int)conf1->directives.size(); k++) {
  1351 + string e = conf1->at(k)->name;
  1352 + if (e != "enabled" && e != "vfilter" && e != "vcodec"
  1353 + && e != "vbitrate" && e != "vfps" && e != "vwidth" && e != "vheight"
  1354 + && e != "vthreads" && e != "vprofile" && e != "vpreset" && e != "vparams"
  1355 + && e != "acodec" && e != "abitrate" && e != "asample_rate" && e != "achannels"
  1356 + && e != "aparams" && e != "output"
  1357 + ) {
  1358 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1359 + srs_error("unsupported vhost transcode engine directive %s, ret=%d", e.c_str(), ret);
  1360 + return ret;
  1361 + }
  1362 + }
  1363 + }
  1364 + }
  1365 + } else if (n == "bandcheck") {
  1366 + for (int j = 0; j < (int)conf0->directives.size(); j++) {
  1367 + string m = conf0->at(j)->name.c_str();
  1368 + if (m != "enabled" && m != "key" && m != "interval" && m != "limit_kbps") {
  1369 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1370 + srs_error("unsupported vhost bandcheck directive %s, ret=%d", m.c_str(), ret);
  1371 + return ret;
  1372 + }
  1373 + }
  1374 + }
  1375 + }
  1376 + }
  1377 + }
  1378 +
  1379 + ////////////////////////////////////////////////////////////////////////
  1380 + // check listen for rtmp.
  1381 + ////////////////////////////////////////////////////////////////////////
  1382 + if (true) {
  1383 + vector<string> listens = get_listen();
  1384 + if (listens.size() <= 0) {
  1385 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1386 + srs_error("directive \"listen\" is empty, ret=%d", ret);
  1387 + return ret;
  1388 + }
  1389 + for (int i = 0; i < (int)listens.size(); i++) {
  1390 + string port = listens[i];
  1391 + if (port.empty() || ::atoi(port.c_str()) <= 0) {
  1392 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1393 + srs_error("directive listen invalid, port=%s, ret=%d", port.c_str(), ret);
  1394 + return ret;
  1395 + }
  1396 + }
  1397 + }
1206 1398
1207 - // check rtmp port specified by directive listen.  
1208 - if (get_listen().size() <= 0) { 1399 + ////////////////////////////////////////////////////////////////////////
  1400 + // check max connections
  1401 + ////////////////////////////////////////////////////////////////////////
  1402 + if (get_max_connections() <= 0) {
1209 ret = ERROR_SYSTEM_CONFIG_INVALID; 1403 ret = ERROR_SYSTEM_CONFIG_INVALID;
1210 - srs_error("directive \"listen\" is empty, ret=%d", ret); 1404 + srs_error("directive max_connections invalid, max_connections=%d, ret=%d", get_max_connections(), ret);
1211 return ret; 1405 return ret;
1212 } 1406 }
1213 1407
1214 // TODO: FIXME: check others. 1408 // TODO: FIXME: check others.
1215 1409
1216 - // check log  
1217 - std::string log_filename = this->get_log_file();  
1218 - if (get_log_tank_file() && log_filename.empty()) {  
1219 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1220 - srs_error("must specifies the file to write log to. ret=%d", ret);  
1221 - return ret;  
1222 - }  
1223 - if (get_log_tank_file()) {  
1224 - srs_trace("write log to file %s", log_filename.c_str());  
1225 - srs_trace("you can: tailf %s", log_filename.c_str());  
1226 - srs_trace("@see: %s", SRS_WIKI_URL_LOG);  
1227 - } else {  
1228 - srs_trace("write log to console"); 1410 + ////////////////////////////////////////////////////////////////////////
  1411 + // check log name and level
  1412 + ////////////////////////////////////////////////////////////////////////
  1413 + if (true) {
  1414 + std::string log_filename = this->get_log_file();
  1415 + if (get_log_tank_file() && log_filename.empty()) {
  1416 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1417 + srs_error("must specifies the file to write log to. ret=%d", ret);
  1418 + return ret;
  1419 + }
  1420 + if (get_log_tank_file()) {
  1421 + srs_trace("write log to file %s", log_filename.c_str());
  1422 + srs_trace("you can: tailf %s", log_filename.c_str());
  1423 + srs_trace("@see: %s", SRS_WIKI_URL_LOG);
  1424 + } else {
  1425 + srs_trace("write log to console");
  1426 + }
1229 } 1427 }
1230 1428
  1429 + ////////////////////////////////////////////////////////////////////////
1231 // check features 1430 // check features
  1431 + ////////////////////////////////////////////////////////////////////////
1232 #ifndef SRS_AUTO_HTTP_SERVER 1432 #ifndef SRS_AUTO_HTTP_SERVER
1233 if (get_http_stream_enabled()) { 1433 if (get_http_stream_enabled()) {
1234 srs_warn("http_stream is disabled by configure"); 1434 srs_warn("http_stream is disabled by configure");
@@ -1242,6 +1442,7 @@ int SrsConfig::check_config() @@ -1242,6 +1442,7 @@ int SrsConfig::check_config()
1242 vector<SrsConfDirective*> vhosts = get_vhosts(); 1442 vector<SrsConfDirective*> vhosts = get_vhosts();
1243 for (int i = 0; i < (int)vhosts.size(); i++) { 1443 for (int i = 0; i < (int)vhosts.size(); i++) {
1244 SrsConfDirective* vhost = vhosts[i]; 1444 SrsConfDirective* vhost = vhosts[i];
  1445 + srs_assert(vhost != NULL);
1245 #ifndef SRS_AUTO_DVR 1446 #ifndef SRS_AUTO_DVR
1246 if (get_dvr_enabled(vhost->arg0())) { 1447 if (get_dvr_enabled(vhost->arg0())) {
1247 srs_warn("dvr of vhost %s is disabled by configure", vhost->arg0().c_str()); 1448 srs_warn("dvr of vhost %s is disabled by configure", vhost->arg0().c_str());
@@ -1355,9 +1556,14 @@ string SrsConfig::get_pid_file() @@ -1355,9 +1556,14 @@ string SrsConfig::get_pid_file()
1355 return conf->arg0(); 1556 return conf->arg0();
1356 } 1557 }
1357 1558
  1559 +SrsConfDirective* SrsConfig::get_pithy_print()
  1560 +{
  1561 + return root->get("pithy_print");
  1562 +}
  1563 +
1358 int SrsConfig::get_pithy_print_publish() 1564 int SrsConfig::get_pithy_print_publish()
1359 { 1565 {
1360 - SrsConfDirective* pithy = root->get("pithy_print"); 1566 + SrsConfDirective* pithy = get_pithy_print();
1361 if (!pithy) { 1567 if (!pithy) {
1362 return SRS_CONF_DEFAULT_STAGE_PUBLISH_USER_INTERVAL_MS; 1568 return SRS_CONF_DEFAULT_STAGE_PUBLISH_USER_INTERVAL_MS;
1363 } 1569 }
@@ -1372,7 +1578,7 @@ int SrsConfig::get_pithy_print_publish() @@ -1372,7 +1578,7 @@ int SrsConfig::get_pithy_print_publish()
1372 1578
1373 int SrsConfig::get_pithy_print_forwarder() 1579 int SrsConfig::get_pithy_print_forwarder()
1374 { 1580 {
1375 - SrsConfDirective* pithy = root->get("pithy_print"); 1581 + SrsConfDirective* pithy = get_pithy_print();
1376 if (!pithy) { 1582 if (!pithy) {
1377 return SRS_CONF_DEFAULT_STAGE_FORWARDER_INTERVAL_MS; 1583 return SRS_CONF_DEFAULT_STAGE_FORWARDER_INTERVAL_MS;
1378 } 1584 }
@@ -1387,7 +1593,7 @@ int SrsConfig::get_pithy_print_forwarder() @@ -1387,7 +1593,7 @@ int SrsConfig::get_pithy_print_forwarder()
1387 1593
1388 int SrsConfig::get_pithy_print_encoder() 1594 int SrsConfig::get_pithy_print_encoder()
1389 { 1595 {
1390 - SrsConfDirective* pithy = root->get("pithy_print"); 1596 + SrsConfDirective* pithy = get_pithy_print();
1391 if (!pithy) { 1597 if (!pithy) {
1392 return SRS_CONF_DEFAULT_STAGE_ENCODER_INTERVAL_MS; 1598 return SRS_CONF_DEFAULT_STAGE_ENCODER_INTERVAL_MS;
1393 } 1599 }
@@ -1402,7 +1608,7 @@ int SrsConfig::get_pithy_print_encoder() @@ -1402,7 +1608,7 @@ int SrsConfig::get_pithy_print_encoder()
1402 1608
1403 int SrsConfig::get_pithy_print_ingester() 1609 int SrsConfig::get_pithy_print_ingester()
1404 { 1610 {
1405 - SrsConfDirective* pithy = root->get("pithy_print"); 1611 + SrsConfDirective* pithy = get_pithy_print();
1406 if (!pithy) { 1612 if (!pithy) {
1407 return SRS_CONF_DEFAULT_STAGE_INGESTER_INTERVAL_MS; 1613 return SRS_CONF_DEFAULT_STAGE_INGESTER_INTERVAL_MS;
1408 } 1614 }
@@ -1417,7 +1623,7 @@ int SrsConfig::get_pithy_print_ingester() @@ -1417,7 +1623,7 @@ int SrsConfig::get_pithy_print_ingester()
1417 1623
1418 int SrsConfig::get_pithy_print_hls() 1624 int SrsConfig::get_pithy_print_hls()
1419 { 1625 {
1420 - SrsConfDirective* pithy = root->get("pithy_print"); 1626 + SrsConfDirective* pithy = get_pithy_print();
1421 if (!pithy) { 1627 if (!pithy) {
1422 return SRS_CONF_DEFAULT_STAGE_HLS_INTERVAL_MS; 1628 return SRS_CONF_DEFAULT_STAGE_HLS_INTERVAL_MS;
1423 } 1629 }
@@ -1432,7 +1638,7 @@ int SrsConfig::get_pithy_print_hls() @@ -1432,7 +1638,7 @@ int SrsConfig::get_pithy_print_hls()
1432 1638
1433 int SrsConfig::get_pithy_print_play() 1639 int SrsConfig::get_pithy_print_play()
1434 { 1640 {
1435 - SrsConfDirective* pithy = root->get("pithy_print"); 1641 + SrsConfDirective* pithy = get_pithy_print();
1436 if (!pithy) { 1642 if (!pithy) {
1437 return SRS_CONF_DEFAULT_STAGE_PLAY_USER_INTERVAL_MS; 1643 return SRS_CONF_DEFAULT_STAGE_PLAY_USER_INTERVAL_MS;
1438 } 1644 }
@@ -1447,7 +1653,7 @@ int SrsConfig::get_pithy_print_play() @@ -1447,7 +1653,7 @@ int SrsConfig::get_pithy_print_play()
1447 1653
1448 int SrsConfig::get_pithy_print_edge() 1654 int SrsConfig::get_pithy_print_edge()
1449 { 1655 {
1450 - SrsConfDirective* pithy = root->get("pithy_print"); 1656 + SrsConfDirective* pithy = get_pithy_print();
1451 if (!pithy) { 1657 if (!pithy) {
1452 return SRS_CONF_DEFAULT_STAGE_EDGE_INTERVAL_MS; 1658 return SRS_CONF_DEFAULT_STAGE_EDGE_INTERVAL_MS;
1453 } 1659 }
@@ -391,6 +391,10 @@ public: @@ -391,6 +391,10 @@ public:
391 * user can use different pid file for each process. 391 * user can use different pid file for each process.
392 */ 392 */
393 virtual std::string get_pid_file(); 393 virtual std::string get_pid_file();
  394 +// pithy print
  395 +private:
  396 + virtual SrsConfDirective* get_pithy_print();
  397 +public:
394 /** 398 /**
395 * get the pithy print interval for publish, in ms, 399 * get the pithy print interval for publish, in ms,
396 * the publish(flash/FMLE) message print. 400 * the publish(flash/FMLE) message print.