Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added check for DTSTART in CalendarEventObject::ValidObject
[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.
104         
105         for (vector<string>::iterator iter = ObjectName.begin();
106                 iter != ObjectName.end(); iter++){
107                         
108                 try{
109                         PropertyName = ObjectName[SeekCount].substr(0,7);
110                 }
111                         
112                 catch(const out_of_range& oor){
113                         continue;
114                 }
115                 
116                 if (PropertyName == "DTSTART"){
117                         
118                         if (ValidDateTimeStart == false){
119                                 ValidDateTimeStart = true;
120                         } else {
121                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
122                         }
123                                 
124                 }
125                         
126                 SeekCount++;
127                         
128         }
129         
130         SeekCount = 0;
131         
132         // Look for END:VEVENT.
133         
134         for (vector<string>::iterator iter = ObjectName.begin();
135                 iter != ObjectName.end(); iter++){
136         
137                 if (ObjectName[SeekCount] == "END" &&
138                         ObjectData[SeekCount] == "VEVENT"){
139                         
140                         if (ValidEnd == false){
141                                 ValidEnd = true;
142                         } else {
143                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
144                         }
145                                 
146                 }
147                         
148                 SeekCount++;
149                         
150         }
151         
152         // Check if the VEVENT is valid.
154         if (ValidBegin == true && 
155                 ValidEnd == true && 
156                 ValidDateTimeStamp == true &&
157                 ValidDateTimeStart == true &&
158                 ValidUniqueID == true){
159                 
160                 return CALENDAROBJECTVALID_OK;
161                         
162         } else {
163                 
164                 return CALENDAROBJECTVALID_INVALIDFORMAT;
165                 
166         }
167         
170 void CalendarEventObject::ProcessData(){
171         
172         // Process the data.
173         
174         multimap<string,string> DataReceived;
175         
176         // Get the Date Time Stamp (DTSTAMP).
177         
178         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTAMP");
179         
180         // Process the data from DTSTAMP.
181         
182         if (DataReceived.begin() != DataReceived.end()){
183         
184                 try {
185                         DateTimeStampTokens = DataReceived.begin()->first.substr(8);
186                 }
187                 
188                 catch(const out_of_range &oor){
189                         // Do nothing as there is no data.
190                 }               
191                 
192                 DateTimeStampData = DataReceived.begin()->second;
193                 
194         }
196         // Get the Unique ID (UID).
197         
198         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "UID");
199         
200         // Process the data from DTSTAMP.
201         
202         if (DataReceived.begin() != DataReceived.end()){
203         
204                 try {
205                         UniqueIDTokens = DataReceived.begin()->first.substr(4);
206                 }
207                 
208                 catch(const out_of_range &oor){
209                         // Do nothing as there is no data.
210                 }               
211                 
212                 UniqueID = DataReceived.begin()->second;
213                 
214         }
215         
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