diff --git a/Connector_HTTP/Makefile b/Connector_HTTP/Makefile index 0e0cf9d1..3d30eb53 100644 --- a/Connector_HTTP/Makefile +++ b/Connector_HTTP/Makefile @@ -1,4 +1,4 @@ -SRC = main.cpp ../util/socket.cpp ../util/http_parser.cpp ../util/flv_tag.cpp ../util/amf.cpp ../util/dtsc.cpp ../util/config.cpp ../util/base64.cpp +SRC = main.cpp ../util/socket.cpp ../util/http_parser.cpp ../util/flv_tag.cpp ../util/amf.cpp ../util/dtsc.cpp ../util/config.cpp ../util/base64.cpp ../util/json.cpp OBJ = $(SRC:.cpp=.o) OUT = MistConnHTTP INCLUDES = diff --git a/Connector_HTTP/main.cpp b/Connector_HTTP/main.cpp index 8ea07b08..3767eecb 100644 --- a/Connector_HTTP/main.cpp +++ b/Connector_HTTP/main.cpp @@ -13,6 +13,7 @@ #include #include "../util/socket.h" #include "../util/http_parser.h" +#include "../util/json.h" #include "../util/dtsc.h" #include "../util/flv_tag.h" #include "../util/MP4/interface.cpp" @@ -187,6 +188,28 @@ namespace Connector_HTTP{ printf("Sending crossdomain.xml file\n"); #endif } + if (HTTP_R.url.substr(0, 7) == "/embed_" && HTTP_R.url.substr(HTTP_R.url.length() - 3, 3) == ".js"){ + streamname = HTTP_R.url.substr(7, HTTP_R.url.length() - 10); + JSON::Value ServConf = JSON::fromFile("/tmp/mist/streamlist"); + std::string response; + handler = HANDLER_NONE; + HTTP_S.Clean(); + HTTP_S.SetHeader("Content-Type", "application/javascript"); + response = "// Generating embed code for stream " + streamname + "\n\n"; + if (ServConf["streams"].isMember(streamname)){ + std::string streamurl = "http://" + HTTP_S.GetHeader("Host") + "/" + streamname + ".flv"; + response += "// Stream URL: " + streamurl + "\n\n"; + response += "document.write('');\n"; + }else{ + response += "// Stream not available at this server.\nalert(\"This stream is currently not available at this server.\\\\nPlease try again later!\");"; + } + response += ""; + HTTP_S.SetBody(response); + HTTP_S.SendResponse(conn, "200", "OK"); + #if DEBUG >= 3 + printf("Sending embed code for %s\n", streamname.c_str()); + #endif + } if (handler == HANDLER_FLASH){ if (HTTP_R.url.find("f4m") == std::string::npos){ Movie = HTTP_R.url.substr(1); diff --git a/Controller/main.cpp b/Controller/main.cpp index 8c074c7e..40d114eb 100644 --- a/Controller/main.cpp +++ b/Controller/main.cpp @@ -72,15 +72,6 @@ void WriteFile( std::string Filename, std::string contents ) { File.close( ); } -std::string ReadFile( std::string Filename ) { - std::string Result; - std::ifstream File; - File.open( Filename.c_str( ) ); - while( File.good( ) ) { Result += File.get( ); } - File.close( ); - return Result; -} - class ConnectedUser{ public: std::string writebuffer; @@ -268,7 +259,7 @@ void CheckAllStreams(JSON::Value & data){ } } if (changed){ - WriteFile("/tmp/mist/streamlist", data.toString()); + WriteFile("/tmp/mist/streamlist", Storage.toString()); } } @@ -297,7 +288,7 @@ void CheckStreams(JSON::Value & in, JSON::Value & out){ } out = in; if (changed){ - WriteFile("/tmp/mist/streamlist", out.toString()); + WriteFile("/tmp/mist/streamlist", Storage.toString()); } } @@ -312,7 +303,7 @@ int main(int argc, char ** argv){ sigaction(SIGTERM, &new_action, NULL); sigaction(SIGPIPE, &new_action, NULL); - Storage = JSON::fromString(ReadFile("config.json")); + Storage = JSON::fromFile("config.json"); Util::Config C; C.listen_port = (long long int)Storage["config"]["controller"]["port"]; if (C.listen_port < 1){C.listen_port = 4242;} diff --git a/util/json.cpp b/util/json.cpp index d4b3efc4..e8e12641 100644 --- a/util/json.cpp +++ b/util/json.cpp @@ -2,6 +2,7 @@ #include "json.h" #include +#include int JSON::Value::c2hex(int c){ if (c >= '0' && c <= '9') return c - '0'; @@ -423,3 +424,13 @@ JSON::Value JSON::fromString(std::string json){ std::istringstream is(json); return JSON::Value(is); } + +/// Converts a file to a JSON::Value. +JSON::Value JSON::fromFile(std::string filename){ + std::string Result; + std::ifstream File; + File.open(filename.c_str()); + while (File.good()){Result += File.get();} + File.close( ); + return fromString(Result); +} diff --git a/util/json.h b/util/json.h index 8de01e11..047178cd 100644 --- a/util/json.h +++ b/util/json.h @@ -69,5 +69,6 @@ namespace JSON{ }; Value fromString(std::string json); + Value fromFile(std::string filename); };