Fixed Controller compiling, upped socket lib verbosity, fixed JSON::Value null -> string convert, fixed Makefile install command.
This commit is contained in:
parent
d81a99573c
commit
8722effe2f
4 changed files with 80 additions and 46 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -146,32 +147,64 @@ void Authorize( JSON::Value & Request, JSON::Value & Response, ConnectedUser & c
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckProtocols(JSON::Value & p){
|
void CheckProtocols(JSON::Value & p){
|
||||||
static std::map<std::string, std::string> connports;
|
static std::map<std::string, std::string> current_connectors;
|
||||||
bool seenHTTP = false;
|
std::map<std::string, std::string> new_connectors;
|
||||||
bool seenRTMP = false;
|
std::map<std::string, std::string>::iterator iter;
|
||||||
|
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
|
JSON::Value counter = (long long int)0;
|
||||||
|
|
||||||
|
//collect object type
|
||||||
for (JSON::ObjIter jit = p.ObjBegin(); jit != p.ObjEnd(); jit++){
|
for (JSON::ObjIter jit = p.ObjBegin(); jit != p.ObjEnd(); jit++){
|
||||||
if (jit->first == "HTTP"){
|
tmp = "MistConn";
|
||||||
tmp = (std::string)jit->second["port"];
|
tmp += (std::string)jit->second["connector"];
|
||||||
seenHTTP = true;
|
tmp += " -n -p ";
|
||||||
if (connports["HTTP"] != tmp){Util::Procs::Stop("HTTP");}
|
tmp += (std::string)jit->second["port"];
|
||||||
connports["HTTP"] = tmp;
|
if (jit->second.isMember("interface")){
|
||||||
if (!Util::Procs::isActive("HTTP")){
|
tmp += " -i ";
|
||||||
Util::Procs::Start("HTTP", std::string("MistConnHTTP -n -p ")+tmp);
|
tmp += (std::string)jit->second["interface"];
|
||||||
|
}
|
||||||
|
if (jit->second.isMember("username")){
|
||||||
|
tmp += " -u ";
|
||||||
|
tmp += (std::string)jit->second["username"];
|
||||||
|
}
|
||||||
|
counter = (long long int)counter + 1;
|
||||||
|
new_connectors[std::string("Conn")+(std::string)counter] = tmp;
|
||||||
|
}
|
||||||
|
//collect array type
|
||||||
|
for (JSON::ArrIter ait = p.ArrBegin(); ait != p.ArrEnd(); ait++){
|
||||||
|
tmp = "MistConn";
|
||||||
|
tmp += (std::string)(*ait)["connector"];
|
||||||
|
tmp += " -n -p ";
|
||||||
|
tmp += (std::string)(*ait)["port"];
|
||||||
|
if ((*ait).isMember("interface")){
|
||||||
|
tmp += " -i ";
|
||||||
|
tmp += (std::string)(*ait)["interface"];
|
||||||
|
}
|
||||||
|
if ((*ait).isMember("username")){
|
||||||
|
tmp += " -u ";
|
||||||
|
tmp += (std::string)(*ait)["username"];
|
||||||
|
}
|
||||||
|
counter = (long long int)counter + 1;
|
||||||
|
new_connectors[std::string("Conn")+(std::string)counter] = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
//shut down deleted/changed connectors
|
||||||
|
for (iter = current_connectors.begin(); iter != current_connectors.end(); iter++){
|
||||||
|
if (new_connectors.count(iter->first) != 1 || new_connectors[iter->first] != iter->second){
|
||||||
|
Util::Procs::Stop(iter->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (jit->first == "RTMP"){
|
|
||||||
tmp = (std::string)jit->second["port"];
|
//start up new/changed connectors
|
||||||
seenRTMP = true;
|
for (iter = new_connectors.begin(); iter != new_connectors.end(); iter++){
|
||||||
if (connports["RTMP"] != tmp){Util::Procs::Stop("RTMP");}
|
if (current_connectors.count(iter->first) != 1 || current_connectors[iter->first] != iter->second || !Util::Procs::isActive(iter->first)){
|
||||||
connports["RTMP"] = tmp;
|
Util::Procs::Start(iter->first, iter->second);
|
||||||
if (!Util::Procs::isActive("RTMP")){
|
|
||||||
Util::Procs::Start("RTMP", std::string("MistConnRTMP -n -p ")+tmp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!seenHTTP){Util::Procs::Stop("HTTP");}
|
//store new state
|
||||||
if (!seenRTMP){Util::Procs::Stop("RTMP");}
|
current_connectors = new_connectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckConfig(JSON::Value & in, JSON::Value & out){
|
void CheckConfig(JSON::Value & in, JSON::Value & out){
|
||||||
|
@ -227,15 +260,15 @@ void CheckAllStreams(JSON::Value & data){
|
||||||
startStream(jit->first, jit->second);
|
startStream(jit->first, jit->second);
|
||||||
}
|
}
|
||||||
if (currTime - lastBuffer[jit->first] > 5){
|
if (currTime - lastBuffer[jit->first] > 5){
|
||||||
if (jit->second["online"] != 0){changed = true;}
|
if ((long long int)jit->second["online"] != 0){changed = true;}
|
||||||
jit->second["online"] = 0;
|
jit->second["online"] = 0;
|
||||||
}else{
|
}else{
|
||||||
if (jit->second["online"] != 1){changed = true;}
|
if ((long long int)jit->second["online"] != 1){changed = true;}
|
||||||
jit->second["online"] = 1;
|
jit->second["online"] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (changed){
|
if (changed){
|
||||||
WriteFile("/tmp/mist/streamlist", out.toString());
|
WriteFile("/tmp/mist/streamlist", data.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +278,7 @@ void CheckStreams(JSON::Value & in, JSON::Value & out){
|
||||||
if (out.isMember(jit->first)){
|
if (out.isMember(jit->first)){
|
||||||
if (!streamsEqual(jit->second, out[jit->first])){
|
if (!streamsEqual(jit->second, out[jit->first])){
|
||||||
Log("STRM", std::string("Updated stream ")+jit->first);
|
Log("STRM", std::string("Updated stream ")+jit->first);
|
||||||
changed = true
|
changed = true;
|
||||||
Util::Procs::Stop(jit->first);
|
Util::Procs::Stop(jit->first);
|
||||||
startStream(jit->first, jit->second);
|
startStream(jit->first, jit->second);
|
||||||
}
|
}
|
||||||
|
@ -279,10 +312,15 @@ int main(int argc, char ** argv){
|
||||||
sigaction(SIGTERM, &new_action, NULL);
|
sigaction(SIGTERM, &new_action, NULL);
|
||||||
sigaction(SIGPIPE, &new_action, NULL);
|
sigaction(SIGPIPE, &new_action, NULL);
|
||||||
|
|
||||||
|
Storage = JSON::fromString(ReadFile("config.json"));
|
||||||
Util::Config C;
|
Util::Config C;
|
||||||
C.confsection = "API";
|
C.listen_port = (long long int)Storage["config"]["controller"]["port"];
|
||||||
|
if (C.listen_port < 1){C.listen_port = 4242;}
|
||||||
|
C.interface = (std::string)Storage["config"]["controller"]["interface"];
|
||||||
|
if (C.interface == ""){C.interface = "0.0.0.0";}
|
||||||
|
C.username = (std::string)Storage["config"]["controller"]["username"];
|
||||||
|
if (C.username == ""){C.username = "root";}
|
||||||
C.parseArgs(argc, argv);
|
C.parseArgs(argc, argv);
|
||||||
C.parseFile();
|
|
||||||
time_t lastuplink = 0;
|
time_t lastuplink = 0;
|
||||||
time_t processchecker = 0;
|
time_t processchecker = 0;
|
||||||
API_Socket = Socket::Server(C.listen_port, C.interface, true);
|
API_Socket = Socket::Server(C.listen_port, C.interface, true);
|
||||||
|
@ -299,7 +337,6 @@ int main(int argc, char ** argv){
|
||||||
JSON::Value Response;
|
JSON::Value Response;
|
||||||
std::string jsonp;
|
std::string jsonp;
|
||||||
ConnectedUser * uplink = 0;
|
ConnectedUser * uplink = 0;
|
||||||
Storage = JSON::fromString(ReadFile("config.json"));
|
|
||||||
while (API_Socket.connected()){
|
while (API_Socket.connected()){
|
||||||
usleep(100000); //sleep for 100 ms - prevents 100% CPU time
|
usleep(100000); //sleep for 100 ms - prevents 100% CPU time
|
||||||
|
|
||||||
|
|
15
Makefile
15
Makefile
|
@ -1,5 +1,5 @@
|
||||||
default: client
|
default: client
|
||||||
.PHONY: client client-debug client-clean clean release-install debug-install docs
|
.PHONY: client client-debug client-clean clean release-install debug-install install docs
|
||||||
|
|
||||||
prepare:
|
prepare:
|
||||||
mkdir -p ./bin
|
mkdir -p ./bin
|
||||||
|
@ -27,17 +27,10 @@ client-release: prepare
|
||||||
cd Controller; $(MAKE) DEBUG=0 OPTIMIZE=-O2
|
cd Controller; $(MAKE) DEBUG=0 OPTIMIZE=-O2
|
||||||
release: client-release
|
release: client-release
|
||||||
release-install: client-clean client-release
|
release-install: client-clean client-release
|
||||||
cd Connector_RTMP; $(MAKE) install
|
cp ./bin/Mist* /usr/bin/
|
||||||
cd Connector_HTTP; $(MAKE) install
|
|
||||||
cd Connector_RAW; $(MAKE) install
|
|
||||||
cd Buffer; $(MAKE) install
|
|
||||||
cd Controller; $(MAKE) install
|
|
||||||
debug-install: client-clean client-debug
|
debug-install: client-clean client-debug
|
||||||
cd Connector_RTMP; $(MAKE) install
|
cp ./bin/Mist* /usr/bin/
|
||||||
cd Connector_HTTP; $(MAKE) install
|
install: debug-install
|
||||||
cd Connector_RAW; $(MAKE) install
|
|
||||||
cd Buffer; $(MAKE) install
|
|
||||||
cd Controller; $(MAKE) install
|
|
||||||
docs:
|
docs:
|
||||||
doxygen ./Doxyfile > /dev/null
|
doxygen ./Doxyfile > /dev/null
|
||||||
|
|
||||||
|
|
|
@ -253,10 +253,14 @@ JSON::Value::operator long long int(){
|
||||||
JSON::Value::operator std::string(){
|
JSON::Value::operator std::string(){
|
||||||
if (myType == STRING){
|
if (myType == STRING){
|
||||||
return strVal;
|
return strVal;
|
||||||
|
}else{
|
||||||
|
if (myType == EMPTY){
|
||||||
|
return "";
|
||||||
}else{
|
}else{
|
||||||
return toString();
|
return toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Retrieves or sets the JSON::Value at this position in the object.
|
/// Retrieves or sets the JSON::Value at this position in the object.
|
||||||
/// Converts destructively to object if not already an object.
|
/// Converts destructively to object if not already an object.
|
||||||
|
|
|
@ -454,7 +454,7 @@ Socket::Server::Server(int port, std::string hostname, bool nonblock){
|
||||||
sock = socket(AF_INET6, SOCK_STREAM, 0);
|
sock = socket(AF_INET6, SOCK_STREAM, 0);
|
||||||
if (sock < 0){
|
if (sock < 0){
|
||||||
#if DEBUG >= 1
|
#if DEBUG >= 1
|
||||||
fprintf(stderr, "Could not create socket! Error: %s\n", strerror(errno));
|
fprintf(stderr, "Could not create socket %s:%i! Error: %s\n", hostname.c_str(), port, strerror(errno));
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -468,7 +468,7 @@ Socket::Server::Server(int port, std::string hostname, bool nonblock){
|
||||||
struct sockaddr_in6 addr;
|
struct sockaddr_in6 addr;
|
||||||
addr.sin6_family = AF_INET6;
|
addr.sin6_family = AF_INET6;
|
||||||
addr.sin6_port = htons(port);//set port
|
addr.sin6_port = htons(port);//set port
|
||||||
if (hostname == "0.0.0.0"){
|
if (hostname == "0.0.0.0" || hostname.length() == 0){
|
||||||
addr.sin6_addr = in6addr_any;
|
addr.sin6_addr = in6addr_any;
|
||||||
}else{
|
}else{
|
||||||
inet_pton(AF_INET6, hostname.c_str(), &addr.sin6_addr);//set interface, 0.0.0.0 (default) is all
|
inet_pton(AF_INET6, hostname.c_str(), &addr.sin6_addr);//set interface, 0.0.0.0 (default) is all
|
||||||
|
@ -487,14 +487,14 @@ Socket::Server::Server(int port, std::string hostname, bool nonblock){
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
#if DEBUG >= 1
|
#if DEBUG >= 1
|
||||||
fprintf(stderr, "Binding failed, retrying as IPv4... (%s)\n", strerror(errno));
|
fprintf(stderr, "Binding %s:%i failed, retrying as IPv4... (%s)\n", hostname.c_str(), port, strerror(errno));
|
||||||
#endif
|
#endif
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (sock < 0){
|
if (sock < 0){
|
||||||
#if DEBUG >= 1
|
#if DEBUG >= 1
|
||||||
fprintf(stderr, "Could not create socket! Error: %s\n", strerror(errno));
|
fprintf(stderr, "Could not create socket %s:%i! Error: %s\n", hostname.c_str(), port, strerror(errno));
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -508,7 +508,7 @@ Socket::Server::Server(int port, std::string hostname, bool nonblock){
|
||||||
struct sockaddr_in addr4;
|
struct sockaddr_in addr4;
|
||||||
addr4.sin_family = AF_INET;
|
addr4.sin_family = AF_INET;
|
||||||
addr4.sin_port = htons(port);//set port
|
addr4.sin_port = htons(port);//set port
|
||||||
if (hostname == "0.0.0.0"){
|
if (hostname == "0.0.0.0" || hostname.length() == 0){
|
||||||
addr4.sin_addr.s_addr = INADDR_ANY;
|
addr4.sin_addr.s_addr = INADDR_ANY;
|
||||||
}else{
|
}else{
|
||||||
inet_pton(AF_INET, hostname.c_str(), &addr4.sin_addr);//set interface, 0.0.0.0 (default) is all
|
inet_pton(AF_INET, hostname.c_str(), &addr4.sin_addr);//set interface, 0.0.0.0 (default) is all
|
||||||
|
@ -527,7 +527,7 @@ Socket::Server::Server(int port, std::string hostname, bool nonblock){
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
#if DEBUG >= 1
|
#if DEBUG >= 1
|
||||||
fprintf(stderr, "IPv4 binding also failed, giving up. (%s)\n", strerror(errno));
|
fprintf(stderr, "IPv4 binding %s:%i also failed, giving up. (%s)\n", hostname.c_str(), port, strerror(errno));
|
||||||
#endif
|
#endif
|
||||||
close();
|
close();
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue