diff --git a/conf/log.toml b/conf/log.toml index 64b5fea..a51abd8 100644 --- a/conf/log.toml +++ b/conf/log.toml @@ -1,4 +1,4 @@ [log] -output = file # stderr, file -file = "log/stellar.log" -level = FATAL # TRACE, DEBUG, INFO, WARN, ERROR, FATAL +output = "stderr" # stderr, file +file = "log/stellar.log" +level = "ERROR" # TRACE, DEBUG, INFO, WARN, ERROR, FATAL diff --git a/conf/stellar.toml b/conf/stellar.toml index 275294a..708acc0 100644 --- a/conf/stellar.toml +++ b/conf/stellar.toml @@ -3,9 +3,9 @@ snowflake_base = 1 # [0, 31] snowflake_offset = 2 # [0, 127] [packet_io] -mode = dumpfile # dumpfile, dumpfilelist, marsio -app_symbol = stellar -dev_symbol = nf_0_fw +mode = "dumpfile" # dumpfile, dumpfilelist, marsio +app_symbol = "stellar" +dev_symbol = "nf_0_fw" dumpfile_path = "/tmp/dumpfile/dumpfile.pcap" #dumpfile_path = "/tmp/dumpfile/dumpfilelist" diff --git a/src/core/stellar_config.cpp b/src/core/stellar_config.cpp index 15806cb..f30c1a8 100644 --- a/src/core/stellar_config.cpp +++ b/src/core/stellar_config.cpp @@ -46,6 +46,7 @@ static int parse_snowflake_section(toml_table_t *root, struct snowflake_options // retuun -1: failed static int parse_packet_io_section(toml_table_t *root, struct packet_io_options *opts) { + char *temp; const char *ptr; toml_table_t *table; toml_array_t *mask_array; @@ -58,20 +59,21 @@ static int parse_packet_io_section(toml_table_t *root, struct packet_io_options } ptr = toml_raw_in(table, "mode"); - if (ptr == NULL) + temp = NULL; + if (ptr == NULL || toml_rtos(ptr, &temp) != 0) { CONFIG_LOG_ERROR("config file missing packet_io->mode"); return -1; } - if (strcmp(ptr, "dumpfile") == 0) + if (strcmp(temp, "dumpfile") == 0) { opts->mode = PACKET_IO_DUMPFILE; } - else if (strcmp(ptr, "dumpfilelist") == 0) + else if (strcmp(temp, "dumpfilelist") == 0) { opts->mode = PACKET_IO_DUMPFILELIST; } - else if (strcmp(ptr, "marsio") == 0) + else if (strcmp(temp, "marsio") == 0) { opts->mode = PACKET_IO_MARSIO; } @@ -84,31 +86,33 @@ static int parse_packet_io_section(toml_table_t *root, struct packet_io_options if (opts->mode == PACKET_IO_DUMPFILE || opts->mode == PACKET_IO_DUMPFILELIST) { ptr = toml_raw_in(table, "dumpfile_path"); - if (ptr == NULL) + temp = NULL; + if (ptr == NULL || toml_rtos(ptr, &temp) != 0) { CONFIG_LOG_ERROR("config file missing packet_io->dumpfile_path"); return -1; } - // skip "" - strncpy(opts->dumpfile_path, ptr + 1, strlen(ptr) - 2); + strcpy(opts->dumpfile_path, temp); } else { ptr = toml_raw_in(table, "app_symbol"); - if (ptr == NULL) + temp = NULL; + if (ptr == NULL || toml_rtos(ptr, &temp) != 0) { CONFIG_LOG_ERROR("config file missing packet_io->app_symbol"); return -1; } - strncpy(opts->app_symbol, ptr, sizeof(opts->app_symbol) - 1); + strcpy(opts->app_symbol, temp); ptr = toml_raw_in(table, "dev_symbol"); - if (ptr == NULL) + temp = NULL; + if (ptr == NULL || toml_rtos(ptr, &temp) != 0) { CONFIG_LOG_ERROR("config file missing packet_io->dev_symbol"); return -1; } - strncpy(opts->dev_symbol, ptr, sizeof(opts->dev_symbol) - 1); + strcpy(opts->dev_symbol, temp); } ptr = toml_raw_in(table, "nr_threads"); diff --git a/src/log/log.cpp b/src/log/log.cpp index 7ed4ab2..a72e498 100644 --- a/src/log/log.cpp +++ b/src/log/log.cpp @@ -99,6 +99,7 @@ static int parse_config(struct log_config *config, const char *cfg_file) int ret = -1; FILE *fp = NULL; char errbuf[200]; + char *temp; const char *ptr; toml_table_t *log_section = NULL; toml_table_t *conf_table = NULL; @@ -126,16 +127,17 @@ static int parse_config(struct log_config *config, const char *cfg_file) // output ptr = toml_raw_in(log_section, "output"); - if (ptr == NULL) + temp = NULL; + if (ptr == NULL || toml_rtos(ptr, &temp) != 0) { fprintf(stderr, "config file %s missing log.output\n", cfg_file); goto error_out; } - if (strcasecmp(ptr, "stderr") == 0) + if (strcasecmp(temp, "stderr") == 0) { config->output = LOG_OUTPUT_STDERR; } - else if (strcasecmp(ptr, "file") == 0) + else if (strcasecmp(temp, "file") == 0) { config->output = LOG_OUTPUT_FILE; } @@ -149,23 +151,24 @@ static int parse_config(struct log_config *config, const char *cfg_file) if (config->output == LOG_OUTPUT_FILE) { ptr = toml_raw_in(log_section, "file"); - if (ptr == NULL) + temp = NULL; + if (ptr == NULL || toml_rtos(ptr, &temp) != 0) { fprintf(stderr, "config file %s missing log.file\n", cfg_file); goto error_out; } - // skip "" - strncpy(config->log_file, ptr + 1, strlen(ptr) - 2); + strcpy(config->log_file, temp); } // level ptr = toml_raw_in(log_section, "level"); - if (ptr == NULL) + temp = NULL; + if (ptr == NULL || toml_rtos(ptr, &temp) != 0) { fprintf(stderr, "config file %s missing log.level\n", cfg_file); goto error_out; } - config->level = check_level(ptr); + config->level = check_level(temp); if (config->level == LOG_NONE) { fprintf(stderr, "config file %s invalid log.level\n", cfg_file); diff --git a/src/log/test/conf/log_file.toml b/src/log/test/conf/log_file.toml index f423a38..f604db0 100644 --- a/src/log/test/conf/log_file.toml +++ b/src/log/test/conf/log_file.toml @@ -1,4 +1,4 @@ [log] -output = file # stderr, file -file = stellar.log -level = DEBUG # TRACE, DEBUG, INFO, WARN, ERROR, FATAL +output = "file" # stderr, file +file = "stellar.log" +level = "DEBUG" # TRACE, DEBUG, INFO, WARN, ERROR, FATAL diff --git a/src/log/test/conf/log_stderr.toml b/src/log/test/conf/log_stderr.toml index dda2a3d..59813c9 100644 --- a/src/log/test/conf/log_stderr.toml +++ b/src/log/test/conf/log_stderr.toml @@ -1,4 +1,4 @@ [log] -output = stderr # stderr, file -file = stellar.log -level = DEBUG # TRACE, DEBUG, INFO, WARN, ERROR, FATAL +output = "stderr" # stderr, file +file = "stellar.log" +level = "DEBUG" # TRACE, DEBUG, INFO, WARN, ERROR, FATAL diff --git a/test/packet_inject/conf/log.toml b/test/packet_inject/conf/log.toml index 8f155c0..a50d2f5 100644 --- a/test/packet_inject/conf/log.toml +++ b/test/packet_inject/conf/log.toml @@ -1,4 +1,4 @@ [log] -output = stderr # stderr, file -level = DEBUG # TRACE, DEBUG, INFO, WARN, ERROR, FATAL +output = "stderr" # stderr, file +level = "DEBUG" # TRACE, DEBUG, INFO, WARN, ERROR, FATAL file = "log/stellar.log" diff --git a/test/packet_inject/conf/stellar.toml b/test/packet_inject/conf/stellar.toml index d200ceb..9a98991 100644 --- a/test/packet_inject/conf/stellar.toml +++ b/test/packet_inject/conf/stellar.toml @@ -3,9 +3,9 @@ snowflake_base = 1 # [0, 31] snowflake_offset = 2 # [0, 127] [packet_io] -mode = marsio # dumpfile, dumpfilelist, marsio -app_symbol = stellar -dev_symbol = nf_0_fw +mode = "dumpfile" # dumpfile, dumpfilelist, marsio +app_symbol = "stellar" +dev_symbol = "nf_0_fw" dumpfile_path = "/tmp/dumpfile/dumpfile.pcap" #dumpfile_path = "/tmp/dumpfile/dumpfilelist"