Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added the AddCalendar function.
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 17 Apr 2016 20:36:22 +0000 (21:36 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 17 Apr 2016 20:36:22 +0000 (21:36 +0100)
Added the AddCalendar function to the CalDAV object. Unit tests also
done for the function.

source/objects/CalDAV/CalDAV.cpp
source/objects/CalDAV/CalDAV.h
source/tests/xestiacalendar_caldav.h

index 51a1ec6..e2a787d 100644 (file)
@@ -534,6 +534,97 @@ 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+       "<c:mkcalendar xmlns:d=\"DAV:\" xmlns:c=\"urn:ietf:params:xml:ns:caldav\">\n"
+       " <d:set>\n"
+       "  <d:prop>\n"
+       "   <d:displayname>";
+       CalendarAddRequest += CalendarName;
+       CalendarAddRequest += "</d:displayname>\n"
+       "   <c:supported-calendar-component-set>\n"
+       "    <c:comp name=\"VTODO\"/>\n"
+       "    <c:comp name=\"VEVENT\"/>\n"
+       "   </c:supported-calendar-component-set>\n"
+       "  </d:prop>\n"
+       " </d:set>\n"
+       "</c:mkcalendar>";
+       
+       CalendarAddSendData.readptr = &CalendarAddRequest;
+       CalendarAddSendData.sizeleft = CalendarAddRequest.size();
+       
+       // Setup the header.
+       
+       struct curl_slist *CalendarRequestHeader = NULL;
+       
+       cout << CalendarListURLAddress << endl;
+       
+       //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
index aee045a..cbe065a 100644 (file)
@@ -29,6 +29,7 @@
 #include <map>
 #include "../../common/colour.h"
 #include "../../common/text.h"
+#include "../../common/uuid.h"
 
 using namespace std;
 
@@ -141,6 +142,7 @@ class CalDAV{
                CalDAVServerResult GetServerResult();
                CalDAVServerSupport GetServerSupport();
                CalDAVCalendarList GetCalendars();
+               CalDAVServerResult AddCalendar(string CalendarName);
        
                string GetUserPrincipal();
                string GetCalendarHome(string UserPrincipalURI);
index 8c9860b..2e5d9cb 100644 (file)
@@ -501,4 +501,54 @@ TEST(CalDAV, ListCalendars){
        ASSERT_EQ(207, ConnResult.HTTPCode);
        ASSERT_EQ(CURLE_OK, ConnResult.Code);
        
+}
+
+TEST(CalDAV, AddCalendar){
+       
+       CalDAVConnectionData ConnNormal;
+       string CurrentUserPrincipal;
+
+       bool ValidDataNormal = false;
+       
+       // Attempt to read the caldavtest.auth file.
+
+       ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
+       if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
+               ValidDataNormal = true;
+       }
+
+       ASSERT_EQ(true, ValidDataNormal);
+       
+       // Setup the connection.
+       
+       CalDAV ServerConnection;
+       
+       ServerConnection.SetupConnectionData(&ConnNormal);
+       
+       // Verify the connection settings.
+       
+       CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
+       
+       ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
+       ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
+       ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
+       ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
+       ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
+       
+       // Connect to the server.
+       
+       CalDAVServerResult ConnResult = ServerConnection.Connect();
+       
+       EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
+       ASSERT_EQ(200, ConnResult.HTTPCode);
+       ASSERT_EQ(CURLE_OK, ConnResult.Code);
+       
+       // Add a calendar to the server.
+       
+       ConnResult = ServerConnection.AddCalendar("New Calendar");
+       
+       EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
+       ASSERT_EQ(201, ConnResult.HTTPCode);
+       ASSERT_EQ(CURLE_OK, ConnResult.Code);
+       
 }
\ No newline at end of file
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy