1 // CalDAV.cpp - CalDAV Connection Object.
3 // (c) 2016-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Calendar is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Calendar is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
23 size_t CalDAVReceive(char *receivedBuffer, size_t size, size_t newMemoryBytes, string *stringPointer)
26 stringPointer->append(receivedBuffer, newMemoryBytes);
28 return size * newMemoryBytes;
32 size_t CalDAVSend(char *sendBuffer, size_t size, size_t newMemoryBytes, void *dataStruct){
34 struct CalDAVSendData *uploadPtr = (struct calDAVSendData *)dataStruct;
36 if (uploadPtr->sizeleft){
38 uploadPtr->sizeleft--;
41 charSend = (*uploadPtr->readptr)[uploadPtr->seek];
43 *sendBuffer = charSend;
57 // Setup the objects within the CalDAV connection
60 connectionHandle = curl_easy_init();
66 // Destory the objects within the CalDAV connection
69 curl_easy_cleanup(connectionHandle);
70 connectionHandle = nullptr;
74 void CalDAV::SetupConnectionData(CalDAVConnectionData *connData){
76 // Check if ConnData is a nullptr, return if it is.
78 if (connData == nullptr){
82 // Set the connection settings to the values from ConnData.
84 connectionData = (*connData);
88 CalDAVStatus CalDAV::GetConnectionData(){
90 // Get the current connection settings for the CalDAV
91 // connection object and return a CalDAVStatus object.
93 CalDAVStatus connectionStatus;
95 connectionStatus.hostname = connectionData.hostname;
96 connectionStatus.port = connectionData.port;
97 connectionStatus.username = connectionData.username;
98 connectionStatus.prefix = connectionData.prefix;
99 connectionStatus.useSSL = connectionData.useSSL;
100 connectionStatus.timeout = connectionData.timeout;
102 return connectionStatus;
106 CalDAVServerResult CalDAV::Connect(){
108 CalDAVServerResult serverResult;
110 string serverAddress = "";
111 string serverUserPass = "";
113 // Setup the server address.
115 serverAddress = BuildServerAddress(&connectionData, "/principals/");
117 // Setup the server password.
119 ServerUserPass += connectionData.username;
120 ServerUserPass += ":";
121 ServerUserPass += connectionData.password;
123 curl_easy_setopt(connectionHandle, CURLOPT_URL, serverAddress.c_str());
124 curl_easy_setopt(connectionHandle, CURLOPT_USERPWD, serverUserPass.c_str());
125 curl_easy_setopt(connectionHandle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
126 curl_easy_setopt(connectionHandle, CURLOPT_FAILONERROR, 1L);
127 curl_easy_setopt(connectionHandle, CURLOPT_TIMEOUT, connectionData.timeout);
128 curl_easy_setopt(connectionHandle, CURLOPT_WRITEFUNCTION, calDAVReceive);
129 curl_easy_setopt(connectionHandle, CURLOPT_WRITEDATA, &serverData);
130 curl_easy_setopt(connectionHandle, CURLOPT_WRITEHEADER, &serverHeader);
132 // Connect to the CalDAV server.
134 serverResult.code = curl_easy_perform(connectionHandle);
136 // Process the result received from the server.
138 if (serverResult.code != CURLE_OK){
140 serverResult.result = CALDAVQUERYRESULT_SERVERERROR;
144 serverResult.result = CALDAVQUERYRESULT_OK;
148 // Get the HTTP code.
150 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &serverResult.httpCode);
156 CalDAVServerResult CalDAV::GetServerResult(){
158 return connectionServerResult;
162 CalDAVServerSupport CalDAV::GetServerSupport(){
164 CalDAVServerSupport serverStatus;
166 // Setup the server connection.
168 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "OPTIONS");
170 CURLcode serverResult = curl_easy_perform(connectionHandle);
174 if (serverResult == CURLE_OK){
175 connectionServerResult.result = CALDAVQUERYRESULT_OK;
177 connectionServerResult.result = CALDAVQUERYRESULT_SERVERERROR;
179 connectionServerResult.code = serverResult;
180 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &connectionServerResult.httpCode);
182 if (serverResult != CURLE_OK){
186 // Check that the server header has data in,
187 // otherwise return an "empty" CalDAVServerSupport.
189 if (serverHeader.size() == 0){
193 // Process each line looking for the first DAV header
196 bool newlineMode = true;
200 for (int charSeek = 0; charSeek < serverHeader.size(); charSeek++){
202 if (newlineMode == true){
204 // Check if we have reached the end of the string.
206 if (charSeek >= serverHeader.size()){
212 // Check the first four letters to make sure
215 string davHeaderCheck = "";
218 davHeaderCheck = serverHeader.substr(charSeek, 4);
221 catch (out_of_range &oor){
225 if (davHeaderCheck == "DAV:"){
229 for (; charSeek < serverHeader.size(); charSeek++){
231 if (serverHeader[charSeek] == '\n'){
237 davLine.push_back(serverHeader[charSeek]);
249 if (serverHeader[charSeek] == '\n'){
257 // Process the DAV line.
259 vector<string> davLineData;
260 string davSegmentString;
262 for (int charSeek = 0; charSeek < davLine.size(); charSeek++){
264 if (davLine[charSeek] == ' '){
268 if (davLine[charSeek] == ','){
270 davLineData.push_back(davSegmentString);
271 davSegmentString.clear();
276 davSegmentString += davLine[charSeek];
280 // Process the DAV values and set each value
281 // to true as required.
283 for (int davItemSeek = 0;
284 davItemSeek < davLineData.size();
287 if (davLineData.at(davItemSeek) == "calendar-access"){
289 serverStatus.basicSupport = true;
295 // Reset the connection status.
297 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);
303 string CalDAV::GetUserPrincipal(){
305 string currentUserPrincipal = "";
306 string userPrincipalRequest = "";
307 CalDAVSendData userPrincipalSendData;
309 userPrincipalRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
310 "<d:propfind xmlns:d=\"DAV:\">\n"
312 " <d:current-user-principal />\n"
316 userPrincipalSendData.readptr = &userPrincipalRequest;
317 userPrincipalSendData.sizeleft = userPrincipalRequest.size();
321 struct curl_slist *userPrincipalRequestHeader = NULL;
323 userPrincipalRequestHeader = curl_slist_append(userPrincipalRequestHeader, "Depth: 0");
324 userPrincipalRequestHeader = curl_slist_append(userPrincipalRequestHeader, "Prefer: return-minimal");
325 userPrincipalRequestHeader = curl_slist_append(userPrincipalRequestHeader, "Content-Type: application/xml; charset=utf-8");
327 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, userPrincipalRequestHeader);
329 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
330 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
331 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &userPrincipalSendData);
332 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, calDAVSend);
337 serverHeader.clear();
339 CURLcode serverResult = curl_easy_perform(connectionHandle);
343 if (serverResult == CURLE_OK){
344 connectionServerResult.Result = CALDAVQUERYRESULT_OK;
346 connectionServerResult.Result = CALDAVQUERYRESULT_SERVERERROR;
348 connectionServerResult.Code = serverResult;
349 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &connectionServerResult.HTTPCode);
351 if (serverResult != CURLE_OK){
353 return currentUserPrincipal;
357 // Process the User Principal from the ServerData.
359 currentUserPrincipal = ProcessXMLUserPrincipal();
361 // Reset the changed settings.
363 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
364 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
365 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
367 return currentUserPrincipal;
371 string CalDAV::GetCalendarHome(string userPrincipalURI){
373 string calendarHomeURI = "";
375 // Build the Calendar Home URL address.
377 string calendarHomeURL = BuildServerAddress(&connectionData, userPrincipalURI);
379 // Setup the header request.
381 CalDAVSendData calendarHomeSendData;
383 string calendarHomeRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
384 "<d:propfind xmlns:d=\"DAV:\" xmlns:c=\"urn:ietf:params:xml:ns:caldav\">\n"
386 " <c:calendar-home-set />\n"
390 calendarHomeSendData.readptr = &calendarHomeRequest;
391 calendarHomeSendData.sizeleft = calendarHomeRequest.size();
395 struct curl_slist *calendarRequestHeader = NULL;
397 calendarRequestHeader = curl_slist_append(calendarRequestHeader, "Depth: 0");
398 calendarRequestHeader = curl_slist_append(calendarRequestHeader, "Prefer: return-minimal");
399 calendarRequestHeader = curl_slist_append(calendarRequestHeader, "Content-Type: application/xml; charset=utf-8");
401 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, calendarRequestHeader);
402 curl_easy_setopt(connectionHandle, CURLOPT_URL, calendarHomeURL.c_str());
403 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
404 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
405 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &calendarHomeSendData);
406 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, calDAVSend);
411 serverHeader.clear();
413 CURLcode serverResult = curl_easy_perform(connectionHandle);
417 if (serverResult == CURLE_OK){
418 connectionServerResult.result = CALDAVQUERYRESULT_OK;
420 connectionServerResult.result = CALDAVQUERYRESULT_SERVERERROR;
422 connectionServerResult.code = serverResult;
423 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &connectionServerResult.httpCode);
425 if (serverResult != CURLE_OK){
427 return calendarHomeURI;
431 // Process the User Principal from the ServerData.
433 calendarHomeURI = ProcessXMLCalendarHome();
435 // Reset the changed settings.
437 string originalServerAddress = BuildServerAddress(&connectionData, "/principals/");
438 curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
440 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
441 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
442 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
443 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
445 return calendarHomeURI;
449 CalDAVCalendarList CalDAV::GetCalendars(){
451 CalDAVCalendarList serverList;
452 CalDAVSendData calendarListSendData;
454 // Build the server address.
456 string userPrincipalURI = "";
457 userPrincipalURI = GetUserPrincipal();
459 if (userPrincipalURI.size() == 0){
465 string calendarHomeURI = "";
466 calendarHomeURI = GetCalendarHome(userPrincipalURI);
468 string calendarListURLAddress = BuildServerAddress(&connectionData, calendarHomeURI);
470 string calendarListRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
471 "<d:propfind xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\""
472 " xmlns:c=\"urn:ietf:params:xml:ns:caldav\" xmlns:x0=\"http://apple.com/ns/ical/\">\n"
474 " <d:resourcetype />\n"
475 " <d:displayname />\n"
476 " <d:sync-token />\n"
477 " <x0:calendar-color />\n"
478 " <x0:calendar-order />\n"
480 " <c:supported-calendar-component-set />\n"
481 " <c:calendar-description />\n"
485 calendarListSendData.readptr = &calendarListRequest;
486 calendarListSendData.sizeleft = calendarListRequest.size();
490 struct curl_slist *calendarListRequestHeader = NULL;
492 calendarListRequestHeader = curl_slist_append(calendarListRequestHeader, "Depth: 1");
493 calendarListRequestHeader = curl_slist_append(calendarListRequestHeader, "Prefer: return-minimal");
494 calendarListRequestHeader = curl_slist_append(calendarListRequestHeader, "Content-Type: application/xml; charset=utf-8");
496 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, calendarListRequestHeader);
497 curl_easy_setopt(connectionHandle, CURLOPT_URL, calendarListURLAddress.c_str());
498 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
499 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
500 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &calendarListSendData);
501 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, calDAVSend);
506 serverHeader.clear();
508 CURLcode serverResult = curl_easy_perform(connectionHandle);
510 //ServerList = ProcessXMLCalendarList();
512 if (serverResult == CURLE_OK){
513 connectionServerResult.result = CALDAVQUERYRESULT_OK;
515 connectionServerResult.result = CALDAVQUERYRESULT_SERVERERROR;
517 connectionServerResult.code = serverResult;
518 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &connectionServerResult.httpCode);
520 if (cerverResult != CURLE_OK){
526 // Process the received XML data into a list of calendars
529 serverList = ProcessXMLCalendarList();
531 // Restore the original settings.
533 string originalServerAddress = BuildServerAddress(&connectionData, "/principals/");
535 curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
536 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);
537 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
538 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
539 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
545 CalDAVEntryList CalDAV::GetEntryList(string *calendarHREF){
547 CalDAVEntryList entryList;
548 CalDAVSendData entryListSendData;
550 if (calendarHREF->size() == 0){
556 string entryListURLAddress = BuildServerAddress(&connectionData, *calendarHREF);
558 string entryListRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
560 /*if (CalendarTag == nullptr){*/
562 entryListRequest += "<c:calendar-query xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\""
563 " xmlns:c=\"urn:ietf:params:xml:ns:caldav\" xmlns:x0=\"http://apple.com/ns/ical/\">\n"
566 " <c:calendar-data />\n"
569 " <c:comp-filter name=\"VCALENDAR\" />\n"
571 "</c:calendar-query>";
575 EntryListRequest += "<d:sync-collection xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\""
576 " xmlns:c=\"urn:ietf:params:xml:ns:caldav\" xmlns:x0=\"http://apple.com/ns/ical/\">\n"
578 EntryListRequest += *CalendarTag;
579 EntryListRequest += "</d:sync-token>\n"
580 " <d:sync-level>1</d:sync-level>\n"
583 " <c:calendar-data />\n"
585 "</d:sync-collection>";
589 entryListSendData.readptr = &entryListRequest;
590 entryListSendData.sizeleft = entryListRequest.size();
592 struct curl_slist *entryListRequestHeader = NULL;
594 entryListRequestHeader = curl_slist_append(entryListRequestHeader, "Content-Type: application/xml; charset=utf-8");
596 /*if (CalendarTag != nullptr){
598 EntryListRequestHeader = curl_slist_append(EntryListRequestHeader, "Content-Type: application/xml; charset=utf-8");
599 EntryListRequestHeader = curl_slist_append(EntryListRequestHeader, "Content-Type: application/xml; charset=utf-8");
603 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, entryListRequestHeader);
604 curl_easy_setopt(connectionHandle, CURLOPT_URL, entryListURLAddress.c_str());
605 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "REPORT");
606 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
607 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &entryListSendData);
608 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, calDAVSend);
613 serverHeader.clear();
615 CURLcode serverResult = curl_easy_perform(connectionHandle);
617 //ServerList = ProcessXMLCalendarList();
619 if (serverResult == CURLE_OK){
620 connectionServerResult.result = CALDAVQUERYRESULT_OK;
622 connectionServerResult.result = CALDAVQUERYRESULT_SERVERERROR;
624 connectionServerResult.code = serverResult;
625 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &connectionServerResult.httpCode);
627 if (serverResult != CURLE_OK){
633 // Process the received XML data into a list of calendars
636 entryList = ProcessXMLEntryList();
638 // Restore the original settings.
640 string originalServerAddress = BuildServerAddress(&connectionData, "/principals/");
642 curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
643 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);
644 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
645 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
646 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
652 CalDAVEntryList CalDAV::GetEntryList(string *calendarHREF, string *calendarTag){
654 CalDAVEntryList entryList;
655 CalDAVSendData entryListSendData;
657 if (calendarHREF->size() == 0){
663 string entryListURLAddress = BuildServerAddress(&connectionData, *calendarHREF);
665 // First query: Get the list of contacts that need to be updated.
667 string entryListRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
669 entryListRequest += "<d:sync-collection xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\""
670 " xmlns:c=\"urn:ietf:params:xml:ns:caldav\" xmlns:x0=\"http://apple.com/ns/ical/\">\n"
673 if (calendarTag != nullptr){
675 entryListRequest += *calendarTag;
679 entryListRequest += "";
683 entryListRequest += "</d:sync-token>\n"
684 " <d:sync-level>1</d:sync-level>\n"
688 "</d:sync-collection>";
690 entryListSendData.readptr = &entryListRequest;
691 entryListSendData.sizeleft = entryListRequest.size();
693 struct curl_slist *entryListRequestHeader = NULL;
695 entryListRequestHeader = curl_slist_append(entryListRequestHeader, "Content-Type: application/xml; charset=utf-8");
697 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, entryListRequestHeader);
698 curl_easy_setopt(connectionHandle, CURLOPT_URL, entryListURLAddress.c_str());
699 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "REPORT");
700 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
701 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &entryListSendData);
702 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, calDAVSend);
707 serverHeader.clear();
709 CURLcode serverResult = curl_easy_perform(connectionHandle);
711 if (serverResult == CURLE_OK){
712 connectionServerResult.result = CALDAVQUERYRESULT_OK;
714 connectionServerResult.result = CALDAVQUERYRESULT_SERVERERROR;
716 connectionServerResult.code = serverResult;
717 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &connectionServerResult.httpCode);
719 if (serverResult != CURLE_OK){
725 entryList = ProcessXMLSyncTokenList();
727 // Check the last entry matches the HREF and if it
728 // does then delete it.
730 if (entryList.href.size() > 0) {
732 if (entryList.href.rbegin()->second == *calendarHREF){
734 entryList.href.erase((entryList.href.size() - 1));
735 entryList.tag.erase((entryList.href.size() - 1));
736 entryList.data.erase((entryList.href.size() - 1));
742 // Build the list into a new list for getting the new
743 // calendar data with.
745 entryListRequest.clear();
747 entryListRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
749 entryListRequest += "<c:calendar-multiget xmlns:d=\"DAV:\" "
750 " xmlns:c=\"urn:ietf:params:xml:ns:caldav\">\n"
753 " <c:calendar-data />\n"
756 for (std::map<int,string>::iterator hrefIter = entryList.href.begin();
757 hrefIter != entryList.href.end(); hrefIter++){
759 string entryListHREFString = hrefIter->second;
761 entryListRequest += " <d:href>";
762 entryListRequest += entryListHREFString;
763 entryListRequest += "</d:href>\n";
767 entryListRequest += "</c:calendar-multiget>";
769 CalDAVSendData updatedEntryListSendData;
771 updatedEntryListSendData.readptr = &entryListRequest;
772 updatedEntryListSendData.sizeleft = entryListRequest.size();
774 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, entryListRequestHeader);
775 curl_easy_setopt(connectionHandle, CURLOPT_URL, entryListURLAddress.c_str());
776 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "REPORT");
777 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
778 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &updatedEntryListSendData);
779 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, calDAVSend);
781 // Get the updated calendar data.
784 serverHeader.clear();
785 entryList.href.clear();
786 entryList.tag.clear();
787 entryList.data.clear();
789 serverResult = curl_easy_perform(connectionHandle);
791 // Check the last entry matches the HREF and if it
792 // does then delete it.
794 if (serverResult == CURLE_OK){
795 connectionServerResult.result = CALDAVQUERYRESULT_OK;
797 connectionServerResult.result = CALDAVQUERYRESULT_SERVERERROR;
799 connectionServerResult.code = serverResult;
800 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &connectionServerResult.httpCode);
802 if (serverResult != CURLE_OK){
808 entryList = ProcessXMLEntryList();
810 // Second query: Get the list of contact data for the contacts that have
813 // Restore the original settings.
815 string originalServerAddress = BuildServerAddress(&connectionData, "/principals/");
817 curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
818 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);
819 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
820 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
821 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
827 CalDAVServerResult CalDAV::AddCalendar(string calendarName){
829 CalDAVServerResult serverResult;
831 AddCalendar(&calendarName, nullptr);
837 CalDAVServerResult CalDAV::AddCalendar(string *calendarName, string *calendarShortName){
839 CalDAVServerResult serverResult;
840 CalDAVSendData calendarAddSendData;
842 // Build the server address.
844 string userPrincipalURI = "";
845 userPrincipalURI = GetUserPrincipal();
847 if (userPrincipalURI.size() == 0){
853 string calendarHomeURI = "";
854 calendarHomeURI = GetCalendarHome(userPrincipalURI);
856 // Generate the UUID.
858 string UUIDValue = "";
860 if (calendarShortName == nullptr){
862 UUIDValue = GenerateUUID();
863 UUIDValue.erase(UUIDValue.end()-1);
867 UUIDValue = *calendarShortName;
871 string calendarHomeURL = calendarHomeURI;
872 calendarHomeURL.append(UUIDValue);
873 calendarHomeURL.append("/");
875 // Build the calendar list address.
877 string calendarListURLAddress = BuildServerAddress(&connectionData, calendarHomeURL);
879 string calendarAddRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
880 "<c:mkcalendar xmlns:d=\"DAV:\" xmlns:c=\"urn:ietf:params:xml:ns:caldav\">\n"
884 calendarAddRequest += *calendarName;
885 calendarAddRequest += "</d:displayname>\n"
886 " <c:supported-calendar-component-set>\n"
887 " <c:comp name=\"VTODO\"/>\n"
888 " <c:comp name=\"VEVENT\"/>\n"
889 " </c:supported-calendar-component-set>\n"
894 calendarAddSendData.readptr = &calendarAddRequest;
895 calendarAddSendData.sizeleft = calendarAddRequest.size();
899 struct curl_slist *calendarRequestHeader = NULL;
901 //curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, CalendarRequestHeader);
902 curl_easy_setopt(connectionHandle, CURLOPT_URL, calendarListURLAddress.c_str());
903 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "MKCALENDAR");
904 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
905 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &calendarAddSendData);
906 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, calDAVSend);
911 serverHeader.clear();
913 CURLcode serverConnectionResult = curl_easy_perform(connectionHandle);
915 if (serverConnectionResult == CURLE_OK){
916 serverResult.result = CALDAVQUERYRESULT_OK;
918 serverResult.result = CALDAVQUERYRESULT_SERVERERROR;
920 serverResult.code = serverConnectionResult;
921 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &serverResult.httpCode);
923 // Restore the original settings.
925 string originalServerAddress = BuildServerAddress(&connectionData, "/principals/");
926 curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
927 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);
928 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
929 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
930 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
936 CalDAVServerResult CalDAV::EditCalendarProcess(string *calendarHREF,
937 string *calendarName,
938 Colour *calendarColour,
939 string *calendarDescription,
942 CalDAVServerResult serverResult;
943 CalDAVSendData calendarEditSendData;
945 // Build the server address.
947 string userPrincipalURI = "";
948 userPrincipalURI = GetUserPrincipal();
950 if (userPrincipalURI.size() == 0){
956 string calendarHomeURI = "";
957 calendarHomeURI = GetCalendarHome(userPrincipalURI);
959 // Generate the UUID.
961 string UUIDValue = GenerateUUID();
962 UUIDValue.erase(UUIDValue.end()-1);
964 string calendarHomeURL = calendarHomeURI;
965 calendarHomeURL.append(UUIDValue);
966 calendarHomeURL.append("/");
968 // Build the calendar list address.
970 string calendarEditURLAddress = BuildServerAddress(&connectionData, (*calendarHREF));
972 string calendarEditRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
973 "<d:propertyupdate xmlns:d=\"DAV:\" xmlns:c=\"urn:ietf:params:xml:ns:caldav\"\n"
974 " xmlns:x0=\"http://apple.com/ns/ical/\">\n"
978 // Update the calendar name.
980 if (calendarName != nullptr){
982 calendarEditRequest += "<d:displayname>";
983 calendarEditRequest += (*calendarName);
984 calendarEditRequest += "</d:displayname>\n";
988 // Update the calendar colour.
990 if (calendarColour != nullptr){
992 calendarEditRequest += "<x0:calendar-color>";
993 calendarEditRequest += (*calendarColour);
994 calendarEditRequest += "</x0:calendar-color>\n";
998 // Update the calendar description.
1000 if (calendarDescription != nullptr){
1002 calendarEditRequest += "<c:calendar-description>";
1003 calendarEditRequest += (*calendarDescription);
1004 calendarEditRequest += "</c:calendar-description>\n";
1008 // Update the calendar order.
1010 if (calendarOrder != nullptr){
1012 calendarEditRequest += "<x0:calendar-order>";
1013 calendarEditRequest += to_string((*calendarOrder));
1014 calendarEditRequest += "</x0:calendar-order>\n";
1018 calendarEditRequest += " </d:prop>\n"
1020 "</d:propertyupdate>";
1022 calendarEditSendData.readptr = &calendarEditRequest;
1023 calendarEditSendData.sizeleft = calendarEditRequest.size();
1025 // Setup the header.
1027 struct curl_slist *calendarRequestHeader = NULL;
1029 //curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, CalendarRequestHeader);
1030 curl_easy_setopt(connectionHandle, CURLOPT_URL, calendarEditURLAddress.c_str());
1031 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "PROPPATCH");
1032 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
1033 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &calendarEditSendData);
1034 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, calDAVSend);
1036 // Process the data.
1039 serverHeader.clear();
1041 CURLcode serverConnectionResult = curl_easy_perform(connectionHandle);
1043 if (serverConnectionRsult == CURLE_OK){
1044 serverResult.result = CALDAVQUERYRESULT_OK;
1046 serverResult.result = CALDAVQUERYRESULT_SERVERERROR;
1048 serverResult.code = serverConnectionResult;
1049 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &serverResult.httpCode);
1051 // Restore the original settings.
1053 string originalServerAddress = BuildServerAddress(&connectionData, "/principals/");
1054 curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
1055 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);
1056 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
1057 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
1058 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
1060 return ServerResult;
1064 CalDAVServerResult CalDAV::EditCalendar(string *calendarHREF,
1065 string *calendarName,
1066 Colour *calendarColour,
1067 string *calendarDescription,
1068 int *calendarOrder){
1070 CalDAVServerResult serverResult;
1072 serverResult = EditCalendarProcess(calendarHREF,
1075 calendarDescription,
1078 return serverResult;
1082 CalDAVServerResult CalDAV::EditCalendar(string *CalendarHREF,
1083 Colour *CalendarColour){
1086 CalDAVServerResult serverResult;
1088 serverResult = EditCalendarProcess(calendarHREF,
1094 return serverResult;
1098 CalDAVServerResult CalDAV::EditCalendar(string *calendarHREF,
1099 string *calendarName){
1101 CalDAVServerResult serverResult;
1103 serverResult = EditCalendarProcess(calendarHREF,
1109 return serverResult;
1113 CalDAVServerResult CalDAV::EditCalendar(string *calendarHREF,
1114 int *calendarOrder){
1116 CalDAVServerResult serverResult;
1118 serverResult = EditCalendarProcess(calendarHREF,
1124 return serverResult;
1128 CalDAVServerResult CalDAV::EditCalendarDescription(string *calendarHREF,
1129 string *calendarDescription){
1131 CalDAVServerResult serverResult;
1133 serverResult = EditCalendarProcess(calendarHREF,
1136 calendarDescription,
1139 return serverResult;
1143 CalDAVServerResult CalDAV::DeleteCalendar(string *calendarHREF){
1145 CalDAVServerResult serverResult;
1147 // Build the server address.
1149 string userPrincipalURI = "";
1150 userPrincipalURI = GetUserPrincipal();
1152 if (userPrincipalURI.size() == 0){
1154 return serverResult;
1158 string calendarHomeURI = "";
1159 calendarHomeURI = GetCalendarHome(userPrincipalURI);
1161 // Generate the UUID.
1163 string UUIDValue = GenerateUUID();
1164 UUIDValue.erase(UUIDValue.end()-1);
1166 string calendarHomeURL = calendarHomeURI;
1167 calendarHomeURL.append(UUIDValue);
1168 calendarHomeURL.append("/");
1170 // Build the calendar list address.
1172 struct curl_slist *deleteRequestHeader = NULL;
1174 deleteRequestHeader = curl_slist_append(deleteRequestHeader, "Depth: infinity");
1176 string calendarDeleteURLAddress = BuildServerAddress(&connectionData, (*calendarHREF));
1178 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, deleteRequestHeader);
1179 curl_easy_setopt(connectionHandle, CURLOPT_URL, calendarDeleteURLAddress.c_str());
1180 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "DELETE");
1182 // Delete the calendar.
1185 serverHeader.clear();
1187 CURLcode serverConnectionResult = curl_easy_perform(connectionHandle);
1189 if (serverConnectionResult == CURLE_OK){
1190 serverResult.Result = CALDAVQUERYRESULT_OK;
1192 serverResult.Result = CALDAVQUERYRESULT_SERVERERROR;
1194 serverResult.code = serverConnectionResult;
1195 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &serverResult.httpCode);
1197 // Restore the original settings.
1199 string originalServerAddress = BuildServerAddress(&connectionData, "/principals/");
1200 curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
1201 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);
1202 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
1203 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
1204 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
1205 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
1207 return serverResult;
1211 CalDAVServerResult CalDAV::GetEntryETag(string *calendarEntryHREF, string *eTagValue){
1213 CalDAVServerResult serverResult;
1214 CalDAVSendData entryETagGetData;
1216 // Build the server address.
1218 string userPrincipalURI = "";
1219 userPrincipalURI = GetUserPrincipal();
1221 if (userPrincipalURI.size() == 0){
1223 return serverResult;
1227 string calendarHomeURI = "";
1228 calendarHomeURI = GetCalendarHome(userPrincipalURI);
1230 // Split the path and filename.
1232 string entryURIPath;
1233 string entryFilename;
1235 SplitPathFilename(calendarEntryHREF, &entryURIPath, &entryFilename);
1237 // Build the request for the server.
1239 string entryETagRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1240 "<c:calendar-multiget xmlns:d=\"DAV:\" xmlns:c=\"urn:ietf:params:xml:ns:caldav\">\n"
1245 entryETagRequest += (*calendarEntryHREF);
1246 entryETagRequest += "</d:href>\n"
1247 "</c:calendar-multiget>";
1249 entryETagGetData.readptr = &entryETagRequest;
1250 entryETagGetData.sizeleft = entryETagRequest.size();
1252 // Build the calendar list address.
1254 struct curl_slist *getETagRequestHeader = NULL;
1256 getETagRequestHeader = curl_slist_append(getETagRequestHeader, "Depth: 1");
1257 getETagRequestHeader = curl_slist_append(getETagRequestHeader, "Prefer: return-minimal");
1258 getETagRequestHeader = curl_slist_append(getETagRequestHeader, "Content-Type: application/xml; charset=utf-8");
1260 string getETagURLAddress = BuildServerAddress(&connectionData, entryURIPath);
1262 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, getETagRequestHeader);
1263 curl_easy_setopt(connectionHandle, CURLOPT_URL, getETagURLAddress.c_str());
1264 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "REPORT");
1265 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
1266 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &entryETagGetData);
1267 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, calDAVSend);
1269 // Attempt to get the entity tag.
1272 serverHeader.clear();
1274 CURLcode serverConnectionResult = curl_easy_perform(connectionHandle);
1276 if (serverConnectionResult == CURLE_OK){
1277 serverResult.result = CALDAVQUERYRESULT_OK;
1279 serverResult.result = CALDAVQUERYRESULT_SERVERERROR;
1281 serverResult.code = serverConnectionResult;
1282 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &serverResult.httpCode);
1284 if (serverConnectionResult != CURLE_OK){
1285 return serverResult;
1288 // Get the entity tag from the result.
1290 *eTagValue = ProcessXMLEntryETag();
1292 // Restore the original settings.
1294 string originalServerAddress = BuildServerAddress(&connectionData, "/principals/");
1295 curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
1296 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);
1297 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
1298 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
1299 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
1300 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
1302 return serverResult;
1306 CalDAVServerResult CalDAV::AddEntry(string *calendarEntryHREF, string *entryData){
1308 // Add an entry to the calendar collection.
1310 CalDAVServerResult serverResult;
1311 CalDAVSendData entryAddSendData;
1313 // Build the calendar list address.
1315 string entryAddURLAddress = BuildServerAddress(&connectionData, (*calendarEntryHREF));
1317 entryAddSendData.readptr = entryData;
1318 entryAddSendData.sizeleft = entryData->size();
1320 struct curl_slist *calendarRequestHeader = NULL;
1322 calendarRequestHeader = curl_slist_append(calendarRequestHeader, "Content-Type: text/calendar; charset=utf-8");
1324 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, calendarRequestHeader);
1325 curl_easy_setopt(connectionHandle, CURLOPT_URL, entryAddURLAddress.c_str());
1326 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "PUT");
1327 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
1328 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &entryAddSendData);
1329 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, calDAVSend);
1331 // Process the data.
1334 serverHeader.clear();
1336 CURLcode serverConnectionResult = curl_easy_perform(connectionHandle);
1338 if (serverConnectionResult == CURLE_OK){
1339 serverResult.result = CALDAVQUERYRESULT_OK;
1341 serverResult.result = CALDAVQUERYRESULT_SERVERERROR;
1343 serverResult.code = serverConnectionResult;
1344 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &serverResult.httpCode);
1346 // Restore the original settings.
1348 string originalServerAddress = BuildServerAddress(&connectionData, "/principals/");
1349 curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
1350 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);
1351 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
1352 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
1353 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
1354 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
1356 return serverResult;
1360 CalDAVServerResult CalDAV::EditEntry(string *calendarEntryHREF, string *entryData, string *entryETag){
1362 // Edit an entry in the calendar collection.
1364 // Add an entry to the calendar collection.
1366 CalDAVServerResult serverResult;
1367 CalDAVSendData entryAddSendData;
1369 // Build the calendar list address.
1371 string entryAddURLAddress = BuildServerAddress(&connectionData, (*calendarEntryHREF));
1373 entryAddSendData.readptr = entryData;
1374 entryAddSendData.sizeleft = entryData->size();
1376 string ifMatchHeader = "If-Match: \"";
1377 ifMatchHeader.append(*entryETag);
1378 ifMatchHeader.append("\"");
1380 struct curl_slist *calendarRequestHeader = NULL;
1382 calendarRequestHeader = curl_slist_append(calendarRequestHeader, "Content-Type: text/calendar; charset=utf-8");
1383 calendarRequestHeader = curl_slist_append(calendarRequestHeader, ifMatchHeader.c_str());
1385 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, calendarRequestHeader);
1386 curl_easy_setopt(connectionHandle, CURLOPT_URL, entryAddURLAddress.c_str());
1387 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "PUT");
1388 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
1389 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &entryAddSendData);
1390 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, calDAVSend);
1392 // Process the data.
1395 serverHeader.clear();
1397 CURLcode serverConnectionResult = curl_easy_perform(connectionHandle);
1399 if (serverConnectionResult == CURLE_OK){
1400 serverResult.result = CALDAVQUERYRESULT_OK;
1402 serverResult.result = CALDAVQUERYRESULT_SERVERERROR;
1404 serverResult.code = serverConnectionResult;
1405 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &serverResult.httpCode);
1407 // Restore the original settings.
1409 string originalServerAddress = BuildServerAddress(&connectionData, "/principals/");
1410 curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
1411 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);
1412 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
1413 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
1414 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
1415 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
1417 return serverResult;
1421 CalDAVServerResult CalDAV::DeleteEntry(string *calendarEntryHREF){
1423 // Delete an entry in the calendar collection.
1425 CalDAVServerResult serverResult;
1427 // Build the calendar list address.
1429 string entryDeleteURLAddress = BuildServerAddress(&connectionData, (*calendarEntryHREF));
1431 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
1432 curl_easy_setopt(connectionHandle, CURLOPT_URL, entryDeleteURLAddress.c_str());
1433 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "DELETE");
1435 // Delete the calendar.
1438 serverHeader.clear();
1440 CURLcode serverConnectionResult = curl_easy_perform(connectionHandle);
1442 if (serverConnectionResult == CURLE_OK){
1443 serverResult.result = CALDAVQUERYRESULT_OK;
1445 serverResult.result = CALDAVQUERYRESULT_SERVERERROR;
1447 serverResult.code = serverConnectionResult;
1448 curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &serverResult.httpCode);
1450 // Restore the original settings.
1452 string originalServerAddress = BuildServerAddress(&connectionData, "/principals/");
1453 curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
1454 curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);
1455 curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
1456 curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
1457 curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
1458 curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
1460 return serverResult;
1464 bool CalDAVObjectValidSettings(CalDAVConnectionData *connData){
1466 // Check if the passed CalDAV Connection Data is has
1467 // an address set. Return false if nullptr is used.
1469 if (connData == nullptr){
1475 // Check the server hostname. Return false
1476 // if no value has been set.
1478 if (connData->hostname.size() == 0){
1484 // Check the server port. Return false if
1485 // no value has been set or the port number
1486 // is less than 1 or higher than 65535.
1488 if (connData->port < 1 || connData->port > 65535){
1494 // Check the server username. Return false
1495 // if no value has been set.
1497 if (connData->username.size() == 0){
1503 // Check the server password. Return false
1504 // if no value has been set.
1506 if (connData->password.size() == 0){
1512 // Cannot check UseSSL: It is either true
1515 // Cannot check Prefix: The prefix may need
1516 // to be worked out first.
1518 // No errors were found whilst checking so
1525 string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress){
1527 string serverAddress;
1529 // Setup the server address.
1531 if (connData->useSSL == true){
1532 serverAddress += "https://";
1534 serverAddress += "http://";
1537 serverAddress += connData->hostname;
1539 // Check if server port is 80, otherwise
1540 // specifiy the port number in the address.
1542 if (connData->port != 80){
1543 serverAddress += ":";
1544 serverAddress += to_string(connData->port);
1547 serverAddress += uriAddress;
1549 return serverAddress;