Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code to process the URL property in CalendarFreeBusyObject.
[xestiacalendar/.git] / source / objects / calendarfreebusy / CalendarFreeBusy.cpp
1 #include "CalendarFreeBusy.h"
3 using namespace std;
5 CalendarObjectValidResult CalendarFreeBusyObject::ValidObject(){
6  
7         bool ValidBegin = false;
8         bool ValidEnd = false;
9         bool ValidDateTimeStamp = false;
10         bool ValidUniqueID = false;
11         bool ValidDateTimeStart = false;
12         int SeekCount = 0;
13         string PropertyName;
14         
15         // Look for BEGIN:VFREEBUSY.
16         
17         for (vector<string>::iterator iter = ObjectName.begin();
18                 iter != ObjectName.end(); iter++){
19         
20                 if (ObjectName[SeekCount] == "BEGIN" &&
21                         ObjectData[SeekCount] == "VFREEBUSY"){
22                         
23                         if (ValidBegin == false){
24                                 ValidBegin = true;
25                         } else {
26                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
27                         }
28                                 
29                 }
30                 
31                 if (ObjectName[SeekCount] == "END" &&
32                         ObjectData[SeekCount] == "VFREEBUSY" &&
33                         ValidBegin == false){
34                 
35                         return CALENDAROBJECTVALID_INVALIDFORMAT;
36                                 
37                 }
38                 
39                 SeekCount++;
40                         
41         }
42         
43         SeekCount = 0;
44         
45         // Look for DTSTAMP.
46         
47         for (vector<string>::iterator iter = ObjectName.begin();
48                 iter != ObjectName.end(); iter++){
49                         
50                 try{
51                         PropertyName = ObjectName[SeekCount].substr(0,7);
52                 }
53                         
54                 catch(const out_of_range& oor){
55                         continue;
56                 }
57                 
58                 if (PropertyName == "DTSTAMP"){
59                         
60                         if (ValidDateTimeStamp == false){
61                                 ValidDateTimeStamp = true;
62                         } else {
63                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
64                         }
65                                 
66                 }
67                         
68                 SeekCount++;
69                         
70         }
71         
72         SeekCount = 0;
73         
74         // Look for UID.
75         
76         for (vector<string>::iterator iter = ObjectName.begin();
77                 iter != ObjectName.end(); iter++){
78         
79                 try{
80                         PropertyName = ObjectName[SeekCount].substr(0,3);
81                 }
82                 
83                 catch(const out_of_range& oor){
84                         continue;
85                 }
86                         
87                 if (PropertyName == "UID"){
88                         
89                         if (ValidUniqueID == false){
90                                 ValidUniqueID = true;
91                         } else {
92                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
93                         }
94                                 
95                 }
96                         
97                 SeekCount++;
98                         
99         }
100         
101         SeekCount = 0;
102         
103         // Look for END:VFREEBUSY.
104         
105         for (vector<string>::iterator iter = ObjectName.begin();
106                 iter != ObjectName.end(); iter++){
107         
108                 if (ObjectName[SeekCount] == "END" &&
109                         ObjectData[SeekCount] == "VFREEBUSY"){
110                         
111                         if (ValidEnd == false){
112                                 ValidEnd = true;
113                         } else {
114                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
115                         }
116                                 
117                 }
118                         
119                 SeekCount++;
120                         
121         }
122         
123         // Check if the VEVENT is valid.
125         if (ValidBegin == true && 
126                 ValidEnd == true && 
127                 ValidDateTimeStamp == true &&
128                 ValidUniqueID == true){
129                 
130                 return CALENDAROBJECTVALID_OK;
131                         
132         } else {
133                 
134                 return CALENDAROBJECTVALID_INVALIDFORMAT;
135                 
136         }
137         
140 void CalendarFreeBusyObject::ProcessData(){
141         
142         // Process the data.
143         
144         multimap<string,string> DataReceived;
145         map<string,string> PropertyData;
146         string *PropertyNameData = nullptr;
147         int ObjectSeekCount = 0;
148         
149         // Get the Date Time Stamp (DTSTAMP).
150         
151         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTAMP");
152         
153         // Process the data from DTSTAMP.
154         
155         if (DataReceived.begin() != DataReceived.end()){
156         
157                 try {
158                         DateTimeStampTokens = DataReceived.begin()->first.substr(8);
159                 }
160                 
161                 catch(const out_of_range &oor){
162                         // Do nothing as there is no data.
163                 }               
164                 
165                 DateTimeStampData = DataReceived.begin()->second;
166                 
167         }
169         // Get the Unique ID (UID).
170         
171         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "UID");
172         
173         // Process the data from UID.
174         
175         if (DataReceived.begin() != DataReceived.end()){
176         
177                 try {
178                         UniqueIDTokens = DataReceived.begin()->first.substr(4);
179                 }
180                 
181                 catch(const out_of_range &oor){
182                         // Do nothing as there is no data.
183                 }               
184                 
185                 UniqueID = DataReceived.begin()->second;
186                 
187         }
188         
189         // Process the data from CONTACT.
190         
191         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "CONTACT");
193         ObjectSeekCount = 0;
194         
195         for(multimap<string,string>::iterator iter = DataReceived.begin(); 
196                 iter != DataReceived.end(); 
197                 ++iter){
198                 
199                 ContactListTokens.push_back("");
200                 ContactListAltRep.push_back("");
201                 ContactListLanguage.push_back("");
202                 ContactList.push_back("");
203                         
204                 bool TokenData = false;
205                 string PropertyTokens;
206                 
207                 PropertyNameData = (string*)&iter->first;
208                 
209                 PropertyData = SplitValues(*PropertyNameData);
210                         
211                 for(map<string,string>::iterator dataiter = PropertyData.begin();
212                         dataiter != PropertyData.end(); dataiter++){
213                         
214                         if (dataiter->first == "ALTREP"){
215                                 
216                                 ContactListAltRep[ObjectSeekCount] = dataiter->second;
217                                 
218                         } else if (dataiter->first == "LANGUAGE"){
219                                 
220                                 ContactListLanguage[ObjectSeekCount] = dataiter->second;
221                                 
222                         } else {
223                                 
224                                 if (TokenData == false){
225                                         TokenData = true;
226                                 } else {
227                                         PropertyTokens += ";";
228                                 }
229                                 
230                                 PropertyTokens += dataiter->first;
231                                 PropertyTokens += "=";
232                                 PropertyTokens += dataiter->second;
233                                 
234                         }
235                                 
236                 }
237                 
238                 if (PropertyTokens.size() > 0){
239                         ContactListTokens[ObjectSeekCount] = PropertyTokens;
240                 }
241                         
242                 ContactList[ObjectSeekCount] = iter->second;
243                 
244                 ObjectSeekCount++;
245                 
246         }
247         
248         // Get the Date Time Start value.
249         
250         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTART");
251         
252         // Process the data from DTSTART.
253         
254         if (DataReceived.begin() != DataReceived.end()){
255         
256                 bool TokenData = false;
257                 string PropertyTokens;
258                 
259                 PropertyNameData = (string*)&DataReceived.begin()->first;
260                 
261                 PropertyData = SplitValues(*PropertyNameData);
262                 
263                 for(map<string,string>::iterator iter = PropertyData.begin();
264                         iter != PropertyData.end(); iter++){
265                         
266                         if (iter->first == "VALUE"){
267                                 
268                                 DateTimeStartDataValue = iter->second;
269                                 
270                         } else if (iter->first == "TZID"){
271                                 
272                                 DateTimeStartDataTimeZoneID = iter->second;
273                                 
274                         } else {
275                                 
276                                 if (TokenData == false){
277                                         TokenData = true;
278                                 } else {
279                                         PropertyTokens += ";";
280                                 }
281                                 
282                                 PropertyTokens += iter->first;
283                                 PropertyTokens += "=";
284                                 PropertyTokens += iter->second;
285                                 
286                         }
287                                 
288                 }
289                 
290                 if (PropertyTokens.size() > 0){
291                         DateTimeStartDataTokens = PropertyTokens;
292                 }
293                 
294                 DateTimeStartData = DataReceived.begin()->second;
295                 
296         }
297         
298         // Process the data from DTEND.
299         
300         bool DateTimeEndProcessed = false;
301         
302         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTEND");
303         
304         if (DataReceived.begin() != DataReceived.end()){
305         
306                 bool TokenData = false;
307                 string PropertyTokens;
308                 
309                 PropertyNameData = (string*)&DataReceived.begin()->first;
310                 
311                 PropertyData = SplitValues(*PropertyNameData);
312                 
313                 for(map<string,string>::iterator iter = PropertyData.begin();
314                         iter != PropertyData.end(); iter++){
315                         
316                         if (iter->first == "VALUE"){
317                                 
318                                 DateTimeEndDataValue = iter->second;
319                                 
320                         } else if (iter->first == "TZID"){
321                                 
322                                 DateTimeEndDataTimeZoneID = iter->second;
323                                 
324                         } else {
325                                 
326                                 if (TokenData == false){
327                                         TokenData = true;
328                                 } else {
329                                         PropertyTokens += ";";
330                                 }
331                                 
332                                 PropertyTokens += iter->first;
333                                 PropertyTokens += "=";
334                                 PropertyTokens += iter->second;
335                                 
336                         }
337                                 
338                 }
339                 
340                 if (PropertyTokens.size() > 0){
341                         DateTimeEndDataTokens = PropertyTokens;
342                 }
343                 
344                 DateTimeEndData = DataReceived.begin()->second;
345                 
346                 DateTimeEndProcessed = true;
347                 
348         }
349         
350         // Process the data from ORGANIZER.
351         
352         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "ORGANIZER");
353         
354         if (DataReceived.begin() != DataReceived.end()){
355         
356                 bool TokenData = false;
357                 string PropertyTokens;
358                 
359                 PropertyNameData = (string*)&DataReceived.begin()->first;
360                 
361                 PropertyData = SplitValues(*PropertyNameData);
362                 
363                 for(map<string,string>::iterator iter = PropertyData.begin();
364                         iter != PropertyData.end(); iter++){
365                         
366                         if (iter->first == "CN"){
367                                 
368                                 OrganiserDataCommonName = iter->second;
369                                 
370                         } else if (iter->first == "DIR"){
371                                 
372                                 OrganiserDataDirectoryEntry = iter->second;
373                                 
374                         } else if (iter->first == "SENT-BY"){
375                                 
376                                 OrganiserDataSentByParam = iter->second;
377                                 
378                         } else if (iter->first == "LANGUAGE"){
379                                 
380                                 OrganiserDataLanguage = iter->second;
381                                 
382                         } else {
383                                 
384                                 if (TokenData == false){
385                                         TokenData = true;
386                                 } else {
387                                         PropertyTokens += ";";
388                                 }
389                                 
390                                 PropertyTokens += iter->first;
391                                 PropertyTokens += "=";
392                                 PropertyTokens += iter->second;
393                                 
394                         }
395                                 
396                 }
397                 
398                 if (PropertyTokens.size() > 0){
399                         
400                         OrganiserDataTokens = PropertyTokens;
401                         
402                 }
403                 
404                 OrganiserData = DataReceived.begin()->second;
405                 
406         }
407         
408         // Process the data from URL.
409         
410         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "URL");
411         
412         if (DataReceived.begin() != DataReceived.end()){
413         
414                 try {
415                         URLDataTokens = DataReceived.begin()->first.substr(4);
416                 }
417                 
418                 catch(const out_of_range &oor){
419                         // Do nothing as there is no data.
420                 }               
421                 
422                 URLData = DataReceived.begin()->second;
423                 
424         }
425         
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