#include #include #include #include #include #include #include #include #include "scanner_toml.h" static toml_table_t *toml_open(struct logger *logger, const char *toml_path) { FILE *fp=fopen(toml_path, "r"); if (NULL==fp) { STELLAR_LOG_FATAL(logger, EXPORTER_MODULE_NAME, "toml_bool_get can't open config file: %s", toml_path); return NULL; } char errbuf[256]={0}; toml_table_t *root=toml_parse_file(fp, errbuf, sizeof(errbuf)); fclose(fp); return root; } static void toml_close(struct toml_table_t *root) { toml_free(root); } void toml_string_get1(struct logger *logger, const char *toml_path, const char *table_key, const char *key, char **value, size_t *value_sz) { toml_table_t *root=toml_open(logger, toml_path); if(NULL==root) { return ; } toml_table_t *table=toml_table_in(root, table_key); if(NULL==table) { STELLAR_LOG_FATAL(logger, EXPORTER_MODULE_NAME, "toml_string_get can't find key: [%s] in config file: %s", table_key, toml_path); toml_close(root); return ; } toml_datum_t val=toml_string_in(table, key); if(val.ok>0) { *value=strdup(val.u.s); if(value_sz!=NULL) { strlen(*value); } free(val.u.s); } toml_close(root); } void kafka_parameter_get(struct logger *logger, const char *toml_path, const char *table_key, struct kafka_parameter *para) { toml_string_get1(logger, toml_path, table_key, "broker_list", ¶->broker_list, NULL); toml_string_get1(logger, toml_path, table_key, "sasl_username", ¶->sasl_username, NULL); toml_string_get1(logger, toml_path, table_key, "sasl_passwd", ¶->sasl_passwd, NULL); toml_string_get1(logger, toml_path, table_key, "compression", ¶->compression, NULL); toml_string_get1(logger, toml_path, table_key, "require_ack", ¶->require_ack, NULL); toml_string_get1(logger, toml_path, table_key, "send_queue_max_msg", ¶->send_queue_max_msg, NULL); toml_string_get1(logger, toml_path, table_key, "refresh_interval_ms", ¶->refresh_interval_ms, NULL); toml_close(root); }