Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added separate C++ file for processing XML data within the CalDAV object.
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Thu, 3 Mar 2016 03:51:46 +0000 (03:51 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Thu, 3 Mar 2016 03:51:46 +0000 (03:51 +0000)
source/objects/CalDAV/CalDAV-XMLProcessing.cpp [new file with mode: 0644]

diff --git a/source/objects/CalDAV/CalDAV-XMLProcessing.cpp b/source/objects/CalDAV/CalDAV-XMLProcessing.cpp
new file mode 100644 (file)
index 0000000..81d4674
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>
+
+#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
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy