+ 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;
+
+}
+
+CalDAVEntryList CalDAV::GetEntryList(string *calendarHREF){
+
+ CalDAVEntryList entryList;
+ CalDAVSendData entryListSendData;
+
+ if (calendarHREF->size() == 0){
+
+ return entryList;
+
+ }
+
+ string entryListURLAddress = BuildServerAddress(&connectionData, *calendarHREF);
+
+ string entryListRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+
+ /*if (CalendarTag == nullptr){*/
+
+ entryListRequest += "<c:calendar-query xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\""
+ " xmlns:c=\"urn:ietf:params:xml:ns:caldav\" xmlns:x0=\"http://apple.com/ns/ical/\">\n"
+ " <d:prop>\n"
+ " <d:getetag />\n"
+ " <c:calendar-data />\n"
+ " </d:prop>\n"
+ " <c:filter>\n"
+ " <c:comp-filter name=\"VCALENDAR\" />\n"
+ " </c:filter>\n"
+ "</c:calendar-query>";
+
+ /*} else {
+
+ EntryListRequest += "<d:sync-collection xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\""
+ " xmlns:c=\"urn:ietf:params:xml:ns:caldav\" xmlns:x0=\"http://apple.com/ns/ical/\">\n"
+ " <d:sync-token>";
+ EntryListRequest += *CalendarTag;
+ EntryListRequest += "</d:sync-token>\n"
+ " <d:sync-level>1</d:sync-level>\n"
+ " <d:prop>\n"
+ " <d:getetag />\n"
+ " <c:calendar-data />\n"
+ " </d:prop>\n"
+ "</d:sync-collection>";
+
+ }*/
+
+ entryListSendData.readptr = &entryListRequest;
+ entryListSendData.sizeleft = entryListRequest.size();
+
+ struct curl_slist *entryListRequestHeader = NULL;
+
+ entryListRequestHeader = curl_slist_append(entryListRequestHeader, "Content-Type: application/xml; charset=utf-8");
+
+ /*if (CalendarTag != nullptr){
+
+ EntryListRequestHeader = curl_slist_append(EntryListRequestHeader, "Content-Type: application/xml; charset=utf-8");
+ EntryListRequestHeader = curl_slist_append(EntryListRequestHeader, "Content-Type: application/xml; charset=utf-8");
+
+ }*/
+
+ curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, entryListRequestHeader);
+ curl_easy_setopt(connectionHandle, CURLOPT_URL, entryListURLAddress.c_str());
+ curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "REPORT");
+ curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+ curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &entryListSendData);
+ curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
+
+ // Process the data.
+
+ serverData.clear();
+ serverHeader.clear();
+
+ CURLcode serverResult = curl_easy_perform(connectionHandle);
+
+ //ServerList = ProcessXMLCalendarList();
+
+ if (serverResult == CURLE_OK){
+ connectionServerResult.result = CALDAVQUERYRESULT_OK;
+ } else {
+ connectionServerResult.result = CALDAVQUERYRESULT_SERVERERROR;
+ }
+ connectionServerResult.code = serverResult;
+ curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &connectionServerResult.httpCode);
+
+ if (serverResult != CURLE_OK){
+
+ return entryList;
+
+ }
+
+ // Process the received XML data into a list of calendars
+ // and locations.
+
+ entryList = ProcessXMLEntryList();
+
+ // 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 entryList;
+
+}
+
+CalDAVEntryList CalDAV::GetEntryList(string *calendarHREF, string *calendarTag){
+
+ CalDAVEntryList entryList;
+ CalDAVSendData entryListSendData;
+
+ if (calendarHREF->size() == 0){
+
+ return entryList;
+
+ }
+
+ string entryListURLAddress = BuildServerAddress(&connectionData, *calendarHREF);
+
+ // First query: Get the list of contacts that need to be updated.
+
+ string entryListRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+
+ entryListRequest += "<d:sync-collection xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\""
+ " xmlns:c=\"urn:ietf:params:xml:ns:caldav\" xmlns:x0=\"http://apple.com/ns/ical/\">\n"
+ " <d:sync-token>";
+
+ if (calendarTag != nullptr){
+
+ entryListRequest += *calendarTag;
+
+ } else {
+
+ entryListRequest += "";
+
+ }
+
+ entryListRequest += "</d:sync-token>\n"
+ " <d:sync-level>1</d:sync-level>\n"
+ " <d:prop>\n"
+ " <d:getetag />\n"
+ " </d:prop>\n"
+ "</d:sync-collection>";
+
+ entryListSendData.readptr = &entryListRequest;
+ entryListSendData.sizeleft = entryListRequest.size();
+
+ struct curl_slist *entryListRequestHeader = NULL;
+
+ entryListRequestHeader = curl_slist_append(entryListRequestHeader, "Content-Type: application/xml; charset=utf-8");
+
+ curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, entryListRequestHeader);
+ curl_easy_setopt(connectionHandle, CURLOPT_URL, entryListURLAddress.c_str());
+ curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "REPORT");
+ curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+ curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &entryListSendData);
+ curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
+
+ // Process the data.
+
+ serverData.clear();
+ serverHeader.clear();
+
+ CURLcode serverResult = curl_easy_perform(connectionHandle);
+
+ if (serverResult == CURLE_OK){
+ connectionServerResult.result = CALDAVQUERYRESULT_OK;
+ } else {
+ connectionServerResult.result = CALDAVQUERYRESULT_SERVERERROR;
+ }
+ connectionServerResult.code = serverResult;
+ curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &connectionServerResult.httpCode);
+
+ if (serverResult != CURLE_OK){
+
+ return entryList;
+
+ }
+
+ entryList = ProcessXMLSyncTokenList();
+
+ // Check the last entry matches the HREF and if it
+ // does then delete it.
+
+ if (entryList.href.size() > 0) {
+
+ if (entryList.href.rbegin()->second == *calendarHREF){
+
+ entryList.href.erase((entryList.href.size() - 1));
+ entryList.tag.erase((entryList.href.size() - 1));
+ entryList.data.erase((entryList.href.size() - 1));
+
+ }
+
+ }
+
+ // Build the list into a new list for getting the new
+ // calendar data with.
+
+ entryListRequest.clear();
+
+ entryListRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+
+ entryListRequest += "<c:calendar-multiget xmlns:d=\"DAV:\" "
+ " xmlns:c=\"urn:ietf:params:xml:ns:caldav\">\n"
+ " <d:prop>\n"
+ " <d:getetag />\n"
+ " <c:calendar-data />\n"
+ " </d:prop>\n";
+
+ for (std::map<int,string>::iterator hrefIter = entryList.href.begin();
+ hrefIter != entryList.href.end(); hrefIter++){
+
+ string entryListHREFString = hrefIter->second;
+
+ entryListRequest += " <d:href>";
+ entryListRequest += entryListHREFString;
+ entryListRequest += "</d:href>\n";
+
+ }
+
+ entryListRequest += "</c:calendar-multiget>";
+
+ CalDAVSendData updatedEntryListSendData;
+
+ updatedEntryListSendData.readptr = &entryListRequest;
+ updatedEntryListSendData.sizeleft = entryListRequest.size();
+
+ curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, entryListRequestHeader);
+ curl_easy_setopt(connectionHandle, CURLOPT_URL, entryListURLAddress.c_str());
+ curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "REPORT");
+ curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+ curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &updatedEntryListSendData);
+ curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
+
+ // Get the updated calendar data.
+
+ serverData.clear();
+ serverHeader.clear();
+ entryList.href.clear();
+ entryList.tag.clear();
+ entryList.data.clear();
+
+ serverResult = curl_easy_perform(connectionHandle);
+
+ // Check the last entry matches the HREF and if it
+ // does then delete it.
+
+ if (serverResult == CURLE_OK){
+ connectionServerResult.result = CALDAVQUERYRESULT_OK;
+ } else {
+ connectionServerResult.result = CALDAVQUERYRESULT_SERVERERROR;
+ }
+ connectionServerResult.code = serverResult;
+ curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &connectionServerResult.httpCode);
+
+ if (serverResult != CURLE_OK){
+
+ return entryList;
+
+ }
+
+ entryList = ProcessXMLEntryList();
+
+ // Second query: Get the list of contact data for the contacts that have
+ // beenchanged.