winlin

refine config, check name

@@ -1184,11 +1184,23 @@ int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer) @@ -1184,11 +1184,23 @@ int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer)
1184 return ret; 1184 return ret;
1185 } 1185 }
1186 1186
1187 - // TODO: check the hls.  
1188 - // TODO: check forward.  
1189 - // TODO: check ffmpeg.  
1190 - // TODO: check http.  
1191 - // TODO: check pid. 1187 + // check root directives.
  1188 + for (int i = 0; i < (int)root->directives.size(); i++) {
  1189 + SrsConfDirective* conf = root->at(i);
  1190 + std::string n = conf->name;
  1191 + if (n != "listen" && n != "pid" && n != "chunk_size" && n != "ff_log_dir"
  1192 + && n != "srs_log_tank" && n != "srs_log_level" && n != "srs_log_file"
  1193 + && n != "max_connections" && n != "daemon" && n != "heartbeat"
  1194 + && n != "http_api" && n != "http_stream" && n != "vhost"
  1195 + && n != "pithy_print")
  1196 + {
  1197 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1198 + srs_error("unsupported directive %s, ret=%d", n.c_str(), ret);
  1199 + return ret;
  1200 + }
  1201 + }
  1202 +
  1203 + // TODO: FIXME: check others.
1192 1204
1193 // check log 1205 // check log
1194 std::string log_filename = this->get_log_file(); 1206 std::string log_filename = this->get_log_file();
@@ -338,136 +338,444 @@ public: @@ -338,136 +338,444 @@ public:
338 virtual std::string argv(); 338 virtual std::string argv();
339 // global section 339 // global section
340 public: 340 public:
  341 + /**
  342 + * get the directive root, corresponding to the config file.
  343 + * the root directive, no name and args, contains directives.
  344 + * all directive parsed can retrieve from root.
  345 + */
341 virtual SrsConfDirective* get_root(); 346 virtual SrsConfDirective* get_root();
  347 + /**
  348 + *
  349 + */
342 virtual bool get_deamon(); 350 virtual bool get_deamon();
  351 + /**
  352 + *
  353 + */
343 virtual int get_max_connections(); 354 virtual int get_max_connections();
  355 + /**
  356 + *
  357 + */
344 virtual SrsConfDirective* get_listen(); 358 virtual SrsConfDirective* get_listen();
  359 + /**
  360 + *
  361 + */
345 virtual std::string get_pid_file(); 362 virtual std::string get_pid_file();
  363 + /**
  364 + *
  365 + */
346 virtual int get_pithy_print_publish(); 366 virtual int get_pithy_print_publish();
  367 + /**
  368 + *
  369 + */
347 virtual int get_pithy_print_forwarder(); 370 virtual int get_pithy_print_forwarder();
  371 + /**
  372 + *
  373 + */
348 virtual int get_pithy_print_encoder(); 374 virtual int get_pithy_print_encoder();
  375 + /**
  376 + *
  377 + */
349 virtual int get_pithy_print_ingester(); 378 virtual int get_pithy_print_ingester();
  379 + /**
  380 + *
  381 + */
350 virtual int get_pithy_print_hls(); 382 virtual int get_pithy_print_hls();
  383 + /**
  384 + *
  385 + */
351 virtual int get_pithy_print_play(); 386 virtual int get_pithy_print_play();
  387 + /**
  388 + *
  389 + */
352 virtual int get_pithy_print_edge(); 390 virtual int get_pithy_print_edge();
353 // vhost specified section 391 // vhost specified section
354 public: 392 public:
355 virtual SrsConfDirective* get_vhost(std::string vhost); 393 virtual SrsConfDirective* get_vhost(std::string vhost);
  394 + /**
  395 + *
  396 + */
356 virtual void get_vhosts(std::vector<SrsConfDirective*>& vhosts); 397 virtual void get_vhosts(std::vector<SrsConfDirective*>& vhosts);
  398 + /**
  399 + *
  400 + */
357 virtual bool get_vhost_enabled(std::string vhost); 401 virtual bool get_vhost_enabled(std::string vhost);
  402 + /**
  403 + *
  404 + */
358 virtual bool get_vhost_enabled(SrsConfDirective* vhost); 405 virtual bool get_vhost_enabled(SrsConfDirective* vhost);
  406 + /**
  407 + *
  408 + */
359 virtual SrsConfDirective* get_vhost_on_connect(std::string vhost); 409 virtual SrsConfDirective* get_vhost_on_connect(std::string vhost);
  410 + /**
  411 + *
  412 + */
360 virtual SrsConfDirective* get_vhost_on_close(std::string vhost); 413 virtual SrsConfDirective* get_vhost_on_close(std::string vhost);
  414 + /**
  415 + *
  416 + */
361 virtual SrsConfDirective* get_vhost_on_publish(std::string vhost); 417 virtual SrsConfDirective* get_vhost_on_publish(std::string vhost);
  418 + /**
  419 + *
  420 + */
362 virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost); 421 virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost);
  422 + /**
  423 + *
  424 + */
363 virtual SrsConfDirective* get_vhost_on_play(std::string vhost); 425 virtual SrsConfDirective* get_vhost_on_play(std::string vhost);
  426 + /**
  427 + *
  428 + */
364 virtual SrsConfDirective* get_vhost_on_stop(std::string vhost); 429 virtual SrsConfDirective* get_vhost_on_stop(std::string vhost);
  430 + /**
  431 + *
  432 + */
365 virtual SrsConfDirective* get_vhost_on_dvr_hss_reap_flv(std::string vhost); 433 virtual SrsConfDirective* get_vhost_on_dvr_hss_reap_flv(std::string vhost);
  434 + /**
  435 + *
  436 + */
366 virtual bool get_gop_cache(std::string vhost); 437 virtual bool get_gop_cache(std::string vhost);
  438 + /**
  439 + *
  440 + */
367 virtual bool get_atc(std::string vhost); 441 virtual bool get_atc(std::string vhost);
  442 + /**
  443 + *
  444 + */
368 virtual bool get_atc_auto(std::string vhost); 445 virtual bool get_atc_auto(std::string vhost);
  446 + /**
  447 + *
  448 + */
369 virtual int get_time_jitter(std::string vhost); 449 virtual int get_time_jitter(std::string vhost);
  450 + /**
  451 + *
  452 + */
370 virtual double get_queue_length(std::string vhost); 453 virtual double get_queue_length(std::string vhost);
  454 + /**
  455 + *
  456 + */
371 virtual SrsConfDirective* get_forward(std::string vhost); 457 virtual SrsConfDirective* get_forward(std::string vhost);
  458 + /**
  459 + *
  460 + */
372 virtual SrsConfDirective* get_refer(std::string vhost); 461 virtual SrsConfDirective* get_refer(std::string vhost);
  462 + /**
  463 + *
  464 + */
373 virtual SrsConfDirective* get_refer_play(std::string vhost); 465 virtual SrsConfDirective* get_refer_play(std::string vhost);
  466 + /**
  467 + *
  468 + */
374 virtual SrsConfDirective* get_refer_publish(std::string vhost); 469 virtual SrsConfDirective* get_refer_publish(std::string vhost);
  470 + /**
  471 + *
  472 + */
375 virtual int get_chunk_size(const std::string& vhost); 473 virtual int get_chunk_size(const std::string& vhost);
376 // bwct(bandwidth check tool) section 474 // bwct(bandwidth check tool) section
377 public: 475 public:
  476 + /**
  477 + *
  478 + */
378 virtual bool get_bw_check_enabled(const std::string& vhost); 479 virtual bool get_bw_check_enabled(const std::string& vhost);
  480 + /**
  481 + *
  482 + */
379 virtual std::string get_bw_check_key(const std::string& vhost); 483 virtual std::string get_bw_check_key(const std::string& vhost);
  484 + /**
  485 + *
  486 + */
380 virtual int get_bw_check_interval_ms(const std::string& vhost); 487 virtual int get_bw_check_interval_ms(const std::string& vhost);
  488 + /**
  489 + *
  490 + */
381 virtual int get_bw_check_limit_kbps(const std::string& vhost); 491 virtual int get_bw_check_limit_kbps(const std::string& vhost);
382 // vhost edge section 492 // vhost edge section
383 public: 493 public:
  494 + /**
  495 + *
  496 + */
384 virtual bool get_vhost_is_edge(std::string vhost); 497 virtual bool get_vhost_is_edge(std::string vhost);
  498 + /**
  499 + *
  500 + */
385 virtual bool get_vhost_is_edge(SrsConfDirective* vhost); 501 virtual bool get_vhost_is_edge(SrsConfDirective* vhost);
  502 + /**
  503 + *
  504 + */
386 virtual SrsConfDirective* get_vhost_edge_origin(std::string vhost); 505 virtual SrsConfDirective* get_vhost_edge_origin(std::string vhost);
  506 + /**
  507 + *
  508 + */
387 virtual bool get_vhost_edge_token_traverse(std::string vhost); 509 virtual bool get_vhost_edge_token_traverse(std::string vhost);
388 // vhost transcode section 510 // vhost transcode section
389 public: 511 public:
  512 + /**
  513 + *
  514 + */
390 virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope); 515 virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope);
  516 + /**
  517 + *
  518 + */
391 virtual bool get_transcode_enabled(SrsConfDirective* transcode); 519 virtual bool get_transcode_enabled(SrsConfDirective* transcode);
  520 + /**
  521 + *
  522 + */
392 virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode); 523 virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode);
  524 + /**
  525 + *
  526 + */
393 virtual void get_transcode_engines(SrsConfDirective* transcode, std::vector<SrsConfDirective*>& engines); 527 virtual void get_transcode_engines(SrsConfDirective* transcode, std::vector<SrsConfDirective*>& engines);
  528 + /**
  529 + *
  530 + */
394 virtual bool get_engine_enabled(SrsConfDirective* engine); 531 virtual bool get_engine_enabled(SrsConfDirective* engine);
  532 + /**
  533 + *
  534 + */
395 virtual std::string get_engine_vcodec(SrsConfDirective* engine); 535 virtual std::string get_engine_vcodec(SrsConfDirective* engine);
  536 + /**
  537 + *
  538 + */
396 virtual int get_engine_vbitrate(SrsConfDirective* engine); 539 virtual int get_engine_vbitrate(SrsConfDirective* engine);
  540 + /**
  541 + *
  542 + */
397 virtual double get_engine_vfps(SrsConfDirective* engine); 543 virtual double get_engine_vfps(SrsConfDirective* engine);
  544 + /**
  545 + *
  546 + */
398 virtual int get_engine_vwidth(SrsConfDirective* engine); 547 virtual int get_engine_vwidth(SrsConfDirective* engine);
  548 + /**
  549 + *
  550 + */
399 virtual int get_engine_vheight(SrsConfDirective* engine); 551 virtual int get_engine_vheight(SrsConfDirective* engine);
  552 + /**
  553 + *
  554 + */
400 virtual int get_engine_vthreads(SrsConfDirective* engine); 555 virtual int get_engine_vthreads(SrsConfDirective* engine);
  556 + /**
  557 + *
  558 + */
401 virtual std::string get_engine_vprofile(SrsConfDirective* engine); 559 virtual std::string get_engine_vprofile(SrsConfDirective* engine);
  560 + /**
  561 + *
  562 + */
402 virtual std::string get_engine_vpreset(SrsConfDirective* engine); 563 virtual std::string get_engine_vpreset(SrsConfDirective* engine);
  564 + /**
  565 + *
  566 + */
403 virtual void get_engine_vparams(SrsConfDirective* engine, std::vector<std::string>& vparams); 567 virtual void get_engine_vparams(SrsConfDirective* engine, std::vector<std::string>& vparams);
  568 + /**
  569 + *
  570 + */
404 virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& vfilter); 571 virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& vfilter);
  572 + /**
  573 + *
  574 + */
405 virtual std::string get_engine_acodec(SrsConfDirective* engine); 575 virtual std::string get_engine_acodec(SrsConfDirective* engine);
  576 + /**
  577 + *
  578 + */
406 virtual int get_engine_abitrate(SrsConfDirective* engine); 579 virtual int get_engine_abitrate(SrsConfDirective* engine);
  580 + /**
  581 + *
  582 + */
407 virtual int get_engine_asample_rate(SrsConfDirective* engine); 583 virtual int get_engine_asample_rate(SrsConfDirective* engine);
  584 + /**
  585 + *
  586 + */
408 virtual int get_engine_achannels(SrsConfDirective* engine); 587 virtual int get_engine_achannels(SrsConfDirective* engine);
  588 + /**
  589 + *
  590 + */
409 virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams); 591 virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams);
  592 + /**
  593 + *
  594 + */
410 virtual std::string get_engine_output(SrsConfDirective* engine); 595 virtual std::string get_engine_output(SrsConfDirective* engine);
411 // ingest section 596 // ingest section
412 public: 597 public:
  598 + /**
  599 + *
  600 + */
413 virtual void get_ingesters(std::string vhost, std::vector<SrsConfDirective*>& ingeters); 601 virtual void get_ingesters(std::string vhost, std::vector<SrsConfDirective*>& ingeters);
  602 + /**
  603 + *
  604 + */
414 virtual SrsConfDirective* get_ingest_by_id(std::string vhost, std::string ingest_id); 605 virtual SrsConfDirective* get_ingest_by_id(std::string vhost, std::string ingest_id);
  606 + /**
  607 + *
  608 + */
415 virtual bool get_ingest_enabled(SrsConfDirective* ingest); 609 virtual bool get_ingest_enabled(SrsConfDirective* ingest);
  610 + /**
  611 + *
  612 + */
416 virtual std::string get_ingest_ffmpeg(SrsConfDirective* ingest); 613 virtual std::string get_ingest_ffmpeg(SrsConfDirective* ingest);
  614 + /**
  615 + *
  616 + */
417 virtual std::string get_ingest_input_type(SrsConfDirective* ingest); 617 virtual std::string get_ingest_input_type(SrsConfDirective* ingest);
  618 + /**
  619 + *
  620 + */
418 virtual std::string get_ingest_input_url(SrsConfDirective* ingest); 621 virtual std::string get_ingest_input_url(SrsConfDirective* ingest);
419 // log section 622 // log section
420 public: 623 public:
  624 + /**
  625 + *
  626 + */
421 virtual bool get_log_tank_file(); 627 virtual bool get_log_tank_file();
  628 + /**
  629 + *
  630 + */
422 virtual std::string get_log_level(); 631 virtual std::string get_log_level();
  632 + /**
  633 + *
  634 + */
423 virtual std::string get_log_file(); 635 virtual std::string get_log_file();
  636 + /**
  637 + *
  638 + */
424 virtual bool get_ffmpeg_log_enabled(); 639 virtual bool get_ffmpeg_log_enabled();
  640 + /**
  641 + *
  642 + */
425 virtual std::string get_ffmpeg_log_dir(); 643 virtual std::string get_ffmpeg_log_dir();
426 // hls section 644 // hls section
427 private: 645 private:
  646 + /**
  647 + *
  648 + */
428 virtual SrsConfDirective* get_hls(std::string vhost); 649 virtual SrsConfDirective* get_hls(std::string vhost);
429 public: 650 public:
  651 + /**
  652 + *
  653 + */
430 virtual bool get_hls_enabled(std::string vhost); 654 virtual bool get_hls_enabled(std::string vhost);
  655 + /**
  656 + *
  657 + */
431 virtual std::string get_hls_path(std::string vhost); 658 virtual std::string get_hls_path(std::string vhost);
  659 + /**
  660 + *
  661 + */
432 virtual double get_hls_fragment(std::string vhost); 662 virtual double get_hls_fragment(std::string vhost);
  663 + /**
  664 + *
  665 + */
433 virtual double get_hls_window(std::string vhost); 666 virtual double get_hls_window(std::string vhost);
434 // dvr section 667 // dvr section
435 private: 668 private:
  669 + /**
  670 + *
  671 + */
436 virtual SrsConfDirective* get_dvr(std::string vhost); 672 virtual SrsConfDirective* get_dvr(std::string vhost);
437 public: 673 public:
  674 + /**
  675 + *
  676 + */
438 virtual bool get_dvr_enabled(std::string vhost); 677 virtual bool get_dvr_enabled(std::string vhost);
  678 + /**
  679 + *
  680 + */
439 virtual std::string get_dvr_path(std::string vhost); 681 virtual std::string get_dvr_path(std::string vhost);
  682 + /**
  683 + *
  684 + */
440 virtual std::string get_dvr_plan(std::string vhost); 685 virtual std::string get_dvr_plan(std::string vhost);
  686 + /**
  687 + *
  688 + */
441 virtual int get_dvr_duration(std::string vhost); 689 virtual int get_dvr_duration(std::string vhost);
  690 + /**
  691 + *
  692 + */
442 virtual int get_dvr_time_jitter(std::string vhost); 693 virtual int get_dvr_time_jitter(std::string vhost);
443 // http api section 694 // http api section
444 private: 695 private:
  696 + /**
  697 + *
  698 + */
445 virtual SrsConfDirective* get_http_api(); 699 virtual SrsConfDirective* get_http_api();
446 public: 700 public:
  701 + /**
  702 + *
  703 + */
447 virtual bool get_http_api_enabled(); 704 virtual bool get_http_api_enabled();
  705 + /**
  706 + *
  707 + */
448 virtual bool get_http_api_enabled(SrsConfDirective* conf); 708 virtual bool get_http_api_enabled(SrsConfDirective* conf);
  709 + /**
  710 + *
  711 + */
449 virtual int get_http_api_listen(); 712 virtual int get_http_api_listen();
450 // http stream section 713 // http stream section
451 private: 714 private:
  715 + /**
  716 + *
  717 + */
452 virtual SrsConfDirective* get_http_stream(); 718 virtual SrsConfDirective* get_http_stream();
453 public: 719 public:
  720 + /**
  721 + *
  722 + */
454 virtual bool get_http_stream_enabled(); 723 virtual bool get_http_stream_enabled();
  724 + /**
  725 + *
  726 + */
455 virtual bool get_http_stream_enabled(SrsConfDirective* conf); 727 virtual bool get_http_stream_enabled(SrsConfDirective* conf);
  728 + /**
  729 + *
  730 + */
456 virtual int get_http_stream_listen(); 731 virtual int get_http_stream_listen();
  732 + /**
  733 + *
  734 + */
457 virtual std::string get_http_stream_dir(); 735 virtual std::string get_http_stream_dir();
458 public: 736 public:
  737 + /**
  738 + *
  739 + */
459 virtual bool get_vhost_http_enabled(std::string vhost); 740 virtual bool get_vhost_http_enabled(std::string vhost);
  741 + /**
  742 + *
  743 + */
460 virtual std::string get_vhost_http_mount(std::string vhost); 744 virtual std::string get_vhost_http_mount(std::string vhost);
  745 + /**
  746 + *
  747 + */
461 virtual std::string get_vhost_http_dir(std::string vhost); 748 virtual std::string get_vhost_http_dir(std::string vhost);
462 // http heartbeart section 749 // http heartbeart section
463 private: 750 private:
  751 + /**
  752 + *
  753 + */
464 virtual SrsConfDirective* get_heartbeart(); 754 virtual SrsConfDirective* get_heartbeart();
465 public: 755 public:
  756 + /**
  757 + *
  758 + */
466 virtual bool get_heartbeat_enabled(); 759 virtual bool get_heartbeat_enabled();
  760 + /**
  761 + *
  762 + */
467 virtual int64_t get_heartbeat_interval(); 763 virtual int64_t get_heartbeat_interval();
  764 + /**
  765 + *
  766 + */
468 virtual std::string get_heartbeat_url(); 767 virtual std::string get_heartbeat_url();
  768 + /**
  769 + *
  770 + */
469 virtual std::string get_heartbeat_device_id(); 771 virtual std::string get_heartbeat_device_id();
  772 + /**
  773 + *
  774 + */
470 virtual int get_heartbeat_device_index(); 775 virtual int get_heartbeat_device_index();
  776 + /**
  777 + *
  778 + */
471 virtual bool get_heartbeat_summaries(); 779 virtual bool get_heartbeat_summaries();
472 }; 780 };
473 781