[Internal: merge private->RSA , Patch create momanager.db]
[platform/core/system/sync-agent.git] / src / fw-plugins / common-public / vcalendar / src / vcalendar_string_util.c
index e03e98a..52c56f0 100755 (executable)
@@ -254,7 +254,7 @@ static char * _replace_alarm_data(char *origin)
        char *str_interval = NULL;
        calendar_date_type_e cal_type = CALENDAR_DATE_TYPE_ONTIME;
 
-       if ((freq_loc = strstr(origin, BEGIN_ALARM_KEYWORD)) == NULL) {
+       if ((freq_loc = strstr(origin, "\r\nBEGIN:VALARM")) == NULL) {
                _DEBUG_ERROR("there is not trigger data");
                goto return_part;
        }
@@ -600,6 +600,39 @@ char * replace_string(char *origin, const char *src, const char *dest)
        return new_str;
 }
 
+EXPORT_API calendar_list_h set_vcalendar_version(calendar_record_h cal_record)
+{
+       _INNER_FUNC_ENTER;
+       retvm_if(cal_record == NULL, NULL, "cal_record is NULL");
+
+       int service_ret = CALENDAR_ERROR_NONE;
+       calendar_list_h list = NULL;
+       calendar_record_h extended_version = NULL;
+
+       service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_version);
+       goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_create() Fail!: err[%d]", service_ret);
+
+       service_ret = calendar_record_set_str(extended_version, _calendar_extended_property.key, "VERSION");
+       goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret);
+
+       service_ret = calendar_record_set_str(extended_version, _calendar_extended_property.value, ":1.0");
+       goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret);
+
+       service_ret = calendar_list_create(&list);
+       goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_list_create() Fail!: err[%d]", service_ret);
+
+       service_ret = calendar_list_add(list, extended_version);
+       goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_list_add() Fail!: err[%d]", service_ret);
+
+       service_ret = calendar_list_add(list, cal_record);
+       goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_list_add() Fail!: err[%d]", service_ret);
+
+return_part:
+       _INNER_FUNC_EXIT;
+       return list;
+}
+
+
 // PLM(P130408-0777) : In case of DTSTART / DTEND with zulu time ('Z'), GMT timezone should be set.
 EXPORT_API void set_timezone(const char *origin, calendar_record_h cal_record)
 {
@@ -611,10 +644,10 @@ EXPORT_API void set_timezone(const char *origin, calendar_record_h cal_record)
        char *temp = NULL;
        char *str_start = NULL;
 
-       temp = strstr(origin, DTSTART_KEYWORD);
+       temp = strstr(origin, "\r\n"DTSTART_KEYWORD);
        goto_if(temp == NULL, "origin has not DTSTART. origin = %s", origin);
 
-       str_start = get_value_by_token(temp + 2, "DTSTART:", "\r\n");
+       str_start = get_value_by_token(temp + 2, DTSTART_KEYWORD, "\r\n");
        goto_if(str_start == NULL, "str_start is NULL. temp = %s", temp);
 
        if (strstr(str_start, "Z") != NULL) {
@@ -635,6 +668,119 @@ return_part:
        return;
 }
 
+void set_allday(const char *origin, calendar_record_h calendar_record, bool is_phone_to_kies)
+{
+       _INNER_FUNC_ENTER;
+       retm_if(calendar_record == NULL, "calendar_record is NULL");
+       int service_ret = CALENDAR_ERROR_NONE;
+
+       if (is_phone_to_kies) {
+               _DEBUG_INFO("phone to kies");
+               calendar_time_s cal_start_time = {0,};
+               calendar_record_h extended_allday = NULL;
+
+               service_ret = calendar_record_get_caltime(calendar_record, _calendar_event.start_time, &cal_start_time);
+               goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_caltime() Fail!: err[%d]", service_ret);
+
+               service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_allday);
+               goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_create() Fail!: err[%d]", service_ret);
+
+               service_ret = calendar_record_set_str(extended_allday, _calendar_extended_property.key, ALLDAY_PREFIX);
+               goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret);
+
+               if (cal_start_time.type == CALENDAR_TIME_LOCALTIME)
+                       service_ret = calendar_record_set_str(extended_allday, _calendar_extended_property.value, "SET");
+               else
+                       service_ret = calendar_record_set_str(extended_allday, _calendar_extended_property.value, "UNSET");
+
+               goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret);
+
+               service_ret = calendar_record_add_child_record(calendar_record, _calendar_event.extended, extended_allday);
+               goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_add_child_record() Fail!: err[%d]", service_ret);
+       }
+       else {
+               _DEBUG_INFO("kies to phone");
+               retm_if((origin == NULL || strlen(origin) <= 0), "origin is NULL");
+               char *uri = NULL;
+
+               service_ret = calendar_record_get_uri_p(calendar_record, &uri);
+               goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_uri_p() Fail!: err[%d]", service_ret);
+
+               if (strncmp(uri, _calendar_event._uri, strlen(_calendar_event._uri))) {
+                       _DEBUG_ERROR("this is not event");
+                       goto return_part;
+               }
+
+               calendar_time_s cal_time_start = { 0, };
+               calendar_time_s cal_time_end = { 0, };
+               int year = 0;
+               int month = 0;
+               int day = 0;
+
+               service_ret = calendar_record_get_caltime(calendar_record, _calendar_event.start_time, &cal_time_start);
+               goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() Fail!: err[%d]", service_ret);
+
+               char *start_date_loc = NULL;
+               start_date_loc = strstr(origin, "\r\n"DTSTART_KEYWORD);
+               goto_if(start_date_loc == NULL, "start_date_loc is null");
+
+               char str_year_start[5] = {0,};
+               char str_month_start[3] = {0,};
+               char str_date_start[3] = {0,};
+
+               /* example) 20130124T000000Z\r\n = 2013 01 24 T 00 00 00 Z \r\n */
+               strncpy(str_year_start, start_date_loc + strlen("\r\n"DTSTART_KEYWORD), 4);
+               strncpy(str_month_start, start_date_loc + strlen("\r\n"DTSTART_KEYWORD) + 4, 2);
+               strncpy(str_date_start, start_date_loc + strlen("\r\n"DTSTART_KEYWORD) + 4 + 2, 2);
+
+               year = atoi(str_year_start);
+               month = atoi(str_month_start);
+               day = atoi(str_date_start);
+
+               _DEBUG_INFO("start time : year = %d, month = %d, day = %d", year, month, day);
+               cal_time_start.type = CALENDAR_TIME_LOCALTIME;
+               cal_time_start.time.date.year = year;
+               cal_time_start.time.date.month = month;
+               cal_time_start.time.date.mday = day;
+
+               service_ret = calendar_record_set_caltime(calendar_record, _calendar_event.start_time, cal_time_start);
+               goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() Fail!: err[%d]", service_ret);
+
+               service_ret = calendar_record_get_caltime(calendar_record, _calendar_event.end_time, &cal_time_end);
+               goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() Fail!: err[%d]", service_ret);
+
+               char *end_date_loc = NULL;
+               end_date_loc = strstr(origin, "\r\n"DTEND_KEYWORD);
+               goto_if(end_date_loc == NULL, "end_date_loc is null");
+
+               char str_year_end[5] = {0,};
+               char str_month_end[3] = {0,};
+               char str_date_end[3] = {0,};
+
+               /* example) 20130124T000000Z\r\n = 2013 01 24 T 00 00 00 Z \r\n */
+               strncpy(str_year_end, end_date_loc + strlen("\r\n"DTEND_KEYWORD), 4);
+               strncpy(str_month_end, end_date_loc + strlen("\r\n"DTEND_KEYWORD) + 4, 2);
+               strncpy(str_date_end, end_date_loc + strlen("\r\n"DTEND_KEYWORD) + 4 + 2, 2);
+
+               year = atoi(str_year_end);
+               month = atoi(str_month_end);
+               day = atoi(str_date_end);
+
+               _DEBUG_INFO("end time : year = %d, month = %d, day = %d", year, month, day);
+               cal_time_end.type = CALENDAR_TIME_LOCALTIME;
+               cal_time_end.time.date.year = year;
+               cal_time_end.time.date.month = month;
+               cal_time_end.time.date.mday = day;
+
+               service_ret = calendar_record_set_caltime(calendar_record, _calendar_event.end_time, cal_time_end);
+               goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() Fail!: err[%d]", service_ret);
+       }
+
+return_part:
+       _INNER_FUNC_EXIT;
+       return;
+}
+
 char * remove_uid(char *origin)
 {
        _INNER_FUNC_ENTER;
@@ -697,7 +843,7 @@ char * insert_exdate_data(char *origin, sync_agent_calendar_exdate_t *exdate_str
 
                // 2. remove SUMMARY / RRULE / ALARM / EXDATE
                // 2-1. remove 'SUMMARY'
-               if ((old_str = strstr(str_child_vcalendar, SUMMARY_KEYWORD)) != NULL) {
+               if ((old_str = strstr(str_child_vcalendar, "\r\n"SUMMARY_KEYWORD)) != NULL) {
                        _DEBUG_INFO("summary keyword");
                        if ((new_str = strstr(old_str+2, "\r\n")) != NULL) {
                                str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
@@ -713,7 +859,7 @@ char * insert_exdate_data(char *origin, sync_agent_calendar_exdate_t *exdate_str
                }
 
                // 2-3. remove 'ALARM'
-               if ((old_str = strstr(str_child_vcalendar, AALARM_KEYWORD)) != NULL) {
+               if ((old_str = strstr(str_child_vcalendar, "\r\n"AALARM_KEYWORD)) != NULL) {
                        _DEBUG_INFO("alarm keyword");
                        if ((new_str = strstr(old_str+2, "\r\n")) != NULL) {
                                str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str);
@@ -733,10 +879,10 @@ char * insert_exdate_data(char *origin, sync_agent_calendar_exdate_t *exdate_str
                // example ) DTSTART:20130125T000000Z / DTEND:20130125T003000Z / EXDATE:20130201T000000Z => DTSTART:20130201T000000Z / DTEND:20130201T003000Z
                // 3-1. change DTSTART : DTSTART = EXDATE
                char *temp = NULL;
-               if ((temp  = strstr(str_child_vcalendar, DTSTART_KEYWORD)) != NULL) {
+               if ((temp  = strstr(str_child_vcalendar, "\r\n"DTSTART_KEYWORD)) != NULL) {
                        _DEBUG_INFO("start keyword");
 
-                       old_str = get_value_by_token(temp + 2, "DTSTART:", "\r\n");// '2' means strlen("\r\n")
+                       old_str = get_value_by_token(temp + 2, DTSTART_KEYWORD, "\r\n");// '2' means strlen("\r\n")
                        if (old_str == NULL) {
                                _DEBUG_ERROR("old_str is null");
                                goto return_part_free;
@@ -755,10 +901,10 @@ char * insert_exdate_data(char *origin, sync_agent_calendar_exdate_t *exdate_str
 
                // 3-2. change DTEND : DTEND = date of EXDATE + time of origin DTEND
                temp = NULL;
-               if ((temp  = strstr(str_child_vcalendar, DTEND_KEYWORD)) != NULL) {
+               if ((temp  = strstr(str_child_vcalendar, "\r\n"DTEND_KEYWORD)) != NULL) {
                        _DEBUG_INFO("end keyword");
 
-                       old_str = get_value_by_token(temp + 2, "DTEND:", "\r\n");// '2' means strlen("\r\n")
+                       old_str = get_value_by_token(temp + 2, DTEND_KEYWORD, "\r\n");// '2' means strlen("\r\n")
                        if (old_str == NULL) {
                                _DEBUG_ERROR("old_str is null");
                                goto return_part_free;
@@ -790,23 +936,22 @@ char * insert_exdate_data(char *origin, sync_agent_calendar_exdate_t *exdate_str
                _DEBUG_INFO("after 3rd phase str_child_vcalendar = %s", str_child_vcalendar);
 
                // 4. insert EXDATE
-               if (strstr(str_child_vcalendar, END_VEVENT_KEYWORD) != NULL) {
+               if (strstr(str_child_vcalendar, "\r\n"END_VEVENT_KEYWORD"\r\n") != NULL) {
                        _DEBUG_INFO("EXTYPE keyword");
 
-                       char *str_end_vevent = "\r\nEND:VEVENT";
                        char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index);
                        if (exdate_str == NULL) {
                                _DEBUG_ERROR("exdate_str is NULL");
                                goto return_part_free;
                        }
 
-                       new_str = g_strdup_printf("%s%s%s", EXDATE_KEYWORD, exdate_str, str_end_vevent);
+                       new_str = g_strdup_printf("%s%s%s", EXDATE_KEYWORD, exdate_str, "\r\n"END_VEVENT_KEYWORD);
                        if (new_str == NULL) {
                                _DEBUG_ERROR("new_str is null");
                                goto return_part_free;
                        }
 
-                       str_child_vcalendar = replace_string(str_child_vcalendar, str_end_vevent, new_str);
+                       str_child_vcalendar = replace_string(str_child_vcalendar, "\r\n"END_VEVENT_KEYWORD, new_str);
                        if (new_str) {
                                free(new_str);
                                new_str = NULL;
@@ -830,18 +975,17 @@ char * insert_exdate_data(char *origin, sync_agent_calendar_exdate_t *exdate_str
                }
 
                // 3. insert EXDATE
-               if (strstr(str_child_vcalendar, END_VEVENT_KEYWORD) != NULL) {
+               if (strstr(str_child_vcalendar, "\r\n"END_VEVENT_KEYWORD"\r\n") != NULL) {
                        _DEBUG_INFO("EXTYPE keyword");
 
-                       char *str_end_vevent = "\r\nEND:VEVENT";
                        char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index);
                        goto_if(exdate_str == NULL, "exdate_str is NULL");
                        _DEBUG_INFO("exdate_str = %s", exdate_str);
 
-                       new_str = g_strdup_printf("%s%s%s", EXDATE_KEYWORD, exdate_str, str_end_vevent);
+                       new_str = g_strdup_printf("%s%s%s", EXDATE_KEYWORD, exdate_str, "\r\n"END_VEVENT_KEYWORD);
                        goto_if(new_str == NULL, "new_str is NULL");
 
-                       str_child_vcalendar = replace_string(str_child_vcalendar, str_end_vevent, new_str);
+                       str_child_vcalendar = replace_string(str_child_vcalendar, "\r\n"END_VEVENT_KEYWORD, new_str);
                        if (new_str) {
                                free(new_str);
                                new_str = NULL;
@@ -864,96 +1008,6 @@ return_part_free:
        return str_child_vcalendar;
 }
 
-void insert_allday_data(const char *origin, calendar_record_h calendar_record)
-{
-       _INNER_FUNC_ENTER;
-       retm_if((origin == NULL || strlen(origin) <= 0), "origin is NULL");
-       retm_if(calendar_record == NULL, "calendar_record is NULL");
-
-       int service_ret = CALENDAR_ERROR_NONE;
-       char *uri = NULL;
-
-       service_ret = calendar_record_get_uri_p(calendar_record, &uri);
-       goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_uri_p() Fail!: err[%d]", service_ret);
-
-       if (strncmp(uri, _calendar_event._uri, strlen(_calendar_event._uri))) {
-               _DEBUG_ERROR("this is not event");
-               goto return_part;
-       }
-
-       calendar_time_s cal_time_start = { 0, };
-       calendar_time_s cal_time_end = { 0, };
-       int year = 0;
-       int month = 0;
-       int day = 0;
-
-       service_ret = calendar_record_get_caltime(calendar_record, _calendar_event.start_time, &cal_time_start);
-       goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() Fail!: err[%d]", service_ret);
-
-       char *start_date_loc = NULL;
-       if ((start_date_loc = strstr(origin, DTSTART_KEYWORD)) == NULL) {
-               _DEBUG_ERROR("start_date_loc is null");
-               goto return_part;
-       }
-
-       char str_year_start[5] = {0,};
-       char str_month_start[3] = {0,};
-       char str_date_start[3] = {0,};
-
-       /* example) 20130124T000000Z\r\n = 2013 01 24 T 00 00 00 Z \r\n */
-       strncpy(str_year_start, start_date_loc + strlen(DTSTART_KEYWORD), 4);
-       strncpy(str_month_start, start_date_loc + strlen(DTSTART_KEYWORD) + 4, 2);
-       strncpy(str_date_start, start_date_loc + strlen(DTSTART_KEYWORD) + 4 + 2, 2);
-
-       year = atoi(str_year_start);
-       month = atoi(str_month_start);
-       day = atoi(str_date_start);
-
-       _DEBUG_INFO("start time : year = %d, month = %d, day = %d", year, month, day);
-       cal_time_start.type = CALENDAR_TIME_LOCALTIME;
-       cal_time_start.time.date.year = year;
-       cal_time_start.time.date.month = month;
-       cal_time_start.time.date.mday = day;
-
-       service_ret = calendar_record_set_caltime(calendar_record, _calendar_event.start_time, cal_time_start);
-       goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() Fail!: err[%d]", service_ret);
-
-       service_ret = calendar_record_get_caltime(calendar_record, _calendar_event.end_time, &cal_time_end);
-       goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() Fail!: err[%d]", service_ret);
-
-       char *end_date_loc = NULL;
-       if ((end_date_loc = strstr(origin, DTEND_KEYWORD)) == NULL) {
-               _DEBUG_ERROR("end_date_loc is null");
-               goto return_part;
-       }
-
-       char str_year_end[5] = {0,};
-       char str_month_end[3] = {0,};
-       char str_date_end[3] = {0,};
-
-       /* example) 20130124T000000Z\r\n = 2013 01 24 T 00 00 00 Z \r\n */
-       strncpy(str_year_end, end_date_loc + strlen(DTEND_KEYWORD), 4);
-       strncpy(str_month_end, end_date_loc + strlen(DTEND_KEYWORD) + 4, 2);
-       strncpy(str_date_end, end_date_loc + strlen(DTEND_KEYWORD) + 4 + 2, 2);
-
-       year = atoi(str_year_end);
-       month = atoi(str_month_end);
-       day = atoi(str_date_end);
-
-       _DEBUG_INFO("end time : year = %d, month = %d, day = %d", year, month, day);
-       cal_time_end.type = CALENDAR_TIME_LOCALTIME;
-       cal_time_end.time.date.year = year;
-       cal_time_end.time.date.month = month;
-       cal_time_end.time.date.mday = day;
-
-       service_ret = calendar_record_set_caltime(calendar_record, _calendar_event.end_time, cal_time_end);
-       goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() Fail!: err[%d]", service_ret);
-
-return_part:
-       _INNER_FUNC_EXIT;
-       return;
-}
-
 EXPORT_API char * has_image_import(const char *origin)
 {
        _INNER_FUNC_ENTER;
@@ -962,7 +1016,7 @@ EXPORT_API char * has_image_import(const char *origin)
        char *image_path = NULL;
        _DEBUG_INFO("origin = %s", origin);
 
-       if (strstr(origin, CR_IMAGE_KEYWORD_PREFIX_PHOTO) == NULL && strstr(origin, CR_IMAGE_KEYWORD_PREFIX_SNOTE) == NULL) {
+       if (strstr(origin, "\r\n"IMAGE_KEYWORD_PREFIX_PHOTO) == NULL && strstr(origin, "\r\n"IMAGE_KEYWORD_PREFIX_SNOTE) == NULL) {
                _DEBUG_INFO("this calendar has not an image");
                goto return_part;
        }
@@ -1254,12 +1308,12 @@ char * replace_image_data(char *origin, char *image_path)
                goto return_part;
        }
 
-       goto_if(strstr(origin, END_VEVENT_KEYWORD) == NULL, "this data is wrong format. origin = %s", origin);
+       goto_if(strstr(origin, "\r\n"END_VEVENT_KEYWORD"\r\n") == NULL, "this data is wrong format. origin = %s", origin);
 
-       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);
+       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, "\r\n"END_VEVENT_KEYWORD"\r\n");
        goto_if(str_image_info == NULL, "str_image_info is null");
 
-       char *new_agent_data = replace_string(origin, END_VEVENT_KEYWORD, str_image_info);
+       char *new_agent_data = replace_string(origin, "\r\n"END_VEVENT_KEYWORD"\r\n", str_image_info);
        origin = NULL;
        origin = new_agent_data;