Integrated LSP into controller - added library version to HTTP server headers, removed some temporary files from git and added them to .gitignore files.
This commit is contained in:
parent
1ed9fb3316
commit
9c368a5a86
9 changed files with 76 additions and 1595 deletions
|
@ -4,10 +4,25 @@ SUBDIRS=converters analysers
|
|||
bin_PROGRAMS=MistBuffer MistController MistConnRAW MistConnRTMP MistConnHTTP MistConnHTTPProgressive MistConnHTTPDynamic
|
||||
MistBuffer_SOURCES=buffer.cpp buffer_user.h buffer_user.cpp buffer_stream.h buffer_stream.cpp tinythread.cpp tinythread.h ../VERSION
|
||||
MistBuffer_LDADD=$(MIST_LIBS) -lpthread
|
||||
MistController_SOURCES=controller.cpp ../VERSION
|
||||
MistController_SOURCES=controller.cpp ../VERSION ../server.html.h
|
||||
MistConnRAW_SOURCES=conn_raw.cpp ../VERSION
|
||||
MistConnRTMP_SOURCES=conn_rtmp.cpp ../VERSION
|
||||
MistConnHTTP_SOURCES=conn_http.cpp tinythread.cpp tinythread.h ../VERSION
|
||||
MistConnHTTP_LDADD=$(MIST_LIBS) -lpthread
|
||||
MistConnHTTPProgressive_SOURCES=conn_http_progressive.cpp ../VERSION
|
||||
MistConnHTTPDynamic_SOURCES=conn_http_dynamic.cpp ../VERSION
|
||||
|
||||
../lsp/uncompressed.js: ../lsp/jquery.js ../lsp/placeholder.js ../lsp/md5.js ../lsp/main.js ../lsp/functions.js
|
||||
cat ../lsp/jquery.js ../lsp/placeholder.js ../lsp/md5.js ../lsp/main.js ../lsp/functions.js > ../lsp/uncompressed.js
|
||||
../lsp/compressed.js: ../lsp/uncompressed.js
|
||||
echo "<script>" > ../lsp/compressed.js
|
||||
../lsp/closure < ../lsp/uncompressed.js >> ../lsp/compressed.js
|
||||
echo "</script>" >> ../lsp/compressed.js
|
||||
../server.html: ../lsp/compressed.js
|
||||
cat ../lsp/header.html ../lsp/compressed.js > ../server.html
|
||||
echo "<style>" >> ../server.html
|
||||
cat ../lsp/style.css >> ../server.html
|
||||
echo "</style>" >> ../server.html
|
||||
cat ../lsp/footer.html >> ../server.html
|
||||
../server.html.h: ../server.html
|
||||
xxd -i ../server.html ../server.html.h
|
||||
|
|
|
@ -86,14 +86,14 @@ namespace Connector_HTTP{
|
|||
/// Handles requests without associated handler, displaying a nice friendly error message.
|
||||
void Handle_None(HTTP::Parser & H, Socket::Connection * conn){
|
||||
H.Clean();
|
||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION);
|
||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
||||
H.SetBody("<!DOCTYPE html><html><head><title>Unsupported Media Type</title></head><body><h1>Unsupported Media Type</h1>The server isn't quite sure what you wanted to receive from it.</body></html>");
|
||||
conn->Send(H.BuildResponse("415", "Unsupported Media Type"));
|
||||
}
|
||||
|
||||
void Handle_Timeout(HTTP::Parser & H, Socket::Connection * conn){
|
||||
H.Clean();
|
||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION);
|
||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
||||
H.SetBody("<!DOCTYPE html><html><head><title>Gateway timeout</title></head><body><h1>Gateway timeout</h1>Though the server understood your request and attempted to handle it, somehow handling it took longer than it should. Your request has been cancelled - please try again later.</body></html>");
|
||||
conn->Send(H.BuildResponse("504", "Gateway Timeout"));
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ namespace Connector_HTTP{
|
|||
if (H.url == "/crossdomain.xml"){
|
||||
H.Clean();
|
||||
H.SetHeader("Content-Type", "text/xml");
|
||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION);
|
||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
||||
H.SetBody("<?xml version=\"1.0\"?><!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\"><cross-domain-policy><allow-access-from domain=\"*\" /><site-control permitted-cross-domain-policies=\"all\"/></cross-domain-policy>");
|
||||
conn->Send(H.BuildResponse("200", "OK"));
|
||||
return;
|
||||
|
@ -115,7 +115,7 @@ namespace Connector_HTTP{
|
|||
JSON::Value ServConf = JSON::fromFile("/tmp/mist/streamlist");
|
||||
std::string response;
|
||||
H.Clean();
|
||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION);
|
||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
||||
H.SetHeader("Content-Type", "application/javascript");
|
||||
response = "// Generating embed code for stream " + streamname + "\n\n";
|
||||
if (ServConf["streams"].isMember(streamname)){
|
||||
|
@ -220,10 +220,12 @@ namespace Connector_HTTP{
|
|||
if (H.GetHeader("Content-Length") != ""){
|
||||
//known length - simply re-send the request with added headers and continue
|
||||
H.SetHeader("X-UID", uid);
|
||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
||||
conn->Send(H.BuildResponse("200", "OK"));
|
||||
}else{
|
||||
//unknown length
|
||||
H.SetHeader("X-UID", uid);
|
||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
||||
conn->Send(H.BuildResponse("200", "OK"));
|
||||
//continue sending data from this socket and keep it permanently in use
|
||||
while (connconn.count(uid) && connconn[uid]->conn->connected() && conn->connected()){
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <mist/http_parser.h>
|
||||
#include <mist/procs.h>
|
||||
#include <mist/auth.h>
|
||||
#include "../server.html.h"
|
||||
|
||||
#define UPLINK_INTERVAL 30
|
||||
#define COMPILED_USERNAME ""
|
||||
|
@ -489,44 +490,53 @@ int main(int argc, char ** argv){
|
|||
}
|
||||
}else{
|
||||
Request = JSON::fromString(it->H.GetVar("command"));
|
||||
Authorize(Request, Response, (*it));
|
||||
if (it->Authorized){
|
||||
//Parse config and streams from the request.
|
||||
if (Request.isMember("config")){Connector::CheckConfig(Request["config"], Connector::Storage["config"]);}
|
||||
if (Request.isMember("streams")){Connector::CheckStreams(Request["streams"], Connector::Storage["streams"]);}
|
||||
if (Request.isMember("save")){
|
||||
Connector::WriteFile("config.json", Connector::Storage.toString());
|
||||
Connector::Log("CONF", "Config written to file on request through API");
|
||||
}
|
||||
//sent current configuration, no matter if it was changed or not
|
||||
//Response["streams"] = Storage["streams"];
|
||||
Response["config"] = Connector::Storage["config"];
|
||||
Response["streams"] = Connector::Storage["streams"];
|
||||
//add required data to the current unix time to the config, for syncing reasons
|
||||
Response["config"]["time"] = (long long int)time(0);
|
||||
if (!Response["config"].isMember("serverid")){Response["config"]["serverid"] = "";}
|
||||
//sent any available logs and statistics
|
||||
Response["log"] = Connector::Storage["log"];
|
||||
Response["statistics"] = Connector::Storage["statistics"];
|
||||
//clear log and statistics if requested
|
||||
if (Request.isMember("clearstatlogs")){
|
||||
Connector::Storage["log"].null();
|
||||
Connector::Storage["statistics"].null();
|
||||
}
|
||||
}
|
||||
jsonp = "";
|
||||
if (it->H.GetVar("callback") != ""){jsonp = it->H.GetVar("callback");}
|
||||
if (it->H.GetVar("jsonp") != ""){jsonp = it->H.GetVar("jsonp");}
|
||||
it->H.Clean();
|
||||
it->H.protocol = "HTTP/1.0";
|
||||
it->H.SetHeader("Content-Type", "text/javascript");
|
||||
if (jsonp == ""){
|
||||
it->H.SetBody(Response.toString()+"\n\n");
|
||||
}else{
|
||||
it->H.SetBody(jsonp+"("+Response.toString()+");\n\n");
|
||||
}
|
||||
it->C.Send(it->H.BuildResponse("200", "OK"));
|
||||
if (!Request.isObject() && it->H.url != "/api"){
|
||||
it->H.Clean();
|
||||
it->H.SetHeader("Content-Type", "text/html");
|
||||
it->H.SetHeader("X-Info", "To force an API response, request the file /api");
|
||||
it->H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
||||
it->H.SetBody(std::string((char*)___server_html, (size_t)___server_html_len));
|
||||
it->C.Send(it->H.BuildResponse("200", "OK"));
|
||||
it->H.Clean();
|
||||
}else{
|
||||
Authorize(Request, Response, (*it));
|
||||
if (it->Authorized){
|
||||
//Parse config and streams from the request.
|
||||
if (Request.isMember("config")){Connector::CheckConfig(Request["config"], Connector::Storage["config"]);}
|
||||
if (Request.isMember("streams")){Connector::CheckStreams(Request["streams"], Connector::Storage["streams"]);}
|
||||
if (Request.isMember("save")){
|
||||
Connector::WriteFile("config.json", Connector::Storage.toString());
|
||||
Connector::Log("CONF", "Config written to file on request through API");
|
||||
}
|
||||
//sent current configuration, no matter if it was changed or not
|
||||
//Response["streams"] = Storage["streams"];
|
||||
Response["config"] = Connector::Storage["config"];
|
||||
Response["streams"] = Connector::Storage["streams"];
|
||||
//add required data to the current unix time to the config, for syncing reasons
|
||||
Response["config"]["time"] = (long long int)time(0);
|
||||
if (!Response["config"].isMember("serverid")){Response["config"]["serverid"] = "";}
|
||||
//sent any available logs and statistics
|
||||
Response["log"] = Connector::Storage["log"];
|
||||
Response["statistics"] = Connector::Storage["statistics"];
|
||||
//clear log and statistics if requested
|
||||
if (Request.isMember("clearstatlogs")){
|
||||
Connector::Storage["log"].null();
|
||||
Connector::Storage["statistics"].null();
|
||||
}
|
||||
}
|
||||
jsonp = "";
|
||||
if (it->H.GetVar("callback") != ""){jsonp = it->H.GetVar("callback");}
|
||||
if (it->H.GetVar("jsonp") != ""){jsonp = it->H.GetVar("jsonp");}
|
||||
it->H.Clean();
|
||||
it->H.SetHeader("Content-Type", "text/javascript");
|
||||
if (jsonp == ""){
|
||||
it->H.SetBody(Response.toString()+"\n\n");
|
||||
}else{
|
||||
it->H.SetBody(jsonp+"("+Response.toString()+");\n\n");
|
||||
}
|
||||
it->C.Send(it->H.BuildResponse("200", "OK"));
|
||||
it->H.Clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue