提交 5c329844 authored 作者: blu's avatar blu

new feature entropy filter to ignore gray frame without iframe

上级 a360689b
...@@ -21,6 +21,7 @@ using namespace nlohmann; ...@@ -21,6 +21,7 @@ using namespace nlohmann;
// //
class HttpSrv{ class HttpSrv{
#define KEY_CONFIG_MAP "configmap"
private: private:
Server svr; Server svr;
// sn:module -> sn_of_evmgr // sn:module -> sn_of_evmgr
...@@ -28,6 +29,8 @@ class HttpSrv{ ...@@ -28,6 +29,8 @@ class HttpSrv{
json config(string body){ json config(string body){
json ret; json ret;
int iret;
json oldConfigMap = this->configMap;
ret["code"] = 0; ret["code"] = 0;
ret["msg"] = "ok"; ret["msg"] = "ok";
ret["time"] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count(); ret["time"] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
...@@ -50,54 +53,82 @@ class HttpSrv{ ...@@ -50,54 +53,82 @@ class HttpSrv{
ret["code"] = 2; ret["code"] = 2;
ret["msg"] = "evcloudsvc invalid value for key " + k; ret["msg"] = "evcloudsvc invalid value for key " + k;
spdlog::error(ret["msg"].get<string>()); spdlog::error(ret["msg"].get<string>());
continue; break;
}else{ }else{
// find all modules // find all modules
if(v.count("ipcs") == 0||v["ipcs"].size() == 0) { if(v.count("ipcs") == 0||v["ipcs"].size() == 0) {
spdlog::error("invalid ipcs in config body"); spdlog::error("invalid ipcs in config body");
continue; ret["code"] = 3;
break;
}else{ }else{
json &ipcs = v["ipcs"]; json &ipcs = v["ipcs"];
for(auto &ipc : ipcs) { for(auto &ipc : ipcs) {
if(ipc.count("modules") == 0||ipc["modules"].size() == 0) { if(ipc.count("modules") == 0||ipc["modules"].size() == 0) {
spdlog::error("invalid modules in ipcs config body"); spdlog::error("invalid modules in ipcs config body");
continue; ret["code"] = 4;
break;
}else{ }else{
json &modules = ipc["modules"]; json &modules = ipc["modules"];
for(auto &[mn, ml]: modules.items()) { for(auto &[mn, ma]: modules.items()) {
if(ml.count("sn") != 0 && ml["sn"].size() != 0){ for(auto &m:ma) {
string modKey; if(m.count("sn") != 0 && m["sn"].size() != 0){
//ml string modKey;
if(mn == "evml" && ml.count("type") != 0 && ml["type"].size() != 0) { //ml
modKey = ml["sn"].get<string>() +":evml:" + ml["type"].get<string>(); if(mn == "evml" && m.count("type") != 0 && m["type"].size() != 0) {
modKey = m["sn"].get<string>() +":evml:" + m["type"].get<string>();
}else{
modKey = m["sn"].get<string>() + ":" + mn;
}
// modkey -> sn_of_evmgr
this->configMap[modKey] = k;
}else{ }else{
modKey = ml["sn"].get<string>() + ":" + mn; string msg = "evcloudsvc invalid config: " + data.dump();;
ret["code"] = -1;
ret["msg"] = msg;
spdlog::error(msg);
break;
} }
this->configMap[modKey] = v;
} }
} // for modules } // for modules
}
} // for ipc if(ret["code"] != 0) {
} break;
}
} // for ipc
}
}
if(ret["code"] != 0) {
break;
}
} }
// update evmgr config // update evmgr config
json evmgrData; json evmgrData;
evmgrData["data"] = data; evmgrData["data"] = data;
//evmgrData["lastupdated"] = newConfig["lastupdated"];
//save //save
int r = LVDB::setLocalConfig(evmgrData, k); iret = LVDB::setLocalConfig(evmgrData, k);
if(r < 0) { if(iret < 0) {
string msg = "failed to save config " + k + " -> " + evmgrData.dump(); string msg = "failed to save config " + k + " -> " + evmgrData.dump();
spdlog::error(msg); spdlog::error(msg);
ret["code"] = r; ret["code"] = iret;
ret["msg"] = msg; ret["msg"] = msg;
} }
} // for evmgr } // for evmgr
// save configmap // save configmap
if(ret >= 0) { if(ret["code"] == 0) {
LVDB::setValue(this->configMap, "configmap"); iret = LVDB::setValue(this->configMap, KEY_CONFIG_MAP);
if(iret >= 0) {
}else{
ret["code"] = iret;
ret["msg"] = "failed to save configmap";
}
}else{
this->configMap = oldConfigMap;
} }
ret["data"] = newConfig["data"]; ret["data"] = newConfig["data"];
} }
}catch(exception &e) { }catch(exception &e) {
...@@ -115,7 +146,7 @@ class HttpSrv{ ...@@ -115,7 +146,7 @@ class HttpSrv{
void run(){ void run(){
// load configmap // load configmap
json cnfm; json cnfm;
LVDB::getValue(cnfm, "configmap"); LVDB::getValue(cnfm, KEY_CONFIG_MAP);
if(cnfm.size() != 0){ if(cnfm.size() != 0){
this->configMap = cnfm; this->configMap = cnfm;
} }
...@@ -143,6 +174,8 @@ class HttpSrv{ ...@@ -143,6 +174,8 @@ class HttpSrv{
ret = this->config(req.body); ret = this->config(req.body);
if(ret["code"] == 0) { if(ret["code"] == 0) {
//ret["data"] =ret["data"]; //ret["data"] =ret["data"];
}else{
spdlog::error("failed to config: {}", ret.dump());
} }
}else{ }else{
// TODO: calc md5 // TODO: calc md5
...@@ -175,35 +208,40 @@ class HttpSrv{ ...@@ -175,35 +208,40 @@ class HttpSrv{
ret["code"] = 0; ret["code"] = 0;
ret["time"] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count(); ret["time"] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
ret["msg"] = "ok"; ret["msg"] = "ok";
if(!req.has_param("sn") || !req.has_param("module")||req.get_param_value("module").size()< 4){ string sn = req.get_param_value("sn");
string module = req.get_param_value("module");
if(sn.empty() || module.empty() || module.size()< 4){
ret["code"] = 1; ret["code"] = 1;
ret["msg"] = "evcloud bad req: no sn/module param"; ret["msg"] = "evcloud bad req: no sn/module param";
spdlog::error(ret["msg"].get<string>()); spdlog::error(ret["msg"].get<string>());
}else{ }else{
string sn = req.get_param_value("sn");
string module = req.get_param_value("module");
string modname = module.substr(0,4); string modname = module.substr(0,4);
if(modname == "evml") { string key;
modname = "evml:" + module.substr(4, module.size()); if(module == "evmgr") {
}else{ key = sn;
modname = module; }else {
if(modname == "evml") {
modname = "evml:" + module.substr(4, module.size());
}else{
modname = module;
}
key = sn + ":" + modname;
} }
string key = sn + ":" + modname; if(!key.empty()) {
if(this->configMap.count(key) != 0) {
json config; json config;
ret = LVDB::getLocalConfig(config, this->configMap[key]); int iret = LVDB::getLocalConfig(config, key);
if(iret < 0) {
if(ret < 0) {
ret["code"] = 1; ret["code"] = 1;
ret["msg"] = "evcloud failed to get config with k, v:" + key + " " + this->configMap[key].get<string>(); ret["msg"] = "evcloud failed to get config with k, v:" + key + " " + this->configMap[key].get<string>();
spdlog::error(ret["msg"].get<string>()); spdlog::error(ret["msg"].get<string>());
}else{ }else{
ret["data"] = config; ret["data"] = config["data"];
ret["lastupdated"] = config["lastupdated"];
} }
}else{ }else{
ret["code"] = 1; ret["code"] = 1;
ret["msg"] = "no config for sn " + sn, + ", module " + module; ret["msg"] = "no config for sn " + sn + ", module " + module;
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论