From 42ae98f6424d145cec1c931a2c7ecf6ddbadd938 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Thu, 3 Mar 2016 03:51:46 +0000 Subject: [PATCH] Added separate C++ file for processing XML data within the CalDAV object. --- .../objects/CalDAV/CalDAV-XMLProcessing.cpp | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 source/objects/CalDAV/CalDAV-XMLProcessing.cpp diff --git a/source/objects/CalDAV/CalDAV-XMLProcessing.cpp b/source/objects/CalDAV/CalDAV-XMLProcessing.cpp new file mode 100644 index 0000000..81d4674 --- /dev/null +++ b/source/objects/CalDAV/CalDAV-XMLProcessing.cpp @@ -0,0 +1,123 @@ +// 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; + +} + +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; + + } + +} \ No newline at end of file -- 2.39.5