1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef IOTVT_ICALENDAR_H
22 #define IOTVT_ICALENDAR_H
24 //Not supported on Arduino due lack of absolute time need to implement iCalendar
27 #include <stdint.h> // for uint8_t typedef
36 #define FREQ_DAILY (1)
37 #define MAX_BYDAY_SIZE (7) //7 days of week
38 #define TM_YEAR_OFFSET (1900) //tm_year field of c-lang tm date-time struct
39 //represents number of years since 1900.
40 #define TM_DST_OFFSET (1) //c-lang tm struct Daylight Saving Time offset.
41 #define TOTAL_HOURS (24) //Total hours in a day.
43 typedef struct IotvtICalRecur IotvtICalRecur_t;
44 typedef struct IotvtICalPeriod IotvtICalPeriod_t;
47 * date-time = date "T" time.
50 * date-value = date-fullyear date-month date-mday
51 * date-fullyear = 4DIGIT
52 * date-month = 2DIGIT ;01-12
53 * date-mday = 2DIGIT ;01-28, 01-29, 01-30, 01-31
54 * ;based on month/year
56 * time = time-hour time-minute time-second [time-utc]
57 * time-hour = 2DIGIT ;00-23
58 * time-minute = 2DIGIT ;00-59
59 * time-second = 2DIGIT ;00-60
60 * ;The "60" value is used to account for "leap" seconds.
63 * 1. Date with Local time
66 typedef struct tm IotvtICalDateTime_t; //c-lang tm date-time struct
69 * Bit mask for weekdays.
77 WEDNESDAY = (0x1 << 3),
78 THURSDAY = (0x1 << 4),
81 } IotvtICalWeekdayBM_t;
84 * Result code for IotvtICalendar.
88 IOTVTICAL_SUCCESS = 0, /**< successfully completed operation. */
89 IOTVTICAL_VALID_ACCESS, /**< access is within allowable time. */
90 IOTVTICAL_INVALID_ACCESS, /**< access is not within allowable time. */
91 IOTVTICAL_INVALID_PARAMETER, /**< invalid method parameter. */
92 IOTVTICAL_INVALID_RRULE, /**< rrule is not well form, missing FREQ. */
93 IOTVTICAL_INVALID_PERIOD, /**< period is not well form, start-datetime is after end-datetime. */
94 IOTVTICAL_ERROR /**< encounter error. */
98 * Grammar for iCalendar data type PERIOD.
100 * period = date-time "/" date-time ; start-time / end-time.
101 * ;The start-time MUST be before the end-time.
104 struct IotvtICalPeriod
106 IotvtICalDateTime_t startDateTime;
107 IotvtICalDateTime_t endDateTime;
111 * Grammar for iCalendar data type RECUR.
113 * recur = "FREQ"=freq *(
114 * ( ";" "UNTIL" "=" enddate ) /
115 * ( ";" "BYDAY" "=" bywdaylist ) /
120 * bywdaylist = weekday/ ( weekday *("," weekday) )
121 * weekday = "SU" / "MO" / "TU" / "WE" / "TH" / "FR" / "SA"
124 * 1."Allow access on every Monday, Wednesday & Friday between 3pm to 5pm"
125 * PERIOD:20150626T150000/20150626T170000
126 * RRULE: FREQ=DAILY; BYDAY=MO, WE, FR
127 * 2."Allow access every Monday, Wednesday & Friday from 3pm to 5pm until
129 * PERIOD:20150626T150000/20150626T170000
130 * RRULE: FREQ=DAILY; UNTIL=20150703; BYDAY=MO, WE, FR
132 struct IotvtICalRecur
135 IotvtICalDateTime_t until;
136 IotvtICalWeekdayBM_t byDay;
140 * This API is used by policy engine to checks if the
141 * request to access resource is within valid time.
143 * @param period string representing period.
144 * @param recur string representing recurrence rule
146 * @return ::IOTVTICAL_VALID_ACCESS, if the request is within valid time period
147 * ::IOTVTICAL_INVALID_ACCESS, if the request is not within valid time period
148 * ::IOTVTICAL_INVALID_PARAMETER, if parameter are invalid
149 * ::IOTVTICAL_INVALID_PERIOD, if period string has invalid format
150 * ::IOTVTICAL_INVALID_RRULE, if rrule string has invalid format.
152 *Eg: if(IOTVTICAL_VALID_ACCESS == IsRequestWithinValidTime(period, recur))
154 * //Access within allowable time
158 * //Access is not within allowable time.
161 IotvtICalResult_t IsRequestWithinValidTime(const char *period, const char *recur);
164 * Parses periodStr and populate struct IotvtICalPeriod_t.
166 * @param periodStr string to be parsed.
167 * @param period IotvtICalPeriod_t struct to be populated.
169 * @return ::IOTVTICAL_VALID_ACCESS, if the request is within valid time period
170 * ::IOTVTICAL_INVALID_PARAMETER, if parameter are invalid
171 * ::IOTVTICAL_INVALID_PERIOD, if period string has invalid format
172 * ::IOTVTICAL_INVALID_SUCCESS, if no error while parsing.
174 IotvtICalResult_t ParsePeriod(const char *periodStr, IotvtICalPeriod_t *period);
177 * Parses recurStr and populate struct IotvtICalRecur_t.
179 * @param recurStr string to be parsed.
180 * @param recur is the IotvtICalPeriod_t struct to be populated.
182 * @return ::IOTVTICAL_VALID_ACCESS, if the request is within valid time period
183 * ::IOTVTICAL_INVALID_PARAMETER, if parameter are invalid
184 * ::IOTVTICAL_INVALID_PERIOD, if period string has invalid format
185 * ::IOTVTICAL_INVALID_RRULE, if rrule string has invalid format.
187 IotvtICalResult_t ParseRecur(const char *recurStr, IotvtICalRecur_t *recur);
193 #endif //IOTVT_ICALENDAR_H