// CalDAV-XMLProcessing.cpp - CalDAV Connection Object - XML Processing. // // (c) 2016 Xestia Software Development. // // This file is part of Xestia Calendar. // // Xestia Address Book 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, // 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. // // You should have received a copy of the GNU General Public License along // with Xestia Calendar. If not, see #include "CalDAV.h" using namespace std; string CalDAV::ProcessXMLUserPrincipal(){ string UserPrincipalURI; 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; } } // Look for response. if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; } NodeFound = MatchXMLName(&NodeSeek, "response"); // Look for propstat. if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; } NodeFound = MatchXMLName(&NodeSeek, "propstat"); // Look for prop. if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; } NodeFound = MatchXMLName(&NodeSeek, "prop"); // Look for current-user-principal. if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; } NodeFound = MatchXMLName(&NodeSeek, "current-user-principal"); // Look for href. if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; } NodeFound = MatchXMLName(&NodeSeek, "href"); // Get the data from href. UserPrincipalURI = FetchXMLData(&NodeSeek); xmlFreeDoc(xmlCalDAVDoc); return UserPrincipalURI; } string CalDAV::ProcessXMLCalendarHome(){ string CalendarHomeURI; 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; } } // Look for response. if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; } NodeFound = MatchXMLName(&NodeSeek, "response"); // Look for propstat. if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; } NodeFound = MatchXMLName(&NodeSeek, "propstat"); // Look for prop. if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; } NodeFound = MatchXMLName(&NodeSeek, "prop"); // Look for calendar-home-set. if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; } NodeFound = MatchXMLName(&NodeSeek, "calendar-home-set"); // Look for href. if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; } NodeFound = MatchXMLName(&NodeSeek, "href"); // Get the data from href. CalendarHomeURI = FetchXMLData(&NodeSeek); xmlFreeDoc(xmlCalDAVDoc); return CalendarHomeURI; } bool CalDAV::MatchXMLName(xmlNodePtr *NodePtr, string NodeName){ string NodeNameSmallD = "d:" + NodeName; string NodeNameLargeD = "D:" + NodeName; 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()) ){ return true; } } return false; } string CalDAV::FetchXMLData(xmlNodePtr *NodePtr){ for ((*NodePtr) = (*NodePtr)->children; (*NodePtr) != NULL; (*NodePtr) = (*NodePtr)->next) { return (const char*)(*NodePtr)->content; } }