aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-02-06 05:38:02 +0100
committerache <ache@ache.one>2019-02-06 05:38:02 +0100
commitdac4b31e5e5591e5dd0fbba48fa4b9fcce744c8e (patch)
tree5e873b5769d4d09512e712f336a621de0dd492fb
parentgcc11 (diff)
Debug mode
-rw-r--r--contactList.c6
-rw-r--r--main.c5
-rw-r--r--readConfig.c42
-rw-r--r--sms.c18
4 files changed, 52 insertions, 19 deletions
diff --git a/contactList.c b/contactList.c
index a5c7107..cbc3b24 100644
--- a/contactList.c
+++ b/contactList.c
@@ -73,7 +73,7 @@ int fillContactList(char* filename) {
}
if( !file ) {
- perror("Unable to read contact file");
+ fprintf(stderr, "Unable to read contact file: ");
return 1;
}
@@ -83,7 +83,7 @@ int fillContactList(char* filename) {
if( c == ';' ) {
v++;
if( v >= 3) {
- perror("Invalid format (contact file) : too many field");
+ fprintf(stderr, "Invalid format (contact file) : too many field");
return 2; // Invalid
}
}
@@ -93,7 +93,7 @@ int fillContactList(char* filename) {
nbContacts++;
}
else {// Not enougth
- perror("Invalid format (contact file) : not enougth field");
+ fprintf(stderr, "Invalid format (contact file) : not enougth field");
return 2; // Invalid format
}
}
diff --git a/main.c b/main.c
index 3f38f1e..d3359d0 100644
--- a/main.c
+++ b/main.c
@@ -141,7 +141,10 @@ int main(int argc, char* argv[]){
int r = 0;
- if( r = fillContactList(DEFAULT_CONTACT_FILENAME) ) {
+ if( *config.CONTACT_FILENAME && (r = fillContactList(config.CONTACT_FILENAME)) ) {
+#ifdef DEBUG
+ fprintf(stderr, "Error reading contact list (%s)\n", config.CONTACT_FILENAME);
+#endif
return r;
}
if( r = loadConv() ) {
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
}
}
diff --git a/sms.c b/sms.c
index 65a0b8f..bf7fc72 100644
--- a/sms.c
+++ b/sms.c
@@ -155,7 +155,7 @@ int readSMS(char* filename, int inbox_outbox) {
sms_text[++sms_len] = lastChar;
getSms.text = sms_text;
getSms.len = sms_len;
-
+
int r = insertSMS(&getSms);
if( r )
return 2;
@@ -182,12 +182,11 @@ int listSMS(char* smsInboxDir, int inorout) {
if( r ) {
return 2;
}
-
}
}
closedir(dirHandler);
} else {
- fprintf(stderr, "Directory can't be opened");
+ fprintf(stderr, "Directory can't be opened: ");
return 1;
}
return 0;
@@ -198,14 +197,15 @@ int listSMS(char* smsInboxDir, int inorout) {
int loadConv(void) {
- int r = listSMS(config.SMS_INBOX, SMS_IN);
- if( r ) {
- fprintf(stderr, "Impossible de lire les SMS reçu");
+ int r = 0;
+
+ if( *config.SMS_INBOX && (r = listSMS(config.SMS_INBOX, SMS_IN)) ) {
+ fprintf(stderr, "Impossible de lire les SMS reçu\n");
return 1;
}
- r = listSMS(config.SMS_SENTBOX , SMS_OUT);
- if( r ) {
- fprintf(stderr, "Impossible de lire les SMS envoyés");
+ ;
+ if( *config.SMS_SENTBOX && (r = listSMS(config.SMS_SENTBOX , SMS_OUT)) ) {
+ fprintf(stderr, "Impossible de lire les SMS envoyés\n");
return 2;
}