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")))
28 // usage / rrule converting
29 if (strstr(temp_agent_data, "\r\nRRULE:") != NULL) {
30 _DEBUG_INFO("rrule is founed");
31 temp_agent_data = _replace_rrule_data(temp_agent_data);
34 static char * _replace_rrule_data(char *origin)
37 retvm_if(origin == NULL, origin, "origin is NULL.");
39 char *str_new_rrule = NULL;
40 char *str_end_time = NULL;
41 char *freq_loc = NULL;
42 char *str_byday = NULL;
43 char *str_interval = NULL;
44 char *str_period_until = NULL;
45 char *str_period_count = NULL;
46 calendar_date_type_e cal_type = CALENDAR_DATE_TYPE_ONTIME;
48 if ((freq_loc = strstr(origin, RRULE_KEYWORD_FREQ_WEEKLY)) != NULL) {
49 _DEBUG_INFO("this is weekly data");
51 else if ((freq_loc = strstr(origin, RRULE_KEYWORD_FREQ_MONTHLY)) != NULL) {
52 _DEBUG_INFO("this is monthly data");
54 else if ((freq_loc = strstr(origin, RRULE_KEYWORD_FREQ_YEARLY)) != NULL) {
55 _DEBUG_INFO("this is yearly data");
57 else if ((freq_loc = strstr(origin, RRULE_KEYWORD_FREQ_DAILY)) != NULL) {
58 _DEBUG_INFO("this is daily data");
61 _DEBUG_ERROR("this is an undefined rrule type. origin = %s", origin);
65 char *temp_rrule = NULL;
66 if((temp_rrule = strstr(freq_loc, "RRULE:")) == NULL) {
67 _DEBUG_ERROR("temp_rrule is NULL");
71 char *temp_rrule2 = NULL;
72 if((temp_rrule2 = strstr(temp_rrule, "\r\n")) == NULL) {
73 _DEBUG_ERROR("temp_rrule2 is NULL");
77 char str_origin_rrule[100] = {0,};
78 int origin_rrule_length = strlen(temp_rrule) - strlen(temp_rrule2) + 2; // '2' means of '\r\n'
79 if (origin_rrule_length <= 0) {
80 _DEBUG_ERROR("origin_rrule_length <= 0");
84 strncpy(str_origin_rrule, temp_rrule, origin_rrule_length);
85 _DEBUG_INFO("str_origin_rrule = %s", str_origin_rrule);
87 if (strstr(origin, RRULE_KEYWORD_FREQ_WEEKLY) != NULL) {
88 str_byday = get_value_by_token(freq_loc, RRULE_KEYWORD_BYDAY, ";");
89 cal_type = CALENDAR_DATE_TYPE_WEEK;
91 else if (strstr(origin, RRULE_KEYWORD_FREQ_MONTHLY) != NULL) {
92 str_byday = get_value_by_token(freq_loc, RRULE_KEYWORD_BYMONTHDAY, ";");
93 cal_type = CALENDAR_DATE_TYPE_MONTH;
95 else if (strstr(origin, RRULE_KEYWORD_FREQ_YEARLY) != NULL) {
96 str_byday = get_value_by_token(freq_loc, RRULE_KEYWORD_BYMONTHDAY, ";");
97 cal_type = CALENDAR_DATE_TYPE_YEAR;
99 else if (strstr(origin, RRULE_KEYWORD_FREQ_DAILY) != NULL) {
100 cal_type = CALENDAR_DATE_TYPE_DAY;
103 _DEBUG_ERROR("this is an undefined rrule type. origin = %s", origin);
107 if ((cal_type != CALENDAR_DATE_TYPE_DAY) && (str_byday == NULL || strlen(str_byday) <= 0)) {
108 _DEBUG_ERROR("str_byday is null");
112 str_interval = get_value_by_token(freq_loc, RRULE_KEYWORD_INTERVAL, ";");
113 str_period_until = get_value_by_token(freq_loc, RRULE_KEYWORD_UNTIL, ";");
114 str_period_count = get_value_by_token(freq_loc, RRULE_KEYWORD_COUNT, ";");
116 if (str_interval == NULL || strlen(str_interval) <= 0) {
117 _DEBUG_ERROR("str_interval is null");
121 if (str_period_until == NULL && str_period_count == NULL) {
122 str_end_time = (char *)calloc(2, sizeof(char));
123 if (str_end_time == NULL) {
124 _DEBUG_ERROR("str_end_time is null");
127 strncpy(str_end_time, "\r\n", 2);
128 _DEBUG_INFO("endless = %s", str_end_time);
130 else if (str_period_until != NULL) {
131 str_end_time = (char *)calloc(strlen(str_period_until), sizeof(char));
132 if (str_end_time == NULL) {
133 _DEBUG_ERROR("str_end_time is null");
136 strncpy(str_end_time, str_period_until, strlen(str_period_until));
137 _DEBUG_INFO("until = %s", str_end_time);
139 else if (str_period_count != NULL) {
140 str_end_time = (char *)calloc(strlen(str_period_count)+1, sizeof(char));
141 if (str_end_time == NULL) {
142 _DEBUG_ERROR("str_end_time is null");
145 snprintf(str_end_time, strlen(str_period_count)+1, "#%s", str_period_count);
146 _DEBUG_INFO("count = %s", str_end_time);
149 _DEBUG_ERROR("there is an error");
153 int new_rrule_length = 0;
154 if (strstr(origin, RRULE_KEYWORD_FREQ_WEEKLY) != NULL) {
155 new_rrule_length = strlen("RRULE:W") + strlen(str_interval) + strlen(" ") + strlen(str_byday) + strlen(" ") + strlen(str_end_time) + 1;
157 else if (strstr(origin, RRULE_KEYWORD_FREQ_MONTHLY) != NULL) {
158 new_rrule_length = strlen("RRULE:MD") + strlen(str_interval) + strlen(" ") + strlen(str_byday) + strlen(" ") + strlen(str_end_time) + 1;
160 else if (strstr(origin, RRULE_KEYWORD_FREQ_YEARLY) != NULL) {
161 new_rrule_length = strlen("RRULE:YD") + strlen(str_interval) + strlen(" ") + strlen(str_end_time) + 1;
163 else if (strstr(origin, RRULE_KEYWORD_FREQ_DAILY) != NULL) {
164 new_rrule_length = strlen("RRULE:D") + strlen(str_interval) + strlen(" ") + strlen(str_end_time) + 1;
167 _DEBUG_ERROR("this is an undefined rrule type. origin = %s", origin);
171 if (new_rrule_length <= 0) {
172 _DEBUG_ERROR("new_rrule_length(%d) <= 0", new_rrule_length);
176 str_new_rrule = (char *)calloc(new_rrule_length, sizeof(char));
177 if (str_new_rrule == NULL) {
178 _DEBUG_ERROR("str_new_rrule calloc failed");
182 if (strstr(origin, RRULE_KEYWORD_FREQ_WEEKLY) != NULL) {
183 snprintf(str_new_rrule, new_rrule_length, "RRULE:W%s %s %s", str_interval, str_byday, str_end_time);
185 else if (strstr(origin, RRULE_KEYWORD_FREQ_MONTHLY) != NULL) {
186 snprintf(str_new_rrule, new_rrule_length, "RRULE:MD%s %s %s", str_interval, str_byday, str_end_time);
188 else if (strstr(origin, RRULE_KEYWORD_FREQ_YEARLY) != NULL) {
189 snprintf(str_new_rrule, new_rrule_length, "RRULE:YD%s %s", str_interval, str_end_time);
191 else if (strstr(origin, RRULE_KEYWORD_FREQ_DAILY) != NULL) {
192 snprintf(str_new_rrule, new_rrule_length, "RRULE:D%s %s", str_interval, str_end_time);
195 _DEBUG_ERROR("this is an undefined rrule type. origin = %s", origin);
199 _DEBUG_INFO("str_new_rrule = %s", str_new_rrule);
200 _DEBUG_INFO("str_origin_rrule = %s", str_origin_rrule);
202 char *new_agent_data = replace_string(origin, str_origin_rrule, str_new_rrule);
204 origin = new_agent_data;
216 if (str_period_until) {
217 free(str_period_until);
218 str_period_until = NULL;
220 if (str_period_count) {
221 free(str_period_count);
222 str_period_count = NULL;
230 str_new_rrule = NULL;
233 _DEBUG_INFO("origin = %s", origin);
238 // usage / alarm converting
239 if (strstr(temp_agent_data, "\r\nBEGIN:VALARM") != NULL) {
240 _DEBUG_INFO("alarm is founed");
241 temp_agent_data = _replace_alarm_data(temp_agent_data);
244 static char * _replace_alarm_data(char *origin)
247 retvm_if(origin == NULL, origin, "origin is NULL.");
250 char *str_new_alarm = NULL;
251 char *freq_loc = NULL;
252 char *str_trigger = NULL;
253 char *str_customized_trigger = NULL;
254 char *str_interval = NULL;
255 calendar_date_type_e cal_type = CALENDAR_DATE_TYPE_ONTIME;
257 if ((freq_loc = strstr(origin, BEGIN_ALARM_KEYWORD)) == NULL) {
258 _DEBUG_ERROR("there is not trigger data");
263 if((temp = strstr(freq_loc, "BEGIN:VALARM\r\n")) == NULL) {
264 _DEBUG_ERROR("temp is NULL");
269 if((temp2 = strstr(temp, "END:VALARM\r\n")) == NULL) {
270 _DEBUG_ERROR("temp2 is NULL");
274 char str_origin_alarm[100] = {0,};
275 int origin_alarm_length = strlen(temp) - strlen(temp2) + 12; // '12' means of "END:VALARM\r\n"
276 if (origin_alarm_length <= 0) {
277 _DEBUG_ERROR("origin_alarm_length <= 0");
281 strncpy(str_origin_alarm, temp, origin_alarm_length);
282 _DEBUG_INFO("str_origin_alarm = %s", str_origin_alarm);
284 // case 1. "TRIGGER;VALUE=DATE-TIME:" is an alarm that created by user
285 str_customized_trigger = _get_value_by_token(freq_loc, "TRIGGER;VALUE=DATE-TIME:", "\r\n");
286 if (str_customized_trigger != NULL) {
287 _DEBUG_INFO("str_customized_trigger is founded. str_customized_trigger = %s", str_customized_trigger);
289 str_new_alarm = (char *)calloc(30, sizeof(char));
290 if (str_new_alarm == NULL) {
291 _DEBUG_ERROR("new_date_time is null");
295 snprintf(str_new_alarm, 30, "AALARM:%s\r\n", str_customized_trigger);
296 _DEBUG_INFO("str_new_alarm = %s", str_new_alarm);
297 char *new_agent_data = replace_string(origin, str_origin_alarm, str_new_alarm);
299 origin = new_agent_data;
303 // case 2. "TRIGGER:" is a normal alarm
304 str_trigger = _get_value_by_token(freq_loc, "TRIGGER:", "\r\n");
305 if (str_trigger == NULL || strlen(str_trigger) <= 0) {
306 _DEBUG_ERROR("str_trigger is null");
310 char *temp_alarm = 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(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(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(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(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 int ret_str_length = strlen(token_loc) - strlen(token) - strlen(str_temp);
538 if (ret_str_length <= 0) {
539 _DEBUG_ERROR("token_loc = %s", token_loc);
540 _DEBUG_ERROR("token = %s", token);
541 _DEBUG_ERROR("str_temp = %s", str_temp);
542 _DEBUG_ERROR("ret_str_length(%d) <= 0", ret_str_length);
545 str_output = (char *)calloc(ret_str_length, sizeof(char));
546 goto_if(str_output == NULL, "str_output is NULL");
548 memcpy(str_output, token_loc + strlen(token), ret_str_length);
557 char * replace_string(char *origin, const char *src, const char *dest)
561 retvm_if((origin == NULL || strlen(origin) <= 0), NULL, "origin is NULL");
562 retvm_if((src == NULL || strlen(src) <= 0), NULL, "src is NULL");
563 retvm_if((dest == NULL || strlen(dest) <= 0), NULL, "dest is NULL");
565 char *str_top = NULL;
566 if ((str_top = strstr(origin, src)) == NULL) {
567 _DEBUG_ERROR("%s is not founed", src);
571 int top_length = strlen(origin) - strlen(str_top);
572 int middle_length = strlen(dest);
573 int down_length = strlen(origin) - top_length - strlen(src);
574 int new_str_length = top_length + middle_length + down_length + 1;
575 if (new_str_length <= 0) {
576 _DEBUG_ERROR("top_length = %d", top_length);
577 _DEBUG_ERROR("middle_length = %d", middle_length);
578 _DEBUG_ERROR("down_length = %d", down_length);
579 _DEBUG_ERROR("new_str_length(%d) <= 0", new_str_length);
582 char *new_str = (char *)calloc(new_str_length, sizeof(char));
583 if (new_str == NULL) {
584 _DEBUG_ERROR("calloc is failed.");
588 memset(new_str, 0, new_str_length);
589 memcpy(new_str, origin, top_length);
590 memcpy(new_str + top_length, dest, middle_length);
591 memcpy(new_str + top_length + middle_length, origin + top_length + strlen(src), down_length);
593 if (origin != NULL) {
598 _DEBUG_INFO("new_str = %s", new_str);
603 // PLM(P130408-0777) : In case of DTSTART / DTEND with zulu time ('Z'), GMT timezone should be set.
604 EXPORT_API void set_timezone(const char *origin, calendar_record_h cal_record)
607 retm_if(origin == NULL, "origin is NULL");
608 retm_if(cal_record == NULL, "cal_record is NULL");
610 int service_ret = CALENDAR_ERROR_NONE;
612 char *str_start = NULL;
614 temp = strstr(origin, DTSTART_KEYWORD);
615 goto_if(temp == NULL, "origin has not DTSTART. origin = %s", origin);
617 str_start = get_value_by_token(temp + 2, "DTSTART:", "\r\n");
618 goto_if(str_start == NULL, "str_start is NULL. temp = %s", temp);
620 if (strstr(str_start, "Z") != NULL) {
621 _DEBUG_INFO("GMT timezone setting");
622 service_ret = calendar_record_set_str(cal_record, _calendar_event.start_tzid, TIMEZONE_GMT);
623 goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail! : err[%d]", service_ret);
625 service_ret = calendar_record_set_str(cal_record, _calendar_event.end_tzid, TIMEZONE_GMT);
626 goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail! : err[%d]", service_ret);
638 char * remove_uid(char *origin)
641 retvm_if((origin == NULL || strlen(origin) <= 0), NULL, "origin is NULL");
643 _DEBUG_INFO("origin = %s", origin);
645 char *str_uid = NULL;
646 char *str_uid_temp = NULL;
649 if ((temp = strstr(origin, EXTYPE_UID_KEYWORD)) == NULL) {
650 _DEBUG_ERROR("origin has not UID string");
654 str_uid = get_value_by_token(temp+2, "UID:", "\r\n");
655 goto_if(str_uid == NULL, "str_uid is NULL");
657 str_uid_temp = g_strdup_printf("%s%s\r\n", EXTYPE_UID_KEYWORD, str_uid);
658 goto_if(str_uid_temp == NULL, "str_uid_temp is NULL");
660 origin = replace_string(origin, str_uid_temp, "\r\n");
675 char * insert_exdate_data(char *origin, sync_agent_calendar_exdate_t *exdate_struct, int index)
678 retvm_if((origin == NULL || strlen(origin) <= 0), NULL, "origin is NULL");
679 retvm_if(exdate_struct == NULL, NULL, "exdate_struct is NULL");
680 retvm_if(index < 0, NULL, "index < 0");
682 char *old_str = NULL;
683 char *new_str = NULL;
684 // 1. copy from parent vcalendar string
685 char *str_child_vcalendar = strdup((char *)(origin));
687 if (exdate_struct->exdate_type <= CALENDAR_EXDATE_TYPE_NONE && exdate_struct->exdate_type >= CALENDAR_EXDATE_TYPE_MAX) {
688 _DEBUG_ERROR("exdate_type(%d) is wrong type", exdate_struct->exdate_type);
689 goto return_part_free;
692 _DEBUG_INFO("origin = %s", origin);
693 _DEBUG_INFO("cal_exdate_type = %d", exdate_struct->exdate_type);
695 if (exdate_struct->exdate_type == CALENDAR_EXDATE_TYPE_DELETED) {
696 _DEBUG_INFO("delete");
698 // 2. remove SUMMARY / RRULE / ALARM / EXDATE
699 // 2-1. remove 'SUMMARY'
700 if ((old_str = strstr(str_child_vcalendar, SUMMARY_KEYWORD)) != NULL) {
701 _DEBUG_INFO("summary keyword");
702 if ((new_str = strstr(old_str+2, "\r\n")) != NULL) {
703 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
707 // 2-2. remove 'RRULE'
708 if ((old_str = strstr(str_child_vcalendar, RRULE_KEYWORD)) != NULL) {
709 _DEBUG_INFO("rrule keyword");
710 if ((new_str = strstr(old_str+2, "\r\n")) != NULL) {
711 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
715 // 2-3. remove 'ALARM'
716 if ((old_str = strstr(str_child_vcalendar, AALARM_KEYWORD)) != NULL) {
717 _DEBUG_INFO("alarm keyword");
718 if ((new_str = strstr(old_str+2, "\r\n")) != NULL) {
719 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
723 // 2-4. remove 'EXDATE' array
724 if ((old_str = strstr(str_child_vcalendar, EXDATE_KEYWORD)) != NULL) {
725 _DEBUG_INFO("exdate keyword");
726 if ((new_str = strstr(old_str+2, "\r\nX-EXTYPE:1")) != NULL) {
727 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
730 _DEBUG_INFO("after 2nd phase str_child_vcalendar = %s", str_child_vcalendar);
732 // 3. change DTSTART / DTEND
733 // example ) DTSTART:20130125T000000Z / DTEND:20130125T003000Z / EXDATE:20130201T000000Z => DTSTART:20130201T000000Z / DTEND:20130201T003000Z
734 // 3-1. change DTSTART : DTSTART = EXDATE
736 if ((temp = strstr(str_child_vcalendar, DTSTART_KEYWORD)) != NULL) {
737 _DEBUG_INFO("start keyword");
739 old_str = get_value_by_token(temp + 2, "DTSTART:", "\r\n");// '2' means strlen("\r\n")
740 if (old_str == NULL) {
741 _DEBUG_ERROR("old_str is null");
742 goto return_part_free;
744 new_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index);
745 if (new_str == NULL) {
746 _DEBUG_ERROR("new_str is NULL");
747 goto return_part_free;
749 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
756 // 3-2. change DTEND : DTEND = date of EXDATE + time of origin DTEND
758 if ((temp = strstr(str_child_vcalendar, DTEND_KEYWORD)) != NULL) {
759 _DEBUG_INFO("end keyword");
761 old_str = get_value_by_token(temp + 2, "DTEND:", "\r\n");// '2' means strlen("\r\n")
762 if (old_str == NULL) {
763 _DEBUG_ERROR("old_str is null");
764 goto return_part_free;
766 char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index);
767 if (exdate_str == NULL) {
768 _DEBUG_ERROR("exdate_str is NULL");
769 goto return_part_free;
771 _DEBUG_INFO("exdate_str = %s", exdate_str);
772 new_str = (char *)calloc(strlen(exdate_str), sizeof(char));
773 if (new_str == NULL) {
774 _DEBUG_ERROR("new_str calloc failed");
775 goto return_part_free;
778 memcpy(new_str, exdate_str, 8);
779 memcpy(new_str + 8, old_str + 8, 8);
780 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
790 _DEBUG_INFO("after 3rd phase str_child_vcalendar = %s", str_child_vcalendar);
793 if (strstr(str_child_vcalendar, END_VEVENT_KEYWORD) != NULL) {
794 _DEBUG_INFO("EXTYPE keyword");
796 char *str_end_vevent = "\r\nEND:VEVENT";
797 char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index);
798 if (exdate_str == NULL) {
799 _DEBUG_ERROR("exdate_str is NULL");
800 goto return_part_free;
803 new_str = g_strdup_printf("%s%s%s", EXDATE_KEYWORD, exdate_str, str_end_vevent);
804 if (new_str == NULL) {
805 _DEBUG_ERROR("new_str is null");
806 goto return_part_free;
809 str_child_vcalendar = replace_string(str_child_vcalendar, str_end_vevent, new_str);
816 if (strstr(str_child_vcalendar, EXTYPE_DELETE_KEYWORD) != NULL) {
817 str_child_vcalendar = replace_string(str_child_vcalendar, EXTYPE_DELETE_KEYWORD, "UID:000000000000000000000000000000000000000000000000\r\nX-EXTYPE:1");
819 goto return_part_free;
821 else if (exdate_struct->exdate_type == CALENDAR_EXDATE_TYPE_UPDATED_CHILD) {
822 _DEBUG_INFO("update child");
825 if ((old_str = strstr(str_child_vcalendar, RRULE_KEYWORD)) != NULL) {
826 _DEBUG_INFO("rrule keyword");
827 if ((new_str = strstr(old_str+2, "\r\n")) != NULL) {
828 str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
833 if (strstr(str_child_vcalendar, END_VEVENT_KEYWORD) != NULL) {
834 _DEBUG_INFO("EXTYPE keyword");
836 char *str_end_vevent = "\r\nEND:VEVENT";
837 char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index);
838 goto_if(exdate_str == NULL, "exdate_str is NULL");
839 _DEBUG_INFO("exdate_str = %s", exdate_str);
841 new_str = g_strdup_printf("%s%s%s", EXDATE_KEYWORD, exdate_str, str_end_vevent);
842 goto_if(new_str == NULL, "new_str is NULL");
844 str_child_vcalendar = replace_string(str_child_vcalendar, str_end_vevent, new_str);
853 _DEBUG_INFO("last str_child_vcalendar = %s", str_child_vcalendar);
855 return str_child_vcalendar;
858 _DEBUG_INFO("last str_child_vcalendar = %s", str_child_vcalendar);
864 return str_child_vcalendar;
867 void insert_allday_data(const char *origin, calendar_record_h calendar_record)
870 retm_if((origin == NULL || strlen(origin) <= 0), "origin is NULL");
871 retm_if(calendar_record == NULL, "calendar_record is NULL");
873 int service_ret = CALENDAR_ERROR_NONE;
876 service_ret = calendar_record_get_uri_p(calendar_record, &uri);
877 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_uri_p() Fail!: err[%d]", service_ret);
879 if (strncmp(uri, _calendar_event._uri, strlen(_calendar_event._uri))) {
880 _DEBUG_ERROR("this is not event");
884 calendar_time_s cal_time_start = { 0, };
885 calendar_time_s cal_time_end = { 0, };
890 service_ret = calendar_record_get_caltime(calendar_record, _calendar_event.start_time, &cal_time_start);
891 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() Fail!: err[%d]", service_ret);
893 char *start_date_loc = NULL;
894 if ((start_date_loc = strstr(origin, DTSTART_KEYWORD)) == NULL) {
895 _DEBUG_ERROR("start_date_loc is null");
899 char str_year_start[5] = {0,};
900 char str_month_start[3] = {0,};
901 char str_date_start[3] = {0,};
903 /* example) 20130124T000000Z\r\n = 2013 01 24 T 00 00 00 Z \r\n */
904 strncpy(str_year_start, start_date_loc + strlen(DTSTART_KEYWORD), 4);
905 strncpy(str_month_start, start_date_loc + strlen(DTSTART_KEYWORD) + 4, 2);
906 strncpy(str_date_start, start_date_loc + strlen(DTSTART_KEYWORD) + 4 + 2, 2);
908 year = atoi(str_year_start);
909 month = atoi(str_month_start);
910 day = atoi(str_date_start);
912 _DEBUG_INFO("start time : year = %d, month = %d, day = %d", year, month, day);
913 cal_time_start.type = CALENDAR_TIME_LOCALTIME;
914 cal_time_start.time.date.year = year;
915 cal_time_start.time.date.month = month;
916 cal_time_start.time.date.mday = day;
918 service_ret = calendar_record_set_caltime(calendar_record, _calendar_event.start_time, cal_time_start);
919 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() Fail!: err[%d]", service_ret);
921 service_ret = calendar_record_get_caltime(calendar_record, _calendar_event.end_time, &cal_time_end);
922 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() Fail!: err[%d]", service_ret);
924 char *end_date_loc = NULL;
925 if ((end_date_loc = strstr(origin, DTEND_KEYWORD)) == NULL) {
926 _DEBUG_ERROR("end_date_loc is null");
930 char str_year_end[5] = {0,};
931 char str_month_end[3] = {0,};
932 char str_date_end[3] = {0,};
934 /* example) 20130124T000000Z\r\n = 2013 01 24 T 00 00 00 Z \r\n */
935 strncpy(str_year_end, end_date_loc + strlen(DTEND_KEYWORD), 4);
936 strncpy(str_month_end, end_date_loc + strlen(DTEND_KEYWORD) + 4, 2);
937 strncpy(str_date_end, end_date_loc + strlen(DTEND_KEYWORD) + 4 + 2, 2);
939 year = atoi(str_year_end);
940 month = atoi(str_month_end);
941 day = atoi(str_date_end);
943 _DEBUG_INFO("end time : year = %d, month = %d, day = %d", year, month, day);
944 cal_time_end.type = CALENDAR_TIME_LOCALTIME;
945 cal_time_end.time.date.year = year;
946 cal_time_end.time.date.month = month;
947 cal_time_end.time.date.mday = day;
949 service_ret = calendar_record_set_caltime(calendar_record, _calendar_event.end_time, cal_time_end);
950 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() Fail!: err[%d]", service_ret);
957 EXPORT_API char * has_image_import(const char *origin)
961 char *temp_image_path = NULL;
962 char *image_path = NULL;
963 _DEBUG_INFO("origin = %s", origin);
965 if (strstr(origin, CR_IMAGE_KEYWORD_PREFIX_PHOTO) == NULL && strstr(origin, CR_IMAGE_KEYWORD_PREFIX_SNOTE) == NULL) {
966 _DEBUG_INFO("this calendar has not an image");
970 temp_image_path = get_value_by_token(origin, IMAGE_KEYWORD_BEGIN_PATH, IMAGE_KEYWORD_END_PATH);
971 goto_if(temp_image_path == NULL, "temp_image_path is NULL");
973 if (strstr(temp_image_path, INTERNAL_MEMORY_CONVERTED) != NULL) {
974 image_path = replace_string(temp_image_path, INTERNAL_MEMORY_CONVERTED, INTERNAL_MEMORY_ORIGIN);
976 else if (strstr(temp_image_path, EXTERNAL_MEMORY_CONVERTED) != NULL) {
977 image_path = replace_string(temp_image_path, EXTERNAL_MEMORY_CONVERTED, EXTERNAL_MEMORY_ORIGIN);
979 else if (strstr(temp_image_path, SNOTE_MEMORY_ORIGIN) != NULL) {
980 image_path = strdup(temp_image_path);
983 _DEBUG_ERROR("there is an error. origin = %s", origin);
989 _DEBUG_INFO("image_path = %s", image_path);
994 EXPORT_API char * has_image_export(calendar_record_h cal_record)
997 retvm_if(cal_record == NULL, NULL, "cal_record is NULL");
999 calendar_record_h image_record = NULL;
1000 unsigned int child_record_count = 0;
1002 int service_ret = CALENDAR_ERROR_NONE;
1003 char *image_key = NULL;
1004 char *image_path = NULL;
1007 service_ret = calendar_record_get_uri_p(cal_record, &uri);
1008 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_uri_p() Fail!: err[%d]", service_ret);
1010 _DEBUG_INFO("uri = %s", uri);
1012 service_ret = calendar_record_get_child_record_count(cal_record, _calendar_event.extended, &child_record_count);
1013 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() Fail!: err[%d]", service_ret);
1015 for (i = 0; i < child_record_count; i++) {
1016 service_ret = calendar_record_get_child_record_at_p(cal_record, _calendar_event.extended, i, &image_record);
1017 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret);
1019 service_ret = calendar_record_get_str_p(image_record, _calendar_extended_property.key, &image_key);
1020 goto_if(service_ret != CALENDAR_ERROR_NONE || image_key == NULL || strlen(image_key) <= 0, "calendar_record_get_str_p() Fail!: err[%d]", service_ret);
1022 if (strcmp(image_key, CALENDAR_IMAGE_KEYWORD_SNOTE) == 0 || strcmp(image_key, CALENDAR_IMAGE_KEYWORD_PHOTO) == 0) {
1023 _DEBUG_INFO("image is founded. image_key = %s", image_key);
1024 service_ret = calendar_record_get_str(image_record, _calendar_extended_property.value, &image_path);
1025 goto_if(service_ret != CALENDAR_ERROR_NONE || image_path == NULL || strlen(image_path) <= 0, "calendar_record_get_str() Fail!: err[%d]", service_ret);
1026 _DEBUG_INFO("image_path = %s", image_path);
1036 // "EXTYPE" setting, '1' means deleted, '2' means updated : it should be excuted before calendar_vcalendar_make_from_records
1037 void get_exdate_data(calendar_record_h cal_record, sync_agent_calendar_exdate_t *exdate_struct)
1040 retm_if(cal_record == NULL, "cal_record is NULL");
1041 retm_if(exdate_struct == NULL, "exdate_struct is NULL");
1043 calendar_record_h extended_exdate = NULL;
1044 int service_ret = CALENDAR_ERROR_NONE;
1045 int original_event_id = 0;
1046 char *exdate = NULL;
1047 char *recurrence_id = NULL;
1049 exdate_struct->exdate_type = CALENDAR_EXDATE_TYPE_NONE;
1050 exdate_struct->exdate_count = 0;
1051 exdate_struct->exdate_list = NULL;
1053 service_ret = calendar_record_get_int(cal_record, _calendar_event.original_event_id, &original_event_id);
1054 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_int() Fail!: err[%d]", service_ret);
1055 _DEBUG_INFO("original_event_id = %d", original_event_id);
1057 service_ret = calendar_record_get_str(cal_record, _calendar_event.recurrence_id, &recurrence_id);
1058 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_str() Fail!: err[%d]", service_ret);
1059 _DEBUG_INFO("recurrence_id = %s", recurrence_id);
1061 if (original_event_id >= 0 && recurrence_id != NULL && strlen(recurrence_id) > 0) {
1062 service_ret = calendar_record_set_str(cal_record, _calendar_event.exdate, NULL);
1063 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail!: err[%d]", service_ret);
1066 // 1. delete : if 'exdate' value is exist, there are deleted item.
1067 service_ret = calendar_record_get_str(cal_record, _calendar_event.exdate, &exdate);
1068 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_str() Fail!: err[%d]", service_ret);
1069 _DEBUG_INFO("exdate = %s", exdate);
1071 if (exdate != NULL && strlen(exdate) > 0) {
1072 _DEBUG_INFO("EXTYPE:DELETE setting start");
1073 service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_exdate);
1074 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_create() Fail!: err[%d]", service_ret);
1076 service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.key, "X-EXTYPE");
1077 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail!: err[%d]", service_ret);
1079 service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.value, ":1");
1080 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail!: err[%d]", service_ret);
1082 service_ret = calendar_record_add_child_record(cal_record, _calendar_event.extended, extended_exdate);
1083 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_add_child_record() Fail!: err[%d]", service_ret);
1085 exdate_struct->exdate_type = CALENDAR_EXDATE_TYPE_DELETED;
1086 char *str_exdate_loc = NULL;
1087 int exdate_count = 0;
1089 while (exdate_loc < strlen(exdate)) {
1090 int one_exdate_length = 0;
1091 if ((str_exdate_loc = strstr(exdate + exdate_loc, ",")) != NULL) {
1092 one_exdate_length = strlen(exdate) - strlen(str_exdate_loc) - (exdate_count*(DATE_TIME_LENGTH+1));
1095 one_exdate_length = strlen(exdate) - exdate_loc;
1097 _DEBUG_INFO("str_exdate_loc = %s", str_exdate_loc);
1098 if (one_exdate_length <= 0) {
1099 _DEBUG_ERROR("one_exdate_length (%d) <= 0", one_exdate_length);
1102 char *str_one_exdate = (char *)calloc(one_exdate_length, sizeof(char));
1103 if (str_one_exdate == NULL) {
1104 _DEBUG_ERROR("str_one_exdate calloc is failed.");
1107 memcpy(str_one_exdate, exdate + exdate_loc, one_exdate_length);
1108 exdate_loc += (one_exdate_length+1); // '1' meaning of ',' length
1109 exdate_struct->exdate_list = g_list_append(exdate_struct->exdate_list, str_one_exdate);
1111 _DEBUG_INFO("str_one_exdate = %s", str_one_exdate);
1114 _DEBUG_INFO("exdate_count = %d", exdate_count);
1115 exdate_struct->exdate_count = exdate_count;
1116 _DEBUG_INFO("EXTYPE:DELETE setting end");
1120 // 2. update : if 'origianl_event_id' and 'recurrence_id' value are exist, there are updated item.
1121 if (original_event_id < 0 && recurrence_id == NULL ) {
1122 unsigned int count = 0;
1123 service_ret = calendar_record_get_child_record_count(cal_record, _calendar_event.exception, &count);
1124 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() Fail! err[%d]\n", service_ret);
1126 _DEBUG_INFO("this is a normal calendar");
1130 _DEBUG_INFO("parent EXTYPE:UPDATE setting start");
1131 exdate_struct->exdate_type = CALENDAR_EXDATE_TYPE_UPDATED_PARENT;
1132 service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_exdate);
1133 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_create() Fail! err[%d]\n", service_ret);
1135 service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.key, "X-EXTYPE");
1136 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail! err[%d]\n", service_ret);
1138 service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.value, ":2");
1139 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail! err[%d]\n", service_ret);
1141 service_ret = calendar_record_add_child_record(cal_record, _calendar_event.extended, extended_exdate);
1142 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_add_child_record() Fail! err[%d]\n", service_ret);
1144 else if (original_event_id >= 0 && recurrence_id != NULL && strlen(recurrence_id) > 0) {
1145 _DEBUG_INFO("child EXTYPE:UPDATE setting start");
1146 exdate_struct->exdate_type = CALENDAR_EXDATE_TYPE_UPDATED_CHILD;
1147 exdate_struct->exdate_list = g_list_append(exdate_struct->exdate_list, recurrence_id);
1148 exdate_struct->exdate_count = 1;
1149 service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_exdate);
1150 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_create() Fail!: err[%d]", service_ret);
1152 service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.key, "X-EXTYPE");
1153 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail! err[%d]\n", service_ret);
1155 service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.value, ":2");
1156 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail! err[%d]\n", service_ret);
1158 service_ret = calendar_record_add_child_record(cal_record, _calendar_event.extended, extended_exdate);
1159 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_add_child_record() Fail! err[%d]\n", service_ret);
1167 char * replace_rrule_data(char *origin)
1170 retvm_if(origin == NULL, origin, "origin is NULL.");
1173 char *temp_rrule = NULL;
1174 char *str_old_rrule = NULL;
1175 char *str_new_rrule = NULL;
1177 temp = strstr(origin, RRULE_KEYWORD);
1179 _DEBUG_INFO("this vcalendar hasn't rrule data");
1183 // case 1 : weekdays rrule converting
1184 if (strstr(origin, WEEKDAY_RRULE_ORIGIN_KEYWORD) != NULL) {
1185 _DEBUG_INFO("this vcalendar has WEEKDAYS rrule data");
1187 origin = replace_string(origin, WEEKDAY_RRULE_ORIGIN_KEYWORD, WEEKDAY_RRULE_CONVERTED_KEYWORD);
1188 _DEBUG_INFO("AFTER origin = %s", origin);
1192 // case 2 : max rrule converting
1193 str_old_rrule = get_value_by_token(temp + 2, "RRULE:", "\r\n");// '2' means strlen("\r\n")
1194 goto_if(str_old_rrule == NULL, "str_old_rrule is null");
1196 if (strstr(str_old_rrule, MAX_RRULE_DATE_KEYWORD) == NULL) {
1197 _DEBUG_INFO("this vcalendar has rrule data, But it's not until=NONE rrule");
1200 _DEBUG_INFO("this vcalendar has until=NONE rrule");
1202 temp_rrule = get_value_by_token(temp, RRULE_KEYWORD, MAX_RRULE_DATE_KEYWORD);
1203 goto_if(temp_rrule == NULL, "temp_rrule is null");
1205 // every eternal rrule data must have '#0' at the end of string (Calendar-Svc recommend)
1206 str_new_rrule = g_strdup_printf("%s#0", temp_rrule);
1207 goto_if(str_new_rrule == NULL, "str_new_rrule is null");
1208 _DEBUG_INFO("str_new_rrule = %s", str_new_rrule);
1210 origin = replace_string(origin, str_old_rrule, str_new_rrule);
1214 free(str_old_rrule);
1215 str_old_rrule = NULL;
1218 free(str_new_rrule);
1219 str_new_rrule = NULL;
1229 char * replace_image_data(char *origin, char *image_path)
1232 retvm_if(origin == NULL, origin, "origin is NULL.");
1233 retvm_if(image_path == NULL, origin, "image_path is NULL.");
1235 char *str_temp_image_info = NULL;
1236 char *str_image_info = NULL;
1237 char *str_image_tag = NULL;
1239 if (strstr(image_path, INTERNAL_MEMORY_ORIGIN) != NULL) {
1240 str_temp_image_info = replace_string(image_path, INTERNAL_MEMORY_ORIGIN, INTERNAL_MEMORY_CONVERTED);
1241 str_image_tag = strdup(IMAGE_KEYWORD_PREFIX_PHOTO);
1243 else if (strstr(image_path, EXTERNAL_MEMORY_ORIGIN) != NULL) {
1244 str_temp_image_info = replace_string(image_path, EXTERNAL_MEMORY_ORIGIN, EXTERNAL_MEMORY_CONVERTED);
1245 str_image_tag = strdup(IMAGE_KEYWORD_PREFIX_PHOTO);
1247 else if (strstr(image_path, SNOTE_MEMORY_ORIGIN) != NULL) {
1248 str_temp_image_info = strdup(image_path);
1249 //str_image_tag = strdup(IMAGE_KEYWORD_PREFIX_SNOTE);
1250 str_image_tag = strdup(IMAGE_KEYWORD_PREFIX_PHOTO);
1253 _DEBUG_ERROR("there is an error. image_path = %s", image_path);
1257 goto_if(strstr(origin, END_VEVENT_KEYWORD) == NULL, "this data is wrong format. origin = %s", origin);
1259 str_image_info = g_strdup_printf("\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);
1260 goto_if(str_image_info == NULL, "str_image_info is null");
1262 char *new_agent_data = replace_string(origin, END_VEVENT_KEYWORD, str_image_info);
1264 origin = new_agent_data;
1268 if (str_image_info) {
1269 free(str_image_info);
1270 str_image_info = NULL;
1272 if (str_image_tag) {
1273 free(str_image_tag);
1274 str_image_tag = NULL;
1276 if (str_temp_image_info) {
1277 free(str_temp_image_info);
1278 str_temp_image_info = NULL;
1285 // exdate string format like as "20130211T000000Z,20130212T000000Z,20130213T000000Z"
1286 void replace_deleted_exdate_data(const char *origin, calendar_record_h parent_record)
1289 retm_if(origin == NULL, "origin is NULL.");
1290 retm_if(parent_record == NULL, "parent_record is NULL");
1292 char *str_exdata_loc = NULL;
1293 char *old_exdate_str = NULL;
1294 char *new_exdate_str = NULL;
1295 char *new_one_exdate_str = NULL;
1296 int exdate_length = 0;
1297 int service_ret = CALENDAR_ERROR_NONE;
1299 str_exdata_loc = strstr(origin, IMPORT_EXTYPE_DELETE_KEYWORD);
1300 goto_if(str_exdata_loc == NULL, "this vcalendar has not exdate data");
1302 new_one_exdate_str = get_value_by_token(str_exdata_loc + 2, "EXDATE:", "\r\n");
1303 _DEBUG_INFO("new_one_exdate_str = %s", new_one_exdate_str);
1305 service_ret = calendar_record_get_str(parent_record, _calendar_event.exdate, &old_exdate_str);
1306 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail! err[%d]\n", service_ret);
1308 _DEBUG_INFO("old_exdate_str = %s", old_exdate_str);
1309 int old_exdate_str_length = 0;
1310 if (old_exdate_str == NULL) {
1311 old_exdate_str_length = 0;
1314 old_exdate_str_length = strlen(old_exdate_str);
1315 if (strstr(old_exdate_str, new_one_exdate_str) != NULL) {
1316 _DEBUG_ERROR("new_one_exdate_str is already exist in old_exdate_str");
1321 exdate_length = old_exdate_str_length + strlen(new_one_exdate_str) + 2;
1322 new_exdate_str = (char *)calloc(exdate_length, sizeof(char));
1323 goto_if(new_exdate_str == NULL, "new_exdate_str calloc failed, exdate_length = %d", exdate_length);
1325 if (old_exdate_str == NULL)
1326 snprintf(new_exdate_str, exdate_length, "%s", new_one_exdate_str);
1328 snprintf(new_exdate_str, exdate_length, "%s,%s", old_exdate_str, new_one_exdate_str);
1330 _DEBUG_INFO("new_exdate_str = %s", new_exdate_str);
1331 service_ret = calendar_record_set_str(parent_record, _calendar_event.exdate, new_exdate_str);
1332 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail! err[%d]\n", service_ret);
1335 if(new_one_exdate_str) {
1336 free(new_one_exdate_str);
1337 new_one_exdate_str = NULL;
1339 if(new_exdate_str) {
1340 free(new_exdate_str);
1341 new_exdate_str = NULL;
1347 int replace_updated_exdate_data(const char *origin, calendar_record_h parent_record)
1350 retvm_if(origin == NULL, -1, "origin is NULL.");
1351 retvm_if(parent_record == NULL, -1, "parent_record is NULL");
1353 calendar_record_h child_record = NULL;
1354 char *str_exdata_loc = NULL;
1355 char *new_one_exdate_str = NULL;
1356 int parent_service_id = 0;
1357 int child_service_id = 0;
1358 int service_ret = CALENDAR_ERROR_NONE;
1361 str_exdata_loc = strstr(origin, IMPORT_EXTYPE_UPDATE_KEYWORD);
1362 goto_if(str_exdata_loc == NULL, "this vcalendar has not exdate data");
1364 new_one_exdate_str = get_value_by_token(str_exdata_loc + 2, "EXDATE:", "\r\n");
1365 _DEBUG_INFO("new_one_exdate_str = %s", new_one_exdate_str);
1367 service_ret = calendar_record_clone(parent_record, &child_record);
1368 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_clone() Fail!: err[%d]", service_ret);
1370 service_ret = calendar_record_get_int(parent_record, _calendar_event.id, &parent_service_id);
1371 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_int() Fail!: err[%d]", service_ret);
1372 _DEBUG_INFO("parent_service_id = %d", parent_service_id);
1374 service_ret = calendar_record_set_int(child_record, _calendar_event.original_event_id, parent_service_id);
1375 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_int() Fail!: err[%d]", service_ret);
1377 service_ret = calendar_record_set_str(child_record, _calendar_event.recurrence_id, new_one_exdate_str);
1378 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail!: err[%d]", service_ret);
1380 service_ret = calendar_record_set_str(child_record, _calendar_event.exdate, NULL);
1381 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail!: err[%d]", service_ret);
1383 service_ret = calendar_db_insert_record(child_record, &child_service_id);
1384 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_db_insert_record() Fail!: err[%d]", service_ret);
1386 service_ret = calendar_record_destroy(child_record, true);
1387 goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_destroy() Fail!: err[%d]", service_ret);
1388 _DEBUG_INFO("child_service_id = %d", child_service_id);
1390 ret = child_service_id;
1393 if(new_one_exdate_str) {
1394 free(new_one_exdate_str);
1395 new_one_exdate_str = NULL;
1397 if (service_ret != CALENDAR_ERROR_NONE)