[AC_MSG_ERROR([unable to find the d2i_X509_bio() function])]
)
+AC_SEARCH_LIBS([toml_parse], [toml], [],
+ [AC_MSG_ERROR([unable to find the toml_parse() function])]
+)
+
# Check dependencies.
PKG_CHECK_MODULES([CHECK], [check])
rpki_validator_SOURCES += state.h state.c
rpki_validator_SOURCES += thread_var.h thread_var.c
rpki_validator_SOURCES += uri.h uri.c
+rpki_validator_SOURCES += config.h config.c
rpki_validator_SOURCES += rsync/rsync.h rsync/rsync.c
--- /dev/null
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <toml.h>
+
+#include "file.h"
+#include "log.h"
+#include "thread_var.h"
+#include "uri.h"
+
+
+static void
+print_config(struct rpki_config *config)
+{
+ pr_debug("Program configuration");
+ pr_debug_add("{");
+ pr_debug("%s: %s", "local_repository",
+ config->local_repository);
+ pr_debug("%s: %s", "tal.file", config->tal);
+ pr_debug("%s: %s", "enable_rsync",
+ config->enable_rsync ? "true" : "false");
+ pr_debug("%s: %s", "tal.shuffle_uris",
+ config->shuffle_uris ? "true" : "false");
+ pr_debug_rm("}");
+}
+
+static int
+handle_tal_table(struct toml_table_t *tal, struct rpki_config *config)
+{
+ const char *result;
+ int error, bool_result;
+
+ result = toml_raw_in(tal, "file");
+ if (result != 0) {
+ pr_debug("tal.file raw string %s", result);
+ error = toml_rtos(result, &config->tal);
+ if (error)
+ return pr_err("Bad value in '%s'", "file");
+ }
+
+ result = toml_raw_in(tal, "shuffle_uris");
+ if (result != 0) {
+ pr_debug("Boolean %s", result);
+
+ error = toml_rtob(result, &bool_result);
+ if (error)
+ return pr_err("Bad value in '%s'", "shuffle_uris");
+ config->shuffle_uris = bool_result;
+ }
+
+ return 0;
+}
+
+static int
+toml_to_config(struct toml_table_t *root, struct rpki_config *config)
+{
+ struct toml_table_t *tal;
+ const char *result;
+ int error, bool_result;
+
+ result = toml_raw_in(root, "local_repository");
+ if (result != 0) {
+ error = toml_rtos(result, &config->local_repository);
+ if (error)
+ return pr_err("Bad value in '%s'", "local_repository");
+ }
+
+ result = toml_raw_in(root, "enable_rsync");
+ if (result != 0) {
+ error = toml_rtob(result, &bool_result);
+ if (error)
+ return pr_err("Bad value in '%s'", "enable_rsync");
+ config->enable_rsync = bool_result;
+ }
+
+ tal = toml_table_in(root, "tal");
+ if (tal != 0)
+ error = handle_tal_table(tal, config);
+ else
+ return pr_err("Required table '%s' is missing.", "tal");
+
+ return error;
+}
+
+int
+set_config_from_file(char *config_file, struct rpki_config *config)
+{
+ struct file_contents fc;
+ struct toml_table_t *root;
+ struct rpki_uri uri;
+ char errbuf[200];
+ int error;
+ bool is_config_file;
+
+ /* I think I'm not using this struct correctly but I need it to call
+ * some functions, so be careful using the struct rpki_uri here.
+ * Also no needs to be freed. */
+ uri.global = config_file;
+ uri.global_len = strlen(config_file);
+ uri.local = config_file;
+
+ is_config_file = uri_has_extension(&uri, ".ini");
+ is_config_file |= uri_has_extension(&uri, ".toml");
+ if (!is_config_file) {
+ error = pr_err("Invalid Config file extension for file '%s'",
+ uri.local);
+ goto end;
+ }
+
+ error = file_load(&uri, &fc);
+ if (error)
+ goto end; /* Error msg already printed. */
+
+ root = toml_parse((char *) fc.buffer, errbuf, sizeof(errbuf));
+ file_free(&fc);
+
+ if (root == NULL) {
+ error = pr_err("Error while parsing configuration file: %s",
+ errbuf);
+ goto end;
+ }
+
+ error = toml_to_config(root, config);
+
+ toml_free(root);
+
+ print_config(config);
+
+end:
+ return error;
+}
--- /dev/null
+#ifndef SRC_CONFIG_H_
+#define SRC_CONFIG_H_
+
+#include <stdbool.h>
+
+struct rpki_config {
+ /* tal file path*/
+ char *tal;
+ /* Local repository path */
+ char *local_repository;
+ /* Disable rsync downloads */
+ bool enable_rsync;
+ /* Shuffle uris in tal */
+ bool shuffle_uris;
+ /* Configuration file path */
+ bool flag_config;
+};
+
+int set_config_from_file(char *, struct rpki_config *);
+
+#endif /* SRC_CONFIG_H_ */
#include <openssl/objects.h>
#include "common.h"
+#include "config.h"
#include "debug.h"
#include "log.h"
#include "rpp.h"
#include "object/tal.h"
#include "rsync/rsync.h"
-struct rpki_config {
- /* tal file path*/
- char *tal;
- /* Local repository path */
- char *local_repository;
- /* Disable rsync downloads */
- bool disable_rsync;
- /* Shuffle uris in tal */
- bool shuffle_uris;
-};
-
/**
* Registers the RPKI-specific OIDs in the SSL library.
* LibreSSL needs it; not sure about OpenSSL.
return error;
}
+static void
+set_default_configuration(struct rpki_config *config)
+{
+ config->enable_rsync = true;
+ config->shuffle_uris = false;
+ config->local_repository = NULL;
+ config->tal = NULL;
+}
+
static int
-handle_args(int argc, char **argv, struct rpki_config *config)
+handle_file_config(char *config_file, struct rpki_config *config)
+{
+ config->flag_config = false;
+
+ return set_config_from_file(config_file, config);
+}
+
+static int
+handle_flags_config(int argc, char **argv, struct rpki_config *config)
{
int opt, error = 0;
+ config->flag_config = true;
+
static struct option long_options[] = {
- {"tal", no_argument, NULL, 't'},
+ {"tal", required_argument, NULL, 't'},
{"local_repository", required_argument, NULL, 'l'},
{"disable_rsync", no_argument, 0, 'r'},
{"shuffle_uris", no_argument, 0, 's'},
{0,0,0,}
};
- config->disable_rsync = false;
- config->shuffle_uris = false;
- config->local_repository = NULL;
- config->tal = NULL;
-
while ((opt = getopt_long(argc, argv, "t:l:rs", long_options, NULL))
!= -1) {
switch (opt) {
config->local_repository = optarg;
break;
case 'r':
- config->disable_rsync = true;
+ config->enable_rsync = false;
break;
case 's':
config->shuffle_uris = true;
pr_debug("TAL file : %s", config->tal);
pr_debug("Local repository : %s", config->local_repository);
- pr_debug("Disable rsync : %s", config->disable_rsync
+ pr_debug("Enable rsync : %s", config->enable_rsync
? "true" : "false");
pr_debug("shuffle uris : %s", config->shuffle_uris
? "true" : "false");
return error;
}
+static int
+handle_args(int argc, char **argv, struct rpki_config *config)
+{
+ char *config_file;
+
+ if (argc == 1) {
+ return pr_err("Show usage"); /*TODO*/
+ }
+ if (strcasecmp(argv[1], "--configuration_file") == 0) {
+ if (argc == 2) {
+ return pr_err("--configuration_file requires a string "
+ "as argument.");
+ }
+ config_file = argv[2];
+ argc -= 2;
+ argv += 2;
+ return handle_file_config(config_file, config);
+ }
+
+ return handle_flags_config(argc, argv, config);
+}
+
+
int
main(int argc, char **argv)
{
struct tal *tal;
int error;
+ set_default_configuration(&config);
error = handle_args(argc, argv, &config);
if (error)
return error;
print_stack_trace_on_segfault();
- error = rsync_init(!config.disable_rsync);
+ error = rsync_init(config.enable_rsync);
if (error)
return error;