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