]> git.ipfire.org Git - people/ms/network.git/commitdiff
networkd: Add scaffolding to read configuration files
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 30 Jan 2023 02:26:41 +0000 (02:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 30 Jan 2023 02:26:41 +0000 (02:26 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/networkd/config.c
src/networkd/config.h

index d18fb12b0194b22169d76572ff474d8bb381b951..e808531b4949130b545b6be5c0f30c3444342b5d 100644 (file)
 #                                                                             #
 #############################################################################*/
 
+#include <stdio.h>
 #include <stdlib.h>
 
 #include "config.h"
+#include "logging.h"
 
 struct nw_config {
        int nrefs;
@@ -56,3 +58,51 @@ struct nw_config* nw_config_unref(struct nw_config* config) {
        nw_config_free(config);
        return NULL;
 }
+
+static int nw_config_parse(struct nw_config* config, FILE* f) {
+       // XXX TODO
+
+       return 0;
+}
+
+int nw_config_readf(struct nw_config** config, FILE* f) {
+       int r;
+
+       // Create a new config object
+       r = nw_config_create(config);
+       if (r)
+               return r;
+
+       // Parse the configuration
+       r = nw_config_parse(*config, f);
+       if (r)
+               goto ERROR;
+
+       return 0;
+
+ERROR:
+       nw_config_free(*config);
+       return r;
+}
+
+int nw_config_read(struct nw_config** config, const char* path) {
+       FILE* f = NULL;
+       int r;
+
+       // Open the file
+       f = fopen(path, "r");
+       if (!f) {
+               ERROR("Could not read configuration file %s: %m\n", path);
+               r = 1;
+               goto ERROR;
+       }
+
+       // Read from file
+       r = nw_config_readf(config, f);
+
+ERROR:
+       if (f)
+               fclose(f);
+
+       return r;
+}
index a8aed7f0a0616b172fdc2dd50c3b728f0f52fb92..559ba9484fc577ed92caad6863d18582df44fb16 100644 (file)
@@ -28,4 +28,7 @@ int nw_config_create(struct nw_config** config);
 struct nw_config* nw_config_ref(struct nw_config* config);
 struct nw_config* nw_config_unref(struct nw_config* config);
 
+int nw_config_readf(struct nw_config** config, FILE* f);
+int nw_config_read(struct nw_config** config, const char* path);
+
 #endif /* NETWORKD_CONFIG_H */