Merge branch 'master' of http://git.komect.net/ISG/secogateway
This commit is contained in:
commit
62a5d8eea4
|
@ -119,8 +119,8 @@ LINUX_KERNEL := $(HUACHENG_LINUX_KERNEL)
|
|||
endif
|
||||
|
||||
# 设置 ARM64 平台 SDK 头文件和库文件路径
|
||||
ARM64_SDK_INCLUDE := $(SDKTARGETSYSROOT)/include
|
||||
ARM64_SDK_LIBDIR := $(SDKTARGETSYSROOT)
|
||||
ARM64_SDK_INCLUDE := $(SDKTARGETSYSROOT)/usr/include
|
||||
ARM64_SDK_LIBDIR := $(SDKTARGETSYSROOT)/usr/lib
|
||||
|
||||
# 设置平台安装子目录
|
||||
CPU_ARM64_DIR := ARM64
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
|
||||
#define AUTHFREE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|1)
|
||||
#define FREEPARAMETERS_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|2)
|
||||
#define AUTH_CONFIG_RECOVER (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|3)
|
||||
|
||||
|
||||
#define LOG_CONFIG_CONSOLE (uint64)((uint64)LOG_CONFIG_MODULE<<32|1)
|
||||
|
@ -55,6 +56,7 @@
|
|||
#define LOG_CONFIG_REMOTE_DEL_HOST (uint64)((uint64)LOG_CONFIG_MODULE<<32|4)
|
||||
#define LOG_CONFIG_REMOTE_LEVEL (uint64)((uint64)LOG_CONFIG_MODULE<<32|5)
|
||||
#define LOG_CONFIG_FILE (uint64)((uint64)LOG_CONFIG_MODULE<<32|6)
|
||||
#define LOG_CONFIG_REMOTE_GET_HOST (uint64)((uint64)LOG_CONFIG_MODULE<<32|7)
|
||||
|
||||
#define VLAN_CONFIG (uint64)((uint64)VLAN_CONFIG_MODULE<<32|1)
|
||||
|
||||
|
|
|
@ -41,6 +41,14 @@ typedef struct _log_remote_level {
|
|||
u8 level;
|
||||
} log_remote_level_t;
|
||||
|
||||
typedef struct _log_remote_host_x {
|
||||
log_rfc_t rfc;
|
||||
char host[LOG_HOST_SZ];
|
||||
u16 port;
|
||||
u8 level;
|
||||
} log_remote_host_x_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
LOG_UNCOMPRESS = 0,
|
||||
LOG_COMPRESS
|
||||
|
|
|
@ -33,7 +33,7 @@ COMMON_SRCS = configserver.c \
|
|||
netconfig/bridge/libbridge/libbridge_if.c netconfig/bridge/libbridge/libbridge_init.c netconfig/bridge/libbridge/libbridge_devif.c\
|
||||
web_config/config-adm/user_authpara.c \
|
||||
web_config/config-adm/user_authfree.c \
|
||||
web_config/authfree.c web_config/auth_parameters.c\
|
||||
web_config/authfree.c web_config/auth_parameters.c web_config/auth_recover_config.c \
|
||||
user_manager_config/user_recover_config.c user_manager_config/user_group_config.c user_manager_config/user_account_config.c user_manager_config/usermanager-server/array_index.c \
|
||||
user_manager_config/usermanager-server/user_group.c user_manager_config/usermanager-server/user_mod.c user_manager_config/usermanager-server/user.c \
|
||||
log_config/log_config_console.c log_config/log_config_init.c log_config/log_config_cm.c log_config/log_config_monitor.c log_config/log_config_remote.c log_config/log_config_file.c \
|
||||
|
|
|
@ -9,39 +9,72 @@
|
|||
#include "rpc.h"
|
||||
#include "configm.h"
|
||||
|
||||
|
||||
config_service_t g_config_service[] = CONFIG_SERVICE_ARRAY;
|
||||
config_init_t g_config_init[] = CONFIG_INIT_ARRAY;
|
||||
|
||||
void test_big_data(rpc_conn *conn, pointer input, int input_len, void* data) {
|
||||
char buf[input_len];
|
||||
memcpy(buf, input, input_len);
|
||||
buf[input_len] = '\0';
|
||||
printf("get data is %s\n", buf);
|
||||
//sleep(15);
|
||||
rpc_return_null(conn);
|
||||
int cm_format_data(ret_code ret_code, cJSON *item_obj, char *output)
|
||||
{
|
||||
int str_len = 0;
|
||||
char *ret_char = NULL;
|
||||
config_result_t tem_buff = {0};
|
||||
config_result_t *config_ret = &tem_buff;
|
||||
|
||||
|
||||
snprintf(config_ret->resultCode, RET_CODE_LEN - 1, "%d", ret_code);
|
||||
config_ret->message = (char *)rpc_code_format(ret_code);
|
||||
|
||||
s2j_create_json_obj(json_obj);
|
||||
if(json_obj == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
s2j_json_set_basic_element(json_obj, config_ret, string, resultCode);
|
||||
s2j_json_set_basic_element(json_obj, config_ret, string, message);
|
||||
|
||||
cJSON_AddItemToObject(json_obj, "data", item_obj);
|
||||
|
||||
ret_char = cJSON_PrintUnformatted(json_obj);
|
||||
str_len = strlen(ret_char);
|
||||
|
||||
strncpy(output, ret_char, CM_BUFF_SIZE - 1);
|
||||
|
||||
rpc_free(ret_char);
|
||||
cJSON_Delete(json_obj);
|
||||
|
||||
return (str_len + 1);
|
||||
}
|
||||
|
||||
|
||||
void cm_return(rpc_conn *conn, ret_code err_code, char* err_message)
|
||||
{
|
||||
cJSON *res;
|
||||
char *ret_char = NULL;
|
||||
char *null_str = "";
|
||||
config_result_t tem_buff = {0};
|
||||
config_result_t *config_ret = &tem_buff;
|
||||
|
||||
rpc_log_dbg("error %d:%s\n", err_code, err_message);
|
||||
|
||||
res = cJSON_CreateObject();
|
||||
if(res == NULL)
|
||||
snprintf(config_ret->resultCode, RET_CODE_LEN - 1, "%d", err_code);
|
||||
config_ret->message = (char *)rpc_code_format(err_code);
|
||||
config_ret->data = null_str;
|
||||
|
||||
s2j_create_json_obj(json_obj);
|
||||
if(json_obj == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cJSON_AddNumberToObject(res, "error", err_code);
|
||||
ret_char = cJSON_PrintUnformatted(res);
|
||||
s2j_json_set_basic_element(json_obj, config_ret, string, resultCode);
|
||||
s2j_json_set_basic_element(json_obj, config_ret, string, message);
|
||||
s2j_json_set_basic_element(json_obj, config_ret, string, data);
|
||||
|
||||
cJSON_Delete(res);
|
||||
ret_char = cJSON_PrintUnformatted(json_obj);
|
||||
|
||||
rpc_return(conn, ret_char, strlen(ret_char)+1);
|
||||
|
||||
rpc_free(ret_char);
|
||||
cJSON_Delete(json_obj);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,12 @@
|
|||
#include "log_config.h"
|
||||
#include "../web_config/authfree.h"
|
||||
#include "../web_config/auth_parameters.h"
|
||||
#include "../web_config/auth_recover_config.h"
|
||||
#include "natconfig.h"
|
||||
#include "vlan_config.h"
|
||||
|
||||
#define RET_CODE_LEN 16
|
||||
#define RET_MSG_LEN 128
|
||||
|
||||
#define CONFIG_INIT_ARRAY \
|
||||
{\
|
||||
|
@ -116,6 +119,15 @@
|
|||
NULL, \
|
||||
NULL \
|
||||
},\
|
||||
{\
|
||||
AUTH_CONFIG_RECOVER, \
|
||||
CONFIG_FROM_RECOVER1, \
|
||||
TRUE, \
|
||||
auth_recover_chk, \
|
||||
auth_recover_proc, \
|
||||
auth_recover_get, \
|
||||
auth_recover_get_all \
|
||||
},\
|
||||
{\
|
||||
USER_MANAGER_CONFIG_USER, \
|
||||
CONFIG_FROM_WEB, \
|
||||
|
@ -131,8 +143,8 @@
|
|||
FALSE, \
|
||||
log_console_config_chk, \
|
||||
log_console_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
log_console_config_get, \
|
||||
log_console_config_getall \
|
||||
},\
|
||||
{\
|
||||
LOG_CONFIG_MONITOR, \
|
||||
|
@ -140,8 +152,8 @@
|
|||
FALSE, \
|
||||
log_monitor_config_chk, \
|
||||
log_monitor_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
log_monitor_config_get, \
|
||||
log_monitor_config_getall \
|
||||
},\
|
||||
{\
|
||||
LOG_CONFIG_REMOTE_ADD_HOST, \
|
||||
|
@ -167,8 +179,8 @@
|
|||
FALSE, \
|
||||
log_remote_level_config_chk, \
|
||||
log_remote_level_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
log_remote_level_config_get, \
|
||||
log_remote_level_config_getall \
|
||||
},\
|
||||
{\
|
||||
LOG_CONFIG_FILE, \
|
||||
|
@ -176,8 +188,17 @@
|
|||
FALSE, \
|
||||
log_file_config_chk, \
|
||||
log_file_config_proc, \
|
||||
log_file_config_get, \
|
||||
log_file_config_getall \
|
||||
},\
|
||||
{\
|
||||
LOG_CONFIG_REMOTE_GET_HOST, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
log_remote_host_x_config_chk, \
|
||||
NULL, \
|
||||
NULL \
|
||||
log_remote_host_x_config_get, \
|
||||
log_remote_host_x_config_getall \
|
||||
},\
|
||||
{\
|
||||
NAT4_CONFIG, \
|
||||
|
@ -237,5 +258,15 @@ struct _config_service {
|
|||
|
||||
typedef struct _config_service config_service_t;
|
||||
|
||||
struct _config_result {
|
||||
char resultCode[RET_CODE_LEN];
|
||||
char *message;
|
||||
char *data;
|
||||
};
|
||||
|
||||
typedef struct _config_result config_result_t;
|
||||
|
||||
int cm_format_data(ret_code ret_code, cJSON *json_obj, char *output);
|
||||
|
||||
#endif /* RPC_COMMON_H_ */
|
||||
|
||||
|
|
|
@ -40,5 +40,32 @@ ret_code log_file_config_chk(uint source, uint *config_type,
|
|||
ret_code log_file_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
ret_code log_file_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_file_config_getall(uint source,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_remote_level_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_remote_level_config_getall(uint source,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_console_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_console_config_getall(uint source,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_monitor_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_monitor_config_getall(uint source,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_remote_host_x_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_remote_host_x_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_remote_host_x_config_getall(uint source,
|
||||
pointer output, int *output_len);
|
||||
#endif
|
|
@ -1,7 +1,11 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include "log_config_cm.h"
|
||||
#include "rpc_server.h"
|
||||
#include "rpc_client.h"
|
||||
|
||||
int access(const char *pathname, int mode);
|
||||
|
||||
ret_code log_rpc_exec(char* service_name, char* method_name, pointer input, int input_len, int last_lenth)
|
||||
{
|
||||
if ((input == NULL)
|
||||
|
@ -20,3 +24,220 @@ ret_code log_rpc_exec(char* service_name, char* method_name, pointer input, int
|
|||
}
|
||||
|
||||
|
||||
/* 仅适用于以“key=value”方式保存的配置解析,适用于log-sched.conf的解析 */
|
||||
ret_code cm_log_get_keyvalue_from_file(const char *file_str, const char *key_str, char *value_str, int value_len)
|
||||
{
|
||||
ret_code ret = RET_ERR;
|
||||
FILE *fp = NULL;
|
||||
char *pos = NULL;
|
||||
|
||||
if (NULL == file_str || '\0' == file_str[0] || NULL == key_str || (NULL == value_str && value_len>0))
|
||||
{
|
||||
ULOG_ERR(g_log_h, "get log key-value from file: bad input");
|
||||
return ret;
|
||||
}
|
||||
|
||||
fp = fopen(file_str, "r");
|
||||
if (NULL == fp) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (fseek(fp, 0, SEEK_SET) == -1)
|
||||
{
|
||||
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
|
||||
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t n;
|
||||
char *line = NULL;
|
||||
while ((getline(&line, &n, fp)) != -1)
|
||||
{
|
||||
pos = strstr(line, key_str);
|
||||
if (pos != NULL)
|
||||
{
|
||||
/* 跳过key与value间的"=" */
|
||||
strcpy(value_str, pos+strlen(key_str)+1);
|
||||
|
||||
/* 滤除掉段尾的回车换行 */
|
||||
if ('\n' == value_str[strlen(value_str)-1])
|
||||
{
|
||||
value_str[strlen(value_str)-1] = '\0';
|
||||
}
|
||||
|
||||
ULOG_DEBUG(g_log_h, "get config %s:%s", key_str, value_str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = RET_OK;
|
||||
if (NULL != fp)
|
||||
{
|
||||
fclose(fp);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* 检查的文件存在,本函数返回1,否则,本函数返回0 */
|
||||
int cm_log_check_file_is_exist(const char *file_str)
|
||||
{
|
||||
int is_exist = 0;
|
||||
|
||||
if (NULL == file_str || '\0' == file_str[0])
|
||||
{
|
||||
is_exist = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 如果文件存在,access返回0,不存在,access返回-1 */
|
||||
is_exist = ((access(file_str, 0) == 0) ? 1 : 0);
|
||||
}
|
||||
|
||||
return is_exist;
|
||||
}
|
||||
|
||||
|
||||
/* 适用于log-console.conf与log-pty.conf的解析 */
|
||||
ret_code cm_log_get_module_from_file(const char *file_str, char *value_str, int value_len)
|
||||
{
|
||||
ret_code ret = RET_ERR;
|
||||
FILE *fp = NULL;
|
||||
char *pos = NULL;
|
||||
char *pos2 = NULL;
|
||||
size_t tmp_len = 0;
|
||||
|
||||
if (NULL == file_str || '\0' == file_str[0] || (NULL == value_str && value_len>0))
|
||||
{
|
||||
ULOG_ERR(g_log_h, "get log module from file: bad input");
|
||||
return ret;
|
||||
}
|
||||
|
||||
fp = fopen(file_str, "r");
|
||||
if (NULL == fp)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (fseek(fp, 0, SEEK_SET) == -1)
|
||||
{
|
||||
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
|
||||
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t n;
|
||||
char *line = NULL;
|
||||
while ((getline(&line, &n, fp)) != -1)
|
||||
{
|
||||
pos = strstr(line, "\"[");
|
||||
pos2 = strstr(line, "]\"");
|
||||
|
||||
tmp_len = pos2-pos-strlen("\"[");
|
||||
if (pos != NULL && pos2 != NULL && tmp_len < value_len)
|
||||
{
|
||||
strncpy(value_str, pos+strlen("\"["), tmp_len);
|
||||
value_str[tmp_len] = '\0';
|
||||
|
||||
ULOG_DEBUG(g_log_h, "get module: %s", value_str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = RET_OK;
|
||||
if (NULL != fp)
|
||||
{
|
||||
fclose(fp);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* 适用于log-console.conf与log-pty.conf的解析 */
|
||||
ret_code cm_log_get_level_from_file(const char *file_str, u8 *value)
|
||||
{
|
||||
ret_code ret = RET_ERR;
|
||||
FILE *fp = NULL;
|
||||
ssize_t n;
|
||||
char *line = NULL;
|
||||
char *sub_line = NULL;
|
||||
char *pos = NULL;
|
||||
char *pos2 = NULL;
|
||||
size_t tmp_len = 0;
|
||||
char tmp_str[128] = "";
|
||||
int tmp_value;
|
||||
|
||||
if (NULL == file_str || '\0' == file_str[0] || NULL == value)
|
||||
{
|
||||
ULOG_ERR(g_log_h, "get log level from file: bad input");
|
||||
}
|
||||
|
||||
fp = fopen(file_str, "r");
|
||||
if (NULL == fp)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (fseek(fp, 0, SEEK_SET) == -1)
|
||||
{
|
||||
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
|
||||
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
while ((getline(&line, &n, fp)) != -1)
|
||||
{
|
||||
pos = line;
|
||||
|
||||
if (NULL == strstr(pos, ".="))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
sub_line = strstr(pos, ".=");
|
||||
|
||||
if (NULL == sub_line)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (strlen(sub_line) <= strlen(".="))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
pos = sub_line+strlen(".=");
|
||||
}
|
||||
pos2 = strstr(pos, " ");
|
||||
|
||||
if (pos != NULL && pos2 != NULL)
|
||||
{
|
||||
tmp_len = pos2-pos;
|
||||
strncpy(tmp_str, pos, tmp_len);
|
||||
tmp_str[tmp_len] = '\0';
|
||||
|
||||
tmp_value = log_str_to_level(tmp_str);
|
||||
if( -1 == tmp_value)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
*value = (u8)tmp_value;
|
||||
|
||||
ULOG_DEBUG(g_log_h, "get level: %u", *value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = RET_OK;
|
||||
if (NULL != fp)
|
||||
{
|
||||
fclose(fp);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,5 +52,31 @@ extern rpc_client *g_log_client;
|
|||
extern ulog_t *g_log_h;
|
||||
|
||||
ret_code log_rpc_exec(char* service_name, char* method_name, pointer input, int input_len, int last_lenth);
|
||||
ret_code cm_log_get_keyvalue_from_file(const char *file_str, const char *key_str, char *value_str, int value_len);
|
||||
|
||||
int cm_log_check_file_is_exist(const char *file_str);
|
||||
ret_code cm_log_get_module_from_file(const char *file_str, char *value_str, int value_len);
|
||||
ret_code cm_log_get_level_from_file(const char *file_str, u8 *value);
|
||||
|
||||
|
||||
#ifndef CM_LOG_CONF_CONSOLE_FILE
|
||||
#define CM_LOG_CONF_CONSOLE_FILE "/etc/rsyslog.d/log-console.conf"
|
||||
#endif
|
||||
|
||||
#ifndef CM_LOG_CONF_PTY_FILE
|
||||
#define CM_LOG_CONF_PTY_FILE "/etc/rsyslog.d/log-pty.conf"
|
||||
#endif
|
||||
|
||||
#ifndef CM_LOG_CONF_REMOTE_FILE
|
||||
#define CM_LOG_CONF_REMOTE_FILE "/etc/rsyslog.d/log-remote.conf"
|
||||
#endif
|
||||
|
||||
#ifndef CM_LOG_CONF_REMOTE_LEVEL_FILE
|
||||
#define CM_LOG_CONF_REMOTE_LEVEL_FILE "/etc/log-sched.conf"
|
||||
#endif
|
||||
|
||||
#ifndef CM_LOG_CONF_LOGFILE_FILE
|
||||
#define CM_LOG_CONF_LOGFILE_FILE "/etc/log-sched.conf"
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,5 +1,7 @@
|
|||
#include "log_config.h"
|
||||
#include "log_config_cm.h"
|
||||
#include "rpc.h"
|
||||
|
||||
|
||||
ret_code log_console_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
|
@ -14,3 +16,105 @@ ret_code log_console_config_proc(uint source, uint config_type,
|
|||
{
|
||||
return log_rpc_exec(SERIVCE_LOG_CONSOLE_NAME, CONF_LOG_CONSOLE_FUNC, input, input_len, sizeof(log_console_t));
|
||||
}
|
||||
|
||||
static ret_code cm_get_log_console_elems(log_console_t *log_console_conf, int *err_no)
|
||||
{
|
||||
char tmp_module[MAX_MODULE_NAME_SZ] = "";
|
||||
u8 tmp_level = 0;
|
||||
|
||||
if (NULL == log_console_conf || NULL == err_no)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
memset(log_console_conf, 0, sizeof(*log_console_conf));
|
||||
|
||||
if (cm_log_check_file_is_exist(CM_LOG_CONF_CONSOLE_FILE) != 1)
|
||||
{
|
||||
log_console_conf->on = LOG_OFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_console_conf->on = LOG_ON;
|
||||
|
||||
memset(tmp_module, 0, MAX_MODULE_NAME_SZ);
|
||||
if (cm_log_get_module_from_file(CM_LOG_CONF_CONSOLE_FILE, tmp_module, MAX_MODULE_NAME_SZ) == 0)
|
||||
{
|
||||
strncpy(log_console_conf->module, tmp_module, MAX_MODULE_NAME_SZ);
|
||||
}
|
||||
|
||||
if (cm_log_get_level_from_file(CM_LOG_CONF_CONSOLE_FILE, &tmp_level) == 0)
|
||||
{
|
||||
log_console_conf->level = tmp_level;
|
||||
}
|
||||
}
|
||||
|
||||
ULOG_DEBUG(g_log_h, "get log console :level=%u, is_on=%s, module=%s",
|
||||
log_console_conf->level,
|
||||
log_console_conf->on==LOG_ON?"on":"off",
|
||||
log_console_conf->module);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
static ret_code cm_log_console_format_json(log_console_t *log_console_conf,
|
||||
pointer output, int *outlen)
|
||||
{
|
||||
char *json_log_file = NULL;
|
||||
|
||||
/* create Student JSON object */
|
||||
s2j_create_json_obj(json_obj);
|
||||
if (json_obj == NULL)
|
||||
{
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
s2j_json_set_basic_element(json_obj, log_console_conf, int, level);
|
||||
s2j_json_set_basic_element(json_obj, log_console_conf, int, on);
|
||||
s2j_json_set_basic_element(json_obj, log_console_conf, string, module);
|
||||
|
||||
json_log_file = cJSON_PrintUnformatted(json_obj);
|
||||
*outlen = strlen(json_log_file) + 1;
|
||||
memcpy(output, json_log_file, *outlen);
|
||||
|
||||
free(json_log_file);
|
||||
cJSON_Delete(json_obj);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_code log_console_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
log_console_t *log_console_conf = NULL;
|
||||
int err_no = 0;
|
||||
|
||||
log_console_conf = (log_console_t *)input;
|
||||
|
||||
ret = cm_get_log_console_elems(log_console_conf, &err_no);
|
||||
|
||||
RET_ERR_FORMART(ret, err_no, output, *output_len);
|
||||
ASSERT_RET(ret);
|
||||
|
||||
cm_log_console_format_json(log_console_conf, output, output_len);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ret_code log_console_config_getall(uint source,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
log_console_t *log_console_conf = NULL;
|
||||
int err_no = 0;
|
||||
|
||||
log_console_conf = rpc_new(log_console_t, 1);
|
||||
ret = log_console_config_get(source, (pointer)log_console_conf, sizeof(log_console_t)*1, output, output_len);
|
||||
rpc_free(log_console_conf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "log_config.h"
|
||||
#include "log_config_cm.h"
|
||||
#include "rpc.h"
|
||||
|
||||
#define FILE_JSON(s, o) { \
|
||||
s2j_struct_get_basic_element(s, o, int, level); \
|
||||
|
@ -9,6 +10,8 @@
|
|||
S2J_STRUCT_GET_STRING_ELEMENT_N(s, o, del_over_size, MAX_U64_SZ); \
|
||||
}
|
||||
|
||||
#define LOG_CONF_KEY_FILE_MAX_SIZE_STR "file.max_size"
|
||||
|
||||
ret_code log_file_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len)
|
||||
|
@ -24,3 +27,94 @@ ret_code log_file_config_proc(uint source, uint config_type,
|
|||
}
|
||||
|
||||
|
||||
static ret_code cm_get_log_file_elems(log_file_t *log_file_conf, int *err_no)
|
||||
{
|
||||
char value[MAX_LINE_SZ] = "";
|
||||
|
||||
if (NULL == log_file_conf || NULL == err_no)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
memset(log_file_conf, 0, sizeof(*log_file_conf));
|
||||
|
||||
/* level、path、is_compress、del_over_days暂未实现 */
|
||||
|
||||
/* 日志文件大小上限:del_over_size */
|
||||
memset(value, 0, MAX_LINE_SZ);
|
||||
if (cm_log_get_keyvalue_from_file(CM_LOG_CONF_LOGFILE_FILE, LOG_CONF_KEY_FILE_MAX_SIZE_STR, value, sizeof(value)) == 0)
|
||||
{
|
||||
if (strlen(value) < MAX_U64_SZ)
|
||||
{
|
||||
memset(log_file_conf->del_over_size, 0, MAX_U64_SZ);
|
||||
strncpy(log_file_conf->del_over_size, value, strlen(value));
|
||||
}
|
||||
}
|
||||
|
||||
ULOG_DEBUG(g_log_h, "get log file del_over_size:%s", log_file_conf->del_over_size);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_code cm_log_file_format_json(log_file_t *log_file_conf,
|
||||
pointer output, int *outlen)
|
||||
{
|
||||
char *json_log_file = NULL;
|
||||
|
||||
/* create Student JSON object */
|
||||
s2j_create_json_obj(json_obj);
|
||||
if (json_obj == NULL)
|
||||
{
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
s2j_json_set_basic_element(json_obj, log_file_conf, int, level);
|
||||
s2j_json_set_basic_element(json_obj, log_file_conf, string, path);
|
||||
s2j_json_set_basic_element(json_obj, log_file_conf, int, is_compress);
|
||||
s2j_json_set_basic_element(json_obj, log_file_conf, int, del_over_days);
|
||||
s2j_json_set_basic_element(json_obj, log_file_conf, string, del_over_size);
|
||||
|
||||
json_log_file = cJSON_PrintUnformatted(json_obj);
|
||||
*outlen = strlen(json_log_file) + 1;
|
||||
memcpy(output, json_log_file, *outlen);
|
||||
|
||||
free(json_log_file);
|
||||
cJSON_Delete(json_obj);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
ret_code log_file_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
log_file_t *log_file_conf = NULL;
|
||||
int err_no = 0;
|
||||
|
||||
log_file_conf = (log_file_t *)input;
|
||||
|
||||
ret = cm_get_log_file_elems(log_file_conf, &err_no);
|
||||
|
||||
RET_ERR_FORMART(ret, err_no, output, *output_len);
|
||||
ASSERT_RET(ret);
|
||||
|
||||
cm_log_file_format_json(log_file_conf, output, output_len);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ret_code log_file_config_getall(uint source,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
log_file_t *log_file_conf = NULL;
|
||||
int err_no = 0;
|
||||
|
||||
log_file_conf = rpc_new(log_file_t, 1);
|
||||
ret = log_file_config_get(source, (pointer)log_file_conf, sizeof(log_file_t)*1, output, output_len);
|
||||
rpc_free(log_file_conf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "log_config.h"
|
||||
#include "log_config_cm.h"
|
||||
#include "rpc.h"
|
||||
|
||||
ret_code log_monitor_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
|
@ -15,3 +16,105 @@ ret_code log_monitor_config_proc(uint source, uint config_type,
|
|||
return log_rpc_exec(SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, input, input_len, sizeof(log_console_t));
|
||||
}
|
||||
|
||||
|
||||
static ret_code cm_get_log_monitor_elems(log_console_t *log_console_conf, int *err_no)
|
||||
{
|
||||
char tmp_module[MAX_MODULE_NAME_SZ] = "";
|
||||
u8 tmp_level = 0;
|
||||
|
||||
if (NULL == log_console_conf || NULL == err_no)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
memset(log_console_conf, 0, sizeof(*log_console_conf));
|
||||
|
||||
if (cm_log_check_file_is_exist(CM_LOG_CONF_PTY_FILE) != 1)
|
||||
{
|
||||
log_console_conf->on = LOG_OFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_console_conf->on = LOG_ON;
|
||||
|
||||
memset(tmp_module, 0, MAX_MODULE_NAME_SZ);
|
||||
if (cm_log_get_module_from_file(CM_LOG_CONF_PTY_FILE, tmp_module, MAX_MODULE_NAME_SZ) == 0)
|
||||
{
|
||||
strncpy(log_console_conf->module, tmp_module, MAX_MODULE_NAME_SZ);
|
||||
}
|
||||
|
||||
if (cm_log_get_level_from_file(CM_LOG_CONF_PTY_FILE, &tmp_level) == 0)
|
||||
{
|
||||
log_console_conf->level = tmp_level;
|
||||
}
|
||||
}
|
||||
|
||||
ULOG_DEBUG(g_log_h, "get log monitor :level=%u, is_on=%s, module=%s",
|
||||
log_console_conf->level,
|
||||
log_console_conf->on==LOG_ON?"on":"off",
|
||||
log_console_conf->module);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
static ret_code cm_log_monitor_format_json(log_console_t *log_console_conf,
|
||||
pointer output, int *outlen)
|
||||
{
|
||||
char *json_log_file = NULL;
|
||||
|
||||
/* create Student JSON object */
|
||||
s2j_create_json_obj(json_obj);
|
||||
if (json_obj == NULL)
|
||||
{
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
s2j_json_set_basic_element(json_obj, log_console_conf, int, level);
|
||||
s2j_json_set_basic_element(json_obj, log_console_conf, int, on);
|
||||
s2j_json_set_basic_element(json_obj, log_console_conf, string, module);
|
||||
|
||||
json_log_file = cJSON_PrintUnformatted(json_obj);
|
||||
*outlen = strlen(json_log_file) + 1;
|
||||
memcpy(output, json_log_file, *outlen);
|
||||
|
||||
free(json_log_file);
|
||||
cJSON_Delete(json_obj);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_code log_monitor_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
log_console_t *log_console_conf = NULL;
|
||||
int err_no = 0;
|
||||
|
||||
log_console_conf = (log_console_t *)input;
|
||||
|
||||
ret = cm_get_log_monitor_elems(log_console_conf, &err_no);
|
||||
|
||||
RET_ERR_FORMART(ret, err_no, output, *output_len);
|
||||
ASSERT_RET(ret);
|
||||
|
||||
cm_log_monitor_format_json(log_console_conf, output, output_len);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ret_code log_monitor_config_getall(uint source,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
log_console_t *log_console_conf = NULL;
|
||||
int err_no = 0;
|
||||
|
||||
log_console_conf = rpc_new(log_console_t, 1);
|
||||
ret = log_monitor_config_get(source, (pointer)log_console_conf, sizeof(log_console_t)*1, output, output_len);
|
||||
rpc_free(log_console_conf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include "log_config.h"
|
||||
#include "log_config_cm.h"
|
||||
#include "rpc.h"
|
||||
|
||||
#define MAX_REMOTE_HOST_CNT 8
|
||||
|
||||
#define REMOTE_HOST_JSON(s, o) { \
|
||||
s2j_struct_get_basic_element(s, o, int, rfc); \
|
||||
|
@ -11,6 +16,15 @@
|
|||
s2j_struct_get_basic_element(s, o, int, level); \
|
||||
}
|
||||
|
||||
#define REMOTE_HOST_X_JSON(s, o) { \
|
||||
s2j_struct_get_basic_element(s, o, int, rfc); \
|
||||
s2j_struct_get_basic_element(s, o, int, port); \
|
||||
S2J_STRUCT_GET_STRING_ELEMENT_N(s, o, host, LOG_HOST_SZ); \
|
||||
s2j_struct_get_basic_element(s, o, int, level); \
|
||||
}
|
||||
|
||||
|
||||
#define LOG_CONF_KEY_REMOTE_LEVEL "remote.level"
|
||||
|
||||
|
||||
ret_code log_remote_host_config_chk(uint source, uint *config_type,
|
||||
|
@ -48,4 +62,554 @@ ret_code log_remote_level_config_proc(uint source, uint config_type,
|
|||
return log_rpc_exec(SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_LEVEL_FUNC, input, input_len, sizeof(log_remote_level_t));
|
||||
}
|
||||
|
||||
static ret_code cm_get_log_remote_level_elems(log_remote_level_t *log_remote_level, int *err_no)
|
||||
{
|
||||
char value[MAX_LINE_SZ] = "";
|
||||
int tmp_value = 0;
|
||||
|
||||
if (NULL == log_remote_level || NULL == err_no)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
memset(log_remote_level, 0, sizeof(*log_remote_level));
|
||||
|
||||
memset(value, 0, MAX_LINE_SZ);
|
||||
|
||||
if (cm_log_get_keyvalue_from_file(CM_LOG_CONF_REMOTE_LEVEL_FILE, LOG_CONF_KEY_REMOTE_LEVEL, value, sizeof(value)) == 0)
|
||||
{
|
||||
tmp_value = atoi(value);
|
||||
log_remote_level->level = (u8)tmp_value;
|
||||
}
|
||||
|
||||
ULOG_DEBUG(g_log_h, "get log remote level:%u", log_remote_level->level);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
static ret_code cm_log_remote_level_format_json(log_remote_level_t *log_remote_level,
|
||||
pointer output, int *outlen)
|
||||
{
|
||||
char *json_log_file = NULL;
|
||||
|
||||
/* create Student JSON object */
|
||||
s2j_create_json_obj(json_obj);
|
||||
if (json_obj == NULL)
|
||||
{
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
s2j_json_set_basic_element(json_obj, log_remote_level, int, level);
|
||||
|
||||
json_log_file = cJSON_PrintUnformatted(json_obj);
|
||||
*outlen = strlen(json_log_file) + 1;
|
||||
memcpy(output, json_log_file, *outlen);
|
||||
|
||||
free(json_log_file);
|
||||
cJSON_Delete(json_obj);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_code log_remote_level_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
log_remote_level_t *log_remote_level = NULL;
|
||||
int err_no = 0;
|
||||
|
||||
log_remote_level = (log_remote_level_t *)input;
|
||||
|
||||
ret = cm_get_log_remote_level_elems(log_remote_level, &err_no);
|
||||
|
||||
RET_ERR_FORMART(ret, err_no, output, *output_len);
|
||||
ASSERT_RET(ret);
|
||||
|
||||
cm_log_remote_level_format_json(log_remote_level, output, output_len);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ret_code log_remote_level_config_getall(uint source,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
log_remote_level_t *log_remote_level = NULL;
|
||||
int err_no = 0;
|
||||
|
||||
log_remote_level = rpc_new(log_remote_level_t, 1);
|
||||
ret = log_remote_level_config_get(source, (pointer)log_remote_level, sizeof(log_remote_level_t)*1, output, output_len);
|
||||
rpc_free(log_remote_level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* *.=emerg;*.=alert;*.=crit;*.=err;*.=warn;*.=notice;*.=info @1.1.1.1:514:RFC3164fmt
|
||||
* *.=emerg;*.=alert;*.=crit;*.=err;*.=warn;*.=notice;*.=info @@1.1.1.2:514:RFC5424fmt */
|
||||
static ret_code cm_log_prase_host_from_str(char *const input_str, log_remote_host_x_t *ret_host)
|
||||
{
|
||||
char *pos = NULL;
|
||||
char *pos2 = NULL;
|
||||
size_t tmp_len = 0;
|
||||
char tmp_str[128] = "";
|
||||
int tmp_value;
|
||||
int is_find = 0;
|
||||
ret_code ret = RET_ERR;
|
||||
|
||||
if(NULL == input_str || '\0' == input_str[0] || NULL == ret_host)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
pos = input_str;
|
||||
|
||||
memset(tmp_str, 0, sizeof(tmp_str));
|
||||
|
||||
/* 提取日志等级 */
|
||||
while (1)
|
||||
{
|
||||
pos2 = strstr(pos, ".=");
|
||||
|
||||
if (NULL == pos2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (strlen(pos2) <= strlen(".="))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
pos = pos2+strlen(".=");
|
||||
}
|
||||
|
||||
pos2 = strstr(pos, " ");
|
||||
|
||||
if (NULL == pos || NULL == pos2)
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
|
||||
tmp_len = pos2-pos;
|
||||
strncpy(tmp_str, pos, tmp_len);
|
||||
tmp_str[tmp_len] = '\0';
|
||||
|
||||
tmp_value = log_str_to_level(tmp_str);
|
||||
if ( -1 == tmp_value)
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
ret_host->level = (u8)tmp_value;
|
||||
|
||||
/* 提取IP地址 */
|
||||
pos = strstr(pos2, "@");
|
||||
if (NULL == pos)
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
pos ++;
|
||||
|
||||
if('@' == pos[0])
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
|
||||
pos2 = strstr(pos, ":");
|
||||
if (NULL == pos2)
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
|
||||
tmp_len = pos2-pos;
|
||||
if (tmp_len == 0 || tmp_len >= sizeof(ret_host->host))
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
memset(ret_host->host, 0, sizeof(ret_host->host));
|
||||
strncpy(ret_host->host, pos, tmp_len);
|
||||
|
||||
|
||||
/* 提取端口 */
|
||||
pos2 ++;
|
||||
pos = pos2;
|
||||
pos2 = strstr(pos, ":");
|
||||
if (pos2 == NULL)
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
|
||||
tmp_len = pos2-pos;
|
||||
strncpy(tmp_str, pos, tmp_len);
|
||||
tmp_str[tmp_len] = '\0';
|
||||
|
||||
tmp_value = atoi(tmp_str);
|
||||
if (tmp_value < 0)
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
ret_host->port = (u16)tmp_value;
|
||||
|
||||
/* 提取日志存放格式 */
|
||||
pos2++;
|
||||
pos = pos2;
|
||||
|
||||
pos2 = strstr(pos, " ");
|
||||
if (pos2 != NULL)
|
||||
{
|
||||
tmp_len = pos2-pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_len = strlen(pos);
|
||||
}
|
||||
strncpy(tmp_str, pos, tmp_len);
|
||||
tmp_str[tmp_len] = '\0';
|
||||
if ('\n' == tmp_str[tmp_len-1])
|
||||
{
|
||||
tmp_str[tmp_len-1] = '\0';
|
||||
}
|
||||
|
||||
tmp_value = -1;
|
||||
for (int i = 0; i < (sizeof(rfc_tbl) / sizeof(rfc_key_fmt)); i++)
|
||||
{
|
||||
if (strcasecmp(tmp_str, rfc_tbl[i].fmt) == 0)
|
||||
{
|
||||
tmp_value = rfc_tbl[i].rfc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 == tmp_value)
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
ret_host->rfc = tmp_value;
|
||||
|
||||
// ULOG_DEBUG(g_log_h, "get remote host, addr:%s, port:%u, log_format:%d, level:%u",
|
||||
// ret_host->host, ret_host->port, ret_host->rfc, ret_host->level);
|
||||
|
||||
is_find = 1;
|
||||
|
||||
END:
|
||||
|
||||
if (is_find != 1)
|
||||
{
|
||||
memset(ret_host, 0, sizeof(*ret_host));
|
||||
}
|
||||
|
||||
ret = RET_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ret_code cm_log_get_host_from_file_by_addr(const char *file_str, const char *addr_str, log_remote_host_x_t *ret_host)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
ssize_t n;
|
||||
char *line = NULL;
|
||||
char tmp_str[128] = "";
|
||||
int is_find = 0;
|
||||
ret_code ret = RET_ERR;
|
||||
|
||||
if (NULL == file_str || '\0' == file_str[0]
|
||||
|| NULL == addr_str || strlen(addr_str) >= LOG_HOST_SZ
|
||||
|| NULL == ret_host) {
|
||||
ULOG_ERR(g_log_h, "get log host from file: bad input");
|
||||
}
|
||||
|
||||
memset(ret_host, 0, sizeof(*ret_host));
|
||||
memcpy(ret_host->host, addr_str, strlen(addr_str));
|
||||
|
||||
fp = fopen(file_str, "r");
|
||||
if (NULL == fp) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (fseek(fp, 0, SEEK_SET) == -1)
|
||||
{
|
||||
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
|
||||
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
while ((getline(&line, &n, fp)) != -1)
|
||||
{
|
||||
memset(tmp_str, 0, sizeof(tmp_str));
|
||||
sprintf(tmp_str, "@%s:", addr_str);
|
||||
if (NULL == strstr(line, tmp_str))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( cm_log_prase_host_from_str(line, ret_host) == RET_OK )
|
||||
{
|
||||
is_find = 1;
|
||||
}
|
||||
|
||||
ULOG_DEBUG(g_log_h, "get remote host: addr=%s, port=%u, log_format=%d, level=%u",
|
||||
ret_host->host, ret_host->port, ret_host->rfc, ret_host->level);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (is_find != 1)
|
||||
{
|
||||
memset(ret_host, 0, sizeof(*ret_host));
|
||||
}
|
||||
|
||||
ret = RET_OK;
|
||||
if (NULL != fp)
|
||||
{
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static ret_code cm_log_getall_host_from_file(const char *file_str, log_remote_host_x_t *ret_hosts, int *ret_cnt)
|
||||
{
|
||||
log_remote_host_x_t hosts[MAX_REMOTE_HOST_CNT];
|
||||
FILE *fp = NULL;
|
||||
ssize_t n;
|
||||
char *line = NULL;
|
||||
size_t tmp_len = 0;
|
||||
char tmp_str[128] = "";
|
||||
int tmp_value;
|
||||
int cnt = 0;
|
||||
ret_code ret = RET_ERR;
|
||||
|
||||
if (NULL == file_str || '\0' == file_str[0]
|
||||
|| NULL == ret_hosts || NULL == ret_cnt)
|
||||
{
|
||||
ULOG_ERR(g_log_h, "get all log host from file: bad input");
|
||||
}
|
||||
|
||||
fp = fopen(file_str, "r");
|
||||
if (NULL == fp)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (fseek(fp, 0, SEEK_SET) == -1)
|
||||
{
|
||||
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
|
||||
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
cnt = 0;
|
||||
while ((getline(&line, &n, fp)) != -1)
|
||||
{
|
||||
if (NULL == strstr(line, "@"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( cm_log_prase_host_from_str(line, hosts+cnt) != RET_OK )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hosts[cnt].host[0] == '\0')
|
||||
{
|
||||
/* 无效数据 */
|
||||
memset(hosts+cnt, 0, sizeof(log_remote_host_x_t));
|
||||
continue;
|
||||
}
|
||||
|
||||
ULOG_DEBUG(g_log_h, "getall remote host, host[%d]: addr=%s, port=%u, log_format=%d, level=%u",
|
||||
cnt, hosts[cnt].host, hosts[cnt].port, hosts[cnt].rfc, hosts[cnt].level);
|
||||
|
||||
cnt ++;
|
||||
if (cnt >= MAX_REMOTE_HOST_CNT)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (cnt > 0)
|
||||
{
|
||||
memcpy(ret_hosts, &hosts, sizeof(log_remote_host_x_t)*cnt);
|
||||
}
|
||||
|
||||
*ret_cnt = cnt;
|
||||
|
||||
ret = RET_OK;
|
||||
if (NULL != fp)
|
||||
{
|
||||
fclose(fp);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static ret_code cm_get_log_remote_host_elems(log_remote_host_x_t *host_x, int *err_no)
|
||||
{
|
||||
log_remote_host_x_t input_host;
|
||||
log_remote_host_x_t output_host;
|
||||
ret_code ret = RET_ERR;
|
||||
|
||||
if (NULL == host_x || NULL == err_no)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
memcpy(&input_host, host_x, sizeof(log_remote_host_x_t));
|
||||
|
||||
memset(&output_host, 0, sizeof(output_host));
|
||||
if (cm_log_get_host_from_file_by_addr(CM_LOG_CONF_REMOTE_FILE, input_host.host, &output_host) == RET_OK)
|
||||
{
|
||||
memcpy(host_x, &output_host, sizeof(output_host));
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static ret_code cm_getall_log_remote_host_elems(log_remote_host_x_t *host_xs, int *cnt, int *err_no)
|
||||
{
|
||||
ret_code ret = RET_ERR;
|
||||
|
||||
if (NULL == host_xs || NULL == err_no)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
if (cm_log_getall_host_from_file(CM_LOG_CONF_REMOTE_FILE, host_xs, cnt) != RET_OK)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_code cm_log_remote_host_x_format_json(log_remote_host_x_t *host_x,
|
||||
pointer output, int *outlen)
|
||||
{
|
||||
char *json_log_file = NULL;
|
||||
|
||||
/* create Student JSON object */
|
||||
s2j_create_json_obj(json_obj);
|
||||
if (json_obj == NULL)
|
||||
{
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
s2j_json_set_basic_element(json_obj, host_x, int, port);
|
||||
s2j_json_set_basic_element(json_obj, host_x, int, rfc);
|
||||
s2j_json_set_basic_element(json_obj, host_x, string, host);
|
||||
s2j_json_set_basic_element(json_obj, host_x, int, level);
|
||||
|
||||
json_log_file = cJSON_PrintUnformatted(json_obj);
|
||||
*outlen = strlen(json_log_file) + 1;
|
||||
memcpy(output, json_log_file, *outlen);
|
||||
|
||||
free(json_log_file);
|
||||
cJSON_Delete(json_obj);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
ret_code cm_log_remote_host_x_format_json_array(log_remote_host_x_t *host_xs,
|
||||
int count, pointer output, int *outlen)
|
||||
{
|
||||
log_remote_host_x_t tem_buff = {0};
|
||||
log_remote_host_x_t *host_x = &tem_buff;
|
||||
cJSON *json_array = NULL;
|
||||
char *json_str;
|
||||
int i;
|
||||
|
||||
json_array = cJSON_CreateArray();
|
||||
if(json_array == NULL)
|
||||
{
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
memcpy(host_x, &host_xs[i], sizeof(log_remote_host_x_t));
|
||||
|
||||
/* create Student JSON object */
|
||||
s2j_create_json_obj(json_obj);
|
||||
if(json_obj == NULL)
|
||||
{
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
cJSON_AddItemToArray(json_array, json_obj);
|
||||
|
||||
s2j_json_set_basic_element(json_obj, host_x, int, port);
|
||||
s2j_json_set_basic_element(json_obj, host_x, int, rfc);
|
||||
s2j_json_set_basic_element(json_obj, host_x, string, host);
|
||||
s2j_json_set_basic_element(json_obj, host_x, int, level);
|
||||
}
|
||||
|
||||
json_str = cJSON_PrintUnformatted(json_array);
|
||||
*outlen = strlen(json_str) + 1;
|
||||
memcpy(output, json_str, *outlen);
|
||||
|
||||
free(json_str);
|
||||
cJSON_Delete(json_array);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_code log_remote_host_x_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
COMMON_CHK(log_remote_host_x_t, input, input_len, "remote host_x", REMOTE_HOST_X_JSON);
|
||||
}
|
||||
|
||||
|
||||
ret_code log_remote_host_x_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
log_remote_host_x_t *host_x = NULL;
|
||||
int err_no = 0;
|
||||
|
||||
host_x = (log_remote_host_x_t *)input;
|
||||
|
||||
ret = cm_get_log_remote_host_elems(host_x, &err_no);
|
||||
|
||||
RET_ERR_FORMART(ret, err_no, output, *output_len);
|
||||
ASSERT_RET(ret);
|
||||
|
||||
cm_log_remote_host_x_format_json(host_x, output, output_len);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ret_code log_remote_host_x_config_getall(uint source,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
log_remote_host_x_t *host_x = NULL;
|
||||
int cnt = 0;
|
||||
int err_no = 0;
|
||||
|
||||
host_x = rpc_new(log_remote_host_x_t, MAX_REMOTE_HOST_CNT);
|
||||
|
||||
ret = cm_getall_log_remote_host_elems(host_x, &cnt, &err_no);
|
||||
|
||||
RET_ERR_FORMART(ret, err_no, output, *output_len);
|
||||
ASSERT_RET(ret);
|
||||
|
||||
cm_log_remote_host_x_format_json_array(host_x, cnt, output, output_len);
|
||||
ULOG_DEBUG(g_log_h, "log_remote_host_x_config_getall, output=%s, output_len=%d",
|
||||
output, *output_len);
|
||||
|
||||
rpc_free(host_x);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -83,9 +83,9 @@ ret_code ip_config_json_parse(pointer input, uint *conf_type, ip_config_t *confi
|
|||
}
|
||||
|
||||
s2j_struct_get_basic_element(ip_config, json_obj, int, config_type);
|
||||
S2J_STRUCT_GET_STRING_ELEMENT_N(ip_config, json_obj, ifname, INTERFACE_NAMSIZ);
|
||||
s2j_struct_get_string_element(ip_config, json_obj, ifname, INTERFACE_NAMSIZ);
|
||||
s2j_struct_get_basic_element(ip_config, json_obj, int, family);
|
||||
S2J_STRUCT_GET_STRING_ELEMENT_N(ip_config, json_obj, ipaddr, DOT_IP_STR);
|
||||
s2j_struct_get_string_element(ip_config, json_obj, ipaddr, DOT_IP_STR);
|
||||
s2j_struct_get_basic_element(ip_config, json_obj, int, prefixlen);
|
||||
|
||||
strncpy(config_buff->ifname, ip_config->ifname, INTERFACE_NAMSIZ - 1);
|
||||
|
@ -121,7 +121,7 @@ ret_code ip_config_json_parse_array(pointer input, uint *conf_type,
|
|||
|
||||
rpc_log_info("json input:%s \n", cJSON_Print(json_obj));
|
||||
|
||||
iCount = cJSON_GetArraySize(json_obj); /*»ñÈ¡Êý×鳤¶È*/
|
||||
iCount = cJSON_GetArraySize(json_obj);
|
||||
|
||||
config_buff = rpc_new0(ip_config_t, iCount);
|
||||
conf_type = rpc_new0(uint, iCount);
|
||||
|
@ -146,11 +146,11 @@ ret_code ip_config_json_parse_array(pointer input, uint *conf_type,
|
|||
{
|
||||
memset(ip_config, 0, sizeof(ip_config_string_t));
|
||||
|
||||
s2j_struct_get_basic_element(ip_config, json_obj, int, config_type);
|
||||
s2j_struct_get_basic_element(ip_config, json_obj, string, ifname);
|
||||
s2j_struct_get_basic_element(ip_config, json_obj, int, family);
|
||||
s2j_struct_get_basic_element(ip_config, json_obj, string, ipaddr);
|
||||
s2j_struct_get_basic_element(ip_config, json_obj, int, prefixlen);
|
||||
s2j_struct_get_basic_element(ip_config, pArrayItem, int, config_type);
|
||||
s2j_struct_get_string_element(ip_config, pArrayItem, ifname, INTERFACE_NAMSIZ);
|
||||
s2j_struct_get_basic_element(ip_config, pArrayItem, int, family);
|
||||
s2j_struct_get_string_element(ip_config, pArrayItem, ipaddr, DOT_IP_STR);
|
||||
s2j_struct_get_basic_element(ip_config, pArrayItem, int, prefixlen);
|
||||
|
||||
strncpy(config_buff[*cnt].ifname, ip_config->ifname, INTERFACE_NAMSIZ - 1);
|
||||
config_buff[*cnt].family = (uchar)ip_config->family;
|
||||
|
@ -174,7 +174,6 @@ ret_code ip_config_format_json(ip_config_t *config_buff,
|
|||
{
|
||||
ip_config_string_t tem_buff = {0};
|
||||
ip_config_string_t *ip_config = &tem_buff;
|
||||
//cJSON *json_obj = NULL;
|
||||
char *json_ip;
|
||||
|
||||
ip_config->family = AF_INET;
|
||||
|
@ -183,7 +182,6 @@ ret_code ip_config_format_json(ip_config_t *config_buff,
|
|||
strncpy(ip_config->ifname, config_buff->ifname, INTERFACE_NAMSIZ - 1);
|
||||
strncpy(ip_config->ipaddr, inet_ntoa(config_buff->prefix), DOT_IP_STR - 1);
|
||||
|
||||
/* create Student JSON object */
|
||||
s2j_create_json_obj(json_obj);
|
||||
if(json_obj == NULL)
|
||||
{
|
||||
|
@ -195,24 +193,18 @@ ret_code ip_config_format_json(ip_config_t *config_buff,
|
|||
s2j_json_set_basic_element(json_obj, ip_config, string, ipaddr);
|
||||
s2j_json_set_basic_element(json_obj, ip_config, int, prefixlen);
|
||||
|
||||
json_ip = cJSON_PrintUnformatted(json_obj);
|
||||
*outlen = strlen(json_ip) + 1;
|
||||
memcpy(output, json_ip, *outlen);
|
||||
|
||||
free(json_ip);
|
||||
cJSON_Delete(json_obj);
|
||||
*outlen = cm_format_data(RET_OK, json_obj, output);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_code ip_config_format_json_array(ip_config_t *config_buff,
|
||||
int count, pointer output, int *outlen)
|
||||
int count, pointer output,
|
||||
int *outlen)
|
||||
{
|
||||
ip_config_string_t tem_buff = {0};
|
||||
ip_config_string_t *ip_config = &tem_buff;
|
||||
cJSON *json_array = NULL;
|
||||
//cJSON *json_obj = NULL;
|
||||
char *json_ip;
|
||||
int i;
|
||||
|
||||
json_array = cJSON_CreateArray();
|
||||
|
@ -230,7 +222,6 @@ ret_code ip_config_format_json_array(ip_config_t *config_buff,
|
|||
strncpy(ip_config->ifname, config_buff[i].ifname, INTERFACE_NAMSIZ - 1);
|
||||
strncpy(ip_config->ipaddr, inet_ntoa(config_buff[i].prefix), DOT_IP_STR - 1);
|
||||
|
||||
/* create Student JSON object */
|
||||
s2j_create_json_obj(json_obj);
|
||||
if(json_obj == NULL)
|
||||
{
|
||||
|
@ -245,12 +236,9 @@ ret_code ip_config_format_json_array(ip_config_t *config_buff,
|
|||
s2j_json_set_basic_element(json_obj, ip_config, int, prefixlen);
|
||||
}
|
||||
|
||||
json_ip = cJSON_PrintUnformatted(json_array);
|
||||
*outlen = strlen(json_ip) + 1;
|
||||
memcpy(output, json_ip, *outlen);
|
||||
|
||||
free(json_ip);
|
||||
cJSON_Delete(json_array);
|
||||
*outlen = cm_format_data(RET_OK, json_array, output);
|
||||
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
|
|
@ -1824,6 +1824,7 @@ ret_code vid_value_chk(int vid)
|
|||
ret_code vid_num_chk(char *if_name, operation_type op_type, int num)
|
||||
{
|
||||
int ifnode = -1;
|
||||
int total = 0;
|
||||
if(!if_name){
|
||||
printf("[vlan]vid_num_chk: if_name is null.\n");
|
||||
return RET_NULLP;
|
||||
|
@ -1831,13 +1832,15 @@ ret_code vid_num_chk(char *if_name, operation_type op_type, int num)
|
|||
printf("[vlan]vid_num_chk: if_name=%s, op_type=%d, num=%d\n", if_name, op_type, num);
|
||||
ifnode = get_ifnode_from_global(if_name);
|
||||
if(ifnode == -1){
|
||||
printf("[vlan]vid_num_chk: get ifnode empty, return\n");
|
||||
return RET_OK;
|
||||
total = num;
|
||||
printf("[vlan]vid_num_chk: get ifnode empty, total = %d\n", total);
|
||||
}
|
||||
if(op_type == OP_ADD &&
|
||||
g_if_vlan_info[ifnode].vidcnt + num > EACH_PORT_MAX_VLAN_NUM){
|
||||
printf("[vlan]vid_num_chk: ADD operation's vid num(%d+%d=%d) > EACH_PORT_MAX_VLAN_NUM\n",
|
||||
g_if_vlan_info[ifnode].vidcnt, num, g_if_vlan_info[ifnode].vidcnt + num);
|
||||
else{
|
||||
total = g_if_vlan_info[ifnode].vidcnt + num;
|
||||
printf("[vlan]vid_num_chk: total = %d + %d = %d\n", g_if_vlan_info[ifnode].vidcnt, num, total);
|
||||
}
|
||||
if(op_type == OP_ADD && total > EACH_PORT_MAX_VLAN_NUM){
|
||||
printf("[vlan]vid_num_chk: ADD operation's total vid num > EACH_PORT_MAX_VLAN_NUM\n");
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
|
@ -2105,12 +2108,16 @@ ret_code vlan_config_get_chk(uint source, pointer input)
|
|||
printf("[vlan]vlan_config_get_chk: get json parse failed(%d).\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#if 0
|
||||
for(i = 0; i < MAX_INTERFACES; i++){
|
||||
if(interface[i] == 1){
|
||||
printf("[vlan]find a node[%d]\n", i);
|
||||
return RET_OK;
|
||||
}
|
||||
}
|
||||
return RET_INPUTERR;
|
||||
#endif
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
|
@ -2148,7 +2155,7 @@ ret_code vlan_config_chk(uint source,uint *config_type,
|
|||
if(ret != RET_OK){
|
||||
goto out;
|
||||
}
|
||||
*config_type = oper_type;
|
||||
//*config_type = oper_type;
|
||||
printf("[vlan]vlan_config_chk: operate_type=%d\n", oper_type);
|
||||
if(oper_type == CM_CONFIG_SET){
|
||||
printf("[vlan]vlan_config_chk: SET chk\n");
|
||||
|
|
|
@ -248,7 +248,7 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
|||
|
||||
authpara_config_json_parse(input, &conf_type, &auth_parameters);
|
||||
|
||||
if(input_len != sizeof(auth_parameters_t)) {
|
||||
if(input_len < sizeof(auth_parameters_t)) {
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
|
@ -303,11 +303,13 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
|||
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/*Portal server的port通过redis消息队列接口发布给web server*/
|
||||
memset(auth_port, 0, 20);
|
||||
sprintf(auth_port, "%d ", auth_parameters.port);
|
||||
printf("The number 'port' is %d and the string 'port' is %s. \n", auth_parameters.port, auth_port);
|
||||
local_portal_port(auth_port);
|
||||
#endif
|
||||
|
||||
/*创建json对象 */
|
||||
res = cJSON_CreateObject();
|
||||
|
@ -319,6 +321,8 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
|||
}
|
||||
|
||||
/*将json对象转换成json字符串 返回处理结果*/
|
||||
printf("resultcode = %d\n", configure_result->resultcode);
|
||||
printf("message = %s\n", configure_result->message);
|
||||
cJSON_AddNumberToObject(res, "resultcode", configure_result->resultcode);
|
||||
cJSON_AddStringToObject(res, "message", configure_result->message);
|
||||
ret_char = cJSON_PrintUnformatted(res);
|
||||
|
@ -343,4 +347,3 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
|||
free(configure_result);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,321 @@
|
|||
#include "auth_recover_config.h"
|
||||
#include <cjson/cJSON.h>
|
||||
#include "../include/parsefile.h"
|
||||
#include "../include/configm.h"
|
||||
#include "rpc.h"
|
||||
#include "s2j/s2j.h"
|
||||
#include "commuapinl.h"
|
||||
#include "../Platform/common/database/database.h"
|
||||
#include "config_manager.h"
|
||||
#include "authfree.h"
|
||||
#include "auth_parameters.h"
|
||||
#include "include/user_authfree.h"
|
||||
#include "include/user_authpara.h"
|
||||
#include "include/auth_common.h"
|
||||
|
||||
void * auth_hdbc = NULL; //认证数据库连接句柄
|
||||
extern freeauth_configure_t freeauth_array[];
|
||||
extern auth_parameters_t *auth_para;
|
||||
|
||||
|
||||
/*数据库重连*/
|
||||
void db_connect()
|
||||
{
|
||||
if(NULL == auth_hdbc)
|
||||
{
|
||||
auth_hdbc = connect_database(AUTHRECOVER_DATABASE_ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 查询未认证权限恢复 */
|
||||
void auth_getrule_db(char ** rule_db)
|
||||
{
|
||||
int num = 0;
|
||||
int size = 0;
|
||||
char *ret_authrule = NULL;
|
||||
|
||||
/*数据库重连*/
|
||||
db_connect();
|
||||
if(NULL == auth_hdbc)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char *select_sql = "SELECT rule_priority, name, sip, dip, dport, flag FROM `authfree`";
|
||||
ret_authrule = select_datebase_by_number(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authfree", select_sql, 1, 0, &num, 0);
|
||||
|
||||
if(0 == num || NULL == ret_authrule)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
size = strlen(ret_authrule)+1;
|
||||
char * point = (char*)malloc(size);
|
||||
if(NULL == point)
|
||||
{
|
||||
return;
|
||||
}
|
||||
memset(point, 0, size);
|
||||
memcpy(point, ret_authrule, size);
|
||||
*rule_db = point; //在函数外面释放
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* 查询认证参数恢复 */
|
||||
void auth_getpara_db(char ** parameters_db)
|
||||
{
|
||||
int num = 0;
|
||||
int size = 0;
|
||||
char *ret_parameters = NULL;
|
||||
|
||||
/*数据库重连*/
|
||||
db_connect();
|
||||
if(NULL == auth_hdbc)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char *select_sql = "SELECT port, timehorizon, failcount, dip, locktime, aging_time FROM `authparas`";
|
||||
ret_parameters = select_datebase_by_number(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authparas", select_sql, 1, 0, &num, 0);
|
||||
|
||||
if(0 == num || NULL == ret_parameters)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
size = strlen(ret_parameters)+1;
|
||||
char * point = (char*)malloc(size);
|
||||
if(NULL == point)
|
||||
{
|
||||
return;
|
||||
}
|
||||
memset(point, 0, size);
|
||||
memcpy(point, ret_parameters, size);
|
||||
*parameters_db = point; //在函数外面释放
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ret_code auth_recover_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_code auth_recover_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_code auth_recover_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*配置恢复未认证权限、认证参数*/
|
||||
ret_code auth_recover_get_all(uint source,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
char *rule_db = NULL;
|
||||
char *parameters_db = NULL;
|
||||
|
||||
if(CONFIG_FROM_RECOVER1 != source)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
auth_hdbc = connect_database(AUTHRECOVER_DATABASE_ID);
|
||||
|
||||
if(NULL == auth_hdbc)
|
||||
{
|
||||
return RET_SYSERR;
|
||||
}
|
||||
|
||||
/*初始化认证参数结构体指针*/
|
||||
authparInit();
|
||||
|
||||
auth_getrule_db(&rule_db);
|
||||
if(NULL != rule_db)
|
||||
{
|
||||
/*输出参数为json字符串*/
|
||||
cJSON * cjson = cJSON_Parse(rule_db);
|
||||
if(NULL == cjson)
|
||||
{
|
||||
free(rule_db);
|
||||
ret = RET_ERR;
|
||||
return ret;
|
||||
}
|
||||
|
||||
cJSON * data = cJSON_GetObjectItem(cjson, "data");
|
||||
if(NULL == data)
|
||||
{
|
||||
free(rule_db);
|
||||
cJSON_Delete(cjson);
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int mun_rule = cJSON_GetArraySize(data);
|
||||
if(0 == mun_rule)
|
||||
{
|
||||
free(rule_db);
|
||||
cJSON_Delete(cjson);
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
/*创建freeauth_configure_t结构体对象 */
|
||||
s2j_create_struct_obj(freeauth_buff, freeauth_configure_t);
|
||||
|
||||
if(freeauth_buff == NULL) {
|
||||
cJSON_Delete(cjson);
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
for (int i = 0; i < mun_rule; i++)
|
||||
{
|
||||
cJSON *pArrayItem = cJSON_GetArrayItem(data, i);
|
||||
|
||||
if(pArrayItem) {
|
||||
/*获取未认证权限优先级键值对*/
|
||||
cJSON *rule_priority = cJSON_GetObjectItem(pArrayItem, "rule_priority");
|
||||
|
||||
if(rule_priority) {
|
||||
freeauth_buff->rule_priority = rule_priority->valueint;
|
||||
}
|
||||
|
||||
/*未认证权限名称*/
|
||||
cJSON *name = cJSON_GetObjectItem(pArrayItem, "name");
|
||||
|
||||
if(name) {
|
||||
strncpy(freeauth_buff->name, name->valuestring, 31);
|
||||
}
|
||||
|
||||
/*源IP地址*/
|
||||
cJSON *sip = cJSON_GetObjectItem(pArrayItem, "sip");
|
||||
|
||||
if(sip) {
|
||||
freeauth_buff->sip = sip->valueint;
|
||||
}
|
||||
|
||||
/*目的IP地址*/
|
||||
cJSON *dip = cJSON_GetObjectItem(pArrayItem, "dip");
|
||||
|
||||
if(dip) {
|
||||
freeauth_buff->dip = dip->valueint;
|
||||
}
|
||||
|
||||
/*目的端口号*/
|
||||
cJSON *dport = cJSON_GetObjectItem(pArrayItem, "dport");
|
||||
|
||||
if(dport) {
|
||||
freeauth_buff->dport = dport->valueint;
|
||||
}
|
||||
|
||||
/*状态标志位*/
|
||||
cJSON *flag = cJSON_GetObjectItem(pArrayItem, "flag");
|
||||
|
||||
if(flag) {
|
||||
freeauth_buff->flag = flag->valueint;
|
||||
}
|
||||
|
||||
printf("freeauth_buff->name = %p %s\n", &freeauth_buff->name, freeauth_buff->name);
|
||||
|
||||
/*把数据库的内容读出来 然后加到全局变量里边去*/
|
||||
for(i = 0; i < RULE_MAX_NUM; i++) {
|
||||
printf("the name is :%s\n", freeauth_array[i].name);
|
||||
/*两个字符串相等 strcmp值为0*/
|
||||
int a = strlen(freeauth_array[i].name);
|
||||
printf("%d\n", a);
|
||||
|
||||
if(0 == strlen(freeauth_array[i].name)) {
|
||||
printf("%s(%d) freeauth_array[%d] = %p\n", __FUNCTION__, __LINE__, i, &freeauth_array[i]);
|
||||
memset(&freeauth_array[i], 0, sizeof(freeauth_configure_t));
|
||||
freeauth_array[i].rule_priority = freeauth_buff->rule_priority;
|
||||
strncpy(freeauth_array[i].name, freeauth_buff->name, 32);
|
||||
freeauth_array[i].sip = freeauth_buff->sip;
|
||||
freeauth_array[i].dip = freeauth_buff->dip;
|
||||
freeauth_array[i].dport = freeauth_buff->dport;
|
||||
freeauth_array[i].flag = freeauth_buff->flag;
|
||||
printf("[%d %s %d %d %d %d %d]\n", freeauth_array[i].rule_priority, freeauth_array[i].name, freeauth_array[i].sip,
|
||||
freeauth_array[i].dip, freeauth_array[i].dport, freeauth_array[i].dport, i);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
freeauth_buff++;
|
||||
}
|
||||
}
|
||||
|
||||
s2j_delete_struct_obj(freeauth_buff);
|
||||
free(rule_db);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
auth_getpara_db(¶meters_db);
|
||||
if(NULL != parameters_db)
|
||||
{
|
||||
/*输出参数为json字符串*/
|
||||
cJSON * cjson_para = cJSON_Parse(parameters_db);
|
||||
if(NULL == cjson_para)
|
||||
{
|
||||
free(parameters_db);
|
||||
ret = RET_ERR;
|
||||
return ret;
|
||||
}
|
||||
|
||||
cJSON * data_para = cJSON_GetObjectItem(cjson_para, "data");
|
||||
if(NULL == data_para)
|
||||
{
|
||||
free(parameters_db);
|
||||
cJSON_Delete(cjson_para);
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
/*创建freeauth_configure_t结构体对象 */
|
||||
s2j_create_struct_obj(auth_parameters, auth_parameters_t);
|
||||
|
||||
if(auth_parameters == NULL) {
|
||||
cJSON_Delete(cjson_para);
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
/*反序列化数据到freeauth_configure_t结构体对象 */
|
||||
s2j_struct_get_basic_element(auth_parameters, data_para, int, port);
|
||||
s2j_struct_get_basic_element(auth_parameters, data_para, int, timehorizon);
|
||||
s2j_struct_get_basic_element(auth_parameters, data_para, int, failcount);
|
||||
s2j_struct_get_basic_element(auth_parameters, data_para, int, locktime);
|
||||
s2j_struct_get_basic_element(auth_parameters, data_para, int, aging_time);
|
||||
|
||||
/*将数据存入全局结构体指针*/
|
||||
if(auth_para) {
|
||||
auth_para->port = auth_parameters->port;
|
||||
auth_para->timehorizon = auth_parameters->timehorizon;
|
||||
auth_para->failcount = auth_parameters->failcount;
|
||||
auth_para->locktime = auth_parameters->locktime;
|
||||
auth_para->aging_time = auth_parameters->aging_time;
|
||||
}
|
||||
|
||||
s2j_delete_struct_obj(auth_parameters);
|
||||
cJSON_Delete(cjson_para);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef AUTH_RECOVER_H_
|
||||
#define AUTH_RECOVER_H_
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include "rpc_common.h"
|
||||
|
||||
/*数据库重连*/
|
||||
void db_connect();
|
||||
|
||||
/* 查询未认证权限恢复 */
|
||||
void auth_getrule_db(char ** rule_db);
|
||||
|
||||
/* 查询认证参数恢复 */
|
||||
void auth_getpara_db(char ** parameters_db);
|
||||
|
||||
ret_code auth_recover_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
ret_code auth_recover_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
ret_code auth_recover_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
/*配置恢复未认证权限、认证参数*/
|
||||
ret_code auth_recover_get_all(uint source,
|
||||
pointer output, int *output_len);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -278,6 +278,8 @@ ret_code authpara_config_json_parse_array(pointer input, uint *conf_type, freeau
|
|||
|
||||
memset(freeauth_buff, 0, sizeof(freeauth_configure_t) * iCount);
|
||||
|
||||
*fb = freeauth_buff;
|
||||
|
||||
for(i = 0; i < iCount; i++) {
|
||||
|
||||
cJSON *pArrayItem = cJSON_GetArrayItem(data, i);
|
||||
|
@ -325,13 +327,16 @@ ret_code authpara_config_json_parse_array(pointer input, uint *conf_type, freeau
|
|||
freeauth_buff->flag = flag->valueint;
|
||||
}
|
||||
|
||||
#if 0
|
||||
printf("freeauth_buff->name = %p\n", &freeauth_buff->name);
|
||||
|
||||
printf("freeauth_buff->name = %p\n", &freeauth_buff->name);
|
||||
printf("freeauth_buff->name = %s\n", freeauth_buff->name);
|
||||
|
||||
#if 0
|
||||
for (int j = 0; j < iCount; j++)
|
||||
{
|
||||
printf("[%d %s %d %d %d %d]\n",pbuf[j].rule_priority, pbuf[j].name, pbuf[j].sip,
|
||||
pbuf[j].dip, pbuf[j].dport, pbuf[j].flag);
|
||||
printf("[%d %s %d %d %d %d]\n", freeauth_buff->rule_priority, freeauth_buff->name, freeauth_buff->sip,
|
||||
freeauth_buff->dip, freeauth_buff->dport, freeauth_buff->flag);
|
||||
freeauth_buff++;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -345,7 +350,6 @@ ret_code authpara_config_json_parse_array(pointer input, uint *conf_type, freeau
|
|||
|
||||
cJSON_Delete(cjson);
|
||||
|
||||
*fb = freeauth_buff;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
@ -386,20 +390,36 @@ ret_code freeauth_config_add_proc(uint source, uint config_type,
|
|||
freeauth_config_json_parse(input, &conf_type, freeauth_configure);
|
||||
|
||||
/*校验用户名长度*/
|
||||
if(input_len != sizeof(freeauth_configure_t) || NULL == freeauth_configure->name ||
|
||||
if(input_len < sizeof(freeauth_configure_t) || NULL == freeauth_configure->name ||
|
||||
(UNAMESIZE) < strlen(freeauth_configure->name) || 0 == strlen(freeauth_configure->name)) {
|
||||
free(freeauth_configure);
|
||||
printf("the lenth is error\n");
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
|
||||
/* 校验用户名中不含特殊字符 */
|
||||
if(SPECHAR(freeauth_configure->name)) {
|
||||
free(freeauth_configure);
|
||||
printf("username 含有特殊字符\n");
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*校验优先级是否重名,如果优先级已经存在 则退出程序*/
|
||||
for(i = 0; i < RULE_MAX_NUM; i++){
|
||||
if(freeauth_array[i].rule_priority == freeauth_configure->rule_priority) {
|
||||
printf("%s(%d) freeauth_array[%d] = %p\n", __FUNCTION__, __LINE__, i, &freeauth_array[i]);
|
||||
free(freeauth_configure);
|
||||
return RET_EXIST;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*校验端口号*/
|
||||
if((freeauth_configure->dport < DPORT_MIN_NUM) || (freeauth_configure->dport > DPORT_MAX_NUM)) {
|
||||
free(freeauth_configure);
|
||||
printf("the port is error\n");
|
||||
return RET_IPINVALID;
|
||||
}
|
||||
|
||||
|
@ -408,8 +428,39 @@ ret_code freeauth_config_add_proc(uint source, uint config_type,
|
|||
/*两个字符串相等 strcmp值为0*/
|
||||
if(0 == strcmp(freeauth_array[i].name, freeauth_configure->name)) {
|
||||
printf("%s(%d) freeauth_array[%d] = %p\n", __FUNCTION__, __LINE__, i, &freeauth_array[i]);
|
||||
printf("local user is existed\n");
|
||||
|
||||
/*创建json对象 */
|
||||
res = cJSON_CreateObject();
|
||||
|
||||
if(!res) {
|
||||
free(freeauth_configure);
|
||||
return RET_EXIST;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
/*将json对象转换成json字符串 返回处理结果*/
|
||||
cJSON_AddNumberToObject(res, "resultcode", 2);
|
||||
cJSON_AddStringToObject(res, "message", "rule existed");
|
||||
ret_char = cJSON_PrintUnformatted(res);
|
||||
ret_int = strlen(ret_char);
|
||||
|
||||
if(output_len) {
|
||||
*output_len = ret_int;
|
||||
}
|
||||
|
||||
/*超出2k的内存,报错 */
|
||||
if(ret_int >= 1024 * 2) {
|
||||
free(ret_char);
|
||||
cJSON_Delete(res);
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
memcpy(output, ret_char, ret_int + 1);
|
||||
|
||||
free(ret_char);
|
||||
cJSON_Delete(res);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -493,10 +544,26 @@ ret_code freeauth_config_mod_proc(uint source, uint config_type,
|
|||
|
||||
authpara_config_json_parse_array(input, &conf_type, &freeauth_configure, &cnt);
|
||||
|
||||
if(input_len != sizeof(freeauth_configure_t)) {
|
||||
if(input_len < sizeof(freeauth_configure_t)) {
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
|
||||
printf("打印全局数组内全部元素\n");
|
||||
/*打印数组内全部元素*/
|
||||
for(i = 0; i < RULE_MAX_NUM; i++)
|
||||
{
|
||||
printf("[%d %s %d %d %d %d %d]\n", freeauth_array[i].rule_priority, freeauth_array[i].name, freeauth_array[i].sip,
|
||||
freeauth_array[i].dip, freeauth_array[i].dport, freeauth_array[i].dport, i);
|
||||
}
|
||||
|
||||
printf("打印传过来的json串\n");
|
||||
for(int j = 0; j < cnt; j++)
|
||||
{
|
||||
printf("[%d %s %d %d %d %d %d]\n", freeauth_configure[j].rule_priority, freeauth_configure[j].name, freeauth_configure[j].sip,
|
||||
freeauth_configure[j].dip, freeauth_configure[j].dport, freeauth_configure[j].dport, j);
|
||||
}
|
||||
|
||||
/*查找要修改的免认证规则名字,不存在则退出程序 */
|
||||
for(i = 0; i < RULE_MAX_NUM; i++) {
|
||||
/*两个字符串相等 strcmp值为0*/
|
||||
|
@ -590,33 +657,42 @@ ret_code freeauth_config_del_proc(uint source, uint config_type,
|
|||
char *ret_char = NULL;
|
||||
unsigned int ret_int = 0;
|
||||
|
||||
#if 0
|
||||
freeauth_configure = (freeauth_configure_t *)malloc(sizeof(freeauth_configure_t));
|
||||
|
||||
if(freeauth_configure == NULL) {
|
||||
return RET_NAMEINVAL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
authpara_config_json_parse_del_array(input, &conf_type, &freeauth_configure, &cnt);
|
||||
|
||||
if(input_len != sizeof(freeauth_configure_t)) {
|
||||
if(input_len < sizeof(freeauth_configure_t)) {
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
|
||||
printf("打印全局数组内全部元素\n");
|
||||
/*打印数组内全部元素*/
|
||||
for(i = 0; i < RULE_MAX_NUM; i++)
|
||||
{
|
||||
printf("[%d %s %d %d %d %d %d]\n", freeauth_array[i].rule_priority, freeauth_array[i].name, freeauth_array[i].sip,
|
||||
freeauth_array[i].dip, freeauth_array[i].dport, freeauth_array[i].dport, i);
|
||||
}
|
||||
|
||||
printf("打印传过来的json串\n");
|
||||
for(int j = 0; j < cnt; j++)
|
||||
{
|
||||
printf("[%s %d]\n", freeauth_configure[j].name, j);
|
||||
}
|
||||
|
||||
|
||||
/*查找要修改的免认证规则名字,不存在则退出程序 */
|
||||
for(i = 0; i < RULE_MAX_NUM; i++) {
|
||||
/*两个字符串相等 strcmp值为0*/
|
||||
for(int j = 0; j < cnt; j++) {
|
||||
if(0 == strcmp(freeauth_array[i].name, freeauth_configure[j].name))
|
||||
{
|
||||
|
||||
if(0 == strcmp(freeauth_array[i].name, freeauth_configure[j].name)) {
|
||||
printf("%s %d\n", freeauth_array[i].name, i);
|
||||
printf("%s %d\n", freeauth_configure[j].name, j);
|
||||
printf("%s %d\n",freeauth_array[i].name, i);
|
||||
printf("%s %d\n",freeauth_configure[j].name, j);
|
||||
printf("%s(%d) freeauth_array[%d] = %p\n", __FUNCTION__, __LINE__, i, &freeauth_array[j]);
|
||||
/*数据库修改 存入全局变量*/
|
||||
del_authfree(freeauth_configure[j].name, &authfree_result);
|
||||
|
||||
/*数据库删除 存入全局变量*/
|
||||
del_authfree(freeauth_configure[j].name, &authfree_result);
|
||||
#if 0
|
||||
/*用户态下发到内核态auth_hook */
|
||||
int r = -1;
|
||||
|
@ -646,7 +722,8 @@ ret_code freeauth_config_del_proc(uint source, uint config_type,
|
|||
/*创建json对象 */
|
||||
res = cJSON_CreateObject();
|
||||
|
||||
if(!res) {
|
||||
if(!res)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
|
@ -656,12 +733,14 @@ ret_code freeauth_config_del_proc(uint source, uint config_type,
|
|||
ret_char = cJSON_PrintUnformatted(res);
|
||||
ret_int = strlen(ret_char);
|
||||
|
||||
if(output_len) {
|
||||
if(output_len)
|
||||
{
|
||||
*output_len = ret_int;
|
||||
}
|
||||
|
||||
/*超出2k的内存,报错 */
|
||||
if(ret_int >= 1024 * 2) {
|
||||
if(ret_int >= 1024 * 2)
|
||||
{
|
||||
free(ret_char);
|
||||
cJSON_Delete(res);
|
||||
return RET_NOMEM;
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
#include "../Platform/common/database/database.h"
|
||||
#include "../include/user_authfree.h"
|
||||
#include "string.h"
|
||||
|
||||
#define AUTHFREE_DATABASE_ID (16)
|
||||
#define AUTHFREE_TABLE "authfree"
|
||||
#include "../include/auth_common.h"
|
||||
|
||||
extern freeauth_configure_t freeauth_array[];
|
||||
extern void * auth_hdbc;
|
||||
|
||||
static char *authfreemes[] = {"addrule success", "addrule fail", "rule existed", "modrule success",
|
||||
"modrule failure", "rule not found", "delrule success", "delrule fail", "rulenum exceed maxnum",
|
||||
|
@ -37,7 +36,7 @@ static int is_rule_full(void)
|
|||
/*增加未认证权限规则*/
|
||||
void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int dport, int flag, authfree_result_t *authfree_result)
|
||||
{
|
||||
void *authfree_hdbc;
|
||||
//void *authfree_hdbc;
|
||||
char *ret_sql = NULL;
|
||||
int ret_add;
|
||||
int ret;
|
||||
|
@ -55,9 +54,8 @@ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
return;
|
||||
}
|
||||
|
||||
printf("开始连接数据库\n");
|
||||
|
||||
/* 连接数据库 */
|
||||
#if 0
|
||||
authfree_hdbc = connect_database(AUTHFREE_DATABASE_ID);
|
||||
|
||||
if(NULL == authfree_hdbc) {
|
||||
|
@ -67,10 +65,13 @@ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
|
||||
/*长整型bigint 浮点型double 字符串character(10)*/
|
||||
printf("authfree_hdbc = %p\n", authfree_hdbc);
|
||||
ret = create_database_table(AUTHFREE_DATABASE_ID, authfree_hdbc, "authfree", "create table authfree(rule_priority bigint, name character(32), sip bigint, dip bigint, dport bigint, flag bigint)");
|
||||
#endif
|
||||
|
||||
/*建表*/
|
||||
ret = create_database_table(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authfree", "create table authfree(rule_priority bigint, name character(32), sip bigint, dip bigint, dport bigint, flag bigint)");
|
||||
printf("%d \n", ret);
|
||||
|
||||
|
||||
#if 0
|
||||
/*查询数据库是否存在该权限规则*/
|
||||
char *select_sql = "SELECT rule_priority, name, sip, dip, dport, flag FROM `authfree` WHERE name = ?";
|
||||
ret_sql = select_datebase_by_number(AUTHFREE_DATABASE_ID, authfree_hdbc, "authfree", select_sql, 1, 0, &num, 1,
|
||||
|
@ -78,14 +79,18 @@ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
|
||||
if(NULL != ret_sql) {
|
||||
/*用户名已存在*/
|
||||
printf("用户名已存在");
|
||||
disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc);
|
||||
authfree_result->resultcode = RULE_EXISTED;
|
||||
authfree_result->message = get_sql_ret_message(authfree_result->resultcode);
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 根据指定信息查询数据库的获取的结果的条目数 条目数大于10 则不能再添加 */
|
||||
char *select_num = "SELECT rule_priority, name, sip, dip, dport, flag FROM `authfree`";
|
||||
ret = get_select_datebase_number(AUTHFREE_DATABASE_ID, authfree_hdbc, "authfree", select_num, &num_sql, 6,
|
||||
ret = get_select_datebase_number(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authfree", select_num, &num_sql, 6,
|
||||
DB_DATA_INT_TYPE, sizeof(rule_priority), rule_priority,
|
||||
DB_DATA_STRING_TYPE, strlen(name) + 1, name,
|
||||
DB_DATA_INT_TYPE, sizeof(sip), sip,
|
||||
|
@ -97,7 +102,7 @@ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
|
||||
if(num_sql > RULE_MAX_NUM) {
|
||||
/*添加失败*/
|
||||
disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc); // ret_release记录日志
|
||||
//disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc); // ret_release记录日志
|
||||
authfree_result->resultcode = RULE_ID_MAX;
|
||||
authfree_result->message = get_sql_ret_message(authfree_result->resultcode);
|
||||
return;
|
||||
|
@ -105,7 +110,7 @@ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
|
||||
/* 向authfree表中添加:未认证权限名称、内部源IP地址、目的IP地址、目的端口号 */
|
||||
char *addfree_sql = "INSERT INTO `authfree` SET rule_priority = ?, name = ?, sip = ?, dip = ?, dport = ?, flag = ?";
|
||||
ret_add = update_database(AUTHFREE_DATABASE_ID, authfree_hdbc, DB_OP_INSERT, AUTHFREE_TABLE, addfree_sql, 6,
|
||||
ret_add = update_database(AUTHRECOVER_DATABASE_ID, auth_hdbc, DB_OP_INSERT, AUTHFREE_TABLE, addfree_sql, 6,
|
||||
DB_DATA_INT_TYPE, sizeof(rule_priority), rule_priority,
|
||||
DB_DATA_STRING_TYPE, strlen(name) + 1, name,
|
||||
DB_DATA_INT_TYPE, sizeof(sip), sip,
|
||||
|
@ -116,14 +121,13 @@ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
|
||||
if(0 != ret_add) {
|
||||
/*添加失败*/
|
||||
disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc); // ret_release记录日志
|
||||
//disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc); // ret_release记录日志
|
||||
authfree_result->resultcode = ADD_RULE_ERR;
|
||||
authfree_result->message = get_sql_ret_message(authfree_result->resultcode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc);
|
||||
//disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc);
|
||||
|
||||
/*存未认证权限数数组*/
|
||||
for(i = 0; i < RULE_MAX_NUM; i++) {
|
||||
|
@ -147,15 +151,24 @@ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*打印数组内全部元素*/
|
||||
for(i = 0; i < RULE_MAX_NUM; i++)
|
||||
{
|
||||
printf("[%d %s %d %d %d %d %d]\n", freeauth_array[i].rule_priority, freeauth_array[i].name, freeauth_array[i].sip,
|
||||
freeauth_array[i].dip, freeauth_array[i].dport, freeauth_array[i].dport, i);
|
||||
}
|
||||
|
||||
/*添加成功*/
|
||||
authfree_result->resultcode = ADD_RULE_OK;
|
||||
authfree_result->message = get_sql_ret_message(authfree_result->resultcode);
|
||||
}
|
||||
|
||||
|
||||
/*修改未认证权限*/
|
||||
void mod_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int dport, int flag, authfree_result_t *authfree_result)
|
||||
{
|
||||
void *authfree_hdbc;
|
||||
//void *authfree_hdbc;
|
||||
char *ret_sql = NULL;
|
||||
int ret_mod;
|
||||
int ret;
|
||||
|
@ -168,8 +181,9 @@ void mod_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
|
||||
printf("开始连接数据库\n");
|
||||
|
||||
#if 0
|
||||
/* 连接数据库 */
|
||||
authfree_hdbc = connect_database(AUTHFREE_DATABASE_ID);
|
||||
authfree_hdbc = connect_database(AUTHRECOVER_DATABASE_ID);
|
||||
|
||||
if(NULL == authfree_hdbc) {
|
||||
printf("connetc failure\n");
|
||||
|
@ -178,9 +192,13 @@ void mod_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
|
||||
/*长整型bigint 浮点型double 字符串character(10)*/
|
||||
printf("authfree_hdbc = %p\n", authfree_hdbc);
|
||||
ret = create_database_table(AUTHFREE_DATABASE_ID, authfree_hdbc, "authfree", "create table authfree(name character(32), sip bigint, dip bigint, dport bigint)");
|
||||
#endif
|
||||
|
||||
/*建表*/
|
||||
ret = create_database_table(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authfree", "create table authfree(name character(32), sip bigint, dip bigint, dport bigint)");
|
||||
printf("%d \n", ret);
|
||||
|
||||
#if 0
|
||||
/*查询数据库是否存在该权限规则*/
|
||||
char *select_sql = "SELECT name, sip, dip, dport FROM `authfree`WHERE name = ?";
|
||||
ret_sql = select_datebase_by_number(AUTHFREE_DATABASE_ID, authfree_hdbc, "authfree", select_sql, 1, 0, &num, 1,
|
||||
|
@ -193,9 +211,12 @@ void mod_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
authfree_result->message = get_sql_ret_message(authfree_result->resultcode);
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
#endif
|
||||
|
||||
/*修改authfree表中内部源IP地址、目的IP地址、目的端口号 未认证权限名称不能修改 */
|
||||
char *modfree_sql = "UPDATE `authfree` SET rule_priority = ?, sip = ?, dip = ?, dport = ? ,flag = ? WHERE name = ?";
|
||||
ret_mod = update_database(AUTHFREE_DATABASE_ID, authfree_hdbc, DB_OP_UPDATE, AUTHFREE_TABLE, modfree_sql, 6,
|
||||
ret_mod = update_database(AUTHRECOVER_DATABASE_ID, auth_hdbc, DB_OP_UPDATE, AUTHFREE_TABLE, modfree_sql, 6,
|
||||
DB_DATA_INT_TYPE, sizeof(rule_priority), rule_priority,
|
||||
DB_DATA_INT_TYPE, sizeof(sip), sip,
|
||||
DB_DATA_INT_TYPE, sizeof(dip), dip,
|
||||
|
@ -206,14 +227,13 @@ void mod_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
|
||||
if(0 != ret_mod) {
|
||||
/*修改失败*/
|
||||
disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc); // ret_release记录日志
|
||||
//disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc); // ret_release记录日志
|
||||
authfree_result->resultcode = MOD_RULE_ERR;
|
||||
authfree_result->message = get_sql_ret_message(authfree_result->resultcode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc);
|
||||
//disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc);
|
||||
|
||||
/*修改对应未认证权限数数组*/
|
||||
for(i = 0; i < RULE_MAX_NUM; i++) {
|
||||
|
@ -231,15 +251,13 @@ void mod_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
/*打印数组内全部元素*/
|
||||
for(i = 0; i < RULE_MAX_NUM; i++) {
|
||||
printf("%s %d %d %d %d\n", freeauth_array[i].name, freeauth_array[i].sip, freeauth_array[i].dip, freeauth_array[i].dport, i);
|
||||
for(i = 0; i < RULE_MAX_NUM; i++)
|
||||
{
|
||||
printf("[%d %s %d %d %d %d %d]\n", freeauth_array[i].rule_priority, freeauth_array[i].name, freeauth_array[i].sip,
|
||||
freeauth_array[i].dip, freeauth_array[i].dport, freeauth_array[i].dport, i);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*修改成功*/
|
||||
authfree_result->resultcode = MOD_RULE_OK;
|
||||
authfree_result->message = get_sql_ret_message(authfree_result->resultcode);
|
||||
|
@ -249,7 +267,7 @@ void mod_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int
|
|||
/*删除未认证权限*/
|
||||
void del_authfree(char *name, authfree_result_t *authfree_result)
|
||||
{
|
||||
void *authfree_hdbc;
|
||||
//void *authfree_hdbc;
|
||||
char *ret_sql = NULL;
|
||||
int ret_del;
|
||||
int ret;
|
||||
|
@ -260,8 +278,7 @@ void del_authfree(char *name, authfree_result_t *authfree_result)
|
|||
return;
|
||||
}
|
||||
|
||||
printf("开始连接数据库\n");
|
||||
|
||||
#if 0
|
||||
/* 连接数据库 */
|
||||
authfree_hdbc = connect_database(AUTHFREE_DATABASE_ID);
|
||||
|
||||
|
@ -272,35 +289,44 @@ void del_authfree(char *name, authfree_result_t *authfree_result)
|
|||
|
||||
/*长整型bigint 浮点型double 字符串character(10)*/
|
||||
printf("authfree_hdbc = %p\n", authfree_hdbc);
|
||||
ret = create_database_table(AUTHFREE_DATABASE_ID, authfree_hdbc, "authfree", "create table authfree(name character(32), sip bigint, dip bigint, dport bigint)");
|
||||
#endif
|
||||
|
||||
/*建表*/
|
||||
ret = create_database_table(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authfree", "create table authfree(name character(32), sip bigint, dip bigint, dport bigint)");
|
||||
printf("%d \n", ret);
|
||||
|
||||
|
||||
#if 0
|
||||
/*查询数据库是否存在该权限规则*/
|
||||
char *select_sql = "SELECT rule_priority, name, sip, dip, dport, flag FROM `authfree`WHERE name = ?";
|
||||
ret_sql = select_datebase_by_number(AUTHFREE_DATABASE_ID, authfree_hdbc, "authfree", select_sql, 1, 0, &num, 1,
|
||||
DB_DATA_STRING_TYPE, strlen(name) + 1, name);
|
||||
|
||||
|
||||
if(NULL == ret_sql) {
|
||||
/*未认证权限用户名不存在*/
|
||||
authfree_result->resultcode = RULE_NOT_FOUNT;
|
||||
authfree_result->message = get_sql_ret_message(authfree_result->resultcode);
|
||||
return;
|
||||
} else {
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/*删除authfree表中未认证权限名称、内部源IP地址、目的IP地址、目的端口号 */
|
||||
char *delfree_sql = "DELETE FROM authfree WHERE name = ?";
|
||||
int ret_del = update_database(AUTHFREE_DATABASE_ID, authfree_hdbc, DB_OP_DEL, AUTHFREE_TABLE, delfree_sql, 1,
|
||||
ret_del = update_database(AUTHRECOVER_DATABASE_ID, auth_hdbc, DB_OP_DEL, AUTHFREE_TABLE, delfree_sql, 1,
|
||||
DB_DATA_STRING_TYPE, strlen(name) + 1, name);
|
||||
printf("the value of ret:%d\n", ret_del);
|
||||
|
||||
if(0 != ret_del) {
|
||||
disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc); // ret_release记录日志
|
||||
//disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc); // ret_release记录日志
|
||||
authfree_result->resultcode = DEL_RULE_ERR; /*删除失败*/
|
||||
authfree_result->message = get_sql_ret_message(authfree_result->resultcode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc);
|
||||
//disconnect_database(AUTHFREE_DATABASE_ID, authfree_hdbc);
|
||||
|
||||
/*修改对应未认证权限数数组*/
|
||||
for(i = 0; i < RULE_MAX_NUM; i++) {
|
||||
|
@ -314,17 +340,9 @@ void del_authfree(char *name, authfree_result_t *authfree_result)
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
/*打印数组内全部元素*/
|
||||
for(i = 0; i < RULE_MAX_NUM; i++) {
|
||||
printf("[%d %s %d %d %d %d %d]\n", freeauth_array[i].rule_priority, freeauth_array[i].name, freeauth_array[i].sip,
|
||||
freeauth_array[i].dip, freeauth_array[i].dport, freeauth_array[i].dport, i);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*删除成功*/
|
||||
authfree_result->resultcode = DEL_RUL_OK;
|
||||
authfree_result->message = get_sql_ret_message(authfree_result->resultcode);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,18 +8,19 @@
|
|||
#include "../../../../../Common/commuapinl.h"
|
||||
#include "../auth_parameters.h"
|
||||
#include "../Platform/common/database/database.h"
|
||||
|
||||
#define AUTHPARA_DATABASE_ID 15
|
||||
#define AUTHPARA_TABLE "authparas"
|
||||
#include "../include/user_authpara.h"
|
||||
#include "../include/auth_common.h"
|
||||
|
||||
extern auth_parameters_t *auth_para;
|
||||
extern void * auth_hdbc;
|
||||
|
||||
char * mes[]={"ADDSUCCESS", "ADDFAILURE"};
|
||||
char * mes[]={"mod success", "mod failure"};
|
||||
|
||||
/*前端type类型只有修改,修改数据库中的内容,返回值为code message——修改成功 修改失败*/
|
||||
void mod_authpara(int port, int timehorizon, int failcount, int locktime, int aging_time, configure_result_t *configure_result)
|
||||
{
|
||||
void * authpara_hdbc;
|
||||
authparInit();
|
||||
//void * authpara_hdbc;
|
||||
char * ret_sql = NULL;
|
||||
int ret;
|
||||
int num;
|
||||
|
@ -30,6 +31,7 @@ void mod_authpara(int port, int timehorizon, int failcount, int locktime, int ag
|
|||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
printf("开始连接数据库\n");
|
||||
|
||||
/* 连接数据库 */
|
||||
|
@ -42,15 +44,18 @@ void mod_authpara(int port, int timehorizon, int failcount, int locktime, int ag
|
|||
|
||||
/*长整型bigint 浮点型double 字符串character(10)*/
|
||||
printf("authpara_hdbc = %p\n", authpara_hdbc);
|
||||
ret = create_database_table(AUTHPARA_DATABASE_ID, authpara_hdbc, "authparas", "create table authparas(port bigint, timehorizon bigint, failcount bigint, locktime bigint, aging_time bigint)");
|
||||
#endif
|
||||
|
||||
/*建表*/
|
||||
ret = create_database_table(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authparas", "create table authparas(port bigint, timehorizon bigint, failcount bigint, locktime bigint, aging_time bigint)");
|
||||
printf("%d \n",ret);
|
||||
|
||||
/* 存authpara表 默认值 */
|
||||
char *user1_authpara = "INSERT INTO `authparas` SET port = 8080, timehorizon = 1, failcount = 5, locktime = 10, aging_time = 10";
|
||||
int ret_addauthpara = update_database(AUTHPARA_DATABASE_ID, authpara_hdbc, DB_OP_INSERT, AUTHPARA_TABLE, user1_authpara, 0);
|
||||
int ret_addauthpara = update_database(AUTHRECOVER_DATABASE_ID, auth_hdbc, DB_OP_INSERT, AUTHPARA_TABLE, user1_authpara, 0);
|
||||
if(0 != ret_addauthpara)
|
||||
{
|
||||
disconnect_database(AUTHPARA_DATABASE_ID , authpara_hdbc); // ret_release记录日志
|
||||
disconnect_database(AUTHRECOVER_DATABASE_ID , auth_hdbc); // ret_release记录日志
|
||||
configure_result->resultcode = 1;
|
||||
configure_result->message = mes[configure_result->resultcode];
|
||||
return;
|
||||
|
@ -58,7 +63,7 @@ void mod_authpara(int port, int timehorizon, int failcount, int locktime, int ag
|
|||
|
||||
|
||||
char *user_authpara = "UPDATE `authparas` SET port = ?, timehorizon = ?, failcount = ?, locktime = ?, aging_time = ?";
|
||||
ret = update_database(AUTHPARA_DATABASE_ID, authpara_hdbc, DB_OP_UPDATE, AUTHPARA_TABLE, user_authpara, 5,
|
||||
ret = update_database(AUTHRECOVER_DATABASE_ID, auth_hdbc, DB_OP_UPDATE, AUTHPARA_TABLE, user_authpara, 5,
|
||||
DB_DATA_INT_TYPE, sizeof(port), port,
|
||||
DB_DATA_INT_TYPE, sizeof(timehorizon), timehorizon,
|
||||
DB_DATA_INT_TYPE, sizeof(failcount), failcount,
|
||||
|
@ -67,13 +72,13 @@ void mod_authpara(int port, int timehorizon, int failcount, int locktime, int ag
|
|||
printf("the value of ret:%d\n", ret);
|
||||
if(0 != ret)
|
||||
{
|
||||
disconnect_database(AUTHPARA_DATABASE_ID , authpara_hdbc); // ret_release记录日志
|
||||
//disconnect_database(AUTHPARA_DATABASE_ID , authpara_hdbc); // ret_release记录日志
|
||||
configure_result->resultcode = 1;
|
||||
configure_result->message = mes[configure_result->resultcode];
|
||||
return;
|
||||
}
|
||||
|
||||
disconnect_database(AUTHPARA_DATABASE_ID , authpara_hdbc);
|
||||
//disconnect_database(AUTHPARA_DATABASE_ID , authpara_hdbc);
|
||||
|
||||
/*存全局变量*/
|
||||
auth_para->port = port;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef AUTH_COMMON_H_
|
||||
#define AUTH_COMMON_H_
|
||||
|
||||
#define AUTHPARA_TABLE "authparas"
|
||||
#define AUTHFREE_TABLE "authfree"
|
||||
|
||||
#define AUTHRECOVER_DATABASE_ID (15)
|
||||
|
||||
#endif
|
|
@ -11,7 +11,6 @@
|
|||
#define DELAUTHFREE_FAIL_DATABASE (7) //删除未认证权限失败
|
||||
#define RULENUM_EXCEED (8) //未认证权限数量超过最大值
|
||||
|
||||
|
||||
typedef enum {
|
||||
ADD_RULE_OK = 0,
|
||||
ADD_RULE_ERR = 1,
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <stdint.h>
|
||||
#include "../Platform/user/configm/config-server/web_config/auth_parameters.h"
|
||||
|
||||
|
||||
#define ADDUSER_FAIL_NAMEDUP 4 //用户名重名
|
||||
|
||||
#define MODAUTHPARA_SUCCESS 0 //修改认证信息成功
|
||||
|
|
|
@ -5,12 +5,28 @@
|
|||
#include "ulog/ulog_in.h"
|
||||
#include "s2j/s2j.h"
|
||||
|
||||
|
||||
|
||||
static int logging_file_json_parse(pointer input, log_file_t *config_buff);
|
||||
|
||||
|
||||
int conf_file(cJSON *json_obj, int argc, char **argv)
|
||||
{
|
||||
log_file_t log_file = {0};
|
||||
log_file_t log_file_out = {0};
|
||||
int level = LOG_INFO;
|
||||
uint config_type = CM_CONFIG_SET;
|
||||
char *json_output = NULL;
|
||||
|
||||
log_file.is_compress = LOG_UNCOMPRESS;
|
||||
|
||||
int level = LOG_INFO;
|
||||
if (argc == 3 && strstr(argv[2], "get") != NULL)
|
||||
{
|
||||
config_type = CM_CONFIG_GET;
|
||||
}
|
||||
else
|
||||
{
|
||||
config_type = CM_CONFIG_SET;
|
||||
if (argc >= 3) {
|
||||
if ((level = log_str_to_level(argv[2])) < 0) {
|
||||
ULOG_WARNING(g_log, "Unknown log level:%s", argv[2]);
|
||||
|
@ -45,6 +61,7 @@ int conf_file(cJSON *json_obj, int argc, char **argv)
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s2j_json_set_basic_element(json_obj, &log_file, int, level);
|
||||
s2j_json_set_basic_element(json_obj, &log_file, string, path);
|
||||
|
@ -52,12 +69,63 @@ int conf_file(cJSON *json_obj, int argc, char **argv)
|
|||
s2j_json_set_basic_element(json_obj, &log_file, int, del_over_days);
|
||||
s2j_json_set_basic_element(json_obj, &log_file, string, del_over_size);
|
||||
|
||||
int ret = set_log_conf(json_obj, LOG_CONFIG_FILE);
|
||||
int ret = set_log_conf(config_type, json_obj, LOG_CONFIG_FILE, &json_output);
|
||||
if (ret != 0) {
|
||||
ULOG_ERR(g_log, "File log which is configured is failure");
|
||||
} else {
|
||||
ULOG_DEBUG(g_log, "File log whice is configured is success");
|
||||
}
|
||||
|
||||
if (CM_CONFIG_GET == config_type)
|
||||
{
|
||||
logging_file_json_parse(json_output, &log_file_out);
|
||||
|
||||
ULOG_DEBUG(g_log, "Log file get: level=%u, path=%s, is_compress=%d, del_over_days=%u, del_over_size=%s",
|
||||
log_file_out.level,
|
||||
log_file_out.path,
|
||||
log_file_out.is_compress,
|
||||
log_file_out.del_over_days, log_file_out.del_over_size);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int logging_file_json_parse(pointer input, log_file_t *config_buff)
|
||||
{
|
||||
cJSON *json_obj;
|
||||
|
||||
if (NULL == config_buff)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
json_obj = cJSON_Parse(input);
|
||||
if (!json_obj)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
s2j_create_struct_obj(log_file, log_file_t);
|
||||
|
||||
if (log_file == NULL)
|
||||
{
|
||||
cJSON_Delete(json_obj);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s2j_struct_get_basic_element(log_file, json_obj, int, level);
|
||||
S2J_STRUCT_GET_STRING_ELEMENT_N(log_file, json_obj, path, MAX_PATH_SZ);
|
||||
s2j_struct_get_basic_element(log_file, json_obj, int, is_compress);
|
||||
s2j_struct_get_basic_element(log_file, json_obj, int, del_over_days);
|
||||
S2J_STRUCT_GET_STRING_ELEMENT_N(log_file, json_obj, del_over_size, MAX_U64_SZ);
|
||||
|
||||
memcpy(config_buff, log_file, sizeof(log_file_t));
|
||||
|
||||
s2j_delete_struct_obj(json_obj);
|
||||
cJSON_Delete(json_obj);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,14 @@
|
|||
#include "ulog_in.h"
|
||||
#include "s2j/s2j.h"
|
||||
|
||||
#define DEFAULT_REMOTE_HOST 514
|
||||
#define DEFAULT_REMOTE_HOST_PORT 514
|
||||
#define MAX_REMOTE_HOST_CNT 8
|
||||
|
||||
|
||||
static int logging_remote_json_parse(pointer input, log_remote_host_x_t *config_buff);
|
||||
static int logging_remote_json_parse_array(pointer input,
|
||||
log_remote_host_x_t *config_buff, int *cnt);
|
||||
static int logging_remote_level_json_parse(pointer input, log_remote_level_t *config_buff);
|
||||
|
||||
static log_rfc_t get_rfc_by_name(const char *name)
|
||||
{
|
||||
|
@ -20,22 +27,69 @@ static log_rfc_t get_rfc_by_name(const char *name)
|
|||
|
||||
static int conf_remote_by_config_id(cJSON *json_obj, const char *host, const u16 port, const log_rfc_t rfc, uint64 config_id)
|
||||
{
|
||||
log_remote_host_t remote;
|
||||
log_remote_host_x_t remote = {0};
|
||||
char *json_output = NULL;
|
||||
int config_type = CM_CONFIG_SET;
|
||||
|
||||
if (LOG_CONFIG_REMOTE_GET_HOST == config_id)
|
||||
{
|
||||
if (NULL == host || '\0' == host[0])
|
||||
{
|
||||
config_type = CM_CONFIG_GET_ALL;
|
||||
}
|
||||
else
|
||||
{
|
||||
config_type = CM_CONFIG_GET;
|
||||
strncpy(remote.host, host, sizeof(remote.host));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
config_type = CM_CONFIG_SET;
|
||||
strncpy(remote.host, host, sizeof(remote.host));
|
||||
remote.port = port;
|
||||
remote.rfc = rfc;
|
||||
}
|
||||
|
||||
s2j_json_set_basic_element(json_obj, &remote, int, port);
|
||||
s2j_json_set_basic_element(json_obj, &remote, int, rfc);
|
||||
s2j_json_set_basic_element(json_obj, &remote, string, host);
|
||||
s2j_json_set_basic_element(json_obj, &remote, int, level);
|
||||
|
||||
int ret = set_log_conf(json_obj, config_id);
|
||||
int ret = set_log_conf(config_type, json_obj, config_id, &json_output);
|
||||
if (ret != 0) {
|
||||
ULOG_ERR(g_log, "Host of log which is configured is failure");
|
||||
} else {
|
||||
ULOG_DEBUG(g_log, "Host of log whice is configured is success");
|
||||
}
|
||||
|
||||
if (LOG_CONFIG_REMOTE_GET_HOST == config_id)
|
||||
{
|
||||
if (CM_CONFIG_GET_ALL == config_type )
|
||||
{
|
||||
log_remote_host_x_t remotes_out[MAX_REMOTE_HOST_CNT] = {0};
|
||||
int cnt = 0;
|
||||
if (logging_remote_json_parse_array(json_output, remotes_out, &cnt) == 0)
|
||||
{
|
||||
for (int i=0; i<cnt; i++)
|
||||
{
|
||||
ULOG_DEBUG(g_log, "Log host get: host[%d]: addr=%s, port=%u, log_fmt=%u, level=%u",
|
||||
i, remotes_out[i].host, remotes_out[i].port, remotes_out[i].rfc, remotes_out[i].level);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log_remote_host_x_t remote_out = {0};
|
||||
if (logging_remote_json_parse(json_output, &remote_out) == 0)
|
||||
{
|
||||
ULOG_DEBUG(g_log, "Log host get: addr=%s, port=%u, log_fmt=%u, level=%u",
|
||||
remote_out.host, remote_out.port, remote_out.rfc, remote_out.level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -44,7 +98,7 @@ int conf_remote(cJSON *json_obj, int argc, char **argv)
|
|||
int ret = -1;
|
||||
uint64 config_id;
|
||||
|
||||
if (argc <= 3) {
|
||||
if (argc < 3) {
|
||||
ULOG_WARNING(g_log, "Parameter too less");
|
||||
return ret;
|
||||
}
|
||||
|
@ -53,13 +107,19 @@ int conf_remote(cJSON *json_obj, int argc, char **argv)
|
|||
config_id = LOG_CONFIG_REMOTE_ADD_HOST;
|
||||
} else if (strcasecmp(argv[2], "del") == 0) {
|
||||
config_id = LOG_CONFIG_REMOTE_DEL_HOST;
|
||||
} else if (strcasecmp(argv[2], "get") == 0
|
||||
|| strcasecmp(argv[2], "getall") == 0) {
|
||||
config_id = LOG_CONFIG_REMOTE_GET_HOST;
|
||||
} else {
|
||||
ULOG_WARNING(g_log, "Unknown operation command:%s", argv[2]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *host = argv[3];
|
||||
u16 port = DEFAULT_REMOTE_HOST;
|
||||
char *host = NULL;
|
||||
if (argc >= 4) {
|
||||
host = argv[3];
|
||||
}
|
||||
u16 port = DEFAULT_REMOTE_HOST_PORT;
|
||||
if (argc >= 5) {
|
||||
port= atoi(argv[4]);
|
||||
}
|
||||
|
@ -77,29 +137,178 @@ int conf_remote(cJSON *json_obj, int argc, char **argv)
|
|||
|
||||
int conf_remote_level(cJSON *json_obj, int argc, char **argv)
|
||||
{
|
||||
int level;
|
||||
log_remote_level_t log_level = {0};
|
||||
log_remote_level_t log_level_out = {0};
|
||||
uint config_type = CM_CONFIG_SET;
|
||||
char*json_output = NULL;
|
||||
|
||||
if (argc < 3) {
|
||||
ULOG_WARNING(g_log, "Not input log level");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int level;
|
||||
if (argc == 3 && strstr(argv[2], "get") != NULL) {
|
||||
config_type = CM_CONFIG_GET;
|
||||
}
|
||||
else {
|
||||
config_type = CM_CONFIG_SET;
|
||||
|
||||
if ((level = log_str_to_level(argv[2])) < 0) {
|
||||
ULOG_WARNING(g_log, "Unknown log level:%s", argv[2]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
log_remote_level_t log_level;
|
||||
|
||||
log_level.level = (u8)level;
|
||||
}
|
||||
|
||||
s2j_json_set_basic_element(json_obj, &log_level, int, level);
|
||||
int ret = set_log_conf(json_obj, LOG_CONFIG_REMOTE_LEVEL);
|
||||
int ret = set_log_conf(config_type, json_obj, LOG_CONFIG_REMOTE_LEVEL, &json_output);
|
||||
if (ret != 0) {
|
||||
ULOG_ERR(g_log, "Remote level of log which is configured is failure");
|
||||
} else {
|
||||
ULOG_DEBUG(g_log, "Remote level of log whice is configured is success");
|
||||
}
|
||||
|
||||
if (CM_CONFIG_GET == config_type) {
|
||||
logging_remote_level_json_parse(json_output, &log_level_out);
|
||||
|
||||
ULOG_DEBUG(g_log, "Log level get: level=%u", log_level_out.level);
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static int logging_remote_json_parse(pointer input, log_remote_host_x_t *config_buff)
|
||||
{
|
||||
cJSON *json_obj;
|
||||
|
||||
if (NULL == config_buff)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
json_obj = cJSON_Parse(input);
|
||||
if(!json_obj)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ULOG_DEBUG(g_log, "remote json parse, json input:%s \n", cJSON_Print(json_obj));
|
||||
|
||||
s2j_create_struct_obj(log_host_x, log_remote_host_x_t);
|
||||
|
||||
if(log_host_x == NULL)
|
||||
{
|
||||
cJSON_Delete(json_obj);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s2j_struct_get_basic_element(log_host_x, json_obj, int, port);
|
||||
s2j_struct_get_basic_element(log_host_x, json_obj, int, rfc);
|
||||
S2J_STRUCT_GET_STRING_ELEMENT_N(log_host_x, json_obj, host, LOG_HOST_SZ);
|
||||
s2j_struct_get_basic_element(log_host_x, json_obj, int, level);
|
||||
|
||||
memcpy(config_buff, log_host_x, sizeof(log_remote_host_x_t));
|
||||
|
||||
s2j_delete_struct_obj(json_obj);
|
||||
cJSON_Delete(json_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int logging_remote_json_parse_array(pointer input,
|
||||
log_remote_host_x_t *config_buff, int *cnt)
|
||||
{
|
||||
cJSON *json_obj;
|
||||
cJSON* p_array;
|
||||
int json_cnt = 0, i = 0;
|
||||
int used_cnt = 0;
|
||||
|
||||
json_obj = cJSON_Parse(input);
|
||||
if(!json_obj)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ULOG_DEBUG(g_log, "remote json parse array, json input:%s \n", cJSON_Print(json_obj));
|
||||
|
||||
json_cnt = cJSON_GetArraySize(json_obj);
|
||||
if (json_cnt > MAX_REMOTE_HOST_CNT)
|
||||
{
|
||||
used_cnt = MAX_REMOTE_HOST_CNT;
|
||||
}
|
||||
else
|
||||
{
|
||||
used_cnt = json_cnt;
|
||||
}
|
||||
|
||||
s2j_create_struct_obj(log_host_x, log_remote_host_x_t);
|
||||
if(log_host_x == NULL)
|
||||
{
|
||||
cJSON_Delete(json_obj);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*cnt = 0;
|
||||
for (i = 0; i < used_cnt; i++)
|
||||
{
|
||||
p_array = cJSON_GetArrayItem(json_obj, i);
|
||||
if (p_array)
|
||||
{
|
||||
memset(log_host_x, 0, sizeof(log_remote_host_x_t));
|
||||
|
||||
s2j_struct_get_basic_element(log_host_x, p_array, int, port);
|
||||
s2j_struct_get_basic_element(log_host_x, p_array, int, rfc);
|
||||
s2j_struct_get_basic_element(log_host_x, p_array, string, host);
|
||||
s2j_struct_get_basic_element(log_host_x, p_array, int, level);
|
||||
|
||||
memcpy(config_buff+*cnt, log_host_x, sizeof(log_remote_host_x_t));
|
||||
(*cnt)++;
|
||||
}
|
||||
}
|
||||
|
||||
s2j_delete_struct_obj(log_host_x);
|
||||
cJSON_Delete(json_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int logging_remote_level_json_parse(pointer input, log_remote_level_t *config_buff)
|
||||
{
|
||||
cJSON *json_obj;
|
||||
|
||||
if (NULL == config_buff)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
json_obj = cJSON_Parse(input);
|
||||
if (!json_obj)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
s2j_create_struct_obj(log_remote_level, log_remote_level_t);
|
||||
|
||||
if (log_remote_level == NULL)
|
||||
{
|
||||
cJSON_Delete(json_obj);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s2j_struct_get_basic_element(log_remote_level, json_obj, int, level);
|
||||
|
||||
memcpy(config_buff, log_remote_level, sizeof(log_remote_level_t));
|
||||
|
||||
s2j_delete_struct_obj(json_obj);
|
||||
cJSON_Delete(json_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
#include "configmapi.h"
|
||||
#include "ulog/ulog_in.h"
|
||||
|
||||
int set_log_conf(cJSON *json_obj, uint64 config_id)
|
||||
|
||||
|
||||
int set_log_conf(uint config_type, cJSON *json_obj, uint64 config_id, char **json_output)
|
||||
{
|
||||
int ret = -1;
|
||||
char *output;
|
||||
|
@ -18,7 +20,8 @@ int set_log_conf(cJSON *json_obj, uint64 config_id)
|
|||
}
|
||||
|
||||
ULOG_DEBUG(g_log, "Setting log json is %s", json);
|
||||
ret_code ret_c = web_config_exec_sync(CM_CONFIG_SET, config_id,
|
||||
|
||||
ret_code ret_c = web_config_exec_sync(config_type, config_id,
|
||||
json, strlen(json),
|
||||
&output, &output_len);
|
||||
if (ret_c != RET_OK) {
|
||||
|
@ -27,6 +30,16 @@ int set_log_conf(cJSON *json_obj, uint64 config_id)
|
|||
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);
|
||||
}
|
||||
|
@ -34,3 +47,37 @@ int set_log_conf(cJSON *json_obj, uint64 config_id)
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int logging_terminal_json_parse(pointer input, pointer config_buff, uint64 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,11 +13,15 @@
|
|||
|
||||
extern ulog_t *g_log;
|
||||
|
||||
int set_log_conf(cJSON *json_obj, uint64 config_id);
|
||||
int set_log_conf(uint config_type, cJSON *json_obj, uint64 config_id, char **json_output);
|
||||
int logging_terminal_json_parse(pointer input, pointer config_buff, uint64 conf_id);
|
||||
|
||||
#define CONF_TERMINAL(type, json_obj, str_level, on, module_name, conf_id) { \
|
||||
|
||||
#define CONF_TERMINAL(type, config_type, json_obj, str_level, on, module_name, conf_id) { \
|
||||
type terminal = {0}; \
|
||||
type terminal_out = {0}; \
|
||||
int level; \
|
||||
char *json_output = NULL; \
|
||||
\
|
||||
if ((level = log_str_to_level(str_level)) < 0) { \
|
||||
ULOG_WARNING(g_log, "Unknown log level:%s", str_level); \
|
||||
|
@ -34,21 +38,40 @@ int set_log_conf(cJSON *json_obj, uint64 config_id);
|
|||
s2j_json_set_basic_element(json_obj, &terminal, int, on); \
|
||||
s2j_json_set_basic_element(json_obj, &terminal, string, module); \
|
||||
\
|
||||
int ret = set_log_conf(json_obj, conf_id); \
|
||||
int ret = set_log_conf(config_type, json_obj, conf_id, &json_output); \
|
||||
if (ret != 0) { \
|
||||
ULOG_ERR(g_log, "Setting terminal configure of log is failure"); \
|
||||
} else { \
|
||||
ULOG_DEBUG(g_log, "Setting terminal configure of log is success"); \
|
||||
} \
|
||||
\
|
||||
if (CM_CONFIG_GET == config_type) { \
|
||||
if (logging_terminal_json_parse(json_output, &terminal_out, conf_id) == 0) { \
|
||||
if (LOG_ON == terminal_out.on) { \
|
||||
ULOG_DEBUG(g_log, "Log %s get: level=%u, module=%s", \
|
||||
(conf_id == LOG_CONFIG_CONSOLE)?"console":"monitor", \
|
||||
terminal_out.level, \
|
||||
terminal_out.module); \
|
||||
} else { \
|
||||
ULOG_DEBUG(g_log, "Log %s get: off", \
|
||||
(conf_id == LOG_CONFIG_CONSOLE)?"console":"monitor"); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define CMD_PARSE_AND_CONFIG_TERMINAL(type, json_obj, argc, argv, conf_id) { \
|
||||
log_sw_t on = LOG_ON; \
|
||||
char *str_level = DEFAULT_LOG_LEVEL; \
|
||||
uint config_type = CM_CONFIG_SET; \
|
||||
\
|
||||
if (argc >= 3) { \
|
||||
if (strcasecmp(argv[2], "off") == 0) { \
|
||||
on = LOG_OFF; \
|
||||
} else if (strcasecmp(argv[2], "get") == 0) { \
|
||||
config_type = CM_CONFIG_GET; \
|
||||
} else { \
|
||||
str_level = argv[2]; \
|
||||
} \
|
||||
|
@ -59,9 +82,7 @@ int set_log_conf(cJSON *json_obj, uint64 config_id);
|
|||
module = argv[3]; \
|
||||
} \
|
||||
\
|
||||
CONF_TERMINAL(type, json_obj, str_level, on, module, conf_id); \
|
||||
CONF_TERMINAL(type, config_type, json_obj, str_level, on, module, conf_id); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,13 +40,13 @@ int main(int argc, char **argv)
|
|||
{
|
||||
int ret = -1;
|
||||
if (argc < 2) {
|
||||
fprintf(stdout, "Parameter too few");
|
||||
fprintf(stdout, "Parameter too few\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
g_log = ulog_init(LOGGING_MODULE_NAME, 1);
|
||||
if (g_log == NULL) {
|
||||
fprintf(stderr, "Initiating ulog is failure");
|
||||
fprintf(stderr, "Initiating ulog is failure\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ static int trace_recv_handle(struct pdelivnl_ctrl_data *ctrl,
|
|||
case TRACE_CFG_POLICY_REPLY:
|
||||
reply = (trace_reply_t *)NLMSG_DATA(n);
|
||||
if (sizeof(*reply) < (n->nlmsg_len - NLMSG_HDRLEN)) {
|
||||
SYSLOG_WARN("The length of the reply message is required to be %u, but fact length is %u",
|
||||
SYSLOG_WARN("The length of the reply message is required to be %ld, but fact length is %u",
|
||||
sizeof(*reply), (n->nlmsg_len - NLMSG_HDRLEN));
|
||||
break;
|
||||
}
|
||||
|
@ -187,9 +187,9 @@ static trace_ret_t cfg_channel_send(const uint32_t seq, const trace_policy_t *p
|
|||
SYSLOG_DEBUG("Send hdr: is_reply:%d, seq:%u, ver:%u", req.hdr.is_reply, req.hdr.seq, req.hdr.ver);
|
||||
SYSLOG_DEBUG("Send policy:");
|
||||
SYSLOG_DEBUG(" src family:%u, src ip:%02x, sport:%u",
|
||||
req.policy.src.family, req.policy.src.addr.ip4, req.policy.sport);
|
||||
req.policy.src.family, req.policy.src.addr.ip4.s_addr, req.policy.sport);
|
||||
SYSLOG_DEBUG(" dst family:%u, dst ip:%02x, dport:%u",
|
||||
req.policy.dst.family, req.policy.dst.addr.ip4, req.policy.dport);
|
||||
req.policy.dst.family, req.policy.dst.addr.ip4.s_addr, req.policy.dport);
|
||||
SYSLOG_DEBUG(" protocol:%u, app_type:%u", req.policy.protocol, req.policy.app_type);
|
||||
|
||||
/*发送组装好的netlink消息*/
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "ulog.h"
|
||||
#include "log_common.h"
|
||||
#include "ulog_in.h"
|
||||
#include "sev_sched.h"
|
||||
|
||||
#define FILTER_CONTENT ":msg,contains,\""MODULE_FMT"\"\n"
|
||||
#define DEFAULT_CONFIG_FILE_TMP "/etc/log-sched.conf.tmp"
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define REDIRECT_SEPERATE " "
|
||||
|
||||
typedef int (*rpc_cb)(pointer *input, const void *arg, char *str_err, int str_len);
|
||||
typedef int (*rpc_cb)(pointer input, const void *arg, char *str_err, int str_len);
|
||||
|
||||
extern ulog_t *g_log;
|
||||
extern FILE *g_conf_fp;
|
||||
|
|
|
@ -247,7 +247,7 @@ static int del_remote_host(const log_remote_host_t *conf)
|
|||
strcat(prefix, "@");
|
||||
};
|
||||
char redirect[MAX_LINE_SZ];
|
||||
if (snprintf(redirect, sizeof(redirect), "%s@%s:%u:%s",
|
||||
if (snprintf(redirect, sizeof(redirect), "%s@%s:%u;%s",
|
||||
prefix, conf->host, conf->port, rfc_tbl[conf->rfc].fmt) < 0) {
|
||||
ULOG_ERR(g_log, "Setting remote redirect[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
||||
return ret;
|
||||
|
@ -347,7 +347,7 @@ static int __rpc_conf_log_remote(pointer input, const void *arg, char *str_err,
|
|||
log_op_t op;
|
||||
memcpy(&op, arg, sizeof(op));
|
||||
|
||||
int ret = config_log_remote_host(op, (const log_remote_level_t *)input);
|
||||
int ret = config_log_remote_host(op, (const log_remote_host_t *)input);
|
||||
if (ret < 0) {
|
||||
strncpy(str_err, "Configuring remote of log is faiure", str_len);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include "log_common.h"
|
||||
#include "ulog_api.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#define SEV_TIMEOUT 1
|
||||
#define SEV_CMD "systemctl restart rsyslog"
|
||||
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
#!/bin/bash
|
||||
|
||||
# 本脚本功能:
|
||||
# 1. 从logrotate配置文件中取出日志文件的路径(所有日志文件均以logrotate配置文件中第一行指示的路径为前缀),
|
||||
# 2. 从log_sched配置文件中取出日志文件大小上限
|
||||
# 3. 计算步骤1指示的日志文件的总大小,检测日志总大小是否超出上限,若超出则删除所有日志文件
|
||||
|
||||
function deal_logs ()
|
||||
{
|
||||
|
||||
# logrotate配置文件路径
|
||||
logrotate_log_file="/etc/logrotate.d/log-syslog"
|
||||
|
||||
#log_sched配置文件路径
|
||||
log_sched_file="/etc/log-sched.conf"
|
||||
|
||||
# 日志文件前缀
|
||||
prefix=
|
||||
|
||||
# 日志大小上限
|
||||
size_max=0
|
||||
|
||||
echo "**********************************************************"
|
||||
echo " logrotate_cfg: $logrotate_log_file"
|
||||
echo " log_sched_cfg: $log_sched_file"
|
||||
echo "**********************************************************"
|
||||
echo ""
|
||||
|
||||
# logrotate配置文件判空
|
||||
if [ ! -e $logrotate_log_file ] ; then
|
||||
return
|
||||
fi
|
||||
|
||||
# 从logrotate配置文件中第一行有效行中读取出日志文件前缀
|
||||
while read line
|
||||
do
|
||||
if [ -z $line ] ; then
|
||||
continue
|
||||
fi
|
||||
|
||||
prefix=$line;
|
||||
echo "**********************************************************"
|
||||
echo " get log-file-prefix: $prefix"
|
||||
echo "**********************************************************"
|
||||
echo ""
|
||||
|
||||
break
|
||||
done < $logrotate_log_file
|
||||
|
||||
if [ -z $prefix ] ; then
|
||||
echo "get log file failed"
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
# log_sched配置文件判空
|
||||
if [ ! -e $log_sched_file ] ; then
|
||||
return
|
||||
fi
|
||||
|
||||
#从log_sched配置文件中读取出日志大小上限值
|
||||
while read line
|
||||
do
|
||||
tmpkey="file.max_size="
|
||||
|
||||
if [[ $line = *$tmpkey* ]] ; then
|
||||
if [[ $line = $tmpkey ]] ; then
|
||||
echo "size_max is empty, do nothing and return"
|
||||
return
|
||||
fi
|
||||
|
||||
size_max=${line#$tmpkey}
|
||||
echo "**********************************************************"
|
||||
echo " get size_max: $size_max"
|
||||
echo "**********************************************************"
|
||||
echo ""
|
||||
|
||||
break
|
||||
fi
|
||||
done < $log_sched_file
|
||||
|
||||
|
||||
if [ $size_max -eq 0 ] ; then
|
||||
echo "size_max is 0, do nothing and return"
|
||||
return
|
||||
fi
|
||||
|
||||
#定期检查日志总大小是否超限
|
||||
path=$prefix*
|
||||
echo " get path: $path"
|
||||
|
||||
folder_size=$(wc -c $path|grep total |awk '{print $1}')
|
||||
if [ -z $folder_size ] ; then
|
||||
folder_size=0
|
||||
fi
|
||||
|
||||
echo "cursize: $folder_size"
|
||||
echo "maxsize: $size_max"
|
||||
|
||||
if [ $folder_size -gt $size_max ] ; then
|
||||
echo "flush folder $path"
|
||||
rm -rf $path
|
||||
sync
|
||||
fi
|
||||
}
|
||||
|
||||
deal_logs $@
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
# /etc/rsyslog.conf Configuration file for rsyslog.
|
||||
#
|
||||
# For more information see
|
||||
# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
|
||||
#
|
||||
# Default logging rules can be found in /etc/rsyslog.d/50-default.conf
|
||||
|
||||
|
||||
#################
|
||||
#### MODULES ####
|
||||
#################
|
||||
|
||||
module(load="imuxsock") # provides support for local system logging
|
||||
#module(load="immark") # provides --MARK-- message capability
|
||||
|
||||
# provides UDP syslog reception
|
||||
#module(load="imudp")
|
||||
#input(type="imudp" port="514")
|
||||
|
||||
# provides TCP syslog reception
|
||||
#module(load="imtcp")
|
||||
#input(type="imtcp" port="514")
|
||||
|
||||
# provides kernel logging support and enable non-kernel klog messages
|
||||
module(load="imklog" permitnonkernelfacility="on")
|
||||
|
||||
###########################
|
||||
#### GLOBAL DIRECTIVES ####
|
||||
###########################
|
||||
|
||||
#
|
||||
# Use traditional timestamp format.
|
||||
# To enable high precision timestamps, comment out the following line.
|
||||
#
|
||||
|
||||
template(name="RFC3164fmt" type="string" string="<%PRI%>%timestamp:::date-rfc3164% %hostname% %syslogtag%%msg%\n")
|
||||
template(name="RFC5424fmt" type="string" string="<%PRI%>%protocol-version% %timestamp:::date-rfc3339% %hostname% %app-name% %procid% %structured-data% %msgid%%msg%\n")
|
||||
|
||||
|
||||
$ActionFileDefaultTemplate RFC5424fmt
|
||||
|
||||
# Filter duplicated messages
|
||||
$RepeatedMsgReduction on
|
||||
|
||||
#
|
||||
# Set the default permissions for all log files.
|
||||
#
|
||||
$FileOwner syslog
|
||||
$FileGroup adm
|
||||
$FileCreateMode 0640
|
||||
$DirCreateMode 0755
|
||||
$Umask 0022
|
||||
$PrivDropToUser syslog
|
||||
$PrivDropToGroup syslog
|
||||
|
||||
#
|
||||
# Where to place spool and state files
|
||||
#
|
||||
$WorkDirectory /var/spool/rsyslog
|
||||
|
||||
#
|
||||
# Include all config files in /etc/rsyslog.d/
|
||||
#
|
||||
$IncludeConfig /etc/rsyslog.d/*.conf
|
|
@ -38,6 +38,8 @@ typedef enum { WEBM_HANDLE_INVALID_INDEX = -1,
|
|||
WEBM_HANDLE_CONFIG_UUID_USER,
|
||||
WEBM_HANDLE_CONFIG_DETAIL_USER,
|
||||
WEBM_HANDLE_CONFIG_IPV4,
|
||||
WEBM_HANDLE_CONFIG_VLAN_SET,
|
||||
WEBM_HANDLE_CONFIG_VLAN_GET,
|
||||
WEBM_HANDLE_MAX
|
||||
} webm_handle_index;
|
||||
|
||||
|
@ -169,6 +171,20 @@ extern int webm_config_send_proc(server *srv, uint32_t config_type, uint64 confg
|
|||
CM_CONFIG_SET, \
|
||||
IPCONFIG_V4, \
|
||||
webm_config_send_proc \
|
||||
}, \
|
||||
{\
|
||||
WEBM_HANDLE_CONFIG_VLAN_SET, \
|
||||
"/FSG-CF/setvlan", \
|
||||
CM_CONFIG_SET, \
|
||||
VLAN_CONFIG, \
|
||||
webm_config_send_proc \
|
||||
}, \
|
||||
{\
|
||||
WEBM_HANDLE_CONFIG_VLAN_GET, \
|
||||
"/FSG-GF/getvlan", \
|
||||
CM_CONFIG_GET, \
|
||||
VLAN_CONFIG, \
|
||||
webm_config_send_proc \
|
||||
} \
|
||||
\
|
||||
}
|
||||
|
|
|
@ -17,15 +17,18 @@ if(PLAT_ARM64)
|
|||
SET(CMAKE_SYSTEM_NAME Linux)
|
||||
#this one not so much
|
||||
SET(CMAKE_SYSTEM_VERSION 1)
|
||||
# this is install root directory
|
||||
SET(CMAKE_INSTALL_PREFIX /usr)
|
||||
|
||||
# specify the cross compiler
|
||||
SET(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
|
||||
SET(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
|
||||
SET(CMAKE_STRIP aarch64-fsl-linux-strip)
|
||||
SET(CMAKE_STRIP aarch64-linux-gnu-strip)
|
||||
|
||||
# specify the cross compile and link flags
|
||||
# set(CMAKE_C_FLAGS "--sysroot=$ENV{SDKTARGETSYSROOT}")
|
||||
# set(CMAKE_SHARED_LINKER_FLAGS "--sysroot=$ENV{SDKTARGETSYSROOT}")
|
||||
set(CMAKE_C_FLAGS "--sysroot=$ENV{SDKTARGETSYSROOT}")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "--sysroot=$ENV{SDKTARGETSYSROOT}")
|
||||
SET(CMAKE_LIBRARY_PATH $ENV{SDKTARGETSYSROOT}/usr/lib)
|
||||
|
||||
# where is the target environment
|
||||
SET(CMAKE_FIND_ROOT_PATH ${SDKTARGETSYSROOT})
|
||||
|
|
Loading…
Reference in New Issue