summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-08-20 20:36:38 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-08-20 20:36:38 +0200
commit2d2b889bb25f9db008bdac54babf84c2120d2a45 (patch)
tree1b1154fd5c692ad99d3c16ae7768647185687f6c
parent02f779da234da8c17300ca849f9a2c1f8d4a48e0 (diff)
Implemented some basic configuration stuff.
-rw-r--r--conf.c46
-rw-r--r--conf.h11
-rw-r--r--main.c5
3 files changed, 62 insertions, 0 deletions
diff --git a/conf.c b/conf.c
new file mode 100644
index 0000000..eb978e7
--- /dev/null
+++ b/conf.c
@@ -0,0 +1,46 @@
+#include "conf.h"
+
+static GKeyFile *kf = NULL;
+
+gchar *conf_get_string(const gchar *group, const gchar *key) {
+ GError *error = NULL;
+
+ gchar *s = g_key_file_get_string(kf, group, key, &error);
+ if(s == NULL) {
+ g_warning(error->message);
+ g_error_free(error);
+ }
+
+ return s;
+}
+
+gint conf_get_int(const gchar *group, const gchar *key) {
+ GError *error = NULL;
+
+ gint i = g_key_file_get_integer(kf, group, key, &error);
+ if(i == 0 && error != NULL) {
+ g_warning(error->message);
+ g_error_free(error);
+ }
+
+ return i;
+}
+
+gboolean conf_load() {
+ GError *error = NULL;
+ kf = g_key_file_new();
+
+ if(kf == NULL) {
+ return FALSE;
+ }
+
+ if(g_key_file_load_from_file(kf, "audist.conf", G_KEY_FILE_NONE, &error) == FALSE) {
+ g_warning("could not load config file: %s", error->message);
+ }
+
+ return TRUE;
+}
+
+void conf_free() {
+ g_key_file_free(kf);
+}
diff --git a/conf.h b/conf.h
new file mode 100644
index 0000000..7506373
--- /dev/null
+++ b/conf.h
@@ -0,0 +1,11 @@
+#ifndef CONF_H
+#define CONF_H
+
+#include <glib.h>
+
+gchar *conf_get_string(const gchar *group, const gchar *key);
+gint conf_get_int(const gchar *group, const gchar *key);
+gboolean conf_load();
+void conf_free();
+
+#endif
diff --git a/main.c b/main.c
index 3339ae9..a037c7b 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,7 @@
#include "music.h"
#include "httpd.h"
#include "command_service.h"
+#include "conf.h"
#include <glib.h>
#include <glib-object.h>
@@ -17,6 +18,8 @@ static void sig_handler(int sig) {
int main(int argc, char **argv) {
g_type_init();
+ conf_load();
+
music_init(argv[1]);
music_scan_root();
@@ -33,5 +36,7 @@ int main(int argc, char **argv) {
server_stop();
music_free();
+ conf_free();
+
return 0;
}