X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fobjects%2FCalDAV%2FCalDAV.cpp;h=467f3e18d2b872892c137a53ada0bcc9a6a19b62;hb=3511800e4e2c6630a24a4a4945f252f976da75c8;hp=55ee65a983c25fa6825a1a1b0a19eed515f8dd0c;hpb=8916c05c5281bf0c97419df6e7ce6d641c56fb3e;p=xestiacalendar%2F.git diff --git a/source/objects/CalDAV/CalDAV.cpp b/source/objects/CalDAV/CalDAV.cpp index 55ee65a..467f3e1 100644 --- a/source/objects/CalDAV/CalDAV.cpp +++ b/source/objects/CalDAV/CalDAV.cpp @@ -511,17 +511,13 @@ CalDAVCalendarList CalDAV::GetCalendars(){ //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); - - // Process the received XML data into a list of calendars - // and locations. + 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){ @@ -529,8 +525,21 @@ CalDAVCalendarList CalDAV::GetCalendars(){ } + // Process the received XML data into a list of calendars + // and locations. + 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; } @@ -829,6 +838,128 @@ CalDAVServerResult CalDAV::EditCalendarDescription(string *CalendarHREF, return ServerResult; +} + +CalDAVServerResult CalDAV::DeleteCalendar(string *CalendarHREF){ + + CalDAVServerResult ServerResult; + + // Build the server address. + + string UserPrincipalURI = ""; + UserPrincipalURI = GetUserPrincipal(); + + if (UserPrincipalURI.size() == 0){ + + return ServerResult; + + } + + string CalendarHomeURI = ""; + CalendarHomeURI = GetCalendarHome(UserPrincipalURI); + + // Generate the UUID. + + string UUIDValue = GenerateUUID(); + UUIDValue.erase(UUIDValue.end()-1); + + string CalendarHomeURL = CalendarHomeURI; + CalendarHomeURL.append(UUIDValue); + CalendarHomeURL.append("/"); + + // Build the calendar list address. + + struct curl_slist *DeleteRequestHeader = NULL; + + DeleteRequestHeader = curl_slist_append(DeleteRequestHeader, "Depth: infinity"); + + string CalendarDeleteURLAddress = BuildServerAddress(&ConnectionData, (*CalendarHREF)); + + curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, DeleteRequestHeader); + curl_easy_setopt(ConnectionHandle, CURLOPT_URL, CalendarDeleteURLAddress.c_str()); + curl_easy_setopt(ConnectionHandle, CURLOPT_CUSTOMREQUEST, "DELETE"); + + // Delete the calendar. + + ServerData.clear(); + ServerHeader.clear(); + + CURLcode ServerConnectionResult = curl_easy_perform(ConnectionHandle); + + if (ServerConnectionResult == CURLE_OK){ + ServerResult.Result = CALDAVQUERYRESULT_OK; + } else { + ServerResult.Result = CALDAVQUERYRESULT_SERVERERROR; + } + ServerResult.Code = ServerConnectionResult; + curl_easy_getinfo(ConnectionHandle, CURLINFO_RESPONSE_CODE, &ServerResult.HTTPCode); + + // 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); + curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, NULL); + + return ServerResult; + +} + +CalDAVServerResult CalDAV::AddEntry(string *CalendarEntryHREF, string *EntryData){ + + // Add an entry to the calendar collection. + + CalDAVServerResult ServerResult; + CalDAVSendData EntryAddSendData; + + // Build the calendar list address. + + string EntryAddURLAddress = BuildServerAddress(&ConnectionData, (*CalendarEntryHREF)); + + EntryAddSendData.readptr = EntryData; + EntryAddSendData.sizeleft = EntryData->size(); + + struct curl_slist *CalendarRequestHeader = NULL; + + CalendarRequestHeader = curl_slist_append(CalendarRequestHeader, "Content-Type: text/calendar; charset=utf-8"); + + curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, CalendarRequestHeader); + curl_easy_setopt(ConnectionHandle, CURLOPT_URL, EntryAddURLAddress.c_str()); + curl_easy_setopt(ConnectionHandle, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_easy_setopt(ConnectionHandle, CURLOPT_UPLOAD, 1L); + curl_easy_setopt(ConnectionHandle, CURLOPT_READDATA, &EntryAddSendData); + curl_easy_setopt(ConnectionHandle, CURLOPT_READFUNCTION, CalDAVSend); + + // Process the data. + + ServerData.clear(); + ServerHeader.clear(); + + CURLcode ServerConnectionResult = curl_easy_perform(ConnectionHandle); + + if (ServerConnectionResult == CURLE_OK){ + ServerResult.Result = CALDAVQUERYRESULT_OK; + } else { + ServerResult.Result = CALDAVQUERYRESULT_SERVERERROR; + } + ServerResult.Code = ServerConnectionResult; + curl_easy_getinfo(ConnectionHandle, CURLINFO_RESPONSE_CODE, &ServerResult.HTTPCode); + + // 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); + curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, NULL); + + return ServerResult; + } bool CalDAVObjectValidSettings(CalDAVConnectionData *ConnData){