diff --git a/DDV_Controller/Makefile b/DDV_Controller/Makefile index d297d255..34c0119d 100644 --- a/DDV_Controller/Makefile +++ b/DDV_Controller/Makefile @@ -1,4 +1,4 @@ -SRC = main.cpp ../util/json/json_reader.cpp ../util/json/json_value.cpp ../util/json/json_writer.cpp ../util/socket.cpp ../util/http_parser.cpp ../util/md5.cpp +SRC = main.cpp ../util/json/json_reader.cpp ../util/json/json_value.cpp ../util/json/json_writer.cpp ../util/socket.cpp ../util/http_parser.cpp ../util/md5.cpp ../util/util.cpp OBJ = $(SRC:.cpp=.o) OUT = DDV_Controller INCLUDES = diff --git a/DDV_Controller/main.cpp b/DDV_Controller/main.cpp index 08557d8b..9d8f1b47 100644 --- a/DDV_Controller/main.cpp +++ b/DDV_Controller/main.cpp @@ -116,15 +116,15 @@ void CheckStreams(Json::Value & in, Json::Value & out){ if (in.isObject() && (in.size() > 0)){ for (Json::ValueIterator jit = in.begin(); jit != in.end(); jit++){ if (out.isObject() && out.isMember(jit.memberName())){ - Log("CONF", std::string("Updated stream ")+jit.memberName(), Storage); + Log("STRM", std::string("Updated stream ")+jit.memberName(), Storage); }else{ - Log("CONF", std::string("New stream ")+jit.memberName(), Storage); + Log("STRM", std::string("New stream ")+jit.memberName(), Storage); } } if (out.isObject() && (out.size() > 0)){ for (Json::ValueIterator jit = out.begin(); jit != out.end(); jit++){ if (!in.isMember(jit.memberName())){ - Log("CONF", std::string("Deleted stream ")+jit.memberName(), Storage); + Log("STRM", std::string("Deleted stream ")+jit.memberName(), Storage); } } } @@ -169,7 +169,7 @@ int main() { if (it->Authorized){ //Parse config and streams from the request. if (Request.isMember("config")){CheckConfig(Request["config"], Storage["config"]);} - //if (Request.isMember("streams")){CheckStreams(Request["streams"], Storage["streams"]);} + if (Request.isMember("streams")){CheckStreams(Request["streams"], Storage["streams"]);} //sent current configuration, no matter if it was changed or not //Response["streams"] = Storage["streams"]; Response["config"] = Storage["config"]; diff --git a/util/proc.cpp b/util/util.cpp similarity index 95% rename from util/proc.cpp rename to util/util.cpp index bfcd3210..4af99705 100644 --- a/util/proc.cpp +++ b/util/util.cpp @@ -1,5 +1,5 @@ -/// \file proc.cpp -/// Contains generic functions for managing processes. +/// \file util.cpp +/// Contains generic functions for managing processes and configuration. #include "proc.h" #include @@ -246,3 +246,15 @@ std::string Util::Procs::getName(pid_t name){ } return ""; } + +Util::Config::Config(){ + listen_port = 4242; + daemon_mode = true; + interface = "0.0.0.0"; + configfile = "/etc/ddvtech.conf"; + username = "root"; + ignore_daemon = false; + ignore_interface = false; + ignore_port = false; + ignore_user = false; +} \ No newline at end of file diff --git a/util/proc.h b/util/util.h similarity index 61% rename from util/proc.h rename to util/util.h index 4b117f0c..4037a9ca 100644 --- a/util/proc.h +++ b/util/util.h @@ -1,5 +1,5 @@ -/// \file proc.h -/// Contains generic function headers for managing processes. +/// \file util.h +/// Contains generic function headers for managing processes and configuration. #include #include @@ -28,6 +28,27 @@ namespace Util{ static std::string getName(pid_t name); }; + /// Will set the active user to the named username. static setUser(std::string user); + + /// Deals with parsing configuration from files or commandline options. + class Config{ + private: + bool ignore_daemon; + bool ignore_interface; + bool ignore_port; + bool ignore_user; + public: + std::string configfile; + bool daemon_mode; + std::string interface; + int listen_port; + std::string username; + Config(); + void parseArgs(int argc, char ** argv); + }; + /// Will turn the current process into a daemon. + void Daemonize(); + };