Initialize Tizen 2.3
[framework/system/oma-dm-agent.git] / src / agent / framework / platform-event-handler / dm_platform_event_handler.c
1 /*
2  * oma-dm-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 /*lib*/
19 #include <sys/socket.h>
20 #include <sys/un.h>
21 #include <fcntl.h>
22 #include <unistd.h>
23 #include <vconf.h>
24
25 /*sync-agent*/
26 #include <sync_agent.h>
27 #include <plugin/plugin_slp_sysnoti_wap_push.h>
28
29 /*common*/
30 #include "common/dm_common_def.h"
31 #include "common/dm_common.h"
32 #include "common/util/util.h"
33 #include "framework/task/oma_dm_task_request.h"
34 #include "framework/platform-event-handler/dm_platform_event_handler.h"
35 #include "framework/san-parser/pm_sanparser.h"
36 #include "dm-engine/fumo/fumo_account.h"
37 #include "dm-engine/fumo/fumo_engine.h"
38 #include "dm-engine/lawmo/lawmo_account.h"
39 #include "dm-engine/lawmo/lawmo_engine.h"
40 #include "dm-engine/cp/dm_cp_processor.h"
41 #include "dm-engine/cp/dm_cp_security.h"
42 #include "mo-handler/dm_mo_common.h"
43
44 #ifndef OMADM_AGENT_LOG
45 #undef LOG_TAG
46 #define LOG_TAG "OMA_DM_CP_PEH"
47 #endif
48
49 static DM_ERROR _fumo_interval_alarm(int item_id);
50 static DM_ERROR _fumo_account_registration_alarm(int item_id);
51 static DM_ERROR _lawmo_account_registration_alarm(int item_id);
52 //static DM_ERROR _fota_polling_alarm(int item_id);
53 //static DM_ERROR _lawmo_mobile_tracking_start(int item_id);
54 static DM_ERROR _send_event_ds(char *event_msg);
55 static int _dm_notification_operation(const char *out_message, unsigned int outlen);
56
57 static int _dm_notification_operation(const char *out_message, unsigned int outlen)
58 {
59         _INNER_FUNC_ENTER;
60
61         DM_ERROR ret = DM_OK;
62
63         retvm_if((out_message) == NULL, COMMON_ERR_IS_NULL, "out_message is NULL!!");
64         _DEBUG_INFO("out_message %d [%s]", outlen, out_message);
65
66         SanPackage *pSanPackage = NULL;
67         Event_Contents *ev_data = NULL;
68         int is_exist = 0;
69         pSanPackage = sanpackage_noti_parser((char *)out_message, outlen);
70         if (pSanPackage != NULL) {
71                 ev_data = (Event_Contents *) calloc(1, sizeof(Event_Contents));
72                 if (ev_data == NULL) {
73                         _DEBUG_TRACE("calloc failed !!");
74                         free_sanpackageparser(pSanPackage);
75                         return COMMON_ERR_ALLOC;
76                 }
77                 ev_data->type = IP_PUSH_EVENT;
78                 if ((pSanPackage->sessionID) == NULL || (pSanPackage->serverID) == NULL) {
79                         _DEBUG_TRACE("san message null");
80                         goto error;
81                 }
82                 ev_data->session_id = strdup((char *)pSanPackage->sessionID);
83                 ev_data->server_id = strdup((char *)pSanPackage->serverID);
84                 ev_data->noti_type = pSanPackage->uiMode;
85
86                 _DEBUG_TRACE("event type ip push : %d", ev_data->type);
87                 _DEBUG_TRACE("session id : %s", ev_data->session_id);
88                 _DEBUG_TRACE("server id : %s", ev_data->server_id);
89                 _DEBUG_TRACE("noti type : %d", ev_data->noti_type);
90
91                 /* UI CONFIRM */
92                 SERVICE_SERVER_TYPE engine_type;
93                 engine_type = get_service_engine_type(ev_data->server_id);
94                 _DEBUG_TRACE("engine type : %d", engine_type);
95
96                 switch (engine_type) {
97                 case SAMSUNG_FUMO_TYPE:
98                         {
99                                 /*
100                                  * check samsung dm acc
101                                  */
102                                 ret = is_exist_dmacc(SAMSUNG_FUMO_TYPE, &is_exist);
103                                 if (ret != DM_OK || is_exist == 0) {
104                                         _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
105                                         goto error;
106                                 }
107
108                                 ret = fumo_service_start(ev_data);
109                                 if (ret != DM_OK)
110                                         goto error;
111                         }
112                         break;
113                 case GCF_TYPE:
114                         {
115                                 /*
116                                  * check gcf dm acc
117                                  */
118                                 ret = is_exist_dmacc(GCF_TYPE, &is_exist);
119                                 if (ret != DM_OK || is_exist == 0) {
120                                         _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
121                                         goto error;
122                                 }
123
124                                 ret = fumo_service_start(ev_data);
125                                 if (ret != DM_OK)
126                                         goto error;
127                         }
128                         break;
129                 case SAMSUNG_FMM_TYPE:
130                         {
131
132                                 /*
133                                  * check gcf dm acc
134                                  */
135                                 ret = is_exist_dmacc(SAMSUNG_FMM_TYPE, &is_exist);
136                                 if (ret != DM_OK || is_exist == 0) {
137                                         _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
138                                         goto error;
139                                 }
140
141                                 ret = dm_lawmo_common_task_request(ev_data);
142                                 if (ret != DM_OK)
143                                         goto error;
144
145                         }
146                         break;
147                 default:
148                         _DEBUG_TRACE("dm non engine ", ret);
149                         break;
150                 }
151
152         } else {
153                 _DEBUG_TRACE("san message null");
154                 goto error;
155         }
156
157         free_sanpackageparser(pSanPackage);
158         _INNER_FUNC_EXIT;
159         return 1;
160
161  error:
162         if(ev_data != NULL) {
163                 event_data_free((void *)ev_data);
164         }
165         free_sanpackageparser(pSanPackage);
166         _INNER_FUNC_EXIT;
167         _DEBUG_INFO("end error");
168         return 0;
169 }
170
171 int dm_wap_push_incomming_callback(int item_id, void *user_data)
172 {
173         _EXTERN_FUNC_ENTER;
174
175         DM_ERROR ret = DM_OK;
176
177         retvm_if((user_data) == NULL, -1, "user_data is NULL!!");
178
179         pmci_san_incoming_s *incomming_struct = (pmci_san_incoming_s *) user_data;
180         if (incomming_struct != NULL) {
181                 /* db open */
182                 int db_ret = 0;
183                 db_ret = sync_agent_open_agent();
184                 _DEBUG_INFO("OPEN DACI : %d", db_ret);
185
186                 /* generate ext_id */
187                 int ext_id = -1;
188                 char **ext_id_list = NULL;
189                 while (1) {
190                         ext_id_list = sync_agent_generate_item_luid(1, 1);
191                         if (ext_id_list == NULL) {
192                                 ret = -1;
193                                 return ret;
194                         }
195                         ext_id = atoi(ext_id_list[0]);
196                         _DEBUG_INFO("ext_id : %d", ext_id);
197
198                         /* create folder for generated ext_id */
199                         char folder_name[50] = { 0, };
200                         snprintf(folder_name, sizeof(folder_name), "%s/%d", CP_DATA_REPOSITORY_PATH, ext_id);
201                         _DEBUG_INFO("folder name : %s", folder_name);
202
203                         int folder_ret = sync_agent_create_directory(folder_name);
204                         if (folder_ret != 1) {
205                                 _DEBUG_INFO("sync_agent_create_directory( ext_id : %d ) failed !!", ext_id);
206                                 _DEBUG_INFO("retry sync_agent_generate_item_luid() !!");
207 //                              return DM_ERR_UNKNOWN;
208                                 if (ext_id_list[0] != NULL)
209                                         free(ext_id_list[0]);
210
211                                 if (ext_id_list != NULL)
212                                         free(ext_id_list);
213
214                                 ext_id = -1;
215                                 ext_id_list = NULL;
216                         } else {
217                                 _DEBUG_INFO("sync_agent_create_directory( ext_id : %d ) success !!", ext_id);
218                                 if (ext_id_list[0] != NULL)
219                                         free(ext_id_list[0]);
220
221                                 if (ext_id_list != NULL)
222                                         free(ext_id_list);
223
224                                 break;
225                         }
226                 }
227
228                 db_ret = sync_agent_close_agent();
229                 _DEBUG_INFO("CLOSE DACI : %d", db_ret);
230
231                 //              switch( version )
232                 switch (incomming_struct->version) {
233                 case 13:        /*SAN_DM_XML  = 13 */
234                         {
235                                 /*pSanPackage = sanPackage11Parser( msgBody, msgSize ) ; */
236                         }
237                         break;
238                 case 14:        /*SAN_DM_WBXML  = 14 */
239                         {
240                                 /*pSanPackage = sanPackage12Parser( msgBody, msgSize ) ; */
241                         }
242                         break;
243                 case 15:        /*SAN_DM_NOTI  = 15 */
244                         {
245                                 int result = _dm_notification_operation(incomming_struct->msg_body, incomming_struct->msg_size);
246                                 _DEBUG_INFO("wap push parser : %d", result);
247                         }
248                         break;
249                 case 16:        /*SAN_CP_XML = 16 */
250                         {
251                                 //                      CP_ERROR result = process_Recieved_CP_XML(msgBody, msgSize);
252                                 CP_ERROR result = process_Recieved_CP_XML(incomming_struct->msg_body, incomming_struct->msg_size, ext_id);
253                                 _DEBUG_INFO("xml cp parser : %d", result);
254                         }
255                         break;
256                 case 17:        /*SAN_CP_WBXML = 17 */
257                         {
258                                 //                      CP_ERROR result = process_Recieved_CP_WBXML(msgBody, msgSize);
259                                 CP_ERROR result = process_Recieved_CP_WBXML(incomming_struct->msg_body, incomming_struct->msg_size, ext_id);
260                                 _DEBUG_INFO("wxml cp parser : %d", result);
261                         }
262                         break;
263                 default:
264                         break;
265                 }
266         }
267
268         _DEBUG_INFO("end");
269
270         if (ret == DM_OK)
271                 ret = 1;
272
273         _EXTERN_FUNC_EXIT;
274         return ret;
275 }
276
277 int dm_wap_push_operation_callback(int item_id, void *user_data)
278 {
279         _EXTERN_FUNC_ENTER;
280
281         DM_ERROR ret = DM_OK;
282
283         retvm_if((user_data) == NULL, -1, "user_data is NULL!!");
284
285         CP_ERROR err = CP_ERROR_SUCCESS;
286
287         pmci_san_operation_s *operation_struct = (pmci_san_operation_s *) user_data;
288         if (operation_struct != NULL) {
289
290                 process_Set_msgId(operation_struct->msg_id);
291                 _DEBUG_INFO("msg id : %d", operation_struct->msg_id);
292                 _DEBUG_INFO("ext id : %d", operation_struct->ext_id);
293
294                 if (operation_struct->msg_id == -1 && operation_struct->ext_id == -1) { // delete all
295                         _DEBUG_INFO("operation : delete all !!");
296
297                         err = process_Delete_All_CP_Data();
298                         if (err != CP_ERROR_SUCCESS) {
299                                 _DEBUG_INFO("process_Delete_All_CP_Data() fail !!");
300                                 //                              ret =   DM_ERR_CP
301                                 goto return_part;
302                         } else {
303                                 _DEBUG_INFO("process_Delete_All_CP_Data() success !!");
304                         }
305                 } else if (operation_struct->msg_id == -1 && operation_struct->ext_id != -1) {  // delete 1 msg
306                         _DEBUG_INFO("operation : delete 1 msg !!");
307
308                         err = process_Delete_CP_Data(operation_struct->ext_id);
309                         if (err != CP_ERROR_SUCCESS) {
310                                 _DEBUG_INFO("process_Delete_CP_Data() fail !!");
311                                 //                              ret =   DM_ERR_CP
312                                 goto return_part;
313                         } else {
314                                 _DEBUG_INFO("process_Delete_CP_Data() success !!");
315                         }
316                 } else {        // install
317                         _DEBUG_INFO("operation : install !!");
318
319                         int is_correct = -1;
320                         err = process_Check_Pincode(1, NULL, &is_correct, operation_struct->ext_id);
321                         if (err != CP_ERROR_SUCCESS) {
322                                 _DEBUG_INFO("process_Check_Pincode() fail !!");
323                                 //                              ret =   DM_ERR_CP
324                                 goto return_part;
325                         } else {
326                                 _DEBUG_INFO("process_Check_Pincode() success !!");
327
328                                 /* process_Setting_CP() */
329                                 if (is_correct == 1) {
330                                         _DEBUG_INFO("NETWPIN case - Valid PIN !!");
331
332                                         err = process_Setting_CP(operation_struct->ext_id);
333                                         if (err != CP_ERROR_SUCCESS) {
334                                                 _DEBUG_INFO("process_Setting_CP() fail !!");
335                                                 goto return_part;
336                                         } else {
337                                                 _DEBUG_INFO("process_Setting_CP() success !!");
338                                         }
339                                 } else if (is_correct == 0) {
340                                         _DEBUG_INFO("NETWPIN case - Invalid PIN !!");
341                                         err = CP_ERROR_FAIL;
342                                 }
343                         }
344                 }
345         }
346
347  return_part:
348         if (operation_struct != NULL)
349                 free(operation_struct);
350
351         if (ret == DM_OK)
352                 ret = 1;
353
354         _EXTERN_FUNC_EXIT;
355         return ret;
356 }
357
358 int dm_ip_push_callback(int item_id, void *user_data)
359 {
360         _EXTERN_FUNC_ENTER;
361
362         DM_ERROR ret = DM_OK;
363
364         retvm_if((user_data) == NULL, -1, "user_data is NULL!!");
365
366         OPER_MODE operationMode;
367         operationMode = OPER_SERVER_INITIATION_FROM_IP;
368         char *pushmessage = NULL;
369         //ip_push_struct->message = strdup("IPP_20111216000000000000000001|DM|Ft4/CLTiWx/Y0AK+fBIayALoAAAAlPcKeDZnMXExNHI3NQ==");
370
371         pushmessage = strdup((char *)user_data);
372         retvm_if((pushmessage) == NULL, -1, "pushmessage is NULL!!");
373
374         _DEBUG_INFO("user_data : %s", (char *)user_data);
375         _DEBUG_INFO("push contents : %s", pushmessage);
376
377         if (pushmessage != NULL) {
378                 char *app_type = strchr(pushmessage, '|') + 1;
379                 char *message = NULL;
380                 message = strstr(app_type, "DS|");
381
382                 if (message != NULL) {
383                         _DEBUG_INFO("DS event : %s", message);
384                         ret = _send_event_ds(message);
385                         //_EXTERN_FUNC_EXIT;
386                         //return ret;
387                         goto error;
388                 }
389
390                 message = strchr(app_type, '|') + 1;
391                 _DEBUG_INFO("message :%s", message);
392
393                 unsigned int outlen = 0;
394                 unsigned char *out_message = g_base64_decode(message, &outlen);
395
396                 int result = _dm_notification_operation((const char *)out_message, outlen);
397                 _DEBUG_INFO("ip push parser : %d", result);
398
399         } else {
400                 _DEBUG_INFO("push message null");
401                 //do nothing
402                 goto error;
403         }
404
405         str_free(&pushmessage);
406
407         if (ret == DM_OK) {
408                 ret = 1;
409         }
410
411         _EXTERN_FUNC_EXIT;
412
413         return ret;
414
415  error:
416         str_free(&pushmessage);
417
418         _EXTERN_FUNC_EXIT;
419         _DEBUG_INFO("end error ");
420         return ret;
421
422 }
423
424 int dm_telephony_incomming_callback(int item_id, void *user_data)
425 {
426         _EXTERN_FUNC_ENTER;
427
428         _DEBUG_INFO("----------------------------------------------------incomming tel----------------------------------------------------");
429
430         DM_ERROR ret = DM_OK;
431         int is_exist = 0;
432         engine_status *status = NULL;
433
434         /*ret =  DB_Open();
435            _DEBUG_INFO("dm db open = %d", ret); */
436
437         is_exist = IsExist_Engine_id(FUMO_SERVICE_ENGINE);
438         _DEBUG_INFO("is engine : %d", is_exist);
439
440         if (is_exist != 0) {
441                 ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
442                 if (ret != DM_OK)
443                         goto error;
444
445                 if (status != NULL) {
446                         if (status->ui_mode != NULL) {
447                                 if (strcmp(status->ui_mode, OMADM_FUMO_BACKGROUND_UI_TYPE) != 0) {
448
449                                         if (status->engine_status == DM_SERVICE_ING || status->engine_status == DM_SERVICE_UNKNOWN) {
450                                                 _DEBUG_INFO("cancel fumo task id  = %d ", status->task_id);
451                                                 cancel_task(status->task_id);
452                                                 _DEBUG_INFO("terminate ui");
453                                                 terminate_oma_dm_ui(DM_ERR_NOT_FOUND, FUMO_SERVICE_ENGINE);
454                                         } else {
455                                                 /*do nothing */
456                                         }
457                                 } else {
458                                         /*do nothing */
459                                         _DEBUG_INFO("back ground ui");
460                                 }
461                         } else {
462                                 /*do nothing */
463                         }
464                 } else {
465                         /*do nothing */
466                 }
467         } else {
468                 /*do nothing */
469         }
470         /*sleep(1);
471            DB_Close(); */
472         if (status != NULL) {
473                 Free_Memory_Engine_Status(&status, 1);
474         }
475
476         if (ret == DM_OK) {
477                 ret = 1;
478         }
479
480         _EXTERN_FUNC_EXIT;
481         return 1;
482  error:
483         /*sleep(1);
484            DB_Close(); */
485         if (status != NULL) {
486                 Free_Memory_Engine_Status(&status, 1);
487         }
488         _DEBUG_INFO("ERROR END = %d", ret);
489
490         _EXTERN_FUNC_EXIT;
491         return ret;
492 }
493
494 int dm_telephony_end_callback(int item_id, void *user_data)
495 {
496         _EXTERN_FUNC_ENTER;
497
498         _DEBUG_INFO("----------------------------------------------------end tel----------------------------------------------------");
499
500         DM_ERROR ret = DM_OK;
501         sync_agent_da_return_e err = SYNC_AGENT_DA_SUCCESS;
502
503         engine_status *status = NULL;
504         int is_exist = 0;
505         int is_alarm = 0;
506         char *server_id = NULL;
507
508         /*ret =  DB_Open();
509            _DEBUG_INFO("dm db open = %d", ret);
510          */
511         err = sync_agent_open_agent();
512         _DEBUG_INFO("sync agent db open = %d", ret);
513
514         is_exist = IsExist_Engine_id(FUMO_SERVICE_ENGINE);
515         _DEBUG_INFO("is engine : %d", is_exist);
516         if (is_exist == 0) {
517                 sleep(1);
518                 //DB_Close();
519                 _EXTERN_FUNC_EXIT;
520                 return 1;
521         }
522
523         ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
524         if (ret != DM_OK) {
525                 sleep(1);
526                 //DB_Close();
527                 _DEBUG_INFO("sync agent db close = %d", ret);
528
529                 if(status != NULL) {
530                         Free_Memory_Engine_Status(&status, 1);
531                 }
532
533                 _EXTERN_FUNC_EXIT;
534                 return 1;
535         }
536
537         if (status != NULL && status->ui_mode != NULL) {
538                 if (!strcmp(status->ui_mode, OMADM_FUMO_BACKGROUND_UI_TYPE)) {
539
540                         is_alarm = check_existed_fumo_reminder_interval();
541                         if (is_alarm == 1) {
542                                 _DEBUG_INFO("have alarm");
543                         } else {
544                                 sleep(5);
545
546                                 ret = get_Serverid(SAMSUNG_FUMO_TYPE, &server_id);
547                                 if (ret != DM_OK) {
548                                         sleep(1);
549                                         //DB_Close();
550                                         err = sync_agent_close_agent();
551                                         _DEBUG_INFO("sync agent db close = %d", ret);
552                                         Free_Memory_Engine_Status(&status, 1);
553                                         _EXTERN_FUNC_EXIT;
554                                         return 1;
555                                 }
556
557                                 if (server_id != NULL) {
558                                         //current time > alarm time
559                                         Event_Contents *ev_data = (Event_Contents *) calloc(1, sizeof(Event_Contents));
560                                         ev_data->type = UI_EVENT;
561                                         ev_data->session_id = NULL;
562                                         ev_data->server_id = server_id;
563                                         ev_data->noti_type = NOTI_TYPE_USERINTERACTION;
564                                         ev_data->ui_mode = strdup(OMADM_FUMO_NOTI_UI_TYPE);
565
566                                         ret = dm_fumo_common_task_request(ev_data);
567                                         if (ret != DM_OK) {
568                                                 //DB_Close();
569                                                 err = sync_agent_close_agent();
570                                                 _DEBUG_INFO("sync agent db close = %d", ret);
571                                                 Free_Memory_Engine_Status(&status, 1);
572                                                 _EXTERN_FUNC_EXIT;
573                                                 return 1;
574                                         }
575                                 } else {
576                                         _DEBUG_INFO("server id is null");
577                                 }
578                         }
579                 }
580         }
581
582         if (ret == DM_OK) {
583                 ret = 1;
584         }
585
586         sleep(1);
587         //DB_Close();
588         err = sync_agent_close_agent();
589         _DEBUG_INFO("sync agent db close = %d", ret);
590         Free_Memory_Engine_Status(&status, 1);
591
592         _EXTERN_FUNC_EXIT;
593         return 1;
594 }
595
596 int network_on_callback()
597 {
598         _EXTERN_FUNC_ENTER;
599         _DEBUG_INFO("network on");
600         _EXTERN_FUNC_EXIT;
601         return 1;
602 }
603
604 int network_off_callback()
605 {
606         _EXTERN_FUNC_ENTER;
607         _DEBUG_INFO("network off");
608         _EXTERN_FUNC_EXIT;
609         return 1;
610 }
611
612 int network_change_callback()
613 {
614         _EXTERN_FUNC_ENTER;
615
616         int ret = 0;
617         _DEBUG_INFO("changed network");
618
619         ret = 1;
620 /*for prevent*/
621 /*
622  * int config = 0;
623
624         //each company's
625          //check alarm
626
627         if(config == 0) {
628                 _DEBUG_INFO("wifi only off mode download");
629         } else if (config == 1) {
630                 ret = get_wifi_state();
631                 _DEBUG_INFO("wifi only mode : %d", ret);
632                 if (ret != SYNC_AGENT_NA_SUCCESS) {
633                         return 0;
634                 }
635
636                 ret = auto_operate_service_engine();
637                 if(ret !=DM_OK ) {
638                         _DEBUG_INFO("error : %d", ret);
639                         return 0;
640                 }
641         }*/
642
643         _EXTERN_FUNC_EXIT;
644         return ret;
645 }
646
647 int alarm_callback(int item_id, void *user_data)
648 {
649         _EXTERN_FUNC_ENTER;
650         _DEBUG_INFO("#######Scheduler Send Msg Success!!!!!########## : %d", item_id);
651
652         DM_ERROR ret = DM_OK;
653         int value = -1;
654         int count = 0;
655
656         int exist = 0;
657         sync_agent_da_return_e result = SYNC_AGENT_DA_SUCCESS;
658         sync_agent_da_config_s *config = NULL;
659         GList *list = NULL;
660
661         int db_ret = 0;
662         db_ret = sync_agent_open_agent();
663
664         result = sync_agent_is_exist_config(FUMO_INTERVAL_TYPE, FUMO_INTERVAL, &exist);
665         if (result != SYNC_AGENT_DA_SUCCESS) {
666                 _EXTERN_FUNC_EXIT;
667                 return -1;
668         }
669
670         _DEBUG_INFO("exist : %d", exist);
671
672         if (exist != 0) {
673                 result = sync_agent_get_config_list(FUMO_INTERVAL_TYPE, &list);
674                 count = g_list_length(list);
675                 _DEBUG_INFO("count : %d", count);
676                 if (count != 0 && list != NULL) {
677                         config = (sync_agent_da_config_s *) g_list_nth_data(list, 0);
678                         if (chartoint(config->value, &value) == 1) {
679                                 if (value == item_id) {
680                                         ret = _fumo_interval_alarm(item_id);
681                                         if (ret != DM_OK) {
682                                                 sync_agent_free_config_list(list);
683                                                 _EXTERN_FUNC_EXIT;
684                                                 return -1;
685                                         }
686                                 }
687                         }
688                 }
689                 count = 0;
690                 value = -1;
691                 sync_agent_free_config_list(list);
692                 list = NULL;
693         } else {
694
695                 result = sync_agent_remove_service_data(1, item_id);
696                 _DEBUG_INFO("delete alarm %d", result);
697
698         }
699
700         result = sync_agent_is_exist_config(FUMO_ACCOUNT_ALARM_TYPE, FUMO_ACCOUNT_ALARM, &exist);
701         if (result != SYNC_AGENT_DA_SUCCESS) {
702                 _EXTERN_FUNC_EXIT;
703                 return -1;
704         }
705
706         _DEBUG_INFO("exist : %d", exist);
707
708         if (exist != 0) {
709                 result = sync_agent_get_config_list(FUMO_ACCOUNT_ALARM_TYPE, &list);
710                 count = g_list_length(list);
711                 _DEBUG_INFO("count : %d", count);
712                 if (count != 0 && list != NULL) {
713                         config = (sync_agent_da_config_s *) g_list_nth_data(list, 0);
714                         if (chartoint(config->value, &value) == 1) {
715                                 if (value == item_id) {
716                                         ret = _fumo_account_registration_alarm(item_id);
717                                         if (ret != DM_OK) {
718                                                 sync_agent_free_config_list(list);
719                                                 _EXTERN_FUNC_EXIT;
720                                                 return -1;
721                                         }
722                                 }
723                         }
724                 }
725                 count = 0;
726                 value = -1;
727                 sync_agent_free_config_list(list);
728                 list = NULL;
729         }
730
731         result = sync_agent_is_exist_config(LAWMO_ACCOUNT_ALARM_TYPE, LAWMO_ACCOUNT_ALARM, &exist);
732         if (result != SYNC_AGENT_DA_SUCCESS) {
733                 _EXTERN_FUNC_EXIT;
734                 return -1;
735         }
736
737         _DEBUG_INFO("exist : %d", exist);
738
739         if (exist != 0) {
740                 result = sync_agent_get_config_list(LAWMO_ACCOUNT_ALARM_TYPE, &list);
741                 count = g_list_length(list);
742                 _DEBUG_INFO("count : %d", count);
743                 if (count != 0 && list != NULL) {
744                         config = (sync_agent_da_config_s *) g_list_nth_data(list, 0);
745                         if (chartoint(config->value, &value) == 1) {
746                                 if (value == item_id) {
747                                         ret = _lawmo_account_registration_alarm(item_id);
748                                         if (ret != DM_OK) {
749                                                 sync_agent_free_config_list(list);
750                                                 _EXTERN_FUNC_EXIT;
751                                                 return -1;
752                                         }
753                                 }
754                         }
755                 }
756                 count = 0;
757                 value = -1;
758                 sync_agent_free_config_list(list);
759                 list = NULL;
760         }
761
762         db_ret = sync_agent_close_agent();
763         _DEBUG_INFO("CLOSE DACI : %d", db_ret);
764
765         _EXTERN_FUNC_EXIT;
766         return 1;
767 }
768
769 static DM_ERROR _fumo_interval_alarm(int item_id)
770 {
771         _INNER_FUNC_ENTER;
772
773         DM_ERROR ret = DM_OK;
774         char *server_id = NULL;
775         engine_status *status = NULL;
776         Event_Contents *ev_data = NULL;
777         int is_exist = 0;
778
779         ret = DB_Open();
780         _DEBUG_TRACE("status db : %d", ret);
781
782         /*
783          * check samsung dm acc
784          */
785         ret = is_exist_dmacc(SAMSUNG_FUMO_TYPE, &is_exist);
786         if (ret != DM_OK || is_exist == 0) {
787                 _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
788                 goto error;
789         }
790
791         if (IsExist_Engine_id(FUMO_SERVICE_ENGINE) != 0) {
792                 ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
793                 if (ret != DM_OK)
794                         goto error;
795
796                 _DEBUG_TRACE(" result =[%d]\n", ret);
797                 /*update engine_status */
798                 if (status != NULL) {
799                         if (status->server_id != NULL) {
800                                 server_id = strdup(status->server_id);
801                         }
802
803                         status->engine_status = DM_SERVICE_ING;
804                         if (status->download_click == RESUME_STATUS_INSTALL_IDLE) {
805                                 status->download_click = RESUME_STATUS_INSTALL;
806                         } else if (status->download_click == RESUME_STATUS_DOWNLOAD_IDLE) {
807                                 status->download_click = RESUME_STATUS_DOWNLOAD;
808                         } else {
809                                 status->download_click = RESUME_STATUS_DOWNLOAD;
810                         }
811
812                         ret = Update_Engine_Status(status);
813                         _DEBUG_TRACE(" update engine status : %d \n", ret);
814
815                         DB_Close();
816
817                         Free_Memory_Engine_Status(&status, 1);
818                 }
819         } else {
820
821         }
822
823         /*************************************************/
824
825         if (server_id == NULL) {
826                 ret = get_Serverid(SAMSUNG_FUMO_TYPE, &server_id);
827                 if (ret != DM_OK || server_id == NULL)
828                         goto error;
829         }
830
831         ev_data = (Event_Contents *) calloc(1, sizeof(Event_Contents));
832         if (ev_data == NULL) {
833                 _DEBUG_TRACE("calloc failed !!");
834                 ret = COMMON_ERR_ALLOC;
835                 goto error;
836         }
837         ev_data->type = UI_EVENT;
838         ev_data->session_id = NULL;
839         ev_data->server_id = strdup(server_id);
840         ev_data->noti_type = NOTI_TYPE_USERINTERACTION;
841         ev_data->ui_mode = strdup(OMADM_FUMO_NOTI_UI_TYPE);
842
843         _DEBUG_TRACE("alarm : %s", ev_data->server_id);
844         ret = dm_fumo_common_task_request(ev_data);
845         if (ret != DM_OK) {
846                 goto error;
847         }
848
849         str_free(&server_id);
850
851         _INNER_FUNC_EXIT;
852         return ret;
853
854  error:
855         str_free(&server_id);
856         event_data_free((void *)ev_data);
857
858         DB_Close();
859         if (status != NULL)
860                 Free_Memory_Engine_Status(&status, 1);
861
862         _DEBUG_TRACE("end error : %d", ret);
863         _INNER_FUNC_EXIT;
864         return ret;
865 }
866
867 static DM_ERROR _fumo_account_registration_alarm(int item_id)
868 {
869         _INNER_FUNC_ENTER;
870
871         DM_ERROR ret = DM_OK;
872
873         ret = register_fota_account();
874         if (ret == 0) {
875                 _DEBUG_TRACE("fail register fota account : %d ", ret);
876                 ret = DM_ERR_FOTA_ACCOUNT_REGISTRATION;
877         } else {
878                 _DEBUG_TRACE("success register fota account : %d ", ret);
879         }
880
881         _INNER_FUNC_EXIT;
882         return ret;
883 }
884
885 static DM_ERROR _lawmo_account_registration_alarm(int item_id)
886 {
887         _INNER_FUNC_ENTER;
888
889         DM_ERROR ret = DM_OK;
890
891         ret = register_lawmo_account(item_id, NULL);
892         if (ret == 0) {
893                 _DEBUG_TRACE("fail register lawmo account : %d ", ret);
894                 ret = DM_ERR_LAWMO_ACCOUNT_REGISTRATION;
895         } else {
896                 _DEBUG_TRACE("success register lawmo account : %d ", ret);
897         }
898
899         _INNER_FUNC_EXIT;
900         return ret;
901 }
902 /*
903 static DM_ERROR _fota_polling_alarm(int item_id)
904 {
905         _INNER_FUNC_ENTER;
906
907         DM_ERROR ret = DM_OK;
908         _INNER_FUNC_EXIT;
909         return ret;
910 }
911 static DM_ERROR _lawmo_mobile_tracking_start(int item_id)
912 {
913         _INNER_FUNC_ENTER;
914
915         DM_ERROR ret = DM_OK;
916         _INNER_FUNC_EXIT;
917         return ret;
918 }
919 */
920 static DM_ERROR _send_event_ds(char *event_msg)
921 {
922         _INNER_FUNC_ENTER;
923
924         int client_len;
925         int client_sockfd;
926         struct sockaddr_un clientaddr;
927         int event_type = 11;
928         char *msg = NULL;
929
930         retvm_if((event_msg) == NULL, DM_ERR_EVENT_DS, "event_msg is NULL!!");
931
932         msg = strchr(event_msg, '|') + 1;
933         _DEBUG_TRACE("msg = %s", msg);
934
935         sync_agent_event_data_s *event = sync_agent_create_event(event_type);
936         if (event == NULL) {
937                 _DEBUG_TRACE("event is NULL");
938                 _INNER_FUNC_EXIT;
939                 return DM_ERR_EVENT_DS;
940         }
941
942         sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, msg);
943
944         client_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
945         if (client_sockfd == -1) {
946                 _DEBUG_TRACE("socket create Error!!");
947                 sync_agent_free_event(event);
948                 _INNER_FUNC_EXIT;
949                 return DM_ERR_EVENT_DS;
950         }
951
952         bzero(&clientaddr, sizeof(clientaddr));
953         clientaddr.sun_family = AF_UNIX;
954
955         int str_len = 0;
956
957         str_len = g_strlcpy(clientaddr.sun_path, IPC_DS, (int)sizeof(clientaddr.sun_path));
958         if (str_len >= sizeof(clientaddr.sun_path)) {
959                 _DEBUG_TRACE("buffer overflow");
960                 sync_agent_free_event(event);
961                 close(client_sockfd);
962                 _INNER_FUNC_EXIT;
963                 return CP_ERROR_FAIL;
964         }
965
966         client_len = sizeof(clientaddr);
967
968         if (connect(client_sockfd, (struct sockaddr *)&clientaddr, client_len) < 0) {
969                 _DEBUG_TRACE("socket connect error");
970                 sync_agent_free_event(event);
971                 close(client_sockfd);
972                 _INNER_FUNC_EXIT;
973                 return DM_ERR_EVENT_DS;
974         }
975
976         int send_data_size = (event->data - event->size) + 1;
977         int write_ret = write(client_sockfd, (void *)(event->size), send_data_size);
978         _DEBUG_TRACE("write ret : %d", write_ret);
979         close(client_sockfd);
980         sync_agent_free_event(event);
981
982         _INNER_FUNC_EXIT;
983         return DM_OK;
984 }
985
986 void event_data_free(void *event_data)
987 {
988         _EXTERN_FUNC_ENTER;
989
990         retm_if((event_data) == NULL, "event_data is NULL!!");
991
992         Event_Contents *pEvent_data = (Event_Contents *) event_data;
993
994         pEvent_data->type = 0;
995         pEvent_data->noti_type = 0;
996         str_free(&(pEvent_data->server_id));
997         str_free(&(pEvent_data->session_id));
998         str_free(&(pEvent_data->ui_mode));
999
1000         free(pEvent_data);
1001
1002         _EXTERN_FUNC_EXIT;
1003 }