diary

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

commit fc1ac3fb8c87ee87013641472f7b33ffdff80342
parent c249a1c233e6003fb54d96b5e64fc1161928761b
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Sat, 14 Sep 2024 12:45:32 +0200

feat: const events_request post field

Diffstat:
Msrc/caldav.c | 26++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/caldav.c b/src/caldav.c @@ -9,9 +9,9 @@ char ip[INET6_ADDRSTRLEN], ipstr[INET6_ADDRSTRLEN + 2]; // Static XML data for CalDav post requests: // https://write.in0rdr.ch/caldav-calendar-discovery -const char* principal_postfields = "<d:propfind xmlns:d='DAV:' xmlns:cs='http://calendarserver.org/ns/'>" - "<d:prop><d:current-user-principal/></d:prop>" - "</d:propfind>"; +const char* principal_request = "<d:propfind xmlns:d='DAV:' xmlns:cs='http://calendarserver.org/ns/'>" + "<d:prop><d:current-user-principal/></d:prop>" + "</d:propfind>"; const char* homeset_request = "<d:propfind xmlns:d='DAV:' xmlns:c='urn:ietf:params:xml:ns:caldav'>" " <d:prop>" " <c:calendar-home-set />" @@ -25,6 +25,12 @@ const char* calendar_request = "<d:propfind xmlns:d='DAV:' xmlns:cs='http://cale " <c:supported-calendar-component-set />" " </d:prop>" "</d:propfind>"; +char* events_request = "<c:calendar-query xmlns:d='DAV:' xmlns:c='urn:ietf:params:xml:ns:caldav'>" + "<d:prop><d:getetag/><c:calendar-data/></d:prop>" + "<c:filter><c:comp-filter name='VCALENDAR'>" + "<c:comp-filter name='VEVENT'>" + "<c:time-range start='%s' end='%s'/></c:comp-filter>" + "</c:comp-filter></c:filter></c:calendar-query>"; static size_t curl_write_mem_callback(void* contents, size_t size, size_t nmemb, void* userp) { size_t realsize = size * nmemb; @@ -113,7 +119,6 @@ char* caldav_req(struct tm* date, char* url, char* http_method, const char* post char basicauth [strlen(CONFIG.caldav_username) + strlen(CONFIG.caldav_password) + 2]; sprintf(basicauth, "%s:%s", CONFIG.caldav_username, CONFIG.caldav_password); curl_easy_setopt(curl, CURLOPT_USERPWD, basicauth); - tracepoint(diary, debug_string, "curl_easy_perform() basicauth", basicauth); } else { // use OAuth credentials char bearer_token[strlen("Authorization: Bearer ") + strlen(access_token) + 1]; @@ -285,7 +290,7 @@ int caldav_sync(struct tm* date, pthread_create(&progress_tid, NULL, show_progress, (void*)header); pthread_detach(progress_tid); - char* user_principal = caldav_req(date, CONFIG.caldav_server, "PROPFIND", principal_postfields, 0, basicauth_enabled, "application/xml", 1); + char* user_principal = caldav_req(date, CONFIG.caldav_server, "PROPFIND", principal_request, 0, basicauth_enabled, "application/xml", 1); tracepoint(diary, debug_string, "User principal return XML", user_principal); if (user_principal == NULL) { @@ -372,13 +377,6 @@ int caldav_sync(struct tm* date, free(calendar_xml); - char* xml_filter = "<c:calendar-query xmlns:d='DAV:' xmlns:c='urn:ietf:params:xml:ns:caldav'>" - "<d:prop><d:getetag/><c:calendar-data/></d:prop>" - "<c:filter><c:comp-filter name='VCALENDAR'>" - "<c:comp-filter name='VEVENT'>" - "<c:time-range start='%s' end='%s'/></c:comp-filter>" - "</c:comp-filter></c:filter></c:calendar-query>"; - char dstr_start[30]; char dstr_end[30]; char* format_start = "%Y%m%dT000000Z"; // start of day @@ -386,8 +384,8 @@ int caldav_sync(struct tm* date, strftime(dstr_start, sizeof dstr_start, format_start, date); strftime(dstr_end, sizeof dstr_end, format_end, date); - char caldata_postfields[strlen(xml_filter) + strlen(dstr_start) + strlen(dstr_end)]; - sprintf(caldata_postfields, xml_filter, + char caldata_postfields[strlen(events_request) + strlen(dstr_start) + strlen(dstr_end)]; + sprintf(caldata_postfields, events_request, dstr_start, dstr_end);