From c9138ee3356f67e30b75dd6fb4b9ce8d020423cc Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sun, 6 Mar 2016 11:10:14 +0000 Subject: [PATCH] Initial version of CalDAV::GetCalendars Doesn't return a list of calendars at present, but prints the list to std::cout XML formatted (ProcessXMLCalendarAddresses will need to be created). --- source/objects/CalDAV/CalDAV.cpp | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/source/objects/CalDAV/CalDAV.cpp b/source/objects/CalDAV/CalDAV.cpp index acb5321..a34ca07 100644 --- a/source/objects/CalDAV/CalDAV.cpp +++ b/source/objects/CalDAV/CalDAV.cpp @@ -451,6 +451,78 @@ string CalDAV::GetCalendarHome(string UserPrincipalURI){ CalDAVCalendarList CalDAV::GetCalendars(){ CalDAVCalendarList ServerList; + CalDAVSendData CalendarListSendData; + + // Build the server address. + + string UserPrincipalURI = ""; + UserPrincipalURI = GetUserPrincipal(); + + if (UserPrincipalURI.size() == 0){ + + return ServerList; + + } + + string CalendarHomeURI = ""; + CalendarHomeURI = GetCalendarHome(UserPrincipalURI); + + cout << ServerData << endl; + + string CalendarListURLAddress = BuildServerAddress(&ConnectionData, CalendarHomeURI); + + cout << CalendarListURLAddress << endl; + + string CalendarListRequest = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; + + CalendarListSendData.readptr = &CalendarListRequest; + CalendarListSendData.sizeleft = CalendarListRequest.size(); + + // Setup the header. + + struct curl_slist *CalendarListRequestHeader = NULL; + + CalendarListRequestHeader = curl_slist_append(CalendarListRequestHeader, "Depth: 1"); + CalendarListRequestHeader = curl_slist_append(CalendarListRequestHeader, "Prefer: return-minimal"); + CalendarListRequestHeader = curl_slist_append(CalendarListRequestHeader, "Content-Type: application/xml; charset=utf-8"); + + curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, CalendarListRequestHeader); + curl_easy_setopt(ConnectionHandle, CURLOPT_URL, CalendarListURLAddress.c_str()); + curl_easy_setopt(ConnectionHandle, CURLOPT_CUSTOMREQUEST, "PROPFIND"); + curl_easy_setopt(ConnectionHandle, CURLOPT_UPLOAD, 1L); + curl_easy_setopt(ConnectionHandle, CURLOPT_READDATA, &CalendarListSendData); + curl_easy_setopt(ConnectionHandle, CURLOPT_READFUNCTION, CalDAVSend); + + // Process the data. + + ServerData.clear(); + ServerHeader.clear(); + + CURLcode ServerResult = curl_easy_perform(ConnectionHandle); + + cout << ServerData << endl; + + //ServerList = ProcessXMLCalendarList(); + + // Restore the original settings. + + string OriginalServerAddress = BuildServerAddress(&ConnectionData, "/principals"); + curl_easy_setopt(ConnectionHandle, CURLOPT_URL, OriginalServerAddress.c_str()); + curl_easy_setopt(ConnectionHandle, CURLOPT_CUSTOMREQUEST, NULL); + curl_easy_setopt(ConnectionHandle, CURLOPT_UPLOAD, 0L); + curl_easy_setopt(ConnectionHandle, CURLOPT_READDATA, NULL); + curl_easy_setopt(ConnectionHandle, CURLOPT_READFUNCTION, NULL); return ServerList; -- 2.39.5