Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Adde code and unit tests for checking CalDAV support.
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Wed, 2 Mar 2016 12:19:42 +0000 (12:19 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Wed, 2 Mar 2016 12:19:42 +0000 (12:19 +0000)
source/objects/CalDAV/CalDAV.cpp
source/objects/CalDAV/CalDAV.h
source/tests/xestiacalendar_caldav.h

index 21e8ddc..bcd710a 100644 (file)
@@ -133,6 +133,133 @@ CalDAVServerResult CalDAV::Connect(){
        
 }
 
+CalDAVServerSupport CalDAV::GetServerSupport(){
+
+       CalDAVServerSupport ServerStatus;
+       
+       // Setup the server connection.
+       
+       curl_easy_setopt(ConnectionHandle, CURLOPT_CUSTOMREQUEST, "OPTIONS");
+       
+       CURLcode ServerResult = curl_easy_perform(ConnectionHandle);
+       
+       if (ServerResult != CURLE_OK){
+               return ServerStatus;
+       }
+       
+       // Check that the server header has data in,
+       // otherwise return an "empty" CalDAVServerSupport.
+       
+       if (ServerHeader.size() == 0){
+               return ServerStatus;
+       }
+       
+       // Process each line looking for the first DAV header 
+       // line.
+       
+       bool NewlineMode = true;
+       
+       string DAVLine;
+       
+       for (int CharSeek = 0; CharSeek < ServerHeader.size(); CharSeek++){
+               
+               if (NewlineMode == true){
+                       
+                       // Check if we have reached the end of the string.
+                       
+                       if (CharSeek >= ServerHeader.size()){
+                               
+                               break;
+                               
+                       }
+                       
+                       // Check the first four letters to make sure
+                       // they are 'DAV:'.
+                       
+                       string DAVHeaderCheck = "";
+                       
+                       try {
+                               DAVHeaderCheck = ServerHeader.substr(CharSeek, 4);
+                       }
+                       
+                       catch (out_of_range &oor){
+                               break;
+                       }
+                       
+                       if (DAVHeaderCheck == "DAV:"){
+                               
+                               CharSeek += 5;
+                               
+                               for (; CharSeek < ServerHeader.size(); CharSeek++){
+                                       
+                                       if (ServerHeader[CharSeek] == '\n'){
+                                       
+                                               break;
+                                               
+                                       }
+                                       
+                                       DAVLine.push_back(ServerHeader[CharSeek]);
+                                       
+                               }
+                               
+                               break;
+                               
+                       }
+                       
+                       NewlineMode = false;
+                       
+               }
+               
+               if (ServerHeader[CharSeek] == '\n'){
+                       
+                       NewlineMode = true;
+                       
+               }
+               
+       }
+       
+       // Process the DAV line.
+       
+       vector<string> DAVLineData;
+       string DAVSegmentString;
+       
+       for (int CharSeek = 0; CharSeek < DAVLine.size(); CharSeek++){
+               
+               if (DAVLine[CharSeek] == ' '){
+                       continue;
+               }
+               
+               if (DAVLine[CharSeek] == ','){
+                       
+                       DAVLineData.push_back(DAVSegmentString);
+                       DAVSegmentString.clear();
+                       continue;
+                       
+               }
+               
+               DAVSegmentString += DAVLine[CharSeek];
+               
+       }
+       
+       // Process the DAV values and set each value
+       // to true as required.
+       
+       for (int DAVItemSeek = 0; 
+               DAVItemSeek < DAVLineData.size();
+               DAVItemSeek++){
+                       
+               if (DAVLineData.at(DAVItemSeek) == "calendar-access"){
+                       
+                       ServerStatus.BasicSupport = true;
+               
+               }
+                       
+       }
+       
+       return ServerStatus;
+       
+}
+
 bool CalDAVObjectValidSettings(CalDAVConnectionData *ConnData){
 
        // Check if the passed CalDAV Connection Data is has
index 47b9617..d527541 100644 (file)
@@ -22,6 +22,8 @@
 #include <curl/curl.h>
 #include <string>
 #include <iostream>
+#include <vector>
+#include <stdexcept>
 
 using namespace std;
 
@@ -63,6 +65,18 @@ struct CalDAVStatus{
 
 };
 
+// CalDAVServerSupport: used for
+// getting what the server supports
+// from the CalDAV specification.
+
+struct CalDAVServerSupport{
+       
+       // Variable name.                          Name in CalDAV header.
+       
+       bool BasicSupport = false;              // calendar-access
+       
+};
+
 // CalDAVServerResult: used for
 // getting the result of the
 // request made via the CalDAV
@@ -88,6 +102,7 @@ class CalDAV{
                void SetupConnectionData(CalDAVConnectionData *ConnData);
                CalDAVStatus GetConnectionData();
                CalDAVServerResult Connect();
+               CalDAVServerSupport GetServerSupport();
                CalDAV();
                ~CalDAV();
        
index 1557685..4b666c0 100644 (file)
@@ -321,6 +321,53 @@ TEST(CalDAV, BuildServerAddress){
        
 }
 
+TEST(CalDAV, CalendarServerSupport){
+       
+       CalDAVConnectionData ConnNormal;        
+
+       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();
+       
+       ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
+       ASSERT_EQ(200, ConnResult.HTTPCode);
+       ASSERT_EQ(CURLE_OK, ConnResult.Code);
+       
+       // Check for basic support of the calendar server.
+       
+       CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
+       
+       ASSERT_EQ(true, ConnSupport.BasicSupport);
+       
+}
+
 TEST(CalDAV, ListCalendars){
        
        CalDAVConnectionData ConnNormal;        
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