an iCal processing library

Committer:
WiredHome
Date:
Sun Apr 20 13:25:50 2014 +0000
Revision:
0:49245357cd1b
Child:
1:db274b9e40cc
iCal processing library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 0:49245357cd1b 1
WiredHome 0:49245357cd1b 2
WiredHome 0:49245357cd1b 3 #include "iCal.h"
WiredHome 0:49245357cd1b 4 #include <algorithm>
WiredHome 0:49245357cd1b 5
WiredHome 0:49245357cd1b 6 //#define DEBUG "iCal"
WiredHome 0:49245357cd1b 7 #include <cstdio>
WiredHome 0:49245357cd1b 8 #if (defined(DEBUG) && !defined(TARGET_LPC11U24))
WiredHome 0:49245357cd1b 9 #define DBG(x, ...) std::printf("[DBG %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 0:49245357cd1b 10 #define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 0:49245357cd1b 11 #define ERR(x, ...) std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 0:49245357cd1b 12 #define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 0:49245357cd1b 13 #else
WiredHome 0:49245357cd1b 14 #define DBG(x, ...)
WiredHome 0:49245357cd1b 15 #define WARN(x, ...)
WiredHome 0:49245357cd1b 16 #define ERR(x, ...)
WiredHome 0:49245357cd1b 17 #define INFO(x, ...)
WiredHome 0:49245357cd1b 18 #endif
WiredHome 0:49245357cd1b 19
WiredHome 0:49245357cd1b 20 Event_T EventList[EVENT_COUNT];
WiredHome 0:49245357cd1b 21 int EventCount = 0;
WiredHome 0:49245357cd1b 22
WiredHome 0:49245357cd1b 23
WiredHome 0:49245357cd1b 24 const char * RPT_DAYS[] = { "SU", "MO", "TU", "WE", "TH", "FR", "SA", "" };
WiredHome 0:49245357cd1b 25
WiredHome 0:49245357cd1b 26 int GetNumEvents(void)
WiredHome 0:49245357cd1b 27 {
WiredHome 0:49245357cd1b 28 return EventCount;
WiredHome 0:49245357cd1b 29 }
WiredHome 0:49245357cd1b 30
WiredHome 0:49245357cd1b 31 const char * RepeatDayAbbrev(int i)
WiredHome 0:49245357cd1b 32 {
WiredHome 0:49245357cd1b 33 if (i < 7)
WiredHome 0:49245357cd1b 34 return RPT_DAYS[i];
WiredHome 0:49245357cd1b 35 else
WiredHome 0:49245357cd1b 36 return RPT_DAYS[7];
WiredHome 0:49245357cd1b 37 }
WiredHome 0:49245357cd1b 38
WiredHome 0:49245357cd1b 39 void SortEvents()
WiredHome 0:49245357cd1b 40 {
WiredHome 0:49245357cd1b 41 bool swapped;
WiredHome 0:49245357cd1b 42 int e;
WiredHome 0:49245357cd1b 43 Event_T Event;
WiredHome 0:49245357cd1b 44
WiredHome 0:49245357cd1b 45 do {
WiredHome 0:49245357cd1b 46 swapped = false;
WiredHome 0:49245357cd1b 47 for (e=0; e<EventCount-1; e++) {
WiredHome 0:49245357cd1b 48 if (EventList[e].Start > EventList[e+1].Start) {
WiredHome 0:49245357cd1b 49 Event = EventList[e];
WiredHome 0:49245357cd1b 50 EventList[e] = EventList[e+1];
WiredHome 0:49245357cd1b 51 EventList[e+1] = Event;
WiredHome 0:49245357cd1b 52 swapped = true;
WiredHome 0:49245357cd1b 53 }
WiredHome 0:49245357cd1b 54 }
WiredHome 0:49245357cd1b 55 } while (swapped);
WiredHome 0:49245357cd1b 56 }
WiredHome 0:49245357cd1b 57
WiredHome 0:49245357cd1b 58 uint16_t AtoIxN(char * p, int n)
WiredHome 0:49245357cd1b 59 {
WiredHome 0:49245357cd1b 60 uint16_t res = 0;
WiredHome 0:49245357cd1b 61
WiredHome 0:49245357cd1b 62 while (n--) {
WiredHome 0:49245357cd1b 63 res = (res * 10) + (*p - '0');
WiredHome 0:49245357cd1b 64 p++;
WiredHome 0:49245357cd1b 65 }
WiredHome 0:49245357cd1b 66 return res;
WiredHome 0:49245357cd1b 67 }
WiredHome 0:49245357cd1b 68
WiredHome 0:49245357cd1b 69 time_t ParseDateStamp(char * string, NTPClient & ntp)
WiredHome 0:49245357cd1b 70 {
WiredHome 0:49245357cd1b 71 time_t tStamp;
WiredHome 0:49245357cd1b 72 struct tm t;
WiredHome 0:49245357cd1b 73 //INFO("ParseDateStamp(..., %s)\r\n", string);
WiredHome 0:49245357cd1b 74 t.tm_year = AtoIxN(string, 4) - 1900;
WiredHome 0:49245357cd1b 75 t.tm_mon = AtoIxN(string+4, 2) - 1;
WiredHome 0:49245357cd1b 76 t.tm_mday = AtoIxN(string+6, 2);
WiredHome 0:49245357cd1b 77 t.tm_hour = AtoIxN(string+9, 2);
WiredHome 0:49245357cd1b 78 t.tm_min = AtoIxN(string+11, 2);
WiredHome 0:49245357cd1b 79 t.tm_sec = AtoIxN(string+13, 2);
WiredHome 0:49245357cd1b 80 tStamp = mktime(&t);
WiredHome 0:49245357cd1b 81 if (string[strlen(string)-1] == 'Z')
WiredHome 0:49245357cd1b 82 tStamp = tStamp + ntp.getTZO();
WiredHome 0:49245357cd1b 83 return tStamp;
WiredHome 0:49245357cd1b 84 //int tm_sec //seconds after the minute – [0, 60][@1] (public member object)
WiredHome 0:49245357cd1b 85 //int tm_min //minutes after the hour – [0, 59] (public member object)
WiredHome 0:49245357cd1b 86 //int tm_hour //hours since midnight – [0, 23] (public member object)
WiredHome 0:49245357cd1b 87 //int tm_mday //day of the month – [1, 31] (public member object)
WiredHome 0:49245357cd1b 88 //int tm_mon //months since January – [0, 11] (public member object)
WiredHome 0:49245357cd1b 89 //int tm_year //years since 1900 (public member object)
WiredHome 0:49245357cd1b 90 //int tm_wday //days since Sunday – [0, 6] (public member object)
WiredHome 0:49245357cd1b 91 //int tm_yday //days since January 1 – [0, 365]
WiredHome 0:49245357cd1b 92 //int tm_isdst
WiredHome 0:49245357cd1b 93 }
WiredHome 0:49245357cd1b 94
WiredHome 0:49245357cd1b 95 char * FormatCTime(time_t t)
WiredHome 0:49245357cd1b 96 {
WiredHome 0:49245357cd1b 97 static char temp[4][80];
WiredHome 0:49245357cd1b 98 static int i = 0;
WiredHome 0:49245357cd1b 99
WiredHome 0:49245357cd1b 100 i &= 3;
WiredHome 0:49245357cd1b 101 strcpy(temp[i], ctime(&t));
WiredHome 0:49245357cd1b 102 temp[i][strlen(temp[i])-1] = '\0';
WiredHome 0:49245357cd1b 103 return temp[i++];
WiredHome 0:49245357cd1b 104 }
WiredHome 0:49245357cd1b 105
WiredHome 0:49245357cd1b 106
WiredHome 0:49245357cd1b 107 void ShowEventInfo(Event_T & Event)
WiredHome 0:49245357cd1b 108 {
WiredHome 0:49245357cd1b 109 char temp[80];
WiredHome 0:49245357cd1b 110
WiredHome 0:49245357cd1b 111 INFO("*** Summary: %s", Event.Summary);
WiredHome 0:49245357cd1b 112 strcpy(temp, ctime(&Event.Start));
WiredHome 0:49245357cd1b 113 temp[strlen(temp)-1] = '\0';
WiredHome 0:49245357cd1b 114 INFO(" Start: %d %s", Event.Start, temp);
WiredHome 0:49245357cd1b 115 strcpy(temp, ctime(&Event.End));
WiredHome 0:49245357cd1b 116 temp[strlen(temp)-1] = '\0';
WiredHome 0:49245357cd1b 117 INFO(" End: %d %s", Event.End, temp );
WiredHome 0:49245357cd1b 118 INFO(" Count: %d", Event.Count);
WiredHome 0:49245357cd1b 119 INFO(" RepeatFrq: %d", Event.RepeatFreq);
WiredHome 0:49245357cd1b 120 INFO(" RepeatDay: %02X", Event.RepeatDays);
WiredHome 0:49245357cd1b 121 strcpy(temp, ctime(&Event.Until));
WiredHome 0:49245357cd1b 122 temp[strlen(temp)-1] = '\0';
WiredHome 0:49245357cd1b 123 INFO(" Until: %d %s", Event.Until, temp);
WiredHome 0:49245357cd1b 124 INFO(" Location: %s", Event.Location);
WiredHome 0:49245357cd1b 125 INFO(" Category: %s", Event.Category);
WiredHome 0:49245357cd1b 126 INFO(" Priority: %d", Event.Priority);
WiredHome 0:49245357cd1b 127 }
WiredHome 0:49245357cd1b 128
WiredHome 0:49245357cd1b 129
WiredHome 0:49245357cd1b 130 /// Computes the intersection of time1 and time2 ranges, and modifies time1
WiredHome 0:49245357cd1b 131 /// range to represent the intersection.
WiredHome 0:49245357cd1b 132 ///
WiredHome 0:49245357cd1b 133 /// @param start1 is input as the start of the time1 range, and is written
WiredHome 0:49245357cd1b 134 /// to represent the intersection of the two ranges.
WiredHome 0:49245357cd1b 135 /// @param end1 is input as the end of the time1 range and is written to
WiredHome 0:49245357cd1b 136 /// represent the intersection of the two ranges.
WiredHome 0:49245357cd1b 137 /// @param start2 is the start of the time2 range.
WiredHome 0:49245357cd1b 138 /// @param end2 is the end of the time2 range.
WiredHome 0:49245357cd1b 139 /// @returns true if the ranges have an intersection, and the time1 range
WiredHome 0:49245357cd1b 140 /// values have been modified.
WiredHome 0:49245357cd1b 141 ///
WiredHome 0:49245357cd1b 142 bool TimeIntersects(time_t * start1, time_t * end1, time_t * start2, time_t * end2)
WiredHome 0:49245357cd1b 143 {
WiredHome 0:49245357cd1b 144 // |----Time1----|
WiredHome 0:49245357cd1b 145 // |--Time2--| false
WiredHome 0:49245357cd1b 146 //
WiredHome 0:49245357cd1b 147 // |----Time1----|
WiredHome 0:49245357cd1b 148 // |--Time2--| false
WiredHome 0:49245357cd1b 149 //
WiredHome 0:49245357cd1b 150 // |----Time1----|
WiredHome 0:49245357cd1b 151 // |----Time2----|
WiredHome 0:49245357cd1b 152 // |-Time1-| true
WiredHome 0:49245357cd1b 153 //
WiredHome 0:49245357cd1b 154 // |----Time1----|
WiredHome 0:49245357cd1b 155 // |----Time2----|
WiredHome 0:49245357cd1b 156 // |-Time1-| true
WiredHome 0:49245357cd1b 157 //
WiredHome 0:49245357cd1b 158 // |----Time1-------|
WiredHome 0:49245357cd1b 159 // |-Time2-|
WiredHome 0:49245357cd1b 160 // |-Time1-| true
WiredHome 0:49245357cd1b 161 //
WiredHome 0:49245357cd1b 162 if (*end1 < *start2 || *end2 < *start1)
WiredHome 0:49245357cd1b 163 return false;
WiredHome 0:49245357cd1b 164 if (max(*start1,*start2) < min(*end1,*end2)) {
WiredHome 0:49245357cd1b 165 *start1 = max(*start1,*start2);
WiredHome 0:49245357cd1b 166 *end1 = min(*end1,*end2);
WiredHome 0:49245357cd1b 167 return true;
WiredHome 0:49245357cd1b 168 } else {
WiredHome 0:49245357cd1b 169 return false;
WiredHome 0:49245357cd1b 170 }
WiredHome 0:49245357cd1b 171 }
WiredHome 0:49245357cd1b 172
WiredHome 0:49245357cd1b 173 time_t NextInterval(int repeatFreq, int interval)
WiredHome 0:49245357cd1b 174 {
WiredHome 0:49245357cd1b 175 time_t secperday = 60*60*24;
WiredHome 0:49245357cd1b 176 const int repeatFactor[] = {1, 7, 30, 365};
WiredHome 0:49245357cd1b 177 INFO("freq %d, interval %d", repeatFreq, interval);
WiredHome 0:49245357cd1b 178 return repeatFactor[repeatFreq-1] * interval * secperday;
WiredHome 0:49245357cd1b 179 }
WiredHome 0:49245357cd1b 180
WiredHome 0:49245357cd1b 181 bool RepeatIntersects(time_t * start1, time_t * end1, time_t * start2, time_t * end2, Event_T & Event)
WiredHome 0:49245357cd1b 182 {
WiredHome 0:49245357cd1b 183 if (Event.RepeatFreq) {
WiredHome 0:49245357cd1b 184 INFO("%s", Event.Summary);
WiredHome 0:49245357cd1b 185 INFO("** 1: (%s, %s)", FormatCTime(*start1), FormatCTime(*end1));
WiredHome 0:49245357cd1b 186 INFO(" 2: (%s, %s)", FormatCTime(*start2), FormatCTime(*end2));
WiredHome 0:49245357cd1b 187 if (TimeIntersects(start1, end1, start2, end2)) {
WiredHome 0:49245357cd1b 188 return true;
WiredHome 0:49245357cd1b 189 } else if (Event.Start < *start2 && Event.Until > *start2 ) { // Until=....
WiredHome 0:49245357cd1b 190 do {
WiredHome 0:49245357cd1b 191 time_t interval = NextInterval(Event.RepeatFreq, (Event.Interval == 0) ? 1 : Event.Interval);
WiredHome 0:49245357cd1b 192 *start1 = *start1 + interval;
WiredHome 0:49245357cd1b 193 *end1 = *end1 + interval;
WiredHome 0:49245357cd1b 194 INFO("** 1: (%s, %s)", FormatCTime(*start1), FormatCTime(*end1));
WiredHome 0:49245357cd1b 195 INFO("until (%24s, %s)", " ", FormatCTime(Event.Until));
WiredHome 0:49245357cd1b 196 INFO(" 2: (%s, %s)", FormatCTime(*start2), FormatCTime(*end2));
WiredHome 0:49245357cd1b 197 if (TimeIntersects(start1, end1, start2, end2)) {
WiredHome 0:49245357cd1b 198 return true;
WiredHome 0:49245357cd1b 199 }
WiredHome 0:49245357cd1b 200 } while (*start1 < *end2 && *start1 < Event.Until);
WiredHome 0:49245357cd1b 201 } else if (Event.Start < *start2 && Event.Count) { // Count=
WiredHome 0:49245357cd1b 202 int count = Event.Count - 1;
WiredHome 0:49245357cd1b 203 do {
WiredHome 0:49245357cd1b 204 time_t interval = NextInterval(Event.RepeatFreq, (Event.Interval == 0) ? 1 : Event.Interval);
WiredHome 0:49245357cd1b 205 *start1 = *start1 + interval;
WiredHome 0:49245357cd1b 206 *end1 = *end1 + interval;
WiredHome 0:49245357cd1b 207 INFO("** 1: (%s, %s) - %d", FormatCTime(*start1), FormatCTime(*end1), count);
WiredHome 0:49245357cd1b 208 INFO(" 2: (%s, %s)", FormatCTime(*start2), FormatCTime(*end2));
WiredHome 0:49245357cd1b 209 if (TimeIntersects(start1, end1, start2, end2)) {
WiredHome 0:49245357cd1b 210 return true;
WiredHome 0:49245357cd1b 211 }
WiredHome 0:49245357cd1b 212 } while (--count);
WiredHome 0:49245357cd1b 213 } else if (Event.Start < *start2) { // no Count= and no Until=
WiredHome 0:49245357cd1b 214 do {
WiredHome 0:49245357cd1b 215 time_t interval = NextInterval(Event.RepeatFreq, (Event.Interval == 0) ? 1 : Event.Interval);
WiredHome 0:49245357cd1b 216 *start1 = *start1 + interval;
WiredHome 0:49245357cd1b 217 *end1 = *end1 + interval;
WiredHome 0:49245357cd1b 218 INFO("== 1: (%s, %s)", FormatCTime(*start1), FormatCTime(*end1));
WiredHome 0:49245357cd1b 219 INFO(" 2: (%s, %s)", FormatCTime(*start2), FormatCTime(*end2));
WiredHome 0:49245357cd1b 220 if (TimeIntersects(start1, end1, start2, end2)) {
WiredHome 0:49245357cd1b 221 return true;
WiredHome 0:49245357cd1b 222 }
WiredHome 0:49245357cd1b 223 } while (*start1 < *end2);
WiredHome 0:49245357cd1b 224 }
WiredHome 0:49245357cd1b 225 }
WiredHome 0:49245357cd1b 226 return false;
WiredHome 0:49245357cd1b 227 }
WiredHome 0:49245357cd1b 228
WiredHome 0:49245357cd1b 229
WiredHome 0:49245357cd1b 230
WiredHome 0:49245357cd1b 231 void ParseICalStream(char * pStart, time_t gridStartTime, time_t gridEndTime, NTPClient & ntp)
WiredHome 0:49245357cd1b 232 {
WiredHome 0:49245357cd1b 233 Event_T Event;
WiredHome 0:49245357cd1b 234 bool tzAdjusted = false;
WiredHome 0:49245357cd1b 235 char * pEnd;
WiredHome 0:49245357cd1b 236 typedef enum { idle, inTimeZone, inEvent } seekstate_t;
WiredHome 0:49245357cd1b 237 seekstate_t seeking = idle;
WiredHome 0:49245357cd1b 238 EventCount = 0;
WiredHome 0:49245357cd1b 239
WiredHome 0:49245357cd1b 240 while (pStart && EventCount < EVENT_COUNT) {
WiredHome 0:49245357cd1b 241 pEnd = strchr(pStart, '\n');
WiredHome 0:49245357cd1b 242 if (pEnd) {
WiredHome 0:49245357cd1b 243 if (*(pEnd-1) == '\r')
WiredHome 0:49245357cd1b 244 pEnd--;
WiredHome 0:49245357cd1b 245 *pEnd++ = '\0';
WiredHome 0:49245357cd1b 246 while (*pEnd && *pEnd < ' ') {
WiredHome 0:49245357cd1b 247 pEnd++;
WiredHome 0:49245357cd1b 248 }
WiredHome 0:49245357cd1b 249 // pStart now has a single null terminated line of text.
WiredHome 0:49245357cd1b 250 //INFO("*** %s", pStart);
WiredHome 0:49245357cd1b 251 switch (seeking) {
WiredHome 0:49245357cd1b 252 case idle:
WiredHome 0:49245357cd1b 253 if (strcmp(pStart, "BEGIN:VTIMEZONE") == 0)
WiredHome 0:49245357cd1b 254 seeking = inTimeZone;
WiredHome 0:49245357cd1b 255 else if (strcmp(pStart, "BEGIN:VEVENT") == 0) {
WiredHome 0:49245357cd1b 256 seeking = inEvent;
WiredHome 0:49245357cd1b 257 Event.Start = 0;
WiredHome 0:49245357cd1b 258 Event.End = 0;
WiredHome 0:49245357cd1b 259 Event.Until = 0;
WiredHome 0:49245357cd1b 260 Event.Summary[0] = '\0';
WiredHome 0:49245357cd1b 261 Event.Location[0] = '\0';
WiredHome 0:49245357cd1b 262 Event.Category[0] = '\0';
WiredHome 0:49245357cd1b 263 Event.Count = 0;
WiredHome 0:49245357cd1b 264 Event.Interval = 0;
WiredHome 0:49245357cd1b 265 Event.RepeatFreq = rptfNone;
WiredHome 0:49245357cd1b 266 Event.RepeatDays = 0;
WiredHome 0:49245357cd1b 267 Event.Priority = 5; // 5 is Normal
WiredHome 0:49245357cd1b 268 //ShowEventInfo(Event, pc);
WiredHome 0:49245357cd1b 269 }
WiredHome 0:49245357cd1b 270 break;
WiredHome 0:49245357cd1b 271 case inTimeZone:
WiredHome 0:49245357cd1b 272 // Can also pick up daylight savings time
WiredHome 0:49245357cd1b 273 if (strcmp(pStart, "END:VTIMEZONE") == 0)
WiredHome 0:49245357cd1b 274 seeking = idle;
WiredHome 0:49245357cd1b 275 else if (strncmp(pStart, "TZID", 4) == 0)
WiredHome 0:49245357cd1b 276 tzAdjusted = true;
WiredHome 0:49245357cd1b 277 break;
WiredHome 0:49245357cd1b 278 case inEvent:
WiredHome 0:49245357cd1b 279 // inEvent
WiredHome 0:49245357cd1b 280 if (strcmp(pStart, "END:VEVENT") == 0) {
WiredHome 0:49245357cd1b 281 // Timezone offset
WiredHome 0:49245357cd1b 282 if (!tzAdjusted) {
WiredHome 0:49245357cd1b 283 Event.Start += ntp.getTZO();
WiredHome 0:49245357cd1b 284 Event.End += ntp.getTZO();
WiredHome 0:49245357cd1b 285 }
WiredHome 0:49245357cd1b 286 // Process it
WiredHome 0:49245357cd1b 287 ShowEventInfo(Event);
WiredHome 0:49245357cd1b 288 if (1 || Event.Start >= gridStartTime && Event.Start < gridEndTime
WiredHome 0:49245357cd1b 289 || Event.End >= gridStartTime && Event.End < gridEndTime) {
WiredHome 0:49245357cd1b 290 EventList[EventCount++] = Event;
WiredHome 0:49245357cd1b 291 INFO(" ++++++++++++ Added Event %d", EventCount);
WiredHome 0:49245357cd1b 292 }
WiredHome 0:49245357cd1b 293 seeking = idle;
WiredHome 0:49245357cd1b 294 } else if (strncmp(pStart, "DTSTART:", 8) == 0) {
WiredHome 0:49245357cd1b 295 Event.Start = ParseDateStamp(pStart+8, ntp);
WiredHome 0:49245357cd1b 296 //INFO(" Start: %d\r\n", mktime(&Event.eventStart));
WiredHome 0:49245357cd1b 297 } else if (strncmp(pStart, "DTSTART;", 8) == 0) {
WiredHome 0:49245357cd1b 298 char * p = strrchr(pStart, ':');
WiredHome 0:49245357cd1b 299 if (p) {
WiredHome 0:49245357cd1b 300 Event.Start = ParseDateStamp(p+1, ntp);
WiredHome 0:49245357cd1b 301 //INFO(" Start: %d\r\n", mktime(&Event.eventStart));
WiredHome 0:49245357cd1b 302 }
WiredHome 0:49245357cd1b 303 } else if (strncmp(pStart, "DTEND:", 6) == 0) {
WiredHome 0:49245357cd1b 304 Event.End = ParseDateStamp(pStart+6, ntp);
WiredHome 0:49245357cd1b 305 //INFO(" End: %d\r\n", mktime(&Event.eventEnd));
WiredHome 0:49245357cd1b 306 } else if (strncmp(pStart, "DTEND;", 6) == 0) {
WiredHome 0:49245357cd1b 307 char * p = strrchr(pStart, ':');
WiredHome 0:49245357cd1b 308 if (p) {
WiredHome 0:49245357cd1b 309 Event.End = ParseDateStamp(p+1, ntp);
WiredHome 0:49245357cd1b 310 //INFO(" End: %d\r\n", mktime(&Event.eventEnd));
WiredHome 0:49245357cd1b 311 }
WiredHome 0:49245357cd1b 312 } else if (strncmp(pStart, "SUMMARY:", 8) == 0) {
WiredHome 0:49245357cd1b 313 strncpy(Event.Summary, pStart+8, SUMMARY_CHARS-1);
WiredHome 0:49245357cd1b 314 Event.Summary[SUMMARY_CHARS-1] = '\0';
WiredHome 0:49245357cd1b 315 //INFO(" Summary: %s\r\n", Event.Summary);
WiredHome 0:49245357cd1b 316 } else if (strncmp(pStart, "LOCATION:", 9) == 0) {
WiredHome 0:49245357cd1b 317 strncpy(Event.Location, pStart+9, LOCATION_CHARS-1);
WiredHome 0:49245357cd1b 318 Event.Location[LOCATION_CHARS-1] = '\0';
WiredHome 0:49245357cd1b 319 //INFO(" Location: %s\r\n", Event.Location);
WiredHome 0:49245357cd1b 320 } else if (strncmp(pStart, "PRIORITY:", 9) == 0) {
WiredHome 0:49245357cd1b 321 Event.Priority = *(pStart+9) - '0';
WiredHome 0:49245357cd1b 322 //INFO(" Priority: %d\r\n", Event.Priority);
WiredHome 0:49245357cd1b 323 } else if (strncmp(pStart, "CATEGORIES:", 11) == 0) {
WiredHome 0:49245357cd1b 324 strncpy(Event.Category, pStart+11, CATEGORY_CHARS-1);
WiredHome 0:49245357cd1b 325 Event.Category[CATEGORY_CHARS-1] = '\0';
WiredHome 0:49245357cd1b 326 //INFO(" Category: %s\r\n", Event.Category);
WiredHome 0:49245357cd1b 327 } else if (strncmp(pStart, "RRULE:", 6) == 0) {
WiredHome 0:49245357cd1b 328 //RRULE:FREQ=WEEKLY;UNTIL=20140502T180000;BYDAY=MO,TU,WE,TH,FR
WiredHome 0:49245357cd1b 329 char * p1, *p2;
WiredHome 0:49245357cd1b 330 INFO("%s", pStart);
WiredHome 0:49245357cd1b 331 p1 = pStart + 6; // p1 = FREQ=WEEKLY;UNTIL=20140502T180000;BYDAY=MO,TU,WE,TH,FR
WiredHome 0:49245357cd1b 332 p2 = strchr(p1, ';');
WiredHome 0:49245357cd1b 333 if (p2)
WiredHome 0:49245357cd1b 334 *p2++ = '\0';
WiredHome 0:49245357cd1b 335 while (*p1) {
WiredHome 0:49245357cd1b 336 INFO("%s", p1);
WiredHome 0:49245357cd1b 337 if (strncmp(p1, "FREQ=", 5) == 0) {
WiredHome 0:49245357cd1b 338 INFO("%s", p1);
WiredHome 0:49245357cd1b 339 p1 += 5; // p1 = WEEKLY;UNTIL=20140502T180000;BYDAY=MO,TU,WE,TH,FR
WiredHome 0:49245357cd1b 340 if (strncmp(p1, "WEEKLY", 6) == 0) {
WiredHome 0:49245357cd1b 341 INFO(" %s", p1);
WiredHome 0:49245357cd1b 342 Event.RepeatFreq = rptfWeekly;
WiredHome 0:49245357cd1b 343 p1 += 6;
WiredHome 0:49245357cd1b 344 } else if (strncmp(p1, "DAILY", 5) == 0) {
WiredHome 0:49245357cd1b 345 INFO(" %s", p1);
WiredHome 0:49245357cd1b 346 Event.RepeatFreq = rptfDaily;
WiredHome 0:49245357cd1b 347 p1 += 5;
WiredHome 0:49245357cd1b 348 } else if (strncmp(p1, "MONTHLY", 7) == 0) {
WiredHome 0:49245357cd1b 349 INFO(" %s", p1);
WiredHome 0:49245357cd1b 350 Event.RepeatFreq = rptfMonthly;
WiredHome 0:49245357cd1b 351 p1 += 7;
WiredHome 0:49245357cd1b 352 } else if (strncmp(p1, "YEARLY", 6) == 0) {
WiredHome 0:49245357cd1b 353 INFO(" %s", p1);
WiredHome 0:49245357cd1b 354 Event.RepeatFreq = rptfYearly;
WiredHome 0:49245357cd1b 355 p1 += 7;
WiredHome 0:49245357cd1b 356 }
WiredHome 0:49245357cd1b 357 } else if (strncmp(p1, "INTERVAL=", 9) == 0) { // INTERVAL=2
WiredHome 0:49245357cd1b 358 INFO("%s", p1);
WiredHome 0:49245357cd1b 359 p1 += 9;
WiredHome 0:49245357cd1b 360 Event.Interval = atoi(p1);
WiredHome 0:49245357cd1b 361 } else if (strncmp(p1, "COUNT=", 6) == 0) { // COUNT=12;
WiredHome 0:49245357cd1b 362 INFO("%s", p1);
WiredHome 0:49245357cd1b 363 p1 += 6; // p1 =
WiredHome 0:49245357cd1b 364 Event.Count = atoi(p1);
WiredHome 0:49245357cd1b 365 } else if (strncmp(p1, "UNTIL=", 6) == 0) {
WiredHome 0:49245357cd1b 366 INFO("%s", p1);
WiredHome 0:49245357cd1b 367 p1 += 6; // p1 = 20140502T180000;BYDAY=MO,TU,WE,TH,FR
WiredHome 0:49245357cd1b 368 Event.Until = ParseDateStamp(p1, ntp);
WiredHome 0:49245357cd1b 369 } else if (strncmp(p1, "BYDAY=", 6) == 0) {
WiredHome 0:49245357cd1b 370 INFO("%s", p1);
WiredHome 0:49245357cd1b 371 p1 += 6; // p1 = MO,TU,WE,TH,FR
WiredHome 0:49245357cd1b 372 while (*p1 >= ' ') {
WiredHome 0:49245357cd1b 373 INFO(" %s", p1);
WiredHome 0:49245357cd1b 374 for (int d=0; d<7; d++) {
WiredHome 0:49245357cd1b 375 if (strncmp(p1,RepeatDayAbbrev(d),2) == 0) {
WiredHome 0:49245357cd1b 376 Event.RepeatDays |= (1 << d);
WiredHome 0:49245357cd1b 377 INFO(" %s %02X", RepeatDayAbbrev(d), Event.RepeatDays);
WiredHome 0:49245357cd1b 378 break;
WiredHome 0:49245357cd1b 379 }
WiredHome 0:49245357cd1b 380 }
WiredHome 0:49245357cd1b 381 p1 += 3;
WiredHome 0:49245357cd1b 382 }
WiredHome 0:49245357cd1b 383 INFO(" RepeatDay: %02X", Event.RepeatDays);
WiredHome 0:49245357cd1b 384 }
WiredHome 0:49245357cd1b 385 if (!p2)
WiredHome 0:49245357cd1b 386 break;
WiredHome 0:49245357cd1b 387 p1 = p2;
WiredHome 0:49245357cd1b 388 p2 = strchr(p1, ';');
WiredHome 0:49245357cd1b 389 if (p2)
WiredHome 0:49245357cd1b 390 *p2++ = '\0';
WiredHome 0:49245357cd1b 391 }
WiredHome 0:49245357cd1b 392 }
WiredHome 0:49245357cd1b 393 // End of inEvent
WiredHome 0:49245357cd1b 394 break;
WiredHome 0:49245357cd1b 395 default:
WiredHome 0:49245357cd1b 396 seeking = idle;
WiredHome 0:49245357cd1b 397 break;
WiredHome 0:49245357cd1b 398 }
WiredHome 0:49245357cd1b 399 pStart = pEnd;
WiredHome 0:49245357cd1b 400 } else {
WiredHome 0:49245357cd1b 401 pStart = NULL;
WiredHome 0:49245357cd1b 402 }
WiredHome 0:49245357cd1b 403 } // while
WiredHome 0:49245357cd1b 404 }