From abad53ea10af66d3b73823c0081ddf179a3233eb Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sun, 31 Jan 2016 10:16:28 +0000 Subject: [PATCH] Added code to check CalendarTaskObject is valid --- source/objects/calendartask/CalendarTask.cpp | 130 +++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/source/objects/calendartask/CalendarTask.cpp b/source/objects/calendartask/CalendarTask.cpp index 48af315..eb99179 100644 --- a/source/objects/calendartask/CalendarTask.cpp +++ b/source/objects/calendartask/CalendarTask.cpp @@ -4,6 +4,136 @@ using namespace std; CalendarObjectValidResult CalendarTaskObject::ValidObject(){ + bool ValidBegin = false; + bool ValidEnd = false; + bool ValidDateTimeStamp = false; + bool ValidUniqueID = false; + int SeekCount = 0; + string PropertyName; + + // Look for BEGIN:VEVENT. + + for (vector::iterator iter = ObjectName.begin(); + iter != ObjectName.end(); iter++){ + + if (ObjectName[SeekCount] == "BEGIN" && + ObjectData[SeekCount] == "VTODO"){ + + if (ValidBegin == false){ + ValidBegin = true; + } else { + return CALENDAROBJECTVALID_INVALIDFORMAT; + } + + } + + if (ObjectName[SeekCount] == "END" && + ObjectData[SeekCount] == "VTODO" && + ValidBegin == false){ + + return CALENDAROBJECTVALID_INVALIDFORMAT; + + } + + SeekCount++; + + } + + SeekCount = 0; + + // Look for DTSTAMP. + + for (vector::iterator iter = ObjectName.begin(); + iter != ObjectName.end(); iter++){ + + try{ + PropertyName = ObjectName[SeekCount].substr(0,7); + } + + catch(const out_of_range& oor){ + continue; + } + + if (PropertyName == "DTSTAMP"){ + + if (ValidDateTimeStamp == false){ + ValidDateTimeStamp = true; + } else { + return CALENDAROBJECTVALID_INVALIDFORMAT; + } + + } + + SeekCount++; + + } + + SeekCount = 0; + + // Look for UID. + + for (vector::iterator iter = ObjectName.begin(); + iter != ObjectName.end(); iter++){ + + try{ + PropertyName = ObjectName[SeekCount].substr(0,3); + } + + catch(const out_of_range& oor){ + continue; + } + + if (PropertyName == "UID"){ + + if (ValidUniqueID == false){ + ValidUniqueID = true; + } else { + return CALENDAROBJECTVALID_INVALIDFORMAT; + } + + } + + SeekCount++; + + } + + SeekCount = 0; + + // Look for END:VEVENT. + + for (vector::iterator iter = ObjectName.begin(); + iter != ObjectName.end(); iter++){ + + if (ObjectName[SeekCount] == "END" && + ObjectData[SeekCount] == "VTODO"){ + + if (ValidEnd == false){ + ValidEnd = true; + } else { + return CALENDAROBJECTVALID_INVALIDFORMAT; + } + + } + + SeekCount++; + + } + + // Check if the VEVENT is valid. + + if (ValidBegin == true && + ValidEnd == true && + ValidDateTimeStamp == true && + ValidUniqueID == true){ + + return CALENDAROBJECTVALID_OK; + + } else { + + return CALENDAROBJECTVALID_INVALIDFORMAT; + + } + } void CalendarTaskObject::ProcessData(){ -- 2.39.5