Fix issue : fail to make thumbnail
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginEventHandler.cpp
1 /*
2  * Copyright (c) 2014 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 <time.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <errno.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 "MsgCppTypes.h"
30 #include "MsgContact.h"
31 #include "MsgGconfWrapper.h"
32 #include "MsgNotificationWrapper.h"
33 #include "MsgDevicedWrapper.h"
34 #include "SmsPluginTransport.h"
35 #include "SmsPluginSimMsg.h"
36 #include "SmsPluginStorage.h"
37 #include "SmsPluginSetting.h"
38 #include "SmsPluginConcatHandler.h"
39 #include "SmsPluginEventHandler.h"
40 #include "SmsPluginDSHandler.h"
41 #include "SmsPluginParamCodec.h"
42
43
44 /*==================================================================================================
45                                      IMPLEMENTATION OF SmsPluginEventHandler - Member Functions
46 ==================================================================================================*/
47 SmsPluginEventHandler* SmsPluginEventHandler::pInstance = NULL;
48
49
50 SmsPluginEventHandler::SmsPluginEventHandler()
51 {
52         /**  Initialize global parameters */
53         memset(&listener, 0x00, sizeof(MSG_PLUGIN_LISTENER_S));
54         memset(&sentInfo, 0x00, sizeof(SMS_SENT_INFO_S));
55
56         pSimCnt = NULL;
57         devStatus = false;
58         bUdhMwiMethod = false;
59         udhMwiCnt = 0;
60         devHandle = NULL;
61 }
62
63
64 SmsPluginEventHandler::~SmsPluginEventHandler()
65 {
66 }
67
68
69 SmsPluginEventHandler* SmsPluginEventHandler::instance()
70 {
71         if (!pInstance)
72                 pInstance = new SmsPluginEventHandler();
73
74         return pInstance;
75 }
76
77
78 void SmsPluginEventHandler::registerListener(MSG_PLUGIN_LISTENER_S *pListener)
79 {
80         listener = *pListener;
81 }
82
83
84 void SmsPluginEventHandler::handleSentStatus(msg_network_status_t NetStatus)
85 {
86         MSG_DEBUG("NetStatus[%d]", NetStatus);
87
88         if (sentInfo.bLast == true || NetStatus != MSG_NETWORK_SEND_SUCCESS) {
89                 /** Update Msg Status */
90                 if (sentInfo.reqInfo.msgInfo.msgPort.valid == false) {
91                         /*SmsPluginStorage::instance()->updateSentMsg(&(sentInfo.reqInfo.msgInfo), NetStatus); */
92
93                         sentInfo.reqInfo.msgInfo.networkStatus = NetStatus;
94
95                         if (NetStatus == MSG_NETWORK_SEND_SUCCESS) {
96                                 /* contacts-service is not used for gear */
97 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
98                                 MSG_DEBUG("Add phone log");
99                                 MsgAddPhoneLog(&(sentInfo.reqInfo.msgInfo));
100 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
101                                 sentInfo.reqInfo.msgInfo.folderId = MSG_SENTBOX_ID; /* It should be set after adding phone log. */
102                                 /* Send system event */
103                                 bundle *b = NULL;
104                                 b = bundle_create();
105                                 if (b) {
106                                         if (sentInfo.reqInfo.msgInfo.msgType.mainType == MSG_SMS_TYPE)
107                                                 bundle_add_str(b, EVT_KEY_OUT_MSG_TYPE, EVT_VAL_SMS);
108                                         else
109                                                 bundle_add_str(b, EVT_KEY_OUT_MSG_TYPE, EVT_VAL_MMS);
110
111                                         char msgId[MSG_EVENT_MSG_ID_LEN] = {0, };
112                                         snprintf(msgId, sizeof(msgId), "%u", sentInfo.reqInfo.msgInfo.msgId);
113                                         bundle_add_str(b, EVT_KEY_OUT_MSG_ID, msgId);
114                                         eventsystem_send_system_event(SYS_EVENT_OUTGOING_MSG, b);
115                                         bundle_add_str(b, "cmd", "outgoing_msg");
116                                         int ret = aul_launch_app_for_uid("org.tizen.msg-manager", b, msg_get_login_user());
117                                         if (ret <= 0) {
118                                                 MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
119                                         }
120                                         bundle_free(b);
121                                 }
122                         } else {
123                                 sentInfo.reqInfo.msgInfo.bRead = false;
124                         }
125
126                         SmsPluginStorage::instance()->updateSmsMessage(&(sentInfo.reqInfo.msgInfo));
127
128                         callbackStorageChange(MSG_STORAGE_CHANGE_UPDATE, &(sentInfo.reqInfo.msgInfo));
129                 }
130
131                 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bSetting [%d]", sentInfo.reqInfo.sendOptInfo.bSetting);
132                 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bKeepCopy [%d]", sentInfo.reqInfo.sendOptInfo.bKeepCopy);
133                 /** Check sending options */
134                 if (sentInfo.reqInfo.sendOptInfo.bSetting && !sentInfo.reqInfo.sendOptInfo.bKeepCopy && NetStatus == MSG_NETWORK_SEND_SUCCESS) {
135                         SmsPluginStorage::instance()->deleteSmsMessage(sentInfo.reqInfo.msgInfo.msgId);
136                         callbackStorageChange(MSG_STORAGE_CHANGE_DELETE, &(sentInfo.reqInfo.msgInfo));
137                 }
138
139                 /** Callback to MSG FW */
140                 MSG_SENT_STATUS_S msgStatus;
141
142                 msgStatus.reqId = sentInfo.reqInfo.reqId;
143                 msgStatus.status = NetStatus;
144
145                 MSG_DEBUG("sentStatus.reqId : %d", msgStatus.reqId);
146                 MSG_DEBUG("sentStatus.status : %d", msgStatus.status);
147
148                 listener.pfSentStatusCb(&msgStatus);
149         }
150 }
151
152
153 void SmsPluginEventHandler::handleMsgIncoming(TapiHandle *handle, SMS_TPDU_S *pTpdu)
154 {
155         /** Make MSG_MESSAGE_INFO_S */
156         MSG_MESSAGE_INFO_S msgInfo;
157         MSG_MESSAGE_INFO_S stored_msgInfo;
158
159         /** initialize msgInfo */
160         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
161
162         msgInfo.addressList = NULL;
163         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
164
165
166         if (pTpdu->tpduType == SMS_TPDU_DELIVER) {
167                 /** check unsupported message */
168                 if (pTpdu->data.deliver.dcs.codingScheme == SMS_CHARSET_8BIT && pTpdu->data.deliver.pid == 0x11) {
169                         MSG_DEBUG("Unsupported message!!");
170                         SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
171                         return;
172                 }
173         }
174
175         bUdhMwiMethod = false;
176         udhMwiCnt = 0;
177
178         if (pTpdu->data.deliver.dcs.msgClass == SMS_MSG_CLASS_2)
179                 msgInfo.storageId = MSG_STORAGE_UNKNOWN;
180         else
181                 msgInfo.storageId = MSG_STORAGE_PHONE;
182
183         msgInfo.sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
184
185         /** convert to msgInfo */
186         convertTpduToMsginfo(pTpdu, &msgInfo);
187
188         if (msgInfo.msgPort.valid == true) {
189                 if ((msgInfo.msgPort.dstPort >= 0x23F4 && msgInfo.msgPort.dstPort <= 0x23F7) || /** Check unsupported message (Vcard WAP push) **/
190                         (msgInfo.msgPort.dstPort == 0x1581)) { /** Check unsupported message (ringtone smart message) **/
191                         memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
192                         snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "<Unsupported message>");
193                         msgInfo.dataSize = strlen(msgInfo.msgText);
194                         msgInfo.msgPort.valid = false;
195                 }
196         }
197
198         bool bStoreVoiceMsg = false;
199
200         if (bUdhMwiMethod == false) {
201                 /** check MWI and set info to SIM for DCS & Address method */
202                 if (pTpdu->tpduType == SMS_TPDU_DELIVER && pTpdu->data.deliver.dcs.bMWI == true) {
203                         int MwiCnt = 0;
204                         MSG_DEBUG("MWI message - DCS method");
205
206                         if (pTpdu->data.deliver.dcs.bIndActive == false) {
207                                 SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 0);
208                                 MwiCnt = 0;
209                         } else {
210                                 SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 1);
211                                 MwiCnt = 1;
212
213                                 /* For address method */
214                                 if (pTpdu->data.deliver.pid == 0x20 && pTpdu->data.deliver.originAddress.ton == SMS_TON_ALPHANUMERIC) {
215                                         MSG_DEBUG("MWI message - Address method");
216                                         char *voiceNumber = NULL;
217                                         char *voiceAlphaId = NULL;
218                                         char keyName[MAX_VCONFKEY_NAME_LEN];
219
220                                         memset(keyName, 0x00, sizeof(keyName));
221                                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msgInfo.sim_idx);
222                                         if (MsgSettingGetString(keyName, &voiceNumber) != MSG_SUCCESS) {
223                                                 MSG_INFO("MsgSettingGetString() is failed");
224                                         }
225
226                                         memset(keyName, 0x00, sizeof(keyName));
227                                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msgInfo.sim_idx);
228                                         if (MsgSettingGetString(keyName, &voiceAlphaId) != MSG_SUCCESS) {
229                                                 MSG_INFO("MsgSettingGetString() is failed");
230                                         }
231
232                                         memset(msgInfo.addressList[0].addressVal, 0x00, sizeof(msgInfo.addressList[0].addressVal));
233                                         memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
234
235                                         if (voiceNumber) {
236                                                 snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), "%s", voiceNumber);
237                                                 free(voiceNumber);
238                                                 voiceNumber = NULL;
239                                         }
240
241                                         if (voiceAlphaId) {
242                                                 snprintf(msgInfo.addressList[0].displayName, sizeof(msgInfo.addressList[0].displayName), "%s", voiceAlphaId);
243                                                 free(voiceAlphaId);
244                                                 voiceAlphaId = NULL;
245                                         }
246                                 }
247                         }
248
249                         if (pTpdu->data.deliver.dcs.codingGroup == SMS_GROUP_STORE) {
250                                 bStoreVoiceMsg = true;
251                                 memset(&stored_msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
252                                 memcpy(&stored_msgInfo, &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
253                                 stored_msgInfo.msgType.subType = MSG_NORMAL_SMS;
254                         }
255
256                         memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
257                         switch (msgInfo.msgType.subType) {
258                         case MSG_MWI_VOICE_SMS :
259                                 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d", MwiCnt);
260                                 break;
261                         case MSG_MWI_FAX_SMS :
262                                 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new fax message", MwiCnt);
263                                 break;
264                         case MSG_MWI_EMAIL_SMS :
265                                 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new email message", MwiCnt);
266                                 break;
267                         default :
268                                 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new special message", MwiCnt);
269                                 break;
270                         }
271                         msgInfo.dataSize = strlen(msgInfo.msgText);
272
273                         if (pTpdu->data.deliver.dcs.codingGroup == SMS_GROUP_DISCARD)
274                                 msgInfo.bStore = false;
275                 }
276         }
277
278         /** Short Message Type 0 - Just Send Deliver Report */
279         if (msgInfo.msgType.subType == MSG_TYPE0_SMS) {
280                 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
281                 return;
282         }
283
284         /** Print MSG_MESSAGE_INFO_S */
285         MSG_DEBUG("############# Convert  tpdu values to Message Info values ####################");
286         MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
287         if (msgInfo.nAddressCnt > 0) {
288                 MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
289                 MSG_SEC_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
290                 MSG_SEC_DEBUG("msgInfo.addressList[0].displayName : %s", msgInfo.addressList[0].displayName);
291         }
292         MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
293         MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
294         MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
295         MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
296         MSG_DEBUG("msgInfo.bStore : %d", msgInfo.bStore);
297         MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
298         MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
299         MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
300         MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
301         MSG_DEBUG("msgInfo.displayTime : %d", msgInfo.displayTime);
302         MSG_DEBUG("msgInfo.msgPort.valid : %d", msgInfo.msgPort.valid);
303         MSG_DEBUG("msgInfo.encodeType : %d", msgInfo.encodeType);
304         MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
305         MSG_DEBUG("msgInfo.sim_idx : %d", msgInfo.sim_idx);
306
307         if (msgInfo.bTextSms == true) {
308                 MSG_SEC_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
309         } else {
310                 MSG_SEC_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
311         }
312
313         MSG_DEBUG("###############################################################");
314
315         msg_error_t err = MSG_SUCCESS;
316
317         if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS) {
318                 /** Status Report Message */
319                 err = SmsPluginStorage::instance()->updateMsgDeliverStatus(&msgInfo, pTpdu->data.statusRep.msgRef);
320
321                 if (err == MSG_SUCCESS)
322                         err = listener.pfMsgIncomingCb(&msgInfo);
323                 else
324                         MSG_DEBUG("updateMsgDeliverStatus is failed [%d]", err);
325
326                 /** Handling of Fail Case ?? */
327                 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
328         } else { /** SMS Deliver */
329                 /** Class 2 Msg */
330                 if (msgInfo.msgType.classType == MSG_CLASS_2) {
331                         if (msgInfo.bTextSms == false) { /** Concat Msg cannot be saved in SIM */
332                                 msgInfo.msgType.classType = MSG_CLASS_NONE;
333                                 msgInfo.storageId = MSG_STORAGE_PHONE;
334                         } else {
335                                 /** set total segment of Class2 message as 1 */
336                                 SmsPluginSimMsg::instance()->setSmsTpduTotalSegCount(1);
337                         }
338                 }
339
340                 /** Add message to DB */
341                 if (msgInfo.msgPort.valid == false) {
342                         err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
343                 }
344
345                 /** Callback to MSG FW */
346                 if (msgInfo.msgType.classType == MSG_CLASS_2) {
347                         if (((msgInfo.msgType.subType >= MSG_MWI_VOICE_SMS) && (msgInfo.msgType.subType <= MSG_MWI_OTHER_SMS)) &&
348                                         (msgInfo.bStore == false)) {
349                                 if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
350                                         MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
351
352                                 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
353                         }
354                 } else {
355                         if (err == MSG_SUCCESS) {
356                                 MSG_DEBUG("callback to msg fw");
357                                 err = listener.pfMsgIncomingCb(&msgInfo);
358                                 if (bStoreVoiceMsg) {
359                                         err = listener.pfMsgIncomingCb(&stored_msgInfo);
360                                 }
361                         } else {
362                                 if (msgInfo.msgType.classType == MSG_CLASS_0) {
363                                         MSG_DEBUG("callback for class0 message to msg fw");
364                                         if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
365                                                 MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
366                                 }
367                         }
368
369                         /** Send Deliver Report */
370                         if (msgInfo.msgType.classType == MSG_CLASS_0)
371                                 SmsPluginTransport::instance()->sendClass0DeliverReport(handle, err);
372                         else
373                                 SmsPluginTransport::instance()->sendDeliverReport(handle, err);
374                 }
375
376                 /* Tizen Validation System */
377                 char *msisdn = NULL;
378                 char keyName[MAX_VCONFKEY_NAME_LEN];
379                 memset(keyName, 0x00, sizeof(keyName));
380                 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, msgInfo.sim_idx);
381                 if (MsgSettingGetString(keyName, &msisdn) != MSG_SUCCESS) {
382                         MSG_INFO("MsgSettingGetString() is failed");
383                 }
384
385                 MSG_SMS_VLD_INFO("%d, SMS Receive, %s->%s, %s",  msgInfo.msgId, \
386                                                                                                                                 msgInfo.addressList[0].addressVal, \
387                                                                                                                                 (msisdn == NULL)?"ME":msisdn, \
388                                                                                                                                 (err == MSG_SUCCESS)?"Success":"Fail");
389
390                 MSG_SMS_VLD_TXT("%d, [%s]", msgInfo.msgId, msgInfo.msgText);
391
392                 if (msisdn) {
393                         free(msisdn);
394                         msisdn = NULL;
395                 }
396         }
397 }
398
399 void SmsPluginEventHandler::handlePushMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen, char *application_id, char *content_type)
400 {
401         MSG_PUSH_MESSAGE_DATA_S pushData;
402
403         memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
404
405         /** set PUSH data */
406         memcpy(pushData.pushHeader, pPushHeader, strlen(pPushHeader));
407
408         pushData.pushBodyLen = pushBodyLen;
409         memcpy(pushData.pushBody, pPushBody, pushBodyLen);
410
411         memcpy(pushData.pushAppId, application_id, MAX_WAPPUSH_ID_LEN);
412         memcpy(pushData.pushContentType, content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN);
413
414         /** Callback to MSG FW */
415         listener.pfPushMsgIncomingCb(&pushData);
416 }
417
418
419 void SmsPluginEventHandler::handleResendMessage(void)
420 {
421         listener.pfResendMessageCb();
422 }
423
424
425 void SmsPluginEventHandler::handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, int simIndex)
426 {
427         MSG_SYNCML_MESSAGE_DATA_S syncMLData;
428
429         memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
430
431         /** set syncML data */
432         syncMLData.syncmlType = msgType;
433
434         syncMLData.simIndex = simIndex;
435
436         syncMLData.pushBodyLen = PushBodyLen;
437         memcpy(syncMLData.pushBody, pPushBody, PushBodyLen);
438
439         syncMLData.wspHeaderLen = WspHeaderLen;
440         memcpy(syncMLData.wspHeader, pWspHeader, WspHeaderLen);
441
442         /** Callback to MSG FW */
443         listener.pfSyncMLMsgIncomingCb(&syncMLData);
444 }
445
446
447 void SmsPluginEventHandler::handleLBSMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen)
448 {
449         MSG_LBS_MESSAGE_DATA_S lBSData;
450
451         memset(&lBSData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
452
453         /** set LBA data */
454         memcpy(lBSData.pushHeader, pPushHeader, strlen(pPushHeader));
455
456         lBSData.pushBodyLen = pushBodyLen;
457         memcpy(lBSData.pushBody, pPushBody, pushBodyLen);
458
459         /** Callback to MSG FW */
460         listener.pfLBSMsgIncomingCb(&lBSData);
461 }
462
463 msg_error_t SmsPluginEventHandler::callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgInfo)
464 {
465         MSG_BEGIN();
466
467         msg_error_t err = MSG_SUCCESS;
468
469         /** Callback to MSG FW */
470         err = listener.pfMsgIncomingCb(pMsgInfo);
471
472         MSG_END();
473
474         return err;
475 }
476
477 msg_error_t SmsPluginEventHandler::callbackCBMsgIncoming(MSG_CB_MSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
478 {
479         MSG_BEGIN();
480
481         msg_error_t err = MSG_SUCCESS;
482
483         /** Callback to MSG FW */
484         err = listener.pfCBMsgIncomingCb(pCbMsg, pMsgInfo);
485
486         MSG_END();
487
488         return err;
489 }
490
491
492 msg_error_t SmsPluginEventHandler::callbackInitSimBySat()
493 {
494         /** Callback to MSG FW */
495         return listener.pfInitSimBySatCb();
496 }
497
498
499 msg_error_t SmsPluginEventHandler::callbackStorageChange(msg_storage_change_type_t storageChangeType, MSG_MESSAGE_INFO_S *pMsgInfo)
500 {
501         msg_id_list_s msgIdList;
502         msg_message_id_t msgIds[1];
503         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
504
505         msgIdList.nCount = 1;
506         msgIds[0] = pMsgInfo->msgId;
507         msgIdList.msgIdList = msgIds;
508
509         /* Callback to MSG FW */
510         listener.pfStorageChangeCb(storageChangeType, &msgIdList);
511
512         return MSG_SUCCESS;
513 }
514
515
516 void SmsPluginEventHandler::convertTpduToMsginfo(SMS_TPDU_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
517 {
518         switch (pTpdu->tpduType) {
519         case SMS_TPDU_SUBMIT :
520                 convertSubmitTpduToMsginfo(&pTpdu->data.submit, msgInfo);
521                 break;
522         case SMS_TPDU_DELIVER :
523                 convertDeliverTpduToMsginfo(&pTpdu->data.deliver, msgInfo);
524                 break;
525         case SMS_TPDU_STATUS_REP :
526                 convertStatusRepTpduToMsginfo(&pTpdu->data.statusRep, msgInfo);
527                 break;
528         }
529 }
530
531
532 void SmsPluginEventHandler::convertSubmitTpduToMsginfo(const SMS_SUBMIT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
533 {
534         int addressListCnt = 0;
535
536         /** Convert Type  values */
537         msgInfo->msgType.mainType = MSG_SMS_TYPE;
538         msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
539
540         /** set folder id (temporary) */
541         msgInfo->folderId = MSG_SENTBOX_ID;
542
543         switch (pTpdu->dcs.msgClass) {
544         case SMS_MSG_CLASS_0:
545                 msgInfo->msgType.classType = MSG_CLASS_0;
546                 break;
547         case SMS_MSG_CLASS_1:
548                 msgInfo->msgType.classType = MSG_CLASS_1;
549                 break;
550         case SMS_MSG_CLASS_2:
551                 msgInfo->msgType.classType = MSG_CLASS_2;
552                 break;
553         case SMS_MSG_CLASS_3:
554                 msgInfo->msgType.classType = MSG_CLASS_3;
555                 break;
556         default:
557                 msgInfo->msgType.classType = MSG_CLASS_NONE;
558                 break;
559         }
560
561         msgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
562         msgInfo->bRead = false;
563         msgInfo->bProtected = false;
564         msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
565         msgInfo->direction = MSG_DIRECTION_TYPE_MO;
566         msgInfo->bTextSms = true;
567
568         memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
569
570         /** What kind of time has to be saved?? (temporary store time) */
571         msgInfo->displayTime = time(NULL);
572
573         /** Convert Address values */
574         msgInfo->nAddressCnt = 1;
575
576         msgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
577         memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
578
579         msgInfo->addressList[addressListCnt].addressType = MSG_ADDRESS_TYPE_PLMN;
580         strncpy(msgInfo->addressList[addressListCnt].addressVal, pTpdu->destAddress.address, MAX_ADDRESS_VAL_LEN);
581
582         /**exception operation for none userdata */
583         if (pTpdu->userData.length == 0) {
584                 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "[Broken Message]");
585                 msgInfo->dataSize = strlen(msgInfo->msgText);
586                 return;
587         }
588
589         /** Convert Data values */
590         MsgTextConvert *textCvt = MsgTextConvert::instance();
591         if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
592                 MSG_LANG_INFO_S langInfo = {0, };
593
594                 langInfo.bSingleShift = false;
595                 langInfo.bLockingShift = false;
596
597                 msgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
598         } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
599                 msgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
600         }
601 }
602
603
604 void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
605 {
606         MSG_BEGIN();
607
608         /** Convert Type  values */
609         msgInfo->msgType.mainType = MSG_SMS_TYPE;
610         msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
611
612         /** set folder id (temporary) */
613         msgInfo->folderId = MSG_INBOX_ID;
614
615         time_t rawtime = 0;
616         if (msgInfo->storageId == MSG_STORAGE_SIM) {
617         /*** Comment below lines to save local UTC time..... (it could be used later.)
618         ***/
619                 if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
620                         MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
621                         MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
622                         MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
623                         MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
624                         MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
625                         MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
626                         MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
627
628                         char displayTime[32];
629                         struct tm timeTM;
630
631                         struct tm timeinfo;
632                         memset(&timeinfo, 0x00, sizeof(tm));
633
634                         timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
635                         timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
636                         timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
637                         timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
638                         timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
639                         timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
640                         timeinfo.tm_isdst = 0;
641
642                         rawtime = mktime(&timeinfo);
643
644                         MSG_DEBUG("tzname[0] [%s]", tzname[0]);
645                         MSG_DEBUG("tzname[1] [%s]", tzname[1]);
646                         MSG_DEBUG("timezone [%d]", timezone);
647                         MSG_DEBUG("daylight [%d]", daylight);
648
649                         memset(displayTime, 0x00, sizeof(displayTime));
650                         strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
651                         MSG_DEBUG("displayTime [%s]", displayTime);
652
653                         rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
654
655                         localtime_r(&rawtime, &timeTM);
656                         memset(displayTime, 0x00, sizeof(displayTime));
657                         strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeTM);
658                         MSG_DEBUG("displayTime [%s]", displayTime);
659
660                         rawtime -= timezone;
661
662                         localtime_r(&rawtime, &timeTM);
663                         memset(displayTime, 0x00, sizeof(displayTime));
664                         strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeTM);
665                         MSG_DEBUG("displayTime [%s]", displayTime);
666                 }
667         }
668         else
669                 rawtime = time(NULL);
670
671         msgInfo->displayTime = rawtime;
672
673         switch (pTpdu->dcs.msgClass) {
674         case SMS_MSG_CLASS_0:
675                 msgInfo->msgType.classType = MSG_CLASS_0;
676                 break;
677         case SMS_MSG_CLASS_1:
678                 msgInfo->msgType.classType = MSG_CLASS_1;
679                 break;
680         case SMS_MSG_CLASS_2:
681                 msgInfo->msgType.classType = MSG_CLASS_2;
682                 msgInfo->storageId = MSG_STORAGE_SIM;
683                 break;
684         case SMS_MSG_CLASS_3:
685                 msgInfo->msgType.classType = MSG_CLASS_3;
686                 break;
687         default:
688                 msgInfo->msgType.classType = MSG_CLASS_NONE;
689                 break;
690         }
691
692         if (pTpdu->dcs.bMWI) {
693                 if (pTpdu->dcs.indType == SMS_VOICE_INDICATOR)
694                         msgInfo->msgType.subType = MSG_MWI_VOICE_SMS;
695                 else if (pTpdu->dcs.indType == SMS_VOICE2_INDICATOR)
696                         msgInfo->msgType.subType = MSG_MWI_VOICE2_SMS;
697                 else if (pTpdu->dcs.indType == SMS_FAX_INDICATOR)
698                         msgInfo->msgType.subType = MSG_MWI_FAX_SMS;
699                 else if (pTpdu->dcs.indType == SMS_EMAIL_INDICATOR)
700                         msgInfo->msgType.subType = MSG_MWI_EMAIL_SMS;
701                 else if (pTpdu->dcs.indType == SMS_OTHER_INDICATOR)
702                         msgInfo->msgType.subType = MSG_MWI_OTHER_SMS;
703         }
704
705         msgInfo->networkStatus = MSG_NETWORK_RECEIVED;
706         msgInfo->bRead = false;
707         msgInfo->bProtected = false;
708         msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
709         msgInfo->direction = MSG_DIRECTION_TYPE_MT;
710         msgInfo->bTextSms = true;
711
712         memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
713
714         /** Convert Address values */
715         msgInfo->nAddressCnt = 1;
716
717         msgInfo->addressList =  (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
718         memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
719
720         msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
721         strncpy(msgInfo->addressList[0].addressVal, pTpdu->originAddress.address, MAX_ADDRESS_VAL_LEN);
722
723         msgInfo->msgPort.valid = false;
724         msgInfo->msgPort.dstPort = 0;
725         msgInfo->msgPort.srcPort = 0;
726
727         for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
728                 /** Convert UDH values - Port Number */
729                 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
730                         msgInfo->msgPort.valid = true;
731                         msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
732                         msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
733                 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
734                         msgInfo->msgPort.valid = true;
735                         msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
736                         msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
737                 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_SPECIAL_SMS) {
738                         msgInfo->msgType.subType = (pTpdu->userData.header[i].udh.specialInd.msgInd+MSG_MWI_VOICE_SMS);
739                         msgInfo->bStore = pTpdu->userData.header[i].udh.specialInd.bStore;
740
741                         bUdhMwiMethod = true;
742
743                         if (pTpdu->dcs.codingGroup == SMS_GROUP_DISCARD)
744                                 msgInfo->bStore = false;
745
746                         udhMwiCnt = pTpdu->userData.header[i].udh.specialInd.waitMsgNum;
747
748                         if (udhMwiCnt < 0) {
749                                 MSG_DEBUG("Message waiting number is smaller than 0. It will be treated as 0. [%d]", udhMwiCnt);
750                                 udhMwiCnt = 0;
751                         }
752
753                         MSG_DEBUG("Message waiting number : [%d]", udhMwiCnt);
754
755                         SmsPluginSetting::instance()->setMwiInfo(msgInfo->sim_idx, msgInfo->msgType.subType, udhMwiCnt);
756
757                         if (udhMwiCnt > 0 && (msgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && msgInfo->msgType.subType <= MSG_MWI_OTHER_SMS)) {
758                                 switch (msgInfo->msgType.subType) {
759                                 case MSG_MWI_VOICE_SMS :
760                                         snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d", udhMwiCnt);
761                                         break;
762                                 case MSG_MWI_FAX_SMS :
763                                         snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new fax message", udhMwiCnt);
764                                         break;
765                                 case MSG_MWI_EMAIL_SMS :
766                                         snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new email message", udhMwiCnt);
767                                         break;
768                                 default :
769                                         snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new special message", udhMwiCnt);
770                                         break;
771                                 }
772                                 msgInfo->dataSize = strlen(msgInfo->msgText);
773                                 return;
774                         }
775                 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_ALTERNATE_REPLY_ADDRESS) {
776                         strncpy(msgInfo->addressList[0].addressVal, pTpdu->userData.header[i].udh.alternateAddress.address, MAX_ADDRESS_VAL_LEN);
777                 } else if (pTpdu->userData.header[i].udhType >= SMS_UDH_EMS_FIRST && pTpdu->userData.header[i].udhType <= SMS_UDH_EMS_LAST) {
778                         /* TODO: Raw text should be changed to string design id. Currently there's no design id in message-app-lite */
779 /*                      char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSGF_POP_ERROR_UNSUPPORTED_MSG");
780                         snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%s", msg_text);
781 */
782                         snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "Unsupported Message");
783                         msgInfo->dataSize = strlen(msgInfo->msgText);
784 /*                      if (msg_text) {
785                                 free(msg_text);
786                                 msg_text = NULL;
787                         }
788 */
789                         return;
790                 }
791         }
792
793         /**length 0 - no user data - msg should be received */
794         if (pTpdu->userData.length <= 0) {
795                 memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
796                 msgInfo->dataSize = 0;
797
798                 switch (pTpdu->dcs.codingScheme) {
799                 case SMS_CHARSET_7BIT:
800                         msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
801                         break;
802                 case SMS_CHARSET_8BIT:
803                         msgInfo->encodeType = MSG_ENCODE_8BIT;
804                         break;
805                 case SMS_CHARSET_UCS2:
806                         msgInfo->encodeType = MSG_ENCODE_UCS2;
807                         break;
808                 default:
809                         msgInfo->encodeType = MSG_ENCODE_8BIT;
810                         break;
811                 }
812
813                 return;
814         } else if (pTpdu->userData.length > MAX_MSG_TEXT_LEN) {
815                 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "[Broken Message]");
816                 msgInfo->dataSize = strlen(msgInfo->msgData);
817                 return;
818         }
819
820         /** Convert Data values */
821         MsgTextConvert *textCvt = MsgTextConvert::instance();
822         if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
823                 MSG_LANG_INFO_S langInfo = {0, };
824
825                 langInfo.bSingleShift = false;
826                 langInfo.bLockingShift = false;
827
828                 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
829                         if (pTpdu->userData.header[i].udhType == SMS_UDH_SINGLE_SHIFT) {
830                                 langInfo.bSingleShift = true;
831                                 langInfo.singleLang = pTpdu->userData.header[i].udh.singleShift.langId;
832                         } else if (pTpdu->userData.header[i].udhType == SMS_UDH_LOCKING_SHIFT) {
833                                 langInfo.bLockingShift = true;
834                                 langInfo.lockingLang = pTpdu->userData.header[i].udh.lockingShift.langId;
835                         }
836                 }
837
838                 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
839                 msgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
840         } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_8BIT) {
841                 msgInfo->encodeType = MSG_ENCODE_8BIT;
842                 memcpy(msgInfo->msgText, pTpdu->userData.data, sizeof(pTpdu->userData.data));
843                 msgInfo->dataSize = pTpdu->userData.length;
844         } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
845                 msgInfo->encodeType = MSG_ENCODE_UCS2;
846                 msgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
847         } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_EUCKR) {
848                 msgInfo->encodeType = MSG_ENCODE_8BIT;
849                 msgInfo->dataSize = textCvt->convertEUCKRToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
850                 return;
851         }
852
853         MSG_END();
854 }
855
856
857 void SmsPluginEventHandler::convertStatusRepTpduToMsginfo(const SMS_STATUS_REPORT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
858 {
859         /** Convert Type  values */
860         msgInfo->msgType.mainType = MSG_SMS_TYPE;
861         msgInfo->msgType.subType = MSG_STATUS_REPORT_SMS;
862
863         /** set folder id */
864         msgInfo->folderId = MSG_INBOX_ID;
865
866         /** set storage id */
867         if (msgInfo->storageId == MSG_STORAGE_UNKNOWN) {
868                 msgInfo->storageId = MSG_STORAGE_PHONE;
869         }
870
871         switch (pTpdu->dcs.msgClass) {
872         case SMS_MSG_CLASS_0:
873                 msgInfo->msgType.classType = MSG_CLASS_0;
874                 break;
875         case SMS_MSG_CLASS_1:
876                 msgInfo->msgType.classType = MSG_CLASS_1;
877                 break;
878         case SMS_MSG_CLASS_2:
879                 msgInfo->msgType.classType = MSG_CLASS_2;
880                 break;
881         case SMS_MSG_CLASS_3:
882                 msgInfo->msgType.classType = MSG_CLASS_3;
883                 break;
884         default:
885                 msgInfo->msgType.classType = MSG_CLASS_NONE;
886                 break;
887         }
888
889         MSG_DEBUG("delivery status : [%d]", pTpdu->status);
890
891         if (pTpdu->status == SMS_STATUS_RECEIVE_SUCCESS)
892                 msgInfo->networkStatus = MSG_NETWORK_DELIVER_SUCCESS;
893         else if (pTpdu->status == SMS_STATUS_TRY_REQUEST_PENDING)
894                 msgInfo->networkStatus = MSG_NETWORK_DELIVER_PENDING;
895         else if (pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED)
896                 msgInfo->networkStatus = MSG_NETWORK_DELIVER_EXPIRED;
897         else
898                 msgInfo->networkStatus = MSG_NETWORK_DELIVER_FAIL;
899
900         msgInfo->bRead = false;
901         msgInfo->bProtected = false;
902         msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
903         msgInfo->direction = MSG_DIRECTION_TYPE_MT;
904         msgInfo->bTextSms = true;
905
906         memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
907
908         msgInfo->displayTime = time(NULL);
909
910         /** Convert Address values */
911         msgInfo->nAddressCnt = 1;
912
913         msgInfo->addressList =  (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
914         memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
915
916         msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
917         strncpy(msgInfo->addressList[0].addressVal, pTpdu->recipAddress.address, MAX_ADDRESS_VAL_LEN);
918
919         msgInfo->msgPort.valid = false;
920         msgInfo->msgPort.dstPort = 0;
921         msgInfo->msgPort.srcPort = 0;
922
923         for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
924                 /** Convert UDH values - Port Number */
925                 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
926                         msgInfo->msgPort.valid = true;
927                         msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
928                         msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
929                 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
930                         msgInfo->msgPort.valid = true;
931                         msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
932                         msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
933                 }
934         }
935
936         memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
937         msgInfo->dataSize = 0;
938
939         if (pTpdu->status <= SMS_STATUS_SMSC_SPECIFIC_LAST) {
940                 char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSGF_BODY_MESSAGE_DELIVERED");
941                 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%s", msg_text);
942                 msgInfo->dataSize = strlen(msgInfo->msgText);
943                 if (msg_text) {
944                         free(msg_text);
945                         msg_text = NULL;
946                 }
947         } else if (pTpdu->status == SMS_STATUS_TEMP_SERVICE_REJECTED) {
948                 char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSGF_BODY_MMSDELIVERYMSGREJECTED");
949                 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%s", msg_text);
950                 msgInfo->dataSize = strlen(msgInfo->msgText);
951                 if (msg_text) {
952                         free(msg_text);
953                         msg_text = NULL;
954                 }
955         } else if (pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED) {
956                 char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSGF_BODY_MESSAGE_HAS_EXPIRED");
957                 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%s", msg_text);
958                 msgInfo->dataSize = strlen(msgInfo->msgText);
959                 if (msg_text) {
960                         free(msg_text);
961                         msg_text = NULL;
962                 }
963         } else {
964                 strncpy(msgInfo->msgText, "Message delivery failed.", MAX_MSG_TEXT_LEN);
965                 msgInfo->dataSize = strlen(msgInfo->msgText);
966         }
967 }
968
969
970 MSG_SUB_TYPE_T SmsPluginEventHandler::convertMsgSubType(SMS_PID_T pid)
971 {
972         switch (pid) {
973         case SMS_PID_TYPE0 :
974                 return MSG_TYPE0_SMS;
975         case SMS_PID_REPLACE_TYPE1 :
976                 return MSG_REPLACE_TYPE1_SMS;
977         case SMS_PID_REPLACE_TYPE2 :
978                 return MSG_REPLACE_TYPE2_SMS;
979         case SMS_PID_REPLACE_TYPE3 :
980                 return MSG_REPLACE_TYPE3_SMS;
981         case SMS_PID_REPLACE_TYPE4 :
982                 return MSG_REPLACE_TYPE4_SMS;
983         case SMS_PID_REPLACE_TYPE5 :
984                 return MSG_REPLACE_TYPE5_SMS;
985         case SMS_PID_REPLACE_TYPE6 :
986                 return MSG_REPLACE_TYPE6_SMS;
987         case SMS_PID_REPLACE_TYPE7 :
988                 return MSG_REPLACE_TYPE7_SMS;
989         case SMS_PID_RETURN_CALL :
990                 return MSG_MWI_OTHER_SMS;
991         default :
992                 return MSG_NORMAL_SMS;
993         }
994 }
995
996
997 void SmsPluginEventHandler::SetSentInfo(SMS_SENT_INFO_S *pSentInfo)
998 {
999         memset(&sentInfo, 0x00, sizeof(SMS_SENT_INFO_S));
1000         memcpy(&sentInfo, pSentInfo, sizeof(SMS_SENT_INFO_S));
1001
1002         MSG_DEBUG("sentInfo.reqId : %d", sentInfo.reqInfo.reqId);
1003         MSG_DEBUG("sentInfo.bLast : %d", sentInfo.bLast);
1004 }
1005
1006
1007 void SmsPluginEventHandler::setDeviceStatus(TapiHandle *handle)
1008 {
1009         if (handle == devHandle) {
1010                 mx.lock();
1011                 devStatus = true;
1012                 cv.signal();
1013                 mx.unlock();
1014         }
1015 }
1016
1017
1018 bool SmsPluginEventHandler::getDeviceStatus(TapiHandle *handle)
1019 {
1020         int ret = 0;
1021
1022         mx.lock();
1023         devHandle = handle;
1024         ret = cv.timedwait(mx.pMsgMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1025
1026         if (ret == ETIMEDOUT) {
1027                 MSG_WARN("WARNING: DEVICE STATUS TIME-OUT");
1028                 devStatus = false;
1029         }
1030         devHandle = NULL;
1031         mx.unlock();
1032         return devStatus;
1033 }
1034
1035
1036 msg_error_t SmsPluginEventHandler::handleSimMsg(MSG_MESSAGE_INFO_S *pMsgInfo, int *simIdList, msg_message_id_t *retMsgId, int listSize)
1037 {
1038         MSG_BEGIN();
1039
1040         msg_error_t err = MSG_SUCCESS;
1041
1042         /** Callback to MSG FW */
1043         err = listener.pfSimMsgIncomingCb(pMsgInfo, simIdList, retMsgId, listSize);
1044
1045         MSG_END();
1046
1047         return err;
1048 }
1049
1050 msg_error_t SmsPluginEventHandler::updateIMSI(int sim_idx)
1051 {
1052         MSG_BEGIN();
1053
1054         msg_error_t err = MSG_SUCCESS;
1055
1056         /** Callback to MSG FW */
1057         err = listener.pfSimInitImsiCb(sim_idx);
1058
1059         MSG_END();
1060
1061         return err;
1062 }
1063
1064 void SmsPluginEventHandler::handleSimMemoryFull(int simIndex)
1065 {
1066         char keyName[MAX_VCONFKEY_NAME_LEN];
1067         bool bSimSst = true;
1068         memset(keyName, 0x00, sizeof(keyName));
1069         snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SERVICE_TABLE, simIndex);
1070         if (MsgSettingGetBool(keyName, &bSimSst) != MSG_SUCCESS)
1071                 MSG_ERR("MsgSettingGetBool [%s] failed", keyName);
1072
1073         if (bSimSst == true)
1074                 MsgInsertTicker("Sim memory full. Delete some items", SMS_MESSAGE_SIM_MESSAGE_FULL, true, 0);
1075 }