X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fobjects%2FCalDAV%2FCalDAV.cpp;h=e2a787d6d23757675552e1e53cde79c07a329e7a;hb=d22dbc7054f255d8df75b273f8f2df625aab5aa2;hp=256bc2580c6e1707acec3a4892a81b11130cacdc;hpb=fa5d5c7e130a79c0ace4da537746ab42234f8c9e;p=xestiacalendar%2F.git
diff --git a/source/objects/CalDAV/CalDAV.cpp b/source/objects/CalDAV/CalDAV.cpp
index 256bc25..e2a787d 100644
--- a/source/objects/CalDAV/CalDAV.cpp
+++ b/source/objects/CalDAV/CalDAV.cpp
@@ -32,6 +32,29 @@ size_t CalDAVReceive(char *ReceivedBuffer, size_t Size, size_t NewMemoryBytes, s
}
+size_t CalDAVSend(char *SendBuffer, size_t Size, size_t NewMemoryBytes, void *DataStruct){
+
+ struct CalDAVSendData *UploadPtr = (struct CalDAVSendData *)DataStruct;
+
+ if (UploadPtr->sizeleft){
+
+ UploadPtr->sizeleft--;
+ char CharSend;
+
+ CharSend = (*UploadPtr->readptr)[UploadPtr->seek];
+
+ *SendBuffer = CharSend;
+
+ UploadPtr->seek++;
+
+ return 1;
+
+ }
+
+ return 0;
+
+}
+
CalDAV::CalDAV(){
// Setup the objects within the CalDAV connection
@@ -105,7 +128,7 @@ CalDAVServerResult CalDAV::Connect(){
curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_easy_setopt(ConnectionHandle, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(ConnectionHandle, CURLOPT_TIMEOUT, ConnectionData.Timeout);
- curl_easy_setopt(ConnectionHandle, CURLOPT_WRITEFUNCTION, CalDAVOutput);
+ curl_easy_setopt(ConnectionHandle, CURLOPT_WRITEFUNCTION, CalDAVReceive);
curl_easy_setopt(ConnectionHandle, CURLOPT_WRITEDATA, &ServerData);
curl_easy_setopt(ConnectionHandle, CURLOPT_WRITEHEADER, &ServerHeader);
@@ -133,6 +156,12 @@ CalDAVServerResult CalDAV::Connect(){
}
+CalDAVServerResult CalDAV::GetServerResult(){
+
+ return ConnectionServerResult;
+
+}
+
CalDAVServerSupport CalDAV::GetServerSupport(){
CalDAVServerSupport ServerStatus;
@@ -143,6 +172,16 @@ CalDAVServerSupport CalDAV::GetServerSupport(){
CURLcode ServerResult = curl_easy_perform(ConnectionHandle);
+ // Set the results.
+
+ if (ServerResult == CURLE_OK){
+ ConnectionServerResult.Result = CALDAVQUERYRESULT_OK;
+ } else {
+ ConnectionServerResult.Result = CALDAVQUERYRESULT_SERVERERROR;
+ }
+ ConnectionServerResult.Code = ServerResult;
+ curl_easy_getinfo(ConnectionHandle, CURLINFO_RESPONSE_CODE, &ConnectionServerResult.HTTPCode);
+
if (ServerResult != CURLE_OK){
return ServerStatus;
}
@@ -256,10 +295,336 @@ CalDAVServerSupport CalDAV::GetServerSupport(){
}
+ // Reset the connection status.
+
+ curl_easy_setopt(ConnectionHandle, CURLOPT_CUSTOMREQUEST, NULL);
+
return ServerStatus;
}
+string CalDAV::GetUserPrincipal(){
+
+ string CurrentUserPrincipal = "";
+ string UserPrincipalRequest = "";
+ CalDAVSendData UserPrincipalSendData;
+
+ UserPrincipalRequest = "\n"
+ "\n"
+ " \n"
+ " \n"
+ " \n"
+ "";
+
+ UserPrincipalSendData.readptr = &UserPrincipalRequest;
+ UserPrincipalSendData.sizeleft = UserPrincipalRequest.size();
+
+ // Setup the header.
+
+ struct curl_slist *UserPrincipalRequestHeader = NULL;
+
+ UserPrincipalRequestHeader = curl_slist_append(UserPrincipalRequestHeader, "Depth: 0");
+ UserPrincipalRequestHeader = curl_slist_append(UserPrincipalRequestHeader, "Prefer: return-minimal");
+ UserPrincipalRequestHeader = curl_slist_append(UserPrincipalRequestHeader, "Content-Type: application/xml; charset=utf-8");
+
+ curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, UserPrincipalRequestHeader);
+
+ curl_easy_setopt(ConnectionHandle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
+ curl_easy_setopt(ConnectionHandle, CURLOPT_UPLOAD, 1L);
+ curl_easy_setopt(ConnectionHandle, CURLOPT_READDATA, &UserPrincipalSendData);
+ curl_easy_setopt(ConnectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
+
+ // Process the data.
+
+ ServerData.clear();
+ ServerHeader.clear();
+
+ CURLcode ServerResult = curl_easy_perform(ConnectionHandle);
+
+ // Set the results.
+
+ if (ServerResult == CURLE_OK){
+ ConnectionServerResult.Result = CALDAVQUERYRESULT_OK;
+ } else {
+ ConnectionServerResult.Result = CALDAVQUERYRESULT_SERVERERROR;
+ }
+ ConnectionServerResult.Code = ServerResult;
+ curl_easy_getinfo(ConnectionHandle, CURLINFO_RESPONSE_CODE, &ConnectionServerResult.HTTPCode);
+
+ if (ServerResult != CURLE_OK){
+
+ return CurrentUserPrincipal;
+
+ }
+
+ // Process the User Principal from the ServerData.
+
+ CurrentUserPrincipal = ProcessXMLUserPrincipal();
+
+ // Reset the changed settings.
+
+ curl_easy_setopt(ConnectionHandle, CURLOPT_UPLOAD, 0L);
+ curl_easy_setopt(ConnectionHandle, CURLOPT_READDATA, NULL);
+ curl_easy_setopt(ConnectionHandle, CURLOPT_READFUNCTION, NULL);
+
+ return CurrentUserPrincipal;
+
+}
+
+string CalDAV::GetCalendarHome(string UserPrincipalURI){
+
+ string CalendarHomeURI = "";
+
+ // Build the Calendar Home URL address.
+
+ string CalendarHomeURL = BuildServerAddress(&ConnectionData, UserPrincipalURI);
+
+ // Setup the header request.
+
+ CalDAVSendData CalendarHomeSendData;
+
+ string CalendarHomeRequest = "\n"
+ "\n"
+ " \n"
+ " \n"
+ " \n"
+ "";
+
+ CalendarHomeSendData.readptr = &CalendarHomeRequest;
+ CalendarHomeSendData.sizeleft = CalendarHomeRequest.size();
+
+ // Setup the header.
+
+ struct curl_slist *CalendarRequestHeader = NULL;
+
+ CalendarRequestHeader = curl_slist_append(CalendarRequestHeader, "Depth: 0");
+ CalendarRequestHeader = curl_slist_append(CalendarRequestHeader, "Prefer: return-minimal");
+ CalendarRequestHeader = curl_slist_append(CalendarRequestHeader, "Content-Type: application/xml; charset=utf-8");
+
+ curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, CalendarRequestHeader);
+ curl_easy_setopt(ConnectionHandle, CURLOPT_URL, CalendarHomeURL.c_str());
+ curl_easy_setopt(ConnectionHandle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
+ curl_easy_setopt(ConnectionHandle, CURLOPT_UPLOAD, 1L);
+ curl_easy_setopt(ConnectionHandle, CURLOPT_READDATA, &CalendarHomeSendData);
+ curl_easy_setopt(ConnectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
+
+ // Process the data.
+
+ ServerData.clear();
+ ServerHeader.clear();
+
+ CURLcode ServerResult = curl_easy_perform(ConnectionHandle);
+
+ // Set the results.
+
+ if (ServerResult == CURLE_OK){
+ ConnectionServerResult.Result = CALDAVQUERYRESULT_OK;
+ } else {
+ ConnectionServerResult.Result = CALDAVQUERYRESULT_SERVERERROR;
+ }
+ ConnectionServerResult.Code = ServerResult;
+ curl_easy_getinfo(ConnectionHandle, CURLINFO_RESPONSE_CODE, &ConnectionServerResult.HTTPCode);
+
+ if (ServerResult != CURLE_OK){
+
+ return CalendarHomeURI;
+
+ }
+
+ // Process the User Principal from the ServerData.
+
+ CalendarHomeURI = ProcessXMLCalendarHome();
+
+ // Reset the changed settings.
+
+ 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);
+
+ return CalendarHomeURI;
+
+}
+
+CalDAVCalendarList CalDAV::GetCalendars(){
+
+ CalDAVCalendarList ServerList;
+ CalDAVSendData CalendarListSendData;
+
+ // Build the server address.
+
+ string UserPrincipalURI = "";
+ UserPrincipalURI = GetUserPrincipal();
+
+ if (UserPrincipalURI.size() == 0){
+
+ return ServerList;
+
+ }
+
+ string CalendarHomeURI = "";
+ CalendarHomeURI = GetCalendarHome(UserPrincipalURI);
+
+ string CalendarListURLAddress = BuildServerAddress(&ConnectionData, CalendarHomeURI);
+
+ string CalendarListRequest = "\n"
+ "\n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ "";
+
+ CalendarListSendData.readptr = &CalendarListRequest;
+ CalendarListSendData.sizeleft = CalendarListRequest.size();
+
+ // Setup the header.
+
+ struct curl_slist *CalendarListRequestHeader = NULL;
+
+ CalendarListRequestHeader = curl_slist_append(CalendarListRequestHeader, "Depth: 1");
+ CalendarListRequestHeader = curl_slist_append(CalendarListRequestHeader, "Prefer: return-minimal");
+ CalendarListRequestHeader = curl_slist_append(CalendarListRequestHeader, "Content-Type: application/xml; charset=utf-8");
+
+ curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, CalendarListRequestHeader);
+ curl_easy_setopt(ConnectionHandle, CURLOPT_URL, CalendarListURLAddress.c_str());
+ curl_easy_setopt(ConnectionHandle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
+ curl_easy_setopt(ConnectionHandle, CURLOPT_UPLOAD, 1L);
+ curl_easy_setopt(ConnectionHandle, CURLOPT_READDATA, &CalendarListSendData);
+ curl_easy_setopt(ConnectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
+
+ // Process the data.
+
+ ServerData.clear();
+ ServerHeader.clear();
+
+ CURLcode ServerResult = curl_easy_perform(ConnectionHandle);
+
+ //ServerList = ProcessXMLCalendarList();
+
+ // 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);
+
+ // Process the received XML data into a list of calendars
+ // and locations.
+
+ if (ServerResult != CURLE_OK){
+
+ return ServerList;
+
+ }
+
+ ServerList = ProcessXMLCalendarList();
+
+ return ServerList;
+
+}
+
+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;
+
+ 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