# #
#############################################################################*/
+#include <stdio.h>
#include <stdlib.h>
#include "config.h"
+#include "logging.h"
struct nw_config {
int nrefs;
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;
+}
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 */