diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit 10ab811986af9d83cc476e2a1015838dc851f395
parent 6a0ae7c78c10e6b201bd973c16d6fb9d8f28feed
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Sun, 16 May 2021 22:39:36 +0200

add google app creds to config

Diffstat:
Mcaldav.c | 6+++---
Mdiary.c | 12++++++++++++
Mutils.c | 6+++++-
Mutils.h | 16++++++++++++++++
4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/caldav.c b/caldav.c @@ -148,8 +148,8 @@ void set_access_token(char* code, char* verifier) { char postfields[500]; sprintf(postfields, "client_id=%s&client_secret=%s&code=%s&code_verifier=%s&grant_type=authorization_code&redirect_uri=http://%s:%i", - GOOGLE_OAUTH_CLIENT_ID, - GOOGLE_OAUTH_CLIENT_SECRET, + CONFIG.google_clientid, + CONFIG.google_secretid, code, verifier, ipstr, @@ -232,7 +232,7 @@ void caldav_sync(struct tm* date, WINDOW* header) { GOOGLE_OAUTH_RESPONSE_TYPE, ipstr, GOOGLE_OAUTH_REDIRECT_PORT, - GOOGLE_OAUTH_CLIENT_ID); + CONFIG.google_clientid); fprintf(stderr, "Google OAuth2 authorization URI: %s\n", uri); // Show the Google OAuth2 authorization URI in the header diff --git a/diary.c b/diary.c @@ -320,6 +320,18 @@ bool read_config(const char* file_path) } else if (strcmp("editor", key_buf) == 0) { CONFIG.editor = (char *) malloc(strlen(value_buf) + 1 * sizeof(char)); strcpy(CONFIG.editor, value_buf); + } else if (strcmp("google_tokenfile", key_buf) == 0) { + CONFIG.google_tokenfile = (char *) malloc(strlen(value_buf) + 1 * sizeof(char)); + strcpy(CONFIG.google_tokenfile, value_buf); + } else if (strcmp("google_clientid", key_buf) == 0) { + CONFIG.google_clientid = (char *) malloc(strlen(value_buf) + 1 * sizeof(char)); + strcpy(CONFIG.google_clientid, value_buf); + } else if (strcmp("google_secretid", key_buf) == 0) { + CONFIG.google_secretid = (char *) malloc(strlen(value_buf) + 1 * sizeof(char)); + strcpy(CONFIG.google_secretid, value_buf); + } else if (strcmp("google_calendar", key_buf) == 0) { + CONFIG.google_calendar = (char *) malloc(strlen(value_buf) + 1 * sizeof(char)); + strcpy(CONFIG.google_calendar, value_buf); } } } diff --git a/utils.c b/utils.c @@ -4,7 +4,11 @@ config CONFIG = { .range = 1, .weekday = 1, .fmt = "%Y-%m-%d", - .editor = "" + .editor = "", + .google_tokenfile = GOOGLE_OAUTH_TOKEN_FILE, + .google_clientid = GOOGLE_OAUTH_CLIENT_ID, + .google_secretid = GOOGLE_OAUTH_CLIENT_SECRET, + .google_calendar = "" }; void get_date_str(const struct tm* date, char* date_str, size_t date_str_size, const char* fmt) diff --git a/utils.h b/utils.h @@ -4,6 +4,14 @@ #include <stdlib.h> #include <time.h> +#define GOOGLE_OAUTH_TOKEN_FILE "~/.diary-token" +#ifndef GOOGLE_OAUTH_CLIENT_ID + #define GOOGLE_OAUTH_CLIENT_ID "" +#endif +#ifndef GOOGLE_OAUTH_CLIENT_SECRET + #define GOOGLE_OAUTH_CLIENT_SECRET "" +#endif + typedef struct { // Path that holds the journal text files @@ -16,6 +24,14 @@ typedef struct char* fmt; // Editor to open journal files with char* editor; + // File for Google OAuth access token + char* google_tokenfile; + // Google client id + char* google_clientid; + // Google secret id + char* google_secretid; + // Google calendar to synchronize + char* google_calendar; } config; config CONFIG;