Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added ProcessXMLCalenadrHome to the CalDAV Object.
[xestiacalendar/.git] / source / objects / CalDAV / CalDAV-XMLProcessing.cpp
1 // CalDAV-XMLProcessing.cpp - CalDAV Connection Object - XML Processing.
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
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.
10 //
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.
15 //
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/>
19 #include "CalDAV.h"
21 using namespace std;
22  
23 string CalDAV::ProcessXMLUserPrincipal(){
25         string UserPrincipalURI;
26         
27         xmlDocPtr xmlCalDAVDoc;
28         xmlCalDAVDoc = xmlReadMemory(ServerData.c_str(), (int)ServerData.size(), "noname.xml", NULL, 0);
30         xmlNodePtr NodeSeek;
31         bool NodeFound = false;
32         
33         // Start with the first node, look for multistatus.
34         
35         for (NodeSeek = xmlCalDAVDoc->children;
36                 NodeSeek != NULL;
37                 NodeSeek = NodeSeek->next)
38         {
39         
40                 if (!xmlStrcmp(NodeSeek->name, (const xmlChar *)"multistatus") ||
41                         !xmlStrcmp(NodeSeek->name, (const xmlChar *)"d:multistatus") ||
42                         !xmlStrcmp(NodeSeek->name, (const xmlChar *)"D:multistatus")
43                 ){
44                         
45                         NodeFound = true;
46                         break;
47                         
48                 }
49                 
50         }
51         
52         // Look for response.
54         if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
55         NodeFound = MatchXMLName(&NodeSeek, "response");
57         // Look for propstat.
58         
59         if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
60         NodeFound = MatchXMLName(&NodeSeek, "propstat");
62         // Look for prop.
63         
64         if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
65         NodeFound = MatchXMLName(&NodeSeek, "prop");
66         
67         // Look for current-user-principal.
68         
69         if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
70         NodeFound = MatchXMLName(&NodeSeek, "current-user-principal");
71         
72         // Look for href.       
73         
74         if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
75         NodeFound = MatchXMLName(&NodeSeek, "href");
77         // Get the data from href.
78         
79         UserPrincipalURI = FetchXMLData(&NodeSeek);
80         
81         xmlFreeDoc(xmlCalDAVDoc);
82         
83         return UserPrincipalURI;
84         
85 }
87 string CalDAV::ProcessXMLCalendarHome(){
89         string CalendarHomeURI;
90         
91         xmlDocPtr xmlCalDAVDoc;
92         xmlCalDAVDoc = xmlReadMemory(ServerData.c_str(), (int)ServerData.size(), "noname.xml", NULL, 0);
94         xmlNodePtr NodeSeek;
95         bool NodeFound = false;
96         
97         // Start with the first node, look for multistatus.
98         
99         for (NodeSeek = xmlCalDAVDoc->children;
100                 NodeSeek != NULL;
101                 NodeSeek = NodeSeek->next)
102         {
103         
104                 if (!xmlStrcmp(NodeSeek->name, (const xmlChar *)"multistatus") ||
105                         !xmlStrcmp(NodeSeek->name, (const xmlChar *)"d:multistatus") ||
106                         !xmlStrcmp(NodeSeek->name, (const xmlChar *)"D:multistatus")
107                 ){
108                         
109                         NodeFound = true;
110                         break;
111                         
112                 }
113                 
114         }
115         
116         // Look for response.
118         if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
119         NodeFound = MatchXMLName(&NodeSeek, "response");
121         // Look for propstat.
122         
123         if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
124         NodeFound = MatchXMLName(&NodeSeek, "propstat");
126         // Look for prop.
127         
128         if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
129         NodeFound = MatchXMLName(&NodeSeek, "prop");
130         
131         // Look for calendar-home-set.
132         
133         if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
134         NodeFound = MatchXMLName(&NodeSeek, "calendar-home-set");
135         
136         // Look for href.       
137         
138         if (NodeFound == false){ return CalendarHomeURI; } else { NodeFound = false; }
139         NodeFound = MatchXMLName(&NodeSeek, "href");
141         // Get the data from href.
142         
143         CalendarHomeURI = FetchXMLData(&NodeSeek);
144         
145         xmlFreeDoc(xmlCalDAVDoc);
146         
147         return CalendarHomeURI;
148         
151 bool CalDAV::MatchXMLName(xmlNodePtr *NodePtr, string NodeName){
153         string NodeNameSmallD = "d:" + NodeName;
154         string NodeNameLargeD = "D:" + NodeName;
155         
156         for ((*NodePtr) = (*NodePtr)->children;
157                 (*NodePtr) != NULL;
158                 (*NodePtr) = (*NodePtr)->next)
159         {
160         
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())
164                 ){
165                         
166                         return true;
167                         
168                 }
169                 
170         }
171         
172         return false;
173         
176 string CalDAV::FetchXMLData(xmlNodePtr *NodePtr){
178         for ((*NodePtr) = (*NodePtr)->children;
179                 (*NodePtr) != NULL;
180                 (*NodePtr) = (*NodePtr)->next)
181         {
182                                                                 
183                 return (const char*)(*NodePtr)->content;
184                         
185         }
186         
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