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;