X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fobjects%2FCalDAV%2FCalDAV-XMLProcessing.cpp;h=0018ebf6484bde2e8e73dd4b08c750350ac6ea6f;hb=cba151c4b833a26c63984769f921bab5e755decd;hp=8f39d860781769c56308f085cbebfc3cff6908e9;hpb=9dcad69a6d44601369836cbc712d5eb228628139;p=xestiacalendar%2F.git diff --git a/source/objects/CalDAV/CalDAV-XMLProcessing.cpp b/source/objects/CalDAV/CalDAV-XMLProcessing.cpp index 8f39d86..0018ebf 100644 --- a/source/objects/CalDAV/CalDAV-XMLProcessing.cpp +++ b/source/objects/CalDAV/CalDAV-XMLProcessing.cpp @@ -1,14 +1,14 @@ // 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. @@ -210,7 +210,8 @@ CalDAVCalendarList CalDAV::ProcessXMLCalendarList(){ NodeMatch = xmlCopyNode(NodeResponse, 1); if (MatchXMLName(&NodeMatch, "response")){ - NodeData = xmlCopyNode(NodeMatch, 1); + + NodeData = xmlCopyNode(NodeMatch, 1); // Check the resource type is a calendar. @@ -464,6 +465,211 @@ string CalDAV::ProcessXMLEntryETag(){ } +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); + + 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++; + + } + + } + + xmlFreeDoc(xmlCalDAVDoc); + + return EntryList; + +} + bool CalDAV::MatchXMLNameTransverse(xmlNodePtr *NodePtr, string NodeName){ string NodeNameSmallD = "d:" + NodeName;