commit 4f0c04e478fda3f0734480a2e242ce40e7d07479
parent d4902f6a3a2adc9e5950e6b9b8d21bcbca4dc0ca
Author: Andreas Gruhler <agruhl@gmx.ch>
Date: Thu, 23 Jun 2022 14:24:12 +0200
fix(#15): Check google input params
Diffstat:
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/src/caldav.c b/src/caldav.c
@@ -598,6 +598,23 @@ int caldav_sync(struct tm* date,
bool confirm) {
pthread_t progress_tid;
+ char* info_txt;
+
+ if (strcmp(CONFIG.google_clientid, "") || strcmp(CONFIG.google_secretid, "") || strcmp(CONFIG.google_calendar, "")) {
+ wclear(header);
+ wresize(header, LINES, getmaxx(header));
+ info_txt = "Missing sync parameters. Set Google Client ID, secret and remote calendar name.\n"
+ "Press any key to continue.";
+ mvwprintw(header, 0, 0, info_txt);
+ wrefresh(header);
+
+ // accept any input to proceed
+ noecho();
+ wgetch(header);
+ echo();
+ wclear(header);
+ }
+
// fetch existing API tokens from file
char* tokfile = read_tokenfile();
free(tokfile);
@@ -644,9 +661,9 @@ int caldav_sync(struct tm* date,
pthread_cancel(progress_tid);
wclear(header);
wresize(header, LINES, getmaxx(header));
- char* info_txt = "Offline, corrupted or otherwise invalid OAuth2 credential tokenfile.\n"
- "Go online or delete tokenfile '%s' and restart diary to retry.\n"
- "Press any key to continue.";
+ info_txt = "Offline, corrupted or otherwise invalid OAuth2 credential tokenfile.\n"
+ "Go online or delete tokenfile '%s' and restart diary to retry.\n"
+ "Press any key to continue.";
mvwprintw(header, 0, 0, info_txt, CONFIG.google_tokenfile);
wrefresh(header);
@@ -706,6 +723,17 @@ int caldav_sync(struct tm* date,
// currently, the code below will just extract the first occurance of
// LAST-MODIFIED, UID and DESCRIPTION (from the first event)
+ if (event == NULL) {
+ // Event not found. The curl request probably failed due to one of the missing input parameters:
+ // - Google Client ID
+ // - Google Secret ID
+ // - Google Calendar Name
+ pthread_cancel(progress_tid);
+ wclear(header);
+ free(home_set);
+ return -1;
+ }
+
// get path of entry
char path[100];
char* ppath = path;