// CalDAV-XMLProcessing.cpp - CalDAV Connection Object - XML Processing.
//
-// (c) 2016 Xestia Software Development.
+// (c) 2016-2017 Xestia Software Development.
//
// This file is part of Xestia Calendar.
//
-// Xestia Address Book is free software: you can redistribute it and/or modify
+// Xestia Calendar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, version 3 of the license.
//
-// Xestia Address Book is distributed in the hope that it will be useful,
+// Xestia Calendar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
string CalDAV::ProcessXMLUserPrincipal(){
- string UserPrincipalURI;
+ string userPrincipalURI;
xmlDocPtr xmlCalDAVDoc;
- xmlCalDAVDoc = xmlReadMemory(ServerData.c_str(), (int)ServerData.size(), "noname.xml", NULL, 0);
+ xmlCalDAVDoc = xmlReadMemory(serverData.c_str(), (int)serverData.size(), "noname.xml", NULL, 0);
- xmlNodePtr NodeSeek;
- bool NodeFound = false;
+ xmlNodePtr nodeSeek;
+ bool nodeFound = false;
// Start with the first node, look for multistatus.
- for (NodeSeek = xmlCalDAVDoc->children;
- NodeSeek != NULL;
- NodeSeek = NodeSeek->next)
+ for (nodeSeek = xmlCalDAVDoc->children;
+ nodeSeek != NULL;
+ nodeSeek = nodeSeek->next)
{
- if (!xmlStrcmp(NodeSeek->name, (const xmlChar *)"multistatus") ||
- !xmlStrcmp(NodeSeek->name, (const xmlChar *)"d:multistatus") ||
- !xmlStrcmp(NodeSeek->name, (const xmlChar *)"D:multistatus")
+ if (!xmlStrcmp(nodeSeek->name, (const xmlChar *)"multistatus") ||
+ !xmlStrcmp(nodeSeek->name, (const xmlChar *)"d:multistatus") ||
+ !xmlStrcmp(nodeSeek->name, (const xmlChar *)"D:multistatus")
){
- NodeFound = true;
+ nodeFound = true;
break;
}
}
+ if (nodeFound == false){
+
+ return userPrincipalURI;
+
+ }
+
// Look for response.
- if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "response");
+ if (nodeFound == false){ return userPrincipalURI; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "response");
// Look for propstat.
- if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "propstat");
+ if (nodeFound == false){ return userPrincipalURI; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "propstat");
// Look for prop.
- if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "prop");
+ if (nodeFound == false){ return userPrincipalURI; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "prop");
// Look for current-user-principal.
- if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "current-user-principal");
+ if (nodeFound == false){ return userPrincipalURI; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "current-user-principal");
// Look for href.
- if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "href");
+ if (nodeFound == false){ return userPrincipalURI; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "href");
// Get the data from href.
- UserPrincipalURI = FetchXMLData(&NodeSeek);
+ userPrincipalURI = FetchXMLData(&nodeSeek);
xmlFreeDoc(xmlCalDAVDoc);
- return UserPrincipalURI;
+ return userPrincipalURI;
}
string CalDAV::ProcessXMLCalendarHome(){
- string CalendarHomeURI;
+ string calendarHomeURI;
xmlDocPtr xmlCalDAVDoc;
- xmlCalDAVDoc = xmlReadMemory(ServerData.c_str(), (int)ServerData.size(), "noname.xml", NULL, 0);
+ xmlCalDAVDoc = xmlReadMemory(serverData.c_str(), (int)serverData.size(), "noname.xml", NULL, 0);
- xmlNodePtr NodeSeek;
- bool NodeFound = false;
+ xmlNodePtr nodeSeek;
+ bool nodeFound = false;
// Start with the first node, look for multistatus.
- for (NodeSeek = xmlCalDAVDoc->children;
- NodeSeek != NULL;
- NodeSeek = NodeSeek->next)
+ for (nodeSeek = xmlCalDAVDoc->children;
+ nodeSeek != NULL;
+ nodeSeek = nodeSeek->next)
{
- if (!xmlStrcmp(NodeSeek->name, (const xmlChar *)"multistatus") ||
- !xmlStrcmp(NodeSeek->name, (const xmlChar *)"d:multistatus") ||
- !xmlStrcmp(NodeSeek->name, (const xmlChar *)"D:multistatus")
+ if (!xmlStrcmp(nodeSeek->name, (const xmlChar *)"multistatus") ||
+ !xmlStrcmp(nodeSeek->name, (const xmlChar *)"d:multistatus") ||
+ !xmlStrcmp(nodeSeek->name, (const xmlChar *)"D:multistatus")
){
- NodeFound = true;
+ nodeFound = true;
break;
}
}
+ if (nodeFound == false){
+
+ return calendarHomeURI;
+
+ }
+
// Look for response.
- if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "response");
+ if (nodeFound == false){ return calendarHomeURI; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "response");
// Look for propstat.
- if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "propstat");
+ if (nodeFound == false){ return calendarHomeURI; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "propstat");
// Look for prop.
- if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "prop");
+ if (nodeFound == false){ return calendarHomeURI; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "prop");
// Look for calendar-home-set.
- if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "calendar-home-set");
+ if (nodeFound == false){ return calendarHomeURI; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "calendar-home-set");
// Look for href.
- if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "href");
+ if (nodeFound == false){ return calendarHomeURI; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "href");
// Get the data from href.
- CalendarHomeURI = FetchXMLData(&NodeSeek);
+ calendarHomeURI = FetchXMLData(&nodeSeek);
xmlFreeDoc(xmlCalDAVDoc);
- return CalendarHomeURI;
+ return calendarHomeURI;
}
CalDAVCalendarList CalDAV::ProcessXMLCalendarList(){
- CalDAVCalendarList CalendarList;
+ CalDAVCalendarList calendarList;
xmlDocPtr xmlCalDAVDoc;
- xmlCalDAVDoc = xmlReadMemory(ServerData.c_str(), (int)ServerData.size(), "noname.xml", NULL, 0);
+ xmlCalDAVDoc = xmlReadMemory(serverData.c_str(), (int)serverData.size(), "noname.xml", NULL, 0);
- xmlNodePtr NodeSeek = NULL;
- xmlNodePtr NodeResponse = NULL;
- xmlNodePtr NodeMatch = NULL;
- xmlNodePtr NodeData = NULL;
- bool NodeFound = false;
- int ResponseCount = 0;
+ xmlNodePtr nodeSeek = NULL;
+ xmlNodePtr nodeResponse = NULL;
+ xmlNodePtr nodeMatch = NULL;
+ xmlNodePtr nodeData = NULL;
+ bool nodeFound = false;
+ int responseCount = 0;
// Start with the first node, look for multistatus.
- for (NodeSeek = xmlCalDAVDoc->children;
- NodeSeek != NULL;
- NodeSeek = NodeSeek->next)
+ for (nodeSeek = xmlCalDAVDoc->children;
+ nodeSeek != NULL;
+ nodeSeek = nodeSeek->next)
{
- if (!xmlStrcmp(NodeSeek->name, (const xmlChar *)"multistatus") ||
- !xmlStrcmp(NodeSeek->name, (const xmlChar *)"d:multistatus") ||
- !xmlStrcmp(NodeSeek->name, (const xmlChar *)"D:multistatus")
+ if (!xmlStrcmp(nodeSeek->name, (const xmlChar *)"multistatus") ||
+ !xmlStrcmp(nodeSeek->name, (const xmlChar *)"d:multistatus") ||
+ !xmlStrcmp(nodeSeek->name, (const xmlChar *)"D:multistatus")
){
- NodeResponse = NodeSeek->children;
- NodeFound = true;
+ nodeResponse = nodeSeek->children;
+ nodeFound = true;
break;
}
}
- for (NodeResponse = NodeSeek->children;
- NodeResponse != nullptr;
- NodeResponse = NodeResponse->next)
+ if (nodeFound == false){
+
+ return calendarList;
+
+ }
+
+ for (nodeResponse = nodeSeek->children;
+ nodeResponse != nullptr;
+ nodeResponse = nodeResponse->next)
{
// Go through each of the responses and find the calendars.
- NodeMatch = xmlCopyNode(NodeResponse, 1);
+ nodeMatch = xmlCopyNode(nodeResponse, 1);
- if (MatchXMLName(&NodeMatch, "response")){
-\r NodeData = xmlCopyNode(NodeMatch, 1);
+ if (MatchXMLName(&nodeMatch, "response")){
+
+ nodeData = xmlCopyNode(nodeMatch, 1);
// Check the resource type is a calendar.
- if (!MatchXMLNameTransverse(&NodeData, "propstat")){ continue; }
- if (!MatchXMLNameTransverse(&NodeData, "prop")){ continue; }
- if (!MatchXMLNameTransverse(&NodeData, "resourcetype")){ continue; }
- if (!MatchXMLNameTransverse(&NodeData, "calendar")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "propstat")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "prop")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "resourcetype")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "calendar")){ continue; }
// Get the HREF.
- NodeData = xmlCopyNode(NodeMatch, 1);
+ nodeData = xmlCopyNode(nodeMatch, 1);
- if (!MatchXMLNameTransverse(&NodeData, "href")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "href")){ continue; }
- string HREFAddress = FetchXMLData(&NodeData);
+ string hrefAddress = FetchXMLData(&nodeData);
// Get the calendar name.
- NodeData = xmlCopyNode(NodeMatch, 1);
+ nodeData = xmlCopyNode(nodeMatch, 1);
- if (!MatchXMLNameTransverse(&NodeData, "propstat")){ continue; }
- if (!MatchXMLNameTransverse(&NodeData, "prop")){ continue; }
- if (!MatchXMLNameTransverse(&NodeData, "displayname")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "propstat")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "prop")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "displayname")){ continue; }
- string CalendarName = FetchXMLData(&NodeData);
+ string calendarName = FetchXMLData(&nodeData);
// Get the calendar description.
- NodeData = xmlCopyNode(NodeMatch, 1);
+ nodeData = xmlCopyNode(nodeMatch, 1);
- string CalendarDescription = "";
+ string calendarDescription = "";
- if (!MatchXMLNameTransverse(&NodeData, "propstat")){ continue; }
- if (!MatchXMLNameTransverse(&NodeData, "prop")){ continue; }
- if (MatchXMLNameTransverse(&NodeData, "calendar-description")){
+ if (!MatchXMLNameTransverse(&nodeData, "propstat")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "prop")){ continue; }
+ if (MatchXMLNameTransverse(&nodeData, "calendar-description")){
- CalendarDescription = FetchXMLData(&NodeData);
+ calendarDescription = FetchXMLData(&nodeData);
}
// Get the calendar colour.
- NodeData = xmlCopyNode(NodeMatch, 1);
+ nodeData = xmlCopyNode(nodeMatch, 1);
- Colour CalendarColour;
- bool ColourResult = false;
+ Colour calendarColour;
+ bool colourResult = false;
- if (!MatchXMLNameTransverse(&NodeData, "propstat")){ continue; }
- if (!MatchXMLNameTransverse(&NodeData, "prop")){ continue; }
- if (MatchXMLNameTransverse(&NodeData, "calendar-color")){
+ if (!MatchXMLNameTransverse(&nodeData, "propstat")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "prop")){ continue; }
+ if (MatchXMLNameTransverse(&nodeData, "calendar-color")){
- string CalendarColourString = "";
- string CalendarColourHexValue = "";
- int ColourNumber;
- bool KeepRunning = true;
+ string calendarColourString = "";
+ string calendarColourHexValue = "";
+ int colourNumber;
+ bool keepRunning = true;
- CalendarColourString = FetchXMLData(&NodeData);
+ calendarColourString = FetchXMLData(&nodeData);
- while(KeepRunning == true){
+ while(keepRunning == true){
- if (CalendarColourString.substr(0,1) == "#" && CalendarColourString.length() == 9){
+ if (calendarColourString.substr(0,1) == "#" && calendarColourString.length() == 9){
// Get the red colour.
- CalendarColourHexValue = CalendarColourString.substr(1,2);
- if (!HexToInt(&CalendarColourHexValue, &ColourNumber)){ break; }
- CalendarColour.red = ColourNumber;
+ calendarColourHexValue = calendarColourString.substr(1,2);
+ if (!HexToInt(&calendarColourHexValue, &colourNumber)){ break; }
+ calendarColour.red = colourNumber;
// Get the green colour.
- CalendarColourHexValue = CalendarColourString.substr(3,2);
- if (!HexToInt(&CalendarColourHexValue, &ColourNumber)){ break; }
- CalendarColour.green = ColourNumber;
+ calendarColourHexValue = calendarColourString.substr(3,2);
+ if (!HexToInt(&calendarColourHexValue, &colourNumber)){ break; }
+ calendarColour.green = colourNumber;
// Get the blue colour.
- CalendarColourHexValue = CalendarColourString.substr(5,2);
- if (!HexToInt(&CalendarColourHexValue, &ColourNumber)){ break; };
- CalendarColour.blue = ColourNumber;
+ calendarColourHexValue = calendarColourString.substr(5,2);
+ if (!HexToInt(&calendarColourHexValue, &colourNumber)){ break; };
+ calendarColour.blue = colourNumber;
// Get the alpha.
- CalendarColourHexValue = CalendarColourString.substr(7,2);
- if (!HexToInt(&CalendarColourHexValue, &ColourNumber)){ break; };
- CalendarColour.alpha = ColourNumber;
+ calendarColourHexValue = calendarColourString.substr(7,2);
+ if (!HexToInt(&calendarColourHexValue, &colourNumber)){ break; };
+ calendarColour.alpha = colourNumber;
- ColourResult = true;
+ colourResult = true;
} else {
- ColourResult = false;
+ colourResult = false;
}
}
- if (ColourResult == false){
+ if (colourResult == false){
- CalendarColour.red = 0;
- CalendarColour.blue = 0;
- CalendarColour.green = 0;
- CalendarColour.alpha = 0;
+ calendarColour.red = 0;
+ calendarColour.blue = 0;
+ calendarColour.green = 0;
+ calendarColour.alpha = 0;
}
// Get the calendar order.
- NodeData = xmlCopyNode(NodeMatch, 1);
+ nodeData = xmlCopyNode(nodeMatch, 1);
- int CalendarOrder = 0;
+ int calendarOrder = 0;
- if (!MatchXMLNameTransverse(&NodeData, "propstat")){ continue; }
- if (!MatchXMLNameTransverse(&NodeData, "prop")){ continue; }
- if (MatchXMLNameTransverse(&NodeData, "calendar-order")){
+ if (!MatchXMLNameTransverse(&nodeData, "propstat")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "prop")){ continue; }
+ if (MatchXMLNameTransverse(&nodeData, "calendar-order")){
- string CalendarOrderString = FetchXMLData(&NodeData);
- if (!HexToInt(&CalendarOrderString, &CalendarOrder)){
- CalendarOrder = 0;
+ string calendarOrderString = FetchXMLData(&nodeData);
+ if (!HexToInt(&calendarOrderString, &calendarOrder)){
+ calendarOrder = 0;
}
}
// Get the calendar tag.
- NodeData = xmlCopyNode(NodeMatch, 1);
+ nodeData = xmlCopyNode(nodeMatch, 1);
- string CalendarTag = "";
+ string calendarTag = "";
- if (!MatchXMLNameTransverse(&NodeData, "propstat")){ continue; }
- if (!MatchXMLNameTransverse(&NodeData, "prop")){ continue; }
- if (MatchXMLNameTransverse(&NodeData, "getctag")){
+ if (!MatchXMLNameTransverse(&nodeData, "propstat")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "prop")){ continue; }
+ if (MatchXMLNameTransverse(&nodeData, "getctag")){
- CalendarTag = FetchXMLData(&NodeData);
+ calendarTag = FetchXMLData(&nodeData);
+
+ }
+
+ // Get the calendar tag URL.
+
+ nodeData = xmlCopyNode(nodeMatch, 1);
+
+ string calendarTagURL = "";
+
+ if (!MatchXMLNameTransverse(&nodeData, "propstat")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "prop")){ continue; }
+ if (MatchXMLNameTransverse(&nodeData, "sync-token")){
+
+ calendarTagURL = FetchXMLData(&nodeData);
}
// Insert the calendar information into the
// list if all the information is there.
- CalendarList.Name.insert(make_pair(ResponseCount, CalendarName));
- CalendarList.Description.insert(make_pair(ResponseCount, CalendarDescription));
- CalendarList.HREF.insert(make_pair(ResponseCount, HREFAddress));
- CalendarList.CalColour.insert(make_pair(ResponseCount, CalendarColour));
- CalendarList.Order.insert(make_pair(ResponseCount, CalendarOrder));
- CalendarList.Tag.insert(make_pair(ResponseCount, CalendarTag));
+ calendarList.name.insert(make_pair(responseCount, calendarName));
+ calendarList.description.insert(make_pair(responseCount, calendarDescription));
+ calendarList.href.insert(make_pair(responseCount, hrefAddress));
+ calendarList.calColour.insert(make_pair(responseCount, calendarColour));
+ calendarList.order.insert(make_pair(responseCount, calendarOrder));
+ calendarList.tag.insert(make_pair(responseCount, calendarTag));
+ calendarList.tagURL.insert(make_pair(responseCount, calendarTagURL));
- ResponseCount++;
+ responseCount++;
}
xmlFreeDoc(xmlCalDAVDoc);
- return CalendarList;
+ return calendarList;
}
string CalDAV::ProcessXMLEntryETag(){
- string EntryETag;
+ string entryETag;
xmlDocPtr xmlCalDAVDoc;
- xmlCalDAVDoc = xmlReadMemory(ServerData.c_str(), (int)ServerData.size(), "noname.xml", NULL, 0);
+ xmlCalDAVDoc = xmlReadMemory(serverData.c_str(), (int)serverData.size(), "noname.xml", NULL, 0);
- xmlNodePtr NodeSeek;
- bool NodeFound = false;
+ xmlNodePtr nodeSeek;
+ bool nodeFound = false;
// Start with the first node, look for multistatus.
- for (NodeSeek = xmlCalDAVDoc->children;
- NodeSeek != NULL;
- NodeSeek = NodeSeek->next)
+ for (nodeSeek = xmlCalDAVDoc->children;
+ nodeSeek != NULL;
+ nodeSeek = nodeSeek->next)
{
- if (!xmlStrcmp(NodeSeek->name, (const xmlChar *)"multistatus") ||
- !xmlStrcmp(NodeSeek->name, (const xmlChar *)"d:multistatus") ||
- !xmlStrcmp(NodeSeek->name, (const xmlChar *)"D:multistatus")
+ if (!xmlStrcmp(nodeSeek->name, (const xmlChar *)"multistatus") ||
+ !xmlStrcmp(nodeSeek->name, (const xmlChar *)"d:multistatus") ||
+ !xmlStrcmp(nodeSeek->name, (const xmlChar *)"D:multistatus")
){
- NodeFound = true;
+ nodeFound = true;
break;
}
}
+ if (nodeFound == false){
+
+ return entryETag;
+
+ }
+
// Look for response.
- if (NodeFound == false){ return EntryETag; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "response");
+ if (nodeFound == false){ return entryETag; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "response");
// Look for propstat.
- if (NodeFound == false){ return EntryETag; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "propstat");
+ if (nodeFound == false){ return entryETag; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "propstat");
// Look for prop.
- if (NodeFound == false){ return EntryETag; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "prop");
+ if (nodeFound == false){ return entryETag; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "prop");
// Look for calendar-home-set.
- if (NodeFound == false){ return EntryETag; } else { NodeFound = false; }
- NodeFound = MatchXMLNameTransverse(&NodeSeek, "getetag");
+ if (nodeFound == false){ return entryETag; } else { nodeFound = false; }
+ nodeFound = MatchXMLNameTransverse(&nodeSeek, "getetag");
// Get the data from href.
- EntryETag = FetchXMLData(&NodeSeek);
+ entryETag = FetchXMLData(&nodeSeek);
xmlFreeDoc(xmlCalDAVDoc);
// Check if the entity tag contains quote marks
// at the start and end and remove them (if needed).
- if (EntryETag.substr(0,1) == "\"" &&
- EntryETag.substr(EntryETag.size()-1, 1) == "\"" && EntryETag.size() > 2){
+ if (entryETag.substr(0,1) == "\"" &&
+ entryETag.substr(entryETag.size()-1, 1) == "\"" && entryETag.size() > 2){
+
+ entryETag.erase(entryETag.begin());
+ entryETag.erase(entryETag.end()-1);
+
+ }
+
+ return entryETag;
+
+}
+
+CalDAVEntryList CalDAV::ProcessXMLEntryList(){
+
+ CalDAVEntryList entryList;
+
+ xmlDocPtr xmlCalDAVDoc;
+ xmlCalDAVDoc = xmlReadMemory(serverData.c_str(), (int)serverData.size(), "noname.xml", NULL, 0);
+
+ xmlNodePtr nodeSeek = NULL;
+ xmlNodePtr nodeResponse = NULL;
+ xmlNodePtr nodeMatch = NULL;
+ xmlNodePtr nodeData = NULL;
+ bool nodeFound = false;
+ int responseCount = 0;
+
+ // Start with the first node, look for multistatus.
+
+ for (nodeSeek = xmlCalDAVDoc->children;
+ nodeSeek != NULL;
+ nodeSeek = nodeSeek->next)
+ {
+
+ if (!xmlStrcmp(nodeSeek->name, (const xmlChar *)"multistatus") ||
+ !xmlStrcmp(nodeSeek->name, (const xmlChar *)"d:multistatus") ||
+ !xmlStrcmp(nodeSeek->name, (const xmlChar *)"D:multistatus")
+ ){
+
+ nodeResponse = nodeSeek->children;
+ nodeFound = true;
+ break;
+
+ }
+
+ }
+
+ if (nodeFound == false){
+
+ return entryList;
+
+ }
+
+ for (nodeResponse = nodeSeek->children;
+ nodeResponse != nullptr;
+ nodeResponse = nodeResponse->next)
+ {
+
+ // Go through each of the responses and find the calendars.
+
+ nodeMatch = xmlCopyNode(nodeResponse, 1);
+
+ if (MatchXMLName(&nodeMatch, "response")){
+
+ nodeData = xmlCopyNode(nodeMatch, 1);
+
+ // Get the HREF.
+
+ nodeData = xmlCopyNode(nodeMatch, 1);
+
+ if (!MatchXMLNameTransverse(&nodeData, "href")){ continue; }
+
+ string hrefAddress = FetchXMLData(&nodeData);
+
+ // Get the calendar data.
+
+ nodeData = xmlCopyNode(nodeMatch, 1);
+
+ string entryDescription = "";
+
+ if (!MatchXMLNameTransverse(&nodeData, "propstat")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "prop")){ continue; }
+ if (MatchXMLNameTransverse(&nodeData, "calendar-data")){
+
+ // Note: libxml2 will strip the CDATA part at the start and
+ // end of each calendar-data section.
+
+ entryDescription = FetchXMLData(&nodeData);
+
+ }
+
+ // Get the entry entity tag.
+
+ nodeData = xmlCopyNode(nodeMatch, 1);
+
+ string entryEntityTag = "";
+
+ if (!MatchXMLNameTransverse(&nodeData, "propstat")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "prop")){ continue; }
+ if (MatchXMLNameTransverse(&nodeData, "getetag")){
+
+ entryEntityTag = FetchXMLData(&nodeData);
+
+ }
+
+ // Insert the calendar information into the
+ // list if all the information is there.
+
+ entryList.href.insert(make_pair(responseCount, hrefAddress));
+ entryList.data.insert(make_pair(responseCount, entryDescription));
+ entryList.tag.insert(make_pair(responseCount, entryEntityTag));
+
+ responseCount++;
+
+ }
+
+ }
+
+ xmlFreeDoc(xmlCalDAVDoc);
+
+ return entryList;
+
+}
+
+CalDAVEntryList CalDAV::ProcessXMLSyncTokenList(){
+
+ CalDAVEntryList entryList;
+
+ xmlDocPtr xmlCalDAVDoc;
+ xmlCalDAVDoc = xmlReadMemory(serverData.c_str(), (int)serverData.size(), "noname.xml", NULL, 0);
+
+ xmlNodePtr nodeSeek = NULL;
+ xmlNodePtr nodeResponse = NULL;
+ xmlNodePtr nodeMatch = NULL;
+ xmlNodePtr nodeData = NULL;
+ bool nodeFound = false;
+ int responseCount = 0;
+
+ // Start with the first node, look for multistatus.
+
+ for (nodeSeek = xmlCalDAVDoc->children;
+ nodeSeek != NULL;
+ nodeSeek = nodeSeek->next)
+ {
+
+ if (!xmlStrcmp(nodeSeek->name, (const xmlChar *)"multistatus") ||
+ !xmlStrcmp(nodeSeek->name, (const xmlChar *)"d:multistatus") ||
+ !xmlStrcmp(nodeSeek->name, (const xmlChar *)"D:multistatus")
+ ){
+
+ nodeResponse = nodeSeek->children;
+ nodeFound = true;
+ break;
+
+ }
+
+ }
+
+ if (nodeFound == false){
+
+ return entryList;
+
+ }
+
+ for (nodeResponse = nodeSeek->children;
+ nodeResponse != nullptr;
+ nodeResponse = nodeResponse->next)
+ {
+
+ // Go through each of the responses and find the calendars.
+
+ nodeMatch = xmlCopyNode(nodeResponse, 1);
- EntryETag.erase(EntryETag.begin());
- EntryETag.erase(EntryETag.end()-1);
+ if (MatchXMLName(&nodeMatch, "response")){
+
+ nodeData = xmlCopyNode(nodeMatch, 1);
+ // Get the HREF.
+
+ nodeData = xmlCopyNode(nodeMatch, 1);
+
+ if (!MatchXMLNameTransverse(&nodeData, "href")){ continue; }
+
+ string hrefAddress = FetchXMLData(&nodeData);
+
+ // Get the entry entity tag.
+
+ nodeData = xmlCopyNode(nodeMatch, 1);
+
+ string entryEntityTag = "";
+
+ if (!MatchXMLNameTransverse(&nodeData, "propstat")){ continue; }
+ if (!MatchXMLNameTransverse(&nodeData, "prop")){ continue; }
+ if (MatchXMLNameTransverse(&nodeData, "getetag")){
+
+ entryEntityTag = FetchXMLData(&nodeData);
+
+ }
+
+ // Insert the calendar information into the
+ // list if all the information is there.
+
+ entryList.href.insert(make_pair(responseCount, hrefAddress));
+ entryList.data.insert(make_pair(responseCount, ""));
+ entryList.tag.insert(make_pair(responseCount, entryEntityTag));
+
+ responseCount++;
+
+ }
+
}
- return EntryETag;
+ xmlFreeDoc(xmlCalDAVDoc);
+
+ return entryList;
}
-bool CalDAV::MatchXMLNameTransverse(xmlNodePtr *NodePtr, string NodeName){
+bool CalDAV::MatchXMLNameTransverse(xmlNodePtr *nodePtr, string nodeName){
- string NodeNameSmallD = "d:" + NodeName;
- string NodeNameLargeD = "D:" + NodeName;
+ string nodeNameSmallD = "d:" + nodeName;
+ string nodeNameLargeD = "D:" + nodeName;
- for ((*NodePtr) = (*NodePtr)->children;
- (*NodePtr) != NULL;
- (*NodePtr) = (*NodePtr)->next)
+ for ((*nodePtr) = (*nodePtr)->children;
+ (*nodePtr) != NULL;
+ (*nodePtr) = (*nodePtr)->next)
{
- if (!xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeName.c_str()) ||
- !xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeNameSmallD.c_str()) ||
- !xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeNameLargeD.c_str())
+ if (!xmlStrcmp((*nodePtr)->name, (const xmlChar *)nodeName.c_str()) ||
+ !xmlStrcmp((*nodePtr)->name, (const xmlChar *)nodeNameSmallD.c_str()) ||
+ !xmlStrcmp((*nodePtr)->name, (const xmlChar *)nodeNameLargeD.c_str())
){
return true;
}
-bool CalDAV::MatchXMLName(xmlNodePtr *NodePtrOriginal, string NodeName){
+bool CalDAV::MatchXMLName(xmlNodePtr *nodePtrOriginal, string nodeName){
- if (NodePtrOriginal == nullptr){
+ if (nodePtrOriginal == nullptr){
return false;
}
- string NodeNameSmallD = "d:" + NodeName;
- string NodeNameLargeD = "D:" + NodeName;
+ string nodeNameSmallD = "d:" + nodeName;
+ string nodeNameLargeD = "D:" + nodeName;
- xmlNodePtr *NodePtr = NodePtrOriginal;
+ xmlNodePtr *nodePtr = nodePtrOriginal;
- if (!xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeName.c_str()) ||
- !xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeNameSmallD.c_str()) ||
- !xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeNameLargeD.c_str())
+ if (!xmlStrcmp((*nodePtr)->name, (const xmlChar *)nodeName.c_str()) ||
+ !xmlStrcmp((*nodePtr)->name, (const xmlChar *)nodeNameSmallD.c_str()) ||
+ !xmlStrcmp((*nodePtr)->name, (const xmlChar *)nodeNameLargeD.c_str())
){
return true;
}
-string CalDAV::FetchXMLData(xmlNodePtr *NodePtr){
+string CalDAV::FetchXMLData(xmlNodePtr *nodePtr){
- for ((*NodePtr) = (*NodePtr)->children;
- (*NodePtr) != NULL;
- (*NodePtr) = (*NodePtr)->next)
+ for ((*nodePtr) = (*nodePtr)->children;
+ (*nodePtr) != NULL;
+ (*nodePtr) = (*nodePtr)->next)
{
- return (const char*)(*NodePtr)->content;
+ return (const char*)(*nodePtr)->content;
}