secgateway/Platform/user/logging/logging_common.c

84 lines
1.9 KiB
C
Raw Normal View History

#include "logging_common.h"
#include "ulog_api.h"
#include "log_types.h"
#include "configm.h"
#include "configmapi.h"
#include "ulog/ulog_in.h"
int set_log_conf(uint config_type, cJSON *json_obj, uint64 config_id, cJSON **json_output)
{
int ret = -1;
char *output;
int output_len;
char *json = cJSON_PrintUnformatted(json_obj);
if (json == NULL) {
ULOG_ERR(g_log, "Converting struct to json is failure");
return ret;
}
ULOG_DEBUG(g_log, "Setting log json is %s", json);
ret_code ret_c = web_config_exec_sync(config_type, config_id,
json, strlen(json),
&output, &output_len);
if (ret_c != RET_OK) {
ULOG_ERR(g_log, "Log of Web config is failure:%d", ret_c);
} else {
ret = 0;
}
if ((CM_CONFIG_GET == config_type || CM_CONFIG_GET_ALL == config_type) && json_output != NULL)
{
ULOG_DEBUG(g_log, "get outputlen:%d, output:%s", output_len, output);
*json_output = output;
}
else
{
*json_output = NULL;
}
if (json != NULL) {
free(json);
}
return ret;
}
int logging_terminal_json_parse(pointer input, pointer config_buff, int conf_id)
{
cJSON *json_obj = NULL;
if (NULL == config_buff) {
return -1;
}
json_obj = cJSON_Parse(input);
if (!json_obj)
{
return -1;
}
s2j_create_struct_obj(log_terminal, log_console_t);
if (NULL == log_terminal)
{
cJSON_Delete(json_obj);
return -1;
}
s2j_struct_get_basic_element(log_terminal, json_obj, int, level);
s2j_struct_get_basic_element(log_terminal, json_obj, int, on);
s2j_struct_get_basic_element(log_terminal, json_obj, string, module);
memcpy(config_buff, log_terminal, sizeof(log_console_t));
s2j_delete_struct_obj(json_obj);
cJSON_Delete(json_obj);
return 0;
}