diary

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

commit b8b6dc73d81ff0bdef0903403de9845b85b7ad2e
parent 0aa67d2a0f54df4e6ba8987194c835a5672eb32f
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Sat, 25 Mar 2023 12:51:10 +0100

fix(caldav): incr postfield size by port

Diffstat:
Msrc/caldav.c | 21++++++++++++++++++++-
Msrc/diary-tp.h | 14++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/src/caldav.c b/src/caldav.c @@ -127,6 +127,7 @@ void update_global_token_vars(char* input) { // contained a valid refresh_token, i.e, if it was the initial // interactive authZ request from token code confirmed by the user char* new_refresh_token = extract_json_value(input, "refresh_token", true); + tracepoint(diary, debug_string, "New refresh token", new_refresh_token); if (new_refresh_token != NULL) { strncpy(refresh_token, new_refresh_token, 210); free(new_refresh_token); @@ -173,8 +174,11 @@ void get_access_token(char* code, char* verifier, bool refresh) { char* postfields_code = "client_id=%s&client_secret=%s&code=%s&code_verifier=%s&grant_type=authorization_code&redirect_uri=http://%s:%i"; char* postfields; + tracepoint(diary, debug, "Getting access token get_access_token()"); + if (refresh) { // work with refresh token, subtract 3 placholders + tracepoint(diary, debug_sizet, "strlen(refresh_token)", strlen(refresh_token)); postfields = calloc(strlen(postfields_refresh) - 6 + strlen(CONFIG.google_clientid) + strlen(CONFIG.google_secretid) + strlen(refresh_token) + 1, sizeof(char)); sprintf(postfields, postfields_refresh, CONFIG.google_clientid, @@ -182,7 +186,20 @@ void get_access_token(char* code, char* verifier, bool refresh) { refresh_token); } else { // work with auth code, subtract 6 placeholders - postfields = calloc(strlen(postfields_code) - 12 + strlen(CONFIG.google_clientid) + strlen(CONFIG.google_secretid) + strlen(code) + strlen(verifier) + strlen(ipstr) + 1, sizeof(char)); + tracepoint(diary, debug_sizet, "strlen(postfields_code)", strlen(postfields_code)); + tracepoint(diary, debug_sizet, "strlen(CONFIG.google_clientid)", strlen(CONFIG.google_clientid)); + tracepoint(diary, debug_sizet, "strlen(CONFIG.google_secretid))", strlen(CONFIG.google_secretid)); + tracepoint(diary, debug_sizet, "strlen(code)", strlen(code)); + tracepoint(diary, debug_sizet, "strlen(verifier)", strlen(verifier)); + tracepoint(diary, debug_sizet, "strlen(ipstr)", strlen(ipstr)); + tracepoint(diary, debug_sizet, "strlen(ipstr)", strlen(MKSTR(GOOGLE_OAUTH_REDIRECT_PORT))); + postfields = calloc(strlen(postfields_code) - 12 + + strlen(CONFIG.google_clientid) + + strlen(CONFIG.google_secretid) + + strlen(code) + + strlen(verifier) + + strlen(ipstr) + + strlen(MKSTR(GOOGLE_OAUTH_REDIRECT_PORT)) + 1, sizeof(char)); sprintf(postfields, postfields_code, CONFIG.google_clientid, CONFIG.google_secretid, @@ -629,6 +646,7 @@ int caldav_sync(struct tm* date, } // get acess token using code and verifier + tracepoint(diary, debug, "Fetching access token with code challenge"); get_access_token(code, challenge, false); free(code); @@ -649,6 +667,7 @@ int caldav_sync(struct tm* date, // The principal could not be fetched, // get new acess token with refresh token tracepoint(diary, debug, "Unable to fetch principal, refreshing API token"); + tracepoint(diary, debug, "Fetching access token with refresh token"); get_access_token(NULL, NULL, true); // Retry request for event with new token user_principal = caldav_req(date, GOOGLE_CALDAV_URI, "PROPFIND", principal_postfields, 0); diff --git a/src/diary-tp.h b/src/diary-tp.h @@ -108,6 +108,19 @@ TRACEPOINT_EVENT( TRACEPOINT_EVENT( diary, + debug_sizet, + TP_ARGS( + char*, msg_arg, + size_t, n_arg + ), + TP_FIELDS( + ctf_string(msg, msg_arg) + ctf_integer(size_t, n, n_arg) + ) +) + +TRACEPOINT_EVENT( + diary, warning_string, TP_ARGS( char*, msg_arg, @@ -131,6 +144,7 @@ TRACEPOINT_LOGLEVEL(diary, error_int_long, TRACE_ERR) TRACEPOINT_LOGLEVEL(diary, debug, TRACE_DEBUG) TRACEPOINT_LOGLEVEL(diary, debug_string, TRACE_DEBUG) TRACEPOINT_LOGLEVEL(diary, debug_double, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(diary, debug_sizet, TRACE_DEBUG) TRACEPOINT_LOGLEVEL(diary, warning_string, TRACE_WARNING) #endif /* _DIARY_TP_H */