winlin

add utest for config vhosts, transcode/dvr/hls

@@ -1630,7 +1630,7 @@ SrsConfDirective* SrsConfig::get_forward(string vhost) @@ -1630,7 +1630,7 @@ SrsConfDirective* SrsConfig::get_forward(string vhost)
1630 return conf->get("forward"); 1630 return conf->get("forward");
1631 } 1631 }
1632 1632
1633 -SrsConfDirective* SrsConfig::get_vhost_on_connect(string vhost) 1633 +SrsConfDirective* SrsConfig::get_vhost_http_hooks(string vhost)
1634 { 1634 {
1635 SrsConfDirective* conf = get_vhost(vhost); 1635 SrsConfDirective* conf = get_vhost(vhost);
1636 1636
@@ -1638,34 +1638,41 @@ SrsConfDirective* SrsConfig::get_vhost_on_connect(string vhost) @@ -1638,34 +1638,41 @@ SrsConfDirective* SrsConfig::get_vhost_on_connect(string vhost)
1638 return NULL; 1638 return NULL;
1639 } 1639 }
1640 1640
1641 - conf = conf->get("http_hooks"); 1641 + return conf->get("http_hooks");
  1642 +}
  1643 +
  1644 +bool SrsConfig::get_vhost_http_hooks_enabled(string vhost)
  1645 +{
  1646 + SrsConfDirective* conf = get_vhost_http_hooks(vhost);
  1647 +
1642 if (!conf) { 1648 if (!conf) {
1643 - return NULL; 1649 + return false;
1644 } 1650 }
1645 1651
1646 SrsConfDirective* enabled = conf->get("enabled"); 1652 SrsConfDirective* enabled = conf->get("enabled");
1647 if (!enabled || enabled->arg0() != "on") { 1653 if (!enabled || enabled->arg0() != "on") {
1648 - return NULL; 1654 + return false;
1649 } 1655 }
1650 1656
1651 - return conf->get("on_connect"); 1657 + return true;
1652 } 1658 }
1653 1659
1654 -SrsConfDirective* SrsConfig::get_vhost_on_close(string vhost) 1660 +SrsConfDirective* SrsConfig::get_vhost_on_connect(string vhost)
1655 { 1661 {
1656 - SrsConfDirective* conf = get_vhost(vhost); 1662 + SrsConfDirective* conf = get_vhost_http_hooks(vhost);
1657 1663
1658 if (!conf) { 1664 if (!conf) {
1659 return NULL; 1665 return NULL;
1660 } 1666 }
1661 1667
1662 - conf = conf->get("http_hooks");  
1663 - if (!conf) {  
1664 - return NULL;  
1665 - } 1668 + return conf->get("on_connect");
  1669 +}
1666 1670
1667 - SrsConfDirective* enabled = conf->get("enabled");  
1668 - if (!enabled || enabled->arg0() != "on") { 1671 +SrsConfDirective* SrsConfig::get_vhost_on_close(string vhost)
  1672 +{
  1673 + SrsConfDirective* conf = get_vhost_http_hooks(vhost);
  1674 +
  1675 + if (!conf) {
1669 return NULL; 1676 return NULL;
1670 } 1677 }
1671 1678
@@ -1674,106 +1681,56 @@ SrsConfDirective* SrsConfig::get_vhost_on_close(string vhost) @@ -1674,106 +1681,56 @@ SrsConfDirective* SrsConfig::get_vhost_on_close(string vhost)
1674 1681
1675 SrsConfDirective* SrsConfig::get_vhost_on_publish(string vhost) 1682 SrsConfDirective* SrsConfig::get_vhost_on_publish(string vhost)
1676 { 1683 {
1677 - SrsConfDirective* conf = get_vhost(vhost); 1684 + SrsConfDirective* conf = get_vhost_http_hooks(vhost);
1678 1685
1679 if (!conf) { 1686 if (!conf) {
1680 return NULL; 1687 return NULL;
1681 } 1688 }
1682 1689
1683 - conf = conf->get("http_hooks");  
1684 - if (!conf) {  
1685 - return NULL;  
1686 - }  
1687 -  
1688 - SrsConfDirective* enabled = conf->get("enabled");  
1689 - if (!enabled || enabled->arg0() != "on") {  
1690 - return NULL;  
1691 - }  
1692 -  
1693 return conf->get("on_publish"); 1690 return conf->get("on_publish");
1694 } 1691 }
1695 1692
1696 SrsConfDirective* SrsConfig::get_vhost_on_unpublish(string vhost) 1693 SrsConfDirective* SrsConfig::get_vhost_on_unpublish(string vhost)
1697 { 1694 {
1698 - SrsConfDirective* conf = get_vhost(vhost); 1695 + SrsConfDirective* conf = get_vhost_http_hooks(vhost);
1699 1696
1700 if (!conf) { 1697 if (!conf) {
1701 return NULL; 1698 return NULL;
1702 } 1699 }
1703 1700
1704 - conf = conf->get("http_hooks");  
1705 - if (!conf) {  
1706 - return NULL;  
1707 - }  
1708 -  
1709 - SrsConfDirective* enabled = conf->get("enabled");  
1710 - if (!enabled || enabled->arg0() != "on") {  
1711 - return NULL;  
1712 - }  
1713 -  
1714 return conf->get("on_unpublish"); 1701 return conf->get("on_unpublish");
1715 } 1702 }
1716 1703
1717 SrsConfDirective* SrsConfig::get_vhost_on_play(string vhost) 1704 SrsConfDirective* SrsConfig::get_vhost_on_play(string vhost)
1718 { 1705 {
1719 - SrsConfDirective* conf = get_vhost(vhost); 1706 + SrsConfDirective* conf = get_vhost_http_hooks(vhost);
1720 1707
1721 if (!conf) { 1708 if (!conf) {
1722 return NULL; 1709 return NULL;
1723 } 1710 }
1724 1711
1725 - conf = conf->get("http_hooks");  
1726 - if (!conf) {  
1727 - return NULL;  
1728 - }  
1729 -  
1730 - SrsConfDirective* enabled = conf->get("enabled");  
1731 - if (!enabled || enabled->arg0() != "on") {  
1732 - return NULL;  
1733 - }  
1734 -  
1735 return conf->get("on_play"); 1712 return conf->get("on_play");
1736 } 1713 }
1737 1714
1738 SrsConfDirective* SrsConfig::get_vhost_on_stop(string vhost) 1715 SrsConfDirective* SrsConfig::get_vhost_on_stop(string vhost)
1739 { 1716 {
1740 - SrsConfDirective* conf = get_vhost(vhost); 1717 + SrsConfDirective* conf = get_vhost_http_hooks(vhost);
1741 1718
1742 if (!conf) { 1719 if (!conf) {
1743 return NULL; 1720 return NULL;
1744 } 1721 }
1745 1722
1746 - conf = conf->get("http_hooks");  
1747 - if (!conf) {  
1748 - return NULL;  
1749 - }  
1750 -  
1751 - SrsConfDirective* enabled = conf->get("enabled");  
1752 - if (!enabled || enabled->arg0() != "on") {  
1753 - return NULL;  
1754 - }  
1755 -  
1756 return conf->get("on_stop"); 1723 return conf->get("on_stop");
1757 } 1724 }
1758 1725
1759 SrsConfDirective* SrsConfig::get_vhost_on_dvr_hss_reap_flv(string vhost) 1726 SrsConfDirective* SrsConfig::get_vhost_on_dvr_hss_reap_flv(string vhost)
1760 { 1727 {
1761 - SrsConfDirective* conf = get_vhost(vhost); 1728 + SrsConfDirective* conf = get_vhost_http_hooks(vhost);
1762 1729
1763 if (!conf) { 1730 if (!conf) {
1764 return NULL; 1731 return NULL;
1765 } 1732 }
1766 1733
1767 - conf = conf->get("http_hooks");  
1768 - if (!conf) {  
1769 - return NULL;  
1770 - }  
1771 -  
1772 - SrsConfDirective* enabled = conf->get("enabled");  
1773 - if (!enabled || enabled->arg0() != "on") {  
1774 - return NULL;  
1775 - }  
1776 -  
1777 return conf->get("on_dvr_hss_reap_flv"); 1734 return conf->get("on_dvr_hss_reap_flv");
1778 } 1735 }
1779 1736
@@ -515,8 +515,18 @@ public: @@ -515,8 +515,18 @@ public:
515 */ 515 */
516 virtual SrsConfDirective* get_forward(std::string vhost); 516 virtual SrsConfDirective* get_forward(std::string vhost);
517 // http_hooks section 517 // http_hooks section
  518 +private:
  519 + /**
  520 + * get the http_hooks directive of vhost.
  521 + */
  522 + virtual SrsConfDirective* get_vhost_http_hooks(std::string vhost);
518 public: 523 public:
519 /** 524 /**
  525 + * whether vhost http-hooks enabled.
  526 + * @remark, if not enabled, donot callback all http hooks.
  527 + */
  528 + virtual bool get_vhost_http_hooks_enabled(std::string vhost);
  529 + /**
520 * get the on_connect callbacks of vhost. 530 * get the on_connect callbacks of vhost.
521 * @return the on_connect callback directive, the args is the url to callback. 531 * @return the on_connect callback directive, the args is the url to callback.
522 */ 532 */
@@ -371,6 +371,7 @@ int SrsDvrPlan::on_dvr_hss_reap_flv() @@ -371,6 +371,7 @@ int SrsDvrPlan::on_dvr_hss_reap_flv()
371 int ret = ERROR_SUCCESS; 371 int ret = ERROR_SUCCESS;
372 372
373 #ifdef SRS_AUTO_HTTP_CALLBACK 373 #ifdef SRS_AUTO_HTTP_CALLBACK
  374 + if (!_srs_config->get_vhost_http_hooks_enabled(_req->vhost)) {
374 // HTTP: on_dvr_hss_reap_flv 375 // HTTP: on_dvr_hss_reap_flv
375 SrsConfDirective* on_dvr_hss_reap_flv = _srs_config->get_vhost_on_dvr_hss_reap_flv(_req->vhost); 376 SrsConfDirective* on_dvr_hss_reap_flv = _srs_config->get_vhost_on_dvr_hss_reap_flv(_req->vhost);
376 if (!on_dvr_hss_reap_flv) { 377 if (!on_dvr_hss_reap_flv) {
@@ -382,6 +383,7 @@ int SrsDvrPlan::on_dvr_hss_reap_flv() @@ -382,6 +383,7 @@ int SrsDvrPlan::on_dvr_hss_reap_flv()
382 std::string url = on_dvr_hss_reap_flv->args.at(i); 383 std::string url = on_dvr_hss_reap_flv->args.at(i);
383 SrsHttpHooks::on_dvr_hss_reap_flv(url, _req, segment); 384 SrsHttpHooks::on_dvr_hss_reap_flv(url, _req, segment);
384 } 385 }
  386 + }
385 #endif 387 #endif
386 388
387 return ret; 389 return ret;
@@ -641,6 +643,7 @@ int SrsDvrHssPlan::on_dvr_hss_reap_flv_header(string path) @@ -641,6 +643,7 @@ int SrsDvrHssPlan::on_dvr_hss_reap_flv_header(string path)
641 int ret = ERROR_SUCCESS; 643 int ret = ERROR_SUCCESS;
642 644
643 #ifdef SRS_AUTO_HTTP_CALLBACK 645 #ifdef SRS_AUTO_HTTP_CALLBACK
  646 + if (!_srs_config->get_vhost_http_hooks_enabled(_req->vhost)) {
644 // HTTP: on_dvr_hss_reap_flv_header 647 // HTTP: on_dvr_hss_reap_flv_header
645 SrsConfDirective* on_dvr_hss_reap_flv = _srs_config->get_vhost_on_dvr_hss_reap_flv(_req->vhost); 648 SrsConfDirective* on_dvr_hss_reap_flv = _srs_config->get_vhost_on_dvr_hss_reap_flv(_req->vhost);
646 if (!on_dvr_hss_reap_flv) { 649 if (!on_dvr_hss_reap_flv) {
@@ -652,6 +655,7 @@ int SrsDvrHssPlan::on_dvr_hss_reap_flv_header(string path) @@ -652,6 +655,7 @@ int SrsDvrHssPlan::on_dvr_hss_reap_flv_header(string path)
652 std::string url = on_dvr_hss_reap_flv->args.at(i); 655 std::string url = on_dvr_hss_reap_flv->args.at(i);
653 SrsHttpHooks::on_dvr_hss_reap_flv_header(url, _req, path); 656 SrsHttpHooks::on_dvr_hss_reap_flv_header(url, _req, path);
654 } 657 }
  658 + }
655 #endif 659 #endif
656 660
657 return ret; 661 return ret;
@@ -984,6 +984,7 @@ int SrsRtmpConn::http_hooks_on_connect() @@ -984,6 +984,7 @@ int SrsRtmpConn::http_hooks_on_connect()
984 int ret = ERROR_SUCCESS; 984 int ret = ERROR_SUCCESS;
985 985
986 #ifdef SRS_AUTO_HTTP_CALLBACK 986 #ifdef SRS_AUTO_HTTP_CALLBACK
  987 + if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
987 // HTTP: on_connect 988 // HTTP: on_connect
988 SrsConfDirective* on_connect = _srs_config->get_vhost_on_connect(req->vhost); 989 SrsConfDirective* on_connect = _srs_config->get_vhost_on_connect(req->vhost);
989 if (!on_connect) { 990 if (!on_connect) {
@@ -999,6 +1000,7 @@ int SrsRtmpConn::http_hooks_on_connect() @@ -999,6 +1000,7 @@ int SrsRtmpConn::http_hooks_on_connect()
999 return ret; 1000 return ret;
1000 } 1001 }
1001 } 1002 }
  1003 + }
1002 #endif 1004 #endif
1003 1005
1004 return ret; 1006 return ret;
@@ -1007,6 +1009,7 @@ int SrsRtmpConn::http_hooks_on_connect() @@ -1007,6 +1009,7 @@ int SrsRtmpConn::http_hooks_on_connect()
1007 void SrsRtmpConn::http_hooks_on_close() 1009 void SrsRtmpConn::http_hooks_on_close()
1008 { 1010 {
1009 #ifdef SRS_AUTO_HTTP_CALLBACK 1011 #ifdef SRS_AUTO_HTTP_CALLBACK
  1012 + if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
1010 // whatever the ret code, notify the api hooks. 1013 // whatever the ret code, notify the api hooks.
1011 // HTTP: on_close 1014 // HTTP: on_close
1012 SrsConfDirective* on_close = _srs_config->get_vhost_on_close(req->vhost); 1015 SrsConfDirective* on_close = _srs_config->get_vhost_on_close(req->vhost);
@@ -1020,6 +1023,7 @@ void SrsRtmpConn::http_hooks_on_close() @@ -1020,6 +1023,7 @@ void SrsRtmpConn::http_hooks_on_close()
1020 std::string url = on_close->args.at(i); 1023 std::string url = on_close->args.at(i);
1021 SrsHttpHooks::on_close(url, connection_id, ip, req); 1024 SrsHttpHooks::on_close(url, connection_id, ip, req);
1022 } 1025 }
  1026 + }
1023 #endif 1027 #endif
1024 } 1028 }
1025 1029
@@ -1028,6 +1032,7 @@ int SrsRtmpConn::http_hooks_on_publish() @@ -1028,6 +1032,7 @@ int SrsRtmpConn::http_hooks_on_publish()
1028 int ret = ERROR_SUCCESS; 1032 int ret = ERROR_SUCCESS;
1029 1033
1030 #ifdef SRS_AUTO_HTTP_CALLBACK 1034 #ifdef SRS_AUTO_HTTP_CALLBACK
  1035 + if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
1031 // HTTP: on_publish 1036 // HTTP: on_publish
1032 SrsConfDirective* on_publish = _srs_config->get_vhost_on_publish(req->vhost); 1037 SrsConfDirective* on_publish = _srs_config->get_vhost_on_publish(req->vhost);
1033 if (!on_publish) { 1038 if (!on_publish) {
@@ -1043,6 +1048,7 @@ int SrsRtmpConn::http_hooks_on_publish() @@ -1043,6 +1048,7 @@ int SrsRtmpConn::http_hooks_on_publish()
1043 return ret; 1048 return ret;
1044 } 1049 }
1045 } 1050 }
  1051 + }
1046 #endif 1052 #endif
1047 1053
1048 return ret; 1054 return ret;
@@ -1051,6 +1057,7 @@ int SrsRtmpConn::http_hooks_on_publish() @@ -1051,6 +1057,7 @@ int SrsRtmpConn::http_hooks_on_publish()
1051 void SrsRtmpConn::http_hooks_on_unpublish() 1057 void SrsRtmpConn::http_hooks_on_unpublish()
1052 { 1058 {
1053 #ifdef SRS_AUTO_HTTP_CALLBACK 1059 #ifdef SRS_AUTO_HTTP_CALLBACK
  1060 + if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
1054 // whatever the ret code, notify the api hooks. 1061 // whatever the ret code, notify the api hooks.
1055 // HTTP: on_unpublish 1062 // HTTP: on_unpublish
1056 SrsConfDirective* on_unpublish = _srs_config->get_vhost_on_unpublish(req->vhost); 1063 SrsConfDirective* on_unpublish = _srs_config->get_vhost_on_unpublish(req->vhost);
@@ -1064,6 +1071,7 @@ void SrsRtmpConn::http_hooks_on_unpublish() @@ -1064,6 +1071,7 @@ void SrsRtmpConn::http_hooks_on_unpublish()
1064 std::string url = on_unpublish->args.at(i); 1071 std::string url = on_unpublish->args.at(i);
1065 SrsHttpHooks::on_unpublish(url, connection_id, ip, req); 1072 SrsHttpHooks::on_unpublish(url, connection_id, ip, req);
1066 } 1073 }
  1074 + }
1067 #endif 1075 #endif
1068 } 1076 }
1069 1077
@@ -1072,6 +1080,7 @@ int SrsRtmpConn::http_hooks_on_play() @@ -1072,6 +1080,7 @@ int SrsRtmpConn::http_hooks_on_play()
1072 int ret = ERROR_SUCCESS; 1080 int ret = ERROR_SUCCESS;
1073 1081
1074 #ifdef SRS_AUTO_HTTP_CALLBACK 1082 #ifdef SRS_AUTO_HTTP_CALLBACK
  1083 + if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
1075 // HTTP: on_play 1084 // HTTP: on_play
1076 SrsConfDirective* on_play = _srs_config->get_vhost_on_play(req->vhost); 1085 SrsConfDirective* on_play = _srs_config->get_vhost_on_play(req->vhost);
1077 if (!on_play) { 1086 if (!on_play) {
@@ -1087,6 +1096,7 @@ int SrsRtmpConn::http_hooks_on_play() @@ -1087,6 +1096,7 @@ int SrsRtmpConn::http_hooks_on_play()
1087 return ret; 1096 return ret;
1088 } 1097 }
1089 } 1098 }
  1099 + }
1090 #endif 1100 #endif
1091 1101
1092 return ret; 1102 return ret;
@@ -1095,6 +1105,7 @@ int SrsRtmpConn::http_hooks_on_play() @@ -1095,6 +1105,7 @@ int SrsRtmpConn::http_hooks_on_play()
1095 void SrsRtmpConn::http_hooks_on_stop() 1105 void SrsRtmpConn::http_hooks_on_stop()
1096 { 1106 {
1097 #ifdef SRS_AUTO_HTTP_CALLBACK 1107 #ifdef SRS_AUTO_HTTP_CALLBACK
  1108 + if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
1098 // whatever the ret code, notify the api hooks. 1109 // whatever the ret code, notify the api hooks.
1099 // HTTP: on_stop 1110 // HTTP: on_stop
1100 SrsConfDirective* on_stop = _srs_config->get_vhost_on_stop(req->vhost); 1111 SrsConfDirective* on_stop = _srs_config->get_vhost_on_stop(req->vhost);
@@ -1108,6 +1119,7 @@ void SrsRtmpConn::http_hooks_on_stop() @@ -1108,6 +1119,7 @@ void SrsRtmpConn::http_hooks_on_stop()
1108 std::string url = on_stop->args.at(i); 1119 std::string url = on_stop->args.at(i);
1109 SrsHttpHooks::on_stop(url, connection_id, ip, req); 1120 SrsHttpHooks::on_stop(url, connection_id, ip, req);
1110 } 1121 }
  1122 + }
1111 #endif 1123 #endif
1112 1124
1113 return; 1125 return;