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 = MatchXMLNameTransverse(&NodeSeek, "response");
59 if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
60 NodeFound = MatchXMLNameTransverse(&NodeSeek, "propstat");
64 if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
65 NodeFound = MatchXMLNameTransverse(&NodeSeek, "prop");
67 // Look for current-user-principal.
69 if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
70 NodeFound = MatchXMLNameTransverse(&NodeSeek, "current-user-principal");
74 if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
75 NodeFound = MatchXMLNameTransverse(&NodeSeek, "href");
77 // Get the data from href.
79 UserPrincipalURI = FetchXMLData(&NodeSeek);
81 xmlFreeDoc(xmlCalDAVDoc);
83 return UserPrincipalURI;
87 string CalDAV::ProcessXMLCalendarHome(){
89 string CalendarHomeURI;
91 xmlDocPtr xmlCalDAVDoc;
92 xmlCalDAVDoc = xmlReadMemory(ServerData.c_str(), (int)ServerData.size(), "noname.xml", NULL, 0);
95 bool NodeFound = false;
97 // Start with the first node, look for multistatus.
99 for (NodeSeek = xmlCalDAVDoc->children;
101 NodeSeek = NodeSeek->next)
104 if (!xmlStrcmp(NodeSeek->name, (const xmlChar *)"multistatus") ||
105 !xmlStrcmp(NodeSeek->name, (const xmlChar *)"d:multistatus") ||
106 !xmlStrcmp(NodeSeek->name, (const xmlChar *)"D:multistatus")
116 // Look for response.
118 if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
119 NodeFound = MatchXMLNameTransverse(&NodeSeek, "response");
121 // Look for propstat.
123 if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
124 NodeFound = MatchXMLNameTransverse(&NodeSeek, "propstat");
128 if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
129 NodeFound = MatchXMLNameTransverse(&NodeSeek, "prop");
131 // Look for calendar-home-set.
133 if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
134 NodeFound = MatchXMLNameTransverse(&NodeSeek, "calendar-home-set");
138 if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
139 NodeFound = MatchXMLNameTransverse(&NodeSeek, "href");
141 // Get the data from href.
143 CalendarHomeURI = FetchXMLData(&NodeSeek);
145 xmlFreeDoc(xmlCalDAVDoc);
147 return CalendarHomeURI;
151 bool CalDAV::MatchXMLNameTransverse(xmlNodePtr *NodePtr, string NodeName){
153 string NodeNameSmallD = "d:" + NodeName;
154 string NodeNameLargeD = "D:" + NodeName;
156 for ((*NodePtr) = (*NodePtr)->children;
158 (*NodePtr) = (*NodePtr)->next)
161 if (!xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeName.c_str()) ||
162 !xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeNameSmallD.c_str()) ||
163 !xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeNameLargeD.c_str())
176 string CalDAV::FetchXMLData(xmlNodePtr *NodePtr){
178 for ((*NodePtr) = (*NodePtr)->children;
180 (*NodePtr) = (*NodePtr)->next)
183 return (const char*)(*NodePtr)->content;