Fix issue : fail to make thumbnail
[platform/core/messaging/msg-service.git] / plugin / sms_cdma_plugin / SmsCdmaPluginEventHandler.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <errno.h>
20 #include <time.h>
21
22 #include <aul.h>
23 #include <bundle.h>
24 #include <eventsystem.h>
25
26 #include "MsgDebug.h"
27 #include "MsgUtilFile.h"
28 #include "MsgUtilFunction.h"
29 #include "MsgUtilStorage.h"
30 #include "MsgCppTypes.h"
31 #include "MsgContact.h"
32 #include "MsgGconfWrapper.h"
33 #include "MsgNotificationWrapper.h"
34
35 #include "SmsCdmaPluginTransport.h"
36 #include "SmsCdmaPluginStorage.h"
37 #include "SmsCdmaPluginSetting.h"
38 #include "SmsCdmaPluginEventHandler.h"
39 #include "SmsCdmaPluginWapPushHandler.h"
40
41
42
43 SmsPluginEventHandler* SmsPluginEventHandler::pInstance = NULL;
44
45
46 SmsPluginEventHandler::SmsPluginEventHandler()
47 {
48         /*  Initialize global parameters */
49         memset(&listener, 0x00, sizeof(MSG_PLUGIN_LISTENER_S));
50         memset(&sentInfo, 0x00, sizeof(sms_sent_info_s));
51         devStatus = false;
52 }
53
54
55 SmsPluginEventHandler::~SmsPluginEventHandler()
56 {
57 }
58
59
60 SmsPluginEventHandler* SmsPluginEventHandler::instance()
61 {
62         if (!pInstance)
63                 pInstance = new SmsPluginEventHandler();
64
65         return pInstance;
66 }
67
68
69 void SmsPluginEventHandler::registerListener(MSG_PLUGIN_LISTENER_S *pListener)
70 {
71         listener = *pListener;
72 }
73
74
75 void SmsPluginEventHandler::convertTpduToMsginfo(sms_trans_p2p_msg_s *p_p2p_msg, MSG_MESSAGE_INFO_S *p_msg_info)
76 {
77         MSG_BEGIN();
78
79         /* Address */
80         if (p_p2p_msg->telesvc_msg.data.deliver.callback_number.szData[0] != '\0')
81                 p_msg_info->nAddressCnt = 2;
82         else
83                 p_msg_info->nAddressCnt = 1;
84
85         p_msg_info->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * p_msg_info->nAddressCnt];
86
87         if (p_msg_info->addressList) {
88                 switch (p_msg_info->nAddressCnt) {
89                 case 2:
90                         memset(p_msg_info->addressList[1].addressVal, 0x00, MAX_ADDRESS_VAL_LEN+1);
91                 case 1:
92                         memset(p_msg_info->addressList[0].addressVal, 0x00, MAX_ADDRESS_VAL_LEN+1);
93                         break;
94                 default:
95                         MSG_ERR("Invalid case");
96                         memset(p_msg_info->addressList[0].addressVal, 0x00, MAX_ADDRESS_VAL_LEN+1);
97                 }
98         }
99
100         if (p_p2p_msg->address.szData[0] != '\0') {
101                 p_msg_info->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
102                 memcpy(p_msg_info->addressList[0].addressVal, p_p2p_msg->address.szData, MAX_ADDRESS_VAL_LEN);
103                 p_msg_info->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_TO;
104         }
105
106
107         /* Teleservice message */
108         switch (p_p2p_msg->telesvc_msg.type) {
109         case SMS_TYPE_DELIVER:
110         p_msg_info->msgType.subType = MSG_NORMAL_SMS;
111         p_msg_info->folderId = MSG_INBOX_ID;
112
113         convertDeliverMsgToMsgInfo(&(p_p2p_msg->telesvc_msg.data.deliver), p_msg_info);
114         break;
115         case SMS_TYPE_DELIVERY_ACK:
116                 convertAckMsgToMsgInfo(&(p_p2p_msg->telesvc_msg.data.delivery_ack), p_msg_info);
117                 break;
118         case SMS_TYPE_SUBMIT_REPORT:
119                 convertReportMsgToMsgInfo(&(p_p2p_msg->telesvc_msg.data.report), p_msg_info);
120                 break;
121         default:
122                 MSG_DEBUG("No matching type = [%d]", p_p2p_msg->telesvc_msg.type);
123                 break;
124         }
125
126         MSG_END();
127 }
128
129
130 void SmsPluginEventHandler::convertTpduToMsginfo(sms_trans_broadcast_msg_s *p_cb_msg, MSG_MESSAGE_INFO_S *p_msg_info)
131 {
132         MSG_BEGIN();
133
134         /* Address */
135         p_msg_info->nAddressCnt = 0;
136         p_msg_info->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
137
138         if (p_msg_info->addressList) {
139                 memset(p_msg_info->addressList[0].addressVal, 0x00, MAX_ADDRESS_VAL_LEN+1);
140         }
141
142         /* Bearer Data */
143         if (p_cb_msg->telesvc_msg.type == SMS_TYPE_DELIVER) {
144                 p_msg_info->msgType.subType = MSG_CB_SMS;
145                 p_msg_info->folderId = MSG_CBMSGBOX_ID;
146
147                 if (p_cb_msg->svc_ctg >= SMS_TRANS_SVC_CTG_CMAS_PRESIDENTIAL && p_cb_msg->svc_ctg <= SMS_TRANS_SVC_CTG_CMAS_TEST)
148                         convertCMASMsgToMsgInfo(&(p_cb_msg->telesvc_msg.data.deliver), p_msg_info);
149                 else
150                         convertDeliverMsgToMsgInfo(&(p_cb_msg->telesvc_msg.data.deliver), p_msg_info);
151         } else {
152                 MSG_DEBUG("No matching type = [%d]", p_cb_msg->telesvc_msg.type);
153         }
154
155         if (p_msg_info->nAddressCnt == 0) {
156                 p_msg_info->nAddressCnt = 1;
157                 p_msg_info->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
158                 p_msg_info->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_TO;
159
160                 if (p_cb_msg->svc_ctg == SMS_TRANS_SVC_CTG_CMAS_PRESIDENTIAL)
161                         snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "Presidential Alert");
162                 else if (p_cb_msg->svc_ctg == SMS_TRANS_SVC_CTG_CMAS_EXTREME)
163                         snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "Extreme Alert");
164                 else if (p_cb_msg->svc_ctg == SMS_TRANS_SVC_CTG_CMAS_SEVERE)
165                         snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "Severe Alert");
166                 else if (p_cb_msg->svc_ctg == SMS_TRANS_SVC_CTG_CMAS_AMBER)
167                         snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "AMBER Alert");
168                 else if (p_cb_msg->svc_ctg == SMS_TRANS_SVC_CTG_CMAS_TEST)
169                         snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "Emergency Alert");
170                 else
171                         snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "CB Message");
172         }
173
174         MSG_END();
175 }
176
177
178 void SmsPluginEventHandler::convertCMASMsgToMsgInfo(sms_telesvc_deliver_s *p_deliver, MSG_MESSAGE_INFO_S *p_msg_info)
179 {
180         MSG_BEGIN();
181
182         p_msg_info->msgType.mainType = MSG_SMS_TYPE;
183
184         p_msg_info->msgType.classType = MSG_CLASS_NONE;
185         p_msg_info->networkStatus = MSG_NETWORK_RECEIVED;
186         p_msg_info->bRead = false;
187         p_msg_info->bProtected = false;
188         p_msg_info->direction = MSG_DIRECTION_TYPE_MT;
189         p_msg_info->bTextSms = true;
190
191         if (p_deliver->callback_number.szData[0] != '\0') {
192                 /* If callback number is in received pdu, replace the address value. */
193                 memset(p_msg_info->addressList[0].addressVal, 0x00, MAX_ADDRESS_VAL_LEN+1);
194                 p_msg_info->nAddressCnt = 1;
195                 p_msg_info->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
196                 snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "%s", p_deliver->callback_number.szData);
197                 p_msg_info->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_TO;
198         }
199
200         time_t rawtime = 0;
201         p_msg_info->storageId = MSG_STORAGE_PHONE;
202
203 #if 0 /* Save Timestamp of message center. */
204                 char displayTime[32];
205                 struct tm * timeTM;
206
207                 struct tm timeinfo;
208                 memset(&timeinfo, 0x00, sizeof(tm));
209
210                 if (p_deliver->time_stamp.year > 95)
211                         timeinfo.tm_year = (p_deliver->time_stamp.year + 1900);
212                 else
213                         timeinfo.tm_year = (p_deliver->time_stamp.year + 2000);
214
215                 timeinfo.tm_mon = (p_deliver->time_stamp.month - 1);
216                 timeinfo.tm_mday = p_deliver->time_stamp.day;
217                 timeinfo.tm_hour = p_deliver->time_stamp.hour;
218                 timeinfo.tm_min = p_deliver->time_stamp.minute;
219                 timeinfo.tm_sec = p_deliver->time_stamp.second;
220                 timeinfo.tm_isdst = 0;
221
222                 rawtime = mktime(&timeinfo);
223
224                 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
225                 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
226                 MSG_DEBUG("timezone [%d]", timezone);
227                 MSG_DEBUG("daylight [%d]", daylight);
228
229                 memset(displayTime, 0x00, sizeof(displayTime));
230                 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
231                 MSG_DEBUG("displayTime [%s]", displayTime);
232
233                 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
234
235                 timeTM = localtime(&rawtime);
236                 memset(displayTime, 0x00, sizeof(displayTime));
237                 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
238                 MSG_DEBUG("displayTime [%s]", displayTime);
239
240                 rawtime -= timezone;
241
242                 timeTM = localtime(&rawtime);
243                 memset(displayTime, 0x00, sizeof(displayTime));
244                 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
245                 MSG_DEBUG("displayTime [%s]", displayTime);
246         }
247 #else
248         rawtime = time(NULL);
249 #endif
250
251         p_msg_info->displayTime = rawtime;
252
253
254         if (p_deliver->priority == SMS_PRIORITY_URGENT || p_deliver->priority == SMS_PRIORITY_EMERGENCY)
255                 p_msg_info->priority = MSG_MESSAGE_PRIORITY_HIGH;
256         else
257                 p_msg_info->priority = MSG_MESSAGE_PRIORITY_NORMAL;
258
259
260         memset(p_msg_info->subject, 0x00, MAX_SUBJECT_LEN+1);
261
262         p_msg_info->msgPort.valid = false;
263         p_msg_info->msgPort.dstPort = 0;
264         p_msg_info->msgPort.srcPort = 0;
265
266         p_msg_info->encodeType = getEncodeType(p_deliver->cmas_data.encode_type);
267
268         if (p_deliver->cmas_data.data_len <= 0) {
269                 memset(p_msg_info->msgText, 0x00, sizeof(p_msg_info->msgText));
270                 p_msg_info->dataSize = 0;
271         } else if (p_deliver->cmas_data.data_len > MAX_MSG_TEXT_LEN) {
272                 snprintf(p_msg_info->msgText, MAX_MSG_TEXT_LEN, "[Broken Message]");
273                 p_msg_info->dataSize = strlen(p_msg_info->msgData);
274                 return;
275         } else {
276                 if (p_msg_info->encodeType == MSG_ENCODE_UCS2) {
277                         MSG_DEBUG("Encode Type = UCS2");
278                         MsgTextConvert *textCvt = MsgTextConvert::instance();
279                         p_msg_info->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->cmas_data.alert_text, p_deliver->cmas_data.data_len);
280                 } else if (p_msg_info->encodeType == MSG_ENCODE_EUCKR) {
281                         MSG_DEBUG("Encode Type = EUCKR");
282                         MsgTextConvert *textCvt = MsgTextConvert::instance();
283                         p_msg_info->dataSize = textCvt->convertEUCKRToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->cmas_data.alert_text, p_deliver->cmas_data.data_len);
284                 } else if (p_msg_info->encodeType == MSG_ENCODE_SHIFT_JIS) {
285                         MSG_DEBUG("Encode Type = Shift-JIS");
286                         MsgTextConvert *textCvt = MsgTextConvert::instance();
287                         p_msg_info->dataSize = textCvt->convertSHIFTJISToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->cmas_data.alert_text, p_deliver->cmas_data.data_len);
288                 } else if (p_msg_info->encodeType == MSG_ENCODE_GSM7BIT) {
289                         MSG_DEBUG("Encode Type = GSM7BIT");
290                         MSG_LANG_INFO_S langinfo = {0, };
291                         MsgTextConvert *textCvt = MsgTextConvert::instance();
292                         p_msg_info->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->cmas_data.alert_text, p_deliver->cmas_data.data_len, &langinfo);
293                 } else {
294                         snprintf(p_msg_info->msgText, sizeof(p_msg_info->msgText), "%s", p_deliver->cmas_data.alert_text);
295                         p_msg_info->dataSize = p_deliver->cmas_data.data_len;
296                 }
297         }
298
299         MSG_END();
300 }
301
302
303 void SmsPluginEventHandler::convertDeliverMsgToMsgInfo(sms_telesvc_deliver_s *p_deliver, MSG_MESSAGE_INFO_S *p_msg_info)
304 {
305         MSG_BEGIN();
306
307         p_msg_info->msgType.mainType = MSG_SMS_TYPE;
308         /*
309         p_msg_info->msgType.subType = MSG_NORMAL_SMS;
310         p_msg_info->folderId = MSG_INBOX_ID;
311         */
312         p_msg_info->msgType.classType = MSG_CLASS_NONE;
313         p_msg_info->networkStatus = MSG_NETWORK_RECEIVED;
314         p_msg_info->bRead = false;
315         p_msg_info->bProtected = false;
316         p_msg_info->direction = MSG_DIRECTION_TYPE_MT;
317         p_msg_info->bTextSms = true;
318
319         if (p_deliver->callback_number.szData[0] != '\0') {
320                 /* If callback number is in received pdu, replace the address value. */
321                 memset(p_msg_info->addressList[1].addressVal, 0x00, MAX_ADDRESS_VAL_LEN+1);
322                 p_msg_info->addressList[1].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
323                 memcpy(p_msg_info->addressList[1].addressVal, p_deliver->callback_number.szData, MAX_ADDRESS_VAL_LEN);
324                 p_msg_info->addressList[1].recipientType = MSG_RECIPIENTS_TYPE_TO;
325         }
326
327         time_t rawtime = 0;
328         p_msg_info->storageId = MSG_STORAGE_PHONE;
329
330 #if 0 /* Save Timestamp of message center. */
331                 char displayTime[32];
332                 struct tm * timeTM;
333
334                 struct tm timeinfo;
335                 memset(&timeinfo, 0x00, sizeof(tm));
336
337                 if (p_deliver->time_stamp.year > 95)
338                         timeinfo.tm_year = (p_deliver->time_stamp.year + 1900);
339                 else
340                         timeinfo.tm_year = (p_deliver->time_stamp.year + 2000);
341
342                 timeinfo.tm_mon = (p_deliver->time_stamp.month - 1);
343                 timeinfo.tm_mday = p_deliver->time_stamp.day;
344                 timeinfo.tm_hour = p_deliver->time_stamp.hour;
345                 timeinfo.tm_min = p_deliver->time_stamp.minute;
346                 timeinfo.tm_sec = p_deliver->time_stamp.second;
347                 timeinfo.tm_isdst = 0;
348
349                 rawtime = mktime(&timeinfo);
350
351                 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
352                 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
353                 MSG_DEBUG("timezone [%d]", timezone);
354                 MSG_DEBUG("daylight [%d]", daylight);
355
356                 memset(displayTime, 0x00, sizeof(displayTime));
357                 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
358                 MSG_DEBUG("displayTime [%s]", displayTime);
359
360                 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
361
362                 timeTM = localtime(&rawtime);
363                 memset(displayTime, 0x00, sizeof(displayTime));
364                 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
365                 MSG_DEBUG("displayTime [%s]", displayTime);
366
367                 rawtime -= timezone;
368
369                 timeTM = localtime(&rawtime);
370                 memset(displayTime, 0x00, sizeof(displayTime));
371                 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
372                 MSG_DEBUG("displayTime [%s]", displayTime);
373         }
374 #else
375         rawtime = time(NULL);
376 #endif
377
378         p_msg_info->displayTime = rawtime;
379
380
381         if (p_deliver->priority == SMS_PRIORITY_URGENT || p_deliver->priority == SMS_PRIORITY_EMERGENCY)
382                 p_msg_info->priority = MSG_MESSAGE_PRIORITY_HIGH;
383         else
384                 p_msg_info->priority = MSG_MESSAGE_PRIORITY_NORMAL;
385
386
387         memset(p_msg_info->subject, 0x00, MAX_SUBJECT_LEN+1);
388
389         p_msg_info->msgPort.valid = false;
390         p_msg_info->msgPort.dstPort = 0;
391         p_msg_info->msgPort.srcPort = 0;
392
393         p_msg_info->encodeType = getEncodeType(p_deliver->user_data.encode_type);
394
395         if (p_deliver->user_data.data_len <= 0) {
396                 memset(p_msg_info->msgText, 0x00, sizeof(p_msg_info->msgText));
397                 p_msg_info->dataSize = 0;
398         } else if (p_deliver->user_data.data_len > MAX_MSG_TEXT_LEN) {
399                 snprintf(p_msg_info->msgText, MAX_MSG_TEXT_LEN, "[Broken Message]");
400                 p_msg_info->dataSize = strlen(p_msg_info->msgData);
401                 return;
402         } else {
403                 if (p_msg_info->encodeType == MSG_ENCODE_UCS2) {
404                         MSG_DEBUG("Encode Type = UCS2");
405                         MsgTextConvert *textCvt = MsgTextConvert::instance();
406                         p_msg_info->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->user_data.user_data, p_deliver->user_data.data_len);
407                 } else if (p_msg_info->encodeType == MSG_ENCODE_EUCKR) {
408                         MSG_DEBUG("Encode Type = EUCKR");
409                         MsgTextConvert *textCvt = MsgTextConvert::instance();
410                         p_msg_info->dataSize = textCvt->convertEUCKRToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->user_data.user_data, p_deliver->user_data.data_len);
411                 } else if (p_msg_info->encodeType == MSG_ENCODE_SHIFT_JIS) {
412                         MSG_DEBUG("Encode Type = Shift-JIS");
413                         MsgTextConvert *textCvt = MsgTextConvert::instance();
414                         p_msg_info->dataSize = textCvt->convertSHIFTJISToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->user_data.user_data, p_deliver->user_data.data_len);
415                 } else if (p_msg_info->encodeType == MSG_ENCODE_GSM7BIT) {
416                         MSG_DEBUG("Encode Type = GSM7BIT");
417                         MSG_LANG_INFO_S langinfo = {0, };
418                         MsgTextConvert *textCvt = MsgTextConvert::instance();
419                         p_msg_info->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->user_data.user_data, p_deliver->user_data.data_len, &langinfo);
420                 } else {
421                         snprintf(p_msg_info->msgText, sizeof(p_msg_info->msgText), "%s", p_deliver->user_data.user_data);
422                         p_msg_info->dataSize = p_deliver->user_data.data_len;
423                 }
424         }
425
426         MSG_END();
427 }
428
429
430 void SmsPluginEventHandler::convertAckMsgToMsgInfo(sms_telesvc_deliver_ack_s *p_deliver, MSG_MESSAGE_INFO_S *p_msg_info)
431 {
432 }
433
434
435 void SmsPluginEventHandler::convertReportMsgToMsgInfo(sms_telesvc_report_s *p_deliver, MSG_MESSAGE_INFO_S *p_msg_info)
436 {
437 }
438
439
440 void SmsPluginEventHandler::SetSentInfo(sms_sent_info_s *pSentInfo)
441 {
442         memset(&sentInfo, 0x00, sizeof(sms_sent_info_s));
443         memcpy(&sentInfo, pSentInfo, sizeof(sms_sent_info_s));
444
445         MSG_DEBUG("sentInfo.reqId : %d", sentInfo.reqInfo.reqId);
446         MSG_DEBUG("sentInfo.bLast : %d", sentInfo.bLast);
447 }
448
449
450
451 void SmsPluginEventHandler::handleSentStatus(msg_network_status_t NetStatus)
452 {
453         MSG_DEBUG("NetStatus[%d]", NetStatus);
454
455         if (sentInfo.bLast == true || NetStatus != MSG_NETWORK_SEND_SUCCESS) {
456                 /* Update Msg Status */
457                 if (sentInfo.reqInfo.msgInfo.msgPort.valid == false) {
458                         sentInfo.reqInfo.msgInfo.networkStatus = NetStatus;
459
460                         if (NetStatus == MSG_NETWORK_SEND_SUCCESS) {
461                                 MSG_DEBUG("Add phone log");
462                                 MsgAddPhoneLog(&(sentInfo.reqInfo.msgInfo));
463                                 sentInfo.reqInfo.msgInfo.folderId = MSG_SENTBOX_ID;
464                                 /* Send system event */
465                                 bundle *b = NULL;
466                                 b = bundle_create();
467                                 if (b) {
468                                         if (sentInfo.reqInfo.msgInfo.msgType.mainType == MSG_SMS_TYPE)
469                                                 bundle_add_str(b, EVT_KEY_OUT_MSG_TYPE, EVT_VAL_SMS);
470                                         else
471                                                 bundle_add_str(b, EVT_KEY_OUT_MSG_TYPE, EVT_VAL_MMS);
472
473                                         char msgId[MSG_EVENT_MSG_ID_LEN] = {0, };
474                                         snprintf(msgId, sizeof(msgId), "%u", sentInfo.reqInfo.msgInfo.msgId);
475                                         bundle_add_str(b, EVT_KEY_OUT_MSG_ID, msgId);
476                                         eventsystem_send_system_event(SYS_EVENT_OUTGOING_MSG, b);
477                                         bundle_add_str(b, "cmd", "outgoing_msg");
478                                         int ret = aul_launch_app_for_uid("org.tizen.msg-manager", b, msg_get_login_user());
479                                         if (ret <= 0) {
480                                                 MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
481                                         }
482                                         bundle_free(b);
483                                 }
484                         } else {
485                                 sentInfo.reqInfo.msgInfo.bRead = false;
486                         }
487
488                         callbackStorageChange(MSG_STORAGE_CHANGE_UPDATE, &(sentInfo.reqInfo.msgInfo));
489                 }
490
491                 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bSetting [%d]", sentInfo.reqInfo.sendOptInfo.bSetting);
492                 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bKeepCopy [%d]", sentInfo.reqInfo.sendOptInfo.bKeepCopy);
493                 /* Check sending options */
494                 if (sentInfo.reqInfo.sendOptInfo.bSetting && !sentInfo.reqInfo.sendOptInfo.bKeepCopy && NetStatus == MSG_NETWORK_SEND_SUCCESS) {
495                         callbackStorageChange(MSG_STORAGE_CHANGE_DELETE, &(sentInfo.reqInfo.msgInfo));
496                 }
497
498                 /* Callback to MSG FW */
499                 MSG_SENT_STATUS_S msgStatus;
500
501                 msgStatus.reqId = sentInfo.reqInfo.reqId;
502                 msgStatus.status = NetStatus;
503
504                 MSG_DEBUG("sentStatus.reqId : %d", msgStatus.reqId);
505                 MSG_DEBUG("sentStatus.status : %d", msgStatus.status);
506
507                 listener.pfSentStatusCb(&msgStatus);
508         }
509 }
510
511
512 void SmsPluginEventHandler::handleMsgIncoming(sms_trans_p2p_msg_s *p_p2p_msg)
513 {
514         /* Make MSG_MESSAGE_INFO_S */
515         MSG_MESSAGE_INFO_S msgInfo;
516
517         /* initialize msgInfo */
518         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
519
520         msgInfo.addressList = NULL;
521         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
522
523         /* convert to msgInfo */
524         convertTpduToMsginfo(p_p2p_msg, &msgInfo);
525
526         if (p_p2p_msg->telesvc_id == SMS_TRANS_TELESVC_RESERVED) {
527                 MSG_DEBUG("This Incoming Message has Unknown Teleservice ID");
528                 SmsPluginTransport::instance()->sendDeliverReport(MSG_ERR_INVALID_MSG_TYPE, p_p2p_msg);
529                 return;
530         }
531
532         /* Check for Voice Mail Notification */
533         if (p_p2p_msg->telesvc_id == SMS_TRANS_TELESVC_VMN_95) {
534                 if (p_p2p_msg->telesvc_msg.data.deliver.enhanced_vmn.fax_included)
535                         msgInfo.msgType.subType = MSG_MWI_FAX_SMS;
536                 else
537                         msgInfo.msgType.subType = MSG_MWI_VOICE_SMS;
538
539                 if (p_p2p_msg->telesvc_msg.data.deliver.num_msg < 0)
540                         p_p2p_msg->telesvc_msg.data.deliver.num_msg = 0;
541
542                 int voice_cnt = 0;
543                 if (MsgSettingGetInt(VOICEMAIL_COUNT, &voice_cnt) != MSG_SUCCESS) {
544                         MSG_INFO("MsgSettingGetInt() is failed");
545                 }
546
547                 /* repeated msg check for voicemail */
548                 if (voice_cnt == p_p2p_msg->telesvc_msg.data.deliver.num_msg) {
549                         SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS, p_p2p_msg);
550                         return;
551                 }
552
553                 SmsPluginSetting::instance()->setMwiInfo(msgInfo.msgType.subType, p_p2p_msg->telesvc_msg.data.deliver.num_msg);
554
555                 memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
556
557                 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d", p_p2p_msg->telesvc_msg.data.deliver.num_msg);
558                 msgInfo.dataSize = strlen(msgInfo.msgText);
559         } else if (p_p2p_msg->telesvc_id == SMS_TRANS_TELESVC_WEMT) {
560                 /* Check for EMS(Unsupported) */
561                 char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSGF_POP_ERROR_UNSUPPORTED_MSG");
562                 memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
563                 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%s", msg_text);
564                 msgInfo.dataSize = strlen(msgInfo.msgText);
565
566                 if (msg_text) {
567                         free(msg_text);
568                         msg_text = NULL;
569                 }
570         }
571
572         /* Print MSG_MESSAGE_INFO_S */
573         MSG_DEBUG("############# Convert  tpdu values to Message Info values ####################");
574         MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
575         MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
576         MSG_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
577         MSG_DEBUG("msgInfo.addressList[0].displayName : %s", msgInfo.addressList[0].displayName);
578         MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
579         MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
580         MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
581         MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
582         MSG_DEBUG("msgInfo.bStore : %d", msgInfo.bStore);
583         MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
584         MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
585         MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
586         MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
587         MSG_DEBUG("msgInfo.displayTime : %s", ctime(&msgInfo.displayTime));
588         MSG_DEBUG("msgInfo.msgPort.valid : %d", msgInfo.msgPort.valid);
589         MSG_DEBUG("msgInfo.encodeType : %d", msgInfo.encodeType);
590         MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
591
592         if (msgInfo.bTextSms == true) {
593                 MSG_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
594         } else {
595                 MSG_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
596         }
597
598         MSG_DEBUG("###############################################################");
599
600         msg_error_t err = MSG_SUCCESS;
601         bool isUnique = true;
602         MSG_UNIQUE_INDEX_S unq_ind;
603         memset(&unq_ind, 0x00, sizeof(MSG_UNIQUE_INDEX_S));
604
605         if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS) {
606                 /* Status Report Message */
607                 /*
608                 err = SmsPluginStorage::instance()->updateMsgDeliverStatus(&msgInfo, pTpdu->data.statusRep.msgRef);
609
610                 if (err == MSG_SUCCESS)
611                         err = listener.pfMsgIncomingCb(&msgInfo);
612                 else
613                         MSG_DEBUG("updateMsgDeliverStatus is failed [%d]", err);
614                 */
615
616                 /* Handling of Fail Case ?? */
617                 /* SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS); */
618         } else { /* SMS Deliver */
619                 /* Add message to DB */
620                 if (msgInfo.msgPort.valid == false) {
621                         if (p_p2p_msg->telesvc_id != SMS_TRANS_TELESVC_VMN_95) {
622                                 memcpy(unq_ind.address, p_p2p_msg->address.szData, sizeof(p_p2p_msg->address.szData));
623                                 memcpy(unq_ind.sub_address, p_p2p_msg->sub_address.szData, sizeof(p_p2p_msg->sub_address.szData));
624                                 unq_ind.tele_msgId = p_p2p_msg->telesvc_msg.data.deliver.msg_id.msg_id;
625                                 snprintf(unq_ind.time_stamp, sizeof(unq_ind.time_stamp), "%02d%02d%02d%02d%02d%02d",
626                                                 p_p2p_msg->telesvc_msg.data.deliver.time_stamp.year, p_p2p_msg->telesvc_msg.data.deliver.time_stamp.month,
627                                                 p_p2p_msg->telesvc_msg.data.deliver.time_stamp.day, p_p2p_msg->telesvc_msg.data.deliver.time_stamp.hours,
628                                                 p_p2p_msg->telesvc_msg.data.deliver.time_stamp.minutes, p_p2p_msg->telesvc_msg.data.deliver.time_stamp.seconds);
629                                 unq_ind.telesvc_id = p_p2p_msg->telesvc_id;
630                                 isUnique = listener.pfCheckUniquenessCb(&unq_ind, 0, false);
631                         }
632                 }
633
634                 if (isUnique) {
635                         err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
636                 } else {
637                         SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS, p_p2p_msg);
638                         return;
639                 }
640
641                 /* Callback to MSG FW */
642                 if (err == MSG_SUCCESS) {
643                         MSG_DEBUG("callback to msg fw");
644                         err = listener.pfMsgIncomingCb(&msgInfo);
645                 } else {
646                         if (msgInfo.msgType.classType == MSG_CLASS_0) {
647                                 MSG_DEBUG("callback for class0 message to msg fw");
648                                 if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
649                                         MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
650                         }
651                 }
652
653                 if (err == MSG_SUCCESS && p_p2p_msg->telesvc_id != SMS_TRANS_TELESVC_VMN_95)
654                         listener.pfCheckUniquenessCb(&unq_ind, msgInfo.msgId, true);
655
656                 /* Send Deliver Report */
657                 if (p_p2p_msg->telesvc_id == SMS_TRANS_TELESVC_WEMT) {
658                         SmsPluginTransport::instance()->sendDeliverReport(MSG_ERR_INVALID_MSG_TYPE, p_p2p_msg);
659                 } else {
660                         SmsPluginTransport::instance()->sendDeliverReport(err, p_p2p_msg);
661                 }
662
663                 /* Tizen Validation System */
664                 char *msisdn = NULL;
665                 char keyName[MAX_VCONFKEY_NAME_LEN];
666                 int simIndex = 1;
667
668                 memset(keyName, 0x00, sizeof(keyName));
669                 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, simIndex);
670
671                 if (MsgSettingGetString(keyName, &msisdn) != MSG_SUCCESS) {
672                         MSG_INFO("MsgSettingGetString() is failed");
673                 }
674
675                 MSG_SMS_VLD_INFO("%d, SMS Receive, %s->%s, %s", msgInfo.msgId, \
676                                                                                                                 msgInfo.addressList[0].addressVal, \
677                                                                                                                 (msisdn == NULL)?"ME":msisdn, \
678                                                                                                                 (err == MSG_SUCCESS)?"Success":"Fail");
679
680                 MSG_SMS_VLD_TXT("%d, [%s]", msgInfo.msgId, msgInfo.msgText);
681
682                 if (msisdn) {
683                         free(msisdn);
684                         msisdn = NULL;
685                 }
686         }
687 }
688
689
690 void SmsPluginEventHandler::handleCbMsgIncoming(sms_trans_broadcast_msg_s *p_cb_msg)
691 {
692         MSG_BEGIN();
693
694         if (p_cb_msg->telesvc_msg.data.deliver.cmas_data.encode_type == SMS_ENCODE_KOREAN
695                 || p_cb_msg->telesvc_msg.data.deliver.cmas_data.encode_type == SMS_ENCODE_GSMDCS) {
696                 MSG_DEBUG("This encode type is not supported [%d]", p_cb_msg->telesvc_msg.data.deliver.cmas_data.encode_type);
697                 return;
698         }
699
700         /* Make MSG_MESSAGE_INFO_S */
701         MSG_MESSAGE_INFO_S msgInfo;
702
703         /* initialize msgInfo */
704         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
705
706         msgInfo.addressList = NULL;
707         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
708
709         /* convert to msgInfo */
710         convertTpduToMsginfo(p_cb_msg, &msgInfo);
711         msgInfo.msgId = p_cb_msg->telesvc_msg.data.deliver.msg_id.msg_id;
712
713         /* Print MSG_MESSAGE_INFO_S */
714         MSG_DEBUG("############# Convert  tpdu values to Message Info values ####################");
715         MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
716         MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
717         MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
718         MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
719         MSG_DEBUG("msgInfo.bStore : %d", msgInfo.bStore);
720         MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
721         MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
722         MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
723         MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
724         MSG_DEBUG("msgInfo.displayTime : %s", ctime(&msgInfo.displayTime));
725         MSG_DEBUG("msgInfo.msgPort.valid : %d", msgInfo.msgPort.valid);
726         MSG_DEBUG("msgInfo.encodeType : %d", msgInfo.encodeType);
727         MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
728         MSG_DEBUG("msgInfo.msgId : %d", msgInfo.msgId);
729
730         if (msgInfo.bTextSms == true) {
731                 MSG_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
732         } else {
733                 MSG_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
734         }
735
736         MSG_DEBUG("###############################################################");
737
738         msg_error_t err = MSG_SUCCESS;
739
740         /* Add message to DB */
741         if (msgInfo.msgPort.valid == false) {
742                 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
743         }
744
745         if (!checkCbOpt(p_cb_msg->svc_ctg)) {
746                 MSG_DEBUG("The CB Msg is not supported by option.");
747                 return;
748         }
749
750         /* Callback to MSG FW */
751         if (err == MSG_SUCCESS) {
752 #if 1
753                 MSG_CB_MSG_S cbOutMsg = {0, };
754                 bool is_duplicate = false;
755
756                 switch (p_cb_msg->svc_ctg) {
757                 case SMS_TRANS_SVC_CTG_CMAS_PRESIDENTIAL :
758                         msgInfo.msgType.subType = MSG_CMAS_PRESIDENTIAL;
759                         break;
760                 case SMS_TRANS_SVC_CTG_CMAS_EXTREME :
761                         msgInfo.msgType.subType = MSG_CMAS_EXTREME;
762                         break;
763                 case SMS_TRANS_SVC_CTG_CMAS_SEVERE :
764                         msgInfo.msgType.subType = MSG_CMAS_SEVERE;
765                         break;
766                 case SMS_TRANS_SVC_CTG_CMAS_AMBER :
767                         msgInfo.msgType.subType = MSG_CMAS_AMBER;
768                         break;
769                 case SMS_TRANS_SVC_CTG_CMAS_TEST :
770                         msgInfo.msgType.subType = MSG_CMAS_TEST;
771                         break;
772                 default :
773                         msgInfo.msgType.subType = MSG_CB_SMS;
774                         break;
775                 }
776
777                 cbOutMsg.type = msgInfo.msgType.subType;
778                 cbOutMsg.receivedTime = msgInfo.displayTime;
779                 /* encodeCbSerialNum (CbMsgPage.pageHeader.serialNum); */
780                 cbOutMsg.serialNum = 0;
781                 cbOutMsg.messageId = msgInfo.msgId;
782                 /* cbOutMsg.dcs = CbMsgPage.pageHeader.dcs.rawData; */
783                 memset (cbOutMsg.cbText, 0x00, sizeof(cbOutMsg.cbText));
784
785                 cbOutMsg.cbTextLen = msgInfo.dataSize;
786                 memset(cbOutMsg.language_type, 0x00, sizeof(cbOutMsg.language_type));
787                 /* memcpy(cbOutMsg.language_type, CbMsgPage.pageHeader.dcs.iso639Lang, 3); */
788
789                 if (!is_duplicate) {
790                         MSG_DEBUG("callback to msg fw");
791                         err = listener.pfCBMsgIncomingCb(&cbOutMsg, &msgInfo);
792
793                         if (err != MSG_SUCCESS) {
794                                 MSG_WARN("callbackMsgIncoming() Error !! [%d]", err);
795                         }
796                 } else {
797                         MSG_WARN("duplicate cb serialNum[%d] messageId[%d]", cbOutMsg.serialNum, cbOutMsg.messageId);
798                 }
799
800 #else
801                 err = listener.pfMsgIncomingCb(&msgInfo);
802 #endif
803         }
804
805         /* Send Deliver Report */
806         /* SmsPluginTransport::instance()->sendDeliverReport(err, p_cb_msg); */
807
808         /* Tizen Validation System */
809         char *msisdn = NULL;
810         char keyName[MAX_VCONFKEY_NAME_LEN];
811         int simIndex = 1;
812
813         memset(keyName, 0x00, sizeof(keyName));
814         snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, simIndex);
815
816         if (MsgSettingGetString(keyName, &msisdn) != MSG_SUCCESS) {
817                 MSG_INFO("MsgSettingGetString() is failed");
818         }
819
820         MSG_SMS_VLD_INFO("%d, SMS Receive, %s->%s, %s", msgInfo.msgId, \
821                                                                                                         msgInfo.addressList[0].addressVal, \
822                                                                                                         (msisdn == NULL)?"ME":msisdn, \
823                                                                                                         (err == MSG_SUCCESS)?"Success":"Fail");
824
825         MSG_SMS_VLD_TXT("%d, [%s]", msgInfo.msgId, msgInfo.msgText);
826
827         if (msisdn) {
828                 free(msisdn);
829                 msisdn = NULL;
830         }
831
832         MSG_END();
833 }
834
835
836 void SmsPluginEventHandler::handleWapMsgIncoming(sms_trans_p2p_msg_s *p_p2p_msg)
837 {
838         MSG_BEGIN();
839
840         sms_wap_msg_s msg;
841         memset(&msg, 0x00, sizeof(sms_wap_msg_s));
842
843         msg.msgId = p_p2p_msg->telesvc_msg.data.deliver.msg_id.msg_id;
844         msg.totalSeg = p_p2p_msg->telesvc_msg.data.deliver.user_data.user_data[1];
845         msg.segNum = p_p2p_msg->telesvc_msg.data.deliver.user_data.user_data[2];
846
847         char tmpUserText[SMS_MAX_USER_DATA_LEN+1] = {0, };
848         sms_telesvc_userdata_s tmpUserData;
849         memset(&tmpUserData, 0x00, sizeof(sms_telesvc_userdata_s));
850
851         tmpUserData.data_len = p_p2p_msg->telesvc_msg.data.deliver.user_data.data_len - 3;
852         memcpy(tmpUserText, &(p_p2p_msg->telesvc_msg.data.deliver.user_data.user_data[3]), tmpUserData.data_len);
853         memcpy(tmpUserData.user_data, tmpUserText, sizeof(tmpUserData.user_data));
854
855         unsigned char segCnt = checkWapMsg(&msg, &tmpUserData);
856
857         MSG_DEBUG("segNum [%d]", msg.segNum);
858         MSG_DEBUG("segCnt [%d]", segCnt);
859         MSG_DEBUG("msg.totalSeg [%d]", msg.totalSeg);
860
861         if (segCnt == msg.totalSeg) {
862                 MSG_DEBUG("RECEIVED LAST WAP : %d", segCnt);
863
864                 unsigned short srcPort = 0, dstPort = 0;
865                 int dataSize = 0;
866                 char* pUserData = NULL;
867                 char* pTmpUserData = NULL;
868                 unique_ptr<char*, void(*)(char**)> dataBuf(&pUserData, unique_ptr_deleter);
869                 unique_ptr<char*, void(*)(char**)> dataBuf1(&pTmpUserData, unique_ptr_deleter);
870
871                 MSG_MESSAGE_INFO_S msgInfo = {0, };
872
873                 msgInfo.addressList = NULL;
874                 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
875
876                 dataSize = MakeWapUserData(msg.msgId, &pUserData);
877
878                 pTmpUserData = new char[dataSize];
879
880                 memcpy(pTmpUserData, pUserData, dataSize);
881                 memset(pUserData, 0x00, dataSize);
882
883                 srcPort = pTmpUserData[0] << 8  | pTmpUserData[1];
884                 dstPort = pTmpUserData[2] << 8 | pTmpUserData[3];
885
886 #ifndef FEATURE_OMADM_DUPLICATE_PORT_WAPPUSH
887                 dataSize -= 4;
888                 memcpy(pUserData, &pTmpUserData[4], dataSize);
889 #else
890                 if ((srcPort == 0x23f0 && dstPort == 0x0b84) &&
891                         ((pTmpUserData[4] << 8 | pTmpUserData[5]) == 0x23f0) &&
892                         ((pTmpUserData[6] << 8 | pTmpUserData[7]) == 0x0b84)) {
893                         dataSize -= 8;
894                         memcpy(pUserData, &pTmpUserData[8], dataSize);
895                 } else {
896                         dataSize -= 4;
897                         memcpy(pUserData, &pTmpUserData[4], dataSize);
898                 }
899 #endif
900
901                 if (dataSize > 0) {
902                         MSG_DEBUG("dataSize = %d", dataSize);
903                         for (int i = 0; i < dataSize; i++)
904                                 MSG_DEBUG("UserData[%d] = [%c] [%02x]", i, pUserData[i], pUserData[i]);
905
906                         if      (SmsPluginWapPushHandler::instance()->IsWapPushMsg(dstPort) == true) {
907                                 msgInfo.msgType.mainType = MSG_SMS_TYPE;
908                                 SmsPluginWapPushHandler::instance()->copyDeliverData(&(p_p2p_msg->address));
909                                 SmsPluginWapPushHandler::instance()->handleWapPushMsg(pUserData, dataSize);
910                         } else {
911                                 MSG_DEBUG("not supported wap push port [%x]", dstPort);
912                         }
913                 }
914
915                 /* remove from waplist */
916                 for (int index = wapList.size()-1; index >= 0 ; index--) {
917                         if (wapList[index].msgId == msg.msgId) {
918                                 MSG_DEBUG("remove waplist of the index [%d]", index);
919                                 wapList.erase(wapList.begin()+index);
920                                 break;
921                         }
922                 }
923         }
924
925         /* Send Deliver Report */
926         SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS, p_p2p_msg);
927
928         MSG_END();
929 }
930
931
932 void SmsPluginEventHandler::handleResendMessage(void)
933 {
934         listener.pfResendMessageCb();
935 }
936
937
938 msg_error_t SmsPluginEventHandler::callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgInfo)
939 {
940         MSG_BEGIN();
941
942         msg_error_t err = MSG_SUCCESS;
943
944         /* Callback to MSG FW */
945         err = listener.pfMsgIncomingCb(pMsgInfo);
946
947         MSG_END();
948
949         return err;
950 }
951
952
953 msg_error_t SmsPluginEventHandler::callbackStorageChange(msg_storage_change_type_t storageChangeType, MSG_MESSAGE_INFO_S *pMsgInfo)
954 {
955         /* Callback to MSG FW */
956         listener.pfStorageChangeCb(storageChangeType, pMsgInfo);
957
958         return MSG_SUCCESS;
959 }
960
961
962 void SmsPluginEventHandler::setDeviceStatus()
963 {
964         mx.lock();
965         devStatus = true;
966         cv.signal();
967         mx.unlock();
968 }
969
970
971 bool SmsPluginEventHandler::getDeviceStatus()
972 {
973         int ret = 0;
974
975         mx.lock();
976
977         ret = cv.timedwait(mx.pMsgMutex(), 25);
978
979         if (ret == ETIMEDOUT) {
980                 MSG_DEBUG("WARNING: DEVICE STATUS TIME-OUT");
981                 devStatus = false;
982                 bNeedInitConfig = true;
983         }
984         mx.unlock();
985         return devStatus;
986 }
987
988
989 void SmsPluginEventHandler::setNeedInitConfig(bool bNeeded)
990 {
991         bNeedInitConfig = bNeeded;
992 }
993
994
995 bool SmsPluginEventHandler::getNeedInitConfig()
996 {
997         return bNeedInitConfig;
998 }
999
1000
1001 msg_encode_type_t SmsPluginEventHandler::getEncodeType(sms_encoding_type_t encode_type)
1002 {
1003         switch (encode_type) {
1004         case SMS_ENCODE_GSM7BIT:
1005                 return MSG_ENCODE_GSM7BIT;
1006         case SMS_ENCODE_KOREAN:
1007         case SMS_ENCODE_EUCKR:
1008                 return MSG_ENCODE_EUCKR;
1009         case SMS_ENCODE_IA5:
1010         case SMS_ENCODE_7BIT_ASCII:
1011         case SMS_ENCODE_LATIN_HEBREW:
1012         case SMS_ENCODE_LATIN:
1013         case SMS_ENCODE_OCTET:
1014                 return MSG_ENCODE_8BIT;
1015         case SMS_ENCODE_SHIFT_JIS:
1016                 return MSG_ENCODE_SHIFT_JIS;
1017         /*
1018         case SMS_ENCODE_EPM :
1019         case SMS_ENCODE_UNICODE :
1020         case SMS_ENCODE_GSMDCS :
1021         */
1022         default:
1023                 return MSG_ENCODE_UCS2;
1024         }
1025
1026         return MSG_ENCODE_UCS2;
1027 }
1028
1029
1030 unsigned short SmsPluginEventHandler::checkWapMsg(sms_wap_msg_s *pMsg, sms_telesvc_userdata_s *pUserdata)
1031 {
1032         unsigned char currSegNum = 0;
1033
1034         bool bFind = false;
1035
1036         for (unsigned int i = 0; i < wapList.size(); i++) {
1037                 if (wapList[i].msgId == pMsg->msgId) {
1038                         if (wapList[i].data.count(pMsg->segNum) != 0) {
1039                                 MSG_DEBUG("The Segment Number already exists [%d]", pMsg->segNum);
1040                                 return 0;
1041                         }
1042                         wap_data_s wapData = {0};
1043
1044                         memcpy(wapData.data, pUserdata->user_data, pUserdata->data_len);
1045                         wapData.length = pUserdata->data_len;
1046
1047                         pair<unsigned char, wap_data_s> newData(pMsg->segNum, wapData);
1048                         wapList[i].data.insert(newData);
1049
1050                         MSG_DEBUG("MSG DATA : %s", pUserdata->user_data);
1051                         MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.data);
1052                         MSG_DEBUG("DATA SIZE [%d]", pUserdata->data_len);
1053
1054                         wapList[i].segNum++;
1055                         wapList[i].totalSize += pUserdata->data_len;
1056                         currSegNum = wapList[i].segNum;
1057
1058                         bFind = true;
1059
1060                         break;
1061                 }
1062         }
1063
1064         /* New Wap Push Msg */
1065         if (bFind == false) {
1066                 sms_wap_info_s tmpInfo;
1067                 tmpInfo.msgId = pMsg->msgId;
1068                 tmpInfo.totalSeg = pMsg->totalSeg;
1069                 tmpInfo.segNum = 1;
1070
1071                 tmpInfo.totalSize = pUserdata->data_len;
1072
1073                 wap_data_s wapData = {0};
1074
1075                 memcpy(wapData.data, pUserdata->user_data, pUserdata->data_len);
1076                 wapData.length = pUserdata->data_len;
1077
1078                 pair<unsigned char, wap_data_s> newData(pMsg->segNum, wapData);
1079                 tmpInfo.data.insert(newData);
1080
1081                 MSG_DEBUG("MSG DATA : %s", pUserdata->user_data);
1082                 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.data);
1083                 MSG_DEBUG("DATA SIZE [%d]", pUserdata->data_len);
1084
1085                 wapList.push_back(tmpInfo);
1086
1087                 currSegNum = tmpInfo.segNum;
1088         }
1089
1090         return currSegNum;
1091 }
1092
1093
1094 int SmsPluginEventHandler::MakeWapUserData(unsigned short msgId, char **ppTotalData)
1095 {
1096         wapDataMap::iterator it;
1097
1098         int totalSize = 0, offset = 0;
1099
1100         for (unsigned int i = 0; i < wapList.size(); i++) {
1101                 if (wapList[i].msgId == msgId) {
1102                         totalSize = wapList[i].totalSize;
1103
1104                         if (totalSize <= 0) {
1105                                 MSG_DEBUG("Size Error : totalSize <= 0");
1106                                 return 0;
1107                         }
1108
1109                         MSG_DEBUG("totalSize [%d]", totalSize);
1110
1111                         if (*ppTotalData == NULL)
1112                                 *ppTotalData = new char[totalSize];
1113
1114                         for (it = wapList[i].data.begin(); it != wapList[i].data.end(); it++) {
1115                                 memcpy(*ppTotalData+offset, it->second.data, it->second.length);
1116                                 offset += it->second.length;
1117                         }
1118                 }
1119         }
1120
1121         return totalSize;
1122 }
1123
1124
1125 void SmsPluginEventHandler::handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen)
1126 {
1127         MSG_SYNCML_MESSAGE_DATA_S syncMLData;
1128
1129         memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
1130
1131         /* set syncML data */
1132         syncMLData.syncmlType = msgType;
1133
1134         syncMLData.pushBodyLen = PushBodyLen;
1135         memcpy(syncMLData.pushBody, pPushBody, PushBodyLen);
1136
1137         syncMLData.wspHeaderLen = WspHeaderLen;
1138         memcpy(syncMLData.wspHeader, pWspHeader, WspHeaderLen);
1139
1140         /* Callback to MSG FW */
1141         listener.pfSyncMLMsgIncomingCb(&syncMLData);
1142 }
1143
1144
1145 void SmsPluginEventHandler::handleLBSMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen)
1146 {
1147         MSG_LBS_MESSAGE_DATA_S lBSData;
1148
1149         memset(&lBSData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
1150
1151         /* set LBA data */
1152         memcpy(lBSData.pushHeader, pPushHeader, strlen(pPushHeader));
1153
1154         lBSData.pushBodyLen = pushBodyLen;
1155         memcpy(lBSData.pushBody, pPushBody, pushBodyLen);
1156
1157         /* Callback to MSG FW */
1158         listener.pfLBSMsgIncomingCb(&lBSData);
1159 }
1160
1161
1162 void SmsPluginEventHandler::handlePushMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen, char *application_id, char *content_type)
1163 {
1164         MSG_PUSH_MESSAGE_DATA_S pushData;
1165
1166         memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
1167
1168         /* set PUSH data */
1169         memcpy(pushData.pushHeader, pPushHeader, strlen(pPushHeader));
1170
1171         pushData.pushBodyLen = pushBodyLen;
1172         memcpy(pushData.pushBody, pPushBody, pushBodyLen);
1173
1174         memcpy(pushData.pushAppId, application_id, MAX_WAPPUSH_ID_LEN);
1175         memcpy(pushData.pushContentType, content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN);
1176
1177         /* Callback to MSG FW */
1178         listener.pfPushMsgIncomingCb(&pushData);
1179 }
1180
1181
1182 bool SmsPluginEventHandler::checkCbOpt(sms_trans_svc_ctg_t svc_ctg)
1183 {
1184         bool bReceive = false;
1185         char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
1186         int sim_idx = 1;
1187
1188         memset(keyName, 0x00, sizeof(keyName));
1189         snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, sim_idx);
1190         if (MsgSettingGetBool(keyName, &bReceive) != MSG_SUCCESS)
1191                 MSG_INFO("MsgSettingGetBool() is failed");
1192
1193         /* Receive CB Msg = FALSE */
1194         if (!bReceive) {
1195                 MSG_DEBUG("RECEIVE CB = FALSE");
1196                 return false;
1197         }
1198
1199         if (svc_ctg >= SMS_TRANS_SVC_CTG_CMAS_PRESIDENTIAL && svc_ctg <= SMS_TRANS_SVC_CTG_CMAS_TEST) {
1200                 bool bActivate = false;
1201                 short Category = 0;
1202                 MSG_CB_CHANNEL_S cbChannelInfo = {0, };
1203                 msg_error_t err = MSG_SUCCESS;
1204                 MsgDbHandler *dbHandle = getDbHandle();
1205
1206                 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo);
1207                 if (err != MSG_SUCCESS) {
1208                         MSG_DEBUG("Error value of MsgStoGetCBChannelInfo [%d]", err);
1209                         return false;
1210                 }
1211
1212                 for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
1213                         bActivate = cbChannelInfo.channelInfo[i].bActivate;
1214                         Category = cbChannelInfo.channelInfo[i].ctg;
1215
1216                         if (bActivate == true && svc_ctg == Category) {
1217                                 MSG_DEBUG("FIND CHANNEL = [%d]", svc_ctg);
1218                                 return true;
1219                         }
1220                 }
1221
1222                 return false;
1223         }
1224
1225         return true;
1226 }