Util merge-age

This commit is contained in:
Thulinma 2011-10-17 08:42:26 +02:00
commit 72278f28b8
4 changed files with 42 additions and 9 deletions

View file

@ -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) OBJ = $(SRC:.cpp=.o)
OUT = DDV_Controller OUT = DDV_Controller
INCLUDES = INCLUDES =

View file

@ -116,15 +116,15 @@ void CheckStreams(Json::Value & in, Json::Value & out){
if (in.isObject() && (in.size() > 0)){ if (in.isObject() && (in.size() > 0)){
for (Json::ValueIterator jit = in.begin(); jit != in.end(); jit++){ for (Json::ValueIterator jit = in.begin(); jit != in.end(); jit++){
if (out.isObject() && out.isMember(jit.memberName())){ 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{ }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)){ if (out.isObject() && (out.size() > 0)){
for (Json::ValueIterator jit = out.begin(); jit != out.end(); jit++){ for (Json::ValueIterator jit = out.begin(); jit != out.end(); jit++){
if (!in.isMember(jit.memberName())){ 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){ if (it->Authorized){
//Parse config and streams from the request. //Parse config and streams from the request.
if (Request.isMember("config")){CheckConfig(Request["config"], Storage["config"]);} 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 //sent current configuration, no matter if it was changed or not
//Response["streams"] = Storage["streams"]; //Response["streams"] = Storage["streams"];
Response["config"] = Storage["config"]; Response["config"] = Storage["config"];

View file

@ -1,5 +1,5 @@
/// \file proc.cpp /// \file util.cpp
/// Contains generic functions for managing processes. /// Contains generic functions for managing processes and configuration.
#include "proc.h" #include "proc.h"
#include <string.h> #include <string.h>
@ -246,3 +246,15 @@ std::string Util::Procs::getName(pid_t name){
} }
return ""; 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;
}

View file

@ -1,5 +1,5 @@
/// \file proc.h /// \file util.h
/// Contains generic function headers for managing processes. /// Contains generic function headers for managing processes and configuration.
#include <unistd.h> #include <unistd.h>
#include <string> #include <string>
@ -28,6 +28,27 @@ namespace Util{
static std::string getName(pid_t name); static std::string getName(pid_t name);
}; };
/// Will set the active user to the named username.
static setUser(std::string user); 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();
}; };