2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <tr1/unordered_set>
26 #include "MsgCppTypes.h"
27 #include "MsgContact.h"
28 #include "MsgUtilFile.h"
30 #include "MsgUtilStorage.h"
31 #include "MsgGconfWrapper.h"
32 #include "MsgSqliteWrapper.h"
33 #include "MsgPluginManager.h"
34 #include "MsgStorageHandler.h"
35 #include "MsgNotificationWrapper.h"
36 #include "MsgDevicedWrapper.h"
37 #include "MsgTransManager.h"
42 /*==================================================================================================
44 ==================================================================================================*/
48 bool delNotiRunning = false;
52 bool delLogRunning = false;
55 /*==================================================================================================
57 ==================================================================================================*/
58 static gboolean resetNotification(void *pVoid)
62 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
70 /*==================================================================================================
71 FUNCTION IMPLEMENTATION
72 ==================================================================================================*/
74 msg_error_t MsgStoAddMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
78 msg_error_t err = MSG_SUCCESS;
80 unsigned int rowId = 0;
81 msg_thread_id_t convId = 0;
83 char sqlQuery[MAX_QUERY_LEN+1];
85 MsgDbHandler *dbHandle = getDbHandle();
87 dbHandle->beginTrans();
89 if (pMsg->nAddressCnt > 0) {
90 err = MsgStoAddAddress(dbHandle, pMsg, &convId);
92 if (err != MSG_SUCCESS) {
93 dbHandle->endTrans(false);
97 pMsg->threadId = convId;
100 if (pMsg->msgId > 0) {
104 err = dbHandle->getRowId(MSGFW_MESSAGE_TABLE_NAME, &rowId);
105 if (err != MSG_SUCCESS) {
106 dbHandle->endTrans(false);
109 pMsg->msgId = (msg_message_id_t)rowId;
114 char *pFileData = NULL;
115 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
118 if (pMsg->bTextSms == false) {
119 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
120 dbHandle->endTrans(false);
121 return MSG_ERR_STORAGE_ERROR;
124 MSG_DEBUG("file size [%d]", fileSize);
127 char keyName[MAX_VCONFKEY_NAME_LEN];
128 memset(keyName, 0x00, sizeof(keyName));
129 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, pMsg->sim_idx);
132 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
133 MSG_INFO("MsgSettingGetString() is failed");
137 memset(sqlQuery, 0x00, sizeof(sqlQuery));
139 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %u, %zu, %d, %d, %d, %d, %d, %d, %d, ?, '', '', ?, 0, %d, '%s', %d);",
140 MSGFW_MESSAGE_TABLE_NAME, rowId, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType,
141 (unsigned int)pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
142 0, pMsg->bBackup, pMsg->sim_idx, imsi, pMsg->bRestricted);
144 MSG_DEBUG("QUERY : %s", sqlQuery);
149 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
150 dbHandle->endTrans(false);
151 return MSG_ERR_DB_EXEC;
154 dbHandle->bindText(pMsg->subject, 1);
156 if (pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
157 dbHandle->bindText("", 2);
159 if (pMsg->bTextSms == false)
160 dbHandle->bindText(pFileData, 2);
162 dbHandle->bindText(pMsg->msgText, 2);
165 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
166 dbHandle->finalizeQuery();
167 dbHandle->endTrans(false);
168 return MSG_ERR_DB_EXEC;
171 dbHandle->finalizeQuery();
173 if (pMsg->msgType.subType != MSG_SENDREQ_MMS) {
174 err = MsgStoUpdateConversation(dbHandle, convId);
176 if (err != MSG_SUCCESS) {
177 dbHandle->endTrans(false);
183 /* In the case of MMS Message, load the MMS plugin to save MMS PDU */
184 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
185 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
186 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
188 dbHandle->endTrans(false);
189 return MSG_ERR_NULL_POINTER;
192 if (pFileData == NULL) {
193 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
194 dbHandle->endTrans(false);
195 return MSG_ERR_STORAGE_ERROR;
198 MSG_DEBUG("file size [%d]", fileSize);
201 err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
203 if (err != MSG_SUCCESS) {
204 dbHandle->endTrans(false);
205 return MSG_ERR_STORAGE_ERROR;
208 if (pMsg->msgType.subType == MSG_SENDREQ_MMS
209 || pMsg->msgType.subType == MSG_RETRIEVE_MMS
210 || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS
211 || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
212 MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
214 err = MsgStoUpdateMMSMessage(pMsg);
216 if (err != MSG_SUCCESS) {
217 dbHandle->endTrans(false);
218 return MSG_ERR_STORAGE_ERROR;
222 } else if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL) {
223 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
225 dbHandle->endTrans(false);
226 return MSG_ERR_NULL_POINTER;
228 err = plg->addMessage(pMsg, pSendOptInfo, NULL);
229 if (err != MSG_SUCCESS) {
230 dbHandle->endTrans(false);
231 return MSG_ERR_STORAGE_ERROR;
235 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
236 char *pMmsSerializedData = NULL;
237 unique_ptr<char*, void(*)(char**)> buf_mms(&pMmsSerializedData, unique_ptr_deleter);
239 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
240 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
243 dbHandle->endTrans(false);
244 return MSG_ERR_NULL_POINTER;
247 if (MsgOpenAndReadFile(pMsg->msgData, &pMmsSerializedData, &fileSize) == false) {
248 dbHandle->endTrans(false);
249 return MSG_ERR_STORAGE_ERROR;
252 MSG_DEBUG("file size [%d]", fileSize);
254 err = plg->addMessage(pMsg, pSendOptInfo, pMmsSerializedData);
256 if (err != MSG_SUCCESS) {
257 dbHandle->endTrans(false);
258 return MSG_ERR_STORAGE_ERROR;
261 * if (pMsg->msgText[0] != '\0') {
262 * g_file_get_contents((gchar*)pMsg->msgText, (gchar**)&pFileData, (gsize*)&fileSize, NULL);
263 * MSG_DEBUG("file size [%d]", fileSize);
267 if (pMsg->msgType.subType == MSG_SENDREQ_MMS
268 || pMsg->msgType.subType == MSG_RETRIEVE_MMS
269 || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS
270 || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
271 MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
272 err = MsgStoUpdateMMSMessage(pMsg);
276 if (pMsg->bTextSms == false) {
277 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
278 dbHandle->endTrans(false);
279 return MSG_ERR_STORAGE_ERROR;
281 MSG_DEBUG("file size [%d]", fileSize);
285 dbHandle->endTrans(true);
293 msg_error_t MsgStoUpdateMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
295 msg_error_t err = MSG_SUCCESS;
297 char sqlQuery[MAX_QUERY_LEN+1];
299 msg_thread_id_t convId = 0;
300 MsgDbHandler *dbHandle = getDbHandle();
301 dbHandle->beginTrans();
303 MSG_MAIN_TYPE_T prevType;
304 memset(sqlQuery, 0x00, sizeof(sqlQuery));
305 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE FROM %s WHERE MSG_ID = %d;",
306 MSGFW_MESSAGE_TABLE_NAME, pMsg->msgId);
308 MSG_DEBUG("QUERY : %s", sqlQuery);
310 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
311 dbHandle->endTrans(false);
312 return MSG_ERR_DB_PREPARE;
315 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
316 dbHandle->finalizeQuery();
317 dbHandle->endTrans(false);
318 return MSG_ERR_STORAGE_ERROR;
321 prevType = dbHandle->columnInt(0);
322 dbHandle->finalizeQuery();
324 /* check msg type with previous type */
325 if (prevType != pMsg->msgType.mainType) {
326 MSG_DEBUG("different msg type to update [prev : %d], [current : %d]", prevType, pMsg->msgType.mainType);
328 err = MsgStoDeleteMessage(pMsg->msgId, false);
329 if (err != MSG_SUCCESS) {
330 dbHandle->endTrans(false);
334 err = MsgStoAddMessage(pMsg, pSendOptInfo);
335 if (err != MSG_SUCCESS) {
336 dbHandle->endTrans(false);
340 dbHandle->endTrans(false);
344 if (pMsg->nAddressCnt > 0) {
346 err = MsgStoAddAddress(dbHandle, pMsg, &convId);
348 if (err != MSG_SUCCESS) {
349 dbHandle->endTrans(false);
356 char *pFileData = NULL;
357 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
360 if (pMsg->bTextSms == false) {
361 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
362 dbHandle->endTrans(false);
363 return MSG_ERR_STORAGE_ERROR;
367 if (pSendOptInfo != NULL) {
368 /* Get Global setting value if bSetting == false */
369 if (pSendOptInfo->bSetting == false) {
370 if (MsgSettingGetBool(MSG_KEEP_COPY, &pSendOptInfo->bKeepCopy) != MSG_SUCCESS)
371 MSG_INFO("MsgSettingGetBool() is failed");
373 if (pMsg->msgType.mainType == MSG_SMS_TYPE) {
374 if (MsgSettingGetBool(SMS_SEND_DELIVERY_REPORT, &pSendOptInfo->bDeliverReq) != MSG_SUCCESS)
375 MSG_INFO("MsgSettingGetBool() is failed");
377 if (MsgSettingGetBool(SMS_SEND_REPLY_PATH, &pSendOptInfo->option.smsSendOptInfo.bReplyPath) != MSG_SUCCESS)
378 MSG_INFO("MsgSettingGetBool() is failed");
379 } else if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
380 if (MsgSettingGetBool(MMS_SEND_DELIVERY_REPORT, &pSendOptInfo->bDeliverReq) != MSG_SUCCESS)
381 MSG_INFO("MsgSettingGetBool() is failed");
383 if (MsgSettingGetBool(MMS_SEND_READ_REPLY, &pSendOptInfo->option.mmsSendOptInfo.bReadReq) != MSG_SUCCESS)
384 MSG_INFO("MsgSettingGetBool() is failed");
387 if (MsgSettingGetInt(MMS_SEND_EXPIRY_TIME, &tmpVal) != MSG_SUCCESS) {
388 MSG_INFO("MsgSettingGetInt() is failed");
390 pSendOptInfo->option.mmsSendOptInfo.expiryTime.time = (unsigned int)tmpVal;
392 if (MsgSettingGetInt(MMS_SEND_DELIVERY_TIME, &tmpVal) != MSG_SUCCESS) {
393 MSG_INFO("MsgSettingGetInt() is failed");
395 MSG_MMS_DELIVERY_TIME_T deliveryTime = (MSG_MMS_DELIVERY_TIME_T)tmpVal;
397 if (deliveryTime == MSG_DELIVERY_TIME_CUSTOM) {
398 pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime = true;
399 if (MsgSettingGetInt(MMS_SEND_CUSTOM_DELIVERY, &tmpVal) != MSG_SUCCESS) {
400 MSG_INFO("MsgSettingGetInt() is failed");
402 pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = (unsigned int)tmpVal;
404 pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime = false;
405 pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = (unsigned int)deliveryTime;
408 if (MsgSettingGetInt(MMS_SEND_PRIORITY, &tmpVal) != MSG_SUCCESS) {
409 MSG_INFO("MsgSettingGetInt() is failed");
411 pSendOptInfo->option.mmsSendOptInfo.priority = (msg_priority_type_t)tmpVal;
417 memset(sqlQuery, 0x00, sizeof(sqlQuery));
419 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET CONV_ID = %d, FOLDER_ID = %d, STORAGE_ID = %d, MAIN_TYPE = %d, SUB_TYPE = %d, \
420 DISPLAY_TIME = %lu, DATA_SIZE = %zu, NETWORK_STATUS = %d, READ_STATUS = %d, PROTECTED = %d, PRIORITY = %d, MSG_DIRECTION = %d, \
421 BACKUP = %d, SUBJECT = ?, MSG_TEXT = ? \
423 MSGFW_MESSAGE_TABLE_NAME, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->displayTime, pMsg->dataSize,
424 pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction, pMsg->bBackup, pMsg->msgId);
426 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
427 dbHandle->endTrans(false);
428 return MSG_ERR_DB_EXEC;
431 dbHandle->bindText(pMsg->subject, 1);
433 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pMsg->bTextSms == false)
434 dbHandle->bindText(pFileData, 2);
436 dbHandle->bindText(pMsg->msgText, 2);
438 MSG_DEBUG("%s", sqlQuery);
440 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
441 dbHandle->finalizeQuery();
442 dbHandle->endTrans(false);
443 return MSG_ERR_DB_EXEC;
446 dbHandle->finalizeQuery();
448 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL) {
449 if (pSendOptInfo->bSetting == true) {
450 memset(sqlQuery, 0x00, sizeof(sqlQuery));
451 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET "
456 "WHERE MSG_ID = %d;",
457 MSGFW_SMS_SENDOPT_TABLE_NAME,
458 pSendOptInfo->bDeliverReq,
459 pSendOptInfo->bKeepCopy,
460 pSendOptInfo->option.smsSendOptInfo.bReplyPath,
464 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
465 dbHandle->endTrans(false);
466 return MSG_ERR_DB_EXEC;
469 } else if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
470 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
472 dbHandle->endTrans(false);
473 return MSG_ERR_NULL_POINTER;
476 err = plg->updateMessage(pMsg, pSendOptInfo, pFileData);
478 if (err != MSG_SUCCESS) {
479 dbHandle->endTrans(false);
480 return MSG_ERR_STORAGE_ERROR;
483 if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
484 MSG_SEC_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
486 err = MsgStoUpdateMMSMessage(pMsg);
488 if (err != MSG_SUCCESS) {
489 dbHandle->endTrans(false);
490 return MSG_ERR_STORAGE_ERROR;
495 err = MsgStoUpdateConversation(dbHandle, convId);
497 if (err != MSG_SUCCESS) {
498 dbHandle->endTrans(false);
499 return MSG_ERR_STORAGE_ERROR;
502 err = MsgStoClearConversationTable(dbHandle);
504 if (err != MSG_SUCCESS) {
505 dbHandle->endTrans(false);
506 return MSG_ERR_STORAGE_ERROR;
509 dbHandle->endTrans(true);
515 msg_error_t MsgStoUpdateReadStatus(msg_message_id_t msgId, bool bRead)
517 char sqlQuery[MAX_QUERY_LEN+1];
519 msg_storage_id_t storageId;
521 MsgDbHandler *dbHandle = getDbHandle();
522 if (MsgStoSetReadStatus(dbHandle, msgId, bRead) != MSG_SUCCESS) {
523 MSG_DEBUG("MsgStoSetReadStatus() Error");
524 return MSG_ERR_STORAGE_ERROR;
527 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
530 #ifndef FEATURE_SMS_CDMA
532 memset(sqlQuery, 0x00, sizeof(sqlQuery));
533 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT STORAGE_ID FROM %s WHERE MSG_ID = %d;",
534 MSGFW_MESSAGE_TABLE_NAME, msgId);
536 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
537 return MSG_ERR_DB_PREPARE;
539 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
540 storageId = dbHandle->columnInt(0);
542 dbHandle->finalizeQuery();
543 return MSG_ERR_DB_STEP;
545 dbHandle->finalizeQuery();
547 MSG_DEBUG("StorageId:[%d]", storageId);
549 /* Update Read Status for SIM Msg */
550 if (storageId == MSG_STORAGE_SIM) {
551 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
554 MSG_DEBUG("SMS Plug-in is NULL");
555 return MSG_ERR_NULL_POINTER;
559 memset(sqlQuery, 0x00, sizeof(sqlQuery));
560 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
561 MSGFW_SIM_MSG_TABLE_NAME, msgId);
563 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
564 return MSG_ERR_DB_PREPARE;
567 msg_sim_slot_id_t sim_idx;
569 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
570 sim_idx = dbHandle->columnInt(0);
571 simId = dbHandle->columnInt(1);
573 if (plg->setReadStatus(sim_idx, simId) != MSG_SUCCESS) {
574 MSG_DEBUG("Fail to Set Read Status for SIM SMS");
578 dbHandle->finalizeQuery();
587 msg_error_t MsgStoUpdateThreadReadStatus(msg_thread_id_t threadId, msg_id_list_s *pMsgIdList)
591 msg_error_t err = MSG_SUCCESS;
593 char sqlQuery[MAX_QUERY_LEN+1];
595 /*** Get msg id list **/
596 int rowCnt = 0, index = 0;
597 pMsgIdList->nCount = 0;
598 MsgDbHandler *dbHandle = getDbHandle();
600 memset(sqlQuery, 0x00, sizeof(sqlQuery));
601 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s "
602 "WHERE CONV_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d AND FOLDER_ID < %d;",
603 MSGFW_MESSAGE_TABLE_NAME,
604 threadId, MSG_STORAGE_PHONE, MSG_SPAMBOX_ID);
606 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
608 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
609 MSG_DEBUG("Fail to getTable().");
610 dbHandle->freeTable();
615 dbHandle->freeTable();
619 pMsgIdList->nCount = rowCnt;
620 MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
622 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
624 for (int i = 0; i < rowCnt; i++)
625 pMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
627 dbHandle->freeTable();
630 /* set read status */
631 dbHandle->beginTrans();
632 memset(sqlQuery, 0x00, sizeof(sqlQuery));
633 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET READ_STATUS = %d "
634 "WHERE CONV_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d AND FOLDER_ID < %d;",
635 MSGFW_MESSAGE_TABLE_NAME, 1,
636 threadId, MSG_STORAGE_PHONE, MSG_SPAMBOX_ID);
638 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
639 dbHandle->endTrans(false);
640 return MSG_ERR_DB_EXEC;
644 if (MsgStoUpdateConversation(dbHandle, threadId) != MSG_SUCCESS) {
645 MSG_DEBUG("MsgStoUpdateConversation() Error");
646 dbHandle->endTrans(false);
647 return MSG_ERR_STORAGE_ERROR;
650 dbHandle->endTrans(true);
651 if (g_idle_add(resetNotification, NULL) == 0) {
652 MSG_DEBUG("resetNotification() Error");
661 msg_error_t MsgStoUpdateProtectedStatus(msg_message_id_t msgId, bool bProtected)
663 char sqlQuery[MAX_QUERY_LEN+1];
664 MsgDbHandler *dbHandle = getDbHandle();
666 memset(sqlQuery, 0x00, sizeof(sqlQuery));
667 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET PROTECTED = %d WHERE MSG_ID = %d;",
668 MSGFW_MESSAGE_TABLE_NAME, (int)bProtected, msgId);
670 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
671 return MSG_ERR_DB_EXEC;
677 msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
681 MSG_DEBUG("Msg Id : %d", msgId);
683 msg_error_t err = MSG_SUCCESS;
685 char sqlQuery[MAX_QUERY_LEN+1];
686 MsgDbHandler *dbHandle = getDbHandle();
688 /* delete report notification */
689 char tempAddr[MAX_ADDRESS_VAL_LEN+1];
690 memset(tempAddr, 0x00, sizeof(tempAddr));
691 memset(sqlQuery, 0x00, sizeof(sqlQuery));
692 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.ADDRESS_VAL FROM %s A, %s B WHERE A.CONV_ID = B.CONV_ID AND A.MSG_ID = %d;"
693 , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, msgId);
695 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
696 return MSG_ERR_DB_PREPARE;
698 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
699 dbHandle->finalizeQuery();
700 return MSG_ERR_DB_DONE;
703 snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
705 MSG_SEC_DEBUG("Updated address = %s", tempAddr);
707 MsgDeleteReportNotification(tempAddr);
709 dbHandle->finalizeQuery();
711 MsgDeleteSentReadReportNotification(msgId);
713 /* Get SUB_TYPE, STORAGE_ID */
714 memset(sqlQuery, 0x00, sizeof(sqlQuery));
715 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE, FOLDER_ID, STORAGE_ID, READ_STATUS, CONV_ID, SIM_INDEX \
716 FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
718 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
719 MSG_DEBUG("Query Failed [%s]", sqlQuery);
720 return MSG_ERR_DB_PREPARE;
723 MSG_MESSAGE_TYPE_S msgType;
724 msg_folder_id_t folderId;
725 msg_storage_id_t storageId;
726 msg_thread_id_t convId;
727 msg_sim_slot_id_t simIndex;
730 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
731 msgType.mainType = dbHandle->columnInt(0);
732 msgType.subType = dbHandle->columnInt(1);
733 folderId = dbHandle->columnInt(2);
734 storageId = dbHandle->columnInt(3);
735 bRead = dbHandle->columnInt(4);
736 convId = dbHandle->columnInt(5);
737 simIndex = dbHandle->columnInt(6);
739 MSG_DEBUG("Main Type:[%d] SubType:[%d] FolderId:[%d] StorageId:[%d] ReadStatus:[%d] ConversationId:[%d], simIndex=[%d]", msgType.mainType, msgType.subType, folderId, storageId, bRead, convId, simIndex);
741 MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
743 dbHandle->finalizeQuery();
745 return MSG_ERR_DB_STEP;
748 dbHandle->finalizeQuery();
750 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
753 MSG_DEBUG("SMS Plug-in is NULL");
754 return MSG_ERR_NULL_POINTER;
757 dbHandle->beginTrans();
759 #ifndef FEATURE_SMS_CDMA
760 /* Check sim message */
761 if (storageId == MSG_STORAGE_SIM) {
762 msg_sim_id_t simMsgId;
763 msg_sim_slot_id_t sim_idx;
766 /* get sim message id */
767 memset(sqlQuery, 0x00, sizeof(sqlQuery));
768 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
769 MSGFW_SIM_MSG_TABLE_NAME, msgId);
771 MSG_DEBUG("sqlQuery is [%s]", sqlQuery);
773 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
774 dbHandle->endTrans(false);
775 return MSG_ERR_DB_PREPARE;
778 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
782 sim_idx = dbHandle->columnInt(0);
783 simMsgId = dbHandle->columnInt(1);
785 MSG_DEBUG("SIM Msg Id : [%d]", simMsgId);
787 err = plg->deleteSimMessage(sim_idx, simMsgId);
789 if (err != MSG_SUCCESS) {
790 dbHandle->finalizeQuery();
791 dbHandle->endTrans(false);
795 dbHandle->finalizeQuery();
797 /*Sim message delete in db table */
798 memset(sqlQuery, 0x00, sizeof(sqlQuery));
799 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE SIM_ID = %d AND SIM_SLOT_ID =%d;", MSGFW_SIM_MSG_TABLE_NAME, simMsgId, sim_idx);
801 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
802 dbHandle->finalizeQuery();
803 dbHandle->endTrans(false);
804 return MSG_ERR_DB_EXEC;
808 dbHandle->finalizeQuery();
811 /* each type has to be handled in plug in ? */
812 if (msgType.mainType == MSG_SMS_TYPE) {
813 memset(sqlQuery, 0x00, sizeof(sqlQuery));
814 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
815 MSGFW_SMS_SENDOPT_TABLE_NAME, msgId);
817 /* Delete SMS Send Option */
818 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
819 dbHandle->endTrans(false);
820 return MSG_ERR_DB_EXEC;
823 memset(sqlQuery, 0x00, sizeof(sqlQuery));
824 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
825 MSGFW_SMS_REPORT_TABLE_NAME, msgId);
827 /* Delete Data from SMS_REPORT table */
828 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
829 dbHandle->endTrans(false);
830 return MSG_ERR_DB_EXEC;
833 if (msgType.subType == MSG_CB_SMS || msgType.subType == MSG_JAVACB_SMS
834 || (msgType.subType >= MSG_CMAS_PRESIDENTIAL && msgType.subType <= MSG_CMAS_OPERATOR_DEFINED)) {
835 memset(sqlQuery, 0x00, sizeof(sqlQuery));
836 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
837 MSGFW_CB_MSG_TABLE_NAME, msgId);
839 /* Delete Push Message from push table */
840 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
841 dbHandle->endTrans(false);
842 return MSG_ERR_DB_EXEC;
844 } else if (msgType.subType >= MSG_WAP_SI_SMS && msgType.subType <= MSG_WAP_CO_SMS) {
845 memset(sqlQuery, 0x00, sizeof(sqlQuery));
846 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
847 MSGFW_PUSH_MSG_TABLE_NAME, msgId);
849 /* Delete Push Message from push table */
850 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
851 dbHandle->endTrans(false);
852 return MSG_ERR_DB_EXEC;
854 } else if (msgType.subType == MSG_SYNCML_CP) {
855 memset(sqlQuery, 0x00, sizeof(sqlQuery));
856 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
857 MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
859 /* Delete SyncML Message from syncML table */
860 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
861 dbHandle->endTrans(false);
862 return MSG_ERR_DB_EXEC;
865 } else if (msgType.mainType == MSG_MMS_TYPE) {
866 char filePath[MSG_FILEPATH_LEN_MAX + 1] = {0, };
867 char dirPath[MSG_FILEPATH_LEN_MAX + 1]= {0, };
869 /*remove multipart */
870 memset(sqlQuery, 0x00, sizeof(sqlQuery));
871 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
872 MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
874 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
875 dbHandle->endTrans(false);
876 return MSG_ERR_DB_PREPARE;
879 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
880 memset(filePath, 0x00, sizeof(filePath));
881 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
882 if (remove(filePath) == -1)
883 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
885 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
887 dbHandle->finalizeQuery();
889 /* Delete Data from Multipart table */
890 memset(sqlQuery, 0x00, sizeof(sqlQuery));
891 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
892 MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
894 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
895 dbHandle->endTrans(false);
896 return MSG_ERR_DB_EXEC;
899 memset(sqlQuery, 0x00, sizeof(sqlQuery));
900 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
901 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
903 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
904 dbHandle->endTrans(false);
905 return MSG_ERR_DB_PREPARE;
908 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
909 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
911 snprintf(dirPath, MSG_FILEPATH_LEN_MAX, "%s.dir", filePath);
913 if (remove(filePath) == -1)
914 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
916 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
923 MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
924 dbHandle->finalizeQuery();
925 dbHandle->endTrans(false);
926 return MSG_ERR_DB_STEP;
929 dbHandle->finalizeQuery();
931 /* remove thumbnail file */
932 memset(sqlQuery, 0x00, sizeof(sqlQuery));
933 snprintf(sqlQuery, sizeof(sqlQuery),
934 "SELECT VALUE FROM %s "
935 "WHERE MSG_ID = %d AND (TYPE=%d OR TYPE=%d);",
936 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO);
938 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
939 dbHandle->endTrans(false);
940 return MSG_ERR_DB_PREPARE;
943 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
944 memset(filePath, 0x00, sizeof(filePath));
945 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
946 if (remove(filePath) == -1)
947 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
949 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
952 dbHandle->finalizeQuery();
954 memset(sqlQuery, 0x00, sizeof(sqlQuery));
955 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
956 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId);
958 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
959 dbHandle->endTrans(false);
960 return MSG_ERR_DB_EXEC;
963 memset(sqlQuery, 0x00, sizeof(sqlQuery));
964 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
965 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
967 /* Delete Data from MMS table */
968 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
969 dbHandle->endTrans(false);
970 return MSG_ERR_DB_EXEC;
973 memset(sqlQuery, 0x00, sizeof(sqlQuery));
974 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
975 MSGFW_REPORT_TABLE_NAME, msgId);
977 /* Delete Data from MMS STATUS table */
978 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
979 dbHandle->endTrans(false);
980 return MSG_ERR_DB_EXEC;
984 memset(sqlQuery, 0x00, sizeof(sqlQuery));
985 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
987 /* Delete Message from msg table */
988 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
989 dbHandle->endTrans(false);
990 return MSG_ERR_DB_EXEC;
993 #ifdef FEATURE_SMS_CDMA
994 memset(sqlQuery, 0x00, sizeof(sqlQuery));
995 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_UNIQUENESS_INFO_TABLE_NAME, msgId);
997 /* Delete Message from uniqueness table */
998 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
999 dbHandle->endTrans(false);
1000 return MSG_ERR_DB_EXEC;
1005 /* Clear Conversation table */
1006 if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
1007 dbHandle->endTrans(false);
1008 return MSG_ERR_DB_EXEC;
1011 /* Update conversation table. */
1012 if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
1013 dbHandle->endTrans(false);
1014 return MSG_ERR_STORAGE_ERROR;
1017 dbHandle->endTrans(true);
1019 /* Update Thread Callback */
1020 if (bCheckIndication == true) {
1021 if (MsgExistConversation(dbHandle, convId) == true && MsgExistInThreadViewList(dbHandle, convId) == true)
1022 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, convId);
1024 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, convId);
1027 if (msgType.mainType == MSG_SMS_TYPE && folderId == MSG_INBOX_ID) {
1028 msgType.classType = MSG_CLASS_NONE;
1030 /* Set memory status in SIM */
1031 if (MsgStoCheckMsgCntFull(dbHandle, &msgType, folderId) == MSG_SUCCESS) {
1032 MSG_DEBUG("Set Memory Status");
1034 plg->setMemoryStatus(simIndex, MSG_SUCCESS);
1038 if (bCheckIndication == true) {
1039 MSG_DEBUG("bCheckIndication is true.");
1040 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1047 msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyDB, msg_id_list_s *pMsgIdList)
1049 msg_error_t err = MSG_SUCCESS;
1051 char sqlQuery[MAX_QUERY_LEN+1];
1053 queue<msg_thread_id_t> threadList, threadList2;
1055 #ifdef FEATURE_SMS_CDMA
1056 const char *tableList[] = {MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1057 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1058 MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1059 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1060 MSGFW_UNIQUENESS_INFO_TABLE_NAME};
1062 const char *tableList[] = {MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1063 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1064 MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1065 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME};
1068 int listCnt = sizeof(tableList)/sizeof(char *);
1070 MsgDbHandler *dbHandle = getDbHandle();
1071 signed char folder_id;
1073 /* Get conversation ID from Folder */
1074 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1076 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE FOLDER_ID = %d",
1077 MSGFW_MESSAGE_TABLE_NAME, folderId);
1079 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1081 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1082 MSG_DEBUG("Fail to getTable().");
1083 dbHandle->freeTable();
1088 dbHandle->freeTable();
1092 for (int i = 1; i <= rowCnt; i++) {
1093 MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
1094 threadList.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1095 threadList2.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1098 dbHandle->freeTable();
1100 /*** Get msg id list **/
1101 msg_id_list_s *pToDeleteMsgIdList = NULL;
1102 pToDeleteMsgIdList = (msg_id_list_s *)new char[sizeof(msg_id_list_s)];
1103 if (pToDeleteMsgIdList == NULL) {
1104 MSG_DEBUG("pToDeleteMsgIdList is NULL.");
1105 return MSG_ERR_NULL_POINTER;
1107 memset(pToDeleteMsgIdList, 0x00, sizeof(msg_id_list_s));
1109 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1110 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d",
1111 MSGFW_MESSAGE_TABLE_NAME, folderId);
1116 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
1118 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1119 MSG_DEBUG("Fail to getTable().");
1120 dbHandle->freeTable();
1125 dbHandle->freeTable();
1131 pToDeleteMsgIdList->nCount = rowCnt;
1133 MSG_DEBUG("pToDeleteMsgIdList->nCount [%d]", pToDeleteMsgIdList->nCount);
1135 pToDeleteMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
1136 memset(pToDeleteMsgIdList->msgIdList, 0x00, sizeof(msg_message_id_t) * rowCnt);
1138 for (int i = 0; i < rowCnt; i++)
1139 pToDeleteMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
1141 dbHandle->freeTable();
1144 /*** Delete Sim Message In Folder **/
1145 folder_id = (signed char)folderId;
1146 if (folder_id >= MSG_INBOX_ID) {
1147 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1149 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d AND STORAGE_ID = %d",
1150 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_SIM);
1154 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1155 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1156 dbHandle->freeTable();
1160 for (int i = 1; i <= rowCnt; i++) {
1161 err = MsgStoDeleteMessage(dbHandle->getColumnToInt(i), false);
1163 if (err != MSG_SUCCESS) {
1164 MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
1166 dbHandle->freeTable();
1171 /*Delete phone log */
1172 /* MsgDeletePhoneLog(dbHandle->getColumnToInt(i)); */
1175 dbHandle->freeTable();
1178 dbHandle->beginTrans();
1180 for (int i = 0; i < listCnt; i++) {
1181 if (!strcmp(tableList[i], MMS_PLUGIN_MESSAGE_TABLE_NAME)) {
1184 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1185 char dirPath[MSG_FILEPATH_LEN_MAX] = {0, };
1186 /* remove multipart */
1187 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1188 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s;",
1189 MSGFW_MMS_MULTIPART_TABLE_NAME);
1191 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1192 dbHandle->endTrans(false);
1193 return MSG_ERR_DB_PREPARE;
1196 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1197 memset(filePath, 0x00, sizeof(filePath));
1198 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
1199 if (remove(filePath) == -1)
1200 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1202 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1204 dbHandle->finalizeQuery();
1206 /* Delete Data from Multipart table */
1207 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1208 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;",
1209 MSGFW_MMS_MULTIPART_TABLE_NAME);
1211 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1212 err = MSG_ERR_DB_EXEC;
1213 dbHandle->endTrans(false);
1217 /*get mms msg id list */
1218 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1219 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.FILE_PATH FROM %s A, %s B \
1220 WHERE A.FOLDER_ID = %d AND A.MAIN_TYPE = %d AND A.MSG_ID = B.MSG_ID",
1221 MSGFW_MESSAGE_TABLE_NAME, MMS_PLUGIN_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE);
1223 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1224 MSG_DEBUG("rowCnt %d", rowCnt);
1226 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1227 MSG_DEBUG("Fail to getTable().");
1229 dbHandle->freeTable();
1230 dbHandle->endTrans(false);
1235 for (int i = 1; i <= rowCnt; i++) {
1236 memset(filePath, 0x00, sizeof(filePath));
1237 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1239 MSG_SEC_DEBUG("filePath [%s]", filePath);
1241 /*delete raw file */
1242 snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
1244 if (remove(filePath) == -1)
1245 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1247 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1254 dbHandle->freeTable();
1257 /* delete thumbnail */
1258 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1259 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1260 snprintf(sqlQuery, sizeof(sqlQuery),
1261 "SELECT VALUE FROM %s "
1262 "WHERE (TYPE=%d OR TYPE=%d) "
1263 "AND (MSG_ID IN (SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d));",
1264 MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO, MSGFW_MESSAGE_TABLE_NAME, folderId);
1266 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1267 dbHandle->endTrans(false);
1268 return MSG_ERR_DB_PREPARE;
1271 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1272 memset(filePath, 0x00, sizeof(filePath));
1273 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
1274 if (remove(filePath) == -1)
1275 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1277 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1280 dbHandle->finalizeQuery();
1282 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1284 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN \
1285 (SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d);",
1286 tableList[i], MSGFW_MESSAGE_TABLE_NAME, folderId);
1288 /* Delete Message in specific folder from table */
1289 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1290 MSG_DEBUG("sqlQuery [%s]", sqlQuery);
1291 dbHandle->endTrans(false);
1292 err = MSG_ERR_DB_EXEC;
1298 /* Clear Conversation table */
1299 if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
1300 dbHandle->endTrans(false);
1301 err = MSG_ERR_DB_EXEC;
1306 /* Update Address */
1307 while (!threadList.empty()) {
1308 err = MsgStoUpdateConversation(dbHandle, threadList.front());
1312 if (err != MSG_SUCCESS) {
1313 dbHandle->endTrans(false);
1319 dbHandle->endTrans(true);
1321 /* Update Thread Callback */
1322 while (!threadList2.empty()) {
1323 msg_thread_id_t cur_thread_id = threadList2.front();
1324 if (MsgExistConversation(dbHandle, cur_thread_id) == true && MsgExistInThreadViewList(dbHandle, cur_thread_id) == true)
1325 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, cur_thread_id);
1327 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, cur_thread_id);
1332 /* Set pMsgIdList */
1333 if (pMsgIdList != NULL && pToDeleteMsgIdList->nCount > 0) {
1334 pMsgIdList->nCount = pToDeleteMsgIdList->nCount;
1336 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * pToDeleteMsgIdList->nCount];
1337 memset(pMsgIdList->msgIdList, 0x00, sizeof(msg_message_id_t) * pToDeleteMsgIdList->nCount);
1338 memcpy(pMsgIdList->msgIdList, pToDeleteMsgIdList->msgIdList, sizeof(msg_message_id_t) * pToDeleteMsgIdList->nCount);
1341 /* Create thread for noti and phone log delete. */
1343 if (pToDeleteMsgIdList->nCount > 0) {
1345 if (pToDeleteMsgIdList != NULL) {
1346 /*free peer info list */
1347 if (pToDeleteMsgIdList->msgIdList != NULL)
1348 delete [] pToDeleteMsgIdList->msgIdList;
1350 delete [] pToDeleteMsgIdList;
1353 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1360 MSG_DEBUG("Error case Free Memory");
1362 while (!threadList.empty()) {
1368 if (pToDeleteMsgIdList != NULL) {
1369 /*free peer info list */
1370 if (pToDeleteMsgIdList->msgIdList != NULL)
1371 delete [] pToDeleteMsgIdList->msgIdList;
1373 delete [] pToDeleteMsgIdList;
1380 msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
1386 msg_error_t err = MSG_SUCCESS;
1387 if (pMsgIdList->nCount < 1) {
1388 MSG_DEBUG("pMsgIdList->nCount < 1");
1392 char sqlQuery[MAX_QUERY_LEN+1];
1394 queue<msg_thread_id_t> threadList1, threadList2, threadList3;
1396 #ifdef FEATURE_SMS_CDMA
1397 const char *tableList[] = {MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1398 MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1399 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1400 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1401 MSGFW_SMS_REPORT_TABLE_NAME, MSGFW_MMS_MULTIPART_TABLE_NAME,
1402 MSGFW_UNIQUENESS_INFO_TABLE_NAME};
1404 const char *tableList[] = {MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1405 MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1406 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1407 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1408 MSGFW_SMS_REPORT_TABLE_NAME, MSGFW_MMS_MULTIPART_TABLE_NAME};
1411 int listCnt = sizeof(tableList)/sizeof(char *);
1413 MsgDbHandler *dbHandle = getDbHandle();
1415 dbHandle->beginTrans();
1416 /* reset msgid temp table */
1417 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1418 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_TMP_MSGID_TABLE_NAME);
1419 MSG_DEBUG("[%s]", sqlQuery);
1421 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1422 dbHandle->endTrans(false);
1423 return MSG_ERR_DB_EXEC;
1426 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
1427 dbHandle->finalizeQuery();
1428 dbHandle->endTrans(false);
1429 return MSG_ERR_DB_EXEC;
1432 dbHandle->finalizeQuery();
1434 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1435 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (?)", MSGFW_TMP_MSGID_TABLE_NAME);
1436 MSG_DEBUG("[%s]", sqlQuery);
1437 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1438 dbHandle->endTrans(false);
1439 return MSG_ERR_DB_PREPARE;
1442 for (int i = 0; i < pMsgIdList->nCount; i++) {
1443 dbHandle->resetQuery();
1444 dbHandle->bindInt(pMsgIdList->msgIdList[i], 1);
1445 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
1446 dbHandle->finalizeQuery();
1447 dbHandle->endTrans(false);
1448 return MSG_ERR_DB_EXEC;
1452 dbHandle->finalizeQuery();
1453 dbHandle->endTrans(true);
1455 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1456 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE MSG_ID IN %s;", MSGFW_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1458 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1460 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1461 MSG_DEBUG("Fail to getTable().");
1462 dbHandle->freeTable();
1466 MSG_DEBUG("rowCnt [%d]", rowCnt);
1469 dbHandle->freeTable();
1473 for (int i = 1; i <= rowCnt; i++) {
1474 MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
1475 threadList1.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1476 threadList2.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1477 threadList3.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1479 dbHandle->freeTable();
1481 /* delete report notification */
1482 char tempAddr[MAX_ADDRESS_VAL_LEN+1];
1483 bool isSentReadReportDeleted = false;
1484 while (!threadList1.empty()) {
1485 memset(tempAddr, 0x00, sizeof(tempAddr));
1486 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1487 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.ADDRESS_VAL FROM %s A, %s B WHERE A.CONV_ID = B.CONV_ID AND A.CONV_ID = %d;"
1488 , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, threadList1.front());
1490 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1491 return MSG_ERR_DB_PREPARE;
1493 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
1494 dbHandle->finalizeQuery();
1495 return MSG_ERR_DB_DONE;
1498 snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
1500 MSG_SEC_DEBUG("Updated address = %s", tempAddr);
1502 MsgDeleteReportNotification(tempAddr);
1504 dbHandle->finalizeQuery();
1507 if (!isSentReadReportDeleted && !MsgIsSentReadReportNotificationExist(threadList1.front(), &msgId)) {
1508 //delete read report sent notification
1509 MsgDeleteSentReadReportNotification(msgId);
1510 isSentReadReportDeleted = true;
1517 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1518 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d AND MSG_ID IN %s;",
1519 MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, MSGFW_TMP_MSGID_TABLE_NAME);
1522 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1524 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1525 MSG_DEBUG("Fail to getTable().");
1526 dbHandle->freeTable();
1530 for (int i = 1; i <= rowCnt; i++) {
1531 err = MsgStoDeleteMessage(dbHandle->getColumnToInt(i), false);
1532 if (err != MSG_SUCCESS) {
1533 MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
1536 dbHandle->freeTable();
1538 dbHandle->beginTrans();
1539 for (int i = 0; i < listCnt; i++) {
1541 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1542 char dirPath[MSG_FILEPATH_LEN_MAX] = {0, };
1546 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1547 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN %s;", MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1549 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1551 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1552 MSG_DEBUG("Fail to getTable().");
1556 MSG_DEBUG("rowCnt %d", rowCnt);
1558 for (int i = 1; i <= rowCnt; i++) {
1559 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1561 MSG_SEC_DEBUG("filePath [%s]", filePath);
1563 /* Delete raw file. */
1564 snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
1566 if (remove(filePath) == -1)
1567 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1569 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1575 dbHandle->freeTable();
1577 } else if (i == 1) {
1578 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1582 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1583 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT VALUE FROM %s WHERE (TYPE = %d OR TYPE = %d) AND MSG_ID IN %s;",
1584 MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO, MSGFW_TMP_MSGID_TABLE_NAME);
1586 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1588 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1589 MSG_DEBUG("Fail to getTable().");
1593 MSG_DEBUG("rowCnt %d", rowCnt);
1595 for (int i = 1; i <= rowCnt; i++) {
1596 memset(filePath, 0x00, sizeof(filePath));
1597 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1598 if (remove(filePath) == -1)
1599 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1601 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1603 dbHandle->freeTable();
1604 } else if (!strcmp(tableList[i], MSGFW_MMS_MULTIPART_TABLE_NAME)) {
1605 /* MMS file path to delete. */
1606 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1610 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1611 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN %s;", MSGFW_MMS_MULTIPART_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1613 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1615 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1616 MSG_DEBUG("Fail to getTable().");
1620 MSG_DEBUG("rowCnt %d", rowCnt);
1622 for (int i = 1; i <= rowCnt; i++) {
1623 memset(filePath, 0x00, sizeof(filePath));
1624 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1625 if (filePath[0] != '\0') {
1626 if (remove(filePath) == -1)
1627 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1629 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1632 dbHandle->freeTable();
1634 /* MMS thumbnail path to delete */
1635 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1636 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT THUMB_FILE_PATH FROM %s WHERE MSG_ID IN %s;", MSGFW_MMS_MULTIPART_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1638 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1640 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1641 MSG_DEBUG("Fail to getTable().");
1645 MSG_DEBUG("rowCnt %d", rowCnt);
1647 for (int i = 1; i <= rowCnt; i++) {
1648 memset(filePath, 0x00, sizeof(filePath));
1649 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1650 if (filePath[0] != '\0') {
1651 if (remove(filePath) == -1)
1652 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1654 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1658 dbHandle->freeTable();
1661 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1662 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN %s;", tableList[i], MSGFW_TMP_MSGID_TABLE_NAME);
1664 /* Delete Message in specific folder from table */
1665 err = dbHandle->execQuery(sqlQuery);
1666 if (err != MSG_SUCCESS) {
1667 MSG_DEBUG("Fail to execQuery().");
1671 /* Clear Conversation table */
1672 err = MsgStoClearConversationTable(dbHandle);
1673 if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoClearConversationTable().");
1675 /* Update Address */
1676 while (!threadList2.empty()) {
1677 err = MsgStoUpdateConversation(dbHandle, threadList2.front());
1678 if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoUpdateConversation().");
1681 err = dbHandle->endTrans(true);
1682 if (err != MSG_SUCCESS) {
1683 MSG_DEBUG("Fail to endTrans(true).");
1684 dbHandle->endTrans(false);
1688 /* Update Thread Callback */
1689 while (!threadList3.empty()) {
1690 msg_thread_id_t cur_thread_id = threadList3.front();
1691 if (MsgExistConversation(dbHandle, cur_thread_id) == true && MsgExistInThreadViewList(dbHandle, cur_thread_id) == true)
1692 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, cur_thread_id);
1694 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, cur_thread_id);
1699 if (g_idle_add(resetNotification, NULL) == 0) {
1700 MSG_DEBUG("resetNotification() Error");
1708 msg_error_t MsgStoMoveMessageToFolder(msg_message_id_t msgId, msg_folder_id_t destFolderId)
1710 msg_error_t err = MSG_SUCCESS;
1711 MSG_MESSAGE_TYPE_S msgType;
1712 msg_thread_id_t convId = 0;
1714 MsgStoGetMsgType(msgId, &msgType);
1716 char sqlQuery[MAX_QUERY_LEN+1];
1717 MsgDbHandler *dbHandle = getDbHandle();
1719 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1721 if (msgType.mainType == MSG_SMS_TYPE)
1722 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_ID = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, destFolderId, msgId);
1724 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_ID = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, destFolderId, msgId);
1726 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
1727 return MSG_ERR_DB_EXEC;
1729 /* get conversation id */
1730 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1732 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONV_ID FROM %s WHERE MSG_ID = %d;",
1733 MSGFW_MESSAGE_TABLE_NAME, msgId);
1735 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1736 return MSG_ERR_DB_PREPARE;
1738 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW)
1739 convId = dbHandle->columnInt(0);
1741 MSG_DEBUG("convId : %d", convId);
1743 dbHandle->finalizeQuery();
1745 /* update conversation table */
1746 err = MsgStoUpdateConversation(dbHandle, convId);
1748 /* update notification */
1749 signed char dest_folder_id = (signed char)destFolderId;
1750 if (dest_folder_id != MSG_SPAMBOX_ID)
1751 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1757 msg_error_t MsgStoMoveMessageToStorage(msg_message_id_t msgId, msg_storage_id_t destStorageId)
1761 msg_error_t err = MSG_SUCCESS;
1763 char sqlQuery[MAX_QUERY_LEN+1];
1764 MsgDbHandler *dbHandle = getDbHandle();
1766 MSG_DEBUG("msgId : %d, destStorageId : %d", msgId, destStorageId);
1768 switch (destStorageId) {
1769 case MSG_STORAGE_SIM : /* Move message to sim card */
1770 case MSG_STORAGE_SIM2 : {
1771 MSG_MESSAGE_INFO_S msgInfo;
1772 SMS_SIM_ID_LIST_S simIdList;
1774 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1775 memset(&simIdList, 0x00, sizeof(SMS_SIM_ID_LIST_S));
1777 if ((err = MsgStoGetMessage(msgId, &msgInfo, NULL)) != MSG_SUCCESS)
1780 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
1782 MSG_DEBUG("SMS Plug-in is NULL");
1783 return MSG_ERR_NULL_POINTER;
1786 if (destStorageId == MSG_STORAGE_SIM)
1787 msgInfo.sim_idx = 1;
1788 else if (destStorageId == MSG_STORAGE_SIM2)
1789 msgInfo.sim_idx = 2;
1791 if ((err = plg->saveSimMessage(&msgInfo, &simIdList)) != MSG_SUCCESS)
1794 dbHandle->beginTrans();
1796 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1797 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d, SIM_INDEX = %d WHERE MSG_ID = %d;",
1798 MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, msgInfo.sim_idx, msgId);
1799 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1801 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1802 dbHandle->endTrans(false);
1803 return MSG_ERR_DB_EXEC;
1806 for (unsigned int i = 0; i < simIdList.count; i++) {
1807 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1808 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
1809 MSGFW_SIM_MSG_TABLE_NAME, msgInfo.sim_idx, simIdList.simId[i], msgId);
1810 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1812 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1813 dbHandle->endTrans(false);
1814 return MSG_ERR_DB_EXEC;
1818 dbHandle->endTrans(true);
1822 default: { /* Moving message to memory (when destination storage id is MSG_STORAGE_PHONE) */
1823 #ifndef FEATURE_SMS_CDMA
1824 bool bSimMsg = false;
1827 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1828 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT STORAGE_ID FROM %s WHERE MSG_ID = %d;",
1829 MSGFW_MESSAGE_TABLE_NAME, msgId);
1831 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1833 if (err != MSG_SUCCESS) {
1834 MSG_DEBUG("Fail to getTable().");
1835 dbHandle->freeTable();
1839 if (dbHandle->getColumnToInt(1) == MSG_STORAGE_SIM) {
1840 MSG_DEBUG("It is SIM Message");
1844 dbHandle->freeTable();
1846 if (bSimMsg == true) {
1847 msg_sim_id_t simMsgId;
1848 msg_sim_slot_id_t sim_idx;
1850 /* get sim message id */
1851 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1853 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
1854 MSGFW_SIM_MSG_TABLE_NAME, msgId);
1858 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
1860 if (err != MSG_SUCCESS) {
1861 MSG_DEBUG("Fail to getTable().");
1862 dbHandle->freeTable();
1866 /* Delete messages in sim card */
1867 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
1869 MSG_DEBUG("SMS Plug-in is NULL");
1870 dbHandle->freeTable();
1871 return MSG_ERR_NULL_POINTER;
1874 for (int i = 0; i < rowCnt; i++) {
1875 sim_idx = dbHandle->getColumnToInt(index++);
1876 simMsgId = dbHandle->getColumnToInt(index++);
1878 MSG_DEBUG("simMsgId is %d.", simMsgId);
1880 if ((err = plg->deleteSimMessage(sim_idx, simMsgId)) != MSG_SUCCESS) {
1881 dbHandle->freeTable();
1886 dbHandle->freeTable();
1888 dbHandle->beginTrans();
1890 /* Delete Messages in SIM Msg table */
1891 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1892 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
1893 MSGFW_SIM_MSG_TABLE_NAME, msgId);
1894 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1896 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1897 dbHandle->endTrans(false);
1898 return MSG_ERR_DB_EXEC;
1901 /* Move storage id */
1902 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1903 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d WHERE MSG_ID = %d;",
1904 MSGFW_MESSAGE_TABLE_NAME, destStorageId, msgId);
1905 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1907 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1908 dbHandle->endTrans(false);
1909 return MSG_ERR_DB_EXEC;
1912 dbHandle->endTrans(true);
1923 msg_error_t MsgStoCountMessage(msg_folder_id_t folderId, MSG_COUNT_INFO_S *pCountInfo)
1925 if (pCountInfo == NULL) {
1926 MSG_DEBUG("pCountInfo is NULL");
1927 return MSG_ERR_NULL_POINTER;
1930 char sqlQuery[MAX_QUERY_LEN+1];
1931 MsgDbHandler *dbHandle = getDbHandle();
1933 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1934 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 1 AND STORAGE_ID = %d "
1935 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d "
1936 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND STORAGE_ID = %d "
1937 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND STORAGE_ID = %d;",
1938 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_PHONE,
1939 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_PHONE,
1940 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_SMS_TYPE, MSG_STORAGE_PHONE,
1941 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE, MSG_STORAGE_PHONE);
1943 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1944 return MSG_ERR_DB_PREPARE;
1946 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1947 pCountInfo->nReadCnt = dbHandle->columnInt(0);
1949 dbHandle->finalizeQuery();
1950 return MSG_ERR_DB_STEP;
1953 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1954 pCountInfo->nUnreadCnt = dbHandle->columnInt(0);
1956 dbHandle->finalizeQuery();
1957 return MSG_ERR_DB_STEP;
1960 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1961 pCountInfo->nSms = dbHandle->columnInt(0);
1963 dbHandle->finalizeQuery();
1964 return MSG_ERR_DB_STEP;
1967 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1968 pCountInfo->nMms = dbHandle->columnInt(0);
1970 dbHandle->finalizeQuery();
1971 return MSG_ERR_DB_STEP;
1974 dbHandle->finalizeQuery();
1980 msg_error_t MsgStoCountMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount)
1982 if (pMsgType == NULL) {
1983 MSG_DEBUG("pMsgType is NULL");
1984 return MSG_ERR_NULL_POINTER;
1989 char sqlQuery[MAX_QUERY_LEN+1];
1990 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1992 MsgDbHandler *dbHandle = getDbHandle();
1994 if ((pMsgType->mainType == MSG_SMS_TYPE) &&
1995 (pMsgType->subType == MSG_NORMAL_SMS || pMsgType->subType == MSG_STATUS_REPORT_SMS || pMsgType->subType == MSG_CONCAT_SIM_SMS)) {
1996 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d);",
1997 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_NORMAL_SMS, MSG_STATUS_REPORT_SMS, MSG_CONCAT_SIM_SMS);
1998 } else if ((pMsgType->mainType == MSG_SMS_TYPE) &&
1999 (pMsgType->subType == MSG_WAP_SI_SMS || pMsgType->subType == MSG_WAP_SL_SMS)) {
2001 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d);",
2002 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_WAP_SI_SMS, MSG_WAP_SL_SMS);
2003 } else if ((pMsgType->mainType == MSG_MMS_TYPE) &&
2004 (pMsgType->subType == MSG_SENDREQ_MMS || pMsgType->subType == MSG_SENDCONF_MMS || pMsgType->subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgType->subType == MSG_RETRIEVE_MANUALCONF_MMS)) {
2006 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d, %d);",
2007 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_SENDREQ_MMS, MSG_SENDCONF_MMS, MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS);
2009 return MSG_ERR_INVALID_PARAMETER;
2012 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2013 return MSG_ERR_DB_PREPARE;
2015 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2016 *pMsgCount = dbHandle->columnInt(0);
2018 dbHandle->finalizeQuery();
2019 return MSG_ERR_DB_STEP;
2022 dbHandle->finalizeQuery();
2028 msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
2030 char sqlQuery[MAX_QUERY_LEN+1];
2031 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2032 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, \
2033 SUB_TYPE, DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
2034 BACKUP, PRIORITY, MSG_DIRECTION, DPM_RESTRICTED, SCHEDULED_TIME, SUBJECT, MSG_TEXT, THUMB_PATH, SIM_INDEX \
2035 FROM %s WHERE MSG_ID = %d;",
2036 MSGFW_MESSAGE_TABLE_NAME, msgId);
2038 MsgDbHandler *dbHandle = getDbHandle();
2040 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2041 return MSG_ERR_DB_PREPARE;
2043 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2044 pMsg->msgId = dbHandle->columnInt(0);
2045 pMsg->threadId = dbHandle->columnInt(1);
2046 pMsg->folderId = dbHandle->columnInt(2);
2047 pMsg->storageId = dbHandle->columnInt(3);
2048 pMsg->msgType.mainType = dbHandle->columnInt(4);
2049 pMsg->msgType.subType = dbHandle->columnInt(5);
2050 pMsg->displayTime = (time_t)dbHandle->columnInt(6);
2051 pMsg->dataSize = dbHandle->columnInt(7);
2052 pMsg->networkStatus = dbHandle->columnInt(8);
2053 pMsg->bRead = dbHandle->columnInt(9);
2054 pMsg->bProtected = dbHandle->columnInt(10);
2055 pMsg->bBackup = dbHandle->columnInt(11);
2056 pMsg->priority = dbHandle->columnInt(12);
2057 pMsg->direction = dbHandle->columnInt(13);
2058 pMsg->bRestricted = dbHandle->columnInt(14);
2060 strncpy(pMsg->subject, (char *)dbHandle->columnText(16), MAX_SUBJECT_LEN);
2062 /* Temp_File_Handling */
2063 if (pMsg->msgType.mainType == MSG_SMS_TYPE || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
2064 if (pMsg->dataSize > MAX_MSG_TEXT_LEN) {
2065 char msgData[pMsg->dataSize+1];
2066 memset(msgData, 0x00, sizeof(msgData));
2068 strncpy(msgData, (char *)dbHandle->columnText(17), pMsg->dataSize);
2070 /* Save Message Data into File */
2071 char fileName[MSG_FILENAME_LEN_MAX+1];
2072 memset(fileName, 0x00, sizeof(fileName));
2074 if (MsgCreateFileName(fileName) == false) {
2075 dbHandle->finalizeQuery();
2076 return MSG_ERR_STORAGE_ERROR;
2079 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, fileName);
2081 if (MsgWriteIpcFile(fileName, msgData, pMsg->dataSize) == false) {
2082 dbHandle->finalizeQuery();
2083 return MSG_ERR_STORAGE_ERROR;
2086 strncpy(pMsg->msgData, fileName, MAX_MSG_DATA_LEN);
2088 pMsg->bTextSms = false;
2090 memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
2091 strncpy(pMsg->msgText, (char *)dbHandle->columnText(17), pMsg->dataSize);
2093 /* For WAP PUSH SI Message */
2094 if (pMsg->msgType.subType == MSG_WAP_SI_SMS) {
2095 strncat(pMsg->msgText, "\n", MAX_MSG_TEXT_LEN-strlen(pMsg->msgText));
2096 strncat(pMsg->msgText, pMsg->subject, MAX_MSG_TEXT_LEN-strlen(pMsg->msgText));
2097 MSG_SEC_DEBUG("pMsg->msgText : [%s]", pMsg->msgText);
2098 pMsg->dataSize = sizeof(pMsg->msgText);
2101 pMsg->bTextSms = true;
2104 if (dbHandle->columnText(16) != NULL)
2105 strncpy(pMsg->msgText, (char *)dbHandle->columnText(17), MAX_MSG_TEXT_LEN);
2108 /* thumbnail path */
2109 if (dbHandle->columnText(18)!= NULL && ((char *)dbHandle->columnText(18))[0] != '\0') {
2110 strncpy(pMsg->thumbPath, (char *)dbHandle->columnText(18), MSG_FILEPATH_LEN_MAX);
2111 MSG_DEBUG("pMsg->thumbPath : [%s]", pMsg->thumbPath);
2114 if (pMsg->bRestricted == true) {
2116 memset(pMsg->msgData, 0x00, sizeof(pMsg->msgData));
2117 memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
2118 memset(pMsg->subject, 0x00, sizeof(pMsg->subject));
2119 memset(pMsg->thumbPath, 0x00, sizeof(pMsg->thumbPath));
2122 pMsg->sim_idx = dbHandle->columnInt(19);
2124 dbHandle->finalizeQuery();
2125 MSG_DEBUG("%s", sqlQuery);
2126 return MSG_ERR_DB_STEP;
2129 dbHandle->finalizeQuery();
2132 /* get address information. */
2133 MsgStoGetAddressByMsgId(dbHandle, pMsg->msgId, &pMsg->nAddressCnt, &pMsg->addressList);
2135 /* Get MMS body if it is MMS. */
2136 if ((pMsg->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS &&
2137 (pMsg->msgType.subType == MSG_RETRIEVE_MMS || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS)) ||
2138 pMsg->msgType.subType == MSG_SENDREQ_MMS || pMsg->msgType.subType == MSG_SENDCONF_MMS || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
2139 msg_error_t err = MSG_SUCCESS;
2140 char *pDestMsg = NULL;
2141 int temp_size = pMsg->dataSize; /* save raw file size; */
2143 /* call mms plugin to get mms specific message data */
2144 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(pMsg->msgType.mainType);
2146 MSG_DEBUG("SMS Plug-in is NULL");
2147 return MSG_ERR_NULL_POINTER;
2150 err = plg->getMmsMessage(pMsg, pSendOptInfo, &pDestMsg);
2151 if (err != MSG_SUCCESS) {
2156 return MSG_ERR_STORAGE_ERROR;
2159 memset(pMsg->msgData, 0, MAX_MSG_DATA_LEN+1);
2161 /* Encode MMS specific data to MMS_MESSAGE_DATA_S */
2162 if (pMsg->dataSize > MAX_MSG_DATA_LEN) {
2163 /* Save Message Data into File */
2164 char tempFileName[MSG_FILENAME_LEN_MAX+1];
2165 memset(tempFileName, 0x00, sizeof(tempFileName));
2167 if (MsgCreateFileName(tempFileName) == false) {
2172 return MSG_ERR_STORAGE_ERROR;
2174 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, tempFileName);
2176 if (MsgWriteIpcFile(tempFileName, pDestMsg, pMsg->dataSize) == false) {
2181 return MSG_ERR_STORAGE_ERROR;
2183 strncpy(pMsg->msgData, tempFileName, MAX_MSG_DATA_LEN);
2184 pMsg->bTextSms = false;
2186 strncpy(pMsg->msgData, pDestMsg, pMsg->dataSize);
2187 pMsg->bTextSms = true;
2190 pMsg->dataSize = temp_size; /*raw file size; */
2198 /* Get SMS Sending Options */
2199 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL)
2200 MsgStoGetSmsSendOpt(pMsg, pSendOptInfo);
2205 msg_error_t MsgStoGetFailedMessage(int **failed_msg_list, int *count)
2209 msg_error_t err = MSG_SUCCESS;
2210 char sqlQuery[MAX_QUERY_LEN+1];
2211 int rowCnt = 0, index = 0;
2212 MsgDbHandler *dbHandle = getDbHandle();
2214 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2216 /* Folder ID == 2 : sending failed message, Folder ID == 1 : retrieve failed message */
2217 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE (NETWORK_STATUS = %d OR NETWORK_STATUS == %d) AND (FOLDER_ID = %d OR FOLDER_ID = %d);",
2218 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_PENDING, MSG_NETWORK_RETRIEVE_PENDING, MSG_OUTBOX_ID, MSG_INBOX_ID);
2219 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2221 if(err == MSG_ERR_DB_NORECORD) {
2222 dbHandle->freeTable();
2226 int *list = new int[rowCnt];
2228 for(int i = 0; i < rowCnt; ++i) {
2229 list[i] = dbHandle->getColumnToInt(index++);
2231 *failed_msg_list = list;
2232 dbHandle->freeTable();
2238 msg_error_t MsgStoAddSyncMLMessage(MSG_MESSAGE_INFO_S *pMsgInfo, int extId, int pinCode)
2242 msg_error_t err = MSG_SUCCESS;
2244 char sqlQuery[MAX_QUERY_LEN+1];
2246 unsigned int rowId = 0;
2247 msg_thread_id_t convId = 0;
2248 MsgDbHandler *dbHandle = getDbHandle();
2250 dbHandle->beginTrans();
2252 if (pMsgInfo->nAddressCnt > 0) {
2253 err = MsgStoAddAddress(dbHandle, pMsgInfo, &convId);
2255 if (err != MSG_SUCCESS) {
2256 dbHandle->endTrans(false);
2261 /* Add Message Table */
2262 pMsgInfo->threadId = convId;
2263 rowId = MsgStoAddMessageTable(dbHandle, pMsgInfo);
2266 dbHandle->endTrans(false);
2267 return MSG_ERR_DB_ROW;
2270 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2271 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
2272 MSGFW_SYNCML_MSG_TABLE_NAME, rowId, extId, pinCode);
2274 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
2275 dbHandle->endTrans(false);
2276 return MSG_ERR_DB_EXEC;
2279 if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
2280 dbHandle->endTrans(false);
2281 return MSG_ERR_STORAGE_ERROR;
2284 dbHandle->endTrans(true);
2286 pMsgInfo->msgId = (msg_message_id_t)rowId;
2288 MsgInsertNotification(pMsgInfo);
2297 msg_error_t MsgStoGetMsgType(msg_message_id_t msgId, MSG_MESSAGE_TYPE_S *pMsgType)
2299 MsgDbHandler *dbHandle = getDbHandle();
2300 char sqlQuery[MAX_QUERY_LEN+1];
2302 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2304 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE FROM %s WHERE MSG_ID = %d;",
2305 MSGFW_MESSAGE_TABLE_NAME, msgId);
2307 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2308 return MSG_ERR_DB_PREPARE;
2310 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2311 pMsgType->mainType = dbHandle->columnInt(0);
2312 pMsgType->subType = dbHandle->columnInt(1);
2315 dbHandle->finalizeQuery();
2321 msg_error_t MsgStoGetQuickPanelData(msg_quickpanel_type_t QPtype, MSG_MESSAGE_INFO_S *pMsg)
2323 msg_error_t err = MSG_SUCCESS;
2325 MsgDbHandler *dbHandle = getDbHandle();
2326 char sqlQuery[MAX_QUERY_LEN+1];
2328 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2330 if (QPtype == MSG_QUICKPANEL_SMS) {
2331 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND SUB_TYPE = %d AND READ_STATUS = 0 ORDER BY DISPLAY_TIME DESC;",
2332 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_SMS_TYPE, MSG_NORMAL_SMS);
2333 } else if (QPtype == MSG_QUICKPANEL_MMS) {
2334 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d) AND READ_STATUS = 0 ORDER BY DISPLAY_TIME DESC;",
2335 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_MMS_TYPE, MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS);
2336 } else if (QPtype == MSG_QUICKPANEL_DELIVER_REP) {
2337 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE SUB_TYPE IN (%d, %d) AND READ_STATUS = 0 ORDER BY DISPLAY_TIME DESC;",
2338 MSGFW_MESSAGE_TABLE_NAME, MSG_STATUS_REPORT_SMS, MSG_DELIVERYIND_MMS);
2339 } else if (QPtype == MSG_QUICKPANEL_READ_REP) {
2340 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE = %d AND READ_STATUS = 0 ORDER BY DISPLAY_TIME DESC;",
2341 MSGFW_MESSAGE_TABLE_NAME, MSG_MMS_TYPE, MSG_READORGIND_MMS);
2342 } else if (QPtype == MSG_QUICKPANEL_VOICEMAIL) {
2343 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND SUB_TYPE = %d AND READ_STATUS = 0 ORDER BY DISPLAY_TIME DESC;",
2344 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MWI_VOICE_SMS);
2345 } else if (QPtype == MSG_QUICKPANEL_MMS_NOTI) {
2346 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND SUB_TYPE = %d AND READ_STATUS = 0 ORDER BY DISPLAY_TIME DESC;",
2347 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_MMS_TYPE, MSG_NOTIFICATIONIND_MMS);
2350 /* Get Message ID */
2351 msg_message_id_t msgId;
2353 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2354 return MSG_ERR_DB_PREPARE;
2356 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2357 msgId = dbHandle->columnInt(0);
2359 dbHandle->finalizeQuery();
2360 return MSG_ERR_DB_STEP;
2363 dbHandle->finalizeQuery();
2365 /* Get Message Info */
2366 err = MsgStoGetMessage(msgId, pMsg, NULL);
2372 msg_error_t MsgStoDeleteThreadMessageList(msg_thread_id_t threadId, bool bIncludeProtect, msg_id_list_s *pMsgIdList)
2374 msg_error_t err = MSG_SUCCESS;
2376 MsgDbHandler *dbHandle = getDbHandle();
2377 char sqlQuery[MAX_QUERY_LEN+1];
2379 /*** Get msg id list **/
2380 int rowCnt = 0, index = 0;
2382 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2384 #ifdef MSG_NOTI_INTEGRATION
2385 if (bIncludeProtect) {
2386 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2387 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
2388 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
2390 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2391 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0;",
2392 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
2395 if (bIncludeProtect) {
2396 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2397 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
2398 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
2400 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2401 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0;",
2402 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
2406 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2408 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
2409 MSG_ERR("Fail to getTable().");
2410 dbHandle->freeTable();
2415 dbHandle->freeTable();
2417 err = MsgStoClearConversationTable(dbHandle);
2418 if (err != MSG_SUCCESS) {
2419 MSG_ERR("Fail to MsgStoClearConversationTable().");
2423 err = MsgStoUpdateConversation(dbHandle, threadId);
2424 if (err != MSG_SUCCESS) {
2425 MSG_ERR("Fail to MsgStoUpdateConversation().");
2432 pMsgIdList->nCount = rowCnt;
2434 MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
2436 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
2438 for (int i = 0; i < rowCnt; i++)
2439 pMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
2441 dbHandle->freeTable();
2444 err = MsgStoDeleteMessageByList(pMsgIdList);
2445 if (err != MSG_SUCCESS) {
2446 MSG_ERR("Fail to MsgStoDeleteMessageByList().");
2454 msg_error_t MsgStoSetTempAddressTable(MSG_ADDRESS_INFO_S *pAddrInfo, int addr_cnt)
2456 MsgDbHandler *dbHandle = getDbHandle();
2457 char sqlQuery[MAX_QUERY_LEN+1];
2459 dbHandle->beginTrans();
2460 /* reset address temp table */
2461 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2462 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_ADDRESS_TEMP_TABLE_NAME);
2463 MSG_DEBUG("[%s]", sqlQuery);
2465 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2466 return MSG_ERR_DB_EXEC;
2468 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2469 dbHandle->finalizeQuery();
2470 dbHandle->endTrans(false);
2471 return MSG_ERR_DB_EXEC;
2474 dbHandle->finalizeQuery();
2476 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2477 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (?);", MSGFW_ADDRESS_TEMP_TABLE_NAME);
2478 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
2479 dbHandle->endTrans(false);
2480 return MSG_ERR_DB_PREPARE;
2483 char newPhoneNum[MAX_ADDRESS_VAL_LEN+1];
2484 char tmpNum[MAX_ADDRESS_VAL_LEN+1];
2485 for (int i = 0; i < addr_cnt; i++) {
2486 memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
2487 memset(tmpNum, 0x00, sizeof(tmpNum));
2488 MsgConvertNumber(pAddrInfo[i].addressVal, tmpNum, sizeof(tmpNum));
2489 snprintf(newPhoneNum, sizeof(newPhoneNum), "%%%%%s", tmpNum);
2490 dbHandle->resetQuery();
2491 dbHandle->bindText(newPhoneNum, 1);
2492 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2493 dbHandle->finalizeQuery();
2494 dbHandle->endTrans(false);
2495 return MSG_ERR_DB_EXEC;
2499 dbHandle->finalizeQuery();
2500 dbHandle->endTrans(true);
2506 msg_error_t MsgStoCountMsgByContact(const MSG_THREAD_LIST_INDEX_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pThreadCountInfo)
2508 MsgDbHandler *dbHandle = getDbHandle();
2509 char sqlQuery[MAX_QUERY_LEN+1];
2511 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2513 if (pAddrInfo->contactId > 0) {
2514 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) AS TOTAL, "
2515 "SUM(CASE WHEN READ_STATUS = 0 AND FOLDER_ID = %d THEN 1 ELSE 0 END), "
2516 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END), "
2517 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END) "
2518 "FROM (SELECT * FROM %s A JOIN %s B ON A.CONV_ID = B.CONV_ID WHERE B.CONTACT_ID = %d)",
2519 MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MMS_TYPE, MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pAddrInfo->contactId);
2521 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) AS TOTAL, "
2522 "SUM(CASE WHEN READ_STATUS = 0 AND FOLDER_ID = %d THEN 1 ELSE 0 END), "
2523 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END), "
2524 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END) "
2525 "FROM (SELECT * FROM %s A JOIN %s B ON A.CONV_ID = B.CONV_ID WHERE B.ADDRESS_VAL = '%s')",
2526 MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MMS_TYPE, MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pAddrInfo->msgAddrInfo.addressVal);
2529 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2530 return MSG_ERR_DB_PREPARE;
2532 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2533 pThreadCountInfo->totalCount = dbHandle->columnInt(0);
2534 pThreadCountInfo->unReadCount = dbHandle->columnInt(1);
2535 pThreadCountInfo->smsMsgCount = dbHandle->columnInt(2);
2536 pThreadCountInfo->mmsMsgCount = dbHandle->columnInt(3);
2538 dbHandle->finalizeQuery();
2539 return MSG_ERR_DB_STEP;
2542 dbHandle->finalizeQuery();
2548 msg_error_t MsgStoGetSyncMLExtId(msg_message_id_t msgId, int *extId)
2550 MsgDbHandler *dbHandle = getDbHandle();
2551 char sqlQuery[MAX_QUERY_LEN+1];
2553 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2555 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXT_ID FROM %s WHERE MSG_ID = %d;",
2556 MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
2558 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2559 return MSG_ERR_DB_PREPARE;
2561 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2562 *extId = dbHandle->columnInt(0);
2564 dbHandle->finalizeQuery();
2565 return MSG_ERR_DB_STEP;
2568 dbHandle->finalizeQuery();
2574 msg_error_t MsgStoGetSmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
2576 MsgDbHandler *dbHandle = getDbHandle();
2577 char sqlQuery[MAX_QUERY_LEN+1];
2578 msg_error_t err = MSG_SUCCESS;
2580 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2581 snprintf(sqlQuery, sizeof(sqlQuery),
2582 "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
2584 "WHERE MSG_ID = %d "
2585 "order by TIME ASC;"
2586 , MSGFW_SMS_REPORT_TABLE_NAME, msgId);
2588 int rowCnt = 0, index = 0;
2589 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2591 if (err != MSG_SUCCESS) {
2592 MSG_DEBUG("Fail to getTable().");
2593 dbHandle->freeTable();
2594 if (err == MSG_ERR_DB_NORECORD)
2600 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
2601 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
2603 for (int i = 0; i < rowCnt; i++) {
2604 dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
2605 report_status[i].type = dbHandle->getColumnToInt(index++);
2606 report_status[i].status = dbHandle->getColumnToInt(index++);
2607 report_status[i].statusTime = (time_t)dbHandle->getColumnToInt(index++);
2609 MSG_SEC_DEBUG("(%d/%d) address = %s, report_type = %d, report_status = %d, report_time = %d", i+1, rowCnt, report_status[i].addressVal, report_status[i].type, report_status[i].status, report_status[i].statusTime);
2612 *pReportStatus = report_status;
2614 dbHandle->freeTable();
2619 msg_error_t MsgStoGetMmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
2621 MsgDbHandler *dbHandle = getDbHandle();
2622 char sqlQuery[MAX_QUERY_LEN+1];
2624 msg_direction_type_t direction = MSG_DIRECTION_TYPE_MO;
2626 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_DIRECTION FROM %s WHERE MSG_ID = %d;",
2627 MSGFW_MESSAGE_TABLE_NAME, msgId);
2629 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2630 return MSG_ERR_DB_PREPARE;
2632 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2633 direction = dbHandle->columnInt(0);
2636 dbHandle->finalizeQuery();
2638 if (direction == MSG_DIRECTION_TYPE_MO) {/*get received report list of MO message */
2639 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2640 /*MSG_ID INTEGER , ADDRESS_VAL TEXT , STATUS_TYPE INTEGER , STATUS INTEGER DEFAULT 0 , TIME DATETIME) */
2641 /*select * from MSG_REPORT_TABLE where MSG_ID=38 order by ADDRESS_VAL DESC, STATUS_TYPE ASC; */
2642 snprintf(sqlQuery, sizeof(sqlQuery),
2643 "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
2645 "WHERE MSG_ID = %d "
2646 "order by ADDRESS_VAL DESC, STATUS_TYPE ASC;"
2647 , MSGFW_REPORT_TABLE_NAME, msgId);
2649 int rowCnt = 0, index = 0;
2650 msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2651 if (err != MSG_SUCCESS) {
2652 MSG_DEBUG("Fail to getTable().");
2653 dbHandle->freeTable();
2654 if (err == MSG_ERR_DB_NORECORD)
2660 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
2661 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
2663 for (int i = 0; i < rowCnt; i++) {
2664 dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
2665 report_status[i].type = dbHandle->getColumnToInt(index++);
2666 report_status[i].status = dbHandle->getColumnToInt(index++);
2667 report_status[i].statusTime = (time_t)dbHandle->getColumnToInt(index++);
2669 MSG_DEBUG("(%d/%d) addr = %s, report_type = %d, report_status = %d, report_time = %d", i+1, rowCnt, report_status[i].addressVal, report_status[i].type, report_status[i].status, report_status[i].statusTime);
2672 *pReportStatus = report_status;
2674 dbHandle->freeTable();
2676 } else if (direction == MSG_DIRECTION_TYPE_MT) { /*read report sent status of MT message */
2677 int readReportSentStatus;
2679 if (MsgStoCheckReadReportRequested(dbHandle, msgId) == false) {
2681 *pReportStatus = NULL;
2682 return MSG_ERR_READREPORT_NOT_REQUESTED;
2685 MsgStoGetReadReportSendStatus(msgId, &readReportSentStatus);
2689 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)];
2690 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
2692 report_status->addressVal[0] = '\0';
2693 report_status->type = MSG_REPORT_TYPE_READ_REPORT_SENT;
2694 report_status->status = readReportSentStatus;
2695 report_status->statusTime = 0;
2697 MSG_DEBUG("report_type = %d, report_status = %d", report_status->type, report_status->status);
2699 *pReportStatus = report_status;
2706 msg_error_t MsgStoGetThreadIdByAddress(const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t *pThreadId)
2708 MsgDbHandler *dbHandle = getDbHandle();
2709 if(pMsg->nAddressCnt > 0) {
2710 if (MsgExistAddress(dbHandle, pMsg, pThreadId) == true) {
2711 MSG_DEBUG("Conversation ID : [%d]", *pThreadId);
2713 /* check thread count */
2714 MSG_THREAD_VIEW_S threadInfo;
2715 memset(&threadInfo, 0x00, sizeof(MSG_THREAD_VIEW_S));
2716 MsgStoGetThreadInfo(*pThreadId, &threadInfo);
2717 MSG_DEBUG("threadInfo.smsCnt [%d], threadInfo.mmsCnt [%d]", threadInfo.smsCnt, threadInfo.mmsCnt);
2718 if ((threadInfo.smsCnt + threadInfo.mmsCnt) > 0) {
2729 msg_error_t MsgStoGetThreadUnreadCnt(msg_thread_id_t threadId, int *cnt)
2733 MsgDbHandler *dbHandle = getDbHandle();
2737 char sqlQuery[MAX_QUERY_LEN+1];
2740 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2741 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s A \
2742 WHERE CONV_ID = %d AND READ_STATUS = 0;", MSGFW_MESSAGE_TABLE_NAME, threadId);
2744 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2745 return MSG_ERR_DB_PREPARE;
2747 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2748 msgCnt = dbHandle->columnInt(0);
2751 dbHandle->finalizeQuery();
2761 msg_error_t MsgStoGetThreadInfo(msg_thread_id_t threadId, MSG_THREAD_VIEW_S *pThreadInfo)
2765 MsgDbHandler *dbHandle = getDbHandle();
2766 int rowCnt = 0, index = 0;
2768 char sqlQuery[MAX_QUERY_LEN+1];
2769 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2771 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.UNREAD_CNT, A.SMS_CNT, A.MMS_CNT, "
2772 "A.MAIN_TYPE, A.SUB_TYPE, A.MSG_DIRECTION, A.DISPLAY_TIME, A.DISPLAY_NAME, A.MSG_TEXT, "
2773 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.PROTECTED = 1) AS PROTECTED, "
2774 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.FOLDER_ID = %d) AS DRAFT, "
2775 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.NETWORK_STATUS = %d) AS FAILED, "
2776 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.NETWORK_STATUS = %d) AS SENDING "
2777 "FROM %s A WHERE A.CONV_ID = %d AND A.SMS_CNT + A.MMS_CNT > 0;",
2778 MSGFW_MESSAGE_TABLE_NAME,
2779 MSGFW_MESSAGE_TABLE_NAME, MSG_DRAFT_ID,
2780 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_FAIL,
2781 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SENDING,
2782 MSGFW_CONVERSATION_TABLE_NAME, threadId);
2784 msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2786 if (err == MSG_ERR_DB_NORECORD) {
2787 dbHandle->freeTable();
2789 } else if (err != MSG_SUCCESS) {
2790 MSG_DEBUG("Fail to getTable().");
2791 dbHandle->freeTable();
2796 MSG_DEBUG("rowCnt is %d", rowCnt);
2797 dbHandle->freeTable();
2800 pThreadInfo->threadId = dbHandle->getColumnToInt(index++);
2802 pThreadInfo->unreadCnt = dbHandle->getColumnToInt(index++);
2803 pThreadInfo->smsCnt = dbHandle->getColumnToInt(index++);
2804 pThreadInfo->mmsCnt = dbHandle->getColumnToInt(index++);
2806 pThreadInfo->mainType = dbHandle->getColumnToInt(index++);
2807 pThreadInfo->subType = dbHandle->getColumnToInt(index++);
2809 pThreadInfo->direction = dbHandle->getColumnToInt(index++);
2810 pThreadInfo->threadTime = (time_t)dbHandle->getColumnToInt(index++);
2812 memset(pThreadInfo->threadName, 0x00, sizeof(pThreadInfo->threadName));
2813 dbHandle->getColumnToString(index++, MAX_THREAD_NAME_LEN, pThreadInfo->threadName);
2815 memset(pThreadInfo->threadData, 0x00, sizeof(pThreadInfo->threadData));
2816 dbHandle->getColumnToString(index++, MAX_THREAD_DATA_LEN, pThreadInfo->threadData);
2818 int protectedCnt = dbHandle->getColumnToInt(index++);
2819 if (protectedCnt > 0)
2820 pThreadInfo->bProtected = true;
2822 int draftCnt = dbHandle->getColumnToInt(index++);
2824 pThreadInfo->bDraft = true;
2826 int failedCnt = dbHandle->getColumnToInt(index++);
2828 pThreadInfo->bSendFailed = true;
2830 int sendingCnt = dbHandle->getColumnToInt(index++);
2832 pThreadInfo->bSending = true;
2835 dbHandle->freeTable();
2843 msg_error_t MsgStoRestoreMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
2847 MsgDbHandler *dbHandle = getDbHandle();
2848 msg_error_t err = MSG_SUCCESS;
2849 char sqlQuery[MAX_QUERY_LEN+1];
2851 if(MsgExistConversation(dbHandle, pMsg->threadId)) {
2852 /* add message to address table which having same thread_id and datetime; */
2853 for (int i = 0; i < pMsg->nAddressCnt; i++) {
2854 if(MsgExistAddress(dbHandle, pMsg, pMsg->threadId, i) == false) {
2855 unsigned int addrId;
2856 MSG_CONTACT_INFO_S contactInfo;
2857 memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
2859 /* Get Contact Info */
2860 /* if (MsgGetContactInfo(&(pMsg->addressList[i]), &contactInfo) != MSG_SUCCESS) { */
2861 /* MSG_DEBUG("MsgGetContactInfo() fail."); */
2863 err = dbHandle->getRowId(MSGFW_ADDRESS_TABLE_NAME, &addrId);
2864 if (err != MSG_SUCCESS) {
2865 MSG_DEBUG("pDbHandle->getRowId fail. [%d]", err);
2870 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2871 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, '%s', %d, %d, ?, ?, ?, ?, ?, '%s', 0);",
2872 MSGFW_ADDRESS_TABLE_NAME, addrId, pMsg->threadId, pMsg->addressList[i].addressType, pMsg->addressList[i].recipientType, pMsg->addressList[i].addressVal,
2873 contactInfo.contactId, contactInfo.addrbookId, contactInfo.imagePath);
2875 MSG_SEC_DEBUG("Add Address Info. [%s]", sqlQuery);
2877 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2878 return MSG_ERR_DB_PREPARE;
2880 dbHandle->bindText(contactInfo.firstName, 1);
2881 dbHandle->bindText(contactInfo.lastName, 2);
2882 dbHandle->bindText(contactInfo.middleName, 3);
2883 dbHandle->bindText(contactInfo.prefix, 4);
2884 dbHandle->bindText(contactInfo.suffix, 5);
2886 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2887 dbHandle->finalizeQuery();
2888 return MSG_ERR_DB_STEP;
2891 dbHandle->finalizeQuery();
2893 /* set conversation display name by conv id */
2894 MsgStoSetConversationDisplayName(dbHandle, pMsg->threadId);
2899 if(!MsgExistMessage(dbHandle, pMsg)) {
2900 unsigned int rowId = 0;
2902 if (pMsg->threadId > 0 && pMsg->folderId == MSG_DRAFT_ID) {
2903 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2905 snprintf(sqlQuery, sizeof(sqlQuery),
2906 "DELETE FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d;",
2907 MSGFW_MESSAGE_TABLE_NAME, pMsg->threadId, MSG_DRAFT_ID);
2909 MSG_DEBUG("sqlQuery [%s]", sqlQuery);
2911 err = dbHandle->execQuery(sqlQuery);
2913 if (err != MSG_SUCCESS) {
2914 MSG_DEBUG("fail to delete draft messages.");
2918 err = dbHandle->getRowId(MSGFW_MESSAGE_TABLE_NAME, &rowId);
2920 pMsg->msgId = (msg_message_id_t)rowId;
2924 char *pFileData = NULL;
2925 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
2928 if (pMsg->bTextSms == false) {
2929 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
2930 return MSG_ERR_STORAGE_ERROR;
2932 MSG_DEBUG("file size [%d]", fileSize);
2935 char keyName[MAX_VCONFKEY_NAME_LEN];
2936 memset(keyName, 0x00, sizeof(keyName));
2937 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, pMsg->sim_idx);
2940 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
2941 MSG_INFO("MsgSettingGetString() is failed");
2945 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2947 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %lu, %zu, %d, %d, %d, %d, %d, 0, %d, ?, '', '', ?, 0, %d, '%s');",
2948 MSGFW_MESSAGE_TABLE_NAME, rowId, pMsg->threadId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType,
2949 pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
2950 pMsg->bBackup, pMsg->sim_idx, imsi);
2953 MSG_DEBUG("QUERY : %s", sqlQuery);
2960 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
2961 return MSG_ERR_DB_EXEC;
2964 dbHandle->bindText(pMsg->subject, 1);
2966 if (pMsg->bTextSms == false)
2967 dbHandle->bindText(pFileData, 2);
2969 dbHandle->bindText(pMsg->msgText, 2);
2971 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2972 dbHandle->finalizeQuery();
2973 return MSG_ERR_DB_EXEC;
2976 dbHandle->finalizeQuery();
2978 if (pMsg->msgType.subType != MSG_SENDREQ_MMS) {
2979 err = MsgStoUpdateConversation(dbHandle, pMsg->threadId);
2981 if (err != MSG_SUCCESS) {
2986 /* In the case of MMS Message, load the MMS plugin to save MMS PDU */
2987 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
2988 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
2989 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
2991 return MSG_ERR_NULL_POINTER;
2993 err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
2995 if (err != MSG_SUCCESS)
2996 return MSG_ERR_STORAGE_ERROR;
2998 if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
2999 MSG_SEC_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
3001 err = MsgStoUpdateMMSMessage(pMsg);
3003 if (err != MSG_SUCCESS)
3004 return MSG_ERR_STORAGE_ERROR;
3010 /* add message to conversation, message, address table; */
3012 err = MsgStoAddMessage(pMsg, pSendOptInfo);
3021 msg_message_id_t MsgStoAddSimMessage(MSG_MESSAGE_INFO_S *pMsg, int *simIdList, int listSize)
3024 MsgDbHandler *dbHandle = getDbHandle();
3025 if (pMsg == NULL || pMsg->msgType.mainType == MSG_MMS_TYPE) {
3026 MSG_DEBUG("pMsg == NULL || pMsg->msgType.mainType == MSG_MMS_TYPE");
3030 if ((pMsg->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsg->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
3031 if (pMsg->msgId > 0) {
3032 pMsg->bRead = false;
3033 if (MsgStoUpdateMessage(pMsg, NULL) != MSG_SUCCESS) {
3034 MSG_DEBUG("MsgStoUpdateMessage is failed!!!");
3037 if (MsgStoAddMessage(pMsg, NULL) != MSG_SUCCESS) {
3038 MSG_DEBUG("MsgStoAddMessage is failed!!!");
3043 if (MsgStoAddMessage(pMsg, NULL) != MSG_SUCCESS) {
3044 MSG_DEBUG("MsgStoAddMessage is failed!!!");
3049 dbHandle->beginTrans();
3051 MSG_DEBUG("simIdList exist.");
3053 for(int i = 0; i < listSize; ++i) {
3055 simId = simIdList[i] - 1;
3056 char sqlQuery[MAX_QUERY_LEN+1];
3057 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3058 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
3059 MSGFW_SIM_MSG_TABLE_NAME, pMsg->sim_idx, simId, pMsg->msgId);
3061 MSG_DEBUG("QUERY : %s", sqlQuery);
3063 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
3064 dbHandle->endTrans(false);
3072 dbHandle->endTrans(true);
3080 #ifdef FEATURE_SMS_CDMA
3081 msg_error_t MsgCheckUniqueness(bool bInsert, msg_message_id_t msgId, MSG_UNIQUE_INDEX_S *p_msg)
3085 MsgDbHandler *dbHandle = getDbHandle();
3088 char sqlQuery[MAX_QUERY_LEN+1];
3091 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3092 dbHandle->beginTrans();
3094 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT * FROM %s WHERE TELE_MSG_ID = %d AND ADDRESS = '%s' AND SUB_ADDRESS = '%s' AND TIME_STAMP = '%s' AND TELESVC_ID = %d;",
3095 MSGFW_UNIQUENESS_INFO_TABLE_NAME, p_msg->tele_msgId, p_msg->address, p_msg->sub_address, p_msg->time_stamp, p_msg->telesvc_id);
3097 dbHandle->getTable(sqlQuery, &nRowCnt, NULL);
3098 MSG_DEBUG("nRowCnt = [%d]", nRowCnt);
3100 dbHandle->freeTable();
3101 dbHandle->endTrans(true);
3104 MSG_DEBUG("<<<<This incoming message is a new message>>>>");
3107 MSG_DEBUG("<<<<This incoming message is a repeated message>>>>");
3108 return MSG_ERR_UNKNOWN;
3111 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3112 dbHandle->beginTrans();
3114 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, '%s', '%s', '%s', %d);",
3115 MSGFW_UNIQUENESS_INFO_TABLE_NAME, msgId, p_msg->tele_msgId, p_msg->address, p_msg->sub_address, p_msg->time_stamp, p_msg->telesvc_id);
3117 dbHandle->execQuery(sqlQuery);
3118 dbHandle->endTrans(true);
3127 msg_error_t MsgStoUpdateIMSI(int sim_idx)
3130 MSG_DEBUG("sim_idx = %d", sim_idx);
3132 /* msg_error_t err = MSG_SUCCESS; */
3133 MsgDbHandler *dbHandle = getDbHandle();
3135 char sqlQuery[MAX_QUERY_LEN+1];
3136 char keyName[MAX_VCONFKEY_NAME_LEN];
3138 dbHandle->beginTrans();
3141 MSG_DEBUG("sim index is 0");
3142 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3144 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET SIM_INDEX = 0;",
3145 MSGFW_MESSAGE_TABLE_NAME);
3147 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
3148 dbHandle->endTrans(false);
3149 return MSG_ERR_DB_EXEC;
3152 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
3153 dbHandle->finalizeQuery();
3154 dbHandle->endTrans(false);
3155 return MSG_ERR_DB_EXEC;
3158 MSG_DEBUG("sim index is %d", sim_idx);
3160 memset(keyName, 0x00, sizeof(keyName));
3161 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, sim_idx);
3164 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
3165 MSG_INFO("MsgSettingGetString() is failed");
3168 MSG_SEC_DEBUG("imsi value exist -> %s", imsi);
3170 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3172 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET SIM_INDEX = %d \
3173 WHERE SIM_IMSI LIKE '%s';",
3174 MSGFW_MESSAGE_TABLE_NAME, sim_idx, imsi);
3181 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
3182 dbHandle->endTrans(false);
3183 return MSG_ERR_DB_EXEC;
3186 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
3187 dbHandle->finalizeQuery();
3188 dbHandle->endTrans(false);
3189 return MSG_ERR_DB_EXEC;
3193 dbHandle->finalizeQuery();
3194 dbHandle->endTrans(true);
3202 msg_error_t MsgStoUpdateDPMRestrictedStatus(MSG_MAIN_TYPE_T msgType)
3204 msg_error_t err = MSG_SUCCESS;
3206 char sqlQuery[MAX_QUERY_LEN+1];
3207 MsgDbHandler *dbHandle = getDbHandle();
3209 msg_id_list_s msgIdList = {0, };
3212 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3213 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE MAIN_TYPE = %d AND DPM_RESTRICTED = 1;",
3214 MSGFW_MESSAGE_TABLE_NAME, msgType);
3216 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
3217 if (err != MSG_SUCCESS) {
3218 dbHandle->freeTable();
3222 msg_message_id_t *msgIds = new msg_message_id_t[rowCnt];
3223 for (int i = 0; i < rowCnt; i++) {
3224 msgIds[i] = dbHandle->getColumnToInt(i + 1);
3227 dbHandle->freeTable();
3229 msgIdList.nCount = rowCnt;
3230 msgIdList.msgIdList = msgIds;
3232 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3233 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET DPM_RESTRICTED = 0 WHERE MAIN_TYPE = %d AND DPM_RESTRICTED = 1;",
3234 MSGFW_MESSAGE_TABLE_NAME, msgType);
3236 err = dbHandle->execQuery(sqlQuery);
3237 if (err == MSG_SUCCESS) {
3238 MsgStoUpdateAllAddress();
3239 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
3242 if (msgIdList.msgIdList)
3243 delete [] msgIdList.msgIdList;