X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fobjects%2FCalDAV%2FCalDAV.cpp;h=001743f808c43691c316e806d9cdd9494ef62ec4;hb=be97678f3efdc2b38b5dcc60850531dd5e394a5b;hp=51a1ec632181b6766813a76d84f0e930bcd4f562;hpb=fb7334af110912e40389f059adcf58c4a289a881;p=xestiacalendar%2F.git diff --git a/source/objects/CalDAV/CalDAV.cpp b/source/objects/CalDAV/CalDAV.cpp index 51a1ec6..001743f 100644 --- a/source/objects/CalDAV/CalDAV.cpp +++ b/source/objects/CalDAV/CalDAV.cpp @@ -437,12 +437,13 @@ string CalDAV::GetCalendarHome(string UserPrincipalURI){ // Reset the changed settings. - string OriginalServerAddress = BuildServerAddress(&ConnectionData, "/principals"); + string OriginalServerAddress = BuildServerAddress(&ConnectionData, "/principals/"); curl_easy_setopt(ConnectionHandle, CURLOPT_URL, OriginalServerAddress.c_str()); 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 CalendarHomeURI; @@ -534,6 +535,95 @@ CalDAVCalendarList CalDAV::GetCalendars(){ } +CalDAVServerResult CalDAV::AddCalendar(string CalendarName){ + + CalDAVServerResult ServerResult; + CalDAVSendData CalendarAddSendData; + + // 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. + + string CalendarListURLAddress = BuildServerAddress(&ConnectionData, CalendarHomeURL); + + string CalendarAddRequest = "\n" + "\n" + " \n" + " \n" + " "; + CalendarAddRequest += CalendarName; + CalendarAddRequest += "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; + + CalendarAddSendData.readptr = &CalendarAddRequest; + CalendarAddSendData.sizeleft = CalendarAddRequest.size(); + + // Setup the header. + + struct curl_slist *CalendarRequestHeader = NULL; + + //curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, CalendarRequestHeader); + curl_easy_setopt(ConnectionHandle, CURLOPT_URL, CalendarListURLAddress.c_str()); + curl_easy_setopt(ConnectionHandle, CURLOPT_CUSTOMREQUEST, "MKCALENDAR"); + curl_easy_setopt(ConnectionHandle, CURLOPT_UPLOAD, 1L); + curl_easy_setopt(ConnectionHandle, CURLOPT_READDATA, &CalendarAddSendData); + 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); + + return ServerResult; + +} + bool CalDAVObjectValidSettings(CalDAVConnectionData *ConnData){ // Check if the passed CalDAV Connection Data is has