3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "vcalendar_string_util.h"
20 #define DATE_TIME_LENGTH 16
23 #define EXPORT_API __attribute__ ((visibility("default")))
27 // usage / rrule converting
28 if (strstr(temp_agent_data, "\r\nRRULE:") != NULL) {
29 _DEBUG_INFO("rrule is founed");
30 temp_agent_data = _replace_rrule_data(temp_agent_data);
33 static char * _replace_rrule_data(char *origin)
36 retvm_if(origin == NULL, origin, "origin is NULL.");
38 char *str_new_rrule = NULL;
39 char *str_end_time = NULL;
40 char *freq_loc = NULL;
41 char *str_byday = NULL;
42 char *str_interval = NULL;
43 char *str_period_until = NULL;
44 char *str_period_count = NULL;
45 calendar_date_type_e cal_type = CALENDAR_DATE_TYPE_ONTIME;
47 if ((freq_loc = strstr(origin, RRULE_KEYWORD_FREQ_WEEKLY)) != NULL) {
48 _DEBUG_INFO("this is weekly data");
50 else if ((freq_loc = strstr(origin, RRULE_KEYWORD_FREQ_MONTHLY)) != NULL) {
51 _DEBUG_INFO("this is monthly data");
53 else if ((freq_loc = strstr(origin, RRULE_KEYWORD_FREQ_YEARLY)) != NULL) {
54 _DEBUG_INFO("this is yearly data");
56 else if ((freq_loc = strstr(origin, RRULE_KEYWORD_FREQ_DAILY)) != NULL) {
57 _DEBUG_INFO("this is daily data");
60 _DEBUG_ERROR("this is an undefined rrule type. origin = %s", origin);
64 char *temp_rrule = NULL;
65 if((temp_rrule = strstr(freq_loc, "RRULE:")) == NULL) {
66 _DEBUG_ERROR("temp_rrule is NULL");
70 char *temp_rrule2 = NULL;
71 if((temp_rrule2 = strstr(temp_rrule, "\r\n")) == NULL) {
72 _DEBUG_ERROR("temp_rrule2 is NULL");
76 char str_origin_rrule[100] = {0,};
77 int origin_rrule_length = strlen(temp_rrule) - strlen(temp_rrule2) + 2; // '2' means of '\r\n'
78 if (origin_rrule_length <= 0) {
79 _DEBUG_ERROR("origin_rrule_length <= 0");
83 strncpy(str_origin_rrule, temp_rrule, origin_rrule_length);
84 _DEBUG_INFO("str_origin_rrule = %s", str_origin_rrule);
86 if (strstr(origin, RRULE_KEYWORD_FREQ_WEEKLY) != NULL) {
87 str_byday = get_value_by_token(freq_loc, RRULE_KEYWORD_BYDAY, ";");
88 cal_type = CALENDAR_DATE_TYPE_WEEK;
90 else if (strstr(origin, RRULE_KEYWORD_FREQ_MONTHLY) != NULL) {
91 str_byday = get_value_by_token(freq_loc, RRULE_KEYWORD_BYMONTHDAY, ";");
92 cal_type = CALENDAR_DATE_TYPE_MONTH;
94 else if (strstr(origin, RRULE_KEYWORD_FREQ_YEARLY) != NULL) {
95 str_byday = get_value_by_token(freq_loc, RRULE_KEYWORD_BYMONTHDAY, ";");
96 cal_type = CALENDAR_DATE_TYPE_YEAR;
98 else if (strstr(origin, RRULE_KEYWORD_FREQ_DAILY) != NULL) {
99 cal_type = CALENDAR_DATE_TYPE_DAY;
102 _DEBUG_ERROR("this is an undefined rrule type. origin = %s", origin);
106 if ((cal_type != CALENDAR_DATE_TYPE_DAY) && (str_byday == NULL || strlen(str_byday) <= 0)) {
107 _DEBUG_ERROR("str_byday is null");
111 str_interval = get_value_by_token(freq_loc, RRULE_KEYWORD_INTERVAL, ";");
112 str_period_until = get_value_by_token(freq_loc, RRULE_KEYWORD_UNTIL, ";");
113 str_period_count = get_value_by_token(freq_loc, RRULE_KEYWORD_COUNT, ";");
115 if (str_interval == NULL || strlen(str_interval) <= 0) {
116 _DEBUG_ERROR("str_interval is null");
120 if (str_period_until == NULL && str_period_count == NULL) {
121 str_end_time = (char *)calloc(2, sizeof(char));
122 if (str_end_time == NULL) {
123 _DEBUG_ERROR("str_end_time is null");
126 strncpy(str_end_time, "\r\n", 2);
127 _DEBUG_INFO("endless = %s", str_end_time);
129 else if (str_period_until != NULL) {
130 str_end_time = (char *)calloc(strlen(str_period_until), sizeof(char));
131 if (str_end_time == NULL) {
132 _DEBUG_ERROR("str_end_time is null");
135 strncpy(str_end_time, str_period_until, strlen(str_period_until));
136 _DEBUG_INFO("until = %s", str_end_time);
138 else if (str_period_count != NULL) {
139 str_end_time = (char *)calloc(strlen(str_period_count)+1, sizeof(char));
140 if (str_end_time == NULL) {
141 _DEBUG_ERROR("str_end_time is null");
144 snprintf(str_end_time, strlen(str_period_count)+1, "#%s", str_period_count);
145 _DEBUG_INFO("count = %s", str_end_time);
148 _DEBUG_ERROR("there is an error");
152 int new_rrule_length = 0;
153 if (strstr(origin, RRULE_KEYWORD_FREQ_WEEKLY) != NULL) {
154 new_rrule_length = strlen("RRULE:W") + strlen(str_interval) + strlen(" ") + strlen(str_byday) + strlen(" ") + strlen(str_end_time) + 1;
156 else if (strstr(origin, RRULE_KEYWORD_FREQ_MONTHLY) != NULL) {
157 new_rrule_length = strlen("RRULE:MD") + strlen(str_interval) + strlen(" ") + strlen(str_byday) + strlen(" ") + strlen(str_end_time) + 1;
159 else if (strstr(origin, RRULE_KEYWORD_FREQ_YEARLY) != NULL) {
160 new_rrule_length = strlen("RRULE:YD") + strlen(str_interval) + strlen(" ") + strlen(str_end_time) + 1;
162 else if (strstr(origin, RRULE_KEYWORD_FREQ_DAILY) != NULL) {
163 new_rrule_length = strlen("RRULE:D") + strlen(str_interval) + strlen(" ") + strlen(str_end_time) + 1;
166 _DEBUG_ERROR("this is an undefined rrule type. origin = %s", origin);
170 if (new_rrule_length <= 0) {
171 _DEBUG_ERROR("new_rrule_length(%d) <= 0", new_rrule_length);
175 str_new_rrule = (char *)calloc(new_rrule_length, sizeof(char));
176 if (str_new_rrule == NULL) {
177 _DEBUG_ERROR("str_new_rrule calloc failed");
181 if (strstr(origin, RRULE_KEYWORD_FREQ_WEEKLY) != NULL) {
182 snprintf(str_new_rrule, new_rrule_length, "RRULE:W%s %s %s", str_interval, str_byday, str_end_time);
184 else if (strstr(origin, RRULE_KEYWORD_FREQ_MONTHLY) != NULL) {
185 snprintf(str_new_rrule, new_rrule_length, "RRULE:MD%s %s %s", str_interval, str_byday, str_end_time);
187 else if (strstr(origin, RRULE_KEYWORD_FREQ_YEARLY) != NULL) {
188 snprintf(str_new_rrule, new_rrule_length, "RRULE:YD%s %s", str_interval, str_end_time);
190 else if (strstr(origin, RRULE_KEYWORD_FREQ_DAILY) != NULL) {
191 snprintf(str_new_rrule, new_rrule_length, "RRULE:D%s %s", str_interval, str_end_time);
194 _DEBUG_ERROR("this is an undefined rrule type. origin = %s", origin);
198 _DEBUG_INFO("str_new_rrule = %s", str_new_rrule);
199 _DEBUG_INFO("str_origin_rrule = %s", str_origin_rrule);
201 char *new_agent_data = replace_string(origin, str_origin_rrule, str_new_rrule);
203 origin = new_agent_data;
215 if (str_period_until) {
216 free(str_period_until);
217 str_period_until = NULL;
219 if (str_period_count) {
220 free(str_period_count);
221 str_period_count = NULL;
229 str_new_rrule = NULL;
232 _DEBUG_INFO("origin = %s", origin);
237 // usage / alarm converting
238 if (strstr(temp_agent_data, "\r\nBEGIN:VALARM") != NULL) {
239 _DEBUG_INFO("alarm is founed");
240 temp_agent_data = _replace_alarm_data(temp_agent_data);
243 static char * _replace_alarm_data(char *origin)
246 retvm_if(origin == NULL, origin, "origin is NULL.");
249 char *str_new_alarm = NULL;
250 char *freq_loc = NULL;
251 char *str_trigger = NULL;
252 char *str_customized_trigger = NULL;
253 char *str_interval = NULL;
254 calendar_date_type_e cal_type = CALENDAR_DATE_TYPE_ONTIME;
256 if ((freq_loc = strstr(origin, BEGIN_ALARM_KEYWORD)) == NULL) {
257 _DEBUG_ERROR("there is not trigger data");
262 if((temp = strstr(freq_loc, "BEGIN:VALARM\r\n")) == NULL) {
263 _DEBUG_ERROR("temp is NULL");
268 if((temp2 = strstr(temp, "END:VALARM\r\n")) == NULL) {
269 _DEBUG_ERROR("temp2 is NULL");
273 char str_origin_alarm[100] = {0,};
274 int origin_alarm_length = strlen(temp) - strlen(temp2) + 12; // '12' means of "END:VALARM\r\n"
275 if (origin_alarm_length <= 0) {
276 _DEBUG_ERROR("origin_alarm_length <= 0");
280 strncpy(str_origin_alarm, temp, origin_alarm_length);
281 _DEBUG_INFO("str_origin_alarm = %s", str_origin_alarm);
283 // case 1. "TRIGGER;VALUE=DATE-TIME:" is an alarm that created by user
284 str_customized_trigger = _get_value_by_token(freq_loc, "TRIGGER;VALUE=DATE-TIME:", "\r\n");
285 if (str_customized_trigger != NULL) {
286 _DEBUG_INFO("str_customized_trigger is founded. str_customized_trigger = %s", str_customized_trigger);
288 str_new_alarm = (char *)calloc(30, sizeof(char));
289 if (str_new_alarm == NULL) {
290 _DEBUG_ERROR("new_date_time is null");
294 snprintf(str_new_alarm, 30, "AALARM:%s\r\n", str_customized_trigger);
295 _DEBUG_INFO("str_new_alarm = %s", str_new_alarm);
296 char *new_agent_data = _replace_string(origin, str_origin_alarm, str_new_alarm);
298 origin = new_agent_data;
302 // case 2. "TRIGGER:" is a normal alarm
303 str_trigger = _get_value_by_token(freq_loc, "TRIGGER:", "\r\n");
304 if (str_trigger == NULL || strlen(str_trigger) <= 0) {
305 _DEBUG_ERROR("str_trigger is null");
309 char *temp_alarm = NULL;
310 char *temp_alarm2 = NULL;
311 if((temp_alarm = strstr(str_trigger, "P0W")) != NULL) {
312 cal_type = CALENDAR_DATE_TYPE_ONTIME;
315 else if((temp_alarm = strstr(str_trigger, "PT")) != NULL) {
316 if((temp_alarm2 = strstr(temp_alarm, "H")) != NULL) {
317 cal_type = CALENDAR_DATE_TYPE_HOUR;
318 str_interval = _get_value_by_token(str_trigger, "PT", "H");
319 interval = atoi(str_interval);
321 else if((temp_alarm2 = strstr(temp_alarm, "M")) != NULL) {
322 cal_type = CALENDAR_DATE_TYPE_MINUTE;
323 str_interval = _get_value_by_token(str_trigger, "PT", "M");
324 interval = atoi(str_interval);
327 _DEBUG_ERROR("wrong type, temp_alarm = %s", temp_alarm);
331 else if((temp_alarm = strstr(str_trigger, "P")) != NULL) {
332 if((temp_alarm2 = strstr(temp_alarm, "D")) != NULL) {
333 cal_type = CALENDAR_DATE_TYPE_DAY;
334 str_interval = _get_value_by_token(str_trigger, "P", "D");
335 interval = atoi(str_interval);
337 else if((temp_alarm2 = strstr(temp_alarm, "W")) != NULL) {
338 cal_type = CALENDAR_DATE_TYPE_WEEK;
339 str_interval = _get_value_by_token(str_trigger, "P", "W");
340 interval = atoi(str_interval);
343 _DEBUG_ERROR("wrong type, temp_alarm = %s", temp_alarm);
348 _DEBUG_ERROR("wrong type, temp_alarm = %s", temp_alarm);
352 str_new_alarm = _calculate_date_time(origin, interval, cal_type);
353 if (str_new_alarm == NULL || strlen(str_new_alarm) <= 0) {
354 _DEBUG_ERROR("str_new_alarm is null");
358 _DEBUG_INFO("str_new_alarm = %s", str_new_alarm);
359 _DEBUG_INFO("str_origin_alarm = %s", str_origin_alarm);
361 char *new_agent_data = _replace_string(origin, str_origin_alarm, str_new_alarm);
363 origin = new_agent_data;
371 if (str_customized_trigger) {
372 free(str_customized_trigger);
373 str_customized_trigger = NULL;
377 str_new_alarm = NULL;
385 _DEBUG_INFO("origin = %s", origin);
390 static char * _calculate_date_time(char *origin, int value, calendar_date_type_e type)
393 retvm_if(origin == NULL, NULL, "origin is NULL");
395 _DEBUG_INFO("origin = %s", origin);
396 _DEBUG_INFO("value = %d", value);
398 UCalendar *ucal = NULL;
399 char *start_time = NULL;
400 char *new_date_time = NULL;
401 char *start_date_loc = NULL;
402 if ((start_date_loc = strstr(origin, DTSTART_KEYWORD)) == NULL) {
403 _DEBUG_ERROR("start_date_loc is null");
407 char str_year[5] = {0,};
408 char str_month[3] = {0,};
409 char str_date[3] = {0,};
410 char str_hour[3] = {0,};
411 char str_minute[3] = {0,};
412 char str_second[3] = {0,};
414 /* example) 20130124T000000Z\r\n = 2013 01 24 T 00 00 00 Z \r\n */
415 strncpy(str_year, start_date_loc + strlen(DTSTART_KEYWORD), 4);
416 strncpy(str_month, start_date_loc + strlen(DTSTART_KEYWORD) + 4, 2);
417 strncpy(str_date, start_date_loc + strlen(DTSTART_KEYWORD) + 4 + 2, 2);
418 strncpy(str_hour, start_date_loc + strlen(DTSTART_KEYWORD) + 4 + 2 + 2 + 1, 2);
419 strncpy(str_minute, start_date_loc + strlen(DTSTART_KEYWORD) + 4 + 2 + 2 + 1 + 2, 2);
420 strncpy(str_second, start_date_loc + strlen(DTSTART_KEYWORD) + 4 + 2 + 2 + 1 + 2 + 2, 2);
422 int year = atoi(str_year);
423 int month = atoi(str_month);
424 int date = atoi(str_date);
425 int hour = atoi(str_hour);
426 int minute = atoi(str_minute);
427 int second = atoi(str_second);
428 long long int date_time = 0;
430 start_time = (char *)calloc(20, sizeof(char));
431 if (start_time == NULL) {
432 _DEBUG_ERROR("start_time is null");
436 snprintf(start_time, 20, "%04d%02d%02dT%02d%02d%02dZ\r\n", year, month, date, hour, minute, second);
437 _DEBUG_INFO("start_time = %s", start_time);
439 UErrorCode status = U_ZERO_ERROR;
440 ucal = ucal_open(0, -1, uloc_getDefault(), UCAL_TRADITIONAL, &status);
441 if (U_FAILURE(status)) {
442 _DEBUG_ERROR("ucal_open failed (%s)", u_errorName(status));
446 ucal_setAttribute(ucal, UCAL_LENIENT, 1);
447 ucal_setDateTime(ucal, year, month - 1, date, hour, minute, second, &status);
448 date_time = ucal_getMillis(ucal, &status);
451 case CALENDAR_DATE_TYPE_ONTIME:
452 _DEBUG_INFO("CALENDAR_DATE_TYPE_ONTIME");
453 date_time = date_time / 1000;
455 case CALENDAR_DATE_TYPE_WEEK:
456 _DEBUG_INFO("CALENDAR_DATE_TYPE_WEEK");
457 date_time = date_time / 1000;
458 date_time = date_time - (value*60*60*24*7);
460 case CALENDAR_DATE_TYPE_DAY:
461 _DEBUG_INFO("CALENDAR_DATE_TYPE_DAY");
462 date_time = date_time / 1000;
463 date_time = date_time - (value*60*60*24);
465 case CALENDAR_DATE_TYPE_HOUR:
466 _DEBUG_INFO("CALENDAR_DATE_TYPE_HOUR");
467 date_time = date_time / 1000;
468 date_time = date_time - (value*60*60);
470 case CALENDAR_DATE_TYPE_MINUTE:
471 _DEBUG_INFO("CALENDAR_DATE_TYPE_MINUTE");
472 date_time = date_time / 1000;
473 date_time = date_time - (value*60);
476 _DEBUG_ERROR("%d is not supported type", type);
481 if (U_FAILURE(status)) {
482 _DEBUG_ERROR("ucal_setDateTime failed (%s)", u_errorName(status));
486 ucal_setMillis(ucal, (date_time * 1000), &status);
488 year = month = date = hour = minute = second = 0;
489 year = ucal_get(ucal, UCAL_YEAR, &status);
490 month = ucal_get(ucal, UCAL_MONTH, &status) + 1;
491 date = ucal_get(ucal, UCAL_DATE, &status);
492 hour = ucal_get(ucal, UCAL_HOUR_OF_DAY, &status);
493 minute = ucal_get(ucal, UCAL_MINUTE, &status);
494 second = ucal_get(ucal, UCAL_SECOND, &status);
496 new_date_time = (char *)calloc(30, sizeof(char));
497 if (new_date_time == NULL) {
498 _DEBUG_ERROR("new_date_time is null");
502 snprintf(new_date_time, 30, "AALARM:%04d%02d%02dT%02d%02d%02dZ\r\n", year, month, date, hour, minute, second);
503 _DEBUG_INFO("new_date_time = %s", new_date_time);
506 _DEBUG_INFO("return_part");
518 return new_date_time;
523 char * get_value_by_token(const char *src, const char *token, const char *end_of_token)
526 if (src == NULL || strlen(src) <= 0) {
527 _DEBUG_ERROR("src is null");
531 char *token_loc = NULL;
532 char *str_output = NULL;
534 if ((token_loc = strstr(src, token)) != NULL) {
535 char *str_temp = strstr(token_loc, end_of_token);
536 if (str_temp != NULL) {
537 _DEBUG_INFO("token_loc = %s", token_loc);
538 _DEBUG_INFO("token = %s", token);
539 _DEBUG_INFO("str_temp = %s", str_temp);
540 int ret_str_length = strlen(token_loc) - strlen(token) - strlen(str_temp);
541 if (ret_str_length <= 0) {
542 _DEBUG_ERROR("ret_str_length(%d) <= 0", ret_str_length);
545 str_output = (char *)calloc(ret_str_length, sizeof(char));
546 if (str_output == NULL) {
547 _DEBUG_ERROR("calloc failed");
550 memcpy(str_output, token_loc + strlen(token), ret_str_length);
559 char * replace_string(char *origin, const char *src, const char *dest)
563 retvm_if((origin == NULL || strlen(origin) <= 0), NULL, "origin is NULL");
564 retvm_if((src == NULL || strlen(src) <= 0), NULL, "src is NULL");
565 retvm_if((dest == NULL || strlen(dest) <= 0), NULL, "dest is NULL");
567 _DEBUG_INFO("origin = %s", origin);
568 _DEBUG_INFO("src = %s", src);
569 _DEBUG_INFO("dest = %s", dest);
571 char *str_top = NULL;
573 if ((str_top = strstr(origin, src)) == NULL) {
574 _DEBUG_INFO("%s is not founed", src);
578 int top_length = strlen(origin) - strlen(str_top);
579 int middle_length = strlen(dest);
580 int down_length = strlen(origin) - top_length - strlen(src);
581 int new_str_length = top_length + middle_length + down_length + 1;
582 if (new_str_length <= 0) {
583 _DEBUG_ERROR("new_str_length(%d) <= 0", new_str_length);
586 char *new_str = (char *)calloc(new_str_length, sizeof(char));
587 if (new_str == NULL) {
588 _DEBUG_ERROR("calloc is failed.");
592 memset(new_str, 0, new_str_length);
593 memcpy(new_str, origin, top_length);
594 memcpy(new_str + top_length, dest, middle_length);
595 memcpy(new_str + top_length + middle_length, origin + top_length + strlen(src), down_length);
597 if (origin != NULL) {
602 _DEBUG_INFO("new_str = %s", new_str);
607 char * remove_timezone(char *origin)
610 retvm_if((origin == NULL || strlen(origin) <= 0), NULL, "origin is NULL");
612 _DEBUG_INFO("origin = %s", origin);
614 char *str_timezone = NULL;
615 char *str_temp = NULL;
617 if ((str_temp = strstr(origin, "\r\nDTSTART;TZID=")) != NULL) {
618 _DEBUG_INFO("str_temp = %s", str_temp);
619 str_timezone = get_value_by_token(str_temp, "\r\nDTSTART", ":");
620 _DEBUG_INFO("str_timezone = %s", str_timezone);
621 strcat(str_timezone, ":");
622 _DEBUG_INFO("str_timezone = %s", str_timezone);
623 origin = replace_string(origin, str_timezone, ":");
630 if ((str_temp = strstr(origin, "\r\nDTEND;TZID=")) != NULL) {
631 _DEBUG_INFO("str_temp = %s", str_temp);
632 str_timezone = get_value_by_token(str_temp, "\r\nDTEND", ":");
633 _DEBUG_INFO("str_timezone = %s", str_timezone);
634 strcat(str_timezone, ":");
635 _DEBUG_INFO("str_timezone = %s", str_timezone);
636 origin = replace_string(origin, str_timezone, ":");
643 _DEBUG_INFO("origin = %s", origin);
648 char * insert_exdate_data(const char *origin, sync_agent_calendar_exdate_t *exdate_struct, int index)
651 retvm_if((origin == NULL || strlen(origin) <= 0), NULL, "origin is NULL");
652 retvm_if(exdate_struct == NULL, NULL, "exdate_struct is NULL");
653 retvm_if(index < 0, NULL, "index < 0");
655 char *old_str = NULL;
656 char *new_str = NULL;
657 // 1. copy from parent vcalendar string
658 char *str_child_vcalendar = strdup((char *)(origin));
660 if (exdate_struct->exdate_type != CALENDAR_EXDATE_TYPE_DELETED && exdate_struct->exdate_type != CALENDAR_EXDATE_TYPE_UPDATED) {
661 _DEBUG_ERROR("exdate_type(%d) is wrong", exdate_struct->exdate_type);
665 _DEBUG_INFO("origin = %s", origin);
666 _DEBUG_INFO("cal_exdate_type = %d", exdate_struct->exdate_type);
668 if (exdate_struct->exdate_type == CALENDAR_EXDATE_TYPE_DELETED) {
669 _DEBUG_INFO("delete");
670 // 2. remove SUMMARY / RRULE / ALARM / EXDATE
671 // 2-1. remove 'SUMMARY'
672 if ((old_str = strstr(str_child_vcalendar, SUMMARY_KEYWORD)) != NULL) {
673 _DEBUG_INFO("summary keyword");
674 _DEBUG_INFO("old_str = %s", old_str);
675 if ((new_str = strstr(old_str+2, "\r\n")) != NULL) {
676 _DEBUG_INFO("new_str = %s", new_str);
677 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
678 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
682 // 2-2. remove 'RRULE'
683 if ((old_str = strstr(str_child_vcalendar, RRULE_KEYWORD)) != NULL) {
684 _DEBUG_INFO("rrule keyword");
685 _DEBUG_INFO("old_str = %s", old_str);
686 if ((new_str = strstr(old_str+2, "\r\n")) != NULL) {
687 _DEBUG_INFO("new_str = %s", new_str);
688 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
689 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
693 // 2-3. remove 'ALARM'
694 if ((old_str = strstr(str_child_vcalendar, AALARM_KEYWORD)) != NULL) {
695 _DEBUG_INFO("alarm keyword");
696 _DEBUG_INFO("old_str = %s", old_str);
697 if ((new_str = strstr(old_str+2, "\r\n")) != NULL) {
698 _DEBUG_INFO("new_str = %s", new_str);
699 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
700 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
704 // 2-4. remove 'EXDATE' array
705 if ((old_str = strstr(str_child_vcalendar, EXDATE_KEYWORD)) != NULL) {
706 _DEBUG_INFO("exdate keyword");
707 _DEBUG_INFO("old_str = %s", old_str);
708 if ((new_str = strstr(old_str+2, "\r\nX-EXTYPE:1")) != NULL) {
709 _DEBUG_INFO("new_str = %s", new_str);
710 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
711 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
715 // 3. change DTSTART / DTEND
716 // example ) DTSTART:20130125T000000Z / DTEND:20130125T003000Z / EXDATE:20130201T000000Z => DTSTART:20130201T000000Z / DTEND:20130201T003000Z
717 // 3-1. change DTSTART : DTSTART = EXDATE
719 if ((temp = strstr(str_child_vcalendar, DTSTART_KEYWORD)) != NULL) {
720 _DEBUG_INFO("start keyword");
721 _DEBUG_INFO("temp = %s", temp );
723 old_str = get_value_by_token(temp + 2, "DTSTART:", "\r\n");// '2' means strlen("\r\n")
724 if (old_str == NULL) {
725 _DEBUG_ERROR("old_str is null");
728 _DEBUG_INFO("old_str = %s", old_str);
729 new_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index);
730 if (new_str == NULL) {
731 _DEBUG_ERROR("new_str is NULL");
734 _DEBUG_INFO("new_str = %s", new_str);
735 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
736 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
739 // 3-2. change DTEND : DTEND = date of EXDATE + time of origin DTEND
741 if ((temp = strstr(str_child_vcalendar, DTEND_KEYWORD)) != NULL) {
742 _DEBUG_INFO("end keyword");
743 _DEBUG_INFO("temp = %s", temp );
745 old_str = get_value_by_token(temp + 2, "DTEND:", "\r\n");// '2' means strlen("\r\n")
746 if (old_str == NULL) {
747 _DEBUG_ERROR("old_str is null");
750 _DEBUG_INFO("old_str = %s", old_str);
751 char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index);
752 if (exdate_str == NULL) {
753 _DEBUG_ERROR("exdate_str is NULL");
756 _DEBUG_INFO("exdate_str = %s", exdate_str);
757 new_str = (char *)calloc(strlen(exdate_str), sizeof(char));
758 if (new_str == NULL) {
759 _DEBUG_ERROR("new_str calloc failed");
763 memcpy(new_str, exdate_str, 8);
764 memcpy(new_str + 8, old_str + 8, 8);
765 _DEBUG_INFO("new_str = %s", new_str);
766 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
767 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
772 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
776 if ((temp = strstr(str_child_vcalendar, END_VEVENT_KEYWORD)) != NULL) {
777 _DEBUG_INFO("EXTYPE keyword");
778 _DEBUG_INFO("temp = %s", temp);
780 char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index);
781 if (exdate_str == NULL) {
782 _DEBUG_ERROR("exdate_str is NULL");
785 _DEBUG_INFO("exdate_str = %s", exdate_str);
787 new_str = (char *)calloc(100, sizeof(char));
788 if (new_str == NULL) {
789 _DEBUG_ERROR("new_str calloc failed");
792 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
793 char *str_end_vevent = "\r\nEND:VEVENT";
794 snprintf(new_str, 100, "%s%s%s", EXDATE_KEYWORD, exdate_str, str_end_vevent);
795 _DEBUG_INFO("new_str = %s", new_str);
796 str_child_vcalendar = replace_string(str_child_vcalendar, str_end_vevent, new_str);
797 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
802 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
805 if ((temp = strstr(str_child_vcalendar, EXTYPE_DELETE_KEYWORD)) != NULL) {
806 str_child_vcalendar = replace_string(str_child_vcalendar, EXTYPE_DELETE_KEYWORD, "UID:000000000000000000000000000000000000000000000000\r\nX-EXTYPE:1");
807 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
810 else if (exdate_struct->exdate_type == CALENDAR_EXDATE_TYPE_UPDATED) {
811 _DEBUG_INFO("update");
812 // 2. remove RRULE / EXDATE
813 // 2-1. remove 'RRULE'
814 if ((old_str = strstr(str_child_vcalendar, RRULE_KEYWORD)) != NULL) {
815 _DEBUG_INFO("rrule keyword");
816 _DEBUG_INFO("old_str = %s", old_str);
817 if ((new_str = strstr(old_str+2, "\r\n")) != NULL) {
818 _DEBUG_INFO("new_str = %s", new_str);
819 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
820 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
824 // 2-2. remove 'EXDATE' array
825 if ((old_str = strstr(str_child_vcalendar, EXDATE_KEYWORD)) != NULL) {
826 _DEBUG_INFO("exdate keyword");
827 _DEBUG_INFO("old_str = %s", old_str);
828 if ((new_str = strstr(old_str+2, "\r\n")) != NULL) {
829 _DEBUG_INFO("new_str = %s", new_str);
830 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
831 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
835 // 3. change DTSTART / DTEND
836 // example ) DTSTART:20130125T000000Z / DTEND:20130125T003000Z / EXDATE:20130201T000000Z => DTSTART:20130201T000000Z / DTEND:20130201T003000Z
837 // 3-1. change DTSTART : DTSTART = EXDATE
839 if ((temp = strstr(str_child_vcalendar, DTSTART_KEYWORD)) != NULL) {
840 _DEBUG_INFO("start keyword");
841 _DEBUG_INFO("temp = %s", temp );
843 old_str = get_value_by_token(temp + 2, "DTSTART:", "\r\n");// '2' means strlen("\r\n")
844 if (old_str == NULL) {
845 _DEBUG_ERROR("old_str is null");
848 _DEBUG_INFO("old_str = %s", old_str);
849 new_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index);
850 if (new_str == NULL) {
851 _DEBUG_ERROR("new_str is NULL");
854 _DEBUG_INFO("new_str = %s", new_str);
855 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
856 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
859 // 3-2. change DTEND : DTEND = date of EXDATE + time of origin DTEND
861 if ((temp = strstr(str_child_vcalendar, DTEND_KEYWORD)) != NULL) {
862 _DEBUG_INFO("end keyword");
863 _DEBUG_INFO("temp = %s", temp );
865 old_str = get_value_by_token(temp + 2, "DTEND:", "\r\n");// '2' means strlen("\r\n")
866 if (old_str == NULL) {
867 _DEBUG_ERROR("old_str is null");
870 _DEBUG_INFO("old_str = %s", old_str);
871 char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index);
872 if (exdate_str == NULL) {
873 _DEBUG_ERROR("exdate_str is NULL");
876 _DEBUG_INFO("exdate_str = %s", exdate_str);
877 new_str = (char *)calloc(strlen(exdate_str), sizeof(char));
878 if (new_str == NULL) {
879 _DEBUG_ERROR("new_str calloc failed");
883 memcpy(new_str, exdate_str, 8);
884 memcpy(new_str + 8, old_str + 8, 8);
885 _DEBUG_INFO("new_str = %s", new_str);
886 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
887 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
892 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
896 if ((temp = strstr(str_child_vcalendar, END_VEVENT_KEYWORD)) != NULL) {
897 _DEBUG_INFO("EXTYPE keyword");
898 _DEBUG_INFO("temp = %s", temp);
900 char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index);
901 if (exdate_str == NULL) {
902 _DEBUG_ERROR("exdate_str is NULL");
905 _DEBUG_INFO("exdate_str = %s", exdate_str);
907 new_str = (char *)calloc(100, sizeof(char));
908 if (new_str == NULL) {
909 _DEBUG_ERROR("new_str calloc failed");
912 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
913 char *str_end_vevent = "\r\nEND:VEVENT";
914 snprintf(new_str, 100, "%s%s%s", EXDATE_KEYWORD, exdate_str, str_end_vevent);
915 _DEBUG_INFO("new_str = %s", new_str);
916 str_child_vcalendar = replace_string(str_child_vcalendar, str_end_vevent, new_str);
917 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
922 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
925 if ((temp = strstr(str_child_vcalendar, EXTYPE_UPDATE_KEYWORD)) != NULL) {
926 str_child_vcalendar = replace_string(str_child_vcalendar, EXTYPE_UPDATE_KEYWORD, "UID:000000000000000000000000000000000000000000000000\r\nX-EXTYPE:2");
927 _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar);
931 _DEBUG_INFO("cal_exdate_type(%d) is wrong type", exdate_struct->exdate_type);
936 _DEBUG_INFO("last str_child_vcalendar = %s", str_child_vcalendar);
937 return str_child_vcalendar;
940 void insert_allday_data(const char *origin, calendar_record_h calendar_record)
943 retm_if((origin == NULL || strlen(origin) <= 0), "origin is NULL");
944 retm_if(calendar_record == NULL, "calendar_record is NULL");
946 int service_ret = CALENDAR_ERROR_NONE;
949 service_ret = calendar_record_get_uri_p(calendar_record, &uri);
950 if (service_ret != CALENDAR_ERROR_NONE) {
951 _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret);
955 if (strncmp(uri, _calendar_event._uri, strlen(_calendar_event._uri))) {
956 _DEBUG_ERROR("this is not event");
960 calendar_time_s cal_time_start = { 0, };
961 calendar_time_s cal_time_end = { 0, };
966 service_ret = calendar_record_get_caltime(calendar_record, _calendar_event.start_time, &cal_time_start);
967 if (service_ret != CALENDAR_ERROR_NONE) {
968 _DEBUG_ERROR("calendar_record_get_caltime() Fail: err[%d]", service_ret);
972 char *start_date_loc = NULL;
973 if ((start_date_loc = strstr(origin, DTSTART_KEYWORD)) == NULL) {
974 _DEBUG_ERROR("start_date_loc is null");
978 char str_year_start[5] = {0,};
979 char str_month_start[3] = {0,};
980 char str_date_start[3] = {0,};
982 /* example) 20130124T000000Z\r\n = 2013 01 24 T 00 00 00 Z \r\n */
983 strncpy(str_year_start, start_date_loc + strlen(DTSTART_KEYWORD), 4);
984 strncpy(str_month_start, start_date_loc + strlen(DTSTART_KEYWORD) + 4, 2);
985 strncpy(str_date_start, start_date_loc + strlen(DTSTART_KEYWORD) + 4 + 2, 2);
987 year = atoi(str_year_start);
988 month = atoi(str_month_start);
989 day = atoi(str_date_start);
991 _DEBUG_INFO("start time : year = %d, month = %d, day = %d", year, month, day);
992 cal_time_start.type = CALENDAR_TIME_LOCALTIME;
993 cal_time_start.time.date.year = year;
994 cal_time_start.time.date.month = month;
995 cal_time_start.time.date.mday = day;
997 service_ret = calendar_record_set_caltime(calendar_record, _calendar_event.start_time, cal_time_start);
998 if (service_ret != CALENDAR_ERROR_NONE) {
999 _DEBUG_ERROR("calendar_record_set_caltime() Fail: err[%d]", service_ret);
1003 service_ret = calendar_record_get_caltime(calendar_record, _calendar_event.end_time, &cal_time_end);
1004 if (service_ret != CALENDAR_ERROR_NONE) {
1005 _DEBUG_ERROR("calendar_record_get_caltime() Fail: err[%d]", service_ret);
1009 char *end_date_loc = NULL;
1010 if ((end_date_loc = strstr(origin, DTEND_KEYWORD)) == NULL) {
1011 _DEBUG_ERROR("end_date_loc is null");
1015 char str_year_end[5] = {0,};
1016 char str_month_end[3] = {0,};
1017 char str_date_end[3] = {0,};
1019 /* example) 20130124T000000Z\r\n = 2013 01 24 T 00 00 00 Z \r\n */
1020 strncpy(str_year_end, end_date_loc + strlen(DTEND_KEYWORD), 4);
1021 strncpy(str_month_end, end_date_loc + strlen(DTEND_KEYWORD) + 4, 2);
1022 strncpy(str_date_end, end_date_loc + strlen(DTEND_KEYWORD) + 4 + 2, 2);
1024 year = atoi(str_year_end);
1025 month = atoi(str_month_end);
1026 day = atoi(str_date_end);
1028 _DEBUG_INFO("end time : year = %d, month = %d, day = %d", year, month, day);
1029 cal_time_end.type = CALENDAR_TIME_LOCALTIME;
1030 cal_time_end.time.date.year = year;
1031 cal_time_end.time.date.month = month;
1032 cal_time_end.time.date.mday = day;
1034 service_ret = calendar_record_set_caltime(calendar_record, _calendar_event.end_time, cal_time_end);
1035 if (service_ret != CALENDAR_ERROR_NONE) {
1036 _DEBUG_ERROR("calendar_record_set_caltime() Fail: err[%d]", service_ret);
1045 EXPORT_API char * has_image_import(const char *origin)
1049 char *temp_image_path = NULL;
1050 char *image_path = NULL;
1052 if (strstr(origin, IMAGE_KEYWORD_PREFIX_PHOTO) == NULL && strstr(origin, IMAGE_KEYWORD_PREFIX_SNOTE) == NULL) {
1053 _DEBUG_INFO("this calendar has not an image");
1057 temp_image_path = get_value_by_token(origin, IMAGE_KEYWORD_BEGIN_PATH, IMAGE_KEYWORD_END_PATH);
1059 if (strstr(temp_image_path, INTERNAL_MEMORY_CONVERTED) != NULL) {
1060 image_path = replace_string(temp_image_path, INTERNAL_MEMORY_CONVERTED, INTERNAL_MEMORY_ORIGIN);
1062 else if (strstr(temp_image_path, EXTERNAL_MEMORY_CONVERTED) != NULL) {
1063 image_path = replace_string(temp_image_path, EXTERNAL_MEMORY_CONVERTED, EXTERNAL_MEMORY_ORIGIN);
1065 else if (strstr(temp_image_path, SNOTE_MEMORY_ORIGIN) != NULL) {
1066 image_path = strdup(temp_image_path);
1069 _DEBUG_ERROR("there is an error. origin = %s", origin);
1075 _DEBUG_INFO("image_path = %s", image_path);
1080 EXPORT_API char * has_image_export(calendar_record_h cal_record)
1083 retvm_if(cal_record == NULL, NULL, "cal_record is NULL");
1085 calendar_record_h image_record = NULL;
1086 unsigned int child_record_count = 0;
1088 int service_ret = CALENDAR_ERROR_NONE;
1089 char *image_key = NULL;
1090 char *image_path = NULL;
1093 service_ret = calendar_record_get_uri_p(cal_record, &uri);
1094 if (service_ret != CALENDAR_ERROR_NONE) {
1095 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret);
1098 _DEBUG_INFO("uri = %s", uri);
1099 _DEBUG_INFO("_calendar_event.uri = %s", _calendar_event._uri);
1101 service_ret = calendar_record_get_child_record_count(cal_record, _calendar_event.extended, &child_record_count);
1102 if (service_ret != CALENDAR_ERROR_NONE) {
1103 _DEBUG_ERROR("calendar_record_get_child_record_count() Fail: err[%d]", service_ret);
1107 for (i = 0; i < child_record_count; i++) {
1108 service_ret = calendar_record_get_child_record_at_p(cal_record, _calendar_event.extended, i, &image_record);
1109 if (service_ret != CALENDAR_ERROR_NONE) {
1110 _DEBUG_ERROR("calendar_record_get_child_record_at_p() Fail: err[%d]", service_ret);
1114 service_ret = calendar_record_get_str_p(image_record, _calendar_extended_property.key, &image_key);
1115 if (service_ret != CALENDAR_ERROR_NONE || image_key == NULL || strlen(image_key) <= 0) {
1116 _DEBUG_ERROR("calendar_record_get_str_p is failed(%d)", service_ret);
1120 if (strcmp(image_key, CALENDAR_IMAGE_KEYWORD_SNOTE) == 0 || strcmp(image_key, CALENDAR_IMAGE_KEYWORD_PHOTO) == 0) {
1121 _DEBUG_INFO("image is founded. image_key = %s", image_key);
1122 service_ret = calendar_record_get_str(image_record, _calendar_extended_property.value, &image_path);
1123 if (service_ret != CALENDAR_ERROR_NONE || image_path == NULL || strlen(image_path) <= 0) {
1124 _DEBUG_ERROR("calendar_record_get_str_p is failed(%d)", service_ret);
1128 _DEBUG_INFO("image_path = %s", image_path);
1138 // "EXTYPE" setting, '1' means deleted, '2' means updated : it should be excuted before calendar_vcalendar_make_from_records
1139 void get_exdate_data(calendar_record_h cal_record, sync_agent_calendar_exdate_t *exdate_struct)
1142 retm_if(cal_record == NULL, "cal_record is NULL");
1143 retm_if(exdate_struct == NULL, "exdate_struct is NULL");
1145 calendar_record_h extended_exdate = NULL;
1146 char *exdate = NULL;
1147 char *recurrence_id = NULL;
1148 int service_ret = CALENDAR_ERROR_NONE;
1149 int original_event_id = 0;
1151 exdate_struct->exdate_type = CALENDAR_EXDATE_TYPE_NONE;
1155 service_ret = calendar_record_get_uri_p(cal_record, &uri);
1156 if (service_ret != CALENDAR_ERROR_NONE) {
1157 _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret);
1160 _DEBUG_INFO("uri = %s", uri);
1162 // 1. delete : if 'exdate' value is exist, there are deleted item.
1163 service_ret = calendar_record_get_str(cal_record, _calendar_event.exdate, &exdate);
1164 if (service_ret != CALENDAR_ERROR_NONE) {
1165 _DEBUG_ERROR("calendar_list_create() Fail!: err[%d]", service_ret);
1168 _DEBUG_INFO("exdate = %s", exdate);
1170 if (exdate != NULL && strlen(exdate) > 0) {
1171 _DEBUG_INFO("EXTYPE:DELETE setting start");
1172 service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_exdate);
1173 if (service_ret != CALENDAR_ERROR_NONE) {
1174 _DEBUG_ERROR("calendar_record_create() Fail!: err[%d]", service_ret);
1177 service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.key, "X-EXTYPE");
1178 if (service_ret != CALENDAR_ERROR_NONE) {
1179 _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret);
1182 service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.value, ":1");
1183 if (service_ret != CALENDAR_ERROR_NONE) {
1184 _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret);
1187 service_ret = calendar_record_add_child_record(cal_record, _calendar_event.extended, extended_exdate);
1188 if (service_ret != CALENDAR_ERROR_NONE) {
1189 _DEBUG_ERROR("calendar_record_add_child_record() Fail!: err[%d]", service_ret);
1193 exdate_struct->exdate_type = CALENDAR_EXDATE_TYPE_DELETED;
1194 char *str_exdate_loc = NULL;
1195 int exdate_count = 0;
1197 while (exdate_loc < strlen(exdate)) {
1198 _DEBUG_INFO("111111111111 exdate_loc = %d", exdate_loc);
1199 _DEBUG_INFO("111111111111 strlen(exdate) = %d", strlen(exdate));
1200 int one_exdate_length = 0;
1201 if ((str_exdate_loc = strstr(exdate + exdate_loc, ",")) != NULL) {
1202 one_exdate_length = strlen(exdate) - strlen(str_exdate_loc) - (exdate_count*(DATE_TIME_LENGTH+1));
1205 one_exdate_length = strlen(exdate) - exdate_loc;
1207 _DEBUG_INFO("str_exdate_loc = %s", str_exdate_loc);
1208 if (one_exdate_length <= 0) {
1209 _DEBUG_ERROR("one_exdate_length (%d) <= 0", one_exdate_length);
1212 char *str_one_exdate = (char *)calloc(one_exdate_length, sizeof(char));
1213 if (str_one_exdate == NULL) {
1214 _DEBUG_ERROR("str_one_exdate calloc is failed.");
1217 memcpy(str_one_exdate, exdate + exdate_loc, one_exdate_length);
1218 exdate_loc += (one_exdate_length+1); // '1' meaning of ',' length
1219 exdate_struct->exdate_list = g_list_append(exdate_struct->exdate_list, str_one_exdate);
1221 _DEBUG_INFO("str_one_exdate = %s", str_one_exdate);
1222 _DEBUG_INFO("one_exdate_length = %d", one_exdate_length);
1223 _DEBUG_INFO("exdate_loc = %d", exdate_loc);
1224 _DEBUG_INFO("exdate_count = %d\n\n", exdate_count);
1227 _DEBUG_INFO("exdate_loc = %d", exdate_loc);
1228 _DEBUG_INFO("exdate_count = %d", exdate_count);
1229 exdate_struct->exdate_count = exdate_count;
1230 _DEBUG_INFO("EXTYPE:DELETE setting end");
1233 _DEBUG_INFO("222222222");
1234 // 2. update : if 'origianl_event_id' and 'recurrence_id' value are exist, there are updated item.
1235 service_ret = calendar_record_get_int(cal_record, _calendar_event.original_event_id, &original_event_id);
1236 if (service_ret != CALENDAR_ERROR_NONE) {
1237 _DEBUG_ERROR("calendar_list_create() Fail!: err[%d]", service_ret);
1240 _DEBUG_INFO("original_event_id = %d", original_event_id);
1242 service_ret = calendar_record_get_str(cal_record, _calendar_event.recurrence_id, &recurrence_id);
1243 if (service_ret != CALENDAR_ERROR_NONE) {
1244 _DEBUG_ERROR("calendar_list_create() Fail!: err[%d]", service_ret);
1247 _DEBUG_INFO("recurrence_id = %s", recurrence_id);
1249 if (original_event_id > 0 && recurrence_id != NULL && strlen(recurrence_id) > 0) {
1250 _DEBUG_INFO("EXTYPE:UPDATE setting start");
1251 service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_exdate);
1252 if (service_ret != CALENDAR_ERROR_NONE) {
1253 _DEBUG_ERROR("calendar_record_create() Fail!: err[%d]", service_ret);
1256 service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.key, "X-EXTYPE");
1257 if (service_ret != CALENDAR_ERROR_NONE) {
1258 _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret);
1261 service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.value, ":2");
1262 if (service_ret != CALENDAR_ERROR_NONE) {
1263 _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret);
1266 service_ret = calendar_record_add_child_record(cal_record, _calendar_event.extended, extended_exdate);
1267 if (service_ret != CALENDAR_ERROR_NONE) {
1268 _DEBUG_ERROR("calendar_record_add_child_record() Fail!: err[%d]", service_ret);
1271 exdate_struct->exdate_type = CALENDAR_EXDATE_TYPE_UPDATED;
1272 _DEBUG_INFO("EXTYPE:UPDATE setting end");
1280 char * replace_max_rrule_data(char *origin)
1283 retvm_if(origin == NULL, origin, "origin is NULL.");
1286 char *temp_rrule = NULL;
1287 char *str_old_rrule = NULL;
1288 char *str_new_rrule = NULL;
1290 if ((temp = strstr(origin, RRULE_KEYWORD)) == NULL) {
1291 _DEBUG_INFO("this vcalendar hasn't rrule data");
1295 str_old_rrule = get_value_by_token(temp + 2, "RRULE:", "\r\n");// '2' means strlen("\r\n")
1296 if (str_old_rrule == NULL) {
1297 _DEBUG_ERROR("str_old_rrule is null");
1301 if (strstr(str_old_rrule, MAX_RRULE_DATE_KEYWORD) == NULL) {
1302 _DEBUG_INFO("this vcalendar has rrule data, But it's not until=NONE rrule");
1305 _DEBUG_INFO("this vcalendar has until=NONE rrule");
1307 temp_rrule = get_value_by_token(temp, RRULE_KEYWORD, MAX_RRULE_DATE_KEYWORD);
1308 if (temp_rrule == NULL) {
1309 _DEBUG_ERROR("temp_rrule is null");
1313 str_new_rrule = (char *)calloc(strlen(temp_rrule) + 2, sizeof(char));
1314 if (str_new_rrule == NULL) {
1315 _DEBUG_ERROR("str_new_rrule calloc failed");
1319 // every eternal rrule data must have '#0' at the end of string (Calendar-Svc recommend)
1320 snprintf(str_new_rrule, strlen(temp_rrule) + 2, "%s#0", temp_rrule);
1321 origin = replace_string(origin, str_old_rrule, str_new_rrule);
1325 free(str_old_rrule);
1326 str_old_rrule = NULL;
1329 free(str_new_rrule);
1330 str_new_rrule = NULL;
1337 _DEBUG_INFO("origin = %s", origin);
1341 char * replace_image_data(char *origin, char *image_path)
1344 retvm_if(origin == NULL, origin, "origin is NULL.");
1345 retvm_if(image_path == NULL, origin, "image_path is NULL.");
1347 int image_path_length = 500;
1348 char *str_temp_image_info = NULL;
1349 char *str_image_info = NULL;
1350 char *str_image_tag = NULL;
1352 _DEBUG_INFO("origin = %s", origin);
1353 _DEBUG_INFO("image_path = %s", image_path);
1355 if (strstr(image_path, INTERNAL_MEMORY_ORIGIN) != NULL) {
1356 str_temp_image_info = replace_string(image_path, INTERNAL_MEMORY_ORIGIN, INTERNAL_MEMORY_CONVERTED);
1357 str_image_tag = strdup("X-SS-ATTACH-IMAGE");
1359 else if (strstr(image_path, EXTERNAL_MEMORY_ORIGIN) != NULL) {
1360 str_temp_image_info = replace_string(image_path, EXTERNAL_MEMORY_ORIGIN, EXTERNAL_MEMORY_CONVERTED);
1361 str_image_tag = strdup("X-SS-ATTACH-IMAGE");
1363 else if (strstr(image_path, SNOTE_MEMORY_ORIGIN) != NULL) {
1364 str_temp_image_info = strdup(image_path);
1365 //str_image_tag = strdup("X-SS-ATTACH-SNOTE");
1366 str_image_tag = strdup("X-SS-ATTACH-IMAGE");
1369 _DEBUG_ERROR("there is an error. image_path = %s", image_path);
1373 if (strstr(origin, END_VEVENT_KEYWORD) == NULL) {
1374 _DEBUG_ERROR("this data is wrong format. origin = %s", origin);
1378 if (image_path_length <= 0) {
1379 _DEBUG_ERROR("image_path_length(%d) <= 0", image_path_length);
1382 str_image_info = (char *)calloc(image_path_length, sizeof(char));
1383 if (str_image_info == NULL) {
1384 _DEBUG_ERROR("str_image_info calloc failed");
1388 snprintf(str_image_info, image_path_length, "\r\n%s;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:NAME=3Dnull=3BPATH=3D%s=3BDATE=3D%s", str_image_tag, str_temp_image_info, END_VEVENT_KEYWORD);
1390 char *new_agent_data = replace_string(origin, END_VEVENT_KEYWORD, str_image_info);
1392 origin = new_agent_data;
1396 if (str_image_info) {
1397 free(str_image_info);
1398 str_image_info = NULL;
1400 if (str_image_tag) {
1401 free(str_image_tag);
1402 str_image_tag = NULL;
1404 if (str_temp_image_info) {
1405 free(str_temp_image_info);
1406 str_temp_image_info = NULL;
1410 _DEBUG_INFO("origin = %s", origin);
1414 // exdate string format like as "20130211T000000Z,20130211T000000Z,20130211T000000Z"
1415 sync_agent_da_return_e replace_exdate_data(const char *origin, calendar_record_h calendar_record)
1418 retvm_if(origin == NULL, SYNC_AGENT_DA_ERRORS, "origin is NULL.");
1419 retvm_if(calendar_record == NULL, SYNC_AGENT_DA_ERRORS, "calendar_record is NULL");
1421 char *str_exdata_loc = NULL;
1422 char *old_exdate_str = NULL;
1423 char *new_exdate_str = NULL;
1424 char *new_one_exdate_str = NULL;
1425 int exdate_length = 0;
1426 int service_ret = CALENDAR_ERROR_NONE;
1427 sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
1429 if ((str_exdata_loc = strstr(origin, IMPORT_EXTYPE_DELETE_KEYWORD)) == NULL) {
1430 _DEBUG_ERROR("this vcalendar has not exdate data");
1431 ret = SYNC_AGENT_DA_ERRORS;
1435 new_one_exdate_str = get_value_by_token(str_exdata_loc + 2, "EXDATE:", "\r\n");
1436 _DEBUG_INFO("new_one_exdate_str = %s", new_one_exdate_str);
1438 service_ret = calendar_record_get_str(calendar_record, _calendar_event.exdate, &old_exdate_str);
1439 if (service_ret != CALENDAR_ERROR_NONE) {
1440 _DEBUG_ERROR("calendar_record_set_str() Fail! err[%d]\n", service_ret);
1444 _DEBUG_INFO("old_exdate_str = %s", old_exdate_str);
1445 int old_exdate_str_length = 0;
1446 if (old_exdate_str == NULL)
1447 old_exdate_str_length = 0;
1449 old_exdate_str_length = strlen(old_exdate_str);
1451 exdate_length = old_exdate_str_length + strlen(new_one_exdate_str) + 2;
1452 _DEBUG_INFO("exdate_length = %d", exdate_length);
1453 new_exdate_str = (char *)calloc(exdate_length, sizeof(char));
1454 if (new_exdate_str == NULL) {
1455 _DEBUG_ERROR("new_exdate_str calloc failed");
1459 if (old_exdate_str == NULL)
1460 snprintf(new_exdate_str, exdate_length, "%s", new_one_exdate_str);
1462 snprintf(new_exdate_str, exdate_length, "%s,%s", old_exdate_str, new_one_exdate_str);
1464 _DEBUG_INFO("new_exdate_str = %s", new_exdate_str);
1466 service_ret = calendar_record_set_str(calendar_record, _calendar_event.exdate, new_exdate_str);
1467 if (service_ret != CALENDAR_ERROR_NONE) {
1468 _DEBUG_ERROR("calendar_record_set_str() Fail! err[%d]\n", service_ret);
1473 if(new_one_exdate_str) {
1474 free(new_one_exdate_str);
1475 new_one_exdate_str = NULL;
1477 if(new_exdate_str) {
1478 free(new_exdate_str);
1479 new_exdate_str = NULL;