X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fobjects%2FCalDAV%2FCalDAV-XMLProcessing.cpp;h=d216a336d29cf1b42fb2d65c081d1dc6eeb14228;hb=e2a3b3d990c7171947b617b83285d5656b3ae477;hp=38e26c7c84ef9b726ef6613c56402df2191e3f0a;hpb=fb7334af110912e40389f059adcf58c4a289a881;p=xestiacalendar%2F.git diff --git a/source/objects/CalDAV/CalDAV-XMLProcessing.cpp b/source/objects/CalDAV/CalDAV-XMLProcessing.cpp index 38e26c7..d216a33 100644 --- a/source/objects/CalDAV/CalDAV-XMLProcessing.cpp +++ b/source/objects/CalDAV/CalDAV-XMLProcessing.cpp @@ -49,6 +49,12 @@ string CalDAV::ProcessXMLUserPrincipal(){ } + if (NodeFound == false){ + + return UserPrincipalURI; + + } + // Look for response. if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; } @@ -113,6 +119,12 @@ string CalDAV::ProcessXMLCalendarHome(){ } + if (NodeFound == false){ + + return CalendarHomeURI; + + } + // Look for response. if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; } @@ -182,6 +194,12 @@ CalDAVCalendarList CalDAV::ProcessXMLCalendarList(){ } + if (NodeFound == false){ + + return CalendarList; + + } + for (NodeResponse = NodeSeek->children; NodeResponse != nullptr; NodeResponse = NodeResponse->next) @@ -333,6 +351,20 @@ CalDAVCalendarList CalDAV::ProcessXMLCalendarList(){ } + // 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. @@ -342,6 +374,7 @@ CalDAVCalendarList CalDAV::ProcessXMLCalendarList(){ 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++; @@ -355,6 +388,287 @@ CalDAVCalendarList CalDAV::ProcessXMLCalendarList(){ } +string CalDAV::ProcessXMLEntryETag(){ + + string EntryETag; + + xmlDocPtr xmlCalDAVDoc; + xmlCalDAVDoc = xmlReadMemory(ServerData.c_str(), (int)ServerData.size(), "noname.xml", NULL, 0); + + xmlNodePtr NodeSeek; + bool NodeFound = false; + + // 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") + ){ + + NodeFound = true; + break; + + } + + } + + if (NodeFound == false){ + + return EntryETag; + + } + + // Look for 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"); + + // Look for 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"); + + // Get the data from href. + + 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){ + + 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); + + 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;