JSON-based input selection.

This commit is contained in:
Thulinma 2014-10-02 15:41:50 +02:00
parent d85fe140ca
commit 8542281ac2
13 changed files with 279 additions and 215 deletions

View file

@ -25,7 +25,7 @@ namespace Mist {
return ((long long int)timePoint[0] << 56) | ((long long int)timePoint[1] << 48) | ((long long int)timePoint[2] << 40) | ((long long int)timePoint[3] << 32) | ((long long int)timePoint[4] << 24) | ((long long int)timePoint[5] << 16) | ((long long int)timePoint[6] << 8) | timePoint[7];
}
void Output::init(Util::Config * cfg){
void Output::init(Util::Config * cfg){
capa["optional"]["debug"]["name"] = "debug";
capa["optional"]["debug"]["help"] = "The debug level at which messages need to be printed.";
capa["optional"]["debug"]["option"] = "--debug";
@ -226,7 +226,7 @@ namespace Mist {
if (streamIndex.mapped){
return;
}
if (!Util::Stream::getStream(streamName)){
if (!Util::startInput(streamName)){
DEBUG_MSG(DLVL_FAIL, "Opening stream disallowed - aborting initalization");
onFail();
return;

View file

@ -2,6 +2,7 @@
#include <mist/http_parser.h>
#include <mist/defines.h>
#include <mist/stream.h>
#include <sys/stat.h>
#include <cstring>
#include <cstdlib>
@ -446,30 +447,34 @@ namespace Mist {
if ((amfData.getContentP(0)->StrValue() == "publish")) {
if (amfData.getContentP(3)) {
streamName = amfData.getContentP(3)->StrValue();
Util::Stream::sanitizeName(streamName);
Util::sanitizeName(streamName);
//pull the server configuration
JSON::Value servConf = JSON::fromFile(Util::getTmpFolder() + "streamlist");
if (servConf.isMember("streams") && servConf["streams"].isMember(streamName)){
JSON::Value & streamConfig = servConf["streams"][streamName];
if (!streamConfig.isMember("source") || streamConfig["source"].asStringRef().substr(0, 7) != "push://"){
DEBUG_MSG(DLVL_FAIL, "Push rejected - stream not a push-able stream. (%s != push://*)", streamConfig["source"].asStringRef().c_str());
IPC::sharedPage serverCfg("!mistConfig", 4*1024*1024); ///< Contains server configuration and capabilities
IPC::semaphore configLock("!mistConfLock", 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://"){
DEBUG_MSG(DLVL_FAIL, "Push rejected - stream not a push-able stream. (%s != push://*)", streamCfg.getMember("source").asString().c_str());
myConn.close();
return;
}
std::string source = streamConfig["source"].asStringRef().substr(7);
std::string IP = source.substr(0, source.find('@'));
if (IP != ""){
if (!myConn.isAddress(IP)){
DEBUG_MSG(DLVL_FAIL, "Push rejected - source host not whitelisted");
myConn.close();
return;
}else{
std::string source = streamCfg.getMember("source").asString().substr(7);
std::string IP = source.substr(0, source.find('@'));
if (IP != ""){
if (!myConn.isAddress(IP)){
DEBUG_MSG(DLVL_FAIL, "Push rejected - source host not whitelisted");
myConn.close();
}
}
}
}else{
DEBUG_MSG(DLVL_FAIL, "Push rejected - stream not configured.");
myConn.close();
return;
}
configLock.post();
configLock.close();
if (!myConn){return;}//do not initialize if rejected
initialize();
}
//send a _result reply
@ -513,8 +518,8 @@ namespace Mist {
//handle variables
if (streamName.find('?') != std::string::npos){
std::string tmpVars = streamName.substr(streamName.find('?') + 1);
Util::Stream::sanitizeName(streamName);
parseVars(tmpVars);
Util::sanitizeName(streamName);
}
initialize();