Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed output of address to console in AddCalendar
[xestiacalendar/.git] / source / objects / CalDAV / CalDAV.cpp
index a34ca07..001743f 100644 (file)
@@ -437,12 +437,13 @@ string CalDAV::GetCalendarHome(string UserPrincipalURI){
        
        // Reset the changed settings.
        
-       string OriginalServerAddress = BuildServerAddress(&ConnectionData, "/principals");
+       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);
+       curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, NULL);
        
        return CalendarHomeURI;
        
@@ -467,12 +468,8 @@ CalDAVCalendarList CalDAV::GetCalendars(){
        string CalendarHomeURI = "";
        CalendarHomeURI = GetCalendarHome(UserPrincipalURI);
        
-       cout << ServerData << endl;
-       
        string CalendarListURLAddress = BuildServerAddress(&ConnectionData, CalendarHomeURI);
        
-       cout << CalendarListURLAddress << endl;
-       
        string CalendarListRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
        "<d:propfind xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\""
        " xmlns:c=\"urn:ietf:params:xml:ns:caldav\" xmlns:x0=\"http://apple.com/ns/ical/\">\n"
@@ -483,6 +480,7 @@ CalDAVCalendarList CalDAV::GetCalendars(){
        "  <x0:calendar-order />\n"
        "  <cs:getctag />\n"
        "  <c:supported-calendar-component-set />\n"
+       "  <c:calendar-description />\n"
        " </d:prop>\n"
        "</d:propfind>";
        
@@ -511,8 +509,6 @@ CalDAVCalendarList CalDAV::GetCalendars(){
        
        CURLcode ServerResult = curl_easy_perform(ConnectionHandle);
        
-       cout << ServerData << endl;
-       
        //ServerList = ProcessXMLCalendarList();
        
        // Restore the original settings.
@@ -524,10 +520,110 @@ CalDAVCalendarList CalDAV::GetCalendars(){
        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 = "<?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;
+       
+       //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
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