1 #include "CalendarFreeBusy.h"
5 CalendarObjectValidResult CalendarFreeBusyObject::ValidObject(){
7 bool ValidBegin = false;
9 bool ValidDateTimeStamp = false;
10 bool ValidUniqueID = false;
11 bool ValidDateTimeStart = false;
15 // Look for BEGIN:VFREEBUSY.
17 for (vector<string>::iterator iter = ObjectName.begin();
18 iter != ObjectName.end(); iter++){
20 if (ObjectName[SeekCount] == "BEGIN" &&
21 ObjectData[SeekCount] == "VFREEBUSY"){
23 if (ValidBegin == false){
26 return CALENDAROBJECTVALID_INVALIDFORMAT;
31 if (ObjectName[SeekCount] == "END" &&
32 ObjectData[SeekCount] == "VFREEBUSY" &&
35 return CALENDAROBJECTVALID_INVALIDFORMAT;
47 for (vector<string>::iterator iter = ObjectName.begin();
48 iter != ObjectName.end(); iter++){
51 PropertyName = ObjectName[SeekCount].substr(0,7);
54 catch(const out_of_range& oor){
58 if (PropertyName == "DTSTAMP"){
60 if (ValidDateTimeStamp == false){
61 ValidDateTimeStamp = true;
63 return CALENDAROBJECTVALID_INVALIDFORMAT;
76 for (vector<string>::iterator iter = ObjectName.begin();
77 iter != ObjectName.end(); iter++){
80 PropertyName = ObjectName[SeekCount].substr(0,3);
83 catch(const out_of_range& oor){
87 if (PropertyName == "UID"){
89 if (ValidUniqueID == false){
92 return CALENDAROBJECTVALID_INVALIDFORMAT;
103 // Look for END:VFREEBUSY.
105 for (vector<string>::iterator iter = ObjectName.begin();
106 iter != ObjectName.end(); iter++){
108 if (ObjectName[SeekCount] == "END" &&
109 ObjectData[SeekCount] == "VFREEBUSY"){
111 if (ValidEnd == false){
114 return CALENDAROBJECTVALID_INVALIDFORMAT;
123 // Check if the VEVENT is valid.
125 if (ValidBegin == true &&
127 ValidDateTimeStamp == true &&
128 ValidUniqueID == true){
130 return CALENDAROBJECTVALID_OK;
134 return CALENDAROBJECTVALID_INVALIDFORMAT;
140 void CalendarFreeBusyObject::ProcessData(){
144 multimap<string,string> DataReceived;
145 map<string,string> PropertyData;
146 string *PropertyNameData = nullptr;
147 int ObjectSeekCount = 0;
149 // Get the Date Time Stamp (DTSTAMP).
151 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTAMP");
153 // Process the data from DTSTAMP.
155 if (DataReceived.begin() != DataReceived.end()){
158 DateTimeStampTokens = DataReceived.begin()->first.substr(8);
161 catch(const out_of_range &oor){
162 // Do nothing as there is no data.
165 DateTimeStampData = DataReceived.begin()->second;
169 // Get the Unique ID (UID).
171 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "UID");
173 // Process the data from UID.
175 if (DataReceived.begin() != DataReceived.end()){
178 UniqueIDTokens = DataReceived.begin()->first.substr(4);
181 catch(const out_of_range &oor){
182 // Do nothing as there is no data.
185 UniqueID = DataReceived.begin()->second;
189 // Process the data from CONTACT.
191 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "CONTACT");
195 for(multimap<string,string>::iterator iter = DataReceived.begin();
196 iter != DataReceived.end();
199 ContactListTokens.push_back("");
200 ContactListAltRep.push_back("");
201 ContactListLanguage.push_back("");
202 ContactList.push_back("");
204 bool TokenData = false;
205 string PropertyTokens;
207 PropertyNameData = (string*)&iter->first;
209 PropertyData = SplitValues(*PropertyNameData);
211 for(map<string,string>::iterator dataiter = PropertyData.begin();
212 dataiter != PropertyData.end(); dataiter++){
214 if (dataiter->first == "ALTREP"){
216 ContactListAltRep[ObjectSeekCount] = dataiter->second;
218 } else if (dataiter->first == "LANGUAGE"){
220 ContactListLanguage[ObjectSeekCount] = dataiter->second;
224 if (TokenData == false){
227 PropertyTokens += ";";
230 PropertyTokens += dataiter->first;
231 PropertyTokens += "=";
232 PropertyTokens += dataiter->second;
238 if (PropertyTokens.size() > 0){
239 ContactListTokens[ObjectSeekCount] = PropertyTokens;
242 ContactList[ObjectSeekCount] = iter->second;
248 // Get the Date Time Start value.
250 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTART");
252 // Process the data from DTSTART.
254 if (DataReceived.begin() != DataReceived.end()){
256 bool TokenData = false;
257 string PropertyTokens;
259 PropertyNameData = (string*)&DataReceived.begin()->first;
261 PropertyData = SplitValues(*PropertyNameData);
263 for(map<string,string>::iterator iter = PropertyData.begin();
264 iter != PropertyData.end(); iter++){
266 if (iter->first == "VALUE"){
268 DateTimeStartDataValue = iter->second;
270 } else if (iter->first == "TZID"){
272 DateTimeStartDataTimeZoneID = iter->second;
276 if (TokenData == false){
279 PropertyTokens += ";";
282 PropertyTokens += iter->first;
283 PropertyTokens += "=";
284 PropertyTokens += iter->second;
290 if (PropertyTokens.size() > 0){
291 DateTimeStartDataTokens = PropertyTokens;
294 DateTimeStartData = DataReceived.begin()->second;
298 // Process the data from DTEND.
300 bool DateTimeEndProcessed = false;
302 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTEND");
304 if (DataReceived.begin() != DataReceived.end()){
306 bool TokenData = false;
307 string PropertyTokens;
309 PropertyNameData = (string*)&DataReceived.begin()->first;
311 PropertyData = SplitValues(*PropertyNameData);
313 for(map<string,string>::iterator iter = PropertyData.begin();
314 iter != PropertyData.end(); iter++){
316 if (iter->first == "VALUE"){
318 DateTimeEndDataValue = iter->second;
320 } else if (iter->first == "TZID"){
322 DateTimeEndDataTimeZoneID = iter->second;
326 if (TokenData == false){
329 PropertyTokens += ";";
332 PropertyTokens += iter->first;
333 PropertyTokens += "=";
334 PropertyTokens += iter->second;
340 if (PropertyTokens.size() > 0){
341 DateTimeEndDataTokens = PropertyTokens;
344 DateTimeEndData = DataReceived.begin()->second;
346 DateTimeEndProcessed = true;
350 // Process the data from ORGANIZER.
352 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "ORGANIZER");
354 if (DataReceived.begin() != DataReceived.end()){
356 bool TokenData = false;
357 string PropertyTokens;
359 PropertyNameData = (string*)&DataReceived.begin()->first;
361 PropertyData = SplitValues(*PropertyNameData);
363 for(map<string,string>::iterator iter = PropertyData.begin();
364 iter != PropertyData.end(); iter++){
366 if (iter->first == "CN"){
368 OrganiserDataCommonName = iter->second;
370 } else if (iter->first == "DIR"){
372 OrganiserDataDirectoryEntry = iter->second;
374 } else if (iter->first == "SENT-BY"){
376 OrganiserDataSentByParam = iter->second;
378 } else if (iter->first == "LANGUAGE"){
380 OrganiserDataLanguage = iter->second;
384 if (TokenData == false){
387 PropertyTokens += ";";
390 PropertyTokens += iter->first;
391 PropertyTokens += "=";
392 PropertyTokens += iter->second;
398 if (PropertyTokens.size() > 0){
400 OrganiserDataTokens = PropertyTokens;
404 OrganiserData = DataReceived.begin()->second;