diff --git a/src/connectors/conn_http.cpp b/src/connectors/conn_http.cpp index 4c050398..8494ecbf 100644 --- a/src/connectors/conn_http.cpp +++ b/src/connectors/conn_http.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include "embed.js.h" @@ -86,21 +88,7 @@ namespace Connector_HTTP { tthread::mutex timeoutStartMutex; ///< Mutex for starting timeout thread. tthread::mutex timeoutMutex; ///< Mutex for timeout thread. tthread::thread * timeouter = 0; ///< Thread that times out connections to connectors. - JSON::Value capabilities; ///< Holds a list of all HTTP connectors and their properties - JSON::Value ServConf; /// < holds configuration, loads from file in main - - - void updateConfig(){ - static unsigned long long int confUpdateTime=0; - static tthread::mutex updateLock; - if( Util::bootSecs() -confUpdateTime > 10 ){ - tthread::lock_guard guard(updateLock); - if( Util::bootSecs() -confUpdateTime > 10 ){ - ServConf = JSON::fromFile(Util::getTmpFolder() + "streamlist"); - confUpdateTime=Util::bootSecs(); - } - } - } + IPC::sharedPage serverCfg; ///< Contains server configuration and capabilities ///\brief Function run as a thread to timeout requests on the proxy. ///\param n A NULL-pointer @@ -273,7 +261,6 @@ namespace Connector_HTTP { ///\param conn The connection to the client that issued the request. ///\return A timestamp indicating when the request was parsed. long long int proxyHandleInternal(HTTP::Parser & H, Socket::Connection & conn){ - updateConfig(); std::string url = H.getUrl(); if (url == "/crossdomain.xml"){ @@ -315,20 +302,20 @@ namespace Connector_HTTP { // send logo icon if (url.length() > 6 && url.substr(url.length() - 5, 5) == ".html"){ std::string streamname = url.substr(1, url.length() - 6); - Util::Stream::sanitizeName(streamname); + Util::sanitizeName(streamname); H.Clean(); H.SetHeader("Content-Type", "text/html"); H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver); H.SetBody("Stream "+streamname+""); long long int ret = Util::getMS(); - conn.SendNow(H.BuildResponse("200", "OK")); + H.SendResponse("200", "OK", conn); return ret; } // send smil MBR index if (url.length() > 6 && url.substr(url.length() - 5, 5) == ".smil"){ std::string streamname = url.substr(1, url.length() - 6); - Util::Stream::sanitizeName(streamname); + Util::sanitizeName(streamname); std::string host = H.GetHeader("Host"); if (host.find(':')){ @@ -337,38 +324,45 @@ namespace Connector_HTTP { std::string port, url_rel; - for (JSON::ArrIter it = ServConf["config"]["protocols"].ArrBegin(); it != ServConf["config"]["protocols"].ArrEnd(); it++){ - const std::string & cName = ( *it)["connector"].asStringRef(); - if (cName != "RTMP"){continue;} - //if we have the RTMP port, - if (capabilities.isMember(cName) && capabilities[cName].isMember("optional") && capabilities[cName]["optional"].isMember("port")){ - //get the default port if none is set - if (( *it)["port"].asInt() == 0){ - port = capabilities[cName]["optional"]["port"]["default"].asString(); - } - //extract url - if (capabilities[cName].isMember("url_rel")){ - url_rel = capabilities[cName]["url_rel"].asString(); - if (url_rel.find('$')){ - url_rel.resize(url_rel.find('$')); - } - } + IPC::semaphore configLock("!mistConfLock", O_CREAT | O_RDWR, ACCESSPERMS, 1); + configLock.wait(); + DTSC::Scan prtcls = DTSC::Scan(serverCfg.mapped, serverCfg.len).getMember("config").getMember("protocols"); + DTSC::Scan capa = DTSC::Scan(serverCfg.mapped, serverCfg.len).getMember("capabilities").getMember("connectors").getMember("RTMP"); + unsigned int pro_cnt = prtcls.getSize(); + for (unsigned int i = 0; i < pro_cnt; ++i){ + if (prtcls.getIndice(i).getMember("connector").asString() != "RTMP"){ + continue; + } + port = prtcls.getIndice(i).getMember("port").asString(); + //get the default port if none is set + if (!port.size()){ + port = capa.getMember("optional").getMember("port").getMember("default").asString(); + } + //extract url + url_rel = capa.getMember("url_rel").asString(); + if (url_rel.find('$')){ + url_rel.resize(url_rel.find('$')); } } std::string trackSources;//this string contains all track sources for MBR smil - for (JSON::ObjIter it = ServConf["streams"][streamname]["meta"]["tracks"].ObjBegin(); it != ServConf["streams"][streamname]["meta"]["tracks"].ObjEnd(); it++){//for all tracks - if (it->second.isMember("type") && it->second["type"].asString() == "video"){ - trackSources += "