merge with master
[platform/core/system/sync-agent.git] / src / fw-plugins / common-public / vcalendar-task / src / plugin_interface.c
1 /*
2  * sync-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <stdlib.h>
21 #include <glib/gprintf.h>
22
23 #include <calendar2.h>
24 #include <calendar_types2.h>
25
26 #include "utility/sync_util.h"
27 #include "plugin/data_converter_interface.h"
28 #include "encoding_util.h"
29 #include "in_datastore_info_task.h"
30 #include "vcalendar_string_util.h"
31
32 #ifndef EXPORT_API
33 #define EXPORT_API __attribute__ ((visibility("default")))
34 #endif
35
36 #ifndef SYNC_AGENT_LOG
37 #undef LOG_TAG
38 #define LOG_TAG "PLUGIN_DC_VCALENDAR"
39 #endif
40
41 static int _free_obj_field_info(sync_agent_plugin_field_info_s * field_list, int count);
42 static int _set_obj_field_info(sync_agent_plugin_field_info_s ** field_list, int count, vcalendar_field_list_s * input_list);
43 static sync_agent_da_return_e _convert_service_error_to_common_error(calendar_error_e err);
44
45 EXPORT_API sync_agent_da_return_e sync_agent_plugin_converter(const void *agent_data, void **service_data)
46 {
47         _EXTERN_FUNC_ENTER;
48
49         retvm_if(agent_data == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "agent_data is NULL. FAIL !!!");
50
51         calendar_list_h calendar_list = NULL;
52         calendar_record_h temp_service_data = NULL;
53         sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
54         int service_ret = CALENDAR_ERROR_NONE;
55         const char *temp_agent_data = (const char *)agent_data;
56         char *image_path = has_image_import(temp_agent_data);
57         char *temp_image_path = NULL;
58         char *token = NULL;
59         char *temp = NULL;
60
61         _DEBUG_INFO("temp_agent_data= %s", temp_agent_data);
62
63         // 1. priority converting : it should be excuted before calendar_vcalendar_parse_to_calendar
64         if (strstr(temp_agent_data, "\r\nPRIORITY:") != NULL) {
65                 _DEBUG_INFO("priority is founed");
66                 temp = strdup(temp_agent_data);
67                 temp = replace_priority_data(temp, false);
68                 temp_agent_data = temp;
69         }
70
71         // 2. if the vcalendar has until : NONE rrule, then max rrule should be converted : it should be excuted before calendar_vcalendar_parse_to_calendar
72         if (strstr(temp_agent_data, RRULE_KEYWORD) != NULL) {
73                 temp = strdup(temp_agent_data);
74                 temp_agent_data = replace_max_rrule_data(temp);
75                 temp = NULL;
76         }
77
78         service_ret = calendar_vcalendar_parse_to_calendar(temp_agent_data, &calendar_list);
79         if (service_ret != CALENDAR_ERROR_NONE) {
80                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_vcalendar_parse_to_calendar() Fail! err[%d]\n", service_ret);
81                 ret = _convert_service_error_to_common_error(service_ret);
82                 *service_data = NULL;
83         }
84
85         if (calendar_list == NULL) {
86                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_vcalendar_parse_to_calendar() -> temp_service_data is null, err[%d] !!", service_ret);
87                 ret = SYNC_AGENT_DA_ERRORS;
88                 goto return_part;
89         }
90
91         service_ret = calendar_list_first(calendar_list);
92         if (service_ret != CALENDAR_ERROR_NONE) {
93                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_list_first() Fail! : err[%d]", service_ret);
94                 ret = _convert_service_error_to_common_error(service_ret);
95         }
96
97         do
98     {
99                 char *uri = NULL;
100         service_ret = calendar_list_get_current_record_p(calendar_list, &temp_service_data);
101                 if ((service_ret != CALENDAR_ERROR_NONE) || (temp_service_data == NULL)) {
102                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_list_get_current_record_p() Fail! : err[%d]", service_ret);
103                         goto return_part;
104                 }
105
106                 service_ret = calendar_record_get_uri_p(temp_service_data, &uri);
107                 if (service_ret != CALENDAR_ERROR_NONE) {
108                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret);
109                         goto return_part;
110                 }
111
112                 if (!strncmp(uri, _calendar_todo._uri, strlen(_calendar_todo._uri))) {
113                         _DEBUG_INFO("this is todo");
114                         break;
115                 }
116                 else if (!strncmp(uri, _calendar_extended_property._uri, strlen(_calendar_extended_property._uri))) {
117                         _DEBUG_INFO("this is extended");
118                         continue;
119                 }
120                 else {
121                         _DEBUG_INFO("%s is wrong uri", uri);
122                 }
123     } while(calendar_list_next(calendar_list) != CALENDAR_ERROR_NO_DATA);
124
125         // 1. timezone setting : it should be excuted after calendar_vcalendar_parse_to_calendar
126         service_ret = calendar_record_set_str(temp_service_data, _calendar_todo.start_tzid, "Asia/Seoul");
127         if (service_ret != CALENDAR_ERROR_NONE) {
128                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret);
129                 ret = _convert_service_error_to_common_error(service_ret);
130                 /*i think when set return fail then going throw input schedule */
131         }
132
133         service_ret = calendar_record_set_str(temp_service_data, _calendar_todo.due_tzid, "Asia/Seoul");
134         if (service_ret != CALENDAR_ERROR_NONE) {
135                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret);
136                 ret = _convert_service_error_to_common_error(service_ret);
137                 /*i think when set return fail then going throw input schedule */
138         }
139
140         // 2. "no due date" setting : it should be excuted after calendar_vcalendar_parse_to_calendar
141         if (strstr((char *)temp_agent_data, MAX_DUE_DATE_KEYWORD) != NULL) {
142                 _DEBUG_INFO("no due date setting");
143
144                 calendar_time_s cal_time_end = { 0, };
145                 service_ret = calendar_record_get_caltime(temp_service_data, _calendar_todo.due_time, &cal_time_end);
146                 if (service_ret != CALENDAR_ERROR_NONE) {
147                         _DEBUG_ERROR("calendar_record_get_caltime() Fail: err[%d]", service_ret);
148                         ret = _convert_service_error_to_common_error(service_ret);
149                 }
150
151                 cal_time_end.type = CALENDAR_TIME_UTIME;
152                 cal_time_end.time.utime = CALENDAR_TODO_NO_DUE_DATE;
153                 service_ret = calendar_record_set_caltime(temp_service_data, _calendar_todo.due_time, cal_time_end);
154                 if (service_ret != CALENDAR_ERROR_NONE) {
155                         _DEBUG_ERROR("calendar_record_set_caltime() Fail: err[%d]", service_ret);
156                         ret = _convert_service_error_to_common_error(service_ret);
157                 }
158         }
159
160         // 3. add image info : it should be excuted after calendar_vcalendar_parse_to_calendar
161         if( image_path != NULL ) {
162                 _DEBUG_INFO("image is founded. %s", image_path);
163
164                 /////////////////////////////////////  S Note temporary code ////////////////////////////
165                 if (strstr(image_path, "=\r\n") != NULL) {
166                         temp_image_path = get_value_by_token(image_path, "/opt/usr/apps/com.samsung.smemo/data/", "=\r\n");
167                         _DEBUG_INFO("temp_image_path = %s", temp_image_path);
168                         token = (char *)calloc(1000, sizeof(char));
169                         if (token == NULL) {
170                                 _DEBUG_ERROR("token calloc() is failed");
171                                 ret = SYNC_AGENT_DA_ERRORS;
172                                 goto return_part;
173                         }
174
175                         snprintf(token, 1000, "%s=\r\n", temp_image_path);
176                         _DEBUG_INFO("token = %s", token);
177
178                         temp = get_value_by_token(image_path, token, ".png");
179
180                         if (image_path) {
181                                 free(image_path);
182                                 image_path = NULL;
183                         }
184
185                         image_path = (char *)calloc(1000, sizeof(char));
186                         if (image_path == NULL) {
187                                 _DEBUG_ERROR("image_path is null");
188                                 ret = SYNC_AGENT_DA_ERRORS;
189                                 goto return_part;
190                         }
191
192                         snprintf(image_path, 1000, "/opt/usr/apps/com.samsung.smemo/data/%s%s.png", temp_image_path, temp);
193                         _DEBUG_INFO("image_path = %s", image_path);
194                 }
195                 /////////////////////////////////////  S Note temporary code ////////////////////////////
196
197                 calendar_record_h image_record = NULL;
198
199                 service_ret = calendar_record_create(_calendar_extended_property._uri, &image_record);
200                 if (service_ret != CALENDAR_ERROR_NONE) {
201                         _DEBUG_ERROR("calendar_record_create() Fail! err[%d]\n", service_ret);
202                         ret = _convert_service_error_to_common_error(service_ret);
203                 }
204
205                 service_ret = calendar_record_set_str(image_record, _calendar_extended_property.key, CALENDAR_IMAGE_KEYWORD_PHOTO);
206                 if (service_ret != CALENDAR_ERROR_NONE) {
207                         _DEBUG_ERROR("calendar_record_set_str() Fail! err[%d]\n", service_ret);
208                         ret = _convert_service_error_to_common_error(service_ret);
209                 }
210
211                 service_ret = calendar_record_set_str(image_record, _calendar_extended_property.value, image_path);
212                 if (service_ret != CALENDAR_ERROR_NONE) {
213                         _DEBUG_ERROR("calendar_record_set_str() Fail! err[%d]\n", service_ret);
214                         ret = _convert_service_error_to_common_error(service_ret);
215                 }
216
217                 service_ret = calendar_record_add_child_record(temp_service_data, _calendar_todo.extended, image_record);
218                 if (service_ret != CALENDAR_ERROR_NONE) {
219                         _DEBUG_ERROR("calendar_record_add_child_record() Fail! err[%d]\n", service_ret);
220                         ret = _convert_service_error_to_common_error(service_ret);
221                 }
222         }
223
224         *service_data = (void *)temp_service_data;
225         _DEBUG_INFO("calendar_vcalendar_parse_to_calendar() Success!\n");
226
227 return_part:
228         _DEBUG_INFO("return part");
229
230         if (calendar_list != NULL) {
231                 service_ret = calendar_list_destroy(calendar_list, false);
232                 if (service_ret != CALENDAR_ERROR_NONE) {
233                         _DEBUG_ERROR("calendar_list_destroy() Fail! : err = %d", service_ret);
234                 }
235                 calendar_list = NULL;
236         }
237         if (image_path) {
238                 free(image_path);
239                 image_path = NULL;
240         }
241         if (temp_image_path) {
242                 free(temp_image_path);
243                 temp_image_path = NULL;
244         }
245         if (token) {
246                 free(token);
247                 token = NULL;
248         }
249         if (temp) {
250                 free(temp);
251                 temp = NULL;
252         }
253
254         _EXTERN_FUNC_EXIT;
255         return ret;
256 }
257
258 sync_agent_da_return_e _vtodo_merge_new_to_old(calendar_record_h old_service_data, calendar_record_h new_service_data)
259 {
260         _EXTERN_FUNC_ENTER;
261         retvm_if(old_service_data == NULL, SYNC_AGENT_DA_ERRORS, "old_service_data is NULL. FAIL !!!");
262         retvm_if(new_service_data == NULL, SYNC_AGENT_DA_ERRORS, "new_service_data is NULL. FAIL !!!");
263
264         int service_ret = 0;
265         sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
266
267         /*priority */
268         int priority = 0;
269         service_ret = calendar_record_get_int(new_service_data, _calendar_todo.priority, &priority);
270         if (service_ret != CALENDAR_ERROR_NONE) {
271                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int Fail! err[%d]\n", service_ret);
272                 return SYNC_AGENT_DA_ERRORS;
273         }
274         _DEBUG_INFO("priority= %d", priority);
275
276         service_ret = calendar_record_set_int(old_service_data, _calendar_todo.priority, priority);
277         if (service_ret != CALENDAR_ERROR_NONE) {
278                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int() Fail! err[%d]\n", service_ret);
279                 return SYNC_AGENT_DA_ERRORS;
280         }
281
282         /*description */
283         char *description = 0;
284         service_ret = calendar_record_get_str_p(new_service_data, _calendar_todo.description, &description);
285         if (service_ret != CALENDAR_ERROR_NONE) {
286                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str_p() Fail! err[%d]\n", service_ret);
287                 return SYNC_AGENT_DA_ERRORS;
288         }
289         _DEBUG_INFO("description = %s", description);
290
291         service_ret = calendar_record_set_str(old_service_data, _calendar_todo.description, description);
292         if (service_ret != CALENDAR_ERROR_NONE) {
293                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret);
294                 return SYNC_AGENT_DA_ERRORS;
295         }
296
297         /*start time */
298         calendar_time_s task_time_start = { 0, };
299         service_ret = calendar_record_get_caltime(new_service_data, _calendar_todo.start_time, &task_time_start);
300         if (service_ret != CALENDAR_ERROR_NONE) {
301                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_caltime() Fail! err[%d]\n", service_ret);
302                 return SYNC_AGENT_DA_ERRORS;
303         }
304
305         service_ret = calendar_record_set_caltime(old_service_data, _calendar_todo.start_time, task_time_start);
306         if (service_ret != CALENDAR_ERROR_NONE) {
307                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_caltime() Fail! err[%d]\n", service_ret);
308                 return SYNC_AGENT_DA_ERRORS;
309         }
310
311         /*end time */
312         calendar_time_s task_time_end = { 0, };
313         service_ret = calendar_record_get_caltime(new_service_data, _calendar_todo.due_time, &task_time_end);
314         if (service_ret != CALENDAR_ERROR_NONE) {
315                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_caltime() Fail! err[%d]\n", service_ret);
316                 return SYNC_AGENT_DA_ERRORS;
317         }
318
319         service_ret = calendar_record_set_caltime(old_service_data, _calendar_todo.due_time, task_time_end);
320         if (service_ret != CALENDAR_ERROR_NONE) {
321                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_caltime() Fail! err[%d]\n", service_ret);
322                 return SYNC_AGENT_DA_ERRORS;
323         }
324
325         /* summary */
326         char *summary = 0;
327         service_ret = calendar_record_get_str_p(new_service_data, _calendar_todo.summary, &summary);
328         if (service_ret != CALENDAR_ERROR_NONE) {
329                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str_p() Fail! err[%d]\n", service_ret);
330                 return SYNC_AGENT_DA_ERRORS;
331         }
332
333         service_ret = calendar_record_set_str(old_service_data, _calendar_todo.summary, summary);
334         if (service_ret != CALENDAR_ERROR_NONE) {
335                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret);
336                 return SYNC_AGENT_DA_ERRORS;
337         }
338
339         /* location */
340         char *location = 0;
341         service_ret = calendar_record_get_str_p(new_service_data, _calendar_todo.location, &location);
342         if (service_ret != CALENDAR_ERROR_NONE) {
343                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str_p() Fail! err[%d]\n", service_ret);
344                 return SYNC_AGENT_DA_ERRORS;
345         }
346
347         service_ret = calendar_record_set_str(old_service_data, _calendar_todo.location, location);
348         if (service_ret != CALENDAR_ERROR_NONE) {
349                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret);
350                 return SYNC_AGENT_DA_ERRORS;
351         }
352
353         /* rrule */
354         int num;
355         char *text = NULL;
356         calendar_time_s caltime = {0};
357
358         service_ret = calendar_record_get_int(new_service_data, _calendar_todo.freq, &num);
359         if (service_ret != CALENDAR_ERROR_NONE) {
360                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(freq) Fail! err[%d]\n", service_ret);
361                 return SYNC_AGENT_DA_ERRORS;
362         }
363         service_ret = calendar_record_set_int(old_service_data, _calendar_todo.freq, num);
364         if (service_ret != CALENDAR_ERROR_NONE) {
365                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(freq) Fail! err[%d]\n", service_ret);
366                 return SYNC_AGENT_DA_ERRORS;
367         }
368
369         service_ret = calendar_record_get_int(new_service_data, _calendar_todo.range_type, &num);
370         if (service_ret != CALENDAR_ERROR_NONE) {
371                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(range_type) Fail! err[%d]\n", service_ret);
372                 return SYNC_AGENT_DA_ERRORS;
373         }
374         service_ret = calendar_record_set_int(old_service_data, _calendar_todo.range_type, num);
375         if (service_ret != CALENDAR_ERROR_NONE) {
376                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(range_type) Fail! err[%d]\n", service_ret);
377                 return SYNC_AGENT_DA_ERRORS;
378         }
379
380         service_ret = calendar_record_get_caltime(new_service_data, _calendar_todo.until_time, &caltime);
381         if (service_ret != CALENDAR_ERROR_NONE) {
382                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_caltime(until_time) Fail! err[%d]\n", service_ret);
383                 return SYNC_AGENT_DA_ERRORS;
384         }
385         service_ret = calendar_record_set_caltime(old_service_data, _calendar_todo.until_time, caltime);
386         if (service_ret != CALENDAR_ERROR_NONE) {
387                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_caltime(until_time) Fail! err[%d]\n", service_ret);
388                 return SYNC_AGENT_DA_ERRORS;
389         }
390
391         service_ret = calendar_record_get_int(new_service_data, _calendar_todo.count, &num);
392         if (service_ret != CALENDAR_ERROR_NONE) {
393                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(count) Fail! err[%d]\n", service_ret);
394                 return SYNC_AGENT_DA_ERRORS;
395         }
396         service_ret = calendar_record_set_int(old_service_data, _calendar_todo.count, num);
397         if (service_ret != CALENDAR_ERROR_NONE) {
398                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(count) Fail! err[%d]\n", service_ret);
399                 return SYNC_AGENT_DA_ERRORS;
400         }
401
402         service_ret = calendar_record_get_int(new_service_data, _calendar_todo.interval, &num);
403         if (service_ret != CALENDAR_ERROR_NONE) {
404                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(interval) Fail! err[%d]\n", service_ret);
405                 return SYNC_AGENT_DA_ERRORS;
406         }
407         service_ret = calendar_record_set_int(old_service_data, _calendar_todo.interval, num);
408         if (service_ret != CALENDAR_ERROR_NONE) {
409                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(interval) Fail! err[%d]\n", service_ret);
410                 return SYNC_AGENT_DA_ERRORS;
411         }
412
413         service_ret = calendar_record_get_str(new_service_data, _calendar_todo.bysecond, &text);
414         if (service_ret != CALENDAR_ERROR_NONE) {
415                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(bysecond) Fail! err[%d]\n", service_ret);
416                 return SYNC_AGENT_DA_ERRORS;
417         }
418         service_ret = calendar_record_set_str(old_service_data, _calendar_todo.bysecond, text);
419         if (service_ret != CALENDAR_ERROR_NONE) {
420                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(bysecond) Fail! err[%d]\n", service_ret);
421                 return SYNC_AGENT_DA_ERRORS;
422         }
423
424         service_ret = calendar_record_get_str(new_service_data, _calendar_todo.byminute, &text);
425         if (service_ret != CALENDAR_ERROR_NONE) {
426                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(byminute) Fail! err[%d]\n", service_ret);
427                 return SYNC_AGENT_DA_ERRORS;
428         }
429         service_ret = calendar_record_set_str(old_service_data, _calendar_todo.byminute, text);
430         if (service_ret != CALENDAR_ERROR_NONE) {
431                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(byminute) Fail! err[%d]\n", service_ret);
432                 return SYNC_AGENT_DA_ERRORS;
433         }
434
435         service_ret = calendar_record_get_str(new_service_data, _calendar_todo.byhour, &text);
436         if (service_ret != CALENDAR_ERROR_NONE) {
437                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(byhour) Fail! err[%d]\n", service_ret);
438                 return SYNC_AGENT_DA_ERRORS;
439         }
440         service_ret = calendar_record_set_str(old_service_data, _calendar_todo.byhour, text);
441         if (service_ret != CALENDAR_ERROR_NONE) {
442                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(byhour) Fail! err[%d]\n", service_ret);
443                 return SYNC_AGENT_DA_ERRORS;
444         }
445
446         service_ret = calendar_record_get_str(new_service_data, _calendar_todo.byday, &text);
447         if (service_ret != CALENDAR_ERROR_NONE) {
448                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(byday) Fail! err[%d]\n", service_ret);
449                 return SYNC_AGENT_DA_ERRORS;
450         }
451         service_ret = calendar_record_set_str(old_service_data, _calendar_todo.byday, text);
452         if (service_ret != CALENDAR_ERROR_NONE) {
453                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(byday) Fail! err[%d]\n", service_ret);
454                 return SYNC_AGENT_DA_ERRORS;
455         }
456
457         service_ret = calendar_record_get_str(new_service_data, _calendar_todo.bymonthday, &text);
458         if (service_ret != CALENDAR_ERROR_NONE) {
459                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(bymonthday) Fail! err[%d]\n", service_ret);
460                 return SYNC_AGENT_DA_ERRORS;
461         }
462         service_ret = calendar_record_set_str(old_service_data, _calendar_todo.bymonthday, text);
463         if (service_ret != CALENDAR_ERROR_NONE) {
464                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(bymonthday) Fail! err[%d]\n", service_ret);
465                 return SYNC_AGENT_DA_ERRORS;
466         }
467
468         service_ret = calendar_record_get_str(new_service_data, _calendar_todo.byyearday, &text);
469         if (service_ret != CALENDAR_ERROR_NONE) {
470                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(byyearday) Fail! err[%d]\n", service_ret);
471                 return SYNC_AGENT_DA_ERRORS;
472         }
473         service_ret = calendar_record_set_str(old_service_data, _calendar_todo.byyearday, text);
474         if (service_ret != CALENDAR_ERROR_NONE) {
475                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(byyearday) Fail! err[%d]\n", service_ret);
476                 return SYNC_AGENT_DA_ERRORS;
477         }
478
479         service_ret = calendar_record_get_str(new_service_data, _calendar_todo.byweekno, &text);
480         if (service_ret != CALENDAR_ERROR_NONE) {
481                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(byweekno) Fail! err[%d]\n", service_ret);
482                 return SYNC_AGENT_DA_ERRORS;
483         }
484         service_ret = calendar_record_set_str(old_service_data, _calendar_todo.byweekno, text);
485         if (service_ret != CALENDAR_ERROR_NONE) {
486                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(byweekno) Fail! err[%d]\n", service_ret);
487                 return SYNC_AGENT_DA_ERRORS;
488         }
489
490         service_ret = calendar_record_get_str(new_service_data, _calendar_todo.bymonth, &text);
491         if (service_ret != CALENDAR_ERROR_NONE) {
492                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(bymonth) Fail! err[%d]\n", service_ret);
493                 return SYNC_AGENT_DA_ERRORS;
494         }
495         service_ret = calendar_record_set_str(old_service_data, _calendar_todo.bymonth, text);
496         if (service_ret != CALENDAR_ERROR_NONE) {
497                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(bymonth) Fail! err[%d]\n", service_ret);
498                 return SYNC_AGENT_DA_ERRORS;
499         }
500
501         service_ret = calendar_record_get_str(new_service_data, _calendar_todo.bysetpos, &text);
502         if (service_ret != CALENDAR_ERROR_NONE) {
503                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(bysetpos) Fail! err[%d]\n", service_ret);
504                 return SYNC_AGENT_DA_ERRORS;
505         }
506         service_ret = calendar_record_set_str(old_service_data, _calendar_todo.bysetpos, text);
507         if (service_ret != CALENDAR_ERROR_NONE) {
508                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(bysetpos) Fail! err[%d]\n", service_ret);
509                 return SYNC_AGENT_DA_ERRORS;
510         }
511
512         service_ret = calendar_record_get_int(new_service_data, _calendar_todo.wkst, &num);
513         if (service_ret != CALENDAR_ERROR_NONE) {
514                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(wkst) Fail! err[%d]\n", service_ret);
515                 return SYNC_AGENT_DA_ERRORS;
516         }
517         service_ret = calendar_record_set_int(old_service_data, _calendar_todo.wkst, num);
518         if (service_ret != CALENDAR_ERROR_NONE) {
519                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(wkst) Fail! err[%d]\n", service_ret);
520                 return SYNC_AGENT_DA_ERRORS;
521         }
522
523         /* alarm */
524         calendar_record_h new_alarm_record = NULL;
525         calendar_record_h old_alarm_record = NULL;
526         calendar_time_s alarm_time = {0};
527         int new_data_has_alarm = 0;
528         int old_data_has_alarm = 0;
529         int type = 0;
530         int tick = 0;
531         int tick_unit = 0;
532         int alarm_id = 0;
533         description = NULL;
534
535         service_ret = calendar_record_get_int(new_service_data, _calendar_todo.has_alarm, &new_data_has_alarm);
536         if (service_ret != CALENDAR_ERROR_NONE) {
537                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(has_alarm) Fail! err[%d]\n", service_ret);
538                 return SYNC_AGENT_DA_ERRORS;
539         }
540         _DEBUG_INFO("new_data_has_alarm = %d", new_data_has_alarm);
541
542         service_ret = calendar_record_get_int(old_service_data, _calendar_todo.has_alarm, &old_data_has_alarm);
543         if (service_ret != CALENDAR_ERROR_NONE) {
544                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(has_alarm) Fail! err[%d]\n", service_ret);
545                 return SYNC_AGENT_DA_ERRORS;
546         }
547         _DEBUG_INFO("old_data_has_alarm = %d", old_data_has_alarm);
548
549         if (new_data_has_alarm == 0 && old_data_has_alarm == 1) {
550                 _DEBUG_INFO("alarm record shoud be deleted");
551
552                 service_ret = calendar_record_get_child_record_at_p(old_service_data, _calendar_todo.calendar_alarm, 0, &old_alarm_record);
553                 if (service_ret != CALENDAR_ERROR_NONE) {
554                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_child_record_at_p() Fail! err[%d]\n", service_ret);
555                         return SYNC_AGENT_DA_ERRORS;
556                 }
557
558                 service_ret = calendar_record_remove_child_record(old_service_data, _calendar_todo.calendar_alarm, old_alarm_record);
559                 if (service_ret != CALENDAR_ERROR_NONE) {
560                                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_remove_child_record() Fail! err[%d]\n", service_ret);
561                                 return SYNC_AGENT_DA_ERRORS;
562                 }
563         }
564         else if (new_data_has_alarm == 1) {
565                 service_ret = calendar_record_get_child_record_at_p(new_service_data, _calendar_todo.calendar_alarm, 0, &new_alarm_record);
566                 if (service_ret != CALENDAR_ERROR_NONE) {
567                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_child_record_at_p(_calendar_todo.calendar_alarm) Fail! err[%d]\n", service_ret);
568                         return SYNC_AGENT_DA_ERRORS;
569                 }
570
571                 service_ret = calendar_record_get_int(new_alarm_record, _calendar_alarm.type, &type);
572                 if (service_ret != CALENDAR_ERROR_NONE) {
573                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(type) Fail! err[%d]\n", service_ret);
574                         return SYNC_AGENT_DA_ERRORS;
575                 }
576
577                 service_ret = calendar_record_get_lli(new_alarm_record, _calendar_alarm.time, &alarm_time.time.utime);
578                 if (service_ret != CALENDAR_ERROR_NONE) {
579                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(time) Fail! err[%d]\n", service_ret);
580                         return SYNC_AGENT_DA_ERRORS;
581                 }
582
583                 service_ret = calendar_record_get_int(new_alarm_record, _calendar_alarm.tick, &tick);
584                 if (service_ret != CALENDAR_ERROR_NONE) {
585                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(tick) Fail! err[%d]\n", service_ret);
586                         return SYNC_AGENT_DA_ERRORS;
587                 }
588
589                 service_ret = calendar_record_get_int(new_alarm_record, _calendar_alarm.tick_unit, &tick_unit);
590                 if (service_ret != CALENDAR_ERROR_NONE) {
591                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(tick_unit) Fail! err[%d]\n", service_ret);
592                         return SYNC_AGENT_DA_ERRORS;
593                 }
594
595                 service_ret = calendar_record_get_str(new_alarm_record, _calendar_alarm.description, &description);
596                 if (service_ret != CALENDAR_ERROR_NONE) {
597                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(description) Fail! err[%d]\n", service_ret);
598                         return SYNC_AGENT_DA_ERRORS;
599                 }
600
601                 service_ret = calendar_record_get_int(new_alarm_record, _calendar_alarm.alarm_id, &alarm_id);
602                 if (service_ret != CALENDAR_ERROR_NONE) {
603                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(alarm_id) Fail! err[%d]\n", service_ret);
604                         return SYNC_AGENT_DA_ERRORS;
605                 }
606
607                 if (old_data_has_alarm == 0) {
608                         _DEBUG_INFO("alarm record should be created");
609
610                         service_ret = calendar_record_create(_calendar_alarm._uri, &old_alarm_record);
611                         if (service_ret != CALENDAR_ERROR_NONE) {
612                                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_create Fail! err[%d]\n", service_ret);
613                                 return SYNC_AGENT_DA_ERRORS;
614                         }
615                 }
616                 else if (old_data_has_alarm == 1) {
617                         _DEBUG_INFO("alarm record should be overwrited");
618
619                         service_ret = calendar_record_get_child_record_at_p(old_service_data, _calendar_todo.calendar_alarm, 0, &old_alarm_record);
620                         if (service_ret != CALENDAR_ERROR_NONE) {
621                                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_child_record_at_p(_calendar_alarm._uri) Fail! err[%d]\n", service_ret);
622                                 return SYNC_AGENT_DA_ERRORS;
623                         }
624                 }
625                 else {
626                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] this is an error. new_data_has_alarm = %d, old_data_has_alarm = %d", new_data_has_alarm, old_data_has_alarm);
627                         return SYNC_AGENT_DA_ERRORS;
628                 }
629
630                 service_ret = calendar_record_set_int(old_alarm_record, _calendar_alarm.type, type);
631                 if (service_ret != CALENDAR_ERROR_NONE) {
632                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(type) Fail! err[%d]\n", service_ret);
633                         return SYNC_AGENT_DA_ERRORS;
634                 }
635
636                 service_ret = calendar_record_set_lli(old_alarm_record, _calendar_alarm.time, alarm_time.time.utime);
637                 if (service_ret != CALENDAR_ERROR_NONE) {
638                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_lli(time) Fail! err[%d]\n", service_ret);
639                         return SYNC_AGENT_DA_ERRORS;
640                 }
641
642                 service_ret = calendar_record_set_int(old_alarm_record, _calendar_alarm.tick, tick);
643                 if (service_ret != CALENDAR_ERROR_NONE) {
644                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(tick) Fail! err[%d]\n", service_ret);
645                         return SYNC_AGENT_DA_ERRORS;
646                 }
647
648                 service_ret = calendar_record_set_int(old_alarm_record, _calendar_alarm.tick_unit, tick_unit);
649                 if (service_ret != CALENDAR_ERROR_NONE) {
650                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(tick_unit) Fail! err[%d]\n", service_ret);
651                         return SYNC_AGENT_DA_ERRORS;
652                 }
653
654                 service_ret = calendar_record_set_str(old_alarm_record, _calendar_alarm.description, description);
655                 if (service_ret != CALENDAR_ERROR_NONE) {
656                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(description) Fail! err[%d]\n", service_ret);
657                         return SYNC_AGENT_DA_ERRORS;
658                 }
659
660                 service_ret = calendar_record_set_int(old_alarm_record, _calendar_alarm.alarm_id, alarm_id);
661                 if (service_ret != CALENDAR_ERROR_NONE) {
662                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(alarm_id) Fail! err[%d]\n", service_ret);
663                         return SYNC_AGENT_DA_ERRORS;
664                 }
665
666                 if (old_data_has_alarm == 0) {
667                         _DEBUG_INFO("alarm record should be created - add child rocord(alarm)");
668
669                         service_ret = calendar_record_add_child_record(old_service_data, _calendar_todo.calendar_alarm, old_alarm_record);
670                         if (service_ret != CALENDAR_ERROR_NONE) {
671                                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_child_record_at_p(_calendar_alarm._uri) Fail! err[%d]\n", service_ret);
672                                 return SYNC_AGENT_DA_ERRORS;
673                         }
674                 }
675         }
676
677         /* image is not supported Outlook sync. So, image field should be not merged (2013/01/14 concept)  */
678
679         _EXTERN_FUNC_EXIT;
680         return ret;
681 }
682
683 EXPORT_API sync_agent_da_return_e sync_agent_plugin_replace_converter(void *old_service_data, const void *agent_data, void **new_service_data)
684 {
685         _EXTERN_FUNC_ENTER;
686
687         retvm_if(old_service_data == NULL, SYNC_AGENT_DA_ERRORS, "old_service_data is NULL. FAIL !!!");
688         retvm_if(agent_data == NULL, SYNC_AGENT_DA_ERRORS, "agent_data is NULL. FAIL !!!");
689
690         calendar_list_h calendar_list = NULL;
691         calendar_record_h temp_new_service_data = NULL;
692         calendar_record_h temp_old_service_data = (calendar_record_h) old_service_data;
693         sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
694         int service_ret = CALENDAR_ERROR_NONE;
695         const char *temp_agent_data = (const char *)agent_data;
696         char *temp = NULL;
697
698         if (temp_agent_data == NULL) {
699                 _DEBUG_ERROR("inputed temp_agent_data is null");
700                 return SYNC_AGENT_DA_ERRORS;
701         }
702
703         _DEBUG_INFO("temp_agent_data= %s", temp_agent_data);
704
705         // 1. if the vcalendar has until : NONE rrule, then max rrule should be converted : it should be excuted before calendar_vcalendar_parse_to_calendar
706         if (strstr(temp_agent_data, RRULE_KEYWORD) != NULL) {
707                 temp = strdup(temp_agent_data);
708                 temp_agent_data = replace_max_rrule_data(temp);
709                 temp = NULL;
710         }
711
712         // 2. priority converting : it should be excuted before calendar_vcalendar_parse_to_calendar
713         if (strstr(temp_agent_data, "\r\nPRIORITY:") != NULL) {
714                 _DEBUG_INFO("priority is founed");
715                 temp = strdup(temp_agent_data);
716                 temp = replace_priority_data(temp, false);
717                 temp_agent_data = temp;
718         }
719
720         _DEBUG_INFO("temp_agent_data= %s", temp_agent_data);
721         service_ret = calendar_vcalendar_parse_to_calendar(temp_agent_data, &calendar_list);
722         if (service_ret != CALENDAR_ERROR_NONE) {
723                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_vcalendar_parse_to_calendar() Fail! err[%d]\n", service_ret);
724                 *new_service_data = NULL;
725                 goto return_part;
726         }
727         _DEBUG_INFO("[dc_vcalendar-task_plugIn] calendar_vcalendar_parse_to_calendar() success!\n");
728
729         service_ret = calendar_list_first(calendar_list);
730         if (service_ret != CALENDAR_ERROR_NONE) {
731                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_list_first() Fail! : err[%d]", service_ret);
732                 goto return_part;
733         }
734
735         int count = 0;
736         calendar_list_get_count(calendar_list, &count);
737         _DEBUG_INFO("count = %d", count);
738         do
739     {
740                 char *uri = NULL;
741                 char *key = NULL;
742         service_ret = calendar_list_get_current_record_p(calendar_list, &temp_new_service_data);
743                 if ((service_ret != CALENDAR_ERROR_NONE) || (temp_new_service_data == NULL)) {
744                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_list_get_current_record_p() Fail! : err[%d]", service_ret);
745                         goto return_part;
746                 }
747
748                 service_ret = calendar_record_get_uri_p(temp_new_service_data, &uri);
749                 if (service_ret != CALENDAR_ERROR_NONE) {
750                         _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret);
751                         goto return_part;
752                 }
753                 _DEBUG_INFO("temp_new_service_data URI = %s", uri);
754
755                 if (!strncmp(uri, _calendar_todo._uri, strlen(_calendar_todo._uri))) {
756                         _DEBUG_INFO("this is todo");
757                         ret = _vtodo_merge_new_to_old(temp_old_service_data, temp_new_service_data);
758                         if (ret != SYNC_AGENT_DA_SUCCESS) {
759                                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int() Fail! err[%d]\n", ret);
760                         }
761
762                         // 1. "no due date" setting : it should be excuted after calendar_vcalendar_parse_to_calendar
763                         if (strstr((char *)temp_agent_data, MAX_DUE_DATE_KEYWORD) != NULL) {
764                                 _DEBUG_INFO("no due date setting");
765
766                                 calendar_time_s cal_time_end = { 0, };
767                                 service_ret = calendar_record_get_caltime(temp_old_service_data, _calendar_todo.due_time, &cal_time_end);
768                                 if (service_ret != CALENDAR_ERROR_NONE) {
769                                         _DEBUG_ERROR("calendar_record_get_caltime() Fail: err[%d]", service_ret);
770                                         ret = _convert_service_error_to_common_error(service_ret);
771                                 }
772
773                                 cal_time_end.type = CALENDAR_TIME_UTIME;
774                                 cal_time_end.time.utime = CALENDAR_TODO_NO_DUE_DATE;
775                                 service_ret = calendar_record_set_caltime(temp_old_service_data, _calendar_todo.due_time, cal_time_end);
776                                 if (service_ret != CALENDAR_ERROR_NONE) {
777                                         _DEBUG_ERROR("calendar_record_set_caltime() Fail: err[%d]", service_ret);
778                                         ret = _convert_service_error_to_common_error(service_ret);
779                                 }
780                         }
781                 }
782                 else if (!strncmp(uri, _calendar_extended_property._uri, strlen(_calendar_extended_property._uri))) {
783                         _DEBUG_INFO("this is extended");
784                         ret = calendar_record_get_str(temp_new_service_data, _calendar_extended_property.key, &key);
785                         if (service_ret != CALENDAR_ERROR_NONE) {
786                                 _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str() Fail! : err[%d]", service_ret);
787                                 goto return_part;
788                         }
789                         _DEBUG_INFO("key = %s", key);
790                         if (strncmp(key, "VERSION", strlen("VERSION"))) {
791                                 _DEBUG_INFO("this is extended, not VCALENDAR:VERSION extend");
792                                 calendar_record_add_child_record(temp_old_service_data, _calendar_todo.extended, temp_new_service_data);
793                         }
794                 }
795     } while(calendar_list_next(calendar_list) != CALENDAR_ERROR_NO_DATA);
796         *new_service_data = temp_old_service_data;
797
798 return_part:
799         _DEBUG_INFO("return_part");
800         if (calendar_list != NULL) {
801                 service_ret = calendar_list_destroy(calendar_list, false);
802                 if (service_ret != CALENDAR_ERROR_NONE) {
803                         _DEBUG_ERROR("calendar_list_destroy() Fail! : err = %d", service_ret);
804                 }
805                 calendar_list = NULL;
806         }
807         ret = _convert_service_error_to_common_error(service_ret);
808         _EXTERN_FUNC_EXIT;
809         return ret;
810 }
811
812 EXPORT_API sync_agent_da_return_e sync_agent_plugin_reverse_converter(void *service_data, void **agent_data)
813 {
814         _EXTERN_FUNC_ENTER;
815
816         retvm_if(service_data == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "service_data is NULL. FAIL !!!");
817
818         calendar_list_h list = NULL;
819         calendar_record_h temp_service_data = (calendar_record_h) service_data;
820         calendar_record_h image_item = (calendar_record_h) temp_service_data;
821         calendar_record_h extended_version = NULL;
822         sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
823         int service_ret = CALENDAR_ERROR_NONE;
824         char *temp_agent_data = NULL;
825
826         _DEBUG_INFO("converter start");
827         service_ret = calendar_list_create(&list);
828         if (service_ret != CALENDAR_ERROR_NONE) {
829                 _DEBUG_ERROR("calendar_list_create() Fail!: err[%d]", service_ret);
830                 ret = _convert_service_error_to_common_error(service_ret);
831                 goto return_part;
832         }
833
834         // 1. extended vcalendar version : it should be excuted before calendar_vcalendar_make_from_records
835         service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_version);
836         if (service_ret != CALENDAR_ERROR_NONE) {
837                 _DEBUG_ERROR("calendar_record_create() Fail!: err[%d]", service_ret);
838                 ret = SYNC_AGENT_DA_ERRORS;
839                 goto return_part;
840         }
841
842         service_ret = calendar_record_set_str(extended_version, _calendar_extended_property.key, "VERSION");
843         if (service_ret != CALENDAR_ERROR_NONE) {
844                 _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret);
845                 ret = SYNC_AGENT_DA_ERRORS;
846                 goto return_part;
847         }
848
849         service_ret = calendar_record_set_str(extended_version, _calendar_extended_property.value, ":1.0");
850         if (service_ret != CALENDAR_ERROR_NONE) {
851                 _DEBUG_ERROR("calendar_record_create() Fail!: err[%d]", service_ret);
852                 ret = SYNC_AGENT_DA_ERRORS;
853                 goto return_part;
854         }
855
856         service_ret = calendar_list_add(list, extended_version);
857         if (service_ret != CALENDAR_ERROR_NONE || list == NULL) {
858                 _DEBUG_ERROR("calendar_list_add() Fail!: err[%d]", service_ret);
859                 ret = _convert_service_error_to_common_error(service_ret);
860                 goto return_part;
861         }
862
863         service_ret = calendar_list_add(list, temp_service_data);
864         if (service_ret != CALENDAR_ERROR_NONE || list == NULL) {
865                 _DEBUG_ERROR("calendar_list_add() Fail!: err[%d]", service_ret);
866                 ret = _convert_service_error_to_common_error(service_ret);
867                 goto return_part;
868         }
869
870         service_ret = calendar_vcalendar_make_from_records(list, &temp_agent_data);
871         _DEBUG_INFO("temp_agent_data = %s", temp_agent_data);
872         if (service_ret != CALENDAR_ERROR_NONE) {
873                 _DEBUG_ERROR("calendar_vcalendar_make_from_records() Fail!: err[%d]", service_ret);
874                 ret = _convert_service_error_to_common_error(service_ret);
875                 goto return_part;
876         }
877
878         //  1. remove 'timezone' : after calendar_vcalendar_make_from_records
879         temp_agent_data = remove_timezone(temp_agent_data);
880         _DEBUG_INFO("temp_agent_data = %s", temp_agent_data);
881
882         //  2. image converting : it should be excuted after calendar_vcalendar_make_from_records
883         char *image_path = has_image_export(image_item);
884         if( image_path != NULL ) {
885                 _DEBUG_INFO("image is founded.");
886                 temp_agent_data = replace_image_data(temp_agent_data, image_path);
887         }
888
889         // 3. task priority converting : it should be excuted after calendar_vcalendar_make_from_records
890         if (strstr(temp_agent_data, "\r\nPRIORITY:") != NULL) {
891                 _DEBUG_INFO("priority is founed");
892                 temp_agent_data = replace_priority_data(temp_agent_data, true);
893         }
894
895         // originally, vtodo has not DTSTART, but exceptively DTSTART should be added for alarm time setting at Kies
896         // 4. DTSTART converting : it should be excuted after calendar_vcalendar_make_from_records
897         if (strstr(temp_agent_data, END_VTODO_KEYWORD) != NULL) {
898                 temp_agent_data = replace_string(temp_agent_data, END_VTODO_KEYWORD, "\r\nDTSTART:20370101T090000\r\nEND:VTODO\r\n");
899         }
900
901         // originally, "NO DUE DATE" vtodo has not "DUE:xxxxxx", but exceptively DUE should be added for alarm time setting at Kies
902         // 5. DUE converting : it should be excuted after calendar_vcalendar_make_from_records
903         if (strstr(temp_agent_data, DUEDATE_KEYWORD) == NULL) {
904                 temp_agent_data = replace_string(temp_agent_data, END_VTODO_KEYWORD, "\r\nDUE:20370101T090000\r\nEND:VTODO\r\n");
905         }
906
907 return_part:
908         _DEBUG_INFO("return_part");
909         *agent_data = (void *)temp_agent_data;
910
911         if (list != NULL) {
912                 service_ret = calendar_list_destroy(list, true);
913                 if (service_ret != CALENDAR_ERROR_NONE) {
914                         _DEBUG_ERROR("calendar_list_destroy() Fail!: err[%d]", service_ret);
915                         ret = _convert_service_error_to_common_error(service_ret);
916                 }
917         }
918         _DEBUG_INFO("agent_data = %s", *agent_data);
919         _EXTERN_FUNC_EXIT;
920         return ret;
921 }
922
923 EXPORT_API void *sync_agent_plugin_alloc_object()
924 {
925         _EXTERN_FUNC_ENTER;
926         _DEBUG_INFO("[dc_vcalendar-task_plugIn] not implement !!");
927         _EXTERN_FUNC_EXIT;
928         return 0;
929 }
930
931 EXPORT_API int sync_agent_plugin_free_object(void *in_object)
932 {
933         _EXTERN_FUNC_ENTER;
934         _DEBUG_INFO("[dc_vcalendar-task_plugIn] not implement !!");
935         _EXTERN_FUNC_EXIT;
936         return 0;
937 }
938
939 EXPORT_API void *sync_agent_plugin_set_value(void *in_object, int key, char *extension_key, void *value)
940 {
941         _EXTERN_FUNC_ENTER;
942         _DEBUG_INFO("[dc_vcalendar-task_plugIn] not implement !!");
943         _EXTERN_FUNC_EXIT;
944
945         return 0;
946 }
947
948 EXPORT_API void *sync_agent_plugin_get_value(void *in_object, int key, char *extension_key)
949 {
950         _EXTERN_FUNC_ENTER;
951         _DEBUG_INFO("[dc_vcalendar-task_plugIn] not implement !!");
952         _EXTERN_FUNC_EXIT;
953         return 0;
954 }
955
956 EXPORT_API sync_agent_plugin_object_info_s *sync_agent_plugin_get_obj_info()
957 {
958         _EXTERN_FUNC_ENTER;
959
960         sync_agent_plugin_object_info_s *obj_info = (sync_agent_plugin_object_info_s *) calloc(1, sizeof(sync_agent_plugin_object_info_s));
961         if (obj_info == NULL) {
962                 _DEBUG_ERROR("CALLOC failed !!!");
963                 return NULL;
964         }
965
966         obj_info->type = VCALENDAR_TYPE;
967         obj_info->version = VCALENDAR_VERSION;
968         obj_info->field_cnt = sizeof(vcalendar_field_list) / sizeof(vcalendar_field_list_s);
969
970         if (obj_info->field_cnt > 0)
971                 if (_set_obj_field_info(&(obj_info->field_list), obj_info->field_cnt, vcalendar_field_list) == 0) {
972
973                         if (obj_info != NULL)
974                                 free(obj_info);
975
976                         return NULL;
977                 }
978
979         _EXTERN_FUNC_EXIT;
980
981         return obj_info;
982 }
983
984
985 EXPORT_API int sync_agent_plugin_free_obj_info(sync_agent_plugin_object_info_s * obj_info)
986 {
987         _EXTERN_FUNC_ENTER;
988
989         if (obj_info != NULL) {
990                 if (obj_info->field_cnt > 0)
991                         if (_free_obj_field_info(obj_info->field_list, obj_info->field_cnt) == 0)
992                                 return 0;
993
994                 free(obj_info);
995         }
996
997         _EXTERN_FUNC_EXIT;
998
999         return 1;
1000 }
1001
1002 static int _free_obj_field_info(sync_agent_plugin_field_info_s * field_list, int count)
1003 {
1004         _INNER_FUNC_ENTER;
1005
1006         int field_count = 0;
1007         sync_agent_plugin_field_info_s *child = NULL;
1008
1009         if (field_list != NULL) {
1010                 for (field_count = 0; field_count < count; field_count++) {
1011                         child = field_list + field_count;
1012                         if (child->field_child_cnt > 0)
1013                                 if (_free_obj_field_info(child->field_child_list, child->field_child_cnt) == 0)
1014                                         return 0;
1015                 }
1016                 free(field_list);
1017         }
1018
1019         _INNER_FUNC_EXIT;
1020
1021         return 1;
1022 }
1023
1024 static int _set_obj_field_info(sync_agent_plugin_field_info_s ** field_list, int count, vcalendar_field_list_s * input_list)
1025 {
1026         _INNER_FUNC_ENTER;
1027
1028         int field_count = 0;
1029         sync_agent_plugin_field_info_s *child = NULL;
1030
1031         *field_list = (sync_agent_plugin_field_info_s *) calloc(count, sizeof(sync_agent_plugin_field_info_s));
1032         if (*field_list == NULL) {
1033                 _DEBUG_ERROR("CALLOC failed !!!");
1034                 return 0;
1035         }
1036
1037         for (field_count = 0; field_count < count; field_count++) {
1038                 child = (*field_list) + field_count;
1039                 child->field_name = input_list[field_count].field_name;
1040                 _DEBUG_TRACE("[%s]", child->field_name);
1041
1042                 if (input_list[field_count].field_enum == VCALENDAR_FIELD_BEGIN || input_list[field_count].field_enum == VCALENDAR_FIELD_END) {
1043                         child->field_child_cnt = sizeof(vcalendar_field_list_begin_end) / sizeof(vcalendar_field_list_s);
1044                         _DEBUG_TRACE("----------");
1045                         _set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcalendar_field_list_begin_end);
1046                         _DEBUG_TRACE("==========");
1047                 } else if (input_list[field_count].field_enum == VCALENDAR_FIELD_VERSION) {
1048                         child->field_child_cnt = sizeof(vcalendar_field_list_version) / sizeof(vcalendar_field_list_s);
1049                         _DEBUG_TRACE("----------");
1050                         _set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcalendar_field_list_version);
1051                         _DEBUG_TRACE("==========");
1052                 } else if (input_list[field_count].field_enum == VCALENDAR_FIELD_CATEGORIES) {
1053                         child->field_child_cnt = sizeof(vcalendar_field_list_categories) / sizeof(vcalendar_field_list_s);
1054                         _DEBUG_TRACE("----------");
1055                         _set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcalendar_field_list_categories);
1056                         _DEBUG_TRACE("==========");
1057                 } else if (input_list[field_count].field_enum == VCALENDAR_FIELD_STATUS) {
1058                         child->field_child_cnt = sizeof(vcalendar_field_list_status) / sizeof(vcalendar_field_list_s);
1059                         _DEBUG_TRACE("----------");
1060                         _set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcalendar_field_list_status);
1061                         _DEBUG_TRACE("==========");
1062                 }
1063         }
1064
1065         _INNER_FUNC_EXIT;
1066
1067         return 1;
1068 }
1069
1070 static sync_agent_da_return_e _convert_service_error_to_common_error(calendar_error_e err)
1071 {
1072         _INNER_FUNC_ENTER;
1073
1074         sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
1075         _DEBUG_TRACE("[da_calendar_plugIn] Error Code : %d\n", err);
1076
1077         switch (err) {
1078         case CALENDAR_ERROR_DB_RECORD_NOT_FOUND:
1079         case CALENDAR_ERROR_NO_DATA:
1080                 ret = SYNC_AGENT_DA_ERR_NO_DATA;
1081                 break;
1082         case CALENDAR_ERROR_OUT_OF_MEMORY:
1083                 ret = SYNC_AGENT_DA_ERR_MEMORY_FULL;
1084                 break;
1085         case CALENDAR_ERROR_INVALID_PARAMETER:
1086                 ret = SYNC_AGENT_DA_ERR_INVALID_CONTENT;
1087                 break;
1088         case CALENDAR_ERROR_ITERATOR_END:
1089         case CALENDAR_ERROR_NONE:
1090                 ret = SYNC_AGENT_DA_SUCCESS;
1091                 break;
1092                 /*
1093                  * CALENDAR_ERROR_DB_FAILED
1094                  * CALENDAR_ERROR_NOW_IN_PROGRESS
1095                  * CALENDAR_ERROR_ALREADY_IN_PROGRESS
1096                  * CALENDAR_ERROR_NOT_PERMITTED
1097                  */
1098         default:
1099                 ret = SYNC_AGENT_DA_ERRORS;
1100                 break;
1101         }
1102
1103         _INNER_FUNC_EXIT;
1104
1105         return ret;
1106 }