summaryrefslogtreecommitdiffstats
path: root/src/config-load.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config-load.c')
-rw-r--r--src/config-load.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/config-load.c b/src/config-load.c
new file mode 100644
index 0000000..9335813
--- /dev/null
+++ b/src/config-load.c
@@ -0,0 +1,55 @@
+#include "config-load.h"
+#include "config-ini.h"
+#include "types.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static const char * simple_basename(const char *path) {
+ const char *slash = strrchr(path, '/');
+ return slash ? (slash+1) : path;
+}
+
+static const char * extname(const char *filename) {
+ const char *dot = strrchr(filename, '.');
+ return dot ? (dot+1) : NULL;
+}
+
+static interface_config_t * read_interface_config(const char *path) {
+ ini_file_t *file = read_ini_file(path);
+ ini_section_t *section;
+ ini_field_t *field;
+
+ list_for_each_entry(section, &file->sections, node) {
+ printf("%s\n", section->name);
+
+ list_for_each_entry(field, &section->fields, node)
+ printf("%s.%s=%s\n", section->name, field->key, field->value);
+ }
+
+ free_ini_file(file);
+
+ return NULL;
+}
+
+bool read_config_file(const char *path) {
+ const char *filename = simple_basename(path);
+ const char *ext = extname(filename);
+ if (!ext) {
+ errno = EINVAL;
+ return false;
+ }
+
+ char *name = strndup(filename, (ext - filename) - 1);
+
+ if (strcmp(ext, "interface") == 0) {
+ interface_config_t *iface = read_interface_config(path);
+ free(iface);
+ }
+
+ free(name);
+
+ return true;
+}