1 // CalDAV-XMLProcessing.cpp - CalDAV Connection Object - XML Processing.
3 // (c) 2016 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
23 string CalDAV::ProcessXMLUserPrincipal(){
25 string UserPrincipalURI;
27 xmlDocPtr xmlCalDAVDoc;
28 xmlCalDAVDoc = xmlReadMemory(ServerData.c_str(), (int)ServerData.size(), "noname.xml", NULL, 0);
31 bool NodeFound = false;
33 // Start with the first node, look for multistatus.
35 for (NodeSeek = xmlCalDAVDoc->children;
37 NodeSeek = NodeSeek->next)
40 if (!xmlStrcmp(NodeSeek->name, (const xmlChar *)"multistatus") ||
41 !xmlStrcmp(NodeSeek->name, (const xmlChar *)"d:multistatus") ||
42 !xmlStrcmp(NodeSeek->name, (const xmlChar *)"D:multistatus")
54 if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
55 NodeFound = MatchXMLName(&NodeSeek, "response");
59 if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
60 NodeFound = MatchXMLName(&NodeSeek, "propstat");
64 if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
65 NodeFound = MatchXMLName(&NodeSeek, "prop");
67 // Look for current-user-principal.
69 if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
70 NodeFound = MatchXMLName(&NodeSeek, "current-user-principal");
74 if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
75 NodeFound = MatchXMLName(&NodeSeek, "href");
77 // Get the data from href.
79 UserPrincipalURI = FetchXMLData(&NodeSeek);
81 xmlFreeDoc(xmlCalDAVDoc);
83 return UserPrincipalURI;
87 bool CalDAV::MatchXMLName(xmlNodePtr *NodePtr, string NodeName){
89 string NodeNameSmallD = "d:" + NodeName;
90 string NodeNameLargeD = "D:" + NodeName;
92 for ((*NodePtr) = (*NodePtr)->children;
94 (*NodePtr) = (*NodePtr)->next)
97 if (!xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeName.c_str()) ||
98 !xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeNameSmallD.c_str()) ||
99 !xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeNameLargeD.c_str())
112 string CalDAV::FetchXMLData(xmlNodePtr *NodePtr){
114 for ((*NodePtr) = (*NodePtr)->children;
116 (*NodePtr) = (*NodePtr)->next)
119 return (const char*)(*NodePtr)->content;