aboutsummaryrefslogtreecommitdiff
path: root/readConfig.c
diff options
context:
space:
mode:
Diffstat (limited to 'readConfig.c')
-rw-r--r--readConfig.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/readConfig.c b/readConfig.c
index 94aecc7..5c09957 100644
--- a/readConfig.c
+++ b/readConfig.c
@@ -1,13 +1,14 @@
#include <stdlib.h>
#include <stdio.h>
+#include <wordexp.h>
#include <string.h>
#include "config.h"
-config_t config = { .SMS_INBOX = "/var/spool/sms/inbox/",
- .SMS_SENTBOX = "/var/spool/sms/sent/",
- .SMS_OUTBOX = "/var/spool/sms/inbox/",
+config_t config = { .SMS_INBOX = "",
+ .SMS_SENTBOX = "",
+ .SMS_OUTBOX = "",
.MMS_DIR = "",
- .CONTACT_FILENAME = "/var/spool/sms/contacts.csv"};
+ .CONTACT_FILENAME = ""};
const char* search_key[]= {"SMS_INBOX", "SMS_SENTBOX", "SMS_OUTBOX", "CONTACT_FILENAME", "MMS_DIR"};
@@ -36,6 +37,10 @@ int readConfigFile(void) {
if( file ) {
while(fgets(line, 300, file) != NULL) {
+
+ char* tmp = strrchr(line, '\n');
+ if( tmp ) *tmp = 0;
+
int elem = -1;
for( int i = 0 ; i < sizeof search_key / sizeof *search_key ; i++) {
if( strncmp(line, search_key[i], strlen(search_key[i])) == 0 ) {
@@ -44,9 +49,34 @@ int readConfigFile(void) {
}
}
if(elem >= 0) {
- strtok(line, "\"");
+ char* res = NULL;
+ if(strchr(line, '\"')) {
+ strtok(line, "\"");
+ res = strtok(NULL, "\"");
+ } else if(strchr(line, '=')) {
+ strtok(line, "=");
+ res = strtok(NULL, "=");
+ } else {
+ continue;
+ }
+ char* configProperty = ((char*[]){config.SMS_INBOX, config.SMS_SENTBOX,
+ config.SMS_OUTBOX, config.MMS_DIR, config.CONTACT_FILENAME})[elem];
+ int r = 0;
+
+ if( !res ) res = "";
+ if( strlen(res) > 255 ) continue;
+ wordexp_t p;
+ r = wordexp(res, &p, 0);
+
+ if( r == 0) {
+ if( p.we_wordc > 0 )
+ strncpy( configProperty, p.we_wordv[0], 255);
+ wordfree(&p);
+ } else {
+ strncpy( configProperty, res, 255);
+ }
#ifdef DEBUG
- fprintf(stderr, "%s is \"%s\"\n", search_key[elem], strtok(NULL, "\"") );
+ fprintf(stderr, "%s is \"%s\"\n", search_key[elem], configProperty );
#endif
}
}