Tizen 2.0 Release
[pkgs/o/oma-ds-service.git] / src / agent / framework / event / oma_ds_event_handler.c
1 /*
2  * oma-ds-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 /**
19  *   @OMA_DS_Event_Handler.c
20  *   @version                                                                   0.1
21  *   @brief                                                                             This file is the source file of implementation of event callback function(from ui)
22  */
23
24 #include <glib.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include <sync_agent.h>
29
30 #include "framework/event/oma_ds_event_handler.h"
31 #include "framework/event/oma_ds_platform_event_handler.h"
32 #include "framework/task/oma_ds_engine_controller_task.h"
33 #include "common/common_define.h"
34 #include "common/common_vconf.h"
35 #include "common/common_util.h"
36
37 #ifndef OMADS_AGENT_LOG
38 #undef LOG_TAG
39 #define LOG_TAG "OMA_DS_COMMON"
40 #endif
41
42 #define NOTI_KEY        "OMADS"
43
44 static void _request_manual_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data);
45
46 static void _request_manual_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data)
47 {
48         _INNER_FUNC_ENTER;
49
50         unsigned int request_msg_id_to_cancel = 0;
51         get_manual_sync_request_id(&request_msg_id_to_cancel);
52
53         _INNER_FUNC_EXIT;
54 }
55
56 int event_callback_add_profile_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
57 {
58         _EXTERN_FUNC_ENTER;
59
60         char *profile_dir_name = NULL;
61         char *profile_name = NULL;
62         char *addr = NULL;
63         char *id = NULL;
64         char *password = NULL;
65         char *sync_mode = NULL;
66         char *sync_type = NULL;
67         char *interval = NULL;
68         int category_count;
69         int result = 0;
70         int account_id;
71
72         GList *categorys = NULL;
73         GList *iter = NULL;
74
75         sync_agent_get_event_data_param(request, &profile_dir_name);
76         sync_agent_get_event_data_param(request, &profile_name);
77         sync_agent_get_event_data_param(request, &addr);
78         sync_agent_get_event_data_param(request, &id);
79         sync_agent_get_event_data_param(request, &password);
80         sync_agent_get_event_data_param(request, &sync_mode);
81         sync_agent_get_event_data_param(request, &sync_type);
82         sync_agent_get_event_data_param(request, &interval);
83         sync_agent_get_event_data_param(request, &category_count);
84
85         /*
86            _DEBUG_INFO("request param : %s", profile_dir_name);
87            _DEBUG_INFO("request param : %s", profile_name);
88            _DEBUG_INFO("request param : %s", addr);
89            _DEBUG_INFO("request param : %s", id);
90            _DEBUG_INFO("request param : %s", password);
91            _DEBUG_INFO("request param : %s", sync_mode);
92            _DEBUG_INFO("request param : %s", sync_type);
93            _DEBUG_INFO("request param : %s", interval);
94            _DEBUG_INFO("request param : %d", category_count);
95          */
96
97         int i = 0;
98         for (; i < category_count; i++) {
99                 sync_service_s *category = (sync_service_s *) calloc(1, sizeof(sync_service_s));
100                 if (category == NULL) {
101                         _DEBUG_ERROR("category is NULL !");
102
103                         if (profile_dir_name != NULL)
104                                 free(profile_dir_name);
105
106                         if (profile_name != NULL)
107                                 free(profile_name);
108
109                         if (addr != NULL)
110                                 free(addr);
111
112                         if (id != NULL)
113                                 free(id);
114
115                         if (password != NULL)
116                                 free(password);
117
118                         if (sync_mode != NULL)
119                                 free(sync_mode);
120
121                         if (sync_type != NULL)
122                                 free(sync_type);
123
124                         if (interval != NULL)
125                                 free(interval);
126
127                         return 0;
128                 }
129
130                 sync_agent_get_event_data_param(request, &(category->service_type));
131                 sync_agent_get_event_data_param(request, &(category->enabled));
132                 sync_agent_get_event_data_param(request, &(category->src_uri));
133                 sync_agent_get_event_data_param(request, &(category->tgt_uri));
134                 sync_agent_get_event_data_param(request, &(category->id));
135                 sync_agent_get_event_data_param(request, &(category->password));
136
137                 categorys = g_list_append(categorys, category);
138
139                 /*
140                    _DEBUG_INFO("category[i]->content_type : %d", category->content_type);
141                    _DEBUG_INFO("category[i]->enabled : %d", category->enabled);
142                    _DEBUG_INFO("category[i]->srcURI : %s", category->src_uri);
143                    _DEBUG_INFO("category[i]->tgtURI : %s", category->tgt_uri);
144                    _DEBUG_INFO("category[i]->id : %s", category->id);
145                    _DEBUG_INFO("category[i]->password : %s", category->password);
146                  */
147         }
148
149         /* send to engine controller */
150         void *in_param_value_array[9] = { &profile_dir_name, &profile_name, &addr, &id, &password, &sync_mode, &sync_type, &interval, &categorys };
151         int in_param_index_array[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
152         sync_agent_ec_value_type_e in_param_value_type_array[9] = { SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT,
153                 SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT,
154                 SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT
155         };
156         unsigned int request_msg_id = 0;
157
158         unsigned int out_param_count;
159         sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN;
160         sync_agent_ec_param_param_s **param_array = NULL;
161
162         sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE, 0, 9, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
163
164         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
165         sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &account_id);
166
167         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result);
168         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &account_id);
169
170         for (iter = categorys; iter != NULL; iter = g_list_next(iter)) {
171                 sync_service_s *category = (sync_service_s *) iter->data;
172
173                 if (category != NULL)
174                         free_sync_service(category);
175         }
176
177         _EXTERN_FUNC_EXIT;
178         return 0;
179 }
180
181 int event_callback_edit_profile_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
182 {
183         _EXTERN_FUNC_ENTER;
184
185         char *profile_dir_name = NULL;
186         char *profile_name = NULL;
187         char *addr = NULL;
188         char *id = NULL;
189         char *password = NULL;
190         char *sync_mode = NULL;
191         char *sync_type = NULL;
192         char *interval = NULL;
193         int category_count;
194         int result = 0;
195
196         GList *categorys = NULL;
197         GList *iter = NULL;
198
199         sync_agent_get_event_data_param(request, &profile_dir_name);
200         if (profile_dir_name == NULL) {
201                 _DEBUG_ERROR("profile_dir_name is not defined");
202                 result = 0;
203                 goto error;
204         }
205         _DEBUG_INFO("request param : %s", profile_dir_name);
206
207         int account_id = get_account_id(profile_dir_name, false);
208
209         sync_agent_get_event_data_param(request, &profile_name);
210         sync_agent_get_event_data_param(request, &addr);
211         sync_agent_get_event_data_param(request, &id);
212         sync_agent_get_event_data_param(request, &password);
213         sync_agent_get_event_data_param(request, &sync_mode);
214         sync_agent_get_event_data_param(request, &sync_type);
215         sync_agent_get_event_data_param(request, &interval);
216         sync_agent_get_event_data_param(request, &category_count);
217
218         _DEBUG_INFO("request param : %s", profile_name);
219         _DEBUG_INFO("request param : %s", addr);
220         _DEBUG_INFO("request param : %s", id);
221         _DEBUG_INFO("request param : %s", password);
222         _DEBUG_INFO("request param : %s", sync_mode);
223         _DEBUG_INFO("request param : %s", sync_type);
224         _DEBUG_INFO("request param : %s", interval);
225         _DEBUG_INFO("request param : %d", category_count);
226
227         int i = 0;
228         for (; i < category_count; i++) {
229                 sync_service_s *category = (sync_service_s *) calloc(1, sizeof(sync_service_s));
230                 if (category == NULL) {
231                         _DEBUG_ERROR("category is NULL !");
232
233                         if (profile_dir_name != NULL)
234                                 free(profile_dir_name);
235
236                         if (profile_name != NULL)
237                                 free(profile_name);
238
239                         if (addr != NULL)
240                                 free(addr);
241
242                         if (id != NULL)
243                                 free(id);
244
245                         if (password != NULL)
246                                 free(password);
247
248                         if (sync_mode != NULL)
249                                 free(sync_mode);
250
251                         if (sync_type != NULL)
252                                 free(sync_type);
253
254                         if (interval != NULL)
255                                 free(interval);
256
257                         return 0;
258                 }
259
260                 sync_agent_get_event_data_param(request, &(category->service_type));
261                 sync_agent_get_event_data_param(request, &(category->enabled));
262                 sync_agent_get_event_data_param(request, &(category->src_uri));
263                 sync_agent_get_event_data_param(request, &(category->tgt_uri));
264                 sync_agent_get_event_data_param(request, &(category->id));
265                 sync_agent_get_event_data_param(request, &(category->password));
266
267                 categorys = g_list_append(categorys, category);
268
269                 _DEBUG_INFO("category[i]->content_type : %d", category->service_type);
270                 _DEBUG_INFO("category[i]->enabled : %d", category->enabled);
271                 _DEBUG_INFO("category[i]->srcURI : %s", category->src_uri);
272                 _DEBUG_INFO("category[i]->tgtURI : %s", category->tgt_uri);
273                 _DEBUG_INFO("category[i]->id : %s", category->id);
274                 _DEBUG_INFO("category[i]->password : %s", category->password);
275         }
276
277         /* send to engine controller */
278         void *in_param_value_array[9] = { &account_id, &profile_name, &addr, &id, &password, &sync_mode, &sync_type, &interval, &categorys };
279         int in_param_index_array[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
280         sync_agent_ec_value_type_e in_param_value_type_array[9] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT,
281                 SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT,
282                 SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT
283         };
284         unsigned int request_msg_id = 0;
285
286         unsigned int out_param_count;
287         sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN;
288         sync_agent_ec_param_param_s **param_array = NULL;
289
290         sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_EDIT_PROFILE, 0, 9, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
291
292         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
293
294  error:
295
296         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result);
297
298         for (iter = categorys; iter != NULL; iter = g_list_next(iter)) {
299                 sync_service_s *category = (sync_service_s *) iter->data;
300
301                 if (category != NULL)
302                         free_sync_service(category);
303         }
304
305         if (profile_dir_name != NULL)
306                 free(profile_dir_name);
307
308         _EXTERN_FUNC_EXIT;
309         return 0;
310 }
311
312 int event_callback_delete_profile_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
313 {
314         _EXTERN_FUNC_ENTER;
315
316         int result = 0;
317         int count;
318         sync_agent_get_event_data_param(request, &count);
319         GList *profiles = NULL;
320         int *account_id = 0;
321
322         int i;
323         char *profile = NULL;
324         for (i = 0; i < count; i++) {
325                 if (profile != NULL) {
326                         free(profile);
327                         profile = NULL;
328                 }
329
330                 sync_agent_get_event_data_param(request, &profile);
331                 if (profile == NULL) {
332                         _DEBUG_ERROR("profile is not defined");
333                         result = 0;
334                         goto error;
335                 }
336                 _DEBUG_INFO("request param : %s", profile);
337
338                 account_id = (int *)calloc(1, sizeof(int));
339                 if (account_id == NULL) {
340                         _DEBUG_ERROR("account_id is NULL");
341                         result = 0;
342                         goto error;
343                 }
344
345                 *account_id = get_account_id(profile, false);
346
347                 profiles = g_list_append(profiles, account_id);
348         }
349
350         /* send to engine controller */
351         void *in_param_value_array[1] = { &profiles };
352         int in_param_index_array[1] = { 0 };
353         sync_agent_ec_value_type_e in_param_value_type_array[1] = { SYNC_AGENT_EC_VALUE_TYPE_STRUCT };
354         unsigned int request_msg_id = 0;
355
356         unsigned int out_param_count;
357         sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN;
358         sync_agent_ec_param_param_s **param_array = NULL;
359
360         sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_DELETE_PROFILE, 0, 1, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
361
362         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
363
364  error:
365
366         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result);
367
368         if (profile != NULL)
369                 free(profile);
370
371         _EXTERN_FUNC_EXIT;
372         return 0;
373 }
374
375 int event_callback_request_sync_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
376 {
377         _EXTERN_FUNC_ENTER;
378         char *profile = NULL;
379         int result = 0;
380
381         sync_agent_get_event_data_param(request, &profile);
382         if (profile == NULL) {
383                 _DEBUG_ERROR("profile is not defined");
384                 result = 0;
385                 goto error;
386         }
387         _DEBUG_INFO("request param : %s", profile);
388
389         int account_id = get_account_id(profile, false);
390         char *sync_mode = strdup(DEFINE_SYNC_MODE_MANUAL);
391
392         void *in_param_value_array[3] = { &account_id, &sync_mode, NULL };
393         int in_param_index_array[3] = { 0, 1, 2 };
394         sync_agent_ec_value_type_e in_param_value_type_array[3] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT };
395         unsigned int request_msg_id = 0;
396         sync_agent_request_async_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0, 3, in_param_index_array, in_param_value_type_array, in_param_value_array, _request_manual_sync_task_finish_callback, NULL, (int *)&request_msg_id);
397
398         insert_request_msg_info(SYNC_MODE_MANUAL, request_msg_id);
399
400  error:
401
402         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result);
403
404         if (profile != NULL)
405                 free(profile);
406
407         _EXTERN_FUNC_EXIT;
408         return 0;
409 }
410
411 int event_callback_cancel_sync_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
412 {
413         _EXTERN_FUNC_ENTER;
414         char *profile = NULL;
415         int result = 0;
416         bool res;
417
418         sync_agent_get_event_data_param(request, &profile);
419         if (profile == NULL) {
420                 _DEBUG_ERROR("profile is not defined");
421                 result = 0;
422                 goto error;
423         }
424
425         _DEBUG_INFO("request param : %s", profile);
426
427         res = cancel_current_sync_task();
428         if (res == true)
429                 result = 1;
430         else
431                 result = 0;
432
433  error:
434
435         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result);
436
437         if (profile != NULL)
438                 free(profile);
439
440         _EXTERN_FUNC_EXIT;
441         return 0;
442 }
443
444 int event_callback_get_profile_data_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
445 {
446         _EXTERN_FUNC_ENTER;
447
448         int result = 0;
449         char *profile = NULL;
450         char *profile_name = NULL;
451         char *addr = NULL;
452         char *id = NULL;
453         char *password = NULL;
454         char *sync_mode = NULL;
455         char *sync_type = NULL;
456         char *interval = NULL;
457         int last_session_status = 0;
458         int last_session_time = 0;
459
460         sync_agent_get_event_data_param(request, &profile);
461         if (profile == NULL) {
462                 _DEBUG_ERROR("profile is not defined");
463                 result = 0;
464                 goto error;
465         }
466
467         _DEBUG_INFO("request param : %s", profile);
468
469         int account_id = get_account_id(profile, false);
470
471         int in_param_index_array[1] = { 0 };
472         void *in_param_value_array[1] = { &account_id };
473         sync_agent_ec_value_type_e in_param_value_type_array[1] = { SYNC_AGENT_EC_VALUE_TYPE_INT };
474
475         unsigned int out_param_count;
476         sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN;
477         sync_agent_ec_param_param_s **param_array = NULL;
478
479         unsigned int request_msg_id = 0;
480         sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_DATA, 0, 1, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
481
482         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
483         sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profile_name);
484         sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &addr);
485         sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id);
486         sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password);
487         sync_agent_get_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &sync_mode);
488         sync_agent_get_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &sync_type);
489         sync_agent_get_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &interval);
490         sync_agent_get_param_value(&(param_array[8]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &last_session_status);
491         sync_agent_get_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &last_session_time);
492
493  error:
494
495         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result);
496         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_name);
497         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)addr);
498         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)id);
499         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)password);
500         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_mode);
501         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_type);
502         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)interval);
503         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &last_session_status);
504         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &last_session_time);
505
506         if (profile != NULL)
507                 free(profile);
508
509         _EXTERN_FUNC_EXIT;
510         return 0;
511 }
512
513 int event_callback_get_profile_sync_category_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
514 {
515         _EXTERN_FUNC_ENTER;
516         char *profile = NULL;
517         int content_type = 0;
518         int enabled = 0;
519         char *srcURI = NULL;
520         char *tgtURI = NULL;
521         char *id = NULL;
522         char *password = NULL;
523         int result = 0;
524
525         sync_agent_get_event_data_param(request, &profile);
526         if (profile == NULL) {
527                 _DEBUG_ERROR("profile is not defined");
528                 result = 0;
529                 goto error;
530         }
531
532         sync_agent_get_event_data_param(request, &content_type);
533
534         _DEBUG_INFO("request param : %s", profile);
535         _DEBUG_INFO("request param : %d", content_type);
536
537         int account_id = get_account_id(profile, false);
538         _DEBUG_INFO(" account_id: %d", account_id);
539
540         int in_param_index_array[2] = { 0, 1 };
541         void *in_param_value_array[2] = { &account_id, &content_type };
542         sync_agent_ec_value_type_e in_param_value_type_array[2] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_INT };
543
544         unsigned int out_param_count;
545         sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN;
546         sync_agent_ec_param_param_s **param_array = NULL;
547
548         unsigned int request_msg_id = 0;
549         sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY, 0, 2, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
550
551         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
552         sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &enabled);
553         sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &srcURI);
554         sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &tgtURI);
555         sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id);
556         sync_agent_get_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password);
557
558         /*
559            _DEBUG_INFO("result = %d", result);
560            _DEBUG_INFO("enabled = %d", enabled);
561            _DEBUG_INFO("srcURI = %s", srcURI);
562            _DEBUG_INFO("tgtURI = %s", tgtURI);
563            _DEBUG_INFO("id = %s", id);
564            _DEBUG_INFO("password = %s", password);
565          */
566
567         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result);
568         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &enabled);
569         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)srcURI);
570         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)tgtURI);
571         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)id);
572         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)password);
573
574  error:
575
576         if (profile != NULL)
577                 free(profile);
578
579         _EXTERN_FUNC_EXIT;
580         return 0;
581 }
582
583 int event_callback_get_profile_last_statistics_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
584 {
585         _EXTERN_FUNC_ENTER;
586
587         char *profile = NULL;
588         int content_type = 0;
589         char *dbSynced = "NO";
590         int last_session_time = -1;
591         int server2Client_Total = 0;
592         int server2Client_NrOfAdd = 0;
593         int server2Client_NrOfDelete = 0;
594         int server2Client_NrOfReplace = 0;
595         int client2Server_Total = 0;
596         int client2Server_NrOfAdd = 0;
597         int client2Server_NrOrDelete = 0;
598         int client2Server_NrOfReplace = 0;
599         int result = 0;
600
601         sync_agent_get_event_data_param(request, &profile);
602         if (profile == NULL) {
603                 _DEBUG_ERROR("profile is not defined");
604                 result = 0;
605                 goto error;
606         }
607
608         sync_agent_get_event_data_param(request, &content_type);
609
610         _DEBUG_INFO("request param : %s", profile);
611         _DEBUG_INFO("request param : %d", content_type);
612
613         int account_id = get_account_id(profile, false);
614
615         int in_param_index_array[2] = { 0, 1 };
616         void *in_param_value_array[2] = { &account_id, &content_type };
617         sync_agent_ec_value_type_e in_param_value_type_array[2] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_INT };
618
619         unsigned int out_param_count;
620         sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN;
621         sync_agent_ec_param_param_s **param_array = NULL;
622
623         unsigned int request_msg_id = 0;
624         sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_STATISTICS, 0, 2, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
625
626         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
627         sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &dbSynced);
628         sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &last_session_time);
629         sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_Total);
630         sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfAdd);
631         sync_agent_get_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfDelete);
632         sync_agent_get_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfReplace);
633         sync_agent_get_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_Total);
634         sync_agent_get_param_value(&(param_array[8]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOfAdd);
635         sync_agent_get_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOrDelete);
636         sync_agent_get_param_value(&(param_array[10]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOfReplace);
637
638         /*
639            _DEBUG_INFO("result = %d", result);
640            _DEBUG_INFO("dbSynced = %s\n", dbSynced);
641            _DEBUG_INFO("last_session_time = %d\n", last_session_time);
642            _DEBUG_INFO("server2Client_Total = %d\n", server2Client_Total);
643            _DEBUG_INFO("server2Client_NrOfAdd = %d\n", server2Client_NrOfAdd);
644            _DEBUG_INFO("server2Client_NrOfDelete = %d\n", server2Client_NrOfDelete);
645            _DEBUG_INFO("server2Client_NrOfReplace = %d\n", server2Client_NrOfReplace);
646            _DEBUG_INFO("client2Server_Total = %d\n", client2Server_Total);
647            _DEBUG_INFO("client2Server_NrOfAdd = %d\n", client2Server_NrOfAdd);
648            _DEBUG_INFO("client2Server_NrOrDelete = %d\n", client2Server_NrOrDelete);
649            _DEBUG_INFO("client2Server_NrOfReplace = %d\n", client2Server_NrOfReplace);
650          */
651
652  error:
653
654         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result);
655         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)dbSynced);
656         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &last_session_time);
657         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &server2Client_Total);
658         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &server2Client_NrOfAdd);
659         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &server2Client_NrOfDelete);
660         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &server2Client_NrOfReplace);
661         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &client2Server_Total);
662         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &client2Server_NrOfAdd);
663         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &client2Server_NrOrDelete);
664         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &client2Server_NrOfReplace);
665
666         if (profile != NULL)
667                 free(profile);
668
669         _EXTERN_FUNC_EXIT;
670         return 0;
671 }
672
673 int event_callback_add_profile_cp_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
674 {
675         _EXTERN_FUNC_ENTER;
676
677         char *profile_name = NULL;
678         char *addr = NULL;
679         char *id = NULL;
680         char *password = NULL;
681         int category_count;
682         int result = 0;
683         int account_id;
684
685         sync_agent_get_event_data_param(request, &profile_name);
686         sync_agent_get_event_data_param(request, &addr);
687         sync_agent_get_event_data_param(request, &id);
688         sync_agent_get_event_data_param(request, &password);
689         sync_agent_get_event_data_param(request, &category_count);
690
691         /*
692            _DEBUG_INFO("request param : %s", profile_name);
693            _DEBUG_INFO("request param : %s", addr);
694            _DEBUG_INFO("request param : %s", id);
695            _DEBUG_INFO("request param : %s", password);
696            _DEBUG_INFO("request param : %d", category_count);
697          */
698
699         GList *categorys = NULL;
700         int i = 0;
701         for (; i < category_count; i++) {
702                 resource_cp_s *category = (resource_cp_s *) calloc(1, sizeof(resource_cp_s));
703                 if (category == NULL) {
704                         _DEBUG_ERROR("category is NULL !");
705
706                         if (profile_name != NULL)
707                                 free(profile_name);
708
709                         if (addr != NULL)
710                                 free(addr);
711
712                         if (id != NULL)
713                                 free(id);
714
715                         if (password != NULL)
716                                 free(password);
717
718                         return 0;
719                 }
720
721                 sync_agent_get_event_data_param(request, &(category->name));
722                 sync_agent_get_event_data_param(request, &(category->accept));
723                 sync_agent_get_event_data_param(request, &(category->id));
724                 sync_agent_get_event_data_param(request, &(category->password));
725                 sync_agent_get_event_data_param(request, &(category->auth_type));
726                 sync_agent_get_event_data_param(request, &(category->auth_data));
727
728                 categorys = g_list_append(categorys, category);
729
730                 /*
731                    _DEBUG_INFO("category[%d]->name : %s", i, category->name);
732                    _DEBUG_INFO("category[%d]->accept : %s", i, category->accept);
733                    _DEBUG_INFO("category[%d]->id : %s", i, category->id);
734                    _DEBUG_INFO("category[%d]->password : %s", i, category->password);
735                    _DEBUG_INFO("category[%d]->authType : %s", i, category->auth_type);
736                    _DEBUG_INFO("category[%d]->authData : %s\n", i, category->auth_data);
737                  */
738         }
739
740         /* send to engine controller */
741         void *in_param_value_array[5] = { &profile_name, &addr, &id, &password, &categorys };
742         int in_param_index_array[5] = { 0, 1, 2, 3, 4 };
743         sync_agent_ec_value_type_e in_param_value_type_array[5] = { SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT,
744                 SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT
745         };
746         unsigned int request_msg_id = 0;
747
748         unsigned int out_param_count;
749         sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN;
750         sync_agent_ec_param_param_s **param_array = NULL;
751
752         sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE_CP, 0, 5, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
753
754         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
755         sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &account_id);
756
757         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result);
758         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &account_id);
759
760         _EXTERN_FUNC_EXIT;
761         return 0;
762 }
763
764 int event_callback_request_calllog_sync_async(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
765 {
766         _EXTERN_FUNC_ENTER;
767         char *data = NULL;
768         int result = 0;
769
770         sync_agent_get_event_data_param(request, &data);
771         if (data == NULL) {
772                 _DEBUG_ERROR("data is NULL");
773                 result = 0;
774                 goto error;
775         }
776         _DEBUG_INFO("data = %s", data);
777
778         result = send_ip_push_sync_msg(data);
779
780  error:
781
782         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result);
783
784         _EXTERN_FUNC_EXIT;
785         return 0;
786 }
787
788 int event_callback_request_reset_all_data_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
789 {
790         _EXTERN_FUNC_ENTER;
791
792         int result;
793
794         /* 1. cancel current sync session */
795         cancel_current_sync_task();
796
797         /* 2. reset all data */
798         unsigned int request_msg_id = 0;
799         sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN;
800
801         unsigned int out_param_count;
802         sync_agent_ec_param_param_s **param_array = NULL;
803
804         sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_RESET_ALL_DATA, 0, 0, NULL, NULL, NULL, (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
805
806         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
807         _DEBUG_INFO("result = %d", result);
808
809         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result);
810
811         _EXTERN_FUNC_EXIT;
812         return 0;
813 }
814
815 int event_callback_request_get_all_profiles_data(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
816 {
817         _EXTERN_FUNC_ENTER;
818
819         int result = 0;
820         GList *profiles_data = NULL;
821         GList *profile_iter = NULL;
822         GList *category_iter = NULL;
823
824         int profile_count = 0;
825         int category_count = 0;
826         sync_agent_ds_profile_info *profile_info = NULL;
827         sync_agent_ds_service_info *category_info = NULL;
828
829         unsigned int out_param_count;
830         sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN;
831         sync_agent_ec_param_param_s **param_array = NULL;
832
833         unsigned int request_msg_id = 0;
834         sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_GET_ALL_PROFILES_DATA, 0, 0, NULL, NULL, NULL, (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
835
836         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
837         sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profiles_data);
838
839         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result);
840         _DEBUG_INFO("result = %d", result);
841
842         if (profiles_data != NULL) {
843                 profile_count = g_list_length(profiles_data);
844                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_count);
845                 _DEBUG_INFO("profile_count = %d", profile_count);
846
847                 for (profile_iter = profiles_data; profile_iter != NULL; profile_iter = g_list_next(profile_iter)) {
848                         profile_info = (sync_agent_ds_profile_info *) profile_iter->data;
849
850                         sync_agent_ds_server_info *server_info = &profile_info->server_info;
851                         sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
852
853                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
854                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
855
856                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
857                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
858                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
859
860                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_mode);
861                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_type);
862                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->interval);
863
864                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_info->last_sync_status);
865                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_info->last_sync_time);
866
867                         _DEBUG_INFO("profile_info->profile_dir_name = %s", profile_info->profile_dir_name);
868                         _DEBUG_INFO("profile_info->profile_name = %s", profile_info->profile_name);
869
870                         _DEBUG_INFO("server_info->addr = %s", server_info->addr);
871                         _DEBUG_INFO("server_info->id = %s", server_info->id);
872                         _DEBUG_INFO("server_info->password = %s", server_info->password);
873
874                         _DEBUG_INFO("sync_info->sync_mode = %s", sync_info->sync_mode);
875                         _DEBUG_INFO("sync_info->sync_type = %s", sync_info->sync_type);
876                         _DEBUG_INFO("sync_info->interval = %s", sync_info->interval);
877
878                         _DEBUG_INFO("profile_info->last_sync_status = %d", profile_info->last_sync_status);
879                         _DEBUG_INFO("profile_info->last_sync_time = %d", profile_info->last_sync_time);
880
881                         category_count = g_list_length(profile_info->service_list);
882                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
883
884                         _DEBUG_INFO("category_count = %d", category_count);
885
886                         for (category_iter = profile_info->service_list; category_iter != NULL; category_iter = g_list_next(category_iter)) {
887                                 category_info = (sync_agent_ds_service_info *) category_iter->data;
888
889                                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_info->service_type);
890                                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_info->enabled);
891                                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->src_uri);
892                                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
893                                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
894                                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
895
896                                 _DEBUG_INFO("category_info->service_type = %d", category_info->service_type);
897                                 _DEBUG_INFO("category_info->enabled = %d", category_info->enabled);
898                                 _DEBUG_INFO("category_info->src_uri = %s", category_info->src_uri);
899                                 _DEBUG_INFO("category_info->tgt_uri = %s", category_info->tgt_uri);
900                                 _DEBUG_INFO("category_info->id = %s", category_info->id);
901                                 _DEBUG_INFO("category_info->password = %s", category_info->password);
902                         }
903                 }
904         }
905
906         _EXTERN_FUNC_EXIT;
907         return 0;
908 }