Tizen 2.1 base
[platform/core/system/sync-agent.git] / src / framework / event / oma_ds_api.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 <stdlib.h>
20 #include <string.h>
21
22 #include <glib.h>
23
24 #ifndef SYNC_AGENT_LOG
25 #undef LOG_TAG
26 #define LOG_TAG "OMADS_CLIENT"
27 #endif
28
29 //#include <sync_agent.h>
30 #include "event/event.h"
31 #include "utility/sync_util.h"
32 #include "initialization/initialization.h"
33
34 #ifndef EXPORT_API
35 #define EXPORT_API __attribute__ ((visibility("default")))
36 #endif
37
38 #define OMA_DS_CONFIG_FILE      "/usr/share/oma-ds-cfg/omadsUI_fw_config.xml"
39
40 #define SYNC_AGENT_DS_API_RESULT_FAILURE        0
41 #define SYNC_AGENT_DS_API_RESULT_SUCCESS        1
42
43 typedef enum {
44         SYNC_AGENT_DS_ADD_PROFILE = 1,
45         SYNC_AGENT_DS_UPDATE_PROFILE = 2,
46         SYNC_AGENT_DS_DELETE_PROFILE = 3,
47         SYNC_AGENT_DS_START_SYNC = 4,
48         SYNC_AGENT_DS_STOP_SYNC = 5,
49         SYNC_AGENT_DS_GET_PROFILE = 6,
50         SYNC_AGENT_DS_GET_SYNC_CATEGORY = 7,
51         SYNC_AGENT_DS_GET_SYNC_STATISTICS = 8,
52         SYNC_AGENT_DS_GET_ALL_PROFILES = 9
53 } sync_agent_ds_event_e;
54
55 typedef enum {
56         SYNC_AGENT_DS_SYNC_CONTACTS = 0,
57         SYNC_AGENT_DS_SYNC_SCHEDULE = 1,
58         SYNC_AGENT_DS_SYNC_MEMO = 2
59 } sync_agent_ds_sync_e;
60
61 static gboolean _get_sync_category(char *profile_dir_name, int service_type, sync_agent_ds_service_info ** service)
62 {
63         _INNER_FUNC_ENTER;
64
65         int event_type = SYNC_AGENT_DS_GET_SYNC_CATEGORY;
66         int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
67
68         // check mandatory parameter
69         retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
70         retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
71
72         sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
73         sync_agent_event_data_s *request_event = NULL;
74         sync_agent_event_data_s *response_event = NULL;
75
76         /* create empty event packet */
77         request_event = sync_agent_create_event(event_type);
78         if (request_event == NULL) {
79                 _DEBUG_ERROR("event is NULL");
80                 _EXTERN_FUNC_EXIT;
81                 return FALSE;
82         }
83
84         /* add request parameter to event packet */
85         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
86         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
87
88         /* send event request to ds agent daemon, waiting for response */
89         response_event = sync_agent_send_event(request_event, &error);
90         if (error != SYNC_AGENT_EVENT_SUCCESS) {
91                 _DEBUG_ERROR("error = %d", error);
92                 sync_agent_free_event(request_event);
93                 _EXTERN_FUNC_EXIT;
94                 return FALSE;
95         }
96         if (response_event == NULL) {
97                 _DEBUG_ERROR("response_event is null!!");
98                 sync_agent_free_event(request_event);
99                 _EXTERN_FUNC_EXIT;
100                 return FALSE;
101         }
102
103         *service = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
104         if (*service == NULL) {
105                 _DEBUG_ERROR("calloc failed");
106                 sync_agent_free_event(request_event);
107                 sync_agent_free_event_data(response_event);
108                 return FALSE;
109         }
110
111         /* get response parameter from event packet */
112
113         sync_agent_get_event_data_param(response_event, &api_result);
114         if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
115                 _DEBUG_ERROR("api_result = failed");
116                 sync_agent_free_event(request_event);
117                 sync_agent_free_event_data(response_event);
118                 _EXTERN_FUNC_EXIT;
119                 return SYNC_AGENT_DS_FAIL;
120         }
121
122         sync_agent_get_event_data_param(response_event, &((*service)->enabled));
123         sync_agent_get_event_data_param(response_event, &((*service)->src_uri));
124         sync_agent_get_event_data_param(response_event, &((*service)->tgt_uri));
125         sync_agent_get_event_data_param(response_event, &((*service)->id));
126         sync_agent_get_event_data_param(response_event, &((*service)->password));
127
128         _DEBUG_TRACE("enabled = %d", (*service)->enabled);
129         _DEBUG_TRACE("src_uri = %s", (*service)->src_uri);
130         _DEBUG_TRACE("tgt_uri = %s", (*service)->tgt_uri);
131         _DEBUG_TRACE("id = %s", (*service)->id);
132         _DEBUG_TRACE("password = %s", (*service)->password);
133
134         /* free request & response event */
135         sync_agent_free_event(request_event);
136         sync_agent_free_event_data(response_event);
137
138         _INNER_FUNC_EXIT;
139
140         return TRUE;
141 }
142
143 static gboolean _get_sync_statistics(char *profile_dir_name, int service_type, sync_agent_ds_statistics_info ** statistics)
144 {
145         _INNER_FUNC_ENTER;
146
147         int event_type = SYNC_AGENT_DS_GET_SYNC_STATISTICS;
148         int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
149
150         // check mandatory parameter
151         retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
152         retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
153
154         sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
155         sync_agent_event_data_s *request_event = NULL;
156         sync_agent_event_data_s *response_event = NULL;
157
158         char *statistics_cat = NULL;
159
160         /* create empty event packet */
161         request_event = sync_agent_create_event(event_type);
162         if (request_event == NULL) {
163                 _DEBUG_ERROR("event is NULL");
164                 _EXTERN_FUNC_EXIT;
165                 return FALSE;
166         }
167
168         /* add request parameter to event packet */
169         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
170         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
171
172         /* send event request to ds agent daemon, waiting for response */
173         response_event = sync_agent_send_event(request_event, &error);
174         if (error != SYNC_AGENT_EVENT_SUCCESS) {
175                 _DEBUG_ERROR("error = %d", error);
176                 sync_agent_free_event(request_event);
177                 _EXTERN_FUNC_EXIT;
178                 return FALSE;
179         }
180         if (response_event == NULL) {
181                 _DEBUG_ERROR("response_event is null!!");
182                 sync_agent_free_event(request_event);
183                 _EXTERN_FUNC_EXIT;
184                 return FALSE;
185         }
186
187         *statistics = (sync_agent_ds_statistics_info *) calloc(1, sizeof(sync_agent_ds_statistics_info));
188         if (*statistics == NULL) {
189                 _DEBUG_ERROR("calloc failed");
190                 sync_agent_free_event(request_event);
191                 sync_agent_free_event_data(response_event);
192                 return 0;
193         }
194
195         /* get response parameter from event packet */
196
197         sync_agent_get_event_data_param(response_event, &api_result);
198         if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
199                 _DEBUG_ERROR("api_result = failed");
200                 sync_agent_free_event(request_event);
201                 sync_agent_free_event_data(response_event);
202                 _EXTERN_FUNC_EXIT;
203                 return SYNC_AGENT_DS_FAIL;
204         }
205
206         if (service_type == SYNC_AGENT_DS_SYNC_CONTACTS)
207                 statistics_cat = "contacts";
208         else if (service_type == SYNC_AGENT_DS_SYNC_SCHEDULE)
209                 statistics_cat = "schedule";
210         else if (service_type == SYNC_AGENT_DS_SYNC_MEMO)
211                 statistics_cat = "memo";
212
213         sync_agent_get_event_data_param(response_event, &((*statistics)->dbsynced));
214         sync_agent_get_event_data_param(response_event, &((*statistics)->last_session_time));
215         sync_agent_get_event_data_param(response_event, &((*statistics)->server2client_total));
216         sync_agent_get_event_data_param(response_event, &((*statistics)->server2client_nrofadd));
217         sync_agent_get_event_data_param(response_event, &((*statistics)->server2client_nrofdelete));
218         sync_agent_get_event_data_param(response_event, &((*statistics)->server2client_nrofreplace));
219         sync_agent_get_event_data_param(response_event, &((*statistics)->client2server_total));
220         sync_agent_get_event_data_param(response_event, &((*statistics)->client2server_nrofadd));
221         sync_agent_get_event_data_param(response_event, &((*statistics)->client2server_nrofdelete));
222         sync_agent_get_event_data_param(response_event, &((*statistics)->client2server_nrofreplace));
223
224         _DEBUG_TRACE("%s dbSynced = %s", statistics_cat, (*statistics)->dbsynced);
225         _DEBUG_TRACE("%s lastSessionTime = %d", statistics_cat, (*statistics)->last_session_time);
226         _DEBUG_TRACE("%s server2Client_Total = %d", statistics_cat, (*statistics)->server2client_total);
227         _DEBUG_TRACE("%s server2Client_NrOrAdd = %d", statistics_cat, (*statistics)->server2client_nrofadd);
228         _DEBUG_TRACE("%s server2Client_NrOfDelete = %d", statistics_cat, (*statistics)->server2client_nrofdelete);
229         _DEBUG_TRACE("%s server2Client_NrOfReplace = %d", statistics_cat, (*statistics)->server2client_nrofreplace);
230         _DEBUG_TRACE("%s client2Server_Total = %d", statistics_cat, (*statistics)->client2server_total);
231         _DEBUG_TRACE("%s client2Server_NrOfAdd = %d", statistics_cat, (*statistics)->client2server_nrofadd);
232         _DEBUG_TRACE("%s client2Server_NrOfDelete = %d", statistics_cat, (*statistics)->client2server_nrofdelete);
233         _DEBUG_TRACE("%s client2Server_NrOfReplace = %d", statistics_cat, (*statistics)->client2server_nrofreplace);
234
235         /* free request & response event */
236         sync_agent_free_event(request_event);
237         sync_agent_free_event_data(response_event);
238
239         _INNER_FUNC_EXIT;
240
241         return TRUE;
242 }
243
244 static void _free_sync_category_info(sync_agent_ds_service_info * data)
245 {
246         g_free(data->src_uri);
247         g_free(data->tgt_uri);
248         g_free(data->id);
249         g_free(data->password);
250 }
251
252 EXPORT_API sync_agent_ds_error_e sync_agent_ds_init()
253 {
254         _EXTERN_FUNC_ENTER;
255
256         sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
257
258         sync_agent_init_error_e init_error = sync_agent_init(OMA_DS_CONFIG_FILE);
259
260         if (init_error != SYNC_AGENT_INIT_SUCCESS) {
261                 _DEBUG_ERROR("ds init failed");
262                 result = SYNC_AGENT_DS_FAIL;
263         }
264
265         sync_agent_event_error_e err = sync_agent_run_noti_listener("omads");
266         if (err != SYNC_AGENT_EVENT_SUCCESS) {
267                 _DEBUG_ERROR("RUN NOTILISTNER is failed");
268                 result = SYNC_AGENT_DS_FAIL;
269         }
270
271         _EXTERN_FUNC_EXIT;
272
273         return result;
274 }
275
276 EXPORT_API sync_agent_ds_error_e sync_agent_ds_create_profile_info(ds_profile_h * profile_h)
277 {
278         _EXTERN_FUNC_ENTER;
279
280         sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
281         sync_agent_ds_profile_info *profile_info = NULL;
282
283         // allocate memory for ds profile info
284         profile_info = (sync_agent_ds_profile_info *) calloc(1, sizeof(sync_agent_ds_profile_info));
285         if (profile_info == NULL) {
286                 _DEBUG_ERROR("calloc failed !!");
287                 return SYNC_AGENT_DS_FAIL;
288         }
289         // pass memory pointer to ds profile handle
290         *profile_h = profile_info;
291
292         _EXTERN_FUNC_EXIT;
293
294         return result;
295 }
296
297 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_name(ds_profile_h profile_h, char *profile_dir_name, char *profile_name)
298 {
299         _EXTERN_FUNC_ENTER;
300
301         sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
302         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
303
304         // check mandatory parameter
305         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
306         retvm_if(profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
307
308         // set profile name
309         profile_info->profile_dir_name = g_strdup(profile_dir_name);
310         profile_info->profile_name = g_strdup(profile_name);
311
312         if (profile_info->profile_dir_name == NULL) {
313                 _DEBUG_ERROR("g_strdup failed !!");
314                 return SYNC_AGENT_DS_FAIL;
315         }
316
317         _EXTERN_FUNC_EXIT;
318
319         return result;
320 }
321
322 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_server_info(ds_profile_h profile_h, char *addr, char *id, char *password)
323 {
324         _EXTERN_FUNC_ENTER;
325
326         sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
327         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
328         sync_agent_ds_server_info *server_info = &profile_info->server_info;
329
330         // check mandatory parameter
331         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
332         retvm_if(addr == NULL, SYNC_AGENT_DS_FAIL, "addr is null!!");
333         retvm_if(id == NULL, SYNC_AGENT_DS_FAIL, "id is null!!");
334         retvm_if(password == NULL, SYNC_AGENT_DS_FAIL, "password is null!!");
335
336         // set server info
337         server_info->addr = g_strdup(addr);
338         server_info->id = g_strdup(id);
339         server_info->password = g_strdup(password);
340
341         if ((server_info->addr == NULL)
342             || (server_info->id == NULL)
343             || (server_info->password == NULL)) {
344                 _DEBUG_ERROR("g_strdup failed !!");
345                 return SYNC_AGENT_DS_FAIL;
346         }
347
348         _EXTERN_FUNC_EXIT;
349
350         return result;
351 }
352
353 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_sync_info(ds_profile_h profile_h, char *sync_mode, char *sync_type, char *interval)
354 {
355         _EXTERN_FUNC_ENTER;
356
357         sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
358         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
359         sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
360
361         // check mandatory parameter
362         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
363         retvm_if(sync_mode == NULL, SYNC_AGENT_DS_FAIL, "sync_mode is null!!");
364         retvm_if(sync_type == NULL, SYNC_AGENT_DS_FAIL, "sync_type is null!!");
365         retvm_if(interval == NULL, SYNC_AGENT_DS_FAIL, "interval is null!!");
366
367         // set server info
368         sync_info->sync_mode = g_strdup(sync_mode);
369         sync_info->sync_type = g_strdup(sync_type);
370         sync_info->interval = g_strdup(interval);
371
372         if ((sync_info->sync_mode == NULL)
373             || (sync_info->sync_type == NULL)
374             || (sync_info->interval == NULL)) {
375                 _DEBUG_ERROR("g_strdup failed !!");
376                 return SYNC_AGENT_DS_FAIL;
377         }
378
379         _EXTERN_FUNC_EXIT;
380
381         return result;
382 }
383
384 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_sync_service_info(ds_profile_h profile_h, sync_agent_ds_service_type_e service_type, int enabled, char *src_uri, char *tgt_uri, char *id, char *password)
385 {
386         _EXTERN_FUNC_ENTER;
387
388         sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
389         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
390         sync_agent_ds_service_info *category_info = NULL;
391
392         // check mandatory parameter
393         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
394         retvm_if(src_uri == NULL, SYNC_AGENT_DS_FAIL, "src_uri is null!!");
395
396         // allocate memory for sync_category
397         category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
398         retvm_if(category_info == NULL, SYNC_AGENT_DS_FAIL, "calloc failed");
399         category_info->service_type = service_type;
400         category_info->enabled = enabled;
401         category_info->src_uri = g_strdup(src_uri);
402         category_info->tgt_uri = g_strdup(tgt_uri);
403
404         profile_info->service_list = g_list_append(profile_info->service_list, category_info);
405
406         if (category_info->src_uri == NULL) {
407                 _DEBUG_ERROR("g_strdup failed !!");
408                 return SYNC_AGENT_DS_FAIL;
409         }
410
411         _EXTERN_FUNC_EXIT;
412
413         return result;
414 }
415
416 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_name(ds_profile_h profile_h, char **profile_dir_name, char **profile_name)
417 {
418         _EXTERN_FUNC_ENTER;
419
420         // check mandatory parameter
421         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
422
423         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
424
425         sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
426
427         *profile_dir_name = g_strdup(profile_info->profile_dir_name);
428         *profile_name = g_strdup(profile_info->profile_name);
429
430         if ((*profile_dir_name == NULL)
431             || (*profile_name == NULL)) {
432                 _DEBUG_ERROR("g_strdup failed !!");
433                 return SYNC_AGENT_DS_FAIL;
434         }
435
436         _DEBUG_INFO("profileDirame = %s", *profile_dir_name);
437         _DEBUG_INFO("get_profile_name = %s", *profile_name);
438
439         _EXTERN_FUNC_EXIT;
440
441         return result;
442 }
443
444 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_server_info(ds_profile_h profile_h, sync_agent_ds_server_info * server_info)
445 {
446         _EXTERN_FUNC_ENTER;
447
448         // check mandatory parameter
449         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
450         retvm_if(server_info == NULL, SYNC_AGENT_DS_FAIL, "server_info is null!!");
451
452         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
453         sync_agent_ds_server_info *ds_server_info = &profile_info->server_info;
454
455         sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
456
457         server_info->addr = g_strdup(ds_server_info->addr);
458         server_info->id = g_strdup(ds_server_info->id);
459         server_info->password = g_strdup(ds_server_info->password);
460
461         if ((server_info->addr == NULL)
462             || (server_info->id == NULL)
463             || (server_info->password == NULL)) {
464                 _DEBUG_ERROR("g_strdup failed !!");
465                 return SYNC_AGENT_DS_FAIL;
466         }
467
468         _DEBUG_INFO("get_addr = %s", server_info->addr);
469         _DEBUG_INFO("get_id = %s", server_info->id);
470         _DEBUG_INFO("get_password = %s", server_info->password);
471
472         _EXTERN_FUNC_EXIT;
473
474         return result;
475 }
476
477 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_info(ds_profile_h profile_h, sync_agent_ds_sync_info * sync_info)
478 {
479         _EXTERN_FUNC_ENTER;
480
481         // check mandatory parameter
482         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
483         retvm_if(sync_info == NULL, SYNC_AGENT_DS_FAIL, "sync_info is null!!");
484
485         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
486         sync_agent_ds_sync_info *ds_sync_info = &profile_info->sync_info;
487
488         sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
489
490         sync_info->sync_mode = g_strdup(ds_sync_info->sync_mode);
491         sync_info->sync_type = g_strdup(ds_sync_info->sync_type);
492         sync_info->interval = g_strdup(ds_sync_info->interval);
493
494         if ((sync_info->sync_mode == NULL)
495             || (sync_info->sync_type == NULL)
496             || (sync_info->interval == NULL)) {
497                 _DEBUG_ERROR("g_strdup failed !!");
498                 return SYNC_AGENT_DS_FAIL;
499         }
500
501         _DEBUG_INFO("get_sync_mode = %s", sync_info->sync_mode);
502         _DEBUG_INFO("get_sync_type = %s", sync_info->sync_type);
503         _DEBUG_INFO("get_interval = %s", sync_info->interval);
504
505         _EXTERN_FUNC_EXIT;
506
507         return result;
508 }
509
510 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_service_info(ds_profile_h profile_h, GList ** category_list)
511 {
512         _EXTERN_FUNC_ENTER;
513
514         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
515
516         int category_count = 0;
517         int i = 0;
518         sync_agent_ds_service_info *category_info = NULL;
519
520         *category_list = g_list_copy(profile_info->service_list);
521
522         if (*category_list == NULL) {
523                 _DEBUG_ERROR("g_list_copy failed !!");
524                 return SYNC_AGENT_DS_FAIL;
525         }
526
527         category_count = g_list_length(*category_list);
528         for (; i < category_count; i++) {
529                 category_info = (sync_agent_ds_service_info *) g_list_nth_data(*category_list, i);
530
531                 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
532                 _DEBUG_INFO("category[%d]->src_uri = %s", i, category_info->src_uri);
533                 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
534                 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
535                 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
536         }
537
538         _EXTERN_FUNC_EXIT;
539
540         return SYNC_AGENT_DS_SUCCESS;
541 }
542
543 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_statistics(ds_profile_h profile_h, GList ** statistics_list)
544 {
545         _EXTERN_FUNC_ENTER;
546
547         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
548         sync_agent_ds_statistics_info *statistics = NULL;
549
550         gboolean result_sync_category = FALSE;
551
552         /* get last contacts sync result */
553         result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &statistics);
554         if (result_sync_category)
555                 *statistics_list = g_list_append(*statistics_list, statistics);
556
557         /* get last schedule sync result */
558         statistics = NULL;
559         result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &statistics);
560         if (result_sync_category)
561                 *statistics_list = g_list_append(*statistics_list, statistics);
562
563         /* get last memo sync result */
564         statistics = NULL;
565         result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_MEMO, &statistics);
566         if (result_sync_category)
567                 *statistics_list = g_list_append(*statistics_list, statistics);
568
569         _EXTERN_FUNC_EXIT;
570
571         return SYNC_AGENT_DS_SUCCESS;
572 }
573
574 EXPORT_API sync_agent_ds_error_e sync_agent_ds_add_profile(ds_profile_h profile_h, int *profile_id)
575 {
576         _EXTERN_FUNC_ENTER;
577
578         // check mandatory parameter
579         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
580
581         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
582         sync_agent_ds_server_info *server_info = &profile_info->server_info;
583         sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
584         GList *list = profile_info->service_list;
585
586         int event_type = SYNC_AGENT_DS_ADD_PROFILE;
587         sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
588         sync_agent_event_data_s *request_event = NULL;
589         sync_agent_event_data_s *response_event = NULL;
590
591         int prof_id = 0;
592         int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
593         sync_agent_ds_service_info *category_info = NULL;
594         int category_count = 0;
595         int i = 0;
596
597         /* create empty event packet */
598         request_event = sync_agent_create_event(event_type);
599         if (request_event == NULL) {
600                 _DEBUG_ERROR("event is NULL");
601                 _EXTERN_FUNC_EXIT;
602                 return SYNC_AGENT_DS_FAIL;
603         }
604
605         /* add request parameter to event packet */
606         _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
607         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
608         _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
609         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
610         _DEBUG_INFO("addr = %s", server_info->addr);
611         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
612         _DEBUG_INFO("id = %s", server_info->id);
613         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
614         _DEBUG_INFO("password = %s", server_info->password);
615         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
616         _DEBUG_INFO("sync_mode = %s", sync_info->sync_mode);
617         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_mode);
618         _DEBUG_INFO("sync_type = %s", sync_info->sync_type);
619         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_type);
620         _DEBUG_INFO("interval = %s", sync_info->interval);
621         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->interval);
622
623         category_count = g_list_length(list);
624         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
625
626         for (; i < category_count; i++) {
627                 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
628
629                 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
630                 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
631                 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
632                 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
633                 _DEBUG_INFO("category[%d]->src_uri = %s", i, category_info->src_uri);
634                 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->src_uri);
635                 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
636                 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
637                 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
638                 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
639                 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
640                 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
641         }
642
643         /* send event request to ds agent daemon, waiting for response */
644         response_event = sync_agent_send_event(request_event, &error);
645         if (error != SYNC_AGENT_EVENT_SUCCESS) {
646                 _DEBUG_ERROR("error = %d", error);
647                 sync_agent_free_event(request_event);
648                 _EXTERN_FUNC_EXIT;
649                 return SYNC_AGENT_DS_FAIL;
650         }
651         if (response_event == NULL) {
652                 _DEBUG_ERROR("response_event is null!!");
653                 sync_agent_free_event(request_event);
654                 _EXTERN_FUNC_EXIT;
655                 return SYNC_AGENT_DS_FAIL;
656         }
657
658         /* get response parameter from event packet */
659         sync_agent_get_event_data_param(response_event, &api_result);
660
661         if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
662                 _DEBUG_ERROR("api_result = failed");
663                 sync_agent_free_event(request_event);
664                 sync_agent_free_event_data(response_event);
665                 _EXTERN_FUNC_EXIT;
666                 return SYNC_AGENT_DS_FAIL;
667         }
668
669         sync_agent_get_event_data_param(response_event, &prof_id);
670
671         _DEBUG_VERBOSE("profile_id = %d", prof_id);
672         *profile_id = prof_id;
673
674         /* free request & response event */
675         sync_agent_free_event(request_event);
676         sync_agent_free_event_data(response_event);
677
678         _EXTERN_FUNC_EXIT;
679
680         return SYNC_AGENT_DS_SUCCESS;
681 }
682
683 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile(char *profile_dir_name, ds_profile_h * profile_h)
684 {
685         _EXTERN_FUNC_ENTER;
686
687         int event_type = SYNC_AGENT_DS_GET_PROFILE;
688         sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
689         sync_agent_event_data_s *request_event = NULL;
690         sync_agent_event_data_s *response_event = NULL;
691
692         gboolean result_sync_category = FALSE;
693         sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
694         int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
695         sync_agent_ds_service_info *category = NULL;
696
697         // check mandatory parameter
698         retvm_if(profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
699
700         //////////////////////////////////
701         //
702         // Phase 1. get profile detail info
703
704         /* create empty event packet */
705         request_event = sync_agent_create_event(event_type);
706         if (request_event == NULL) {
707                 _DEBUG_ERROR("event is NULL");
708                 _EXTERN_FUNC_EXIT;
709                 return SYNC_AGENT_DS_FAIL;
710         }
711
712         /* add request parameter to event packet */
713         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
714
715         /* send event request to ds agent daemon, waiting for response */
716         response_event = sync_agent_send_event(request_event, &error);
717         if (error != SYNC_AGENT_EVENT_SUCCESS) {
718                 _DEBUG_ERROR("error = %d", error);
719                 sync_agent_free_event(request_event);
720                 _EXTERN_FUNC_EXIT;
721                 return SYNC_AGENT_DS_FAIL;
722         }
723         if (response_event == NULL) {
724                 _DEBUG_ERROR("response_event is null!!");
725                 sync_agent_free_event(request_event);
726                 _EXTERN_FUNC_EXIT;
727                 return SYNC_AGENT_DS_FAIL;
728         }
729
730         /* get response parameter from event packet */
731
732         result = sync_agent_ds_create_profile_info(profile_h);
733         if (result == SYNC_AGENT_DS_FAIL) {
734                 _DEBUG_ERROR("failed to create profile info!");
735                 sync_agent_free_event(request_event);
736                 sync_agent_free_event_data(response_event);
737                 return FALSE;
738         }
739
740         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) (*profile_h);
741         sync_agent_ds_server_info *server_info = &profile_info->server_info;
742         sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
743 //      GList * list = profile_info->category_list;
744
745         sync_agent_get_event_data_param(response_event, &api_result);
746         if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
747                 _DEBUG_ERROR("api_result = failed");
748                 sync_agent_free_event(request_event);
749                 sync_agent_free_event_data(response_event);
750                 _EXTERN_FUNC_EXIT;
751                 return SYNC_AGENT_DS_FAIL;
752         }
753
754         profile_info->profile_dir_name = g_strdup(profile_dir_name);
755
756         sync_agent_get_event_data_param(response_event, &profile_info->profile_name);
757         sync_agent_get_event_data_param(response_event, &server_info->addr);
758         sync_agent_get_event_data_param(response_event, &server_info->id);
759         sync_agent_get_event_data_param(response_event, &server_info->password);
760         sync_agent_get_event_data_param(response_event, &sync_info->sync_mode);
761         sync_agent_get_event_data_param(response_event, &sync_info->sync_type);
762         sync_agent_get_event_data_param(response_event, &sync_info->interval);
763         sync_agent_get_event_data_param(response_event, &profile_info->last_sync_status);
764         sync_agent_get_event_data_param(response_event, &profile_info->last_sync_time);
765
766         _DEBUG_INFO("profileDirame = %s", profile_info->profile_name);
767         _DEBUG_INFO("addr = %s", server_info->addr);
768         _DEBUG_INFO("id = %s", server_info->id);
769         _DEBUG_INFO("password = %s", server_info->password);
770         _DEBUG_INFO("sync_mode = %s", sync_info->sync_mode);
771         _DEBUG_INFO("sync_type = %s", sync_info->sync_type);
772         _DEBUG_INFO("interval = %s", sync_info->interval);
773         _DEBUG_VERBOSE("lastSyncStatus = %d\n", profile_info->last_sync_status);
774         _DEBUG_VERBOSE("lastSyncTime = %d\n", profile_info->last_sync_time);
775
776         /* free request & response event */
777         sync_agent_free_event(request_event);
778         sync_agent_free_event_data(response_event);
779
780         //////////////////////////////////
781         //
782         // Phase 2. get sync category info
783
784         /* get contacts sync_category */
785         result_sync_category = _get_sync_category(profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &category);
786         if (result_sync_category)
787                 profile_info->service_list = g_list_append(profile_info->service_list, category);
788
789         /* get schedule sync_category */
790         category = NULL;
791         result_sync_category = _get_sync_category(profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &category);
792         if (result_sync_category)
793                 profile_info->service_list = g_list_append(profile_info->service_list, category);
794
795         /* get memo sync_category */
796         category = NULL;
797         result_sync_category = _get_sync_category(profile_dir_name, SYNC_AGENT_DS_SYNC_MEMO, &category);
798         if (result_sync_category)
799                 profile_info->service_list = g_list_append(profile_info->service_list, category);
800
801         _EXTERN_FUNC_EXIT;
802
803         return SYNC_AGENT_DS_SUCCESS;
804 }
805
806 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_all_profile(GList ** profile_list)
807 {
808         _EXTERN_FUNC_ENTER;
809
810         int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
811         sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
812         sync_agent_event_data_s *request_event = NULL;
813         sync_agent_event_data_s *response_event = NULL;
814
815         ds_profile_h profile_h = NULL;
816         sync_agent_ds_service_info *category_info = NULL;
817
818         int profile_count = 0;
819         int category_count = 0;
820
821         sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
822         int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
823
824         /* create empty event packet */
825         request_event = sync_agent_create_event(event_type);
826         if (request_event == NULL) {
827                 _DEBUG_ERROR("event is NULL");
828                 _EXTERN_FUNC_EXIT;
829                 return SYNC_AGENT_DS_FAIL;
830         }
831
832         /* send event request to ds agent daemon, waiting for response */
833         response_event = sync_agent_send_event(request_event, &error);
834         if (error != SYNC_AGENT_EVENT_SUCCESS) {
835                 _DEBUG_ERROR("error = %d", error);
836                 sync_agent_free_event(request_event);
837                 _EXTERN_FUNC_EXIT;
838                 return SYNC_AGENT_DS_FAIL;
839         }
840         if (response_event == NULL) {
841                 _DEBUG_ERROR("response_event is null!!");
842                 sync_agent_free_event(request_event);
843                 _EXTERN_FUNC_EXIT;
844                 return SYNC_AGENT_DS_FAIL;
845         }
846
847         sync_agent_get_event_data_param(response_event, &api_result);
848         if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
849                 _DEBUG_ERROR("api_result = failed");
850                 sync_agent_free_event(request_event);
851                 sync_agent_free_event_data(response_event);
852                 _EXTERN_FUNC_EXIT;
853                 return SYNC_AGENT_DS_FAIL;
854         }
855
856         sync_agent_get_event_data_param(response_event, &profile_count);
857         _DEBUG_INFO("profile_count = %d", profile_count);
858
859         int i;
860         for (i = 0; i < profile_count; i++) {
861
862                 result = sync_agent_ds_create_profile_info(&profile_h);
863                 if (result == SYNC_AGENT_DS_FAIL) {
864                         _DEBUG_ERROR("failed to create profile info!");
865                         sync_agent_free_event(request_event);
866                         sync_agent_free_event_data(response_event);
867                         return FALSE;
868                 }
869
870                 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
871                 sync_agent_ds_server_info *server_info = &profile_info->server_info;
872                 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
873
874                 sync_agent_get_event_data_param(response_event, &profile_info->profile_dir_name);
875                 sync_agent_get_event_data_param(response_event, &profile_info->profile_name);
876                 sync_agent_get_event_data_param(response_event, &server_info->addr);
877                 sync_agent_get_event_data_param(response_event, &server_info->id);
878                 sync_agent_get_event_data_param(response_event, &server_info->password);
879                 sync_agent_get_event_data_param(response_event, &sync_info->sync_mode);
880                 sync_agent_get_event_data_param(response_event, &sync_info->sync_type);
881                 sync_agent_get_event_data_param(response_event, &sync_info->interval);
882                 sync_agent_get_event_data_param(response_event, &profile_info->last_sync_status);
883                 sync_agent_get_event_data_param(response_event, &profile_info->last_sync_time);
884
885                 _DEBUG_INFO("profile_info->profile_dir_name = %s", profile_info->profile_dir_name);
886                 _DEBUG_INFO("profile_info->profile_name = %s", profile_info->profile_name);
887                 _DEBUG_INFO("profile_info->addr = %s", server_info->addr);
888                 _DEBUG_INFO("profile_info->id = %s", server_info->id);
889                 _DEBUG_INFO("profile_info->password = %s", server_info->password);
890                 _DEBUG_INFO("profile_info->sync_mode = %s", sync_info->sync_mode);
891                 _DEBUG_INFO("profile_info->sync_type = %s", sync_info->sync_type);
892                 _DEBUG_INFO("profile_info->interval = %s", sync_info->interval);
893                 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
894                 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
895
896                 sync_agent_get_event_data_param(response_event, &category_count);
897
898                 int j;
899                 for (j = 0; j < category_count; j++) {
900
901                         category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
902                         if (category_info == NULL) {
903                                 _DEBUG_ERROR("calloc failed");
904                                 sync_agent_ds_free_profile_info(profile_h);
905                                 sync_agent_free_event(request_event);
906                                 sync_agent_free_event_data(response_event);
907                                 return FALSE;
908                         }
909
910                         sync_agent_get_event_data_param(response_event, &category_info->service_type);
911                         sync_agent_get_event_data_param(response_event, &category_info->enabled);
912                         sync_agent_get_event_data_param(response_event, &category_info->src_uri);
913                         sync_agent_get_event_data_param(response_event, &category_info->tgt_uri);
914                         sync_agent_get_event_data_param(response_event, &category_info->id);
915                         sync_agent_get_event_data_param(response_event, &category_info->password);
916
917                         _DEBUG_INFO("category_info->service_type = %d", category_info->service_type);
918                         _DEBUG_INFO("category_info->enabled = %d", category_info->enabled);
919                         _DEBUG_INFO("category_info->src_uri = %s", category_info->src_uri);
920                         _DEBUG_INFO("category_info->tgt_uri = %s", category_info->tgt_uri);
921                         _DEBUG_INFO("category_info->id = %s", category_info->id);
922                         _DEBUG_INFO("category_info->password = %s", category_info->password);
923
924                         profile_info->service_list = g_list_append(profile_info->service_list, category_info);
925                         category_info = NULL;
926                 }
927
928                 *profile_list = g_list_append(*profile_list, profile_h);
929                 profile_h = NULL;
930         }
931
932         /* free request & response event */
933         sync_agent_free_event(request_event);
934         sync_agent_free_event_data(response_event);
935
936         _EXTERN_FUNC_EXIT;
937
938         return SYNC_AGENT_DS_SUCCESS;
939 }
940
941 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_last_sync_info(ds_profile_h profile_h, int *lastSyncStatus, int *lastSyncTime)
942 {
943         _EXTERN_FUNC_ENTER;
944
945         // check mandatory parameter
946         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
947         retvm_if(lastSyncStatus == NULL, SYNC_AGENT_DS_FAIL, "last session status is null!!");
948         retvm_if(lastSyncTime == NULL, SYNC_AGENT_DS_FAIL, "last session time is null!!");
949
950         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
951
952         *lastSyncStatus = profile_info->last_sync_status;
953         *lastSyncTime = profile_info->last_sync_time;
954
955         _EXTERN_FUNC_EXIT;
956
957         return SYNC_AGENT_DS_SUCCESS;
958 }
959
960 EXPORT_API sync_agent_ds_error_e sync_agent_ds_update_profile(ds_profile_h profile_h)
961 {
962         _EXTERN_FUNC_ENTER;
963
964         // check mandatory parameter
965         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
966
967         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
968         sync_agent_ds_server_info *server_info = &profile_info->server_info;
969         sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
970         GList *list = profile_info->service_list;
971
972         int event_type = SYNC_AGENT_DS_UPDATE_PROFILE;
973         sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
974         sync_agent_event_data_s *request_event = NULL;
975         sync_agent_event_data_s *response_event = NULL;
976
977         int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
978         sync_agent_ds_service_info *category_info = NULL;
979         int category_count = 0;
980         int i = 0;
981
982         /* create empty event packet */
983         request_event = sync_agent_create_event(event_type);
984         if (request_event == NULL) {
985                 _DEBUG_ERROR("event is NULL");
986                 _EXTERN_FUNC_EXIT;
987                 return SYNC_AGENT_DS_FAIL;
988         }
989
990         /* add request parameter to event packet */
991         _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
992         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
993         _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
994         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
995         _DEBUG_INFO("addr = %s", server_info->addr);
996         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
997         _DEBUG_INFO("id = %s", server_info->id);
998         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
999         _DEBUG_INFO("password = %s", server_info->password);
1000         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1001         _DEBUG_INFO("sync_mode = %s", sync_info->sync_mode);
1002         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_mode);
1003         _DEBUG_INFO("sync_type = %s", sync_info->sync_type);
1004         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_type);
1005         _DEBUG_INFO("interval = %s", sync_info->interval);
1006         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->interval);
1007
1008         category_count = g_list_length(list);
1009         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1010
1011         for (; i < category_count; i++) {
1012                 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1013
1014                 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1015                 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1016                 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1017                 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1018                 _DEBUG_INFO("category[%d]->src_uri = %s", i, category_info->src_uri);
1019                 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->src_uri);
1020                 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1021                 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1022                 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1023                 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1024                 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1025                 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1026         }
1027
1028         /* send event request to ds agent daemon, waiting for response */
1029         response_event = sync_agent_send_event(request_event, &error);
1030         if (error != SYNC_AGENT_EVENT_SUCCESS) {
1031                 _DEBUG_ERROR("error = %d", error);
1032                 sync_agent_free_event(request_event);
1033                 _EXTERN_FUNC_EXIT;
1034                 return SYNC_AGENT_DS_FAIL;
1035         }
1036         if (response_event == NULL) {
1037                 _DEBUG_ERROR("response_event is null!!");
1038                 sync_agent_free_event(request_event);
1039                 _EXTERN_FUNC_EXIT;
1040                 return SYNC_AGENT_DS_FAIL;
1041         }
1042
1043         /* get response parameter from event packet */
1044         sync_agent_get_event_data_param(response_event, &api_result);
1045
1046         if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1047                 _DEBUG_ERROR("api_result = failed");
1048                 sync_agent_free_event(request_event);
1049                 sync_agent_free_event_data(response_event);
1050                 _EXTERN_FUNC_EXIT;
1051                 return SYNC_AGENT_DS_FAIL;
1052         }
1053
1054         /* free request & response event */
1055         sync_agent_free_event(request_event);
1056         sync_agent_free_event_data(response_event);
1057
1058         _EXTERN_FUNC_EXIT;
1059
1060         return SYNC_AGENT_DS_SUCCESS;
1061 }
1062
1063 EXPORT_API sync_agent_ds_error_e sync_agent_ds_delete_profile(ds_profile_h profile_h)
1064 {
1065         _EXTERN_FUNC_ENTER;
1066
1067         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1068
1069         int event_type = SYNC_AGENT_DS_DELETE_PROFILE;
1070         sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1071         sync_agent_event_data_s *request_event = NULL;
1072         sync_agent_event_data_s *response_event = NULL;
1073
1074         int count = 1;
1075         int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1076
1077         // check mandatory parameter
1078         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1079         retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1080
1081         /* create empty event packet */
1082         request_event = sync_agent_create_event(event_type);
1083         if (request_event == NULL) {
1084                 _DEBUG_ERROR("event is NULL");
1085                 return SYNC_AGENT_DS_FAIL;
1086         }
1087
1088         /* add request parameter to event packet */
1089         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &count);
1090
1091         _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1092         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1093
1094         /* send event request to ds agent daemon, waiting for response */
1095         response_event = sync_agent_send_event(request_event, &error);
1096         if (error != SYNC_AGENT_EVENT_SUCCESS) {
1097                 _DEBUG_ERROR("error = %d", error);
1098                 sync_agent_free_event(request_event);
1099                 _EXTERN_FUNC_EXIT;
1100                 return SYNC_AGENT_DS_FAIL;
1101         }
1102         if (response_event == NULL) {
1103                 _DEBUG_ERROR("response_event is null!!");
1104                 sync_agent_free_event(request_event);
1105                 _EXTERN_FUNC_EXIT;
1106                 return SYNC_AGENT_DS_FAIL;
1107         }
1108
1109         /* get response parameter from event packet */
1110         sync_agent_get_event_data_param(response_event, &api_result);
1111
1112         if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1113                 _DEBUG_ERROR("api_result = failed");
1114                 sync_agent_free_event(request_event);
1115                 sync_agent_free_event_data(response_event);
1116                 _EXTERN_FUNC_EXIT;
1117                 return SYNC_AGENT_DS_FAIL;
1118         }
1119
1120         /* free request & response event */
1121         sync_agent_free_event(request_event);
1122         sync_agent_free_event_data(response_event);
1123
1124         _EXTERN_FUNC_EXIT;
1125
1126         return SYNC_AGENT_DS_SUCCESS;
1127 }
1128
1129 EXPORT_API sync_agent_ds_error_e sync_agent_ds_start_sync(ds_profile_h profile_h)
1130 {
1131         _EXTERN_FUNC_ENTER;
1132
1133         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1134
1135         int event_type = SYNC_AGENT_DS_START_SYNC;
1136         sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1137         sync_agent_event_data_s *request_event = NULL;
1138         sync_agent_event_data_s *response_event = NULL;
1139
1140         int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1141
1142         // check mandatory parameter
1143         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1144         retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1145
1146         /* create empty event packet */
1147         request_event = sync_agent_create_event(event_type);
1148         if (request_event == NULL) {
1149                 _DEBUG_ERROR("event is NULL");
1150                 return SYNC_AGENT_DS_FAIL;
1151         }
1152
1153         /* add request parameter to event packet */
1154         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1155
1156         /* send event request to ds agent daemon, waiting for response */
1157         response_event = sync_agent_send_event(request_event, &error);
1158         if (error != SYNC_AGENT_EVENT_SUCCESS) {
1159                 _DEBUG_ERROR("error = %d", error);
1160                 sync_agent_free_event(request_event);
1161                 _EXTERN_FUNC_EXIT;
1162                 return SYNC_AGENT_DS_FAIL;
1163         }
1164         if (response_event == NULL) {
1165                 _DEBUG_ERROR("response_event is null!!");
1166                 sync_agent_free_event(request_event);
1167                 _EXTERN_FUNC_EXIT;
1168                 return SYNC_AGENT_DS_FAIL;
1169         }
1170
1171         /* get response parameter from event packet */
1172         sync_agent_get_event_data_param(response_event, &api_result);
1173
1174         if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1175                 _DEBUG_ERROR("api_result = failed");
1176                 sync_agent_free_event(request_event);
1177                 sync_agent_free_event_data(response_event);
1178                 _EXTERN_FUNC_EXIT;
1179                 return SYNC_AGENT_DS_FAIL;
1180         }
1181
1182         /* free request & response event */
1183         sync_agent_free_event(request_event);
1184         sync_agent_free_event_data(response_event);
1185
1186         _EXTERN_FUNC_EXIT;
1187
1188         return SYNC_AGENT_DS_SUCCESS;
1189 }
1190
1191 EXPORT_API sync_agent_ds_error_e sync_agent_ds_stop_sync(ds_profile_h profile_h)
1192 {
1193         _EXTERN_FUNC_ENTER;
1194
1195         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1196
1197         int event_type = SYNC_AGENT_DS_STOP_SYNC;
1198         sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1199         sync_agent_event_data_s *request_event = NULL;
1200         sync_agent_event_data_s *response_event = NULL;
1201
1202         int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1203
1204         // check mandatory parameter
1205         retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1206         retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1207
1208         /* create empty event packet */
1209         request_event = sync_agent_create_event(event_type);
1210         if (request_event == NULL) {
1211                 _DEBUG_ERROR("event is NULL");
1212                 return SYNC_AGENT_DS_FAIL;
1213         }
1214
1215         /* add request parameter to event packet */
1216         sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1217
1218         /* send event request to ds agent daemon, waiting for response */
1219         response_event = sync_agent_send_event(request_event, &error);
1220         if (error != SYNC_AGENT_EVENT_SUCCESS) {
1221                 _DEBUG_ERROR("error = %d", error);
1222                 sync_agent_free_event(request_event);
1223                 _EXTERN_FUNC_EXIT;
1224                 return SYNC_AGENT_DS_FAIL;
1225         }
1226         if (response_event == NULL) {
1227                 _DEBUG_ERROR("response_event is null!!");
1228                 sync_agent_free_event(request_event);
1229                 _EXTERN_FUNC_EXIT;
1230                 return SYNC_AGENT_DS_FAIL;
1231         }
1232
1233         /* get response parameter from event packet */
1234         sync_agent_get_event_data_param(response_event, &api_result);
1235
1236         if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1237                 _DEBUG_ERROR("api_result = failed");
1238                 sync_agent_free_event(request_event);
1239                 sync_agent_free_event_data(response_event);
1240                 _EXTERN_FUNC_EXIT;
1241                 return SYNC_AGENT_DS_FAIL;
1242         }
1243
1244         /* free request & response event */
1245         sync_agent_free_event(request_event);
1246         sync_agent_free_event_data(response_event);
1247
1248         _EXTERN_FUNC_EXIT;
1249
1250         return SYNC_AGENT_DS_SUCCESS;
1251 }
1252
1253 EXPORT_API void sync_agent_ds_free_profile_info(ds_profile_h profile_h)
1254 {
1255         _EXTERN_FUNC_ENTER;
1256
1257         // check mandatory parameter
1258         retm_if(profile_h == NULL, "profile handle is null!!");
1259
1260         sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1261
1262         sync_agent_ds_server_info *server_info = &profile_info->server_info;
1263         sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1264         GList *category_list = profile_info->service_list;
1265
1266         // free profile name
1267         g_free(profile_info->profile_dir_name);
1268         g_free(profile_info->profile_name);
1269
1270         // free server information
1271         g_free(server_info->addr);
1272         g_free(server_info->id);
1273         g_free(server_info->password);
1274
1275         // free sync mode information
1276         g_free(sync_info->sync_mode);
1277         g_free(sync_info->sync_type);
1278         g_free(sync_info->interval);
1279
1280         // free sync category information
1281         g_list_free_full(category_list, (GDestroyNotify) _free_sync_category_info);
1282
1283         // free profile information
1284         g_free(profile_info);
1285
1286         _EXTERN_FUNC_EXIT;
1287 }
1288
1289 EXPORT_API sync_agent_ds_error_e sync_agent_ds_deinit()
1290 {
1291         _EXTERN_FUNC_ENTER;
1292
1293         sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1294
1295         sync_agent_deinit_error_e deinit = SYNC_AGENT_DEINIT_SUCCESS;
1296
1297         deinit = sync_agent_deinit();
1298         if (deinit != SYNC_AGENT_DEINIT_SUCCESS) {
1299                 _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1300                 result = SYNC_AGENT_DS_FAIL;
1301         }
1302 //      if (err != SYNC_AGENT_EVENT_SUCCESS) {
1303 //      sync_agent_event_error_e err = sync_agent_stop_noti_listener();
1304 //              _DEBUG_INFO("STOP NOTILISTNER is failed");
1305 //              result = SYNC_AGENT_DS_FAIL;
1306 //      }
1307 //
1308 //      err = sync_agent_clean_event_handler();
1309 //      if (err != SYNC_AGENT_EVENT_SUCCESS) {
1310 //              _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1311 //              result = SYNC_AGENT_DS_FAIL;
1312 //      }
1313
1314         _EXTERN_FUNC_EXIT;
1315
1316         return result;
1317 }