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, %d, %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 = %d, 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 memset(sqlQuery, 0x00, sizeof(sqlQuery));
835 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
836 MSGFW_CB_MSG_TABLE_NAME, msgId);
838 /* Delete Push Message from push table */
839 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
840 dbHandle->endTrans(false);
841 return MSG_ERR_DB_EXEC;
843 } else if (msgType.subType >= MSG_WAP_SI_SMS && msgType.subType <= MSG_WAP_CO_SMS) {
844 memset(sqlQuery, 0x00, sizeof(sqlQuery));
845 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
846 MSGFW_PUSH_MSG_TABLE_NAME, msgId);
848 /* Delete Push Message from push table */
849 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
850 dbHandle->endTrans(false);
851 return MSG_ERR_DB_EXEC;
853 } else if (msgType.subType == MSG_SYNCML_CP) {
854 memset(sqlQuery, 0x00, sizeof(sqlQuery));
855 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
856 MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
858 /* Delete SyncML Message from syncML table */
859 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
860 dbHandle->endTrans(false);
861 return MSG_ERR_DB_EXEC;
864 } else if (msgType.mainType == MSG_MMS_TYPE) {
865 char filePath[MSG_FILEPATH_LEN_MAX + 1] = {0, };
866 char dirPath[MSG_FILEPATH_LEN_MAX + 1]= {0, };
868 /*remove multipart */
869 memset(sqlQuery, 0x00, sizeof(sqlQuery));
870 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
871 MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
873 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
874 dbHandle->endTrans(false);
875 return MSG_ERR_DB_PREPARE;
878 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
879 memset(filePath, 0x00, sizeof(filePath));
880 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
881 if (remove(filePath) == -1)
882 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
884 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
886 dbHandle->finalizeQuery();
888 /* Delete Data from Multipart table */
889 memset(sqlQuery, 0x00, sizeof(sqlQuery));
890 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
891 MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
893 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
894 dbHandle->endTrans(false);
895 return MSG_ERR_DB_EXEC;
898 memset(sqlQuery, 0x00, sizeof(sqlQuery));
899 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
900 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
902 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
903 dbHandle->endTrans(false);
904 return MSG_ERR_DB_PREPARE;
907 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
908 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
910 snprintf(dirPath, MSG_FILEPATH_LEN_MAX, "%s.dir", filePath);
912 if (remove(filePath) == -1)
913 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
915 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
922 MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
923 dbHandle->finalizeQuery();
924 dbHandle->endTrans(false);
925 return MSG_ERR_DB_STEP;
928 dbHandle->finalizeQuery();
930 /* remove thumbnail file */
931 memset(sqlQuery, 0x00, sizeof(sqlQuery));
932 snprintf(sqlQuery, sizeof(sqlQuery),
933 "SELECT VALUE FROM %s "
934 "WHERE MSG_ID = %d AND (TYPE=%d OR TYPE=%d);",
935 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO);
937 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
938 dbHandle->endTrans(false);
939 return MSG_ERR_DB_PREPARE;
942 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
943 memset(filePath, 0x00, sizeof(filePath));
944 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
945 if (remove(filePath) == -1)
946 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
948 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
951 dbHandle->finalizeQuery();
953 memset(sqlQuery, 0x00, sizeof(sqlQuery));
954 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
955 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId);
957 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
958 dbHandle->endTrans(false);
959 return MSG_ERR_DB_EXEC;
962 memset(sqlQuery, 0x00, sizeof(sqlQuery));
963 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
964 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
966 /* Delete Data from MMS table */
967 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
968 dbHandle->endTrans(false);
969 return MSG_ERR_DB_EXEC;
972 memset(sqlQuery, 0x00, sizeof(sqlQuery));
973 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
974 MSGFW_REPORT_TABLE_NAME, msgId);
976 /* Delete Data from MMS STATUS table */
977 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
978 dbHandle->endTrans(false);
979 return MSG_ERR_DB_EXEC;
983 memset(sqlQuery, 0x00, sizeof(sqlQuery));
984 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
986 /* Delete Message from msg table */
987 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
988 dbHandle->endTrans(false);
989 return MSG_ERR_DB_EXEC;
992 #ifdef FEATURE_SMS_CDMA
993 memset(sqlQuery, 0x00, sizeof(sqlQuery));
994 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_UNIQUENESS_INFO_TABLE_NAME, msgId);
996 /* Delete Message from uniqueness table */
997 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
998 dbHandle->endTrans(false);
999 return MSG_ERR_DB_EXEC;
1004 /* Clear Conversation table */
1005 if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
1006 dbHandle->endTrans(false);
1007 return MSG_ERR_DB_EXEC;
1010 /* Update conversation table. */
1011 if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
1012 dbHandle->endTrans(false);
1013 return MSG_ERR_STORAGE_ERROR;
1016 dbHandle->endTrans(true);
1018 /* Update Thread Callback */
1019 if (bCheckIndication == true && MsgExistConversation(dbHandle, convId) == true)
1020 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, convId);
1022 if (msgType.mainType == MSG_SMS_TYPE && folderId == MSG_INBOX_ID) {
1023 msgType.classType = MSG_CLASS_NONE;
1025 /* Set memory status in SIM */
1026 if (MsgStoCheckMsgCntFull(dbHandle, &msgType, folderId) == MSG_SUCCESS) {
1027 MSG_DEBUG("Set Memory Status");
1029 plg->setMemoryStatus(simIndex, MSG_SUCCESS);
1033 if (bCheckIndication == true) {
1034 MSG_DEBUG("bCheckIndication is true.");
1035 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1042 msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyDB, msg_id_list_s *pMsgIdList)
1044 msg_error_t err = MSG_SUCCESS;
1046 char sqlQuery[MAX_QUERY_LEN+1];
1048 queue<msg_thread_id_t> threadList, threadList2;
1050 #ifdef FEATURE_SMS_CDMA
1051 const char *tableList[] = {MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1052 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1053 MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1054 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1055 MSGFW_UNIQUENESS_INFO_TABLE_NAME};
1057 const char *tableList[] = {MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1058 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1059 MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1060 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME};
1063 int listCnt = sizeof(tableList)/sizeof(char *);
1065 MsgDbHandler *dbHandle = getDbHandle();
1066 signed char folder_id;
1068 /* Get conversation ID from Folder */
1069 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1071 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE FOLDER_ID = %d",
1072 MSGFW_MESSAGE_TABLE_NAME, folderId);
1074 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1076 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1077 MSG_DEBUG("Fail to getTable().");
1078 dbHandle->freeTable();
1083 dbHandle->freeTable();
1087 for (int i = 1; i <= rowCnt; i++) {
1088 MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
1089 threadList.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1090 threadList2.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1093 dbHandle->freeTable();
1095 /*** Get msg id list **/
1096 msg_id_list_s *pToDeleteMsgIdList = NULL;
1097 pToDeleteMsgIdList = (msg_id_list_s *)new char[sizeof(msg_id_list_s)];
1098 if (pToDeleteMsgIdList == NULL) {
1099 MSG_DEBUG("pToDeleteMsgIdList is NULL.");
1100 return MSG_ERR_NULL_POINTER;
1102 memset(pToDeleteMsgIdList, 0x00, sizeof(msg_id_list_s));
1104 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1105 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d",
1106 MSGFW_MESSAGE_TABLE_NAME, folderId);
1111 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
1113 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1114 MSG_DEBUG("Fail to getTable().");
1115 dbHandle->freeTable();
1120 dbHandle->freeTable();
1126 pToDeleteMsgIdList->nCount = rowCnt;
1128 MSG_DEBUG("pToDeleteMsgIdList->nCount [%d]", pToDeleteMsgIdList->nCount);
1130 pToDeleteMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
1131 memset(pToDeleteMsgIdList->msgIdList, 0x00, sizeof(msg_message_id_t) * rowCnt);
1133 for (int i = 0; i < rowCnt; i++)
1134 pToDeleteMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
1136 dbHandle->freeTable();
1139 /*** Delete Sim Message In Folder **/
1140 folder_id = (signed char)folderId;
1141 if (folder_id >= MSG_INBOX_ID) {
1142 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1144 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d AND STORAGE_ID = %d",
1145 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_SIM);
1149 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1150 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1151 dbHandle->freeTable();
1155 for (int i = 1; i <= rowCnt; i++) {
1156 err = MsgStoDeleteMessage(dbHandle->getColumnToInt(i), false);
1158 if (err != MSG_SUCCESS) {
1159 MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
1161 dbHandle->freeTable();
1166 /*Delete phone log */
1167 /* MsgDeletePhoneLog(dbHandle->getColumnToInt(i)); */
1170 dbHandle->freeTable();
1173 dbHandle->beginTrans();
1175 for (int i = 0; i < listCnt; i++) {
1176 if (!strcmp(tableList[i], MMS_PLUGIN_MESSAGE_TABLE_NAME)) {
1179 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1180 char dirPath[MSG_FILEPATH_LEN_MAX] = {0, };
1181 /* remove multipart */
1182 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1183 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s;",
1184 MSGFW_MMS_MULTIPART_TABLE_NAME);
1186 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1187 dbHandle->endTrans(false);
1188 return MSG_ERR_DB_PREPARE;
1191 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1192 memset(filePath, 0x00, sizeof(filePath));
1193 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
1194 if (remove(filePath) == -1)
1195 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1197 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1199 dbHandle->finalizeQuery();
1201 /* Delete Data from Multipart table */
1202 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1203 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;",
1204 MSGFW_MMS_MULTIPART_TABLE_NAME);
1206 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1207 err = MSG_ERR_DB_EXEC;
1208 dbHandle->endTrans(false);
1212 /*get mms msg id list */
1213 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1214 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.FILE_PATH FROM %s A, %s B \
1215 WHERE A.FOLDER_ID = %d AND A.MAIN_TYPE = %d AND A.MSG_ID = B.MSG_ID",
1216 MSGFW_MESSAGE_TABLE_NAME, MMS_PLUGIN_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE);
1218 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1219 MSG_DEBUG("rowCnt %d", rowCnt);
1221 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1222 MSG_DEBUG("Fail to getTable().");
1224 dbHandle->freeTable();
1225 dbHandle->endTrans(false);
1230 for (int i = 1; i <= rowCnt; i++) {
1231 memset(filePath, 0x00, sizeof(filePath));
1232 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1234 MSG_SEC_DEBUG("filePath [%s]", filePath);
1236 /*delete raw file */
1237 snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
1239 if (remove(filePath) == -1)
1240 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1242 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1249 dbHandle->freeTable();
1252 /* delete thumbnail */
1253 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1254 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1255 snprintf(sqlQuery, sizeof(sqlQuery),
1256 "SELECT VALUE FROM %s "
1257 "WHERE (TYPE=%d OR TYPE=%d) "
1258 "AND (MSG_ID IN (SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d));",
1259 MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO, MSGFW_MESSAGE_TABLE_NAME, folderId);
1261 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1262 dbHandle->endTrans(false);
1263 return MSG_ERR_DB_PREPARE;
1266 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1267 memset(filePath, 0x00, sizeof(filePath));
1268 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
1269 if (remove(filePath) == -1)
1270 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1272 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1275 dbHandle->finalizeQuery();
1277 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1279 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN \
1280 (SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d);",
1281 tableList[i], MSGFW_MESSAGE_TABLE_NAME, folderId);
1283 /* Delete Message in specific folder from table */
1284 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1285 MSG_DEBUG("sqlQuery [%s]", sqlQuery);
1286 dbHandle->endTrans(false);
1287 err = MSG_ERR_DB_EXEC;
1293 /* Clear Conversation table */
1294 if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
1295 dbHandle->endTrans(false);
1296 err = MSG_ERR_DB_EXEC;
1301 /* Update Address */
1302 while (!threadList.empty()) {
1303 err = MsgStoUpdateConversation(dbHandle, threadList.front());
1307 if (err != MSG_SUCCESS) {
1308 dbHandle->endTrans(false);
1314 dbHandle->endTrans(true);
1316 /* Update Thread Callback */
1317 while (!threadList2.empty()) {
1318 msg_thread_id_t cur_thread_id = threadList2.front();
1319 if (MsgExistConversation(dbHandle, cur_thread_id) == true)
1320 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, cur_thread_id);
1325 /* Set pMsgIdList */
1326 if (pMsgIdList != NULL && pToDeleteMsgIdList->nCount > 0) {
1327 pMsgIdList->nCount = pToDeleteMsgIdList->nCount;
1329 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * pToDeleteMsgIdList->nCount];
1330 memset(pMsgIdList->msgIdList, 0x00, sizeof(msg_message_id_t) * pToDeleteMsgIdList->nCount);
1331 memcpy(pMsgIdList->msgIdList, pToDeleteMsgIdList->msgIdList, sizeof(msg_message_id_t) * pToDeleteMsgIdList->nCount);
1334 /* Create thread for noti and phone log delete. */
1336 if (pToDeleteMsgIdList->nCount > 0) {
1338 if (pToDeleteMsgIdList != NULL) {
1339 /*free peer info list */
1340 if (pToDeleteMsgIdList->msgIdList != NULL)
1341 delete [] pToDeleteMsgIdList->msgIdList;
1343 delete [] pToDeleteMsgIdList;
1346 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1353 MSG_DEBUG("Error case Free Memory");
1355 while (!threadList.empty()) {
1361 if (pToDeleteMsgIdList != NULL) {
1362 /*free peer info list */
1363 if (pToDeleteMsgIdList->msgIdList != NULL)
1364 delete [] pToDeleteMsgIdList->msgIdList;
1366 delete [] pToDeleteMsgIdList;
1373 msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
1379 msg_error_t err = MSG_SUCCESS;
1380 if (pMsgIdList->nCount < 1) {
1381 MSG_DEBUG("pMsgIdList->nCount < 1");
1385 char sqlQuery[MAX_QUERY_LEN+1];
1387 queue<msg_thread_id_t> threadList1, threadList2, threadList3;
1389 #ifdef FEATURE_SMS_CDMA
1390 const char *tableList[] = {MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1391 MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1392 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1393 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1394 MSGFW_SMS_REPORT_TABLE_NAME, MSGFW_MMS_MULTIPART_TABLE_NAME,
1395 MSGFW_UNIQUENESS_INFO_TABLE_NAME};
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};
1404 int listCnt = sizeof(tableList)/sizeof(char *);
1406 MsgDbHandler *dbHandle = getDbHandle();
1408 dbHandle->beginTrans();
1409 /* reset msgid temp table */
1410 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1411 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_TMP_MSGID_TABLE_NAME);
1412 MSG_DEBUG("[%s]", sqlQuery);
1414 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1415 dbHandle->endTrans(false);
1416 return MSG_ERR_DB_EXEC;
1419 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
1420 dbHandle->finalizeQuery();
1421 dbHandle->endTrans(false);
1422 return MSG_ERR_DB_EXEC;
1425 dbHandle->finalizeQuery();
1427 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1428 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (?)", MSGFW_TMP_MSGID_TABLE_NAME);
1429 MSG_DEBUG("[%s]", sqlQuery);
1430 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1431 dbHandle->endTrans(false);
1432 return MSG_ERR_DB_PREPARE;
1435 for (int i = 0; i < pMsgIdList->nCount; i++) {
1436 dbHandle->resetQuery();
1437 dbHandle->bindInt(pMsgIdList->msgIdList[i], 1);
1438 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
1439 dbHandle->finalizeQuery();
1440 dbHandle->endTrans(false);
1441 return MSG_ERR_DB_EXEC;
1445 dbHandle->finalizeQuery();
1446 dbHandle->endTrans(true);
1448 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1449 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE MSG_ID IN %s;", MSGFW_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1451 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1453 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1454 MSG_DEBUG("Fail to getTable().");
1455 dbHandle->freeTable();
1459 MSG_DEBUG("rowCnt [%d]", rowCnt);
1462 dbHandle->freeTable();
1466 for (int i = 1; i <= rowCnt; i++) {
1467 MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
1468 threadList1.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1469 threadList2.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1470 threadList3.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1472 dbHandle->freeTable();
1474 /* delete report notification */
1475 char tempAddr[MAX_ADDRESS_VAL_LEN+1];
1476 bool isSentReadReportDeleted = false;
1477 while (!threadList1.empty()) {
1478 memset(tempAddr, 0x00, sizeof(tempAddr));
1479 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1480 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;"
1481 , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, threadList1.front());
1483 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1484 return MSG_ERR_DB_PREPARE;
1486 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
1487 dbHandle->finalizeQuery();
1488 return MSG_ERR_DB_DONE;
1491 snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
1493 MSG_SEC_DEBUG("Updated address = %s", tempAddr);
1495 MsgDeleteReportNotification(tempAddr);
1497 dbHandle->finalizeQuery();
1500 if (!isSentReadReportDeleted && !MsgIsSentReadReportNotificationExist(threadList1.front(), &msgId)) {
1501 //delete read report sent notification
1502 MsgDeleteSentReadReportNotification(msgId);
1503 isSentReadReportDeleted = true;
1510 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1511 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d AND MSG_ID IN %s;",
1512 MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, MSGFW_TMP_MSGID_TABLE_NAME);
1515 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1517 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1518 MSG_DEBUG("Fail to getTable().");
1519 dbHandle->freeTable();
1523 for (int i = 1; i <= rowCnt; i++) {
1524 err = MsgStoDeleteMessage(dbHandle->getColumnToInt(i), false);
1525 if (err != MSG_SUCCESS) {
1526 MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
1529 dbHandle->freeTable();
1531 dbHandle->beginTrans();
1532 for (int i = 0; i < listCnt; i++) {
1534 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1535 char dirPath[MSG_FILEPATH_LEN_MAX] = {0, };
1539 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1540 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN %s;", MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1542 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1544 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1545 MSG_DEBUG("Fail to getTable().");
1549 MSG_DEBUG("rowCnt %d", rowCnt);
1551 for (int i = 1; i <= rowCnt; i++) {
1552 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1554 MSG_SEC_DEBUG("filePath [%s]", filePath);
1556 /* Delete raw file. */
1557 snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
1559 if (remove(filePath) == -1)
1560 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1562 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1568 dbHandle->freeTable();
1570 } else if (i == 1) {
1571 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1575 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1576 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT VALUE FROM %s WHERE (TYPE = %d OR TYPE = %d) AND MSG_ID IN %s;",
1577 MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO, MSGFW_TMP_MSGID_TABLE_NAME);
1579 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1581 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1582 MSG_DEBUG("Fail to getTable().");
1586 MSG_DEBUG("rowCnt %d", rowCnt);
1588 for (int i = 1; i <= rowCnt; i++) {
1589 memset(filePath, 0x00, sizeof(filePath));
1590 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
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);
1596 dbHandle->freeTable();
1597 } else if (!strcmp(tableList[i], MSGFW_MMS_MULTIPART_TABLE_NAME)) {
1598 /* MMS file path to delete. */
1599 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1603 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1604 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN %s;", MSGFW_MMS_MULTIPART_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1606 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1608 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1609 MSG_DEBUG("Fail to getTable().");
1613 MSG_DEBUG("rowCnt %d", rowCnt);
1615 for (int i = 1; i <= rowCnt; i++) {
1616 memset(filePath, 0x00, sizeof(filePath));
1617 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1618 if (filePath[0] != '\0') {
1619 if (remove(filePath) == -1)
1620 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1622 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1625 dbHandle->freeTable();
1627 /* MMS thumbnail path to delete */
1628 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1629 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);
1631 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1633 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1634 MSG_DEBUG("Fail to getTable().");
1638 MSG_DEBUG("rowCnt %d", rowCnt);
1640 for (int i = 1; i <= rowCnt; i++) {
1641 memset(filePath, 0x00, sizeof(filePath));
1642 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1643 if (filePath[0] != '\0') {
1644 if (remove(filePath) == -1)
1645 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1647 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1651 dbHandle->freeTable();
1654 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1655 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN %s;", tableList[i], MSGFW_TMP_MSGID_TABLE_NAME);
1657 /* Delete Message in specific folder from table */
1658 err = dbHandle->execQuery(sqlQuery);
1659 if (err != MSG_SUCCESS) {
1660 MSG_DEBUG("Fail to execQuery().");
1664 /* Clear Conversation table */
1665 err = MsgStoClearConversationTable(dbHandle);
1666 if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoClearConversationTable().");
1668 /* Update Address */
1669 while (!threadList2.empty()) {
1670 err = MsgStoUpdateConversation(dbHandle, threadList2.front());
1671 if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoUpdateConversation().");
1674 err = dbHandle->endTrans(true);
1675 if (err != MSG_SUCCESS) {
1676 MSG_DEBUG("Fail to endTrans(true).");
1677 dbHandle->endTrans(false);
1681 /* Update Thread Callback */
1682 while (!threadList3.empty()) {
1683 msg_thread_id_t cur_thread_id = threadList3.front();
1684 if (MsgExistConversation(dbHandle, cur_thread_id) == true)
1685 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, cur_thread_id);
1690 if (g_idle_add(resetNotification, NULL) == 0) {
1691 MSG_DEBUG("resetNotification() Error");
1699 msg_error_t MsgStoMoveMessageToFolder(msg_message_id_t msgId, msg_folder_id_t destFolderId)
1701 msg_error_t err = MSG_SUCCESS;
1702 MSG_MESSAGE_TYPE_S msgType;
1703 msg_thread_id_t convId = 0;
1705 MsgStoGetMsgType(msgId, &msgType);
1707 char sqlQuery[MAX_QUERY_LEN+1];
1708 MsgDbHandler *dbHandle = getDbHandle();
1710 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1712 if (msgType.mainType == MSG_SMS_TYPE)
1713 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_ID = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, destFolderId, msgId);
1715 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_ID = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, destFolderId, msgId);
1717 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
1718 return MSG_ERR_DB_EXEC;
1720 /* get conversation id */
1721 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1723 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONV_ID FROM %s WHERE MSG_ID = %d;",
1724 MSGFW_MESSAGE_TABLE_NAME, msgId);
1726 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1727 return MSG_ERR_DB_PREPARE;
1729 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW)
1730 convId = dbHandle->columnInt(0);
1732 MSG_DEBUG("convId : %d", convId);
1734 dbHandle->finalizeQuery();
1736 /* update conversation table */
1737 err = MsgStoUpdateConversation(dbHandle, convId);
1739 /* update notification */
1740 signed char dest_folder_id = (signed char)destFolderId;
1741 if (dest_folder_id != MSG_SPAMBOX_ID)
1742 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1748 msg_error_t MsgStoMoveMessageToStorage(msg_message_id_t msgId, msg_storage_id_t destStorageId)
1752 msg_error_t err = MSG_SUCCESS;
1754 char sqlQuery[MAX_QUERY_LEN+1];
1755 MsgDbHandler *dbHandle = getDbHandle();
1757 MSG_DEBUG("msgId : %d, destStorageId : %d", msgId, destStorageId);
1759 switch (destStorageId) {
1760 case MSG_STORAGE_SIM : /* Move message to sim card */
1761 case MSG_STORAGE_SIM2 : {
1762 MSG_MESSAGE_INFO_S msgInfo;
1763 SMS_SIM_ID_LIST_S simIdList;
1765 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1766 memset(&simIdList, 0x00, sizeof(SMS_SIM_ID_LIST_S));
1768 if ((err = MsgStoGetMessage(msgId, &msgInfo, NULL)) != MSG_SUCCESS)
1771 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
1773 MSG_DEBUG("SMS Plug-in is NULL");
1774 return MSG_ERR_NULL_POINTER;
1777 if (destStorageId == MSG_STORAGE_SIM)
1778 msgInfo.sim_idx = 1;
1779 else if (destStorageId == MSG_STORAGE_SIM2)
1780 msgInfo.sim_idx = 2;
1782 if ((err = plg->saveSimMessage(&msgInfo, &simIdList)) != MSG_SUCCESS)
1785 dbHandle->beginTrans();
1787 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1788 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d, SIM_INDEX = %d WHERE MSG_ID = %d;",
1789 MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, msgInfo.sim_idx, msgId);
1790 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1792 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1793 dbHandle->endTrans(false);
1794 return MSG_ERR_DB_EXEC;
1797 for (unsigned int i = 0; i < simIdList.count; i++) {
1798 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1799 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
1800 MSGFW_SIM_MSG_TABLE_NAME, msgInfo.sim_idx, simIdList.simId[i], msgId);
1801 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1803 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1804 dbHandle->endTrans(false);
1805 return MSG_ERR_DB_EXEC;
1809 dbHandle->endTrans(true);
1813 default: { /* Moving message to memory (when destination storage id is MSG_STORAGE_PHONE) */
1814 #ifndef FEATURE_SMS_CDMA
1815 bool bSimMsg = false;
1818 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1819 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT STORAGE_ID FROM %s WHERE MSG_ID = %d;",
1820 MSGFW_MESSAGE_TABLE_NAME, msgId);
1822 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1824 if (err != MSG_SUCCESS) {
1825 MSG_DEBUG("Fail to getTable().");
1826 dbHandle->freeTable();
1830 if (dbHandle->getColumnToInt(1) == MSG_STORAGE_SIM) {
1831 MSG_DEBUG("It is SIM Message");
1835 dbHandle->freeTable();
1837 if (bSimMsg == true) {
1838 msg_sim_id_t simMsgId;
1839 msg_sim_slot_id_t sim_idx;
1841 /* get sim message id */
1842 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1844 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
1845 MSGFW_SIM_MSG_TABLE_NAME, msgId);
1849 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
1851 if (err != MSG_SUCCESS) {
1852 MSG_DEBUG("Fail to getTable().");
1853 dbHandle->freeTable();
1857 /* Delete messages in sim card */
1858 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
1860 MSG_DEBUG("SMS Plug-in is NULL");
1861 dbHandle->freeTable();
1862 return MSG_ERR_NULL_POINTER;
1865 for (int i = 0; i < rowCnt; i++) {
1866 sim_idx = dbHandle->getColumnToInt(index++);
1867 simMsgId = dbHandle->getColumnToInt(index++);
1869 MSG_DEBUG("simMsgId is %d.", simMsgId);
1871 if ((err = plg->deleteSimMessage(sim_idx, simMsgId)) != MSG_SUCCESS) {
1872 dbHandle->freeTable();
1877 dbHandle->freeTable();
1879 dbHandle->beginTrans();
1881 /* Delete Messages in SIM Msg table */
1882 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1883 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
1884 MSGFW_SIM_MSG_TABLE_NAME, msgId);
1885 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1887 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1888 dbHandle->endTrans(false);
1889 return MSG_ERR_DB_EXEC;
1892 /* Move storage id */
1893 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1894 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d WHERE MSG_ID = %d;",
1895 MSGFW_MESSAGE_TABLE_NAME, destStorageId, msgId);
1896 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1898 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1899 dbHandle->endTrans(false);
1900 return MSG_ERR_DB_EXEC;
1903 dbHandle->endTrans(true);
1914 msg_error_t MsgStoCountMessage(msg_folder_id_t folderId, MSG_COUNT_INFO_S *pCountInfo)
1916 if (pCountInfo == NULL) {
1917 MSG_DEBUG("pCountInfo is NULL");
1918 return MSG_ERR_NULL_POINTER;
1921 char sqlQuery[MAX_QUERY_LEN+1];
1922 MsgDbHandler *dbHandle = getDbHandle();
1924 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1925 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 1 AND STORAGE_ID = %d "
1926 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d "
1927 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND STORAGE_ID = %d "
1928 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND STORAGE_ID = %d;",
1929 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_PHONE,
1930 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_PHONE,
1931 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_SMS_TYPE, MSG_STORAGE_PHONE,
1932 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE, MSG_STORAGE_PHONE);
1934 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1935 return MSG_ERR_DB_PREPARE;
1937 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1938 pCountInfo->nReadCnt = dbHandle->columnInt(0);
1940 dbHandle->finalizeQuery();
1941 return MSG_ERR_DB_STEP;
1944 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1945 pCountInfo->nUnreadCnt = dbHandle->columnInt(0);
1947 dbHandle->finalizeQuery();
1948 return MSG_ERR_DB_STEP;
1951 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1952 pCountInfo->nSms = dbHandle->columnInt(0);
1954 dbHandle->finalizeQuery();
1955 return MSG_ERR_DB_STEP;
1958 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1959 pCountInfo->nMms = dbHandle->columnInt(0);
1961 dbHandle->finalizeQuery();
1962 return MSG_ERR_DB_STEP;
1965 dbHandle->finalizeQuery();
1971 msg_error_t MsgStoCountMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount)
1973 if (pMsgType == NULL) {
1974 MSG_DEBUG("pMsgType is NULL");
1975 return MSG_ERR_NULL_POINTER;
1980 char sqlQuery[MAX_QUERY_LEN+1];
1981 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1983 MsgDbHandler *dbHandle = getDbHandle();
1985 if ((pMsgType->mainType == MSG_SMS_TYPE) &&
1986 (pMsgType->subType == MSG_NORMAL_SMS || pMsgType->subType == MSG_STATUS_REPORT_SMS || pMsgType->subType == MSG_CONCAT_SIM_SMS)) {
1987 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d);",
1988 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_NORMAL_SMS, MSG_STATUS_REPORT_SMS, MSG_CONCAT_SIM_SMS);
1989 } else if ((pMsgType->mainType == MSG_SMS_TYPE) &&
1990 (pMsgType->subType == MSG_WAP_SI_SMS || pMsgType->subType == MSG_WAP_SL_SMS)) {
1992 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d);",
1993 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_WAP_SI_SMS, MSG_WAP_SL_SMS);
1994 } else if ((pMsgType->mainType == MSG_MMS_TYPE) &&
1995 (pMsgType->subType == MSG_SENDREQ_MMS || pMsgType->subType == MSG_SENDCONF_MMS || pMsgType->subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgType->subType == MSG_RETRIEVE_MANUALCONF_MMS)) {
1997 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d, %d);",
1998 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_SENDREQ_MMS, MSG_SENDCONF_MMS, MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS);
2000 return MSG_ERR_INVALID_PARAMETER;
2003 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2004 return MSG_ERR_DB_PREPARE;
2006 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2007 *pMsgCount = dbHandle->columnInt(0);
2009 dbHandle->finalizeQuery();
2010 return MSG_ERR_DB_STEP;
2013 dbHandle->finalizeQuery();
2019 msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
2021 char sqlQuery[MAX_QUERY_LEN+1];
2022 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2023 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, \
2024 SUB_TYPE, DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
2025 BACKUP, PRIORITY, MSG_DIRECTION, DPM_RESTRICTED, SCHEDULED_TIME, SUBJECT, MSG_TEXT, THUMB_PATH, SIM_INDEX \
2026 FROM %s WHERE MSG_ID = %d;",
2027 MSGFW_MESSAGE_TABLE_NAME, msgId);
2029 MsgDbHandler *dbHandle = getDbHandle();
2031 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2032 return MSG_ERR_DB_PREPARE;
2034 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2035 pMsg->msgId = dbHandle->columnInt(0);
2036 pMsg->threadId = dbHandle->columnInt(1);
2037 pMsg->folderId = dbHandle->columnInt(2);
2038 pMsg->storageId = dbHandle->columnInt(3);
2039 pMsg->msgType.mainType = dbHandle->columnInt(4);
2040 pMsg->msgType.subType = dbHandle->columnInt(5);
2041 pMsg->displayTime = (time_t)dbHandle->columnInt(6);
2042 pMsg->dataSize = dbHandle->columnInt(7);
2043 pMsg->networkStatus = dbHandle->columnInt(8);
2044 pMsg->bRead = dbHandle->columnInt(9);
2045 pMsg->bProtected = dbHandle->columnInt(10);
2046 pMsg->bBackup = dbHandle->columnInt(11);
2047 pMsg->priority = dbHandle->columnInt(12);
2048 pMsg->direction = dbHandle->columnInt(13);
2049 pMsg->bRestricted = dbHandle->columnInt(14);
2051 strncpy(pMsg->subject, (char *)dbHandle->columnText(16), MAX_SUBJECT_LEN);
2053 /* Temp_File_Handling */
2054 if (pMsg->msgType.mainType == MSG_SMS_TYPE || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
2055 if (pMsg->dataSize > MAX_MSG_TEXT_LEN) {
2056 char msgData[pMsg->dataSize+1];
2057 memset(msgData, 0x00, sizeof(msgData));
2059 strncpy(msgData, (char *)dbHandle->columnText(17), pMsg->dataSize);
2061 /* Save Message Data into File */
2062 char fileName[MSG_FILENAME_LEN_MAX+1];
2063 memset(fileName, 0x00, sizeof(fileName));
2065 if (MsgCreateFileName(fileName) == false) {
2066 dbHandle->finalizeQuery();
2067 return MSG_ERR_STORAGE_ERROR;
2070 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, fileName);
2072 if (MsgWriteIpcFile(fileName, msgData, pMsg->dataSize) == false) {
2073 dbHandle->finalizeQuery();
2074 return MSG_ERR_STORAGE_ERROR;
2077 strncpy(pMsg->msgData, fileName, MAX_MSG_DATA_LEN);
2079 pMsg->bTextSms = false;
2081 memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
2082 strncpy(pMsg->msgText, (char *)dbHandle->columnText(17), pMsg->dataSize);
2084 /* For WAP PUSH SI Message */
2085 if (pMsg->msgType.subType == MSG_WAP_SI_SMS) {
2086 strncat(pMsg->msgText, "\n", MAX_MSG_TEXT_LEN-strlen(pMsg->msgText));
2087 strncat(pMsg->msgText, pMsg->subject, MAX_MSG_TEXT_LEN-strlen(pMsg->msgText));
2088 MSG_SEC_DEBUG("pMsg->msgText : [%s]", pMsg->msgText);
2089 pMsg->dataSize = sizeof(pMsg->msgText);
2092 pMsg->bTextSms = true;
2095 if (dbHandle->columnText(16) != NULL)
2096 strncpy(pMsg->msgText, (char *)dbHandle->columnText(17), MAX_MSG_TEXT_LEN);
2099 /* thumbnail path */
2100 if (dbHandle->columnText(18)!= NULL && ((char *)dbHandle->columnText(18))[0] != '\0') {
2101 strncpy(pMsg->thumbPath, (char *)dbHandle->columnText(18), MSG_FILEPATH_LEN_MAX);
2102 MSG_DEBUG("pMsg->thumbPath : [%s]", pMsg->thumbPath);
2105 if (pMsg->bRestricted == true) {
2107 memset(pMsg->msgData, 0x00, sizeof(pMsg->msgData));
2108 memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
2109 memset(pMsg->subject, 0x00, sizeof(pMsg->subject));
2110 memset(pMsg->thumbPath, 0x00, sizeof(pMsg->thumbPath));
2113 pMsg->sim_idx = dbHandle->columnInt(19);
2115 dbHandle->finalizeQuery();
2116 MSG_DEBUG("%s", sqlQuery);
2117 return MSG_ERR_DB_STEP;
2120 dbHandle->finalizeQuery();
2123 /* get address information. */
2124 MsgStoGetAddressByMsgId(dbHandle, pMsg->msgId, &pMsg->nAddressCnt, &pMsg->addressList);
2126 /* Get MMS body if it is MMS. */
2127 if ((pMsg->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS &&
2128 (pMsg->msgType.subType == MSG_RETRIEVE_MMS || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS)) ||
2129 pMsg->msgType.subType == MSG_SENDREQ_MMS || pMsg->msgType.subType == MSG_SENDCONF_MMS || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
2130 msg_error_t err = MSG_SUCCESS;
2131 char *pDestMsg = NULL;
2132 int temp_size = pMsg->dataSize; /* save raw file size; */
2134 /* call mms plugin to get mms specific message data */
2135 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(pMsg->msgType.mainType);
2137 MSG_DEBUG("SMS Plug-in is NULL");
2138 return MSG_ERR_NULL_POINTER;
2141 err = plg->getMmsMessage(pMsg, pSendOptInfo, &pDestMsg);
2142 if (err != MSG_SUCCESS) {
2147 return MSG_ERR_STORAGE_ERROR;
2150 memset(pMsg->msgData, 0, MAX_MSG_DATA_LEN+1);
2152 /* Encode MMS specific data to MMS_MESSAGE_DATA_S */
2153 if (pMsg->dataSize > MAX_MSG_DATA_LEN) {
2154 /* Save Message Data into File */
2155 char tempFileName[MSG_FILENAME_LEN_MAX+1];
2156 memset(tempFileName, 0x00, sizeof(tempFileName));
2158 if (MsgCreateFileName(tempFileName) == false) {
2163 return MSG_ERR_STORAGE_ERROR;
2165 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, tempFileName);
2167 if (MsgWriteIpcFile(tempFileName, pDestMsg, pMsg->dataSize) == false) {
2172 return MSG_ERR_STORAGE_ERROR;
2174 strncpy(pMsg->msgData, tempFileName, MAX_MSG_DATA_LEN);
2175 pMsg->bTextSms = false;
2177 strncpy(pMsg->msgData, pDestMsg, pMsg->dataSize);
2178 pMsg->bTextSms = true;
2181 pMsg->dataSize = temp_size; /*raw file size; */
2189 /* Get SMS Sending Options */
2190 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL)
2191 MsgStoGetSmsSendOpt(pMsg, pSendOptInfo);
2196 msg_error_t MsgStoGetFailedMessage(int **failed_msg_list, int *count)
2200 msg_error_t err = MSG_SUCCESS;
2201 char sqlQuery[MAX_QUERY_LEN+1];
2202 int rowCnt = 0, index = 0;
2203 MsgDbHandler *dbHandle = getDbHandle();
2205 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2207 /* Folder ID == 2 : sending failed message, Folder ID == 1 : retrieve failed message */
2208 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);",
2209 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_PENDING, MSG_NETWORK_RETRIEVE_PENDING, MSG_OUTBOX_ID, MSG_INBOX_ID);
2210 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2212 if(err == MSG_ERR_DB_NORECORD) {
2213 dbHandle->freeTable();
2217 int *list = new int[rowCnt];
2219 for(int i = 0; i < rowCnt; ++i) {
2220 list[i] = dbHandle->getColumnToInt(index++);
2222 *failed_msg_list = list;
2223 dbHandle->freeTable();
2229 msg_error_t MsgStoAddSyncMLMessage(MSG_MESSAGE_INFO_S *pMsgInfo, int extId, int pinCode)
2233 msg_error_t err = MSG_SUCCESS;
2235 char sqlQuery[MAX_QUERY_LEN+1];
2237 unsigned int rowId = 0;
2238 msg_thread_id_t convId = 0;
2239 MsgDbHandler *dbHandle = getDbHandle();
2241 dbHandle->beginTrans();
2243 if (pMsgInfo->nAddressCnt > 0) {
2244 err = MsgStoAddAddress(dbHandle, pMsgInfo, &convId);
2246 if (err != MSG_SUCCESS) {
2247 dbHandle->endTrans(false);
2252 /* Add Message Table */
2253 pMsgInfo->threadId = convId;
2254 rowId = MsgStoAddMessageTable(dbHandle, pMsgInfo);
2257 dbHandle->endTrans(false);
2258 return MSG_ERR_DB_ROW;
2261 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2262 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
2263 MSGFW_SYNCML_MSG_TABLE_NAME, rowId, extId, pinCode);
2265 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
2266 dbHandle->endTrans(false);
2267 return MSG_ERR_DB_EXEC;
2270 if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
2271 dbHandle->endTrans(false);
2272 return MSG_ERR_STORAGE_ERROR;
2275 dbHandle->endTrans(true);
2277 pMsgInfo->msgId = (msg_message_id_t)rowId;
2279 MsgInsertNotification(pMsgInfo);
2288 msg_error_t MsgStoGetMsgType(msg_message_id_t msgId, MSG_MESSAGE_TYPE_S *pMsgType)
2290 MsgDbHandler *dbHandle = getDbHandle();
2291 char sqlQuery[MAX_QUERY_LEN+1];
2293 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2295 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE FROM %s WHERE MSG_ID = %d;",
2296 MSGFW_MESSAGE_TABLE_NAME, msgId);
2298 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2299 return MSG_ERR_DB_PREPARE;
2301 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2302 pMsgType->mainType = dbHandle->columnInt(0);
2303 pMsgType->subType = dbHandle->columnInt(1);
2306 dbHandle->finalizeQuery();
2312 msg_error_t MsgStoGetQuickPanelData(msg_quickpanel_type_t QPtype, MSG_MESSAGE_INFO_S *pMsg)
2314 msg_error_t err = MSG_SUCCESS;
2316 MsgDbHandler *dbHandle = getDbHandle();
2317 char sqlQuery[MAX_QUERY_LEN+1];
2319 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2321 if (QPtype == MSG_QUICKPANEL_SMS) {
2322 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;",
2323 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_SMS_TYPE, MSG_NORMAL_SMS);
2324 } else if (QPtype == MSG_QUICKPANEL_MMS) {
2325 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;",
2326 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_MMS_TYPE, MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS);
2327 } else if (QPtype == MSG_QUICKPANEL_DELIVER_REP) {
2328 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE SUB_TYPE IN (%d, %d) AND READ_STATUS = 0 ORDER BY DISPLAY_TIME DESC;",
2329 MSGFW_MESSAGE_TABLE_NAME, MSG_STATUS_REPORT_SMS, MSG_DELIVERYIND_MMS);
2330 } else if (QPtype == MSG_QUICKPANEL_READ_REP) {
2331 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;",
2332 MSGFW_MESSAGE_TABLE_NAME, MSG_MMS_TYPE, MSG_READORGIND_MMS);
2333 } else if (QPtype == MSG_QUICKPANEL_VOICEMAIL) {
2334 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;",
2335 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MWI_VOICE_SMS);
2336 } else if (QPtype == MSG_QUICKPANEL_MMS_NOTI) {
2337 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;",
2338 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_MMS_TYPE, MSG_NOTIFICATIONIND_MMS);
2341 /* Get Message ID */
2342 msg_message_id_t msgId;
2344 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2345 return MSG_ERR_DB_PREPARE;
2347 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2348 msgId = dbHandle->columnInt(0);
2350 dbHandle->finalizeQuery();
2351 return MSG_ERR_DB_STEP;
2354 dbHandle->finalizeQuery();
2356 /* Get Message Info */
2357 err = MsgStoGetMessage(msgId, pMsg, NULL);
2363 msg_error_t MsgStoDeleteThreadMessageList(msg_thread_id_t threadId, bool bIncludeProtect, msg_id_list_s *pMsgIdList)
2365 msg_error_t err = MSG_SUCCESS;
2367 MsgDbHandler *dbHandle = getDbHandle();
2368 char sqlQuery[MAX_QUERY_LEN+1];
2370 /*** Get msg id list **/
2371 int rowCnt = 0, index = 0;
2373 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2375 #ifdef MSG_NOTI_INTEGRATION
2376 if (bIncludeProtect) {
2377 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2378 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
2379 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
2381 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2382 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0;",
2383 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
2386 if (bIncludeProtect) {
2387 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2388 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
2389 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
2391 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2392 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0;",
2393 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
2397 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2399 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
2400 MSG_ERR("Fail to getTable().");
2401 dbHandle->freeTable();
2406 dbHandle->freeTable();
2408 err = MsgStoClearConversationTable(dbHandle);
2409 if (err != MSG_SUCCESS) {
2410 MSG_ERR("Fail to MsgStoClearConversationTable().");
2414 err = MsgStoUpdateConversation(dbHandle, threadId);
2415 if (err != MSG_SUCCESS) {
2416 MSG_ERR("Fail to MsgStoUpdateConversation().");
2423 pMsgIdList->nCount = rowCnt;
2425 MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
2427 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
2429 for (int i = 0; i < rowCnt; i++)
2430 pMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
2432 dbHandle->freeTable();
2435 err = MsgStoDeleteMessageByList(pMsgIdList);
2436 if (err != MSG_SUCCESS) {
2437 MSG_ERR("Fail to MsgStoDeleteMessageByList().");
2445 msg_error_t MsgStoSetTempAddressTable(MSG_ADDRESS_INFO_S *pAddrInfo, int addr_cnt)
2447 MsgDbHandler *dbHandle = getDbHandle();
2448 char sqlQuery[MAX_QUERY_LEN+1];
2450 dbHandle->beginTrans();
2451 /* reset address temp table */
2452 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2453 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_ADDRESS_TEMP_TABLE_NAME);
2454 MSG_DEBUG("[%s]", sqlQuery);
2456 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2457 return MSG_ERR_DB_EXEC;
2459 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2460 dbHandle->finalizeQuery();
2461 dbHandle->endTrans(false);
2462 return MSG_ERR_DB_EXEC;
2465 dbHandle->finalizeQuery();
2467 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2468 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (?);", MSGFW_ADDRESS_TEMP_TABLE_NAME);
2469 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
2470 dbHandle->endTrans(false);
2471 return MSG_ERR_DB_PREPARE;
2474 char newPhoneNum[MAX_ADDRESS_VAL_LEN+1];
2475 char tmpNum[MAX_ADDRESS_VAL_LEN+1];
2476 for (int i = 0; i < addr_cnt; i++) {
2477 memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
2478 memset(tmpNum, 0x00, sizeof(tmpNum));
2479 MsgConvertNumber(pAddrInfo[i].addressVal, tmpNum, sizeof(tmpNum));
2480 snprintf(newPhoneNum, sizeof(newPhoneNum), "%%%%%s", tmpNum);
2481 dbHandle->resetQuery();
2482 dbHandle->bindText(newPhoneNum, 1);
2483 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2484 dbHandle->finalizeQuery();
2485 dbHandle->endTrans(false);
2486 return MSG_ERR_DB_EXEC;
2490 dbHandle->finalizeQuery();
2491 dbHandle->endTrans(true);
2497 msg_error_t MsgStoCountMsgByContact(const MSG_THREAD_LIST_INDEX_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pThreadCountInfo)
2499 MsgDbHandler *dbHandle = getDbHandle();
2500 char sqlQuery[MAX_QUERY_LEN+1];
2502 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2504 if (pAddrInfo->contactId > 0) {
2505 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) AS TOTAL, "
2506 "SUM(CASE WHEN READ_STATUS = 0 AND FOLDER_ID = %d THEN 1 ELSE 0 END), "
2507 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END), "
2508 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END) "
2509 "FROM (SELECT * FROM %s A JOIN %s B ON A.CONV_ID = B.CONV_ID WHERE B.CONTACT_ID = %d)",
2510 MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MMS_TYPE, MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pAddrInfo->contactId);
2512 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) AS TOTAL, "
2513 "SUM(CASE WHEN READ_STATUS = 0 AND FOLDER_ID = %d THEN 1 ELSE 0 END), "
2514 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END), "
2515 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END) "
2516 "FROM (SELECT * FROM %s A JOIN %s B ON A.CONV_ID = B.CONV_ID WHERE B.ADDRESS_VAL = '%s')",
2517 MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MMS_TYPE, MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pAddrInfo->msgAddrInfo.addressVal);
2520 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2521 return MSG_ERR_DB_PREPARE;
2523 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2524 pThreadCountInfo->totalCount = dbHandle->columnInt(0);
2525 pThreadCountInfo->unReadCount = dbHandle->columnInt(1);
2526 pThreadCountInfo->smsMsgCount = dbHandle->columnInt(2);
2527 pThreadCountInfo->mmsMsgCount = dbHandle->columnInt(3);
2529 dbHandle->finalizeQuery();
2530 return MSG_ERR_DB_STEP;
2533 dbHandle->finalizeQuery();
2539 msg_error_t MsgStoGetSyncMLExtId(msg_message_id_t msgId, int *extId)
2541 MsgDbHandler *dbHandle = getDbHandle();
2542 char sqlQuery[MAX_QUERY_LEN+1];
2544 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2546 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXT_ID FROM %s WHERE MSG_ID = %d;",
2547 MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
2549 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2550 return MSG_ERR_DB_PREPARE;
2552 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2553 *extId = dbHandle->columnInt(0);
2555 dbHandle->finalizeQuery();
2556 return MSG_ERR_DB_STEP;
2559 dbHandle->finalizeQuery();
2565 msg_error_t MsgStoGetSmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
2567 MsgDbHandler *dbHandle = getDbHandle();
2568 char sqlQuery[MAX_QUERY_LEN+1];
2569 msg_error_t err = MSG_SUCCESS;
2571 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2572 snprintf(sqlQuery, sizeof(sqlQuery),
2573 "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
2575 "WHERE MSG_ID = %d "
2576 "order by TIME ASC;"
2577 , MSGFW_SMS_REPORT_TABLE_NAME, msgId);
2579 int rowCnt = 0, index = 0;
2580 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2582 if (err != MSG_SUCCESS) {
2583 MSG_DEBUG("Fail to getTable().");
2584 dbHandle->freeTable();
2585 if (err == MSG_ERR_DB_NORECORD)
2591 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
2592 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
2594 for (int i = 0; i < rowCnt; i++) {
2595 dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
2596 report_status[i].type = dbHandle->getColumnToInt(index++);
2597 report_status[i].status = dbHandle->getColumnToInt(index++);
2598 report_status[i].statusTime = (time_t)dbHandle->getColumnToInt(index++);
2600 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);
2603 *pReportStatus = report_status;
2605 dbHandle->freeTable();
2610 msg_error_t MsgStoGetMmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
2612 MsgDbHandler *dbHandle = getDbHandle();
2613 char sqlQuery[MAX_QUERY_LEN+1];
2615 msg_direction_type_t direction = MSG_DIRECTION_TYPE_MO;
2617 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_DIRECTION FROM %s WHERE MSG_ID = %d;",
2618 MSGFW_MESSAGE_TABLE_NAME, msgId);
2620 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2621 return MSG_ERR_DB_PREPARE;
2623 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2624 direction = dbHandle->columnInt(0);
2627 dbHandle->finalizeQuery();
2629 if (direction == MSG_DIRECTION_TYPE_MO) {/*get received report list of MO message */
2630 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2631 /*MSG_ID INTEGER , ADDRESS_VAL TEXT , STATUS_TYPE INTEGER , STATUS INTEGER DEFAULT 0 , TIME DATETIME) */
2632 /*select * from MSG_REPORT_TABLE where MSG_ID=38 order by ADDRESS_VAL DESC, STATUS_TYPE ASC; */
2633 snprintf(sqlQuery, sizeof(sqlQuery),
2634 "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
2636 "WHERE MSG_ID = %d "
2637 "order by ADDRESS_VAL DESC, STATUS_TYPE ASC;"
2638 , MSGFW_REPORT_TABLE_NAME, msgId);
2640 int rowCnt = 0, index = 0;
2641 msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2642 if (err != MSG_SUCCESS) {
2643 MSG_DEBUG("Fail to getTable().");
2644 dbHandle->freeTable();
2645 if (err == MSG_ERR_DB_NORECORD)
2651 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
2652 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
2654 for (int i = 0; i < rowCnt; i++) {
2655 dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
2656 report_status[i].type = dbHandle->getColumnToInt(index++);
2657 report_status[i].status = dbHandle->getColumnToInt(index++);
2658 report_status[i].statusTime = (time_t)dbHandle->getColumnToInt(index++);
2660 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);
2663 *pReportStatus = report_status;
2665 dbHandle->freeTable();
2667 } else if (direction == MSG_DIRECTION_TYPE_MT) { /*read report sent status of MT message */
2668 int readReportSentStatus;
2670 if (MsgStoCheckReadReportRequested(dbHandle, msgId) == false) {
2672 *pReportStatus = NULL;
2673 return MSG_ERR_READREPORT_NOT_REQUESTED;
2676 MsgStoGetReadReportSendStatus(msgId, &readReportSentStatus);
2680 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)];
2681 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
2683 report_status->addressVal[0] = '\0';
2684 report_status->type = MSG_REPORT_TYPE_READ_REPORT_SENT;
2685 report_status->status = readReportSentStatus;
2686 report_status->statusTime = 0;
2688 MSG_DEBUG("report_type = %d, report_status = %d", report_status->type, report_status->status);
2690 *pReportStatus = report_status;
2697 msg_error_t MsgStoGetThreadIdByAddress(const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t *pThreadId)
2699 MsgDbHandler *dbHandle = getDbHandle();
2700 if(pMsg->nAddressCnt > 0) {
2701 if (MsgExistAddress(dbHandle, pMsg, pThreadId) == true) {
2702 MSG_DEBUG("Conversation ID : [%d]", *pThreadId);
2704 /* check thread count */
2705 MSG_THREAD_VIEW_S threadInfo;
2706 memset(&threadInfo, 0x00, sizeof(MSG_THREAD_VIEW_S));
2707 MsgStoGetThreadInfo(*pThreadId, &threadInfo);
2708 MSG_DEBUG("threadInfo.smsCnt [%d], threadInfo.mmsCnt [%d]", threadInfo.smsCnt, threadInfo.mmsCnt);
2709 if ((threadInfo.smsCnt + threadInfo.mmsCnt) > 0) {
2720 msg_error_t MsgStoGetThreadUnreadCnt(msg_thread_id_t threadId, int *cnt)
2724 MsgDbHandler *dbHandle = getDbHandle();
2728 char sqlQuery[MAX_QUERY_LEN+1];
2731 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2732 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s A \
2733 WHERE CONV_ID = %d AND READ_STATUS = 0;", MSGFW_MESSAGE_TABLE_NAME, threadId);
2735 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2736 return MSG_ERR_DB_PREPARE;
2738 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2739 msgCnt = dbHandle->columnInt(0);
2742 dbHandle->finalizeQuery();
2752 msg_error_t MsgStoGetThreadInfo(msg_thread_id_t threadId, MSG_THREAD_VIEW_S *pThreadInfo)
2756 MsgDbHandler *dbHandle = getDbHandle();
2757 int rowCnt = 0, index = 0;
2759 char sqlQuery[MAX_QUERY_LEN+1];
2760 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2762 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.UNREAD_CNT, A.SMS_CNT, A.MMS_CNT, "
2763 "A.MAIN_TYPE, A.SUB_TYPE, A.MSG_DIRECTION, A.DISPLAY_TIME, A.DISPLAY_NAME, A.MSG_TEXT, "
2764 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.PROTECTED = 1) AS PROTECTED, "
2765 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.FOLDER_ID = %d) AS DRAFT, "
2766 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.NETWORK_STATUS = %d) AS FAILED, "
2767 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.NETWORK_STATUS = %d) AS SENDING "
2768 "FROM %s A WHERE A.CONV_ID = %d AND A.SMS_CNT + A.MMS_CNT > 0;",
2769 MSGFW_MESSAGE_TABLE_NAME,
2770 MSGFW_MESSAGE_TABLE_NAME, MSG_DRAFT_ID,
2771 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_FAIL,
2772 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SENDING,
2773 MSGFW_CONVERSATION_TABLE_NAME, threadId);
2775 msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2777 if (err == MSG_ERR_DB_NORECORD) {
2778 dbHandle->freeTable();
2780 } else if (err != MSG_SUCCESS) {
2781 MSG_DEBUG("Fail to getTable().");
2782 dbHandle->freeTable();
2787 MSG_DEBUG("rowCnt is %d", rowCnt);
2788 dbHandle->freeTable();
2791 pThreadInfo->threadId = dbHandle->getColumnToInt(index++);
2793 pThreadInfo->unreadCnt = dbHandle->getColumnToInt(index++);
2794 pThreadInfo->smsCnt = dbHandle->getColumnToInt(index++);
2795 pThreadInfo->mmsCnt = dbHandle->getColumnToInt(index++);
2797 pThreadInfo->mainType = dbHandle->getColumnToInt(index++);
2798 pThreadInfo->subType = dbHandle->getColumnToInt(index++);
2800 pThreadInfo->direction = dbHandle->getColumnToInt(index++);
2801 pThreadInfo->threadTime = (time_t)dbHandle->getColumnToInt(index++);
2803 memset(pThreadInfo->threadName, 0x00, sizeof(pThreadInfo->threadName));
2804 dbHandle->getColumnToString(index++, MAX_THREAD_NAME_LEN, pThreadInfo->threadName);
2806 memset(pThreadInfo->threadData, 0x00, sizeof(pThreadInfo->threadData));
2807 dbHandle->getColumnToString(index++, MAX_THREAD_DATA_LEN, pThreadInfo->threadData);
2809 int protectedCnt = dbHandle->getColumnToInt(index++);
2810 if (protectedCnt > 0)
2811 pThreadInfo->bProtected = true;
2813 int draftCnt = dbHandle->getColumnToInt(index++);
2815 pThreadInfo->bDraft = true;
2817 int failedCnt = dbHandle->getColumnToInt(index++);
2819 pThreadInfo->bSendFailed = true;
2821 int sendingCnt = dbHandle->getColumnToInt(index++);
2823 pThreadInfo->bSending = true;
2826 dbHandle->freeTable();
2834 msg_error_t MsgStoRestoreMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
2838 MsgDbHandler *dbHandle = getDbHandle();
2839 msg_error_t err = MSG_SUCCESS;
2840 char sqlQuery[MAX_QUERY_LEN+1];
2842 if(MsgExistConversation(dbHandle, pMsg->threadId)) {
2843 /* add message to address table which having same thread_id and datetime; */
2844 for (int i = 0; i < pMsg->nAddressCnt; i++) {
2845 if(MsgExistAddress(dbHandle, pMsg, pMsg->threadId, i) == false) {
2846 unsigned int addrId;
2847 MSG_CONTACT_INFO_S contactInfo;
2848 memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
2850 /* Get Contact Info */
2851 /* if (MsgGetContactInfo(&(pMsg->addressList[i]), &contactInfo) != MSG_SUCCESS) { */
2852 /* MSG_DEBUG("MsgGetContactInfo() fail."); */
2854 err = dbHandle->getRowId(MSGFW_ADDRESS_TABLE_NAME, &addrId);
2855 if (err != MSG_SUCCESS) {
2856 MSG_DEBUG("pDbHandle->getRowId fail. [%d]", err);
2861 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2862 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, '%s', %d, %d, ?, ?, ?, ?, ?, '%s', 0);",
2863 MSGFW_ADDRESS_TABLE_NAME, addrId, pMsg->threadId, pMsg->addressList[i].addressType, pMsg->addressList[i].recipientType, pMsg->addressList[i].addressVal,
2864 contactInfo.contactId, contactInfo.addrbookId, contactInfo.imagePath);
2866 MSG_SEC_DEBUG("Add Address Info. [%s]", sqlQuery);
2868 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2869 return MSG_ERR_DB_PREPARE;
2871 dbHandle->bindText(contactInfo.firstName, 1);
2872 dbHandle->bindText(contactInfo.lastName, 2);
2873 dbHandle->bindText(contactInfo.middleName, 3);
2874 dbHandle->bindText(contactInfo.prefix, 4);
2875 dbHandle->bindText(contactInfo.suffix, 5);
2877 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2878 dbHandle->finalizeQuery();
2879 return MSG_ERR_DB_STEP;
2882 dbHandle->finalizeQuery();
2884 /* set conversation display name by conv id */
2885 MsgStoSetConversationDisplayName(dbHandle, pMsg->threadId);
2890 if(!MsgExistMessage(dbHandle, pMsg)) {
2891 unsigned int rowId = 0;
2893 if (pMsg->threadId > 0 && pMsg->folderId == MSG_DRAFT_ID) {
2894 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2896 snprintf(sqlQuery, sizeof(sqlQuery),
2897 "DELETE FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d;",
2898 MSGFW_MESSAGE_TABLE_NAME, pMsg->threadId, MSG_DRAFT_ID);
2900 MSG_DEBUG("sqlQuery [%s]", sqlQuery);
2902 err = dbHandle->execQuery(sqlQuery);
2904 if (err != MSG_SUCCESS) {
2905 MSG_DEBUG("fail to delete draft messages.");
2909 err = dbHandle->getRowId(MSGFW_MESSAGE_TABLE_NAME, &rowId);
2911 pMsg->msgId = (msg_message_id_t)rowId;
2915 char *pFileData = NULL;
2916 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
2919 if (pMsg->bTextSms == false) {
2920 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
2921 return MSG_ERR_STORAGE_ERROR;
2923 MSG_DEBUG("file size [%d]", fileSize);
2926 char keyName[MAX_VCONFKEY_NAME_LEN];
2927 memset(keyName, 0x00, sizeof(keyName));
2928 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, pMsg->sim_idx);
2931 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
2932 MSG_INFO("MsgSettingGetString() is failed");
2936 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2938 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');",
2939 MSGFW_MESSAGE_TABLE_NAME, rowId, pMsg->threadId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType,
2940 pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
2941 pMsg->bBackup, pMsg->sim_idx, imsi);
2944 MSG_DEBUG("QUERY : %s", sqlQuery);
2951 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
2952 return MSG_ERR_DB_EXEC;
2955 dbHandle->bindText(pMsg->subject, 1);
2957 if (pMsg->bTextSms == false)
2958 dbHandle->bindText(pFileData, 2);
2960 dbHandle->bindText(pMsg->msgText, 2);
2962 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2963 dbHandle->finalizeQuery();
2964 return MSG_ERR_DB_EXEC;
2967 dbHandle->finalizeQuery();
2969 if (pMsg->msgType.subType != MSG_SENDREQ_MMS) {
2970 err = MsgStoUpdateConversation(dbHandle, pMsg->threadId);
2972 if (err != MSG_SUCCESS) {
2977 /* In the case of MMS Message, load the MMS plugin to save MMS PDU */
2978 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
2979 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
2980 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
2982 return MSG_ERR_NULL_POINTER;
2984 err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
2986 if (err != MSG_SUCCESS)
2987 return MSG_ERR_STORAGE_ERROR;
2989 if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
2990 MSG_SEC_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
2992 err = MsgStoUpdateMMSMessage(pMsg);
2994 if (err != MSG_SUCCESS)
2995 return MSG_ERR_STORAGE_ERROR;
3001 /* add message to conversation, message, address table; */
3003 err = MsgStoAddMessage(pMsg, pSendOptInfo);
3012 msg_message_id_t MsgStoAddSimMessage(MSG_MESSAGE_INFO_S *pMsg, int *simIdList, int listSize)
3015 MsgDbHandler *dbHandle = getDbHandle();
3016 if (pMsg == NULL || pMsg->msgType.mainType == MSG_MMS_TYPE) {
3017 MSG_DEBUG("pMsg == NULL || pMsg->msgType.mainType == MSG_MMS_TYPE");
3021 if ((pMsg->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsg->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
3022 if (pMsg->msgId > 0) {
3023 pMsg->bRead = false;
3024 if (MsgStoUpdateMessage(pMsg, NULL) != MSG_SUCCESS) {
3025 MSG_DEBUG("MsgStoUpdateMessage is failed!!!");
3028 if (MsgStoAddMessage(pMsg, NULL) != MSG_SUCCESS) {
3029 MSG_DEBUG("MsgStoAddMessage is failed!!!");
3034 if (MsgStoAddMessage(pMsg, NULL) != MSG_SUCCESS) {
3035 MSG_DEBUG("MsgStoAddMessage is failed!!!");
3040 dbHandle->beginTrans();
3042 MSG_DEBUG("simIdList exist.");
3044 for(int i = 0; i < listSize; ++i) {
3046 simId = simIdList[i] - 1;
3047 char sqlQuery[MAX_QUERY_LEN+1];
3048 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3049 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
3050 MSGFW_SIM_MSG_TABLE_NAME, pMsg->sim_idx, simId, pMsg->msgId);
3052 MSG_DEBUG("QUERY : %s", sqlQuery);
3054 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
3055 dbHandle->endTrans(false);
3063 dbHandle->endTrans(true);
3071 #ifdef FEATURE_SMS_CDMA
3072 msg_error_t MsgCheckUniqueness(bool bInsert, msg_message_id_t msgId, MSG_UNIQUE_INDEX_S *p_msg)
3076 MsgDbHandler *dbHandle = getDbHandle();
3079 char sqlQuery[MAX_QUERY_LEN+1];
3082 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3083 dbHandle->beginTrans();
3085 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;",
3086 MSGFW_UNIQUENESS_INFO_TABLE_NAME, p_msg->tele_msgId, p_msg->address, p_msg->sub_address, p_msg->time_stamp, p_msg->telesvc_id);
3088 dbHandle->getTable(sqlQuery, &nRowCnt, NULL);
3089 MSG_DEBUG("nRowCnt = [%d]", nRowCnt);
3091 dbHandle->freeTable();
3092 dbHandle->endTrans(true);
3095 MSG_DEBUG("<<<<This incoming message is a new message>>>>");
3098 MSG_DEBUG("<<<<This incoming message is a repeated message>>>>");
3099 return MSG_ERR_UNKNOWN;
3102 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3103 dbHandle->beginTrans();
3105 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, '%s', '%s', '%s', %d);",
3106 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);
3108 dbHandle->execQuery(sqlQuery);
3109 dbHandle->endTrans(true);
3118 msg_error_t MsgStoUpdateIMSI(int sim_idx)
3121 MSG_DEBUG("sim_idx = %d", sim_idx);
3123 /* msg_error_t err = MSG_SUCCESS; */
3124 MsgDbHandler *dbHandle = getDbHandle();
3126 char sqlQuery[MAX_QUERY_LEN+1];
3127 char keyName[MAX_VCONFKEY_NAME_LEN];
3129 dbHandle->beginTrans();
3132 MSG_DEBUG("sim index is 0");
3133 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3135 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET SIM_INDEX = 0;",
3136 MSGFW_MESSAGE_TABLE_NAME);
3138 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
3139 dbHandle->endTrans(false);
3140 return MSG_ERR_DB_EXEC;
3143 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
3144 dbHandle->finalizeQuery();
3145 dbHandle->endTrans(false);
3146 return MSG_ERR_DB_EXEC;
3149 MSG_DEBUG("sim index is %d", sim_idx);
3151 memset(keyName, 0x00, sizeof(keyName));
3152 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, sim_idx);
3155 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
3156 MSG_INFO("MsgSettingGetString() is failed");
3159 MSG_SEC_DEBUG("imsi value exist -> %s", imsi);
3161 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3163 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET SIM_INDEX = %d \
3164 WHERE SIM_IMSI LIKE '%s';",
3165 MSGFW_MESSAGE_TABLE_NAME, sim_idx, imsi);
3172 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
3173 dbHandle->endTrans(false);
3174 return MSG_ERR_DB_EXEC;
3177 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
3178 dbHandle->finalizeQuery();
3179 dbHandle->endTrans(false);
3180 return MSG_ERR_DB_EXEC;
3184 dbHandle->finalizeQuery();
3185 dbHandle->endTrans(true);
3193 msg_error_t MsgStoUpdateDPMRestrictedStatus(MSG_MAIN_TYPE_T msgType)
3195 msg_error_t err = MSG_SUCCESS;
3197 char sqlQuery[MAX_QUERY_LEN+1];
3198 MsgDbHandler *dbHandle = getDbHandle();
3200 msg_id_list_s msgIdList = {0, };
3203 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3204 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE MAIN_TYPE = %d AND DPM_RESTRICTED = 1;",
3205 MSGFW_MESSAGE_TABLE_NAME, msgType);
3207 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
3208 if (err != MSG_SUCCESS) {
3209 dbHandle->freeTable();
3213 msg_message_id_t *msgIds = new msg_message_id_t[rowCnt];
3214 for (int i = 0; i < rowCnt; i++) {
3215 msgIds[i] = dbHandle->getColumnToInt(i + 1);
3218 dbHandle->freeTable();
3220 msgIdList.nCount = rowCnt;
3221 msgIdList.msgIdList = msgIds;
3223 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3224 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET DPM_RESTRICTED = 0 WHERE MAIN_TYPE = %d AND DPM_RESTRICTED = 1;",
3225 MSGFW_MESSAGE_TABLE_NAME, msgType);
3227 err = dbHandle->execQuery(sqlQuery);
3228 if (err == MSG_SUCCESS) {
3229 MsgStoUpdateAllAddress();
3230 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
3233 if (msgIdList.msgIdList)
3234 delete [] msgIdList.msgIdList;