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"
41 /*==================================================================================================
43 ==================================================================================================*/
47 bool delNotiRunning = false;
51 bool delLogRunning = false;
54 /*==================================================================================================
56 ==================================================================================================*/
57 static gboolean resetNotification(void *pVoid)
61 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
69 /*==================================================================================================
70 FUNCTION IMPLEMENTATION
71 ==================================================================================================*/
73 msg_error_t MsgStoAddMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
77 msg_error_t err = MSG_SUCCESS;
79 unsigned int rowId = 0;
80 msg_thread_id_t convId = 0;
82 char sqlQuery[MAX_QUERY_LEN+1];
84 MsgDbHandler *dbHandle = getDbHandle();
86 dbHandle->beginTrans();
88 if (pMsg->nAddressCnt > 0) {
89 err = MsgStoAddAddress(dbHandle, pMsg, &convId);
91 if (err != MSG_SUCCESS) {
92 dbHandle->endTrans(false);
96 pMsg->threadId = convId;
99 if (pMsg->msgId > 0) {
103 err = dbHandle->getRowId(MSGFW_MESSAGE_TABLE_NAME, &rowId);
104 if (err != MSG_SUCCESS) {
105 dbHandle->endTrans(false);
108 pMsg->msgId = (msg_message_id_t)rowId;
113 char *pFileData = NULL;
114 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
117 if (pMsg->bTextSms == false) {
118 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
119 dbHandle->endTrans(false);
120 return MSG_ERR_STORAGE_ERROR;
123 MSG_DEBUG("file size [%d]", fileSize);
126 char keyName[MAX_VCONFKEY_NAME_LEN];
127 memset(keyName, 0x00, sizeof(keyName));
128 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, pMsg->sim_idx);
131 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
132 MSG_INFO("MsgSettingGetString() is failed");
136 memset(sqlQuery, 0x00, sizeof(sqlQuery));
138 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %u, %d, %d, %d, %d, %d, %d, %d, %d, ?, '', '', ?, 0, %d, '%s');",
139 MSGFW_MESSAGE_TABLE_NAME, rowId, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType,
140 (unsigned int)pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
141 0, pMsg->bBackup, pMsg->sim_idx, imsi);
143 MSG_DEBUG("QUERY : %s", sqlQuery);
148 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
149 dbHandle->endTrans(false);
150 return MSG_ERR_DB_EXEC;
153 dbHandle->bindText(pMsg->subject, 1);
155 if (pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
156 dbHandle->bindText("", 2);
158 if (pMsg->bTextSms == false)
159 dbHandle->bindText(pFileData, 2);
161 dbHandle->bindText(pMsg->msgText, 2);
164 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
165 dbHandle->finalizeQuery();
166 dbHandle->endTrans(false);
167 return MSG_ERR_DB_EXEC;
170 dbHandle->finalizeQuery();
172 if (pMsg->msgType.subType != MSG_SENDREQ_MMS) {
173 err = MsgStoUpdateConversation(dbHandle, convId);
175 if (err != MSG_SUCCESS) {
176 dbHandle->endTrans(false);
182 /* In the case of MMS Message, load the MMS plugin to save MMS PDU */
183 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
184 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
185 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
187 dbHandle->endTrans(false);
188 return MSG_ERR_NULL_POINTER;
191 if (pFileData == NULL) {
192 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
193 dbHandle->endTrans(false);
194 return MSG_ERR_STORAGE_ERROR;
197 MSG_DEBUG("file size [%d]", fileSize);
200 err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
202 if (err != MSG_SUCCESS) {
203 dbHandle->endTrans(false);
204 return MSG_ERR_STORAGE_ERROR;
207 if (pMsg->msgType.subType == MSG_SENDREQ_MMS
208 || pMsg->msgType.subType == MSG_RETRIEVE_MMS
209 || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS
210 || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
211 MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
213 err = MsgStoUpdateMMSMessage(pMsg);
215 if (err != MSG_SUCCESS) {
216 dbHandle->endTrans(false);
217 return MSG_ERR_STORAGE_ERROR;
221 } else if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL) {
222 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
224 dbHandle->endTrans(false);
225 return MSG_ERR_NULL_POINTER;
227 err = plg->addMessage(pMsg, pSendOptInfo, NULL);
228 if (err != MSG_SUCCESS) {
229 dbHandle->endTrans(false);
230 return MSG_ERR_STORAGE_ERROR;
234 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
235 char *pMmsSerializedData = NULL;
236 unique_ptr<char*, void(*)(char**)> buf_mms(&pMmsSerializedData, unique_ptr_deleter);
238 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
239 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
242 dbHandle->endTrans(false);
243 return MSG_ERR_NULL_POINTER;
246 if (MsgOpenAndReadFile(pMsg->msgData, &pMmsSerializedData, &fileSize) == false) {
247 dbHandle->endTrans(false);
248 return MSG_ERR_STORAGE_ERROR;
251 MSG_DEBUG("file size [%d]", fileSize);
253 err = plg->addMessage(pMsg, pSendOptInfo, pMmsSerializedData);
255 if (err != MSG_SUCCESS) {
256 dbHandle->endTrans(false);
257 return MSG_ERR_STORAGE_ERROR;
260 * if (pMsg->msgText[0] != '\0') {
261 * g_file_get_contents((gchar*)pMsg->msgText, (gchar**)&pFileData, (gsize*)&fileSize, NULL);
262 * MSG_DEBUG("file size [%d]", fileSize);
266 if (pMsg->msgType.subType == MSG_SENDREQ_MMS
267 || pMsg->msgType.subType == MSG_RETRIEVE_MMS
268 || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS
269 || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
270 MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
271 err = MsgStoUpdateMMSMessage(pMsg);
275 if (pMsg->bTextSms == false) {
276 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
277 dbHandle->endTrans(false);
278 return MSG_ERR_STORAGE_ERROR;
280 MSG_DEBUG("file size [%d]", fileSize);
284 dbHandle->endTrans(true);
292 msg_error_t MsgStoUpdateMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
294 msg_error_t err = MSG_SUCCESS;
296 char sqlQuery[MAX_QUERY_LEN+1];
298 msg_thread_id_t convId = 0;
299 MsgDbHandler *dbHandle = getDbHandle();
300 dbHandle->beginTrans();
302 MSG_MAIN_TYPE_T prevType;
303 memset(sqlQuery, 0x00, sizeof(sqlQuery));
304 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE FROM %s WHERE MSG_ID = %d;",
305 MSGFW_MESSAGE_TABLE_NAME, pMsg->msgId);
307 MSG_DEBUG("QUERY : %s", sqlQuery);
309 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
310 dbHandle->endTrans(false);
311 return MSG_ERR_DB_PREPARE;
314 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
315 dbHandle->finalizeQuery();
316 dbHandle->endTrans(false);
317 return MSG_ERR_STORAGE_ERROR;
320 prevType = dbHandle->columnInt(0);
321 dbHandle->finalizeQuery();
323 /* check msg type with previous type */
324 if (prevType != pMsg->msgType.mainType) {
325 MSG_DEBUG("different msg type to update [prev : %d], [current : %d]", prevType, pMsg->msgType.mainType);
327 err = MsgStoDeleteMessage(pMsg->msgId, false);
328 if (err != MSG_SUCCESS) {
329 dbHandle->endTrans(false);
333 err = MsgStoAddMessage(pMsg, pSendOptInfo);
334 if (err != MSG_SUCCESS) {
335 dbHandle->endTrans(false);
339 dbHandle->endTrans(false);
343 if (pMsg->nAddressCnt > 0) {
345 err = MsgStoAddAddress(dbHandle, pMsg, &convId);
347 if (err != MSG_SUCCESS) {
348 dbHandle->endTrans(false);
355 char *pFileData = NULL;
356 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
359 if (pMsg->bTextSms == false) {
360 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
361 dbHandle->endTrans(false);
362 return MSG_ERR_STORAGE_ERROR;
366 if (pSendOptInfo != NULL) {
367 /* Get Global setting value if bSetting == false */
368 if (pSendOptInfo->bSetting == false) {
369 if (MsgSettingGetBool(MSG_KEEP_COPY, &pSendOptInfo->bKeepCopy) != MSG_SUCCESS)
370 MSG_INFO("MsgSettingGetBool() is failed");
372 if (pMsg->msgType.mainType == MSG_SMS_TYPE) {
373 if (MsgSettingGetBool(SMS_SEND_DELIVERY_REPORT, &pSendOptInfo->bDeliverReq) != MSG_SUCCESS)
374 MSG_INFO("MsgSettingGetBool() is failed");
376 if (MsgSettingGetBool(SMS_SEND_REPLY_PATH, &pSendOptInfo->option.smsSendOptInfo.bReplyPath) != MSG_SUCCESS)
377 MSG_INFO("MsgSettingGetBool() is failed");
378 } else if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
379 if (MsgSettingGetBool(MMS_SEND_DELIVERY_REPORT, &pSendOptInfo->bDeliverReq) != MSG_SUCCESS)
380 MSG_INFO("MsgSettingGetBool() is failed");
382 if (MsgSettingGetBool(MMS_SEND_READ_REPLY, &pSendOptInfo->option.mmsSendOptInfo.bReadReq) != MSG_SUCCESS)
383 MSG_INFO("MsgSettingGetBool() is failed");
386 if (MsgSettingGetInt(MMS_SEND_EXPIRY_TIME, &tmpVal) != MSG_SUCCESS) {
387 MSG_INFO("MsgSettingGetInt() is failed");
389 pSendOptInfo->option.mmsSendOptInfo.expiryTime.time = (unsigned int)tmpVal;
391 if (MsgSettingGetInt(MMS_SEND_DELIVERY_TIME, &tmpVal) != MSG_SUCCESS) {
392 MSG_INFO("MsgSettingGetInt() is failed");
394 MSG_MMS_DELIVERY_TIME_T deliveryTime = (MSG_MMS_DELIVERY_TIME_T)tmpVal;
396 if (deliveryTime == MSG_DELIVERY_TIME_CUSTOM) {
397 pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime = true;
398 if (MsgSettingGetInt(MMS_SEND_CUSTOM_DELIVERY, &tmpVal) != MSG_SUCCESS) {
399 MSG_INFO("MsgSettingGetInt() is failed");
401 pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = (unsigned int)tmpVal;
403 pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime = false;
404 pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = (unsigned int)deliveryTime;
407 if (MsgSettingGetInt(MMS_SEND_PRIORITY, &tmpVal) != MSG_SUCCESS) {
408 MSG_INFO("MsgSettingGetInt() is failed");
410 pSendOptInfo->option.mmsSendOptInfo.priority = (msg_priority_type_t)tmpVal;
416 memset(sqlQuery, 0x00, sizeof(sqlQuery));
418 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET CONV_ID = %d, FOLDER_ID = %d, STORAGE_ID = %d, MAIN_TYPE = %d, SUB_TYPE = %d, \
419 DISPLAY_TIME = %lu, DATA_SIZE = %d, NETWORK_STATUS = %d, READ_STATUS = %d, PROTECTED = %d, PRIORITY = %d, MSG_DIRECTION = %d, \
420 BACKUP = %d, SUBJECT = ?, MSG_TEXT = ? \
422 MSGFW_MESSAGE_TABLE_NAME, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->displayTime, pMsg->dataSize,
423 pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction, pMsg->bBackup, pMsg->msgId);
425 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
426 dbHandle->endTrans(false);
427 return MSG_ERR_DB_EXEC;
430 dbHandle->bindText(pMsg->subject, 1);
432 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pMsg->bTextSms == false)
433 dbHandle->bindText(pFileData, 2);
435 dbHandle->bindText(pMsg->msgText, 2);
437 MSG_DEBUG("%s", sqlQuery);
439 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
440 dbHandle->finalizeQuery();
441 dbHandle->endTrans(false);
442 return MSG_ERR_DB_EXEC;
445 dbHandle->finalizeQuery();
447 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL) {
448 if (pSendOptInfo->bSetting == true) {
449 memset(sqlQuery, 0x00, sizeof(sqlQuery));
450 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET "
455 "WHERE MSG_ID = %d;",
456 MSGFW_SMS_SENDOPT_TABLE_NAME,
457 pSendOptInfo->bDeliverReq,
458 pSendOptInfo->bKeepCopy,
459 pSendOptInfo->option.smsSendOptInfo.bReplyPath,
463 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
464 dbHandle->endTrans(false);
465 return MSG_ERR_DB_EXEC;
468 } else if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
469 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
471 dbHandle->endTrans(false);
472 return MSG_ERR_NULL_POINTER;
475 err = plg->updateMessage(pMsg, pSendOptInfo, pFileData);
477 if (err != MSG_SUCCESS) {
478 dbHandle->endTrans(false);
479 return MSG_ERR_STORAGE_ERROR;
482 if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
483 MSG_SEC_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
485 err = MsgStoUpdateMMSMessage(pMsg);
487 if (err != MSG_SUCCESS) {
488 dbHandle->endTrans(false);
489 return MSG_ERR_STORAGE_ERROR;
494 err = MsgStoUpdateConversation(dbHandle, convId);
496 if (err != MSG_SUCCESS) {
497 dbHandle->endTrans(false);
498 return MSG_ERR_STORAGE_ERROR;
501 err = MsgStoClearConversationTable(dbHandle);
503 if (err != MSG_SUCCESS) {
504 dbHandle->endTrans(false);
505 return MSG_ERR_STORAGE_ERROR;
508 dbHandle->endTrans(true);
514 msg_error_t MsgStoUpdateReadStatus(msg_message_id_t msgId, bool bRead)
516 char sqlQuery[MAX_QUERY_LEN+1];
518 msg_storage_id_t storageId;
520 MsgDbHandler *dbHandle = getDbHandle();
521 if (MsgStoSetReadStatus(dbHandle, msgId, bRead) != MSG_SUCCESS) {
522 MSG_DEBUG("MsgStoSetReadStatus() Error");
523 return MSG_ERR_STORAGE_ERROR;
526 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
529 #ifndef FEATURE_SMS_CDMA
531 memset(sqlQuery, 0x00, sizeof(sqlQuery));
532 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT STORAGE_ID FROM %s WHERE MSG_ID = %d;",
533 MSGFW_MESSAGE_TABLE_NAME, msgId);
535 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
536 return MSG_ERR_DB_PREPARE;
538 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
539 storageId = dbHandle->columnInt(0);
541 dbHandle->finalizeQuery();
542 return MSG_ERR_DB_STEP;
544 dbHandle->finalizeQuery();
546 MSG_DEBUG("StorageId:[%d]", storageId);
548 /* Update Read Status for SIM Msg */
549 if (storageId == MSG_STORAGE_SIM) {
550 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
553 MSG_DEBUG("SMS Plug-in is NULL");
554 return MSG_ERR_NULL_POINTER;
558 memset(sqlQuery, 0x00, sizeof(sqlQuery));
559 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
560 MSGFW_SIM_MSG_TABLE_NAME, msgId);
562 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
563 return MSG_ERR_DB_PREPARE;
566 msg_sim_slot_id_t sim_idx;
568 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
569 sim_idx = dbHandle->columnInt(0);
570 simId = dbHandle->columnInt(1);
572 if (plg->setReadStatus(sim_idx, simId) != MSG_SUCCESS) {
573 MSG_DEBUG("Fail to Set Read Status for SIM SMS");
577 dbHandle->finalizeQuery();
586 msg_error_t MsgStoUpdateThreadReadStatus(msg_thread_id_t threadId, msg_id_list_s *pMsgIdList)
590 msg_error_t err = MSG_SUCCESS;
592 char sqlQuery[MAX_QUERY_LEN+1];
594 /*** Get msg id list **/
595 int rowCnt = 0, index = 0;
596 pMsgIdList->nCount = 0;
597 MsgDbHandler *dbHandle = getDbHandle();
599 memset(sqlQuery, 0x00, sizeof(sqlQuery));
600 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s "
601 "WHERE CONV_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d AND FOLDER_ID < %d;",
602 MSGFW_MESSAGE_TABLE_NAME,
603 threadId, MSG_STORAGE_PHONE, MSG_SPAMBOX_ID);
605 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
607 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
608 MSG_DEBUG("Fail to getTable().");
609 dbHandle->freeTable();
614 dbHandle->freeTable();
618 pMsgIdList->nCount = rowCnt;
619 MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
621 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
623 for (int i = 0; i < rowCnt; i++)
624 pMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
626 dbHandle->freeTable();
629 /* set read status */
630 dbHandle->beginTrans();
631 memset(sqlQuery, 0x00, sizeof(sqlQuery));
632 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET READ_STATUS = %d "
633 "WHERE CONV_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d AND FOLDER_ID < %d;",
634 MSGFW_MESSAGE_TABLE_NAME, 1,
635 threadId, MSG_STORAGE_PHONE, MSG_SPAMBOX_ID);
637 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
638 dbHandle->endTrans(false);
639 return MSG_ERR_DB_EXEC;
643 if (MsgStoUpdateConversation(dbHandle, threadId) != MSG_SUCCESS) {
644 MSG_DEBUG("MsgStoUpdateConversation() Error");
645 dbHandle->endTrans(false);
646 return MSG_ERR_STORAGE_ERROR;
649 dbHandle->endTrans(true);
650 if (g_idle_add(resetNotification, NULL) == 0) {
651 MSG_DEBUG("resetNotification() Error");
660 msg_error_t MsgStoUpdateProtectedStatus(msg_message_id_t msgId, bool bProtected)
662 char sqlQuery[MAX_QUERY_LEN+1];
663 MsgDbHandler *dbHandle = getDbHandle();
665 memset(sqlQuery, 0x00, sizeof(sqlQuery));
666 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET PROTECTED = %d WHERE MSG_ID = %d;",
667 MSGFW_MESSAGE_TABLE_NAME, (int)bProtected, msgId);
669 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
670 return MSG_ERR_DB_EXEC;
676 msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
680 MSG_DEBUG("Msg Id : %d", msgId);
682 msg_error_t err = MSG_SUCCESS;
684 char sqlQuery[MAX_QUERY_LEN+1];
685 MsgDbHandler *dbHandle = getDbHandle();
687 /* delete report notification */
688 char tempAddr[MAX_ADDRESS_VAL_LEN+1];
689 memset(tempAddr, 0x00, sizeof(tempAddr));
690 memset(sqlQuery, 0x00, sizeof(sqlQuery));
691 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;"
692 , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, msgId);
694 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
695 return MSG_ERR_DB_PREPARE;
697 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
698 dbHandle->finalizeQuery();
699 return MSG_ERR_DB_DONE;
702 snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
704 MSG_SEC_DEBUG("Updated address = %s", tempAddr);
706 MsgDeleteReportNotification(tempAddr);
708 dbHandle->finalizeQuery();
710 /* Get SUB_TYPE, STORAGE_ID */
711 memset(sqlQuery, 0x00, sizeof(sqlQuery));
712 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE, FOLDER_ID, STORAGE_ID, READ_STATUS, CONV_ID, SIM_INDEX \
713 FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
715 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
716 MSG_DEBUG("Query Failed [%s]", sqlQuery);
717 return MSG_ERR_DB_PREPARE;
720 MSG_MESSAGE_TYPE_S msgType;
721 msg_folder_id_t folderId;
722 msg_storage_id_t storageId;
723 msg_thread_id_t convId;
724 msg_sim_slot_id_t simIndex;
727 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
728 msgType.mainType = dbHandle->columnInt(0);
729 msgType.subType = dbHandle->columnInt(1);
730 folderId = dbHandle->columnInt(2);
731 storageId = dbHandle->columnInt(3);
732 bRead = dbHandle->columnInt(4);
733 convId = dbHandle->columnInt(5);
734 simIndex = dbHandle->columnInt(6);
736 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);
738 MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
740 dbHandle->finalizeQuery();
742 return MSG_ERR_DB_STEP;
745 dbHandle->finalizeQuery();
747 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
750 MSG_DEBUG("SMS Plug-in is NULL");
751 return MSG_ERR_NULL_POINTER;
754 dbHandle->beginTrans();
756 #ifndef FEATURE_SMS_CDMA
757 /* Check sim message */
758 if (storageId == MSG_STORAGE_SIM) {
759 msg_sim_id_t simMsgId;
760 msg_sim_slot_id_t sim_idx;
763 /* get sim message id */
764 memset(sqlQuery, 0x00, sizeof(sqlQuery));
765 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
766 MSGFW_SIM_MSG_TABLE_NAME, msgId);
768 MSG_DEBUG("sqlQuery is [%s]", sqlQuery);
770 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
771 dbHandle->endTrans(false);
772 return MSG_ERR_DB_PREPARE;
775 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
779 sim_idx = dbHandle->columnInt(0);
780 simMsgId = dbHandle->columnInt(1);
782 MSG_DEBUG("SIM Msg Id : [%d]", simMsgId);
784 err = plg->deleteSimMessage(sim_idx, simMsgId);
786 if (err != MSG_SUCCESS) {
787 dbHandle->finalizeQuery();
788 dbHandle->endTrans(false);
792 dbHandle->finalizeQuery();
794 /*Sim message delete in db table */
795 memset(sqlQuery, 0x00, sizeof(sqlQuery));
796 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE SIM_ID = %d AND SIM_SLOT_ID =%d;", MSGFW_SIM_MSG_TABLE_NAME, simMsgId, sim_idx);
798 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
799 dbHandle->finalizeQuery();
800 dbHandle->endTrans(false);
801 return MSG_ERR_DB_EXEC;
805 dbHandle->finalizeQuery();
808 /* each type has to be handled in plug in ? */
809 if (msgType.mainType == MSG_SMS_TYPE) {
810 memset(sqlQuery, 0x00, sizeof(sqlQuery));
811 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
812 MSGFW_SMS_SENDOPT_TABLE_NAME, msgId);
814 /* Delete SMS Send Option */
815 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
816 dbHandle->endTrans(false);
817 return MSG_ERR_DB_EXEC;
820 memset(sqlQuery, 0x00, sizeof(sqlQuery));
821 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
822 MSGFW_SMS_REPORT_TABLE_NAME, msgId);
824 /* Delete Data from SMS_REPORT table */
825 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
826 dbHandle->endTrans(false);
827 return MSG_ERR_DB_EXEC;
830 if (msgType.subType == MSG_CB_SMS || msgType.subType == MSG_JAVACB_SMS) {
831 memset(sqlQuery, 0x00, sizeof(sqlQuery));
832 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
833 MSGFW_CB_MSG_TABLE_NAME, msgId);
835 /* Delete Push Message from push table */
836 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
837 dbHandle->endTrans(false);
838 return MSG_ERR_DB_EXEC;
840 } else if (msgType.subType >= MSG_WAP_SI_SMS && msgType.subType <= MSG_WAP_CO_SMS) {
841 memset(sqlQuery, 0x00, sizeof(sqlQuery));
842 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
843 MSGFW_PUSH_MSG_TABLE_NAME, msgId);
845 /* Delete Push Message from push table */
846 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
847 dbHandle->endTrans(false);
848 return MSG_ERR_DB_EXEC;
850 } else if (msgType.subType == MSG_SYNCML_CP) {
851 memset(sqlQuery, 0x00, sizeof(sqlQuery));
852 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
853 MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
855 /* Delete SyncML Message from syncML table */
856 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
857 dbHandle->endTrans(false);
858 return MSG_ERR_DB_EXEC;
861 } else if (msgType.mainType == MSG_MMS_TYPE) {
862 char filePath[MSG_FILEPATH_LEN_MAX + 1] = {0, };
863 char dirPath[MSG_FILEPATH_LEN_MAX + 1]= {0, };
865 /*remove multipart */
866 memset(sqlQuery, 0x00, sizeof(sqlQuery));
867 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
868 MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
870 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
871 dbHandle->endTrans(false);
872 return MSG_ERR_DB_PREPARE;
875 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
876 memset(filePath, 0x00, sizeof(filePath));
877 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
878 if (remove(filePath) == -1)
879 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
881 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
883 dbHandle->finalizeQuery();
885 /* Delete Data from Multipart table */
886 memset(sqlQuery, 0x00, sizeof(sqlQuery));
887 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
888 MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
890 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
891 dbHandle->endTrans(false);
892 return MSG_ERR_DB_EXEC;
895 memset(sqlQuery, 0x00, sizeof(sqlQuery));
896 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
897 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
899 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
900 dbHandle->endTrans(false);
901 return MSG_ERR_DB_PREPARE;
904 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
905 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
907 snprintf(dirPath, MSG_FILEPATH_LEN_MAX, "%s.dir", filePath);
909 if (remove(filePath) == -1)
910 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
912 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
919 MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
920 dbHandle->finalizeQuery();
921 dbHandle->endTrans(false);
922 return MSG_ERR_DB_STEP;
925 dbHandle->finalizeQuery();
927 /* remove thumbnail file */
928 memset(sqlQuery, 0x00, sizeof(sqlQuery));
929 snprintf(sqlQuery, sizeof(sqlQuery),
930 "SELECT VALUE FROM %s "
931 "WHERE MSG_ID = %d AND (TYPE=%d OR TYPE=%d);",
932 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO);
934 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
935 dbHandle->endTrans(false);
936 return MSG_ERR_DB_PREPARE;
939 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
940 memset(filePath, 0x00, sizeof(filePath));
941 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
942 if (remove(filePath) == -1)
943 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
945 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
948 dbHandle->finalizeQuery();
950 memset(sqlQuery, 0x00, sizeof(sqlQuery));
951 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
952 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId);
954 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
955 dbHandle->endTrans(false);
956 return MSG_ERR_DB_EXEC;
959 memset(sqlQuery, 0x00, sizeof(sqlQuery));
960 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
961 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
963 /* Delete Data from MMS table */
964 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
965 dbHandle->endTrans(false);
966 return MSG_ERR_DB_EXEC;
969 memset(sqlQuery, 0x00, sizeof(sqlQuery));
970 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
971 MSGFW_REPORT_TABLE_NAME, msgId);
973 /* Delete Data from MMS STATUS table */
974 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
975 dbHandle->endTrans(false);
976 return MSG_ERR_DB_EXEC;
980 memset(sqlQuery, 0x00, sizeof(sqlQuery));
981 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
983 /* Delete Message from msg table */
984 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
985 dbHandle->endTrans(false);
986 return MSG_ERR_DB_EXEC;
989 #ifdef FEATURE_SMS_CDMA
990 memset(sqlQuery, 0x00, sizeof(sqlQuery));
991 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_UNIQUENESS_INFO_TABLE_NAME, msgId);
993 /* Delete Message from uniqueness table */
994 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
995 dbHandle->endTrans(false);
996 return MSG_ERR_DB_EXEC;
1001 /* Clear Conversation table */
1002 if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
1003 dbHandle->endTrans(false);
1004 return MSG_ERR_DB_EXEC;
1007 /* Update conversation table. */
1008 if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
1009 dbHandle->endTrans(false);
1010 return MSG_ERR_STORAGE_ERROR;
1013 dbHandle->endTrans(true);
1015 if (msgType.mainType == MSG_SMS_TYPE && folderId == MSG_INBOX_ID) {
1016 msgType.classType = MSG_CLASS_NONE;
1018 /* Set memory status in SIM */
1019 if (MsgStoCheckMsgCntFull(dbHandle, &msgType, folderId) == MSG_SUCCESS) {
1020 MSG_DEBUG("Set Memory Status");
1022 plg->setMemoryStatus(simIndex, MSG_SUCCESS);
1026 if (bCheckIndication == true) {
1027 MSG_DEBUG("bCheckIndication is true.");
1028 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1035 msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyDB, msg_id_list_s *pMsgIdList)
1037 msg_error_t err = MSG_SUCCESS;
1039 char sqlQuery[MAX_QUERY_LEN+1];
1041 queue<msg_thread_id_t> threadList;
1043 #ifdef FEATURE_SMS_CDMA
1044 const char *tableList[] = {MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1045 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1046 MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1047 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1048 MSGFW_UNIQUENESS_INFO_TABLE_NAME};
1050 const char *tableList[] = {MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1051 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1052 MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1053 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME};
1056 int listCnt = sizeof(tableList)/sizeof(char *);
1058 MsgDbHandler *dbHandle = getDbHandle();
1059 signed char folder_id;
1061 /* Get conversation ID from Folder */
1062 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1064 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE FOLDER_ID = %d",
1065 MSGFW_MESSAGE_TABLE_NAME, folderId);
1067 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1069 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1070 MSG_DEBUG("Fail to getTable().");
1071 dbHandle->freeTable();
1076 dbHandle->freeTable();
1080 for (int i = 1; i <= rowCnt; i++) {
1081 MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
1082 threadList.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1085 dbHandle->freeTable();
1087 /*** Get msg id list **/
1088 msg_id_list_s *pToDeleteMsgIdList = NULL;
1089 pToDeleteMsgIdList = (msg_id_list_s *)new char[sizeof(msg_id_list_s)];
1090 if (pToDeleteMsgIdList == NULL) {
1091 MSG_DEBUG("pToDeleteMsgIdList is NULL.");
1092 return MSG_ERR_NULL_POINTER;
1094 memset(pToDeleteMsgIdList, 0x00, sizeof(msg_id_list_s));
1096 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1097 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d",
1098 MSGFW_MESSAGE_TABLE_NAME, folderId);
1103 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
1105 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1106 MSG_DEBUG("Fail to getTable().");
1107 dbHandle->freeTable();
1112 dbHandle->freeTable();
1118 pToDeleteMsgIdList->nCount = rowCnt;
1120 MSG_DEBUG("pToDeleteMsgIdList->nCount [%d]", pToDeleteMsgIdList->nCount);
1122 pToDeleteMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
1124 for (int i = 0; i < rowCnt; i++)
1125 pToDeleteMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
1127 dbHandle->freeTable();
1130 /*** Delete Sim Message In Folder **/
1131 folder_id = (signed char)folderId;
1132 if (folder_id >= MSG_INBOX_ID) {
1133 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1135 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d AND STORAGE_ID = %d",
1136 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_SIM);
1140 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1141 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1142 dbHandle->freeTable();
1146 for (int i = 1; i <= rowCnt; i++) {
1147 err = MsgStoDeleteMessage(dbHandle->getColumnToInt(i), false);
1149 if (err != MSG_SUCCESS) {
1150 MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
1152 dbHandle->freeTable();
1157 /*Delete phone log */
1158 /* MsgDeletePhoneLog(dbHandle->getColumnToInt(i)); */
1161 dbHandle->freeTable();
1164 dbHandle->beginTrans();
1166 for (int i = 0; i < listCnt; i++) {
1167 if (!strcmp(tableList[i], MMS_PLUGIN_MESSAGE_TABLE_NAME)) {
1170 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1171 char dirPath[MSG_FILEPATH_LEN_MAX] = {0, };
1172 /* remove multipart */
1173 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1174 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s;",
1175 MSGFW_MMS_MULTIPART_TABLE_NAME);
1177 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1178 dbHandle->endTrans(false);
1179 return MSG_ERR_DB_PREPARE;
1182 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1183 memset(filePath, 0x00, sizeof(filePath));
1184 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
1185 if (remove(filePath) == -1)
1186 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1188 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1190 dbHandle->finalizeQuery();
1192 /* Delete Data from Multipart table */
1193 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1194 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;",
1195 MSGFW_MMS_MULTIPART_TABLE_NAME);
1197 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1198 err = MSG_ERR_DB_EXEC;
1199 dbHandle->endTrans(false);
1203 /*get mms msg id list */
1204 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1205 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.FILE_PATH FROM %s A, %s B \
1206 WHERE A.FOLDER_ID = %d AND A.MAIN_TYPE = %d AND A.MSG_ID = B.MSG_ID",
1207 MSGFW_MESSAGE_TABLE_NAME, MMS_PLUGIN_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE);
1209 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1210 MSG_DEBUG("rowCnt %d", rowCnt);
1212 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1213 MSG_DEBUG("Fail to getTable().");
1215 dbHandle->freeTable();
1216 dbHandle->endTrans(false);
1221 for (int i = 1; i <= rowCnt; i++) {
1222 memset(filePath, 0x00, sizeof(filePath));
1223 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1225 MSG_SEC_DEBUG("filePath [%s]", filePath);
1227 /*delete raw file */
1228 snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
1230 if (remove(filePath) == -1)
1231 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1233 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1240 dbHandle->freeTable();
1243 /* delete thumbnail */
1244 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1245 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1246 snprintf(sqlQuery, sizeof(sqlQuery),
1247 "SELECT VALUE FROM %s "
1248 "WHERE (TYPE=%d OR TYPE=%d) "
1249 "AND (MSG_ID IN (SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d));",
1250 MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO, MSGFW_MESSAGE_TABLE_NAME, folderId);
1252 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1253 dbHandle->endTrans(false);
1254 return MSG_ERR_DB_PREPARE;
1257 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1258 memset(filePath, 0x00, sizeof(filePath));
1259 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
1260 if (remove(filePath) == -1)
1261 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1263 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1266 dbHandle->finalizeQuery();
1268 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1270 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN \
1271 (SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d);",
1272 tableList[i], MSGFW_MESSAGE_TABLE_NAME, folderId);
1274 /* Delete Message in specific folder from table */
1275 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1276 MSG_DEBUG("sqlQuery [%s]", sqlQuery);
1277 dbHandle->endTrans(false);
1278 err = MSG_ERR_DB_EXEC;
1284 /* Clear Conversation table */
1285 if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
1286 dbHandle->endTrans(false);
1287 err = MSG_ERR_DB_EXEC;
1292 /* Update Address */
1293 while (!threadList.empty()) {
1294 err = MsgStoUpdateConversation(dbHandle, threadList.front());
1298 if (err != MSG_SUCCESS) {
1299 dbHandle->endTrans(false);
1305 dbHandle->endTrans(true);
1307 /* Set pMsgIdList */
1308 if (pMsgIdList != NULL && pToDeleteMsgIdList->nCount > 0) {
1309 pMsgIdList->nCount = pToDeleteMsgIdList->nCount;
1311 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t)*pToDeleteMsgIdList->nCount];
1312 memcpy(pMsgIdList->msgIdList, pToDeleteMsgIdList->msgIdList, sizeof(msg_message_id_t)*pToDeleteMsgIdList->nCount);
1315 /* Create thread for noti and phone log delete. */
1317 if (pToDeleteMsgIdList->nCount > 0) {
1319 if (pToDeleteMsgIdList != NULL) {
1320 /*free peer info list */
1321 if (pToDeleteMsgIdList->msgIdList != NULL)
1322 delete [] pToDeleteMsgIdList->msgIdList;
1324 delete [] pToDeleteMsgIdList;
1327 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1334 MSG_DEBUG("Error case Free Memory");
1336 while (!threadList.empty()) {
1342 if (pToDeleteMsgIdList != NULL) {
1343 /*free peer info list */
1344 if (pToDeleteMsgIdList->msgIdList != NULL)
1345 delete [] pToDeleteMsgIdList->msgIdList;
1347 delete [] pToDeleteMsgIdList;
1354 msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
1360 msg_error_t err = MSG_SUCCESS;
1361 if (pMsgIdList->nCount < 1) {
1362 MSG_DEBUG("pMsgIdList->nCount < 1");
1366 char sqlQuery[MAX_QUERY_LEN+1];
1368 queue<msg_thread_id_t> threadList1, threadList2;
1370 #ifdef FEATURE_SMS_CDMA
1371 const char *tableList[] = {MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1372 MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1373 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1374 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1375 MSGFW_SMS_REPORT_TABLE_NAME, MSGFW_MMS_MULTIPART_TABLE_NAME,
1376 MSGFW_UNIQUENESS_INFO_TABLE_NAME};
1378 const char *tableList[] = {MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1379 MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1380 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1381 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1382 MSGFW_SMS_REPORT_TABLE_NAME, MSGFW_MMS_MULTIPART_TABLE_NAME};
1385 int listCnt = sizeof(tableList)/sizeof(char *);
1387 MsgDbHandler *dbHandle = getDbHandle();
1389 dbHandle->beginTrans();
1390 /* reset msgid temp table */
1391 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1392 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_TMP_MSGID_TABLE_NAME);
1393 MSG_DEBUG("[%s]", sqlQuery);
1395 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1396 dbHandle->endTrans(false);
1397 return MSG_ERR_DB_EXEC;
1400 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
1401 dbHandle->finalizeQuery();
1402 dbHandle->endTrans(false);
1403 return MSG_ERR_DB_EXEC;
1406 dbHandle->finalizeQuery();
1408 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1409 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (?)", MSGFW_TMP_MSGID_TABLE_NAME);
1410 MSG_DEBUG("[%s]", sqlQuery);
1411 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1412 dbHandle->endTrans(false);
1413 return MSG_ERR_DB_PREPARE;
1416 for (int i = 0; i < pMsgIdList->nCount; i++) {
1417 dbHandle->resetQuery();
1418 dbHandle->bindInt(pMsgIdList->msgIdList[i], 1);
1419 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
1420 dbHandle->finalizeQuery();
1421 dbHandle->endTrans(false);
1422 return MSG_ERR_DB_EXEC;
1426 dbHandle->finalizeQuery();
1427 dbHandle->endTrans(true);
1429 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1430 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE MSG_ID IN %s;", MSGFW_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1432 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1434 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1435 MSG_DEBUG("Fail to getTable().");
1436 dbHandle->freeTable();
1440 MSG_DEBUG("rowCnt [%d]", rowCnt);
1443 dbHandle->freeTable();
1447 for (int i = 1; i <= rowCnt; i++) {
1448 MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
1449 threadList1.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1450 threadList2.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1452 dbHandle->freeTable();
1454 /* delete report notification */
1455 char tempAddr[MAX_ADDRESS_VAL_LEN+1];
1456 while (!threadList1.empty()) {
1457 memset(tempAddr, 0x00, sizeof(tempAddr));
1458 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1459 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;"
1460 , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, threadList1.front());
1462 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1463 return MSG_ERR_DB_PREPARE;
1465 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
1466 dbHandle->finalizeQuery();
1467 return MSG_ERR_DB_DONE;
1470 snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
1472 MSG_SEC_DEBUG("Updated address = %s", tempAddr);
1474 MsgDeleteReportNotification(tempAddr);
1476 dbHandle->finalizeQuery();
1482 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1483 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d AND MSG_ID IN %s;",
1484 MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, MSGFW_TMP_MSGID_TABLE_NAME);
1487 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1489 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1490 MSG_DEBUG("Fail to getTable().");
1491 dbHandle->freeTable();
1495 for (int i = 1; i <= rowCnt; i++) {
1496 err = MsgStoDeleteMessage(dbHandle->getColumnToInt(i), false);
1497 if (err != MSG_SUCCESS) {
1498 MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
1501 dbHandle->freeTable();
1503 dbHandle->beginTrans();
1504 for (int i = 0; i < listCnt; i++) {
1506 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1507 char dirPath[MSG_FILEPATH_LEN_MAX] = {0, };
1511 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1512 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN %s;", MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1514 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1516 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1517 MSG_DEBUG("Fail to getTable().");
1521 MSG_DEBUG("rowCnt %d", rowCnt);
1523 for (int i = 1; i <= rowCnt; i++) {
1524 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1526 MSG_SEC_DEBUG("filePath [%s]", filePath);
1528 /* Delete raw file. */
1529 snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
1531 if (remove(filePath) == -1)
1532 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1534 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1540 dbHandle->freeTable();
1542 } else if (i == 1) {
1543 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1547 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1548 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT VALUE FROM %s WHERE (TYPE = %d OR TYPE = %d) AND MSG_ID IN %s;",
1549 MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO, MSGFW_TMP_MSGID_TABLE_NAME);
1551 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1553 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1554 MSG_DEBUG("Fail to getTable().");
1558 MSG_DEBUG("rowCnt %d", rowCnt);
1560 for (int i = 1; i <= rowCnt; i++) {
1561 memset(filePath, 0x00, sizeof(filePath));
1562 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1563 if (remove(filePath) == -1)
1564 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1566 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1568 dbHandle->freeTable();
1569 } else if (!strcmp(tableList[i], MSGFW_MMS_MULTIPART_TABLE_NAME)) {
1570 /* MMS file path to delete. */
1571 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1575 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1576 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN %s;", MSGFW_MMS_MULTIPART_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1578 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1580 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1581 MSG_DEBUG("Fail to getTable().");
1585 MSG_DEBUG("rowCnt %d", rowCnt);
1587 for (int i = 1; i <= rowCnt; i++) {
1588 memset(filePath, 0x00, sizeof(filePath));
1589 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1590 if (filePath[0] != '\0') {
1591 if (remove(filePath) == -1)
1592 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1594 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1597 dbHandle->freeTable();
1599 /* MMS thumbnail path to delete */
1600 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1601 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);
1603 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1605 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1606 MSG_DEBUG("Fail to getTable().");
1610 MSG_DEBUG("rowCnt %d", rowCnt);
1612 for (int i = 1; i <= rowCnt; i++) {
1613 memset(filePath, 0x00, sizeof(filePath));
1614 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1615 if (filePath[0] != '\0') {
1616 if (remove(filePath) == -1)
1617 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1619 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1623 dbHandle->freeTable();
1626 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1627 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN %s;", tableList[i], MSGFW_TMP_MSGID_TABLE_NAME);
1629 /* Delete Message in specific folder from table */
1630 err = dbHandle->execQuery(sqlQuery);
1631 if (err != MSG_SUCCESS) {
1632 MSG_DEBUG("Fail to execQuery().");
1636 /* Clear Conversation table */
1637 err = MsgStoClearConversationTable(dbHandle);
1638 if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoClearConversationTable().");
1640 /* Update Address */
1641 while (!threadList2.empty()) {
1642 err = MsgStoUpdateConversation(dbHandle, threadList2.front());
1643 if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoUpdateConversation().");
1646 err = dbHandle->endTrans(true);
1647 if (err != MSG_SUCCESS) {
1648 MSG_DEBUG("Fail to endTrans(true).");
1649 dbHandle->endTrans(false);
1653 if (g_idle_add(resetNotification, NULL) == 0) {
1654 MSG_DEBUG("resetNotification() Error");
1662 msg_error_t MsgStoMoveMessageToFolder(msg_message_id_t msgId, msg_folder_id_t destFolderId)
1664 msg_error_t err = MSG_SUCCESS;
1665 MSG_MESSAGE_TYPE_S msgType;
1666 msg_thread_id_t convId = 0;
1668 MsgStoGetMsgType(msgId, &msgType);
1670 char sqlQuery[MAX_QUERY_LEN+1];
1671 MsgDbHandler *dbHandle = getDbHandle();
1673 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1675 if (msgType.mainType == MSG_SMS_TYPE)
1676 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_ID = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, destFolderId, msgId);
1678 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_ID = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, destFolderId, msgId);
1680 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
1681 return MSG_ERR_DB_EXEC;
1683 /* get conversation id */
1684 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1686 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONV_ID FROM %s WHERE MSG_ID = %d;",
1687 MSGFW_MESSAGE_TABLE_NAME, msgId);
1689 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1690 return MSG_ERR_DB_PREPARE;
1692 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW)
1693 convId = dbHandle->columnInt(0);
1695 MSG_DEBUG("convId : %d", convId);
1697 dbHandle->finalizeQuery();
1699 /* update conversation table */
1700 err = MsgStoUpdateConversation(dbHandle, convId);
1702 /* update notification */
1703 signed char dest_folder_id = (signed char)destFolderId;
1704 if (dest_folder_id != MSG_SPAMBOX_ID)
1705 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1711 msg_error_t MsgStoMoveMessageToStorage(msg_message_id_t msgId, msg_storage_id_t destStorageId)
1715 msg_error_t err = MSG_SUCCESS;
1717 char sqlQuery[MAX_QUERY_LEN+1];
1718 MsgDbHandler *dbHandle = getDbHandle();
1720 MSG_DEBUG("msgId : %d, destStorageId : %d", msgId, destStorageId);
1722 switch (destStorageId) {
1723 case MSG_STORAGE_SIM : /* Move message to sim card */
1724 case MSG_STORAGE_SIM2 : {
1725 MSG_MESSAGE_INFO_S msgInfo;
1726 SMS_SIM_ID_LIST_S simIdList;
1728 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1729 memset(&simIdList, 0x00, sizeof(SMS_SIM_ID_LIST_S));
1731 if ((err = MsgStoGetMessage(msgId, &msgInfo, NULL)) != MSG_SUCCESS)
1734 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
1736 MSG_DEBUG("SMS Plug-in is NULL");
1737 return MSG_ERR_NULL_POINTER;
1740 if (destStorageId == MSG_STORAGE_SIM)
1741 msgInfo.sim_idx = 1;
1742 else if (destStorageId == MSG_STORAGE_SIM2)
1743 msgInfo.sim_idx = 2;
1745 if ((err = plg->saveSimMessage(&msgInfo, &simIdList)) != MSG_SUCCESS)
1748 dbHandle->beginTrans();
1750 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1751 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d, SIM_INDEX = %d WHERE MSG_ID = %d;",
1752 MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, msgInfo.sim_idx, msgId);
1753 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1755 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1756 dbHandle->endTrans(false);
1757 return MSG_ERR_DB_EXEC;
1760 for (unsigned int i = 0; i < simIdList.count; i++) {
1761 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1762 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
1763 MSGFW_SIM_MSG_TABLE_NAME, msgInfo.sim_idx, simIdList.simId[i], msgId);
1764 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1766 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1767 dbHandle->endTrans(false);
1768 return MSG_ERR_DB_EXEC;
1772 dbHandle->endTrans(true);
1776 default: { /* Moving message to memory (when destination storage id is MSG_STORAGE_PHONE) */
1777 #ifndef FEATURE_SMS_CDMA
1778 bool bSimMsg = false;
1781 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1782 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT STORAGE_ID FROM %s WHERE MSG_ID = %d;",
1783 MSGFW_MESSAGE_TABLE_NAME, msgId);
1785 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1787 if (err != MSG_SUCCESS) {
1788 MSG_DEBUG("Fail to getTable().");
1789 dbHandle->freeTable();
1793 if (dbHandle->getColumnToInt(1) == MSG_STORAGE_SIM) {
1794 MSG_DEBUG("It is SIM Message");
1798 dbHandle->freeTable();
1800 if (bSimMsg == true) {
1801 msg_sim_id_t simMsgId;
1802 msg_sim_slot_id_t sim_idx;
1804 /* get sim message id */
1805 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1807 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
1808 MSGFW_SIM_MSG_TABLE_NAME, msgId);
1812 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
1814 if (err != MSG_SUCCESS) {
1815 MSG_DEBUG("Fail to getTable().");
1816 dbHandle->freeTable();
1820 /* Delete messages in sim card */
1821 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
1823 MSG_DEBUG("SMS Plug-in is NULL");
1824 dbHandle->freeTable();
1825 return MSG_ERR_NULL_POINTER;
1828 for (int i = 0; i < rowCnt; i++) {
1829 sim_idx = dbHandle->getColumnToInt(index++);
1830 simMsgId = dbHandle->getColumnToInt(index++);
1832 MSG_DEBUG("simMsgId is %d.", simMsgId);
1834 if ((err = plg->deleteSimMessage(sim_idx, simMsgId)) != MSG_SUCCESS) {
1835 dbHandle->freeTable();
1840 dbHandle->freeTable();
1842 dbHandle->beginTrans();
1844 /* Delete Messages in SIM Msg table */
1845 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1846 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
1847 MSGFW_SIM_MSG_TABLE_NAME, msgId);
1848 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1850 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1851 dbHandle->endTrans(false);
1852 return MSG_ERR_DB_EXEC;
1855 /* Move storage id */
1856 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1857 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d WHERE MSG_ID = %d;",
1858 MSGFW_MESSAGE_TABLE_NAME, destStorageId, msgId);
1859 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1861 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1862 dbHandle->endTrans(false);
1863 return MSG_ERR_DB_EXEC;
1866 dbHandle->endTrans(true);
1877 msg_error_t MsgStoCountMessage(msg_folder_id_t folderId, MSG_COUNT_INFO_S *pCountInfo)
1879 if (pCountInfo == NULL) {
1880 MSG_DEBUG("pCountInfo is NULL");
1881 return MSG_ERR_NULL_POINTER;
1884 char sqlQuery[MAX_QUERY_LEN+1];
1885 MsgDbHandler *dbHandle = getDbHandle();
1887 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1888 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 1 AND STORAGE_ID = %d "
1889 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d "
1890 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND STORAGE_ID = %d "
1891 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND STORAGE_ID = %d;",
1892 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_PHONE,
1893 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_PHONE,
1894 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_SMS_TYPE, MSG_STORAGE_PHONE,
1895 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE, MSG_STORAGE_PHONE);
1897 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1898 return MSG_ERR_DB_PREPARE;
1900 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1901 pCountInfo->nReadCnt = dbHandle->columnInt(0);
1903 dbHandle->finalizeQuery();
1904 return MSG_ERR_DB_STEP;
1907 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1908 pCountInfo->nUnreadCnt = dbHandle->columnInt(0);
1910 dbHandle->finalizeQuery();
1911 return MSG_ERR_DB_STEP;
1914 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1915 pCountInfo->nSms = dbHandle->columnInt(0);
1917 dbHandle->finalizeQuery();
1918 return MSG_ERR_DB_STEP;
1921 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1922 pCountInfo->nMms = dbHandle->columnInt(0);
1924 dbHandle->finalizeQuery();
1925 return MSG_ERR_DB_STEP;
1928 dbHandle->finalizeQuery();
1934 msg_error_t MsgStoCountMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount)
1936 if (pMsgType == NULL) {
1937 MSG_DEBUG("pMsgType is NULL");
1938 return MSG_ERR_NULL_POINTER;
1943 char sqlQuery[MAX_QUERY_LEN+1];
1944 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1946 MsgDbHandler *dbHandle = getDbHandle();
1948 if ((pMsgType->mainType == MSG_SMS_TYPE) &&
1949 (pMsgType->subType == MSG_NORMAL_SMS || pMsgType->subType == MSG_STATUS_REPORT_SMS || pMsgType->subType == MSG_CONCAT_SIM_SMS)) {
1950 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d);",
1951 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_NORMAL_SMS, MSG_STATUS_REPORT_SMS, MSG_CONCAT_SIM_SMS);
1952 } else if ((pMsgType->mainType == MSG_SMS_TYPE) &&
1953 (pMsgType->subType == MSG_WAP_SI_SMS || pMsgType->subType == MSG_WAP_SL_SMS)) {
1955 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d);",
1956 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_WAP_SI_SMS, MSG_WAP_SL_SMS);
1957 } else if ((pMsgType->mainType == MSG_MMS_TYPE) &&
1958 (pMsgType->subType == MSG_SENDREQ_MMS || pMsgType->subType == MSG_SENDCONF_MMS || pMsgType->subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgType->subType == MSG_RETRIEVE_MANUALCONF_MMS)) {
1960 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d, %d);",
1961 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_SENDREQ_MMS, MSG_SENDCONF_MMS, MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS);
1963 return MSG_ERR_INVALID_PARAMETER;
1966 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1967 return MSG_ERR_DB_PREPARE;
1969 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1970 *pMsgCount = dbHandle->columnInt(0);
1972 dbHandle->finalizeQuery();
1973 return MSG_ERR_DB_STEP;
1976 dbHandle->finalizeQuery();
1982 msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
1984 char sqlQuery[MAX_QUERY_LEN+1];
1985 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1986 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, \
1987 SUB_TYPE, DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
1988 BACKUP, PRIORITY, MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, THUMB_PATH, SIM_INDEX \
1989 FROM %s WHERE MSG_ID = %d;",
1990 MSGFW_MESSAGE_TABLE_NAME, msgId);
1992 MsgDbHandler *dbHandle = getDbHandle();
1994 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1995 return MSG_ERR_DB_PREPARE;
1997 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1998 pMsg->msgId = dbHandle->columnInt(0);
1999 pMsg->threadId = dbHandle->columnInt(1);
2000 pMsg->folderId = dbHandle->columnInt(2);
2001 pMsg->storageId = dbHandle->columnInt(3);
2002 pMsg->msgType.mainType = dbHandle->columnInt(4);
2003 pMsg->msgType.subType = dbHandle->columnInt(5);
2004 pMsg->displayTime = (time_t)dbHandle->columnInt(6);
2005 pMsg->dataSize = dbHandle->columnInt(7);
2006 pMsg->networkStatus = dbHandle->columnInt(8);
2007 pMsg->bRead = dbHandle->columnInt(9);
2008 pMsg->bProtected = dbHandle->columnInt(10);
2009 pMsg->bBackup = dbHandle->columnInt(11);
2010 pMsg->priority = dbHandle->columnInt(12);
2011 pMsg->direction = dbHandle->columnInt(13);
2013 strncpy(pMsg->subject, (char *)dbHandle->columnText(15), MAX_SUBJECT_LEN);
2015 /* Temp_File_Handling */
2016 if (pMsg->msgType.mainType == MSG_SMS_TYPE || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
2017 if (pMsg->dataSize > MAX_MSG_TEXT_LEN) {
2018 char msgData[pMsg->dataSize+1];
2019 memset(msgData, 0x00, sizeof(msgData));
2021 strncpy(msgData, (char *)dbHandle->columnText(16), pMsg->dataSize);
2023 /* Save Message Data into File */
2024 char fileName[MSG_FILENAME_LEN_MAX+1];
2025 memset(fileName, 0x00, sizeof(fileName));
2027 if (MsgCreateFileName(fileName) == false) {
2028 dbHandle->finalizeQuery();
2029 return MSG_ERR_STORAGE_ERROR;
2032 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, fileName);
2034 if (MsgWriteIpcFile(fileName, msgData, pMsg->dataSize) == false) {
2035 dbHandle->finalizeQuery();
2036 return MSG_ERR_STORAGE_ERROR;
2039 strncpy(pMsg->msgData, fileName, MAX_MSG_DATA_LEN);
2041 pMsg->bTextSms = false;
2043 memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
2044 strncpy(pMsg->msgText, (char *)dbHandle->columnText(16), pMsg->dataSize);
2046 /* For WAP PUSH SI Message */
2047 if (pMsg->msgType.subType == MSG_WAP_SI_SMS) {
2048 strncat(pMsg->msgText, "\n", MAX_MSG_TEXT_LEN-strlen(pMsg->msgText));
2049 strncat(pMsg->msgText, pMsg->subject, MAX_MSG_TEXT_LEN-strlen(pMsg->msgText));
2050 MSG_SEC_DEBUG("pMsg->msgText : [%s]", pMsg->msgText);
2051 pMsg->dataSize = sizeof(pMsg->msgText);
2054 pMsg->bTextSms = true;
2057 if (dbHandle->columnText(16) != NULL)
2058 strncpy(pMsg->msgText, (char *)dbHandle->columnText(16), MAX_MSG_TEXT_LEN);
2061 /* thumbnail path */
2062 if (dbHandle->columnText(17)!= NULL && ((char *)dbHandle->columnText(17))[0] != '\0') {
2063 strncpy(pMsg->thumbPath, (char *)dbHandle->columnText(17), MSG_FILEPATH_LEN_MAX);
2064 MSG_DEBUG("pMsg->thumbPath : [%s]", pMsg->thumbPath);
2066 pMsg->sim_idx = dbHandle->columnInt(18);
2068 dbHandle->finalizeQuery();
2069 MSG_DEBUG("%s", sqlQuery);
2070 return MSG_ERR_DB_STEP;
2073 dbHandle->finalizeQuery();
2076 /* get address information. */
2077 MsgStoGetAddressByMsgId(dbHandle, pMsg->msgId, &pMsg->nAddressCnt, &pMsg->addressList);
2079 /* Get MMS body if it is MMS. */
2080 if ((pMsg->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS &&
2081 (pMsg->msgType.subType == MSG_RETRIEVE_MMS || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS)) ||
2082 pMsg->msgType.subType == MSG_SENDREQ_MMS || pMsg->msgType.subType == MSG_SENDCONF_MMS || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
2083 msg_error_t err = MSG_SUCCESS;
2084 char *pDestMsg = NULL;
2085 int temp_size = pMsg->dataSize; /* save raw file size; */
2087 /* call mms plugin to get mms specific message data */
2088 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(pMsg->msgType.mainType);
2090 MSG_DEBUG("SMS Plug-in is NULL");
2091 return MSG_ERR_NULL_POINTER;
2094 err = plg->getMmsMessage(pMsg, pSendOptInfo, &pDestMsg);
2095 if (err != MSG_SUCCESS) {
2100 return MSG_ERR_STORAGE_ERROR;
2103 memset(pMsg->msgData, 0, MAX_MSG_DATA_LEN+1);
2105 /* Encode MMS specific data to MMS_MESSAGE_DATA_S */
2106 if (pMsg->dataSize > MAX_MSG_DATA_LEN) {
2107 /* Save Message Data into File */
2108 char tempFileName[MSG_FILENAME_LEN_MAX+1];
2109 memset(tempFileName, 0x00, sizeof(tempFileName));
2111 if (MsgCreateFileName(tempFileName) == false) {
2116 return MSG_ERR_STORAGE_ERROR;
2118 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, tempFileName);
2120 if (MsgWriteIpcFile(tempFileName, pDestMsg, pMsg->dataSize) == false) {
2125 return MSG_ERR_STORAGE_ERROR;
2127 strncpy(pMsg->msgData, tempFileName, MAX_MSG_DATA_LEN);
2128 pMsg->bTextSms = false;
2130 strncpy(pMsg->msgData, pDestMsg, pMsg->dataSize);
2131 pMsg->bTextSms = true;
2134 pMsg->dataSize = temp_size; /*raw file size; */
2142 /* Get SMS Sending Options */
2143 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL)
2144 MsgStoGetSmsSendOpt(pMsg, pSendOptInfo);
2149 msg_error_t MsgStoGetFailedMessage(int **failed_msg_list, int *count)
2153 msg_error_t err = MSG_SUCCESS;
2154 char sqlQuery[MAX_QUERY_LEN+1];
2155 int rowCnt = 0, index = 0;
2156 MsgDbHandler *dbHandle = getDbHandle();
2158 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2160 /* Folder ID == 2 : sending failed message, Folder ID == 1 : retrieve failed message */
2161 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);",
2162 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_PENDING, MSG_NETWORK_RETRIEVE_PENDING, MSG_OUTBOX_ID, MSG_INBOX_ID);
2163 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2165 if(err == MSG_ERR_DB_NORECORD) {
2166 dbHandle->freeTable();
2170 int *list = new int[rowCnt];
2172 for(int i = 0; i < rowCnt; ++i) {
2173 list[i] = dbHandle->getColumnToInt(index++);
2175 *failed_msg_list = list;
2176 dbHandle->freeTable();
2182 msg_error_t MsgStoAddSyncMLMessage(MSG_MESSAGE_INFO_S *pMsgInfo, int extId, int pinCode)
2186 msg_error_t err = MSG_SUCCESS;
2188 char sqlQuery[MAX_QUERY_LEN+1];
2190 unsigned int rowId = 0;
2191 msg_thread_id_t convId = 0;
2192 MsgDbHandler *dbHandle = getDbHandle();
2194 dbHandle->beginTrans();
2196 if (pMsgInfo->nAddressCnt > 0) {
2197 err = MsgStoAddAddress(dbHandle, pMsgInfo, &convId);
2199 if (err != MSG_SUCCESS) {
2200 dbHandle->endTrans(false);
2205 /* Add Message Table */
2206 pMsgInfo->threadId = convId;
2207 rowId = MsgStoAddMessageTable(dbHandle, pMsgInfo);
2210 dbHandle->endTrans(false);
2211 return MSG_ERR_DB_ROW;
2214 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2215 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
2216 MSGFW_SYNCML_MSG_TABLE_NAME, rowId, extId, pinCode);
2218 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
2219 dbHandle->endTrans(false);
2220 return MSG_ERR_DB_EXEC;
2223 if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
2224 dbHandle->endTrans(false);
2225 return MSG_ERR_STORAGE_ERROR;
2228 dbHandle->endTrans(true);
2230 pMsgInfo->msgId = (msg_message_id_t)rowId;
2232 MsgInsertNotification(pMsgInfo);
2233 if (MsgCheckNotificationSettingEnable())
2242 msg_error_t MsgStoGetMsgType(msg_message_id_t msgId, MSG_MESSAGE_TYPE_S *pMsgType)
2244 MsgDbHandler *dbHandle = getDbHandle();
2245 char sqlQuery[MAX_QUERY_LEN+1];
2247 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2249 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE FROM %s WHERE MSG_ID = %d;",
2250 MSGFW_MESSAGE_TABLE_NAME, msgId);
2252 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2253 return MSG_ERR_DB_PREPARE;
2255 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2256 pMsgType->mainType = dbHandle->columnInt(0);
2257 pMsgType->subType = dbHandle->columnInt(1);
2260 dbHandle->finalizeQuery();
2266 msg_error_t MsgStoGetQuickPanelData(msg_quickpanel_type_t QPtype, MSG_MESSAGE_INFO_S *pMsg)
2268 msg_error_t err = MSG_SUCCESS;
2270 MsgDbHandler *dbHandle = getDbHandle();
2271 char sqlQuery[MAX_QUERY_LEN+1];
2273 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2275 if (QPtype == MSG_QUICKPANEL_SMS) {
2276 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;",
2277 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_SMS_TYPE, MSG_NORMAL_SMS);
2278 } else if (QPtype == MSG_QUICKPANEL_MMS) {
2279 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;",
2280 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_MMS_TYPE, MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS);
2281 } else if (QPtype == MSG_QUICKPANEL_DELIVER_REP) {
2282 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE SUB_TYPE IN (%d, %d) AND READ_STATUS = 0 ORDER BY DISPLAY_TIME DESC;",
2283 MSGFW_MESSAGE_TABLE_NAME, MSG_STATUS_REPORT_SMS, MSG_DELIVERYIND_MMS);
2284 } else if (QPtype == MSG_QUICKPANEL_READ_REP) {
2285 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;",
2286 MSGFW_MESSAGE_TABLE_NAME, MSG_MMS_TYPE, MSG_READORGIND_MMS);
2287 } else if (QPtype == MSG_QUICKPANEL_VOICEMAIL) {
2288 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;",
2289 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MWI_VOICE_SMS);
2290 } else if (QPtype == MSG_QUICKPANEL_MMS_NOTI) {
2291 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;",
2292 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_MMS_TYPE, MSG_NOTIFICATIONIND_MMS);
2295 /* Get Message ID */
2296 msg_message_id_t msgId;
2298 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2299 return MSG_ERR_DB_PREPARE;
2301 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2302 msgId = dbHandle->columnInt(0);
2304 dbHandle->finalizeQuery();
2305 return MSG_ERR_DB_STEP;
2308 dbHandle->finalizeQuery();
2310 /* Get Message Info */
2311 err = MsgStoGetMessage(msgId, pMsg, NULL);
2317 msg_error_t MsgStoDeleteThreadMessageList(msg_thread_id_t threadId, bool bIncludeProtect, msg_id_list_s *pMsgIdList)
2319 msg_error_t err = MSG_SUCCESS;
2321 MsgDbHandler *dbHandle = getDbHandle();
2322 char sqlQuery[MAX_QUERY_LEN+1];
2324 /*** Get msg id list **/
2325 int rowCnt = 0, index = 0;
2327 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2329 #ifdef MSG_NOTI_INTEGRATION
2330 if (bIncludeProtect) {
2331 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2332 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
2333 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
2335 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2336 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0;",
2337 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
2340 if (bIncludeProtect) {
2341 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2342 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
2343 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
2345 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2346 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0;",
2347 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
2351 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2353 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
2354 MSG_ERR("Fail to getTable().");
2355 dbHandle->freeTable();
2360 dbHandle->freeTable();
2362 err = MsgStoClearConversationTable(dbHandle);
2363 if (err != MSG_SUCCESS) {
2364 MSG_ERR("Fail to MsgStoClearConversationTable().");
2368 err = MsgStoUpdateConversation(dbHandle, threadId);
2369 if (err != MSG_SUCCESS) {
2370 MSG_ERR("Fail to MsgStoUpdateConversation().");
2377 pMsgIdList->nCount = rowCnt;
2379 MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
2381 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
2383 for (int i = 0; i < rowCnt; i++)
2384 pMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
2386 dbHandle->freeTable();
2389 err = MsgStoDeleteMessageByList(pMsgIdList);
2390 if (err != MSG_SUCCESS) {
2391 MSG_ERR("Fail to MsgStoDeleteMessageByList().");
2399 msg_error_t MsgStoSetTempAddressTable(MSG_ADDRESS_INFO_S *pAddrInfo, int addr_cnt)
2401 MsgDbHandler *dbHandle = getDbHandle();
2402 char sqlQuery[MAX_QUERY_LEN+1];
2404 dbHandle->beginTrans();
2405 /* reset address temp table */
2406 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2407 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_ADDRESS_TEMP_TABLE_NAME);
2408 MSG_DEBUG("[%s]", sqlQuery);
2410 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2411 return MSG_ERR_DB_EXEC;
2413 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2414 dbHandle->finalizeQuery();
2415 dbHandle->endTrans(false);
2416 return MSG_ERR_DB_EXEC;
2419 dbHandle->finalizeQuery();
2421 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2422 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (?);", MSGFW_ADDRESS_TEMP_TABLE_NAME);
2423 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
2424 dbHandle->endTrans(false);
2425 return MSG_ERR_DB_PREPARE;
2428 char newPhoneNum[MAX_ADDRESS_VAL_LEN+1];
2429 char tmpNum[MAX_ADDRESS_VAL_LEN+1];
2430 for (int i = 0; i < addr_cnt; i++) {
2431 memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
2432 memset(tmpNum, 0x00, sizeof(tmpNum));
2433 MsgConvertNumber(pAddrInfo[i].addressVal, tmpNum, sizeof(tmpNum));
2434 snprintf(newPhoneNum, sizeof(newPhoneNum), "%%%%%s", tmpNum);
2435 dbHandle->resetQuery();
2436 dbHandle->bindText(newPhoneNum, 1);
2437 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2438 dbHandle->finalizeQuery();
2439 dbHandle->endTrans(false);
2440 return MSG_ERR_DB_EXEC;
2444 dbHandle->finalizeQuery();
2445 dbHandle->endTrans(true);
2451 msg_error_t MsgStoCountMsgByContact(const MSG_THREAD_LIST_INDEX_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pThreadCountInfo)
2453 MsgDbHandler *dbHandle = getDbHandle();
2454 char sqlQuery[MAX_QUERY_LEN+1];
2456 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2458 if (pAddrInfo->contactId > 0) {
2459 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) AS TOTAL, \
2460 SUM(CASE WHEN READ_STATUS = 0 AND FOLDER_ID = %d THEN 1 ELSE 0 END), \
2461 SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END), \
2462 SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END) \
2463 FROM (SELECT * FROM %s A JOIN %s B ON A.CONV_ID = B.CONV_ID WHERE B.CONTACT_ID = %d)",
2464 MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MMS_TYPE, MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pAddrInfo->contactId);
2466 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) AS TOTAL, \
2467 SUM(CASE WHEN READ_STATUS = 0 AND FOLDER_ID = %d THEN 1 ELSE 0 END), \
2468 SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END), \
2469 SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END) \
2470 FROM (SELECT * FROM %s A JOIN %s B ON A.CONV_ID = B.CONV_ID WHERE B.ADDRESS_VAL = '%s')",
2471 MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MMS_TYPE, MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pAddrInfo->msgAddrInfo.addressVal);
2474 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2475 return MSG_ERR_DB_PREPARE;
2477 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2478 pThreadCountInfo->totalCount = dbHandle->columnInt(0);
2479 pThreadCountInfo->unReadCount = dbHandle->columnInt(1);
2480 pThreadCountInfo->smsMsgCount = dbHandle->columnInt(2);
2481 pThreadCountInfo->mmsMsgCount = dbHandle->columnInt(3);
2483 dbHandle->finalizeQuery();
2484 return MSG_ERR_DB_STEP;
2487 dbHandle->finalizeQuery();
2493 msg_error_t MsgStoGetSyncMLExtId(msg_message_id_t msgId, int *extId)
2495 MsgDbHandler *dbHandle = getDbHandle();
2496 char sqlQuery[MAX_QUERY_LEN+1];
2498 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2500 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXT_ID FROM %s WHERE MSG_ID = %d;",
2501 MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
2503 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2504 return MSG_ERR_DB_PREPARE;
2506 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2507 *extId = dbHandle->columnInt(0);
2509 dbHandle->finalizeQuery();
2510 return MSG_ERR_DB_STEP;
2513 dbHandle->finalizeQuery();
2519 msg_error_t MsgStoGetSmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
2521 MsgDbHandler *dbHandle = getDbHandle();
2522 char sqlQuery[MAX_QUERY_LEN+1];
2523 msg_error_t err = MSG_SUCCESS;
2525 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2526 snprintf(sqlQuery, sizeof(sqlQuery),
2527 "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
2529 "WHERE MSG_ID = %d "
2530 "order by TIME ASC;"
2531 , MSGFW_SMS_REPORT_TABLE_NAME, msgId);
2533 int rowCnt = 0, index = 0;
2534 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2536 if (err != MSG_SUCCESS) {
2537 MSG_DEBUG("Fail to getTable().");
2538 dbHandle->freeTable();
2539 if (err == MSG_ERR_DB_NORECORD)
2545 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
2546 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
2548 for (int i = 0; i < rowCnt; i++) {
2549 dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
2550 report_status[i].type = dbHandle->getColumnToInt(index++);
2551 report_status[i].status = dbHandle->getColumnToInt(index++);
2552 report_status[i].statusTime = (time_t)dbHandle->getColumnToInt(index++);
2554 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);
2557 *pReportStatus = report_status;
2559 dbHandle->freeTable();
2564 msg_error_t MsgStoGetMmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
2566 MsgDbHandler *dbHandle = getDbHandle();
2567 char sqlQuery[MAX_QUERY_LEN+1];
2569 msg_direction_type_t direction = MSG_DIRECTION_TYPE_MO;
2571 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_DIRECTION FROM %s WHERE MSG_ID = %d;",
2572 MSGFW_MESSAGE_TABLE_NAME, msgId);
2574 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2575 return MSG_ERR_DB_PREPARE;
2577 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2578 direction = dbHandle->columnInt(0);
2581 dbHandle->finalizeQuery();
2583 if (direction == MSG_DIRECTION_TYPE_MO) {/*get received report list of MO message */
2584 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2585 /*MSG_ID INTEGER , ADDRESS_VAL TEXT , STATUS_TYPE INTEGER , STATUS INTEGER DEFAULT 0 , TIME DATETIME) */
2586 /*select * from MSG_REPORT_TABLE where MSG_ID=38 order by ADDRESS_VAL DESC, STATUS_TYPE ASC; */
2587 snprintf(sqlQuery, sizeof(sqlQuery),
2588 "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
2590 "WHERE MSG_ID = %d "
2591 "order by ADDRESS_VAL DESC, STATUS_TYPE ASC;"
2592 , MSGFW_REPORT_TABLE_NAME, msgId);
2594 int rowCnt = 0, index = 0;
2595 msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2596 if (err != MSG_SUCCESS) {
2597 MSG_DEBUG("Fail to getTable().");
2598 dbHandle->freeTable();
2599 if (err == MSG_ERR_DB_NORECORD)
2605 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
2606 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
2608 for (int i = 0; i < rowCnt; i++) {
2609 dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
2610 report_status[i].type = dbHandle->getColumnToInt(index++);
2611 report_status[i].status = dbHandle->getColumnToInt(index++);
2612 report_status[i].statusTime = (time_t)dbHandle->getColumnToInt(index++);
2614 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);
2617 *pReportStatus = report_status;
2619 dbHandle->freeTable();
2621 } else if (direction == MSG_DIRECTION_TYPE_MT) { /*read report sent status of MT message */
2622 int readReportSentStatus;
2624 if (MsgStoCheckReadReportRequested(dbHandle, msgId) == false) {
2626 *pReportStatus = NULL;
2627 return MSG_ERR_READREPORT_NOT_REQUESTED;
2630 MsgStoGetReadReportSendStatus(msgId, &readReportSentStatus);
2634 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)];
2635 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
2637 report_status->addressVal[0] = '\0';
2638 report_status->type = MSG_REPORT_TYPE_READ_REPORT_SENT;
2639 report_status->status = readReportSentStatus;
2640 report_status->statusTime = 0;
2642 MSG_DEBUG("report_type = %d, report_status = %d", report_status->type, report_status->status);
2644 *pReportStatus = report_status;
2651 msg_error_t MsgStoGetThreadIdByAddress(const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t *pThreadId)
2653 MsgDbHandler *dbHandle = getDbHandle();
2654 if(pMsg->nAddressCnt > 0) {
2655 if (MsgExistAddress(dbHandle, pMsg, pThreadId) == true) {
2656 MSG_DEBUG("Conversation ID : [%d]", *pThreadId);
2658 /* check thread count */
2659 MSG_THREAD_VIEW_S threadInfo;
2660 memset(&threadInfo, 0x00, sizeof(MSG_THREAD_VIEW_S));
2661 MsgStoGetThreadInfo(*pThreadId, &threadInfo);
2662 MSG_DEBUG("threadInfo.smsCnt [%d], threadInfo.mmsCnt [%d]", threadInfo.smsCnt, threadInfo.mmsCnt);
2663 if ((threadInfo.smsCnt + threadInfo.mmsCnt) > 0) {
2674 msg_error_t MsgStoGetThreadUnreadCnt(msg_thread_id_t threadId, int *cnt)
2678 MsgDbHandler *dbHandle = getDbHandle();
2682 char sqlQuery[MAX_QUERY_LEN+1];
2685 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2686 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s A \
2687 WHERE CONV_ID = %d AND READ_STATUS = 0;", MSGFW_MESSAGE_TABLE_NAME, threadId);
2689 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2690 return MSG_ERR_DB_PREPARE;
2692 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2693 msgCnt = dbHandle->columnInt(0);
2696 dbHandle->finalizeQuery();
2706 msg_error_t MsgStoGetThreadInfo(msg_thread_id_t threadId, MSG_THREAD_VIEW_S *pThreadInfo)
2710 MsgDbHandler *dbHandle = getDbHandle();
2711 int rowCnt = 0, index = 0;
2713 char sqlQuery[MAX_QUERY_LEN+1];
2714 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2716 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.UNREAD_CNT, A.SMS_CNT, A.MMS_CNT, "
2717 "A.MAIN_TYPE, A.SUB_TYPE, A.MSG_DIRECTION, A.DISPLAY_TIME, A.DISPLAY_NAME, A.MSG_TEXT, "
2718 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.PROTECTED = 1) AS PROTECTED, "
2719 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.FOLDER_ID = %d) AS DRAFT, "
2720 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.NETWORK_STATUS = %d) AS FAILED, "
2721 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.NETWORK_STATUS = %d) AS SENDING "
2722 "FROM %s A WHERE A.CONV_ID = %d AND A.SMS_CNT + A.MMS_CNT > 0;",
2723 MSGFW_MESSAGE_TABLE_NAME,
2724 MSGFW_MESSAGE_TABLE_NAME, MSG_DRAFT_ID,
2725 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_FAIL,
2726 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SENDING,
2727 MSGFW_CONVERSATION_TABLE_NAME, threadId);
2729 msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2731 if (err == MSG_ERR_DB_NORECORD) {
2732 dbHandle->freeTable();
2734 } else if (err != MSG_SUCCESS) {
2735 MSG_DEBUG("Fail to getTable().");
2736 dbHandle->freeTable();
2741 MSG_DEBUG("rowCnt is %d", rowCnt);
2742 dbHandle->freeTable();
2745 pThreadInfo->threadId = dbHandle->getColumnToInt(index++);
2747 pThreadInfo->unreadCnt = dbHandle->getColumnToInt(index++);
2748 pThreadInfo->smsCnt = dbHandle->getColumnToInt(index++);
2749 pThreadInfo->mmsCnt = dbHandle->getColumnToInt(index++);
2751 pThreadInfo->mainType = dbHandle->getColumnToInt(index++);
2752 pThreadInfo->subType = dbHandle->getColumnToInt(index++);
2754 pThreadInfo->direction = dbHandle->getColumnToInt(index++);
2755 pThreadInfo->threadTime = (time_t)dbHandle->getColumnToInt(index++);
2757 memset(pThreadInfo->threadName, 0x00, sizeof(pThreadInfo->threadName));
2758 dbHandle->getColumnToString(index++, MAX_THREAD_NAME_LEN, pThreadInfo->threadName);
2760 memset(pThreadInfo->threadData, 0x00, sizeof(pThreadInfo->threadData));
2761 dbHandle->getColumnToString(index++, MAX_THREAD_DATA_LEN, pThreadInfo->threadData);
2763 int protectedCnt = dbHandle->getColumnToInt(index++);
2764 if (protectedCnt > 0)
2765 pThreadInfo->bProtected = true;
2767 int draftCnt = dbHandle->getColumnToInt(index++);
2769 pThreadInfo->bDraft = true;
2771 int failedCnt = dbHandle->getColumnToInt(index++);
2773 pThreadInfo->bSendFailed = true;
2775 int sendingCnt = dbHandle->getColumnToInt(index++);
2777 pThreadInfo->bSending = true;
2780 dbHandle->freeTable();
2788 msg_error_t MsgStoRestoreMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
2792 MsgDbHandler *dbHandle = getDbHandle();
2793 msg_error_t err = MSG_SUCCESS;
2794 char sqlQuery[MAX_QUERY_LEN+1];
2796 if(MsgExistConversation(dbHandle, pMsg->threadId)) {
2797 /* add message to address table which having same thread_id and datetime; */
2798 for (int i = 0; i < pMsg->nAddressCnt; i++) {
2799 if(MsgExistAddress(dbHandle, pMsg, pMsg->threadId, i) == false) {
2800 unsigned int addrId;
2801 MSG_CONTACT_INFO_S contactInfo;
2802 memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
2804 /* Get Contact Info */
2805 /* if (MsgGetContactInfo(&(pMsg->addressList[i]), &contactInfo) != MSG_SUCCESS) { */
2806 /* MSG_DEBUG("MsgGetContactInfo() fail."); */
2808 err = dbHandle->getRowId(MSGFW_ADDRESS_TABLE_NAME, &addrId);
2809 if (err != MSG_SUCCESS) {
2810 MSG_DEBUG("pDbHandle->getRowId fail. [%d]", err);
2815 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2816 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, '%s', %d, %d, ?, ?, ?, ?, ?, '%s', 0);",
2817 MSGFW_ADDRESS_TABLE_NAME, addrId, pMsg->threadId, pMsg->addressList[i].addressType, pMsg->addressList[i].recipientType, pMsg->addressList[i].addressVal,
2818 contactInfo.contactId, contactInfo.addrbookId, contactInfo.imagePath);
2820 MSG_SEC_DEBUG("Add Address Info. [%s]", sqlQuery);
2822 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2823 return MSG_ERR_DB_PREPARE;
2825 dbHandle->bindText(contactInfo.firstName, 1);
2826 dbHandle->bindText(contactInfo.lastName, 2);
2827 dbHandle->bindText(contactInfo.middleName, 3);
2828 dbHandle->bindText(contactInfo.prefix, 4);
2829 dbHandle->bindText(contactInfo.suffix, 5);
2831 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2832 dbHandle->finalizeQuery();
2833 return MSG_ERR_DB_STEP;
2836 dbHandle->finalizeQuery();
2838 /* set conversation display name by conv id */
2839 MsgStoSetConversationDisplayName(dbHandle, pMsg->threadId);
2844 if(!MsgExistMessage(dbHandle, pMsg)) {
2845 unsigned int rowId = 0;
2847 if (pMsg->threadId > 0 && pMsg->folderId == MSG_DRAFT_ID) {
2848 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2850 snprintf(sqlQuery, sizeof(sqlQuery),
2851 "DELETE FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d;",
2852 MSGFW_MESSAGE_TABLE_NAME, pMsg->threadId, MSG_DRAFT_ID);
2854 MSG_DEBUG("sqlQuery [%s]", sqlQuery);
2856 err = dbHandle->execQuery(sqlQuery);
2858 if (err != MSG_SUCCESS) {
2859 MSG_DEBUG("fail to delete draft messages.");
2863 err = dbHandle->getRowId(MSGFW_MESSAGE_TABLE_NAME, &rowId);
2865 pMsg->msgId = (msg_message_id_t)rowId;
2869 char *pFileData = NULL;
2870 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
2873 if (pMsg->bTextSms == false) {
2874 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
2875 return MSG_ERR_STORAGE_ERROR;
2877 MSG_DEBUG("file size [%d]", fileSize);
2880 char keyName[MAX_VCONFKEY_NAME_LEN];
2881 memset(keyName, 0x00, sizeof(keyName));
2882 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, pMsg->sim_idx);
2885 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
2886 MSG_INFO("MsgSettingGetString() is failed");
2890 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2892 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %ld, %d, %d, %d, %d, %d, %d, 0, %d, ?, '', '', ?, 0, %d, '%s');",
2893 MSGFW_MESSAGE_TABLE_NAME, rowId, pMsg->threadId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType,
2894 pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
2895 pMsg->bBackup, pMsg->sim_idx, imsi);
2898 MSG_DEBUG("QUERY : %s", sqlQuery);
2905 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
2906 return MSG_ERR_DB_EXEC;
2909 dbHandle->bindText(pMsg->subject, 1);
2911 if (pMsg->bTextSms == false)
2912 dbHandle->bindText(pFileData, 2);
2914 dbHandle->bindText(pMsg->msgText, 2);
2916 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2917 dbHandle->finalizeQuery();
2918 return MSG_ERR_DB_EXEC;
2921 dbHandle->finalizeQuery();
2923 if (pMsg->msgType.subType != MSG_SENDREQ_MMS) {
2924 err = MsgStoUpdateConversation(dbHandle, pMsg->threadId);
2926 if (err != MSG_SUCCESS) {
2931 /* In the case of MMS Message, load the MMS plugin to save MMS PDU */
2932 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
2933 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
2934 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
2936 return MSG_ERR_NULL_POINTER;
2938 err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
2940 if (err != MSG_SUCCESS)
2941 return MSG_ERR_STORAGE_ERROR;
2943 if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
2944 MSG_SEC_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
2946 err = MsgStoUpdateMMSMessage(pMsg);
2948 if (err != MSG_SUCCESS)
2949 return MSG_ERR_STORAGE_ERROR;
2955 /* add message to conversation, message, address table; */
2957 err = MsgStoAddMessage(pMsg, pSendOptInfo);
2966 msg_message_id_t MsgStoAddSimMessage(MSG_MESSAGE_INFO_S *pMsg, int *simIdList, int listSize)
2969 MsgDbHandler *dbHandle = getDbHandle();
2970 if (pMsg == NULL || pMsg->msgType.mainType == MSG_MMS_TYPE) {
2971 MSG_DEBUG("pMsg == NULL || pMsg->msgType.mainType == MSG_MMS_TYPE");
2975 if ((pMsg->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsg->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
2976 if (pMsg->msgId > 0) {
2977 pMsg->bRead = false;
2978 if (MsgStoUpdateMessage(pMsg, NULL) != MSG_SUCCESS) {
2979 MSG_DEBUG("MsgStoUpdateMessage is failed!!!");
2982 if (MsgStoAddMessage(pMsg, NULL) != MSG_SUCCESS) {
2983 MSG_DEBUG("MsgStoAddMessage is failed!!!");
2988 if (MsgStoAddMessage(pMsg, NULL) != MSG_SUCCESS) {
2989 MSG_DEBUG("MsgStoAddMessage is failed!!!");
2994 dbHandle->beginTrans();
2996 MSG_DEBUG("simIdList exist.");
2998 for(int i = 0; i < listSize; ++i) {
3000 simId = simIdList[i] - 1;
3001 char sqlQuery[MAX_QUERY_LEN+1];
3002 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3003 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
3004 MSGFW_SIM_MSG_TABLE_NAME, pMsg->sim_idx, simId, pMsg->msgId);
3006 MSG_DEBUG("QUERY : %s", sqlQuery);
3008 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
3009 dbHandle->endTrans(false);
3017 dbHandle->endTrans(true);
3025 #ifdef FEATURE_SMS_CDMA
3026 msg_error_t MsgCheckUniqueness(bool bInsert, msg_message_id_t msgId, MSG_UNIQUE_INDEX_S *p_msg)
3030 MsgDbHandler *dbHandle = getDbHandle();
3033 char sqlQuery[MAX_QUERY_LEN+1];
3036 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3037 dbHandle->beginTrans();
3039 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;",
3040 MSGFW_UNIQUENESS_INFO_TABLE_NAME, p_msg->tele_msgId, p_msg->address, p_msg->sub_address, p_msg->time_stamp, p_msg->telesvc_id);
3042 dbHandle->getTable(sqlQuery, &nRowCnt, NULL);
3043 MSG_DEBUG("nRowCnt = [%d]", nRowCnt);
3045 dbHandle->freeTable();
3046 dbHandle->endTrans(true);
3049 MSG_DEBUG("<<<<This incoming message is a new message>>>>");
3053 MSG_DEBUG("<<<<This incoming message is a repeated message>>>>");
3054 return MSG_ERR_UNKNOWN;
3058 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3059 dbHandle->beginTrans();
3061 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, '%s', '%s', '%s', %d);",
3062 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);
3064 dbHandle->execQuery(sqlQuery);
3065 dbHandle->endTrans(true);
3074 msg_error_t MsgStoUpdateIMSI(int sim_idx)
3077 MSG_DEBUG("sim_idx = %d", sim_idx);
3079 /* msg_error_t err = MSG_SUCCESS; */
3080 MsgDbHandler *dbHandle = getDbHandle();
3082 char sqlQuery[MAX_QUERY_LEN+1];
3083 char keyName[MAX_VCONFKEY_NAME_LEN];
3085 dbHandle->beginTrans();
3088 MSG_DEBUG("sim index is 0");
3089 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3091 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET SIM_INDEX = 0;",
3092 MSGFW_MESSAGE_TABLE_NAME);
3094 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
3095 dbHandle->endTrans(false);
3096 return MSG_ERR_DB_EXEC;
3099 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
3100 dbHandle->finalizeQuery();
3101 dbHandle->endTrans(false);
3102 return MSG_ERR_DB_EXEC;
3105 MSG_DEBUG("sim index is %d", sim_idx);
3107 memset(keyName, 0x00, sizeof(keyName));
3108 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, sim_idx);
3111 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
3112 MSG_INFO("MsgSettingGetString() is failed");
3115 MSG_SEC_DEBUG("imsi value exist -> %s", imsi);
3117 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3119 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET SIM_INDEX = %d \
3120 WHERE SIM_IMSI LIKE '%s';",
3121 MSGFW_MESSAGE_TABLE_NAME, sim_idx, imsi);
3128 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
3129 dbHandle->endTrans(false);
3130 return MSG_ERR_DB_EXEC;
3133 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
3134 dbHandle->finalizeQuery();
3135 dbHandle->endTrans(false);
3136 return MSG_ERR_DB_EXEC;
3140 dbHandle->finalizeQuery();
3141 dbHandle->endTrans(true);