2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <tr1/unordered_set>
26 #include "MsgCppTypes.h"
27 #include "MsgContact.h"
28 #include "MsgUtilFile.h"
30 #include "MsgUtilStorage.h"
31 #include "MsgGconfWrapper.h"
32 #include "MsgSqliteWrapper.h"
33 #include "MsgPluginManager.h"
34 #include "MsgStorageHandler.h"
35 #include "MsgNotificationWrapper.h"
36 #include "MsgDevicedWrapper.h"
37 #include "MsgTransManager.h"
42 /*==================================================================================================
44 ==================================================================================================*/
48 bool delNotiRunning = false;
52 bool delLogRunning = false;
55 /*==================================================================================================
57 ==================================================================================================*/
58 static gboolean resetNotification(void *pVoid)
62 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
70 /*==================================================================================================
71 FUNCTION IMPLEMENTATION
72 ==================================================================================================*/
74 msg_error_t MsgStoAddMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
78 msg_error_t err = MSG_SUCCESS;
80 unsigned int rowId = 0;
81 msg_thread_id_t convId = 0;
83 char sqlQuery[MAX_QUERY_LEN+1];
85 MsgDbHandler *dbHandle = getDbHandle();
87 dbHandle->beginTrans();
89 if (pMsg->nAddressCnt > 0) {
90 err = MsgStoAddAddress(dbHandle, pMsg, &convId);
92 if (err != MSG_SUCCESS) {
93 dbHandle->endTrans(false);
97 pMsg->threadId = convId;
100 if (pMsg->msgId > 0) {
104 err = dbHandle->getRowId(MSGFW_MESSAGE_TABLE_NAME, &rowId);
105 if (err != MSG_SUCCESS) {
106 dbHandle->endTrans(false);
109 pMsg->msgId = (msg_message_id_t)rowId;
114 char *pFileData = NULL;
115 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
118 if (pMsg->bTextSms == false) {
119 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
120 dbHandle->endTrans(false);
121 return MSG_ERR_STORAGE_ERROR;
124 MSG_DEBUG("file size [%d]", fileSize);
127 char keyName[MAX_VCONFKEY_NAME_LEN];
128 memset(keyName, 0x00, sizeof(keyName));
129 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, pMsg->sim_idx);
132 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
133 MSG_INFO("MsgSettingGetString() is failed");
137 memset(sqlQuery, 0x00, sizeof(sqlQuery));
139 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %u, %d, %d, %d, %d, %d, %d, %d, %d, ?, '', '', ?, 0, %d, '%s', %d);",
140 MSGFW_MESSAGE_TABLE_NAME, rowId, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType,
141 (unsigned int)pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
142 0, pMsg->bBackup, pMsg->sim_idx, imsi, pMsg->bRestricted);
144 MSG_DEBUG("QUERY : %s", sqlQuery);
149 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
150 dbHandle->endTrans(false);
151 return MSG_ERR_DB_EXEC;
154 dbHandle->bindText(pMsg->subject, 1);
156 if (pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
157 dbHandle->bindText("", 2);
159 if (pMsg->bTextSms == false)
160 dbHandle->bindText(pFileData, 2);
162 dbHandle->bindText(pMsg->msgText, 2);
165 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
166 dbHandle->finalizeQuery();
167 dbHandle->endTrans(false);
168 return MSG_ERR_DB_EXEC;
171 dbHandle->finalizeQuery();
173 if (pMsg->msgType.subType != MSG_SENDREQ_MMS) {
174 err = MsgStoUpdateConversation(dbHandle, convId);
176 if (err != MSG_SUCCESS) {
177 dbHandle->endTrans(false);
183 /* In the case of MMS Message, load the MMS plugin to save MMS PDU */
184 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
185 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
186 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
188 dbHandle->endTrans(false);
189 return MSG_ERR_NULL_POINTER;
192 if (pFileData == NULL) {
193 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
194 dbHandle->endTrans(false);
195 return MSG_ERR_STORAGE_ERROR;
198 MSG_DEBUG("file size [%d]", fileSize);
201 err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
203 if (err != MSG_SUCCESS) {
204 dbHandle->endTrans(false);
205 return MSG_ERR_STORAGE_ERROR;
208 if (pMsg->msgType.subType == MSG_SENDREQ_MMS
209 || pMsg->msgType.subType == MSG_RETRIEVE_MMS
210 || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS
211 || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
212 MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
214 err = MsgStoUpdateMMSMessage(pMsg);
216 if (err != MSG_SUCCESS) {
217 dbHandle->endTrans(false);
218 return MSG_ERR_STORAGE_ERROR;
222 } else if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL) {
223 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
225 dbHandle->endTrans(false);
226 return MSG_ERR_NULL_POINTER;
228 err = plg->addMessage(pMsg, pSendOptInfo, NULL);
229 if (err != MSG_SUCCESS) {
230 dbHandle->endTrans(false);
231 return MSG_ERR_STORAGE_ERROR;
235 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
236 char *pMmsSerializedData = NULL;
237 unique_ptr<char*, void(*)(char**)> buf_mms(&pMmsSerializedData, unique_ptr_deleter);
239 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
240 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
243 dbHandle->endTrans(false);
244 return MSG_ERR_NULL_POINTER;
247 if (MsgOpenAndReadFile(pMsg->msgData, &pMmsSerializedData, &fileSize) == false) {
248 dbHandle->endTrans(false);
249 return MSG_ERR_STORAGE_ERROR;
252 MSG_DEBUG("file size [%d]", fileSize);
254 err = plg->addMessage(pMsg, pSendOptInfo, pMmsSerializedData);
256 if (err != MSG_SUCCESS) {
257 dbHandle->endTrans(false);
258 return MSG_ERR_STORAGE_ERROR;
261 * if (pMsg->msgText[0] != '\0') {
262 * g_file_get_contents((gchar*)pMsg->msgText, (gchar**)&pFileData, (gsize*)&fileSize, NULL);
263 * MSG_DEBUG("file size [%d]", fileSize);
267 if (pMsg->msgType.subType == MSG_SENDREQ_MMS
268 || pMsg->msgType.subType == MSG_RETRIEVE_MMS
269 || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS
270 || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
271 MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
272 err = MsgStoUpdateMMSMessage(pMsg);
276 if (pMsg->bTextSms == false) {
277 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
278 dbHandle->endTrans(false);
279 return MSG_ERR_STORAGE_ERROR;
281 MSG_DEBUG("file size [%d]", fileSize);
285 dbHandle->endTrans(true);
293 msg_error_t MsgStoUpdateMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
295 msg_error_t err = MSG_SUCCESS;
297 char sqlQuery[MAX_QUERY_LEN+1];
299 msg_thread_id_t convId = 0;
300 MsgDbHandler *dbHandle = getDbHandle();
301 dbHandle->beginTrans();
303 MSG_MAIN_TYPE_T prevType;
304 memset(sqlQuery, 0x00, sizeof(sqlQuery));
305 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE FROM %s WHERE MSG_ID = %d;",
306 MSGFW_MESSAGE_TABLE_NAME, pMsg->msgId);
308 MSG_DEBUG("QUERY : %s", sqlQuery);
310 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
311 dbHandle->endTrans(false);
312 return MSG_ERR_DB_PREPARE;
315 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
316 dbHandle->finalizeQuery();
317 dbHandle->endTrans(false);
318 return MSG_ERR_STORAGE_ERROR;
321 prevType = dbHandle->columnInt(0);
322 dbHandle->finalizeQuery();
324 /* check msg type with previous type */
325 if (prevType != pMsg->msgType.mainType) {
326 MSG_DEBUG("different msg type to update [prev : %d], [current : %d]", prevType, pMsg->msgType.mainType);
328 err = MsgStoDeleteMessage(pMsg->msgId, false);
329 if (err != MSG_SUCCESS) {
330 dbHandle->endTrans(false);
334 err = MsgStoAddMessage(pMsg, pSendOptInfo);
335 if (err != MSG_SUCCESS) {
336 dbHandle->endTrans(false);
340 dbHandle->endTrans(false);
344 if (pMsg->nAddressCnt > 0) {
346 err = MsgStoAddAddress(dbHandle, pMsg, &convId);
348 if (err != MSG_SUCCESS) {
349 dbHandle->endTrans(false);
356 char *pFileData = NULL;
357 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
360 if (pMsg->bTextSms == false) {
361 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
362 dbHandle->endTrans(false);
363 return MSG_ERR_STORAGE_ERROR;
367 if (pSendOptInfo != NULL) {
368 /* Get Global setting value if bSetting == false */
369 if (pSendOptInfo->bSetting == false) {
370 if (MsgSettingGetBool(MSG_KEEP_COPY, &pSendOptInfo->bKeepCopy) != MSG_SUCCESS)
371 MSG_INFO("MsgSettingGetBool() is failed");
373 if (pMsg->msgType.mainType == MSG_SMS_TYPE) {
374 if (MsgSettingGetBool(SMS_SEND_DELIVERY_REPORT, &pSendOptInfo->bDeliverReq) != MSG_SUCCESS)
375 MSG_INFO("MsgSettingGetBool() is failed");
377 if (MsgSettingGetBool(SMS_SEND_REPLY_PATH, &pSendOptInfo->option.smsSendOptInfo.bReplyPath) != MSG_SUCCESS)
378 MSG_INFO("MsgSettingGetBool() is failed");
379 } else if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
380 if (MsgSettingGetBool(MMS_SEND_DELIVERY_REPORT, &pSendOptInfo->bDeliverReq) != MSG_SUCCESS)
381 MSG_INFO("MsgSettingGetBool() is failed");
383 if (MsgSettingGetBool(MMS_SEND_READ_REPLY, &pSendOptInfo->option.mmsSendOptInfo.bReadReq) != MSG_SUCCESS)
384 MSG_INFO("MsgSettingGetBool() is failed");
387 if (MsgSettingGetInt(MMS_SEND_EXPIRY_TIME, &tmpVal) != MSG_SUCCESS) {
388 MSG_INFO("MsgSettingGetInt() is failed");
390 pSendOptInfo->option.mmsSendOptInfo.expiryTime.time = (unsigned int)tmpVal;
392 if (MsgSettingGetInt(MMS_SEND_DELIVERY_TIME, &tmpVal) != MSG_SUCCESS) {
393 MSG_INFO("MsgSettingGetInt() is failed");
395 MSG_MMS_DELIVERY_TIME_T deliveryTime = (MSG_MMS_DELIVERY_TIME_T)tmpVal;
397 if (deliveryTime == MSG_DELIVERY_TIME_CUSTOM) {
398 pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime = true;
399 if (MsgSettingGetInt(MMS_SEND_CUSTOM_DELIVERY, &tmpVal) != MSG_SUCCESS) {
400 MSG_INFO("MsgSettingGetInt() is failed");
402 pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = (unsigned int)tmpVal;
404 pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime = false;
405 pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = (unsigned int)deliveryTime;
408 if (MsgSettingGetInt(MMS_SEND_PRIORITY, &tmpVal) != MSG_SUCCESS) {
409 MSG_INFO("MsgSettingGetInt() is failed");
411 pSendOptInfo->option.mmsSendOptInfo.priority = (msg_priority_type_t)tmpVal;
417 memset(sqlQuery, 0x00, sizeof(sqlQuery));
419 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET CONV_ID = %d, FOLDER_ID = %d, STORAGE_ID = %d, MAIN_TYPE = %d, SUB_TYPE = %d, \
420 DISPLAY_TIME = %lu, DATA_SIZE = %d, NETWORK_STATUS = %d, READ_STATUS = %d, PROTECTED = %d, PRIORITY = %d, MSG_DIRECTION = %d, \
421 BACKUP = %d, SUBJECT = ?, MSG_TEXT = ? \
423 MSGFW_MESSAGE_TABLE_NAME, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->displayTime, pMsg->dataSize,
424 pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction, pMsg->bBackup, pMsg->msgId);
426 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
427 dbHandle->endTrans(false);
428 return MSG_ERR_DB_EXEC;
431 dbHandle->bindText(pMsg->subject, 1);
433 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pMsg->bTextSms == false)
434 dbHandle->bindText(pFileData, 2);
436 dbHandle->bindText(pMsg->msgText, 2);
438 MSG_DEBUG("%s", sqlQuery);
440 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
441 dbHandle->finalizeQuery();
442 dbHandle->endTrans(false);
443 return MSG_ERR_DB_EXEC;
446 dbHandle->finalizeQuery();
448 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL) {
449 if (pSendOptInfo->bSetting == true) {
450 memset(sqlQuery, 0x00, sizeof(sqlQuery));
451 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET "
456 "WHERE MSG_ID = %d;",
457 MSGFW_SMS_SENDOPT_TABLE_NAME,
458 pSendOptInfo->bDeliverReq,
459 pSendOptInfo->bKeepCopy,
460 pSendOptInfo->option.smsSendOptInfo.bReplyPath,
464 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
465 dbHandle->endTrans(false);
466 return MSG_ERR_DB_EXEC;
469 } else if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
470 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
472 dbHandle->endTrans(false);
473 return MSG_ERR_NULL_POINTER;
476 err = plg->updateMessage(pMsg, pSendOptInfo, pFileData);
478 if (err != MSG_SUCCESS) {
479 dbHandle->endTrans(false);
480 return MSG_ERR_STORAGE_ERROR;
483 if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
484 MSG_SEC_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
486 err = MsgStoUpdateMMSMessage(pMsg);
488 if (err != MSG_SUCCESS) {
489 dbHandle->endTrans(false);
490 return MSG_ERR_STORAGE_ERROR;
495 err = MsgStoUpdateConversation(dbHandle, convId);
497 if (err != MSG_SUCCESS) {
498 dbHandle->endTrans(false);
499 return MSG_ERR_STORAGE_ERROR;
502 err = MsgStoClearConversationTable(dbHandle);
504 if (err != MSG_SUCCESS) {
505 dbHandle->endTrans(false);
506 return MSG_ERR_STORAGE_ERROR;
509 dbHandle->endTrans(true);
515 msg_error_t MsgStoUpdateReadStatus(msg_message_id_t msgId, bool bRead)
517 char sqlQuery[MAX_QUERY_LEN+1];
519 msg_storage_id_t storageId;
521 MsgDbHandler *dbHandle = getDbHandle();
522 if (MsgStoSetReadStatus(dbHandle, msgId, bRead) != MSG_SUCCESS) {
523 MSG_DEBUG("MsgStoSetReadStatus() Error");
524 return MSG_ERR_STORAGE_ERROR;
527 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
530 #ifndef FEATURE_SMS_CDMA
532 memset(sqlQuery, 0x00, sizeof(sqlQuery));
533 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT STORAGE_ID FROM %s WHERE MSG_ID = %d;",
534 MSGFW_MESSAGE_TABLE_NAME, msgId);
536 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
537 return MSG_ERR_DB_PREPARE;
539 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
540 storageId = dbHandle->columnInt(0);
542 dbHandle->finalizeQuery();
543 return MSG_ERR_DB_STEP;
545 dbHandle->finalizeQuery();
547 MSG_DEBUG("StorageId:[%d]", storageId);
549 /* Update Read Status for SIM Msg */
550 if (storageId == MSG_STORAGE_SIM) {
551 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
554 MSG_DEBUG("SMS Plug-in is NULL");
555 return MSG_ERR_NULL_POINTER;
559 memset(sqlQuery, 0x00, sizeof(sqlQuery));
560 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
561 MSGFW_SIM_MSG_TABLE_NAME, msgId);
563 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
564 return MSG_ERR_DB_PREPARE;
567 msg_sim_slot_id_t sim_idx;
569 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
570 sim_idx = dbHandle->columnInt(0);
571 simId = dbHandle->columnInt(1);
573 if (plg->setReadStatus(sim_idx, simId) != MSG_SUCCESS) {
574 MSG_DEBUG("Fail to Set Read Status for SIM SMS");
578 dbHandle->finalizeQuery();
587 msg_error_t MsgStoUpdateThreadReadStatus(msg_thread_id_t threadId, msg_id_list_s *pMsgIdList)
591 msg_error_t err = MSG_SUCCESS;
593 char sqlQuery[MAX_QUERY_LEN+1];
595 /*** Get msg id list **/
596 int rowCnt = 0, index = 0;
597 pMsgIdList->nCount = 0;
598 MsgDbHandler *dbHandle = getDbHandle();
600 memset(sqlQuery, 0x00, sizeof(sqlQuery));
601 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s "
602 "WHERE CONV_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d AND FOLDER_ID < %d;",
603 MSGFW_MESSAGE_TABLE_NAME,
604 threadId, MSG_STORAGE_PHONE, MSG_SPAMBOX_ID);
606 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
608 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
609 MSG_DEBUG("Fail to getTable().");
610 dbHandle->freeTable();
615 dbHandle->freeTable();
619 pMsgIdList->nCount = rowCnt;
620 MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
622 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
624 for (int i = 0; i < rowCnt; i++)
625 pMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
627 dbHandle->freeTable();
630 /* set read status */
631 dbHandle->beginTrans();
632 memset(sqlQuery, 0x00, sizeof(sqlQuery));
633 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET READ_STATUS = %d "
634 "WHERE CONV_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d AND FOLDER_ID < %d;",
635 MSGFW_MESSAGE_TABLE_NAME, 1,
636 threadId, MSG_STORAGE_PHONE, MSG_SPAMBOX_ID);
638 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
639 dbHandle->endTrans(false);
640 return MSG_ERR_DB_EXEC;
644 if (MsgStoUpdateConversation(dbHandle, threadId) != MSG_SUCCESS) {
645 MSG_DEBUG("MsgStoUpdateConversation() Error");
646 dbHandle->endTrans(false);
647 return MSG_ERR_STORAGE_ERROR;
650 dbHandle->endTrans(true);
651 if (g_idle_add(resetNotification, NULL) == 0) {
652 MSG_DEBUG("resetNotification() Error");
661 msg_error_t MsgStoUpdateProtectedStatus(msg_message_id_t msgId, bool bProtected)
663 char sqlQuery[MAX_QUERY_LEN+1];
664 MsgDbHandler *dbHandle = getDbHandle();
666 memset(sqlQuery, 0x00, sizeof(sqlQuery));
667 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET PROTECTED = %d WHERE MSG_ID = %d;",
668 MSGFW_MESSAGE_TABLE_NAME, (int)bProtected, msgId);
670 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
671 return MSG_ERR_DB_EXEC;
677 msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
681 MSG_DEBUG("Msg Id : %d", msgId);
683 msg_error_t err = MSG_SUCCESS;
685 char sqlQuery[MAX_QUERY_LEN+1];
686 MsgDbHandler *dbHandle = getDbHandle();
688 /* delete report notification */
689 char tempAddr[MAX_ADDRESS_VAL_LEN+1];
690 memset(tempAddr, 0x00, sizeof(tempAddr));
691 memset(sqlQuery, 0x00, sizeof(sqlQuery));
692 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.ADDRESS_VAL FROM %s A, %s B WHERE A.CONV_ID = B.CONV_ID AND A.MSG_ID = %d;"
693 , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, msgId);
695 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
696 return MSG_ERR_DB_PREPARE;
698 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
699 dbHandle->finalizeQuery();
700 return MSG_ERR_DB_DONE;
703 snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
705 MSG_SEC_DEBUG("Updated address = %s", tempAddr);
707 MsgDeleteReportNotification(tempAddr);
709 dbHandle->finalizeQuery();
711 /* Get SUB_TYPE, STORAGE_ID */
712 memset(sqlQuery, 0x00, sizeof(sqlQuery));
713 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE, FOLDER_ID, STORAGE_ID, READ_STATUS, CONV_ID, SIM_INDEX \
714 FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
716 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
717 MSG_DEBUG("Query Failed [%s]", sqlQuery);
718 return MSG_ERR_DB_PREPARE;
721 MSG_MESSAGE_TYPE_S msgType;
722 msg_folder_id_t folderId;
723 msg_storage_id_t storageId;
724 msg_thread_id_t convId;
725 msg_sim_slot_id_t simIndex;
728 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
729 msgType.mainType = dbHandle->columnInt(0);
730 msgType.subType = dbHandle->columnInt(1);
731 folderId = dbHandle->columnInt(2);
732 storageId = dbHandle->columnInt(3);
733 bRead = dbHandle->columnInt(4);
734 convId = dbHandle->columnInt(5);
735 simIndex = dbHandle->columnInt(6);
737 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);
739 MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
741 dbHandle->finalizeQuery();
743 return MSG_ERR_DB_STEP;
746 dbHandle->finalizeQuery();
748 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
751 MSG_DEBUG("SMS Plug-in is NULL");
752 return MSG_ERR_NULL_POINTER;
755 dbHandle->beginTrans();
757 #ifndef FEATURE_SMS_CDMA
758 /* Check sim message */
759 if (storageId == MSG_STORAGE_SIM) {
760 msg_sim_id_t simMsgId;
761 msg_sim_slot_id_t sim_idx;
764 /* get sim message id */
765 memset(sqlQuery, 0x00, sizeof(sqlQuery));
766 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
767 MSGFW_SIM_MSG_TABLE_NAME, msgId);
769 MSG_DEBUG("sqlQuery is [%s]", sqlQuery);
771 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
772 dbHandle->endTrans(false);
773 return MSG_ERR_DB_PREPARE;
776 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
780 sim_idx = dbHandle->columnInt(0);
781 simMsgId = dbHandle->columnInt(1);
783 MSG_DEBUG("SIM Msg Id : [%d]", simMsgId);
785 err = plg->deleteSimMessage(sim_idx, simMsgId);
787 if (err != MSG_SUCCESS) {
788 dbHandle->finalizeQuery();
789 dbHandle->endTrans(false);
793 dbHandle->finalizeQuery();
795 /*Sim message delete in db table */
796 memset(sqlQuery, 0x00, sizeof(sqlQuery));
797 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE SIM_ID = %d AND SIM_SLOT_ID =%d;", MSGFW_SIM_MSG_TABLE_NAME, simMsgId, sim_idx);
799 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
800 dbHandle->finalizeQuery();
801 dbHandle->endTrans(false);
802 return MSG_ERR_DB_EXEC;
806 dbHandle->finalizeQuery();
809 /* each type has to be handled in plug in ? */
810 if (msgType.mainType == MSG_SMS_TYPE) {
811 memset(sqlQuery, 0x00, sizeof(sqlQuery));
812 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
813 MSGFW_SMS_SENDOPT_TABLE_NAME, msgId);
815 /* Delete SMS Send Option */
816 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
817 dbHandle->endTrans(false);
818 return MSG_ERR_DB_EXEC;
821 memset(sqlQuery, 0x00, sizeof(sqlQuery));
822 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
823 MSGFW_SMS_REPORT_TABLE_NAME, msgId);
825 /* Delete Data from SMS_REPORT table */
826 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
827 dbHandle->endTrans(false);
828 return MSG_ERR_DB_EXEC;
831 if (msgType.subType == MSG_CB_SMS || msgType.subType == MSG_JAVACB_SMS) {
832 memset(sqlQuery, 0x00, sizeof(sqlQuery));
833 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
834 MSGFW_CB_MSG_TABLE_NAME, msgId);
836 /* Delete Push Message from push table */
837 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
838 dbHandle->endTrans(false);
839 return MSG_ERR_DB_EXEC;
841 } else if (msgType.subType >= MSG_WAP_SI_SMS && msgType.subType <= MSG_WAP_CO_SMS) {
842 memset(sqlQuery, 0x00, sizeof(sqlQuery));
843 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
844 MSGFW_PUSH_MSG_TABLE_NAME, msgId);
846 /* Delete Push Message from push table */
847 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
848 dbHandle->endTrans(false);
849 return MSG_ERR_DB_EXEC;
851 } else if (msgType.subType == MSG_SYNCML_CP) {
852 memset(sqlQuery, 0x00, sizeof(sqlQuery));
853 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
854 MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
856 /* Delete SyncML Message from syncML table */
857 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
858 dbHandle->endTrans(false);
859 return MSG_ERR_DB_EXEC;
862 } else if (msgType.mainType == MSG_MMS_TYPE) {
863 char filePath[MSG_FILEPATH_LEN_MAX + 1] = {0, };
864 char dirPath[MSG_FILEPATH_LEN_MAX + 1]= {0, };
866 /*remove multipart */
867 memset(sqlQuery, 0x00, sizeof(sqlQuery));
868 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
869 MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
871 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
872 dbHandle->endTrans(false);
873 return MSG_ERR_DB_PREPARE;
876 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
877 memset(filePath, 0x00, sizeof(filePath));
878 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
879 if (remove(filePath) == -1)
880 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
882 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
884 dbHandle->finalizeQuery();
886 /* Delete Data from Multipart table */
887 memset(sqlQuery, 0x00, sizeof(sqlQuery));
888 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
889 MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
891 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
892 dbHandle->endTrans(false);
893 return MSG_ERR_DB_EXEC;
896 memset(sqlQuery, 0x00, sizeof(sqlQuery));
897 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
898 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
900 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
901 dbHandle->endTrans(false);
902 return MSG_ERR_DB_PREPARE;
905 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
906 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
908 snprintf(dirPath, MSG_FILEPATH_LEN_MAX, "%s.dir", filePath);
910 if (remove(filePath) == -1)
911 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
913 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
920 MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
921 dbHandle->finalizeQuery();
922 dbHandle->endTrans(false);
923 return MSG_ERR_DB_STEP;
926 dbHandle->finalizeQuery();
928 /* remove thumbnail file */
929 memset(sqlQuery, 0x00, sizeof(sqlQuery));
930 snprintf(sqlQuery, sizeof(sqlQuery),
931 "SELECT VALUE FROM %s "
932 "WHERE MSG_ID = %d AND (TYPE=%d OR TYPE=%d);",
933 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO);
935 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
936 dbHandle->endTrans(false);
937 return MSG_ERR_DB_PREPARE;
940 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
941 memset(filePath, 0x00, sizeof(filePath));
942 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
943 if (remove(filePath) == -1)
944 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
946 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
949 dbHandle->finalizeQuery();
951 memset(sqlQuery, 0x00, sizeof(sqlQuery));
952 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
953 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId);
955 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
956 dbHandle->endTrans(false);
957 return MSG_ERR_DB_EXEC;
960 memset(sqlQuery, 0x00, sizeof(sqlQuery));
961 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
962 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
964 /* Delete Data from MMS table */
965 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
966 dbHandle->endTrans(false);
967 return MSG_ERR_DB_EXEC;
970 memset(sqlQuery, 0x00, sizeof(sqlQuery));
971 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
972 MSGFW_REPORT_TABLE_NAME, msgId);
974 /* Delete Data from MMS STATUS table */
975 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
976 dbHandle->endTrans(false);
977 return MSG_ERR_DB_EXEC;
981 memset(sqlQuery, 0x00, sizeof(sqlQuery));
982 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
984 /* Delete Message from msg table */
985 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
986 dbHandle->endTrans(false);
987 return MSG_ERR_DB_EXEC;
990 #ifdef FEATURE_SMS_CDMA
991 memset(sqlQuery, 0x00, sizeof(sqlQuery));
992 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_UNIQUENESS_INFO_TABLE_NAME, msgId);
994 /* Delete Message from uniqueness table */
995 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
996 dbHandle->endTrans(false);
997 return MSG_ERR_DB_EXEC;
1002 /* Clear Conversation table */
1003 if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
1004 dbHandle->endTrans(false);
1005 return MSG_ERR_DB_EXEC;
1008 /* Update conversation table. */
1009 if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
1010 dbHandle->endTrans(false);
1011 return MSG_ERR_STORAGE_ERROR;
1014 dbHandle->endTrans(true);
1016 if (msgType.mainType == MSG_SMS_TYPE && folderId == MSG_INBOX_ID) {
1017 msgType.classType = MSG_CLASS_NONE;
1019 /* Set memory status in SIM */
1020 if (MsgStoCheckMsgCntFull(dbHandle, &msgType, folderId) == MSG_SUCCESS) {
1021 MSG_DEBUG("Set Memory Status");
1023 plg->setMemoryStatus(simIndex, MSG_SUCCESS);
1027 if (bCheckIndication == true) {
1028 MSG_DEBUG("bCheckIndication is true.");
1029 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1036 msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyDB, msg_id_list_s *pMsgIdList)
1038 msg_error_t err = MSG_SUCCESS;
1040 char sqlQuery[MAX_QUERY_LEN+1];
1042 queue<msg_thread_id_t> threadList;
1044 #ifdef FEATURE_SMS_CDMA
1045 const char *tableList[] = {MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1046 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1047 MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1048 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1049 MSGFW_UNIQUENESS_INFO_TABLE_NAME};
1051 const char *tableList[] = {MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1052 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1053 MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1054 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME};
1057 int listCnt = sizeof(tableList)/sizeof(char *);
1059 MsgDbHandler *dbHandle = getDbHandle();
1060 signed char folder_id;
1062 /* Get conversation ID from Folder */
1063 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1065 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE FOLDER_ID = %d",
1066 MSGFW_MESSAGE_TABLE_NAME, folderId);
1068 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1070 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1071 MSG_DEBUG("Fail to getTable().");
1072 dbHandle->freeTable();
1077 dbHandle->freeTable();
1081 for (int i = 1; i <= rowCnt; i++) {
1082 MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
1083 threadList.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1086 dbHandle->freeTable();
1088 /*** Get msg id list **/
1089 msg_id_list_s *pToDeleteMsgIdList = NULL;
1090 pToDeleteMsgIdList = (msg_id_list_s *)new char[sizeof(msg_id_list_s)];
1091 if (pToDeleteMsgIdList == NULL) {
1092 MSG_DEBUG("pToDeleteMsgIdList is NULL.");
1093 return MSG_ERR_NULL_POINTER;
1095 memset(pToDeleteMsgIdList, 0x00, sizeof(msg_id_list_s));
1097 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1098 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d",
1099 MSGFW_MESSAGE_TABLE_NAME, folderId);
1104 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
1106 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1107 MSG_DEBUG("Fail to getTable().");
1108 dbHandle->freeTable();
1113 dbHandle->freeTable();
1119 pToDeleteMsgIdList->nCount = rowCnt;
1121 MSG_DEBUG("pToDeleteMsgIdList->nCount [%d]", pToDeleteMsgIdList->nCount);
1123 pToDeleteMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
1124 memset(pToDeleteMsgIdList->msgIdList, 0x00, sizeof(msg_message_id_t) * rowCnt);
1126 for (int i = 0; i < rowCnt; i++)
1127 pToDeleteMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
1129 dbHandle->freeTable();
1132 /*** Delete Sim Message In Folder **/
1133 folder_id = (signed char)folderId;
1134 if (folder_id >= MSG_INBOX_ID) {
1135 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1137 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d AND STORAGE_ID = %d",
1138 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_SIM);
1142 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1143 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1144 dbHandle->freeTable();
1148 for (int i = 1; i <= rowCnt; i++) {
1149 err = MsgStoDeleteMessage(dbHandle->getColumnToInt(i), false);
1151 if (err != MSG_SUCCESS) {
1152 MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
1154 dbHandle->freeTable();
1159 /*Delete phone log */
1160 /* MsgDeletePhoneLog(dbHandle->getColumnToInt(i)); */
1163 dbHandle->freeTable();
1166 dbHandle->beginTrans();
1168 for (int i = 0; i < listCnt; i++) {
1169 if (!strcmp(tableList[i], MMS_PLUGIN_MESSAGE_TABLE_NAME)) {
1172 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1173 char dirPath[MSG_FILEPATH_LEN_MAX] = {0, };
1174 /* remove multipart */
1175 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1176 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s;",
1177 MSGFW_MMS_MULTIPART_TABLE_NAME);
1179 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1180 dbHandle->endTrans(false);
1181 return MSG_ERR_DB_PREPARE;
1184 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1185 memset(filePath, 0x00, sizeof(filePath));
1186 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
1187 if (remove(filePath) == -1)
1188 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1190 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1192 dbHandle->finalizeQuery();
1194 /* Delete Data from Multipart table */
1195 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1196 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;",
1197 MSGFW_MMS_MULTIPART_TABLE_NAME);
1199 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1200 err = MSG_ERR_DB_EXEC;
1201 dbHandle->endTrans(false);
1205 /*get mms msg id list */
1206 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1207 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.FILE_PATH FROM %s A, %s B \
1208 WHERE A.FOLDER_ID = %d AND A.MAIN_TYPE = %d AND A.MSG_ID = B.MSG_ID",
1209 MSGFW_MESSAGE_TABLE_NAME, MMS_PLUGIN_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE);
1211 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1212 MSG_DEBUG("rowCnt %d", rowCnt);
1214 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1215 MSG_DEBUG("Fail to getTable().");
1217 dbHandle->freeTable();
1218 dbHandle->endTrans(false);
1223 for (int i = 1; i <= rowCnt; i++) {
1224 memset(filePath, 0x00, sizeof(filePath));
1225 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1227 MSG_SEC_DEBUG("filePath [%s]", filePath);
1229 /*delete raw file */
1230 snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
1232 if (remove(filePath) == -1)
1233 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1235 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1242 dbHandle->freeTable();
1245 /* delete thumbnail */
1246 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1247 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1248 snprintf(sqlQuery, sizeof(sqlQuery),
1249 "SELECT VALUE FROM %s "
1250 "WHERE (TYPE=%d OR TYPE=%d) "
1251 "AND (MSG_ID IN (SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d));",
1252 MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO, MSGFW_MESSAGE_TABLE_NAME, folderId);
1254 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1255 dbHandle->endTrans(false);
1256 return MSG_ERR_DB_PREPARE;
1259 while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1260 memset(filePath, 0x00, sizeof(filePath));
1261 strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
1262 if (remove(filePath) == -1)
1263 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1265 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1268 dbHandle->finalizeQuery();
1270 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1272 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN \
1273 (SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d);",
1274 tableList[i], MSGFW_MESSAGE_TABLE_NAME, folderId);
1276 /* Delete Message in specific folder from table */
1277 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1278 MSG_DEBUG("sqlQuery [%s]", sqlQuery);
1279 dbHandle->endTrans(false);
1280 err = MSG_ERR_DB_EXEC;
1286 /* Clear Conversation table */
1287 if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
1288 dbHandle->endTrans(false);
1289 err = MSG_ERR_DB_EXEC;
1294 /* Update Address */
1295 while (!threadList.empty()) {
1296 err = MsgStoUpdateConversation(dbHandle, threadList.front());
1300 if (err != MSG_SUCCESS) {
1301 dbHandle->endTrans(false);
1307 dbHandle->endTrans(true);
1309 /* Set pMsgIdList */
1310 if (pMsgIdList != NULL && pToDeleteMsgIdList->nCount > 0) {
1311 pMsgIdList->nCount = pToDeleteMsgIdList->nCount;
1313 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * pToDeleteMsgIdList->nCount];
1314 memset(pMsgIdList->msgIdList, 0x00, sizeof(msg_message_id_t) * pToDeleteMsgIdList->nCount);
1315 memcpy(pMsgIdList->msgIdList, pToDeleteMsgIdList->msgIdList, sizeof(msg_message_id_t) * pToDeleteMsgIdList->nCount);
1318 /* Create thread for noti and phone log delete. */
1320 if (pToDeleteMsgIdList->nCount > 0) {
1322 if (pToDeleteMsgIdList != NULL) {
1323 /*free peer info list */
1324 if (pToDeleteMsgIdList->msgIdList != NULL)
1325 delete [] pToDeleteMsgIdList->msgIdList;
1327 delete [] pToDeleteMsgIdList;
1330 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1337 MSG_DEBUG("Error case Free Memory");
1339 while (!threadList.empty()) {
1345 if (pToDeleteMsgIdList != NULL) {
1346 /*free peer info list */
1347 if (pToDeleteMsgIdList->msgIdList != NULL)
1348 delete [] pToDeleteMsgIdList->msgIdList;
1350 delete [] pToDeleteMsgIdList;
1357 msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
1363 msg_error_t err = MSG_SUCCESS;
1364 if (pMsgIdList->nCount < 1) {
1365 MSG_DEBUG("pMsgIdList->nCount < 1");
1369 char sqlQuery[MAX_QUERY_LEN+1];
1371 queue<msg_thread_id_t> threadList1, threadList2;
1373 #ifdef FEATURE_SMS_CDMA
1374 const char *tableList[] = {MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1375 MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1376 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1377 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1378 MSGFW_SMS_REPORT_TABLE_NAME, MSGFW_MMS_MULTIPART_TABLE_NAME,
1379 MSGFW_UNIQUENESS_INFO_TABLE_NAME};
1381 const char *tableList[] = {MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
1382 MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
1383 MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
1384 MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1385 MSGFW_SMS_REPORT_TABLE_NAME, MSGFW_MMS_MULTIPART_TABLE_NAME};
1388 int listCnt = sizeof(tableList)/sizeof(char *);
1390 MsgDbHandler *dbHandle = getDbHandle();
1392 dbHandle->beginTrans();
1393 /* reset msgid temp table */
1394 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1395 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_TMP_MSGID_TABLE_NAME);
1396 MSG_DEBUG("[%s]", sqlQuery);
1398 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1399 dbHandle->endTrans(false);
1400 return MSG_ERR_DB_EXEC;
1403 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
1404 dbHandle->finalizeQuery();
1405 dbHandle->endTrans(false);
1406 return MSG_ERR_DB_EXEC;
1409 dbHandle->finalizeQuery();
1411 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1412 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (?)", MSGFW_TMP_MSGID_TABLE_NAME);
1413 MSG_DEBUG("[%s]", sqlQuery);
1414 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1415 dbHandle->endTrans(false);
1416 return MSG_ERR_DB_PREPARE;
1419 for (int i = 0; i < pMsgIdList->nCount; i++) {
1420 dbHandle->resetQuery();
1421 dbHandle->bindInt(pMsgIdList->msgIdList[i], 1);
1422 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
1423 dbHandle->finalizeQuery();
1424 dbHandle->endTrans(false);
1425 return MSG_ERR_DB_EXEC;
1429 dbHandle->finalizeQuery();
1430 dbHandle->endTrans(true);
1432 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1433 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE MSG_ID IN %s;", MSGFW_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1435 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1437 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1438 MSG_DEBUG("Fail to getTable().");
1439 dbHandle->freeTable();
1443 MSG_DEBUG("rowCnt [%d]", rowCnt);
1446 dbHandle->freeTable();
1450 for (int i = 1; i <= rowCnt; i++) {
1451 MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
1452 threadList1.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1453 threadList2.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
1455 dbHandle->freeTable();
1457 /* delete report notification */
1458 char tempAddr[MAX_ADDRESS_VAL_LEN+1];
1459 while (!threadList1.empty()) {
1460 memset(tempAddr, 0x00, sizeof(tempAddr));
1461 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1462 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;"
1463 , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, threadList1.front());
1465 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1466 return MSG_ERR_DB_PREPARE;
1468 if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
1469 dbHandle->finalizeQuery();
1470 return MSG_ERR_DB_DONE;
1473 snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
1475 MSG_SEC_DEBUG("Updated address = %s", tempAddr);
1477 MsgDeleteReportNotification(tempAddr);
1479 dbHandle->finalizeQuery();
1485 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1486 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d AND MSG_ID IN %s;",
1487 MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, MSGFW_TMP_MSGID_TABLE_NAME);
1490 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1492 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1493 MSG_DEBUG("Fail to getTable().");
1494 dbHandle->freeTable();
1498 for (int i = 1; i <= rowCnt; i++) {
1499 err = MsgStoDeleteMessage(dbHandle->getColumnToInt(i), false);
1500 if (err != MSG_SUCCESS) {
1501 MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
1504 dbHandle->freeTable();
1506 dbHandle->beginTrans();
1507 for (int i = 0; i < listCnt; i++) {
1509 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1510 char dirPath[MSG_FILEPATH_LEN_MAX] = {0, };
1514 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1515 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN %s;", MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1517 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1519 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1520 MSG_DEBUG("Fail to getTable().");
1524 MSG_DEBUG("rowCnt %d", rowCnt);
1526 for (int i = 1; i <= rowCnt; i++) {
1527 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1529 MSG_SEC_DEBUG("filePath [%s]", filePath);
1531 /* Delete raw file. */
1532 snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
1534 if (remove(filePath) == -1)
1535 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1537 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1543 dbHandle->freeTable();
1545 } else if (i == 1) {
1546 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1550 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1551 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT VALUE FROM %s WHERE (TYPE = %d OR TYPE = %d) AND MSG_ID IN %s;",
1552 MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO, MSGFW_TMP_MSGID_TABLE_NAME);
1554 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1556 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1557 MSG_DEBUG("Fail to getTable().");
1561 MSG_DEBUG("rowCnt %d", rowCnt);
1563 for (int i = 1; i <= rowCnt; i++) {
1564 memset(filePath, 0x00, sizeof(filePath));
1565 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1566 if (remove(filePath) == -1)
1567 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1569 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1571 dbHandle->freeTable();
1572 } else if (!strcmp(tableList[i], MSGFW_MMS_MULTIPART_TABLE_NAME)) {
1573 /* MMS file path to delete. */
1574 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1578 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1579 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN %s;", MSGFW_MMS_MULTIPART_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
1581 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1583 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1584 MSG_DEBUG("Fail to getTable().");
1588 MSG_DEBUG("rowCnt %d", rowCnt);
1590 for (int i = 1; i <= rowCnt; i++) {
1591 memset(filePath, 0x00, sizeof(filePath));
1592 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1593 if (filePath[0] != '\0') {
1594 if (remove(filePath) == -1)
1595 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1597 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1600 dbHandle->freeTable();
1602 /* MMS thumbnail path to delete */
1603 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1604 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);
1606 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1608 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1609 MSG_DEBUG("Fail to getTable().");
1613 MSG_DEBUG("rowCnt %d", rowCnt);
1615 for (int i = 1; i <= rowCnt; i++) {
1616 memset(filePath, 0x00, sizeof(filePath));
1617 dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
1618 if (filePath[0] != '\0') {
1619 if (remove(filePath) == -1)
1620 MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
1622 MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
1626 dbHandle->freeTable();
1629 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1630 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN %s;", tableList[i], MSGFW_TMP_MSGID_TABLE_NAME);
1632 /* Delete Message in specific folder from table */
1633 err = dbHandle->execQuery(sqlQuery);
1634 if (err != MSG_SUCCESS) {
1635 MSG_DEBUG("Fail to execQuery().");
1639 /* Clear Conversation table */
1640 err = MsgStoClearConversationTable(dbHandle);
1641 if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoClearConversationTable().");
1643 /* Update Address */
1644 while (!threadList2.empty()) {
1645 err = MsgStoUpdateConversation(dbHandle, threadList2.front());
1646 if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoUpdateConversation().");
1649 err = dbHandle->endTrans(true);
1650 if (err != MSG_SUCCESS) {
1651 MSG_DEBUG("Fail to endTrans(true).");
1652 dbHandle->endTrans(false);
1656 if (g_idle_add(resetNotification, NULL) == 0) {
1657 MSG_DEBUG("resetNotification() Error");
1665 msg_error_t MsgStoMoveMessageToFolder(msg_message_id_t msgId, msg_folder_id_t destFolderId)
1667 msg_error_t err = MSG_SUCCESS;
1668 MSG_MESSAGE_TYPE_S msgType;
1669 msg_thread_id_t convId = 0;
1671 MsgStoGetMsgType(msgId, &msgType);
1673 char sqlQuery[MAX_QUERY_LEN+1];
1674 MsgDbHandler *dbHandle = getDbHandle();
1676 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1678 if (msgType.mainType == MSG_SMS_TYPE)
1679 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_ID = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, destFolderId, msgId);
1681 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_ID = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, destFolderId, msgId);
1683 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
1684 return MSG_ERR_DB_EXEC;
1686 /* get conversation id */
1687 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1689 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONV_ID FROM %s WHERE MSG_ID = %d;",
1690 MSGFW_MESSAGE_TABLE_NAME, msgId);
1692 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1693 return MSG_ERR_DB_PREPARE;
1695 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW)
1696 convId = dbHandle->columnInt(0);
1698 MSG_DEBUG("convId : %d", convId);
1700 dbHandle->finalizeQuery();
1702 /* update conversation table */
1703 err = MsgStoUpdateConversation(dbHandle, convId);
1705 /* update notification */
1706 signed char dest_folder_id = (signed char)destFolderId;
1707 if (dest_folder_id != MSG_SPAMBOX_ID)
1708 MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
1714 msg_error_t MsgStoMoveMessageToStorage(msg_message_id_t msgId, msg_storage_id_t destStorageId)
1718 msg_error_t err = MSG_SUCCESS;
1720 char sqlQuery[MAX_QUERY_LEN+1];
1721 MsgDbHandler *dbHandle = getDbHandle();
1723 MSG_DEBUG("msgId : %d, destStorageId : %d", msgId, destStorageId);
1725 switch (destStorageId) {
1726 case MSG_STORAGE_SIM : /* Move message to sim card */
1727 case MSG_STORAGE_SIM2 : {
1728 MSG_MESSAGE_INFO_S msgInfo;
1729 SMS_SIM_ID_LIST_S simIdList;
1731 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1732 memset(&simIdList, 0x00, sizeof(SMS_SIM_ID_LIST_S));
1734 if ((err = MsgStoGetMessage(msgId, &msgInfo, NULL)) != MSG_SUCCESS)
1737 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
1739 MSG_DEBUG("SMS Plug-in is NULL");
1740 return MSG_ERR_NULL_POINTER;
1743 if (destStorageId == MSG_STORAGE_SIM)
1744 msgInfo.sim_idx = 1;
1745 else if (destStorageId == MSG_STORAGE_SIM2)
1746 msgInfo.sim_idx = 2;
1748 if ((err = plg->saveSimMessage(&msgInfo, &simIdList)) != MSG_SUCCESS)
1751 dbHandle->beginTrans();
1753 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1754 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d, SIM_INDEX = %d WHERE MSG_ID = %d;",
1755 MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, msgInfo.sim_idx, msgId);
1756 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1758 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1759 dbHandle->endTrans(false);
1760 return MSG_ERR_DB_EXEC;
1763 for (unsigned int i = 0; i < simIdList.count; i++) {
1764 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1765 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
1766 MSGFW_SIM_MSG_TABLE_NAME, msgInfo.sim_idx, simIdList.simId[i], msgId);
1767 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1769 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1770 dbHandle->endTrans(false);
1771 return MSG_ERR_DB_EXEC;
1775 dbHandle->endTrans(true);
1779 default: { /* Moving message to memory (when destination storage id is MSG_STORAGE_PHONE) */
1780 #ifndef FEATURE_SMS_CDMA
1781 bool bSimMsg = false;
1784 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1785 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT STORAGE_ID FROM %s WHERE MSG_ID = %d;",
1786 MSGFW_MESSAGE_TABLE_NAME, msgId);
1788 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
1790 if (err != MSG_SUCCESS) {
1791 MSG_DEBUG("Fail to getTable().");
1792 dbHandle->freeTable();
1796 if (dbHandle->getColumnToInt(1) == MSG_STORAGE_SIM) {
1797 MSG_DEBUG("It is SIM Message");
1801 dbHandle->freeTable();
1803 if (bSimMsg == true) {
1804 msg_sim_id_t simMsgId;
1805 msg_sim_slot_id_t sim_idx;
1807 /* get sim message id */
1808 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1810 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
1811 MSGFW_SIM_MSG_TABLE_NAME, msgId);
1815 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
1817 if (err != MSG_SUCCESS) {
1818 MSG_DEBUG("Fail to getTable().");
1819 dbHandle->freeTable();
1823 /* Delete messages in sim card */
1824 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
1826 MSG_DEBUG("SMS Plug-in is NULL");
1827 dbHandle->freeTable();
1828 return MSG_ERR_NULL_POINTER;
1831 for (int i = 0; i < rowCnt; i++) {
1832 sim_idx = dbHandle->getColumnToInt(index++);
1833 simMsgId = dbHandle->getColumnToInt(index++);
1835 MSG_DEBUG("simMsgId is %d.", simMsgId);
1837 if ((err = plg->deleteSimMessage(sim_idx, simMsgId)) != MSG_SUCCESS) {
1838 dbHandle->freeTable();
1843 dbHandle->freeTable();
1845 dbHandle->beginTrans();
1847 /* Delete Messages in SIM Msg table */
1848 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1849 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
1850 MSGFW_SIM_MSG_TABLE_NAME, msgId);
1851 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1853 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1854 dbHandle->endTrans(false);
1855 return MSG_ERR_DB_EXEC;
1858 /* Move storage id */
1859 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1860 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d WHERE MSG_ID = %d;",
1861 MSGFW_MESSAGE_TABLE_NAME, destStorageId, msgId);
1862 MSG_DEBUG("SQL query=[%s]", sqlQuery);
1864 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
1865 dbHandle->endTrans(false);
1866 return MSG_ERR_DB_EXEC;
1869 dbHandle->endTrans(true);
1880 msg_error_t MsgStoCountMessage(msg_folder_id_t folderId, MSG_COUNT_INFO_S *pCountInfo)
1882 if (pCountInfo == NULL) {
1883 MSG_DEBUG("pCountInfo is NULL");
1884 return MSG_ERR_NULL_POINTER;
1887 char sqlQuery[MAX_QUERY_LEN+1];
1888 MsgDbHandler *dbHandle = getDbHandle();
1890 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1891 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 1 AND STORAGE_ID = %d "
1892 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d "
1893 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND STORAGE_ID = %d "
1894 "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND STORAGE_ID = %d;",
1895 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_PHONE,
1896 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_PHONE,
1897 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_SMS_TYPE, MSG_STORAGE_PHONE,
1898 MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE, MSG_STORAGE_PHONE);
1900 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1901 return MSG_ERR_DB_PREPARE;
1903 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1904 pCountInfo->nReadCnt = dbHandle->columnInt(0);
1906 dbHandle->finalizeQuery();
1907 return MSG_ERR_DB_STEP;
1910 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1911 pCountInfo->nUnreadCnt = dbHandle->columnInt(0);
1913 dbHandle->finalizeQuery();
1914 return MSG_ERR_DB_STEP;
1917 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1918 pCountInfo->nSms = dbHandle->columnInt(0);
1920 dbHandle->finalizeQuery();
1921 return MSG_ERR_DB_STEP;
1924 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1925 pCountInfo->nMms = dbHandle->columnInt(0);
1927 dbHandle->finalizeQuery();
1928 return MSG_ERR_DB_STEP;
1931 dbHandle->finalizeQuery();
1937 msg_error_t MsgStoCountMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount)
1939 if (pMsgType == NULL) {
1940 MSG_DEBUG("pMsgType is NULL");
1941 return MSG_ERR_NULL_POINTER;
1946 char sqlQuery[MAX_QUERY_LEN+1];
1947 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1949 MsgDbHandler *dbHandle = getDbHandle();
1951 if ((pMsgType->mainType == MSG_SMS_TYPE) &&
1952 (pMsgType->subType == MSG_NORMAL_SMS || pMsgType->subType == MSG_STATUS_REPORT_SMS || pMsgType->subType == MSG_CONCAT_SIM_SMS)) {
1953 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d);",
1954 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_NORMAL_SMS, MSG_STATUS_REPORT_SMS, MSG_CONCAT_SIM_SMS);
1955 } else if ((pMsgType->mainType == MSG_SMS_TYPE) &&
1956 (pMsgType->subType == MSG_WAP_SI_SMS || pMsgType->subType == MSG_WAP_SL_SMS)) {
1958 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d);",
1959 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_WAP_SI_SMS, MSG_WAP_SL_SMS);
1960 } else if ((pMsgType->mainType == MSG_MMS_TYPE) &&
1961 (pMsgType->subType == MSG_SENDREQ_MMS || pMsgType->subType == MSG_SENDCONF_MMS || pMsgType->subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgType->subType == MSG_RETRIEVE_MANUALCONF_MMS)) {
1963 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d, %d);",
1964 MSGFW_MESSAGE_TABLE_NAME, pMsgType->mainType, MSG_SENDREQ_MMS, MSG_SENDCONF_MMS, MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS);
1966 return MSG_ERR_INVALID_PARAMETER;
1969 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1970 return MSG_ERR_DB_PREPARE;
1972 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
1973 *pMsgCount = dbHandle->columnInt(0);
1975 dbHandle->finalizeQuery();
1976 return MSG_ERR_DB_STEP;
1979 dbHandle->finalizeQuery();
1985 msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
1987 char sqlQuery[MAX_QUERY_LEN+1];
1988 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1989 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, \
1990 SUB_TYPE, DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
1991 BACKUP, PRIORITY, MSG_DIRECTION, DPM_RESTRICTED, SCHEDULED_TIME, SUBJECT, MSG_TEXT, THUMB_PATH, SIM_INDEX \
1992 FROM %s WHERE MSG_ID = %d;",
1993 MSGFW_MESSAGE_TABLE_NAME, msgId);
1995 MsgDbHandler *dbHandle = getDbHandle();
1997 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
1998 return MSG_ERR_DB_PREPARE;
2000 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2001 pMsg->msgId = dbHandle->columnInt(0);
2002 pMsg->threadId = dbHandle->columnInt(1);
2003 pMsg->folderId = dbHandle->columnInt(2);
2004 pMsg->storageId = dbHandle->columnInt(3);
2005 pMsg->msgType.mainType = dbHandle->columnInt(4);
2006 pMsg->msgType.subType = dbHandle->columnInt(5);
2007 pMsg->displayTime = (time_t)dbHandle->columnInt(6);
2008 pMsg->dataSize = dbHandle->columnInt(7);
2009 pMsg->networkStatus = dbHandle->columnInt(8);
2010 pMsg->bRead = dbHandle->columnInt(9);
2011 pMsg->bProtected = dbHandle->columnInt(10);
2012 pMsg->bBackup = dbHandle->columnInt(11);
2013 pMsg->priority = dbHandle->columnInt(12);
2014 pMsg->direction = dbHandle->columnInt(13);
2015 pMsg->bRestricted = dbHandle->columnInt(14);
2017 strncpy(pMsg->subject, (char *)dbHandle->columnText(16), MAX_SUBJECT_LEN);
2019 /* Temp_File_Handling */
2020 if (pMsg->msgType.mainType == MSG_SMS_TYPE || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
2021 if (pMsg->dataSize > MAX_MSG_TEXT_LEN) {
2022 char msgData[pMsg->dataSize+1];
2023 memset(msgData, 0x00, sizeof(msgData));
2025 strncpy(msgData, (char *)dbHandle->columnText(17), pMsg->dataSize);
2027 /* Save Message Data into File */
2028 char fileName[MSG_FILENAME_LEN_MAX+1];
2029 memset(fileName, 0x00, sizeof(fileName));
2031 if (MsgCreateFileName(fileName) == false) {
2032 dbHandle->finalizeQuery();
2033 return MSG_ERR_STORAGE_ERROR;
2036 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, fileName);
2038 if (MsgWriteIpcFile(fileName, msgData, pMsg->dataSize) == false) {
2039 dbHandle->finalizeQuery();
2040 return MSG_ERR_STORAGE_ERROR;
2043 strncpy(pMsg->msgData, fileName, MAX_MSG_DATA_LEN);
2045 pMsg->bTextSms = false;
2047 memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
2048 strncpy(pMsg->msgText, (char *)dbHandle->columnText(17), pMsg->dataSize);
2050 /* For WAP PUSH SI Message */
2051 if (pMsg->msgType.subType == MSG_WAP_SI_SMS) {
2052 strncat(pMsg->msgText, "\n", MAX_MSG_TEXT_LEN-strlen(pMsg->msgText));
2053 strncat(pMsg->msgText, pMsg->subject, MAX_MSG_TEXT_LEN-strlen(pMsg->msgText));
2054 MSG_SEC_DEBUG("pMsg->msgText : [%s]", pMsg->msgText);
2055 pMsg->dataSize = sizeof(pMsg->msgText);
2058 pMsg->bTextSms = true;
2061 if (dbHandle->columnText(16) != NULL)
2062 strncpy(pMsg->msgText, (char *)dbHandle->columnText(17), MAX_MSG_TEXT_LEN);
2065 /* thumbnail path */
2066 if (dbHandle->columnText(18)!= NULL && ((char *)dbHandle->columnText(18))[0] != '\0') {
2067 strncpy(pMsg->thumbPath, (char *)dbHandle->columnText(18), MSG_FILEPATH_LEN_MAX);
2068 MSG_DEBUG("pMsg->thumbPath : [%s]", pMsg->thumbPath);
2071 if (pMsg->bRestricted == true) {
2073 memset(pMsg->msgData, 0x00, sizeof(pMsg->msgData));
2074 memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
2075 memset(pMsg->subject, 0x00, sizeof(pMsg->subject));
2076 memset(pMsg->thumbPath, 0x00, sizeof(pMsg->thumbPath));
2080 pMsg->sim_idx = dbHandle->columnInt(19);
2082 dbHandle->finalizeQuery();
2083 MSG_DEBUG("%s", sqlQuery);
2084 return MSG_ERR_DB_STEP;
2087 dbHandle->finalizeQuery();
2090 /* get address information. */
2091 MsgStoGetAddressByMsgId(dbHandle, pMsg->msgId, &pMsg->nAddressCnt, &pMsg->addressList);
2093 /* Get MMS body if it is MMS. */
2094 if ((pMsg->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS &&
2095 (pMsg->msgType.subType == MSG_RETRIEVE_MMS || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS)) ||
2096 pMsg->msgType.subType == MSG_SENDREQ_MMS || pMsg->msgType.subType == MSG_SENDCONF_MMS || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
2097 msg_error_t err = MSG_SUCCESS;
2098 char *pDestMsg = NULL;
2099 int temp_size = pMsg->dataSize; /* save raw file size; */
2101 /* call mms plugin to get mms specific message data */
2102 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(pMsg->msgType.mainType);
2104 MSG_DEBUG("SMS Plug-in is NULL");
2105 return MSG_ERR_NULL_POINTER;
2108 err = plg->getMmsMessage(pMsg, pSendOptInfo, &pDestMsg);
2109 if (err != MSG_SUCCESS) {
2114 return MSG_ERR_STORAGE_ERROR;
2117 memset(pMsg->msgData, 0, MAX_MSG_DATA_LEN+1);
2119 /* Encode MMS specific data to MMS_MESSAGE_DATA_S */
2120 if (pMsg->dataSize > MAX_MSG_DATA_LEN) {
2121 /* Save Message Data into File */
2122 char tempFileName[MSG_FILENAME_LEN_MAX+1];
2123 memset(tempFileName, 0x00, sizeof(tempFileName));
2125 if (MsgCreateFileName(tempFileName) == false) {
2130 return MSG_ERR_STORAGE_ERROR;
2132 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, tempFileName);
2134 if (MsgWriteIpcFile(tempFileName, pDestMsg, pMsg->dataSize) == false) {
2139 return MSG_ERR_STORAGE_ERROR;
2141 strncpy(pMsg->msgData, tempFileName, MAX_MSG_DATA_LEN);
2142 pMsg->bTextSms = false;
2144 strncpy(pMsg->msgData, pDestMsg, pMsg->dataSize);
2145 pMsg->bTextSms = true;
2148 pMsg->dataSize = temp_size; /*raw file size; */
2156 /* Get SMS Sending Options */
2157 if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL)
2158 MsgStoGetSmsSendOpt(pMsg, pSendOptInfo);
2163 msg_error_t MsgStoGetFailedMessage(int **failed_msg_list, int *count)
2167 msg_error_t err = MSG_SUCCESS;
2168 char sqlQuery[MAX_QUERY_LEN+1];
2169 int rowCnt = 0, index = 0;
2170 MsgDbHandler *dbHandle = getDbHandle();
2172 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2174 /* Folder ID == 2 : sending failed message, Folder ID == 1 : retrieve failed message */
2175 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);",
2176 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_PENDING, MSG_NETWORK_RETRIEVE_PENDING, MSG_OUTBOX_ID, MSG_INBOX_ID);
2177 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2179 if(err == MSG_ERR_DB_NORECORD) {
2180 dbHandle->freeTable();
2184 int *list = new int[rowCnt];
2186 for(int i = 0; i < rowCnt; ++i) {
2187 list[i] = dbHandle->getColumnToInt(index++);
2189 *failed_msg_list = list;
2190 dbHandle->freeTable();
2196 msg_error_t MsgStoAddSyncMLMessage(MSG_MESSAGE_INFO_S *pMsgInfo, int extId, int pinCode)
2200 msg_error_t err = MSG_SUCCESS;
2202 char sqlQuery[MAX_QUERY_LEN+1];
2204 unsigned int rowId = 0;
2205 msg_thread_id_t convId = 0;
2206 MsgDbHandler *dbHandle = getDbHandle();
2208 dbHandle->beginTrans();
2210 if (pMsgInfo->nAddressCnt > 0) {
2211 err = MsgStoAddAddress(dbHandle, pMsgInfo, &convId);
2213 if (err != MSG_SUCCESS) {
2214 dbHandle->endTrans(false);
2219 /* Add Message Table */
2220 pMsgInfo->threadId = convId;
2221 rowId = MsgStoAddMessageTable(dbHandle, pMsgInfo);
2224 dbHandle->endTrans(false);
2225 return MSG_ERR_DB_ROW;
2228 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2229 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
2230 MSGFW_SYNCML_MSG_TABLE_NAME, rowId, extId, pinCode);
2232 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
2233 dbHandle->endTrans(false);
2234 return MSG_ERR_DB_EXEC;
2237 if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
2238 dbHandle->endTrans(false);
2239 return MSG_ERR_STORAGE_ERROR;
2242 dbHandle->endTrans(true);
2244 pMsgInfo->msgId = (msg_message_id_t)rowId;
2246 MsgInsertNotification(pMsgInfo);
2255 msg_error_t MsgStoGetMsgType(msg_message_id_t msgId, MSG_MESSAGE_TYPE_S *pMsgType)
2257 MsgDbHandler *dbHandle = getDbHandle();
2258 char sqlQuery[MAX_QUERY_LEN+1];
2260 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2262 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE FROM %s WHERE MSG_ID = %d;",
2263 MSGFW_MESSAGE_TABLE_NAME, msgId);
2265 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2266 return MSG_ERR_DB_PREPARE;
2268 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2269 pMsgType->mainType = dbHandle->columnInt(0);
2270 pMsgType->subType = dbHandle->columnInt(1);
2273 dbHandle->finalizeQuery();
2279 msg_error_t MsgStoGetQuickPanelData(msg_quickpanel_type_t QPtype, MSG_MESSAGE_INFO_S *pMsg)
2281 msg_error_t err = MSG_SUCCESS;
2283 MsgDbHandler *dbHandle = getDbHandle();
2284 char sqlQuery[MAX_QUERY_LEN+1];
2286 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2288 if (QPtype == MSG_QUICKPANEL_SMS) {
2289 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;",
2290 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_SMS_TYPE, MSG_NORMAL_SMS);
2291 } else if (QPtype == MSG_QUICKPANEL_MMS) {
2292 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;",
2293 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_MMS_TYPE, MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS);
2294 } else if (QPtype == MSG_QUICKPANEL_DELIVER_REP) {
2295 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE SUB_TYPE IN (%d, %d) AND READ_STATUS = 0 ORDER BY DISPLAY_TIME DESC;",
2296 MSGFW_MESSAGE_TABLE_NAME, MSG_STATUS_REPORT_SMS, MSG_DELIVERYIND_MMS);
2297 } else if (QPtype == MSG_QUICKPANEL_READ_REP) {
2298 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;",
2299 MSGFW_MESSAGE_TABLE_NAME, MSG_MMS_TYPE, MSG_READORGIND_MMS);
2300 } else if (QPtype == MSG_QUICKPANEL_VOICEMAIL) {
2301 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;",
2302 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MWI_VOICE_SMS);
2303 } else if (QPtype == MSG_QUICKPANEL_MMS_NOTI) {
2304 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;",
2305 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_MMS_TYPE, MSG_NOTIFICATIONIND_MMS);
2308 /* Get Message ID */
2309 msg_message_id_t msgId;
2311 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2312 return MSG_ERR_DB_PREPARE;
2314 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2315 msgId = dbHandle->columnInt(0);
2317 dbHandle->finalizeQuery();
2318 return MSG_ERR_DB_STEP;
2321 dbHandle->finalizeQuery();
2323 /* Get Message Info */
2324 err = MsgStoGetMessage(msgId, pMsg, NULL);
2330 msg_error_t MsgStoDeleteThreadMessageList(msg_thread_id_t threadId, bool bIncludeProtect, msg_id_list_s *pMsgIdList)
2332 msg_error_t err = MSG_SUCCESS;
2334 MsgDbHandler *dbHandle = getDbHandle();
2335 char sqlQuery[MAX_QUERY_LEN+1];
2337 /*** Get msg id list **/
2338 int rowCnt = 0, index = 0;
2340 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2342 #ifdef MSG_NOTI_INTEGRATION
2343 if (bIncludeProtect) {
2344 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2345 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
2346 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
2348 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2349 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0;",
2350 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
2353 if (bIncludeProtect) {
2354 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2355 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
2356 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
2358 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
2359 CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0;",
2360 MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
2364 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2366 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
2367 MSG_ERR("Fail to getTable().");
2368 dbHandle->freeTable();
2373 dbHandle->freeTable();
2375 err = MsgStoClearConversationTable(dbHandle);
2376 if (err != MSG_SUCCESS) {
2377 MSG_ERR("Fail to MsgStoClearConversationTable().");
2381 err = MsgStoUpdateConversation(dbHandle, threadId);
2382 if (err != MSG_SUCCESS) {
2383 MSG_ERR("Fail to MsgStoUpdateConversation().");
2390 pMsgIdList->nCount = rowCnt;
2392 MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
2394 pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
2396 for (int i = 0; i < rowCnt; i++)
2397 pMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
2399 dbHandle->freeTable();
2402 err = MsgStoDeleteMessageByList(pMsgIdList);
2403 if (err != MSG_SUCCESS) {
2404 MSG_ERR("Fail to MsgStoDeleteMessageByList().");
2412 msg_error_t MsgStoSetTempAddressTable(MSG_ADDRESS_INFO_S *pAddrInfo, int addr_cnt)
2414 MsgDbHandler *dbHandle = getDbHandle();
2415 char sqlQuery[MAX_QUERY_LEN+1];
2417 dbHandle->beginTrans();
2418 /* reset address temp table */
2419 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2420 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_ADDRESS_TEMP_TABLE_NAME);
2421 MSG_DEBUG("[%s]", sqlQuery);
2423 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2424 return MSG_ERR_DB_EXEC;
2426 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2427 dbHandle->finalizeQuery();
2428 dbHandle->endTrans(false);
2429 return MSG_ERR_DB_EXEC;
2432 dbHandle->finalizeQuery();
2434 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2435 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (?);", MSGFW_ADDRESS_TEMP_TABLE_NAME);
2436 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
2437 dbHandle->endTrans(false);
2438 return MSG_ERR_DB_PREPARE;
2441 char newPhoneNum[MAX_ADDRESS_VAL_LEN+1];
2442 char tmpNum[MAX_ADDRESS_VAL_LEN+1];
2443 for (int i = 0; i < addr_cnt; i++) {
2444 memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
2445 memset(tmpNum, 0x00, sizeof(tmpNum));
2446 MsgConvertNumber(pAddrInfo[i].addressVal, tmpNum, sizeof(tmpNum));
2447 snprintf(newPhoneNum, sizeof(newPhoneNum), "%%%%%s", tmpNum);
2448 dbHandle->resetQuery();
2449 dbHandle->bindText(newPhoneNum, 1);
2450 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2451 dbHandle->finalizeQuery();
2452 dbHandle->endTrans(false);
2453 return MSG_ERR_DB_EXEC;
2457 dbHandle->finalizeQuery();
2458 dbHandle->endTrans(true);
2464 msg_error_t MsgStoCountMsgByContact(const MSG_THREAD_LIST_INDEX_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pThreadCountInfo)
2466 MsgDbHandler *dbHandle = getDbHandle();
2467 char sqlQuery[MAX_QUERY_LEN+1];
2469 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2471 if (pAddrInfo->contactId > 0) {
2472 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) AS TOTAL, "
2473 "SUM(CASE WHEN READ_STATUS = 0 AND FOLDER_ID = %d THEN 1 ELSE 0 END), "
2474 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END), "
2475 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END) "
2476 "FROM (SELECT * FROM %s A JOIN %s B ON A.CONV_ID = B.CONV_ID WHERE B.CONTACT_ID = %d)",
2477 MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MMS_TYPE, MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pAddrInfo->contactId);
2479 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) AS TOTAL, "
2480 "SUM(CASE WHEN READ_STATUS = 0 AND FOLDER_ID = %d THEN 1 ELSE 0 END), "
2481 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END), "
2482 "SUM(CASE WHEN MAIN_TYPE = %d THEN 1 ELSE 0 END) "
2483 "FROM (SELECT * FROM %s A JOIN %s B ON A.CONV_ID = B.CONV_ID WHERE B.ADDRESS_VAL = '%s')",
2484 MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MMS_TYPE, MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pAddrInfo->msgAddrInfo.addressVal);
2487 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2488 return MSG_ERR_DB_PREPARE;
2490 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2491 pThreadCountInfo->totalCount = dbHandle->columnInt(0);
2492 pThreadCountInfo->unReadCount = dbHandle->columnInt(1);
2493 pThreadCountInfo->smsMsgCount = dbHandle->columnInt(2);
2494 pThreadCountInfo->mmsMsgCount = dbHandle->columnInt(3);
2496 dbHandle->finalizeQuery();
2497 return MSG_ERR_DB_STEP;
2500 dbHandle->finalizeQuery();
2506 msg_error_t MsgStoGetSyncMLExtId(msg_message_id_t msgId, int *extId)
2508 MsgDbHandler *dbHandle = getDbHandle();
2509 char sqlQuery[MAX_QUERY_LEN+1];
2511 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2513 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXT_ID FROM %s WHERE MSG_ID = %d;",
2514 MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
2516 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2517 return MSG_ERR_DB_PREPARE;
2519 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2520 *extId = dbHandle->columnInt(0);
2522 dbHandle->finalizeQuery();
2523 return MSG_ERR_DB_STEP;
2526 dbHandle->finalizeQuery();
2532 msg_error_t MsgStoGetSmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
2534 MsgDbHandler *dbHandle = getDbHandle();
2535 char sqlQuery[MAX_QUERY_LEN+1];
2536 msg_error_t err = MSG_SUCCESS;
2538 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2539 snprintf(sqlQuery, sizeof(sqlQuery),
2540 "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
2542 "WHERE MSG_ID = %d "
2543 "order by TIME ASC;"
2544 , MSGFW_SMS_REPORT_TABLE_NAME, msgId);
2546 int rowCnt = 0, index = 0;
2547 err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2549 if (err != MSG_SUCCESS) {
2550 MSG_DEBUG("Fail to getTable().");
2551 dbHandle->freeTable();
2552 if (err == MSG_ERR_DB_NORECORD)
2558 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
2559 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
2561 for (int i = 0; i < rowCnt; i++) {
2562 dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
2563 report_status[i].type = dbHandle->getColumnToInt(index++);
2564 report_status[i].status = dbHandle->getColumnToInt(index++);
2565 report_status[i].statusTime = (time_t)dbHandle->getColumnToInt(index++);
2567 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);
2570 *pReportStatus = report_status;
2572 dbHandle->freeTable();
2577 msg_error_t MsgStoGetMmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
2579 MsgDbHandler *dbHandle = getDbHandle();
2580 char sqlQuery[MAX_QUERY_LEN+1];
2582 msg_direction_type_t direction = MSG_DIRECTION_TYPE_MO;
2584 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_DIRECTION FROM %s WHERE MSG_ID = %d;",
2585 MSGFW_MESSAGE_TABLE_NAME, msgId);
2587 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2588 return MSG_ERR_DB_PREPARE;
2590 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2591 direction = dbHandle->columnInt(0);
2594 dbHandle->finalizeQuery();
2596 if (direction == MSG_DIRECTION_TYPE_MO) {/*get received report list of MO message */
2597 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2598 /*MSG_ID INTEGER , ADDRESS_VAL TEXT , STATUS_TYPE INTEGER , STATUS INTEGER DEFAULT 0 , TIME DATETIME) */
2599 /*select * from MSG_REPORT_TABLE where MSG_ID=38 order by ADDRESS_VAL DESC, STATUS_TYPE ASC; */
2600 snprintf(sqlQuery, sizeof(sqlQuery),
2601 "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
2603 "WHERE MSG_ID = %d "
2604 "order by ADDRESS_VAL DESC, STATUS_TYPE ASC;"
2605 , MSGFW_REPORT_TABLE_NAME, msgId);
2607 int rowCnt = 0, index = 0;
2608 msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2609 if (err != MSG_SUCCESS) {
2610 MSG_DEBUG("Fail to getTable().");
2611 dbHandle->freeTable();
2612 if (err == MSG_ERR_DB_NORECORD)
2618 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
2619 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
2621 for (int i = 0; i < rowCnt; i++) {
2622 dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
2623 report_status[i].type = dbHandle->getColumnToInt(index++);
2624 report_status[i].status = dbHandle->getColumnToInt(index++);
2625 report_status[i].statusTime = (time_t)dbHandle->getColumnToInt(index++);
2627 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);
2630 *pReportStatus = report_status;
2632 dbHandle->freeTable();
2634 } else if (direction == MSG_DIRECTION_TYPE_MT) { /*read report sent status of MT message */
2635 int readReportSentStatus;
2637 if (MsgStoCheckReadReportRequested(dbHandle, msgId) == false) {
2639 *pReportStatus = NULL;
2640 return MSG_ERR_READREPORT_NOT_REQUESTED;
2643 MsgStoGetReadReportSendStatus(msgId, &readReportSentStatus);
2647 MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)];
2648 memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
2650 report_status->addressVal[0] = '\0';
2651 report_status->type = MSG_REPORT_TYPE_READ_REPORT_SENT;
2652 report_status->status = readReportSentStatus;
2653 report_status->statusTime = 0;
2655 MSG_DEBUG("report_type = %d, report_status = %d", report_status->type, report_status->status);
2657 *pReportStatus = report_status;
2664 msg_error_t MsgStoGetThreadIdByAddress(const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t *pThreadId)
2666 MsgDbHandler *dbHandle = getDbHandle();
2667 if(pMsg->nAddressCnt > 0) {
2668 if (MsgExistAddress(dbHandle, pMsg, pThreadId) == true) {
2669 MSG_DEBUG("Conversation ID : [%d]", *pThreadId);
2671 /* check thread count */
2672 MSG_THREAD_VIEW_S threadInfo;
2673 memset(&threadInfo, 0x00, sizeof(MSG_THREAD_VIEW_S));
2674 MsgStoGetThreadInfo(*pThreadId, &threadInfo);
2675 MSG_DEBUG("threadInfo.smsCnt [%d], threadInfo.mmsCnt [%d]", threadInfo.smsCnt, threadInfo.mmsCnt);
2676 if ((threadInfo.smsCnt + threadInfo.mmsCnt) > 0) {
2687 msg_error_t MsgStoGetThreadUnreadCnt(msg_thread_id_t threadId, int *cnt)
2691 MsgDbHandler *dbHandle = getDbHandle();
2695 char sqlQuery[MAX_QUERY_LEN+1];
2698 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2699 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s A \
2700 WHERE CONV_ID = %d AND READ_STATUS = 0;", MSGFW_MESSAGE_TABLE_NAME, threadId);
2702 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2703 return MSG_ERR_DB_PREPARE;
2705 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
2706 msgCnt = dbHandle->columnInt(0);
2709 dbHandle->finalizeQuery();
2719 msg_error_t MsgStoGetThreadInfo(msg_thread_id_t threadId, MSG_THREAD_VIEW_S *pThreadInfo)
2723 MsgDbHandler *dbHandle = getDbHandle();
2724 int rowCnt = 0, index = 0;
2726 char sqlQuery[MAX_QUERY_LEN+1];
2727 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2729 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.UNREAD_CNT, A.SMS_CNT, A.MMS_CNT, "
2730 "A.MAIN_TYPE, A.SUB_TYPE, A.MSG_DIRECTION, A.DISPLAY_TIME, A.DISPLAY_NAME, A.MSG_TEXT, "
2731 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.PROTECTED = 1) AS PROTECTED, "
2732 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.FOLDER_ID = %d) AS DRAFT, "
2733 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.NETWORK_STATUS = %d) AS FAILED, "
2734 "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.NETWORK_STATUS = %d) AS SENDING "
2735 "FROM %s A WHERE A.CONV_ID = %d AND A.SMS_CNT + A.MMS_CNT > 0;",
2736 MSGFW_MESSAGE_TABLE_NAME,
2737 MSGFW_MESSAGE_TABLE_NAME, MSG_DRAFT_ID,
2738 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_FAIL,
2739 MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SENDING,
2740 MSGFW_CONVERSATION_TABLE_NAME, threadId);
2742 msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
2744 if (err == MSG_ERR_DB_NORECORD) {
2745 dbHandle->freeTable();
2747 } else if (err != MSG_SUCCESS) {
2748 MSG_DEBUG("Fail to getTable().");
2749 dbHandle->freeTable();
2754 MSG_DEBUG("rowCnt is %d", rowCnt);
2755 dbHandle->freeTable();
2758 pThreadInfo->threadId = dbHandle->getColumnToInt(index++);
2760 pThreadInfo->unreadCnt = dbHandle->getColumnToInt(index++);
2761 pThreadInfo->smsCnt = dbHandle->getColumnToInt(index++);
2762 pThreadInfo->mmsCnt = dbHandle->getColumnToInt(index++);
2764 pThreadInfo->mainType = dbHandle->getColumnToInt(index++);
2765 pThreadInfo->subType = dbHandle->getColumnToInt(index++);
2767 pThreadInfo->direction = dbHandle->getColumnToInt(index++);
2768 pThreadInfo->threadTime = (time_t)dbHandle->getColumnToInt(index++);
2770 memset(pThreadInfo->threadName, 0x00, sizeof(pThreadInfo->threadName));
2771 dbHandle->getColumnToString(index++, MAX_THREAD_NAME_LEN, pThreadInfo->threadName);
2773 memset(pThreadInfo->threadData, 0x00, sizeof(pThreadInfo->threadData));
2774 dbHandle->getColumnToString(index++, MAX_THREAD_DATA_LEN, pThreadInfo->threadData);
2776 int protectedCnt = dbHandle->getColumnToInt(index++);
2777 if (protectedCnt > 0)
2778 pThreadInfo->bProtected = true;
2780 int draftCnt = dbHandle->getColumnToInt(index++);
2782 pThreadInfo->bDraft = true;
2784 int failedCnt = dbHandle->getColumnToInt(index++);
2786 pThreadInfo->bSendFailed = true;
2788 int sendingCnt = dbHandle->getColumnToInt(index++);
2790 pThreadInfo->bSending = true;
2793 dbHandle->freeTable();
2801 msg_error_t MsgStoRestoreMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
2805 MsgDbHandler *dbHandle = getDbHandle();
2806 msg_error_t err = MSG_SUCCESS;
2807 char sqlQuery[MAX_QUERY_LEN+1];
2809 if(MsgExistConversation(dbHandle, pMsg->threadId)) {
2810 /* add message to address table which having same thread_id and datetime; */
2811 for (int i = 0; i < pMsg->nAddressCnt; i++) {
2812 if(MsgExistAddress(dbHandle, pMsg, pMsg->threadId, i) == false) {
2813 unsigned int addrId;
2814 MSG_CONTACT_INFO_S contactInfo;
2815 memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
2817 /* Get Contact Info */
2818 /* if (MsgGetContactInfo(&(pMsg->addressList[i]), &contactInfo) != MSG_SUCCESS) { */
2819 /* MSG_DEBUG("MsgGetContactInfo() fail."); */
2821 err = dbHandle->getRowId(MSGFW_ADDRESS_TABLE_NAME, &addrId);
2822 if (err != MSG_SUCCESS) {
2823 MSG_DEBUG("pDbHandle->getRowId fail. [%d]", err);
2828 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2829 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, '%s', %d, %d, ?, ?, ?, ?, ?, '%s', 0);",
2830 MSGFW_ADDRESS_TABLE_NAME, addrId, pMsg->threadId, pMsg->addressList[i].addressType, pMsg->addressList[i].recipientType, pMsg->addressList[i].addressVal,
2831 contactInfo.contactId, contactInfo.addrbookId, contactInfo.imagePath);
2833 MSG_SEC_DEBUG("Add Address Info. [%s]", sqlQuery);
2835 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
2836 return MSG_ERR_DB_PREPARE;
2838 dbHandle->bindText(contactInfo.firstName, 1);
2839 dbHandle->bindText(contactInfo.lastName, 2);
2840 dbHandle->bindText(contactInfo.middleName, 3);
2841 dbHandle->bindText(contactInfo.prefix, 4);
2842 dbHandle->bindText(contactInfo.suffix, 5);
2844 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2845 dbHandle->finalizeQuery();
2846 return MSG_ERR_DB_STEP;
2849 dbHandle->finalizeQuery();
2851 /* set conversation display name by conv id */
2852 MsgStoSetConversationDisplayName(dbHandle, pMsg->threadId);
2857 if(!MsgExistMessage(dbHandle, pMsg)) {
2858 unsigned int rowId = 0;
2860 if (pMsg->threadId > 0 && pMsg->folderId == MSG_DRAFT_ID) {
2861 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2863 snprintf(sqlQuery, sizeof(sqlQuery),
2864 "DELETE FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d;",
2865 MSGFW_MESSAGE_TABLE_NAME, pMsg->threadId, MSG_DRAFT_ID);
2867 MSG_DEBUG("sqlQuery [%s]", sqlQuery);
2869 err = dbHandle->execQuery(sqlQuery);
2871 if (err != MSG_SUCCESS) {
2872 MSG_DEBUG("fail to delete draft messages.");
2876 err = dbHandle->getRowId(MSGFW_MESSAGE_TABLE_NAME, &rowId);
2878 pMsg->msgId = (msg_message_id_t)rowId;
2882 char *pFileData = NULL;
2883 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
2886 if (pMsg->bTextSms == false) {
2887 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
2888 return MSG_ERR_STORAGE_ERROR;
2890 MSG_DEBUG("file size [%d]", fileSize);
2893 char keyName[MAX_VCONFKEY_NAME_LEN];
2894 memset(keyName, 0x00, sizeof(keyName));
2895 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, pMsg->sim_idx);
2898 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
2899 MSG_INFO("MsgSettingGetString() is failed");
2903 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2905 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %ld, %d, %d, %d, %d, %d, %d, 0, %d, ?, '', '', ?, 0, %d, '%s');",
2906 MSGFW_MESSAGE_TABLE_NAME, rowId, pMsg->threadId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType,
2907 pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
2908 pMsg->bBackup, pMsg->sim_idx, imsi);
2911 MSG_DEBUG("QUERY : %s", sqlQuery);
2918 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
2919 return MSG_ERR_DB_EXEC;
2922 dbHandle->bindText(pMsg->subject, 1);
2924 if (pMsg->bTextSms == false)
2925 dbHandle->bindText(pFileData, 2);
2927 dbHandle->bindText(pMsg->msgText, 2);
2929 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
2930 dbHandle->finalizeQuery();
2931 return MSG_ERR_DB_EXEC;
2934 dbHandle->finalizeQuery();
2936 if (pMsg->msgType.subType != MSG_SENDREQ_MMS) {
2937 err = MsgStoUpdateConversation(dbHandle, pMsg->threadId);
2939 if (err != MSG_SUCCESS) {
2944 /* In the case of MMS Message, load the MMS plugin to save MMS PDU */
2945 if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
2946 if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
2947 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
2949 return MSG_ERR_NULL_POINTER;
2951 err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
2953 if (err != MSG_SUCCESS)
2954 return MSG_ERR_STORAGE_ERROR;
2956 if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
2957 MSG_SEC_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
2959 err = MsgStoUpdateMMSMessage(pMsg);
2961 if (err != MSG_SUCCESS)
2962 return MSG_ERR_STORAGE_ERROR;
2968 /* add message to conversation, message, address table; */
2970 err = MsgStoAddMessage(pMsg, pSendOptInfo);
2979 msg_message_id_t MsgStoAddSimMessage(MSG_MESSAGE_INFO_S *pMsg, int *simIdList, int listSize)
2982 MsgDbHandler *dbHandle = getDbHandle();
2983 if (pMsg == NULL || pMsg->msgType.mainType == MSG_MMS_TYPE) {
2984 MSG_DEBUG("pMsg == NULL || pMsg->msgType.mainType == MSG_MMS_TYPE");
2988 if ((pMsg->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsg->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
2989 if (pMsg->msgId > 0) {
2990 pMsg->bRead = false;
2991 if (MsgStoUpdateMessage(pMsg, NULL) != MSG_SUCCESS) {
2992 MSG_DEBUG("MsgStoUpdateMessage is failed!!!");
2995 if (MsgStoAddMessage(pMsg, NULL) != MSG_SUCCESS) {
2996 MSG_DEBUG("MsgStoAddMessage is failed!!!");
3001 if (MsgStoAddMessage(pMsg, NULL) != MSG_SUCCESS) {
3002 MSG_DEBUG("MsgStoAddMessage is failed!!!");
3007 dbHandle->beginTrans();
3009 MSG_DEBUG("simIdList exist.");
3011 for(int i = 0; i < listSize; ++i) {
3013 simId = simIdList[i] - 1;
3014 char sqlQuery[MAX_QUERY_LEN+1];
3015 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3016 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
3017 MSGFW_SIM_MSG_TABLE_NAME, pMsg->sim_idx, simId, pMsg->msgId);
3019 MSG_DEBUG("QUERY : %s", sqlQuery);
3021 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
3022 dbHandle->endTrans(false);
3030 dbHandle->endTrans(true);
3038 #ifdef FEATURE_SMS_CDMA
3039 msg_error_t MsgCheckUniqueness(bool bInsert, msg_message_id_t msgId, MSG_UNIQUE_INDEX_S *p_msg)
3043 MsgDbHandler *dbHandle = getDbHandle();
3046 char sqlQuery[MAX_QUERY_LEN+1];
3049 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3050 dbHandle->beginTrans();
3052 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;",
3053 MSGFW_UNIQUENESS_INFO_TABLE_NAME, p_msg->tele_msgId, p_msg->address, p_msg->sub_address, p_msg->time_stamp, p_msg->telesvc_id);
3055 dbHandle->getTable(sqlQuery, &nRowCnt, NULL);
3056 MSG_DEBUG("nRowCnt = [%d]", nRowCnt);
3058 dbHandle->freeTable();
3059 dbHandle->endTrans(true);
3062 MSG_DEBUG("<<<<This incoming message is a new message>>>>");
3065 MSG_DEBUG("<<<<This incoming message is a repeated message>>>>");
3066 return MSG_ERR_UNKNOWN;
3069 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3070 dbHandle->beginTrans();
3072 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, '%s', '%s', '%s', %d);",
3073 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);
3075 dbHandle->execQuery(sqlQuery);
3076 dbHandle->endTrans(true);
3085 msg_error_t MsgStoUpdateIMSI(int sim_idx)
3088 MSG_DEBUG("sim_idx = %d", sim_idx);
3090 /* msg_error_t err = MSG_SUCCESS; */
3091 MsgDbHandler *dbHandle = getDbHandle();
3093 char sqlQuery[MAX_QUERY_LEN+1];
3094 char keyName[MAX_VCONFKEY_NAME_LEN];
3096 dbHandle->beginTrans();
3099 MSG_DEBUG("sim index is 0");
3100 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3102 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET SIM_INDEX = 0;",
3103 MSGFW_MESSAGE_TABLE_NAME);
3105 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
3106 dbHandle->endTrans(false);
3107 return MSG_ERR_DB_EXEC;
3110 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
3111 dbHandle->finalizeQuery();
3112 dbHandle->endTrans(false);
3113 return MSG_ERR_DB_EXEC;
3116 MSG_DEBUG("sim index is %d", sim_idx);
3118 memset(keyName, 0x00, sizeof(keyName));
3119 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, sim_idx);
3122 if (MsgSettingGetString(keyName, &imsi) != MSG_SUCCESS) {
3123 MSG_INFO("MsgSettingGetString() is failed");
3126 MSG_SEC_DEBUG("imsi value exist -> %s", imsi);
3128 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3130 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET SIM_INDEX = %d \
3131 WHERE SIM_IMSI LIKE '%s';",
3132 MSGFW_MESSAGE_TABLE_NAME, sim_idx, imsi);
3139 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
3140 dbHandle->endTrans(false);
3141 return MSG_ERR_DB_EXEC;
3144 if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
3145 dbHandle->finalizeQuery();
3146 dbHandle->endTrans(false);
3147 return MSG_ERR_DB_EXEC;
3151 dbHandle->finalizeQuery();
3152 dbHandle->endTrans(true);
3160 msg_error_t MsgStoUpdateDPMRestrictedStatus(MSG_MAIN_TYPE_T msgType)
3162 msg_error_t err = MSG_SUCCESS;
3164 char sqlQuery[MAX_QUERY_LEN+1];
3165 MsgDbHandler *dbHandle = getDbHandle();
3167 msg_id_list_s msgIdList = {0,};
3170 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3171 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE MAIN_TYPE = %d AND DPM_RESTRICTED = 1;",
3172 MSGFW_MESSAGE_TABLE_NAME, msgType);
3174 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
3175 if (err != MSG_SUCCESS) {
3176 dbHandle->freeTable();
3180 msg_message_id_t *msgIds = new msg_message_id_t[rowCnt];
3181 for (int i = 0; i < rowCnt; i++) {
3182 msgIds[i] = dbHandle->getColumnToInt(i + 1);
3185 dbHandle->freeTable();
3187 msgIdList.nCount = rowCnt;
3188 msgIdList.msgIdList = msgIds;
3190 memset(sqlQuery, 0x00, sizeof(sqlQuery));
3191 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET DPM_RESTRICTED = 0 WHERE MAIN_TYPE = %d AND DPM_RESTRICTED = 1;",
3192 MSGFW_MESSAGE_TABLE_NAME, msgType);
3194 err = dbHandle->execQuery(sqlQuery);
3195 if (err == MSG_SUCCESS) {
3196 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
3199 if (msgIdList.msgIdList)
3200 delete [] msgIdList.msgIdList;