2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <tr1/unordered_set>
26 #include "MsgCppTypes.h"
27 #include "MsgContact.h"
28 #include "MsgUtilFile.h"
30 #include "MsgUtilStorage.h"
31 #include "MsgGconfWrapper.h"
32 #include "MsgSqliteWrapper.h"
33 #include "MsgPluginManager.h"
34 #include "MsgStorageHandler.h"
35 #include "MsgNotificationWrapper.h"
36 #include "MsgDevicedWrapper.h"
37 #include "MsgTransManager.h"
42 /*==================================================================================================
44 ==================================================================================================*/
48 bool delNotiRunning = false;
52 bool delLogRunning = false;
55 /*==================================================================================================
57 ==================================================================================================*/
58 static gboolean resetNotification(void *pVoid)
62 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
70 /*==================================================================================================
71 FUNCTION IMPLEMENTATION
72 ==================================================================================================*/
74 msg_error_t MsgStoAddMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
78 msg_error_t err = MSG_SUCCESS;
80 unsigned int rowId = 0;
81 msg_thread_id_t convId = 0;
83 char sqlQuery[MAX_QUERY_LEN+1];
85 MsgDbHandler *dbHandle = getDbHandle();
87 dbHandle->beginTrans();
89 if (pMsg->nAddressCnt > 0) {
90 err = MsgStoAddAddress(dbHandle, pMsg, &convId);
92 if (err != MSG_SUCCESS) {
93 dbHandle->endTrans(false);
97 pMsg->threadId = convId;
100 if (pMsg->msgId > 0) {
104 err = dbHandle->getRowId(MSGFW_MESSAGE_TABLE_NAME, &rowId);
105 if (err != MSG_SUCCESS) {
106 dbHandle->endTrans(false);
109 pMsg->msgId = (msg_message_id_t)rowId;
114 char *pFileData = NULL;
115 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
118 if (pMsg->bTextSms == false) {
119 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
120 dbHandle->endTrans(false);
121 return MSG_ERR_STORAGE_ERROR;
124 MSG_DEBUG("file size [%d]", fileSize);
127 char keyName[MAX_VCONFKEY_NAME_LEN];
128 memset(keyName, 0x00, sizeof(keyName));
129 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, pMsg->sim_idx);
132 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
133 MSG_INFO("MsgSettingGetString() is failed");
137 memset(sqlQuery, 0x00, sizeof(sqlQuery));
139 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %u, %zu, %d, %d, %d, %d, %d, %d, %d, ?, '', '', ?, 0, %d, '%s', %d);",
140 MSGFW_MESSAGE_TABLE_NAME, rowId, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType,
141 (unsigned int)pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
142 0, pMsg->bBackup, pMsg->sim_idx, imsi, pMsg->bRestricted);
144 MSG_DEBUG("QUERY : %s", sqlQuery);
149 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
150 dbHandle->endTrans(false);
151 return MSG_ERR_DB_EXEC;
154 dbHandle->bindText(pMsg->subject, 1);
156 if (pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
157 dbHandle->bindText("", 2);
159 if (pMsg->bTextSms == false)
160 dbHandle->bindText(pFileData, 2);
162 dbHandle->bindText(pMsg->msgText, 2);
165 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
166 dbHandle->finalizeQuery();
167 dbHandle->endTrans(false);
168 return MSG_ERR_DB_EXEC;
171 dbHandle->finalizeQuery();
173 if (pMsg->msgType.subType != MSG_SENDREQ_MMS) {
174 err = MsgStoUpdateConversation(dbHandle, convId);
176 if (err != MSG_SUCCESS) {
177 dbHandle->endTrans(false);
183 /* In the case of MMS Message, load the MMS plugin to save MMS PDU */
184 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
185 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
186 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
188 dbHandle->endTrans(false);
189 return MSG_ERR_NULL_POINTER;
192 if (pFileData == NULL) {
193 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
194 dbHandle->endTrans(false);
195 return MSG_ERR_STORAGE_ERROR;
198 MSG_DEBUG("file size [%d]", fileSize);
201 err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
203 if (err != MSG_SUCCESS) {
204 dbHandle->endTrans(false);
205 return MSG_ERR_STORAGE_ERROR;
208 if (pMsg->msgType.subType == MSG_SENDREQ_MMS
209 || pMsg->msgType.subType == MSG_RETRIEVE_MMS
210 || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS
211 || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
212 MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
214 err = MsgStoUpdateMMSMessage(pMsg);
216 if (err != MSG_SUCCESS) {
217 dbHandle->endTrans(false);
218 return MSG_ERR_STORAGE_ERROR;
222 } else if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL) {
223 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
225 dbHandle->endTrans(false);
226 return MSG_ERR_NULL_POINTER;
228 err = plg->addMessage(pMsg, pSendOptInfo, NULL);
229 if (err != MSG_SUCCESS) {
230 dbHandle->endTrans(false);
231 return MSG_ERR_STORAGE_ERROR;
235 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
236 char *pMmsSerializedData = NULL;
237 unique_ptr<char*, void(*)(char**)> buf_mms(&pMmsSerializedData, unique_ptr_deleter);
239 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
240 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
243 dbHandle->endTrans(false);
244 return MSG_ERR_NULL_POINTER;
247 if (MsgOpenAndReadFile(pMsg->msgData, &pMmsSerializedData, &fileSize) == false) {
248 dbHandle->endTrans(false);
249 return MSG_ERR_STORAGE_ERROR;
252 MSG_DEBUG("file size [%d]", fileSize);
254 err = plg->addMessage(pMsg, pSendOptInfo, pMmsSerializedData);
256 if (err != MSG_SUCCESS) {
257 dbHandle->endTrans(false);
258 return MSG_ERR_STORAGE_ERROR;
261 * if (pMsg->msgText[0] != '\0') {
262 * g_file_get_contents((gchar*)pMsg->msgText, (gchar**)&pFileData, (gsize*)&fileSize, NULL);
263 * MSG_DEBUG("file size [%d]", fileSize);
267 if (pMsg->msgType.subType == MSG_SENDREQ_MMS
268 || pMsg->msgType.subType == MSG_RETRIEVE_MMS
269 || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS
270 || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
271 MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
272 err = MsgStoUpdateMMSMessage(pMsg);
276 if (pMsg->bTextSms == false) {
277 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
278 dbHandle->endTrans(false);
279 return MSG_ERR_STORAGE_ERROR;
281 MSG_DEBUG("file size [%d]", fileSize);
285 dbHandle->endTrans(true);
293 msg_error_t MsgStoUpdateMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
295 msg_error_t err = MSG_SUCCESS;
297 char sqlQuery[MAX_QUERY_LEN+1];
299 msg_thread_id_t convId = 0;
300 msg_thread_id_t prevConvId = pMsg->threadId;
301 MsgDbHandler *dbHandle = getDbHandle();
302 dbHandle->beginTrans();
304 MSG_MAIN_TYPE_T prevType;
305 memset(sqlQuery, 0x00, sizeof(sqlQuery));
306 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE FROM %s WHERE MSG_ID = %d;",
307 MSGFW_MESSAGE_TABLE_NAME, pMsg->msgId);
309 MSG_DEBUG("QUERY : %s", sqlQuery);
311 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
312 dbHandle->endTrans(false);
313 return MSG_ERR_DB_PREPARE;
316 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
317 dbHandle->finalizeQuery();
318 dbHandle->endTrans(false);
319 return MSG_ERR_STORAGE_ERROR;
322 prevType = dbHandle->columnInt(0);
323 dbHandle->finalizeQuery();
325 /* check msg type with previous type */
326 if (prevType != pMsg->msgType.mainType) {
327 MSG_DEBUG("different msg type to update [prev : %d], [current : %d]", prevType, pMsg->msgType.mainType);
329 err = MsgStoDeleteMessage(pMsg->msgId, false);
330 if (err != MSG_SUCCESS) {
331 dbHandle->endTrans(false);
335 err = MsgStoAddMessage(pMsg, pSendOptInfo);
336 if (err != MSG_SUCCESS) {
337 dbHandle->endTrans(false);
341 dbHandle->endTrans(false);
345 if (pMsg->nAddressCnt > 0) {
347 err = MsgStoAddAddress(dbHandle, pMsg, &convId);
349 if (err != MSG_SUCCESS) {
350 dbHandle->endTrans(false);
357 char *pFileData = NULL;
358 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
361 if (pMsg->bTextSms == false) {
362 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
363 dbHandle->endTrans(false);
364 return MSG_ERR_STORAGE_ERROR;
368 if (pSendOptInfo != NULL) {
369 /* Get Global setting value if bSetting == false */
370 if (pSendOptInfo->bSetting == false) {
371 if (MsgSettingGetBool(MSG_KEEP_COPY, &pSendOptInfo->bKeepCopy) != MSG_SUCCESS)
372 MSG_INFO("MsgSettingGetBool() is failed");
374 if (pMsg->msgType.mainType == MSG_SMS_TYPE) {
375 if (MsgSettingGetBool(SMS_SEND_DELIVERY_REPORT, &pSendOptInfo->bDeliverReq) != MSG_SUCCESS)
376 MSG_INFO("MsgSettingGetBool() is failed");
378 if (MsgSettingGetBool(SMS_SEND_REPLY_PATH, &pSendOptInfo->option.smsSendOptInfo.bReplyPath) != MSG_SUCCESS)
379 MSG_INFO("MsgSettingGetBool() is failed");
380 } else if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
381 if (MsgSettingGetBool(MMS_SEND_DELIVERY_REPORT, &pSendOptInfo->bDeliverReq) != MSG_SUCCESS)
382 MSG_INFO("MsgSettingGetBool() is failed");
384 if (MsgSettingGetBool(MMS_SEND_READ_REPLY, &pSendOptInfo->option.mmsSendOptInfo.bReadReq) != MSG_SUCCESS)
385 MSG_INFO("MsgSettingGetBool() is failed");
388 if (MsgSettingGetInt(MMS_SEND_EXPIRY_TIME, &tmpVal) != MSG_SUCCESS) {
389 MSG_INFO("MsgSettingGetInt() is failed");
391 pSendOptInfo->option.mmsSendOptInfo.expiryTime.time = (unsigned int)tmpVal;
393 if (MsgSettingGetInt(MMS_SEND_DELIVERY_TIME, &tmpVal) != MSG_SUCCESS) {
394 MSG_INFO("MsgSettingGetInt() is failed");
396 MSG_MMS_DELIVERY_TIME_T deliveryTime = (MSG_MMS_DELIVERY_TIME_T)tmpVal;
398 if (deliveryTime == MSG_DELIVERY_TIME_CUSTOM) {
399 pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime = true;
400 if (MsgSettingGetInt(MMS_SEND_CUSTOM_DELIVERY, &tmpVal) != MSG_SUCCESS) {
401 MSG_INFO("MsgSettingGetInt() is failed");
403 pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = (unsigned int)tmpVal;
405 pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime = false;
406 pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = (unsigned int)deliveryTime;
409 if (MsgSettingGetInt(MMS_SEND_PRIORITY, &tmpVal) != MSG_SUCCESS) {
410 MSG_INFO("MsgSettingGetInt() is failed");
412 pSendOptInfo->option.mmsSendOptInfo.priority = (msg_priority_type_t)tmpVal;
418 memset(sqlQuery, 0x00, sizeof(sqlQuery));
420 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET CONV_ID = %d, FOLDER_ID = %d, STORAGE_ID = %d, MAIN_TYPE = %d, SUB_TYPE = %d, \
421 DISPLAY_TIME = %lu, DATA_SIZE = %zu, NETWORK_STATUS = %d, READ_STATUS = %d, PROTECTED = %d, PRIORITY = %d, MSG_DIRECTION = %d, \
422 BACKUP = %d, SUBJECT = ?, MSG_TEXT = ? \
424 MSGFW_MESSAGE_TABLE_NAME, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->displayTime, pMsg->dataSize,
425 pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction, pMsg->bBackup, pMsg->msgId);
427 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
428 dbHandle->endTrans(false);
429 return MSG_ERR_DB_EXEC;
432 dbHandle->bindText(pMsg->subject, 1);
434 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pMsg->bTextSms == false)
435 dbHandle->bindText(pFileData, 2);
437 dbHandle->bindText(pMsg->msgText, 2);
439 MSG_DEBUG("%s", sqlQuery);
441 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
442 dbHandle->finalizeQuery();
443 dbHandle->endTrans(false);
444 return MSG_ERR_DB_EXEC;
447 dbHandle->finalizeQuery();
449 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL) {
450 if (pSendOptInfo->bSetting == true) {
451 memset(sqlQuery, 0x00, sizeof(sqlQuery));
452 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET "
457 "WHERE MSG_ID = %d;",
458 MSGFW_SMS_SENDOPT_TABLE_NAME,
459 pSendOptInfo->bDeliverReq,
460 pSendOptInfo->bKeepCopy,
461 pSendOptInfo->option.smsSendOptInfo.bReplyPath,
465 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
466 dbHandle->endTrans(false);
467 return MSG_ERR_DB_EXEC;
470 } else if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
471 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
473 dbHandle->endTrans(false);
474 return MSG_ERR_NULL_POINTER;
477 err = plg->updateMessage(pMsg, pSendOptInfo, pFileData);
479 if (err != MSG_SUCCESS) {
480 dbHandle->endTrans(false);
481 return MSG_ERR_STORAGE_ERROR;
484 if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
485 MSG_SEC_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
487 err = MsgStoUpdateMMSMessage(pMsg);
489 if (err != MSG_SUCCESS) {
490 dbHandle->endTrans(false);
491 return MSG_ERR_STORAGE_ERROR;
496 err = MsgStoUpdateConversation(dbHandle, convId);
498 if (err != MSG_SUCCESS) {
499 dbHandle->endTrans(false);
500 return MSG_ERR_STORAGE_ERROR;
503 err = MsgStoClearConversationTable(dbHandle);
505 if (err != MSG_SUCCESS) {
506 dbHandle->endTrans(false);
507 return MSG_ERR_STORAGE_ERROR;
510 dbHandle->endTrans(true);
512 if (prevConvId != 0 && prevConvId != convId && MsgExistInThreadViewList(dbHandle, prevConvId) == false)
513 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, prevConvId);
519 msg_error_t MsgStoUpdateReadStatus(msg_message_id_t msgId, bool bRead)
521 char sqlQuery[MAX_QUERY_LEN+1];
523 msg_storage_id_t storageId;
525 MsgDbHandler *dbHandle = getDbHandle();
526 if (MsgStoSetReadStatus(dbHandle, msgId, bRead) != MSG_SUCCESS) {
527 MSG_DEBUG("MsgStoSetReadStatus() Error");
528 return MSG_ERR_STORAGE_ERROR;
531 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
534 #ifndef FEATURE_SMS_CDMA
536 memset(sqlQuery, 0x00, sizeof(sqlQuery));
537 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT STORAGE_ID FROM %s WHERE MSG_ID = %d;",
538 MSGFW_MESSAGE_TABLE_NAME, msgId);
540 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
541 return MSG_ERR_DB_PREPARE;
543 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
544 storageId = dbHandle->columnInt(0);
546 dbHandle->finalizeQuery();
547 return MSG_ERR_DB_STEP;
549 dbHandle->finalizeQuery();
551 MSG_DEBUG("StorageId:[%d]", storageId);
553 /* Update Read Status for SIM Msg */
554 if (storageId == MSG_STORAGE_SIM) {
555 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
558 MSG_DEBUG("SMS Plug-in is NULL");
559 return MSG_ERR_NULL_POINTER;
563 memset(sqlQuery, 0x00, sizeof(sqlQuery));
564 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
565 MSGFW_SIM_MSG_TABLE_NAME, msgId);
567 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
568 return MSG_ERR_DB_PREPARE;
571 msg_sim_slot_id_t sim_idx;
573 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
574 sim_idx = dbHandle->columnInt(0);
575 simId = dbHandle->columnInt(1);
577 if (plg->setReadStatus(sim_idx, simId) != MSG_SUCCESS) {
578 MSG_DEBUG("Fail to Set Read Status for SIM SMS");
582 dbHandle->finalizeQuery();
591 msg_error_t MsgStoUpdateThreadReadStatus(msg_thread_id_t threadId, msg_id_list_s *pMsgIdList)
595 msg_error_t err = MSG_SUCCESS;
597 char sqlQuery[MAX_QUERY_LEN+1];
599 /*** Get msg id list **/
600 int rowCnt = 0, index = 0;
601 pMsgIdList->nCount = 0;
602 MsgDbHandler *dbHandle = getDbHandle();
604 memset(sqlQuery, 0x00, sizeof(sqlQuery));
605 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s "
606 "WHERE CONV_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d AND FOLDER_ID < %d;",
607 MSGFW_MESSAGE_TABLE_NAME,
608 threadId, MSG_STORAGE_PHONE, MSG_SPAMBOX_ID);
610 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
612 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
613 MSG_DEBUG("Fail to getTable().");
614 dbHandle->freeTable();
619 dbHandle->freeTable();
623 pMsgIdList->nCount = rowCnt;
624 MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
626 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
628 for (int i = 0; i < rowCnt; i++)
629 pMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
631 dbHandle->freeTable();
634 /* set read status */
635 dbHandle->beginTrans();
636 memset(sqlQuery, 0x00, sizeof(sqlQuery));
637 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET READ_STATUS = %d "
638 "WHERE CONV_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d AND FOLDER_ID < %d;",
639 MSGFW_MESSAGE_TABLE_NAME, 1,
640 threadId, MSG_STORAGE_PHONE, MSG_SPAMBOX_ID);
642 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
643 dbHandle->endTrans(false);
644 return MSG_ERR_DB_EXEC;
648 if (MsgStoUpdateConversation(dbHandle, threadId) != MSG_SUCCESS) {
649 MSG_DEBUG("MsgStoUpdateConversation() Error");
650 dbHandle->endTrans(false);
651 return MSG_ERR_STORAGE_ERROR;
654 dbHandle->endTrans(true);
655 if (g_idle_add(resetNotification, NULL) == 0) {
656 MSG_DEBUG("resetNotification() Error");
665 msg_error_t MsgStoUpdateProtectedStatus(msg_message_id_t msgId, bool bProtected)
667 char sqlQuery[MAX_QUERY_LEN+1];
668 MsgDbHandler *dbHandle = getDbHandle();
670 memset(sqlQuery, 0x00, sizeof(sqlQuery));
671 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET PROTECTED = %d WHERE MSG_ID = %d;",
672 MSGFW_MESSAGE_TABLE_NAME, (int)bProtected, msgId);
674 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
675 return MSG_ERR_DB_EXEC;
681 msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
685 MSG_DEBUG("Msg Id : %d", msgId);
687 msg_error_t err = MSG_SUCCESS;
689 char sqlQuery[MAX_QUERY_LEN+1];
690 MsgDbHandler *dbHandle = getDbHandle();
692 /* delete report notification */
693 char tempAddr[MAX_ADDRESS_VAL_LEN+1];
694 memset(tempAddr, 0x00, sizeof(tempAddr));
695 memset(sqlQuery, 0x00, sizeof(sqlQuery));
696 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;"
697 , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, msgId);
699 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
700 return MSG_ERR_DB_PREPARE;
702 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
703 dbHandle->finalizeQuery();
704 return MSG_ERR_DB_DONE;
707 snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
709 MSG_SEC_DEBUG("Updated address = %s", tempAddr);
711 MsgDeleteReportNotification(tempAddr);
713 dbHandle->finalizeQuery();
715 MsgDeleteSentReadReportNotification(msgId);
717 /* Get SUB_TYPE, STORAGE_ID */
718 memset(sqlQuery, 0x00, sizeof(sqlQuery));
719 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE, FOLDER_ID, STORAGE_ID, READ_STATUS, CONV_ID, SIM_INDEX \
720 FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
722 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
723 MSG_DEBUG("Query Failed [%s]", sqlQuery);
724 return MSG_ERR_DB_PREPARE;
727 MSG_MESSAGE_TYPE_S msgType;
728 msg_folder_id_t folderId;
729 msg_storage_id_t storageId;
730 msg_thread_id_t convId;
731 msg_sim_slot_id_t simIndex;
734 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
735 msgType.mainType = dbHandle->columnInt(0);
736 msgType.subType = dbHandle->columnInt(1);
737 folderId = dbHandle->columnInt(2);
738 storageId = dbHandle->columnInt(3);
739 bRead = dbHandle->columnInt(4);
740 convId = dbHandle->columnInt(5);
741 simIndex = dbHandle->columnInt(6);
743 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);
745 MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
747 dbHandle->finalizeQuery();
749 return MSG_ERR_DB_STEP;
752 dbHandle->finalizeQuery();
754 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
757 MSG_DEBUG("SMS Plug-in is NULL");
758 return MSG_ERR_NULL_POINTER;
761 dbHandle->beginTrans();
763 #ifndef FEATURE_SMS_CDMA
764 /* Check sim message */
765 if (storageId == MSG_STORAGE_SIM) {
766 msg_sim_id_t simMsgId;
767 msg_sim_slot_id_t sim_idx;
770 /* get sim message id */
771 memset(sqlQuery, 0x00, sizeof(sqlQuery));
772 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
773 MSGFW_SIM_MSG_TABLE_NAME, msgId);
775 MSG_DEBUG("sqlQuery is [%s]", sqlQuery);
777 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
778 dbHandle->endTrans(false);
779 return MSG_ERR_DB_PREPARE;
782 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
786 sim_idx = dbHandle->columnInt(0);
787 simMsgId = dbHandle->columnInt(1);
789 MSG_DEBUG("SIM Msg Id : [%d]", simMsgId);
791 err = plg->deleteSimMessage(sim_idx, simMsgId);
793 if (err != MSG_SUCCESS) {
794 dbHandle->finalizeQuery();
795 dbHandle->endTrans(false);
799 dbHandle->finalizeQuery();
801 /*Sim message delete in db table */
802 memset(sqlQuery, 0x00, sizeof(sqlQuery));
803 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE SIM_ID = %d AND SIM_SLOT_ID =%d;", MSGFW_SIM_MSG_TABLE_NAME, simMsgId, sim_idx);
805 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
806 dbHandle->finalizeQuery();
807 dbHandle->endTrans(false);
808 return MSG_ERR_DB_EXEC;
812 dbHandle->finalizeQuery();
815 /* each type has to be handled in plug in ? */
816 if (msgType.mainType == MSG_SMS_TYPE) {
817 memset(sqlQuery, 0x00, sizeof(sqlQuery));
818 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
819 MSGFW_SMS_SENDOPT_TABLE_NAME, msgId);
821 /* Delete SMS Send Option */
822 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
823 dbHandle->endTrans(false);
824 return MSG_ERR_DB_EXEC;
827 memset(sqlQuery, 0x00, sizeof(sqlQuery));
828 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
829 MSGFW_SMS_REPORT_TABLE_NAME, msgId);
831 /* Delete Data from SMS_REPORT table */
832 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
833 dbHandle->endTrans(false);
834 return MSG_ERR_DB_EXEC;
837 if (msgType.subType == MSG_CB_SMS || msgType.subType == MSG_JAVACB_SMS
838 || (msgType.subType >= MSG_CMAS_PRESIDENTIAL && msgType.subType <= MSG_CMAS_OPERATOR_DEFINED)) {
839 memset(sqlQuery, 0x00, sizeof(sqlQuery));
840 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
841 MSGFW_CB_MSG_TABLE_NAME, msgId);
843 /* Delete Push Message from push table */
844 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
845 dbHandle->endTrans(false);
846 return MSG_ERR_DB_EXEC;
848 } else if (msgType.subType >= MSG_WAP_SI_SMS && msgType.subType <= MSG_WAP_CO_SMS) {
849 memset(sqlQuery, 0x00, sizeof(sqlQuery));
850 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
851 MSGFW_PUSH_MSG_TABLE_NAME, msgId);
853 /* Delete Push Message from push table */
854 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
855 dbHandle->endTrans(false);
856 return MSG_ERR_DB_EXEC;
858 } else if (msgType.subType == MSG_SYNCML_CP) {
859 memset(sqlQuery, 0x00, sizeof(sqlQuery));
860 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
861 MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
863 /* Delete SyncML Message from syncML table */
864 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
865 dbHandle->endTrans(false);
866 return MSG_ERR_DB_EXEC;
869 } else if (msgType.mainType == MSG_MMS_TYPE) {
870 char filePath[MSG_FILEPATH_LEN_MAX + 1] = {0, };
871 char dirPath[MSG_FILEPATH_LEN_MAX + 1]= {0, };
873 /*remove multipart */
874 memset(sqlQuery, 0x00, sizeof(sqlQuery));
875 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
876 MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
878 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
879 dbHandle->endTrans(false);
880 return MSG_ERR_DB_PREPARE;
883 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
884 memset(filePath, 0x00, sizeof(filePath));
885 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
886 if (remove(filePath) == -1)
887 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
889 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
891 dbHandle->finalizeQuery();
893 /* Delete Data from Multipart table */
894 memset(sqlQuery, 0x00, sizeof(sqlQuery));
895 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
896 MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
898 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
899 dbHandle->endTrans(false);
900 return MSG_ERR_DB_EXEC;
903 memset(sqlQuery, 0x00, sizeof(sqlQuery));
904 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
905 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
907 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
908 dbHandle->endTrans(false);
909 return MSG_ERR_DB_PREPARE;
912 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
913 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
915 snprintf(dirPath, MSG_FILEPATH_LEN_MAX, "%s.dir", filePath);
917 if (remove(filePath) == -1)
918 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
920 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
927 MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
928 dbHandle->finalizeQuery();
929 dbHandle->endTrans(false);
930 return MSG_ERR_DB_STEP;
933 dbHandle->finalizeQuery();
935 /* remove thumbnail file */
936 memset(sqlQuery, 0x00, sizeof(sqlQuery));
937 snprintf(sqlQuery, sizeof(sqlQuery),
938 "SELECT VALUE FROM %s "
939 "WHERE MSG_ID = %d AND (TYPE=%d OR TYPE=%d);",
940 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO);
942 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
943 dbHandle->endTrans(false);
944 return MSG_ERR_DB_PREPARE;
947 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
948 memset(filePath, 0x00, sizeof(filePath));
949 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
950 if (remove(filePath) == -1)
951 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
953 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
956 dbHandle->finalizeQuery();
958 memset(sqlQuery, 0x00, sizeof(sqlQuery));
959 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
960 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId);
962 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
963 dbHandle->endTrans(false);
964 return MSG_ERR_DB_EXEC;
967 memset(sqlQuery, 0x00, sizeof(sqlQuery));
968 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
969 MSGFW_MMS_RECIPIENTS_TABLE_NAME, msgId);
971 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
972 dbHandle->endTrans(false);
973 return MSG_ERR_DB_EXEC;
976 memset(sqlQuery, 0x00, sizeof(sqlQuery));
977 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
978 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
980 /* Delete Data from MMS table */
981 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
982 dbHandle->endTrans(false);
983 return MSG_ERR_DB_EXEC;
986 memset(sqlQuery, 0x00, sizeof(sqlQuery));
987 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
988 MSGFW_REPORT_TABLE_NAME, msgId);
990 /* Delete Data from MMS STATUS table */
991 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
992 dbHandle->endTrans(false);
993 return MSG_ERR_DB_EXEC;
997 memset(sqlQuery, 0x00, sizeof(sqlQuery));
998 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
1000 /* Delete Message from msg table */
1001 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1002 dbHandle->endTrans(false);
1003 return MSG_ERR_DB_EXEC;
1006 #ifdef FEATURE_SMS_CDMA
1007 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1008 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_UNIQUENESS_INFO_TABLE_NAME, msgId);
1010 /* Delete Message from uniqueness table */
1011 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1012 dbHandle->endTrans(false);
1013 return MSG_ERR_DB_EXEC;
1018 /* Clear Conversation table */
1019 if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
1020 dbHandle->endTrans(false);
1021 return MSG_ERR_DB_EXEC;
1024 /* Update conversation table. */
1025 if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
1026 dbHandle->endTrans(false);
1027 return MSG_ERR_STORAGE_ERROR;
1030 dbHandle->endTrans(true);
1032 /* Update Thread Callback */
1033 if (bCheckIndication == true) {
1034 if (MsgExistConversation(dbHandle, convId) == true && MsgExistInThreadViewList(dbHandle, convId) == true)
1035 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, convId);
1037 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, convId);
1040 if (msgType.mainType == MSG_SMS_TYPE && folderId == MSG_INBOX_ID) {
1041 msgType.classType = MSG_CLASS_NONE;
1043 /* Set memory status in SIM */
1044 if (MsgStoCheckMsgCntFull(dbHandle, &msgType, folderId) == MSG_SUCCESS) {
1045 MSG_DEBUG("Set Memory Status");
1047 plg->setMemoryStatus(simIndex, MSG_SUCCESS);
1051 if (bCheckIndication == true) {
1052 MSG_DEBUG("bCheckIndication is true.");
1053 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1060 msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyDB, msg_id_list_s *pMsgIdList)
1062 msg_error_t err = MSG_SUCCESS;
1064 char sqlQuery[MAX_QUERY_LEN+1];
1066 queue<msg_thread_id_t> threadList, threadList2;
1068 #ifdef FEATURE_SMS_CDMA
1069 const char *tableList[] = {MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1070 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1071 MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1072 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1073 MSGFW_MMS_RECIPIENTS_TABLE_NAME, MSGFW_UNIQUENESS_INFO_TABLE_NAME};
1075 const char *tableList[] = {MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1076 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1077 MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1078 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1079 MSGFW_MMS_RECIPIENTS_TABLE_NAME};
1082 int listCnt = sizeof(tableList)/sizeof(char *);
1084 MsgDbHandler *dbHandle = getDbHandle();
1085 signed char folder_id;
1087 /* Get conversation ID from Folder */
1088 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1090 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE FOLDER_ID = %d",
1091 MSGFW_MESSAGE_TABLE_NAME, folderId);
1093 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1095 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1096 MSG_DEBUG("Fail to getTable().");
1097 dbHandle->freeTable();
1102 dbHandle->freeTable();
1106 for (int i = 1; i <= rowCnt; i++) {
1107 MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
1108 threadList.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1109 threadList2.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1112 dbHandle->freeTable();
1114 /*** Get msg id list **/
1115 msg_id_list_s *pToDeleteMsgIdList = NULL;
1116 pToDeleteMsgIdList = (msg_id_list_s *)new char[sizeof(msg_id_list_s)];
1117 if (pToDeleteMsgIdList == NULL) {
1118 MSG_DEBUG("pToDeleteMsgIdList is NULL.");
1119 return MSG_ERR_NULL_POINTER;
1121 memset(pToDeleteMsgIdList, 0x00, sizeof(msg_id_list_s));
1123 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1124 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d",
1125 MSGFW_MESSAGE_TABLE_NAME, folderId);
1130 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
1132 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1133 MSG_DEBUG("Fail to getTable().");
1134 dbHandle->freeTable();
1139 dbHandle->freeTable();
1145 pToDeleteMsgIdList->nCount = rowCnt;
1147 MSG_DEBUG("pToDeleteMsgIdList->nCount [%d]", pToDeleteMsgIdList->nCount);
1149 pToDeleteMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
1150 memset(pToDeleteMsgIdList->msgIdList, 0x00, sizeof(msg_message_id_t) * rowCnt);
1152 for (int i = 0; i < rowCnt; i++)
1153 pToDeleteMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
1155 dbHandle->freeTable();
1158 /*** Delete Sim Message In Folder **/
1159 folder_id = (signed char)folderId;
1160 if (folder_id >= MSG_INBOX_ID) {
1161 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1163 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d AND STORAGE_ID = %d",
1164 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_SIM);
1168 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1169 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1170 dbHandle->freeTable();
1174 for (int i = 1; i <= rowCnt; i++) {
1175 err = MsgStoDeleteMessage(dbHandle->getColumnToInt(i), false);
1177 if (err != MSG_SUCCESS) {
1178 MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
1180 dbHandle->freeTable();
1185 /*Delete phone log */
1186 /* MsgDeletePhoneLog(dbHandle->getColumnToInt(i)); */
1189 dbHandle->freeTable();
1192 dbHandle->beginTrans();
1194 for (int i = 0; i < listCnt; i++) {
1195 if (!strcmp(tableList[i], MMS_PLUGIN_MESSAGE_TABLE_NAME)) {
1198 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1199 char dirPath[MSG_FILEPATH_LEN_MAX] = {0, };
1200 /* remove multipart */
1201 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1202 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s;",
1203 MSGFW_MMS_MULTIPART_TABLE_NAME);
1205 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1206 dbHandle->endTrans(false);
1207 return MSG_ERR_DB_PREPARE;
1210 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1211 memset(filePath, 0x00, sizeof(filePath));
1212 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
1213 if (remove(filePath) == -1)
1214 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1216 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1218 dbHandle->finalizeQuery();
1220 /* Delete Data from Multipart table */
1221 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1222 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;",
1223 MSGFW_MMS_MULTIPART_TABLE_NAME);
1225 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1226 err = MSG_ERR_DB_EXEC;
1227 dbHandle->endTrans(false);
1231 /*get mms msg id list */
1232 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1233 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.FILE_PATH FROM %s A, %s B \
1234 WHERE A.FOLDER_ID = %d AND A.MAIN_TYPE = %d AND A.MSG_ID = B.MSG_ID",
1235 MSGFW_MESSAGE_TABLE_NAME, MMS_PLUGIN_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE);
1237 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1238 MSG_DEBUG("rowCnt %d", rowCnt);
1240 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1241 MSG_DEBUG("Fail to getTable().");
1243 dbHandle->freeTable();
1244 dbHandle->endTrans(false);
1249 for (int i = 1; i <= rowCnt; i++) {
1250 memset(filePath, 0x00, sizeof(filePath));
1251 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1253 MSG_SEC_DEBUG("filePath [%s]", filePath);
1255 /*delete raw file */
1256 snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
1258 if (remove(filePath) == -1)
1259 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1261 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1268 dbHandle->freeTable();
1271 /* delete thumbnail */
1272 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1273 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1274 snprintf(sqlQuery, sizeof(sqlQuery),
1275 "SELECT VALUE FROM %s "
1276 "WHERE (TYPE=%d OR TYPE=%d) "
1277 "AND (MSG_ID IN (SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d));",
1278 MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO, MSGFW_MESSAGE_TABLE_NAME, folderId);
1280 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1281 dbHandle->endTrans(false);
1282 return MSG_ERR_DB_PREPARE;
1285 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1286 memset(filePath, 0x00, sizeof(filePath));
1287 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
1288 if (remove(filePath) == -1)
1289 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1291 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1294 dbHandle->finalizeQuery();
1296 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1298 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN \
1299 (SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d);",
1300 tableList[i], MSGFW_MESSAGE_TABLE_NAME, folderId);
1302 /* Delete Message in specific folder from table */
1303 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1304 MSG_DEBUG("sqlQuery [%s]", sqlQuery);
1305 dbHandle->endTrans(false);
1306 err = MSG_ERR_DB_EXEC;
1312 /* Clear Conversation table */
1313 if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
1314 dbHandle->endTrans(false);
1315 err = MSG_ERR_DB_EXEC;
1320 /* Update Address */
1321 while (!threadList.empty()) {
1322 err = MsgStoUpdateConversation(dbHandle, threadList.front());
1326 if (err != MSG_SUCCESS) {
1327 dbHandle->endTrans(false);
1333 dbHandle->endTrans(true);
1335 /* Update Thread Callback */
1336 while (!threadList2.empty()) {
1337 msg_thread_id_t cur_thread_id = threadList2.front();
1338 if (MsgExistConversation(dbHandle, cur_thread_id) == true && MsgExistInThreadViewList(dbHandle, cur_thread_id) == true)
1339 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, cur_thread_id);
1341 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, cur_thread_id);
1346 /* Set pMsgIdList */
1347 if (pMsgIdList != NULL && pToDeleteMsgIdList->nCount > 0) {
1348 pMsgIdList->nCount = pToDeleteMsgIdList->nCount;
1350 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * pToDeleteMsgIdList->nCount];
1351 memset(pMsgIdList->msgIdList, 0x00, sizeof(msg_message_id_t) * pToDeleteMsgIdList->nCount);
1352 memcpy(pMsgIdList->msgIdList, pToDeleteMsgIdList->msgIdList, sizeof(msg_message_id_t) * pToDeleteMsgIdList->nCount);
1355 /* Create thread for noti and phone log delete. */
1357 if (pToDeleteMsgIdList->nCount > 0) {
1359 if (pToDeleteMsgIdList != NULL) {
1360 /*free peer info list */
1361 if (pToDeleteMsgIdList->msgIdList != NULL)
1362 delete [] pToDeleteMsgIdList->msgIdList;
1364 delete [] pToDeleteMsgIdList;
1367 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1374 MSG_DEBUG("Error case Free Memory");
1376 while (!threadList.empty()) {
1382 if (pToDeleteMsgIdList != NULL) {
1383 /*free peer info list */
1384 if (pToDeleteMsgIdList->msgIdList != NULL)
1385 delete [] pToDeleteMsgIdList->msgIdList;
1387 delete [] pToDeleteMsgIdList;
1394 msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
1400 msg_error_t err = MSG_SUCCESS;
1401 if (pMsgIdList->nCount < 1) {
1402 MSG_DEBUG("pMsgIdList->nCount < 1");
1406 char sqlQuery[MAX_QUERY_LEN+1];
1408 queue<msg_thread_id_t> threadList1, threadList2, threadList3;
1410 #ifdef FEATURE_SMS_CDMA
1411 const char *tableList[] = {MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1412 MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1413 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1414 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1415 MSGFW_SMS_REPORT_TABLE_NAME, MSGFW_MMS_MULTIPART_TABLE_NAME,
1416 MSGFW_MMS_RECIPIENTS_TABLE_NAME, MSGFW_UNIQUENESS_INFO_TABLE_NAME};
1418 const char *tableList[] = {MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1419 MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1420 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1421 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1422 MSGFW_SMS_REPORT_TABLE_NAME, MSGFW_MMS_MULTIPART_TABLE_NAME,
1423 MSGFW_MMS_RECIPIENTS_TABLE_NAME};
1426 int listCnt = sizeof(tableList)/sizeof(char *);
1428 MsgDbHandler *dbHandle = getDbHandle();
1430 dbHandle->beginTrans();
1431 /* reset msgid temp table */
1432 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1433 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_TMP_MSGID_TABLE_NAME);
1434 MSG_DEBUG("[%s]", sqlQuery);
1436 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1437 dbHandle->endTrans(false);
1438 return MSG_ERR_DB_EXEC;
1441 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
1442 dbHandle->finalizeQuery();
1443 dbHandle->endTrans(false);
1444 return MSG_ERR_DB_EXEC;
1447 dbHandle->finalizeQuery();
1449 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1450 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (?)", MSGFW_TMP_MSGID_TABLE_NAME);
1451 MSG_DEBUG("[%s]", sqlQuery);
1452 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1453 dbHandle->endTrans(false);
1454 return MSG_ERR_DB_PREPARE;
1457 for (int i = 0; i < pMsgIdList->nCount; i++) {
1458 dbHandle->resetQuery();
1459 dbHandle->bindInt(pMsgIdList->msgIdList[i], 1);
1460 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
1461 dbHandle->finalizeQuery();
1462 dbHandle->endTrans(false);
1463 return MSG_ERR_DB_EXEC;
1467 dbHandle->finalizeQuery();
1468 dbHandle->endTrans(true);
1470 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1471 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE MSG_ID IN %s;", MSGFW_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1473 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1475 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1476 MSG_DEBUG("Fail to getTable().");
1477 dbHandle->freeTable();
1481 MSG_DEBUG("rowCnt [%d]", rowCnt);
1484 dbHandle->freeTable();
1488 for (int i = 1; i <= rowCnt; i++) {
1489 MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
1490 threadList1.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1491 threadList2.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1492 threadList3.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1494 dbHandle->freeTable();
1496 /* delete report notification */
1497 char tempAddr[MAX_ADDRESS_VAL_LEN+1];
1498 bool isSentReadReportDeleted = false;
1499 while (!threadList1.empty()) {
1500 memset(tempAddr, 0x00, sizeof(tempAddr));
1501 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1502 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;"
1503 , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, threadList1.front());
1505 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1506 return MSG_ERR_DB_PREPARE;
1508 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
1509 dbHandle->finalizeQuery();
1510 return MSG_ERR_DB_DONE;
1513 snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
1515 MSG_SEC_DEBUG("Updated address = %s", tempAddr);
1517 MsgDeleteReportNotification(tempAddr);
1519 dbHandle->finalizeQuery();
1522 if (!isSentReadReportDeleted && !MsgIsSentReadReportNotificationExist(threadList1.front(), &msgId)) {
1523 //delete read report sent notification
1524 MsgDeleteSentReadReportNotification(msgId);
1525 isSentReadReportDeleted = true;
1532 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1533 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d AND MSG_ID IN %s;",
1534 MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, MSGFW_TMP_MSGID_TABLE_NAME);
1537 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1539 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1540 MSG_DEBUG("Fail to getTable().");
1541 dbHandle->freeTable();
1545 for (int i = 1; i <= rowCnt; i++) {
1546 err = MsgStoDeleteMessage(dbHandle->getColumnToInt(i), false);
1547 if (err != MSG_SUCCESS) {
1548 MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
1551 dbHandle->freeTable();
1553 dbHandle->beginTrans();
1554 for (int i = 0; i < listCnt; i++) {
1556 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1557 char dirPath[MSG_FILEPATH_LEN_MAX] = {0, };
1561 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1562 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN %s;", MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1564 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1566 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1567 MSG_DEBUG("Fail to getTable().");
1571 MSG_DEBUG("rowCnt %d", rowCnt);
1573 for (int i = 1; i <= rowCnt; i++) {
1574 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1576 MSG_SEC_DEBUG("filePath [%s]", filePath);
1578 /* Delete raw file. */
1579 snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
1581 if (remove(filePath) == -1)
1582 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1584 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1590 dbHandle->freeTable();
1592 } else if (i == 1) {
1593 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1597 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1598 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT VALUE FROM %s WHERE (TYPE = %d OR TYPE = %d) AND MSG_ID IN %s;",
1599 MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO, MSGFW_TMP_MSGID_TABLE_NAME);
1601 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1603 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1604 MSG_DEBUG("Fail to getTable().");
1608 MSG_DEBUG("rowCnt %d", rowCnt);
1610 for (int i = 1; i <= rowCnt; i++) {
1611 memset(filePath, 0x00, sizeof(filePath));
1612 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1613 if (remove(filePath) == -1)
1614 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1616 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1618 dbHandle->freeTable();
1619 } else if (!strcmp(tableList[i], MSGFW_MMS_MULTIPART_TABLE_NAME)) {
1620 /* MMS file path to delete. */
1621 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1625 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1626 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN %s;", MSGFW_MMS_MULTIPART_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1628 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1630 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1631 MSG_DEBUG("Fail to getTable().");
1635 MSG_DEBUG("rowCnt %d", rowCnt);
1637 for (int i = 1; i <= rowCnt; i++) {
1638 memset(filePath, 0x00, sizeof(filePath));
1639 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1640 if (filePath[0] != '\0') {
1641 if (remove(filePath) == -1)
1642 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1644 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1647 dbHandle->freeTable();
1649 /* MMS thumbnail path to delete */
1650 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1651 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);
1653 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1655 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1656 MSG_DEBUG("Fail to getTable().");
1660 MSG_DEBUG("rowCnt %d", rowCnt);
1662 for (int i = 1; i <= rowCnt; i++) {
1663 memset(filePath, 0x00, sizeof(filePath));
1664 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1665 if (filePath[0] != '\0') {
1666 if (remove(filePath) == -1)
1667 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1669 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1673 dbHandle->freeTable();
1676 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1677 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN %s;", tableList[i], MSGFW_TMP_MSGID_TABLE_NAME);
1679 /* Delete Message in specific folder from table */
1680 err = dbHandle->execQuery(sqlQuery);
1681 if (err != MSG_SUCCESS) {
1682 MSG_DEBUG("Fail to execQuery().");
1686 /* Clear Conversation table */
1687 err = MsgStoClearConversationTable(dbHandle);
1688 if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoClearConversationTable().");
1690 /* Update Address */
1691 while (!threadList2.empty()) {
1692 err = MsgStoUpdateConversation(dbHandle, threadList2.front());
1693 if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoUpdateConversation().");
1696 err = dbHandle->endTrans(true);
1697 if (err != MSG_SUCCESS) {
1698 MSG_DEBUG("Fail to endTrans(true).");
1699 dbHandle->endTrans(false);
1703 /* Update Thread Callback */
1704 while (!threadList3.empty()) {
1705 msg_thread_id_t cur_thread_id = threadList3.front();
1706 if (MsgExistConversation(dbHandle, cur_thread_id) == true && MsgExistInThreadViewList(dbHandle, cur_thread_id) == true)
1707 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, cur_thread_id);
1709 MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, cur_thread_id);
1714 if (g_idle_add(resetNotification, NULL) == 0) {
1715 MSG_DEBUG("resetNotification() Error");
1723 msg_error_t MsgStoMoveMessageToFolder(msg_message_id_t msgId, msg_folder_id_t destFolderId)
1725 msg_error_t err = MSG_SUCCESS;
1726 MSG_MESSAGE_TYPE_S msgType;
1727 msg_thread_id_t convId = 0;
1729 MsgStoGetMsgType(msgId, &msgType);
1731 char sqlQuery[MAX_QUERY_LEN+1];
1732 MsgDbHandler *dbHandle = getDbHandle();
1734 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1736 if (msgType.mainType == MSG_SMS_TYPE)
1737 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_ID = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, destFolderId, msgId);
1739 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_ID = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, destFolderId, msgId);
1741 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
1742 return MSG_ERR_DB_EXEC;
1744 /* get conversation id */
1745 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1747 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONV_ID FROM %s WHERE MSG_ID = %d;",
1748 MSGFW_MESSAGE_TABLE_NAME, msgId);
1750 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1751 return MSG_ERR_DB_PREPARE;
1753 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW)
1754 convId = dbHandle->columnInt(0);
1756 MSG_DEBUG("convId : %d", convId);
1758 dbHandle->finalizeQuery();
1760 /* update conversation table */
1761 err = MsgStoUpdateConversation(dbHandle, convId);
1763 /* update notification */
1764 signed char dest_folder_id = (signed char)destFolderId;
1765 if (dest_folder_id != MSG_SPAMBOX_ID)
1766 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1772 msg_error_t MsgStoMoveMessageToStorage(msg_message_id_t msgId, msg_storage_id_t destStorageId)
1776 msg_error_t err = MSG_SUCCESS;
1778 char sqlQuery[MAX_QUERY_LEN+1];
1779 MsgDbHandler *dbHandle = getDbHandle();
1781 MSG_DEBUG("msgId : %d, destStorageId : %d", msgId, destStorageId);
1783 switch (destStorageId) {
1784 case MSG_STORAGE_SIM : /* Move message to sim card */
1785 case MSG_STORAGE_SIM2 : {
1786 MSG_MESSAGE_INFO_S msgInfo;
1787 SMS_SIM_ID_LIST_S simIdList;
1789 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1790 memset(&simIdList, 0x00, sizeof(SMS_SIM_ID_LIST_S));
1792 if ((err = MsgStoGetMessage(msgId, &msgInfo, NULL)) != MSG_SUCCESS)
1795 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
1797 MSG_DEBUG("SMS Plug-in is NULL");
1798 return MSG_ERR_NULL_POINTER;
1801 if (destStorageId == MSG_STORAGE_SIM)
1802 msgInfo.sim_idx = 1;
1803 else if (destStorageId == MSG_STORAGE_SIM2)
1804 msgInfo.sim_idx = 2;
1806 if ((err = plg->saveSimMessage(&msgInfo, &simIdList)) != MSG_SUCCESS)
1809 dbHandle->beginTrans();
1811 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1812 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d, SIM_INDEX = %d WHERE MSG_ID = %d;",
1813 MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, msgInfo.sim_idx, msgId);
1814 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1816 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1817 dbHandle->endTrans(false);
1818 return MSG_ERR_DB_EXEC;
1821 for (unsigned int i = 0; i < simIdList.count; i++) {
1822 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1823 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
1824 MSGFW_SIM_MSG_TABLE_NAME, msgInfo.sim_idx, simIdList.simId[i], msgId);
1825 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1827 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1828 dbHandle->endTrans(false);
1829 return MSG_ERR_DB_EXEC;
1833 dbHandle->endTrans(true);
1837 default: { /* Moving message to memory (when destination storage id is MSG_STORAGE_PHONE) */
1838 #ifndef FEATURE_SMS_CDMA
1839 bool bSimMsg = false;
1842 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1843 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT STORAGE_ID FROM %s WHERE MSG_ID = %d;",
1844 MSGFW_MESSAGE_TABLE_NAME, msgId);
1846 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1848 if (err != MSG_SUCCESS) {
1849 MSG_DEBUG("Fail to getTable().");
1850 dbHandle->freeTable();
1854 if (dbHandle->getColumnToInt(1) == MSG_STORAGE_SIM) {
1855 MSG_DEBUG("It is SIM Message");
1859 dbHandle->freeTable();
1861 if (bSimMsg == true) {
1862 msg_sim_id_t simMsgId;
1863 msg_sim_slot_id_t sim_idx;
1865 /* get sim message id */
1866 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1868 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
1869 MSGFW_SIM_MSG_TABLE_NAME, msgId);
1873 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
1875 if (err != MSG_SUCCESS) {
1876 MSG_DEBUG("Fail to getTable().");
1877 dbHandle->freeTable();
1881 /* Delete messages in sim card */
1882 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
1884 MSG_DEBUG("SMS Plug-in is NULL");
1885 dbHandle->freeTable();
1886 return MSG_ERR_NULL_POINTER;
1889 for (int i = 0; i < rowCnt; i++) {
1890 sim_idx = dbHandle->getColumnToInt(index++);
1891 simMsgId = dbHandle->getColumnToInt(index++);
1893 MSG_DEBUG("simMsgId is %d.", simMsgId);
1895 if ((err = plg->deleteSimMessage(sim_idx, simMsgId)) != MSG_SUCCESS) {
1896 dbHandle->freeTable();
1901 dbHandle->freeTable();
1903 dbHandle->beginTrans();
1905 /* Delete Messages in SIM Msg table */
1906 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1907 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
1908 MSGFW_SIM_MSG_TABLE_NAME, msgId);
1909 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1911 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1912 dbHandle->endTrans(false);
1913 return MSG_ERR_DB_EXEC;
1916 /* Move storage id */
1917 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1918 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d WHERE MSG_ID = %d;",
1919 MSGFW_MESSAGE_TABLE_NAME, destStorageId, msgId);
1920 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1922 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1923 dbHandle->endTrans(false);
1924 return MSG_ERR_DB_EXEC;
1927 dbHandle->endTrans(true);
1938 msg_error_t MsgStoCountMessage(msg_folder_id_t folderId, MSG_COUNT_INFO_S *pCountInfo)
1940 if (pCountInfo == NULL) {
1941 MSG_DEBUG("pCountInfo is NULL");
1942 return MSG_ERR_NULL_POINTER;
1945 char sqlQuery[MAX_QUERY_LEN+1];
1946 MsgDbHandler *dbHandle = getDbHandle();
1948 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1949 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 1 AND STORAGE_ID = %d "
1950 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d "
1951 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND STORAGE_ID = %d "
1952 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND STORAGE_ID = %d;",
1953 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_PHONE,
1954 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_PHONE,
1955 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_SMS_TYPE, MSG_STORAGE_PHONE,
1956 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE, MSG_STORAGE_PHONE);
1958 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1959 return MSG_ERR_DB_PREPARE;
1961 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1962 pCountInfo->nReadCnt = dbHandle->columnInt(0);
1964 dbHandle->finalizeQuery();
1965 return MSG_ERR_DB_STEP;
1968 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1969 pCountInfo->nUnreadCnt = dbHandle->columnInt(0);
1971 dbHandle->finalizeQuery();
1972 return MSG_ERR_DB_STEP;
1975 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1976 pCountInfo->nSms = dbHandle->columnInt(0);
1978 dbHandle->finalizeQuery();
1979 return MSG_ERR_DB_STEP;
1982 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1983 pCountInfo->nMms = dbHandle->columnInt(0);
1985 dbHandle->finalizeQuery();
1986 return MSG_ERR_DB_STEP;
1989 dbHandle->finalizeQuery();
1995 msg_error_t MsgStoCountMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount)
1997 if (pMsgType == NULL) {
1998 MSG_DEBUG("pMsgType is NULL");
1999 return MSG_ERR_NULL_POINTER;
2004 char sqlQuery[MAX_QUERY_LEN+1];
2005 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2007 MsgDbHandler *dbHandle = getDbHandle();
2009 if ((pMsgType->mainType == MSG_SMS_TYPE) &&
2010 (pMsgType->subType == MSG_NORMAL_SMS || pMsgType->subType == MSG_STATUS_REPORT_SMS || pMsgType->subType == MSG_CONCAT_SIM_SMS)) {
2011 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d);",
2012 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_NORMAL_SMS, MSG_STATUS_REPORT_SMS, MSG_CONCAT_SIM_SMS);
2013 } else if ((pMsgType->mainType == MSG_SMS_TYPE) &&
2014 (pMsgType->subType == MSG_WAP_SI_SMS || pMsgType->subType == MSG_WAP_SL_SMS)) {
2016 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d);",
2017 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_WAP_SI_SMS, MSG_WAP_SL_SMS);
2018 } else if ((pMsgType->mainType == MSG_MMS_TYPE) &&
2019 (pMsgType->subType == MSG_SENDREQ_MMS || pMsgType->subType == MSG_SENDCONF_MMS || pMsgType->subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgType->subType == MSG_RETRIEVE_MANUALCONF_MMS)) {
2021 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d, %d);",
2022 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_SENDREQ_MMS, MSG_SENDCONF_MMS, MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS);
2024 return MSG_ERR_INVALID_PARAMETER;
2027 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2028 return MSG_ERR_DB_PREPARE;
2030 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2031 *pMsgCount = dbHandle->columnInt(0);
2033 dbHandle->finalizeQuery();
2034 return MSG_ERR_DB_STEP;
2037 dbHandle->finalizeQuery();
2043 msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
2045 char sqlQuery[MAX_QUERY_LEN+1];
2046 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2047 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, \
2048 SUB_TYPE, DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
2049 BACKUP, PRIORITY, MSG_DIRECTION, DPM_RESTRICTED, SCHEDULED_TIME, SUBJECT, MSG_TEXT, THUMB_PATH, SIM_INDEX \
2050 FROM %s WHERE MSG_ID = %d;",
2051 MSGFW_MESSAGE_TABLE_NAME, msgId);
2053 MsgDbHandler *dbHandle = getDbHandle();
2055 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2056 return MSG_ERR_DB_PREPARE;
2058 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2059 pMsg->msgId = dbHandle->columnInt(0);
2060 pMsg->threadId = dbHandle->columnInt(1);
2061 pMsg->folderId = dbHandle->columnInt(2);
2062 pMsg->storageId = dbHandle->columnInt(3);
2063 pMsg->msgType.mainType = dbHandle->columnInt(4);
2064 pMsg->msgType.subType = dbHandle->columnInt(5);
2065 pMsg->displayTime = (time_t)dbHandle->columnInt(6);
2066 pMsg->dataSize = dbHandle->columnInt(7);
2067 pMsg->networkStatus = dbHandle->columnInt(8);
2068 pMsg->bRead = dbHandle->columnInt(9);
2069 pMsg->bProtected = dbHandle->columnInt(10);
2070 pMsg->bBackup = dbHandle->columnInt(11);
2071 pMsg->priority = dbHandle->columnInt(12);
2072 pMsg->direction = dbHandle->columnInt(13);
2073 pMsg->bRestricted = dbHandle->columnInt(14);
2075 strncpy(pMsg->subject, (char *)dbHandle->columnText(16), MAX_SUBJECT_LEN);
2077 /* Temp_File_Handling */
2078 if (pMsg->msgType.mainType == MSG_SMS_TYPE || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
2079 if (pMsg->dataSize > MAX_MSG_TEXT_LEN) {
2080 char msgData[pMsg->dataSize+1];
2081 memset(msgData, 0x00, sizeof(msgData));
2083 strncpy(msgData, (char *)dbHandle->columnText(17), pMsg->dataSize);
2085 /* Save Message Data into File */
2086 char fileName[MSG_FILENAME_LEN_MAX+1];
2087 memset(fileName, 0x00, sizeof(fileName));
2089 if (MsgCreateFileName(fileName) == false) {
2090 dbHandle->finalizeQuery();
2091 return MSG_ERR_STORAGE_ERROR;
2094 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, fileName);
2096 if (MsgWriteIpcFile(fileName, msgData, pMsg->dataSize) == false) {
2097 dbHandle->finalizeQuery();
2098 return MSG_ERR_STORAGE_ERROR;
2101 strncpy(pMsg->msgData, fileName, MAX_MSG_DATA_LEN);
2103 pMsg->bTextSms = false;
2105 memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
2106 strncpy(pMsg->msgText, (char *)dbHandle->columnText(17), pMsg->dataSize);
2108 /* For WAP PUSH SI Message */
2109 if (pMsg->msgType.subType == MSG_WAP_SI_SMS) {
2110 strncat(pMsg->msgText, "\n", MAX_MSG_TEXT_LEN-strlen(pMsg->msgText));
2111 strncat(pMsg->msgText, pMsg->subject, MAX_MSG_TEXT_LEN-strlen(pMsg->msgText));
2112 MSG_SEC_DEBUG("pMsg->msgText : [%s]", pMsg->msgText);
2113 pMsg->dataSize = sizeof(pMsg->msgText);
2116 pMsg->bTextSms = true;
2119 if (dbHandle->columnText(16) != NULL)
2120 strncpy(pMsg->msgText, (char *)dbHandle->columnText(17), MAX_MSG_TEXT_LEN);
2123 /* thumbnail path */
2124 if (dbHandle->columnText(18)!= NULL && ((char *)dbHandle->columnText(18))[0] != '\0') {
2125 strncpy(pMsg->thumbPath, (char *)dbHandle->columnText(18), MSG_FILEPATH_LEN_MAX);
2126 MSG_DEBUG("pMsg->thumbPath : [%s]", pMsg->thumbPath);
2129 if (pMsg->bRestricted == true) {
2131 memset(pMsg->msgData, 0x00, sizeof(pMsg->msgData));
2132 memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
2133 memset(pMsg->subject, 0x00, sizeof(pMsg->subject));
2134 memset(pMsg->thumbPath, 0x00, sizeof(pMsg->thumbPath));
2137 pMsg->sim_idx = dbHandle->columnInt(19);
2139 dbHandle->finalizeQuery();
2140 MSG_DEBUG("%s", sqlQuery);
2141 return MSG_ERR_DB_STEP;
2144 dbHandle->finalizeQuery();
2146 /* Get MMS body if it is MMS. */
2147 if ((pMsg->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS &&
2148 (pMsg->msgType.subType == MSG_RETRIEVE_MMS || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS)) ||
2149 pMsg->msgType.subType == MSG_SENDREQ_MMS || pMsg->msgType.subType == MSG_SENDCONF_MMS || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
2150 msg_error_t err = MSG_SUCCESS;
2151 char *pDestMsg = NULL;
2152 int temp_size = pMsg->dataSize; /* save raw file size; */
2154 /* call mms plugin to get mms specific message data */
2155 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(pMsg->msgType.mainType);
2157 MSG_DEBUG("SMS Plug-in is NULL");
2158 return MSG_ERR_NULL_POINTER;
2161 err = plg->getMmsMessage(pMsg, pSendOptInfo, &pDestMsg);
2162 if (err != MSG_SUCCESS) {
2167 return MSG_ERR_STORAGE_ERROR;
2170 memset(pMsg->msgData, 0, MAX_MSG_DATA_LEN+1);
2172 /* Encode MMS specific data to MMS_MESSAGE_DATA_S */
2173 if (pMsg->dataSize > MAX_MSG_DATA_LEN) {
2174 /* Save Message Data into File */
2175 char tempFileName[MSG_FILENAME_LEN_MAX+1];
2176 memset(tempFileName, 0x00, sizeof(tempFileName));
2178 if (MsgCreateFileName(tempFileName) == false) {
2183 return MSG_ERR_STORAGE_ERROR;
2185 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, tempFileName);
2187 if (MsgWriteIpcFile(tempFileName, pDestMsg, pMsg->dataSize) == false) {
2192 return MSG_ERR_STORAGE_ERROR;
2194 strncpy(pMsg->msgData, tempFileName, MAX_MSG_DATA_LEN);
2195 pMsg->bTextSms = false;
2197 strncpy(pMsg->msgData, pDestMsg, pMsg->dataSize);
2198 pMsg->bTextSms = true;
2201 pMsg->dataSize = temp_size; /*raw file size; */
2207 /* get recipients information. */
2208 MsgStoGetRecipientsByMsgId(dbHandle, pMsg->msgId, &pMsg->nAddressCnt, &pMsg->addressList);
2211 /* get address information. */
2212 MsgStoGetAddressByMsgId(dbHandle, pMsg->msgId, &pMsg->nAddressCnt, &pMsg->addressList);
2215 /* Get SMS Sending Options */
2216 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL)
2217 MsgStoGetSmsSendOpt(pMsg, pSendOptInfo);
2222 msg_error_t MsgStoGetFailedMessage(int **failed_msg_list, int *count)
2226 msg_error_t err = MSG_SUCCESS;
2227 char sqlQuery[MAX_QUERY_LEN+1];
2228 int rowCnt = 0, index = 0;
2229 MsgDbHandler *dbHandle = getDbHandle();
2231 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2233 /* Folder ID == 2 : sending failed message, Folder ID == 1 : retrieve failed message */
2234 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);",
2235 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_PENDING, MSG_NETWORK_RETRIEVE_PENDING, MSG_OUTBOX_ID, MSG_INBOX_ID);
2236 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2238 if(err == MSG_ERR_DB_NORECORD) {
2239 dbHandle->freeTable();
2243 int *list = new int[rowCnt];
2245 for(int i = 0; i < rowCnt; ++i) {
2246 list[i] = dbHandle->getColumnToInt(index++);
2248 *failed_msg_list = list;
2249 dbHandle->freeTable();
2255 msg_error_t MsgStoAddSyncMLMessage(MSG_MESSAGE_INFO_S *pMsgInfo, int extId, int pinCode)
2259 msg_error_t err = MSG_SUCCESS;
2261 char sqlQuery[MAX_QUERY_LEN+1];
2263 unsigned int rowId = 0;
2264 msg_thread_id_t convId = 0;
2265 MsgDbHandler *dbHandle = getDbHandle();
2267 dbHandle->beginTrans();
2269 if (pMsgInfo->nAddressCnt > 0) {
2270 err = MsgStoAddAddress(dbHandle, pMsgInfo, &convId);
2272 if (err != MSG_SUCCESS) {
2273 dbHandle->endTrans(false);
2278 /* Add Message Table */
2279 pMsgInfo->threadId = convId;
2280 rowId = MsgStoAddMessageTable(dbHandle, pMsgInfo);
2283 dbHandle->endTrans(false);
2284 return MSG_ERR_DB_ROW;
2287 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2288 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
2289 MSGFW_SYNCML_MSG_TABLE_NAME, rowId, extId, pinCode);
2291 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
2292 dbHandle->endTrans(false);
2293 return MSG_ERR_DB_EXEC;
2296 if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
2297 dbHandle->endTrans(false);
2298 return MSG_ERR_STORAGE_ERROR;
2301 dbHandle->endTrans(true);
2303 pMsgInfo->msgId = (msg_message_id_t)rowId;
2305 MsgInsertNotification(pMsgInfo);
2314 msg_error_t MsgStoGetMsgType(msg_message_id_t msgId, MSG_MESSAGE_TYPE_S *pMsgType)
2316 MsgDbHandler *dbHandle = getDbHandle();
2317 char sqlQuery[MAX_QUERY_LEN+1];
2319 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2321 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE FROM %s WHERE MSG_ID = %d;",
2322 MSGFW_MESSAGE_TABLE_NAME, msgId);
2324 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2325 return MSG_ERR_DB_PREPARE;
2327 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2328 pMsgType->mainType = dbHandle->columnInt(0);
2329 pMsgType->subType = dbHandle->columnInt(1);
2332 dbHandle->finalizeQuery();
2338 msg_error_t MsgStoGetQuickPanelData(msg_quickpanel_type_t QPtype, MSG_MESSAGE_INFO_S *pMsg)
2340 msg_error_t err = MSG_SUCCESS;
2342 MsgDbHandler *dbHandle = getDbHandle();
2343 char sqlQuery[MAX_QUERY_LEN+1];
2345 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2347 if (QPtype == MSG_QUICKPANEL_SMS) {
2348 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;",
2349 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_SMS_TYPE, MSG_NORMAL_SMS);
2350 } else if (QPtype == MSG_QUICKPANEL_MMS) {
2351 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;",
2352 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_MMS_TYPE, MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS);
2353 } else if (QPtype == MSG_QUICKPANEL_DELIVER_REP) {
2354 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE SUB_TYPE IN (%d, %d) AND READ_STATUS = 0 ORDER BY DISPLAY_TIME DESC;",
2355 MSGFW_MESSAGE_TABLE_NAME, MSG_STATUS_REPORT_SMS, MSG_DELIVERYIND_MMS);
2356 } else if (QPtype == MSG_QUICKPANEL_READ_REP) {
2357 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;",
2358 MSGFW_MESSAGE_TABLE_NAME, MSG_MMS_TYPE, MSG_READORGIND_MMS);
2359 } else if (QPtype == MSG_QUICKPANEL_VOICEMAIL) {
2360 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;",
2361 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MWI_VOICE_SMS);
2362 } else if (QPtype == MSG_QUICKPANEL_MMS_NOTI) {
2363 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;",
2364 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_MMS_TYPE, MSG_NOTIFICATIONIND_MMS);
2367 /* Get Message ID */
2368 msg_message_id_t msgId;
2370 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2371 return MSG_ERR_DB_PREPARE;
2373 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2374 msgId = dbHandle->columnInt(0);
2376 dbHandle->finalizeQuery();
2377 return MSG_ERR_DB_STEP;
2380 dbHandle->finalizeQuery();
2382 /* Get Message Info */
2383 err = MsgStoGetMessage(msgId, pMsg, NULL);
2389 msg_error_t MsgStoDeleteThreadMessageList(msg_thread_id_t threadId, bool bIncludeProtect, msg_id_list_s *pMsgIdList)
2391 msg_error_t err = MSG_SUCCESS;
2393 MsgDbHandler *dbHandle = getDbHandle();
2394 char sqlQuery[MAX_QUERY_LEN+1];
2396 /*** Get msg id list **/
2397 int rowCnt = 0, index = 0;
2399 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2401 #ifdef MSG_NOTI_INTEGRATION
2402 if (bIncludeProtect) {
2403 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2404 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
2405 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
2407 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2408 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0;",
2409 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
2412 if (bIncludeProtect) {
2413 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2414 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
2415 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
2417 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2418 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0;",
2419 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
2423 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2425 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
2426 MSG_ERR("Fail to getTable().");
2427 dbHandle->freeTable();
2432 dbHandle->freeTable();
2434 err = MsgStoClearConversationTable(dbHandle);
2435 if (err != MSG_SUCCESS) {
2436 MSG_ERR("Fail to MsgStoClearConversationTable().");
2440 err = MsgStoUpdateConversation(dbHandle, threadId);
2441 if (err != MSG_SUCCESS) {
2442 MSG_ERR("Fail to MsgStoUpdateConversation().");
2449 pMsgIdList->nCount = rowCnt;
2451 MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
2453 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
2455 for (int i = 0; i < rowCnt; i++)
2456 pMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
2458 dbHandle->freeTable();
2461 err = MsgStoDeleteMessageByList(pMsgIdList);
2462 if (err != MSG_SUCCESS) {
2463 MSG_ERR("Fail to MsgStoDeleteMessageByList().");
2471 msg_error_t MsgStoSetTempAddressTable(MSG_ADDRESS_INFO_S *pAddrInfo, int addr_cnt)
2473 MsgDbHandler *dbHandle = getDbHandle();
2474 char sqlQuery[MAX_QUERY_LEN+1];
2476 dbHandle->beginTrans();
2477 /* reset address temp table */
2478 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2479 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_ADDRESS_TEMP_TABLE_NAME);
2480 MSG_DEBUG("[%s]", sqlQuery);
2482 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2483 return MSG_ERR_DB_EXEC;
2485 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2486 dbHandle->finalizeQuery();
2487 dbHandle->endTrans(false);
2488 return MSG_ERR_DB_EXEC;
2491 dbHandle->finalizeQuery();
2493 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2494 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (?);", MSGFW_ADDRESS_TEMP_TABLE_NAME);
2495 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
2496 dbHandle->endTrans(false);
2497 return MSG_ERR_DB_PREPARE;
2500 char newPhoneNum[MAX_ADDRESS_VAL_LEN+1];
2501 char tmpNum[MAX_ADDRESS_VAL_LEN+1];
2502 for (int i = 0; i < addr_cnt; i++) {
2503 memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
2504 memset(tmpNum, 0x00, sizeof(tmpNum));
2505 MsgConvertNumber(pAddrInfo[i].addressVal, tmpNum, sizeof(tmpNum));
2506 snprintf(newPhoneNum, sizeof(newPhoneNum), "%%%%%s", tmpNum);
2507 dbHandle->resetQuery();
2508 dbHandle->bindText(newPhoneNum, 1);
2509 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2510 dbHandle->finalizeQuery();
2511 dbHandle->endTrans(false);
2512 return MSG_ERR_DB_EXEC;
2516 dbHandle->finalizeQuery();
2517 dbHandle->endTrans(true);
2523 msg_error_t MsgStoCountMsgByContact(const MSG_THREAD_LIST_INDEX_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pThreadCountInfo)
2525 MsgDbHandler *dbHandle = getDbHandle();
2526 char sqlQuery[MAX_QUERY_LEN+1];
2528 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2530 if (pAddrInfo->contactId > 0) {
2531 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) AS TOTAL, "
2532 "SUM(CASE WHEN READ_STATUS = 0 AND FOLDER_ID = %d THEN 1 ELSE 0 END), "
2533 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END), "
2534 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END) "
2535 "FROM (SELECT * FROM %s A JOIN %s B ON A.CONV_ID = B.CONV_ID WHERE B.CONTACT_ID = %d)",
2536 MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MMS_TYPE, MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pAddrInfo->contactId);
2538 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) AS TOTAL, "
2539 "SUM(CASE WHEN READ_STATUS = 0 AND FOLDER_ID = %d THEN 1 ELSE 0 END), "
2540 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END), "
2541 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END) "
2542 "FROM (SELECT * FROM %s A JOIN %s B ON A.CONV_ID = B.CONV_ID WHERE B.ADDRESS_VAL = '%s')",
2543 MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MMS_TYPE, MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pAddrInfo->msgAddrInfo.addressVal);
2546 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2547 return MSG_ERR_DB_PREPARE;
2549 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2550 pThreadCountInfo->totalCount = dbHandle->columnInt(0);
2551 pThreadCountInfo->unReadCount = dbHandle->columnInt(1);
2552 pThreadCountInfo->smsMsgCount = dbHandle->columnInt(2);
2553 pThreadCountInfo->mmsMsgCount = dbHandle->columnInt(3);
2555 dbHandle->finalizeQuery();
2556 return MSG_ERR_DB_STEP;
2559 dbHandle->finalizeQuery();
2565 msg_error_t MsgStoGetSyncMLExtId(msg_message_id_t msgId, int *extId)
2567 MsgDbHandler *dbHandle = getDbHandle();
2568 char sqlQuery[MAX_QUERY_LEN+1];
2570 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2572 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXT_ID FROM %s WHERE MSG_ID = %d;",
2573 MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
2575 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2576 return MSG_ERR_DB_PREPARE;
2578 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2579 *extId = dbHandle->columnInt(0);
2581 dbHandle->finalizeQuery();
2582 return MSG_ERR_DB_STEP;
2585 dbHandle->finalizeQuery();
2591 msg_error_t MsgStoGetSmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
2593 MsgDbHandler *dbHandle = getDbHandle();
2594 char sqlQuery[MAX_QUERY_LEN+1];
2595 msg_error_t err = MSG_SUCCESS;
2597 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2598 snprintf(sqlQuery, sizeof(sqlQuery),
2599 "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
2601 "WHERE MSG_ID = %d "
2602 "order by TIME ASC;"
2603 , MSGFW_SMS_REPORT_TABLE_NAME, msgId);
2605 int rowCnt = 0, index = 0;
2606 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2608 if (err != MSG_SUCCESS) {
2609 MSG_DEBUG("Fail to getTable().");
2610 dbHandle->freeTable();
2611 if (err == MSG_ERR_DB_NORECORD)
2617 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
2618 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
2620 for (int i = 0; i < rowCnt; i++) {
2621 dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
2622 report_status[i].type = dbHandle->getColumnToInt(index++);
2623 report_status[i].status = dbHandle->getColumnToInt(index++);
2624 report_status[i].statusTime = (time_t)dbHandle->getColumnToInt(index++);
2626 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);
2629 *pReportStatus = report_status;
2631 dbHandle->freeTable();
2636 msg_error_t MsgStoGetMmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
2638 MsgDbHandler *dbHandle = getDbHandle();
2639 char sqlQuery[MAX_QUERY_LEN+1];
2641 msg_direction_type_t direction = MSG_DIRECTION_TYPE_MO;
2643 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_DIRECTION FROM %s WHERE MSG_ID = %d;",
2644 MSGFW_MESSAGE_TABLE_NAME, msgId);
2646 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2647 return MSG_ERR_DB_PREPARE;
2649 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2650 direction = dbHandle->columnInt(0);
2653 dbHandle->finalizeQuery();
2655 if (direction == MSG_DIRECTION_TYPE_MO) {/*get received report list of MO message */
2656 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2657 /*MSG_ID INTEGER , ADDRESS_VAL TEXT , STATUS_TYPE INTEGER , STATUS INTEGER DEFAULT 0 , TIME DATETIME) */
2658 /*select * from MSG_REPORT_TABLE where MSG_ID=38 order by ADDRESS_VAL DESC, STATUS_TYPE ASC; */
2659 snprintf(sqlQuery, sizeof(sqlQuery),
2660 "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
2662 "WHERE MSG_ID = %d "
2663 "order by ADDRESS_VAL DESC, STATUS_TYPE ASC;"
2664 , MSGFW_REPORT_TABLE_NAME, msgId);
2666 int rowCnt = 0, index = 0;
2667 msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2668 if (err != MSG_SUCCESS) {
2669 MSG_DEBUG("Fail to getTable().");
2670 dbHandle->freeTable();
2671 if (err == MSG_ERR_DB_NORECORD)
2677 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
2678 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
2680 for (int i = 0; i < rowCnt; i++) {
2681 dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
2682 report_status[i].type = dbHandle->getColumnToInt(index++);
2683 report_status[i].status = dbHandle->getColumnToInt(index++);
2684 report_status[i].statusTime = (time_t)dbHandle->getColumnToInt(index++);
2686 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);
2689 *pReportStatus = report_status;
2691 dbHandle->freeTable();
2693 } else if (direction == MSG_DIRECTION_TYPE_MT) { /*read report sent status of MT message */
2694 int readReportSentStatus;
2696 if (MsgStoCheckReadReportRequested(dbHandle, msgId) == false) {
2698 *pReportStatus = NULL;
2699 return MSG_ERR_READREPORT_NOT_REQUESTED;
2702 MsgStoGetReadReportSendStatus(msgId, &readReportSentStatus);
2706 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)];
2707 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
2709 report_status->addressVal[0] = '\0';
2710 report_status->type = MSG_REPORT_TYPE_READ_REPORT_SENT;
2711 report_status->status = readReportSentStatus;
2712 report_status->statusTime = 0;
2714 MSG_DEBUG("report_type = %d, report_status = %d", report_status->type, report_status->status);
2716 *pReportStatus = report_status;
2723 msg_error_t MsgStoGetThreadIdByAddress(const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t *pThreadId)
2725 MsgDbHandler *dbHandle = getDbHandle();
2726 if(pMsg->nAddressCnt > 0) {
2727 if (MsgExistAddress(dbHandle, pMsg, pThreadId) == true) {
2728 MSG_DEBUG("Conversation ID : [%d]", *pThreadId);
2730 /* check thread count */
2731 MSG_THREAD_VIEW_S threadInfo;
2732 memset(&threadInfo, 0x00, sizeof(MSG_THREAD_VIEW_S));
2733 MsgStoGetThreadInfo(*pThreadId, &threadInfo);
2734 MSG_DEBUG("threadInfo.smsCnt [%d], threadInfo.mmsCnt [%d]", threadInfo.smsCnt, threadInfo.mmsCnt);
2735 if ((threadInfo.smsCnt + threadInfo.mmsCnt) > 0) {
2746 msg_error_t MsgStoGetThreadUnreadCnt(msg_thread_id_t threadId, int *cnt)
2750 MsgDbHandler *dbHandle = getDbHandle();
2754 char sqlQuery[MAX_QUERY_LEN+1];
2757 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2758 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s A \
2759 WHERE CONV_ID = %d AND READ_STATUS = 0;", MSGFW_MESSAGE_TABLE_NAME, threadId);
2761 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2762 return MSG_ERR_DB_PREPARE;
2764 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2765 msgCnt = dbHandle->columnInt(0);
2768 dbHandle->finalizeQuery();
2778 msg_error_t MsgStoGetThreadInfo(msg_thread_id_t threadId, MSG_THREAD_VIEW_S *pThreadInfo)
2782 MsgDbHandler *dbHandle = getDbHandle();
2783 int rowCnt = 0, index = 0;
2785 char sqlQuery[MAX_QUERY_LEN+1];
2786 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2788 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.UNREAD_CNT, A.SMS_CNT, A.MMS_CNT, "
2789 "A.MAIN_TYPE, A.SUB_TYPE, A.MSG_DIRECTION, A.DISPLAY_TIME, A.DISPLAY_NAME, A.MSG_TEXT, "
2790 "(COUNT(CASE WHEN M.PROTECTED = 1 THEN 1 END)) AS PROTECTED, "
2791 "(CASE WHEN B.FOLDER_ID = %d THEN 1 END) AS DRAFT, "
2792 "(CASE WHEN B.NETWORK_STATUS = %d THEN 1 END) AS FAILED, "
2793 "(CASE WHEN B.NETWORK_STATUS = %d THEN 1 END) AS SENDING "
2795 "LEFT OUTER JOIN %s B ON A.LAST_MSG_ID = B.MSG_ID "
2796 "LEFT OUTER JOIN %s M ON A.CONV_ID = M.CONV_ID "
2797 "WHERE A.CONV_ID = %d AND A.SMS_CNT + A.MMS_CNT > 0;",
2799 MSG_NETWORK_SEND_FAIL,
2800 MSG_NETWORK_SENDING,
2801 MSGFW_CONVERSATION_TABLE_NAME,
2802 MSGFW_MESSAGE_TABLE_NAME,
2803 MSGFW_MESSAGE_TABLE_NAME,
2806 msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2808 if (err == MSG_ERR_DB_NORECORD) {
2809 dbHandle->freeTable();
2811 } else if (err != MSG_SUCCESS) {
2812 MSG_DEBUG("Fail to getTable().");
2813 dbHandle->freeTable();
2818 MSG_DEBUG("rowCnt is %d", rowCnt);
2819 dbHandle->freeTable();
2822 pThreadInfo->threadId = dbHandle->getColumnToInt(index++);
2824 pThreadInfo->unreadCnt = dbHandle->getColumnToInt(index++);
2825 pThreadInfo->smsCnt = dbHandle->getColumnToInt(index++);
2826 pThreadInfo->mmsCnt = dbHandle->getColumnToInt(index++);
2828 pThreadInfo->mainType = dbHandle->getColumnToInt(index++);
2829 pThreadInfo->subType = dbHandle->getColumnToInt(index++);
2831 pThreadInfo->direction = dbHandle->getColumnToInt(index++);
2832 pThreadInfo->threadTime = (time_t)dbHandle->getColumnToInt(index++);
2834 memset(pThreadInfo->threadName, 0x00, sizeof(pThreadInfo->threadName));
2835 dbHandle->getColumnToString(index++, MAX_THREAD_NAME_LEN, pThreadInfo->threadName);
2837 memset(pThreadInfo->threadData, 0x00, sizeof(pThreadInfo->threadData));
2838 dbHandle->getColumnToString(index++, MAX_THREAD_DATA_LEN, pThreadInfo->threadData);
2840 pThreadInfo->bProtected = (dbHandle->getColumnToInt(index++) > 0) ? true : false;
2841 pThreadInfo->bDraft = dbHandle->getColumnToInt(index++);
2842 pThreadInfo->bSendFailed = dbHandle->getColumnToInt(index++);
2843 pThreadInfo->bSending = dbHandle->getColumnToInt(index++);
2846 dbHandle->freeTable();
2854 msg_error_t MsgStoRestoreMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
2858 MsgDbHandler *dbHandle = getDbHandle();
2859 msg_error_t err = MSG_SUCCESS;
2860 char sqlQuery[MAX_QUERY_LEN+1];
2862 if(MsgExistConversation(dbHandle, pMsg->threadId)) {
2863 /* add message to address table which having same thread_id and datetime; */
2864 for (int i = 0; i < pMsg->nAddressCnt; i++) {
2865 if(MsgExistAddress(dbHandle, pMsg, pMsg->threadId, i) == false) {
2866 unsigned int addrId;
2867 MSG_CONTACT_INFO_S contactInfo;
2868 memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
2870 /* Get Contact Info */
2871 /* if (MsgGetContactInfo(&(pMsg->addressList[i]), &contactInfo) != MSG_SUCCESS) { */
2872 /* MSG_DEBUG("MsgGetContactInfo() fail."); */
2874 err = dbHandle->getRowId(MSGFW_ADDRESS_TABLE_NAME, &addrId);
2875 if (err != MSG_SUCCESS) {
2876 MSG_DEBUG("pDbHandle->getRowId fail. [%d]", err);
2881 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2882 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, '%s', %d, %d, ?, ?, ?, ?, ?, '%s', 0);",
2883 MSGFW_ADDRESS_TABLE_NAME, addrId, pMsg->threadId, pMsg->addressList[i].addressType, pMsg->addressList[i].recipientType, pMsg->addressList[i].addressVal,
2884 contactInfo.contactId, contactInfo.addrbookId, contactInfo.imagePath);
2886 MSG_SEC_DEBUG("Add Address Info. [%s]", sqlQuery);
2888 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2889 return MSG_ERR_DB_PREPARE;
2891 dbHandle->bindText(contactInfo.firstName, 1);
2892 dbHandle->bindText(contactInfo.lastName, 2);
2893 dbHandle->bindText(contactInfo.middleName, 3);
2894 dbHandle->bindText(contactInfo.prefix, 4);
2895 dbHandle->bindText(contactInfo.suffix, 5);
2897 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2898 dbHandle->finalizeQuery();
2899 return MSG_ERR_DB_STEP;
2902 dbHandle->finalizeQuery();
2904 /* set conversation display name by conv id */
2905 MsgStoSetConversationDisplayName(dbHandle, pMsg->threadId);
2910 if(!MsgExistMessage(dbHandle, pMsg)) {
2911 unsigned int rowId = 0;
2913 if (pMsg->threadId > 0 && pMsg->folderId == MSG_DRAFT_ID) {
2914 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2916 snprintf(sqlQuery, sizeof(sqlQuery),
2917 "DELETE FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d;",
2918 MSGFW_MESSAGE_TABLE_NAME, pMsg->threadId, MSG_DRAFT_ID);
2920 MSG_DEBUG("sqlQuery [%s]", sqlQuery);
2922 err = dbHandle->execQuery(sqlQuery);
2924 if (err != MSG_SUCCESS) {
2925 MSG_DEBUG("fail to delete draft messages.");
2929 err = dbHandle->getRowId(MSGFW_MESSAGE_TABLE_NAME, &rowId);
2931 pMsg->msgId = (msg_message_id_t)rowId;
2935 char *pFileData = NULL;
2936 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
2939 if (pMsg->bTextSms == false) {
2940 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
2941 return MSG_ERR_STORAGE_ERROR;
2943 MSG_DEBUG("file size [%d]", fileSize);
2946 char keyName[MAX_VCONFKEY_NAME_LEN];
2947 memset(keyName, 0x00, sizeof(keyName));
2948 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, pMsg->sim_idx);
2951 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
2952 MSG_INFO("MsgSettingGetString() is failed");
2956 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2958 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %lu, %zu, %d, %d, %d, %d, %d, 0, %d, ?, '', '', ?, 0, %d, '%s');",
2959 MSGFW_MESSAGE_TABLE_NAME, rowId, pMsg->threadId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType,
2960 pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
2961 pMsg->bBackup, pMsg->sim_idx, imsi);
2964 MSG_DEBUG("QUERY : %s", sqlQuery);
2971 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
2972 return MSG_ERR_DB_EXEC;
2975 dbHandle->bindText(pMsg->subject, 1);
2977 if (pMsg->bTextSms == false)
2978 dbHandle->bindText(pFileData, 2);
2980 dbHandle->bindText(pMsg->msgText, 2);
2982 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2983 dbHandle->finalizeQuery();
2984 return MSG_ERR_DB_EXEC;
2987 dbHandle->finalizeQuery();
2989 if (pMsg->msgType.subType != MSG_SENDREQ_MMS) {
2990 err = MsgStoUpdateConversation(dbHandle, pMsg->threadId);
2992 if (err != MSG_SUCCESS) {
2997 /* In the case of MMS Message, load the MMS plugin to save MMS PDU */
2998 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
2999 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
3000 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
3002 return MSG_ERR_NULL_POINTER;
3004 err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
3006 if (err != MSG_SUCCESS)
3007 return MSG_ERR_STORAGE_ERROR;
3009 if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
3010 MSG_SEC_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
3012 err = MsgStoUpdateMMSMessage(pMsg);
3014 if (err != MSG_SUCCESS)
3015 return MSG_ERR_STORAGE_ERROR;
3021 /* add message to conversation, message, address table; */
3023 err = MsgStoAddMessage(pMsg, pSendOptInfo);
3032 msg_message_id_t MsgStoAddSimMessage(MSG_MESSAGE_INFO_S *pMsg, int *simIdList, int listSize)
3035 MsgDbHandler *dbHandle = getDbHandle();
3036 if (pMsg == NULL || pMsg->msgType.mainType == MSG_MMS_TYPE) {
3037 MSG_DEBUG("pMsg == NULL || pMsg->msgType.mainType == MSG_MMS_TYPE");
3041 if ((pMsg->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsg->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
3042 if (pMsg->msgId > 0) {
3043 pMsg->bRead = false;
3044 if (MsgStoUpdateMessage(pMsg, NULL) != MSG_SUCCESS) {
3045 MSG_DEBUG("MsgStoUpdateMessage is failed!!!");
3048 if (MsgStoAddMessage(pMsg, NULL) != MSG_SUCCESS) {
3049 MSG_DEBUG("MsgStoAddMessage is failed!!!");
3054 if (MsgStoAddMessage(pMsg, NULL) != MSG_SUCCESS) {
3055 MSG_DEBUG("MsgStoAddMessage is failed!!!");
3060 dbHandle->beginTrans();
3062 MSG_DEBUG("simIdList exist.");
3064 for(int i = 0; i < listSize; ++i) {
3066 simId = simIdList[i] - 1;
3067 char sqlQuery[MAX_QUERY_LEN+1];
3068 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3069 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
3070 MSGFW_SIM_MSG_TABLE_NAME, pMsg->sim_idx, simId, pMsg->msgId);
3072 MSG_DEBUG("QUERY : %s", sqlQuery);
3074 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
3075 dbHandle->endTrans(false);
3083 dbHandle->endTrans(true);
3091 #ifdef FEATURE_SMS_CDMA
3092 msg_error_t MsgCheckUniqueness(bool bInsert, msg_message_id_t msgId, MSG_UNIQUE_INDEX_S *p_msg)
3096 MsgDbHandler *dbHandle = getDbHandle();
3099 char sqlQuery[MAX_QUERY_LEN+1];
3102 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3103 dbHandle->beginTrans();
3105 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;",
3106 MSGFW_UNIQUENESS_INFO_TABLE_NAME, p_msg->tele_msgId, p_msg->address, p_msg->sub_address, p_msg->time_stamp, p_msg->telesvc_id);
3108 dbHandle->getTable(sqlQuery, &nRowCnt, NULL);
3109 MSG_DEBUG("nRowCnt = [%d]", nRowCnt);
3111 dbHandle->freeTable();
3112 dbHandle->endTrans(true);
3115 MSG_DEBUG("<<<<This incoming message is a new message>>>>");
3118 MSG_DEBUG("<<<<This incoming message is a repeated message>>>>");
3119 return MSG_ERR_UNKNOWN;
3122 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3123 dbHandle->beginTrans();
3125 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, '%s', '%s', '%s', %d);",
3126 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);
3128 dbHandle->execQuery(sqlQuery);
3129 dbHandle->endTrans(true);
3138 msg_error_t MsgStoUpdateIMSI(int sim_idx)
3141 MSG_DEBUG("sim_idx = %d", sim_idx);
3143 /* msg_error_t err = MSG_SUCCESS; */
3144 MsgDbHandler *dbHandle = getDbHandle();
3146 char sqlQuery[MAX_QUERY_LEN+1];
3147 char keyName[MAX_VCONFKEY_NAME_LEN];
3149 dbHandle->beginTrans();
3152 MSG_DEBUG("sim index is 0");
3153 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3155 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET SIM_INDEX = 0;",
3156 MSGFW_MESSAGE_TABLE_NAME);
3158 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
3159 dbHandle->endTrans(false);
3160 return MSG_ERR_DB_EXEC;
3163 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
3164 dbHandle->finalizeQuery();
3165 dbHandle->endTrans(false);
3166 return MSG_ERR_DB_EXEC;
3169 MSG_DEBUG("sim index is %d", sim_idx);
3171 memset(keyName, 0x00, sizeof(keyName));
3172 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, sim_idx);
3175 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
3176 MSG_INFO("MsgSettingGetString() is failed");
3179 MSG_SEC_DEBUG("imsi value exist -> %s", imsi);
3181 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3183 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET SIM_INDEX = %d \
3184 WHERE SIM_IMSI LIKE '%s';",
3185 MSGFW_MESSAGE_TABLE_NAME, sim_idx, imsi);
3192 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
3193 dbHandle->endTrans(false);
3194 return MSG_ERR_DB_EXEC;
3197 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
3198 dbHandle->finalizeQuery();
3199 dbHandle->endTrans(false);
3200 return MSG_ERR_DB_EXEC;
3204 dbHandle->finalizeQuery();
3205 dbHandle->endTrans(true);
3213 msg_error_t MsgStoUpdateDPMRestrictedStatus(MSG_MAIN_TYPE_T msgType)
3215 msg_error_t err = MSG_SUCCESS;
3217 char sqlQuery[MAX_QUERY_LEN+1];
3218 MsgDbHandler *dbHandle = getDbHandle();
3220 msg_id_list_s msgIdList = {0, };
3223 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3224 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE MAIN_TYPE = %d AND DPM_RESTRICTED = 1;",
3225 MSGFW_MESSAGE_TABLE_NAME, msgType);
3227 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
3228 if (err != MSG_SUCCESS) {
3229 dbHandle->freeTable();
3233 msg_message_id_t *msgIds = new msg_message_id_t[rowCnt];
3234 for (int i = 0; i < rowCnt; i++) {
3235 msgIds[i] = dbHandle->getColumnToInt(i + 1);
3238 dbHandle->freeTable();
3240 msgIdList.nCount = rowCnt;
3241 msgIdList.msgIdList = msgIds;
3243 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3244 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET DPM_RESTRICTED = 0 WHERE MAIN_TYPE = %d AND DPM_RESTRICTED = 1;",
3245 MSGFW_MESSAGE_TABLE_NAME, msgType);
3247 err = dbHandle->execQuery(sqlQuery);
3248 if (err == MSG_SUCCESS) {
3249 MsgStoUpdateAllAddress();
3250 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
3253 if (msgIdList.msgIdList)
3254 delete [] msgIdList.msgIdList;