}
+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
#include <curl/curl.h>
#include <string>
#include <iostream>
+#include <vector>
+#include <stdexcept>
using namespace std;
};
+// 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
void SetupConnectionData(CalDAVConnectionData *ConnData);
CalDAVStatus GetConnectionData();
CalDAVServerResult Connect();
+ CalDAVServerSupport GetServerSupport();
CalDAV();
~CalDAV();
}
+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;