4 * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include "calendar_list.h"
24 #include "cal_internal.h"
25 #include "cal_typedef.h"
26 #include "cal_record.h"
29 #include "cal_vcalendar.h"
30 #include "cal_vcalendar_parse.h"
31 #include "cal_utils.h"
41 char *timezone_tzid; /* TZ(ver1) VTIMEZONE(ver2) */
42 char *datetime_tzid; /* in vevent, vtodo as param: TZID=US-Eastern */
44 int type; /* event, todo */
57 VCAL_RECURRENCE_YEARLY_BYYEARDAY,
58 VCAL_RECURRENCE_YEARLY_BYWEEKLY,
59 VCAL_RECURRENCE_YEARLY_BYMONTH,
60 VCAL_RECURRENCE_YEARLY_BYMONTHDAY,
61 VCAL_RECURRENCE_YEARLY_BYDAY,
62 VCAL_RECURRENCE_MONTHLY_BYMONTHDAY,
63 VCAL_RECURRENCE_MONTHLY_BYDAY,
64 VCAL_RECURRENCE_WEEKLY,
65 VCAL_RECURRENCE_DAILY,
74 VCAL_DATETIME_LENGTH_YYYYMMDD = 8,
75 VCAL_DATETIME_LENGTH_YYYYMMDDTHHMMSS = 15,
76 VCAL_DATETIME_LENGTH_YYYYMMDDTHHMMSSZ = 16,
81 VCAL_COMPONENT_VEVENT,
83 VCAL_COMPONENT_VJOURNAL,
84 VCAL_COMPONENT_VFREEBUSY,
85 VCAL_COMPONENT_VTIMEZONE,
91 VCAL_PROPERTY_VERSION,
99 VCAL_COMPONENT_PROPERTY_NONE,
100 VCAL_COMPONENT_PROPERTY_DTSTAMP,
101 VCAL_COMPONENT_PROPERTY_UID,
102 VCAL_COMPONENT_PROPERTY_RECURRENCE_ID,
103 VCAL_COMPONENT_PROPERTY_DTSTART,
104 VCAL_COMPONENT_PROPERTY_CREATED, /* for ver 2: created */
105 VCAL_COMPONENT_PROPERTY_DCREATED, /* for ver 1: created */
106 VCAL_COMPONENT_PROPERTY_DESCRIPTION,
107 VCAL_COMPONENT_PROPERTY_LAST_MODIFIED,
108 VCAL_COMPONENT_PROPERTY_LOCATION,
109 VCAL_COMPONENT_PROPERTY_PRIORITY,
110 VCAL_COMPONENT_PROPERTY_STATUS,
111 VCAL_COMPONENT_PROPERTY_SUMMARY,
112 VCAL_COMPONENT_PROPERTY_RRULE,
113 VCAL_COMPONENT_PROPERTY_DTEND,
114 VCAL_COMPONENT_PROPERTY_DUE,
115 VCAL_COMPONENT_PROPERTY_ATTENDEE,
116 VCAL_COMPONENT_PROPERTY_CATEGORIES,
117 VCAL_COMPONENT_PROPERTY_DALARM, /* for ver 1: display alarm */
118 VCAL_COMPONENT_PROPERTY_MALARM, /* for ver 1: mail alarm */
119 VCAL_COMPONENT_PROPERTY_AALARM, /* for ver 1: audio alarm */
120 VCAL_COMPONENT_PROPERTY_EXDATE,
121 VCAL_COMPONENT_PROPERTY_X_ALLDAY,
122 VCAL_COMPONENT_PROPERTY_X_LUNAR,
123 VCAL_COMPONENT_PROPERTY_BEGIN,
124 VCAL_COMPONENT_PROPERTY_END,
125 VCAL_COMPONENT_PROPERTY_EXTENDED,
126 VCAL_COMPONENT_PROPERTY_MAX,
130 VCAL_COMPONENT_PROPERTY_VALARM_NONE,
131 VCAL_COMPONENT_PROPERTY_VALARM_ACTION,
132 VCAL_COMPONENT_PROPERTY_VALARM_TRIGGER,
133 VCAL_COMPONENT_PROPERTY_VALARM_REPEAT,
134 VCAL_COMPONENT_PROPERTY_VALARM_ATTACH,
135 VCAL_COMPONENT_PROPERTY_VALARM_DESCRIPTION,
136 VCAL_COMPONENT_PROPERTY_VALARM_SUMMARY,
137 VCAL_COMPONENT_PROPERTY_VALARM_DURATION,
138 VCAL_COMPONENT_PROPERTY_VALARM_END,
139 VCAL_COMPONENT_PROPERTY_VALARM_MAX,
144 VCAL_ENCODING_BASE64,
145 VCAL_ENCODING_QUOTED_PRINTABLE,
153 VCAL_CHARSET_ISO_8859_1,
154 VCAL_CHARSET_UTF_MAX,
158 VCAL_COMPONENT_PROPERTY_VTIMEZONE_NONE,
159 VCAL_COMPONENT_PROPERTY_VTIMEZONE_DTSTART,
160 VCAL_COMPONENT_PROPERTY_VTIMEZONE_TZOFFSETFROM,
161 VCAL_COMPONENT_PROPERTY_VTIMEZONE_TZOFFSETTO,
162 VCAL_COMPONENT_PROPERTY_VTIMEZONE_TZNAME,
163 VCAL_COMPONENT_PROPERTY_VTIMEZONE_RDATE,
164 VCAL_COMPONENT_PROPERTY_VTIMEZONE_END,
165 VCAL_COMPONENT_PROPERTY_VTIMEZONE_MAX,
169 VCAL_VER_10_DALARM_NONE = 0,
170 VCAL_VER_10_DALARM_RUN_TIME,
171 VCAL_VER_10_DALARM_SNOOZE_TIME,
172 VCAL_VER_10_DALARM_REPEAT_COUNT,
173 VCAL_VER_10_DALARM_DISPLAY_STRING,
177 VCAL_VER_10_MALARM_NONE = 0,
178 VCAL_VER_10_MALARM_RUN_TIME,
179 VCAL_VER_10_MALARM_SNOOZE_TIME,
180 VCAL_VER_10_MALARM_REPEAT_COUNT,
181 VCAL_VER_10_MALARM_ADDRESS_STRING,
182 VCAL_VER_10_MALARM_NOTE_STRING,
186 VCAL_VER_10_AALARM_NONE = 0,
187 VCAL_VER_10_AALARM_RUN_TIME,
188 VCAL_VER_10_AALARM_SNOOZE_TIME,
189 VCAL_VER_10_AALARM_REPEAT_COUNT,
190 VCAL_VER_10_AALARM_AUDIO_CONTENT,
193 static const char *vcal_component[VCAL_COMPONENT_MAX] = {0};
194 static void __init_component(void)
196 if (NULL == *vcal_component) {
197 vcal_component[VCAL_COMPONENT_VEVENT] = "VEVENT";
198 vcal_component[VCAL_COMPONENT_VTODO] = "VTODO";
199 vcal_component[VCAL_COMPONENT_VJOURNAL] = "VJOURNAL";
200 vcal_component[VCAL_COMPONENT_VFREEBUSY] = "VFREEBUSY";
201 vcal_component[VCAL_COMPONENT_VTIMEZONE] = "VTIMEZONE";
205 static const char *vcal_property[VCAL_PROPERTY_MAX] = {0};
206 static void __init_property(void)
208 if (NULL == *vcal_property) {
209 vcal_property[VCAL_PROPERTY_VERSION] = "VERSION";
210 vcal_property[VCAL_PROPERTY_TZ] = "TZ";
211 vcal_property[VCAL_PROPERTY_BEGIN] = "BEGIN";
212 vcal_property[VCAL_PROPERTY_END] = "END";
216 static const char *component_property[VCAL_COMPONENT_PROPERTY_MAX] = {0};
217 static void __init_component_property(void)
219 if (NULL == *component_property) {
220 component_property[VCAL_COMPONENT_PROPERTY_DTSTAMP] = "DTSTAMP";
221 component_property[VCAL_COMPONENT_PROPERTY_UID] = "UID";
222 component_property[VCAL_COMPONENT_PROPERTY_RECURRENCE_ID] = "RECURRENCE-ID";
223 component_property[VCAL_COMPONENT_PROPERTY_DTSTART] = "DTSTART";
224 component_property[VCAL_COMPONENT_PROPERTY_CREATED] = "CREATED"; /* for ver 2: created */
225 component_property[VCAL_COMPONENT_PROPERTY_DCREATED] = "DCREATED"; /* for ver 1: created */
226 component_property[VCAL_COMPONENT_PROPERTY_DESCRIPTION] = "DESCRIPTION";
227 component_property[VCAL_COMPONENT_PROPERTY_LAST_MODIFIED] = "LAST-MODIFIED";
228 component_property[VCAL_COMPONENT_PROPERTY_LOCATION] = "LOCATION";
229 component_property[VCAL_COMPONENT_PROPERTY_PRIORITY] = "PRIORITY";
230 component_property[VCAL_COMPONENT_PROPERTY_STATUS] = "STATUS";
231 component_property[VCAL_COMPONENT_PROPERTY_SUMMARY] = "SUMMARY";
232 component_property[VCAL_COMPONENT_PROPERTY_RRULE] = "RRULE";
233 component_property[VCAL_COMPONENT_PROPERTY_DTEND] = "DTEND";
234 component_property[VCAL_COMPONENT_PROPERTY_DUE] = "DUE";
235 component_property[VCAL_COMPONENT_PROPERTY_ATTENDEE] = "ATTENDEE";
236 component_property[VCAL_COMPONENT_PROPERTY_CATEGORIES] = "CATEGORIES";
237 component_property[VCAL_COMPONENT_PROPERTY_DALARM] = "DALARM";
238 component_property[VCAL_COMPONENT_PROPERTY_MALARM] = "MALARM";
239 component_property[VCAL_COMPONENT_PROPERTY_AALARM] = "AALARM";
240 component_property[VCAL_COMPONENT_PROPERTY_EXDATE] = "EXDATE";
241 component_property[VCAL_COMPONENT_PROPERTY_X_ALLDAY] = "X-ALLDAY";
242 component_property[VCAL_COMPONENT_PROPERTY_X_LUNAR] = "X-LUNAR";
243 component_property[VCAL_COMPONENT_PROPERTY_BEGIN] = "BEGIN"; /* start alarm component */
244 component_property[VCAL_COMPONENT_PROPERTY_END] = "END"; /* exit record component */
245 component_property[VCAL_COMPONENT_PROPERTY_EXTENDED] = "X-";
249 static const char *component_property_valarm[VCAL_COMPONENT_PROPERTY_VALARM_MAX] = {0};
250 static void __init_component_property_valarm(void)
252 if (NULL == *component_property_valarm) {
253 component_property_valarm[VCAL_COMPONENT_PROPERTY_VALARM_ACTION] = "ACTION";
254 component_property_valarm[VCAL_COMPONENT_PROPERTY_VALARM_TRIGGER] = "TRIGGER";
255 component_property_valarm[VCAL_COMPONENT_PROPERTY_VALARM_REPEAT] = "REPEAT";
256 component_property_valarm[VCAL_COMPONENT_PROPERTY_VALARM_ATTACH] = "ATTACH";
257 component_property_valarm[VCAL_COMPONENT_PROPERTY_VALARM_DESCRIPTION] = "DESCRIPTION";
258 component_property_valarm[VCAL_COMPONENT_PROPERTY_VALARM_SUMMARY] = "SUMMARY";
259 component_property_valarm[VCAL_COMPONENT_PROPERTY_VALARM_DURATION] = "DURATION";
260 component_property_valarm[VCAL_COMPONENT_PROPERTY_VALARM_END] = "END";
264 static const char *component_property_vtimezone[VCAL_COMPONENT_PROPERTY_VTIMEZONE_MAX] = {0};
265 static void __init_component_property_vtimezone(void)
267 if (NULL == *component_property_vtimezone) {
268 component_property_vtimezone[VCAL_COMPONENT_PROPERTY_VTIMEZONE_DTSTART] = "DTSTART";
269 component_property_vtimezone[VCAL_COMPONENT_PROPERTY_VTIMEZONE_TZOFFSETFROM] = "TZOFFSETFROM";
270 component_property_vtimezone[VCAL_COMPONENT_PROPERTY_VTIMEZONE_TZOFFSETTO] = "TZOFFSETTO";
271 component_property_vtimezone[VCAL_COMPONENT_PROPERTY_VTIMEZONE_TZNAME] = "TZNAME";
272 component_property_vtimezone[VCAL_COMPONENT_PROPERTY_VTIMEZONE_RDATE] = "RDATE";
273 component_property_vtimezone[VCAL_COMPONENT_PROPERTY_VTIMEZONE_END] = "END";
277 static inline void __print_cursor(char *cursor, int line)
281 for (i = 0; i < 5; i++) {
282 if (VCAL_CR == *(cursor + i) || VCAL_LF == *(cursor + i)) break;
283 DBG("[%c]", *(cursor + i));
287 static inline void __free_user_data(struct user_data *ud)
290 if (ud->timezone_tzid) free(ud->timezone_tzid);
291 if (ud->datetime_tzid) free(ud->datetime_tzid);
296 static inline char* __remove_empty_line(char *src)
299 if ('\n' != *src && '\r' != *src)
306 static inline char* __remove_invalid_space(char *src)
325 static inline char* __crlf(char *p)
327 RETV_IF(NULL == p, NULL);
328 while (VCAL_LF != *p) {
337 static bool __check_has_rrule(char *stream)
339 RETV_IF(NULL == stream, false);
342 char *cursor = stream;
344 if (*(cursor++) == VCAL_LF) {
345 if (*(cursor++) == 'R' &&
346 *(cursor++) == 'R' &&
347 *(cursor++) == 'U' &&
348 *(cursor++) == 'L' &&
349 *(cursor++) == 'E' &&
350 *(cursor++) == ':') {
352 } else if (*(cursor-1) == 'E' &&
353 *(cursor++) == 'N' &&
354 *(cursor++) == 'D' &&
355 *(cursor++) == ':' &&
356 *(cursor++) == 'V' &&
357 *(cursor++) == 'E' &&
358 *(cursor++) == 'V' &&
359 *(cursor++) == 'E' &&
360 *(cursor++) == 'N' &&
361 *(cursor++) == 'T') {
369 static int _sub_caltime(struct user_data *ud, calendar_time_s *s, calendar_time_s *a, int *diff)
371 RETV_IF(NULL == s, CALENDAR_ERROR_INVALID_PARAMETER);
372 RETV_IF(NULL == a, CALENDAR_ERROR_INVALID_PARAMETER);
373 RETV_IF(NULL == diff, CALENDAR_ERROR_INVALID_PARAMETER);
375 if (s->type != a->type) {
376 WARN("This is strange. start type(%d) alarm type(%d)", s->type, a->type);
378 if (ud->timezone_tzid)
379 tz = ud->timezone_tzid;
380 else if (ud->datetime_tzid)
381 tz = ud->datetime_tzid;
385 long long int lli = 0;
386 if (CALENDAR_TIME_LOCALTIME == s->type) {
387 lli = cal_time_convert_itol(tz, s->time.date.year, s->time.date.month,
388 s->time.date.mday, s->time.date.hour, s->time.date.minute,
389 s->time.date.second);
390 *diff = lli - a->time.utime;
391 DBG("Convert start localtime with tz[%s] and get(%lld)", tz, lli);
393 lli = cal_time_convert_itol(tz, a->time.date.year, a->time.date.month,
394 a->time.date.mday, a->time.date.hour, a->time.date.minute,
395 a->time.date.second);
396 *diff = s->time.utime - lli;
397 DBG("Convert alarm localtime with tz[%s] and get(%lld)", tz, lli);
399 return CALENDAR_ERROR_NONE;
402 case CALENDAR_TIME_UTIME:
403 *diff = s->time.utime - a->time.utime;
405 case CALENDAR_TIME_LOCALTIME:
406 *diff = cal_time_convert_itol(NULL, s->time.date.year, s->time.date.month,
407 s->time.date.mday, s->time.date.hour, s->time.date.minute, s->time.date.second) -
408 cal_time_convert_itol(NULL, a->time.date.year, a->time.date.month,
409 a->time.date.mday, a->time.date.hour, a->time.date.minute, a->time.date.second);
412 return CALENDAR_ERROR_NONE;
415 static void _get_tick_unit(int t, int *tick, int *unit)
420 if (0 == (t % CALENDAR_ALARM_TIME_UNIT_WEEK)) {
421 *tick = t / CALENDAR_ALARM_TIME_UNIT_WEEK;
422 *unit = CALENDAR_ALARM_TIME_UNIT_WEEK;
423 } else if (0 == (t % CALENDAR_ALARM_TIME_UNIT_DAY)) {
424 *tick = t / CALENDAR_ALARM_TIME_UNIT_DAY;
425 *unit = CALENDAR_ALARM_TIME_UNIT_DAY;
426 } else if (0 == (t % CALENDAR_ALARM_TIME_UNIT_HOUR)) {
427 *tick = t / CALENDAR_ALARM_TIME_UNIT_HOUR;
428 *unit = CALENDAR_ALARM_TIME_UNIT_HOUR;
429 } else if (0 == (t % CALENDAR_ALARM_TIME_UNIT_MINUTE)) {
430 *tick = t / CALENDAR_ALARM_TIME_UNIT_MINUTE;
431 *unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
434 *unit = CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
436 DBG("tick(%d), unit(%d)", *tick, *unit);
439 static char* __get_value(char *cursor, char **value)
441 RETV_IF(NULL == cursor, NULL);
442 RETV_IF(NULL == value, NULL);
444 /* offset: length until ';' or ':' */
446 while (':' != *(cursor + offset) && ';' != *(cursor + offset))
450 while (VCAL_LF != *(cursor + offset + i)) {
451 if ('\0' == *(cursor + offset + i))
457 char *p = calloc(i + 1, sizeof(char));
458 RETVM_IF(NULL == p, NULL, "calloc() Fail");
460 if (VCAL_CR == *(cursor + offset + i -1))
461 memcpy(p, cursor + offset, i -1);
463 memcpy(p, cursor + offset, i);
466 DBG("offset(%d) len(%d) value[%s]", offset, i, *value);
468 return cursor + offset + i +1;
471 static char* __check_word(char *src, const char *word)
473 RETV_IF(NULL == src, NULL);
475 src = __remove_empty_line(src);
476 src = __remove_invalid_space(src);
478 while (*src == *word) {
482 if ('\0' == *src || '\0' == *word)
493 * Change '-' to '/' as icu format to be recognized in icu library.
494 * ig. US-Easten -> US/Eastern
496 static inline void __adjust_tzid(char *p)
500 DBG("Before [%s]", p);
503 if ('-' == *(p +i)) {
504 if ('1' <= *(p +i +1) && *(p +i +1) <= '9')
511 DBG("After [%s]", p);
514 static void __unfolding(char *p)
523 if (VCAL_LF == *(p +1) && ' ' == *(p +2)) /* ver1.0:out of spec, but allowed exceptional case */
525 else if (VCAL_CR == *(p +1) && VCAL_LF == *(p +2) && ' ' == *(p +3)) /* ver1.0:in spec case */
527 else if (VCAL_CR == *(p +1) && VCAL_LF == *(p +2)) /* galaxy wants this format */
533 if (' ' == *(p + 1)) /* ver2.0:out of spec, but allowed exceptional case */
535 else if ('\t' == *(p + 1)) /* ver2.0:out of spec, but allowed exceptional case */
541 if ('\n' == *(p + 1) && ' ' == *(p + 2)) /* ver2.0:in spec case */
543 else if ('\n' == *(p + 1) && '\t' == *(p + 2)) /* ver2.0:out of spec, but allowed exceptional case */
555 static void __decode_escaped_char(char *p)
562 if ('\\' == *p && *(p +1)) {
591 static void __decode_base64(char *p)
596 DBG("Before [%s]", p);
599 buf = g_base64_decode(p, &size);
604 if (strlen(p) < size) {
609 snprintf(p, size + 1, "%s%c", buf, '\0');
611 DBG("After [%s]", p);
614 static char __decode_hexa(char *p)
617 char decoded[2] = {0x00, 0x00};
619 for (i = 0; i < 2; i++) {
622 decoded[i] = p[i] - '0';
625 decoded[i] = p[i] - 'a' + 10;
628 decoded[i] = p[i] - 'A' + 10;
632 return (char)((decoded[0] << 4) + decoded[1]);
635 static void __decode_quoted_printable(char *p)
643 DBG("Before[%s]", p);
646 if (p[i+1] == 0x09 || p[i+1] == 0x20) {
648 } else if (p[i+1] == '\r' || p[i+1] == '\n') {
651 if (p[i+1] == '0' && tolower(p[i+2]) == 'd' &&
652 p[i+3] == '=' && p[i+4] == '0' && tolower(p[i+5]) == 'a') {
657 ch = __decode_hexa(p +i +1);
673 static char* __decode_iso8859_1_to_utf8(char *p)
675 RETV_IF(NULL == p, NULL);
680 DBG("Before [%s]", p);
685 out_p = realloc(p, len);
687 ERR("realloc() Fail");
691 /* check enough space */
692 for (src = dst = out_p; *src; src++, dst++) {
699 *dst-- = 0x80 | (*src & 0x3f);
700 *dst-- = 0xc0 | (*((unsigned char *)src--) >> 6);
705 DBG("After [%s]", out_p);
709 static char* __decode_charset(char *p)
712 t = g_strsplit(p, ":", 2);
713 RETVM_IF(NULL == t, NULL, "g_strsplit() Fail");
715 if ('\0' == *t[0]) { /* no param */
717 return cal_strdup(p + 1);
721 s = g_strsplit(t[0], ";", -1);
723 ERR("g_strsplit() Fail");
727 int count_param = g_strv_length(s);
728 DBG("count_param(%d)", count_param);
730 int charset = VCAL_CHARSET_NONE;
731 int encoding = VCAL_ENCODING_NONE;
734 for (i = 0; i < count_param; i++) {
735 if (NULL == s[i] || '\0' == *s[i])
738 if (CAL_STRING_EQUAL == strncmp(s[i], "CHARSET=", strlen("CHARSET="))) {
739 int key_len = strlen("CHARSET=");
740 if (CAL_STRING_EQUAL == strcmp(s[i] + key_len, "UTF-8"))
741 charset = VCAL_CHARSET_UTF_8;
742 else if (CAL_STRING_EQUAL == strcmp(s[i] + key_len, "ISO-8859-1"))
743 charset = VCAL_CHARSET_ISO_8859_1;
745 WARN("Not support charset[%s]", s[i] + key_len);
746 } else if (CAL_STRING_EQUAL == strncmp(s[i], "ENCODING=", strlen("ENCODING="))) {
747 int key_len = strlen("ENCODING=");
748 if (CAL_STRING_EQUAL == strcmp(s[i] + key_len, "BASE64"))
749 encoding = VCAL_ENCODING_BASE64;
750 else if (CAL_STRING_EQUAL == strcmp(s[i] + key_len, "QUOTED-PRINTABLE"))
751 encoding = VCAL_ENCODING_QUOTED_PRINTABLE;
753 WARN("Not support encoding[%s]", s[i] + key_len);
761 char *ret_str = strdup(t[1]);
765 case VCAL_ENCODING_BASE64:
766 __decode_base64(ret_str);
768 case VCAL_ENCODING_QUOTED_PRINTABLE:
769 __decode_quoted_printable(ret_str);
774 case VCAL_CHARSET_UTF_8:
776 case VCAL_CHARSET_ISO_8859_1:
777 ret_str = __decode_iso8859_1_to_utf8(ret_str);
784 static char* __decode_datetime(char *p, struct user_data *ud)
787 t = g_strsplit(p, ":", -1);
788 RETVM_IF(NULL == t, NULL, "g_strsplit() Fail");
790 if ('\0' == *t[0]) { /* no param */
794 int count = g_strv_length(t);
795 int len_param = strlen(t[count -1]);
796 *(p + strlen(p) - len_param -1) = '\0';
801 s = g_strsplit(p, ";", -1);
802 RETVM_IF(NULL == s, p + strlen(p) - len_param, "g_strsplit() Fail");
804 int count_param = g_strv_length(s);
805 DBG("count_param(%d)", count_param);
807 for (i = 0; i < count_param; i++) {
808 if (NULL == s[i] || '\0' == *s[i])
811 if (CAL_STRING_EQUAL != strncmp(s[i], "TZID=", strlen("TZID=")))
814 if (ud->datetime_tzid)
818 tzid = strdup(s[i] + strlen("TZID="));
820 ERR("strdup() Fail");
824 DBG("modified tzid[%s]", tzid);
826 if (true == cal_time_is_available_tzid(tzid)) {
828 ud->datetime_tzid = tzid;
833 if (ud->timezone_tzid && *ud->timezone_tzid) {
834 ud->datetime_tzid = strdup(ud->timezone_tzid);
835 if (NULL == ud->datetime_tzid) {
836 ERR("strdup() Fail");
839 DBG("set datetime_tzid[%s] as timezone_tzid", ud->datetime_tzid);
848 DBG("(%d) (%d) [%s]", strlen(p), len_param, p + strlen(p) +1);
849 return p + strlen(p) +1;
852 static void __decode_duration(char *cursor, int len, int *tick, int *unit)
854 RET_IF(NULL == cursor);
855 RET_IF('\0' == *cursor);
856 RET_IF(NULL == tick);
857 RET_IF(NULL == unit);
864 for (i = 0; i < len; i++) {
865 switch (*(cursor + i)) {
888 u = CALENDAR_ALARM_TIME_UNIT_WEEK;
889 snprintf(buf, digit + 1, "%s", cursor + i - digit);
891 DBG("[%s] (%d)", buf, t);
895 u = CALENDAR_ALARM_TIME_UNIT_DAY;
896 snprintf(buf, digit + 1, "%s", cursor + i - digit);
898 DBG("[%s] (%d)", buf, t);
902 u = CALENDAR_ALARM_TIME_UNIT_HOUR;
903 snprintf(buf, digit + 1, "%s", cursor + i - digit);
905 DBG("[%s] (%d)", buf, t);
909 u = CALENDAR_ALARM_TIME_UNIT_MINUTE;
910 snprintf(buf, digit + 1, "%s", cursor + i - digit);
912 DBG("[%s] (%d)", buf, t);
916 u = CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
917 snprintf(buf, digit + 1, "%s", cursor + i - digit);
919 DBG("[%s] (%d)", buf, t);
923 ERR("Invalid value");
929 _get_tick_unit(t, tick, unit);
932 static bool __is_digit(char *p)
935 if ((*p < '0' || '9' < *p) && '+' != *p && '-' != *p)
942 static char* __get_index(char *cursor, const char **array, int len, int *index)
944 RETV_IF(NULL == index, NULL);
948 for (i = 1; i < len; i++) {
949 new = __check_word(cursor, array[i]);
958 DBG("index(%d) [%s]", i, array[i]);
959 return cursor + strlen(array[i]);
962 static void __get_version(char *value, int *version)
966 RET_IF(NULL == value);
967 RET_IF(NULL == version);
969 if (CAL_STRING_EQUAL == strncmp(value, ":1.0", strlen(":1.0")))
974 DBG("version(%d)", *version);
977 static int _get_caltime(char *p, calendar_time_s *caltime, struct user_data *ud)
979 RETV_IF(NULL == p, CALENDAR_ERROR_INVALID_PARAMETER);
980 RETV_IF('\0' == *p, CALENDAR_ERROR_INVALID_PARAMETER);
981 RETV_IF(NULL == caltime, CALENDAR_ERROR_INVALID_PARAMETER);
982 RETV_IF(NULL == ud, CALENDAR_ERROR_INVALID_PARAMETER);
984 int ret = CALENDAR_ERROR_NONE;
987 case VCAL_DATETIME_LENGTH_YYYYMMDD:
988 caltime->type = CALENDAR_TIME_LOCALTIME;
989 sscanf(p, CAL_DATETIME_FORMAT_YYYYMMDD,
990 &(caltime->time.date.year), &(caltime->time.date.month), &(caltime->time.date.mday));
991 caltime->time.date.hour = 0;
992 caltime->time.date.minute = 0;
993 caltime->time.date.second = 0;
994 DBG(CAL_DATETIME_FORMAT_YYYYMMDDTHHMMSS,
995 caltime->time.date.year, caltime->time.date.month, caltime->time.date.mday,
996 caltime->time.date.hour, caltime->time.date.minute, caltime->time.date.second);
998 case VCAL_DATETIME_LENGTH_YYYYMMDDTHHMMSS:
999 sscanf(p, CAL_DATETIME_FORMAT_YYYYMMDDTHHMMSS,
1000 &(caltime->time.date.year), &(caltime->time.date.month), &(caltime->time.date.mday),
1001 &(caltime->time.date.hour), &(caltime->time.date.minute), &(caltime->time.date.second));
1003 if (VCAL_VER_1 == ud->version) {
1004 caltime->type = CALENDAR_TIME_LOCALTIME;
1006 if (NULL == ud->datetime_tzid || '\0' == *ud->datetime_tzid) {
1007 if (NULL == ud->timezone_tzid || '\0' == *ud->timezone_tzid) {
1008 /* Without tzid is localtime */
1009 caltime->type = CALENDAR_TIME_LOCALTIME;
1010 DBG(CAL_DATETIME_FORMAT_YYYYMMDDTHHMMSS,
1011 caltime->time.date.year, caltime->time.date.month, caltime->time.date.mday,
1012 caltime->time.date.hour, caltime->time.date.minute, caltime->time.date.second);
1014 /* No 'Z' with tzid means utime */
1015 caltime->type = CALENDAR_TIME_UTIME;
1016 caltime->time.utime = cal_time_convert_itol(ud->timezone_tzid,
1017 caltime->time.date.year, caltime->time.date.month, caltime->time.date.mday,
1018 caltime->time.date.hour, caltime->time.date.minute, caltime->time.date.second);
1019 DBG("timezone_tzid[%s] (%lld)", ud->timezone_tzid, caltime->time.utime);
1022 /* No 'Z' with tzid means utime */
1023 caltime->type = CALENDAR_TIME_UTIME;
1024 caltime->time.utime = cal_time_convert_itol(ud->datetime_tzid,
1025 caltime->time.date.year, caltime->time.date.month, caltime->time.date.mday,
1026 caltime->time.date.hour, caltime->time.date.minute, caltime->time.date.second);
1027 DBG("datetime_tzid[%s] (%lld)", ud->datetime_tzid, caltime->time.utime);
1031 case VCAL_DATETIME_LENGTH_YYYYMMDDTHHMMSSZ:
1032 if (ud->is_allday) {
1033 caltime->type = CALENDAR_TIME_LOCALTIME;
1034 sscanf(p, CAL_DATETIME_FORMAT_YYYYMMDDTHHMMSSZ,
1035 &(caltime->time.date.year), &(caltime->time.date.month), &(caltime->time.date.mday),
1036 &(caltime->time.date.hour), &(caltime->time.date.minute), &(caltime->time.date.second));
1037 caltime->time.date.hour = 0;
1038 caltime->time.date.minute = 0;
1039 caltime->time.date.second = 0;
1040 DBG(CAL_DATETIME_FORMAT_YYYYMMDDTHHMMSS,
1041 caltime->time.date.year, caltime->time.date.month, caltime->time.date.mday,
1042 caltime->time.date.hour, caltime->time.date.minute, caltime->time.date.second);
1044 caltime->type = CALENDAR_TIME_UTIME;
1045 caltime->time.utime = cal_time_convert_lli(p);
1046 DBG("(%lld)", caltime->time.utime);
1050 ERR("Invalid time format[%s]", p);
1051 ret = CALENDAR_ERROR_INVALID_PARAMETER;
1064 static void __parse_tz(const char *tz, int *h, int *m)
1068 char **t = g_strsplit(tz, ":", -1);
1069 RETM_IF(NULL == t, "g_strsplit() is NULL");
1074 else if ('+' == *t[0])
1079 if (0 == strlen(t[0])) {
1087 snprintf(buf, strlen(t[0]), "%s", t[0] + 1);
1090 snprintf(buf, strlen(t[0]) + 1, "%s", t[0]);
1092 if (h) *h = sign * atoi(buf);
1094 if (1 == g_strv_length(t)) {
1100 snprintf(buf, strlen(t[1]) + 1, "%s", t[1]);
1101 if (m) *m = atoi(buf);
1106 static void __get_tz(char *value, char **tz)
1108 RET_IF(NULL == value);
1112 __parse_tz(value +1, &h, &m); /* +1 to skip ':' */
1114 char buf[CAL_STR_SHORT_LEN32] = {0};
1116 snprintf(buf, sizeof(buf), "Etc/GMT%c%d", h < 0 ? '+' : '-', h);
1118 cal_time_get_registered_tzid_with_offset(h * 3600 + m * 60, buf, sizeof(buf));
1120 DBG("set tzid [%s]", buf);
1125 static void __work_component_property_dtstamp(char *value, calendar_record_h record, struct user_data *ud)
1130 static void __work_component_property_uid(char *value, calendar_record_h record, struct user_data *ud)
1132 RET_IF(NULL == value);
1133 RET_IF('\0' == *value);
1134 RET_IF(NULL == record);
1138 char *s = __decode_charset(value);
1139 __decode_escaped_char(s);
1141 case CALENDAR_BOOK_TYPE_EVENT:
1142 ret = cal_record_set_str(record, _calendar_event.uid, s);
1143 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1145 case CALENDAR_BOOK_TYPE_TODO:
1146 ret = cal_record_set_str(record, _calendar_todo.uid, s);
1147 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1153 static void __work_component_property_recurrence_id(char *value, calendar_record_h record, struct user_data *ud)
1155 RET_IF(NULL == value);
1156 RET_IF('\0' == *value);
1157 RET_IF(NULL == record);
1162 case CALENDAR_BOOK_TYPE_EVENT:
1163 ret = cal_record_set_str(record, _calendar_event.recurrence_id, value +1);
1164 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1166 case CALENDAR_BOOK_TYPE_TODO:
1167 DBG("Not supported in todo");
1172 static void __work_component_property_dtstart(char *value, calendar_record_h record, struct user_data *ud)
1174 RET_IF(NULL == value);
1175 RET_IF('\0' == *value);
1176 RET_IF(NULL == record);
1181 value = __decode_datetime(value, ud);
1182 calendar_time_s dtstart = {0};
1183 ret = _get_caltime(value, &dtstart, ud);
1184 if (CALENDAR_ERROR_NONE != ret) {
1185 ERR("_get_caltime() Fail(%d)", ret);
1190 tzid = ud->datetime_tzid ? ud->datetime_tzid : (ud->timezone_tzid ? ud->timezone_tzid : NULL);
1193 case CALENDAR_BOOK_TYPE_EVENT:
1194 if (tzid && *tzid) {
1195 ret = cal_record_set_str(record, _calendar_event.start_tzid, tzid);
1196 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1198 ret = cal_record_set_caltime(record, _calendar_event.start_time, dtstart);
1199 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail(%d)", ret);
1201 case CALENDAR_BOOK_TYPE_TODO:
1202 if (tzid && *tzid) {
1203 ret = cal_record_set_str(record, _calendar_todo.start_tzid, tzid);
1204 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1206 ret = cal_record_set_caltime(record, _calendar_todo.start_time, dtstart);
1207 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail(%d)", ret);
1211 /* check if dtend is earlier than dtstart. */
1212 if (CALENDAR_BOOK_TYPE_TODO == ud->type) /* skip in todo */
1215 calendar_time_s dtend = {0};
1216 ret = calendar_record_get_caltime(record, _calendar_event.end_time, &dtend);
1217 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Fail(%d)", ret);
1219 if (0 == dtend.time.utime) /* not set yet */
1223 _sub_caltime(ud, &dtstart, &dtend, &diff);
1224 if (diff <= 0) /* proper data */
1227 WARN("dtend < dtstart so set end time to start");
1231 static void __work_component_property_created(char *value, calendar_record_h record, struct user_data *ud)
1233 RET_IF(NULL == value);
1234 RET_IF('\0' == *value);
1235 RET_IF(NULL == record);
1240 case CALENDAR_BOOK_TYPE_EVENT:
1241 ret = cal_record_set_lli(record, _calendar_event.created_time, cal_time_convert_lli(value));
1242 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_lli() Fail(%d)", ret);
1245 case CALENDAR_BOOK_TYPE_TODO:
1246 ret = cal_record_set_lli(record, _calendar_todo.created_time, cal_time_convert_lli(value));
1247 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_lli() Fail(%d)", ret);
1252 static void __work_component_property_description(char *value, calendar_record_h record, struct user_data *ud)
1254 RET_IF(NULL == value);
1255 RET_IF('\0' == *value);
1256 RET_IF(NULL == record);
1260 char *s = __decode_charset(value);
1261 __decode_escaped_char(s);
1263 case CALENDAR_BOOK_TYPE_EVENT:
1264 ret = cal_record_set_str(record, _calendar_event.description, s);
1265 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1267 case CALENDAR_BOOK_TYPE_TODO:
1268 ret = cal_record_set_str(record, _calendar_todo.description, s);
1269 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1275 static void __work_component_property_last_modified(char *value, calendar_record_h record, struct user_data *ud)
1277 RET_IF(NULL == value);
1278 RET_IF('\0' == *value);
1279 RET_IF(NULL == record);
1284 case CALENDAR_BOOK_TYPE_EVENT:
1285 ret = cal_record_set_lli(record, _calendar_event.last_modified_time, cal_time_convert_lli(value));
1286 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_lli() Fail(%d)", ret);
1288 case CALENDAR_BOOK_TYPE_TODO:
1289 ret = cal_record_set_lli(record, _calendar_todo.last_modified_time, cal_time_convert_lli(value));
1290 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_lli() Fail(%d)", ret);
1295 static void __work_component_property_location(char *value, calendar_record_h record, struct user_data *ud)
1297 RET_IF(NULL == value);
1298 RET_IF('\0' == *value);
1299 RET_IF(NULL == record);
1303 char *s = __decode_charset(value);
1304 __decode_escaped_char(s);
1306 case CALENDAR_BOOK_TYPE_EVENT:
1307 ret = cal_record_set_str(record, _calendar_event.location, s);
1308 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1310 case CALENDAR_BOOK_TYPE_TODO:
1311 ret = cal_record_set_str(record, _calendar_todo.location, s);
1312 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1318 static int __decode_priority(char *value, struct user_data *ud)
1320 int original_priority = atoi(value);
1321 int modified_priority = 0;
1323 switch (ud->version) {
1325 switch (original_priority) {
1327 modified_priority = CALENDAR_TODO_PRIORITY_LOW;
1330 modified_priority = CALENDAR_TODO_PRIORITY_NORMAL;
1333 modified_priority = CALENDAR_TODO_PRIORITY_HIGH;
1336 DBG("Unable to parse [%s]", value);
1337 modified_priority = CALENDAR_TODO_PRIORITY_NONE;
1344 switch (original_priority) {
1346 modified_priority = CALENDAR_TODO_PRIORITY_HIGH;
1349 modified_priority = CALENDAR_TODO_PRIORITY_NORMAL;
1352 modified_priority = CALENDAR_TODO_PRIORITY_LOW;
1355 DBG("Unable to parse [%s]", value);
1356 modified_priority = CALENDAR_TODO_PRIORITY_NONE;
1361 DBG("convert priority(%d) -> (%d)", original_priority, modified_priority);
1362 return modified_priority;
1365 static void __work_component_property_priority(char *value, calendar_record_h record, struct user_data *ud)
1367 RET_IF(NULL == value);
1368 RET_IF('\0' == *value);
1369 RET_IF(NULL == record);
1371 RETM_IF(*value < '0' || '9' < *value, "out of range[%s]", value);
1374 int modified_priority = __decode_priority(value, ud);
1376 case CALENDAR_BOOK_TYPE_EVENT:
1377 ret = cal_record_set_int(record, _calendar_event.priority, modified_priority);
1378 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1380 case CALENDAR_BOOK_TYPE_TODO:
1381 ret = cal_record_set_int(record, _calendar_todo.priority, modified_priority);
1382 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1387 static void __work_component_property_status(char *value, calendar_record_h record, struct user_data *ud)
1389 RET_IF(NULL == value);
1390 RET_IF('\0' == *value);
1391 RET_IF(NULL == record);
1397 case CALENDAR_BOOK_TYPE_EVENT:
1398 if (CAL_STRING_EQUAL == strncmp(value, ":TENTATIVE", strlen(":TENTATIVE")))
1399 status = CALENDAR_EVENT_STATUS_TENTATIVE;
1400 else if (CAL_STRING_EQUAL == strncmp(value, ":CONFIRMED", strlen(":CONFIRMED")))
1401 status = CALENDAR_EVENT_STATUS_CONFIRMED;
1402 else if (CAL_STRING_EQUAL == strncmp(value, ":CANCELLED", strlen(":CANCELLED")))
1403 status = CALENDAR_EVENT_STATUS_CANCELLED;
1405 status = CALENDAR_EVENT_STATUS_NONE;
1407 ret = cal_record_set_int(record, _calendar_event.event_status, status);
1408 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1410 case CALENDAR_BOOK_TYPE_TODO:
1411 if (CAL_STRING_EQUAL == strncmp(value, ":NEEDS-ACTION", strlen(":NEEDS-ACTION")))
1412 status = CALENDAR_TODO_STATUS_NEEDS_ACTION;
1413 else if (CAL_STRING_EQUAL == strncmp(value, ":NEEDS ACTION", strlen(":NEEDS ACTION")))
1414 status = CALENDAR_TODO_STATUS_NEEDS_ACTION;
1415 else if (CAL_STRING_EQUAL == strncmp(value, ":COMPLETED", strlen(":COMPLETED")))
1416 status = CALENDAR_TODO_STATUS_COMPLETED;
1417 else if (CAL_STRING_EQUAL == strncmp(value, ":IN-PROCESS", strlen(":IN-PROCESS")))
1418 status = CALENDAR_TODO_STATUS_IN_PROCESS;
1419 else if (CAL_STRING_EQUAL == strncmp(value, ":CANCELLED", strlen(":CANCELLED")))
1420 status = CALENDAR_TODO_STATUS_CANCELED;
1422 status = CALENDAR_TODO_STATUS_NONE;
1424 ret = cal_record_set_int(record, _calendar_todo.todo_status, status);
1425 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1430 static void __work_component_property_summary(char *value, calendar_record_h record, struct user_data *ud)
1432 RET_IF(NULL == value);
1433 RET_IF('\0' == *value);
1434 RET_IF(NULL == record);
1438 char *s = __decode_charset(value);
1439 __decode_escaped_char(s);
1441 case CALENDAR_BOOK_TYPE_EVENT:
1442 ret = cal_record_set_str(record, _calendar_event.summary, s);
1443 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1445 case CALENDAR_BOOK_TYPE_TODO:
1446 ret = cal_record_set_str(record, _calendar_todo.summary, s);
1447 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1453 static bool __is_wday_string(char *p)
1455 RETV_IF(NULL == p, false);
1456 RETV_IF('0' == *p, false);
1458 if ('S' == *p && 'U' == *(p +1))
1460 else if ('M' == *p && 'O' == *(p +1))
1462 else if ('T' == *p && 'U' == *(p +1))
1464 else if ('W' == *p && 'E' == *(p +1))
1466 else if ('T' == *p && 'H' == *(p +1))
1468 else if ('F' == *p && 'R' == *(p +1))
1470 else if ('S' == *p && 'A' == *(p +1))
1477 static int __get_frequency(char *p)
1479 if ('Y' == *p && 'M' == *(p +1))
1480 return VCAL_RECURRENCE_YEARLY_BYMONTH;
1481 else if ('Y' == *p && 'D' == *(p +1))
1482 return VCAL_RECURRENCE_YEARLY_BYYEARDAY;
1483 else if ('M' == *p && 'P' == *(p +1))
1484 return VCAL_RECURRENCE_MONTHLY_BYDAY;
1485 else if ('M' == *p && 'D' == *(p +1))
1486 return VCAL_RECURRENCE_MONTHLY_BYMONTHDAY;
1487 else if ('W' == *p && 'E' != *(p +1)) /* check 'E' for WE(Wednesday) */
1488 return VCAL_RECURRENCE_WEEKLY;
1490 return VCAL_RECURRENCE_DAILY;
1492 return VCAL_RECURRENCE_NONE;
1495 static void __set_bystr(int freq_mode, calendar_record_h record, char *bystr)
1497 RET_IF(NULL == record);
1498 RET_IF(NULL == bystr);
1499 RET_IF('\0' == *bystr);
1501 DBG("bystr[%s]", bystr);
1502 bystr[strlen(bystr) -1] = '\0'; /* to remove ',' */
1504 switch (freq_mode) {
1505 case VCAL_RECURRENCE_YEARLY_BYMONTH:
1506 ret = cal_record_set_str(record, _calendar_event.bymonth, bystr);
1507 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1509 case VCAL_RECURRENCE_YEARLY_BYYEARDAY:
1510 ret = cal_record_set_str(record, _calendar_event.byyearday, bystr);
1511 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1513 case VCAL_RECURRENCE_MONTHLY_BYMONTHDAY:
1514 ret = cal_record_set_str(record, _calendar_event.bymonthday, bystr);
1515 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1517 case VCAL_RECURRENCE_MONTHLY_BYDAY:
1518 ret = cal_record_set_str(record, _calendar_event.byday, bystr);
1519 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1521 case VCAL_RECURRENCE_WEEKLY:
1522 ret = cal_record_set_str(record, _calendar_event.byday, bystr);
1523 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1525 case VCAL_RECURRENCE_DAILY:
1531 * Yearly |bymonth |YM1 6 7 #10
1532 * |YM1 1 6 12 #5 MP1 1+ MO 1- FR
1533 * Yearly |byyearday |YD3 1 100 200 #10
1534 * Monthly|byposition|MP2 1+ SU 1- SU #10
1535 * Monthly|byday |MD1 1 1- #10
1536 * Weekly | |W2 MO WE FR 19941224T000000Z
1539 static void __work_component_property_rrule_ver_1(char *value, calendar_record_h record, struct user_data *ud)
1543 RET_IF(NULL == value);
1544 RET_IF('\0' == *value);
1545 RET_IF(NULL == record);
1550 t = g_strsplit_set(value, ": ", -1);
1551 RETM_IF(NULL == t, "g_strsplit_set() Fail");
1554 int len = g_strv_length(t);
1558 bool has_by = false;
1560 char bystr[CAL_STR_MIDDLE_LEN] = {0};
1567 for (i = 0; i < len; i++) {
1568 if (NULL == t[i] || '\0' == *t[i])
1573 if (true == __is_wday_string(t[i])) {
1577 for (j = 0; j < week_index; j++)
1578 len_str += snprintf(bystr + len_str, sizeof(bystr) - len_str, "%d%s,", week[j], t[i]);
1581 len_str += snprintf(bystr + len_str, sizeof(bystr) - len_str, "%s,", t[i]);
1583 DBG("[%s] week_index(%d)", bystr, week_index);
1584 } else if ('L' == *t[i] && 'D' == *(t[i] +1)) { /* last day */
1586 len_str += snprintf(bystr + len_str, sizeof(bystr) - len_str, "%s,", "-1");
1588 } else if ('W' == *t[i] && 'K' == *(t[i] +1) && 'S' == *(t[i] +2) && 'T' == *(t[i] +3)) { /* +4 is '=' */
1589 if ('S' == *(t[i] +5) && 'U' == *(t[i] +6))
1590 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_SUNDAY);
1591 else if ('M' == *(t[i] +5))
1592 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_MONDAY);
1593 else if ('T' == *(t[i] +5) && 'U' == *(t[i] +6))
1594 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_TUESDAY);
1595 else if ('W' == *(t[i] +5))
1596 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_WEDNESDAY);
1597 else if ('T' == *(t[i] +5) && 'H' == *(t[i] +6))
1598 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_THURSDAY);
1599 else if ('F' == *(t[i] +5))
1600 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_FRIDAY);
1601 else if ('S' == *(t[i] +5) && 'A' == *(t[i] +6))
1602 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_SATURDAY);
1604 ERR("Invalid parameter[%s]", t[i]);
1606 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1607 } else if (true == __is_digit(t[i])) {
1610 bool exit_loop = false;
1613 switch (freq_mode) {
1614 case VCAL_RECURRENCE_MONTHLY_BYDAY:
1615 case VCAL_RECURRENCE_WEEKLY:
1619 while (*(t[i] +j)) {
1620 switch (*(t[i] +j)) {
1632 if (true == exit_loop) break;
1635 snprintf(buf, j +1, "%s", t[i]);
1636 week[week_index] = atoi(buf) * sign;
1641 while (*(t[i] +j)) {
1642 switch (*(t[i] +j)) {
1654 if (true == exit_loop) break;
1657 snprintf(buf, j +1, "%s", t[i]);
1658 len_str += snprintf(bystr + len_str, sizeof(bystr) - len_str, "%d,", (atoi(buf) * sign));
1662 if (true == has_by) {
1663 __set_bystr(freq_mode, record, bystr);
1665 memset(bystr, 0x0, strlen(bystr));
1669 if (VCAL_RECURRENCE_NONE != (freq_mode = __get_frequency(t[i]))) {
1670 if (0 == frequency) {
1672 switch (freq_mode) {
1673 case VCAL_RECURRENCE_YEARLY_BYMONTH:
1674 frequency = CALENDAR_RECURRENCE_YEARLY;
1675 interval = ('\0' == *(t[i] +2)) ? 1 : atoi(t[i] +2);
1677 case VCAL_RECURRENCE_YEARLY_BYYEARDAY:
1678 frequency = CALENDAR_RECURRENCE_YEARLY;
1679 interval = ('\0' == *(t[i] +2)) ? 1 : atoi(t[i] +2);
1681 case VCAL_RECURRENCE_MONTHLY_BYDAY:
1682 frequency = CALENDAR_RECURRENCE_MONTHLY;
1683 interval = ('\0' == *(t[i] +2)) ? 1 : atoi(t[i] +2);
1685 case VCAL_RECURRENCE_MONTHLY_BYMONTHDAY:
1686 frequency = CALENDAR_RECURRENCE_MONTHLY;
1687 interval = ('\0' == *(t[i] +2)) ? 1 : atoi(t[i] +2);
1689 case VCAL_RECURRENCE_WEEKLY:
1690 frequency = CALENDAR_RECURRENCE_WEEKLY;
1691 interval = ('\0' == *(t[i] +1)) ? 1 : atoi(t[i] +1);
1693 case VCAL_RECURRENCE_DAILY:
1694 frequency = CALENDAR_RECURRENCE_DAILY;
1695 interval = ('\0' == *(t[i] +1)) ? 1 : atoi(t[i] +1);
1698 ret = cal_record_set_int(record, _calendar_event.freq, frequency);
1699 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1700 ret = cal_record_set_int(record, _calendar_event.interval, interval);
1701 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1702 DBG("frequency[%d] interval(%d)", frequency, interval);
1705 if ('0' <= *t[i] && *t[i] <= '9' && strlen("YYYYMMDDTHHMMSS") <= strlen(t[i])) {
1707 calendar_time_s caltime = {0};
1708 _get_caltime(t[i], &caltime, ud);
1709 ret = cal_record_set_int(record, _calendar_event.range_type, CALENDAR_RANGE_UNTIL);
1710 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1711 ret = cal_record_set_caltime(record, _calendar_event.until_time, caltime);
1712 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail(%d)", ret);
1714 } else if ('#' == *t[i]) {
1716 if (true == __is_digit(t[i] +1)) {
1717 if (0 == atoi(t[i] +1)) {
1719 ret = cal_record_set_int(record, _calendar_event.range_type, CALENDAR_RANGE_NONE);
1720 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1722 DBG("count (%d)", atoi(t[i] +1));
1723 ret = cal_record_set_int(record, _calendar_event.range_type, CALENDAR_RANGE_COUNT);
1724 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1725 ret = cal_record_set_int(record, _calendar_event.count, atoi(t[i] +1));
1726 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1729 ERR("Unable to parse count[%s]", t[i]);
1738 __set_bystr(freq_mode, record, bystr);
1743 static void __work_component_property_rrule_ver_2(char *value, calendar_record_h record, struct user_data *ud)
1748 RET_IF(NULL == value);
1749 RET_IF('\0' == *value);
1750 RET_IF(NULL == record);
1753 t = g_strsplit_set(value, ";:", -1);
1754 RETM_IF(NULL == t, "g_strsplit_set() Fail");
1756 ret = cal_record_set_int(record, _calendar_event.range_type, CALENDAR_RANGE_NONE);
1757 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1759 int len = g_strv_length(t);
1761 for (i = 0; i < len; i++) {
1762 if (NULL == t[i] || '\0' == *t[i]) continue;
1764 if (CAL_STRING_EQUAL == strncmp(t[i], "FREQ=", strlen("FREQ="))) {
1766 if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("FREQ"), "=YEARLY", strlen("=YEARLY")))
1767 frequency = CALENDAR_RECURRENCE_YEARLY;
1768 else if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("FREQ"), "=MONTHLY", strlen("=MONTHLY")))
1769 frequency = CALENDAR_RECURRENCE_MONTHLY;
1770 else if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("FREQ"), "=WEEKLY", strlen("=WEEKLY")))
1771 frequency = CALENDAR_RECURRENCE_WEEKLY;
1772 else if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("FREQ"), "=DAILY", strlen("=DAILY")))
1773 frequency = CALENDAR_RECURRENCE_DAILY;
1775 frequency = CALENDAR_RECURRENCE_NONE;
1777 DBG("frequency(%d) [%s]", frequency, t[i] + strlen("FREQ") + 1);
1778 ret = cal_record_set_int(record, _calendar_event.freq, frequency);
1779 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1781 } else if (CAL_STRING_EQUAL == strncmp(t[i], "UNTIL=", strlen("UNTIL="))) {
1782 calendar_time_s caltime = {0};
1783 _get_caltime(t[i] + strlen("UNTIL="), &caltime, ud);
1784 ret = cal_record_set_caltime(record, _calendar_event.until_time, caltime);
1785 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail(%d)", ret);
1786 ret = cal_record_set_int(record, _calendar_event.range_type, CALENDAR_RANGE_UNTIL);
1787 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1788 } else if (CAL_STRING_EQUAL == strncmp(t[i], "COUNT=", strlen("COUNT="))) {
1789 int count = atoi(t[i] + strlen("COUNT="));
1790 if (count < 1) count = 1;
1791 ret = cal_record_set_int(record, _calendar_event.count, count);
1792 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1793 ret = cal_record_set_int(record, _calendar_event.range_type, CALENDAR_RANGE_COUNT);
1794 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1795 } else if (CAL_STRING_EQUAL == strncmp(t[i], "INTERVAL=", strlen("INTERVAL="))) {
1796 int interval = atoi(t[i] + strlen("INTERVAL="));
1797 if (interval < 1) interval = 1;
1798 ret = cal_record_set_int(record, _calendar_event.interval, interval);
1799 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1800 } else if (CAL_STRING_EQUAL == strncmp(t[i], "BYYEARDAY=", strlen("BYYEARDAY="))) {
1801 ret = cal_record_set_str(record, _calendar_event.byyearday, t[i] + strlen("BYYEARDAY="));
1802 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1803 } else if (CAL_STRING_EQUAL == strncmp(t[i], "BYWEEKNO=", strlen("BYWEEKNO="))) {
1804 ret = cal_record_set_str(record, _calendar_event.byweekno, t[i] + strlen("BYWEEKNO="));
1805 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1806 } else if (CAL_STRING_EQUAL == strncmp(t[i], "BYMONTH=", strlen("BYMONTH="))) {
1807 ret = cal_record_set_str(record, _calendar_event.bymonth, t[i] + strlen("BYMONTH="));
1808 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1809 } else if (CAL_STRING_EQUAL == strncmp(t[i], "BYMONTHDAY=", strlen("BYMONTHDAY="))) {
1810 ret = cal_record_set_str(record, _calendar_event.bymonthday, t[i] + strlen("BYMONTHDAY="));
1811 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1812 } else if (CAL_STRING_EQUAL == strncmp(t[i], "BYDAY=", strlen("BYDAY="))) {
1813 ret = cal_record_set_str(record, _calendar_event.byday, t[i] + strlen("BYDAY="));
1814 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1815 } else if (CAL_STRING_EQUAL == strncmp(t[i], "BYSETPOS=", strlen("BYSETPOS="))) {
1816 ret = cal_record_set_str(record, _calendar_event.bysetpos, t[i] + strlen("BYSETPOS="));
1817 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1818 } else if (CAL_STRING_EQUAL == strncmp(t[i], "WKST=", strlen("WKST="))) {
1819 if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("WKST="), "SU", strlen("SU")))
1820 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_SUNDAY);
1821 else if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("WKST="), "MO", strlen("MO")))
1822 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_MONDAY);
1823 else if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("WKST="), "TU", strlen("TU")))
1824 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_TUESDAY);
1825 else if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("WKST="), "WE", strlen("WE")))
1826 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_WEDNESDAY);
1827 else if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("WKST="), "TH", strlen("TH")))
1828 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_THURSDAY);
1829 else if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("WKST="), "FR", strlen("FR")))
1830 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_FRIDAY);
1831 else if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("WKST="), "SA", strlen("SA")))
1832 ret = cal_record_set_int(record, _calendar_event.wkst, CALENDAR_SATURDAY);
1834 DBG("Unable to parse[%s]", t[i]);
1836 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1838 DBG("Unable to parse[%s]", t[i]);
1845 static void __work_component_property_rrule(char *value, calendar_record_h record, struct user_data *ud)
1849 RET_IF(NULL == value);
1850 RET_IF('\0' == *value);
1851 RET_IF(NULL == record);
1854 int version = ud->version;
1855 /* check if this field has different version content */
1856 if (CAL_STRING_EQUAL == strncmp(value, ":FREQ=", strlen(":FREQ=")))
1857 version = VCAL_VER_2;
1859 version = VCAL_VER_1;
1862 case CALENDAR_BOOK_TYPE_EVENT:
1865 __work_component_property_rrule_ver_1(value, record, ud);
1868 __work_component_property_rrule_ver_2(value, record, ud);
1872 case CALENDAR_BOOK_TYPE_TODO:
1873 DBG("Not support rrule in todo");
1878 static void __work_component_property_dtend(char *value, calendar_record_h record, struct user_data *ud)
1880 RET_IF(NULL == value);
1881 RET_IF('\0' == *value);
1882 RET_IF(NULL == record);
1887 value = __decode_datetime(value, ud);
1888 calendar_time_s dtend = {0};
1889 ret = _get_caltime(value, &dtend, ud);
1890 if (CALENDAR_ERROR_NONE != ret) {
1891 ERR("_get_caltime() Fail(%d)", ret);
1896 tzid = ud->datetime_tzid ? ud->datetime_tzid : (ud->timezone_tzid ? ud->timezone_tzid : NULL);
1898 /* check if dtend is earlier than dtstart. */
1900 if (CALENDAR_BOOK_TYPE_TODO == ud->type) /* skip in todo */
1903 calendar_time_s dtstart = {0};
1904 ret = calendar_record_get_caltime(record, _calendar_event.start_time, &dtstart);
1905 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Fail(%d)", ret);
1907 if (0 == dtstart.time.utime) /* not set yet */
1911 _sub_caltime(ud, &dtstart, &dtend, &diff);
1912 if (diff <= 0) /* proper data */
1915 WARN("dtend < dtstart so set end time to start");
1920 case CALENDAR_BOOK_TYPE_EVENT:
1921 if (tzid && *tzid) {
1922 ret = cal_record_set_str(record, _calendar_event.end_tzid, tzid);
1923 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1925 ret = cal_record_set_caltime(record, _calendar_event.end_time, dtend);
1926 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail(%d)", ret);
1928 case CALENDAR_BOOK_TYPE_TODO:
1929 if (tzid && *tzid) {
1930 ret = cal_record_set_str(record, _calendar_todo.due_tzid, tzid);
1931 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
1933 ret = cal_record_set_caltime(record, _calendar_todo.due_time, dtend);
1934 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail(%d)", ret);
1939 static void __work_component_property_attendee_mailto(calendar_record_h attendee, char *value)
1941 RET_IF(NULL == value);
1942 RET_IF('\0' == *value);
1943 RET_IF(NULL == attendee);
1946 char *mailto = NULL;
1947 ret = calendar_record_get_str(attendee, _calendar_attendee.email, &mailto);
1948 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_get_str() Fail");
1952 ret = cal_record_set_str(attendee, _calendar_attendee.email, value);
1953 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail");
1955 static void __work_component_property_attendee_cutype(calendar_record_h attendee, char *value)
1959 RET_IF(NULL == value);
1960 RET_IF('\0' == *value);
1961 RET_IF(NULL == attendee);
1963 const char *prop = NULL;
1964 if (CAL_STRING_EQUAL == strncmp(value, "INDIVIDUAL", strlen("INDIVIDUAL"))) {
1965 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_CUTYPE_INDIVIDUAL);
1966 if (strlen(value) > strlen("INDIVIDUAL"))
1967 prop = "INDIVIDUAL";
1969 } else if (CAL_STRING_EQUAL == strncmp(value, "GROUP", strlen("GROUP"))) {
1970 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_CUTYPE_GROUP);
1971 if (strlen(value) > strlen("GROUP"))
1974 } else if (CAL_STRING_EQUAL == strncmp(value, "RESOURCE", strlen("RESOURCE"))) {
1975 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_CUTYPE_RESOURCE);
1976 if (strlen(value) > strlen("RESOURCE"))
1979 } else if (CAL_STRING_EQUAL == strncmp(value, "ROOM", strlen("ROOM"))) {
1980 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_CUTYPE_ROOM);
1981 if (strlen(value) > strlen("ROOM"))
1984 } else if (CAL_STRING_EQUAL == strncmp(value, "UNKNOWN", strlen("UNKNOWN"))) {
1985 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_CUTYPE_UNKNOWN);
1986 if (strlen(value) > strlen("UNKNOWN"))
1990 ERR("Invalid value[%s]", value);
1992 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
1995 if (prop && CAL_STRING_EQUAL == strncmp(value + strlen(prop), ":MAILTO", strlen(":MAILTO")))
1996 __work_component_property_attendee_mailto(attendee, value + strlen(prop) + strlen(":MAILTO") +1);
1998 static void __work_component_property_attendee_member(calendar_record_h attendee, char *value)
2000 RET_IF(NULL == value);
2001 RET_IF('\0' == *value);
2002 RET_IF(NULL == attendee);
2004 int ret = cal_record_set_str(attendee, _calendar_attendee.member, value);
2005 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
2007 static void __work_component_property_attendee_role(calendar_record_h attendee, char *value)
2011 RET_IF(NULL == value);
2012 RET_IF('\0' == *value);
2013 RET_IF(NULL == attendee);
2015 const char *prop = NULL;
2016 if (CAL_STRING_EQUAL == strncmp(value, "REQ-PARTICIPANT", strlen("REQ-PARTICIPANT"))) {
2017 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT);
2018 if (strlen(value) > strlen("REQ-PARTICIPANT"))
2019 prop = "REQ-PARTICIPANT";
2020 } else if (CAL_STRING_EQUAL == strncmp(value, "OPT-PARTICIPANT", strlen("OPT-PARTICIPANT"))) {
2021 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT);
2022 if (strlen(value) > strlen("OPT-PARTICIPANT"))
2023 prop = "OPT-PARTICIPANT";
2024 } else if (CAL_STRING_EQUAL == strncmp(value, "NON-PARTICIPANT", strlen("NON-PARTICIPANT"))) {
2025 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT);
2026 if (strlen(value) > strlen("NON-PARTICIPANT"))
2027 prop = "NON-PARTICIPANT";
2028 } else if (CAL_STRING_EQUAL == strncmp(value, "CHAIR", strlen("CHAIR"))) {
2029 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_ROLE_CHAIR);
2030 if (strlen(value) > strlen("CHAIR"))
2033 ERR("Invalid value[%s]", value);
2035 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2038 if (prop && CAL_STRING_EQUAL == strncmp(value + strlen(prop), ":MAILTO", strlen(":MAILTO")))
2039 __work_component_property_attendee_mailto(attendee, value + strlen(prop) + strlen(":MAILTO") +1);
2041 static void __work_component_property_attendee_partstat(calendar_record_h attendee, char *value)
2045 RET_IF(NULL == value);
2046 RET_IF('\0' == *value);
2047 RET_IF(NULL == attendee);
2049 const char *prop = NULL;
2050 if (CAL_STRING_EQUAL == strncmp(value, "NEEDS-ACTION", strlen("NEEDS-ACTION"))) {
2051 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_STATUS_PENDING);
2052 if (strlen(value) > strlen("NEEDS-ACTION"))
2053 prop = "NEEDS-ACTION";
2055 } else if (CAL_STRING_EQUAL == strncmp(value, "ACCEPTED", strlen("ACCEPTED"))) {
2056 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_STATUS_ACCEPTED);
2057 if (strlen(value) > strlen("ACCEPTED"))
2060 } else if (CAL_STRING_EQUAL == strncmp(value, "DECLINED", strlen("DECLINED"))) {
2061 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_STATUS_DECLINED);
2062 if (strlen(value) > strlen("DECLINED"))
2065 } else if (CAL_STRING_EQUAL == strncmp(value, "TENTATIVE", strlen("TENTATIVE"))) {
2066 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_STATUS_TENTATIVE);
2067 if (strlen(value) > strlen("TENTATIVE"))
2070 } else if (CAL_STRING_EQUAL == strncmp(value, "DELEGATED", strlen("DELEGATED"))) {
2071 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_STATUS_DELEGATED);
2072 if (strlen(value) > strlen("DELEGATED"))
2075 } else if (CAL_STRING_EQUAL == strncmp(value, "COMPLETED", strlen("COMPLETED"))) {
2076 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_STATUS_COMPLETED);
2077 if (strlen(value) > strlen("COMPLETED"))
2080 } else if (CAL_STRING_EQUAL == strncmp(value, "IN-PROCESS", strlen("IN-PROCESS"))) {
2081 ret = cal_record_set_int(attendee, _calendar_attendee.cutype, CALENDAR_ATTENDEE_STATUS_IN_PROCESS);
2082 if (strlen(value) > strlen("IN-PROCESS"))
2083 prop = "IN-PROCESS";
2086 ERR("Invalid value[%s]", value);
2088 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2091 if (prop && CAL_STRING_EQUAL == strncmp(value + strlen(prop), ":MAILTO", strlen(":MAILTO")))
2092 __work_component_property_attendee_mailto(attendee, value + strlen(prop) + strlen(":MAILTO") +1);
2094 static void __work_component_property_attendee_rsvp(calendar_record_h attendee, char *value)
2096 RET_IF(NULL == value);
2097 RET_IF('\0' == *value);
2098 RET_IF(NULL == attendee);
2101 if (CAL_STRING_EQUAL == strncmp(value, "TRUE", strlen("TRUE")))
2102 ret = cal_record_set_int(attendee, _calendar_attendee.rsvp, 1);
2104 ret = cal_record_set_int(attendee, _calendar_attendee.rsvp, 0);
2106 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2108 static void __work_component_property_attendee_delegated_to(calendar_record_h attendee, char *value)
2110 RET_IF(NULL == value);
2111 RET_IF('\0' == *value);
2112 RET_IF(NULL == attendee);
2115 ret = cal_record_set_str(attendee, _calendar_attendee.delegatee_uri, value);
2116 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail");
2118 static void __work_component_property_attendee_delegated_from(calendar_record_h attendee, char *value)
2120 RET_IF(NULL == value);
2121 RET_IF('\0' == *value);
2122 RET_IF(NULL == attendee);
2125 ret = cal_record_set_str(attendee, _calendar_attendee.delegator_uri, value);
2126 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail");
2128 static void __work_component_property_attendee_sent_by(calendar_record_h attendee, char *value)
2132 static void __work_component_property_attendee_cn(calendar_record_h attendee, char *value)
2134 RET_IF(NULL == value);
2135 RET_IF('\0' == *value);
2136 RET_IF(NULL == attendee);
2139 ret = cal_record_set_str(attendee, _calendar_attendee.name, value);
2140 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail");
2142 static void __work_component_property_attendee_dir(calendar_record_h attendee, char *value)
2149 * ATTENDEE;ROLE=REQ-PARTICIPANT;DELEGATED-FROM="MAILTO:bob@host.com";PARTSTAT=ACCEPTED;CN=Jane Doe:MAILTO:jdoe@host1.com
2150 * ATTENDEE;CN=John Smith;DIR="ldap://host.com:6666/o=eDABC%20Industries,c=3DUS??(cn=3DBJim%20Dolittle)":MAILTO:jimdo@host1.com
2151 * ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com
2152 * ATTENDEE;CN=MAILTO:MAILTO:MAILTO@host.com
2154 static void __work_component_property_attendee(char *value, calendar_record_h record, struct user_data *ud)
2156 RET_IF(NULL == value);
2157 RET_IF('\0' == *value);
2158 RET_IF(NULL == record);
2162 calendar_record_h attendee = NULL;
2163 ret = calendar_record_create(_calendar_attendee._uri, &attendee);
2164 RETM_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_create() Fail(%d)", ret);
2167 t = g_strsplit(value, ";", -1);
2168 RETM_IF(NULL == t, "g_strsplit() Fail");
2170 int len = g_strv_length(t);
2172 for (i = 0; i < len; i++) {
2173 if (NULL == t[i] || '\0' == *t[i]) continue;
2175 if (CAL_STRING_EQUAL == strncmp(t[i], "CUTYPE", strlen("CUTYPE")))
2176 __work_component_property_attendee_cutype(attendee, t[i] + strlen("CUTYPE") +1);
2177 else if (CAL_STRING_EQUAL == strncmp(t[i], "MEMBER", strlen("MEMBER")))
2178 __work_component_property_attendee_member(attendee, t[i] + strlen("MEMBER") +1);
2179 else if (CAL_STRING_EQUAL == strncmp(t[i], "ROLE", strlen("ROLE")))
2180 __work_component_property_attendee_role(attendee, t[i] + strlen("ROLE") +1);
2181 else if (CAL_STRING_EQUAL == strncmp(t[i], "PARTSTAT", strlen("PARTSTAT")))
2182 __work_component_property_attendee_partstat(attendee, t[i] + strlen("PARTSTAT") +1);
2183 else if (CAL_STRING_EQUAL == strncmp(t[i], "RSVP", strlen("RSVP")))
2184 __work_component_property_attendee_rsvp(attendee, t[i] + strlen("RSVP") +1);
2185 else if (CAL_STRING_EQUAL == strncmp(t[i], "DELEGATED-TO", strlen("DELEGATED-TO")))
2186 __work_component_property_attendee_delegated_to(attendee, t[i] + strlen("DELEGATED-TO") +1);
2187 else if (CAL_STRING_EQUAL == strncmp(t[i], "DELEGATED-FROM", strlen("DELEGATED-FROM")))
2188 __work_component_property_attendee_delegated_from(attendee, t[i] + strlen("DELEGATED-FROM") +1);
2189 else if (CAL_STRING_EQUAL == strncmp(t[i], "SENT_BY", strlen("SENT_BY")))
2190 __work_component_property_attendee_sent_by(attendee, t[i] + strlen("SENT_BY") +1);
2191 else if (CAL_STRING_EQUAL == strncmp(t[i], "CN", strlen("CN")))
2192 __work_component_property_attendee_cn(attendee, t[i] + strlen("CN") +1);
2193 else if (CAL_STRING_EQUAL == strncmp(t[i], "DIR", strlen("DIR")))
2194 __work_component_property_attendee_dir(attendee, t[i] + strlen("DIR") +1);
2195 else if (CAL_STRING_EQUAL == strncmp(t[i], ":MAILTO", strlen(":MAILTO")))
2196 __work_component_property_attendee_mailto(attendee, t[i] + strlen(":MAILTO") +1);
2198 ERR("Invalid value[%s]", t[i]);
2204 case CALENDAR_BOOK_TYPE_EVENT:
2205 ret = calendar_record_add_child_record(record, _calendar_event.calendar_attendee, attendee);
2206 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_add_child_record() Fail(%d)", ret);
2208 case CALENDAR_BOOK_TYPE_TODO:
2209 ret = calendar_record_add_child_record(record, _calendar_event.calendar_attendee, attendee);
2210 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_add_child_record() Fail(%d)", ret);
2215 static void __work_component_property_categories(char *value, calendar_record_h record, struct user_data *ud)
2217 RET_IF(NULL == value);
2218 RET_IF('\0' == *value);
2219 RET_IF(NULL == record);
2223 char *s = __decode_charset(value);
2224 __decode_escaped_char(s);
2226 case CALENDAR_BOOK_TYPE_EVENT:
2227 ret = cal_record_set_str(record, _calendar_event.categories, s);
2228 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
2230 case CALENDAR_BOOK_TYPE_TODO:
2231 ret = cal_record_set_str(record, _calendar_todo.categories, s);
2232 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
2238 static void _set_alarm_tick_unit(calendar_record_h alarm, calendar_time_s alarm_time, int diff)
2242 RET_IF(NULL == alarm);
2245 DBG("set specific alarm");
2246 ret = cal_record_set_caltime(alarm, _calendar_alarm.alarm_time, alarm_time);
2247 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail(%d)", ret);
2248 ret = cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_SPECIFIC);
2249 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2250 } else if (0 == diff) {
2251 DBG("set alarm in start time");
2252 ret = cal_record_set_int(alarm, _calendar_alarm.tick, 0);
2253 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2254 ret = cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_HOUR);
2255 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2259 _get_tick_unit(diff, &tick, &unit);
2260 ret = cal_record_set_int(alarm, _calendar_alarm.tick, tick);
2261 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2262 ret = cal_record_set_int(alarm, _calendar_alarm.tick_unit, unit);
2263 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2269 * dalarmparts = 0*3(strnosemi ";") strnosemi; runTime, snoozeTime, repeatCount, displayString
2270 * DALARM:19960415T235000;PT5M;2;Your Taxes Are Due !!!
2272 static void __work_component_property_dalarm(char *value, calendar_record_h record, struct user_data *ud)
2274 RET_IF(NULL == value);
2275 RET_IF('\0' == *value);
2276 RET_IF(NULL == record);
2281 t = g_strsplit_set(value, ";:", -1);
2282 RETM_IF(NULL == t, "g_strsplit_set() Fail");
2284 calendar_record_h alarm = NULL;
2285 ret = calendar_record_create(_calendar_alarm._uri, &alarm);
2286 if (CALENDAR_ERROR_NONE != ret) {
2287 ERR("calendar_record_create() Fail(%d)", ret);
2291 ret = cal_record_set_int(alarm, _calendar_alarm.action, CALENDAR_ALARM_ACTION_DISPLAY);
2292 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2294 int len = g_strv_length(t);
2296 int index = VCAL_VER_10_DALARM_NONE;
2297 for (i = 0; i < len; i++) {
2300 if (NULL == t[i] || '\0' == *t[i])
2303 if ('0' <= *t[i] && *t[i] <= '9' && strlen("PTM") < strlen(t[i])) {
2305 index = VCAL_VER_10_DALARM_RUN_TIME;
2306 calendar_time_s alarm_time = {0};
2307 ret = _get_caltime(t[i], &alarm_time, ud);
2308 if (CALENDAR_ERROR_NONE != ret) {
2309 ERR("_get_caltime() Fail(%d)", ret);
2310 index = VCAL_VER_10_AALARM_NONE;
2314 if (true == ud->has_rrule) {
2315 calendar_time_s start_time = {0};
2316 ret = calendar_record_get_caltime(record, _calendar_event.start_time, &start_time);
2319 ret = _sub_caltime(ud, &start_time, &alarm_time, &diff);
2320 if (CALENDAR_ERROR_NONE != ret) {
2321 ERR("_sub_caltime() Fail(%d)", ret);
2322 index = VCAL_VER_10_DALARM_NONE;
2325 _set_alarm_tick_unit(alarm, alarm_time, diff);
2328 _set_alarm_tick_unit(alarm, alarm_time, -1); /* -1 goes to specific time */
2330 } else if (VCAL_VER_10_DALARM_DISPLAY_STRING == index) { /* displayString */
2331 DBG("displayString [%s]", t[i]);
2332 ret = cal_record_set_str(alarm, _calendar_alarm.summary, t[i]);
2333 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
2340 if (VCAL_VER_10_DALARM_NONE == index) {
2342 calendar_record_destroy(alarm, true);
2348 case VCALENDAR_TYPE_VEVENT:
2349 ret = calendar_record_add_child_record(record, _calendar_event.calendar_alarm, alarm);
2350 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_add_child_record() Fail(%d)", ret);
2352 case VCALENDAR_TYPE_VTODO:
2353 ret = calendar_record_add_child_record(record, _calendar_todo.calendar_alarm, alarm);
2354 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_add_child_record() Fail(%d)", ret);
2362 * malarmparts = 0*4(strnosemi ";") strnosemi; runTime, snoozeTime, repeatCount, addressString, noteString
2364 static void __work_component_property_malarm(char *value, calendar_record_h record, struct user_data *ud)
2366 /* diff with aalarm: action */
2367 RET_IF(NULL == value);
2368 RET_IF('\0' == *value);
2369 RET_IF(NULL == record);
2374 t = g_strsplit_set(value, ";:", -1);
2375 RETM_IF(NULL == t, "g_strsplit_set() Fail");
2377 calendar_record_h alarm = NULL;
2378 ret = calendar_record_create(_calendar_alarm._uri, &alarm);
2379 if (CALENDAR_ERROR_NONE != ret) {
2380 ERR("calendar_record_create() Fail(%d)", ret);
2384 ret = cal_record_set_int(alarm, _calendar_alarm.action, CALENDAR_ALARM_ACTION_EMAIL);
2385 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2387 int len = g_strv_length(t);
2389 int index = VCAL_VER_10_MALARM_NONE;
2390 for (i = 0; i < len; i++) {
2393 if (NULL == t[i] || '\0' == *t[i])
2396 if ('0' <= *t[i] && *t[i] <= '9' && strlen("PTM") < strlen(t[i])) {
2398 index = VCAL_VER_10_MALARM_RUN_TIME;
2399 calendar_time_s alarm_time = {0};
2400 ret = _get_caltime(t[i], &alarm_time, ud);
2401 if (CALENDAR_ERROR_NONE != ret) {
2402 ERR("_get_caltime() Fail(%d)", ret);
2403 index = VCAL_VER_10_AALARM_NONE;
2407 if (true == ud->has_rrule) {
2408 calendar_time_s start_time = {0};
2409 ret = calendar_record_get_caltime(record, _calendar_event.start_time, &start_time);
2410 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Fail(%d)", ret);
2413 ret = _sub_caltime(ud, &start_time, &alarm_time, &diff);
2414 if (CALENDAR_ERROR_NONE != ret) {
2415 ERR("_sub_caltime() Fail(%d)", ret);
2416 index = VCAL_VER_10_MALARM_NONE;
2419 _set_alarm_tick_unit(alarm, alarm_time, diff);
2422 _set_alarm_tick_unit(alarm, alarm_time, -1); /* -1 goes to specific time */
2424 } else if (VCAL_VER_10_MALARM_ADDRESS_STRING == index) { /* addressString */
2425 DBG("addressString [%s]", t[i]);
2426 ret = cal_record_set_str(alarm, _calendar_alarm.attach, t[i]);
2427 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
2429 } else if (VCAL_VER_10_MALARM_NOTE_STRING == index) { /* noteString */
2430 DBG("noteString [%s]", t[i]);
2431 ret = cal_record_set_str(alarm, _calendar_alarm.description, t[i]);
2432 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
2439 if (VCAL_VER_10_MALARM_NONE == index) {
2441 calendar_record_destroy(alarm, true);
2447 case VCALENDAR_TYPE_VEVENT:
2448 ret = calendar_record_add_child_record(record, _calendar_event.calendar_alarm, alarm);
2449 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_add_child_record() Fail(%d)", ret);
2451 case VCALENDAR_TYPE_VTODO:
2452 ret = calendar_record_add_child_record(record, _calendar_todo.calendar_alarm, alarm);
2453 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_add_child_record() Fail(%d)", ret);
2460 * aalarmparts = 0*3(strnosemi ";") strnosemi; runTime, snoozeTime, repeatCount, audioContent
2461 * AALARM;TYPE=WAVE;VALUE=URL:19960415T235959; ; ; file:///mmedia/taps.wav
2462 * AALARM;TYPE=WAVE;VALUE=CONTENT-ID:19960903T060000;PT15M;4;<jsmith.part2.=960901T083000.xyzMail@host1.com>
2464 static void __work_component_property_aalarm(char *value, calendar_record_h record, struct user_data *ud)
2468 RET_IF(NULL == value);
2469 RET_IF('\0' == *value);
2470 RET_IF(NULL == record);
2475 t = g_strsplit_set(value, ";:", -1);
2476 RETM_IF(NULL == t, "g_strsplit_set() Fail");
2478 calendar_record_h alarm = NULL;
2479 ret = calendar_record_create(_calendar_alarm._uri, &alarm);
2480 if (CALENDAR_ERROR_NONE != ret) {
2481 ERR("calendar_record_create() Fail(%d)", ret);
2485 ret = cal_record_set_int(alarm, _calendar_alarm.action, CALENDAR_ALARM_ACTION_AUDIO);
2486 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2488 int len = g_strv_length(t);
2490 int index = VCAL_VER_10_AALARM_NONE;
2491 for (i = 0; i < len; i++) {
2494 if (NULL == t[i] || '\0' == *t[i])
2497 if ('0' <= *t[i] && *t[i] <= '9' && strlen("PTM") < strlen(t[i])) {
2499 index = VCAL_VER_10_AALARM_RUN_TIME;
2500 calendar_time_s alarm_time = {0};
2501 ret = _get_caltime(t[i], &alarm_time, ud);
2502 if (CALENDAR_ERROR_NONE != ret) {
2503 ERR("_get_caltime() Fail(%d)", ret);
2504 index = VCAL_VER_10_AALARM_NONE;
2508 if (true == ud->has_rrule) {
2509 calendar_time_s start_time = {0};
2510 ret = calendar_record_get_caltime(record, _calendar_event.start_time, &start_time);
2513 ret = _sub_caltime(ud, &start_time, &alarm_time, &diff);
2514 if (CALENDAR_ERROR_NONE != ret) {
2515 ERR("_sub_caltime() Fail(%d)", ret);
2516 index = VCAL_VER_10_AALARM_NONE;
2519 _set_alarm_tick_unit(alarm, alarm_time, diff);
2522 _set_alarm_tick_unit(alarm, alarm_time, -1); /* -1 goes to specific time */
2524 } else if (VCAL_VER_10_AALARM_AUDIO_CONTENT == index) {
2526 DBG("Content [%s]", t[i]);
2527 ret = cal_record_set_str(alarm, _calendar_alarm.attach, t[i]);
2528 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
2534 if (VCAL_VER_10_AALARM_NONE == index) {
2536 calendar_record_destroy(alarm, true);
2542 case VCALENDAR_TYPE_VEVENT:
2543 ret = calendar_record_add_child_record(record, _calendar_event.calendar_alarm, alarm);
2544 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_add_child_record() Fail(%d)", ret);
2546 case VCALENDAR_TYPE_VTODO:
2547 ret = calendar_record_add_child_record(record, _calendar_todo.calendar_alarm, alarm);
2548 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_add_child_record() Fail(%d)", ret);
2554 static void __work_component_property_exdate(char *value, calendar_record_h record, struct user_data *ud)
2556 RET_IF(NULL == value);
2557 RET_IF('\0' == *value);
2558 RET_IF(NULL == record);
2563 case CALENDAR_BOOK_TYPE_EVENT:
2564 ret = cal_record_set_str(record, _calendar_event.exdate, value + 1);
2565 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
2567 case CALENDAR_BOOK_TYPE_TODO:
2568 ERR("No exdate in todo");
2573 static void __work_component_property_x_allday(char *value, calendar_record_h record, struct user_data *ud)
2575 RET_IF(NULL == value);
2576 RET_IF('\0' == *value);
2577 RET_IF(NULL == record);
2581 if (CAL_STRING_EQUAL == strncmp(value, ":SET", strlen(":SET"))) {
2582 DBG("x-allday: set");
2583 ud->is_allday = true;
2585 calendar_time_s caltime = {0};
2587 case CALENDAR_BOOK_TYPE_EVENT:
2588 ret = calendar_record_get_caltime(record, _calendar_event.start_time, &caltime);
2589 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Fail");
2590 if (CALENDAR_TIME_LOCALTIME == caltime.type) {
2591 caltime.time.date.hour = 0;
2592 caltime.time.date.minute = 0;
2593 caltime.time.date.second = 0;
2594 ret = cal_record_set_caltime(record, _calendar_event.start_time, caltime);
2595 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail");
2597 ret = calendar_record_get_caltime(record, _calendar_event.end_time, &caltime);
2598 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Fail");
2599 if (CALENDAR_TIME_LOCALTIME == caltime.type) {
2600 caltime.time.date.hour = 0;
2601 caltime.time.date.minute = 0;
2602 caltime.time.date.second = 0;
2603 ret = cal_record_set_caltime(record, _calendar_event.end_time, caltime);
2604 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail");
2606 ret = calendar_record_get_caltime(record, _calendar_event.until_time, &caltime);
2607 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Fail");
2608 if (CALENDAR_TIME_LOCALTIME == caltime.type) {
2609 caltime.time.date.hour = 0;
2610 caltime.time.date.minute = 0;
2611 caltime.time.date.second = 0;
2612 ret = cal_record_set_caltime(record, _calendar_event.until_time, caltime);
2613 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail");
2616 case CALENDAR_BOOK_TYPE_TODO:
2617 ret = calendar_record_get_caltime(record, _calendar_todo.start_time, &caltime);
2618 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Fail");
2619 if (CALENDAR_TIME_LOCALTIME == caltime.type) {
2620 caltime.time.date.hour = 0;
2621 caltime.time.date.minute = 0;
2622 caltime.time.date.second = 0;
2623 ret = cal_record_set_caltime(record, _calendar_todo.start_time, caltime);
2624 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail");
2626 ret = calendar_record_get_caltime(record, _calendar_todo.due_time, &caltime);
2627 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Fail");
2628 if (CALENDAR_TIME_LOCALTIME == caltime.type) {
2629 caltime.time.date.hour = 0;
2630 caltime.time.date.minute = 0;
2631 caltime.time.date.second = 0;
2632 ret = cal_record_set_caltime(record, _calendar_todo.due_time, caltime);
2633 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail");
2640 static void __work_component_property_x_lunar(char *value, calendar_record_h record, struct user_data *ud)
2642 RET_IF(NULL == value);
2643 RET_IF('\0' == *value);
2644 RET_IF(NULL == record);
2648 if (CAL_STRING_EQUAL == strncmp(value, ":SET", strlen(":SET"))) {
2649 DBG("x-lunar: set");
2651 case CALENDAR_BOOK_TYPE_EVENT:
2652 ret = cal_record_set_int(record, _calendar_event.calendar_system_type, CALENDAR_SYSTEM_EAST_ASIAN_LUNISOLAR);
2653 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2655 case CALENDAR_BOOK_TYPE_TODO:
2656 DBG("Not supported lunar in todo");
2662 static void __work_component_property_valarm_action(char *value, calendar_record_h alarm, struct user_data *ud)
2664 RET_IF(NULL == value);
2665 RET_IF('\0' == *value);
2666 RET_IF(NULL == alarm);
2668 const char *prop[CALENDAR_ALARM_ACTION_MAX] = {":AUDIO", ":DISPLAY", ":EMAIL"};
2672 for (i = 0; i < CALENDAR_ALARM_ACTION_MAX; i++) {
2673 if (CAL_STRING_EQUAL == strncmp(value, prop[i], strlen(prop[i]))) {
2674 ret = cal_record_set_int(alarm, _calendar_alarm.action, i);
2675 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2681 static void __work_component_property_valarm_trigger(char *value, calendar_record_h record, calendar_record_h alarm, struct user_data *ud)
2685 RET_IF(NULL == value);
2686 RET_IF('\0' == *value);
2687 RET_IF(NULL == alarm);
2692 t = g_strsplit_set(value, ";:", -1);
2693 RETM_IF(NULL == t, "g_strsplit_set() Fail");
2695 int related = VCAL_RELATED_NONE;
2696 int len = g_strv_length(t);
2698 for (i = 0; i < len; i++) {
2699 if (NULL == t[i] || '\0' == *t[i]) continue;
2701 if (CAL_STRING_EQUAL == strncmp(t[i], "RELATED", strlen("RELATED"))) {
2702 if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("RELATED"), "=START", strlen("=START")))
2703 related = VCAL_RELATED_START;
2704 else if (CAL_STRING_EQUAL == strncmp(t[i] + strlen("RELATED"), "=END", strlen("=END")))
2705 related = VCAL_RELATED_END;
2707 ERR("Invalid related:[%s]", t[i]);
2708 } else if (CAL_STRING_EQUAL == strncmp(t[i], "VALUE", strlen("VALUE"))) {
2711 if ('0' <= *t[i] && *t[i] <= '9' && strlen("YYYYDDMM") <= strlen(t[i])) {
2712 calendar_time_s caltime = {0};
2713 _get_caltime(t[i], &caltime, ud);
2714 ret = cal_record_set_caltime(alarm, _calendar_alarm.alarm_time, caltime);
2715 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail(%d)", ret);
2716 ret = cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_SPECIFIC);
2717 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2721 __decode_duration(t[i], strlen(t[i]), &tick, &unit);
2722 if (CALENDAR_ALARM_TIME_UNIT_SPECIFIC == unit || 0 < tick) {
2723 if (CALENDAR_ALARM_TIME_UNIT_SPECIFIC == unit)
2724 DBG("alarm tick is second, changed as specific.");
2726 DBG("alarm is set after start/end time(%d).", tick);
2728 calendar_time_s caltime = {0};
2729 if (VCAL_RELATED_NONE == related) {
2731 case CALENDAR_BOOK_TYPE_EVENT:
2732 related = VCAL_RELATED_START;
2734 case CALENDAR_BOOK_TYPE_TODO:
2735 related = VCAL_RELATED_END;
2740 case VCAL_RELATED_START:
2741 ret = calendar_record_get_caltime(record, _calendar_event.start_time, &caltime);
2742 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Fail(%d)", ret);
2744 case VCAL_RELATED_END:
2745 ret = calendar_record_get_caltime(record, _calendar_event.end_time, &caltime);
2746 WARN_IF(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Fail(%d)", ret);
2749 cal_time_modify_caltime(&caltime, tick * unit);
2750 ret = cal_record_set_caltime(alarm, _calendar_alarm.alarm_time, caltime);
2751 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_caltime() Fail(%d)", ret);
2752 ret = cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_SPECIFIC);
2753 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2755 ret = cal_record_set_int(alarm, _calendar_alarm.tick, (-1 * tick));
2756 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2757 ret = cal_record_set_int(alarm, _calendar_alarm.tick_unit, unit);
2758 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
2767 static void __work_component_property_valarm_repeat(char *value, calendar_record_h alarm, struct user_data *ud)
2772 static void __work_component_property_valarm_attach(char *value, calendar_record_h alarm, struct user_data *ud)
2774 RET_IF(NULL == value);
2775 RET_IF('\0' == *value);
2776 RET_IF(NULL == alarm);
2778 int ret = cal_record_set_str(alarm, _calendar_alarm.attach, value + 1);
2779 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
2782 static void __work_component_property_valarm_description(char *value, calendar_record_h alarm, struct user_data *ud)
2784 RET_IF(NULL == value);
2785 RET_IF('\0' == *value);
2786 RET_IF(NULL == alarm);
2788 int ret = cal_record_set_str(alarm, _calendar_alarm.description, value + 1);
2789 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
2792 static void __work_component_property_valarm_summary(char *value, calendar_record_h alarm, struct user_data *ud)
2794 RET_IF(NULL == value);
2795 RET_IF('\0' == *value);
2796 RET_IF(NULL == alarm);
2798 int ret = cal_record_set_str(alarm, _calendar_alarm.summary, value);
2799 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
2802 static void __work_component_property_valarm_duration(char *value, calendar_record_h alarm, struct user_data *ud)
2807 static char* __work_component_property_begin(char *cursor, calendar_record_h record, struct user_data *ud)
2811 RETV_IF(NULL == cursor, NULL);
2812 RETV_IF(NULL == record, NULL);
2813 RETV_IF(NULL == ud, NULL);
2815 if (0 != strncmp(cursor, ":VALARM", strlen(":VALARM"))) {
2816 DBG("this is not valarm");
2817 return __crlf(cursor);
2820 __init_component_property_valarm();
2823 calendar_record_h alarm = NULL;
2824 ret = calendar_record_create(_calendar_alarm._uri, &alarm);
2825 RETVM_IF(CALENDAR_ERROR_NONE != ret, NULL, "calendar_record_create() Fail(%d)", ret);
2827 cursor = __crlf(cursor); /* crlf: BEGIN:VALARM */
2828 bool exit_loop = false;
2831 cursor = __get_index(cursor, component_property_valarm, VCAL_COMPONENT_PROPERTY_VALARM_MAX, &index);
2835 case VCAL_COMPONENT_PROPERTY_VALARM_ACTION:
2836 cursor = __get_value(cursor, &value);
2837 __work_component_property_valarm_action(value, alarm, ud);
2842 case VCAL_COMPONENT_PROPERTY_VALARM_TRIGGER:
2843 cursor = __get_value(cursor, &value);
2844 __work_component_property_valarm_trigger(value, record, alarm, ud);
2849 case VCAL_COMPONENT_PROPERTY_VALARM_REPEAT:
2850 cursor = __get_value(cursor, &value);
2851 __work_component_property_valarm_repeat(value, alarm, ud);
2856 case VCAL_COMPONENT_PROPERTY_VALARM_ATTACH:
2857 cursor = __get_value(cursor, &value);
2858 __work_component_property_valarm_attach(value, alarm, ud);
2863 case VCAL_COMPONENT_PROPERTY_VALARM_DESCRIPTION:
2864 cursor = __get_value(cursor, &value);
2865 __work_component_property_valarm_description(value, alarm, ud);
2870 case VCAL_COMPONENT_PROPERTY_VALARM_SUMMARY:
2871 cursor = __get_value(cursor, &value);
2872 __work_component_property_valarm_summary(value, alarm, ud);
2877 case VCAL_COMPONENT_PROPERTY_VALARM_DURATION:
2878 cursor = __get_value(cursor, &value);
2879 __work_component_property_valarm_duration(value, alarm, ud);
2884 case VCAL_COMPONENT_PROPERTY_VALARM_END:
2890 ERR("Invalid index(%d)", index);
2891 cursor = __crlf(cursor);
2895 if (true == exit_loop) break;
2899 case VCALENDAR_TYPE_VEVENT:
2900 ret = calendar_record_add_child_record(record, _calendar_event.calendar_alarm, alarm);
2902 case VCALENDAR_TYPE_VTODO:
2903 ret = calendar_record_add_child_record(record, _calendar_todo.calendar_alarm, alarm);
2906 RETVM_IF(CALENDAR_ERROR_NONE != ret, NULL, "calendar_record_add_child_record() Fail(%d)", ret);
2910 static char* __work_component_vevent(char *cursor, calendar_record_h record, struct user_data *ud)
2912 RETV_IF(NULL == cursor, NULL);
2913 RETV_IF(NULL == record, NULL);
2915 bool exit_loop = false;
2918 cursor = __get_index(cursor, component_property, VCAL_COMPONENT_PROPERTY_MAX, &index);
2922 case VCAL_COMPONENT_PROPERTY_DTSTAMP:
2923 cursor = __get_value(cursor, &value);
2924 __work_component_property_dtstamp(value, record, ud);
2928 case VCAL_COMPONENT_PROPERTY_UID:
2929 cursor = __get_value(cursor, &value);
2930 __work_component_property_uid(value, record, ud);
2934 case VCAL_COMPONENT_PROPERTY_RECURRENCE_ID:
2935 cursor = __get_value(cursor, &value);
2936 __work_component_property_recurrence_id(value, record, ud);
2940 case VCAL_COMPONENT_PROPERTY_DTSTART:
2941 cursor = __get_value(cursor, &value);
2942 __work_component_property_dtstart(value, record, ud);
2946 case VCAL_COMPONENT_PROPERTY_CREATED:
2947 cursor = __get_value(cursor, &value);
2948 __work_component_property_created(value, record, ud);
2952 case VCAL_COMPONENT_PROPERTY_DCREATED:
2953 cursor = __get_value(cursor, &value);
2954 __work_component_property_created(value, record, ud);
2958 case VCAL_COMPONENT_PROPERTY_DESCRIPTION:
2959 cursor = __get_value(cursor, &value);
2960 __work_component_property_description(value, record, ud);
2964 case VCAL_COMPONENT_PROPERTY_LAST_MODIFIED:
2965 cursor = __get_value(cursor, &value);
2966 __work_component_property_last_modified(value, record, ud);
2970 case VCAL_COMPONENT_PROPERTY_LOCATION:
2971 cursor = __get_value(cursor, &value);
2972 __work_component_property_location(value, record, ud);
2976 case VCAL_COMPONENT_PROPERTY_PRIORITY:
2977 cursor = __get_value(cursor, &value);
2978 __work_component_property_priority(value + 1, record, ud);
2982 case VCAL_COMPONENT_PROPERTY_STATUS:
2983 cursor = __get_value(cursor, &value);
2984 __work_component_property_status(value, record, ud);
2988 case VCAL_COMPONENT_PROPERTY_SUMMARY:
2989 cursor = __get_value(cursor, &value);
2990 __work_component_property_summary(value, record, ud);
2994 case VCAL_COMPONENT_PROPERTY_RRULE:
2995 cursor = __get_value(cursor, &value);
2996 __work_component_property_rrule(value, record, ud);
3000 case VCAL_COMPONENT_PROPERTY_DTEND:
3001 if (CAL_STRING_EQUAL != strcmp(((cal_record_s*)(record))->view_uri, _calendar_event._uri))
3003 cursor = __get_value(cursor, &value);
3004 __work_component_property_dtend(value, record, ud);
3008 case VCAL_COMPONENT_PROPERTY_DUE:
3009 if (CAL_STRING_EQUAL != strcmp(((cal_record_s*)(record))->view_uri, _calendar_todo._uri))
3011 cursor = __get_value(cursor, &value);
3012 __work_component_property_dtend(value, record, ud);
3016 case VCAL_COMPONENT_PROPERTY_ATTENDEE:
3017 cursor = __get_value(cursor, &value);
3018 __work_component_property_attendee(value, record, ud);
3022 case VCAL_COMPONENT_PROPERTY_CATEGORIES:
3023 cursor = __get_value(cursor, &value);
3024 __work_component_property_categories(value, record, ud);
3028 case VCAL_COMPONENT_PROPERTY_DALARM:
3029 cursor = __get_value(cursor, &value);
3030 __work_component_property_dalarm(value, record, ud);
3034 case VCAL_COMPONENT_PROPERTY_MALARM:
3035 cursor = __get_value(cursor, &value);
3036 __work_component_property_malarm(value, record, ud);
3040 case VCAL_COMPONENT_PROPERTY_AALARM:
3041 cursor = __get_value(cursor, &value);
3042 __work_component_property_aalarm(value, record, ud);
3046 case VCAL_COMPONENT_PROPERTY_EXDATE:
3047 cursor = __get_value(cursor, &value);
3048 __work_component_property_exdate(value, record, ud);
3052 case VCAL_COMPONENT_PROPERTY_X_ALLDAY:
3053 cursor = __get_value(cursor, &value);
3054 __work_component_property_x_allday(value, record, ud);
3058 case VCAL_COMPONENT_PROPERTY_X_LUNAR:
3059 cursor = __get_value(cursor, &value);
3060 __work_component_property_x_lunar(value, record, ud);
3064 case VCAL_COMPONENT_PROPERTY_BEGIN:
3065 cursor = __work_component_property_begin(cursor, record, ud);
3067 cursor = __crlf(cursor);
3069 case VCAL_COMPONENT_PROPERTY_END:
3071 cursor = __crlf(cursor);
3074 case VCAL_COMPONENT_PROPERTY_EXTENDED:
3075 cursor = __get_value(cursor, &value);
3080 cursor = __crlf(cursor);
3083 if (true == exit_loop) break;
3088 static char* __work_component_vjournal(char *cursor, calendar_record_h record, struct user_data *ud)
3090 RETV_IF(NULL == cursor, NULL);
3092 DBG("Not supported vjournal");
3094 bool exit_loop = false;
3097 cursor = __get_index(cursor, component_property, VCAL_COMPONENT_PROPERTY_MAX, &index);
3099 case VCAL_COMPONENT_PROPERTY_END:
3101 cursor = __crlf(cursor);
3106 cursor = __crlf(cursor);
3109 if (true == exit_loop) break;
3114 static char* __work_component_vfreebusy(char *cursor, calendar_record_h record, struct user_data *ud)
3116 RETV_IF(NULL == cursor, NULL);
3118 DBG("Not supported vfreebusy");
3120 bool exit_loop = false;
3123 cursor = __get_index(cursor, component_property, VCAL_COMPONENT_PROPERTY_MAX, &index);
3125 case VCAL_COMPONENT_PROPERTY_END:
3127 cursor = __crlf(cursor);
3132 cursor = __crlf(cursor);
3135 if (true == exit_loop) break;
3140 static void __work_component_property_vtimezone_standard_dtstart(char *value, calendar_record_h record, struct user_data *ud)
3144 RET_IF(NULL == value);
3145 RET_IF('\0' == *value);
3146 RET_IF(NULL == record);
3149 int y = 0, m = 0, d = 0;
3150 int h = 0, n = 0, s = 0;
3151 sscanf(value +1, CAL_DATETIME_FORMAT_YYYYMMDDTHHMMSS, &y, &m, &d, &h, &n, &s);
3152 ret = cal_record_set_int(record, _calendar_timezone.standard_start_month, m);
3153 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
3154 ret = cal_record_set_int(record, _calendar_timezone.standard_start_hour, h);
3155 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
3157 long long int t = cal_time_convert_lli(value +1);
3158 int nth = 0, wday = 0;
3159 cal_time_get_nth_wday(t, &nth, &wday);
3160 ret = cal_record_set_int(record, _calendar_timezone.standard_start_position_of_week, nth);
3161 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
3162 ret = cal_record_set_int(record, _calendar_timezone.standard_start_day, wday);
3163 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
3165 static void __work_component_property_vtimezone_standard_tzoffsetfrom(char *value, calendar_record_h record, struct user_data *ud)
3169 static void __work_component_property_vtimezone_standard_tzoffsetto(char *value, calendar_record_h record, struct user_data *ud)
3173 RET_IF(NULL == value);
3174 RET_IF('\0' == *value);
3175 RET_IF(NULL == record);
3179 sscanf(value, "%c%02d%02d", &c, &h, &m);
3181 int offset = h * 60 + m;
3182 if ('-' == c) offset *= -1;
3185 ret = cal_record_set_int(record, _calendar_timezone.standard_bias, offset);
3186 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
3187 ret = cal_record_set_int(record, _calendar_timezone.tz_offset_from_gmt, offset);
3188 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
3190 if (NULL == ud->timezone_tzid || '\0' == *ud->timezone_tzid) {
3191 char buf[CAL_STR_SHORT_LEN32] = {0};
3192 snprintf(buf, sizeof(buf), "Etc/GMT%c%d", offset < 0 ? '+' : '-', h);
3193 ud->timezone_tzid = strdup(buf);
3194 __adjust_tzid(ud->timezone_tzid);
3195 DBG("timezone_tzid[%s]", ud->timezone_tzid);
3198 static void __work_component_property_vtimezone_standard_tzname(char *value, calendar_record_h record, struct user_data *ud)
3200 RET_IF(NULL == value);
3201 RET_IF('\0' == *value);
3202 RET_IF(NULL == record);
3204 int ret = cal_record_set_str(record, _calendar_timezone.standard_name, value);
3205 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
3207 static void __work_component_property_vtimezone_standard_rdate(char *value, calendar_record_h record, struct user_data *ud)
3211 static char* __work_component_vtimezone_standard(char *cursor, calendar_record_h record, struct user_data *ud)
3215 RETV_IF(NULL == cursor, __crlf(cursor));
3216 RETV_IF('\0' == *cursor, __crlf(cursor));
3217 RETV_IF(NULL == record, __crlf(cursor));
3219 cursor = __crlf(cursor);
3220 bool exit_loop = false;
3223 cursor = __get_index(cursor, component_property_vtimezone, VCAL_COMPONENT_PROPERTY_VTIMEZONE_MAX, &index);
3227 case VCAL_COMPONENT_PROPERTY_VTIMEZONE_DTSTART:
3228 cursor = __get_value(cursor, &value);
3229 __work_component_property_vtimezone_standard_dtstart(value +1, record, ud);
3233 case VCAL_COMPONENT_PROPERTY_VTIMEZONE_TZOFFSETFROM:
3234 cursor = __get_value(cursor, &value);
3235 __work_component_property_vtimezone_standard_tzoffsetfrom(value, record, ud);
3239 case VCAL_COMPONENT_PROPERTY_VTIMEZONE_TZOFFSETTO:
3240 cursor = __get_value(cursor, &value);
3241 __work_component_property_vtimezone_standard_tzoffsetto(value +1, record, ud);
3245 case VCAL_COMPONENT_PROPERTY_VTIMEZONE_TZNAME:
3246 cursor = __get_value(cursor, &value);
3247 __work_component_property_vtimezone_standard_tzname(value +1, record, ud);
3251 case VCAL_COMPONENT_PROPERTY_VTIMEZONE_RDATE:
3252 cursor = __get_value(cursor, &value);
3253 __work_component_property_vtimezone_standard_rdate(value, record, ud);
3257 case VCAL_COMPONENT_PROPERTY_VTIMEZONE_END:
3258 cursor = __crlf(cursor);
3262 cursor = __crlf(cursor);
3265 if (true == exit_loop) break;
3270 static void __work_component_property_vtimezone_daylight_dtstart(char *value, calendar_record_h record, struct user_data *ud)
3272 RET_IF(NULL == value);
3273 RET_IF('\0' == *value);
3274 RET_IF(NULL == record);
3277 int y = 0, m = 0, d = 0;
3278 int h = 0, n = 0, s = 0;
3279 sscanf(value +1, CAL_DATETIME_FORMAT_YYYYMMDDTHHMMSS, &y, &m, &d, &h, &n, &s);
3280 ret = cal_record_set_int(record, _calendar_timezone.day_light_start_month, m);
3281 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
3282 ret = cal_record_set_int(record, _calendar_timezone.day_light_start_hour, h);
3283 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
3285 long long int t = cal_time_convert_lli(value +1);
3286 int nth = 0, wday = 0;
3287 cal_time_get_nth_wday(t, &nth, &wday);
3288 ret = cal_record_set_int(record, _calendar_timezone.day_light_start_position_of_week, nth);
3289 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
3290 ret = cal_record_set_int(record, _calendar_timezone.day_light_start_day, wday);
3291 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
3293 static void __work_component_property_vtimezone_daylight_tzoffsetfrom(char *value, calendar_record_h record, struct user_data *ud)
3297 static void __work_component_property_vtimezone_daylight_tzoffsetto(char *value, calendar_record_h record, struct user_data *ud)
3299 RET_IF(NULL == value);
3300 RET_IF('\0' == *value);
3301 RET_IF(NULL == record);
3305 sscanf(value, "%c%02d%02d", &c, &h, &m);
3307 int offset = h * 60 + m;
3308 if ('-' == c) offset *= -1;
3310 int ret = cal_record_set_int(record, _calendar_timezone.day_light_bias, offset);
3311 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_int() Fail(%d)", ret);
3313 static void __work_component_property_vtimezone_daylight_tzname(char *value, calendar_record_h record, struct user_data *ud)
3315 RET_IF(NULL == value);
3316 RET_IF('\0' == *value);
3317 RET_IF(NULL == record);
3319 int ret = cal_record_set_str(record, _calendar_timezone.day_light_name, value);
3320 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_record_set_str() Fail(%d)", ret);
3322 static void __work_component_property_vtimezone_daylight_rdate(char *value, calendar_record_h record, struct user_data *ud)
3326 static char* __work_component_vtimezone_daylight(char *cursor, calendar_record_h record, struct user_data *ud)
3328 RETV_IF(NULL == cursor, __crlf(cursor));
3329 RETV_IF('\0' == *cursor, __crlf(cursor));
3330 RETV_IF(NULL == record, __crlf(cursor));
3332 cursor = __crlf(cursor);
3333 bool exit_loop = false;
3336 cursor = __get_index(cursor, component_property_vtimezone, VCAL_COMPONENT_PROPERTY_VTIMEZONE_MAX, &index);
3340 case VCAL_COMPONENT_PROPERTY_VTIMEZONE_DTSTART:
3341 cursor = __get_value(cursor, &value);
3342 __work_component_property_vtimezone_daylight_dtstart(value +1, record, ud);
3346 case VCAL_COMPONENT_PROPERTY_VTIMEZONE_TZOFFSETFROM:
3347 cursor = __get_value(cursor, &value);
3348 __work_component_property_vtimezone_daylight_tzoffsetfrom(value, record, ud);
3352 case VCAL_COMPONENT_PROPERTY_VTIMEZONE_TZOFFSETTO:
3353 cursor = __get_value(cursor, &value);
3354 __work_component_property_vtimezone_daylight_tzoffsetto(value +1, record, ud);
3358 case VCAL_COMPONENT_PROPERTY_VTIMEZONE_TZNAME:
3359 cursor = __get_value(cursor, &value);
3360 __work_component_property_vtimezone_daylight_tzname(value +1, record, ud);
3364 case VCAL_COMPONENT_PROPERTY_VTIMEZONE_RDATE:
3365 cursor = __get_value(cursor, &value);
3366 __work_component_property_vtimezone_daylight_rdate(value, record, ud);
3370 case VCAL_COMPONENT_PROPERTY_VTIMEZONE_END:
3371 cursor = __crlf(cursor);
3375 cursor = __crlf(cursor);
3378 if (true == exit_loop) break;
3383 static char* __work_component_vtimezone(char *cursor, calendar_record_h record, struct user_data *ud)
3387 RETV_IF(NULL == cursor, NULL);
3388 RETV_IF(NULL == record, NULL);
3390 __init_component_property_vtimezone();
3393 if (CAL_STRING_EQUAL == strncmp(cursor, "TZID:", strlen("TZID:"))) {
3394 char *p = cursor + strlen("TZID");
3395 if (NULL == p || '\0' == *p) {
3396 ERR("Inavlid tzid");
3397 cursor = __crlf(cursor);
3400 if (ud->timezone_tzid) {
3401 free(ud->timezone_tzid);
3402 ud->timezone_tzid = NULL;
3405 cursor = __get_value(p, &value);
3406 __adjust_tzid(value);
3407 DBG("tzid[%s]", value +1);
3408 if (true == cal_time_is_available_tzid(value +1))
3409 ud->timezone_tzid = strdup(value +1);
3411 DBG("Invalid tzid string[%s]", value +1);
3414 } else if (CAL_STRING_EQUAL == strncmp(cursor, "BEGIN:STANDARD", strlen("BEGIN:STANDARD"))) {
3415 cursor = __work_component_vtimezone_standard(cursor, record, ud);
3416 } else if (CAL_STRING_EQUAL == strncmp(cursor, "BEGIN:DAYLIGHT", strlen("BEGIN:DAYLIGHT"))) {
3417 cursor = __work_component_vtimezone_daylight(cursor, record, ud);
3418 } else if (CAL_STRING_EQUAL == strncmp(cursor, "END", strlen("END"))) {
3419 cursor = __crlf(cursor);
3422 DBG("Unable to parse");
3423 __print_cursor(cursor, __LINE__);
3424 cursor = __crlf(cursor);
3430 static char* __work_property_begin(char *cursor, calendar_record_h *out_record, struct user_data *ud)
3433 RETV_IF(NULL == cursor, NULL);
3434 RETV_IF('\0' == *cursor, NULL);
3435 RETV_IF(NULL == out_record, NULL);
3436 RETV_IF(NULL == ud, NULL);
3440 cursor = __get_index(cursor +1, vcal_component, VCAL_COMPONENT_MAX, &index);
3441 cursor = __crlf(cursor);
3442 calendar_record_h record = NULL;
3444 case VCAL_COMPONENT_VEVENT:
3445 ret = calendar_record_create(_calendar_event._uri, &record);
3446 RETVM_IF(CALENDAR_ERROR_NONE != ret, NULL, "calendar_record_create() Fail(%d)", ret);
3447 ud->type = CALENDAR_BOOK_TYPE_EVENT;
3448 ud->has_rrule = __check_has_rrule(cursor);
3449 cursor = __work_component_vevent(cursor, record, ud);
3452 case VCAL_COMPONENT_VTODO:
3453 ret = calendar_record_create(_calendar_todo._uri, &record);
3454 RETVM_IF(CALENDAR_ERROR_NONE != ret, NULL, "calendar_record_create() Fail(%d)", ret);
3455 ud->type = CALENDAR_BOOK_TYPE_TODO;
3456 ud->has_rrule = __check_has_rrule(cursor);
3457 cursor = __work_component_vevent(cursor, record, ud); /* same as event */
3460 case VCAL_COMPONENT_VJOURNAL:
3461 cursor = __work_component_vjournal(cursor, record, ud);
3464 case VCAL_COMPONENT_VFREEBUSY:
3465 cursor = __work_component_vfreebusy(cursor, record, ud);
3468 case VCAL_COMPONENT_VTIMEZONE:
3469 ret = calendar_record_create(_calendar_timezone._uri, &record);
3470 RETVM_IF(CALENDAR_ERROR_NONE != ret, NULL, "calendar_record_create() Fail(%d)", ret);
3471 cursor = __work_component_vtimezone(cursor, record, ud);
3474 *out_record = record;
3478 int cal_vcalendar_parse_vcalendar_object(char *stream, calendar_list_h list, vcalendar_foreach_s *foreach_data)
3482 RETV_IF(NULL == stream, CALENDAR_ERROR_INVALID_PARAMETER);
3483 RETV_IF(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER);
3487 __init_component_property();
3488 __unfolding(stream);
3490 struct user_data *ud = calloc(1, sizeof(struct user_data));
3491 RETVM_IF(NULL == ud, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
3492 ud->version = VCAL_VER_2; /* default */
3494 calendar_record_h record = NULL;
3497 bool exit_loop = false;
3498 char *cursor = (char *)stream;
3502 cursor = __get_index(cursor, vcal_property, VCAL_PROPERTY_MAX, &index);
3504 case VCAL_PROPERTY_VERSION:
3505 cursor = __get_value(cursor, &value);
3506 __get_version(value, &ud->version);
3511 case VCAL_PROPERTY_TZ:
3512 if (ud->timezone_tzid)
3514 cursor = __get_value(cursor, &value);
3515 __get_tz(value + 1, &ud->timezone_tzid);
3516 __adjust_tzid(ud->timezone_tzid);
3517 DBG("timezone_tzid[%s]", ud->timezone_tzid);
3522 case VCAL_PROPERTY_BEGIN: /* BEGIN:VEVENT */
3523 cursor = __work_property_begin(cursor, &record, ud);
3524 calendar_list_add(list, record);
3527 foreach_data->ret = foreach_data->callback(record, foreach_data->user_data);
3528 if (false == foreach_data->ret)
3533 case VCAL_PROPERTY_END: /* END:VCALENDAR */
3534 DBG("exit VCALENDAR");
3535 /* fini vcalendar */
3540 DBG("skip invalid property, index(%d)", index);
3541 cursor = __crlf(cursor);
3544 if (true == exit_loop)
3548 DBG("count(%d)", count);
3551 free(ud->timezone_tzid);
3554 return CALENDAR_ERROR_NONE;