modify for ledgerupdate
This commit is contained in:
@@ -721,8 +721,16 @@ std::string extractDataJson(const char* inputJson) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// <20><>ȡ "messageBoy" <20><><EFBFBD><EFBFBD>
|
||||
cJSON* messageBoy = cJSON_GetObjectItem(root, "messageBoy");
|
||||
if (messageBoy == NULL || messageBoy->type != cJSON_Object) {
|
||||
std::cerr << "'messageBoy' is missing or is not an object" << std::endl;
|
||||
cJSON_Delete(root);
|
||||
return "";
|
||||
}
|
||||
|
||||
// <20><>ȡ "data" <20><><EFBFBD><EFBFBD>
|
||||
cJSON* data = cJSON_GetObjectItem(root, "data");
|
||||
cJSON* data = cJSON_GetObjectItem(messageBoy, "data");
|
||||
if (data == NULL || data->type != cJSON_Array) {
|
||||
std::cerr << "'data' is missing or is not an array" << std::endl;
|
||||
cJSON_Delete(root);
|
||||
@@ -768,12 +776,20 @@ bool parseJsonMessageRT(const std::string& body, std::string& devSeries, std::st
|
||||
return false;
|
||||
}
|
||||
|
||||
// <20><>ȡ "messageBoy" <20><><EFBFBD><EFBFBD>
|
||||
cJSON* messageBoy = cJSON_GetObjectItem(root, "messageBoy");
|
||||
if (messageBoy == NULL || messageBoy->type != cJSON_Object) {
|
||||
std::cerr << "'messageBoy' is missing or is not an object" << std::endl;
|
||||
cJSON_Delete(root);
|
||||
return "";
|
||||
}
|
||||
|
||||
// <20><>ȡ<EFBFBD>ֶ<EFBFBD>
|
||||
cJSON* devSeriesItem = cJSON_GetObjectItem(root, "devSeries");
|
||||
cJSON* lineItem = cJSON_GetObjectItem(root, "line");
|
||||
cJSON* realDataItem = cJSON_GetObjectItem(root, "realData");
|
||||
cJSON* soeDataItem = cJSON_GetObjectItem(root, "soeData");
|
||||
cJSON* limitItem = cJSON_GetObjectItem(root, "limit");
|
||||
cJSON* devSeriesItem = cJSON_GetObjectItem(messageBoy, "devSeries");
|
||||
cJSON* lineItem = cJSON_GetObjectItem(messageBoy, "line");
|
||||
cJSON* realDataItem = cJSON_GetObjectItem(messageBoy, "realData");
|
||||
cJSON* soeDataItem = cJSON_GetObjectItem(messageBoy, "soeData");
|
||||
cJSON* limitItem = cJSON_GetObjectItem(messageBoy, "limit");
|
||||
|
||||
if (devSeriesItem && lineItem && realDataItem && soeDataItem && limitItem) {
|
||||
devSeries = devSeriesItem->valuestring;
|
||||
@@ -896,6 +912,46 @@ void close_listening_socket() {
|
||||
}
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ip<69><70>ʽ
|
||||
bool isValidIP(const std::string &ip) {
|
||||
std::vector<std::string> parts;
|
||||
std::stringstream ss(ip);
|
||||
std::string part;
|
||||
|
||||
// ʹ<><CAB9> "." <20><>Ϊ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD> IP <20><>ַ<EFBFBD>ָ<EFBFBD><D6B8>ɸ<EFBFBD><C9B8><EFBFBD><EFBFBD><EFBFBD>
|
||||
while (getline(ss, part, '.')) {
|
||||
parts.push_back(part);
|
||||
}
|
||||
|
||||
// IP <20><>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 4 <20><><EFBFBD><EFBFBD>
|
||||
if (parts.size() != 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// У<><D0A3>ÿһ<C3BF><D2BB><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 <20><> 255 ֮<><D6AE>
|
||||
for (size_t i = 0; i < parts.size(); ++i) {
|
||||
// У<><D0A3>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
||||
for (size_t j = 0; j < parts[i].size(); ++j) {
|
||||
if (!isdigit(parts[i][j])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ת<><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>Χ<EFBFBD><CEA7>
|
||||
int num = atoi(parts[i].c_str());
|
||||
if (num < 0 || num > 255) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>㣨<EFBFBD><E3A3A8> 01<30><31>001 <20>ȣ<EFBFBD>
|
||||
if (parts[i].length() > 1 && parts[i][0] == '0') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//ִ<>нű<D0BD><C5B1><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>
|
||||
void execute_bash(string fun,int process_num,string type)
|
||||
{
|
||||
@@ -918,6 +974,25 @@ void execute_bash(string fun,int process_num,string type)
|
||||
system(command);
|
||||
}
|
||||
|
||||
//ִ<>нű<D0BD><C5B1><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>
|
||||
void execute_bash_debug(string fun,string ip,string type)
|
||||
{
|
||||
|
||||
const char* script = "/FeProject/bin/set_debug.sh";//ʹ<><CAB9>setsid<69><64>ֹ<EFBFBD>˿<EFBFBD>ռ<EFBFBD><D5BC>
|
||||
const char* param1 = fun.c_str();
|
||||
const char* param2 = ip.c_str();
|
||||
const char* param3 = type.c_str();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
char command[256];
|
||||
snprintf(command, sizeof(command), "%s %s %s %s &", script, param1, param2, param3);
|
||||
|
||||
std::cout << "command:" << command <<std::endl;
|
||||
|
||||
// ִ<><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
system(command);
|
||||
}
|
||||
|
||||
void parse_set(const std::string& json_str) {
|
||||
// <20><><EFBFBD><EFBFBD> JSON <20>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
cJSON* root = cJSON_Parse(json_str.c_str());
|
||||
@@ -926,8 +1001,16 @@ void parse_set(const std::string& json_str) {
|
||||
return;
|
||||
}
|
||||
|
||||
// <20><>ȡ "messageBoy" <20><><EFBFBD><EFBFBD>
|
||||
cJSON* messageBoy = cJSON_GetObjectItem(root, "messageBoy");
|
||||
if (messageBoy == NULL || messageBoy->type != cJSON_Object) {
|
||||
std::cerr << "'messageBoy' is missing or is not an object" << std::endl;
|
||||
cJSON_Delete(root);
|
||||
return ;
|
||||
}
|
||||
|
||||
// <20><>ȡ code <20>ֶ<EFBFBD>
|
||||
cJSON* code = cJSON_GetObjectItem(root, "code");
|
||||
cJSON* code = cJSON_GetObjectItem(messageBoy, "code");
|
||||
if (code == nullptr) {
|
||||
std::cout << "Missing 'code' in JSON." << std::endl;
|
||||
cJSON_Delete(root);
|
||||
@@ -946,7 +1029,7 @@ void parse_set(const std::string& json_str) {
|
||||
string index_value_str = index->valuestring;
|
||||
int index_value = StringToInt(index_value_str);
|
||||
|
||||
//<2F><><EFBFBD>̺<EFBFBD>Ϊ0<CEAA>Ľ<EFBFBD><C4BD>̴<EFBFBD><CCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨<EFBFBD>˸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
//<2F><><EFBFBD>̺<EFBFBD>Ϊ0<CEAA>Ľ<EFBFBD><C4BD>̴<EFBFBD><CCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
if (index_value != g_front_seg_index && g_front_seg_index !=0) {
|
||||
std::cout << "msg index:"<< index_value <<"doesnt match self index:" << g_front_seg_index << std::endl;
|
||||
cJSON_Delete(root);
|
||||
@@ -997,6 +1080,38 @@ void parse_set(const std::string& json_str) {
|
||||
}
|
||||
|
||||
}
|
||||
else if (code_str == "set_debug"){
|
||||
if(g_node_id == STAT_DATA_BASE_NODE_ID && g_front_seg_index == 1){
|
||||
std::cout << "cfg_stat_data process" << g_front_seg_index <<" handle this msg" << std::endl;
|
||||
// <20><><EFBFBD><EFBFBD> set_process
|
||||
cJSON* data = cJSON_GetObjectItem(root, "data");
|
||||
if (data != nullptr && data->type == cJSON_Array) {
|
||||
int data_size = cJSON_GetArraySize(data);
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
cJSON* item = cJSON_GetArrayItem(data, i);
|
||||
|
||||
std::string fun = cJSON_GetObjectItem(item, "fun")->valuestring;
|
||||
std::string ip = cJSON_GetObjectItem(item, "ip")->valuestring;
|
||||
std::string frontType = cJSON_GetObjectItem(item, "frontType")->valuestring;
|
||||
|
||||
//У<><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if((fun == "start" || fun == "delete") &&
|
||||
isValidIP(ip) &&
|
||||
(frontType == "stat" || frontType == "recall" || frontType == "3s" || frontType == "comtrade")){
|
||||
execute_bash_debug(fun, ip, frontType);
|
||||
std::cout << "!!!!!!!!!!!!!!!! execute mark:" << i << " !!!!!!!!!!!!!!!" <<std::endl;
|
||||
}
|
||||
else{
|
||||
std::cout << "param is not executable" <<std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << "this msg should only execute once" <<std::endl;
|
||||
}
|
||||
}
|
||||
else{
|
||||
std::cout << "only cfg_stat_data index 1 can control process,this process not handle this msg" << std::endl;
|
||||
}
|
||||
}
|
||||
else{
|
||||
std::cout << "set process code str error" <<std::endl;
|
||||
}
|
||||
@@ -1197,15 +1312,23 @@ void parse_control(const std::string& json_str, const std::string& output_dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
// <20><>ȡ "messageBoy" <20><><EFBFBD><EFBFBD>
|
||||
cJSON* messageBoy = cJSON_GetObjectItem(root, "messageBoy");
|
||||
if (messageBoy == NULL || messageBoy->type != cJSON_Object) {
|
||||
std::cerr << "'messageBoy' is missing or is not an object" << std::endl;
|
||||
cJSON_Delete(root);
|
||||
return ;
|
||||
}
|
||||
|
||||
// <20><>ȡ code <20>ֶ<EFBFBD>
|
||||
cJSON* code = cJSON_GetObjectItem(root, "code");
|
||||
cJSON* code = cJSON_GetObjectItem(messageBoy, "code");
|
||||
if (code == nullptr) {
|
||||
std::cout << "Missing 'code' in JSON." << std::endl;
|
||||
cJSON_Delete(root);
|
||||
return;
|
||||
}
|
||||
|
||||
cJSON* index = cJSON_GetObjectItem(root, "index");
|
||||
cJSON* index = cJSON_GetObjectItem(messageBoy, "index");
|
||||
if (index == nullptr) {
|
||||
std::cout << "Missing 'index' in JSON." << std::endl;
|
||||
cJSON_Delete(root);
|
||||
@@ -1235,7 +1358,7 @@ void parse_control(const std::string& json_str, const std::string& output_dir) {
|
||||
std::cout << "add or update ledger" <<std::endl;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> add_terminal <20><> ledger_modify
|
||||
cJSON* data = cJSON_GetObjectItem(root, "data");
|
||||
cJSON* data = cJSON_GetObjectItem(messageBoy, "data");
|
||||
if (data != nullptr && data->type == cJSON_Array) {
|
||||
int data_size = cJSON_GetArraySize(data);
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
Reference in New Issue
Block a user