commit bca4f026e08975ee6c0a9ae1bdcd81f021b1a6bc
parent 97d33cc29e37740e04d70e0d5b16fc7b0d9a2f66
Author: Andreas Gruhler <agruhl@gmx.ch>
Date: Sun, 13 Jun 2021 17:25:29 +0200
fix unfold emtpy DESCRIPTION
Diffstat:
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/src/caldav.c b/src/caldav.c
@@ -648,6 +648,8 @@ void caldav_sync(struct tm* date, WINDOW* header, WINDOW* cal, int pad_pos, cons
access_token = NULL;
free(refresh_token);
refresh_token = NULL;
+ pthread_cancel(progress_tid);
+ wclear(header);
return;
}
@@ -743,6 +745,8 @@ void caldav_sync(struct tm* date, WINDOW* header, WINDOW* cal, int pad_pos, cons
if (! (local_file_exists || remote_file_exists)) {
fprintf(stderr, "Neither local nor remote file exists, giving up.\n");
+ pthread_cancel(progress_tid);
+ wclear(header);
return;
}
@@ -777,13 +781,12 @@ void caldav_sync(struct tm* date, WINDOW* header, WINDOW* cal, int pad_pos, cons
int conf_ch;
if ((timediff < 0 && remote_file_exists) || (!local_file_exists && remote_file_exists)) {
rmt_desc = extract_ical_field(event, "DESCRIPTION", true);
- // todo: fix bug, DESCRIPTION is literally "LAST-MODIFIED:20210602T210152Z"
- // (next line) whenever DESCRIPTION is empty
-
fprintf(stderr, "Remote event description:%s\n", rmt_desc);
if (rmt_desc == NULL) {
- fprintf(stderr, "Failed to fetch description of remote event.\n");
+ fprintf(stderr, "Failed to fetch description of remote event. Might be empty.\n");
+ pthread_cancel(progress_tid);
+ wclear(header);
return;
}
diff --git a/src/utils.c b/src/utils.c
@@ -79,6 +79,8 @@ char* fold(const char* str) {
}
char* unfold(const char* str) {
+ if (strcmp(str, "\n")) return NULL;
+
// work on a copy of the str
char* strcp = (char *) malloc(strlen(str) * sizeof(char));
strcpy(strcp, str);
@@ -132,26 +134,27 @@ char* extract_ical_field(const char* ics, char* key, bool multiline) {
}
// work on a copy of the ical xml response
- char* field = (char *) malloc(strlen(ics) * sizeof(char));
- strcpy(field, ics);
+ char* icscp= (char *) malloc(strlen(ics) * sizeof(char));
+ strcpy(icscp, ics);
- char* res = strtok(field, "\n");
+ // tokenize ical by newlines
+ char* res = strtok(icscp, "\n");
while (res != NULL) {
if (regexec(&re, res, 1, pm, 0) == 0) {
res = strstr(res, ":"); // value
res++; // strip the ":"
+
+ if (multiline) {
+ res = unfold(ics + (res - icscp));
+ }
break;
}
// key not in this line, advance line
res = strtok(NULL, "\n");
}
- if (multiline) {
- res = unfold(ics + (res - field));
- }
-
- free(field);
+ free(icscp);
return res;
}