}
+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
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