Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code to process STATUS in CalendarEventObject.
[xestiacalendar/.git] / source / objects / calendarevent / CalendarEvent.cpp
1 #include "CalendarEvent.h"
3 using namespace std;
5 CalendarObjectValidResult CalendarEventObject::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:VEVENT.
16         
17         for (vector<string>::iterator iter = ObjectName.begin();
18                 iter != ObjectName.end(); iter++){
19         
20                 if (ObjectName[SeekCount] == "BEGIN" &&
21                         ObjectData[SeekCount] == "VEVENT"){
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] == "VEVENT" &&
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 DTSTART if nothing is set for METHOD..
104         
105         if (MethodData.size() == 0){
106         
107                 for (vector<string>::iterator iter = ObjectName.begin();
108                         iter != ObjectName.end(); iter++){
109                         
110                         try{
111                                 PropertyName = ObjectName[SeekCount].substr(0,7);
112                         }
113                         
114                         catch(const out_of_range& oor){
115                                 continue;
116                         }
117                 
118                         if (PropertyName == "DTSTART"){
119                         
120                                 if (ValidDateTimeStart == false){
121                                         ValidDateTimeStart = true;
122                                 } else {
123                                         return CALENDAROBJECTVALID_INVALIDFORMAT;
124                                 }
125                                 
126                         }
127                         
128                         SeekCount++;
129                         
130                 }
131         
132         } else {
133                 ValidDateTimeStart = true;
134         }
135         
136         SeekCount = 0;
137         
138         // Look for END:VEVENT.
139         
140         for (vector<string>::iterator iter = ObjectName.begin();
141                 iter != ObjectName.end(); iter++){
142         
143                 if (ObjectName[SeekCount] == "END" &&
144                         ObjectData[SeekCount] == "VEVENT"){
145                         
146                         if (ValidEnd == false){
147                                 ValidEnd = true;
148                         } else {
149                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
150                         }
151                                 
152                 }
153                         
154                 SeekCount++;
155                         
156         }
157         
158         // Check if the VEVENT is valid.
160         if (ValidBegin == true && 
161                 ValidEnd == true && 
162                 ValidDateTimeStamp == true &&
163                 ValidDateTimeStart == true &&
164                 ValidUniqueID == true){
165                 
166                 return CALENDAROBJECTVALID_OK;
167                         
168         } else {
169                 
170                 return CALENDAROBJECTVALID_INVALIDFORMAT;
171                 
172         }
173         
176 void CalendarEventObject::ProcessData(){
177         
178         // Process the data.
179         
180         multimap<string,string> DataReceived;
181         map<string,string> PropertyData;
182         string *PropertyNameData = nullptr;
183         
184         // Get the Date Time Stamp (DTSTAMP).
185         
186         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTAMP");
187         
188         // Process the data from DTSTAMP.
189         
190         if (DataReceived.begin() != DataReceived.end()){
191         
192                 try {
193                         DateTimeStampTokens = DataReceived.begin()->first.substr(8);
194                 }
195                 
196                 catch(const out_of_range &oor){
197                         // Do nothing as there is no data.
198                 }               
199                 
200                 DateTimeStampData = DataReceived.begin()->second;
201                 
202         }
204         // Get the Unique ID (UID).
205         
206         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "UID");
207         
208         // Process the data from UID.
209         
210         if (DataReceived.begin() != DataReceived.end()){
211         
212                 try {
213                         UniqueIDTokens = DataReceived.begin()->first.substr(4);
214                 }
215                 
216                 catch(const out_of_range &oor){
217                         // Do nothing as there is no data.
218                 }               
219                 
220                 UniqueID = DataReceived.begin()->second;
221                 
222         }
223         
224         // Get the Date Time Start value.
225         
226         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTART");
227         
228         // Process the data from DTSTART.
229         
230         if (DataReceived.begin() != DataReceived.end()){
231         
232                 bool TokenData = false;
233                 string PropertyTokens;
234                 
235                 PropertyNameData = (string*)&DataReceived.begin()->first;
236                 
237                 PropertyData = SplitValues(*PropertyNameData);
238                 
239                 for(map<string,string>::iterator iter = PropertyData.begin();
240                         iter != PropertyData.end(); iter++){
241                         
242                         if (iter->first == "VALUE"){
243                                 
244                                 DateTimeStartDataValue = iter->second;
245                                 
246                         } else if (iter->first == "TZID"){
247                                 
248                                 DateTimeStartDataTimeZoneID = iter->second;
249                                 
250                         } else {
251                                 
252                                 if (TokenData == false){
253                                         TokenData = true;
254                                 } else {
255                                         PropertyTokens += ";";
256                                 }
257                                 
258                                 PropertyTokens += iter->first;
259                                 PropertyTokens += "=";
260                                 PropertyTokens += iter->second;
261                                 
262                         }
263                                 
264                 }
265                 
266                 if (PropertyTokens.size() > 0){
267                         DateTimeStartDataTokens = PropertyTokens;
268                 }
269                 
270                 DateTimeStartData = DataReceived.begin()->second;
271                 
272         }
273         
274         // Process the data from CLASS.
275         
276         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "CLASS");
277         
278         if (DataReceived.begin() != DataReceived.end()){
279         
280                 try {
281                         ClassDataTokens = DataReceived.begin()->first.substr(6);
282                 }
283                 
284                 catch(const out_of_range &oor){
285                         // Do nothing as there is no data.
286                 }               
287                 
288                 ClassData = DataReceived.begin()->second;
289                 
290         }
291         
292         // Process the data from CREATED.
293         
294         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "CREATED");
295         
296         if (DataReceived.begin() != DataReceived.end()){
297         
298                 try {
299                         DateTimeCreatedTokens = DataReceived.begin()->first.substr(8);
300                 }
301                 
302                 catch(const out_of_range &oor){
303                         // Do nothing as there is no data.
304                 }               
305                 
306                 DateTimeCreatedData = DataReceived.begin()->second;
307                 
308         }
309         
310         // Process the data from DESCRIPTION.
311         
312         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DESCRIPTION");
313         
314         if (DataReceived.begin() != DataReceived.end()){
315         
316                 bool TokenData = false;
317                 string PropertyTokens;
318                 
319                 PropertyNameData = (string*)&DataReceived.begin()->first;
320                 
321                 PropertyData = SplitValues(*PropertyNameData);
322                 
323                 for(map<string,string>::iterator iter = PropertyData.begin();
324                         iter != PropertyData.end(); iter++){
325                         
326                         if (iter->first == "ALTREP"){
327                                 
328                                 DescriptionListAltRep.clear();
329                                 DescriptionListAltRep.push_back(iter->second);
330                                 
331                         } else if (iter->first == "LANGUAGE"){
332                                 
333                                 DescriptionListLanguage.clear();
334                                 DescriptionListLanguage.push_back(iter->second);
335                                 
336                         } else {
337                                 
338                                 if (TokenData == false){
339                                         TokenData = true;
340                                 } else {
341                                         PropertyTokens += ";";
342                                 }
343                                 
344                                 PropertyTokens += iter->first;
345                                 PropertyTokens += "=";
346                                 PropertyTokens += iter->second;
347                                 
348                         }
349                                 
350                 }
351                 
352                 if (PropertyTokens.size() > 0){
353                         DescriptionListTokens.clear();
354                         DescriptionListTokens.push_back(PropertyTokens);
355                 }
356                 
357                 DescriptionList.clear();
358                 DescriptionList.push_back(DataReceived.begin()->second);
359                 
360         }
361         
362         // Process the data from GEO.
363         
364         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "GEO");
365         
366         if (DataReceived.begin() != DataReceived.end()){
367         
368                 try {
369                         GeographicTokens = DataReceived.begin()->first.substr(4);
370                 }
371                 
372                 catch(const out_of_range &oor){
373                         // Do nothing as there is no data.
374                 }               
375                 
376                 GeographicData = DataReceived.begin()->second;
377                 
378         }
379         
380         // Process the data from LAST-MODIFIED.
381         
382         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "LAST-MODIFIED");
383         
384         if (DataReceived.begin() != DataReceived.end()){
385         
386                 try {
387                         LastModifiedTokens = DataReceived.begin()->first.substr(14);
388                 }
389                 
390                 catch(const out_of_range &oor){
391                         // Do nothing as there is no data.
392                 }               
393                 
394                 LastModifiedData = DataReceived.begin()->second;
395                 
396         }
397         
398         // Process the data from LOCATION.
399         
400         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "LOCATION");
401         
402         if (DataReceived.begin() != DataReceived.end()){
403         
404                 bool TokenData = false;
405                 string PropertyTokens;
406                 
407                 PropertyNameData = (string*)&DataReceived.begin()->first;
408                 
409                 PropertyData = SplitValues(*PropertyNameData);
410                 
411                 for(map<string,string>::iterator iter = PropertyData.begin();
412                         iter != PropertyData.end(); iter++){
413                         
414                         if (iter->first == "ALTREP"){
415                                 
416                                 LocationDataAltRep = iter->second;
417                                 
418                         } else if (iter->first == "LANGUAGE"){
419                                 
420                                 LocationDataLanguage = iter->second;
421                                 
422                         } else {
423                                 
424                                 if (TokenData == false){
425                                         TokenData = true;
426                                 } else {
427                                         PropertyTokens += ";";
428                                 }
429                                 
430                                 PropertyTokens += iter->first;
431                                 PropertyTokens += "=";
432                                 PropertyTokens += iter->second;
433                                 
434                         }
435                                 
436                 }
437                 
438                 if (PropertyTokens.size() > 0){
439                         
440                         LocationDataTokens = PropertyTokens;
441                         
442                 }
443                 
444                 LocationData = DataReceived.begin()->second;
445                 
446         }
447         
448         // Process the data from ORGANIZER.
449         
450         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "ORGANIZER");
451         
452         if (DataReceived.begin() != DataReceived.end()){
453         
454                 bool TokenData = false;
455                 string PropertyTokens;
456                 
457                 PropertyNameData = (string*)&DataReceived.begin()->first;
458                 
459                 PropertyData = SplitValues(*PropertyNameData);
460                 
461                 for(map<string,string>::iterator iter = PropertyData.begin();
462                         iter != PropertyData.end(); iter++){
463                         
464                         if (iter->first == "CN"){
465                                 
466                                 OrganiserDataCommonName = iter->second;
467                                 
468                         } else if (iter->first == "DIR"){
469                                 
470                                 OrganiserDataDirectoryEntry = iter->second;
471                                 
472                         } else if (iter->first == "SENT-BY"){
473                                 
474                                 OrganiserDataSentByParam = iter->second;
475                                 
476                         } else if (iter->first == "LANGUAGE"){
477                                 
478                                 OrganiserDataLanguage = iter->second;
479                                 
480                         } else {
481                                 
482                                 if (TokenData == false){
483                                         TokenData = true;
484                                 } else {
485                                         PropertyTokens += ";";
486                                 }
487                                 
488                                 PropertyTokens += iter->first;
489                                 PropertyTokens += "=";
490                                 PropertyTokens += iter->second;
491                                 
492                         }
493                                 
494                 }
495                 
496                 if (PropertyTokens.size() > 0){
497                         
498                         OrganiserDataTokens = PropertyTokens;
499                         
500                 }
501                 
502                 OrganiserData = DataReceived.begin()->second;
503                 
504         }
506         // Process the data from PRIORITY.
507         
508         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "PRIORITY");
509         
510         if (DataReceived.begin() != DataReceived.end()){
511         
512                 try {
513                         PriorityTokens = DataReceived.begin()->first.substr(9);
514                 }
515                 
516                 catch(const out_of_range &oor){
517                         // Do nothing as there is no data.
518                 }               
519                 
520                 try {
521                         PriorityData = stoi(DataReceived.begin()->second);
522                 }
523                 
524                 catch(const invalid_argument &oor){
525                         PriorityTokens.clear();
526                 }
527                 
528         }
529         
530         // Process the data from SEQUENCE.
531         
532         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "SEQUENCE");
533         
534         if (DataReceived.begin() != DataReceived.end()){
535         
536                 try {
537                         SequenceTokens = DataReceived.begin()->first.substr(9);
538                 }
539                 
540                 catch(const out_of_range &oor){
541                         // Do nothing as there is no data.
542                 }               
543                 
544                 try {
545                         SequenceData = stoi(DataReceived.begin()->second);
546                 }
547                 
548                 catch(const invalid_argument &oor){
549                         SequenceTokens.clear();
550                 }
551                 
552         }
553         
554         // Process the data from STATUS.
555         
556         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "STATUS");
557         
558         if (DataReceived.begin() != DataReceived.end()){
559         
560                 bool TokenData = false;
561                 string PropertyTokens;
562                 
563                 PropertyNameData = (string*)&DataReceived.begin()->first;
564                 
565                 PropertyData = SplitValues(*PropertyNameData);
566                 
567                 for(map<string,string>::iterator iter = PropertyData.begin();
568                         iter != PropertyData.end(); iter++){
569                         
570                         if (iter->first == "LANGUAGE"){
571                                 
572                                 RequestStatusLanguage = iter->second;
573                                 
574                         } else {
575                                 
576                                 if (TokenData == false){
577                                         TokenData = true;
578                                 } else {
579                                         PropertyTokens += ";";
580                                 }
581                                 
582                                 PropertyTokens += iter->first;
583                                 PropertyTokens += "=";
584                                 PropertyTokens += iter->second;
585                                 
586                         }
587                                 
588                 }
589                 
590                 if (PropertyTokens.size() > 0){
591                         
592                         RequestStatusTokens = PropertyTokens;
593                         
594                 }
595                 
596                 RequestStatusData = DataReceived.begin()->second;
597                 
598         }
599         
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