4 * Copyright (c) 2012 - 2013 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.
22 #include "calendar_list.h"
24 #include "cal_internal.h"
25 #include "cal_typedef.h"
26 #include "cal_record.h"
30 #include "cal_vcalendar.h"
31 #include "cal_vcalendar_make.h"
35 EVENT_ATTENDEE_REQ_PARTICIPANT_ROLE=0,
36 EVENT_ATTENDEE_OPT_PARTICIPANT_ROLE,
37 EVENT_ATTENDEE_NON_PARTICIPANT_ROLE,
38 EVENT_ATTENDEE_CHAIR_ROLE,
39 } cal_event_attendee_role_type_t;
43 EVENT_ATTENDEE_NEEDS_ACTION_AT_STATUS=0,
44 EVENT_ATTENDEE_ACCEPTED_AT_STATUS,
45 EVENT_ATTENDEE_DECLINED_AT_STATUS,
46 EVENT_ATTENDEE_TENTATIVE_AT_STATUS,
47 EVENT_ATTENDEE_DELEGATED_AT_STATUS,
48 EVENT_ATTENDEE_COMPLETED_AT_STATUS,
49 EVENT_ATTENDEE_IN_PROCESS_AT_STATUS
50 } cal_event_attendee_status_type_t;
53 static const char *_att_role[] = {
54 [EVENT_ATTENDEE_REQ_PARTICIPANT_ROLE] = "REQ-PARTICIPANT",
55 [EVENT_ATTENDEE_OPT_PARTICIPANT_ROLE] = "OPT-PARTICIPANT",
56 [EVENT_ATTENDEE_NON_PARTICIPANT_ROLE] = "NON-PARTICIPANT",
57 [EVENT_ATTENDEE_CHAIR_ROLE] = "CHAIR",
60 static const char *_att_st[] = {
61 [EVENT_ATTENDEE_NEEDS_ACTION_AT_STATUS] = "NEEDS-ACTION",
62 [EVENT_ATTENDEE_ACCEPTED_AT_STATUS] = "ACCEPTED",
63 [EVENT_ATTENDEE_DECLINED_AT_STATUS] = "DECLINED",
64 [EVENT_ATTENDEE_TENTATIVE_AT_STATUS] = "TENTATIVE",
65 [EVENT_ATTENDEE_DELEGATED_AT_STATUS] = "DELEGATED",
66 [EVENT_ATTENDEE_COMPLETED_AT_STATUS] = "COMPLETED",
67 [EVENT_ATTENDEE_IN_PROCESS_AT_STATUS] = "IN-PROCESS",
70 #define _strlen(s) (((s) && *(s)) ? strlen(s) : 0)
72 static inline int __cal_vcalendar_make_alloc(cal_make_s *b, int n)
74 b->data = realloc(b->data, b->size + n);
76 retvm_if(!b->data, CALENDAR_ERROR_OUT_OF_MEMORY,
80 return CALENDAR_ERROR_NONE;
83 cal_make_s *_cal_vcalendar_make_new(void)
87 b = calloc(1, sizeof(cal_make_s));
92 b->data = calloc(1, sizeof(char));
104 static inline int __cal_vcalendar_make_folding(cal_make_s *b)
107 ret = __cal_vcalendar_make_alloc(b, _strlen(b->lbuf) + 3);
108 retv_if(ret != CALENDAR_ERROR_NONE, ret);
110 strncat(b->data, b->lbuf, b->size - _strlen(b->data) - 1);
111 strncat(b->data, "\r\n ", b->size - _strlen(b->data) - 1);
113 return CALENDAR_ERROR_NONE;
116 static inline int __cal_vcalendar_make_set_str(cal_make_s *b, const char *s)
123 remain_lbuf = sizeof(b->lbuf) - _strlen(b->lbuf);
124 remain_str = _strlen(s);
127 while ( remain_lbuf - 1 < remain_str) {
128 strncat(b->lbuf, s + k, remain_lbuf - 1);
129 k += remain_lbuf - 1;
130 remain_str -= remain_lbuf - 1;
131 ret = __cal_vcalendar_make_folding(b);
132 retv_if(ret != CALENDAR_ERROR_NONE, ret);
133 remain_lbuf = sizeof(b->lbuf);
136 strncat(b->lbuf, s + k, remain_lbuf - 1);
137 return CALENDAR_ERROR_NONE;
140 static inline int __cal_vcalendar_make_flush(cal_make_s *b)
143 ret = __cal_vcalendar_make_alloc(b, _strlen(b->lbuf) + 2);
144 retv_if(ret != CALENDAR_ERROR_NONE, ret);
146 strncat(b->data, b->lbuf, b->size - _strlen(b->data) - 1);
147 strncat(b->data, "\r\n", b->size - _strlen(b->data) - 1);
149 return CALENDAR_ERROR_NONE;
152 static int __cal_vcalendar_make_printf(cal_make_s *b, const char *s1, const char *s2)
157 ret = __cal_vcalendar_make_set_str(b, s1);
158 retv_if(ret != CALENDAR_ERROR_NONE, ret);
162 ret = __cal_vcalendar_make_set_str(b, s2);
163 retv_if(ret != CALENDAR_ERROR_NONE, ret);
166 return __cal_vcalendar_make_flush(b);
169 char *_cal_vcalendar_make_get_data(cal_make_s *b)
173 return strdup(b->data);
176 void _cal_vcalendar_make_free(cal_make_s **b)
188 static const char *__cal_vcalendar_make_itos(int y, int m, int d)
191 snprintf(buf, sizeof(buf), "%04d%02d%02d", y, m, d);
195 /////////////////////////////////////////////////////////////////////////////
196 static inline int __cal_vcalendar_make_class(cal_make_s *b, int v)
199 // TODO : Need to define enumeration of class property
204 c = "PRIVATE"; break;
206 c = "CONFIDENTIAL"; break;
210 __cal_vcalendar_make_printf(b, "CLASS:", c);
211 return CALENDAR_ERROR_NONE;
214 static inline int __cal_vcalendar_make_transp(cal_make_s *b, int v)
216 // TODO : Need to define enumeration of transp property
217 __cal_vcalendar_make_printf(b, "TRANSP:", v? "OPAQUE":"TRANSPARENT");
218 return CALENDAR_ERROR_NONE;
221 static inline int __cal_vcalendar_make_created(cal_make_s *b, long long int t)
223 char* tmp_tzid = NULL;
224 tmp_tzid = _cal_time_convert_ltos(NULL, t);
227 __cal_vcalendar_make_printf(b, "CREATED:", tmp_tzid);
230 return CALENDAR_ERROR_NONE;
233 static inline int __cal_vcalendar_make_dtstart(int version, cal_make_s *b, char *tzid, calendar_time_s *caltime)
235 retvm_if(caltime == NULL, -1, "Invalid argument: calendar_time_s is NULL");
237 if (caltime->time.utime == CALENDAR_TODO_NO_START_DATE)
239 DBG("No start date");
240 return CALENDAR_ERROR_NONE;
243 switch (caltime->type)
245 case CALENDAR_TIME_UTIME:
247 char* str_time = NULL;
248 if (version != 1 && NULL != tzid && strlen(tzid) > 0)
250 str_time = _cal_time_convert_ltos(tzid, caltime->time.utime);
254 snprintf(buf, sizeof(buf), "DTSTART;TZID=%s:", tzid);
255 __cal_vcalendar_make_printf(b, buf, str_time);
261 str_time = _cal_time_convert_ltos(NULL, caltime->time.utime);
264 __cal_vcalendar_make_printf(b, "DTSTART:", str_time);
271 case CALENDAR_TIME_LOCALTIME:
275 snprintf(buf, sizeof(buf), "%04d%02d%02dT000000",
276 caltime->time.date.year, caltime->time.date.month, caltime->time.date.mday);
277 __cal_vcalendar_make_printf(b, "DTSTART:", buf);
282 __cal_vcalendar_make_printf(b, "DTSTART;VALUE=DATE:",
283 __cal_vcalendar_make_itos(caltime->time.date.year,
284 caltime->time.date.month, caltime->time.date.mday));
289 return CALENDAR_ERROR_NONE;
292 static inline int __cal_vcalendar_make_last_mod(cal_make_s *b, long long int lli)
294 char* tmp_tzid = NULL;
295 tmp_tzid = _cal_time_convert_ltos(NULL, lli);
298 __cal_vcalendar_make_printf(b, "LAST-MODIFIED:",tmp_tzid);
301 return CALENDAR_ERROR_NONE;
304 int __cal_vcalendar_make_organizer(cal_make_s *b, char *cn, char *address)
308 ret = __cal_vcalendar_make_set_str(b, "ORGANIZER");
309 retv_if(ret != CALENDAR_ERROR_NONE, ret);
312 ret = __cal_vcalendar_make_set_str(b, ";CN=");
313 ret = __cal_vcalendar_make_set_str(b, cn);
314 retv_if(ret != CALENDAR_ERROR_NONE, ret);
317 if (address && *address)
319 ret = __cal_vcalendar_make_set_str(b, ":mailto:");
320 ret = __cal_vcalendar_make_set_str(b, address);
322 __cal_vcalendar_make_flush(b);
323 return CALENDAR_ERROR_NONE;
326 static inline int __cal_vcalendar_make_priority(cal_make_s *b, int v)
329 snprintf(tmp, sizeof(tmp), "%d", v);
330 __cal_vcalendar_make_printf(b, "PRIORITY:", tmp);
331 return CALENDAR_ERROR_NONE;
334 int __cal_vcalendar_make_dtstamp(cal_make_s *b, char *tzid)
336 char* tmp_tzid = NULL;
337 tmp_tzid = _cal_time_convert_ltos(tzid, _cal_time_get_now());
340 __cal_vcalendar_make_printf(b, "DTSTAMP:", tmp_tzid);
344 return CALENDAR_ERROR_NONE;
347 static inline int __cal_vcalendar_make_dtend(int version, cal_make_s *b, char *tzid, calendar_time_s *caltime)
349 retvm_if(caltime == NULL, -1, "Invalid argument: calendar_time_s is NULL");
351 if (caltime->time.utime == CALENDAR_TODO_NO_DUE_DATE)
353 DBG("No start date");
354 return CALENDAR_ERROR_NONE;
357 switch (caltime->type)
359 case CALENDAR_TIME_UTIME:
361 char* str_time = NULL;
362 if (version != 1 && NULL != tzid && strlen(tzid) > 0)
364 str_time = _cal_time_convert_ltos(tzid, caltime->time.utime);
368 snprintf(buf, sizeof(buf), "DTEND;TZID=%s:", tzid);
369 __cal_vcalendar_make_printf(b, buf, str_time);
375 str_time = _cal_time_convert_ltos(NULL, caltime->time.utime);
378 __cal_vcalendar_make_printf(b, "DTEND:", str_time);
385 case CALENDAR_TIME_LOCALTIME:
389 snprintf(buf, sizeof(buf), "%04d%02d%02dT000000",
390 caltime->time.date.year, caltime->time.date.month, caltime->time.date.mday);
391 __cal_vcalendar_make_printf(b, "DTEND:", buf);
396 __cal_vcalendar_make_printf(b, "DTEND;VALUE=DATE:",
397 __cal_vcalendar_make_itos(caltime->time.date.year,
398 caltime->time.date.month, caltime->time.date.mday));
403 return CALENDAR_ERROR_NONE;
406 static inline int __cal_vcalendar_make_due(int version, cal_make_s *b, char *tzid, calendar_time_s *caltime)
408 retvm_if(caltime == NULL, -1, "Invalid argument: calendar_time_s is NULL");
410 if (caltime->time.utime == CALENDAR_TODO_NO_DUE_DATE)
413 return CALENDAR_ERROR_NONE;
416 switch (caltime->type)
418 case CALENDAR_TIME_UTIME:
420 char* str_time = NULL;
421 if (version != 1 && NULL != tzid && strlen(tzid) > 0)
423 str_time = _cal_time_convert_ltos(tzid, caltime->time.utime);
427 snprintf(buf, sizeof(buf), "DUE;TZID=%s:", tzid);
428 __cal_vcalendar_make_printf(b, buf, str_time);
434 str_time = _cal_time_convert_ltos(NULL, caltime->time.utime);
437 __cal_vcalendar_make_printf(b, "DUE:", str_time);
444 case CALENDAR_TIME_LOCALTIME:
448 snprintf(buf, sizeof(buf), "%04d%02d%02dT000000",
449 caltime->time.date.year, caltime->time.date.month, caltime->time.date.mday);
450 __cal_vcalendar_make_printf(b, "DUE:", buf);
455 __cal_vcalendar_make_printf(b, "DUE:",
456 __cal_vcalendar_make_itos(caltime->time.date.year,
457 caltime->time.date.month, caltime->time.date.mday));
462 return CALENDAR_ERROR_NONE;
465 static inline int __cal_vcalendar_make_exdate(cal_make_s *b, char *s)
467 __cal_vcalendar_make_printf(b, "EXDATE:", s);
468 return CALENDAR_ERROR_NONE;
471 int __cal_vcalendar_make_attendee(cal_make_s *b, calendar_record_h attendee)
474 int role, status, rsvp;
476 char *delegate_uri = NULL;
477 char *delegator_uri = NULL;
481 retvm_if(attendee == NULL, CALENDAR_ERROR_INVALID_PARAMETER,
482 "Invalid argument: attendee is NULL");
484 ret = __cal_vcalendar_make_set_str(b, "ATTENDEE");
485 retv_if(ret != CALENDAR_ERROR_NONE, ret);
487 ret = calendar_record_get_str_p(attendee, _calendar_attendee.group, &group);
489 if (group && *group) {
490 ret = __cal_vcalendar_make_set_str(b, ";CUTYPE=");
491 ret = __cal_vcalendar_make_set_str(b, group);
492 retv_if(ret != CALENDAR_ERROR_NONE, ret);
495 // TODO : NO 'member' member in cal_participant_info_t
497 ret = calendar_record_get_int(attendee, _calendar_attendee.role, &role);
499 ret = __cal_vcalendar_make_set_str(b, ";ROLE=");
500 ret = __cal_vcalendar_make_set_str(b, _att_role[role]);
501 retv_if(ret != CALENDAR_ERROR_NONE, ret);
504 ret = calendar_record_get_int(attendee, _calendar_attendee.status, &status);
506 ret = __cal_vcalendar_make_set_str(b, ";PARTSTAT=");
507 ret = __cal_vcalendar_make_set_str(b, _att_st[status]);
508 retv_if(ret != CALENDAR_ERROR_NONE, ret);
511 ret = calendar_record_get_int(attendee, _calendar_attendee.rsvp, &rsvp);
513 ret = __cal_vcalendar_make_set_str(b, ";RSVP=");
514 ret = __cal_vcalendar_make_set_str(b, rsvp ? "TRUE" : "FALSE");
515 retv_if(ret != CALENDAR_ERROR_NONE, ret);
518 ret = calendar_record_get_str_p(attendee, _calendar_attendee.delegate_uri, &delegate_uri);
519 if (delegate_uri && *delegate_uri)
521 ret = __cal_vcalendar_make_set_str(b, ";DELEGATED-TO=");
522 ret = __cal_vcalendar_make_set_str(b, delegate_uri);
523 retv_if(ret != CALENDAR_ERROR_NONE, ret);
526 ret = calendar_record_get_str_p(attendee, _calendar_attendee.delegator_uri, &delegator_uri);
527 if (delegator_uri && *delegator_uri)
529 ret = __cal_vcalendar_make_set_str(b, ";DELEGATED-FROM=");
530 ret = __cal_vcalendar_make_set_str(b, delegator_uri);
531 retv_if(ret != CALENDAR_ERROR_NONE, ret);
534 // TODO : No 'sentby' member in cal_participant_info_t
536 ret = calendar_record_get_str_p(attendee, _calendar_attendee.name, &name);
538 ret = __cal_vcalendar_make_set_str(b, ";CN=");
539 ret = __cal_vcalendar_make_set_str(b, name);
540 retv_if(ret != CALENDAR_ERROR_NONE, ret);
543 ret = calendar_record_get_str_p(attendee, _calendar_attendee.email, &email);
546 ret = __cal_vcalendar_make_set_str(b, ":mailto:");
547 ret = __cal_vcalendar_make_set_str(b, email);
548 retv_if(ret != CALENDAR_ERROR_NONE, ret);
550 __cal_vcalendar_make_flush(b);
551 return CALENDAR_ERROR_NONE;
554 static const char *vl_dur(calendar_alarm_time_unit_type_e unit, int dur)
566 snprintf(d, sizeof(d), "%d", dur);
572 case CALENDAR_ALARM_TIME_UNIT_WEEK:
573 snprintf(buf + i, sizeof(buf) - i, "%sW", d);
575 case CALENDAR_ALARM_TIME_UNIT_DAY:
576 snprintf(buf + i, sizeof(buf) - i, "%sD", d);
578 case CALENDAR_ALARM_TIME_UNIT_HOUR:
579 snprintf(buf + i, sizeof(buf) - i, "T%sH", d);
581 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
582 snprintf(buf + i, sizeof(buf) - i, "T%sM", d);
591 int __cal_vcalendar_make_trigger(cal_make_s *b, int unit, int dur, long long int t)
593 retvm_if(unit < 0, CALENDAR_ERROR_NO_DATA, "tick unit is invalid");
595 if (unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC)
597 char* tmp_tzid = NULL;
598 tmp_tzid = _cal_time_convert_ltos(NULL, t);
601 __cal_vcalendar_make_printf(b, "TRIGGER;VALUE=DATE-TIME:",tmp_tzid);
608 __cal_vcalendar_make_printf(b, "TRIGGER:", vl_dur(unit, dur));
610 return CALENDAR_ERROR_NONE;
613 int __cal_vcalendar_make_action(cal_make_s *b)
615 return __cal_vcalendar_make_printf(b, "ACTION:", "AUDIO");
618 int __cal_vcalendar_make_audio(cal_make_s *b, calendar_record_h alarm)
624 ret = __cal_vcalendar_make_action(b);
625 retv_if(ret != CALENDAR_ERROR_NONE, ret);
627 ret = calendar_record_get_int(alarm, _calendar_alarm.tick, &tick);
628 ret = calendar_record_get_int(alarm, _calendar_alarm.tick_unit, &unit);
629 ret = calendar_record_get_lli(alarm, _calendar_alarm.time, &utime);
631 ret = __cal_vcalendar_make_trigger(b, unit, tick, utime);
632 retv_if(ret != CALENDAR_ERROR_NONE, ret);
634 // TODO : Support duration
635 // TODO : Support repeat (snooze)
636 return CALENDAR_ERROR_NONE;
640 int __cal_vcalendar_make_aalarm(cal_make_s *b, calendar_record_h record, calendar_record_h alarm)
647 calendar_time_s caltime = {0};
648 retvm_if(alarm == NULL, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid argument: alarm is NULL");
650 ret = calendar_record_get_uri_p(record, &uri);
651 if (CALENDAR_ERROR_NONE != ret)
653 ERR("calendar_record_get_uri_p() failed");
657 if (!strncmp(uri, _calendar_event._uri, strlen(_calendar_event._uri)))
659 type = CALENDAR_RECORD_TYPE_EVENT;
661 else if (!strncmp(uri, _calendar_todo._uri, strlen(_calendar_todo._uri)))
663 type = CALENDAR_RECORD_TYPE_TODO;
667 ERR("Invalid type(%s)", uri);
668 return CALENDAR_ERROR_INVALID_PARAMETER;
671 ret = calendar_record_get_int(alarm, _calendar_alarm.tick_unit, &unit);
672 if (CALENDAR_ERROR_NONE != ret)
674 ERR("calendar_record_get_int() failed");
677 ret = calendar_record_get_int(alarm, _calendar_alarm.tick, &tick);
678 if (CALENDAR_ERROR_NONE != ret)
680 ERR("calendar_record_get_int() failed");
686 case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
687 ret = calendar_record_get_lli(alarm, _calendar_alarm.time, &utime);
688 if (CALENDAR_ERROR_NONE != ret)
690 ERR("calendar_record_get_lli() failed");
698 case CALENDAR_RECORD_TYPE_EVENT:
699 ret = calendar_record_get_caltime(record, _calendar_event.start_time, &caltime);
700 if (CALENDAR_ERROR_NONE != ret)
702 ERR("calendar_record_get_caltime() failed");
705 switch (caltime.type)
707 case CALENDAR_TIME_UTIME:
708 utime = caltime.time.utime - (tick * unit);
711 case CALENDAR_TIME_LOCALTIME:
712 utime = _cal_time_convert_itol(NULL, caltime.time.date.year,
713 caltime.time.date.month, caltime.time.date.mday, 0, 0, 0);
714 utime -= (tick * unit);
719 case CALENDAR_RECORD_TYPE_TODO:
720 ret = calendar_record_get_caltime(record, _calendar_todo.due_time, &caltime);
721 if (CALENDAR_ERROR_NONE != ret)
723 ERR("calendar_record_get_caltime() failed");
726 switch (caltime.type)
728 case CALENDAR_TIME_UTIME:
729 utime = caltime.time.utime - (tick * unit);
732 case CALENDAR_TIME_LOCALTIME:
733 utime = _cal_time_convert_itol(NULL, caltime.time.date.year,
734 caltime.time.date.month, caltime.time.date.mday, 0, 0, 0);
735 utime -= (tick * unit);
743 char *calstr = _cal_time_convert_ltos(NULL, utime);
746 ret = __cal_vcalendar_make_printf(b, "AALARM:", calstr);
749 return CALENDAR_ERROR_NONE;
752 int __cal_vcalendar_make_alarm(cal_make_s *b, calendar_record_h alarm)
755 retvm_if(alarm == NULL, CALENDAR_ERROR_INVALID_PARAMETER,
756 "Invalid argument: alarm is NULL");
758 // TODO : No action type is defined
759 ret = __cal_vcalendar_make_printf(b, "BEGIN:VALARM", NULL);
760 retv_if(ret != CALENDAR_ERROR_NONE, ret);
762 ret = __cal_vcalendar_make_audio(b, alarm);
763 retv_if(ret != CALENDAR_ERROR_NONE, ret);
769 __cal_vcalendar_make_printf(b, "END:VALARM", NULL);
770 return CALENDAR_ERROR_NONE;
773 int __cal_vcalendar_make_rrule_append_mday(char *buf, char *mday)
781 if (NULL == buf || NULL == mday)
783 ERR("Invalid parameter");
784 return CALENDAR_ERROR_INVALID_PARAMETER;
787 t = g_strsplit(mday, ",", -1);
789 ERR("g_strsplit failed");
791 return CALENDAR_ERROR_OUT_OF_MEMORY;
793 length = g_strv_length(t);
794 for (i = 0; i < length; i++)
815 return CALENDAR_ERROR_NONE;
818 int __cal_vcalendar_make_rrule_append_wday(char *buf, char *wday)
825 char buf_temp[8] = {0};
828 t = g_strsplit(wday, ",", -1);
830 ERR("g_strsplit failed");
832 return CALENDAR_ERROR_OUT_OF_MEMORY;
834 length = g_strv_length(t);
835 for (i = 0; i < length; i++)
838 while (*p == ' ') // del space
843 while (p[j] == '+' || p[j] == '-' || (p[j] >= '1' && p[j] <= '9'))
851 snprintf(buf_temp, j, "%s", p + 1);
852 num = atoi(buf_temp);
856 strcat(buf, buf_temp);
863 snprintf(buf_temp, j + 1, "%s", p);
864 num = atoi(buf_temp);
868 strcat(buf, buf_temp);
879 ERR("Out of 1.0 spec");
881 DBG("%d num(%d) val[%s]", i, num, p + j);
891 return CALENDAR_ERROR_NONE;
894 int __cal_vcalendar_make_rrule_append_until(char *buf, calendar_record_h record)
899 char *until_str = NULL;
900 char buf_range[256] = {0};
901 calendar_time_s caltime;
903 ret = calendar_record_get_int(record, _calendar_event.range_type, &range_type);
904 if (CALENDAR_ERROR_NONE != ret)
906 ERR("calendar_record_get_int() failed");
912 case CALENDAR_RANGE_COUNT:
913 ret = calendar_record_get_int(record, _calendar_event.count, &count);
914 if (CALENDAR_ERROR_NONE != ret)
916 ERR("calendar_record_get_int() failed");
919 snprintf(buf_range, sizeof(buf_range), "#%d", count);
922 case CALENDAR_RANGE_UNTIL:
923 memset(&caltime, 0x0, sizeof(calendar_time_s));
924 ret = calendar_record_get_caltime(record, _calendar_event.until_time, &caltime);
925 if (CALENDAR_ERROR_NONE != ret)
927 ERR("calendar_record_get_caltime() failed");
930 switch (caltime.type)
932 case CALENDAR_TIME_UTIME:
933 until_str = _cal_time_convert_ltos(NULL, caltime.time.utime);
934 snprintf(buf_range, sizeof(buf_range), "%s", until_str);
938 case CALENDAR_TIME_LOCALTIME:
939 snprintf(buf_range, sizeof(buf_range), "%04d%02d%02dT000000Z",
940 caltime.time.date.year, caltime.time.date.month, caltime.time.date.mday);
945 case CALENDAR_RANGE_NONE:
946 snprintf(buf_range, sizeof(buf_range), "#0");
949 strcat(buf, buf_range);
951 return CALENDAR_ERROR_NONE;
954 static int __cal_vcalendar_make_rrule_ver1(cal_make_s *b, calendar_record_h record)
959 char *byyearday = NULL;
960 char *bymonth = NULL;
961 char *bymonthday = NULL;
965 ret = calendar_record_get_int(record, _calendar_event.freq, &freq);
966 if (CALENDAR_ERROR_NONE != ret)
968 ERR("calendar_record_get_int() failed");
971 ret = calendar_record_get_int(record, _calendar_event.interval, &interval);
972 if (CALENDAR_ERROR_NONE != ret)
974 ERR("calendar_record_get_int() failed");
977 ret = calendar_record_get_str_p(record, _calendar_event.bymonthday, &byyearday);
978 if (CALENDAR_ERROR_NONE != ret)
980 ERR("calendar_record_get_str_p() failed");
983 ret = calendar_record_get_str_p(record, _calendar_event.bymonth, &bymonth);
984 if (CALENDAR_ERROR_NONE != ret)
986 ERR("calendar_record_get_str_p() failed");
989 ret = calendar_record_get_str_p(record, _calendar_event.byday, &byday);
990 if (CALENDAR_ERROR_NONE != ret)
992 ERR("calendar_record_get_str_p() failed");
995 ret = calendar_record_get_str_p(record, _calendar_event.bymonthday, &bymonthday);
996 if (CALENDAR_ERROR_NONE != ret)
998 ERR("calendar_record_get_str_p() failed");
1003 case CALENDAR_RECURRENCE_DAILY:
1004 snprintf(buf, sizeof(buf), "D%d ", interval);
1007 case CALENDAR_RECURRENCE_WEEKLY:
1008 snprintf(buf, sizeof(buf), "W%d ", interval);
1009 __cal_vcalendar_make_rrule_append_wday(buf, byday);
1012 case CALENDAR_RECURRENCE_MONTHLY:
1015 snprintf(buf, sizeof(buf), "MP%d ", interval);
1016 __cal_vcalendar_make_rrule_append_wday(buf, byday);
1018 else if (bymonthday)
1020 snprintf(buf, sizeof(buf), "MD%d ", interval);
1021 __cal_vcalendar_make_rrule_append_mday(buf, bymonthday);
1025 ERR("Invalid parameter");
1029 case CALENDAR_RECURRENCE_YEARLY:
1032 snprintf(buf, sizeof(buf), "YM%d ", interval);
1033 __cal_vcalendar_make_rrule_append_mday(buf, bymonth);
1037 snprintf(buf, sizeof(buf), "YD%d ", interval);
1038 __cal_vcalendar_make_rrule_append_mday(buf, byyearday);
1042 ERR("Invalid parameter");
1047 ERR("Invalid parameter");
1051 __cal_vcalendar_make_rrule_append_until(buf, record);
1053 return __cal_vcalendar_make_printf(b, "RRULE:", buf);
1056 static int __cal_vcalendar_make_rrule(cal_make_s *b, int freq, calendar_record_h record)
1061 char buf[1024] = {0};
1063 calendar_time_s caltime = {0};
1066 case CALENDAR_RECURRENCE_DAILY:
1067 strcat(buf, "FREQ=DAILY");
1069 case CALENDAR_RECURRENCE_WEEKLY:
1070 strcat(buf, "FREQ=WEEKLY");
1072 case CALENDAR_RECURRENCE_MONTHLY:
1073 strcat(buf, "FREQ=MONTHLY");
1075 case CALENDAR_RECURRENCE_YEARLY:
1076 strcat(buf, "FREQ=YEARLY");
1082 ret = calendar_record_get_int(record, _calendar_event.interval, &num);
1083 snprintf(tmp, sizeof(tmp), "%d", num);
1084 strcat(buf, ";INTERVAL=");
1087 ret = calendar_record_get_str_p(record, _calendar_event.bysecond, &text);
1089 strcat(buf, ";BYSECOND=");
1094 ret = calendar_record_get_str_p(record, _calendar_event.byminute, &text);
1096 strcat(buf, ";BYMINUTE=");
1101 ret = calendar_record_get_str_p(record, _calendar_event.byhour, &text);
1103 strcat(buf, ";BYHOUR=");
1108 ret = calendar_record_get_str_p(record, _calendar_event.byday, &text);
1110 strcat(buf, ";BYDAY=");
1115 ret = calendar_record_get_str_p(record, _calendar_event.bymonthday, &text);
1117 strcat(buf, ";BYMONTHDAY=");
1122 ret = calendar_record_get_str_p(record, _calendar_event.byyearday, &text);
1124 strcat(buf, ";BYYEARDAY=");
1129 ret = calendar_record_get_str_p(record, _calendar_event.byweekno, &text);
1131 strcat(buf, ";BYWEEKNO=");
1136 ret = calendar_record_get_str_p(record, _calendar_event.bymonth, &text);
1138 strcat(buf, ";BYMONTH=");
1143 ret = calendar_record_get_str_p(record, _calendar_event.bysetpos, &text);
1145 strcat(buf, ";BYSETPOS=");
1150 num = CALENDAR_SUNDAY; // default set
1151 ret = calendar_record_get_int(record, _calendar_event.wkst, &num);
1152 strcat(buf, ";WKST=");
1154 case CALENDAR_SUNDAY:
1157 case CALENDAR_MONDAY:
1160 case CALENDAR_TUESDAY:
1163 case CALENDAR_WEDNESDAY:
1166 case CALENDAR_THURSDAY:
1169 case CALENDAR_FRIDAY:
1172 case CALENDAR_SATURDAY:
1177 ret = calendar_record_get_int(record, _calendar_event.range_type, &num);
1179 case CALENDAR_RANGE_COUNT:
1180 ret = calendar_record_get_int(record, _calendar_event.count, &num);
1181 snprintf(tmp, sizeof(tmp), "%d", num);
1182 strcat(buf, ";COUNT=");
1186 case CALENDAR_RANGE_UNTIL:
1187 ret = calendar_record_get_caltime(record, _calendar_event.until_time, &caltime);
1189 if (caltime.type == CALENDAR_TIME_UTIME)
1191 char *tmp_tzid = NULL;
1192 tmp_tzid = _cal_time_convert_ltos(NULL, caltime.time.utime);
1195 snprintf(tmp, sizeof(tmp), "%s", tmp_tzid);
1201 snprintf(tmp, sizeof(tmp), "%04d%02d%02dT000000Z",
1202 caltime.time.date.year,
1203 caltime.time.date.month,
1204 caltime.time.date.mday);
1206 strcat(buf, ";UNTIL=");
1210 case CALENDAR_RANGE_NONE:
1215 return __cal_vcalendar_make_printf(b, "RRULE:", buf);
1217 /////////////////////////////////////////////////////////////////////////////
1219 int __cal_vcalendar_make_child_extended(cal_make_s *b, calendar_record_h child)
1226 ERR("Invalid argument: child is NULL");
1227 return CALENDAR_ERROR_INVALID_PARAMETER;
1230 ret = calendar_record_get_str_p(child, _calendar_extended_property.key, &key);
1231 if (CALENDAR_ERROR_NONE != ret)
1233 ERR("calendar_record_get_str_p() failed");
1236 if (NULL == key || strncmp(key, "X-", strlen("X-")))
1238 DBG("Not extended for vcalendar[%s]", key);
1239 return CALENDAR_ERROR_NONE;
1242 ret = calendar_record_get_str_p(child, _calendar_extended_property.value, &value);
1243 if (CALENDAR_ERROR_NONE != ret)
1245 ERR("calendar_record_get_str_p() failed");
1248 ret = __cal_vcalendar_make_printf(b, key, value);
1249 if (CALENDAR_ERROR_NONE != ret)
1251 ERR("__cal_vcalendar_make_printf() failed");
1255 return CALENDAR_ERROR_NONE;
1258 int __cal_vcalendar_make_printf_str_p(calendar_record_h record, unsigned int property_id, cal_make_s *b, const char *property_str)
1261 char *strval = NULL;
1263 ret = calendar_record_get_str_p(record, property_id, &strval);
1264 if (CALENDAR_ERROR_NONE != ret)
1266 ERR("calendar_record_get_str_p() failed(ret:%d): categories", ret);
1269 if (strval && (strlen(strval) > 0))
1271 ret = __cal_vcalendar_make_printf(b, property_str, strval);
1272 if (CALENDAR_ERROR_NONE != ret)
1274 ERR("__cal_vcalendar_make_printf() failed(ret:%d)", ret);
1278 return CALENDAR_ERROR_NONE;
1281 int __cal_vcalendar_make_schedule(int version, cal_make_s *b, calendar_record_h record)
1286 char *strval = NULL;
1287 char *strval2 = NULL;
1288 calendar_time_s caltime = {0};
1292 ret = calendar_record_get_uri_p(record, &uri);
1294 //_cal_db_rrule_fill_record(record);
1296 ret = __cal_vcalendar_make_printf(b, "BEGIN:VEVENT", NULL);
1297 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1300 ret = calendar_record_get_int(record, _calendar_event.sensitivity, &intval);
1301 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1302 "Failed to get sensitivity(%d)", ret);
1304 __cal_vcalendar_make_class(b, intval);
1305 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1308 ret = calendar_record_get_int(record, _calendar_event.busy_status, &intval);
1309 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1310 "Failed to get busy_status(%d)", ret);
1312 ret = __cal_vcalendar_make_transp(b, intval);
1313 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1316 ret = calendar_record_get_str_p(record, _calendar_event.start_tzid, &tzid);
1317 ret = calendar_record_get_caltime(record, _calendar_event.start_time, &caltime);
1318 if (ret != CALENDAR_ERROR_NONE) {
1319 ERR("Failed to get start_time(%d)", ret);
1322 ret = __cal_vcalendar_make_dtstart(version, b, tzid, &caltime);
1323 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get dtstart(%d)", ret);
1327 /* keis want to skip for there potential error.
1328 ret = calendar_record_get_lli(record, _calendar_event.created_time, &llival);
1329 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1330 "Failed to get created_time(%d)", ret);
1332 ret = __cal_vcalendar_make_created(b, llival);
1333 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1337 __cal_vcalendar_make_printf_str_p(record, _calendar_event.description, b, "DESCRIPTION:");
1340 ret = calendar_record_get_int(record, _calendar_event.freq, &freq);
1341 retvm_if(ret != CALENDAR_ERROR_NONE, ret,
1342 "Failed to get last_modified_time(%d)", ret);
1348 ret = __cal_vcalendar_make_rrule_ver1(b, record);
1352 __cal_vcalendar_make_rrule(b, freq, record);
1357 /* keis want to skip for there potential error.
1358 ret = calendar_record_get_lli(record, _calendar_event.last_modified_time, &llival);
1359 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1360 "Failed to get last_modified_time(%d)", ret);
1362 ret = __cal_vcalendar_make_last_mod(b, llival);
1363 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1366 __cal_vcalendar_make_printf_str_p(record, _calendar_event.location, b, "LOCATION:");
1371 ret = calendar_record_get_str_p(record, _calendar_event.organizer_name, &strval);
1372 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1373 "Failed to get organizer_name(%d)", ret);
1375 ret = calendar_record_get_str_p(record, _calendar_event.organizer_email, &strval2);
1376 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1377 "Failed to get organizer_email(%d)", ret);
1379 if (strval || strval2) {
1380 ret = __cal_vcalendar_make_organizer(b, strval, strval2);
1381 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1384 DBG("No organizer name or email");
1388 ret = calendar_record_get_int(record, _calendar_event.priority, &intval);
1389 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1390 "Failed to get priority(%d)", ret);
1392 DBG("priority(%d)", intval);
1393 ret = __cal_vcalendar_make_priority(b, intval);
1394 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1399 /* keis want to skip for there potential error.
1400 ret = __cal_vcalendar_make_dtstamp(b, tzid);
1401 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1405 __cal_vcalendar_make_printf_str_p(record, _calendar_event.summary, b, "SUMMARY:");
1408 ret = calendar_record_get_caltime(record, _calendar_event.end_time, &caltime);
1409 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1410 "Failed to get end_time(%d)", ret);
1412 ret = __cal_vcalendar_make_dtend(version, b, tzid, &caltime);
1413 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get end(%d)", ret);
1416 __cal_vcalendar_make_printf_str_p(record, _calendar_event.categories, b, "CATEGORIES:");
1419 __cal_vcalendar_make_printf_str_p(record, _calendar_event.uid, b, "UID:");
1422 __cal_vcalendar_make_printf_str_p(record, _calendar_event.exdate, b, "EXDATE:");
1425 calendar_record_h child = NULL;
1429 ret = calendar_record_get_child_record_count(record,
1430 _calendar_event.calendar_attendee, &count);
1431 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1432 "Failed to get child count(%d)", ret);
1437 ret = calendar_record_get_child_record_at_p(record,
1438 _calendar_event.calendar_attendee, count, &child);
1439 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1440 "Failed to get child attendee(%d)", ret);
1442 ret = __cal_vcalendar_make_attendee(b, child);
1443 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1455 // In ver 1.0, only first alarm will be dealt with.
1456 ret = calendar_record_get_child_record_count(record, _calendar_event.calendar_alarm, &count);
1457 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get child count(%d)", ret);
1460 ret = calendar_record_get_child_record_at_p(record, _calendar_event.calendar_alarm, 0, &child);
1461 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get child alarm(%d)", ret);
1463 ret = __cal_vcalendar_make_aalarm(b, record, child);
1464 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1468 DBG("No alarm in ver1.0");
1473 ret = calendar_record_get_child_record_count(record, _calendar_event.calendar_alarm, &count);
1474 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get child count(%d)", ret);
1479 ret = calendar_record_get_child_record_at_p(record, _calendar_event.calendar_alarm, count, &child);
1480 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get child alarm(%d)", ret);
1482 ret = __cal_vcalendar_make_alarm(b, child);
1483 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1488 DBG("No alarm in ver2.0");
1494 ret = calendar_record_get_child_record_count(record, _calendar_event.extended, &count);
1495 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get child count(%d)", ret);
1500 ret = calendar_record_get_child_record_at_p(record, _calendar_event.extended, count, &child);
1501 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get child alarm(%d)", ret);
1503 ret = __cal_vcalendar_make_child_extended(b, child);
1504 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1512 return __cal_vcalendar_make_printf(b, "END:VEVENT", NULL);
1515 int __cal_vcalendar_make_todo(int version, cal_make_s *b, calendar_record_h record)
1519 calendar_time_s caltime = {0};
1523 ret = calendar_record_get_uri_p(record, &uri);
1525 //_cal_db_rrule_fill_record(record);
1527 ret = __cal_vcalendar_make_printf(b, "BEGIN:VTODO", NULL);
1528 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1531 ret = calendar_record_get_int(record, _calendar_todo.sensitivity, &intval);
1532 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1533 "Failed to get sensitivity(%d)", ret);
1535 __cal_vcalendar_make_class(b, intval);
1536 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1539 ret = calendar_record_get_str_p(record, _calendar_todo.start_tzid, &tzid);
1540 ret = calendar_record_get_caltime(record, _calendar_todo.start_time, &caltime);
1541 if (ret != CALENDAR_ERROR_NONE) {
1542 ERR("Failed to get start_time(%d)", ret);
1545 ret = __cal_vcalendar_make_dtstart(version, b, tzid, &caltime);
1546 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1547 "Failed to get dtstart(%d)", ret);
1550 /* keis want to skip for there potential error.
1551 ret = calendar_record_get_lli(record, _calendar_todo.created_time, &llival);
1552 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1553 "Failed to get created_time(%d)", ret);
1555 ret = __cal_vcalendar_make_created(b, llival);
1556 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1560 __cal_vcalendar_make_printf_str_p(record, _calendar_todo.description, b, "DESCRIPTION:");
1566 /* keis want to skip for there potential error.
1567 ret = calendar_record_get_lli(record, _calendar_todo.last_modified_time, &llival);
1568 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1569 "Failed to get last_modified_time(%d)", ret);
1571 ret = __cal_vcalendar_make_last_mod(b, llival);
1572 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1576 __cal_vcalendar_make_printf_str_p(record, _calendar_todo.location, b, "LOCATION:");
1579 ret = calendar_record_get_int(record, _calendar_todo.priority, &intval);
1580 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1581 "Failed to get priority(%d)", ret);
1583 DBG("priority(%d)", intval);
1584 ret = __cal_vcalendar_make_priority(b, intval);
1585 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1590 /* keis want to skip for there potential error.
1591 ret = __cal_vcalendar_make_dtstamp(b, tzid);
1592 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1596 __cal_vcalendar_make_printf_str_p(record, _calendar_todo.summary, b, "SUMMARY:");
1599 ret = calendar_record_get_caltime(record, _calendar_todo.due_time, &caltime);
1600 retvm_if(ret != CALENDAR_ERROR_NONE, -1,
1601 "Failed to get due_time(%d)", ret);
1603 ret = __cal_vcalendar_make_due(version, b, tzid, &caltime);
1604 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "__cal_vcalendar_make_due() failed(%d)", ret);
1607 __cal_vcalendar_make_printf_str_p(record, _calendar_todo.categories, b, "CATEGORIES:");
1610 __cal_vcalendar_make_printf_str_p(record, _calendar_todo.uid, b, "UID:");
1614 calendar_record_h child = NULL;
1619 // In ver 1.0, only first alarm will be dealt with.
1620 ret = calendar_record_get_child_record_count(record, _calendar_todo.calendar_alarm, &count);
1621 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get child count(%d)", ret);
1624 ret = calendar_record_get_child_record_at_p(record, _calendar_todo.calendar_alarm, 0, &child);
1625 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get child alarm(%d)", ret);
1627 ret = __cal_vcalendar_make_aalarm(b, record, child);
1628 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1632 DBG("No alarm in ver1.0");
1637 ret = calendar_record_get_child_record_count(record, _calendar_todo.calendar_alarm, &count);
1638 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get child count(%d)", ret);
1643 ret = calendar_record_get_child_record_at_p(record, _calendar_todo.calendar_alarm, count, &child);
1644 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get child alarm(%d)", ret);
1646 ret = __cal_vcalendar_make_alarm(b, child);
1647 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1652 DBG("No alarm in ver2.0");
1658 ret = calendar_record_get_child_record_count(record, _calendar_todo.extended, &count);
1659 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get child count(%d)", ret);
1664 ret = calendar_record_get_child_record_at_p(record, _calendar_todo.extended, count, &child);
1665 retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get child alarm(%d)", ret);
1667 ret = __cal_vcalendar_make_child_extended(b, child);
1668 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1675 return __cal_vcalendar_make_printf(b, "END:VTODO", NULL);
1678 int __cal_vcalendar_make_parent_extended(cal_make_s *b, calendar_list_h list, int *has_extended, int *version)
1680 int ret = CALENDAR_ERROR_NONE;
1682 cal_list_s *cal_list = (cal_list_s *)list;
1686 ERR("Invalid parameter: list is NULL");
1687 return CALENDAR_ERROR_DB_FAILED;
1690 l = g_list_first(cal_list->record);
1694 calendar_record_h record = (calendar_record_h)l->data;
1695 calendar_record_get_uri_p(record, &uri);
1696 if (strncmp(uri, _calendar_extended_property._uri, strlen(_calendar_extended_property._uri)))
1703 cal_extended_s *extended = (cal_extended_s *)record;
1704 if (NULL == extended)
1706 ERR("extended is NULL");
1707 return CALENDAR_ERROR_DB_FAILED;
1709 ret = __cal_vcalendar_make_printf(b, extended->key, extended->value);
1710 DBG("extended key[%s] value[%s]", extended->key, extended->value);
1711 if (!strncmp(extended->key, "VERSION", strlen("VERSION")))
1713 if (strstr(extended->value, "1.0"))
1722 DBG("version (%s)", extended->value);
1727 return CALENDAR_ERROR_NONE;
1730 int _cal_vcalendar_make_vcalendar(cal_make_s *b, calendar_list_h list)
1734 int has_extended = 0;
1736 calendar_record_h record;
1738 ret = __cal_vcalendar_make_printf(b, "BEGIN:VCALENDAR", NULL);
1739 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1741 ret = __cal_vcalendar_make_parent_extended(b, list, &has_extended, &version);
1742 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1744 if (has_extended == 0)
1746 /* keis want to skip for there potential error.
1747 ret = __cal_vcalendar_make_printf(b, "CALSCALE:GREGORIAN", NULL);
1748 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1750 ret = __cal_vcalendar_make_printf(b, "PRODID:-//Samsung Electronics//Calendar//EN", NULL);
1751 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1754 ret = __cal_vcalendar_make_printf(b, "VERSION:2.0", NULL);
1755 retv_if(ret != CALENDAR_ERROR_NONE, ret);
1758 ret = calendar_list_first(list);
1759 retvm_if(ret != CALENDAR_ERROR_NONE, ret,
1760 "calendar_list_first() Failed");
1764 ret = calendar_list_get_current_record_p(list, &record);
1765 if (ret != CALENDAR_ERROR_NONE)
1767 ERR("Failed to get current record(%d)", ret);
1770 ret = calendar_record_get_uri_p(record, &uri);
1771 if (!strcmp(uri, CALENDAR_VIEW_EVENT))
1773 ret = __cal_vcalendar_make_schedule(version, b, record);
1776 else if (!strcmp(uri, CALENDAR_VIEW_TODO))
1778 ret = __cal_vcalendar_make_todo(version, b, record);
1782 if (ret != CALENDAR_ERROR_NONE)
1784 ERR("__cal_vcalendar_make_schedule() Failed(%d)", ret);
1787 } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
1789 __cal_vcalendar_make_printf(b, "END:VCALENDAR", NULL);
1791 return CALENDAR_ERROR_NONE;