Changed HTTP internals to use more generic URL building

This commit is contained in:
Thulinma 2016-11-16 10:33:59 +01:00
parent 374c9fd0ff
commit bcff43dc80

View file

@ -58,6 +58,8 @@ namespace Mist {
capa.removeMember("deps"); capa.removeMember("deps");
capa["name"] = "HTTP"; capa["name"] = "HTTP";
capa["desc"] = "Generic HTTP handler, required for all other HTTP-based outputs."; capa["desc"] = "Generic HTTP handler, required for all other HTTP-based outputs.";
capa["provides"] = "HTTP";
capa["protocol"] = "http://";
capa["url_match"].append("/crossdomain.xml"); capa["url_match"].append("/crossdomain.xml");
capa["url_match"].append("/clientaccesspolicy.xml"); capa["url_match"].append("/clientaccesspolicy.xml");
capa["url_match"].append("/$.html"); capa["url_match"].append("/$.html");
@ -121,22 +123,21 @@ namespace Mist {
} }
}; };
void addSource(const std::string & rel, std::set<JSON::Value, sourceCompare> & sources, std::string & host, const std::string & port, JSON::Value & conncapa, unsigned int most_simul, unsigned int total_matches, const std::string & flvPlayerPrefix){ void addSource(const std::string & rel, std::set<JSON::Value, sourceCompare> & sources, std::string & host, const std::string & port, JSON::Value & conncapa, unsigned int most_simul, unsigned int total_matches, const std::string & protocol){
JSON::Value tmp; JSON::Value tmp;
tmp["type"] = conncapa["type"]; tmp["type"] = conncapa["type"];
tmp["relurl"] = rel; tmp["relurl"] = rel;
tmp["priority"] = conncapa["priority"]; tmp["priority"] = conncapa["priority"];
if (conncapa.isMember("player_url")){ if (conncapa.isMember("player_url")){tmp["player_url"] = conncapa["player_url"].asStringRef();}
tmp["player_url"] = flvPlayerPrefix + conncapa["player_url"].asStringRef();
}
tmp["simul_tracks"] = most_simul; tmp["simul_tracks"] = most_simul;
tmp["total_matches"] = total_matches; tmp["total_matches"] = total_matches;
tmp["url"] = conncapa["handler"].asStringRef() + "://" + host + ":" + port + rel; tmp["url"] = protocol + host + ":" + port + rel;
sources.insert(tmp); sources.insert(tmp);
} }
void addSources(std::string & streamname, const std::string & rel, std::set<JSON::Value, sourceCompare> & sources, std::string & host, const std::string & port, JSON::Value & conncapa, JSON::Value & strmMeta, const std::string httpHost){ void addSources(std::string & streamname, std::set<JSON::Value, sourceCompare> & sources, std::string & host, const std::string & port, JSON::Value & conncapa, JSON::Value & strmMeta, const std::string httpHost, JSON::Value * mainconn_capa = 0){
const std::string & rel = conncapa["url_rel"].asStringRef();
unsigned int most_simul = 0; unsigned int most_simul = 0;
unsigned int total_matches = 0; unsigned int total_matches = 0;
if (conncapa.isMember("codecs") && conncapa["codecs"].size() > 0){ if (conncapa.isMember("codecs") && conncapa["codecs"].size() > 0){
@ -173,6 +174,10 @@ namespace Mist {
}else{ }else{
relurl = "/"; relurl = "/";
} }
std::string protocol;
if (mainconn_capa && mainconn_capa->isMember("protocol")){
protocol = (*mainconn_capa)["protocol"].asStringRef();
}
jsonForEach(conncapa["methods"], it) { jsonForEach(conncapa["methods"], it) {
if (it->isMember("url_rel")){ if (it->isMember("url_rel")){
size_t foundb = (*it)["url_rel"].asStringRef().find('$'); size_t foundb = (*it)["url_rel"].asStringRef().find('$');
@ -181,7 +186,10 @@ namespace Mist {
} }
} }
if (!strmMeta.isMember("live") || !it->isMember("nolive")){ if (!strmMeta.isMember("live") || !it->isMember("nolive")){
addSource(relurl, sources, host, port, *it, most_simul, total_matches, "http://" + httpHost); if (!protocol.size() && it->isMember("handler")){
protocol = (*it)["handler"].asStringRef() + "://";
}
addSource(relurl, sources, host, port, *it, most_simul, total_matches, protocol);
} }
} }
} }
@ -259,23 +267,6 @@ namespace Mist {
} }
// send generic HTML page // send generic HTML page
/* old embed
if (H.url.length() > 6 && H.url.substr(H.url.length() - 5, 5) == ".html"){
H.Clean();
H.SetHeader("Content-Type", "text/html");
H.SetHeader("Server", "MistServer/" PACKAGE_VERSION);
H.setCORSHeaders();
if(method == "OPTIONS" || method == "HEAD"){
H.SendResponse("200", "OK", myConn);
H.Clean();
return;
}
H.SetBody("<!DOCTYPE html><html><head><title>Stream "+streamName+"</title><style>BODY{color:white;background:black;}</style></head><body><script src=\"embed_"+streamName+".js\"></script></body></html>");
H.SendResponse("200", "OK", myConn);
return;
}
*/
/* new embed */
if (H.url.length() > 6 && H.url.substr(H.url.length() - 5, 5) == ".html"){ if (H.url.length() > 6 && H.url.substr(H.url.length() - 5, 5) == ".html"){
std::string fullHost = H.GetHeader("Host"); std::string fullHost = H.GetHeader("Host");
std::string uAgent = H.GetHeader("User-Agent"); std::string uAgent = H.GetHeader("User-Agent");
@ -467,18 +458,23 @@ namespace Mist {
port = capa.getMember("optional").getMember("port").getMember("default").asString(); port = capa.getMember("optional").getMember("port").getMember("default").asString();
} }
//and a URL - then list the URL //and a URL - then list the URL
JSON::Value capa_json = capa.asJSON();
if (capa.getMember("url_rel") || capa.getMember("methods")){ if (capa.getMember("url_rel") || capa.getMember("methods")){
JSON::Value capa_json = capa.asJSON(); addSources(streamName, sources, host, port, capa_json, json_resp["meta"], fullHost);
addSources(streamName, capa.getMember("url_rel").asString(), sources, host, port, capa_json, json_resp["meta"], fullHost);
} }
//check each enabled protocol separately to see if it depends on this connector //Make note if this connector can be depended upon by other connectors
DTSC::Scan capa_lst = DTSC::Scan(serverCfg.mapped, serverCfg.len).getMember("capabilities").getMember("connectors"); if (capa.getMember("provides")){
unsigned int capa_lst_ctr = capa_lst.getSize(); std::string cProv = capa.getMember("provides").asString();
for (unsigned int j = 0; j < capa_lst_ctr; ++j){ //if this connector can be depended upon by other connectors, loop over the rest
//if it depends on this connector and has a URL, list it //check each enabled protocol separately to see if it depends on this connector
if (conns.count(capa_lst.getIndiceName(j)) && (capa_lst.getIndice(j).getMember("deps").asString() == cName || capa_lst.getIndice(j).getMember("deps").asString() + ".exe" == cName) && capa_lst.getIndice(j).getMember("methods")){ DTSC::Scan capa_lst = DTSC::Scan(serverCfg.mapped, serverCfg.len).getMember("capabilities").getMember("connectors");
JSON::Value capa_json = capa_lst.getIndice(j).asJSON(); unsigned int capa_lst_ctr = capa_lst.getSize();
addSources(streamName, capa_lst.getIndice(j).getMember("url_rel").asString(), sources, host, port, capa_json, json_resp["meta"], fullHost); for (unsigned int j = 0; j < capa_lst_ctr; ++j){
//if it depends on this connector and has a URL, list it
if (conns.count(capa_lst.getIndiceName(j)) && capa_lst.getIndice(j).getMember("deps").asString() == cProv && capa_lst.getIndice(j).getMember("methods")){
JSON::Value subcapa_json = capa_lst.getIndice(j).asJSON();
addSources(streamName, sources, host, port, subcapa_json, json_resp["meta"], fullHost, &capa_json);
}
} }
} }
} }