summaryrefslogtreecommitdiffstats
path: root/src/daemon/settings.c
diff options
context:
space:
mode:
authorGravatar Paulius Ratkevičius <paulius.ratkevicius@ktu.edu> 2019-05-17 15:29:11 +0300
committerGravatar Gediminas Jakutis <gediminas@varciai.lt> 2019-05-17 23:42:06 +0300
commit86b14eb4e0473360cd35163dfe2366f5c91384b3 (patch)
treec05668b90698edb2caf89fc6e8ca5e6c278af3de /src/daemon/settings.c
parent9c0b33eb35d93b1ac3db644dd148979afbed79a5 (diff)
downloadusurpation-86b14eb4e0473360cd35163dfe2366f5c91384b3.tar.gz
usurpation-86b14eb4e0473360cd35163dfe2366f5c91384b3.tar.bz2
usurpation-86b14eb4e0473360cd35163dfe2366f5c91384b3.zip
daemon: semi-stub for config file handling.
The daemon now load and somewhat parses the config files. It does not do anything else with the data yet, that's a TODO. Signed-off-by: Paulius Ratkevičius <paulius.ratkevicius@ktu.edu>
Diffstat (limited to 'src/daemon/settings.c')
-rw-r--r--src/daemon/settings.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/daemon/settings.c b/src/daemon/settings.c
index 4392300..acbf40d 100644
--- a/src/daemon/settings.c
+++ b/src/daemon/settings.c
@@ -19,6 +19,14 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
#include "settings.h"
#include "settings_private.h"
@@ -31,6 +39,7 @@ void settings_init(void)
unset_flag(flag_daemonize);
settings.port = 6996;
settings.verboselevel = USURP_VERBOSITY;
+ setting_readconf("./usurpation.conf");
}
int setting_detach(void)
@@ -68,3 +77,60 @@ void unset_flag(unsigned int flag)
{
settings.flags &= ~flag;
}
+
+/* TODO: semi-stub! */
+static int setting_readconf(const char * const path)
+{
+ struct stat filestat;
+ char *buf;
+ char *line;
+ char *entry;
+ char *value;
+ char *line_state;
+ char *token_state;
+ int fd;
+
+
+ if ((fd = open(path, O_RDONLY | O_NOATIME)) == -1) {
+ if (USURP_VERBOSITY >= 2) {
+ perror("error while opening the configuration file");
+ return 1;
+ }
+ }
+
+ fstat(fd, &filestat);
+ buf = malloc(filestat.st_size);
+
+ if (read(fd, buf, filestat.st_size) != filestat.st_size) {
+ if (USURP_VERBOSITY >= 2) {
+ perror("partial read of configuration file detected");
+ free(buf);
+ return 1;
+ }
+ }
+
+ line = strtok_r(buf, "\n", &line_state);
+
+ while (line) {
+ if (line[0] != '#') {
+ entry = strtok_r(line, "=", &token_state);
+ value = strtok_r(NULL, "=", &token_state);
+ setting_handle_config_entry(entry, value);
+ }
+
+ line = strtok_r(NULL, "\n", &line_state);
+ }
+
+ free(buf);
+
+ return 0;
+}
+
+/* TODO: stub! */
+static int setting_handle_config_entry(const char * const entry, const char * const value)
+{
+ printf( "key: %s\n"
+ "value: %s\n", entry, value);
+
+ return 0;
+}