Fixed TS, added several parameters for MistConnTS, controller now builds parameters correctly (spaces issue)

This commit is contained in:
ThatGuy 2013-07-29 11:40:16 +02:00
parent 67815bcce4
commit 2cc27efcae
4 changed files with 154 additions and 16 deletions

View file

@ -184,6 +184,9 @@ namespace Controller {
capa["connectors"]["TS"]["optional"]["username"]["name"] = "Username";
capa["connectors"]["TS"]["optional"]["username"]["help"] = "Username to drop privileges to - default if unprovided means do not drop privileges";
capa["connectors"]["TS"]["optional"]["username"]["type"] = "str";
capa["connectors"]["TS"]["optional"]["tracks"]["name"] = "Tracks";
capa["connectors"]["TS"]["optional"]["tracks"]["help"] = "The track IDs of the stream that this connector will transmit separated by spaces";
capa["connectors"]["TS"]["optional"]["tracks"]["type"] = "str";
capa["connectors"]["HTTP"]["desc"] =
"Enables the generic HTTP listener, required by all other HTTP protocols. Needs other HTTP protocols enabled to do much of anything.";
capa["connectors"]["HTTP"]["deps"] = "";

View file

@ -1,3 +1,6 @@
#include <stdio.h> // cout, cerr
#include <string>
#include <cstring> // strcpy
#include <mist/json.h>
#include <mist/config.h>
#include <mist/procs.h>
@ -10,6 +13,8 @@ namespace Controller {
static std::map<std::string, std::string> currentConnectors; ///<The currently running connectors.
///\brief Checks if the binary mentioned in the protocol argument is currently active, if so, restarts it.
///\param protocol The protocol to check.
void UpdateProtocol(std::string protocol){
@ -32,7 +37,64 @@ namespace Controller {
}
}
///\brief Checks current protocol configuration, updates state of enabled connectors if neccesary.
void buildPipedArguments(JSON::Value & p, std::string conn, char * argarr[]){
int argnum = 2; //first two are progname and -n
std::string arg;
std::string conname;
for (JSON::ArrIter ait = p.ArrBegin(); ait != p.ArrEnd(); ait++){
conname = (std::string("MistConn") + ( *ait)["connector"].asString());
conn = conn.substr(0, conn.find(" ") );
if ( !( *ait).isMember("connector") || ( *ait)["connector"].asString() == "" || conn != conname){
continue;
}
std::string tmppath = Util::getMyPath() + std::string("MistConn") + ( *ait)["connector"].asString();
argarr[0] = new char[ tmppath.size() + 1]; std::strncpy(argarr[0], tmppath.c_str(), tmppath.size() + 1);
argarr[1] = new char[3]; std::strncpy(argarr[1], "-n\0", 3);
if (( *ait).isMember("port") && ( *ait)["port"].asInt() != 0){
arg = ( *ait)["port"].asString();
argarr[argnum] = new char[3]; std::strncpy(argarr[argnum], "-p\0", 3); argnum++;
argarr[argnum] = new char[arg.size() + 1]; std::strncpy(argarr[argnum], arg.c_str(), arg.size() + 1); argnum++;
}
if (( *ait).isMember("interface") && ( *ait)["interface"].asString() != "" && ( *ait)["interface"].asString() != "0.0.0.0"){
arg = ( *ait)["interface"].asString();
argarr[argnum] = new char[3]; std::strncpy(argarr[argnum], "-i\0", 3); argnum++;
argarr[argnum] = new char[arg.size() + 1]; std::strncpy(argarr[argnum], arg.c_str(), arg.size() + 1 ); argnum++;
}
if (( *ait).isMember("username") && ( *ait)["username"].asString() != "" && ( *ait)["username"].asString() != "root"){
arg = ( *ait)["username"].asString();
argarr[argnum] = new char[3]; std::strncpy(argarr[argnum], "-u\0", 3); argnum++;
argarr[argnum] = new char[arg.size() + 1]; std::strncpy(argarr[argnum], arg.c_str(), arg.size() + 1); argnum++;
}
if (( *ait).isMember("tracks") && ( *ait)["tracks"].asString() != ""){
arg = ( *ait)["tracks"].asString();
argarr[argnum] = new char[3]; std::strncpy(argarr[argnum], "-t\0", 3); argnum++;
argarr[argnum] = new char[arg.size() + 1]; std::strncpy(argarr[argnum], arg.c_str(), arg.size() + 1); argnum++;
}
if (( *ait).isMember("args") && ( *ait)["args"].asString() != ""){
arg = ( *ait)["args"].asString();
argarr[argnum] = new char[arg.size() + 1]; std::strncpy(argarr[argnum], arg.c_str(), arg.size() + 1); argnum++;
}
}
argarr[argnum] = NULL;
}
///\brief Checks current protocol coguration, updates state of enabled connectors if neccesary.
///\param p An object containing all protocols.
void CheckProtocols(JSON::Value & p){
std::map<std::string, std::string> new_connectors;
@ -40,6 +102,13 @@ namespace Controller {
bool haveHTTPgeneric = false;
bool haveHTTPspecific = false;
// used for building args
int zero = 0;
int out = fileno(stdout);
int err = fileno(stderr);
char * argarr[15]; // approx max # of args (with a wide margin)
int i;
std::string tmp;
JSON::Value counter = (long long int)0;
@ -48,7 +117,9 @@ namespace Controller {
continue;
}
tmp = std::string("MistConn") + ( *ait)["connector"].asString() + std::string(" -n");
tmp = std::string("MistConn") + ( *ait)["connector"].asString();
tmp += std::string(" -n");
if (( *ait)["connector"].asString() == "HTTP"){
haveHTTPgeneric = true;
}
@ -62,12 +133,17 @@ namespace Controller {
if (( *ait).isMember("interface") && ( *ait)["interface"].asString() != "" && ( *ait)["interface"].asString() != "0.0.0.0"){
tmp += std::string(" -i ") + ( *ait)["interface"].asString();
}
if (( *ait).isMember("username") && ( *ait)["username"].asString() != "" && ( *ait)["username"].asString() != "root"){
tmp += std::string(" -u ") + ( *ait)["username"].asString();
}
if (( *ait).isMember("tracks") && ( *ait)["tracks"].asString() != ""){
tmp += std::string(" -t \"") + ( *ait)["tracks"].asString() + "\"";
}
if (( *ait).isMember("args") && ( *ait)["args"].asString() != ""){
tmp += std::string(" ") + ( *ait)["args"].asString();
}
@ -93,7 +169,19 @@ namespace Controller {
for (iter = new_connectors.begin(); iter != new_connectors.end(); iter++){
if (currentConnectors.count(iter->first) != 1 || currentConnectors[iter->first] != iter->second || !Util::Procs::isActive(iter->first)){
Log("CONF", "Starting connector: " + iter->second);
Util::Procs::Start(iter->first, Util::getMyPath() + iter->second);
// clear out old args
for (i=0;i<15;i++)
{
argarr[i] = NULL;
}
// get args for this connector
buildPipedArguments(p, iter->second, (char **)&argarr);
// start piped w/ generated args
Util::Procs::StartPiped(iter->first, argarr, &zero, &out, &err);
}
}