#include #include #include #include #include #include "log_remote.h" #include "log_common.h" #define LOG_CONF_REMOTE_FILE_NAME "log-remote.conf" typedef struct _rfc_key_fmt { log_rfc_t rfc; char fmt[20]; } rfc_key_fmt; static rfc_key_fmt rfc_tbl[] = { {LOG_RFC_3164, "RFC3164fmt"}, {LOG_RFC_5424, "RFC5424fmt"} }; static int match_line(const log_remote_host_t *conf) { } static int remote_conf_content(FILE *fp, const u8 level, const char *filter_mod, void *arg) { int ret = 1; FILE *bak_fp = NULL; char path[MAX_PATH_SZ]; snprintf(path, sizeof(path), BAK_FILE, LOG_CONF_REMOTE_FILE_NAME); bak_fp = fopen(bak_fp, "r"); if (bak_fp == NULL) { ULOG_ERR(g_log, "Opening remote back file:%s is failure:%s", path, strerror(errno)); return 1; } char *line = NULL; ssize_t n, n1; char *pad, *host, *rfc_fmt; u16 port; while ((n = getline(&line, &n, bak_fp)) != -1) { n1 = sscanf(line, "%s"REDIRECT_SEPERATE"%s:%u:%s", &pad, &host, &port, &rfc_fmt); if (n1 == 4) { // 匹配到 } if (errno != 0) { // 错误发生 } else { // 未知行,跳过 continue; } if (write_conf_content(fp, level, filter_mod, arg) != 0) { ULOG_ERR(g_log, "Write remote configure is failure"); goto END; } } ret = 0; END: if (line != NULL) { free(line); } if (bak_fp != NULL) { fclose(bak_fp); } return ret; } static int add_remote_host(const log_remote_host_t *conf) { char prefix[1] = ""; if (conf->rfc == LOG_RFC_5424) { strcat(prefix, "@"); }; char redirect[MAX_LINE_SZ]; 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 1; } if (log_conf_append(7, LOG_CONF_PATH, LOG_CONF_REMOTE_FILE_NAME, NULL, write_conf_content, (void *)redirect) != 0) { ULOG_ERR(g_log, "Adding remote server[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt); return 1; } return 0; } static int del_remote_host(const log_remote_host_t *conf) { } static int config_log_remote_host(const log_remote_host_t *conf) { if ((sizeof(rfc_tbl) / sizeof(rfc_key_fmt)) < conf->rfc) { ULOG_WARNING(g_log, "Unknown rfc format key:%u", conf->rfc); return 1; } return 0; } void rpc_conf_log_remote(rpc_conn *conn, pointer input, int input_len, pointer data) { u32 need_len = sizeof(log_remote_host_t); if (input_len < need_len) { ULOG_WARNING(g_log, "The input paramter of rpc log remote host is needed length of %u, but the actual length is %u", need_len, input_len); return; } config_log_remote_host((const log_remote_host_t *)input); }