From 9a783a782d47a01696fd297db6ffa2f8af03b035 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 28 Feb 2017 14:05:37 +0100 Subject: [PATCH] Unified all push-in-enabled outputs into a single style/function of accepting incoming pushes --- src/input/input.cpp | 2 +- src/output/output.cpp | 31 +++++++++++++++++++++++++++++++ src/output/output.h | 1 + src/output/output_rtmp.cpp | 34 ++++++---------------------------- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/input/input.cpp b/src/input/input.cpp index cb046198..1b7378cb 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -297,7 +297,7 @@ namespace Mist { pullLock.unlink(); return; } - if (!Util::startInput(streamName, "push://")) {//manually override stream url to start the buffer + if (!Util::startInput(streamName, "push://INTERNAL_ONLY:"+config->getString("input"))) {//manually override stream url to start the buffer pullLock.post(); pullLock.close(); pullLock.unlink(); diff --git a/src/output/output.cpp b/src/output/output.cpp index 2e18d0d2..f267d52b 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -1088,5 +1088,36 @@ namespace Mist{ return true; } + /// Checks if the set streamName allows pushes from this connector/IP/password combination. + /// Runs all appropriate triggers and checks. + /// Returns true if the push should continue, false otherwise. + bool Output::allowPush(const std::string & passwd){ + std::string strmSource; + + // Initialize the stream source if needed, connect to it + initialize(); + //pull the source setting from metadata + strmSource = myMeta.sourceURI; + + if (!strmSource.size()){ + FAIL_MSG("Push rejected - stream %s not configured", streamName.c_str()); + return false; + } + if (strmSource.substr(0, 7) != "push://"){ + FAIL_MSG("Push rejected - stream %s not a push-able stream. (%s != push://*)", streamName.c_str(), strmSource.c_str()); + return false; + } + + std::string source = strmSource.substr(7); + std::string IP = source.substr(0, source.find('@')); + if (IP != ""){ + if (!myConn.isAddress(IP)){ + FAIL_MSG("Push from %s to %s rejected - source host not whitelisted", getConnectedHost().c_str(), streamName.c_str()); + return false; + } + } + return true; + } + } diff --git a/src/output/output.h b/src/output/output.h index 518f868e..ec7883df 100644 --- a/src/output/output.h +++ b/src/output/output.h @@ -111,6 +111,7 @@ namespace Mist { bool sentHeader;///< If false, triggers sendHeader if parseData is true. std::map bookKeeping; + bool allowPush(const std::string & passwd); }; } diff --git a/src/output/output_rtmp.cpp b/src/output/output_rtmp.cpp index e9135864..de2cf5c3 100644 --- a/src/output/output_rtmp.cpp +++ b/src/output/output_rtmp.cpp @@ -586,35 +586,13 @@ namespace Mist { } Util::sanitizeName(streamName); - //pull the server configuration - IPC::sharedPage serverCfg(SHM_CONF, DEFAULT_CONF_PAGE_SIZE); ///< Contains server configuration and capabilities - IPC::semaphore configLock(SEM_CONF, O_CREAT | O_RDWR, ACCESSPERMS, 1); - configLock.wait(); - - DTSC::Scan streamCfg = DTSC::Scan(serverCfg.mapped, serverCfg.len).getMember("streams").getMember(streamName); - if (streamCfg){ - if (streamCfg.getMember("source").asString().substr(0, 7) != "push://"){ - FAIL_MSG("Push rejected - stream %s not a push-able stream. (%s != push://*)", streamName.c_str(), streamCfg.getMember("source").asString().c_str()); - onFinish(); - }else{ - std::string source = streamCfg.getMember("source").asString().substr(7); - std::string IP = source.substr(0, source.find('@')); - if (IP != ""){ - if (!myConn.isAddress(IP)){ - FAIL_MSG("Push from %s to %s rejected - source host not whitelisted", getConnectedHost().c_str(), streamName.c_str()); - onFinish(); - } - } - } - }else{ - FAIL_MSG("Push from %s rejected - stream '%s' not configured.", getConnectedHost().c_str(), streamName.c_str()); - onFinish(); - } - configLock.post(); - configLock.close(); - if (!myConn){return;}//do not initialize if rejected + isPushing = true; - initialize(); + if (!allowPush("")){ + isPushing = false; + onFinish(); + return; + } } //send a _result reply AMF::Object amfReply("container", AMF::AMF0_DDV_CONTAINER);